简体   繁体   中英

Remote GDB debugging - can't acces source file but no errors printed

I'm trying to remotely debug an application using GDB command line. Path in which gdb is run on the PC is the build path of the application. It contains the amixer executable and amixer.c .

The code is compiled with -g -O2 parameters.

The debug symbols seem to be present:

$ 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

Steps on remote device (stripped binary):

gdbserver 192.16.6.21:12345 amixer

Steps on PC (binary here not stripped):

$ 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... 

Assumptions I've made:

  • break main doesn't throw an error so the executable debug symbols are available. I would expect to see the source file mentioned here already. Like in example : Breakpoint 1 at 0x62f4: file builtin.c, line 879.
  • there is .debug* in the output of readelf -WS amixer so the debug symbols are present
  • list main doesn't list the source of the main function. Something isn't right

  • show directories list $cdir and $cwd I'm guessing at least on of them is the directory from which I've started gdb amixer and that is the build directory with both executables and sources

I'm obviously doing something wrong so am looking for a review of the assumptions and debugging tips.

break main doesn't throw an error so the executable debug symbols are available.

You are mistaken: the fact that break main does not show any errors does not imply that debug symbols are available. And the rest of your output is consistent with debug symbols not being available.

So your first step should be to confirm that debug symbols are in fact present. If readelf -WS amixer does not show any .debug_* or .zdebug_* sections, that would be a proof that no debug info is present. If so, re-check your build command lines for presence of -g flag on compile lines, and absence of -Wl,-s or similar flag on the link line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM