DebugInfo: Use debug_line.dwo for debug_macro.dwo
authorDavid Blaikie <dblaikie@gmail.com>
Sun, 12 Jul 2020 22:35:21 +0000 (15:35 -0700)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 22 Jul 2020 21:06:33 +0000 (14:06 -0700)
This is an alternative proposal to D81476 (and D82084) - the details were sufficiently confusing to me it seemed easier to write some code and see how it looks.

Reviewers: SouraVX

Differential Revision: https://reviews.llvm.org/D84278

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/test/DebugInfo/X86/debug-macro-dwo.ll

index 8475081..40a94ea 100644 (file)
@@ -3000,7 +3000,10 @@ static void emitMacroHeader(AsmPrinter *Asm, const DwarfDebug &DD,
   Asm->OutStreamer->AddComment("Flags: 32 bit, debug_line_offset present");
   Asm->emitInt8(Flags);
   Asm->OutStreamer->AddComment("debug_line_offset");
-  Asm->OutStreamer->emitSymbolValue(CU.getLineTableStartSym(), /*Size=*/4);
+  if (DD.useSplitDwarf())
+    Asm->OutStreamer->emitIntValue(0, /*Size=*/4);
+  else
+    Asm->OutStreamer->emitSymbolValue(CU.getLineTableStartSym(), /*Size=*/4);
 }
 
 void DwarfDebug::handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U) {
@@ -3056,16 +3059,22 @@ void DwarfDebug::emitMacro(DIMacro &M) {
 }
 
 void DwarfDebug::emitMacroFileImpl(
-    DIMacroFile &F, DwarfCompileUnit &U, unsigned StartFile, unsigned EndFile,
+    DIMacroFile &MF, DwarfCompileUnit &U, unsigned StartFile, unsigned EndFile,
     StringRef (*MacroFormToString)(unsigned Form)) {
 
   Asm->OutStreamer->AddComment(MacroFormToString(StartFile));
   Asm->emitULEB128(StartFile);
   Asm->OutStreamer->AddComment("Line Number");
-  Asm->emitULEB128(F.getLine());
+  Asm->emitULEB128(MF.getLine());
   Asm->OutStreamer->AddComment("File Number");
-  Asm->emitULEB128(U.getOrCreateSourceID(F.getFile()));
-  handleMacroNodes(F.getElements(), U);
+  DIFile &F = *MF.getFile();
+  if (useSplitDwarf())
+    Asm->emitULEB128(getDwoLineTable(U)->getFile(
+        F.getDirectory(), F.getFilename(), getMD5AsBytes(&F),
+        Asm->OutContext.getDwarfVersion(), F.getSource()));
+  else
+    Asm->emitULEB128(U.getOrCreateSourceID(&F));
+  handleMacroNodes(MF.getElements(), U);
   Asm->OutStreamer->AddComment(MacroFormToString(EndFile));
   Asm->emitULEB128(EndFile);
 }
index 95727a8..23e889f 100644 (file)
@@ -2,26 +2,34 @@
 ; -gdwarf-5 -gsplit-dwarf -fdebug-macro is specified.
 
 ; RUN: %llc_dwarf -dwarf-version=5 -O0 -filetype=obj \
-; RUN: -split-dwarf-file=foo.dwo < %s | llvm-dwarfdump -v - | FileCheck %s
+; RUN: -split-dwarf-file=foo.dwo < %s | llvm-dwarfdump -debug-macro -debug-info -debug-line -v - | FileCheck %s
 
 ; CHECK-LABEL:  .debug_info contents:
 ; CHECK: DW_AT_macros [DW_FORM_sec_offset] (0x00000000)
 
 ; CHECK-LABEL:  .debug_macro.dwo contents:
 ; CHECK-NEXT: 0x00000000:
-; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02, format = DWARF32
+; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
 ; CHECK-NEXT: DW_MACRO_start_file - lineno: 0 filenum: 0
-; FIXME: This should be filenum 1 (and 2 below) if this was using debug_loc.dwo
-;        (rather than currently incorrectly using debug_loc)
-; CHECK-NEXT:   DW_MACRO_start_file - lineno: 1 filenum: 2
+; CHECK-NEXT:   DW_MACRO_start_file - lineno: 1 filenum: 1
 ; CHECK-NEXT:     DW_MACRO_define_strx - lineno: 1 macro: FOO 5
 ; CHECK-NEXT:   DW_MACRO_end_file
-; CHECK-NEXT:   DW_MACRO_start_file - lineno: 2 filenum: 3
+; CHECK-NEXT:   DW_MACRO_start_file - lineno: 2 filenum: 2
 ; CHECK-NEXT:     DW_MACRO_undef_strx - lineno: 14 macro: YEA
 ; CHECK-NEXT:   DW_MACRO_end_file
 ; CHECK-NEXT:   DW_MACRO_undef_strx - lineno: 14 macro: YEA
 ; CHECK-NEXT: DW_MACRO_end_file
 
+; CHECK-LABEL: .debug_line.dwo contents:
+; CHECK: file_names[  0]:
+; CHECK:            name: "test.c"
+; CHECK: file_names[  1]:
+; CHECK:            name: "foo.h"
+; CHECK: file_names[  2]:
+; CHECK:            name: "bar.h"
+
+
+
 ; ModuleID = 'test.c'
 source_filename = "test.c"
 target datalayout = "e-m:e-p200:32:32-p201:32:32-p202:64:64-i64:64-f80:128-n8:16:32:64-S128"