Index: lldb/trunk/lit/SymbolFile/DWARF/find-variable-file.cpp =================================================================== --- lldb/trunk/lit/SymbolFile/DWARF/find-variable-file.cpp +++ lldb/trunk/lit/SymbolFile/DWARF/find-variable-file.cpp @@ -8,6 +8,16 @@ // RUN: lldb-test symbols --file=find-variable-file-2.cpp --find=variable %t | \ // RUN: FileCheck --check-prefix=TWO %s +// Run the same test with split-dwarf. This is interesting because the two +// split compile units will have the same offset (0). +// RUN: %clang -g -c -o %t-1.o --target=x86_64-pc-linux -gsplit-dwarf %s +// RUN: %clang -g -c -o %t-2.o --target=x86_64-pc-linux -gsplit-dwarf %S/Inputs/find-variable-file-2.cpp +// RUN: ld.lld %t-1.o %t-2.o -o %t +// RUN: lldb-test symbols --file=find-variable-file.cpp --find=variable %t | \ +// RUN: FileCheck --check-prefix=ONE %s +// RUN: lldb-test symbols --file=find-variable-file-2.cpp --find=variable %t | \ +// RUN: FileCheck --check-prefix=TWO %s + // RUN: %clang -g -c -o %t-1.o --target=x86_64-pc-linux -mllvm -accel-tables=Dwarf %s // RUN: %clang -g -c -o %t-2.o --target=x86_64-pc-linux -mllvm -accel-tables=Dwarf %S/Inputs/find-variable-file-2.cpp // RUN: ld.lld %t-1.o %t-2.o -o %t Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h @@ -42,7 +42,7 @@ void GetTypes(ConstString name, DIEArray &offsets) override; void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) override; void GetNamespaces(ConstString name, DIEArray &offsets) override; - void GetFunctions(ConstString name, DWARFDebugInfo &info, + void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, std::vector &dies) override; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "Plugins/SymbolFile/DWARF/AppleDWARFIndex.h" -#include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h" #include "Plugins/SymbolFile/DWARF/DWARFDeclContext.h" #include "Plugins/SymbolFile/DWARF/DWARFUnit.h" #include "Plugins/SymbolFile/DWARF/LogChannelDWARF.h" @@ -133,14 +132,14 @@ m_apple_namespaces_up->FindByName(name.GetStringRef(), offsets); } -void AppleDWARFIndex::GetFunctions(ConstString name, DWARFDebugInfo &info, +void AppleDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, std::vector &dies) { DIEArray offsets; m_apple_names_up->FindByName(name.GetStringRef(), offsets); for (const DIERef &die_ref : offsets) { - ProcessFunctionDIE(name.GetStringRef(), die_ref, info, parent_decl_ctx, + ProcessFunctionDIE(name.GetStringRef(), die_ref, dwarf, parent_decl_ctx, name_type_mask, dies); } } Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.h @@ -12,42 +12,45 @@ #include "lldb/Core/dwarf.h" #include "llvm/ADT/Optional.h" #include "llvm/Support/FormatProviders.h" +#include #include /// Identifies a DWARF debug info entry within a given Module. It contains three /// "coordinates": -/// - section: identifies the section of the debug info entry: debug_info or -/// debug_types -/// - unit_offset: the offset of the unit containing the debug info entry. For -/// regular (unsplit) units, this field is optional, as the die_offset is -/// enough to uniquely identify the containing unit. For split units, this -/// field must contain the offset of the skeleton unit in the main object -/// file. -/// - die_offset: The offset of te debug info entry as an absolute offset from +/// - dwo_num: identifies the dwo file in the Module. If this field is not set, +/// the DIERef references the main file. +/// - section: identifies the section of the debug info entry in the given file: +/// debug_info or debug_types. +/// - die_offset: The offset of the debug info entry as an absolute offset from /// the beginning of the section specified in the section field. class DIERef { public: enum Section : uint8_t { DebugInfo, DebugTypes }; - DIERef(Section s, llvm::Optional u, dw_offset_t d) - : m_section(s), m_unit_offset(u.getValueOr(DW_INVALID_OFFSET)), - m_die_offset(d) {} - - Section section() const { return static_cast
(m_section); } + DIERef(llvm::Optional dwo_num, Section section, + dw_offset_t die_offset) + : m_dwo_num(dwo_num.getValueOr(0)), m_dwo_num_valid(bool(dwo_num)), + m_section(section), m_die_offset(die_offset) { + assert(this->dwo_num() == dwo_num && "Dwo number out of range?"); + } - llvm::Optional unit_offset() const { - if (m_unit_offset != DW_INVALID_OFFSET) - return m_unit_offset; + llvm::Optional dwo_num() const { + if (m_dwo_num_valid) + return m_dwo_num; return llvm::None; } + Section section() const { return static_cast
(m_section); } + dw_offset_t die_offset() const { return m_die_offset; } private: - unsigned m_section : 1; - dw_offset_t m_unit_offset; + uint32_t m_dwo_num : 30; + uint32_t m_dwo_num_valid : 1; + uint32_t m_section : 1; dw_offset_t m_die_offset; }; +static_assert(sizeof(DIERef) == 8, ""); typedef std::vector DIEArray; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DIERef.cpp @@ -11,8 +11,8 @@ void llvm::format_provider::format(const DIERef &ref, raw_ostream &OS, StringRef Style) { + if (ref.dwo_num()) + OS << format_hex_no_prefix(*ref.dwo_num(), 8) << "/"; OS << (ref.section() == DIERef::DebugInfo ? "INFO" : "TYPE"); - if (ref.unit_offset()) - OS << "/" << format_hex_no_prefix(*ref.unit_offset(), 8); OS << "/" << format_hex_no_prefix(ref.die_offset(), 8); } Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp @@ -21,10 +21,8 @@ if (!IsValid()) return llvm::None; - dw_offset_t cu_offset = m_cu->GetOffset(); - if (m_cu->GetBaseObjOffset() != DW_INVALID_OFFSET) - cu_offset = m_cu->GetBaseObjOffset(); - return DIERef(m_cu->GetDebugSection(), cu_offset, m_die->GetOffset()); + return DIERef(m_cu->GetSymbolFileDWARF().GetDwoNum(), m_cu->GetDebugSection(), + m_die->GetOffset()); } dw_tag_t DWARFBaseDIE::Tag() const { Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -151,9 +151,9 @@ if (cu->ContainsDIEOffset(block_die->GetOffset())) return DWARFDIE(cu, block_die); else - return DWARFDIE(dwarf->DebugInfo()->GetUnit( - DIERef(cu->GetDebugSection(), cu->GetOffset(), - block_die->GetOffset())), + return DWARFDIE(dwarf->DebugInfo()->GetUnit(DIERef( + cu->GetSymbolFileDWARF().GetDwoNum(), + cu->GetDebugSection(), block_die->GetOffset())), block_die); } } Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -149,8 +149,6 @@ } DWARFUnit *DWARFDebugInfo::GetUnit(const DIERef &die_ref) { - if (die_ref.unit_offset()) - return GetUnitAtOffset(die_ref.section(), *die_ref.unit_offset()); return GetUnitContainingDIEOffset(die_ref.section(), die_ref.die_offset()); } Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -226,12 +226,6 @@ DWARFRangeList &ranges, int &decl_file, int &decl_line, int &decl_column, int &call_file, int &call_line, int &call_column, DWARFExpression *frame_base) const { - SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile(); - if (dwo_symbol_file) - return GetDIENamesAndRanges( - dwo_symbol_file->GetCompileUnit(), name, mangled, ranges, decl_file, - decl_line, decl_column, call_file, call_line, call_column, frame_base); - dw_addr_t lo_pc = LLDB_INVALID_ADDRESS; dw_addr_t hi_pc = LLDB_INVALID_ADDRESS; std::vector dies; @@ -611,16 +605,7 @@ const DWARFUnit *cu, const dw_attr_t attr, DWARFFormValue &form_value, dw_offset_t *end_attr_offset_ptr, bool check_specification_or_abstract_origin) const { - SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile(); - if (dwo_symbol_file && m_tag != DW_TAG_compile_unit && - m_tag != DW_TAG_partial_unit) - return GetAttributeValue(dwo_symbol_file->GetCompileUnit(), attr, - form_value, end_attr_offset_ptr, - check_specification_or_abstract_origin); - - auto abbrevDecl = GetAbbreviationDeclarationPtr(cu); - - if (abbrevDecl) { + if (auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu)) { uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr); if (attr_idx != DW_INVALID_INDEX) { @@ -665,6 +650,10 @@ } } + // If we're a unit DIE, also check the attributes of the dwo unit (if any). + if (GetParent()) + return 0; + SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile(); if (!dwo_symbol_file) return 0; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFIndex.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFIndex.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFIndex.h @@ -13,7 +13,6 @@ #include "Plugins/SymbolFile/DWARF/DWARFDIE.h" #include "Plugins/SymbolFile/DWARF/DWARFFormValue.h" -class DWARFDebugInfo; class DWARFDeclContext; class DWARFDIE; @@ -40,7 +39,7 @@ virtual void GetTypes(ConstString name, DIEArray &offsets) = 0; virtual void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) = 0; virtual void GetNamespaces(ConstString name, DIEArray &offsets) = 0; - virtual void GetFunctions(ConstString name, DWARFDebugInfo &info, + virtual void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, std::vector &dies) = 0; @@ -58,7 +57,7 @@ /// "parent_decl_ctx" and "name_type_mask", it is inserted into the "dies" /// vector. void ProcessFunctionDIE(llvm::StringRef name, DIERef ref, - DWARFDebugInfo &info, + SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, std::vector &dies); }; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp @@ -7,10 +7,9 @@ //===----------------------------------------------------------------------===// #include "Plugins/SymbolFile/DWARF/DWARFIndex.h" -#include "Plugins/SymbolFile/DWARF/DWARFDIE.h" -#include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h" - #include "Plugins/Language/ObjC/ObjCLanguage.h" +#include "Plugins/SymbolFile/DWARF/DWARFDIE.h" +#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" using namespace lldb_private; using namespace lldb; @@ -18,11 +17,11 @@ DWARFIndex::~DWARFIndex() = default; void DWARFIndex::ProcessFunctionDIE(llvm::StringRef name, DIERef ref, - DWARFDebugInfo &info, + SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, std::vector &dies) { - DWARFDIE die = info.GetDIE(ref); + DWARFDIE die = dwarf.GetDIE(ref); if (!die) { ReportInvalidDIERef(ref, name); return; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h @@ -148,7 +148,6 @@ dw_addr_t GetStrOffsetsBase() const { return m_str_offsets_base; } void SetAddrBase(dw_addr_t addr_base); void SetRangesBase(dw_addr_t ranges_base); - void SetBaseObjOffset(dw_offset_t base_obj_offset); void SetStrOffsetsBase(dw_offset_t str_offsets_base); virtual void BuildAddressRangeTable(DWARFDebugAranges *debug_aranges) = 0; @@ -166,6 +165,8 @@ DWARFDIE GetDIE(dw_offset_t die_offset); + DWARFUnit &GetNonSkeletonUnit(); + static uint8_t GetAddressByteSize(const DWARFUnit *cu); static uint8_t GetDefaultAddressSize(); @@ -203,8 +204,6 @@ SymbolFileDWARFDwo *GetDwoSymbolFile() const; - dw_offset_t GetBaseObjOffset() const; - die_iterator_range dies() { ExtractDIEsIfNeeded(); return die_iterator_range(m_die_array.begin(), m_die_array.end()); @@ -284,9 +283,6 @@ llvm::Optional m_file_spec; dw_addr_t m_addr_base = 0; // Value of DW_AT_addr_base dw_addr_t m_ranges_base = 0; // Value of DW_AT_ranges_base - // If this is a dwo compile unit this is the offset of the base compile unit - // in the main object file - dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET; /// Value of DW_AT_stmt_list. dw_offset_t m_line_table_offset = DW_INVALID_OFFSET; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -363,7 +363,6 @@ else if (gnu_ranges_base) dwo_cu->SetRangesBase(*gnu_ranges_base); - dwo_cu->SetBaseObjOffset(GetOffset()); SetDwoStrOffsetsBase(dwo_cu); } @@ -419,10 +418,6 @@ m_ranges_base = ranges_base; } -void DWARFUnit::SetBaseObjOffset(dw_offset_t base_obj_offset) { - m_base_obj_offset = base_obj_offset; -} - void DWARFUnit::SetStrOffsetsBase(dw_offset_t str_offsets_base) { m_str_offsets_base = str_offsets_base; } @@ -480,6 +475,12 @@ return DWARFDIE(); // Not found } +DWARFUnit &DWARFUnit::GetNonSkeletonUnit() { + if (SymbolFileDWARFDwo *dwo = GetDwoSymbolFile()) + return *dwo->GetCompileUnit(); + return *this; +} + uint8_t DWARFUnit::GetAddressByteSize(const DWARFUnit *cu) { if (cu) return cu->GetAddressByteSize(); @@ -719,8 +720,6 @@ return m_dwo_symbol_file.get(); } -dw_offset_t DWARFUnit::GetBaseObjOffset() const { return m_base_obj_offset; } - const DWARFDebugAranges &DWARFUnit::GetFunctionAranges() { if (m_func_aranges_up == nullptr) { m_func_aranges_up.reset(new DWARFDebugAranges()); Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h @@ -34,7 +34,7 @@ void GetTypes(ConstString name, DIEArray &offsets) override; void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) override; void GetNamespaces(ConstString name, DIEArray &offsets) override; - void GetFunctions(ConstString name, DWARFDebugInfo &info, + void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, std::vector &dies) override; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -64,10 +64,11 @@ // GetDwoSymbolFile to call this automatically because of mutual recursion // between this and DWARFDebugInfoEntry::GetAttributeValue. cu->ExtractUnitDIEIfNeeded(); - uint64_t die_bias = cu->GetDwoSymbolFile() ? 0 : *cu_offset; + cu = &cu->GetNonSkeletonUnit(); if (llvm::Optional die_offset = entry.getDIEUnitOffset()) - return DIERef(DIERef::Section::DebugInfo, *cu_offset, die_bias + *die_offset); + return DIERef(cu->GetSymbolFileDWARF().GetDwoNum(), + DIERef::Section::DebugInfo, cu->GetOffset() + *die_offset); return llvm::None; } @@ -165,8 +166,7 @@ if (!ref) continue; - DWARFUnit *cu = m_debug_info.GetUnitAtOffset(DIERef::Section::DebugInfo, - *ref->unit_offset()); + DWARFUnit *cu = m_debug_info.GetUnit(*ref); if (!cu || !cu->Supports_DW_AT_APPLE_objc_complete_type()) { incomplete_types.push_back(*ref); continue; @@ -222,12 +222,12 @@ } void DebugNamesDWARFIndex::GetFunctions( - ConstString name, DWARFDebugInfo &info, + ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, std::vector &dies) { std::vector v; - m_fallback.GetFunctions(name, info, parent_decl_ctx, name_type_mask, v); + m_fallback.GetFunctions(name, dwarf, parent_decl_ctx, name_type_mask, v); for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name.GetStringRef())) { @@ -236,7 +236,7 @@ continue; if (llvm::Optional ref = ToDIERef(entry)) - ProcessFunctionDIE(name.GetStringRef(), *ref, info, parent_decl_ctx, + ProcessFunctionDIE(name.GetStringRef(), *ref, dwarf, parent_decl_ctx, name_type_mask, v); } Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h @@ -61,7 +61,7 @@ DIEInfo(dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h); explicit operator DIERef() const { - return DIERef(DIERef::Section::DebugInfo, llvm::None, die_offset); + return DIERef(llvm::None, DIERef::Section::DebugInfo, die_offset); } }; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h @@ -13,6 +13,8 @@ #include "Plugins/SymbolFile/DWARF/NameToDIE.h" #include "llvm/ADT/DenseSet.h" +class DWARFDebugInfo; + namespace lldb_private { class ManualDWARFIndex : public DWARFIndex { public: @@ -26,14 +28,14 @@ void GetGlobalVariables(ConstString basename, DIEArray &offsets) override; void GetGlobalVariables(const RegularExpression ®ex, DIEArray &offsets) override; - void GetGlobalVariables(const DWARFUnit &cu, DIEArray &offsets) override; + void GetGlobalVariables(const DWARFUnit &unit, DIEArray &offsets) override; void GetObjCMethods(ConstString class_name, DIEArray &offsets) override; void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, DIEArray &offsets) override; void GetTypes(ConstString name, DIEArray &offsets) override; void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) override; void GetNamespaces(ConstString name, DIEArray &offsets) override; - void GetFunctions(ConstString name, DWARFDebugInfo &info, + void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, std::vector &dies) override; @@ -56,9 +58,9 @@ void Index(); void IndexUnit(DWARFUnit &unit, IndexSet &set); - static void - IndexUnitImpl(DWARFUnit &unit, const lldb::LanguageType cu_language, - const dw_offset_t cu_offset, IndexSet &set); + static void IndexUnitImpl(DWARFUnit &unit, + const lldb::LanguageType cu_language, + IndexSet &set); /// Non-null value means we haven't built the index yet. DWARFDebugInfo *m_debug_info; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -102,18 +102,17 @@ const LanguageType cu_language = unit.GetLanguageType(); - IndexUnitImpl(unit, cu_language, unit.GetOffset(), set); + IndexUnitImpl(unit, cu_language, set); SymbolFileDWARFDwo *dwo_symbol_file = unit.GetDwoSymbolFile(); if (dwo_symbol_file && dwo_symbol_file->GetCompileUnit()) { - IndexUnitImpl(*dwo_symbol_file->GetCompileUnit(), cu_language, - unit.GetOffset(), set); + IndexUnitImpl(*dwo_symbol_file->GetCompileUnit(), cu_language, set); } } -void ManualDWARFIndex::IndexUnitImpl( - DWARFUnit &unit, const LanguageType cu_language, - const dw_offset_t cu_offset, IndexSet &set) { +void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit, + const LanguageType cu_language, + IndexSet &set) { for (const DWARFDebugInfoEntry &die : unit.dies()) { const dw_tag_t tag = die.Tag(); @@ -243,7 +242,7 @@ } } - DIERef ref(unit.GetDebugSection(), cu_offset, die.GetOffset()); + DIERef ref = *DWARFDIE(&unit, &die).GetDIERef(); switch (tag) { case DW_TAG_inlined_subroutine: case DW_TAG_subprogram: @@ -358,10 +357,10 @@ m_set.globals.Find(regex, offsets); } -void ManualDWARFIndex::GetGlobalVariables(const DWARFUnit &cu, +void ManualDWARFIndex::GetGlobalVariables(const DWARFUnit &unit, DIEArray &offsets) { Index(); - m_set.globals.FindAllEntriesForCompileUnit(cu.GetOffset(), offsets); + m_set.globals.FindAllEntriesForUnit(unit, offsets); } void ManualDWARFIndex::GetObjCMethods(ConstString class_name, @@ -393,7 +392,7 @@ m_set.namespaces.Find(name, offsets); } -void ManualDWARFIndex::GetFunctions(ConstString name, DWARFDebugInfo &info, +void ManualDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, std::vector &dies) { @@ -405,7 +404,7 @@ m_set.function_methods.Find(name, offsets); m_set.function_fullnames.Find(name, offsets); for (const DIERef &die_ref: offsets) { - DWARFDIE die = info.GetDIE(die_ref); + DWARFDIE die = dwarf.GetDIE(die_ref); if (!die) continue; if (SymbolFileDWARF::DIEInDeclContext(&parent_decl_ctx, die)) @@ -416,7 +415,7 @@ DIEArray offsets; m_set.function_basenames.Find(name, offsets); for (const DIERef &die_ref: offsets) { - DWARFDIE die = info.GetDIE(die_ref); + DWARFDIE die = dwarf.GetDIE(die_ref); if (!die) continue; if (SymbolFileDWARF::DIEInDeclContext(&parent_decl_ctx, die)) @@ -429,7 +428,7 @@ DIEArray offsets; m_set.function_methods.Find(name, offsets); for (const DIERef &die_ref: offsets) { - if (DWARFDIE die = info.GetDIE(die_ref)) + if (DWARFDIE die = dwarf.GetDIE(die_ref)) dies.push_back(die); } } @@ -439,7 +438,7 @@ DIEArray offsets; m_set.function_selectors.Find(name, offsets); for (const DIERef &die_ref: offsets) { - if (DWARFDIE die = info.GetDIE(die_ref)) + if (DWARFDIE die = dwarf.GetDIE(die_ref)) dies.push_back(die); } } Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h @@ -16,7 +16,7 @@ #include "lldb/Core/dwarf.h" #include "lldb/lldb-defines.h" -class SymbolFileDWARF; +class DWARFUnit; class NameToDIE { public: @@ -38,8 +38,8 @@ size_t Find(const lldb_private::RegularExpression ®ex, DIEArray &info_array) const; - size_t FindAllEntriesForCompileUnit(dw_offset_t cu_offset, - DIEArray &info_array) const; + size_t FindAllEntriesForUnit(const DWARFUnit &unit, + DIEArray &info_array) const; void ForEach(std::function GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu, @@ -290,6 +286,8 @@ // the method returns a pointer to the base compile unit. virtual DWARFCompileUnit *GetBaseCompileUnit() { return nullptr; } + virtual llvm::Optional GetDwoNum() { return llvm::None; } + static bool DIEInDeclContext(const lldb_private::CompilerDeclContext *parent_decl_ctx, const DWARFDIE &die); Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1199,6 +1199,15 @@ ast_parser->GetDeclForUIDFromDWARF(decl); } +user_id_t SymbolFileDWARF::GetUID(DIERef ref) { + if (GetDebugMapSymfile()) + return GetID() | ref.die_offset(); + + return user_id_t(GetDwoNum().getValueOr(0x7fffffff)) << 32 | + ref.die_offset() | + (lldb::user_id_t(ref.section() == DIERef::Section::DebugTypes) << 63); +} + llvm::Optional SymbolFileDWARF::DecodeUID(lldb::user_id_t uid) { // This method can be called without going through the symbol vendor so we @@ -1215,25 +1224,20 @@ SymbolFileDWARF *dwarf = debug_map->GetSymbolFileByOSOIndex( debug_map->GetOSOIndexFromUserID(uid)); return DecodedUID{ - *dwarf, - {DIERef::Section::DebugInfo, DW_INVALID_OFFSET, dw_offset_t(uid)}}; + *dwarf, {llvm::None, DIERef::Section::DebugInfo, dw_offset_t(uid)}}; } - 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) return llvm::None; - SymbolFileDWARF *dwarf = this; - if (DebugInfo()) { - if (DWARFUnit *unit = DebugInfo()->GetUnitAtIndex(dwarf_id)) { - if (unit->GetDwoSymbolFile()) - dwarf = unit->GetDwoSymbolFile(); - } - } - return DecodedUID{*dwarf, {section, DW_INVALID_OFFSET, die_offset}}; + DIERef::Section section = + uid >> 63 ? DIERef::Section::DebugTypes : DIERef::Section::DebugInfo; + + llvm::Optional dwo_num = uid >> 32 & 0x7fffffff; + if (*dwo_num == 0x7fffffff) + dwo_num = llvm::None; + + return DecodedUID{*this, {dwo_num, section, die_offset}}; } DWARFDIE @@ -1493,6 +1497,14 @@ DWARFDIE SymbolFileDWARF::GetDIE(const DIERef &die_ref) { + if (die_ref.dwo_num()) { + return DebugInfo() + ->GetUnitAtIndex(*die_ref.dwo_num()) + ->GetDwoSymbolFile() + ->GetDIE(die_ref); + } + + DWARFDebugInfo *debug_info = DebugInfo(); if (debug_info) return debug_info->GetDIE(die_ref); @@ -2235,10 +2247,6 @@ const uint32_t original_size = sc_list.GetSize(); - DWARFDebugInfo *info = DebugInfo(); - if (info == nullptr) - return 0; - llvm::DenseSet resolved_dies; DIEArray offsets; CompilerDeclContext empty_decl_ctx; @@ -2246,7 +2254,7 @@ parent_decl_ctx = &empty_decl_ctx; std::vector dies; - m_index->GetFunctions(name, *info, *parent_decl_ctx, name_type_mask, dies); + m_index->GetFunctions(name, *this, *parent_decl_ctx, name_type_mask, dies); for (const DWARFDIE &die: dies) { if (resolved_dies.insert(die.GetDIE()).second) ResolveFunction(die, include_inlines, sc_list); @@ -3081,7 +3089,8 @@ sc.comp_unit->SetVariableList(variables); DIEArray die_offsets; - m_index->GetGlobalVariables(*dwarf_cu, die_offsets); + m_index->GetGlobalVariables(dwarf_cu->GetNonSkeletonUnit(), + die_offsets); const size_t num_matches = die_offsets.size(); if (num_matches) { for (size_t i = 0; i < num_matches; ++i) { Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h @@ -44,6 +44,8 @@ DWARFCompileUnit *GetBaseCompileUnit() override { return &m_base_dwarf_cu; } + llvm::Optional GetDwoNum() override { return GetID() >> 32; } + protected: void LoadSectionData(lldb::SectionType sect_type, lldb_private::DWARFDataExtractor &data) override; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp @@ -124,8 +124,7 @@ DWARFDIE SymbolFileDWARFDwo::GetDIE(const DIERef &die_ref) { - lldbassert(!die_ref.unit_offset() || - *die_ref.unit_offset() == m_base_dwarf_cu.GetOffset()); - return DebugInfo()->GetDIEForDIEOffset(die_ref.section(), - die_ref.die_offset()); + if (*die_ref.dwo_num() == GetDwoNum()) + return DebugInfo()->GetDIE(die_ref); + return GetBaseSymbolFile().GetDIE(die_ref); }