Author: labath Date: Mon Jun 11 06:22:31 2018 New Revision: 334402 URL: http://llvm.org/viewvc/llvm-project?rev=334402&view=rev Log: DWARFDebugNames: Fix lookup in dwo files
The getDIESectionOffset function is not correct for split dwarf files (and will probably be removed in D48009). This patch implements correct section offset computation for split and non-split compile units -- we first need to check if the referenced unit is a skeleton unit, and if it is, we add the die offset to the full unit base offset (as the full unit is the one which contains the die). Added: lldb/trunk/lit/SymbolFile/DWARF/find-variable-dwo.cpp Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h Added: lldb/trunk/lit/SymbolFile/DWARF/find-variable-dwo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/DWARF/find-variable-dwo.cpp?rev=334402&view=auto ============================================================================== --- lldb/trunk/lit/SymbolFile/DWARF/find-variable-dwo.cpp (added) +++ lldb/trunk/lit/SymbolFile/DWARF/find-variable-dwo.cpp Mon Jun 11 06:22:31 2018 @@ -0,0 +1,25 @@ +// REQUIRES: lld + +// RUN: clang %s -g -gsplit-dwarf -c -emit-llvm -o - --target=x86_64-pc-linux -DONE | \ +// RUN: llc -accel-tables=Dwarf -filetype=obj -split-dwarf-file=%t-1.dwo -o %t-1.o +// RUN: llvm-objcopy --split-dwo=%t-1.dwo %t-1.o +// RUN: clang %s -g -gsplit-dwarf -c -emit-llvm -o - --target=x86_64-pc-linux -DTWO | \ +// RUN: llc -accel-tables=Dwarf -filetype=obj -split-dwarf-file=%t-2.dwo -o %t-2.o +// RUN: llvm-objcopy --split-dwo=%t-2.dwo %t-2.o +// RUN: ld.lld %t-1.o %t-2.o -o %t +// RUN: lldb-test symbols --name=foo --find=variable %t | FileCheck %s + +// CHECK: Found 2 variables: +#ifdef ONE +namespace one { +int foo; +// CHECK-DAG: name = "foo", type = {{.*}} (int), {{.*}} decl = find-variable-dwo.cpp:[[@LINE-1]] +} // namespace one + +extern "C" void _start() {} +#else +namespace two { +int foo; +// CHECK-DAG: name = "foo", type = {{.*}} (int), {{.*}} decl = find-variable-dwo.cpp:[[@LINE-1]] +} // namespace two +#endif Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp?rev=334402&r1=334401&r2=334402&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp Mon Jun 11 06:22:31 2018 @@ -9,6 +9,7 @@ #include "Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h" #include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h" +#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h" #include "lldb/Utility/RegularExpression.h" #include "lldb/Utility/Stream.h" @@ -26,13 +27,17 @@ llvm::Expected<std::unique_ptr<DebugName DebugNamesDWARFIndex::Create(Module &module, DWARFDataExtractor debug_names, DWARFDataExtractor debug_str, DWARFDebugInfo *debug_info) { + if (!debug_info) { + return llvm::make_error<llvm::StringError>("debug info null", + llvm::inconvertibleErrorCode()); + } auto index_up = llvm::make_unique<DebugNames>(ToLLVM(debug_names), ToLLVM(debug_str)); if (llvm::Error E = index_up->extract()) return std::move(E); return std::unique_ptr<DebugNamesDWARFIndex>(new DebugNamesDWARFIndex( - module, std::move(index_up), debug_names, debug_str, debug_info)); + module, std::move(index_up), debug_names, debug_str, *debug_info)); } llvm::DenseSet<dw_offset_t> @@ -47,9 +52,22 @@ DebugNamesDWARFIndex::GetUnits(const Deb DIERef DebugNamesDWARFIndex::ToDIERef(const DebugNames::Entry &entry) { llvm::Optional<uint64_t> cu_offset = entry.getCUOffset(); - llvm::Optional<uint64_t> die_offset = entry.getDIESectionOffset(); - if (cu_offset && die_offset) - return DIERef(*cu_offset, *die_offset); + if (!cu_offset) + return DIERef(); + + DWARFUnit *cu = m_debug_info.GetCompileUnit(*cu_offset); + if (!cu) + return DIERef(); + + // This initializes the DWO symbol file. It's not possible for + // 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; + + if (llvm::Optional<uint64_t> die_offset = entry.getDIEUnitOffset()) + return DIERef(*cu_offset, die_bias + *die_offset); + return DIERef(); } Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h?rev=334402&r1=334401&r2=334402&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h Mon Jun 11 06:22:31 2018 @@ -51,9 +51,12 @@ private: std::unique_ptr<llvm::DWARFDebugNames> debug_names_up, DWARFDataExtractor debug_names_data, DWARFDataExtractor debug_str_data, - DWARFDebugInfo *debug_info) - : DWARFIndex(module), m_debug_names_up(std::move(debug_names_up)), - m_fallback(module, debug_info, GetUnits(*m_debug_names_up)) {} + DWARFDebugInfo &debug_info) + : DWARFIndex(module), m_debug_info(debug_info), + m_debug_names_up(std::move(debug_names_up)), + m_fallback(module, &debug_info, GetUnits(*m_debug_names_up)) {} + + DWARFDebugInfo &m_debug_info; // LLVM DWARFDebugNames will hold a non-owning reference to this data, so keep // track of the ownership here. @@ -64,8 +67,9 @@ private: std::unique_ptr<DebugNames> m_debug_names_up; ManualDWARFIndex m_fallback; - static DIERef ToDIERef(const DebugNames::Entry &entry); - static void Append(const DebugNames::Entry &entry, DIEArray &offsets); + DIERef ToDIERef(const DebugNames::Entry &entry); + void Append(const DebugNames::Entry &entry, DIEArray &offsets); + static void MaybeLogLookupError(llvm::Error error, const DebugNames::NameIndex &ni, llvm::StringRef name); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits