我在让GDB加载一个特定的库作为核心文件中使用的库的替代时遇到了麻烦。
我如何使GDB列表它尝试每个库的路径?类似于set debug auto-load on
,但是用于共享库。
我在使GDB加载特定库作为核心文件中使用的库的替换时遇到了问题。
GDB将查找从core
获得的绝对路径。
因此,设置solib-search-path
无效,仅设置sysroot
或solib-absolute-prefix
有效。
另外,在加载core
之前,需要设置sysroot
或solib-absolute-prefix
。也就是说,这是有效的:
gdb -ex 'set sysroot /tmp/sysroot' -ex 'file a.out' -ex 'core core'
而这没有(sysroot
设置发生在文件和core
已经加载之后):
gdb -ex 'set sysroot /tmp/sysroot` a.out core
我如何使GDB列表它为每个库尝试的路径?
似乎没有这样的选择。特别是,set debug solib on
在这里实际上没有帮助。使用主干GDB:
gdb/gdb
GNU gdb (GDB) 14.0.50.20230115-git
...
(gdb) set debug solib on
(gdb) file /tmp/a.out
Reading symbols from /tmp/a.out...
(gdb) core /tmp/core
[New LWP 29158]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./a.out'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000401116 in main () at crash.c:3
3 return *ip;
(gdb)
您可以通过在strace
下运行GDB来确定查找共享库的位置:
strace -e open,openat -o /tmp/strace.out gdb/gdb -ex quit /tmp/a.out /tmp/core
In/tmp/strace.out
:
...
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=29289, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
openat(AT_FDCWD, "/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY|O_CLOEXEC) = 9
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY|O_CLOEXEC) = 9
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY) = 9
openat(AT_FDCWD, "/tmp/core", O_RDONLY|O_CLOEXEC) = 9
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY|O_CLOEXEC) = 10
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY) = 10
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY|O_CLOEXEC) = 11
openat(AT_FDCWD, "/usr/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 11
openat(AT_FDCWD, "/usr/lib64/libc.so.6", O_RDONLY) = 11
openat(AT_FDCWD, "/usr/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 12
openat(AT_FDCWD, "/usr/lib64/ld-linux-x86-64.so.2", O_RDONLY|O_CLOEXEC) = 12
openat(AT_FDCWD, "/usr/lib64/ld-linux-x86-64.so.2", O_RDONLY) = 12
openat(AT_FDCWD, "/usr/lib64/ld-linux-x86-64.so.2", O_RDONLY|O_CLOEXEC) = 13
...