Setting breakpoints with name mask eFunctionNameTypeBase was broken for straight C names by 220432. Get

that working again.

llvm-svn: 220602
This commit is contained in:
Jim Ingham 2014-10-25 00:33:55 +00:00
parent d337a59db5
commit fa39bb4a56
4 changed files with 33 additions and 37 deletions

View File

@ -132,9 +132,16 @@ public:
static bool
IsCPPMangledName(const char *name);
// Extract C++ context and identifier from a string using heuristic matching (as opposed to
// CPPLanguageRuntime::MethodName which has to have a fully qualified C++ name with parens and arguments.
// If the name is a lone C identifier (e.g. C) or a qualified C identifier (e.g. A::B::C) it will return true,
// and identifier will be the identifier (C and C respectively) and the context will be "" and "A::B::" respectively.
// If the name fails the heuristic matching for a qualified or unqualified C/C++ identifier, then it will return false
// and identifier and context will be unchanged.
static bool
StripNamespacesFromVariableName (const char *name, const char *&base_name_start, const char *&base_name_end);
ExtractContextAndIdentifier (const char *name, llvm::StringRef &context, llvm::StringRef &identifier);
// in some cases, compilers will output different names for one same type. when that happens, it might be impossible
// to construct SBType objects for a valid type, because the name that is available is not the same as the name that

View File

@ -1710,8 +1710,9 @@ Module::PrepareForFunctionNameLookup (const ConstString &name,
const char *name_cstr = name.GetCString();
lookup_name_type_mask = eFunctionNameTypeNone;
match_name_after_lookup = false;
const char *base_name_start = NULL;
const char *base_name_end = NULL;
llvm::StringRef basename;
llvm::StringRef context;
if (name_type_mask & eFunctionNameTypeAuto)
{
@ -1725,18 +1726,16 @@ Module::PrepareForFunctionNameLookup (const ConstString &name,
lookup_name_type_mask |= eFunctionNameTypeSelector;
CPPLanguageRuntime::MethodName cpp_method (name);
llvm::StringRef basename (cpp_method.GetBasename());
basename = cpp_method.GetBasename();
if (basename.empty())
{
if (CPPLanguageRuntime::StripNamespacesFromVariableName (name_cstr, base_name_start, base_name_end))
if (CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename))
lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
else
lookup_name_type_mask = eFunctionNameTypeFull;
}
else
{
base_name_start = basename.data();
base_name_end = base_name_start + basename.size();
lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
}
}
@ -1751,9 +1750,7 @@ Module::PrepareForFunctionNameLookup (const ConstString &name,
CPPLanguageRuntime::MethodName cpp_method (name);
if (cpp_method.IsValid())
{
llvm::StringRef basename (cpp_method.GetBasename());
base_name_start = basename.data();
base_name_end = base_name_start + basename.size();
basename = cpp_method.GetBasename();
if (!cpp_method.GetQualifiers().empty())
{
@ -1766,12 +1763,9 @@ Module::PrepareForFunctionNameLookup (const ConstString &name,
}
else
{
if (!CPPLanguageRuntime::StripNamespacesFromVariableName (name_cstr, base_name_start, base_name_end))
{
lookup_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
if (lookup_name_type_mask == eFunctionNameTypeNone)
return;
}
// If the CPP method parser didn't manage to chop this up, try to fill in the base name if we can.
// If a::b::c is passed in, we need to just look up "c", and then we'll filter the result later.
CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename);
}
}
@ -1786,16 +1780,13 @@ Module::PrepareForFunctionNameLookup (const ConstString &name,
}
}
if (base_name_start &&
base_name_end &&
base_name_start != name_cstr &&
base_name_start < base_name_end)
if (!basename.empty())
{
// The name supplied was a partial C++ path like "a::count". In this case we want to do a
// lookup on the basename "count" and then make sure any matching results contain "a::count"
// so that it would match "b::a::count" and "a::count". This is why we set "match_name_after_lookup"
// to true
lookup_name.SetCStringWithLength(base_name_start, base_name_end - base_name_start);
lookup_name.SetString(basename);
match_name_after_lookup = true;
}
else

View File

@ -3197,13 +3197,13 @@ SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_privat
if (m_apple_names_ap.get())
{
const char *name_cstr = name.GetCString();
const char *base_name_start;
const char *base_name_end = NULL;
llvm::StringRef basename;
llvm::StringRef context;
if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
base_name_start = name_cstr;
if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename))
basename = name_cstr;
m_apple_names_ap->FindByName (base_name_start, die_offsets);
m_apple_names_ap->FindByName (basename.data(), die_offsets);
}
}
else

View File

@ -11,6 +11,8 @@
#include <string.h>
#include "llvm/ADT/StringRef.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/UniqueCStringMap.h"
#include "lldb/Target/ExecutionContext.h"
@ -190,19 +192,15 @@ CPPLanguageRuntime::IsCPPMangledName (const char *name)
}
bool
CPPLanguageRuntime::StripNamespacesFromVariableName (const char *name, const char *&base_name_start, const char *&base_name_end)
CPPLanguageRuntime::ExtractContextAndIdentifier (const char *name, llvm::StringRef &context, llvm::StringRef &identifier)
{
static RegularExpression g_basename_regex("([A-Za-z_][A-Za-z_0-9]*::)+([A-Za-z_][A-Za-z_0-9]*)$");
RegularExpression::Match match(2);
static RegularExpression g_basename_regex("^(([A-Za-z_][A-Za-z_0-9]*::)*)([A-Za-z_][A-Za-z_0-9]*)$");
RegularExpression::Match match(4);
if (g_basename_regex.Execute (name, &match))
{
llvm::StringRef basename;
if (match.GetMatchAtIndex(name, 2, basename))
{
base_name_start = basename.data();
base_name_end = base_name_start + basename.size();
return true;
}
match.GetMatchAtIndex(name, 1, context);
match.GetMatchAtIndex(name, 3, identifier);
return true;
}
return false;
}