【发布时间】: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不会抛出错误,因此可执行调试符号可用。我希望已经看到这里提到的源文件。就像在example:Breakpoint 1 at 0x62f4: file builtin.c, line 879. -
readelf -WS amixer的输出中有.debug*,因此存在调试符号 list main没有列出 main 函数的来源。有点不对劲show directorieslist$cdir和$cwd我猜至少其中一个是我开始gdb amixer的目录,这是包含可执行文件和源代码的构建目录
我显然做错了什么,所以我正在寻找对假设和调试技巧的审查。
【问题讨论】:
-
addr2line -a 0x11f58 -e /correct/path/to/amixer-with-debug-info是否显示文件名和行号?
标签: debugging gdb embedded-linux remote-debugging gdbserver