【问题标题】:Remote Debugging multi-threaded C program with GDB使用 GDB 远程调试多线程 C 程序
【发布时间】:2011-09-12 12:41:31
【问题描述】:

我正在使用 Eclipse 为 ARM 处理器开发和远程调试一些软件。不幸的是,我正在编写的软件是多线程的,我无法调试它。如果我在线程代码中放置一个断点,我会收到以下消息:

Child terminated with signal = 5

Child terminated with signal = 0x5

GDBserver exiting

在做了相当多的谷歌搜索之后,我找到了一个建议使用这个的“解决方案”:

strip --strip-debug libpthread.so.0

不幸的是,我仍然收到终止错误。

非常感谢您帮助解决这个问题!

谢谢!

【问题讨论】:

  • 我不确定这是否与多线程有关,因为通常使用 gdb 调试它通常可以正常工作。你是怎么调用strip命令的。 cc1.exe 和 gcc.exe 前缀很奇怪。我会在 bash 中作为普通命令调用。
  • @dmeister 这是我找到“解决方案”http://sourceware.org/bugzilla/show_bug.cgi?id=8963 的站点我调用它的方式是在 eclipse 中的 C 构建器的其他标志部分中添加,导致调用为: arm-none-linux-gnueabi-gcc.exe -O0 -g3 -Wall -c -fmessage-length=0 strip --strip-debug libpthread.so.0
  • 您可以将其作为单独的调用尝试,而不是将其添加到构建器中。请注意,这可能需要 root 权限,因为它会更改系统文件 (lbpthread.so.0)。
  • @dmeister 我将其添加为 strip --strip-debug libpthread.so.0 作为构建后调用,但我一直收到与 Child terminated with signal = 5 相同的错误消息
  • 我也尝试将它添加到 .gdbinit 中,但也没有用。我确实发现了这个额外的错误:gdb: error initializing thread_db library

标签: c multithreading eclipse gdb gdbserver


【解决方案1】:

首先,这个(和后续的)错误:

cc1.exe: error: unrecognized command line option "-fstrip-debug"

是由在 GCC 命令行中添加 strip --strip-debug 等引起的。这是显然虚假的事情,而不是你的谷歌搜索所建议的。 (您可能需要清理您的问题以删除对这些错误的引用;它们与您的问题无关。)

做过(或应该有)建议的是使用strip --strip-debug libpthread.so.0而不是使用strip libpthread.so.0

这是因为 GDB 不能使用线程如果你的 libpthread.so.0 被完全剥离。

可以去掉调试符号(strip --strip-debug libpthread.so.0 所做的),但去掉所有符号(strip libpthread.so.0 所做的)是个坏主意。

由于您(显然)不是自己在构建 libpthread.so.0,因此您也不需要剥离它。

应该但是确认您的工具链的提供者没有搞砸它。以下命令不应报告no symbols,实际上应打印匹配的nptl_version(作为定义的符号):

nm /path/to/target/libpthread.so.0 | grep nptl_version

假设到目前为止一切正常,我们现在可以诊断您的问题,除了...您没有提供足够的信息 ;-( 特别是,当您运行 GDB 时,它应该打印类似 using /path/to/libthread_db.so.0 的内容。您可能必须在 Eclipse 中寻找 GDB 控制台,或者您可能想从命令行运行 GDB,这样您就可以准确地看到它打印的内容。

libthread_db.so.0(用于主机)的版本与lipthread.so.0(用于目标)的版本相匹配至关重要。它们都应该由您的工具链供应商提供。

您的问题很可能是 GDB 根本找不到 libthread_db.so.0,或者它找到了错误的。

【讨论】:

  • 感谢您提供此信息,在我的目标上运行命令 nm /path/to/target/libpthread.so.0 | grep nptl_version 时,我得到以下信息:00011468 r nptl_version 我尝试从命令行运行 gdb,但它不打印 using /path/libpthread_db_so.0 它只打印以下内容:Process /root/tempSensor created; pid = 988 Listening on port 2345 Remote debugging from host 192.168.34.37 主机打印:(gdb) target remote 192.168.34.100:2345 Remote debugging using 192.168.34.100:2345 0x00008110 in ?? () (gdb)
  • 如果我现在从 Eclipse 运行它,我会收到以下错误:gdb: error initializing thread_db library
猜你喜欢
  • 1970-01-01
  • 2011-11-29
  • 1970-01-01
  • 1970-01-01
  • 2014-08-31
  • 1970-01-01
  • 2012-01-03
  • 2020-09-21
  • 1970-01-01
相关资源
最近更新 更多