diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h @@ -25,6 +25,8 @@ /// The total length of the entries for that set, not including the length /// field itself. uint64_t Length; + /// The DWARF format of the set. + dwarf::DwarfFormat Format; /// The offset from the beginning of the .debug_info section of the /// compilation unit entry referenced by the table. uint64_t CuOffset; diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp @@ -60,12 +60,12 @@ // the segment selectors are omitted from all tuples, including // the terminating tuple. - dwarf::DwarfFormat format; Error Err = Error::success(); - std::tie(HeaderData.Length, format) = data.getInitialLength(offset_ptr, &Err); + std::tie(HeaderData.Length, HeaderData.Format) = + data.getInitialLength(offset_ptr, &Err); HeaderData.Version = data.getU16(offset_ptr, &Err); - HeaderData.CuOffset = - data.getUnsigned(offset_ptr, dwarf::getDwarfOffsetByteSize(format), &Err); + HeaderData.CuOffset = data.getUnsigned( + offset_ptr, dwarf::getDwarfOffsetByteSize(HeaderData.Format), &Err); HeaderData.AddrSize = data.getU8(offset_ptr, &Err); HeaderData.SegSize = data.getU8(offset_ptr, &Err); if (Err) { @@ -77,7 +77,7 @@ // Perform basic validation of the header fields. uint64_t full_length = - dwarf::getUnitLengthFieldByteSize(format) + HeaderData.Length; + dwarf::getUnitLengthFieldByteSize(HeaderData.Format) + HeaderData.Length; if (!data.isValidOffsetForDataOfSize(Offset, full_length)) return createStringError(errc::invalid_argument, "the length of address range table at offset " @@ -157,10 +157,12 @@ } void DWARFDebugArangeSet::dump(raw_ostream &OS) const { + int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(HeaderData.Format); OS << "Address Range Header: " - << format("length = 0x%8.8" PRIx64 ", ", HeaderData.Length) + << format("length = 0x%0*" PRIx64 ", ", OffsetDumpWidth, HeaderData.Length) << format("version = 0x%4.4x, ", HeaderData.Version) - << format("cu_offset = 0x%8.8" PRIx64 ", ", HeaderData.CuOffset) + << format("cu_offset = 0x%0*" PRIx64 ", ", OffsetDumpWidth, + HeaderData.CuOffset) << format("addr_size = 0x%2.2x, ", HeaderData.AddrSize) << format("seg_size = 0x%2.2x\n", HeaderData.SegSize); diff --git a/llvm/test/DebugInfo/X86/dwarfdump-debug-aranges.s b/llvm/test/DebugInfo/X86/dwarfdump-debug-aranges.s --- a/llvm/test/DebugInfo/X86/dwarfdump-debug-aranges.s +++ b/llvm/test/DebugInfo/X86/dwarfdump-debug-aranges.s @@ -28,11 +28,11 @@ # CHECK: Address Range Header: length = 0x0000001c, .L2version: .short 2 # Version - .long 0x11223344 # Debug Info Offset + .long 0x112233 # Debug Info Offset .byte 4 # Address Size .byte 0 # Segment Selector Size # CHECK-SAME: version = 0x0002, -# CHECK-SAME: cu_offset = 0x11223344, +# CHECK-SAME: cu_offset = 0x00112233, # CHECK-SAME: addr_size = 0x04, # CHECK-SAME: seg_size = 0x00 .space 4 # Padding @@ -48,11 +48,11 @@ # CHECK: Address Range Header: length = 0x0000002c, .L3version: .short 2 # Version - .long 0x22334455 # Debug Info Offset + .long 0x112233 # Debug Info Offset .byte 8 # Address Size .byte 0 # Segment Selector Size # CHECK-SAME: version = 0x0002, -# CHECK-SAME: cu_offset = 0x22334455, +# CHECK-SAME: cu_offset = 0x00112233, # CHECK-SAME: addr_size = 0x08, # CHECK-SAME: seg_size = 0x00 .space 4 # Padding @@ -67,14 +67,14 @@ ## Case 4: Check that 64-bit DWARF format is supported. .long 0xffffffff # DWARF64 mark .quad .L4end - .L4version # Length -# CHECK: Address Range Header: length = 0x0000001c, +# CHECK: Address Range Header: length = 0x000000000000001c, .L4version: .short 2 # Version - .quad 0x1234567899aabbcc # Debug Info Offset + .quad 0x123456789abc # Debug Info Offset .byte 4 # Address Size .byte 0 # Segment Selector Size # CHECK-SAME: version = 0x0002, -# CHECK-SAME: cu_offset = 0x1234567899aabbcc, +# CHECK-SAME: cu_offset = 0x0000123456789abc, # CHECK-SAME: addr_size = 0x04, # CHECK-SAME: seg_size = 0x00 # No padding