diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp index c786451a03df..4e09b523b778 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -79,6 +79,7 @@ void AppleDWARFIndex::GetGlobalVariables( if (!m_apple_names_up) return; + lldbassert(!cu.GetSymbolFileDWARF().GetDwoNum()); const DWARFUnit &non_skeleton_cu = cu.GetNonSkeletonUnit(); DWARFMappedHash::DIEInfoArray hash_data; m_apple_names_up->AppendAllDIEsInRange(non_skeleton_cu.GetOffset(), diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h index 6f2698cc6e6f..fac6c46b4ccf 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h @@ -34,6 +34,7 @@ public: virtual void GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref callback) = 0; + /// \a cu must be the skeleton unit if possible, not GetNonSkeletonUnit(). virtual void GetGlobalVariables(DWARFUnit &cu, llvm::function_ref callback) = 0; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index 2b2c13abb250..4a148e7744bb 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -124,6 +124,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables( void DebugNamesDWARFIndex::GetGlobalVariables( DWARFUnit &cu, llvm::function_ref callback) { + lldbassert(!cu.GetSymbolFileDWARF().GetDwoNum()); 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.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp index 242daa929391..4d36ef9b34bc 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -359,9 +359,9 @@ void ManualDWARFIndex::GetGlobalVariables( void ManualDWARFIndex::GetGlobalVariables( DWARFUnit &unit, llvm::function_ref callback) { + lldbassert(!unit.GetSymbolFileDWARF().GetDwoNum()); Index(); - m_set.globals.FindAllEntriesForUnit(unit.GetNonSkeletonUnit(), - DIERefCallback(callback)); + m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(callback)); } void ManualDWARFIndex::GetObjCMethods( diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp index 42e96af84a96..493d1b4a2702 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp @@ -45,15 +45,16 @@ bool NameToDIE::Find(const RegularExpression ®ex, } void NameToDIE::FindAllEntriesForUnit( - const DWARFUnit &unit, - llvm::function_ref callback) const { + DWARFUnit &s_unit, llvm::function_ref callback) const { + lldbassert(!s_unit.GetSymbolFileDWARF().GetDwoNum()); + const DWARFUnit &ns_unit = s_unit.GetNonSkeletonUnit(); const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i); - if (unit.GetSymbolFileDWARF().GetDwoNum() == die_ref.dwo_num() && - unit.GetDebugSection() == die_ref.section() && - unit.GetOffset() <= die_ref.die_offset() && - die_ref.die_offset() < unit.GetNextUnitOffset()) { + if (ns_unit.GetSymbolFileDWARF().GetDwoNum() == die_ref.dwo_num() && + ns_unit.GetDebugSection() == die_ref.section() && + ns_unit.GetOffset() <= die_ref.die_offset() && + die_ref.die_offset() < ns_unit.GetNextUnitOffset()) { if (!callback(die_ref)) return; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h index a6863f6c9549..994af07189f8 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h @@ -38,8 +38,9 @@ public: bool Find(const lldb_private::RegularExpression ®ex, llvm::function_ref callback) const; + /// \a unit must be the skeleton unit if possible, not GetNonSkeletonUnit(). void - FindAllEntriesForUnit(const DWARFUnit &unit, + FindAllEntriesForUnit(DWARFUnit &unit, llvm::function_ref callback) const; void diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/Inputs/find-variable-file-3.cpp b/lldb/test/Shell/SymbolFile/DWARF/x86/Inputs/find-variable-file-3.cpp new file mode 100644 index 000000000000..39dceb08bb89 --- /dev/null +++ b/lldb/test/Shell/SymbolFile/DWARF/x86/Inputs/find-variable-file-3.cpp @@ -0,0 +1,2 @@ +// No variable should exist in this file. +void f() {} diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/find-variable-file.cpp b/lldb/test/Shell/SymbolFile/DWARF/x86/find-variable-file.cpp index 9b23f36a2138..f1a9a4eb12d0 100644 --- a/lldb/test/Shell/SymbolFile/DWARF/x86/find-variable-file.cpp +++ b/lldb/test/Shell/SymbolFile/DWARF/x86/find-variable-file.cpp @@ -31,12 +31,15 @@ // 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: %clang -c -o %t-3.o --target=x86_64-pc-linux -gdwarf-5 -gsplit-dwarf -gpubnames %S/Inputs/find-variable-file-3.cpp +// RUN: ld.lld %t-1.o %t-2.o %t-3.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 +// RUN: lldb-test symbols --file=find-variable-file-3.cpp --find=variable \ +// RUN: --name=notexists %t // NAMES: Name: .debug_names