How can gdb on a remote host read source files from the host machine?

504 Views Asked by At

I would like to debug a C++ program on a remote embedded device. I have gdb on the remote machine, as well as an adb connection. I can obviously copy there my source files. The problem is that the source path that is stored in the .debug_info section of the compiled binary refer to the host machine paths, which differ from the location the files are stored on the remote machine, and I cannot change the filesystem so that the paths match. For example, here is the .debug_info section

  Compilation Unit @ offset 0x0:
   Length:        0x33aea (32-bit)
   Version:       4
   Abbrev Offset: 0x0
   Pointer Size:  4
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <c>   DW_AT_producer    : (indirect string, offset: 0x1ec94): GNU C++ 4.9.3 -march=armv7-a -mfloat-abi=softfp -mfpu=neon -mtls-dialect=gnu -g -O2 -std=gnu++1y -fexpensive-optimizations -frename-registers -fomit-frame-pointer -ftree-vectorize -finline-functions -finline-limit=64 -fPIC
    <10>   DW_AT_language    : 4        (C++)
    <11>   DW_AT_name        : (indirect string, offset: 0x23eae): /home/david/main.cpp
    <15>   DW_AT_comp_dir    : (indirect string, offset: 0x321ad): /home/david/cmake-build-debug
    <19>   DW_AT_ranges      : 0x1f68
    <1d>   DW_AT_low_pc      : 0x0
    <21>   DW_AT_stmt_list   : 0x0

Here, /home/david/main.cpp is the location of the source file on the host machine. The same file on the remote device will have a different path.

I discovered that I can change the DW_AT_comp_dir using -fdebug-prefix-map, or using the directory command on gdb, but this does not solve the problem because the DW_AT_name is an absolute path and not a relative one. The reason why DW_AT_name is absolute is that the project is compiled using cmake, which uses absolute paths, and I could not find a way to make it use relative paths.

How do you suggest I solve this? My end goal is obviously to be able to see the source code from gdb on the remote machine

0

There are 0 best solutions below