[llvm] ccbd7e8 - [DebugInfo] Support parsing and dumping of DWARF64 macro units.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 16 22:58:50 PDT 2020


Author: Igor Kudrin
Date: 2020-06-17T12:57:54+07:00
New Revision: ccbd7e8d463a1d40852c6acbbecd3ae1e2c38f4c

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

LOG: [DebugInfo] Support parsing and dumping of DWARF64 macro units.

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

Added: 
    llvm/test/DebugInfo/X86/debug-macro-dwarf64.s

Modified: 
    llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
    llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
    llvm/test/DebugInfo/X86/debug-macro-dwo.ll
    llvm/test/DebugInfo/X86/debug-macro-macinfo.s
    llvm/test/DebugInfo/X86/debug-macro-multi-cu-strx.s
    llvm/test/DebugInfo/X86/debug-macro-strp-dwo.s
    llvm/test/DebugInfo/X86/debug-macro-strx-dwo.s
    llvm/test/DebugInfo/X86/debug-macro-v5.ll
    llvm/test/DebugInfo/X86/debug-macro-v5.s

Removed: 
    llvm/test/DebugInfo/X86/unsupported-dwarf64-debug-macro-v5.s


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
index d35fb1711323..4d463d8fe6f5 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
@@ -44,7 +44,7 @@ class DWARFDebugMacro {
     /// opcode_operands_table_flag:
     ///   If the opcode_operands_table_flag is one, the opcode_operands_table
     ///   field (see below) is present. If zero, that field is omitted.
-    uint8_t Flags;
+    uint8_t Flags = 0;
 
     /// debug_line_offset
     ///   An offset in the .debug_line section of the beginning of the line
@@ -58,6 +58,12 @@ class DWARFDebugMacro {
 
     /// Parse the debug_macro header.
     Error parseMacroHeader(DWARFDataExtractor Data, uint64_t *Offset);
+
+    /// Get the DWARF format according to the flags.
+    dwarf::DwarfFormat getDwarfFormat() const;
+
+    /// Get the size of a reference according to the DWARF format.
+    uint8_t getOffsetByteSize() const;
   };
 
   /// A single macro entry within a macro list.

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
index 49ee94bbddad..f920d69cc43f 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
@@ -17,14 +17,23 @@
 using namespace llvm;
 using namespace dwarf;
 
+DwarfFormat DWARFDebugMacro::MacroHeader::getDwarfFormat() const {
+  return Flags & MACRO_OFFSET_SIZE ? DWARF64 : DWARF32;
+}
+
+uint8_t DWARFDebugMacro::MacroHeader::getOffsetByteSize() const {
+  return getDwarfOffsetByteSize(getDwarfFormat());
+}
+
 void DWARFDebugMacro::MacroHeader::dumpMacroHeader(raw_ostream &OS) const {
   // FIXME: Add support for dumping opcode_operands_table
-  OS << format("macro header: version = 0x%04" PRIx16 ", flags = 0x%02" PRIx8,
-               Version, Flags);
+  OS << format("macro header: version = 0x%04" PRIx16, Version)
+     << format(", flags = 0x%02" PRIx8, Flags)
+     << ", format = " << FormatString(getDwarfFormat());
   if (Flags & MACRO_DEBUG_LINE_OFFSET)
-    OS << format(", debug_line_offset = 0x%04" PRIx64 "\n", DebugLineOffset);
-  else
-    OS << "\n";
+    OS << format(", debug_line_offset = 0x%0*" PRIx64, 2 * getOffsetByteSize(),
+                 DebugLineOffset);
+  OS << "\n";
 }
 
 void DWARFDebugMacro::dump(raw_ostream &OS) const {
@@ -72,7 +81,8 @@ void DWARFDebugMacro::dump(raw_ostream &OS) const {
         OS << " filenum: " << E.File;
         break;
       case DW_MACRO_import:
-        OS << format(" - import offset: 0x%08" PRIx64, E.ImportOffset);
+        OS << format(" - import offset: 0x%0*" PRIx64,
+                     2 * Macros.Header.getOffsetByteSize(), E.ImportOffset);
         break;
       case DW_MACRO_end_file:
         break;
@@ -158,8 +168,8 @@ Error DWARFDebugMacro::parseImpl(
       // 2. Source line
       E.Line = Data.getULEB128(&Offset);
       // 3. Macro string
-      // FIXME: Add support for DWARF64
-      StrOffset = Data.getRelocatedValue(/*OffsetSize=*/4, &Offset);
+      StrOffset =
+          Data.getRelocatedValue(M->Header.getOffsetByteSize(), &Offset);
       assert(StringExtractor && "String Extractor not found");
       E.MacroStr = StringExtractor->getCStr(&StrOffset);
       break;
@@ -199,8 +209,8 @@ Error DWARFDebugMacro::parseImpl(
     case DW_MACRO_end_file:
       break;
     case DW_MACRO_import:
-      // FIXME: Add support for DWARF64
-      E.ImportOffset = Data.getRelocatedValue(/*OffsetSize=*/4, &Offset);
+      E.ImportOffset =
+          Data.getRelocatedValue(M->Header.getOffsetByteSize(), &Offset);
       break;
     case DW_MACINFO_vendor_ext:
       // 2. Vendor extension constant
@@ -217,9 +227,6 @@ Error DWARFDebugMacro::MacroHeader::parseMacroHeader(DWARFDataExtractor Data,
                                                      uint64_t *Offset) {
   Version = Data.getU16(Offset);
   uint8_t FlagData = Data.getU8(Offset);
-  // FIXME: Add support for DWARF64
-  if (FlagData & MACRO_OFFSET_SIZE)
-    return createStringError(errc::not_supported, "DWARF64 is not supported");
 
   // FIXME: Add support for parsing opcode_operands_table
   if (FlagData & MACRO_OPCODE_OPERANDS_TABLE)
@@ -227,6 +234,6 @@ Error DWARFDebugMacro::MacroHeader::parseMacroHeader(DWARFDataExtractor Data,
                              "opcode_operands_table is not supported");
   Flags = FlagData;
   if (Flags & MACRO_DEBUG_LINE_OFFSET)
-    DebugLineOffset = Data.getU32(Offset);
+    DebugLineOffset = Data.getUnsigned(Offset, getOffsetByteSize());
   return Error::success();
 }

diff  --git a/llvm/test/DebugInfo/X86/debug-macro-dwarf64.s b/llvm/test/DebugInfo/X86/debug-macro-dwarf64.s
new file mode 100644
index 000000000000..5f9bfd46afb5
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/debug-macro-dwarf64.s
@@ -0,0 +1,53 @@
+## This checks that llvm-dwarfdump can parse and dump DWARF64 macro units.
+
+# RUN: llvm-mc -triple x86_64 -filetype=obj %s -o - \
+# RUN:   | llvm-dwarfdump -debug-macro - \
+# RUN:   | FileCheck %s
+
+# CHECK:      .debug_macro contents:
+
+# CHECK:      0x00000000:
+# CHECK-NEXT: macro header: version = 0x0005, flags = 0x03, format = DWARF64, debug_line_offset = 0x0000000000000000
+# CHECK-NEXT: DW_MACRO_start_file - lineno: 0 filenum: 0
+# CHECK-NEXT:   DW_MACRO_import - import offset: 0x00000000[[MACRO1OFF:[[:xdigit:]]{8}]]
+# CHECK-NEXT: DW_MACRO_end_file
+
+# CHECK:      0x[[MACRO1OFF]]:
+# CHECK-NEXT: macro header: version = 0x0005, flags = 0x01, format = DWARF64
+# CHECK-NEXT: DW_MACRO_define_strp - lineno: 1 macro: FOO 1
+# CHECK-NEXT: DW_MACRO_undef_strp - lineno: 9 macro: BAR
+# CHECK-NEXT: DW_MACRO_undef_strp - lineno: 15 macro: BAZ
+
+    .section .debug_macro, "", @progbits
+.LMacro0:
+    .short 5            # Version
+    .byte 3             # Flags: offset_size_flag | debug_line_offset_flag
+    .quad 0             # Debug Line Offset
+    .byte 3             # DW_MACRO_start_file
+    .uleb128 0          # Line
+    .uleb128 0          # File
+    .byte 7             # DW_MACRO_import
+    .quad .LMacro1
+    .byte 4             # DW_MACRO_end_file
+    .byte 0             # End macro unit
+.LMacro1:
+    .short 5            # Version
+    .byte 1             # Flags: offset_size_flag
+    .byte 5             # DW_MACRO_define_strp
+    .uleb128 1          # Line
+    .quad .LStr0        # "FOO 1"
+    .byte 6             # DW_MACRO_undef_strp
+    .uleb128 9          # Line
+    .quad .LStr1        # "BAR"
+    .byte 6             # DW_MACRO_undef_strp
+    .uleb128 15         # Line
+    .quad .LStr2        # "BAZ"
+    .byte 0             # End macro unit
+
+    .section .debug_str, "MS", @progbits, 1
+.LStr0:
+    .asciz "FOO 1"
+.LStr1:
+    .asciz "BAR"
+.LStr2:
+    .asciz "BAZ"

diff  --git a/llvm/test/DebugInfo/X86/debug-macro-dwo.ll b/llvm/test/DebugInfo/X86/debug-macro-dwo.ll
index b11f2f9513ed..1391795c9cd6 100644
--- a/llvm/test/DebugInfo/X86/debug-macro-dwo.ll
+++ b/llvm/test/DebugInfo/X86/debug-macro-dwo.ll
@@ -9,7 +9,7 @@
 
 ; CHECK-LABEL:  .debug_macro.dwo contents:
 ; CHECK-NEXT: 0x00000000:
-; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02
+; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02, format = DWARF32
 ; CHECK-NEXT: DW_MACRO_start_file - lineno: 0 filenum: 0
 ; CHECK-NEXT:   DW_MACRO_start_file - lineno: 1 filenum: 1
 ; CHECK-NEXT:     DW_MACRO_define_strx - lineno: 1 macro: FOO 5

diff  --git a/llvm/test/DebugInfo/X86/debug-macro-macinfo.s b/llvm/test/DebugInfo/X86/debug-macro-macinfo.s
index a5337cafc907..c981097184c8 100644
--- a/llvm/test/DebugInfo/X86/debug-macro-macinfo.s
+++ b/llvm/test/DebugInfo/X86/debug-macro-macinfo.s
@@ -6,7 +6,7 @@
 
 #      CHECK:.debug_macro contents:
 # CHECK-NEXT:0x00000000:
-# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
+# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
 # 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_end_file

diff  --git a/llvm/test/DebugInfo/X86/debug-macro-multi-cu-strx.s b/llvm/test/DebugInfo/X86/debug-macro-multi-cu-strx.s
index da695962e681..6fdc57cbcf3a 100644
--- a/llvm/test/DebugInfo/X86/debug-macro-multi-cu-strx.s
+++ b/llvm/test/DebugInfo/X86/debug-macro-multi-cu-strx.s
@@ -7,7 +7,7 @@
 
 #      CHECK:.debug_macro contents:
 # CHECK-NEXT:0x00000000:
-# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
+# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
 # 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_define_strx - lineno: 2 macro: COMPILE_UNIT 1
@@ -15,7 +15,7 @@
 # CHECK-NEXT:DW_MACRO_end_file
 
 #      CHECK:0x00000015:
-# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
+# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
 # CHECK-NEXT:DW_MACRO_start_file - lineno: 1 filenum: 3
 # CHECK-NEXT:  DW_MACRO_define_strx - lineno: 2 macro: COMPILE_UNIT 2
 # CHECK-NEXT:  DW_MACRO_undef_strx - lineno: 3 macro: COMPILE_UNIT

diff  --git a/llvm/test/DebugInfo/X86/debug-macro-strp-dwo.s b/llvm/test/DebugInfo/X86/debug-macro-strp-dwo.s
index b74f49da558f..fad9c1b27a34 100644
--- a/llvm/test/DebugInfo/X86/debug-macro-strp-dwo.s
+++ b/llvm/test/DebugInfo/X86/debug-macro-strp-dwo.s
@@ -6,7 +6,7 @@
 
 #      CHECK:.debug_macro.dwo contents:
 # CHECK-NEXT:0x00000000:
-# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
+# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
 # 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

diff  --git a/llvm/test/DebugInfo/X86/debug-macro-strx-dwo.s b/llvm/test/DebugInfo/X86/debug-macro-strx-dwo.s
index 242505f25af2..e60ff5d800de 100644
--- a/llvm/test/DebugInfo/X86/debug-macro-strx-dwo.s
+++ b/llvm/test/DebugInfo/X86/debug-macro-strx-dwo.s
@@ -6,7 +6,7 @@
 
 #      CHECK:.debug_macro.dwo contents:
 # CHECK-NEXT:0x00000000:
-# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
+# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
 # 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

diff  --git a/llvm/test/DebugInfo/X86/debug-macro-v5.ll b/llvm/test/DebugInfo/X86/debug-macro-v5.ll
index 85df7769d71d..a0334c027e71 100644
--- a/llvm/test/DebugInfo/X86/debug-macro-v5.ll
+++ b/llvm/test/DebugInfo/X86/debug-macro-v5.ll
@@ -8,7 +8,7 @@
 
 ; CHECK-LABEL:  .debug_macro contents:
 ; CHECK-NEXT: 0x00000000:
-; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
+; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
 ; CHECK-NEXT: DW_MACRO_start_file - lineno: 0 filenum: 0
 ; CHECK-NEXT:   DW_MACRO_start_file - lineno: 1 filenum: 1
 ; CHECK-NEXT:     DW_MACRO_define_strx - lineno: 1 macro: FOO 5

diff  --git a/llvm/test/DebugInfo/X86/debug-macro-v5.s b/llvm/test/DebugInfo/X86/debug-macro-v5.s
index 00b2cede0a18..15dca70a885a 100644
--- a/llvm/test/DebugInfo/X86/debug-macro-v5.s
+++ b/llvm/test/DebugInfo/X86/debug-macro-v5.s
@@ -6,7 +6,7 @@
 
 #      CHECK:.debug_macro contents:
 # CHECK-NEXT:0x00000000:
-# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000
+# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, format = DWARF32, debug_line_offset = 0x00000000
 # CHECK-NEXT:DW_MACRO_start_file - lineno: 0 filenum: 0
 # CHECK-NEXT:  DW_MACRO_start_file - lineno: 1 filenum: 6
 # CHECK-NEXT:    DW_MACRO_define_strp - lineno: 1 macro: FOO 5
@@ -16,7 +16,7 @@
 # CHECK-NEXT:DW_MACRO_end_file
 
 #      CHECK:0x[[OFFSET]]:
-# CHECK-NEXT:macro header: version = 0x0005, flags = 0x00
+# CHECK-NEXT:macro header: version = 0x0005, flags = 0x00, format = DWARF32
 # CHECK-NEXT:DW_MACRO_define_strp - lineno: 0 macro: WORLD 2
 
 	.section	.debug_macro,"", at progbits

diff  --git a/llvm/test/DebugInfo/X86/unsupported-dwarf64-debug-macro-v5.s b/llvm/test/DebugInfo/X86/unsupported-dwarf64-debug-macro-v5.s
deleted file mode 100644
index a06c97ccf5e7..000000000000
--- a/llvm/test/DebugInfo/X86/unsupported-dwarf64-debug-macro-v5.s
+++ /dev/null
@@ -1,13 +0,0 @@
-## This test checks llvm-dwarfdump emits correct error diagnostics for the
-## unsupported case where DWARF64 flag is present in the debug_macro section header.
-
-# RUN: llvm-mc -triple x86_64-unknown-linux -filetype=obj %s -o -| \
-# RUN:   not llvm-dwarfdump -debug-macro - /dev/null 2>&1 | FileCheck %s
-
-# CHECK:error: DWARF64 is not supported
-
-	.section	.debug_macro,"", at progbits
-.Lcu_macro_begin0:
-	.short	5                      # Macro information version
-	.byte	3                       # Flags: 64 bit, debug_line_offset present
-	.quad	0                       # debug_line_offset


        


More information about the llvm-commits mailing list