Skip to content

Commit

Permalink
Enable for-loops in multiple probes
Browse files Browse the repository at this point in the history
For-loops in multiple probes are now supported without problems b/c
libbpf takes care of program relocations.

This reverts commit cdf9e9d and
re-enables a disabled runtime test for the feature.
  • Loading branch information
viktormalik authored and ajor committed Jul 5, 2024
1 parent f5792f7 commit c8b4cd2
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to
- [#3203](https://github.com/bpftrace/bpftrace/pull/3203)
- Enable avg map reads in kernel space (implicit casting)
- [#3268](https://github.com/bpftrace/bpftrace/pull/3268)
- Enable for-loops in multiple probes
- [#3285](https://github.com/bpftrace/bpftrace/pull/3285)
#### Changed
- Stream output when printing maps
- [#3264](https://github.com/bpftrace/bpftrace/pull/3264)
Expand Down
7 changes: 0 additions & 7 deletions src/ast/passes/semantic_analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2073,13 +2073,6 @@ void SemanticAnalyser::visit(For &f)
* }
*/

if (scope_with_for_loop_.has_value() && *scope_with_for_loop_ != scope_) {
LOG(ERROR, f.loc, err_)
<< "Currently, for-loops can be used only in a single probe.";
} else {
scope_with_for_loop_ = scope_;
}

// Validate decl
const auto &decl_name = f.decl->ident;
if (variable_val_[scope_].find(decl_name) != variable_val_[scope_].end()) {
Expand Down
1 change: 0 additions & 1 deletion src/ast/passes/semantic_analyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ class SemanticAnalyser : public Visitor {
bool has_end_probe_ = false;
bool has_child_ = false;
bool has_pos_param_ = false;
std::optional<ast::Scope *> scope_with_for_loop_ = std::nullopt;
};

Pass CreateSemanticPass();
Expand Down
2 changes: 0 additions & 2 deletions tests/runtime/for
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ EXPECT (64, 128)
EXPECT (65, 129)
TIMEOUT 5

# Disabled due to https://github.com/bpftrace/bpftrace/issues/3021
NAME map multiple probes
PROG BEGIN { @mapA[16] = 32; @mapA[17] = 33; @mapB[64] = 128; @mapB[65] = 129; for ($kv : @mapA) { print($kv); } exit(); } END { for ($kv : @mapB) { print($kv); } }
EXPECT (16, 32)
EXPECT (17, 33)
EXPECT (64, 128)
EXPECT (65, 129)
TIMEOUT 5
REQUIRES bash -c "exit 1"

NAME map nested vals
PROG BEGIN { @mapA[16] = 32; @mapB[64] = 128; @mapB[65] = 129; for ($kv : @mapA) { print($kv); for ($kv2 : @mapB) { print($kv2); } } exit(); }
Expand Down
14 changes: 0 additions & 14 deletions tests/semantic_analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3769,20 +3769,6 @@ kprobe:f { @map[0] = 1; for ($kv : @map) { arg0 } }
)");
}

TEST(semantic_analyser, for_loop_multiple_probes)
{
test_error(R"(
BEGIN { @map[0] = 1 }
k:f1 { for ($kv : @map) { print($kv); } }
k:f2 { for ($kv : @map) { print($kv); } }
)",
R"(
stdin:3:14-17: ERROR: Currently, for-loops can be used only in a single probe.
k:f2 { for ($kv : @map) { print($kv); } }
~~~
)");
}

TEST_F(semantic_analyser_btf, args_builtin_mixed_probes)
{
test_error("kfunc:func_1,tracepoint:sched:sched_one { args }", R"(
Expand Down

0 comments on commit c8b4cd2

Please sign in to comment.