linux - 我需要什么来调试 pthreads?

标签 linux embedded pthreads cross-platform cross-compiling

我想在我的自定义 Linux 发行版上调试 pthreads,但我遗漏了一些东西。我的主机是 Ubuntu 12.04,我的目标是使用 crosstool-NG 交叉编译器工具集构建的 i486 自定义嵌入式 Linux,操作系统的其余部分是使用 Buildroot 构建的。

我将列出事实:

  • 我可以在我的目标上运行多线程应用程序

  • Google Breakpad当我在目标上运行多线程应用程序时,无法创建崩溃报告。当我在我的主机上运行时,具有完全相同的 Breakpad 库构建的完全相同的应用程序将会成功。

  • GDB 无法在我的目标上调试多线程应用程序。

例如

$./gdb -n -ex "thread apply all backtrace" ./a.out --pid 716

dlopen failed on 'libthread_db.so.1' - /lib/libthread_db.so.1: undefined symbol: ps_lgetfpregs
GDB will not be able to debug pthreads.
GNU gdb 6.8

我认为 ps_lgetfpregs 不是问题,因为 this .

  • 我的 crosstool build 创建了 libthread_db.so 文件,并将其放在目标上。

  • 我的 crosstool 构建为我的目标创建了 gdb,因此它应该链接到我在目标上运行的相同库。

  • 如果我在我的主机上针对我的测试应用程序运行 gdb,我会得到每个正在运行的线程的回溯。

我怀疑 Breakpad 的问题与 GDB 的问题有关,但我无法证实这一点。唯一的共同点是缺少多线程调试。

我的主机和目标之间存在一些关键差异,这使我无法在目标上调试 pthread。

有人知道这是什么吗?

编辑:

Denys Dmytriyenko来自 TI 说:

Normally, GDB is not very picky and you can mix and match different versions of gdb and gdbserver. But, unfortunately, if you need to debug multi-threaded apps, there are some dependencies for specific APIs...

For example, this is one of the messages you may see if you didn't build GDB properly for the thread support:

dlopen failed on 'libthread_db.so.1' - /lib/libthread_db.so.1: undefined symbol: ps_lgetfpregs GDB will not be able to debug pthreads.

请注意,此错误与我收到的错误相同,但他没有详细说明如何“正确”构建 GDB。

GDB FAQ说:

(Q) GDB does not see any threads besides the one in which crash occurred; or SIGTRAP kills my program when I set a breakpoint.

(A) This frequently happen on Linux, especially on embedded targets. There are two common causes:

  • you are using glibc, and you have stripped libpthread.so.0

  • mismatch between libpthread.so.0 and libthread_db.so.1

GDB itself does not know how to decode "thread control blocks" maintained by glibc and considered to be glibc private implementation detail. It uses libthread_db.so.1 (part of glibc) to help it do so. Therefore, libthread_db.so.1 and libpthread.so.0 must match in version and compilation flags. In addition, libthread_db.so.1 requires certain non-global symbols to be present in libpthread.so.0.

Solution: use strip --strip-debug libpthread.so.0 instead of strip libpthread.so.0.

我尝试了一个非剥离的 libpthread.so.0,但它没有什么不同。我将调查 pthread 和 thread_db 之间的任何不匹配。

最佳答案

这个:

dlopen failed on 'libthread_db.so.1' - /lib/libthread_db.so.1: undefined symbol: ps_lgetfpregs
GDB will not be able to debug pthreads.

表示 libthread_db.so.1 库无法在 gdb 中找到符号 ps_lgetfpregs

为什么?

因为我使用带有“Build a static native gdb”选项的 Crosstoolg-NG 构建了 gdb,这为 gcc 添加了 -static 选项。

native gdb 是使用 -rdynamic 选项构建的,这会填充 .dynsym ELF 文件中的符号表,包含所有符号,甚至是未使用的符号。 libread_db 使用此符号表从 gdb 中查找 ps_lgetfpregs

但是 -static 从 ELF 文件中剥离了 .dynsym 表。

此时有两种选择:

  1. 如果您想调试线程,请不要构建静态 native gdb。
  2. 构建静态 gdb 和静态 libthread_db(未测试)

编辑:

顺便说一下,这并不能解释为什么 Breakpad 无法在我的目标上调试多线程应用程序。

关于linux - 我需要什么来调试 pthreads?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12315670/

相关文章:

linux - Qt 4.8.4 嵌入式 Linux 处理电源按钮按键

javascript - 在没有互联网连接的嵌入式系统中使用 AngularJS

c - 仅使用停止条件时使用 "for"或 "while"循环?

c - 定义了一点,但没有名字?

c++ - 从静态构造函数代码调用时 pthread 库失败

使用 pthread 时,使用全局变量的 C++ 显示比指针慢 100%?

c - 使用填充防止虚假共享

php - 使用部署在 CentOS 服务器上的 Latchet 框架时,无法从 webapp 的 JS 建立 websocket 连接

linux - 使用 Awk 根据给定的表情符号显示特定行?

linux - 删除 wget 输出中的重复行