From dc4bd2e4419fd96842385b12ebe096c2929afc28 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 12 Jun 2018 13:11:25 +0000 Subject: [PATCH] DWARFDebugNames: Implement last GetGlobalVariables overload This function implements the search for all global variables within a given compilation unit. llvm-svn: 334500 --- .../SymbolFile/DWARF/find-variable-file.cpp | 12 ++++++++-- .../SymbolFile/DWARF/DebugNamesDWARFIndex.cpp | 22 +++++++++++++++++++ .../SymbolFile/DWARF/DebugNamesDWARFIndex.h | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lldb/lit/SymbolFile/DWARF/find-variable-file.cpp b/lldb/lit/SymbolFile/DWARF/find-variable-file.cpp index 4f0cb573aea2..f71d4a2b09b6 100644 --- a/lldb/lit/SymbolFile/DWARF/find-variable-file.cpp +++ b/lldb/lit/SymbolFile/DWARF/find-variable-file.cpp @@ -1,7 +1,15 @@ // REQUIRES: lld -// RUN: clang -g -c -o %t-1.o --target=x86_64-pc-linux %s -// RUN: clang -g -c -o %t-2.o --target=x86_64-pc-linux %S/Inputs/find-variable-file-2.cpp +// RUN: clang -g -c -o %t-1.o --target=x86_64-pc-linux -mllvm -accel-tables=Disable %s +// RUN: clang -g -c -o %t-2.o --target=x86_64-pc-linux -mllvm -accel-tables=Disable %S/Inputs/find-variable-file-2.cpp +// RUN: ld.lld %t-1.o %t-2.o -o %t +// 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: clang -g -c -o %t-1.o --target=x86_64-pc-linux -mllvm -accel-tables=Dwarf %s +// RUN: clang -g -c -o %t-2.o --target=x86_64-pc-linux -mllvm -accel-tables=Dwarf %S/Inputs/find-variable-file-2.cpp // RUN: ld.lld %t-1.o %t-2.o -o %t // RUN: lldb-test symbols --file=find-variable-file.cpp --find=variable %t | \ // RUN: FileCheck --check-prefix=ONE %s diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index 4d909ca821ec..644110c82951 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -123,6 +123,28 @@ void DebugNamesDWARFIndex::GetGlobalVariables(const RegularExpression ®ex, } } +void DebugNamesDWARFIndex::GetGlobalVariables(const DWARFUnit &cu, + DIEArray &offsets) { + m_fallback.GetGlobalVariables(cu, offsets); + + uint64_t cu_offset = cu.GetOffset(); + for (const DebugNames::NameIndex &ni: *m_debug_names_up) { + for (DebugNames::NameTableEntry nte: ni) { + uint32_t entry_offset = nte.getEntryOffset(); + llvm::Expected entry_or = ni.getEntry(&entry_offset); + for (; entry_or; entry_or = ni.getEntry(&entry_offset)) { + if (entry_or->tag() != DW_TAG_variable) + continue; + if (entry_or->getCUOffset() != cu_offset) + continue; + + Append(*entry_or, offsets); + } + MaybeLogLookupError(entry_or.takeError(), ni, nte.getString()); + } + } +} + void DebugNamesDWARFIndex::GetTypes(ConstString name, DIEArray &offsets) { m_fallback.GetTypes(name, offsets); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h index 108e2d0890eb..3daea75977ab 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h @@ -28,7 +28,7 @@ public: void GetGlobalVariables(ConstString basename, DIEArray &offsets) override; void GetGlobalVariables(const RegularExpression ®ex, DIEArray &offsets) override; - void GetGlobalVariables(const DWARFUnit &cu, DIEArray &offsets) override {} + void GetGlobalVariables(const DWARFUnit &cu, DIEArray &offsets) override; void GetObjCMethods(ConstString class_name, DIEArray &offsets) override {} void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, DIEArray &offsets) override {}