[Lldb-commits] [lldb] r173858 - <rdar://problem/9141269>
Greg Clayton
gclayton at apple.com
Tue Jan 29 16:18:29 PST 2013
Author: gclayton
Date: Tue Jan 29 18:18:29 2013
New Revision: 173858
URL: http://llvm.org/viewvc/llvm-project?rev=173858&view=rev
Log:
<rdar://problem/9141269>
Cleaned up the objective C name parsing code to use a class.
Now breakpoints that are set by name that are objective C methods without the leading '+' or '-' will resolve. We do this by expanding all the objective C names for a given string. For example:
(lldb) b [MyString cStringUsingEncoding:]
Will set a breakpoint with multiple possible names:
-[MyString cStringUsingEncoding:]
+[MyString cStringUsingEncoding:]
Also if you have a category, it will strip the category and set a breakpoint in all variants:
(lldb) [MyString(my_category) cStringUsingEncoding:]
Will resolve to the following names:
-[MyString(my_category) cStringUsingEncoding:]
+[MyString(my_category) cStringUsingEncoding:]
-[MyString cStringUsingEncoding:]
+[MyString cStringUsingEncoding:]
Likewise when we have:
(lldb) b -[MyString(my_category) cStringUsingEncoding:]
It will resolve to two names:
-[MyString(my_category) cStringUsingEncoding:]
-[MyString cStringUsingEncoding:]
Modified:
lldb/trunk/include/lldb/Core/RegularExpression.h
lldb/trunk/include/lldb/Core/Timer.h
lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp
lldb/trunk/source/Core/RegularExpression.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/trunk/source/Symbol/Symtab.cpp
lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
Modified: lldb/trunk/include/lldb/Core/RegularExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/RegularExpression.h?rev=173858&r1=173857&r2=173858&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/RegularExpression.h (original)
+++ lldb/trunk/include/lldb/Core/RegularExpression.h Tue Jan 29 18:18:29 2013
@@ -17,6 +17,11 @@
#include <string>
#include <vector>
+namespace llvm
+{
+ class StringRef;
+}
+
namespace lldb_private {
//----------------------------------------------------------------------
@@ -123,11 +128,22 @@ public:
bool
Execute (const char* string, size_t match_count = 0, int execute_flags = 0) const;
+ bool
+ ExecuteThreadSafe (const char* s,
+ llvm::StringRef *matches,
+ size_t num_matches,
+ int execute_flags = 0) const;
size_t
GetErrorAsCString (char *err_str, size_t err_str_max_len) const;
bool
GetMatchAtIndex (const char* s, uint32_t idx, std::string& match_str) const;
+
+ bool
+ GetMatchAtIndex (const char* s, uint32_t idx, llvm::StringRef& match_str) const;
+
+ bool
+ GetMatchSpanningIndices (const char* s, uint32_t idx1, uint32_t idx2, llvm::StringRef& match_str) const;
//------------------------------------------------------------------
/// Free the compiled regular expression.
///
Modified: lldb/trunk/include/lldb/Core/Timer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Timer.h?rev=173858&r1=173857&r2=173858&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Timer.h (original)
+++ lldb/trunk/include/lldb/Core/Timer.h Tue Jan 29 18:18:29 2013
@@ -11,8 +11,9 @@
#define liblldb_Timer_h_
#if defined(__cplusplus)
-#include <memory>
#include <stdio.h>
+#include <memory>
+#include <string>
#include "lldb/lldb-private.h"
#include "lldb/Host/TimeValue.h"
@@ -91,6 +92,49 @@ private:
DISALLOW_COPY_AND_ASSIGN (Timer);
};
+ class ScopedTimer
+ {
+ public:
+ ScopedTimer() :
+ m_start (TimeValue::Now())
+ {
+ }
+
+ uint64_t
+ GetElapsedNanoSeconds() const
+ {
+ return TimeValue::Now() - m_start;
+ }
+
+ protected:
+ TimeValue m_start;
+ };
+
+ class ScopedTimerAggregator
+ {
+ public:
+ ScopedTimerAggregator(const char *desc) :
+ m_description (desc),
+ m_total_nsec()
+ {
+ }
+
+ ~ScopedTimerAggregator()
+ {
+ printf ("Total nsec spent in %s is %llu\n", m_description.c_str(), m_total_nsec);
+ }
+ void
+ Aggregate (const ScopedTimer &scoped_timer)
+ {
+ m_total_nsec += scoped_timer.GetElapsedNanoSeconds();
+ }
+
+ protected:
+ std::string m_description;
+ uint64_t m_total_nsec;
+ };
+
+
} // namespace lldb_private
#endif // #if defined(__cplusplus)
Modified: lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h?rev=173858&r1=173857&r2=173858&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h Tue Jan 29 18:18:29 2013
@@ -31,7 +31,109 @@ class ObjCLanguageRuntime :
public LanguageRuntime
{
public:
-
+ class MethodName
+ {
+ public:
+ enum Type
+ {
+ eTypeUnspecified,
+ eTypeClassMethod,
+ eTypeInstanceMethod
+ };
+
+ MethodName () :
+ m_full(),
+ m_class(),
+ m_category(),
+ m_selector(),
+ m_type (eTypeUnspecified),
+ m_category_is_valid (false)
+ {
+ }
+
+ MethodName (const char *name, bool strict) :
+ m_full(),
+ m_class(),
+ m_category(),
+ m_selector(),
+ m_type (eTypeUnspecified),
+ m_category_is_valid (false)
+ {
+ SetName (name, strict);
+ }
+
+ void
+ Clear();
+
+ bool
+ IsValid (bool strict) const
+ {
+ // If "strict" is true, the name must have everything specified including
+ // the leading "+" or "-" on the method name
+ if (strict && m_type == eTypeUnspecified)
+ return false;
+ // Other than that, m_full will only be filled in if the objective C
+ // name is valid.
+ return (bool)m_full;
+ }
+
+ bool
+ HasCategory()
+ {
+ return (bool)GetCategory();
+ }
+
+ Type
+ GetType () const
+ {
+ return m_type;
+ }
+
+ const ConstString &
+ GetFullName () const
+ {
+ return m_full;
+ }
+
+ ConstString
+ GetFullNameWithoutCategory (bool empty_if_no_category);
+
+ bool
+ SetName (const char *name, bool strict);
+
+ const ConstString &
+ GetClassName ();
+
+ const ConstString &
+ GetClassNameWithCategory ();
+
+ const ConstString &
+ GetCategory ();
+
+ const ConstString &
+ GetSelector ();
+
+ // Get all possible names for a method. Examples:
+ // If name is "+[NSString(my_additions) myStringWithCString:]"
+ // names[0] => "+[NSString(my_additions) myStringWithCString:]"
+ // names[1] => "+[NSString myStringWithCString:]"
+ // If name is specified without the leading '+' or '-' like "[NSString(my_additions) myStringWithCString:]"
+ // names[0] => "+[NSString(my_additions) myStringWithCString:]"
+ // names[1] => "-[NSString(my_additions) myStringWithCString:]"
+ // names[2] => "+[NSString myStringWithCString:]"
+ // names[3] => "-[NSString myStringWithCString:]"
+ size_t
+ GetFullNames (std::vector<ConstString> &names, bool append);
+ protected:
+ ConstString m_full; // Full name: "+[NSString(my_additions) myStringWithCString:]"
+ ConstString m_class; // Class name: "NSString"
+ ConstString m_class_category; // Class with category: "NSString(my_additions)"
+ ConstString m_category; // Category: "my_additions"
+ ConstString m_selector; // Selector: "myStringWithCString:"
+ Type m_type;
+ bool m_category_is_valid;
+
+ };
typedef lldb::addr_t ObjCISA;
class ClassDescriptor;
@@ -351,12 +453,12 @@ public:
/// Returns the number of strings that were successfully filled
/// in.
//------------------------------------------------------------------
- static uint32_t
- ParseMethodName (const char *name,
- ConstString *class_name, // Class name (with category if there is one)
- ConstString *selector_name, // selector only
- ConstString *name_sans_category, // full function name with no category (empty if no category)
- ConstString *class_name_sans_category);// Class name without category (empty if no category)
+// static uint32_t
+// ParseMethodName (const char *name,
+// ConstString *class_name, // Class name (with category if there is one)
+// ConstString *selector_name, // selector only
+// ConstString *name_sans_category, // full function name with no category (empty if no category)
+// ConstString *class_name_sans_category);// Class name without category (empty if no category)
static bool
IsPossibleObjCMethodName (const char *name)
Modified: lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp?rev=173858&r1=173857&r2=173858&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp Tue Jan 29 18:18:29 2013
@@ -22,6 +22,7 @@
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Symbol/SymbolContext.h"
+#include "lldb/Target/ObjCLanguageRuntime.h"
using namespace lldb;
using namespace lldb_private;
@@ -54,7 +55,12 @@ BreakpointResolverName::BreakpointResolv
}
else
{
- m_func_names.push_back(ConstString(func_name));
+ const bool append = true;
+ ObjCLanguageRuntime::MethodName objc_name(func_name, false);
+ if (objc_name.IsValid(false))
+ objc_name.GetFullNames(m_func_names, append);
+ else
+ m_func_names.push_back(ConstString(func_name));
}
}
@@ -68,9 +74,14 @@ BreakpointResolverName::BreakpointResolv
m_match_type (Breakpoint::Exact),
m_skip_prologue (skip_prologue)
{
+ const bool append = true;
for (size_t i = 0; i < num_names; i++)
{
- m_func_names.push_back (ConstString (names[i]));
+ ObjCLanguageRuntime::MethodName objc_name(names[i], false);
+ if (objc_name.IsValid(false))
+ objc_name.GetFullNames(m_func_names, append);
+ else
+ m_func_names.push_back (ConstString (names[i]));
}
}
@@ -84,10 +95,14 @@ BreakpointResolverName::BreakpointResolv
m_skip_prologue (skip_prologue)
{
size_t num_names = names.size();
-
+ const bool append = true;
for (size_t i = 0; i < num_names; i++)
{
- m_func_names.push_back (ConstString (names[i].c_str()));
+ ObjCLanguageRuntime::MethodName objc_name(names[i].c_str(), false);
+ if (objc_name.IsValid(false))
+ objc_name.GetFullNames(m_func_names, append);
+ else
+ m_func_names.push_back (ConstString (names[i].c_str()));
}
}
Modified: lldb/trunk/source/Core/RegularExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegularExpression.cpp?rev=173858&r1=173857&r2=173858&view=diff
==============================================================================
--- lldb/trunk/source/Core/RegularExpression.cpp (original)
+++ lldb/trunk/source/Core/RegularExpression.cpp Tue Jan 29 18:18:29 2013
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/Core/RegularExpression.h"
+#include "llvm/ADT/StringRef.h"
#include <string.h>
using namespace lldb_private;
@@ -146,6 +147,34 @@ RegularExpression::Execute(const char* s
}
bool
+RegularExpression::ExecuteThreadSafe (const char* s, llvm::StringRef *match_srefs, size_t count, int execute_flags) const
+{
+ bool success = false;
+ if (m_comp_err == 0)
+ {
+ std::vector<regmatch_t> matches;
+
+ if (match_srefs && count > 0)
+ matches.resize(count + 1);
+
+ success = ::regexec (&m_preg,
+ s,
+ matches.size(),
+ matches.data(),
+ execute_flags) == 0;
+ for (size_t i=0; i<count; ++i)
+ {
+ size_t match_idx = i+1;
+ if (success && matches[match_idx].rm_so < matches[match_idx].rm_eo)
+ match_srefs[i] = llvm::StringRef(s + matches[match_idx].rm_so, matches[match_idx].rm_eo - matches[match_idx].rm_so);
+ else
+ match_srefs[i] = llvm::StringRef();
+ }
+ }
+ return success;
+}
+
+bool
RegularExpression::GetMatchAtIndex (const char* s, uint32_t idx, std::string& match_str) const
{
if (idx <= m_preg.re_nsub && idx < m_matches.size())
@@ -166,6 +195,46 @@ RegularExpression::GetMatchAtIndex (cons
return false;
}
+bool
+RegularExpression::GetMatchAtIndex (const char* s, uint32_t idx, llvm::StringRef& match_str) const
+{
+ if (idx <= m_preg.re_nsub && idx < m_matches.size())
+ {
+ if (m_matches[idx].rm_eo == m_matches[idx].rm_so)
+ {
+ // Matched the empty string...
+ match_str = llvm::StringRef();
+ return true;
+ }
+ else if (m_matches[idx].rm_eo > m_matches[idx].rm_so)
+ {
+ match_str = llvm::StringRef (s + m_matches[idx].rm_so, m_matches[idx].rm_eo - m_matches[idx].rm_so);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+RegularExpression::GetMatchSpanningIndices (const char* s, uint32_t idx1, uint32_t idx2, llvm::StringRef& match_str) const
+{
+ if (idx1 <= m_preg.re_nsub && idx1 < m_matches.size() && idx2 <= m_preg.re_nsub && idx2 < m_matches.size())
+ {
+ if (m_matches[idx1].rm_so == m_matches[idx2].rm_eo)
+ {
+ // Matched the empty string...
+ match_str = llvm::StringRef();
+ return true;
+ }
+ else if (m_matches[idx1].rm_so < m_matches[idx2].rm_eo)
+ {
+ match_str = llvm::StringRef (s + m_matches[idx1].rm_so, m_matches[idx2].rm_eo - m_matches[idx1].rm_so);
+ return true;
+ }
+ }
+ return false;
+}
+
//----------------------------------------------------------------------
// Returns true if the regular expression compiled and is ready
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=173858&r1=173857&r2=173858&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Tue Jan 29 18:18:29 2013
@@ -396,7 +396,7 @@ CommandInterpreter::LoadCommandDictionar
const char *break_regexes[][2] = {{"^(.*[^[:space:]])[[:space:]]*:[[:space:]]*([[:digit:]]+)[[:space:]]*$", "breakpoint set --file '%1' --line %2"},
{"^([[:digit:]]+)[[:space:]]*$", "breakpoint set --line %1"},
{"^(0x[[:xdigit:]]+)[[:space:]]*$", "breakpoint set --address %1"},
- {"^[\"']?([-+]\\[.*\\])[\"']?[[:space:]]*$", "breakpoint set --name '%1'"},
+ {"^[\"']?([-+]?\\[.*\\])[\"']?[[:space:]]*$", "breakpoint set --name '%1'"},
{"^(-.*)$", "breakpoint set %1"},
{"^(.*[^[:space:]])`(.*[^[:space:]])[[:space:]]*$", "breakpoint set --name '%2' --shlib '%1'"},
{"^(.*[^[:space:]])[[:space:]]*$", "breakpoint set --name '%1'"}};
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp?rev=173858&r1=173857&r2=173858&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Tue Jan 29 18:18:29 2013
@@ -764,28 +764,22 @@ DWARFCompileUnit::Index (const uint32_t
{
// Note, this check is also done in ParseMethodName, but since this is a hot loop, we do the
// simple inlined check outside the call.
- if (ObjCLanguageRuntime::IsPossibleObjCMethodName(name))
+ ObjCLanguageRuntime::MethodName objc_method(name, true);
+ if (objc_method.IsValid(true))
{
- ConstString objc_class_name;
- ConstString objc_selector_name;
- ConstString objc_fullname_no_category_name;
- ConstString objc_class_name_no_category;
- if (ObjCLanguageRuntime::ParseMethodName (name,
- &objc_class_name,
- &objc_selector_name,
- &objc_fullname_no_category_name,
- &objc_class_name_no_category))
- {
- func_fullnames.Insert (ConstString(name), die.GetOffset());
- if (objc_class_name)
- objc_class_selectors.Insert(objc_class_name, die.GetOffset());
- if (objc_class_name_no_category)
- objc_class_selectors.Insert(objc_class_name_no_category, die.GetOffset());
- if (objc_selector_name)
- func_selectors.Insert (objc_selector_name, die.GetOffset());
- if (objc_fullname_no_category_name)
- func_fullnames.Insert (objc_fullname_no_category_name, die.GetOffset());
- }
+ ConstString objc_class_name_with_category (objc_method.GetClassNameWithCategory());
+ ConstString objc_selector_name (objc_method.GetSelector());
+ ConstString objc_fullname_no_category_name (objc_method.GetFullNameWithoutCategory(true));
+ ConstString objc_class_name_no_category (objc_method.GetClassName());
+ func_fullnames.Insert (ConstString(name), die.GetOffset());
+ if (objc_class_name_with_category)
+ objc_class_selectors.Insert(objc_class_name_with_category, die.GetOffset());
+ if (objc_class_name_no_category && objc_class_name_no_category != objc_class_name_with_category)
+ objc_class_selectors.Insert(objc_class_name_no_category, die.GetOffset());
+ if (objc_selector_name)
+ func_selectors.Insert (objc_selector_name, die.GetOffset());
+ if (objc_fullname_no_category_name)
+ func_fullnames.Insert (objc_fullname_no_category_name, die.GetOffset());
}
// If we have a mangled name, then the DW_AT_name attribute
// is usually the method name without the class or any parameters
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=173858&r1=173857&r2=173858&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Tue Jan 29 18:18:29 2013
@@ -1715,22 +1715,14 @@ SymbolFileDWARF::ParseChildMembers
if (prop_getter_name && prop_getter_name[0] == '-')
{
- ObjCLanguageRuntime::ParseMethodName (prop_getter_name,
- NULL,
- &fixed_getter,
- NULL,
- NULL);
- prop_getter_name = fixed_getter.GetCString();
+ ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
+ prop_getter_name = prop_getter_method.GetSelector().GetCString();
}
if (prop_setter_name && prop_setter_name[0] == '-')
{
- ObjCLanguageRuntime::ParseMethodName (prop_setter_name,
- NULL,
- &fixed_setter,
- NULL,
- NULL);
- prop_setter_name = fixed_setter.GetCString();
+ ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
+ prop_setter_name = prop_setter_method.GetSelector().GetCString();
}
// If the names haven't been provided, they need to be
@@ -6281,16 +6273,12 @@ SymbolFileDWARF::ParseType (const Symbol
bool type_handled = false;
if (tag == DW_TAG_subprogram)
{
- ConstString class_name;
- ConstString class_name_no_category;
- if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
- {
- // Use the class name with no category if there is one
- if (class_name_no_category)
- class_name = class_name_no_category;
-
+ ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
+ if (objc_method.IsValid(true))
+ {
SymbolContext empty_sc;
clang_type_t class_opaque_type = NULL;
+ ConstString class_name(objc_method.GetClassName());
if (class_name)
{
TypeList types;
Modified: lldb/trunk/source/Symbol/Symtab.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symtab.cpp?rev=173858&r1=173857&r2=173858&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Symtab.cpp (original)
+++ lldb/trunk/source/Symbol/Symtab.cpp Tue Jan 29 18:18:29 2013
@@ -310,18 +310,18 @@ Symtab::InitNameIndexes()
// If the demangled name turns out to be an ObjC name, and
// is a category name, add the version without categories to the index too.
- ConstString objc_selector_name;
- ConstString objc_base_name;
- if (ObjCLanguageRuntime::ParseMethodName (entry.cstring,
- NULL,
- &objc_selector_name,
- &objc_base_name,
- NULL))
- {
- entry.cstring = objc_base_name.GetCString();
- m_name_to_index.Append (entry);
- entry.cstring = objc_selector_name.GetCString();
+ ObjCLanguageRuntime::MethodName objc_method (entry.cstring, true);
+ if (objc_method.IsValid(true))
+ {
+ entry.cstring = objc_method.GetSelector().GetCString();
m_selector_to_index.Append (entry);
+
+ ConstString objc_method_no_category (objc_method.GetFullNameWithoutCategory(true));
+ if (objc_method_no_category)
+ {
+ entry.cstring = objc_method_no_category.GetCString();
+ m_name_to_index.Append (entry);
+ }
}
}
Modified: lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ObjCLanguageRuntime.cpp?rev=173858&r1=173857&r2=173858&view=diff
==============================================================================
--- lldb/trunk/source/Target/ObjCLanguageRuntime.cpp (original)
+++ lldb/trunk/source/Target/ObjCLanguageRuntime.cpp Tue Jan 29 18:18:29 2013
@@ -11,6 +11,7 @@
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Timer.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/Type.h"
@@ -18,6 +19,8 @@
#include "lldb/Target/ObjCLanguageRuntime.h"
#include "lldb/Target/Target.h"
+#include "llvm/ADT/StringRef.h"
+
using namespace lldb;
using namespace lldb_private;
@@ -131,89 +134,375 @@ ObjCLanguageRuntime::GetByteOffsetForIva
return LLDB_INVALID_IVAR_OFFSET;
}
+void
+ObjCLanguageRuntime::MethodName::Clear()
+{
+ m_full.Clear();
+ m_class.Clear();
+ m_category.Clear();
+ m_selector.Clear();
+ m_type = eTypeUnspecified;
+ m_category_is_valid = false;
+}
+
+//bool
+//ObjCLanguageRuntime::MethodName::SetName (const char *name, bool strict)
+//{
+// Clear();
+// if (name && name[0])
+// {
+// // If "strict" is true. then the method must be specified with a
+// // '+' or '-' at the beginning. If "strict" is false, then the '+'
+// // or '-' can be omitted
+// bool valid_prefix = false;
+//
+// if (name[0] == '+' || name[0] == '-')
+// {
+// valid_prefix = name[1] == '[';
+// }
+// else if (!strict)
+// {
+// // "strict" is false, the name just needs to start with '['
+// valid_prefix = name[0] == '[';
+// }
+//
+// if (valid_prefix)
+// {
+// static RegularExpression g_regex("^([-+]?)\\[([A-Za-z_][A-Za-z_0-9]*)(\\([A-Za-z_][A-Za-z_0-9]*\\))? ([A-Za-z_][A-Za-z_0-9:]*)\\]$");
+// llvm::StringRef matches[4];
+// // Since we are using a global regular expression, we must use the threadsafe version of execute
+// if (g_regex.ExecuteThreadSafe(name, matches, 4))
+// {
+// m_full.SetCString(name);
+// if (matches[0].empty())
+// m_type = eTypeUnspecified;
+// else if (matches[0][0] == '+')
+// m_type = eTypeClassMethod;
+// else
+// m_type = eTypeInstanceMethod;
+// m_class.SetString(matches[1]);
+// m_selector.SetString(matches[3]);
+// if (!matches[2].empty())
+// m_category.SetString(matches[2]);
+// }
+// }
+// }
+// return IsValid(strict);
+//}
-uint32_t
-ObjCLanguageRuntime::ParseMethodName (const char *name,
- ConstString *class_name, // Class name (with category if any)
- ConstString *selector_name, // selector on its own
- ConstString *name_sans_category, // Full function prototype with no category
- ConstString *class_name_sans_category)// Class name with no category (or empty if no category as answer will be in "class_name"
-{
- if (class_name)
- class_name->Clear();
- if (selector_name)
- selector_name->Clear();
- if (name_sans_category)
- name_sans_category->Clear();
- if (class_name_sans_category)
- class_name_sans_category->Clear();
-
- uint32_t result = 0;
+bool
+ObjCLanguageRuntime::MethodName::SetName (const char *name, bool strict)
+{
+ Clear();
+ if (name && name[0])
+ {
+ // If "strict" is true. then the method must be specified with a
+ // '+' or '-' at the beginning. If "strict" is false, then the '+'
+ // or '-' can be omitted
+ bool valid_prefix = false;
+
+ if (name[0] == '+' || name[0] == '-')
+ {
+ valid_prefix = name[1] == '[';
+ if (name[0] == '+')
+ m_type = eTypeClassMethod;
+ else
+ m_type = eTypeInstanceMethod;
+ }
+ else if (!strict)
+ {
+ // "strict" is false, the name just needs to start with '['
+ valid_prefix = name[0] == '[';
+ }
+
+ if (valid_prefix)
+ {
+ int name_len = strlen (name);
+ // Objective C methods must have at least:
+ // "-[" or "+[" prefix
+ // One character for a class name
+ // One character for the space between the class name
+ // One character for the method name
+ // "]" suffix
+ if (name_len >= (5 + (strict ? 1 : 0)) && name[name_len - 1] == ']')
+ {
+ m_full.SetCStringWithLength(name, name_len);
+ }
+ }
+ }
+ return IsValid(strict);
+}
- if (IsPossibleObjCMethodName (name))
+const ConstString &
+ObjCLanguageRuntime::MethodName::GetClassName ()
+{
+ if (!m_class)
{
- int name_len = strlen (name);
- // Objective C methods must have at least:
- // "-[" or "+[" prefix
- // One character for a class name
- // One character for the space between the class name
- // One character for the method name
- // "]" suffix
- if (name_len >= 6 && name[name_len - 1] == ']')
+ if (IsValid(false))
{
- const char *selector_name_ptr = strchr (name, ' ');
- if (selector_name_ptr)
+ const char *full = m_full.GetCString();
+ const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
+ const char *paren_pos = strchr (class_start, '(');
+ if (paren_pos)
{
- if (class_name)
- {
- class_name->SetCStringWithLength (name + 2, selector_name_ptr - name - 2);
- ++result;
- }
-
- // Skip the space
- ++selector_name_ptr;
- // Extract the objective C basename and add it to the
- // accelerator tables
- size_t selector_name_len = name_len - (selector_name_ptr - name) - 1;
- if (selector_name)
- {
- selector_name->SetCStringWithLength (selector_name_ptr, selector_name_len);
- ++result;
- }
-
- // Also see if this is a "category" on our class. If so strip off the category name,
- // and add the class name without it to the basename table.
-
- if (name_sans_category || class_name_sans_category)
+ m_class.SetCStringWithLength (class_start, paren_pos - class_start);
+ }
+ else
+ {
+ // No '(' was found in the full name, we can definitively say
+ // that our category was valid (and empty).
+ m_category_is_valid = true;
+ const char *space_pos = strchr (full, ' ');
+ if (space_pos)
{
- const char *open_paren = strchr (name, '(');
- if (open_paren)
+ m_class.SetCStringWithLength (class_start, space_pos - class_start);
+ if (!m_class_category)
{
- if (class_name_sans_category)
- {
- class_name_sans_category->SetCStringWithLength (name + 2, open_paren - name - 2);
- ++result;
- }
-
- if (name_sans_category)
- {
- const char *close_paren = strchr (open_paren, ')');
- if (open_paren < close_paren)
- {
- std::string buffer (name, open_paren - name);
- buffer.append (close_paren + 1);
- name_sans_category->SetCString (buffer.c_str());
- ++result;
- }
- }
+ // No category in name, so we can also fill in the m_class_category
+ m_class_category = m_class;
}
}
}
}
}
- return result;
+ return m_class;
+}
+
+const ConstString &
+ObjCLanguageRuntime::MethodName::GetClassNameWithCategory ()
+{
+ if (!m_class_category)
+ {
+ if (IsValid(false))
+ {
+ const char *full = m_full.GetCString();
+ const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
+ const char *space_pos = strchr (full, ' ');
+ if (space_pos)
+ {
+ m_class_category.SetCStringWithLength (class_start, space_pos - class_start);
+ // If m_class hasn't been filled in and the class with category doesn't
+ // contain a '(', then we can also fill in the m_class
+ if (!m_class && strchr (m_class_category.GetCString(), '(') == NULL)
+ {
+ m_class = m_class_category;
+ // No '(' was found in the full name, we can definitively say
+ // that our category was valid (and empty).
+ m_category_is_valid = true;
+
+ }
+ }
+ }
+ }
+ return m_class_category;
}
+const ConstString &
+ObjCLanguageRuntime::MethodName::GetSelector ()
+{
+ if (!m_selector)
+ {
+ if (IsValid(false))
+ {
+ const char *full = m_full.GetCString();
+ const char *space_pos = strchr (full, ' ');
+ if (space_pos)
+ {
+ ++space_pos; // skip the space
+ m_selector.SetCStringWithLength (space_pos, m_full.GetLength() - (space_pos - full) - 1);
+ }
+ }
+ }
+ return m_selector;
+}
+
+const ConstString &
+ObjCLanguageRuntime::MethodName::GetCategory ()
+{
+ if (!m_category_is_valid && !m_category)
+ {
+ if (IsValid(false))
+ {
+ m_category_is_valid = true;
+ const char *full = m_full.GetCString();
+ const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
+ const char *open_paren_pos = strchr (class_start, '(');
+ if (open_paren_pos)
+ {
+ ++open_paren_pos; // Skip the open paren
+ const char *close_paren_pos = strchr (open_paren_pos, ')');
+ if (close_paren_pos)
+ m_category.SetCStringWithLength (open_paren_pos, close_paren_pos - open_paren_pos);
+ }
+ }
+ }
+ return m_category;
+}
+
+ConstString
+ObjCLanguageRuntime::MethodName::GetFullNameWithoutCategory (bool empty_if_no_category)
+{
+ if (IsValid(false))
+ {
+ if (HasCategory())
+ {
+ StreamString strm;
+ if (m_type == eTypeClassMethod)
+ strm.PutChar('+');
+ else if (m_type == eTypeInstanceMethod)
+ strm.PutChar('-');
+ strm.Printf("[%s %s]", GetClassName().GetCString(), GetSelector().GetCString());
+ return ConstString(strm.GetString().c_str());
+ }
+
+ if (!empty_if_no_category)
+ {
+ // Just return the full name since it doesn't have a category
+ return GetFullName();
+ }
+ }
+ return ConstString();
+}
+
+size_t
+ObjCLanguageRuntime::MethodName::GetFullNames (std::vector<ConstString> &names, bool append)
+{
+ if (!append)
+ names.clear();
+ if (IsValid(false))
+ {
+ StreamString strm;
+ const bool is_class_method = m_type == eTypeClassMethod;
+ const bool is_instance_method = m_type == eTypeInstanceMethod;
+ const ConstString &category = GetCategory();
+ if (is_class_method || is_instance_method)
+ {
+ names.push_back (m_full);
+ if (category)
+ {
+ strm.Printf("%c[%s %s]",
+ is_class_method ? '+' : '-',
+ GetClassName().GetCString(),
+ GetSelector().GetCString());
+ names.push_back(ConstString(strm.GetString().c_str()));
+ }
+ }
+ else
+ {
+ const ConstString &class_name = GetClassName();
+ const ConstString &selector = GetSelector();
+ strm.Printf("+[%s %s]", class_name.GetCString(), selector.GetCString());
+ names.push_back(ConstString(strm.GetString().c_str()));
+ strm.Clear();
+ strm.Printf("-[%s %s]", class_name.GetCString(), selector.GetCString());
+ names.push_back(ConstString(strm.GetString().c_str()));
+ strm.Clear();
+ if (category)
+ {
+ strm.Printf("+[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
+ names.push_back(ConstString(strm.GetString().c_str()));
+ strm.Clear();
+ strm.Printf("-[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
+ names.push_back(ConstString(strm.GetString().c_str()));
+ }
+ }
+ }
+ return names.size();
+}
+
+
+//uint32_t
+//ObjCLanguageRuntime::ParseMethodName (const char *name,
+// ConstString *class_name, // Class name (with category if any)
+// ConstString *selector_name, // selector on its own
+// ConstString *name_sans_category, // Full function prototype with no category
+// ConstString *class_name_sans_category)// Class name with no category (or empty if no category as answer will be in "class_name"
+//{
+// static ScopedTimerAggregator g_scoped_timer_aggregator ("ObjCLanguageRuntime::ParseMethodName");
+// ScopedTimer scoped_timer;
+// uint32_t result = 0;
+// if (class_name)
+// class_name->Clear();
+// if (selector_name)
+// selector_name->Clear();
+// if (name_sans_category)
+// name_sans_category->Clear();
+// if (class_name_sans_category)
+// class_name_sans_category->Clear();
+//
+//
+// if (IsPossibleObjCMethodName (name))
+// {
+// int name_len = strlen (name);
+// // Objective C methods must have at least:
+// // "-[" or "+[" prefix
+// // One character for a class name
+// // One character for the space between the class name
+// // One character for the method name
+// // "]" suffix
+// if (name_len >= 6 && name[name_len - 1] == ']')
+// {
+// const char *selector_name_ptr = strchr (name, ' ');
+// if (selector_name_ptr)
+// {
+// if (class_name)
+// {
+// class_name->SetCStringWithLength (name + 2, selector_name_ptr - name - 2);
+// ++result;
+// }
+//
+// // Skip the space
+// ++selector_name_ptr;
+// // Extract the objective C basename and add it to the
+// // accelerator tables
+// size_t selector_name_len = name_len - (selector_name_ptr - name) - 1;
+// if (selector_name)
+// {
+// selector_name->SetCStringWithLength (selector_name_ptr, selector_name_len);
+// ++result;
+// }
+//
+// // Also see if this is a "category" on our class. If so strip off the category name,
+// // and add the class name without it to the basename table.
+//
+// if (name_sans_category || class_name_sans_category)
+// {
+// const char *open_paren = strchr (name, '(');
+// if (open_paren)
+// {
+// if (class_name_sans_category)
+// {
+// class_name_sans_category->SetCStringWithLength (name + 2, open_paren - name - 2);
+// ++result;
+// }
+//
+// if (name_sans_category)
+// {
+// const char *close_paren = strchr (open_paren, ')');
+// if (open_paren < close_paren)
+// {
+// std::string buffer (name, open_paren - name);
+// buffer.append (close_paren + 1);
+// name_sans_category->SetCString (buffer.c_str());
+// ++result;
+// }
+// }
+// }
+// }
+// }
+// }
+// }
+// ObjCLanguageRuntime::MethodName method_name(name, true);
+// if (class_name)
+// assert (*class_name == method_name.GetClassNameWithCategory());
+// if (selector_name)
+// assert (*selector_name == method_name.GetSelector());
+// if (class_name_sans_category)
+// assert (*class_name_sans_category == method_name.GetClassName());
+// g_scoped_timer_aggregator.Aggregate (scoped_timer);
+// return result;
+//}
+
bool
ObjCLanguageRuntime::ClassDescriptor::IsPointerValid (lldb::addr_t value,
uint32_t ptr_size,
More information about the lldb-commits
mailing list