25#include "llvm/Support/Threading.h"
75 return IsValid(strict);
79 bool valid_prefix =
false;
81 if (name.size() > 1 && (name[0] ==
'+' || name[0] ==
'-')) {
82 valid_prefix = name[1] ==
'[';
84 m_type = eTypeClassMethod;
86 m_type = eTypeInstanceMethod;
89 valid_prefix = name[0] ==
'[';
93 int name_len = name.size();
100 if (name_len >= (5 + (strict ? 1 : 0)) && name.back() ==
']') {
101 m_full.SetString(name);
104 return IsValid(strict);
108 return SetName(llvm::StringRef(name), strict);
113 if (IsValid(
false)) {
115 const char *class_start = (full[0] ==
'[' ? full + 1 : full + 2);
116 const char *paren_pos = strchr(class_start,
'(');
118 m_class.SetCStringWithLength(class_start, paren_pos - class_start);
122 m_category_is_valid =
true;
123 const char *space_pos = strchr(full,
' ');
125 m_class.SetCStringWithLength(class_start, space_pos - class_start);
126 if (!m_class_category) {
128 m_class_category = m_class;
138 if (!m_class_category) {
139 if (IsValid(
false)) {
141 const char *class_start = (full[0] ==
'[' ? full + 1 : full + 2);
142 const char *space_pos = strchr(full,
' ');
144 m_class_category.SetCStringWithLength(class_start,
145 space_pos - class_start);
148 if (!m_class && strchr(m_class_category.GetCString(),
'(') ==
nullptr) {
149 m_class = m_class_category;
152 m_category_is_valid =
true;
157 return m_class_category;
162 if (IsValid(
false)) {
164 const char *space_pos = strchr(full,
' ');
167 m_selector.SetCStringWithLength(space_pos, m_full.GetLength() -
168 (space_pos - full) - 1);
176 if (!m_category_is_valid && !m_category) {
177 if (IsValid(
false)) {
178 m_category_is_valid =
true;
180 const char *class_start = (full[0] ==
'[' ? full + 1 : full + 2);
181 const char *open_paren_pos = strchr(class_start,
'(');
182 if (open_paren_pos) {
184 const char *close_paren_pos = strchr(open_paren_pos,
')');
186 m_category.SetCStringWithLength(open_paren_pos,
187 close_paren_pos - open_paren_pos);
195 bool empty_if_no_category) {
196 if (IsValid(
false)) {
199 if (m_type == eTypeClassMethod)
201 else if (m_type == eTypeInstanceMethod)
203 strm.
Printf(
"[%s %s]", GetClassName().GetCString(),
204 GetSelector().GetCString());
208 if (!empty_if_no_category) {
210 return GetFullName();
216std::vector<Language::MethodNameVariant>
218 std::vector<Language::MethodNameVariant> variant_names;
220 if (!objc_method.
IsValid(
false)) {
221 return variant_names;
224 variant_names.emplace_back(objc_method.
GetSelector(),
225 lldb::eFunctionNameTypeSelector);
227 const bool is_class_method =
229 const bool is_instance_method =
234 if (is_class_method || is_instance_method) {
235 if (name_sans_category)
236 variant_names.emplace_back(name_sans_category,
237 lldb::eFunctionNameTypeFull);
243 lldb::eFunctionNameTypeFull);
248 lldb::eFunctionNameTypeFull);
251 if (name_sans_category) {
254 lldb::eFunctionNameTypeFull);
259 lldb::eFunctionNameTypeFull);
263 return variant_names;
267 ConstString demangled_name = mangled.GetDemangledName();
274 if (!objc_category_sp)
300 "SEL summary provider",
ConstString(
"SEL"), objc_flags);
303 "SEL summary provider",
ConstString(
"struct objc_selector"), objc_flags);
306 "SEL summary provider",
ConstString(
"objc_selector"), objc_flags);
309 "SEL summary provider",
ConstString(
"objc_selector *"), objc_flags);
312 "SEL summary provider",
ConstString(
"SEL *"), objc_flags);
316 "Class summary provider",
ConstString(
"Class"), objc_flags);
332 ConstString(
"__block_literal_generic"), objc_flags);
335 "months, ${var.days} days, ${var.hours} "
336 "hours, ${var.minutes} minutes "
337 "${var.seconds} seconds",
340 "location=${var.location} length=${var.length}",
344 "location=${var.location}, length=${var.length}",
358 "red=${var.red} green=${var.green} blue=${var.blue}",
362 "(t=${var.top}, l=${var.left}, b=${var.bottom}, r=${var.right})",
367 "${var.month}/${var.day}/${var.year} ${var.hour} "
368 ":${var.minute} :${var.second} dayOfWeek:${var.dayOfWeek}",
371 "${var.ld.year} ${var.ld.hour} "
372 ":${var.ld.minute} :${var.ld.second} "
373 "dayOfWeek:${var.ld.dayOfWeek}",
393 "NSArray summary provider",
ConstString(
"NSArray"), appkit_flags);
396 "NSArray summary provider",
ConstString(
"NSConstantArray"), appkit_flags);
399 "NSArray summary provider",
ConstString(
"NSMutableArray"), appkit_flags);
402 "NSArray summary provider",
ConstString(
"__NSArrayI"), appkit_flags);
405 "NSArray summary provider",
ConstString(
"__NSArray0"), appkit_flags);
408 "NSArray summary provider",
409 ConstString(
"__NSSingleObjectArrayI"), appkit_flags);
412 "NSArray summary provider",
ConstString(
"__NSArrayM"), appkit_flags);
415 "NSArray summary provider",
ConstString(
"__NSCFArray"), appkit_flags);
418 "NSArray summary provider",
ConstString(
"_NSCallStackArray"), appkit_flags);
421 "NSArray summary provider",
ConstString(
"CFArrayRef"), appkit_flags);
424 "NSArray summary provider",
ConstString(
"CFMutableArrayRef"),
429 "NSDictionary summary provider",
ConstString(
"NSDictionary"),
433 "NSDictionary summary provider",
434 ConstString(
"NSConstantDictionary"), appkit_flags);
437 "NSDictionary summary provider",
441 "NSDictionary summary provider",
445 "NSDictionary summary provider",
ConstString(
"__NSDictionaryI"),
449 "NSDictionary summary provider",
450 ConstString(
"__NSSingleEntryDictionaryI"), appkit_flags);
453 "NSDictionary summary provider",
ConstString(
"__NSDictionaryM"),
457 "NSDictionary summary provider",
ConstString(
"CFDictionaryRef"),
461 "NSDictionary summary provider",
ConstString(
"__CFDictionary"),
465 "NSDictionary summary provider",
466 ConstString(
"CFMutableDictionaryRef"), appkit_flags);
469 lldb_private::formatters::NSSetSummaryProvider<false>,
470 "NSSet summary",
ConstString(
"NSSet"), appkit_flags);
472 objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
473 "NSMutableSet summary",
ConstString(
"NSMutableSet"), appkit_flags);
475 lldb_private::formatters::NSSetSummaryProvider<true>,
476 "CFSetRef summary",
ConstString(
"CFSetRef"), appkit_flags);
478 objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<true>,
479 "CFMutableSetRef summary",
ConstString(
"CFMutableSetRef"), appkit_flags);
481 lldb_private::formatters::NSSetSummaryProvider<false>,
482 "__NSCFSet summary",
ConstString(
"__NSCFSet"), appkit_flags);
484 lldb_private::formatters::NSSetSummaryProvider<false>,
485 "__CFSet summary",
ConstString(
"__CFSet"), appkit_flags);
487 lldb_private::formatters::NSSetSummaryProvider<false>,
488 "__NSSetI summary",
ConstString(
"__NSSetI"), appkit_flags);
490 lldb_private::formatters::NSSetSummaryProvider<false>,
491 "__NSSetM summary",
ConstString(
"__NSSetM"), appkit_flags);
493 objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
494 "NSCountedSet summary",
ConstString(
"NSCountedSet"), appkit_flags);
496 objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
497 "NSMutableSet summary",
ConstString(
"NSMutableSet"), appkit_flags);
499 objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
500 "NSOrderedSet summary",
ConstString(
"NSOrderedSet"), appkit_flags);
502 objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
503 "__NSOrderedSetI summary",
ConstString(
"__NSOrderedSetI"), appkit_flags);
505 objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
506 "__NSOrderedSetM summary",
ConstString(
"__NSOrderedSetM"), appkit_flags);
510 "NSError summary provider",
ConstString(
"NSError"), appkit_flags);
513 "NSException summary provider",
ConstString(
"NSException"), appkit_flags);
522 "NSArray synthetic children",
ConstString(
"__NSArrayM"),
526 "NSArray synthetic children",
ConstString(
"__NSArrayI"),
530 "NSArray synthetic children",
ConstString(
"__NSArray0"),
534 "NSArray synthetic children",
539 "NSArray synthetic children",
ConstString(
"NSArray"),
543 "NSArray synthetic children",
ConstString(
"NSConstantArray"),
547 "NSArray synthetic children",
ConstString(
"NSMutableArray"),
551 "NSArray synthetic children",
ConstString(
"__NSCFArray"),
555 "NSArray synthetic children",
ConstString(
"_NSCallStackArray"),
559 "NSArray synthetic children",
564 "NSArray synthetic children",
ConstString(
"CFArrayRef"),
570 "NSDictionary synthetic children",
ConstString(
"__NSDictionaryM"),
575 "NSDictionary synthetic children",
ConstString(
"NSConstantDictionary"),
580 "NSDictionary synthetic children",
ConstString(
"__NSDictionaryI"),
585 "NSDictionary synthetic children",
591 "NSDictionary synthetic children",
ConstString(
"__NSCFDictionary"),
596 "NSDictionary synthetic children",
ConstString(
"NSDictionary"),
601 "NSDictionary synthetic children",
ConstString(
"NSMutableDictionary"),
606 "NSDictionary synthetic children",
ConstString(
"CFDictionaryRef"),
611 "NSDictionary synthetic children",
ConstString(
"CFMutableDictionaryRef"),
616 "NSDictionary synthetic children",
ConstString(
"__CFDictionary"),
621 "NSError synthetic children",
ConstString(
"NSError"),
625 "NSException synthetic children",
ConstString(
"NSException"),
634 "__NSSetI synthetic children",
ConstString(
"__NSSetI"),
638 "__NSSetM synthetic children",
ConstString(
"__NSSetM"),
642 "__NSCFSet synthetic children",
ConstString(
"__NSCFSet"),
646 "CFSetRef synthetic children",
ConstString(
"CFSetRef"),
651 "NSMutableSet synthetic children",
ConstString(
"NSMutableSet"),
655 "NSOrderedSet synthetic children",
ConstString(
"NSOrderedSet"),
659 "__NSOrderedSetI synthetic children",
ConstString(
"__NSOrderedSetI"),
663 "__NSOrderedSetM synthetic children",
ConstString(
"__NSOrderedSetM"),
667 "__CFSet synthetic children",
ConstString(
"__CFSet"),
672 "NSIndexPath synthetic children",
ConstString(
"NSIndexPath"),
677 "CFBag summary provider",
ConstString(
"CFBagRef"), appkit_flags);
680 "CFBag summary provider",
ConstString(
"__CFBag"), appkit_flags);
683 "CFBag summary provider",
ConstString(
"const struct __CFBag"),
687 "CFBag summary provider",
ConstString(
"CFMutableBagRef"), appkit_flags);
691 "CFBinaryHeap summary provider",
ConstString(
"CFBinaryHeapRef"),
695 "CFBinaryHeap summary provider",
ConstString(
"__CFBinaryHeap"),
700 "NSString summary provider",
ConstString(
"NSString"), appkit_flags);
703 "NSString summary provider",
ConstString(
"CFStringRef"), appkit_flags);
706 "NSString summary provider",
ConstString(
"__CFString"), appkit_flags);
709 "NSString summary provider",
ConstString(
"CFMutableStringRef"),
713 "NSString summary provider",
ConstString(
"NSMutableString"),
717 "NSString summary provider",
718 ConstString(
"__NSCFConstantString"), appkit_flags);
721 "NSString summary provider",
ConstString(
"__NSCFString"), appkit_flags);
724 "NSString summary provider",
ConstString(
"NSCFConstantString"),
728 "NSString summary provider",
ConstString(
"NSCFString"), appkit_flags);
731 "NSString summary provider",
ConstString(
"NSPathStore2"), appkit_flags);
734 "NSString summary provider",
735 ConstString(
"NSTaggedPointerString"), appkit_flags);
739 "NSAttributedString summary provider",
744 "NSMutableAttributedString summary provider",
745 ConstString(
"NSMutableAttributedString"), appkit_flags);
749 "NSMutableAttributedString summary provider",
750 ConstString(
"NSConcreteMutableAttributedString"), appkit_flags);
754 "NSBundle summary provider",
ConstString(
"NSBundle"), appkit_flags);
758 "NSData summary provider",
ConstString(
"NSData"), appkit_flags);
761 "NSData summary provider",
ConstString(
"_NSInlineData"), appkit_flags);
764 "NSData summary provider",
ConstString(
"NSConcreteData"), appkit_flags);
767 "NSData summary provider",
ConstString(
"NSConcreteMutableData"),
771 "NSData summary provider",
ConstString(
"NSMutableData"), appkit_flags);
774 "NSData summary provider",
ConstString(
"__NSCFData"), appkit_flags);
777 "NSData summary provider",
ConstString(
"CFDataRef"), appkit_flags);
780 "NSData summary provider",
ConstString(
"CFMutableDataRef"), appkit_flags);
784 "NSMachPort summary provider",
ConstString(
"NSMachPort"), appkit_flags);
788 "NSNotification summary provider",
792 "NSNotification summary provider",
793 ConstString(
"NSConcreteNotification"), appkit_flags);
797 "NSNumber summary provider",
ConstString(
"NSNumber"), appkit_flags);
800 "NSNumber summary provider",
801 ConstString(
"NSConstantIntegerNumber"), appkit_flags);
804 "NSNumber summary provider",
805 ConstString(
"NSConstantDoubleNumber"), appkit_flags);
808 "NSNumber summary provider",
809 ConstString(
"NSConstantFloatNumber"), appkit_flags);
812 "CFNumberRef summary provider",
ConstString(
"CFNumberRef"), appkit_flags);
815 "NSNumber summary provider",
ConstString(
"__NSCFBoolean"), appkit_flags);
818 "NSNumber summary provider",
ConstString(
"__NSCFNumber"), appkit_flags);
821 "NSNumber summary provider",
ConstString(
"NSCFBoolean"), appkit_flags);
824 "NSNumber summary provider",
ConstString(
"NSCFNumber"), appkit_flags);
827 "NSDecimalNumber summary provider",
832 "NSURL summary provider",
ConstString(
"NSURL"), appkit_flags);
835 "NSURL summary provider",
ConstString(
"CFURLRef"), appkit_flags);
839 "NSDate summary provider",
ConstString(
"NSDate"), appkit_flags);
842 "NSDate summary provider",
ConstString(
"__NSDate"), appkit_flags);
845 "NSDate summary provider",
ConstString(
"__NSTaggedDate"), appkit_flags);
848 "NSDate summary provider",
ConstString(
"NSCalendarDate"), appkit_flags);
852 "NSTimeZone summary provider",
ConstString(
"NSTimeZone"), appkit_flags);
855 "NSTimeZone summary provider",
ConstString(
"CFTimeZoneRef"),
859 "NSTimeZone summary provider",
ConstString(
"__NSTimeZone"), appkit_flags);
867 "CFAbsoluteTime summary provider",
873 "NSIndexSet summary provider",
ConstString(
"NSIndexSet"), appkit_flags);
876 "NSIndexSet summary provider",
ConstString(
"NSMutableIndexSet"),
880 "@\"${var.month%d}/${var.day%d}/${var.year%d} "
881 "${var.hour%d}:${var.minute%d}:${var.second}\"",
886 "CFBitVector summary provider",
ConstString(
"CFBitVectorRef"),
890 "CFBitVector summary provider",
891 ConstString(
"CFMutableBitVectorRef"), appkit_flags);
894 "CFBitVector summary provider",
ConstString(
"__CFBitVector"),
898 "CFBitVector summary provider",
899 ConstString(
"__CFMutableBitVector"), appkit_flags);
903 if (!objc_category_sp)
917 "CMTime summary provider",
ConstString(
"CMTime"), cm_flags);
921 static llvm::once_flag g_initialize;
922 static TypeCategoryImplSP g_category;
924 llvm::call_once(g_initialize, [
this]() ->
void {
935std::vector<FormattersMatchCandidate>
938 std::vector<FormattersMatchCandidate> result;
945 const bool check_cpp =
false;
946 const bool check_objc =
true;
947 bool canBeObjCDynamic =
956 if (runtime ==
nullptr)
962 if (
ConstString name = objc_class_sp->GetClassName())
964 {name, valobj.
GetTargetSP()->GetDebugger().GetScriptInterpreter(),
979 bool IsValid()
override {
return m_compiler_type.
IsValid(); }
981 bool DumpToStream(
Stream &stream,
bool print_help_if_available)
override {
983 m_compiler_type.DumpTypeDescription(&stream);
997 ResultSet &results)
override {
1002 if (
auto *decl_vendor = objc_runtime->GetDeclVendor()) {
1007 std::unique_ptr<Language::TypeScavenger::Result> result(
1008 new ObjCScavengerResult(type));
1009 results.insert(std::move(result));
1024 ResultSet &results)
override {
1025 bool result =
false;
1028 auto *persistent_vars = llvm::cast<ClangPersistentVariables>(
1029 target->GetPersistentExpressionStateForLanguage(
1031 if (std::shared_ptr<ClangModulesDeclVendor> clang_modules_decl_vendor =
1032 persistent_vars->GetClangModulesDeclVendor()) {
1034 auto types = clang_modules_decl_vendor->FindTypes(
1036 if (!types.empty()) {
1038 std::unique_ptr<Language::TypeScavenger::Result> result(
1039 new ObjCScavengerResult(types.front()));
1040 results.insert(std::move(result));
1063 return std::unique_ptr<TypeScavenger>(
1065 ObjCRuntimeScavenger,
1066 ObjCDebugInfoScavenger>());
1071 std::string &prefix,
1072 std::string &suffix) {
1074 static ConstString g_CFBinaryHeap(
"CFBinaryHeap");
1076 static ConstString g_NSNumberChar(
"NSNumber:char");
1077 static ConstString g_NSNumberShort(
"NSNumber:short");
1079 static ConstString g_NSNumberLong(
"NSNumber:long");
1080 static ConstString g_NSNumberInt128(
"NSNumber:int128_t");
1081 static ConstString g_NSNumberFloat(
"NSNumber:float");
1082 static ConstString g_NSNumberDouble(
"NSNumber:double");
1095 if (type_hint == g_CFBag || type_hint == g_CFBinaryHeap) {
1100 if (type_hint == g_NSNumberChar) {
1104 if (type_hint == g_NSNumberShort) {
1108 if (type_hint == g_NSNumberInt) {
1112 if (type_hint == g_NSNumberLong) {
1116 if (type_hint == g_NSNumberInt128) {
1117 prefix =
"(int128_t)";
1120 if (type_hint == g_NSNumberFloat) {
1124 if (type_hint == g_NSNumberDouble) {
1125 prefix =
"(double)";
1129 if (type_hint == g_NSData || type_hint == g_NSArray) {
1135 if (type_hint == g_NSString || type_hint == g_NSStringStar) {
1144 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
1145 bool isObjCpointer =
1149 bool canReadValue =
true;
1151 return canReadValue && isZero;
1155 const auto suffixes = {
".h",
".m",
".M"};
1156 for (
auto suffix : suffixes) {
1157 if (file_path.endswith_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.
bool IsEmpty() const
Test for empty string.
void Clear()
Clear this object's state.
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)
std::shared_ptr< ClassDescriptor > ClassDescriptorSP
static ObjCLanguageRuntime * Get(Process &process)
virtual ClassDescriptorSP GetClassDescriptor(ValueObject &in_value)
ConstString GetFullNameWithoutCategory(bool empty_if_no_category)
ConstString GetClassName()
bool IsValid(bool strict) const
bool SetName(const char *name, bool strict)
ConstString GetSelector()
ConstString GetClassNameWithCategory()
ConstString GetCategory()
ConstString GetFullName() const
llvm::StringRef GetPluginName() override
bool GetFormatterPrefixSuffix(ValueObject &valobj, ConstString type_hint, std::string &prefix, std::string &suffix) override
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.
LanguageType
Programming language type.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
static bool IsClangType(const CompilerType &ct)