Blame SOURCES/bpftrace-0.12.1-Fix-single-arg-wildcard-listings.patch

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