Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uprobe DWARF location attachment does not work with uprobe_multi #3173

Open
viktormalik opened this issue May 16, 2024 · 5 comments
Open

uprobe DWARF location attachment does not work with uprobe_multi #3173

viktormalik opened this issue May 16, 2024 · 5 comments
Labels
bug Something isn't working userland Issues or PRs related to tracing userland applications and higher level languages

Comments

@viktormalik
Copy link
Contributor

#3095 introduced parsing of DWARF for a binary and attaching uprobes after the function prologue. This is currently not used in combination with uprobe_multi, compare:

# bpftrace  -e 'uprobe:tests/testprogs/uprobe_loop:uprobeFunction1 {  printf("%s\n", ustack); exit(); }' -c tests/testprogs/uprobe_loop
Attaching 1 probe...

        uprobeFunction1+13
        spin+37
        main+25
        __libc_start_call_main+122
        __libc_start_main_alias_1+139
        _start+37

# bpftrace  -e 'uprobe:tests/testprogs/uprobe_loop:uprobeFunction* {  printf("%s\n", ustack); exit(); }' -c tests/testprogs/uprobe_loop
Attaching 1 probe...

        uprobeFunction1+0
        main+25
        __libc_start_call_main+122
        __libc_start_main_alias_1+139
        _start+37

In the second stack, uprobe is not attached after the prologue.

Since uprobe_multi link actually accepts offsets rather that function names, it should be possible to use these two mechanisms together.

cc @ttreyer

@viktormalik viktormalik added the bug Something isn't working label May 16, 2024
@ajor ajor added the userland Issues or PRs related to tracing userland applications and higher level languages label May 16, 2024
@ttreyer
Copy link
Contributor

ttreyer commented May 16, 2024

Since uprobe_multi link actually accepts offsets rather that function names, it should be possible to use these two mechanisms together.

Just to understand clearly, I could pass something like "uprobeFunction1+1234" inside the probe.funcs vector and the Kernel will set the probe at the specified offset? Or does it accept stringified addresses too?

@ajor
Copy link
Member

ajor commented May 16, 2024

It's bpftrace that does the symbol resolution already in resolve_offset_uprobe_multi.

Then we just pass the raw offsets to the kernel here:

opts.uprobe_multi.offsets = offsets.data();

@viktormalik
Copy link
Contributor Author

It's bpftrace that does the symbol resolution already in resolve_offset_uprobe_multi.

Then we just pass the raw offsets to the kernel here:

opts.uprobe_multi.offsets = offsets.data();

Exactly. So, we could support storing function+offset in probe.funcs and then just add offset to the raw ELF offset passed to opts.uprobe_multi.offsets.

@ttreyer
Copy link
Contributor

ttreyer commented May 17, 2024

Is there something I need to enable in the Kernel?
I'm running Linux 6.8.9-300.fc40.aarch64, but bpftrace --info shows:

Probe types
  kprobe: yes
  tracepoint: yes
  perf_event: yes
  kfunc: yes
  kprobe_multi: no
  uprobe_multi: no
  raw_tp_special: yes
  iter: yes

@ajor
Copy link
Member

ajor commented May 20, 2024

I don't think there are any kernel settings to configure. Have you got a recent version of libbpf? Looks like it'll need 1.3 or newer: https://github.com/libbpf/libbpf/releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working userland Issues or PRs related to tracing userland applications and higher level languages
Projects
None yet
Development

No branches or pull requests

3 participants