如何为 GCC 8.1.0 添加调试符号?

How to add Debug symbols for GCC 8.1.0?

我已将我使用的 GCC 版本从 4.2.1 更新到 8.1.0。 (这是唯一我改变的东西)

问题是在我这样做之后,调试符号消失了。

我 运行 GDB 只有“-g”选项。

使用 gcc v8.1.0,当 运行 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 ()

v4.2.1 是这样的:

(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

如何让 gcc8.1.0 的 dbg 符号像 gcc4.2.1?

gcc 在4.2.1 和8.1.0 版本之间有很多变化。 gcc 4.8 中发生的变化之一是它开始默认发出 DWARF4 调试信息。以前是 DWARF2。您的 gdb 可能无法理解 DWARF4 格式。您可以做的一件事是尝试使用 -gdwarf-2 gcc 选项发出 DWARF2。见 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