首页 > 解决方案 > 强制 gdb 使用提供的线程库

问题描述

我有一个嵌入式 ARM 应用程序,它与所有剥离的 so 库捆绑在一起,包括 libpthread.so。有时应用程序会卡在代码的某些部分,我希望能够使用 gdb 附加到它并查看发生了什么。问题是 gdb 拒绝加载所需的线程支持库,并显示以下消息:

Trying host libthread_db library: /home/me/debug_libs/libthread_db.so.1.
td_ta_new failed: application not linked with libthread
thread_db_load_search returning 0
warning: Unable to find libthread_db matching inferior's thread 
library, thread debugging will not be available.

因此,我无法调试应用程序,例如,我看不到所有线程的当前调用堆栈。经过一番调查,我怀疑td_ta_new失败application not linked with libthread是由 libpthread 的剥离版本引起的,它缺少nptl_version符号。有没有办法绕过错误?gdb 为 ARM 编译并在设备本身上运行。我有未剥离的库版本,但应用程序已经与剥离的库一起运行。

标签: gdb

解决方案


有没有办法绕过错误?

想到的几个方法:

  1. 使用未剥离add-symbol-file的覆盖libpthread.so.0剥离:

    (gdb) info shared libpthread.so # shows the path and memory address where stripped libpthread.so.0 is loaded (gdb) add-symbol-file /path/to/unstripped/libpthread.so.0 $address # should override with new symbols, and attempt to re-load libthread_db.so.1

  2. 运行gdb -ex 'set sysroot /path/to/unstripped' ...where/path/to/unstripped是镜像安装树的路径(也就是说,如果你使用的是/lib/libpthread.so.0,应该有/path/to/unstripped/lib/libpthread.so.0.

    我没有对此进行测试,但我相信它应该可以工作。

  3. 您可以在 GDB 中注释掉版本检查并重建它。


推荐阅读