GDB 不加载调试符号,尽管它们存在
GDB does not load debugging symbols although they are present
我有一个使用 gcc 编译并启用调试符号的二进制文件:
# file binary
binary: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=f5902695bdca690e84987fb377b69d16e3b47829, not stripped
使用objdump -syms binary
我也可以看到调试符号。但是,当我 运行 gdb ./binary
:
时,GDB 不会加载它们
Reading symbols from ./binary...(no debugging symbols found)...done.
(gdb) list
No symbol table is loaded. Use the "file" command.
为什么会发生这种情况,如何加载调试符号?
Why is this happening and how can I load the debugging symbols?
这很可能发生,因为实际上该库没有调试符号。
file binary
... not stripped
上面的输出不表明二进制文件有调试符号,只是它有一个符号table。这样做也是如此:objdump -syms
.
要真正查看调试符号,请执行以下操作:readelf -wi binary
(我预计您不会看到任何符号)。
如果确实存在调试符号,您应该会看到如下内容:
$ readelf -wi ./a.out
Contents of the .debug_info section:
Compilation Unit @ offset 0x0:
Length: 0x4e (32-bit)
Version: 4
Abbrev Offset: 0x0
Pointer Size: 8
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
<c> DW_AT_producer : (indirect string, offset: 0x5): GNU C11 7.3.0 -mtune=generic -march=x86-64 -g
<10> DW_AT_language : 12 (ANSI C99)
<11> DW_AT_name : t.c
<15> DW_AT_comp_dir : (indirect string, offset: 0x0): /tmp
<19> DW_AT_low_pc : 0x5fa
<21> DW_AT_high_pc : 0xb
<29> DW_AT_stmt_list : 0x0
<1><2d>: Abbrev Number: 2 (DW_TAG_subprogram)
<2e> DW_AT_external : 1
<2e> DW_AT_name : (indirect string, offset: 0x33): main
<32> DW_AT_decl_file : 1
<33> DW_AT_decl_line : 1
<34> DW_AT_type : <0x4a>
<38> DW_AT_low_pc : 0x5fa
<40> DW_AT_high_pc : 0xb
<48> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
<4a> DW_AT_GNU_all_call_sites: 1
<1><4a>: Abbrev Number: 3 (DW_TAG_base_type)
<4b> DW_AT_byte_size : 4
<4c> DW_AT_encoding : 5 (signed)
<4d> DW_AT_name : int
<1><51>: Abbrev Number: 0
我有一个使用 gcc 编译并启用调试符号的二进制文件:
# file binary
binary: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=f5902695bdca690e84987fb377b69d16e3b47829, not stripped
使用objdump -syms binary
我也可以看到调试符号。但是,当我 运行 gdb ./binary
:
Reading symbols from ./binary...(no debugging symbols found)...done.
(gdb) list
No symbol table is loaded. Use the "file" command.
为什么会发生这种情况,如何加载调试符号?
Why is this happening and how can I load the debugging symbols?
这很可能发生,因为实际上该库没有调试符号。
file binary
... not stripped
上面的输出不表明二进制文件有调试符号,只是它有一个符号table。这样做也是如此:objdump -syms
.
要真正查看调试符号,请执行以下操作:readelf -wi binary
(我预计您不会看到任何符号)。
如果确实存在调试符号,您应该会看到如下内容:
$ readelf -wi ./a.out
Contents of the .debug_info section:
Compilation Unit @ offset 0x0:
Length: 0x4e (32-bit)
Version: 4
Abbrev Offset: 0x0
Pointer Size: 8
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
<c> DW_AT_producer : (indirect string, offset: 0x5): GNU C11 7.3.0 -mtune=generic -march=x86-64 -g
<10> DW_AT_language : 12 (ANSI C99)
<11> DW_AT_name : t.c
<15> DW_AT_comp_dir : (indirect string, offset: 0x0): /tmp
<19> DW_AT_low_pc : 0x5fa
<21> DW_AT_high_pc : 0xb
<29> DW_AT_stmt_list : 0x0
<1><2d>: Abbrev Number: 2 (DW_TAG_subprogram)
<2e> DW_AT_external : 1
<2e> DW_AT_name : (indirect string, offset: 0x33): main
<32> DW_AT_decl_file : 1
<33> DW_AT_decl_line : 1
<34> DW_AT_type : <0x4a>
<38> DW_AT_low_pc : 0x5fa
<40> DW_AT_high_pc : 0xb
<48> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
<4a> DW_AT_GNU_all_call_sites: 1
<1><4a>: Abbrev Number: 3 (DW_TAG_base_type)
<4b> DW_AT_byte_size : 4
<4c> DW_AT_encoding : 5 (signed)
<4d> DW_AT_name : int
<1><51>: Abbrev Number: 0