Commit e9e699f8 authored by Brendan Gregg's avatar Brendan Gregg Committed by GitHub

Merge pull request #379 from iovisor/abort_messages

all abort()s should print an error message
parents 2b83b671 5c2ca5b9
#include "ast.h"
#include "parser.tab.hh"
#include <iostream>
namespace bpftrace {
namespace ast {
......@@ -109,7 +110,9 @@ std::string opstr(Binop &binop)
case bpftrace::Parser::token::BAND: return "&";
case bpftrace::Parser::token::BOR: return "|";
case bpftrace::Parser::token::BXOR: return "^";
default: abort();
default:
std::cerr << "unknown binary operator" << std::endl;
abort();
}
}
......@@ -120,7 +123,9 @@ std::string opstr(Unop &unop)
case bpftrace::Parser::token::BNOT: return "~";
case bpftrace::Parser::token::MINUS: return "-";
case bpftrace::Parser::token::MUL: return "dereference";
default: abort();
default:
std::cerr << "unknown union operator" << std::endl;
abort();
}
}
......
......@@ -158,6 +158,7 @@ void CodegenLLVM::visit(Builtin &builtin)
}
else
{
std::cerr << "unknown builtin \"" << builtin.ident << "\"" << std::endl;
abort();
}
}
......@@ -462,7 +463,10 @@ void CodegenLLVM::visit(Call &call)
auto &reg_name = static_cast<String&>(*call.vargs->at(0)).str;
int offset = arch::offset(reg_name);
if (offset == -1)
{
std::cerr << "negative offset on reg() call" << std::endl;
abort();
}
AllocaInst *dst = b_.CreateAllocaBPF(call.type, call.func+"_"+reg_name);
Value *src = b_.CreateGEP(ctx_, b_.getInt64(offset * sizeof(uintptr_t)));
......@@ -677,7 +681,7 @@ void CodegenLLVM::visit(Call &call)
else
{
std::cerr << "Error: missing codegen for function \"" << call.func << "\"" << std::endl;
std::cerr << "missing codegen for function \"" << call.func << "\"" << std::endl;
abort();
}
}
......@@ -738,6 +742,7 @@ void CodegenLLVM::visit(Binop &binop)
expr_ = b_.CreateStrcmp(val, string_literal, true);
break;
default:
std::cerr << "missing codegen to string operator \"" << opstr(binop) << "\"" << std::endl;
abort();
}
b_.CreateLifetimeEnd(val);
......@@ -771,9 +776,15 @@ void CodegenLLVM::visit(Binop &binop)
case bpftrace::Parser::token::BAND: expr_ = b_.CreateAnd (lhs, rhs); break;
case bpftrace::Parser::token::BOR: expr_ = b_.CreateOr (lhs, rhs); break;
case bpftrace::Parser::token::BXOR: expr_ = b_.CreateXor (lhs, rhs); break;
case bpftrace::Parser::token::LAND: abort(); // Handled earlier
case bpftrace::Parser::token::LOR: abort(); // Handled earlier
default: abort();
case bpftrace::Parser::token::LAND:
std::cerr << "\"" << opstr(binop) << "\" was handled earlier" << std::endl;
abort();
case bpftrace::Parser::token::LOR:
std::cerr << "\"" << opstr(binop) << "\" was handled earlier" << std::endl;
abort();
default:
std::cerr << "missing codegen (LLVM) to string operator \"" << opstr(binop) << "\"" << std::endl;
abort();
}
}
expr_ = b_.CreateIntCast(expr_, b_.getInt64Ty(), false);
......@@ -804,7 +815,9 @@ void CodegenLLVM::visit(Unop &unop)
b_.CreateLifetimeEnd(dst);
break;
}
default: abort();
default:
std::cerr << "missing codegen to union expression type" << std::endl;
abort();
}
}
else if (type.type == Type::cast)
......@@ -813,6 +826,7 @@ void CodegenLLVM::visit(Unop &unop)
}
else
{
std::cerr << "missing codegen to union operator \"" << opstr(unop) << "\"" << std::endl;
abort();
}
}
......
......@@ -123,6 +123,7 @@ llvm::Type *IRBuilderBPF::GetType(const SizedType &stype)
ty = getInt8Ty();
break;
default:
std::cerr << stype.size << " is not a valid type size for GetType" << std::endl;
abort();
}
}
......
......@@ -880,7 +880,11 @@ int SemanticAnalyser::create_maps(bool debug)
auto search_args = map_key_.find(map_name);
if (search_args == map_key_.end())
{
std::cerr << "map key \"" << map_name << "\" not found" << std::endl;
abort();
}
auto &key = search_args->second;
if (debug)
......@@ -892,7 +896,11 @@ int SemanticAnalyser::create_maps(bool debug)
// store lhist args to the bpftrace::Map
auto map_args = map_args_.find(map_name);
if (map_args == map_args_.end())
{
std::cerr << "map arg \"" << map_name << "\" not found" << std::endl;
abort();
}
Expression &min_arg = *map_args->second.at(1);
Expression &max_arg = *map_args->second.at(2);
Expression &step_arg = *map_args->second.at(3);
......
......@@ -34,7 +34,9 @@ bpf_probe_attach_type attachtype(ProbeType t)
case ProbeType::uprobe: return BPF_PROBE_ENTRY; break;
case ProbeType::uretprobe: return BPF_PROBE_RETURN; break;
case ProbeType::usdt: return BPF_PROBE_ENTRY; break;
default: abort();
default:
std::cerr << "invalid probe attachtype \"" << probetypeName(t) << "\"" << std::endl;
abort();
}
}
......@@ -52,7 +54,9 @@ bpf_prog_type progtype(ProbeType t)
case ProbeType::interval: return BPF_PROG_TYPE_PERF_EVENT; break;
case ProbeType::software: return BPF_PROG_TYPE_PERF_EVENT; break;
case ProbeType::hardware: return BPF_PROG_TYPE_PERF_EVENT; break;
default: abort();
default:
std::cerr << "program type not found" << std::endl;
abort();
}
}
......@@ -89,6 +93,7 @@ AttachedProbe::AttachedProbe(Probe &probe, std::tuple<uint8_t *, uintptr_t> func
attach_hardware();
break;
default:
std::cerr << "invalid attached probe type \"" << probetypeName(probe_.type) << "\"" << std::endl;
abort();
}
}
......@@ -103,6 +108,7 @@ AttachedProbe::AttachedProbe(Probe &probe, std::tuple<uint8_t *, uintptr_t> func
attach_usdt(pid);
break;
default:
std::cerr << "invalid attached probe type \"" << probetypeName(probe_.type) << "\"" << std::endl;
abort();
}
}
......@@ -141,6 +147,7 @@ AttachedProbe::~AttachedProbe()
case ProbeType::hardware:
break;
default:
std::cerr << "invalid attached probe type \"" << probetypeName(probe_.type) << "\" at destructor" << std::endl;
abort();
}
if (err)
......@@ -156,6 +163,7 @@ std::string AttachedProbe::eventprefix() const
case BPF_PROBE_RETURN:
return "r_";
default:
std::cerr << "invalid eventprefix" << std::endl;
abort();
}
}
......@@ -177,6 +185,7 @@ std::string AttachedProbe::eventname() const
case ProbeType::tracepoint:
return probe_.attach_point;
default:
std::cerr << "invalid eventname probe \"" << probetypeName(probe_.type) << "\"" << std::endl;
abort();
}
}
......@@ -284,6 +293,7 @@ static unsigned kernel_version(int attempt)
return 0;
}
std::cerr << "invalid kernel version" << std::endl;
abort();
}
......@@ -472,6 +482,7 @@ void AttachedProbe::attach_profile()
}
else
{
std::cerr << "invalid profile path \"" << probe_.path << "\"" << std::endl;
abort();
}
......@@ -507,6 +518,7 @@ void AttachedProbe::attach_interval()
}
else
{
std::cerr << "invalid interval path \"" << probe_.path << "\"" << std::endl;
abort();
}
......
......@@ -307,6 +307,7 @@ void perf_event_printer(void *cb_cookie, void *data, int size)
system(buffer);
break;
default:
std::cerr << "printf() can only take up to 7 arguments (" << args.size() << ") provided" << std::endl;
abort();
}
......@@ -345,6 +346,7 @@ void perf_event_printer(void *cb_cookie, void *data, int size)
arg_values.at(3)->value(), arg_values.at(4)->value(), arg_values.at(5)->value());
break;
default:
std::cerr << "printf() can only take up to 7 arguments (" << args.size() << ") provided" << std::endl;
abort();
}
}
......@@ -381,6 +383,7 @@ std::vector<std::unique_ptr<IPrintable>> BPFtrace::get_arg_values(const std::vec
*reinterpret_cast<uint8_t*>(arg_data+arg.offset)));
break;
default:
std::cerr << "get_arg_values: invalid integer size. 8, 4, 2 and byte supported. " << arg.type.size << "provided" << std::endl;
abort();
}
break;
......@@ -437,6 +440,7 @@ std::vector<std::unique_ptr<IPrintable>> BPFtrace::get_arg_values(const std::vec
8)));
break;
default:
std::cerr << "invalid argument type" << std::endl;
abort();
}
}
......@@ -1680,8 +1684,12 @@ void BPFtrace::sort_by_key(std::vector<SizedType> key_args,
});
}
else
{
std::cerr << "invalid integer argument size. 4 or 8 expected, but " << arg.size << " provided" << std::endl;
abort();
}
}
else if (arg.type == Type::string)
{
std::stable_sort(values_by_key.begin(), values_by_key.end(), [&](auto &a, auto &b)
......
......@@ -77,6 +77,7 @@ Map::Map(enum bpf_map_type map_type)
}
else
{
std::cerr << "invalid map type" << std::endl;
abort();
}
mapfd_ = bpf_create_map(map_type, name.c_str(), key_size, value_size, max_entries, flags);
......@@ -92,6 +93,7 @@ Map::Map(enum bpf_map_type map_type)
name = "perf event";
break;
default:
std::cerr << "invalid map type" << std::endl;
abort();
}
......
......@@ -88,6 +88,7 @@ std::string MapKey::argument_value(BPFtrace &bpftrace,
case Type::string:
return std::string((char*)data);
}
std::cerr << "invalid mapkey argument type" << std::endl;
abort();
}
......
......@@ -51,7 +51,9 @@ std::string typestr(Type t)
case Type::inet: return "inet"; break;
case Type::cast: return "cast"; break;
case Type::probe: return "probe"; break;
default: abort();
default:
std::cerr << "call or probe type not found" << std::endl;
abort();
}
}
......@@ -87,6 +89,27 @@ std::string probetypeName(const std::string &probeName)
return res;
}
std::string probetypeName(ProbeType t)
{
switch (t)
{
case ProbeType::invalid: return "invalid"; break;
case ProbeType::kprobe: return "kprobe"; break;
case ProbeType::kretprobe: return "kretprobe"; break;
case ProbeType::uprobe: return "uprobe"; break;
case ProbeType::uretprobe: return "uretprobe"; break;
case ProbeType::usdt: return "usdt"; break;
case ProbeType::tracepoint: return "tracepoint"; break;
case ProbeType::profile: return "profile"; break;
case ProbeType::interval: return "interval"; break;
case ProbeType::software: return "software"; break;
case ProbeType::hardware: return "hardware"; break;
default:
std::cerr << "probe type not found" << std::endl;
abort();
}
}
uint64_t asyncactionint(AsyncAction a)
{
return (uint64_t)a;
......
......@@ -99,6 +99,7 @@ const std::vector<ProbeItem> PROBE_LIST =
std::string typestr(Type t);
ProbeType probetype(const std::string &type);
std::string probetypeName(const std::string &type);
std::string probetypeName(ProbeType t);
class Probe
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment