【问题标题】:gdb: thread debugging will not be available?gdb:线程调试将不可用?
【发布时间】:2016-09-15 07:20:58
【问题描述】:

我正在使用 gdb-7.11.1,并在我的嵌入式 powerpc 系统上收到此消息。更多背景知识,我使用的 libpthread 已去除所有非动态符号,包括 nptl_version,libthread_db 使用它来确保它与 libpthread 兼容。

谈到我的问题,gdb 说它无法调试线程,但它似乎可以如下所示。我只是误解了“线程调试”的含义吗? (你看到的 ?? 自然是由于 libpthread 中缺少符号表)

(gdb) break fn2
Breakpoint 1 at 0x1000052c: file test.c, line 7.
(gdb) run
Starting program: /tmp/test
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
[New LWP 21312]
[New LWP 21313]
[New LWP 21314]
[New LWP 21315]
[New LWP 21316]
[New LWP 21317]
[Switching to LWP 21315]

Thread 5 hit Breakpoint 1, fn2 () at test.c:7
7   test.c: No such file or directory.
(gdb) thread apply all bt

Thread 7 (LWP 21317):
#0  0x0fdcf030 in ?? () from /lib/libpthread.so.0
#1  0x0fdc892c in pthread_mutex_lock () from /lib/libpthread.so.0
#2  0x00000000 in ?? ()

Thread 6 (LWP 21316):
#0  0x0fdcf030 in ?? () from /lib/libpthread.so.0
#1  0x0fdc892c in pthread_mutex_lock () from /lib/libpthread.so.0
#2  0x00000000 in ?? ()

Thread 5 (LWP 21315):
#0  fn2 () at test.c:7
#1  0x0fdc6d8c in ?? () from /lib/libpthread.so.0
#2  0x0fd26074 in clone () from /lib/libc.so.6

Thread 4 (LWP 21314):
#0  0x0fdcf030 in ?? () from /lib/libpthread.so.0
#1  0x0fdc892c in pthread_mutex_lock () from /lib/libpthread.so.0
#2  0x00000000 in ?? ()

Thread 3 (LWP 21313):
#0  0x0fdcf030 in ?? () from /lib/libpthread.so.0
#1  0x0fdc892c in pthread_mutex_lock () from /lib/libpthread.so.0
#2  0x00000000 in ?? ()

Thread 2 (LWP 21312):
#0  0x0fdcefdc in ?? () from /lib/libpthread.so.0
#1  0x0fdc892c in pthread_mutex_lock () from /lib/libpthread.so.0
#2  0x00000000 in ?? ()

Thread 1 (LWP 21309):
#0  0x0fd26038 in clone () from /lib/libc.so.6
#1  0x0fdc5f2c in ?? () from /lib/libpthread.so.0
#2  0x0fde6150 in ?? () from /lib/libpthread.so.0
#3  0x0fdc6424 in pthread_create () from /lib/libpthread.so.0
#4  0x100006a4 in main () at test.c:23
(gdb) 

【问题讨论】:

  • 您是否在进行交叉调试?您很可能需要 set solib-search-pathset libthread-db-search-path 让 GDB 找到正确的共享库。
  • @tofro 不,我实际上是在板上运行 gdb。我可以看到 gdb 在 /lib/ 中找到了 libpthread 和 libthread_db,并且它们是整个 fs 中唯一的副本。

标签: c debugging gdb


【解决方案1】:

出现此错误消息的常见原因:

Unable to find libthread_db matching inferior's thread library, ...

拥有完全剥离的libpthread.so.0。不要那样做。

特别是libthread_db.so 需要nptl_version(本地)符号。您可以通过以下方式验证您的libpthread.so.0 是否有:

nm /path/to/libpthread.so.0 | grep version

应该产生类似的东西:

0000000000012cc6 r nptl_version

【讨论】:

  • 有没有办法绕过 nptl_version 检查?我有一个挂起的进程,它使用 libpthread.so 的剥离版本。在使用 gdb 附加到它之后,由于上述错误,我无法调试线程。有什么办法可以强制 gdb 跳过版本检查?如果这很重要,我有一个未剥离的 libpthread.so 版本。
  • @AlexChe 确实这是可能的(两种不同的方式)。请注意提出一个单独的问题。
【解决方案2】:

在 Linux 上(至少和其他),线程库的一个重要部分是在内核中实现的:即“内核线程”,称为 LWP(用于轻量级进程)。

GDB 不需要libthread_db 帮助来跟踪它们,因为操作系统本身可以提供有关它们的关键信息:它们的 CPU 寄存器(主要是 IP、SP、FP)。

我不确定libthread_db 在这种情况下提供了什么。我唯一能想到的就是 LWP 线程 id 映射:

* 3    Thread 0x7ffff6d19700 (LWP 21571) "erato" primes_computer_runner2 (param=0x7fffffffca50) at erato.c:46
  1    Thread 0x7ffff7fad700 (LWP 21565) "erato" 0x00007ffff7bc568d in pthread_join () from /usr/lib/libpthread.so.0

(gdb) print/x thread_handle
$1 = 0x7ffff6d19700

看,Thread 0x7ffff7fad700 映射到 LWP 21565

相比之下,如果没有libthread_db,它只会给出 LWP id(在另一次运行中):

* 3    LWP 22060 "erato" primes_computer_runner2 (param=0x7fffffffca50) at erato.c:46
  1    LWP 22058 "erato" 0x00007ffff76037b1 in clone () from /usr/lib/libc.so.6

如果您想了解有关 pthread_db 用途的更多详细信息,以及为什么它对于用户和混合线程库是强制性的(或等效的),您可以查看我几年前写的这篇文章:

【讨论】:

  • “libthread_db 在该上下文中提供了什么”——它提供了新线程创建的通知(除其他外),因此 GDB 可以附加新线程。没有它,新创建的线程可能会单独运行(至少在下一个断点之前),如果新线程崩溃,您可能会失去整个次等线程。
  • 我明白了……但它不能使用与fork 和/或exec 相同的技术吗? (我的意思是,catch forkcatch exec。)我认为它们与线程创建之间没有任何根本区别
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-12
  • 2014-08-31
  • 1970-01-01
  • 2012-01-03
  • 2011-10-07
  • 2010-12-14
  • 1970-01-01
相关资源
最近更新 更多