远程gdb的时候,打印不出符号:
(gdb) target remote 192.168.3.162:1234
Remote debugging using 192.168.3.162:1234
Reading /tmp/test.bin from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /tmp/test.bin from remote target...
Reading symbols from target:/tmp/test.bin...done.
Reading /lib/ld-musl-aarch64.so.1 from remote target...
Reading /lib/ld-musl-aarch64.so.1 from remote target...
Reading symbols from target:/lib/ld-musl-aarch64.so.1...(no debugging symbols found)...done.
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0x0000007ff7fd1520 in ?? ()
(gdb) bt
#0 0x0000007ff7fc8da8 in ?? ()
#1 0x0000000000000001 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
原因是 可执行文件和链接库没有符号。按照remote device的rootfs结构体,组织一个本地sysroot。
注意可执行文件和ld库等lib库都要使用带符号的debug版本。而且sysroot的bin和library要全,否则也不使用sysroot。
(gdb) set sysroot /work/debug/
warning: .dynamic section for "/work/debug/lib/ld-musl-aarch64.so.1" is not at the expected address (wrong library or version mismatch?)
Reading symbols from /work/debug/lib/ld-musl-aarch64.so.1...done.
Reading symbols from /work/debug/lib/ld-musl-aarch64.so.1...done.
(gdb) bt
#0 0x0000007ff7fd1520 in _dlstart () from /work/debug/lib/ld-musl-aarch64.so.1
#1 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
__syscall_cp_asm () at src/thread/aarch64/syscall_cp.s:28
28 svc 0
(gdb) bt
#0 __syscall_cp_asm () at src/thread/aarch64/syscall_cp.s:28
#1 0x0000007ff7fc98bc in __syscall_cp_c (nr=101, u=<optimized out>, v=<optimized out>, w=<optimized out>, x=<optimized out>, y=<optimized out>,
z=<optimized out>) at src/thread/pthread_cancel.c:33
#2 0x0000007ff7fce608 in __clock_nanosleep (clk=clk@entry=0, flags=flags@entry=0, req=req@entry=0x7ffffffd20, rem=rem@entry=0x7ffffffd20)
at src/time/clock_nanosleep.c:33
#3 0x0000007ff7fceb08 in nanosleep (req=req@entry=0x7ffffffd20, rem=rem@entry=0x7ffffffd20) at src/time/nanosleep.c:6
#4 0x0000007ff7fd11a0 in sleep (seconds=<optimized out>) at src/unistd/sleep.c:7
#5 0x0000000000400590 in b () at test.c:8
#6 0x00000000004005a0 in a () at test.c:14
#7 0x00000000004005bc in main (argc=1, argv=0x7ffffffda8) at test.c:19
参考
https://www.fayewilliams.com/2013/01/31/gdb-unable-to-find-dynamic-linker-breakpoint-function/