25#include "llvm/Support/Threading.h"
63std::optional<const ObjCLanguage::MethodName>
79 if (name.size() < (5 + (strict ? 1 : 0)) || name.back() !=
']')
84 if (name.starts_with(
"+["))
86 else if (name.starts_with(
"-["))
104 llvm::StringRef full = m_full;
105 const size_t class_start_pos = (full.front() ==
'[' ? 1 : 2);
106 const size_t paren_pos = full.find(
'(', class_start_pos);
108 if (paren_pos != llvm::StringRef::npos)
109 return full.substr(class_start_pos, paren_pos - class_start_pos);
112 const size_t space_pos = full.find(
' ', class_start_pos);
113 return full.substr(class_start_pos, space_pos - class_start_pos);
117 llvm::StringRef full = m_full;
118 const size_t class_start_pos = (full.front() ==
'[' ? 1 : 2);
119 const size_t space_pos = full.find(
' ', class_start_pos);
120 return full.substr(class_start_pos, space_pos - class_start_pos);
124 llvm::StringRef full = m_full;
125 const size_t space_pos = full.find(
' ');
126 if (space_pos == llvm::StringRef::npos)
127 return llvm::StringRef();
128 const size_t closing_bracket = full.find(
']', space_pos);
129 return full.substr(space_pos + 1, closing_bracket - space_pos - 1);
133 llvm::StringRef full = m_full;
134 const size_t open_paren_pos = full.find(
'(');
135 const size_t close_paren_pos = full.find(
')');
137 if (open_paren_pos == llvm::StringRef::npos ||
138 close_paren_pos == llvm::StringRef::npos)
139 return llvm::StringRef();
141 return full.substr(open_paren_pos + 1,
142 close_paren_pos - (open_paren_pos + 1));
146 llvm::StringRef full = m_full;
147 const size_t open_paren_pos = full.find(
'(');
148 const size_t close_paren_pos = full.find(
')');
149 if (open_paren_pos == llvm::StringRef::npos ||
150 close_paren_pos == llvm::StringRef::npos)
151 return std::string();
153 llvm::StringRef class_name = GetClassName();
154 llvm::StringRef selector_name = GetSelector();
158 size_t total_size = class_name.size() + selector_name.size() + 3;
159 if (m_type != eTypeUnspecified)
162 std::string name_sans_category;
163 name_sans_category.reserve(total_size);
165 if (m_type == eTypeClassMethod)
166 name_sans_category +=
'+';
167 else if (m_type == eTypeInstanceMethod)
168 name_sans_category +=
'-';
170 name_sans_category +=
'[';
171 name_sans_category.append(class_name.data(), class_name.size());
172 name_sans_category +=
' ';
173 name_sans_category.append(selector_name.data(), selector_name.size());
174 name_sans_category +=
']';
176 return name_sans_category;
179std::vector<Language::MethodNameVariant>
181 std::vector<Language::MethodNameVariant> variant_names;
182 std::optional<const ObjCLanguage::MethodName> objc_method =
185 return variant_names;
187 variant_names.emplace_back(
ConstString(objc_method->GetSelector()),
188 lldb::eFunctionNameTypeSelector);
190 const std::string name_sans_category =
191 objc_method->GetFullNameWithoutCategory();
193 if (objc_method->IsClassMethod() || objc_method->IsInstanceMethod()) {
194 if (!name_sans_category.empty())
195 variant_names.emplace_back(
ConstString(name_sans_category.c_str()),
196 lldb::eFunctionNameTypeFull);
200 strm.
Printf(
"+%s", objc_method->GetFullName().c_str());
202 lldb::eFunctionNameTypeFull);
205 strm.
Printf(
"-%s", objc_method->GetFullName().c_str());
207 lldb::eFunctionNameTypeFull);
210 if (!name_sans_category.empty()) {
211 strm.
Printf(
"+%s", name_sans_category.c_str());
213 lldb::eFunctionNameTypeFull);
216 strm.
Printf(
"-%s", name_sans_category.c_str());
218 lldb::eFunctionNameTypeFull);
222 return variant_names;
233 if (!objc_category_sp)
259 "SEL summary provider",
"SEL", objc_flags);
262 "SEL summary provider",
"struct objc_selector", objc_flags);
265 "SEL summary provider",
"objc_selector", objc_flags);
268 "SEL summary provider",
"objc_selector *", objc_flags);
271 "SEL summary provider",
"SEL *", objc_flags);
275 "Class summary provider",
"Class", objc_flags);
283 "Class synthetic children",
"Class", class_synth_flags);
290 "__block_literal_generic", objc_flags);
293 "${var.years} years, ${var.months} "
294 "months, ${var.days} days, ${var.hours} "
295 "hours, ${var.minutes} minutes "
296 "${var.seconds} seconds",
297 "CFGregorianUnits", objc_flags);
299 "location=${var.location} length=${var.length}",
"CFRange",
303 "location=${var.location}, length=${var.length}",
"NSRange",
306 "NSRectArray", objc_flags);
317 "red=${var.red} green=${var.green} blue=${var.blue}",
318 "RGBColor", objc_flags);
321 "(t=${var.top}, l=${var.left}, b=${var.bottom}, r=${var.right})",
"Rect",
326 "${var.month}/${var.day}/${var.year} ${var.hour} "
327 ":${var.minute} :${var.second} dayOfWeek:${var.dayOfWeek}",
328 "DateTimeRect *", objc_flags);
330 "${var.ld.month}/${var.ld.day}/"
331 "${var.ld.year} ${var.ld.hour} "
332 ":${var.ld.minute} :${var.ld.second} "
333 "dayOfWeek:${var.ld.dayOfWeek}",
334 "LongDateRect", objc_flags);
338 "HIRect", objc_flags);
353 "NSArray summary provider",
"NSArray", appkit_flags);
356 "NSArray summary provider",
"NSConstantArray", appkit_flags);
359 "NSArray summary provider",
"NSMutableArray", appkit_flags);
362 "NSArray summary provider",
"__NSArrayI", appkit_flags);
365 "NSArray summary provider",
"__NSArray0", appkit_flags);
368 "NSArray summary provider",
"__NSSingleObjectArrayI", appkit_flags);
371 "NSArray summary provider",
"__NSArrayM", appkit_flags);
374 "NSArray summary provider",
"__NSCFArray", appkit_flags);
377 "NSArray summary provider",
"_NSCallStackArray", appkit_flags);
380 "NSArray summary provider",
"CFArrayRef", appkit_flags);
383 "NSArray summary provider",
"CFMutableArrayRef", appkit_flags);
387 "NSDictionary summary provider",
"NSDictionary", appkit_flags);
390 "NSDictionary summary provider",
"NSConstantDictionary",
394 "NSDictionary summary provider",
"NSMutableDictionary",
398 "NSDictionary summary provider",
"__NSCFDictionary",
402 "NSDictionary summary provider",
"__NSDictionaryI",
406 "NSDictionary summary provider",
"__NSSingleEntryDictionaryI",
410 "NSDictionary summary provider",
"__NSDictionaryM",
414 "NSDictionary summary provider",
"CFDictionaryRef",
418 "NSDictionary summary provider",
"__CFDictionary",
422 "NSDictionary summary provider",
"CFMutableDictionaryRef",
426 lldb_private::formatters::NSSetSummaryProvider<false>,
427 "NSSet summary",
"NSSet", appkit_flags);
429 lldb_private::formatters::NSSetSummaryProvider<false>,
430 "NSMutableSet summary",
"NSMutableSet", appkit_flags);
432 lldb_private::formatters::NSSetSummaryProvider<true>,
433 "CFSetRef summary",
"CFSetRef", appkit_flags);
435 lldb_private::formatters::NSSetSummaryProvider<true>,
436 "CFMutableSetRef summary",
"CFMutableSetRef", appkit_flags);
438 lldb_private::formatters::NSSetSummaryProvider<false>,
439 "__NSCFSet summary",
"__NSCFSet", appkit_flags);
441 lldb_private::formatters::NSSetSummaryProvider<false>,
442 "__CFSet summary",
"__CFSet", appkit_flags);
444 lldb_private::formatters::NSSetSummaryProvider<false>,
445 "__NSSetI summary",
"__NSSetI", appkit_flags);
447 lldb_private::formatters::NSSetSummaryProvider<false>,
448 "__NSSetM summary",
"__NSSetM", appkit_flags);
450 lldb_private::formatters::NSSetSummaryProvider<false>,
451 "NSCountedSet summary",
"NSCountedSet", appkit_flags);
453 lldb_private::formatters::NSSetSummaryProvider<false>,
454 "NSMutableSet summary",
"NSMutableSet", appkit_flags);
456 lldb_private::formatters::NSSetSummaryProvider<false>,
457 "NSOrderedSet summary",
"NSOrderedSet", appkit_flags);
459 lldb_private::formatters::NSSetSummaryProvider<false>,
460 "__NSOrderedSetI summary",
"__NSOrderedSetI", appkit_flags);
462 lldb_private::formatters::NSSetSummaryProvider<false>,
463 "__NSOrderedSetM summary",
"__NSOrderedSetM", appkit_flags);
467 "NSError summary provider",
"NSError", appkit_flags);
470 "NSException summary provider",
"NSException", appkit_flags);
479 "NSArray synthetic children",
"__NSArrayM",
483 "NSArray synthetic children",
"__NSArrayI",
487 "NSArray synthetic children",
"__NSArray0",
491 "NSArray synthetic children",
"__NSSingleObjectArrayI",
495 "NSArray synthetic children",
"NSArray",
499 "NSArray synthetic children",
"NSConstantArray",
503 "NSArray synthetic children",
"NSMutableArray",
507 "NSArray synthetic children",
"__NSCFArray",
511 "NSArray synthetic children",
"_NSCallStackArray",
515 "NSArray synthetic children",
"CFMutableArrayRef",
519 "NSArray synthetic children",
"CFArrayRef",
525 "NSDictionary synthetic children",
"__NSDictionaryM",
530 "NSDictionary synthetic children",
"NSConstantDictionary",
535 "NSDictionary synthetic children",
"__NSDictionaryI",
540 "NSDictionary synthetic children",
"__NSSingleEntryDictionaryI",
545 "NSDictionary synthetic children",
"__NSCFDictionary",
550 "NSDictionary synthetic children",
"NSDictionary",
555 "NSDictionary synthetic children",
"NSMutableDictionary",
560 "NSDictionary synthetic children",
"CFDictionaryRef",
565 "NSDictionary synthetic children",
"CFMutableDictionaryRef",
570 "NSDictionary synthetic children",
"__CFDictionary",
575 "NSError synthetic children",
"NSError",
579 "NSException synthetic children",
"NSException",
587 "__NSSetI synthetic children",
"__NSSetI",
591 "__NSSetM synthetic children",
"__NSSetM",
595 "__NSCFSet synthetic children",
"__NSCFSet",
599 "CFSetRef synthetic children",
"CFSetRef",
604 "NSMutableSet synthetic children",
"NSMutableSet",
608 "NSOrderedSet synthetic children",
"NSOrderedSet",
612 "__NSOrderedSetI synthetic children",
"__NSOrderedSetI",
616 "__NSOrderedSetM synthetic children",
"__NSOrderedSetM",
620 "__CFSet synthetic children",
"__CFSet",
625 "NSIndexPath synthetic children",
"NSIndexPath",
630 "CFBag summary provider",
"CFBagRef", appkit_flags);
633 "CFBag summary provider",
"__CFBag", appkit_flags);
636 "CFBag summary provider",
"const struct __CFBag", appkit_flags);
639 "CFBag summary provider",
"CFMutableBagRef", appkit_flags);
643 "CFBinaryHeap summary provider",
"CFBinaryHeapRef", appkit_flags);
646 "CFBinaryHeap summary provider",
"__CFBinaryHeap", appkit_flags);
650 "NSString summary provider",
"NSString", appkit_flags);
653 "NSString summary provider",
"CFStringRef", appkit_flags);
656 "NSString summary provider",
"__CFString", appkit_flags);
659 "NSString summary provider",
"CFMutableStringRef", appkit_flags);
662 "NSString summary provider",
"NSMutableString", appkit_flags);
665 "NSString summary provider",
"__NSCFConstantString", appkit_flags);
668 "NSString summary provider",
"__NSCFString", appkit_flags);
671 "NSString summary provider",
"NSCFConstantString", appkit_flags);
674 "NSString summary provider",
"NSCFString", appkit_flags);
677 "NSString summary provider",
"NSPathStore2", appkit_flags);
680 "NSString summary provider",
"NSTaggedPointerString", appkit_flags);
684 "NSAttributedString summary provider",
"NSAttributedString",
689 "NSMutableAttributedString summary provider",
"NSMutableAttributedString",
694 "NSMutableAttributedString summary provider",
695 "NSConcreteMutableAttributedString", appkit_flags);
699 "NSBundle summary provider",
"NSBundle", appkit_flags);
703 "NSData summary provider",
"NSData", appkit_flags);
706 "NSData summary provider",
"_NSInlineData", appkit_flags);
709 "NSData summary provider",
"NSConcreteData", appkit_flags);
712 "NSData summary provider",
"NSConcreteMutableData", appkit_flags);
715 "NSData summary provider",
"NSMutableData", appkit_flags);
718 "NSData summary provider",
"__NSCFData", appkit_flags);
721 "NSData summary provider",
"CFDataRef", appkit_flags);
724 "NSData summary provider",
"CFMutableDataRef", appkit_flags);
728 "NSMachPort summary provider",
"NSMachPort", appkit_flags);
732 "NSNotification summary provider",
"NSNotification", appkit_flags);
735 "NSNotification summary provider",
"NSConcreteNotification",
740 "NSNumber summary provider",
"NSNumber", appkit_flags);
743 "NSNumber summary provider",
"NSConstantIntegerNumber", appkit_flags);
746 "NSNumber summary provider",
"NSConstantDoubleNumber", appkit_flags);
749 "NSNumber summary provider",
"NSConstantFloatNumber", appkit_flags);
752 "CFNumberRef summary provider",
"CFNumberRef", appkit_flags);
755 "NSNumber summary provider",
"__NSCFBoolean", appkit_flags);
758 "NSNumber summary provider",
"__NSCFNumber", appkit_flags);
761 "NSNumber summary provider",
"NSCFBoolean", appkit_flags);
764 "NSNumber summary provider",
"NSCFNumber", appkit_flags);
767 "NSDecimalNumber summary provider",
"NSDecimalNumber", appkit_flags);
771 "NSURL summary provider",
"NSURL", appkit_flags);
774 "NSURL summary provider",
"CFURLRef", appkit_flags);
778 "NSDate summary provider",
"NSDate", appkit_flags);
781 "NSDate summary provider",
"__NSDate", appkit_flags);
784 "NSDate summary provider",
"__NSTaggedDate", appkit_flags);
787 "NSDate summary provider",
"NSCalendarDate", appkit_flags);
791 "NSTimeZone summary provider",
"NSTimeZone", appkit_flags);
794 "NSTimeZone summary provider",
"CFTimeZoneRef", appkit_flags);
797 "NSTimeZone summary provider",
"__NSTimeZone", appkit_flags);
805 "CFAbsoluteTime summary provider",
"CFAbsoluteTime", appkit_flags);
810 "NSIndexSet summary provider",
"NSIndexSet", appkit_flags);
813 "NSIndexSet summary provider",
"NSMutableIndexSet", appkit_flags);
816 "@\"${var.month%d}/${var.day%d}/${var.year%d} "
817 "${var.hour%d}:${var.minute%d}:${var.second}\"",
818 "CFGregorianDate", appkit_flags);
822 "CFBitVector summary provider",
"CFBitVectorRef", appkit_flags);
825 "CFBitVector summary provider",
"CFMutableBitVectorRef", appkit_flags);
828 "CFBitVector summary provider",
"__CFBitVector", appkit_flags);
831 "CFBitVector summary provider",
"__CFMutableBitVector", appkit_flags);
835 if (!objc_category_sp)
849 "CMTime summary provider",
"CMTime", cm_flags);
853 static llvm::once_flag g_initialize;
856 llvm::call_once(g_initialize, [
this]() ->
void {
867std::vector<FormattersMatchCandidate>
870 std::vector<FormattersMatchCandidate> result;
877 const bool check_cpp =
false;
878 const bool check_objc =
true;
879 bool canBeObjCDynamic =
888 if (runtime ==
nullptr)
894 if (
ConstString name = objc_class_sp->GetClassName())
896 {name, valobj.
GetTargetSP()->GetDebugger().GetScriptInterpreter(),
911 bool IsValid()
override {
return m_compiler_type.
IsValid(); }
913 bool DumpToStream(
Stream &stream,
bool print_help_if_available)
override {
915 m_compiler_type.DumpTypeDescription(&stream);
929 ResultSet &results)
override {
934 if (
auto *decl_vendor = objc_runtime->GetDeclVendor()) {
939 std::unique_ptr<Language::TypeScavenger::Result> result(
940 new ObjCScavengerResult(type));
941 results.insert(std::move(result));
956 ResultSet &results)
override {
960 auto *persistent_vars = llvm::cast<ClangPersistentVariables>(
961 target->GetPersistentExpressionStateForLanguage(
963 if (std::shared_ptr<ClangModulesDeclVendor> clang_modules_decl_vendor =
964 persistent_vars->GetClangModulesDeclVendor()) {
966 auto types = clang_modules_decl_vendor->FindTypes(
968 if (!types.empty()) {
970 std::unique_ptr<Language::TypeScavenger::Result> result(
971 new ObjCScavengerResult(types.front()));
972 results.insert(std::move(result));
995 return std::unique_ptr<TypeScavenger>(
997 ObjCRuntimeScavenger,
998 ObjCDebugInfoScavenger>());
1001std::pair<llvm::StringRef, llvm::StringRef>
1003 static constexpr llvm::StringRef empty;
1004 static const llvm::StringMap<
1005 std::pair<const llvm::StringRef, const llvm::StringRef>>
1007 {
"CFBag", {
"@", empty}},
1008 {
"CFBinaryHeap", {
"@", empty}},
1009 {
"NSString", {
"@", empty}},
1010 {
"NSString*", {
"@", empty}},
1011 {
"NSNumber:char", {
"(char)", empty}},
1012 {
"NSNumber:short", {
"(short)", empty}},
1013 {
"NSNumber:int", {
"(int)", empty}},
1014 {
"NSNumber:long", {
"(long)", empty}},
1015 {
"NSNumber:int128_t", {
"(int128_t)", empty}},
1016 {
"NSNumber:float", {
"(float)", empty}},
1017 {
"NSNumber:double", {
"(double)", empty}},
1018 {
"NSData", {
"@\"",
"\""}},
1019 {
"NSArray", {
"@\"",
"\""}},
1021 return g_affix_map.lookup(type_hint);
1025 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
1026 bool isObjCpointer =
1030 bool canReadValue =
true;
1032 return canReadValue && isZero;
1036 const auto suffixes = {
".h",
".m",
".M"};
1037 for (
auto suffix : suffixes) {
1038 if (file_path.ends_with_insensitive(suffix))
static void LoadCoreMediaFormatters(TypeCategoryImplSP objc_category_sp)
static void LoadObjCFormatters(TypeCategoryImplSP objc_category_sp)
#define LLDB_PLUGIN_DEFINE(PluginName)
Generic representation of a type in a programming language.
lldb::LanguageType GetMinimumLanguage()
bool IsPossibleDynamicType(CompilerType *target_type, bool check_cplusplus, bool check_objc) const
CompilerType GetTypedefedType() const
If the current object represents a typedef type, get the underlying type.
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
bool IsTypedefType() const
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
static bool GetCategory(ConstString category, lldb::TypeCategoryImplSP &entry, bool allow_create=true)
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual lldb::ProcessSP CalculateProcess()=0
virtual lldb::TargetSP CalculateTarget()=0
static bool LanguageIsObjC(lldb::LanguageType language)
A class that handles mangled names.
ConstString GetDemangledName() const
Demangled name get accessor.
std::shared_ptr< ClassDescriptor > ClassDescriptorSP
static ObjCLanguageRuntime * Get(Process &process)
virtual ClassDescriptorSP GetClassDescriptor(ValueObject &in_value)
std::string GetFullNameWithoutCategory() const
Creates a variation of this method without the category.
llvm::StringRef GetClassNameWithCategory() const
Returns a reference to the class name with the category.
llvm::StringRef GetSelector() const
Returns a reference to the selector name.
llvm::StringRef GetCategory() const
Returns a reference to the category name.
llvm::StringRef GetClassName() const
Returns a reference to the class name.
static std::optional< const MethodName > Create(llvm::StringRef name, bool strict)
The static factory method for creating a MethodName.
llvm::StringRef GetPluginName() override
std::pair< llvm::StringRef, llvm::StringRef > GetFormatterPrefixSuffix(llvm::StringRef type_hint) override
An individual data formatter may apply to several types and cross language boundaries.
static lldb_private::Language * CreateInstance(lldb::LanguageType language)
std::unique_ptr< TypeScavenger > GetTypeScavenger() override
lldb::TypeCategoryImplSP GetFormatters() override
bool SymbolNameFitsToLanguage(Mangled mangled) const override
Returns true iff the given symbol name is compatible with the mangling scheme of this language.
bool IsSourceFile(llvm::StringRef file_path) const override
std::vector< FormattersMatchCandidate > GetPossibleFormattersMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic) override
std::vector< Language::MethodNameVariant > GetMethodNameVariants(ConstString method_name) const override
bool IsNilReference(ValueObject &valobj) override
static bool IsPossibleObjCMethodName(const char *name)
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t EOL()
Output and End of Line character to the stream.
Flags & SetSkipReferences(bool value=true)
Flags & SetSkipPointers(bool value=true)
Flags & SetCascades(bool value=true)
Flags & SetCascades(bool value=true)
Flags & SetSkipPointers(bool value=true)
Flags & SetHideItemNames(bool value=true)
Flags & SetDontShowChildren(bool value=true)
Flags & SetSkipReferences(bool value=true)
Flags & SetShowMembersOneLiner(bool value=true)
Flags & SetDontShowValue(bool value=true)
CompilerType GetCompilerType()
lldb::ProcessSP GetProcessSP() const
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
lldb::TargetSP GetTargetSP() const
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
LanguageType
Programming language type.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::TypeCategoryImpl > TypeCategoryImplSP
static bool IsClangType(const CompilerType &ct)