From 727c590fe955409fa59d89657b5f7e42d38326e2 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 27 Apr 2022 21:17:01 +0000 Subject: [PATCH] DebugInfo: Use hash-based unit lookup when available in dwp files Fix a test case that had a bogus (probably I hand crafted it at some point) index that didn't point to the right data in the process. --- llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp | 9 ++++++++- llvm/test/DebugInfo/X86/dwarfdump-str-offsets-dwp.s | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp index b91e268..3f554e3 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -83,7 +83,14 @@ void DWARFUnitVector::addUnitsImpl( if (!IndexEntry && IsDWO) { const DWARFUnitIndex &Index = getDWARFUnitIndex( Context, Header.isTypeUnit() ? DW_SECT_EXT_TYPES : DW_SECT_INFO); - IndexEntry = Index.getFromOffset(Header.getOffset()); + if (Index) { + if (Header.isTypeUnit()) + IndexEntry = Index.getFromHash(Header.getTypeHash()); + else if (auto DWOId = Header.getDWOId()) + IndexEntry = Index.getFromHash(*DWOId); + } + if (!IndexEntry) + IndexEntry = Index.getFromOffset(Header.getOffset()); } if (IndexEntry && !Header.applyIndexEntry(IndexEntry)) return nullptr; diff --git a/llvm/test/DebugInfo/X86/dwarfdump-str-offsets-dwp.s b/llvm/test/DebugInfo/X86/dwarfdump-str-offsets-dwp.s index 9bbd4d7..c5350a1 100644 --- a/llvm/test/DebugInfo/X86/dwarfdump-str-offsets-dwp.s +++ b/llvm/test/DebugInfo/X86/dwarfdump-str-offsets-dwp.s @@ -171,7 +171,7 @@ TU1_5_version: .byte 2 # DWARF Unit Type .byte 8 # Address Size (in bytes) .long .debug_abbrev.dwo # Offset Into Abbrev. Section - .quad 0x0011223344556677 # Type Signature + .quad 0xeeaaddbbaabbeedd # Type Signature .long TU1_5_type-TU1_5_start # Type offset # The type-unit DIE, which has a name. .byte 2 # Abbreviation code @@ -191,7 +191,7 @@ TU2_5_version: .byte 2 # DWARF Unit Type .byte 8 # Address Size (in bytes) .long .debug_abbrev.dwo # Offset Into Abbrev. Section - .quad 0x00aabbccddeeff99 # Type Signature + .quad 0x00ffeeffaaff00ff # Type Signature .long TU2_5_type-TU2_5_start # Type offset # The type-unit DIE, which has a name. .byte 2 # Abbreviation code -- 2.7.4