RFC: debug_line Emission

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

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;

The fix is to move the early exist to just below this line: EmitLabel("line_prolog_end", 0), right?

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

Right.

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"

I am not sure I understand this statement?

Evan

I've now tested how GCC does this on Ubuntu, at least. It uses .loc and
does not emit a separate .debug_line prologue. It apparently assumes
that the .file numbers will directly correspond with file indicies in
the debug line section, suitable for use with DW_AT_decl_file.

So I think the way to fix this is to make it dependent on whether
the target uses .loc or not. Something like this:

   // If the target is using .loc/.file, the assembler will be emitting
   // the .debug_line table automatically.
   if (TAI->hasDotLocAndDotFile())
     return;

Dan

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;

The fix is to move the early exist to just below this line:
EmitLabel("line_prolog_end", 0), right?

No. We still need the emission of some of the labels after this. So it would get rid of the if-statement altogether. However, Dan came up with a better solution. :slight_smile:

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"

I am not sure I understand this statement?

Now that I read it, neither can I. :slight_smile: I was trying to say that the .loc and .file directives are there to indicate that the assembler should generate the debug_line section -- with line tables, etc. So the compiler shouldn't be outputting those sections.

-bw