1,调试其他机器上生成的core dump 文件,遇到无法解析的符号怎么办?
典型的是,bt查看函数调用帧栈时,显示出“??”。
(gdb) bt
#0 0x00007f4187251925 in raise () from /lib64/libc.so.6
#1 0x00007f4187253105 in abort () from /lib64/libc.so.6
#2 0x00007f4188b184b9 in ?? ()
#3 0x0000000000000000 in ?? ()
这种情况一般是由于找不到所需的.so动态库导致的,可通过info share命令查看加载的动态库信息。
(gdb) info share
From To Syms Read Shared Object Library
No /lib64/libglog.so.0
0x00007f41884085a0 0x00007f4188409cc8 Yes (*) /lib64/libuuid.so.1
0x00007f41881ef760 0x00007f41881fb0c8 Yes (*) /lib64/libpthread.so.0
0x00007f4186e05de0 0x00007f4186e06998 Yes (*) /lib64/libdl.so.2
(*): Shared library is missing debugging information.
Syms标记为No就表示没有在相应目录中找到所需的动态库,此时可通过set solib-search-path设置动态库的搜索路径(支持设置多个搜索路径,路径之间使用“:”隔开);也可通过set solib-absolute-prefix (别名 set sysroot)指定搜索前缀。具体解释如下:
set solib-absolute-prefix
path
If this variable is set, path will be used as a prefix for any absolute shared library paths; many runtime loaders store the absolute paths to the shared library in the target
program's memory. If you use solib-absolute-prefix to find shared libraries, they need to be laid out in the same way that they are on the target, with e.g. a /usr/lib hierarchy under path.
You can set the default value of solib-absolute-prefix by using the configure-time -with-sysroot option.
show solib-absolute-prefix
Display the current shared library prefix.
set solib-search-path path
If this variable is set, path is a colon-separated list of directories to search for shared libraries. solib-search-path is used after solib-absolute-prefix fails to locate the
library, or if the path to the library is relative instead of absolute. If you want to use solib-search-path instead of solib-absolute-prefix, be sure to set solib-absolute-prefix to a nonexistant directory to prevent gdb from finding your host's libraries.
show solib-search-path
Display the current shared library search path.
2,如何让gdb启动后自动执行某些命令
比如我们用GDB调试时想忽略某个信号,为避免每次调试时都手动输入命令,可以将命令写入用户主目录的.gdbinit文件。如, echo "handle SIGPIPE nostop noprint nopass" > ~/.gdbinit