gdb - 强制 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 编译并在设备本身上运行。我有未剥离的库版本,但应用程序已经与剥离的库一起运行。
解决方案
有没有办法绕过错误?
想到的几个方法:
使用未剥离
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' ...
where/path/to/unstripped
是镜像安装树的路径(也就是说,如果你使用的是/lib/libpthread.so.0
,应该有/path/to/unstripped/lib/libpthread.so.0
.我没有对此进行测试,但我相信它应该可以工作。
您可以在 GDB 中注释掉版本检查并重建它。
推荐阅读
- scala - 2 个 Future 返回的测试值相等
- vb.net - vb.net System.FormatException:'Base-64 字符数组或字符串的长度无效
- python - Python后门复制功能
- vue.js - 多个垂直步进器组件 - Vuetify 问题
- python - 不使用循环打印数字范围?
- django - Django CSRF 令牌:设置和验证不同的服务器?
- python - 带有csv输入的Python类__init__?
- javascript - 如何使用 D3.js 绘制 SVG?
- c++ - 解决 Point() 和 Vector() 之间的类耦合
- c# - 什么是访问 ASP.NET 模型中的全局变量的好方法?