Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lldb/include/lldb/Target/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <vector>

#include "lldb/Core/Highlighter.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginInterface.h"
#include "lldb/DataFormatters/DumpValueObjectOptions.h"
#include "lldb/DataFormatters/FormatClasses.h"
Expand Down Expand Up @@ -379,6 +380,21 @@ class Language : public PluginInterface {
/// Python uses \b except. Defaults to \b catch.
virtual llvm::StringRef GetCatchKeyword() const { return "catch"; }

/// Method invoked by \a Module::LookupInfo::Prune used to filter out symbol
/// search results.
///
/// \param[in] sc A symbol that passed the common symbol search lookup
/// process.
/// \param[in] lookup_info The full lookup info.
///
/// \return whether the given symbol should be discarded from the search
/// results.
virtual bool
SymbolLookupHookShouldPruneResult(const SymbolContext &sc,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "Hook" is right here. You can tell this is a language hook by the fact that we're calling some GetLanguagePlugin->ThisMethod so the "Hook" is redundant. We don't call any of the other language hooks hooks.

const Module::LookupInfo &lookup_info) {
return false;
}

protected:
// Classes that inherit from Language can see and modify these

Expand Down
32 changes: 4 additions & 28 deletions lldb/source/Core/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,40 +787,16 @@ void Module::LookupInfo::Prune(SymbolContextList &sc_list,
}
}

// If we have only full name matches we might have tried to set breakpoint on
// "func" and specified eFunctionNameTypeFull, but we might have found
// "a::func()", "a::b::func()", "c::func()", "func()" and "func". Only
// "func()" and "func" should end up matching.
if (m_name_type_mask == eFunctionNameTypeFull) {
SymbolContext sc;
size_t i = start_idx;
while (i < sc_list.GetSize()) {
if (!sc_list.GetContextAtIndex(i, sc))
break;
// Make sure the mangled and demangled names don't match before we try to
// pull anything out
ConstString mangled_name(sc.GetFunctionName(Mangled::ePreferMangled));
ConstString full_name(sc.GetFunctionName());
if (mangled_name != m_name && full_name != m_name) {
CPlusPlusLanguage::MethodName cpp_method(full_name);
if (cpp_method.IsValid()) {
if (cpp_method.GetContext().empty()) {
if (cpp_method.GetBasename().compare(m_name) != 0) {
sc_list.RemoveContextAtIndex(i);
continue;
}
} else {
std::string qualified_name;
llvm::StringRef anon_prefix("(anonymous namespace)");
if (cpp_method.GetContext() == anon_prefix)
qualified_name = cpp_method.GetBasename().str();
else
qualified_name = cpp_method.GetScopeQualifiedName();
if (qualified_name != m_name.GetCString()) {
sc_list.RemoveContextAtIndex(i);
continue;
}
}
if (Language *languagePlugin = Language::FindPlugin(sc.GetLanguage())) {
if (languagePlugin->SymbolLookupHookShouldPruneResult(sc, *this)) {
sc_list.RemoveContextAtIndex(i);
continue;
}
}
++i;
Expand Down
38 changes: 38 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1759,3 +1759,41 @@ bool CPlusPlusLanguage::GetFunctionDisplayName(

return false;
}

bool CPlusPlusLanguage::SymbolLookupHookShouldPruneResult(
const SymbolContext &sc, const Module::LookupInfo &lookup_info) {
// If we have only full name matches we might have tried to set breakpoint on
// "func" and specified eFunctionNameTypeFull, but we might have found
// "a::func()", "a::b::func()", "c::func()", "func()" and "func". Only
// "func()" and "func" should end up matching.
// Make sure the mangled and demangled names don't match before we try to
// pull anything out

if (lookup_info.GetNameTypeMask() != eFunctionNameTypeFull)
return false;

ConstString mangled_name(sc.GetFunctionName(Mangled::ePreferMangled));
ConstString full_name(sc.GetFunctionName());
ConstString lookup_name = lookup_info.GetName();
if (mangled_name != lookup_name && full_name != lookup_name) {
CPlusPlusLanguage::MethodName cpp_method(full_name);
if (cpp_method.IsValid()) {
if (cpp_method.GetContext().empty()) {
if (cpp_method.GetBasename().compare(lookup_name) != 0) {
return true;
}
} else {
std::string qualified_name;
llvm::StringRef anon_prefix("(anonymous namespace)");
if (cpp_method.GetContext() == anon_prefix)
qualified_name = cpp_method.GetBasename().str();
else
qualified_name = cpp_method.GetScopeQualifiedName();
if (qualified_name != lookup_name.GetCString()) {
return true;
}
}
}
}
return false;
}
3 changes: 3 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class CPlusPlusLanguage : public Language {

const Highlighter *GetHighlighter() const override { return &m_highlighter; }

bool SymbolLookupHookShouldPruneResult(
const SymbolContext &sc, const Module::LookupInfo &lookup_info) override;

// Static Functions
static void Initialize();

Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ bool DWARFIndex::ProcessFunctionDIE(
return true;

// In case of a full match, we just insert everything we find.
if (name_type_mask & eFunctionNameTypeFull && die.GetMangledName() == name)
if (name_type_mask & eFunctionNameTypeFull &&
(die.GetMangledName() == name || die.GetName() == name))
return callback(die);

// If looking for ObjC selectors, we need to also check if the name is a
Expand Down
Loading