[llvm] e7102ee - [DWARF5] Added support for .debug_macro.dwo section in llvm-dwarfdump

Sourabh Singh Tomar via llvm-commits llvm-commits at lists.llvm.org
Fri May 29 11:44:09 PDT 2020


Author: Sourabh Singh Tomar
Date: 2020-05-30T00:12:50+05:30
New Revision: e7102eed20d969c7e75b7d3dc5192290f733797a

URL: https://github.com/llvm/llvm-project/commit/e7102eed20d969c7e75b7d3dc5192290f733797a
DIFF: https://github.com/llvm/llvm-project/commit/e7102eed20d969c7e75b7d3dc5192290f733797a.diff

LOG: [DWARF5] Added support for .debug_macro.dwo section in llvm-dwarfdump

This patch extends the parsing and dumping support of llvm-dwarfdump
for debug_macro.dwo section.

Following forms are supported:

 - DW_MACRO_define
 - DW_MACRO_undef
 - DW_MACRO_start_file
 - DW_MACRO_end_file
 - DW_MACRO_define_strx
 - DW_MACRO_undef_strx
 - DW_MACRO_define_strp
 - DW_MACRO_undef_strp

Reviewed by: ikudrin, dblaikie

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

Added: 
    llvm/test/DebugInfo/X86/debug-macro-strp-dwo.s
    llvm/test/DebugInfo/X86/debug-macro-strx-dwo.s

Modified: 
    llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
    llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h
    llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
