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