diff --git a/CHANGELOG.md b/CHANGELOG.md index 8816d6d35b29..1817b23fd026 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/ast/passes/semantic_analyser.cpp b/src/ast/passes/semantic_analyser.cpp index b5da38ed0d3a..b2ff83862f63 100644 --- a/src/ast/passes/semantic_analyser.cpp +++ b/src/ast/passes/semantic_analyser.cpp @@ -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()) { diff --git a/src/ast/passes/semantic_analyser.h b/src/ast/passes/semantic_analyser.h index f4cc25e87550..b4f24902182f 100644 --- a/src/ast/passes/semantic_analyser.h +++ b/src/ast/passes/semantic_analyser.h @@ -148,7 +148,6 @@ class SemanticAnalyser : public Visitor { bool has_end_probe_ = false; bool has_child_ = false; bool has_pos_param_ = false; - std::optional scope_with_for_loop_ = std::nullopt; }; Pass CreateSemanticPass(); diff --git a/tests/runtime/for b/tests/runtime/for index df9524a91502..85426db50fae 100644 --- a/tests/runtime/for +++ b/tests/runtime/for @@ -40,7 +40,6 @@ 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) @@ -48,7 +47,6 @@ 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(); } diff --git a/tests/semantic_analyser.cpp b/tests/semantic_analyser.cpp index 8d7cdeaaf7ac..d467b303518b 100644 --- a/tests/semantic_analyser.cpp +++ b/tests/semantic_analyser.cpp @@ -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"(