我有一个嵌入式ARM应用程序,它捆绑了所有被剥离的库,包括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编译的,并在设备本身上运行。我有未解压缩的库版本,但应用程序已经与剥离的库一起运行。
有没有办法绕过错误?
想到几种方式:
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
gdb -ex 'set sysroot /path/to/unstripped' ...
,其中/path/to/unstripped
是镜像已安装树的路径(也就是说,如果你使用/lib/libpthread.so.0
,应该有/path/to/unstripped/lib/libpthread.so.0
。
我没有对此进行测试,但我相信它应该可行。