GDB总结

本文介绍了在使用gdb进行核心转储文件调试时,遇到无法解析符号的问题及解决方法。同时,提供了解决方案让gdb启动后自动执行特定命令,以提升调试效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值