[Lldb-commits] [lldb] r182179 - <rdar://problem/11398407>
Greg Clayton
gclayton at apple.com
Fri May 17 17:11:21 PDT 2013
Author: gclayton
Date: Fri May 17 19:11:21 2013
New Revision: 182179
URL: http://llvm.org/viewvc/llvm-project?rev=182179&view=rev
Log:
<rdar://problem/11398407>
Name matching was working inconsistently across many places in LLDB. Anyone doing name lookups where you want to look for all types of names should used "eFunctionNameTypeAuto" as the sole name type mask. This will ensure that we get consistent "lookup function by name" results. We had many function calls using as mask like "eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector". This was due to the function lookup by name evolving over time, but as it stands today, use eFunctionNameTypeAuto when you want general name lookups. Either ModuleList::FindFunctions() or Module::FindFunctions() will figure out the right kinds of names to lookup and remove the "eFunctionNameTypeAuto" and replace it with the exact subset of what the name can be.
This checkin also changes eFunctionNameTypeAny over to use eFunctionNameTypeAuto to reflect this.
Modified:
lldb/trunk/include/lldb/Target/CPPLanguageRuntime.h
lldb/trunk/include/lldb/lldb-enumerations.h
lldb/trunk/source/Commands/CommandObjectTarget.cpp
lldb/trunk/source/Core/AddressResolverName.cpp
lldb/trunk/source/Core/Disassembler.cpp
lldb/trunk/source/Core/Module.cpp
lldb/trunk/source/Symbol/Symtab.cpp
lldb/trunk/source/Target/CPPLanguageRuntime.cpp
Modified: lldb/trunk/include/lldb/Target/CPPLanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/CPPLanguageRuntime.h?rev=182179&r1=182178&r2=182179&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/CPPLanguageRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/CPPLanguageRuntime.h Fri May 17 19:11:21 2013
@@ -86,7 +86,7 @@ public:
return m_full;
}
- const ConstString &
+ llvm::StringRef
GetBasename ();
llvm::StringRef
@@ -103,7 +103,7 @@ public:
Parse();
ConstString m_full; // Full name: "lldb::SBTarget::GetBreakpointAtIndex(unsigned int) const"
- ConstString m_basename; // Basename: "GetBreakpointAtIndex"
+ llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex"
llvm::StringRef m_context; // Decl context: "lldb::SBTarget"
llvm::StringRef m_arguments; // Arguments: "(unsigned int)"
llvm::StringRef m_qualifiers; // Qualifiers: "const"
@@ -134,9 +134,6 @@ public:
IsCPPMangledName(const char *name);
static bool
- IsPossibleCPPCall (const char *name, const char *&base_name_start, const char *&base_name_end);
-
- static bool
StripNamespacesFromVariableName (const char *name, const char *&base_name_start, const char *&base_name_end);
// in some cases, compilers will output different names for one same type. when tht happens, it might be impossible
Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=182179&r1=182178&r2=182179&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Fri May 17 19:11:21 2013
@@ -541,10 +541,7 @@ namespace lldb {
// methods or selectors will be searched.
eFunctionNameTypeMethod = (1u << 4), // Find function by method name (C++) with no namespace or arguments
eFunctionNameTypeSelector = (1u << 5), // Find function by selector name (ObjC) names
- eFunctionNameTypeAny = (eFunctionNameTypeFull |
- eFunctionNameTypeBase |
- eFunctionNameTypeMethod |
- eFunctionNameTypeSelector )
+ eFunctionNameTypeAny = eFunctionNameTypeAuto // DEPRECATED: use eFunctionNameTypeAuto
} FunctionNameType;
Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=182179&r1=182178&r2=182179&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Fri May 17 19:11:21 2013
@@ -1676,7 +1676,7 @@ LookupFunctionInModule (CommandInterpret
ConstString function_name (name);
num_matches = module->FindFunctions (function_name,
NULL,
- eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector,
+ eFunctionNameTypeAuto,
include_symbols,
include_inlines,
append,
Modified: lldb/trunk/source/Core/AddressResolverName.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/AddressResolverName.cpp?rev=182179&r1=182178&r2=182179&view=diff
==============================================================================
--- lldb/trunk/source/Core/AddressResolverName.cpp (original)
+++ lldb/trunk/source/Core/AddressResolverName.cpp Fri May 17 19:11:21 2013
@@ -120,7 +120,7 @@ AddressResolverName::SearchCallback
sym_list);
context.module_sp->FindFunctions (m_func_name,
NULL,
- eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector,
+ eFunctionNameTypeAuto,
include_symbols,
include_inlines,
append,
Modified: lldb/trunk/source/Core/Disassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Disassembler.cpp?rev=182179&r1=182178&r2=182179&view=diff
==============================================================================
--- lldb/trunk/source/Core/Disassembler.cpp (original)
+++ lldb/trunk/source/Core/Disassembler.cpp Fri May 17 19:11:21 2013
@@ -194,10 +194,7 @@ Disassembler::Disassemble
{
module->FindFunctions (name,
NULL,
- eFunctionNameTypeBase |
- eFunctionNameTypeFull |
- eFunctionNameTypeMethod |
- eFunctionNameTypeSelector,
+ eFunctionNameTypeAuto,
include_symbols,
include_inlines,
true,
@@ -206,10 +203,7 @@ Disassembler::Disassemble
else if (exe_ctx.GetTargetPtr())
{
exe_ctx.GetTargetPtr()->GetImages().FindFunctions (name,
- eFunctionNameTypeBase |
- eFunctionNameTypeFull |
- eFunctionNameTypeMethod |
- eFunctionNameTypeSelector,
+ eFunctionNameTypeAuto,
include_symbols,
include_inlines,
false,
Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=182179&r1=182178&r2=182179&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Fri May 17 19:11:21 2013
@@ -1438,8 +1438,19 @@ Module::PrepareForFunctionNameLookup (co
if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
lookup_name_type_mask |= eFunctionNameTypeSelector;
- if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
+ CPPLanguageRuntime::MethodName cpp_method (name);
+ llvm::StringRef basename (cpp_method.GetBasename());
+ if (basename.empty())
+ {
+ if (CPPLanguageRuntime::StripNamespacesFromVariableName (name_cstr, base_name_start, base_name_end))
+ lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
+ }
+ else
+ {
+ base_name_start = basename.data();
+ base_name_end = base_name_start + basename.size();
lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
+ }
}
}
else
@@ -1449,11 +1460,30 @@ Module::PrepareForFunctionNameLookup (co
{
// If they've asked for a CPP method or function name and it can't be that, we don't
// even need to search for CPP methods or names.
- if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
+ 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();
+
+ if (!cpp_method.GetQualifiers().empty())
+ {
+ // There is a "const" or other qualifer following the end of the fucntion parens,
+ // this can't be a eFunctionNameTypeBase
+ lookup_name_type_mask &= ~(eFunctionNameTypeBase);
+ if (lookup_name_type_mask == eFunctionNameTypeNone)
+ return;
+ }
+ }
+ else
{
- lookup_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
- if (lookup_name_type_mask == eFunctionNameTypeNone)
- return;
+ if (!CPPLanguageRuntime::StripNamespacesFromVariableName (name_cstr, base_name_start, base_name_end))
+ {
+ lookup_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
+ if (lookup_name_type_mask == eFunctionNameTypeNone)
+ return;
+ }
}
}
Modified: lldb/trunk/source/Symbol/Symtab.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symtab.cpp?rev=182179&r1=182178&r2=182179&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Symtab.cpp (original)
+++ lldb/trunk/source/Symbol/Symtab.cpp Fri May 17 19:11:21 2013
@@ -320,7 +320,7 @@ Symtab::InitNameIndexes()
entry.cstring[2] != 'Z')) // named local entities (if we eventually handle eSymbolTypeData, we will want this back)
{
CPPLanguageRuntime::MethodName cxx_method (mangled.GetDemangledName());
- entry.cstring = cxx_method.GetBasename ().GetCString();
+ entry.cstring = ConstString(cxx_method.GetBasename()).GetCString();
if (entry.cstring && entry.cstring[0])
{
// ConstString objects permanently store the string in the pool so calling
Modified: lldb/trunk/source/Target/CPPLanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/CPPLanguageRuntime.cpp?rev=182179&r1=182178&r2=182179&view=diff
==============================================================================
--- lldb/trunk/source/Target/CPPLanguageRuntime.cpp (original)
+++ lldb/trunk/source/Target/CPPLanguageRuntime.cpp Fri May 17 19:11:21 2013
@@ -9,6 +9,8 @@
#include "lldb/Target/CPPLanguageRuntime.h"
+#include <string.h>
+
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/UniqueCStringMap.h"
#include "lldb/Target/ExecutionContext.h"
@@ -193,15 +195,7 @@ CPPLanguageRuntime::StripNamespacesFromV
if (base_name_end == NULL)
base_name_end = name + strlen (name);
- const char *last_colon = NULL;
- for (const char *ptr = base_name_end; ptr != name; ptr--)
- {
- if (*ptr == ':')
- {
- last_colon = ptr;
- break;
- }
- }
+ const char *last_colon = strrchr (name, ':');
if (last_colon == NULL)
{
@@ -221,36 +215,6 @@ CPPLanguageRuntime::StripNamespacesFromV
return true;
}
}
-bool
-CPPLanguageRuntime::IsPossibleCPPCall (const char *name, const char *&base_name_start, const char *&base_name_end)
-{
- if (!name)
- return false;
- // For now, I really can't handle taking template names apart, so if you
- // have < or > I'll say "could be CPP but leave the base_name empty which
- // means I couldn't figure out what to use for that.
- // FIXME: Do I need to do more sanity checking here?
-
- if (strchr(name, '>') != NULL || strchr (name, '>') != NULL)
- return true;
-
- size_t name_len = strlen (name);
-
- if (name[name_len - 1] == ')')
- {
- // We've got arguments.
- base_name_end = strchr (name, '(');
- if (base_name_end == NULL)
- return false;
-
- // FIXME: should check that this parenthesis isn't a template specialized
- // on a function type or something gross like that...
- }
- else
- base_name_end = name + strlen (name);
-
- return StripNamespacesFromVariableName (name, base_name_start, base_name_end);
-}
uint32_t
CPPLanguageRuntime::FindEquivalentNames(ConstString type_name, std::vector<ConstString>& equivalents)
@@ -272,7 +236,7 @@ void
CPPLanguageRuntime::MethodName::Clear()
{
m_full.Clear();
- m_basename.Clear();
+ m_basename = llvm::StringRef();
m_context = llvm::StringRef();
m_arguments = llvm::StringRef();
m_qualifiers = llvm::StringRef();
@@ -356,12 +320,12 @@ CPPLanguageRuntime::MethodName::Parse()
context_end = full.rfind(':', basename_end);
if (context_end == llvm::StringRef::npos)
- m_basename.SetString(full.substr(0, basename_end));
+ m_basename = full.substr(0, basename_end);
else
{
m_context = full.substr(0, context_end - 1);
const size_t basename_begin = context_end + 1;
- m_basename.SetString(full.substr(basename_begin, basename_end - basename_begin));
+ m_basename = full.substr(basename_begin, basename_end - basename_begin);
}
m_type = eTypeUnknownMethod;
}
@@ -388,7 +352,7 @@ CPPLanguageRuntime::MethodName::Parse()
}
}
-const ConstString &
+llvm::StringRef
CPPLanguageRuntime::MethodName::GetBasename ()
{
if (!m_parsed)
More information about the lldb-commits
mailing list