libbpf / libbpf-bootstrap

Scaffolding for BPF application development with libbpf and BPF CO-RE
BSD 3-Clause "New" or "Revised" License
1.09k stars 294 forks source link

example uprobe no output #243

Closed zaiqiang-dong closed 10 months ago

zaiqiang-dong commented 10 months ago

build example/uprobe and run success. but no output when sudo cat /sys/kernel/debug/tracing/trace_pipe

root@NB:/home/zaiqdong/work/bin# ./uprobe libbpf: loading object 'uprobe_bpf' from buffer libbpf: elf: section(2) uprobe, size 64, link 0, flags 6, type=1 libbpf: sec 'uprobe': found program 'uprobe_add' at insn offset 0 (0 bytes), code size 8 insns (64 bytes) libbpf: elf: section(3) uretprobe, size 56, link 0, flags 6, type=1 libbpf: sec 'uretprobe': found program 'uretprobe_add' at insn offset 0 (0 bytes), code size 7 insns (56 bytes) libbpf: elf: section(4) uprobe//proc/self/exe:uprobed_sub, size 64, link 0, flags 6, type=1 libbpf: sec 'uprobe//proc/self/exe:uprobed_sub': found program 'uprobe_sub' at insn offset 0 (0 bytes), code size 8 insns (64 bytes) libbpf: elf: section(5) uretprobe//proc/self/exe:uprobed_sub, size 56, link 0, flags 6, type=1 libbpf: sec 'uretprobe//proc/self/exe:uprobed_sub': found program 'uretprobe_sub' at insn offset 0 (0 bytes), code size 7 insns (56 bytes) libbpf: elf: section(6) license, size 13, link 0, flags 3, type=1 libbpf: license of uprobe_bpf is Dual BSD/GPL libbpf: elf: section(7) .rodata, size 128, link 0, flags 2, type=1 libbpf: elf: section(8) .BTF, size 1599, link 0, flags 0, type=1 libbpf: elf: section(9) .BTF.ext, size 328, link 0, flags 0, type=1 libbpf: elf: section(10) .symtab, size 360, link 18, flags 0, type=2 libbpf: elf: section(11) .reluprobe, size 16, link 10, flags 0, type=9 libbpf: elf: section(12) .reluretprobe, size 16, link 10, flags 0, type=9 libbpf: elf: section(13) .reluprobe//proc/self/exe:uprobed_sub, size 16, link 10, flags 0, type=9 libbpf: elf: section(14) .reluretprobe//proc/self/exe:uprobed_sub, size 16, link 10, flags 0, type=9 libbpf: looking for externs among 15 symbols... libbpf: collected 0 externs total libbpf: map 'uprobe_b.rodata' (global data): at sec_idx 7, offset 0, flags 80. libbpf: map 0 is "uprobe_b.rodata" libbpf: sec '.reluprobe': collecting relocation for section(2) 'uprobe' libbpf: sec '.reluprobe': relo #0: insn #2 against '.rodata' libbpf: prog 'uprobe_add': found data map 0 (uprobe_b.rodata, sec 7, off 0) for insn 2 libbpf: sec '.reluretprobe': collecting relocation for section(3) 'uretprobe' libbpf: sec '.reluretprobe': relo #0: insn #1 against '.rodata' libbpf: prog 'uretprobe_add': found data map 0 (uprobe_b.rodata, sec 7, off 0) for insn 1 libbpf: sec '.reluprobe//proc/self/exe:uprobed_sub': collecting relocation for section(4) 'uprobe//proc/self/exe:uprobed_sub' libbpf: sec '.reluprobe//proc/self/exe:uprobed_sub': relo #0: insn #2 against '.rodata' libbpf: prog 'uprobe_sub': found data map 0 (uprobe_b.rodata, sec 7, off 0) for insn 2 libbpf: sec '.reluretprobe//proc/self/exe:uprobed_sub': collecting relocation for section(5) 'uretprobe//proc/self/exe:uprobed_sub' libbpf: sec '.reluretprobe//proc/self/exe:uprobed_sub': relo #0: insn #1 against '.rodata' libbpf: prog 'uretprobe_sub': found data map 0 (uprobe_b.rodata, sec 7, off 0) for insn 1 libbpf: map 'uprobe_b.rodata': created successfully, fd=4 libbpf: elf: symbol address match for 'uprobed_sub' in '/proc/self/exe': 0x8510 libbpf: elf: symbol address match for 'uprobed_sub' in '/proc/self/exe': 0x8510 Successfully started! Please run sudo cat /sys/kernel/debug/tracing/trace_pipe to see output of the BPF programs. ............................................................

anakryiko commented 10 months ago

If some other process has /sys/kernel/debug/tracing/trace_pipe already open, you won't see anything there. So try checking if anything else is reading from it.

But also it has happened that something in the kernel would just break and it will be impossible to print anything into /sys/kernel/debug/tracing/trace_pipe. Restart usually resolved the problem, so you might give it a try as well?

zaiqiang-dong commented 10 months ago

reboot system and retry, no output. run usdt/minimal/kprobe sucess and can get output info from trace_pipe, only uproge work not ok.

anakryiko commented 10 months ago

@zaiqiang-dong can you try if https://github.com/libbpf/libbpf-bootstrap/pull/244 fixes your issue? I suspect it might be due to compiler locally inlining traced functions.

zaiqiang-dong commented 10 months ago

Thanks , https://github.com/libbpf/libbpf-bootstrap/pull/244 work ok for me.