I want to write a software for an ARM target system and debug it remotely. I use gcc, which builds the program correctly. Then I want to debug the program with gdb. Unfortunately I use a x86 Windows on my host system. For debugging I have the gcc linaro 7.5 mingw32 arm linux gnueabi toolchain, together with the included GDB. This version of gdb seems not support the newest version of DWARF. So I get the following error when starting the debugger:
Reading symbols from testProgram...Dwarf Error: wrong version in compilation unit header (is 5, should be 2, 3, or 4) [in
module C:\Tools\gcc-linaro-7.5.0-2019.12-i686-mingw32_arm-linux-gnueabi\bin\testProgram]
(no debugging symbols found)...done.
For building I use the following gcc command:
gcc test.c -gdwarf-4 -gstrict-dwarf -o testProgram
I have also tried to select the Dwarf versions 2 and 3. Each with and without the -gstrict-dwarf
flag. But without success.
This is my test program:
#include "stdio.h"
int main(void)
{
printf("Hello World\n");
return 0;
}
If I check the DWARF Version as in this answer I can see that there are multiple compilation units. Here only at one the DWARF vrsion changes. The others always remain at version 5:
> readelf --debug-dump=info testProgram| grep -A 2 'Compilation Unit @'
Compilation Unit @ offset 0x0:
Length: 0x20 (32-bit)
Version: 5
--
Compilation Unit @ offset 0x24:
Length: 0x4b9 (32-bit)
Version: 5
--
Compilation Unit @ offset 0x4e1:
Length: 0x39 (32-bit)
Version: 5
--
Compilation Unit @ offset 0x51e:
Length: 0x1f (32-bit)
Version: 5
--
Compilation Unit @ offset 0x541:
Length: 0xe7 (32-bit)
Version: 4 // <- only this on changes
--
Compilation Unit @ offset 0x62c:
Length: 0x1f (32-bit)
Version: 5
So I wanted to ask how to make sure that gcc uses the DWARF version you select. The flags seem to me otherwise relatively pointless, if this is used only for individual compilation units and not the entire program.