DebugInfo: Separate different debug_macinfo contributions & print the offset of a...
authorDavid Blaikie <dblaikie@gmail.com>
Tue, 3 Mar 2020 03:30:03 +0000 (19:30 -0800)
committerDavid Blaikie <dblaikie@gmail.com>
Tue, 3 Mar 2020 03:30:30 +0000 (19:30 -0800)
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
llvm/test/DebugInfo/X86/debug-macinfo-split-dwarf.ll
llvm/test/DebugInfo/X86/debug-macro.ll

index 7880bcd..e666c82 100644 (file)
@@ -39,7 +39,10 @@ class DWARFDebugMacro {
     };
   };
 
-  using MacroList = SmallVector<Entry, 4>;
+  struct MacroList {
+    SmallVector<Entry, 4> Macros;
+    uint64_t Offset;
+  };
 
   /// A list of all the macro entries in the debug_macinfo section.
   std::vector<MacroList> MacroLists;
index 8cb259e..2e06e14 100644 (file)
@@ -18,7 +18,8 @@ using namespace dwarf;
 void DWARFDebugMacro::dump(raw_ostream &OS) const {
   unsigned IndLevel = 0;
   for (const auto &Macros : MacroLists) {
-    for (const Entry &E : Macros) {
+    OS << format("0x%08" PRIx64 ":\n", Macros.Offset);
+    for (const Entry &E : Macros.Macros) {
       // There should not be DW_MACINFO_end_file when IndLevel is Zero. However,
       // this check handles the case of corrupted ".debug_macinfo" section.
       if (IndLevel > 0)
@@ -51,7 +52,6 @@ void DWARFDebugMacro::dump(raw_ostream &OS) const {
       }
       OS << "\n";
     }
-    OS << "\n";
   }
 }
 
@@ -62,15 +62,17 @@ void DWARFDebugMacro::parse(DataExtractor data) {
     if (!M) {
       MacroLists.emplace_back();
       M = &MacroLists.back();
+      M->Offset = Offset;
     }
     // A macro list entry consists of:
-    M->emplace_back();
-    Entry &E = M->back();
+    M->Macros.emplace_back();
+    Entry &E = M->Macros.back();
     // 1. Macinfo type
     E.Type = data.getULEB128(&Offset);
 
     if (E.Type == 0) {
       // Reached end of a ".debug_macinfo" section contribution.
+      M = nullptr;
       continue;
     }
 
index e75f138..f7cbff4 100644 (file)
@@ -8,6 +8,7 @@
 ; CHECK:       DW_AT_macro_info  (0x00000000)
 
 ;CHECK-LABEL:.debug_macinfo.dwo contents:
+;CHECK-NEXT: 0x00000000:
 ;CHECK-NEXT:  DW_MACINFO_start_file - lineno: 0 filenum: 1
 ;CHECK-NEXT:    DW_MACINFO_start_file - lineno: 1 filenum: 2
 ;CHECK-NEXT:      DW_MACINFO_define - lineno: 1 macro: define_1 12
index 6a5ae1e..fbcfab6 100644 (file)
@@ -16,6 +16,7 @@
 ; CHECK-NOT: DW_AT_macro_info
 
 ; CHECK-LABEL:     .debug_macinfo contents:
+; CHECK-NEXT: 0x00000000:
 ; CHECK-NEXT: DW_MACINFO_define - lineno: 0 macro: NameCMD ValueCMD
 ; CHECK-NEXT: DW_MACINFO_start_file - lineno: 0 filenum: 1
 ; CHECK-NEXT:   DW_MACINFO_start_file - lineno: 9 filenum: 2
@@ -24,8 +25,9 @@
 ; CHECK-NEXT:   DW_MACINFO_end_file
 ; CHECK-NEXT:   DW_MACINFO_undef - lineno: 10 macro: NameUndef2
 ; CHECK-NEXT: DW_MACINFO_end_file
-
-; CHECK: DW_MACINFO_start_file - lineno: 0 filenum: 1
+; CHECK-EMPTY:
+; CHECK-NEXT: 0x00000045:
+; CHECK-NEXT: DW_MACINFO_start_file - lineno: 0 filenum: 1
 ; CHECK-NEXT: DW_MACINFO_end_file
 
 ; CHECK-LABEL: .debug_line contents: