1 //===-- Cocoa.cpp -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Other libraries and framework includes
16 #include "lldb/Core/Mangled.h"
17 #include "lldb/Core/ValueObject.h"
18 #include "lldb/Core/ValueObjectConstResult.h"
19 #include "lldb/DataFormatters/FormattersHelpers.h"
20 #include "lldb/DataFormatters/StringPrinter.h"
21 #include "lldb/DataFormatters/TypeSummary.h"
22 #include "lldb/Host/Time.h"
23 #include "lldb/Symbol/ClangASTContext.h"
24 #include "lldb/Target/Language.h"
25 #include "lldb/Target/ObjCLanguageRuntime.h"
26 #include "lldb/Target/Process.h"
27 #include "lldb/Target/ProcessStructReader.h"
28 #include "lldb/Target/Target.h"
29 #include "lldb/Utility/DataBufferHeap.h"
30 #include "lldb/Utility/Endian.h"
31 #include "lldb/Utility/Status.h"
32 #include "lldb/Utility/Stream.h"
34 #include "llvm/ADT/APInt.h"
36 #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h"
41 using namespace lldb_private;
42 using namespace lldb_private::formatters;
44 bool lldb_private::formatters::NSBundleSummaryProvider(
45 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
46 ProcessSP process_sp = valobj.GetProcessSP();
50 ObjCLanguageRuntime *runtime =
51 (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime(
52 lldb::eLanguageTypeObjC);
57 ObjCLanguageRuntime::ClassDescriptorSP descriptor(
58 runtime->GetClassDescriptor(valobj));
60 if (!descriptor || !descriptor->IsValid())
63 uint32_t ptr_size = process_sp->GetAddressByteSize();
65 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
70 const char *class_name = descriptor->GetClassName().GetCString();
72 if (!class_name || !*class_name)
75 if (!strcmp(class_name, "NSBundle")) {
76 uint64_t offset = 5 * ptr_size;
77 ValueObjectSP text(valobj.GetSyntheticChildAtOffset(
79 valobj.GetCompilerType().GetBasicTypeFromAST(lldb::eBasicTypeObjCID),
82 StreamString summary_stream;
83 bool was_nsstring_ok =
84 NSStringSummaryProvider(*text, summary_stream, options);
85 if (was_nsstring_ok && summary_stream.GetSize() > 0) {
86 stream.Printf("%s", summary_stream.GetData());
94 bool lldb_private::formatters::NSTimeZoneSummaryProvider(
95 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
96 ProcessSP process_sp = valobj.GetProcessSP();
100 ObjCLanguageRuntime *runtime =
101 (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime(
102 lldb::eLanguageTypeObjC);
107 ObjCLanguageRuntime::ClassDescriptorSP descriptor(
108 runtime->GetClassDescriptor(valobj));
110 if (!descriptor || !descriptor->IsValid())
113 uint32_t ptr_size = process_sp->GetAddressByteSize();
115 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
120 const char *class_name = descriptor->GetClassName().GetCString();
122 if (!class_name || !*class_name)
125 if (!strcmp(class_name, "__NSTimeZone")) {
126 uint64_t offset = ptr_size;
127 ValueObjectSP text(valobj.GetSyntheticChildAtOffset(
128 offset, valobj.GetCompilerType(), true));
129 StreamString summary_stream;
130 bool was_nsstring_ok =
131 NSStringSummaryProvider(*text, summary_stream, options);
132 if (was_nsstring_ok && summary_stream.GetSize() > 0) {
133 stream.Printf("%s", summary_stream.GetData());
141 bool lldb_private::formatters::NSNotificationSummaryProvider(
142 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
143 ProcessSP process_sp = valobj.GetProcessSP();
147 ObjCLanguageRuntime *runtime =
148 (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime(
149 lldb::eLanguageTypeObjC);
154 ObjCLanguageRuntime::ClassDescriptorSP descriptor(
155 runtime->GetClassDescriptor(valobj));
157 if (!descriptor || !descriptor->IsValid())
160 uint32_t ptr_size = process_sp->GetAddressByteSize();
162 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
167 const char *class_name = descriptor->GetClassName().GetCString();
169 if (!class_name || !*class_name)
172 if (!strcmp(class_name, "NSConcreteNotification")) {
173 uint64_t offset = ptr_size;
174 ValueObjectSP text(valobj.GetSyntheticChildAtOffset(
175 offset, valobj.GetCompilerType(), true));
176 StreamString summary_stream;
177 bool was_nsstring_ok =
178 NSStringSummaryProvider(*text, summary_stream, options);
179 if (was_nsstring_ok && summary_stream.GetSize() > 0) {
180 stream.Printf("%s", summary_stream.GetData());
188 bool lldb_private::formatters::NSMachPortSummaryProvider(
189 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
190 ProcessSP process_sp = valobj.GetProcessSP();
194 ObjCLanguageRuntime *runtime =
195 (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime(
196 lldb::eLanguageTypeObjC);
201 ObjCLanguageRuntime::ClassDescriptorSP descriptor(
202 runtime->GetClassDescriptor(valobj));
204 if (!descriptor || !descriptor->IsValid())
207 uint32_t ptr_size = process_sp->GetAddressByteSize();
209 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
214 const char *class_name = descriptor->GetClassName().GetCString();
216 if (!class_name || !*class_name)
219 uint64_t port_number = 0;
221 if (!strcmp(class_name, "NSMachPort")) {
222 uint64_t offset = (ptr_size == 4 ? 12 : 20);
224 port_number = process_sp->ReadUnsignedIntegerFromMemory(
225 offset + valobj_addr, 4, 0, error);
226 if (error.Success()) {
227 stream.Printf("mach port: %u",
228 (uint32_t)(port_number & 0x00000000FFFFFFFF));
236 bool lldb_private::formatters::NSIndexSetSummaryProvider(
237 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
238 ProcessSP process_sp = valobj.GetProcessSP();
242 ObjCLanguageRuntime *runtime =
243 (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime(
244 lldb::eLanguageTypeObjC);
249 ObjCLanguageRuntime::ClassDescriptorSP descriptor(
250 runtime->GetClassDescriptor(valobj));
252 if (!descriptor || !descriptor->IsValid())
255 uint32_t ptr_size = process_sp->GetAddressByteSize();
257 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
262 const char *class_name = descriptor->GetClassName().GetCString();
264 if (!class_name || !*class_name)
270 if (!strcmp(class_name, "NSIndexSet") ||
271 !strcmp(class_name, "NSMutableIndexSet")) {
273 uint32_t mode = process_sp->ReadUnsignedIntegerFromMemory(
274 valobj_addr + ptr_size, 4, 0, error);
277 // this means the set is empty - count = 0
278 if ((mode & 1) == 1) {
283 mode = 1; // this means the set only has one range
285 mode = 2; // this means the set has multiple ranges
287 count = process_sp->ReadUnsignedIntegerFromMemory(
288 valobj_addr + 3 * ptr_size, ptr_size, 0, error);
292 // read a pointer to the data at 2*ptr_size
293 count = process_sp->ReadUnsignedIntegerFromMemory(
294 valobj_addr + 2 * ptr_size, ptr_size, 0, error);
297 // read the data at 2*ptr_size from the first location
298 count = process_sp->ReadUnsignedIntegerFromMemory(count + 2 * ptr_size,
306 stream.Printf("%" PRIu64 " index%s", count, (count == 1 ? "" : "es"));
310 static void NSNumber_FormatChar(ValueObject &valobj, Stream &stream, char value,
311 lldb::LanguageType lang) {
312 static ConstString g_TypeHint("NSNumber:char");
314 std::string prefix, suffix;
315 if (Language *language = Language::FindPlugin(lang)) {
316 if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
323 stream.Printf("%s%hhd%s", prefix.c_str(), value, suffix.c_str());
326 static void NSNumber_FormatShort(ValueObject &valobj, Stream &stream,
327 short value, lldb::LanguageType lang) {
328 static ConstString g_TypeHint("NSNumber:short");
330 std::string prefix, suffix;
331 if (Language *language = Language::FindPlugin(lang)) {
332 if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
339 stream.Printf("%s%hd%s", prefix.c_str(), value, suffix.c_str());
342 static void NSNumber_FormatInt(ValueObject &valobj, Stream &stream, int value,
343 lldb::LanguageType lang) {
344 static ConstString g_TypeHint("NSNumber:int");
346 std::string prefix, suffix;
347 if (Language *language = Language::FindPlugin(lang)) {
348 if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
355 stream.Printf("%s%d%s", prefix.c_str(), value, suffix.c_str());
358 static void NSNumber_FormatLong(ValueObject &valobj, Stream &stream,
359 uint64_t value, lldb::LanguageType lang) {
360 static ConstString g_TypeHint("NSNumber:long");
362 std::string prefix, suffix;
363 if (Language *language = Language::FindPlugin(lang)) {
364 if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
371 stream.Printf("%s%" PRId64 "%s", prefix.c_str(), value, suffix.c_str());
374 static void NSNumber_FormatInt128(ValueObject &valobj, Stream &stream,
375 const llvm::APInt &value,
376 lldb::LanguageType lang) {
377 static ConstString g_TypeHint("NSNumber:int128_t");
379 std::string prefix, suffix;
380 if (Language *language = Language::FindPlugin(lang)) {
381 if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
388 stream.PutCString(prefix.c_str());
389 const int radix = 10;
390 const bool isSigned = true;
391 std::string str = value.toString(radix, isSigned);
392 stream.PutCString(str.c_str());
393 stream.PutCString(suffix.c_str());
396 static void NSNumber_FormatFloat(ValueObject &valobj, Stream &stream,
397 float value, lldb::LanguageType lang) {
398 static ConstString g_TypeHint("NSNumber:float");
400 std::string prefix, suffix;
401 if (Language *language = Language::FindPlugin(lang)) {
402 if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
409 stream.Printf("%s%f%s", prefix.c_str(), value, suffix.c_str());
412 static void NSNumber_FormatDouble(ValueObject &valobj, Stream &stream,
413 double value, lldb::LanguageType lang) {
414 static ConstString g_TypeHint("NSNumber:double");
416 std::string prefix, suffix;
417 if (Language *language = Language::FindPlugin(lang)) {
418 if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
425 stream.Printf("%s%g%s", prefix.c_str(), value, suffix.c_str());
428 bool lldb_private::formatters::NSNumberSummaryProvider(
429 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
430 ProcessSP process_sp = valobj.GetProcessSP();
434 ObjCLanguageRuntime *runtime =
435 (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime(
436 lldb::eLanguageTypeObjC);
441 ObjCLanguageRuntime::ClassDescriptorSP descriptor(
442 runtime->GetClassDescriptor(valobj));
444 if (!descriptor || !descriptor->IsValid())
447 uint32_t ptr_size = process_sp->GetAddressByteSize();
449 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
454 const char *class_name = descriptor->GetClassName().GetCString();
456 if (!class_name || !*class_name)
459 if (!strcmp(class_name, "__NSCFBoolean"))
460 return ObjCBooleanSummaryProvider(valobj, stream, options);
462 if (!strcmp(class_name, "NSNumber") || !strcmp(class_name, "__NSCFNumber")) {
465 if (descriptor->GetTaggedPointerInfo(&i_bits, &value)) {
468 NSNumber_FormatChar(valobj, stream, (char)value, options.GetLanguage());
472 NSNumber_FormatShort(valobj, stream, (short)value,
473 options.GetLanguage());
477 NSNumber_FormatInt(valobj, stream, (int)value, options.GetLanguage());
481 NSNumber_FormatLong(valobj, stream, value, options.GetLanguage());
490 AppleObjCRuntime *runtime =
491 llvm::dyn_cast_or_null<AppleObjCRuntime>(
492 process_sp->GetObjCLanguageRuntime());
494 const bool new_format =
495 (runtime && runtime->GetFoundationVersion() >= 1400);
497 enum class TypeCodes : int {
507 uint64_t data_location = valobj_addr + 2 * ptr_size;
512 process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size,
518 bool is_preserved_number = cfinfoa & 0x8;
519 if (is_preserved_number) {
520 lldbassert(!static_cast<bool>("We should handle preserved numbers!"));
524 type_code = static_cast<TypeCodes>(cfinfoa & 0x7);
527 process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, 1,
534 case 1: type_code = TypeCodes::sint8; break;
535 case 2: type_code = TypeCodes::sint16; break;
536 case 3: type_code = TypeCodes::sint32; break;
537 case 17: data_location += 8; LLVM_FALLTHROUGH;
538 case 4: type_code = TypeCodes::sint64; break;
539 case 5: type_code = TypeCodes::f32; break;
540 case 6: type_code = TypeCodes::f64; break;
541 default: return false;
546 bool success = false;
548 case TypeCodes::sint8:
549 value = process_sp->ReadUnsignedIntegerFromMemory(data_location, 1, 0,
553 NSNumber_FormatChar(valobj, stream, (char)value, options.GetLanguage());
556 case TypeCodes::sint16:
557 value = process_sp->ReadUnsignedIntegerFromMemory(data_location, 2, 0,
561 NSNumber_FormatShort(valobj, stream, (short)value,
562 options.GetLanguage());
565 case TypeCodes::sint32:
566 value = process_sp->ReadUnsignedIntegerFromMemory(data_location, 4, 0,
570 NSNumber_FormatInt(valobj, stream, (int)value, options.GetLanguage());
573 case TypeCodes::sint64:
574 value = process_sp->ReadUnsignedIntegerFromMemory(data_location, 8, 0,
578 NSNumber_FormatLong(valobj, stream, value, options.GetLanguage());
583 uint32_t flt_as_int = process_sp->ReadUnsignedIntegerFromMemory(
584 data_location, 4, 0, error);
587 float flt_value = 0.0f;
588 memcpy(&flt_value, &flt_as_int, sizeof(flt_as_int));
589 NSNumber_FormatFloat(valobj, stream, flt_value, options.GetLanguage());
595 uint64_t dbl_as_lng = process_sp->ReadUnsignedIntegerFromMemory(
596 data_location, 8, 0, error);
599 double dbl_value = 0.0;
600 memcpy(&dbl_value, &dbl_as_lng, sizeof(dbl_as_lng));
601 NSNumber_FormatDouble(valobj, stream, dbl_value, options.GetLanguage());
605 case TypeCodes::sint128: // internally, this is the same
608 words[1] = process_sp->ReadUnsignedIntegerFromMemory(
609 data_location, 8, 0, error);
612 words[0] = process_sp->ReadUnsignedIntegerFromMemory(
613 data_location + 8, 8, 0, error);
616 llvm::APInt i128_value(128, words);
617 NSNumber_FormatInt128(valobj, stream, i128_value, options.GetLanguage());
629 bool lldb_private::formatters::NSURLSummaryProvider(
630 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
631 ProcessSP process_sp = valobj.GetProcessSP();
635 ObjCLanguageRuntime *runtime =
636 (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime(
637 lldb::eLanguageTypeObjC);
642 ObjCLanguageRuntime::ClassDescriptorSP descriptor(
643 runtime->GetClassDescriptor(valobj));
645 if (!descriptor || !descriptor->IsValid())
648 uint32_t ptr_size = process_sp->GetAddressByteSize();
650 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
655 llvm::StringRef class_name = descriptor->GetClassName().GetStringRef();
657 if (!class_name.equals("NSURL"))
660 uint64_t offset_text = ptr_size + ptr_size +
661 8; // ISA + pointer + 8 bytes of data (even on 32bit)
662 uint64_t offset_base = offset_text + ptr_size;
663 CompilerType type(valobj.GetCompilerType());
664 ValueObjectSP text(valobj.GetSyntheticChildAtOffset(offset_text, type, true));
665 ValueObjectSP base(valobj.GetSyntheticChildAtOffset(offset_base, type, true));
668 if (text->GetValueAsUnsigned(0) == 0)
670 StreamString summary;
671 if (!NSStringSummaryProvider(*text, summary, options))
673 if (base && base->GetValueAsUnsigned(0)) {
674 std::string summary_str = summary.GetString();
676 if (!summary_str.empty())
677 summary_str.pop_back();
678 summary_str += " -- ";
679 StreamString base_summary;
680 if (NSURLSummaryProvider(*base, base_summary, options) &&
681 !base_summary.Empty()) {
682 llvm::StringRef base_str = base_summary.GetString();
683 if (base_str.size() > 2)
684 base_str = base_str.drop_front(2);
685 summary_str += base_str;
688 summary.PutCString(summary_str);
690 if (!summary.Empty()) {
691 stream.PutCString(summary.GetString());
698 bool lldb_private::formatters::NSDateSummaryProvider(
699 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
700 ProcessSP process_sp = valobj.GetProcessSP();
704 ObjCLanguageRuntime *runtime =
705 (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime(
706 lldb::eLanguageTypeObjC);
711 ObjCLanguageRuntime::ClassDescriptorSP descriptor(
712 runtime->GetClassDescriptor(valobj));
714 if (!descriptor || !descriptor->IsValid())
717 uint32_t ptr_size = process_sp->GetAddressByteSize();
719 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
724 uint64_t date_value_bits = 0;
725 double date_value = 0.0;
727 ConstString class_name = descriptor->GetClassName();
729 static const ConstString g_NSDate("NSDate");
730 static const ConstString g___NSDate("__NSDate");
731 static const ConstString g___NSTaggedDate("__NSTaggedDate");
732 static const ConstString g_NSCalendarDate("NSCalendarDate");
734 if (class_name.IsEmpty())
737 if ((class_name == g_NSDate) || (class_name == g___NSDate) ||
738 (class_name == g___NSTaggedDate)) {
739 uint64_t info_bits = 0, value_bits = 0;
740 if (descriptor->GetTaggedPointerInfo(&info_bits, &value_bits)) {
741 date_value_bits = ((value_bits << 8) | (info_bits << 4));
742 memcpy(&date_value, &date_value_bits, sizeof(date_value_bits));
745 process_sp->GetTarget().GetArchitecture().GetTriple());
747 (triple.isWatchOS() && triple.isWatchABI()) ? 8 : ptr_size;
749 date_value_bits = process_sp->ReadUnsignedIntegerFromMemory(
750 valobj_addr + delta, 8, 0, error);
751 memcpy(&date_value, &date_value_bits, sizeof(date_value_bits));
755 } else if (class_name == g_NSCalendarDate) {
757 date_value_bits = process_sp->ReadUnsignedIntegerFromMemory(
758 valobj_addr + 2 * ptr_size, 8, 0, error);
759 memcpy(&date_value, &date_value_bits, sizeof(date_value_bits));
765 if (date_value == -63114076800) {
766 stream.Printf("0001-12-30 00:00:00 +0000");
769 // this snippet of code assumes that time_t == seconds since Jan-1-1970
770 // this is generally true and POSIXly happy, but might break if a library
771 // vendor decides to get creative
772 time_t epoch = GetOSXEpoch();
773 epoch = epoch + (time_t)date_value;
774 tm *tm_date = gmtime(&epoch);
777 std::string buffer(1024, 0);
778 if (strftime(&buffer[0], 1023, "%Z", tm_date) == 0)
780 stream.Printf("%04d-%02d-%02d %02d:%02d:%02d %s", tm_date->tm_year + 1900,
781 tm_date->tm_mon + 1, tm_date->tm_mday, tm_date->tm_hour,
782 tm_date->tm_min, tm_date->tm_sec, buffer.c_str());
786 bool lldb_private::formatters::ObjCClassSummaryProvider(
787 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
788 ProcessSP process_sp = valobj.GetProcessSP();
792 ObjCLanguageRuntime *runtime =
793 (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime(
794 lldb::eLanguageTypeObjC);
799 ObjCLanguageRuntime::ClassDescriptorSP descriptor(
800 runtime->GetClassDescriptorFromISA(valobj.GetValueAsUnsigned(0)));
802 if (!descriptor || !descriptor->IsValid())
805 ConstString class_name = descriptor->GetClassName();
807 if (class_name.IsEmpty())
811 Mangled(class_name).GetDemangledName(lldb::eLanguageTypeUnknown))
814 stream.Printf("%s", class_name.AsCString("<unknown class>"));
818 class ObjCClassSyntheticChildrenFrontEnd : public SyntheticChildrenFrontEnd {
820 ObjCClassSyntheticChildrenFrontEnd(lldb::ValueObjectSP valobj_sp)
821 : SyntheticChildrenFrontEnd(*valobj_sp) {}
823 ~ObjCClassSyntheticChildrenFrontEnd() override = default;
825 size_t CalculateNumChildren() override { return 0; }
827 lldb::ValueObjectSP GetChildAtIndex(size_t idx) override {
828 return lldb::ValueObjectSP();
831 bool Update() override { return false; }
833 bool MightHaveChildren() override { return false; }
835 size_t GetIndexOfChildWithName(const ConstString &name) override {
840 SyntheticChildrenFrontEnd *
841 lldb_private::formatters::ObjCClassSyntheticFrontEndCreator(
842 CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
843 return new ObjCClassSyntheticChildrenFrontEnd(valobj_sp);
846 template <bool needs_at>
847 bool lldb_private::formatters::NSDataSummaryProvider(
848 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
849 ProcessSP process_sp = valobj.GetProcessSP();
853 ObjCLanguageRuntime *runtime =
854 (ObjCLanguageRuntime *)process_sp->GetLanguageRuntime(
855 lldb::eLanguageTypeObjC);
860 ObjCLanguageRuntime::ClassDescriptorSP descriptor(
861 runtime->GetClassDescriptor(valobj));
863 if (!descriptor || !descriptor->IsValid())
866 bool is_64bit = (process_sp->GetAddressByteSize() == 8);
867 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
874 const char *class_name = descriptor->GetClassName().GetCString();
876 if (!class_name || !*class_name)
879 if (!strcmp(class_name, "NSConcreteData") ||
880 !strcmp(class_name, "NSConcreteMutableData") ||
881 !strcmp(class_name, "__NSCFData")) {
882 uint32_t offset = (is_64bit ? 16 : 8);
884 value = process_sp->ReadUnsignedIntegerFromMemory(
885 valobj_addr + offset, is_64bit ? 8 : 4, 0, error);
888 } else if (!strcmp(class_name, "_NSInlineData")) {
889 uint32_t offset = (is_64bit ? 8 : 4);
891 value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + offset, 2,
895 } else if (!strcmp(class_name, "_NSZeroData")) {
900 stream.Printf("%s%" PRIu64 " byte%s%s", (needs_at ? "@\"" : ""), value,
901 (value != 1 ? "s" : ""), (needs_at ? "\"" : ""));
906 bool lldb_private::formatters::ObjCBOOLSummaryProvider(
907 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
908 const uint32_t type_info = valobj.GetCompilerType().GetTypeInfo();
910 ValueObjectSP real_guy_sp = valobj.GetSP();
912 if (type_info & eTypeIsPointer) {
914 real_guy_sp = valobj.Dereference(err);
915 if (err.Fail() || !real_guy_sp)
917 } else if (type_info & eTypeIsReference) {
918 real_guy_sp = valobj.GetChildAtIndex(0, true);
922 uint8_t value = (real_guy_sp->GetValueAsUnsigned(0) & 0xFF);
928 stream.Printf("YES");
931 stream.Printf("%u", value);
937 bool lldb_private::formatters::ObjCBooleanSummaryProvider(
938 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
939 lldb::addr_t valobj_ptr_value =
940 valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
941 if (valobj_ptr_value == LLDB_INVALID_ADDRESS)
944 ProcessSP process_sp(valobj.GetProcessSP());
948 if (AppleObjCRuntime *objc_runtime =
949 (AppleObjCRuntime *)process_sp->GetObjCLanguageRuntime()) {
950 lldb::addr_t cf_true = LLDB_INVALID_ADDRESS,
951 cf_false = LLDB_INVALID_ADDRESS;
952 objc_runtime->GetValuesForGlobalCFBooleans(cf_true, cf_false);
953 if (valobj_ptr_value == cf_true) {
954 stream.PutCString("YES");
957 if (valobj_ptr_value == cf_false) {
958 stream.PutCString("NO");
966 template <bool is_sel_ptr>
967 bool lldb_private::formatters::ObjCSELSummaryProvider(
968 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
969 lldb::ValueObjectSP valobj_sp;
971 CompilerType charstar(valobj.GetCompilerType()
972 .GetBasicTypeFromAST(eBasicTypeChar)
978 ExecutionContext exe_ctx(valobj.GetExecutionContextRef());
981 lldb::addr_t data_address = valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
982 if (data_address == LLDB_INVALID_ADDRESS)
984 valobj_sp = ValueObject::CreateValueObjectFromAddress("text", data_address,
989 valobj.GetData(data, error);
993 ValueObject::CreateValueObjectFromData("text", data, exe_ctx, charstar);
999 stream.Printf("%s", valobj_sp->GetSummaryAsCString());
1003 // POSIX has an epoch on Jan-1-1970, but Cocoa prefers Jan-1-2001
1004 // this call gives the POSIX equivalent of the Cocoa epoch
1005 time_t lldb_private::formatters::GetOSXEpoch() {
1006 static time_t epoch = 0;
1011 tm_epoch.tm_sec = 0;
1012 tm_epoch.tm_hour = 0;
1013 tm_epoch.tm_min = 0;
1014 tm_epoch.tm_mon = 0;
1015 tm_epoch.tm_mday = 1;
1016 tm_epoch.tm_year = 2001 - 1900;
1017 tm_epoch.tm_isdst = -1;
1018 tm_epoch.tm_gmtoff = 0;
1019 tm_epoch.tm_zone = nullptr;
1020 epoch = timegm(&tm_epoch);
1026 template bool lldb_private::formatters::NSDataSummaryProvider<true>(
1027 ValueObject &, Stream &, const TypeSummaryOptions &);
1029 template bool lldb_private::formatters::NSDataSummaryProvider<false>(
1030 ValueObject &, Stream &, const TypeSummaryOptions &);
1032 template bool lldb_private::formatters::ObjCSELSummaryProvider<true>(
1033 ValueObject &, Stream &, const TypeSummaryOptions &);
1035 template bool lldb_private::formatters::ObjCSELSummaryProvider<false>(
1036 ValueObject &, Stream &, const TypeSummaryOptions &);