Skip to content

Commit

Permalink
Allow probe builtin for BEGIN and END probes
Browse files Browse the repository at this point in the history
The `BEGIN` and `END` probes need a bit of special treatment as wildcard
expansions isn't possible for them.

```
 bpftrace -e 'BEGIN { printf("%s\n", probe);exit(); } END{printf("%s\n", probe); }'
Attaching 2 probes...
BEGIN
END
```

This fixes #672
  • Loading branch information
fbs authored and ajor committed Jun 2, 2019
1 parent 5cce746 commit 3741efe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ast/codegen_llvm.cpp
Expand Up @@ -1305,7 +1305,12 @@ void CodegenLLVM::visit(Probe &probe)
for (auto attach_point : *probe.attach_points) {
current_attach_point_ = attach_point;

auto matches = bpftrace_.find_wildcard_matches(*attach_point);
std::set<std::string> matches;
if (attach_point->provider == "BEGIN" || attach_point->provider == "END") {
matches.insert(attach_point->provider);
} else {
matches = bpftrace_.find_wildcard_matches(*attach_point);
}

tracepoint_struct_ = "";
for (auto &match_ : matches) {
Expand Down Expand Up @@ -1333,6 +1338,8 @@ void CodegenLLVM::visit(Probe &probe)

// Set the probe identifier so that we can read arguments later
attach_point->usdt = USDTHelper::find(bpftrace_.pid_, attach_point->target, ns, func_id);
} else if (attach_point->provider == "BEGIN" || attach_point->provider == "END") {
probefull_ = attach_point->provider;
} else {
probefull_ = attach_point->name(full_func_id);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/runtime/builtin
Expand Up @@ -79,6 +79,12 @@ EXPECT SUCCESS probe kprobe:do_nanosleep
TIMEOUT 5
AFTER sleep 0.1

NAME begin probe
RUN bpftrace -v -e 'BEGIN { printf("%s", probe);exit(); } END{printf("-%s\n", probe); }'
EXPECT ^BEGIN-END$
TIMEOUT 5
AFTER sleep 0.1

NAME curtask
RUN bpftrace -v -e 'i:ms:1 { printf("SUCCESS '$test' %d\n", curtask); exit(); }'
EXPECT SUCCESS curtask -?[0-9][0-9]*
Expand Down

0 comments on commit 3741efe

Please sign in to comment.