Skip to content

Commit

Permalink
bcc/python: fix attach kprobe/kretprobe using regex
Browse files Browse the repository at this point in the history
Attach kprobe/kretprobe using regular expression should fail
explicitly if no functions are traceable. Currently we catch
all exceptions and if no functions are available, program
continue with no BPF programs attached. In this commit, change
this behavior to explicitly report error to user.

Signed-off-by: Hengqi Chen <[email protected]>
  • Loading branch information
chenhengqi authored and yonghong-song committed Jun 17, 2021
1 parent a25ddf7 commit 0567e71
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/python/bcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,17 @@ def attach_kprobe(self, event=b"", event_off=0, fn_name=b"", event_re=b""):
if event_re:
matches = BPF.get_kprobe_functions(event_re)
self._check_probe_quota(len(matches))
failed = 0
probes = []
for line in matches:
try:
self.attach_kprobe(event=line, fn_name=fn_name)
except:
pass
failed += 1
probes.append(line)
if failed == len(matches):
raise Exception("Failed to attach BPF program %s to kprobe %s" %
(fn_name, '/'.join(probes)))
return

self._check_probe_quota(1)
Expand All @@ -806,12 +812,19 @@ def attach_kretprobe(self, event=b"", fn_name=b"", event_re=b"", maxactive=0):

# allow the caller to glob multiple functions together
if event_re:
for line in BPF.get_kprobe_functions(event_re):
matches = BPF.get_kprobe_functions(event_re)
failed = 0
probes = []
for line in matches:
try:
self.attach_kretprobe(event=line, fn_name=fn_name,
maxactive=maxactive)
except:
pass
failed += 1
probes.append(line)
if failed == len(matches):
raise Exception("Failed to attach BPF program %s to kretprobe %s" %
(fn_name, '/'.join(probes)))
return

self._check_probe_quota(1)
Expand Down

0 comments on commit 0567e71

Please sign in to comment.