7

GCC documentation says that the -g option produces debugging information in the operating system's native format (stabs, COFF, XCOFF, or DWARF 2).

So, what is Linux native debugging symbols format? What is it called?


Update: I've just found a 15-year old gcc mailing list discussion where it was said that the native format at that point was stabs and then they were considering to switch to DWARF2. But it was 15 years ago... Any updates? =)

  • According to the DWARF page on wikipedia, "Linux followed suit, and DWARF-2 did not become the default until the late 1990s.". I'd like to see a more authoritative source though. – Digital Trauma Jul 31 '15 at 23:01
6

On Linux the default is now Dwarf 2 and/or 4. To see this, run readelf --debug-dump=info on a binary containing debug symbols (or stripped symbols); for example, on Fedora, with glibc-debuginfo installed, running readelf --debug-dump=info /usr/lib/debug/bin/gencat.debug will give you something like

 <1><ea>: Abbrev Number: 0
  Compilation Unit @ offset 0xeb:
   Length:        0x5c (32-bit)
   Version:       2
   Abbrev Offset: 0x52
   Pointer Size:  8
 <0><f6>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <f7>   DW_AT_stmt_list   : 0x83
    <fb>   DW_AT_ranges      : 0x0
    <ff>   DW_AT_name        : ../sysdeps/x86_64/crti.S
    <118>   DW_AT_comp_dir    : /usr/src/debug////////glibc-2.21/csu
    <13d>   DW_AT_producer    : GNU AS 2.25
    <149>   DW_AT_language    : 32769   (MIPS assembler)

This is a set of Dwarf 2 information (see the Version: header for version information; the same binary includes Dwarf 2 and Dwarf 4 sections).

  • Can you please elaborate on "the same binary includes Dwarf 2 and Dwarf 4 sections"? Otherwise you seem to be right, Linux uses DWARF. Also the latest documentation for gcc-5.2.0 says that when you use -gdwarf option the default DWARF version is 4. Though the same section of documentation for gcc-4.7.4 (I have gcc-4.7.2 here) says that the default is DWARF version 2. – golem Aug 1 '15 at 13:50
  • So it seems that on Linux with gcc-4.7.2: gcc -g == gcc -gdwarf == gcc -gdwarf-2 – golem Aug 1 '15 at 13:57
  • @golem On the Fedora system I have here, running the command I gave lists Dwarf sections with both versions 2 and 4 in the same binary, hence my comment. The binary was built with gcc 5.1.1; perhaps building with Dwarf 4 includes version 2 sections for backwards compatibility, but that's just a guess, I'd have to investigate further. – Stephen Kitt Aug 1 '15 at 20:34
  • 1
    Since gcc 4.8, gcc -g uses Dwarf 4: gcc.gnu.org/gcc-4.8/changes.html – npostavs Oct 22 '16 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.