diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h @@ -39,7 +39,7 @@ GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref callback) override; void - GetGlobalVariables(const DWARFUnit &cu, + GetGlobalVariables(DWARFUnit &cu, llvm::function_ref callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref callback) override; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -75,12 +75,14 @@ } void AppleDWARFIndex::GetGlobalVariables( - const DWARFUnit &cu, llvm::function_ref callback) { + DWARFUnit &cu, llvm::function_ref callback) { if (!m_apple_names_up) return; + const DWARFUnit &non_skeleton_cu = cu.GetNonSkeletonUnit(); DWARFMappedHash::DIEInfoArray hash_data; - m_apple_names_up->AppendAllDIEsInRange(cu.GetOffset(), cu.GetNextUnitOffset(), + m_apple_names_up->AppendAllDIEsInRange(non_skeleton_cu.GetOffset(), + non_skeleton_cu.GetNextUnitOffset(), hash_data); DWARFMappedHash::ExtractDIEArray(hash_data, DIERefCallback(callback)); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h @@ -35,7 +35,7 @@ GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref callback) = 0; virtual void - GetGlobalVariables(const DWARFUnit &cu, + GetGlobalVariables(DWARFUnit &cu, llvm::function_ref callback) = 0; virtual void GetObjCMethods(ConstString class_name, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h @@ -32,7 +32,7 @@ GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref callback) override; void - GetGlobalVariables(const DWARFUnit &cu, + GetGlobalVariables(DWARFUnit &cu, llvm::function_ref callback) override; void GetObjCMethods(ConstString class_name, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -123,7 +123,7 @@ } void DebugNamesDWARFIndex::GetGlobalVariables( - const DWARFUnit &cu, llvm::function_ref callback) { + DWARFUnit &cu, llvm::function_ref callback) { uint64_t cu_offset = cu.GetOffset(); bool found_entry_for_cu = false; for (const DebugNames::NameIndex &ni: *m_debug_names_up) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h @@ -33,7 +33,7 @@ GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref callback) override; void - GetGlobalVariables(const DWARFUnit &unit, + GetGlobalVariables(DWARFUnit &unit, llvm::function_ref callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref callback) override; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -358,9 +358,10 @@ } void ManualDWARFIndex::GetGlobalVariables( - const DWARFUnit &unit, llvm::function_ref callback) { + DWARFUnit &unit, llvm::function_ref callback) { Index(); - m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(callback)); + m_set.globals.FindAllEntriesForUnit(unit.GetNonSkeletonUnit(), + DIERefCallback(callback)); } void ManualDWARFIndex::GetObjCMethods( 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 @@ -3069,16 +3069,14 @@ variables = std::make_shared(); sc.comp_unit->SetVariableList(variables); - m_index->GetGlobalVariables( - dwarf_cu->GetNonSkeletonUnit(), [&](DWARFDIE die) { - VariableSP var_sp( - ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); - if (var_sp) { - variables->AddVariableIfUnique(var_sp); - ++vars_added; - } - return true; - }); + m_index->GetGlobalVariables(*dwarf_cu, [&](DWARFDIE die) { + VariableSP var_sp(ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); + if (var_sp) { + variables->AddVariableIfUnique(var_sp); + ++vars_added; + } + return true; + }); } return vars_added; } diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/find-variable-file.cpp b/lldb/test/Shell/SymbolFile/DWARF/x86/find-variable-file.cpp --- a/lldb/test/Shell/SymbolFile/DWARF/x86/find-variable-file.cpp +++ b/lldb/test/Shell/SymbolFile/DWARF/x86/find-variable-file.cpp @@ -27,6 +27,17 @@ // 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 and pubnames to check whether we can find +// the compile unit using the name index if it is split. +// RUN: %clang -c -o %t-1.o --target=x86_64-pc-linux -gdwarf-5 -gsplit-dwarf -gpubnames %s +// RUN: %clang -c -o %t-2.o --target=x86_64-pc-linux -gdwarf-5 -gsplit-dwarf -gpubnames %S/Inputs/find-variable-file-2.cpp +// RUN: ld.lld %t-1.o %t-2.o -o %t +// RUN: llvm-readobj --sections %t | FileCheck %s --check-prefix NAMES +// 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 + // NAMES: Name: .debug_names // ONE: Found 1 variables: