From ee1b58a9626be7ab1e922ba3add68f884377a6f6 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 24 May 2019 01:41:58 +0000 Subject: [PATCH] dwarfdump: Deterministically... determine whether parsing a DWARF32 or DWARF64 str_offsets header Rather than trying one and then the other - use the kind of the CU to select which kind of header to parse. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361589 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/DebugInfo/DWARF/DWARFUnit.cpp | 13 ++++++++++--- test/DebugInfo/X86/dwarfdump-str-offsets-macho.s | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/DebugInfo/DWARF/DWARFUnit.cpp b/lib/DebugInfo/DWARF/DWARFUnit.cpp index 7bc52215490..fa165cf2d40 100644 --- a/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -811,12 +811,19 @@ DWARFUnit::determineStringOffsetsTableContribution(DWARFDataExtractor &DA) { auto Offset = toSectionOffset(getUnitDIE().find(DW_AT_str_offsets_base), 0); Optional Descriptor; // Attempt to find a DWARF64 contribution 16 bytes before the base. - if (Offset >= 16) + switch (Header.getFormat()) { + case dwarf::DwarfFormat::DWARF64: + if (Offset < 16) + return None; Descriptor = parseDWARF64StringOffsetsTableHeader(DA, (uint32_t)Offset - 16); - // Try to find a DWARF32 contribution 8 bytes before the base. - if (!Descriptor && Offset >= 8) + break; + case dwarf::DwarfFormat::DWARF32: + if (Offset < 8) + return None; Descriptor = parseDWARF32StringOffsetsTableHeader(DA, (uint32_t)Offset - 8); + break; + } return Descriptor ? Descriptor->validateContributionSize(DA) : Descriptor; } diff --git a/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s b/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s index 1332a94ec3c..10a810a350d 100644 --- a/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s +++ b/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s @@ -160,18 +160,19 @@ CU1_5_version: CU1_5_end: # DWARF v5 CU header - .long CU2_5_end-CU2_5_version # Length of Unit + .long 0xffffffff + .quad CU2_5_end-CU2_5_version # Length of Unit CU2_5_version: .short 5 # DWARF version number .byte 1 # DWARF Unit Type .byte 8 # Address Size (in bytes) - .long 0 # Offset Into Abbrev. Section + .quad 0 # Offset Into Abbrev. Section # The compile-unit DIE, which has a DW_AT_producer, DW_AT_name, # DW_AT_str_offsets and DW_AT_compdir. .byte 1 # Abbreviation code .byte 0 # The index of the producer string .byte 1 # The index of the CU name string - .long Ldebug_str_offsets_base1-Ldebug_str_offsets + .quad Ldebug_str_offsets_base1-Ldebug_str_offsets .byte 2 # The index of the comp dir string .byte 0 # NULL CU2_5_end: -- 2.50.1