iovisor / iovisor/bcc

funccount: "cannot attach kprobe" warning instead of failing?

Open
#2,059 18 comments 2 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
5d 13h
Merged PRs (30d)
3

Description

I just got this error:
```
$ ./funccount.py 'serio*'
cannot attach kprobe, Invalid argument
Failed to attach BPF program trace_count_38 to kprobe serio_raw_drv_exit
```
It looks like serio_raw_drv_exit is a function defined in the __exit section (module cleanup function), therefore attaching a kprobe fails (EINVAL).

Ideally, it'd be nice to blacklist all functions defined in the __exit section (somehow...), but more in general I was wondering if it'd be better to simply report a warning when a single kprobe can't be attached with funccount and keep going, instead of failing.

In practice, something like this:
```
diff --git a/tools/funccount.py b/tools/funccount.py
index 69dd01c8cada..22ae31c3397b 100755
--- a/tools/funccount.py
+++ b/tools/funccount.py
@@ -88,9 +88,12 @@ class Probe(object):
def attach(self):
if self.type == b"p" and not self.library:
for index, function in self.trace_functions.items():
- self.bpf.attach_kprobe(
- event=function,
- fn_name="trace_count_%d" % index)
+ try:
+ self.bpf.attach_kprobe(
+ event=function,
+ fn_name="trace_count_%d" % index)
+ except Exception as e:
+ print("warning: " + str(e))
elif self.type == b"p" and self.library:
for index, function in self.trace_functions.items():
self.bpf.attach_uprobe(
```

What do you think?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in tools/funccount.py at Probe.attach and inspect how trace_functions are attached through bpf.attach_kprobe. Reproduce the serio* case, then determine how a failed individual attachment should be reported while allowing other functions to continue. Done means the command no longer aborts for one invalid kprobe and its warning behavior is covered by the relevant existing tests, if available.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, python
Domain
cli, operating-systems, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.