如何使GDB详细描述其solib搜索过程



我在让GDB加载一个特定的库作为核心文件中使用的库的替代时遇到了麻烦。

我如何使GDB列表它尝试每个库的路径?类似于set debug auto-load on,但是用于共享库。

我在使GDB加载特定库作为核心文件中使用的库的替换时遇到了问题。

GDB将查找从core获得的绝对路径。

因此,设置solib-search-path无效,仅设置sysrootsolib-absolute-prefix有效。

另外,在加载core之前,需要设置sysrootsolib-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
...

最新更新