Index: lit/SymbolFile/DWARF/array-sizes.s =================================================================== --- lit/SymbolFile/DWARF/array-sizes.s +++ lit/SymbolFile/DWARF/array-sizes.s @@ -9,8 +9,8 @@ # RUN: ld.lld %t.o -o %t # RUN: lldb-test symbols %t | FileCheck %s -# CHECK: Variable{0xffffffff0000001e}, name = "X" -# CHECK-SAME: type = {ffffffff00000033} 0x{{[0-9a-f]*}} (char [56]) +# CHECK: Variable{0x7fffffff0000001e}, name = "X" +# CHECK-SAME: type = {7fffffff00000033} 0x{{[0-9a-f]*}} (char [56]) # Generated from "char X[47];" Index: lit/SymbolFile/DWARF/dwarf5_locations.s =================================================================== --- lit/SymbolFile/DWARF/dwarf5_locations.s +++ lit/SymbolFile/DWARF/dwarf5_locations.s @@ -4,7 +4,7 @@ # RUN: ld.lld -m elf_x86_64 %t.o -o %t # RUN: lldb-test symbols %t | FileCheck %s -# CHECK: Variable{0xffffffff00000011}, name = "color" +# CHECK: Variable{0x7fffffff00000011}, name = "color" # CHECK-SAME: location = DW_OP_addrx(0x0) .text Index: source/Plugins/SymbolFile/DWARF/DIERef.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DIERef.h +++ source/Plugins/SymbolFile/DWARF/DIERef.h @@ -16,9 +16,12 @@ class SymbolFileDWARF; struct DIERef { + enum Section : uint8_t { DebugInfo, DebugTypes }; + DIERef() = default; - DIERef(dw_offset_t c, dw_offset_t d) : cu_offset(c), die_offset(d) {} + DIERef(Section s, dw_offset_t c, dw_offset_t d) + : section(s), cu_offset(c), die_offset(d) {} explicit DIERef(const DWARFFormValue &form_value); @@ -30,6 +33,7 @@ return cu_offset != DW_INVALID_OFFSET || die_offset != DW_INVALID_OFFSET; } + Section section = Section::DebugInfo; dw_offset_t cu_offset = DW_INVALID_OFFSET; dw_offset_t die_offset = DW_INVALID_OFFSET; }; Index: source/Plugins/SymbolFile/DWARF/DIERef.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DIERef.cpp +++ source/Plugins/SymbolFile/DWARF/DIERef.cpp @@ -13,10 +13,10 @@ #include "SymbolFileDWARF.h" #include "SymbolFileDWARFDebugMap.h" -DIERef::DIERef(const DWARFFormValue &form_value) - : cu_offset(DW_INVALID_OFFSET), die_offset(DW_INVALID_OFFSET) { +DIERef::DIERef(const DWARFFormValue &form_value) { if (form_value.IsValid()) { if (const DWARFUnit *unit = form_value.GetUnit()) { + section = unit->GetDebugSection(); if (unit->GetBaseObjOffset() != DW_INVALID_OFFSET) cu_offset = unit->GetBaseObjOffset(); else Index: source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp @@ -24,7 +24,7 @@ dw_offset_t cu_offset = m_cu->GetOffset(); if (m_cu->GetBaseObjOffset() != DW_INVALID_OFFSET) cu_offset = m_cu->GetBaseObjOffset(); - return DIERef(cu_offset, m_die->GetOffset()); + return DIERef(m_cu->GetDebugSection(), cu_offset, m_die->GetOffset()); } dw_tag_t DWARFBaseDIE::Tag() const { Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h +++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h @@ -34,6 +34,10 @@ /// Byte size of the compile unit header uint32_t GetHeaderByteSize() const override; + DIERef::Section GetDebugSection() const override { + return DIERef::Section::DebugInfo; + } + private: DWARFCompileUnit(SymbolFileDWARF *dwarf2Data, lldb::user_id_t uid); DISALLOW_COPY_AND_ASSIGN(DWARFCompileUnit); Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -155,7 +155,8 @@ return DWARFDIE(cu, block_die); else return DWARFDIE(dwarf->DebugInfo()->GetUnit( - DIERef(cu->GetOffset(), block_die->GetOffset())), + DIERef(cu->GetDebugSection(), cu->GetOffset(), + block_die->GetOffset())), block_die); } } Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h @@ -41,10 +41,13 @@ size_t GetNumUnits(); DWARFUnit *GetUnitAtIndex(lldb::user_id_t idx); - DWARFUnit *GetUnitAtOffset(dw_offset_t cu_offset, uint32_t *idx_ptr = NULL); - DWARFUnit *GetUnitContainingDIEOffset(dw_offset_t die_offset); + DWARFUnit *GetUnitAtOffset(DIERef::Section section, + dw_offset_t cu_offset, uint32_t *idx_ptr = NULL); + DWARFUnit *GetUnitContainingDIEOffset(DIERef::Section section, + dw_offset_t die_offset); DWARFUnit *GetUnit(const DIERef &die_ref); - DWARFDIE GetDIEForDIEOffset(dw_offset_t die_offset); + DWARFDIE GetDIEForDIEOffset(DIERef::Section section, + dw_offset_t die_offset); DWARFDIE GetDIE(const DIERef &die_ref); enum { @@ -57,9 +60,6 @@ llvm::Expected GetCompileUnitAranges(); protected: - static bool OffsetLessThanUnitOffset(dw_offset_t offset, - const DWARFUnitSP &cu_sp); - typedef std::vector UnitColl; // Member variables @@ -74,7 +74,7 @@ // accessors are called. void ParseUnitHeadersIfNeeded(); - uint32_t FindUnitIndex(dw_offset_t offset); + uint32_t FindUnitIndex(DIERef::Section section, dw_offset_t offset); DISALLOW_COPY_AND_ASSIGN(DWARFDebugInfo); }; Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -116,26 +116,28 @@ return cu; } -bool DWARFDebugInfo::OffsetLessThanUnitOffset(dw_offset_t offset, - const DWARFUnitSP &cu_sp) { - return offset < cu_sp->GetOffset(); -} - -uint32_t DWARFDebugInfo::FindUnitIndex(dw_offset_t offset) { +uint32_t DWARFDebugInfo::FindUnitIndex(DIERef::Section section, + dw_offset_t offset) { ParseUnitHeadersIfNeeded(); // llvm::lower_bound is not used as for DIE offsets it would still return // index +1 and GetOffset() returning index itself would be a special case. - auto pos = llvm::upper_bound(m_units, offset, OffsetLessThanUnitOffset); + auto pos = llvm::upper_bound( + m_units, std::make_pair(section, offset), + [](const std::pair &lhs, + const DWARFUnitSP &rhs) { + return lhs < std::make_pair(rhs->GetDebugSection(), rhs->GetOffset()); + }); uint32_t idx = std::distance(m_units.begin(), pos); if (idx == 0) return DW_INVALID_OFFSET; return idx - 1; } -DWARFUnit *DWARFDebugInfo::GetUnitAtOffset(dw_offset_t cu_offset, +DWARFUnit *DWARFDebugInfo::GetUnitAtOffset(DIERef::Section section, + dw_offset_t cu_offset, uint32_t *idx_ptr) { - uint32_t idx = FindUnitIndex(cu_offset); + uint32_t idx = FindUnitIndex(section, cu_offset); DWARFUnit *result = GetUnitAtIndex(idx); if (result && result->GetOffset() != cu_offset) { result = nullptr; @@ -148,13 +150,15 @@ DWARFUnit *DWARFDebugInfo::GetUnit(const DIERef &die_ref) { if (die_ref.cu_offset == DW_INVALID_OFFSET) - return GetUnitContainingDIEOffset(die_ref.die_offset); + return GetUnitContainingDIEOffset(die_ref.section, die_ref.die_offset); else - return GetUnitAtOffset(die_ref.cu_offset); + return GetUnitAtOffset(die_ref.section, die_ref.cu_offset); } -DWARFUnit *DWARFDebugInfo::GetUnitContainingDIEOffset(dw_offset_t die_offset) { - uint32_t idx = FindUnitIndex(die_offset); +DWARFUnit * +DWARFDebugInfo::GetUnitContainingDIEOffset(DIERef::Section section, + dw_offset_t die_offset) { + uint32_t idx = FindUnitIndex(section, die_offset); DWARFUnit *result = GetUnitAtIndex(idx); if (result && !result->ContainsDIEOffset(die_offset)) return nullptr; @@ -162,8 +166,9 @@ } DWARFDIE -DWARFDebugInfo::GetDIEForDIEOffset(dw_offset_t die_offset) { - DWARFUnit *cu = GetUnitContainingDIEOffset(die_offset); +DWARFDebugInfo::GetDIEForDIEOffset(DIERef::Section section, + dw_offset_t die_offset) { + DWARFUnit *cu = GetUnitContainingDIEOffset(section, die_offset); if (cu) return cu->GetDIE(die_offset); return DWARFDIE(); Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h @@ -167,6 +167,8 @@ return die_iterator_range(m_die_array.begin(), m_die_array.end()); } + virtual DIERef::Section GetDebugSection() const = 0; + protected: DWARFUnit(SymbolFileDWARF *dwarf, lldb::user_id_t uid); Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -545,7 +545,8 @@ // Don't specify the compile unit offset as we don't know it because the // DIE belongs to // a different compile unit in the same symbol file. - return m_dwarf->DebugInfo()->GetDIEForDIEOffset(die_offset); + return m_dwarf->DebugInfo()->GetDIEForDIEOffset(GetDebugSection(), + die_offset); } } return DWARFDIE(); // Not found Index: source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -55,7 +55,7 @@ if (!cu_offset) return DIERef(); - DWARFUnit *cu = m_debug_info.GetUnitAtOffset(*cu_offset); + DWARFUnit *cu = m_debug_info.GetUnitAtOffset(DIERef::Section::DebugInfo, *cu_offset); if (!cu) return DIERef(); @@ -66,7 +66,7 @@ uint64_t die_bias = cu->GetDwoSymbolFile() ? 0 : *cu_offset; if (llvm::Optional die_offset = entry.getDIEUnitOffset()) - return DIERef(*cu_offset, die_bias + *die_offset); + return DIERef(DIERef::Section::DebugInfo, *cu_offset, die_bias + *die_offset); return DIERef(); } @@ -164,7 +164,8 @@ if (!ref) continue; - DWARFUnit *cu = m_debug_info.GetUnitAtOffset(ref.cu_offset); + DWARFUnit *cu = + m_debug_info.GetUnitAtOffset(DIERef::Section::DebugInfo, ref.cu_offset); if (!cu || !cu->Supports_DW_AT_APPLE_objc_complete_type()) { incomplete_types.push_back(ref); continue; Index: source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h =================================================================== --- source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h +++ source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h @@ -48,8 +48,7 @@ }; struct DIEInfo { - dw_offset_t cu_offset; - dw_offset_t offset; // The DIE offset + DIERef die_ref; dw_tag_t tag; uint32_t type_flags; // Any flags for this DIEInfo uint32_t qualified_name_hash; // A 32 bit hash of the fully qualified name @@ -57,7 +56,7 @@ DIEInfo(); DIEInfo(dw_offset_t c, dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h); - explicit operator DIERef() const { return {cu_offset, offset}; } + explicit operator DIERef() const { return die_ref; } }; struct Atom { Index: source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp +++ source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp @@ -78,8 +78,7 @@ return; } else { // Put the one true definition as the first entry so it matches first - die_offsets.emplace(die_offsets.begin(), die_info_array[i].cu_offset, - die_info_array[i].offset); + die_offsets.emplace(die_offsets.begin(), die_info_array[i]); } } else { die_offsets.emplace_back(die_info_array[i]); @@ -119,12 +118,12 @@ } DWARFMappedHash::DIEInfo::DIEInfo() - : cu_offset(DW_INVALID_OFFSET), offset(DW_INVALID_OFFSET), tag(0), - type_flags(0), qualified_name_hash(0) {} + : tag(0), type_flags(0), qualified_name_hash(0) {} DWARFMappedHash::DIEInfo::DIEInfo(dw_offset_t c, dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h) - : cu_offset(c), offset(o), tag(t), type_flags(f), qualified_name_hash(h) {} + : die_ref(DIERef::Section::DebugInfo, c, o), tag(t), type_flags(f), + qualified_name_hash(h) {} DWARFMappedHash::Prologue::Prologue(dw_offset_t _die_base_offset) : die_base_offset(_die_base_offset), atoms(), atom_mask(0), @@ -272,7 +271,7 @@ switch (header_data.atoms[i].type) { case eAtomTypeDIEOffset: // DIE offset, check form for encoding - hash_data.offset = + hash_data.die_ref.die_offset = DWARFFormValue::IsDataForm(form_value.Form()) ? form_value.Unsigned() : form_value.Reference(header_data.die_base_offset); @@ -507,10 +506,10 @@ for (uint32_t i = 0; i < count; ++i) { DIEInfo die_info; if (m_header.Read(m_data, &hash_data_offset, die_info)) { - if (die_info.offset == 0) + if (die_info.die_ref.die_offset == 0) done = true; - if (die_offset_start <= die_info.offset && - die_info.offset < die_offset_end) + if (die_offset_start <= die_info.die_ref.die_offset && + die_info.die_ref.die_offset < die_offset_end) die_info_array.push_back(die_info); } } Index: source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -245,7 +245,7 @@ } } - DIERef ref(cu_offset, die.GetOffset()); + DIERef ref(unit.GetDebugSection(), cu_offset, die.GetOffset()); switch (tag) { case DW_TAG_inlined_subroutine: case DW_TAG_subprogram: Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -287,10 +287,13 @@ DWARFDIE GetDIE(lldb::user_id_t uid); lldb::user_id_t GetUID(const DWARFBaseDIE &die) { - return GetID() | die.GetOffset(); + return GetUID(die.GetDIERef()); } - lldb::user_id_t GetUID(const DIERef &ref) { return GetID() | ref.die_offset; } + lldb::user_id_t GetUID(const DIERef &ref) { + return GetID() | ref.die_offset | + (lldb::user_id_t(ref.section == DIERef::Section::DebugTypes) << 63); + } virtual std::unique_ptr GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu, Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -349,10 +349,10 @@ } SymbolFileDWARF::SymbolFileDWARF(ObjectFile *objfile) - : SymbolFile(objfile), UserID(uint64_t(DW_INVALID_OFFSET) - << 32), // Used by SymbolFileDWARFDebugMap to - // when this class parses .o files to - // contain the .o file index/ID + : SymbolFile(objfile), + UserID(0x7fffffff00000000), // Used by SymbolFileDWARFDebugMap to + // when this class parses .o files to + // contain the .o file index/ID m_debug_map_module_wp(), m_debug_map_symfile(NULL), m_context(*objfile->GetModule()), m_data_debug_abbrev(), m_data_debug_frame(), m_data_debug_info(), m_data_debug_line(), @@ -1257,9 +1257,11 @@ if (SymbolFileDWARFDebugMap *debug_map = GetDebugMapSymfile()) { SymbolFileDWARF *dwarf = debug_map->GetSymbolFileByOSOIndex( debug_map->GetOSOIndexFromUserID(uid)); - return {dwarf, {DW_INVALID_OFFSET, dw_offset_t(uid)}}; + return {dwarf, {DIERef::Section::DebugInfo, DW_INVALID_OFFSET, dw_offset_t(uid)}}; } - uint32_t dwarf_id = uid >> 32; + DIERef::Section section = + uid >> 63 ? DIERef::Section::DebugTypes : DIERef::Section::DebugInfo; + uint32_t dwarf_id = uid >> 32 & 0x7fffffff; dw_offset_t die_offset = uid; if (die_offset == DW_INVALID_OFFSET) @@ -1272,7 +1274,7 @@ dwarf = unit->GetDwoSymbolFile(); } } - return {dwarf, {DW_INVALID_OFFSET, die_offset}}; + return {dwarf, {section, DW_INVALID_OFFSET, die_offset}}; } DWARFDIE @@ -1765,7 +1767,8 @@ } } else { uint32_t cu_idx = DW_INVALID_INDEX; - DWARFUnit *dwarf_cu = debug_info->GetUnitAtOffset(cu_offset, &cu_idx); + DWARFUnit *dwarf_cu = debug_info->GetUnitAtOffset(DIERef::Section::DebugInfo, + cu_offset, &cu_idx); if (dwarf_cu) { sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); if (sc.comp_unit) { Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp @@ -160,5 +160,5 @@ SymbolFileDWARFDwo::GetDIE(const DIERef &die_ref) { lldbassert(die_ref.cu_offset == m_base_dwarf_cu->GetOffset() || die_ref.cu_offset == DW_INVALID_OFFSET); - return DebugInfo()->GetDIEForDIEOffset(die_ref.die_offset); + return DebugInfo()->GetDIEForDIEOffset(die_ref.section, die_ref.die_offset); }