Author: Kim-Anh Tran Date: 2021-08-09T13:15:14+02:00 New Revision: 0dda5425318a5785e3e19cfe369a43b221b9642d
URL: https://github.com/llvm/llvm-project/commit/0dda5425318a5785e3e19cfe369a43b221b9642d DIFF: https://github.com/llvm/llvm-project/commit/0dda5425318a5785e3e19cfe369a43b221b9642d.diff LOG: [DWARF5] Fix offset check when using .debug_names When going through the CU entries in the name index, make sure to compare the name entry's CU offset against the skeleton CU's offset. Previously there would be a mismatch, since the wrong offset was compared, and thus no suitable entry was found. Reviewed By: jankratochvil Differential Revision: https://reviews.llvm.org/D106270 Added: Modified: lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/test/Shell/SymbolFile/DWARF/x86/find-variable-file.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp index 60b6b726f6c09..c786451a03df2 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -75,12 +75,14 @@ void AppleDWARFIndex::GetGlobalVariables( } void AppleDWARFIndex::GetGlobalVariables( - const DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) { + DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> 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/AppleDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h index a7032f50e590a..ef3cb5dee0356 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h @@ -39,7 +39,7 @@ class AppleDWARFIndex : public DWARFIndex { GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref<bool(DWARFDIE die)> callback) override; void - GetGlobalVariables(const DWARFUnit &cu, + GetGlobalVariables(DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) override; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h index ecf82a910b661..6f2698cc6e6fb 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h @@ -35,7 +35,7 @@ class DWARFIndex { GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref<bool(DWARFDIE die)> callback) = 0; virtual void - GetGlobalVariables(const DWARFUnit &cu, + GetGlobalVariables(DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) = 0; virtual void GetObjCMethods(ConstString class_name, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index 5dfa5a176d384..2b2c13abb250b 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -123,7 +123,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables( } void DebugNamesDWARFIndex::GetGlobalVariables( - const DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) { + DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> 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/DebugNamesDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h index 5d041c36c8f29..c451ccd4857fa 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h @@ -32,7 +32,7 @@ class DebugNamesDWARFIndex : public DWARFIndex { GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref<bool(DWARFDIE die)> callback) override; void - GetGlobalVariables(const DWARFUnit &cu, + GetGlobalVariables(DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetObjCMethods(ConstString class_name, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp index 1f40d880ea34b..242daa9293914 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -358,9 +358,10 @@ void ManualDWARFIndex::GetGlobalVariables( } void ManualDWARFIndex::GetGlobalVariables( - const DWARFUnit &unit, llvm::function_ref<bool(DWARFDIE die)> callback) { + DWARFUnit &unit, llvm::function_ref<bool(DWARFDIE die)> 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/ManualDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h index baff989eeccad..36f371402b908 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h @@ -33,7 +33,7 @@ class ManualDWARFIndex : public DWARFIndex { GetGlobalVariables(const RegularExpression ®ex, llvm::function_ref<bool(DWARFDIE die)> callback) override; void - GetGlobalVariables(const DWARFUnit &unit, + GetGlobalVariables(DWARFUnit &unit, llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) override; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 5927ba922593c..01a487f737781 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -3069,16 +3069,14 @@ size_t SymbolFileDWARF::ParseVariablesForContext(const SymbolContext &sc) { variables = std::make_shared<VariableList>(); 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 index b11cf1eb13360..9b23f36a21384 100644 --- 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: _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits