Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.

Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.

This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:

"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.

<rdar://problem/24599697> 

llvm-svn: 275281
This commit is contained in:
Greg Clayton
2016-07-13 17:12:24 +00:00
parent 9531bbd7c3
commit 6234a5c863
5 changed files with 311 additions and 273 deletions

View File

@@ -344,48 +344,25 @@ ModuleList::FindFunctions (const ConstString &name,
if (name_type_mask & eFunctionNameTypeAuto)
{
ConstString lookup_name;
uint32_t lookup_name_type_mask = 0;
bool match_name_after_lookup = false;
Module::PrepareForFunctionNameLookup (name, name_type_mask,
eLanguageTypeUnknown, // TODO: add support
lookup_name,
lookup_name_type_mask,
match_name_after_lookup);
Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
collection::const_iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos)
{
(*pos)->FindFunctions(lookup_name,
(*pos)->FindFunctions(lookup_info.GetLookupName(),
nullptr,
lookup_name_type_mask,
lookup_info.GetNameTypeMask(),
include_symbols,
include_inlines,
true,
sc_list);
}
if (match_name_after_lookup)
{
SymbolContext sc;
size_t i = old_size;
while (i < sc_list.GetSize())
{
if (sc_list.GetContextAtIndex(i, sc))
{
const char *func_name = sc.GetFunctionName().GetCString();
if (func_name != nullptr && strstr(func_name, name.GetCString()) == nullptr)
{
// Remove the current context
sc_list.RemoveContextAtIndex(i);
// Don't increment i and continue in the loop
continue;
}
}
++i;
}
}
const size_t new_size = sc_list.GetSize();
if (old_size < new_size)
lookup_info.Prune (sc_list, old_size);
}
else
{
@@ -408,44 +385,22 @@ ModuleList::FindFunctionSymbols (const ConstString &name,
if (name_type_mask & eFunctionNameTypeAuto)
{
ConstString lookup_name;
uint32_t lookup_name_type_mask = 0;
bool match_name_after_lookup = false;
Module::PrepareForFunctionNameLookup (name, name_type_mask,
eLanguageTypeUnknown, // TODO: add support
lookup_name,
lookup_name_type_mask,
match_name_after_lookup);
Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
collection::const_iterator pos, end = m_modules.end();
for (pos = m_modules.begin(); pos != end; ++pos)
{
(*pos)->FindFunctionSymbols (lookup_name,
lookup_name_type_mask,
sc_list);
}
if (match_name_after_lookup)
{
SymbolContext sc;
size_t i = old_size;
while (i < sc_list.GetSize())
{
if (sc_list.GetContextAtIndex(i, sc))
{
const char *func_name = sc.GetFunctionName().GetCString();
if (func_name != nullptr && strstr(func_name, name.GetCString()) == nullptr)
{
// Remove the current context
sc_list.RemoveContextAtIndex(i);
// Don't increment i and continue in the loop
continue;
}
}
++i;
}
(*pos)->FindFunctionSymbols (lookup_info.GetLookupName(),
lookup_info.GetNameTypeMask(),
sc_list);
}
const size_t new_size = sc_list.GetSize();
if (old_size < new_size)
lookup_info.Prune (sc_list, old_size);
}
else
{