Author: labath Date: Fri Jun 8 03:31:55 2018 New Revision: 334277 URL: http://llvm.org/viewvc/llvm-project?rev=334277&view=rev Log: DebugNamesDWARFIndex: Implement regex version of the GetFunctions method
This also fixes a bug where SymbolFileDWARF was returning the same function multiple times - this can happen if both mangled and demangled names match the regex. Other lookup lookup functions had code to handle this case, but it was forgotten here. Added: lldb/trunk/lit/SymbolFile/DWARF/find-function-regex.cpp Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Added: lldb/trunk/lit/SymbolFile/DWARF/find-function-regex.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/DWARF/find-function-regex.cpp?rev=334277&view=auto ============================================================================== --- lldb/trunk/lit/SymbolFile/DWARF/find-function-regex.cpp (added) +++ lldb/trunk/lit/SymbolFile/DWARF/find-function-regex.cpp Fri Jun 8 03:31:55 2018 @@ -0,0 +1,27 @@ +// REQUIRES: lld + +// RUN: clang %s -g -c -o %t.o --target=x86_64-pc-linux +// RUN: ld.lld %t.o -o %t +// RUN: lldb-test symbols --name=f.o --regex --find=function %t | FileCheck %s +// +// RUN: clang %s -g -c -o %t --target=x86_64-apple-macosx +// RUN: lldb-test symbols --name=f.o --regex --find=function %t | FileCheck %s + +// RUN: clang %s -g -c -emit-llvm -o - --target=x86_64-pc-linux | \ +// RUN: llc -accel-tables=Dwarf -filetype=obj -o %t.o +// RUN: ld.lld %t.o -o %t +// RUN: lldb-test symbols --name=f.o --regex --find=function %t | FileCheck %s + +// CHECK: Found 3 functions: +// CHECK-DAG: name = "foo()", mangled = "_Z3foov" +// CHECK-DAG: name = "ffo()", mangled = "_Z3ffov" +// CHECK-DAG: name = "bar::foo()", mangled = "_ZN3bar3fooEv" + +void foo() {} +void ffo() {} +namespace bar { +void foo() {} +} // namespace bar +void fof() {} + +extern "C" void _start() {} 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=334277&r1=334276&r2=334277&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp Fri Jun 8 03:31:55 2018 @@ -144,6 +144,29 @@ void DebugNamesDWARFIndex::GetFunctions( } } +void DebugNamesDWARFIndex::GetFunctions(const RegularExpression ®ex, + DIEArray &offsets) { + m_fallback.GetFunctions(regex, offsets); + + for (const DebugNames::NameIndex &ni: *m_debug_names_up) { + for (DebugNames::NameTableEntry nte: ni) { + if (!regex.Execute(nte.getString())) + continue; + + uint32_t entry_offset = nte.getEntryOffset(); + llvm::Expected<DebugNames::Entry> entry_or = ni.getEntry(&entry_offset); + for (; entry_or; entry_or = ni.getEntry(&entry_offset)) { + Tag tag = entry_or->tag(); + if (tag != DW_TAG_subprogram && tag != DW_TAG_inlined_subroutine) + continue; + + Append(*entry_or, offsets); + } + MaybeLogLookupError(entry_or.takeError(), ni, nte.getString()); + } + } +} + void DebugNamesDWARFIndex::Dump(Stream &s) { m_fallback.Dump(s); 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=334277&r1=334276&r2=334277&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h Fri Jun 8 03:31:55 2018 @@ -40,7 +40,7 @@ public: uint32_t name_type_mask, std::vector<DWARFDIE> &dies) override; void GetFunctions(const RegularExpression ®ex, - DIEArray &offsets) override {} + DIEArray &offsets) override; void ReportInvalidDIEOffset(dw_offset_t offset, llvm::StringRef name) override {} Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=334277&r1=334276&r2=334277&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Fri Jun 8 03:31:55 2018 @@ -2155,13 +2155,6 @@ uint32_t SymbolFileDWARF::FindGlobalVari return variables.GetSize() - original_size; } -bool SymbolFileDWARF::ResolveFunction(const DIERef &die_ref, - bool include_inlines, - SymbolContextList &sc_list) { - DWARFDIE die = DebugInfo()->GetDIE(die_ref); - return ResolveFunction(die, include_inlines, sc_list); -} - bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die, bool include_inlines, SymbolContextList &sc_list) { @@ -2335,8 +2328,16 @@ uint32_t SymbolFileDWARF::FindFunctions( DIEArray offsets; m_index->GetFunctions(regex, offsets); - for (DIERef ref : offsets) - ResolveFunction(ref, include_inlines, sc_list); + llvm::DenseSet<const DWARFDebugInfoEntry *> resolved_dies; + for (DIERef ref : offsets) { + DWARFDIE die = info->GetDIE(ref); + if (!die) { + m_index->ReportInvalidDIEOffset(ref.die_offset, regex.GetText()); + continue; + } + if (resolved_dies.insert(die.GetDIE()).second) + ResolveFunction(die, include_inlines, sc_list); + } // Return the number of variable that were appended to the list return sc_list.GetSize() - original_size; Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=334277&r1=334276&r2=334277&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Fri Jun 8 03:31:55 2018 @@ -385,9 +385,6 @@ protected: bool ClassOrStructIsVirtual(const DWARFDIE &die); // Given a die_offset, figure out the symbol context representing that die. - bool ResolveFunction(const DIERef &die_ref, bool include_inlines, - lldb_private::SymbolContextList &sc_list); - bool ResolveFunction(const DWARFDIE &die, bool include_inlines, lldb_private::SymbolContextList &sc_list); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits