Skip to content

Commit

Permalink
Call check_available at the begining of the analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
mmisono committed Nov 23, 2020
1 parent c199250 commit 6fcf1a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
45 changes: 13 additions & 32 deletions src/ast/semantic_analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,15 @@ void SemanticAnalyser::visit(Call &call)
}
}

for (auto &ap : *probe_->attach_points)
{
if (!check_available(call, *ap))
{
LOG(ERROR, call.loc, err_) << call.func << " can not be used with \""
<< ap->provider << "\" probes";
}
}

if (call.func == "hist") {
check_assignment(call, true, false, false);
check_nargs(call, 1);
Expand Down Expand Up @@ -766,16 +775,6 @@ void SemanticAnalyser::visit(Call &call)
}
else if (call.func == "reg") {
if (check_nargs(call, 1)) {
for (auto &attach_point : *probe_->attach_points) {
ProbeType type = probetype(attach_point->provider);
if (!check_available(call, type))
{
LOG(ERROR, call.loc, err_)
<< "The reg function cannot be used with 'tracepoint' probes";
continue;
}
}

if (check_arg(call, Type::string, 0, true)) {
auto reg_name = bpftrace_.get_string_literal(call.vargs->at(0));
int offset = arch::offset(reg_name);;
Expand Down Expand Up @@ -810,14 +809,6 @@ void SemanticAnalyser::visit(Call &call)
auto name = bpftrace_.get_string_literal(call.vargs->at(0));
for (auto &ap : *probe_->attach_points)
{
ProbeType type = probetype(ap->provider);
if (!check_available(call, type))
{
LOG(ERROR, call.loc, err_)
<< "uaddr can only be used with u(ret)probes and usdt probes";
sizes.push_back(0);
continue;
}
struct symbol sym = {};
int err = bpftrace_.resolve_uname(name, &sym, ap->target);
if (err < 0 || sym.address == 0)
Expand Down Expand Up @@ -1074,19 +1065,6 @@ void SemanticAnalyser::visit(Call &call)
LOG(ERROR, call.loc, err_)
<< "signal only accepts string literals or integers";
}

for (auto &ap : *probe_->attach_points) {
ProbeType type = probetype(ap->provider);
if (ap->provider == "BEGIN" || ap->provider == "END") {
LOG(ERROR, call.loc, err_) << call.func << " can not be used with \""
<< ap->provider << "\" probes";
}
else if (!check_available(call, type))
{
LOG(ERROR, call.loc, err_) << call.func << " can not be used with \""
<< ap->provider << "\" probes";
}
}
}
else if (call.func == "sizeof")
{
Expand Down Expand Up @@ -2818,9 +2796,10 @@ bool SemanticAnalyser::check_symbol(const Call &call, int arg_num __attribute__(
return true;
}

bool SemanticAnalyser::check_available(const Call &call, ProbeType type)
bool SemanticAnalyser::check_available(const Call &call, const AttachPoint &ap)
{
auto &func = call.func;
ProbeType type = probetype(ap.provider);

if (func == "reg")
{
Expand Down Expand Up @@ -2868,6 +2847,8 @@ bool SemanticAnalyser::check_available(const Call &call, ProbeType type)
}
else if (func == "signal")
{
if (ap.provider == "BEGIN" || ap.provider == "END")
return false;
switch (type)
{
case ProbeType::kprobe:
Expand Down
2 changes: 1 addition & 1 deletion src/ast/semantic_analyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SemanticAnalyser : public ASTVisitor
bool want_literal = false,
bool fail = true);
bool check_symbol(const Call &call, int arg_num);
bool check_available(const Call &call, ProbeType type);
bool check_available(const Call &call, const AttachPoint &ap);

void check_stack_call(Call &call, bool kernel);

Expand Down
2 changes: 1 addition & 1 deletion tests/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MockBPFtrace : public BPFtrace {
{
return -1;
}
else if (name[0] > 'A' && name[0] < 'z')
else if (name[0] >= 'A' && name[0] <= 'z')
{
sym->address = 12345;
sym->size = 4;
Expand Down

0 comments on commit 6fcf1a7

Please sign in to comment.