【问题标题】:Remote GDB debugging - can't acces source file but no errors printed远程 GDB 调试 - 无法访问源文件但没有打印错误
【发布时间】:2015-10-07 02:59:30
【问题描述】:

我正在尝试使用 GDB 命令行远程调试应用程序。 gdb 在 PC 上运行的路径是应用程序的构建路径。它包含amixer 可执行文件和amixer.c

代码使用-g -O2参数编译。

调试符号似乎存在:

$ readelf -WS amixer
There are 38 section headers, starting at offset 0x1d24c:
...
  [27] .debug_aranges    PROGBITS        00000000 00a758 000140 00      0   0  8
  [28] .debug_info       PROGBITS        00000000 00a898 008c59 00      0   0  1
  [29] .debug_abbrev     PROGBITS        00000000 0134f1 00085a 00      0   0  1
  [30] .debug_line       PROGBITS        00000000 013d4b 001a8c 00      0   0  1
  [31] .debug_frame      PROGBITS        00000000 0157d8 000494 00      0   0  4
  [32] .debug_str        PROGBITS        00000000 015c6c 001f75 01  MS  0   0  1
  [33] .debug_loc        PROGBITS        00000000 017be1 004dff 00      0   0  1
  [34] .debug_ranges     PROGBITS        00000000 01c9e0 000700 00      0   0  1

远程设备上的步骤(剥离的二进制文件):

gdbserver 192.16.6.21:12345 amixer

PC 上的步骤(此处未删除二进制):

$ gdb amixer
(gdb) set sysroot /correct/path/to/remote/device/sysroot
(gdb) target remote 192.16.6.12:12345
(gdb) break main 
Breakpoint 1 at 0x11f58
(gdb) list main   
(gdb) show directories 
Source directories searched: $cdir:$cwd
(gdb) continues
...program executes on remote device... 

我所做的假设:

  • break main 不会抛出错误,因此可执行调试符号可用。我希望已经看到这里提到的源文件。就像在exampleBreakpoint 1 at 0x62f4: file builtin.c, line 879.
  • readelf -WS amixer 的输出中有 .debug*,因此存在调试符号
  • list main 没有列出 main 函数的来源。有点不对劲

  • show directories list $cdir$cwd 我猜至少其中一个是我开始 gdb amixer 的目录,这是包含可执行文件和源代码的构建目录

我显然做错了什么,所以我正在寻找对假设和调试技巧的审查。

【问题讨论】:

  • addr2line -a 0x11f58 -e /correct/path/to/amixer-with-debug-info 是否显示文件名和行号?

标签: debugging gdb embedded-linux remote-debugging gdbserver


【解决方案1】:

break main 不会引发错误,因此可执行调试符号可用。

你错了:break main 没有显示任何错误这一事实暗示调试符号可用。并且您的输出的其余部分与调试符号 not 可用是一致的。

因此,您的第一步应该是确认调试符号确实存在。如果readelf -WS amixer 没有显示任何.debug_*.zdebug_* 部分,则证明不存在调试信息。如果是这样,请重新检查您的构建命令行在编译行上是否存在-g 标志,以及在链接行上是否存在-Wl,-s 或类似标志。

【讨论】:

  • Breakpoint 1 at 0x62f4 中的0x62f4 代表什么?我相信这是main 的内存位置,因为它是可找到的,这意味着调试符号可用。
  • @Alan 正如我所说,您的二进制文件符号,但没有调试符号。这些不是一回事(另请参阅 Mark Plotnik 的评论)。
  • 用新的见解更新了问题,调试符号似乎确实可用。我正在探索优化 02 标志可能导致的问题。如果优化会导致调试停止工作,我不确定为什么它会默认同时使用 -02-g
猜你喜欢
  • 2010-10-16
  • 2013-09-22
  • 2015-04-19
  • 2017-02-03
  • 2014-08-31
  • 1970-01-01
  • 2020-05-10
  • 1970-01-01
  • 2014-07-19
相关资源
最近更新 更多