From b7fd0900b18c4b640926e0bb830464565a527ca1 Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Mon, 5 Apr 2021 14:35:08 -0700 Subject: [PATCH] Fix single arg wildcard listings The docs say we can do stuff like # bpftrace -l "*sleep*" so we should probably implement it. We probably regressed on this during the probe matching refactoring. --- src/ast/attachpoint_parser.cpp | 10 +++++++--- tests/runtime/regression | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ast/attachpoint_parser.cpp b/src/ast/attachpoint_parser.cpp index cfac09bc..b62549d7 100644 --- a/src/ast/attachpoint_parser.cpp +++ b/src/ast/attachpoint_parser.cpp @@ -77,6 +77,9 @@ AttachPointParser::State AttachPointParser::parse_attachpoint(AttachPoint &ap) std::set probe_types; if (has_wildcard(parts_.front())) { + // Single argument listing looks at all relevant probe types + std::string probetype_query = (parts_.size() == 1) ? "*" : parts_.front(); + // Probe type expansion // If PID is specified or the second part of the attach point is a path // (contains '/'), use userspace probe types. @@ -85,12 +88,12 @@ AttachPointParser::State AttachPointParser::parse_attachpoint(AttachPoint &ap) (parts_.size() >= 2 && parts_[1].find('/') != std::string::npos)) { probe_types = bpftrace_.probe_matcher_->expand_probetype_userspace( - parts_.front()); + probetype_query); } else { probe_types = bpftrace_.probe_matcher_->expand_probetype_kernel( - parts_.front()); + probetype_query); } } else @@ -111,7 +114,8 @@ AttachPointParser::State AttachPointParser::parse_attachpoint(AttachPoint &ap) for (const auto &probe_type : probe_types) { std::string raw_input = ap.raw_input; - erase_prefix(raw_input); + if (parts_.size() > 1) + erase_prefix(raw_input); raw_input = probe_type + ":" + raw_input; // New attach points have ignore_invalid set to true - probe types for // which raw_input has invalid number of parts will be ignored (instead diff --git a/tests/runtime/regression b/tests/runtime/regression index 7f40ffdb..b7fa4653 100644 --- a/tests/runtime/regression +++ b/tests/runtime/regression @@ -33,3 +33,9 @@ NAME c_array_indexing RUN bpftrace -v -e 'struct Foo { int a; uint8_t b[10]; } uprobe:testprogs/uprobe_test:function2 { $foo = (struct Foo *)arg0; printf("%c %c %c %c %c\n", $foo->b[0], $foo->b[1], $foo->b[2], $foo->b[3], $foo->b[4]) }' -c ./testprogs/uprobe_test EXPECT h e l l o TIMEOUT 5 + +# https://github.com/iovisor/bpftrace/issues/1773 +NAME single_arg_wildcard_listing +RUN bpftrace -l "*do_nanosleep*" +EXPECT kprobe:do_nanosleep +TIMEOUT 1 -- 2.34.1