Skip to content

Commit 58a638b

Browse files
committedMay 11, 2019
[Breakpoint] Make breakpoint language agnostic
Summary: Breakpoint shouldn't need to depend on any specific details from a programming language. Currently the only language-specific detail it takes advantage of are the different qualified names an objective-c method name might have when adding a name lookup. This is reasonably generalizable. The current method name I introduced is "GetVariantMethodNames", which I'm not particularly tied to. If you have a better suggestion, please do let me know. Reviewers: JDevlieghere, jingham, clayborg Subscribers: mgorny, lldb-commits Differential Revision: https://reviews.llvm.org/D61746 llvm-svn: 360509
1 parent 3814d60 commit 58a638b

File tree

5 files changed

+76
-59
lines changed

5 files changed

+76
-59
lines changed
 

‎lldb/include/lldb/Target/Language.h

+8
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ class Language : public PluginInterface {
190190

191191
virtual const char *GetLanguageSpecificTypeLookupHelp();
192192

193+
// If a language can have more than one possible name for a method, this
194+
// function can be used to enumerate them. This is useful when doing name
195+
// lookups.
196+
virtual std::vector<ConstString>
197+
GetMethodNameVariants(ConstString method_name) const {
198+
return std::vector<ConstString>();
199+
};
200+
193201
// if an individual data formatter can apply to several types and cross a
194202
// language boundary it makes sense for individual languages to want to
195203
// customize the printing of values of that type by appending proper

‎lldb/source/Breakpoint/BreakpointResolverName.cpp

+20-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "lldb/Breakpoint/BreakpointResolverName.h"
1010

11-
#include "Plugins/Language/ObjC/ObjCLanguage.h"
1211
#include "lldb/Breakpoint/BreakpointLocation.h"
1312
#include "lldb/Core/Architecture.h"
1413
#include "lldb/Core/Module.h"
@@ -17,6 +16,7 @@
1716
#include "lldb/Symbol/Symbol.h"
1817
#include "lldb/Symbol/SymbolContext.h"
1918
#include "lldb/Target/Target.h"
19+
#include "lldb/Target/Language.h"
2020
#include "lldb/Utility/Log.h"
2121
#include "lldb/Utility/StreamString.h"
2222

@@ -218,20 +218,27 @@ StructuredData::ObjectSP BreakpointResolverName::SerializeToStructuredData() {
218218

219219
void BreakpointResolverName::AddNameLookup(ConstString name,
220220
FunctionNameType name_type_mask) {
221-
ObjCLanguage::MethodName objc_method(name.GetCString(), false);
222-
if (objc_method.IsValid(false)) {
223-
std::vector<ConstString> objc_names;
224-
objc_method.GetFullNames(objc_names, true);
225-
for (ConstString objc_name : objc_names) {
226-
Module::LookupInfo lookup;
227-
lookup.SetName(name);
228-
lookup.SetLookupName(objc_name);
229-
lookup.SetNameTypeMask(eFunctionNameTypeFull);
230-
m_lookups.push_back(lookup);
221+
222+
Module::LookupInfo lookup(name, name_type_mask, m_language);
223+
m_lookups.emplace_back(lookup);
224+
225+
auto add_variant_funcs = [&](Language *lang) {
226+
for (ConstString variant_name : lang->GetMethodNameVariants(name)) {
227+
Module::LookupInfo variant_lookup(name, name_type_mask,
228+
lang->GetLanguageType());
229+
variant_lookup.SetLookupName(variant_name);
230+
m_lookups.emplace_back(variant_lookup);
231231
}
232+
return true;
233+
};
234+
235+
if (Language *lang = Language::FindPlugin(m_language)) {
236+
add_variant_funcs(lang);
232237
} else {
233-
Module::LookupInfo lookup(name, name_type_mask, m_language);
234-
m_lookups.push_back(lookup);
238+
// Most likely m_language is eLanguageTypeUnknown. We check each language for
239+
// possible variants or more qualified names and create lookups for those as
240+
// well.
241+
Language::ForEach(add_variant_funcs);
235242
}
236243
}
237244

‎lldb/source/Breakpoint/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ add_lldb_library(lldbBreakpoint
3030
lldbSymbol
3131
lldbTarget
3232
lldbUtility
33-
lldbPluginObjCLanguage
3433

3534
LINK_COMPONENTS
3635
Support

‎lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp

+36-33
Original file line numberDiff line numberDiff line change
@@ -220,43 +220,46 @@ ConstString ObjCLanguage::MethodName::GetFullNameWithoutCategory(
220220
return ConstString();
221221
}
222222

223-
size_t ObjCLanguage::MethodName::GetFullNames(std::vector<ConstString> &names,
224-
bool append) {
225-
if (!append)
226-
names.clear();
227-
if (IsValid(false)) {
223+
std::vector<ConstString>
224+
ObjCLanguage::GetMethodNameVariants(ConstString method_name) const {
225+
std::vector<ConstString> variant_names;
226+
ObjCLanguage::MethodName objc_method(method_name.GetCString(), false);
227+
if (!objc_method.IsValid(false)) {
228+
return variant_names;
229+
}
230+
231+
const bool is_class_method =
232+
objc_method.GetType() == MethodName::eTypeClassMethod;
233+
const bool is_instance_method =
234+
objc_method.GetType() == MethodName::eTypeInstanceMethod;
235+
ConstString name_sans_category =
236+
objc_method.GetFullNameWithoutCategory(/*empty_if_no_category*/ true);
237+
238+
if (is_class_method || is_instance_method) {
239+
if (name_sans_category)
240+
variant_names.emplace_back(name_sans_category);
241+
} else {
228242
StreamString strm;
229-
const bool is_class_method = m_type == eTypeClassMethod;
230-
const bool is_instance_method = m_type == eTypeInstanceMethod;
231-
ConstString category = GetCategory();
232-
if (is_class_method || is_instance_method) {
233-
names.push_back(m_full);
234-
if (category) {
235-
strm.Printf("%c[%s %s]", is_class_method ? '+' : '-',
236-
GetClassName().GetCString(), GetSelector().GetCString());
237-
names.emplace_back(strm.GetString());
238-
}
239-
} else {
240-
ConstString class_name = GetClassName();
241-
ConstString selector = GetSelector();
242-
strm.Printf("+[%s %s]", class_name.GetCString(), selector.GetCString());
243-
names.emplace_back(strm.GetString());
244-
strm.Clear();
245-
strm.Printf("-[%s %s]", class_name.GetCString(), selector.GetCString());
246-
names.emplace_back(strm.GetString());
243+
244+
strm.Printf("+%s", objc_method.GetFullName().GetCString());
245+
variant_names.emplace_back(strm.GetString());
246+
strm.Clear();
247+
248+
strm.Printf("-%s", objc_method.GetFullName().GetCString());
249+
variant_names.emplace_back(strm.GetString());
250+
strm.Clear();
251+
252+
if (name_sans_category) {
253+
strm.Printf("+%s", name_sans_category.GetCString());
254+
variant_names.emplace_back(strm.GetString());
247255
strm.Clear();
248-
if (category) {
249-
strm.Printf("+[%s(%s) %s]", class_name.GetCString(),
250-
category.GetCString(), selector.GetCString());
251-
names.emplace_back(strm.GetString());
252-
strm.Clear();
253-
strm.Printf("-[%s(%s) %s]", class_name.GetCString(),
254-
category.GetCString(), selector.GetCString());
255-
names.emplace_back(strm.GetString());
256-
}
256+
257+
strm.Printf("-%s", name_sans_category.GetCString());
258+
variant_names.emplace_back(strm.GetString());
257259
}
258260
}
259-
return names.size();
261+
262+
return variant_names;
260263
}
261264

262265
static void LoadObjCFormatters(TypeCategoryImplSP objc_category_sp) {

‎lldb/source/Plugins/Language/ObjC/ObjCLanguage.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ class ObjCLanguage : public Language {
7373

7474
ConstString GetSelector();
7575

76-
// Get all possible names for a method. Examples:
77-
// If name is "+[NSString(my_additions) myStringWithCString:]"
78-
// names[0] => "+[NSString(my_additions) myStringWithCString:]"
79-
// names[1] => "+[NSString myStringWithCString:]"
80-
// If name is specified without the leading '+' or '-' like
81-
// "[NSString(my_additions) myStringWithCString:]"
82-
// names[0] => "+[NSString(my_additions) myStringWithCString:]"
83-
// names[1] => "-[NSString(my_additions) myStringWithCString:]"
84-
// names[2] => "+[NSString myStringWithCString:]"
85-
// names[3] => "-[NSString myStringWithCString:]"
86-
size_t GetFullNames(std::vector<ConstString> &names, bool append);
87-
8876
protected:
8977
ConstString
9078
m_full; // Full name: "+[NSString(my_additions) myStringWithCString:]"
@@ -105,6 +93,18 @@ class ObjCLanguage : public Language {
10593
return lldb::eLanguageTypeObjC;
10694
}
10795

96+
// Get all possible names for a method. Examples:
97+
// If method_name is "+[NSString(my_additions) myStringWithCString:]"
98+
// variant_names[0] => "+[NSString myStringWithCString:]"
99+
// If name is specified without the leading '+' or '-' like
100+
// "[NSString(my_additions) myStringWithCString:]"
101+
// variant_names[0] => "+[NSString(my_additions) myStringWithCString:]"
102+
// variant_names[1] => "-[NSString(my_additions) myStringWithCString:]"
103+
// variant_names[2] => "+[NSString myStringWithCString:]"
104+
// variant_names[3] => "-[NSString myStringWithCString:]"
105+
std::vector<ConstString>
106+
GetMethodNameVariants(ConstString method_name) const override;
107+
108108
lldb::TypeCategoryImplSP GetFormatters() override;
109109

110110
std::vector<ConstString>

0 commit comments

Comments
 (0)
Please sign in to comment.