diff options
Diffstat (limited to 'lldb/source/Plugins')
7 files changed, 869 insertions, 12 deletions
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index b44ba55853e..a69e3dc4246 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -9,8 +9,14 @@ #include "CPlusPlusLanguage.h" +#include <string.h> + +#include "llvm/ADT/StringRef.h" + #include "lldb/Core/ConstString.h" #include "lldb/Core/PluginManager.h" +#include "lldb/Core/RegularExpression.h" +#include "lldb/Core/UniqueCStringMap.h" using namespace lldb; using namespace lldb_private; @@ -62,3 +68,373 @@ CPlusPlusLanguage::CreateInstance (lldb::LanguageType language) return new CPlusPlusLanguage(); return nullptr; } + +void +CPlusPlusLanguage::MethodName::Clear() +{ + m_full.Clear(); + m_basename = llvm::StringRef(); + m_context = llvm::StringRef(); + m_arguments = llvm::StringRef(); + m_qualifiers = llvm::StringRef(); + m_type = eTypeInvalid; + m_parsed = false; + m_parse_error = false; +} + +bool +ReverseFindMatchingChars (const llvm::StringRef &s, + const llvm::StringRef &left_right_chars, + size_t &left_pos, + size_t &right_pos, + size_t pos = llvm::StringRef::npos) +{ + assert (left_right_chars.size() == 2); + left_pos = llvm::StringRef::npos; + const char left_char = left_right_chars[0]; + const char right_char = left_right_chars[1]; + pos = s.find_last_of(left_right_chars, pos); + if (pos == llvm::StringRef::npos || s[pos] == left_char) + return false; + right_pos = pos; + uint32_t depth = 1; + while (pos > 0 && depth > 0) + { + pos = s.find_last_of(left_right_chars, pos); + if (pos == llvm::StringRef::npos) + return false; + if (s[pos] == left_char) + { + if (--depth == 0) + { + left_pos = pos; + return left_pos < right_pos; + } + } + else if (s[pos] == right_char) + { + ++depth; + } + } + return false; +} + + +void +CPlusPlusLanguage::MethodName::Parse() +{ + if (!m_parsed && m_full) + { +// ConstString mangled; +// m_full.GetMangledCounterpart(mangled); +// printf ("\n parsing = '%s'\n", m_full.GetCString()); +// if (mangled) +// printf (" mangled = '%s'\n", mangled.GetCString()); + m_parse_error = false; + m_parsed = true; + llvm::StringRef full (m_full.GetCString()); + + size_t arg_start, arg_end; + llvm::StringRef parens("()", 2); + if (ReverseFindMatchingChars (full, parens, arg_start, arg_end)) + { + m_arguments = full.substr(arg_start, arg_end - arg_start + 1); + if (arg_end + 1 < full.size()) + m_qualifiers = full.substr(arg_end + 1); + if (arg_start > 0) + { + size_t basename_end = arg_start; + size_t context_start = 0; + size_t context_end = llvm::StringRef::npos; + if (basename_end > 0 && full[basename_end-1] == '>') + { + // TODO: handle template junk... + // Templated function + size_t template_start, template_end; + llvm::StringRef lt_gt("<>", 2); + if (ReverseFindMatchingChars (full, lt_gt, template_start, template_end, basename_end)) + { + // Check for templated functions that include return type like: 'void foo<Int>()' + context_start = full.rfind(' ', template_start); + if (context_start == llvm::StringRef::npos) + context_start = 0; + + context_end = full.rfind(':', template_start); + if (context_end == llvm::StringRef::npos || context_end < context_start) + context_end = context_start; + } + else + { + context_end = full.rfind(':', basename_end); + } + } + else if (context_end == llvm::StringRef::npos) + { + context_end = full.rfind(':', basename_end); + } + + if (context_end == llvm::StringRef::npos) + m_basename = full.substr(0, basename_end); + else + { + if (context_start < context_end) + m_context = full.substr(context_start, context_end - 1); + const size_t basename_begin = context_end + 1; + m_basename = full.substr(basename_begin, basename_end - basename_begin); + } + m_type = eTypeUnknownMethod; + } + else + { + m_parse_error = true; + return; + } + +// if (!m_context.empty()) +// printf (" context = '%s'\n", m_context.str().c_str()); +// if (m_basename) +// printf (" basename = '%s'\n", m_basename.GetCString()); +// if (!m_arguments.empty()) +// printf (" arguments = '%s'\n", m_arguments.str().c_str()); +// if (!m_qualifiers.empty()) +// printf ("qualifiers = '%s'\n", m_qualifiers.str().c_str()); + + // Make sure we have a valid C++ basename with optional template args + static RegularExpression g_identifier_regex("^~?([A-Za-z_][A-Za-z_0-9]*)(<.*>)?$"); + std::string basename_str(m_basename.str()); + bool basename_is_valid = g_identifier_regex.Execute (basename_str.c_str(), NULL); + if (!basename_is_valid) + { + // Check for C++ operators + if (m_basename.startswith("operator")) + { + static RegularExpression g_operator_regex("^(operator)( ?)([A-Za-z_][A-Za-z_0-9]*|\\(\\)|\\[\\]|[\\^<>=!\\/*+-]+)(<.*>)?(\\[\\])?$"); + basename_is_valid = g_operator_regex.Execute(basename_str.c_str(), NULL); + } + } + if (!basename_is_valid) + { + // The C++ basename doesn't match our regular expressions so this can't + // be a valid C++ method, clear everything out and indicate an error + m_context = llvm::StringRef(); + m_basename = llvm::StringRef(); + m_arguments = llvm::StringRef(); + m_qualifiers = llvm::StringRef(); + m_parse_error = true; + } + } + else + { + m_parse_error = true; +// printf ("error: didn't find matching parens for arguments\n"); + } + } +} + +llvm::StringRef +CPlusPlusLanguage::MethodName::GetBasename () +{ + if (!m_parsed) + Parse(); + return m_basename; +} + +llvm::StringRef +CPlusPlusLanguage::MethodName::GetContext () +{ + if (!m_parsed) + Parse(); + return m_context; +} + +llvm::StringRef +CPlusPlusLanguage::MethodName::GetArguments () +{ + if (!m_parsed) + Parse(); + return m_arguments; +} + +llvm::StringRef +CPlusPlusLanguage::MethodName::GetQualifiers () +{ + if (!m_parsed) + Parse(); + return m_qualifiers; +} + +bool +CPlusPlusLanguage::IsCPPMangledName (const char *name) +{ + // FIXME, we should really run through all the known C++ Language plugins and ask each one if + // this is a C++ mangled name, but we can put that off till there is actually more than one + // we care about. + + if (name && name[0] == '_' && name[1] == 'Z') + return true; + else + return false; +} + +bool +CPlusPlusLanguage::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(4); + if (g_basename_regex.Execute (name, &match)) + { + match.GetMatchAtIndex(name, 1, context); + match.GetMatchAtIndex(name, 3, identifier); + return true; + } + return false; +} + +class CPPRuntimeEquivalents +{ +public: + CPPRuntimeEquivalents () + { + + m_impl.Append(ConstString("std::basic_string<char, std::char_traits<char>, std::allocator<char> >").AsCString(), ConstString("basic_string<char>")); + + // these two (with a prefixed std::) occur when c++stdlib string class occurs as a template argument in some STL container + m_impl.Append(ConstString("std::basic_string<char, std::char_traits<char>, std::allocator<char> >").AsCString(), ConstString("std::basic_string<char>")); + + m_impl.Sort(); + } + + void + Add (ConstString& type_name, + ConstString& type_equivalent) + { + m_impl.Insert(type_name.AsCString(), type_equivalent); + } + + uint32_t + FindExactMatches (ConstString& type_name, + std::vector<ConstString>& equivalents) + { + + uint32_t count = 0; + + for (ImplData match = m_impl.FindFirstValueForName(type_name.AsCString()); + match != NULL; + match = m_impl.FindNextValueForName(match)) + { + equivalents.push_back(match->value); + count++; + } + + return count; + } + + // partial matches can occur when a name with equivalents is a template argument. + // e.g. we may have "class Foo" be a match for "struct Bar". if we have a typename + // such as "class Templatized<class Foo, Anything>" we want this to be replaced with + // "class Templatized<struct Bar, Anything>". Since partial matching is time consuming + // once we get a partial match, we add it to the exact matches list for faster retrieval + uint32_t + FindPartialMatches (ConstString& type_name, + std::vector<ConstString>& equivalents) + { + + uint32_t count = 0; + + const char* type_name_cstr = type_name.AsCString(); + + size_t items_count = m_impl.GetSize(); + + for (size_t item = 0; item < items_count; item++) + { + const char* key_cstr = m_impl.GetCStringAtIndex(item); + if ( strstr(type_name_cstr,key_cstr) ) + { + count += AppendReplacements(type_name_cstr, + key_cstr, + equivalents); + } + } + + return count; + + } + +private: + + std::string& replace (std::string& target, + std::string& pattern, + std::string& with) + { + size_t pos; + size_t pattern_len = pattern.size(); + + while ( (pos = target.find(pattern)) != std::string::npos ) + target.replace(pos, pattern_len, with); + + return target; + } + + uint32_t + AppendReplacements (const char* original, + const char *matching_key, + std::vector<ConstString>& equivalents) + { + + std::string matching_key_str(matching_key); + ConstString original_const(original); + + uint32_t count = 0; + + for (ImplData match = m_impl.FindFirstValueForName(matching_key); + match != NULL; + match = m_impl.FindNextValueForName(match)) + { + std::string target(original); + std::string equiv_class(match->value.AsCString()); + + replace (target, matching_key_str, equiv_class); + + ConstString target_const(target.c_str()); + +// you will most probably want to leave this off since it might make this map grow indefinitely +#ifdef ENABLE_CPP_EQUIVALENTS_MAP_TO_GROW + Add(original_const, target_const); +#endif + equivalents.push_back(target_const); + + count++; + } + + return count; + } + + typedef UniqueCStringMap<ConstString> Impl; + typedef const Impl::Entry* ImplData; + Impl m_impl; +}; + +static CPPRuntimeEquivalents& +GetEquivalentsMap () +{ + static CPPRuntimeEquivalents g_equivalents_map; + return g_equivalents_map; +} + + +uint32_t +CPlusPlusLanguage::FindEquivalentNames(ConstString type_name, std::vector<ConstString>& equivalents) +{ + uint32_t count = GetEquivalentsMap().FindExactMatches(type_name, equivalents); + + bool might_have_partials= + ( count == 0 ) // if we have a full name match just use it + && (strchr(type_name.AsCString(), '<') != NULL // we should only have partial matches when templates are involved, check that we have + && strchr(type_name.AsCString(), '>') != NULL); // angle brackets in the type_name before trying to scan for partial matches + + if ( might_have_partials ) + count = GetEquivalentsMap().FindPartialMatches(type_name, equivalents); + + return count; +} + diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h index 62a92a62c07..2ede8d8edde 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h @@ -12,9 +12,14 @@ // C Includes // C++ Includes +#include <vector> + // Other libraries and framework includes +#include "llvm/ADT/StringRef.h" + // Project includes #include "lldb/lldb-private.h" +#include "lldb/Core/ConstString.h" #include "lldb/Target/Language.h" namespace lldb_private { @@ -23,6 +28,94 @@ class CPlusPlusLanguage : public Language { public: + class MethodName + { + public: + enum Type + { + eTypeInvalid, + eTypeUnknownMethod, + eTypeClassMethod, + eTypeInstanceMethod + }; + + MethodName () : + m_full(), + m_basename(), + m_context(), + m_arguments(), + m_qualifiers(), + m_type (eTypeInvalid), + m_parsed (false), + m_parse_error (false) + { + } + + MethodName (const ConstString &s) : + m_full(s), + m_basename(), + m_context(), + m_arguments(), + m_qualifiers(), + m_type (eTypeInvalid), + m_parsed (false), + m_parse_error (false) + { + } + + void + Clear(); + + bool + IsValid () + { + if (!m_parsed) + Parse(); + if (m_parse_error) + return false; + if (m_type == eTypeInvalid) + return false; + return (bool)m_full; + } + + Type + GetType () const + { + return m_type; + } + + const ConstString & + GetFullName () const + { + return m_full; + } + + llvm::StringRef + GetBasename (); + + llvm::StringRef + GetContext (); + + llvm::StringRef + GetArguments (); + + llvm::StringRef + GetQualifiers (); + + protected: + void + Parse(); + + ConstString m_full; // Full name: "lldb::SBTarget::GetBreakpointAtIndex(unsigned int) const" + 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" + Type m_type; + bool m_parsed; + bool m_parse_error; + }; + virtual ~CPlusPlusLanguage() = default; CPlusPlusLanguage () = default; @@ -47,6 +140,28 @@ public: static lldb_private::ConstString GetPluginNameStatic(); + + static bool + IsCPPMangledName(const char *name); + + // Extract C++ context and identifier from a string using heuristic matching (as opposed to + // CPlusPlusLanguage::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 + 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 + // can be used as a search key in FindTypes(). the equivalents map here is meant to return possible alternative names + // for a type through which a search can be conducted. Currently, this is only enabled for C++ but can be extended + // to ObjC or other languages if necessary + static uint32_t + FindEquivalentNames(ConstString type_name, std::vector<ConstString>& equivalents); + //------------------------------------------------------------------ // PluginInterface protocol diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp index 8f21c46bfe3..3f3705095d4 100644 --- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp +++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp @@ -11,6 +11,7 @@ #include "lldb/Core/ConstString.h" #include "lldb/Core/PluginManager.h" +#include "lldb/Core/StreamString.h" using namespace lldb; using namespace lldb_private; @@ -66,3 +67,234 @@ ObjCLanguage::CreateInstance (lldb::LanguageType language) return nullptr; } } + +void +ObjCLanguage::MethodName::Clear() +{ + m_full.Clear(); + m_class.Clear(); + m_category.Clear(); + m_selector.Clear(); + m_type = eTypeUnspecified; + m_category_is_valid = false; +} + +bool +ObjCLanguage::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); +} + +const ConstString & +ObjCLanguage::MethodName::GetClassName () +{ + if (!m_class) + { + if (IsValid(false)) + { + 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) + { + 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) + { + m_class.SetCStringWithLength (class_start, space_pos - class_start); + if (!m_class_category) + { + // No category in name, so we can also fill in the m_class_category + m_class_category = m_class; + } + } + } + } + } + return m_class; +} + +const ConstString & +ObjCLanguage::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 & +ObjCLanguage::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 & +ObjCLanguage::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 +ObjCLanguage::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 +ObjCLanguage::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(); +} diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h index 3a43972f3f0..70ecf90ae39 100644 --- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h +++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h @@ -12,9 +12,12 @@ // C Includes // C++ Includes +#include <vector> + // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" +#include "lldb/Core/ConstString.h" #include "lldb/Target/Language.h" namespace lldb_private { @@ -23,6 +26,110 @@ class ObjCLanguage : public Language { 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 !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; + + }; + virtual ~ObjCLanguage() = default; ObjCLanguage () = default; @@ -48,6 +155,30 @@ public: static lldb_private::ConstString GetPluginNameStatic(); + static bool + IsPossibleObjCMethodName (const char *name) + { + if (!name) + return false; + bool starts_right = (name[0] == '+' || name[0] == '-') && name[1] == '['; + bool ends_right = (name[strlen(name) - 1] == ']'); + return (starts_right && ends_right); + } + + static bool + IsPossibleObjCSelector (const char *name) + { + if (!name) + return false; + + if (strchr(name, ':') == NULL) + return true; + else if (name[strlen(name) - 1] == ':') + return true; + else + return false; + } + //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 16ba2970442..51b0ce128d7 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -18,15 +18,19 @@ #include "SymbolFileDWARFDebugMap.h" #include "UniqueDWARFASTType.h" +#include "lldb/Interpreter/Args.h" #include "lldb/Core/Log.h" #include "lldb/Core/Module.h" +#include "lldb/Core/StreamString.h" +#include "lldb/Core/Value.h" +#include "lldb/Host/Host.h" #include "lldb/Symbol/ClangExternalASTSourceCommon.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/TypeList.h" #include "lldb/Target/Language.h" -#include "lldb/Target/ObjCLanguageRuntime.h" +#include "Plugins/Language/ObjC/ObjCLanguage.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" @@ -1045,7 +1049,7 @@ DWARFASTParserClang::ParseTypeFromDWARF (const SymbolContext& sc, if (tag == DW_TAG_subprogram || tag == DW_TAG_inlined_subroutine) { - ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true); + ObjCLanguage::MethodName objc_method (type_name_cstr, true); if (objc_method.IsValid(true)) { CompilerType class_opaque_type; @@ -2473,13 +2477,13 @@ DWARFASTParserClang::ParseChildMembers (const SymbolContext& sc, if (prop_getter_name && prop_getter_name[0] == '-') { - ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true); + ObjCLanguage::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::MethodName prop_setter_method(prop_setter_name, true); + ObjCLanguage::MethodName prop_setter_method(prop_setter_name, true); prop_setter_name = prop_setter_method.GetSelector().GetCString(); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp index 7096b98e1c2..fcbbf2314db 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp @@ -12,12 +12,13 @@ #include "lldb/Core/Mangled.h" #include "lldb/Core/Module.h" #include "lldb/Core/Stream.h" +#include "lldb/Core/StreamString.h" #include "lldb/Core/Timer.h" #include "lldb/Host/StringConvert.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/LineTable.h" #include "lldb/Symbol/ObjectFile.h" -#include "lldb/Target/ObjCLanguageRuntime.h" +#include "Plugins/Language/ObjC/ObjCLanguage.h" #include "DWARFDebugAbbrev.h" #include "DWARFDebugAranges.h" @@ -815,9 +816,7 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, { if (name) { - // Note, this check is also done in ParseMethodName, but since this is a hot loop, we do the - // simple inlined check outside the call. - ObjCLanguageRuntime::MethodName objc_method(name, true); + ObjCLanguage::MethodName objc_method(name, true); if (objc_method.IsValid(true)) { ConstString objc_class_name_with_category (objc_method.GetClassNameWithCategory()); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 752569f2035..7637e43658d 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -54,8 +54,8 @@ #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Symbol/VariableList.h" -#include "lldb/Target/ObjCLanguageRuntime.h" -#include "lldb/Target/CPPLanguageRuntime.h" +#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" +#include "Plugins/Language/ObjC/ObjCLanguage.h" #include "lldb/Target/Language.h" @@ -2102,7 +2102,7 @@ SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const CompilerDec llvm::StringRef basename; llvm::StringRef context; - if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename)) + if (!CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context, basename)) basename = name_cstr; m_apple_names_ap->FindByName (basename.data(), die_offsets); @@ -2531,7 +2531,7 @@ SymbolFileDWARF::FindFunctions (const ConstString &name, if (die) { const char *die_name = die.GetName(); - if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) + if (ObjCLanguage::IsPossibleObjCMethodName(die_name)) { if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) { |

