[llvm] r369356 - [DWARF] Fix DWARFUnit::getDebugInfoSize() for 64-bit DWARF.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 02:50:45 PDT 2019


Author: ikudrin
Date: Tue Aug 20 02:50:44 2019
New Revision: 369356

URL: http://llvm.org/viewvc/llvm-project?rev=369356&view=rev
Log:
[DWARF] Fix DWARFUnit::getDebugInfoSize() for 64-bit DWARF.

The calculation there was correct only for DWARF32.

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

Added:
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_info_min_dwarf64.s
Modified:
    llvm/trunk/include/llvm/BinaryFormat/Dwarf.h
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h

Modified: llvm/trunk/include/llvm/BinaryFormat/Dwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BinaryFormat/Dwarf.h?rev=369356&r1=369355&r2=369356&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BinaryFormat/Dwarf.h (original)
+++ llvm/trunk/include/llvm/BinaryFormat/Dwarf.h Tue Aug 20 02:50:44 2019
@@ -513,6 +513,17 @@ struct FormParams {
   explicit operator bool() const { return Version && AddrSize; }
 };
 
+/// Get the byte size of the unit length field depending on the DWARF format.
+inline uint8_t getUnitLengthFieldByteSize(DwarfFormat Format) {
+  switch (Format) {
+  case DwarfFormat::DWARF32:
+    return 4;
+  case DwarfFormat::DWARF64:
+    return 12;
+  }
+  llvm_unreachable("Invalid Format value");
+}
+
 /// Get the fixed byte size for a given form.
 ///
 /// If the form has a fixed byte size, then an Optional with a value will be

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h?rev=369356&r1=369355&r2=369356&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h Tue Aug 20 02:50:44 2019
@@ -97,10 +97,11 @@ public:
     return UnitType == dwarf::DW_UT_type || UnitType == dwarf::DW_UT_split_type;
   }
   uint8_t getSize() const { return Size; }
+  uint8_t getUnitLengthFieldByteSize() const {
+    return dwarf::getUnitLengthFieldByteSize(FormParams.Format);
+  }
   uint64_t getNextUnitOffset() const {
-    return Offset + Length +
-           (FormParams.Format == llvm::dwarf::DwarfFormat::DWARF64 ? 4 : 0) +
-           FormParams.getDwarfOffsetByteSize();
+    return Offset + Length + getUnitLengthFieldByteSize();
   }
 };
 
@@ -501,7 +502,8 @@ public:
 private:
   /// Size in bytes of the .debug_info data associated with this compile unit.
   size_t getDebugInfoSize() const {
-    return Header.getLength() + 4 - getHeaderSize();
+    return Header.getLength() + Header.getUnitLengthFieldByteSize() -
+           getHeaderSize();
   }
 
   /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it

Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_info_min_dwarf64.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_info_min_dwarf64.s?rev=369356&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_info_min_dwarf64.s (added)
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_info_min_dwarf64.s Tue Aug 20 02:50:44 2019
@@ -0,0 +1,37 @@
+# RUN: llvm-mc %s -filetype obj -triple x86_64-unknown-elf -o - | \
+# RUN:   llvm-dwarfdump -debug-info - | \
+# RUN:   FileCheck %s
+
+        .section .debug_abbrev,"", at progbits
+        .byte 0x01  # Abbrev code
+        .byte 0x11  # DW_TAG_compile_unit
+        .byte 0x00  # DW_CHILDREN_no
+        .byte 0x13  # DW_AT_language
+        .byte 0x05  # DW_FORM_data2
+        .byte 0x00  # EOM(1)
+        .byte 0x00  # EOM(2)
+        .byte 0x00  # EOM(3)
+        
+        .section .debug_info,"", at progbits
+# CHECK: .debug_info contents:
+# CHECK-NEXT: 0x00000000: Compile Unit:
+DI_4_64_start:
+        .long 0xffffffff       # DWARF64 mark
+        .quad DI_4_64_end - DI_4_64_version # Length of Unit
+# CHECK-SAME: length = 0x0000000f
+DI_4_64_version:
+        .short 4               # DWARF version number
+# CHECK-SAME: version = 0x0004
+        .quad .debug_abbrev    # Offset Into Abbrev. Section
+# CHECK-SAME: abbr_offset = 0x0000
+        .byte 8                # Address Size (in bytes)
+# CHECK-SAME: addr_size = 0x08
+# CHECK-SAME: (next unit at 0x0000001b)
+
+        .byte 1                # Abbreviation code
+# CHECK: 0x00000017: DW_TAG_compile_unit
+        .short 4               # DW_LANG_C_plus_plus
+# CHECK-NEXT: DW_AT_language (DW_LANG_C_plus_plus)
+        .byte 0                # NULL
+DI_4_64_end:
+




More information about the llvm-commits mailing list