[LLVMdev] RFC: debug_line Emission

Bill Wendling isanbard at gmail.com
Thu Jul 17 15:33:47 PDT 2008


In CodeGen/DwarfWriter.cpp's EmitDebugLine file, these lines are
causing havoc on Mac OS X systems:

    // If there are no lines to emit (such as when we're using .loc
directives
    // to emit .debug_line information) don't emit a .debug_line
header.
    if (SectionSourceLines.empty())
      return;

Basically, if there's a file with only data in it, we still need the
debug_line prologue generated.

$ cat a.c
const char ver[] __attribute__((used)) = "Hello world\n";
$ gcc -g -O0 -c a.c -o a.gcc.o
$ dwarfdump --debug-line=0 a.gcc.o
----------------------------------------------------------------------
 File: a.gcc.o (architecture i386)
----------------------------------------------------------------------

.debug_line contents:
----------------------------------------------------------------------
debug_line[0x00000000]
----------------------------------------------------------------------
Line table prologue:
   total_length: 0x00000027
        version: 0x0002
prologue_length: 0x00000017
min_inst_length: 0x01
default_is_stmt: 0x01
      line_base: -10
     line_range: 245
    opcode_base: 0x0a
standard_opcode_lengths[ DW_LNS_copy             ] = 0
standard_opcode_lengths[ DW_LNS_advance_pc       ] = 1
standard_opcode_lengths[ DW_LNS_advance_line     ] = 1
standard_opcode_lengths[ DW_LNS_set_file         ] = 1
standard_opcode_lengths[ DW_LNS_set_column       ] = 1
standard_opcode_lengths[ DW_LNS_negate_stmt      ] = 0
standard_opcode_lengths[ DW_LNS_set_basic_block  ] = 0
standard_opcode_lengths[ DW_LNS_const_add_pc     ] = 0
standard_opcode_lengths[ DW_LNS_fixed_advance_pc ] = 1
                Dir  Mod Time   File Len   File Name
                ---- ---------- ---------- ---------------------------
file_names[  1]    0 0x00000000 0x00000000 a.c
0x00000021: DW_LNE_set_address( 0x00000000 )
0x00000028: DW_LNE_end_sequence
            0x0000000000000000      1      1      0

By removing the "early exit" from EmitDebugLine, I got LLVM to
generate this data. However, Dan pointed out that assemblers that use
the ".loc" directive can't have their debug_line generated by the
compiler. My suggestion was to have a flag that indicated that ".loc"
was used. If it was, then we would exit out of the EmitDebugLine
method early. Something like so:

    // If there are no lines to emit (such as when we're using .loc
directives
    // to emit .debug_line information) don't emit a .debug_line
header.
    if (LocDirectiveUsed())
      return;

Dan wasn't sure if this would work in all cases. We don't have a Linux
box to test this on. Does this sound like a good idea? Those who work
with Linux or other OSes, would this idea break things for you?

-bw



More information about the llvm-dev mailing list