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