diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1398,11 +1398,11 @@ user_id_t SymbolFileDWARF::GetUID(DIERef ref) { if (GetDebugMapSymfile()) - return GetID() | ref.die_offset(); + return GetDebugMapSymfile()->GetUID({*this, ref}); - lldbassert(GetDwoNum().value_or(0) <= 0x3fffffff); - return user_id_t(GetDwoNum().value_or(0)) << 32 | ref.die_offset() | - lldb::user_id_t(GetDwoNum().has_value()) << 62 | + lldbassert(ref.dwo_num().value_or(0) <= 0x3fffffff); + return user_id_t(ref.dwo_num().value_or(0)) << 32 | ref.die_offset() | + lldb::user_id_t(ref.dwo_num().has_value()) << 62 | lldb::user_id_t(ref.section() == DIERef::Section::DebugTypes) << 63; } @@ -1419,10 +1419,7 @@ // "lldb::user_id_t" that specifies a DIE from another SymbolFileDWARF // instance. if (SymbolFileDWARFDebugMap *debug_map = GetDebugMapSymfile()) { - SymbolFileDWARF *dwarf = debug_map->GetSymbolFileByOSOIndex( - debug_map->GetOSOIndexFromUserID(uid)); - return DecodedUID{ - *dwarf, {std::nullopt, DIERef::Section::DebugInfo, dw_offset_t(uid)}}; + return debug_map->DecodeUID(uid); } dw_offset_t die_offset = uid; if (die_offset == DW_INVALID_OFFSET) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h @@ -16,9 +16,9 @@ #include #include +#include "SymbolFileDWARF.h" #include "UniqueDWARFASTType.h" -class SymbolFileDWARF; class DWARFCompileUnit; class DWARFDebugAranges; class DWARFDeclContext; @@ -207,9 +207,9 @@ /// the given index contains. lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; - static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid) { - return (uint32_t)((uid >> 32ull) - 1ull); - } + lldb::user_id_t GetUID(SymbolFileDWARF::DecodedUID decoded_uid); + + llvm::Optional DecodeUID(lldb::user_id_t uid); static SymbolFileDWARF *GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -210,7 +210,7 @@ // Set the ID of the symbol file DWARF to the index of the OSO // shifted left by 32 bits to provide a unique prefix for any // UserID's that get created in the symbol file. - oso_symfile->SetID(((uint64_t)m_cu_idx + 1ull) << 32ull); + oso_symfile->SetID(m_cu_idx + 1); } return symfile; } @@ -768,6 +768,26 @@ return 0; } +static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid) { + return static_cast((uid >> 32) - 1); +} + +user_id_t +SymbolFileDWARFDebugMap::GetUID(SymbolFileDWARF::DecodedUID decoded_uid) { + return ((static_cast(decoded_uid.dwarf.GetID()) + 1) << 32) | + decoded_uid.ref.die_offset(); +} + +llvm::Optional +SymbolFileDWARFDebugMap::DecodeUID(user_id_t uid) { + if (SymbolFileDWARF *dwarf = + GetSymbolFileByOSOIndex(GetOSOIndexFromUserID(uid))) { + return SymbolFileDWARF::DecodedUID{ + *dwarf, {std::nullopt, DIERef::Section::DebugInfo, dw_offset_t(uid)}}; + } + return std::nullopt; +} + Type *SymbolFileDWARFDebugMap::ResolveTypeUID(lldb::user_id_t type_uid) { std::lock_guard guard(GetModuleMutex()); const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h @@ -40,7 +40,7 @@ DWARFDIE GetDIE(const DIERef &die_ref) override; - llvm::Optional GetDwoNum() override { return GetID() >> 32; } + llvm::Optional GetDwoNum() override { return GetID(); } lldb::offset_t GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp @@ -28,7 +28,7 @@ : SymbolFileDWARF(objfile, objfile->GetSectionList( /*update_module_section_list*/ false)), m_base_symbol_file(base_symbol_file) { - SetID(user_id_t(id) << 32); + SetID(id); // Parsing of the dwarf unit index is not thread-safe, so we need to prime it // to enable subsequent concurrent lookups.