Bobface
Bobface

Reputation: 2952

GDB does not load debugging symbols although they are present

I have a binary which was compiled with gcc and debugging symbols enabled:

# 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

Using objdump -syms binary I can also see the debugging symbols. However, GDB does not load them when I run 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?

Upvotes: 3

Views: 3092

Answers (1)

Employed Russian
Employed Russian

Reputation: 213375

Why is this happening and how can I load the debugging symbols?

This is most likely happening because in fact the library does not have debugging symbols.

file binary
... not stripped

Above output does not indicate that the binary has debugging symbols, only that it has a symbol table. So does this: objdump -syms.

To really see debugging symbols, do this: readelf -wi binary (I predict you wouldn't see any).

If debug symbols are in fact present, you should see something like this:

$ 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

Upvotes: 4

Related Questions