mirror-linux/scripts/gdb/linux
Ilya Leoshkevich 581ee79a25 scripts/gdb/symbols: make BPF debug info available to GDB
One can debug BPF programs with QEMU gdbstub by setting a breakpoint on
bpf_prog_kallsyms_add(), waiting for a hit with a matching aux.name, and
then setting a breakpoint on bpf_func.  This is tedious, error-prone, and
also lacks line numbers.

Automate this in a way similar to the existing support for modules in
lx-symbols.

Enumerate and monitor changes to both BPF kallsyms and JITed progs.  For
each ksym, generate and compile a synthetic .s file containing the name,
code, and size.  In addition, if this ksym is also a prog, and not a
trampoline, add line number information.

Ensure that this is a no-op if the kernel is built without BPF support or
if "as" is missing.  In theory the "as" dependency may be dropped by
generating the synthetic .o file manually, but this is too much complexity
for too little benefit.

Now one can debug BPF progs out of the box like this:

    (gdb) lx-symbols -bpf
    (gdb) b bpf_prog_4e612a6a881a086b_arena_list_add
    Breakpoint 2 (bpf_prog_4e612a6a881a086b_arena_list_add) pending.

    # ./test_progs -t arena_list

    Thread 4 hit Breakpoint 2, bpf_prog_4e612a6a881a086b_arena_list_add ()
        at linux/tools/testing/selftests/bpf/progs/arena_list.c:51
    51              list_head = &global_head;
    (gdb) n
    bpf_prog_4e612a6a881a086b_arena_list_add () at linux/tools/testing/selftests/bpf/progs/arena_list.c:53
    53              for (i = zero; i < cnt && can_loop; i++) {

This also works for subprogs.

Link: https://lkml.kernel.org/r/20251106124600.86736-3-iii@linux.ibm.com
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Daniel Borkman <daniel@iogearbox.net>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Kieran Bingham <kbingham@kernel.org>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2025-11-20 14:03:42 -08:00
..
.gitignore
Makefile kbuild: scripts/gdb: bring the "abspath" back 2024-06-27 04:20:32 +09:00
__init__.py
bpf.py scripts/gdb/symbols: make BPF debug info available to GDB 2025-11-20 14:03:42 -08:00
clk.py scripts/gdb: bail early if there are no clocks 2023-04-08 13:45:38 -07:00
config.py scripts/gdb: change kernel config dumping method 2022-06-11 18:31:53 +09:00
constants.py.in scripts/gdb/symbols: make BPF debug info available to GDB 2025-11-20 14:03:42 -08:00
cpus.py scripts/gdb: update documentation for lx_per_cpu 2025-05-11 17:54:13 -07:00
device.py scripts/gdb: fix lx-device-list-bus and lx-device-list-class 2023-12-06 16:12:49 -08:00
dmesg.py scripts/gdb: fix 'lx-dmesg' on 32 bits arch 2022-07-21 15:32:52 +02:00
genpd.py scripts/gdb: bail early if there are no generic PD 2023-04-08 13:45:38 -07:00
interrupts.py scripts/gdb: de-reference per-CPU MCE interrupts 2025-07-09 21:07:53 -07:00
kasan.py scripts/gdb: add 'lx-kasan_mem_to_shadow' command 2024-09-01 20:43:29 -07:00
lists.py scripts/gdb: fix list_for_each 2021-02-26 09:41:05 -08:00
mapletree.py scripts/gdb: fix interrupts.py after maple tree conversion 2025-07-09 21:07:53 -07:00
mm.py scripts/gdb: change VA_BITS_MIN when we use 16K page 2024-06-28 19:36:29 -07:00
modules.py gdb: lx-symbols: do not error out on monolithic build 2024-11-14 22:51:14 -08:00
page_owner.py scripts/gdb: remove exception handling and refine print format 2023-12-10 17:21:49 -08:00
pgtable.py x86/mm/64: Always use dynamic memory layout 2025-05-17 10:33:44 +02:00
proc.py scripts/gdb: fix lx-mounts command error 2024-09-01 20:43:28 -07:00
radixtree.py scripts/gdb/radix-tree: add lx-radix-tree-command 2025-11-20 14:03:42 -08:00
rbtree.py scripts/gdb: add iteration function for rbtree 2024-09-01 20:43:28 -07:00
slab.py scripts/gdb: remove exception handling and refine print format 2023-12-10 17:21:49 -08:00
stackdepot.py scripts/gdb: add 'lx-stack_depot_lookup' command. 2024-09-01 20:43:28 -07:00
symbols.py scripts/gdb/symbols: make BPF debug info available to GDB 2025-11-20 14:03:42 -08:00
tasks.py scripts/gdb: make get_thread_info accept pointers 2024-05-08 08:41:28 -07:00
timerlist.py hrtimer: Remove hrtimer_clock_base:: Get_time 2025-09-09 12:27:18 +02:00
utils.py scripts/gdb/symbols: factor out pagination_off() 2025-05-21 10:48:24 -07:00
vfs.py scripts: gdb: vfs: support external dentry names 2025-07-09 21:07:54 -07:00
vmalloc.py scripts/gdb/vmalloc: fix vmallocinfo error 2024-02-21 16:00:02 -08:00
xarray.py scripts/gdb: fix interrupts.py after maple tree conversion 2025-07-09 21:07:53 -07:00