index 3e387343d54f..b36505760e46 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
@@ -72,6 +72,7 @@ class DWARFContext : public DIContext {
   DWARFUnitVector DWOUnits;
   std::unique_ptr<DWARFDebugAbbrev> AbbrevDWO;
   std::unique_ptr<DWARFDebugMacro> MacinfoDWO;
+  std::unique_ptr<DWARFDebugMacro> MacroDWO;
 
   /// The maximum DWARF version of all units.
   unsigned MaxVersion = 0;
@@ -110,8 +111,8 @@ class DWARFContext : public DIContext {
   enum MacroSecType {
     MacinfoSection,
     MacinfoDwoSection,
-    MacroSection
-    // FIXME: Add support for.debug_macro.dwo section.
+    MacroSection,
+    MacroDwoSection
   };
 
 public:
@@ -291,6 +292,9 @@ class DWARFContext : public DIContext {
   /// Get a pointer to the parsed DebugMacro information object.
   const DWARFDebugMacro *getDebugMacro();
 
+  /// Get a pointer to the parsed DebugMacroDWO information object.
+  const DWARFDebugMacro *getDebugMacroDWO();
+
   /// Get a reference to the parsed accelerator table object.
   const DWARFDebugNames &getDebugNames();
 
@@ -319,6 +323,9 @@ class DWARFContext : public DIContext {
   DataExtractor getStringExtractor() const {
     return DataExtractor(DObj->getStrSection(), false, 0);
   }
+  DataExtractor getStringDWOExtractor() const {
+    return DataExtractor(DObj->getStrDWOSection(), false, 0);
+  }
   DataExtractor getLineStringExtractor() const {
     return DataExtractor(DObj->getLineStrSection(), false, 0);
   }

diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h
index 89fccf04a01d..60fcd3daf5b1 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h
@@ -48,6 +48,7 @@ class DWARFObject {
   virtual const DWARFSection &getRangesSection() const { return Dummy; }
   virtual const DWARFSection &getRnglistsSection() const { return Dummy; }
   virtual const DWARFSection &getMacroSection() const { return Dummy; }
+  virtual StringRef getMacroDWOSection() const { return ""; }
   virtual StringRef getMacinfoSection() const { return ""; }
   virtual StringRef getMacinfoDWOSection() const { return ""; }
   virtual const DWARFSection &getPubnamesSection() const { return Dummy; }

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 2989c68436ed..b6e0d9342cf9 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -264,9 +264,13 @@ std::unique_ptr<DWARFDebugMacro>
 DWARFContext::parseMacroOrMacinfo(MacroSecType SectionType) {
   auto Macro = std::make_unique<DWARFDebugMacro>();
   auto ParseAndDump = [&](DWARFDataExtractor &Data, bool IsMacro) {
-    // FIXME: Add support for debug_macro.dwo section.
-    if (Error Err = IsMacro ? Macro->parseMacro(compile_units(),
-                                                getStringExtractor(), Data)
+    if (Error Err = IsMacro ? Macro->parseMacro(SectionType == MacroSection
+                                                    ? compile_units()
+                                                    : dwo_compile_units(),
+                                                SectionType == MacroSection
+                                                    ? getStringExtractor()
+                                                    : getStringDWOExtractor(),
+                                                Data)
                             : Macro->parseMacinfo(Data)) {
       RecoverableErrorHandler(std::move(Err));
       Macro = nullptr;
@@ -289,6 +293,11 @@ DWARFContext::parseMacroOrMacinfo(MacroSecType SectionType) {
     ParseAndDump(Data, /*IsMacro=*/true);
     break;
   }
+  case MacroDwoSection: {
+    DWARFDataExtractor Data(DObj->getMacroDWOSection(), isLittleEndian(), 0);
+    ParseAndDump(Data, /*IsMacro=*/true);
+    break;
+  }
   }
   return Macro;
 }
@@ -461,6 +470,12 @@ void DWARFContext::dump(
       Macro->dump(OS);
   }
 
+  if (shouldDump(Explicit, ".debug_macro.dwo", DIDT_ID_DebugMacro,
+                 DObj->getMacroDWOSection())) {
+    if (auto MacroDWO = getDebugMacroDWO())
+      MacroDWO->dump(OS);
+  }
+
   if (shouldDump(Explicit, ".debug_macinfo", DIDT_ID_DebugMacro,
                  DObj->getMacinfoSection())) {
     if (auto Macinfo = getDebugMacinfo())
@@ -845,6 +860,12 @@ const DWARFDebugMacro *DWARFContext::getDebugMacro() {
   return Macro.get();
 }
 
+const DWARFDebugMacro *DWARFContext::getDebugMacroDWO() {
+  if (!MacroDWO)
+    MacroDWO = parseMacroOrMacinfo(MacroDwoSection);
+  return MacroDWO.get();
+}
+
 const DWARFDebugMacro *DWARFContext::getDebugMacinfo() {
   if (!Macinfo)
     Macinfo = parseMacroOrMacinfo(MacinfoSection);
@@ -1534,6 +1555,7 @@ class DWARFObjInMemory final : public DWARFObject {
   StringRef StrSection;
   StringRef MacinfoSection;
   StringRef MacinfoDWOSection;
+  StringRef MacroDWOSection;
   StringRef AbbrevDWOSection;
   StringRef StrDWOSection;
   StringRef CUIndexSection;
@@ -1554,6 +1576,7 @@ class DWARFObjInMemory final : public DWARFObject {
         .Case("debug_str", &StrSection)
         .Case("debug_macinfo", &MacinfoSection)
         .Case("debug_macinfo.dwo", &MacinfoDWOSection)
+        .Case("debug_macro.dwo", &MacroDWOSection)
         .Case("debug_abbrev.dwo", &AbbrevDWOSection)
         .Case("debug_str.dwo", &StrDWOSection)
         .Case("debug_cu_index", &CUIndexSection)
@@ -1872,6 +1895,7 @@ class DWARFObjInMemory final : public DWARFObject {
     return RnglistsSection;
   }
   const DWARFSection &getMacroSection() const override { return MacroSection; }
+  StringRef getMacroDWOSection() const override { return MacroDWOSection; }
   StringRef getMacinfoSection() const override { return MacinfoSection; }
   StringRef getMacinfoDWOSection() const override { return MacinfoDWOSection; }
   const DWARFSection &getPubnamesSection() const override { return PubnamesSection; }

diff  --git a/llvm/test/DebugInfo/X86/debug-macro-strp-dwo.s b/llvm/test/DebugInfo/X86/debug-macro-strp-dwo.s
new file mode 100644
index 000000000000..b74f49da558f
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/debug-macro-strp-dwo.s
@@ -0,0 +1,36 @@
+## This test checks that llvm-dwarfdump can dump debug_macro.dwo
+## section containing DW_MACRO_*_strp forms present in a dwo object.
+
+# RUN: llvm-mc -triple x86_64-unknown-linux -filetype=obj %s -o -| \
+# RUN:   llvm-dwarfdump -debug-macro - | FileCheck -strict-whitespace -match-full-lines %s
+
+#      CHECK:.debug_macro.dwo contents:
+# CHECK-NEXT:0x00000000:
+# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
+# CHECK-NEXT:DW_MACRO_start_file - lineno: 0 filenum: 0
+# CHECK-NEXT:  DW_MACRO_define_strp - lineno: 1 macro: DWARF_VERSION 5
+# CHECK-NEXT:  DW_MACRO_undef_strp - lineno: 4 macro: DWARF_VERSION
+# CHECK-NEXT:DW_MACRO_end_file
+
+	.section	.debug_macro.dwo,"e", at progbits
+.Lcu_macro_begin0:
+	.short	5                      # Macro information version
+	.byte	2                       # Flags: 32 bit, debug_line_offset present
+	.long	0                       # debug_line_offset
+	.byte	3                       # DW_MACRO_start_file
+	.byte	0                       # Line Number
+	.byte	0                       # File Number
+	.byte	5                       # DW_MACRO_define_strp
+	.byte	1                       # Line Number
+	.long	.Linfo_string0-.debug_str.dwo   # Macro String
+	.byte	6                       # DW_MACRO_undef_strp
+	.byte	4                       # Line Number
+	.long	.Linfo_string1-.debug_str.dwo   # Macro String
+	.byte	4                       # DW_MACRO_end_file
+	.byte	0                       # End Of Macro List Mark
+
+	.section	.debug_str.dwo,"eMS", at progbits,1
+.Linfo_string0:
+	.asciz	"DWARF_VERSION 5"
+.Linfo_string1:
+	.asciz	"DWARF_VERSION"

diff  --git a/llvm/test/DebugInfo/X86/debug-macro-strx-dwo.s b/llvm/test/DebugInfo/X86/debug-macro-strx-dwo.s
new file mode 100644
index 000000000000..242505f25af2
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/debug-macro-strx-dwo.s
@@ -0,0 +1,68 @@
+## This test checks that llvm-dwarfdump can dump debug_macro.dwo
+## section containing DW_MACRO_*_strx forms present in a dwo object.
+
+# RUN: llvm-mc -triple x86_64-unknown-linux -filetype=obj %s -o -| \
+# RUN:   llvm-dwarfdump -debug-macro - | FileCheck -strict-whitespace -match-full-lines %s
+
+#      CHECK:.debug_macro.dwo contents:
+# CHECK-NEXT:0x00000000:
+# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
+# CHECK-NEXT:DW_MACRO_start_file - lineno: 0 filenum: 0
+# CHECK-NEXT:  DW_MACRO_define_strx - lineno: 1 macro: DWARF_VERSION 5
+# CHECK-NEXT:  DW_MACRO_undef_strx - lineno: 4 macro: DWARF_VERSION
+# CHECK-NEXT:DW_MACRO_end_file
+
+	.section	.debug_macro.dwo,"e", at progbits
+.Lcu_macro_begin0:
+	.short	5                      # Macro information version
+	.byte	2                       # Flags: 32 bit, debug_line_offset present
+	.long	0                       # debug_line_offset
+	.byte	3                       # DW_MACRO_start_file
+	.byte	0                       # Line Number
+	.byte	0                       # File Number
+	.byte	11                      # DW_MACRO_define_strx
+	.byte	1                       # Line Number
+	.byte	0                       # Macro String Index
+	.byte	12                      # DW_MACRO_undef_strx
+	.byte	4                       # Line Number
+	.byte	1                       # Macro String Index
+	.byte	4                       # DW_MACRO_end_file
+	.byte	0                       # End Of Macro List Mark
+
+	.section	.debug_str_offsets.dwo,"e", at progbits
+	.long   .Lcu_str_off_end0-.Lcu_str_off_start0 # Unit length
+	.short	5                                     # Version
+	.short	0                                     # Padding
+.Lcu_str_off_start0:
+	.long	.Linfo_string0-.debug_str.dwo
+	.long	.Linfo_string1-.debug_str.dwo
+.Lcu_str_off_end0:
+
+	.section	.debug_str.dwo,"eMS", at progbits,1
+.Linfo_string0:
+	.asciz	"DWARF_VERSION 5"
+.Linfo_string1:
+	.asciz	"DWARF_VERSION"
+
+	.section	.debug_info.dwo,"e", at progbits
+	.long	.Ldebug_info_dwo_end0-.Ldebug_info_dwo_start0 # Length of Unit
+.Ldebug_info_dwo_start0:
+	.short	5                      # DWARF version number
+	.byte	5                       # DWARF Unit Type
+	.byte	8                       # Address Size (in bytes)
+	.long	0                       # Offset Into Abbrev. Section
+	.quad	1536875774479801980
+	.byte	1                       # Abbrev [1] 0x14:0x1a DW_TAG_compile_unit
+	.long   .Lcu_macro_begin0-.debug_macro.dwo # DW_AT_macros
+	.byte	0                       # End Of Children Mark
+.Ldebug_info_dwo_end0:
+
+	.section	.debug_abbrev.dwo,"e", at progbits
+	.byte	1                       # Abbreviation Code
+	.byte	17                      # DW_TAG_compile_unit
+	.byte	0                       # DW_CHILDREN_no
+	.byte	121                     # DW_AT_macros
+	.byte	23                      # DW_FORM_sec_offset
+	.byte	0                       # EOM(1)
+	.byte	0                       # EOM(2)
+	.byte	0                       # EOM(3)


        


More information about the llvm-commits mailing list