gdb:线程调试不可用?

时间:2016-09-15 07:20:58

标签: c debugging gdb

我正在使用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) 

2 个答案:

答案 0 :(得分:0)

在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目的的更多详细信息,以及为什么它对于用户和混合线程库是强制性的(或等效的),您可以看看我几年前写的这篇文章:

答案 1 :(得分:0)

此错误消息的常见原因:

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