diff options
author | Pavel Labath <labath@google.com> | 2018-06-11 13:22:31 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2018-06-11 13:22:31 +0000 |
commit | 08dae4bb3c5b4ec8eff111c1da8cbb980ba479a2 (patch) | |
tree | 4670c3b38d3113882c9a26e47eaf11dd0b05cb2d | |
parent | 8b98f5517f241ea07009cfb7c17588513c7e06ef (diff) | |
download | bcm5719-llvm-08dae4bb3c5b4ec8eff111c1da8cbb980ba479a2.tar.gz bcm5719-llvm-08dae4bb3c5b4ec8eff111c1da8cbb980ba479a2.zip |
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).
llvm-svn: 334402
3 files changed, 56 insertions, 9 deletions
diff --git a/lldb/lit/SymbolFile/DWARF/find-variable-dwo.cpp b/lldb/lit/SymbolFile/DWARF/find-variable-dwo.cpp new file mode 100644 index 00000000000..142ddc82cda --- /dev/null +++ b/lldb/lit/SymbolFile/DWARF/find-variable-dwo.cpp @@ -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 diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index aa123e069fd..4d909ca821e 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -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<DebugNamesDWARFIndex>> 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 DebugNames &debug_names) { 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(); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h index 28f75d068b0..108e2d0890e 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h @@ -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); |