gccgdbdwarfgcc8

How to add Debug symbols for GCC 8.1.0?


I've updated the version of the GCC that I'm using from 4.2.1 to 8.1.0. (This is the only thing that I've changed)

The problem is that after I did it the debug symbols were gone.

I'm running GDB only with "-g" option.

With gcc v8.1.0, there are no debug symbols when running gdb:

(gdb) br test
Breakpoint 1 at 0xa5fa053
(gdb) bt
0  0x09fa2303 in test_func()
1  0x097cecc7 in test_func_2 ()
2  0x097cf314 in test_func_3 ()

with v4.2.1 was like this:

(gdb) br test_func
Breakpoint 1 at 0xaa2fc7a: file /projects/gabriela/test/test.c, line 3
(gdb) r
Breakpoint 1, test_func(unit=0, flags=0, test1=0xffff95e0, test2=0xffff9b9c) at /projects/gabriela/test/test.c, line 3
(gdb) bt
0  test_func (unit=0, flags=0, test1=0xffff95e0, test2=0xffff9b9c) at /projects/gabriela/test/test.c, line 3
1  0x099ad349 in test_func_2 (unit=0, flags=0, test1=0x0, test2=0x0) at /projects/gabriela/test/test.c:10
2  0x099ada04 in test_func_3 (unit=0, flags=0, test1=0x0) at /projects/gabriela/test/test.c:20

How can I make the dbg symbols of gcc8.1.0 to be like gcc4.2.1?


Solution

  • There were changed a lot in gcc between 4.2.1 and 8.1.0 versions. One of the changes that happened in gcc 4.8 is that it started to emit DWARF4 debug information by default. Previously it was DWARF2. Chances are your gdb can't understand DWARF4 format. One thing you can do is to try to emit DWARF2 with -gdwarf-2 gcc option. See GCC 4.8 Release notes:

    DWARF4 is now the default when generating DWARF debug information. When -g is used on a platform that uses DWARF debugging information, GCC will now default to -gdwarf-4 -fno-debug-types-section. GDB 7.5, Valgrind 3.8.0 and elfutils 0.154 debug information consumers support DWARF4 by default. Before GCC 4.8 the default version used was DWARF2. To make GCC 4.8 generate an older DWARF version use -g together with -gdwarf-2 or -gdwarf-3