diff options
Diffstat (limited to 'source/Plugins/Language/ObjC')
-rw-r--r-- | source/Plugins/Language/ObjC/Cocoa.cpp | 119 | ||||
-rw-r--r-- | source/Plugins/Language/ObjC/Cocoa.h | 3 | ||||
-rw-r--r-- | source/Plugins/Language/ObjC/NSDictionary.cpp | 24 | ||||
-rw-r--r-- | source/Plugins/Language/ObjC/NSError.cpp | 11 | ||||
-rw-r--r-- | source/Plugins/Language/ObjC/NSException.cpp | 11 | ||||
-rw-r--r-- | source/Plugins/Language/ObjC/NSSet.cpp | 33 | ||||
-rw-r--r-- | source/Plugins/Language/ObjC/NSString.cpp | 7 | ||||
-rw-r--r-- | source/Plugins/Language/ObjC/ObjCLanguage.cpp | 23 |
8 files changed, 129 insertions, 102 deletions
diff --git a/source/Plugins/Language/ObjC/Cocoa.cpp b/source/Plugins/Language/ObjC/Cocoa.cpp index 8f4997533212..8f278fc2d513 100644 --- a/source/Plugins/Language/ObjC/Cocoa.cpp +++ b/source/Plugins/Language/ObjC/Cocoa.cpp @@ -67,12 +67,12 @@ bool lldb_private::formatters::NSBundleSummaryProvider( if (!valobj_addr) return false; - const char *class_name = descriptor->GetClassName().GetCString(); + llvm::StringRef class_name(descriptor->GetClassName().GetCString()); - if (!class_name || !*class_name) + if (class_name.empty()) return false; - if (!strcmp(class_name, "NSBundle")) { + if (class_name == "NSBundle") { uint64_t offset = 5 * ptr_size; ValueObjectSP text(valobj.GetSyntheticChildAtOffset( offset, @@ -117,12 +117,12 @@ bool lldb_private::formatters::NSTimeZoneSummaryProvider( if (!valobj_addr) return false; - const char *class_name = descriptor->GetClassName().GetCString(); + llvm::StringRef class_name(descriptor->GetClassName().GetCString()); - if (!class_name || !*class_name) + if (class_name.empty()) return false; - if (!strcmp(class_name, "__NSTimeZone")) { + if (class_name == "__NSTimeZone") { uint64_t offset = ptr_size; ValueObjectSP text(valobj.GetSyntheticChildAtOffset( offset, valobj.GetCompilerType(), true)); @@ -164,12 +164,12 @@ bool lldb_private::formatters::NSNotificationSummaryProvider( if (!valobj_addr) return false; - const char *class_name = descriptor->GetClassName().GetCString(); + llvm::StringRef class_name(descriptor->GetClassName().GetCString()); - if (!class_name || !*class_name) + if (class_name.empty()) return false; - if (!strcmp(class_name, "NSConcreteNotification")) { + if (class_name == "NSConcreteNotification") { uint64_t offset = ptr_size; ValueObjectSP text(valobj.GetSyntheticChildAtOffset( offset, valobj.GetCompilerType(), true)); @@ -211,14 +211,14 @@ bool lldb_private::formatters::NSMachPortSummaryProvider( if (!valobj_addr) return false; - const char *class_name = descriptor->GetClassName().GetCString(); + llvm::StringRef class_name(descriptor->GetClassName().GetCString()); - if (!class_name || !*class_name) + if (class_name.empty()) return false; uint64_t port_number = 0; - if (!strcmp(class_name, "NSMachPort")) { + if (class_name == "NSMachPort") { uint64_t offset = (ptr_size == 4 ? 12 : 20); Status error; port_number = process_sp->ReadUnsignedIntegerFromMemory( @@ -259,16 +259,15 @@ bool lldb_private::formatters::NSIndexSetSummaryProvider( if (!valobj_addr) return false; - const char *class_name = descriptor->GetClassName().GetCString(); + llvm::StringRef class_name(descriptor->GetClassName().GetCString()); - if (!class_name || !*class_name) + if (class_name.empty()) return false; uint64_t count = 0; do { - if (!strcmp(class_name, "NSIndexSet") || - !strcmp(class_name, "NSMutableIndexSet")) { + if (class_name == "NSIndexSet" || class_name == "NSMutableIndexSet") { Status error; uint32_t mode = process_sp->ReadUnsignedIntegerFromMemory( valobj_addr + ptr_size, 4, 0, error); @@ -451,15 +450,18 @@ bool lldb_private::formatters::NSNumberSummaryProvider( if (!valobj_addr) return false; - const char *class_name = descriptor->GetClassName().GetCString(); + llvm::StringRef class_name(descriptor->GetClassName().GetCString()); - if (!class_name || !*class_name) + if (class_name.empty()) return false; - if (!strcmp(class_name, "__NSCFBoolean")) + if (class_name == "__NSCFBoolean") return ObjCBooleanSummaryProvider(valobj, stream, options); - if (!strcmp(class_name, "NSNumber") || !strcmp(class_name, "__NSCFNumber")) { + if (class_name == "NSDecimalNumber") + return NSDecimalNumberSummaryProvider(valobj, stream, options); + + if (class_name == "NSNumber" || class_name == "__NSCFNumber") { uint64_t value = 0; uint64_t i_bits = 0; if (descriptor->GetTaggedPointerInfo(&i_bits, &value)) { @@ -626,6 +628,55 @@ bool lldb_private::formatters::NSNumberSummaryProvider( return false; } +bool lldb_private::formatters::NSDecimalNumberSummaryProvider( + ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) { + ProcessSP process_sp = valobj.GetProcessSP(); + if (!process_sp) + return false; + + lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0); + uint32_t ptr_size = process_sp->GetAddressByteSize(); + + Status error; + int8_t exponent = process_sp->ReadUnsignedIntegerFromMemory( + valobj_addr + ptr_size, 1, 0, error); + if (error.Fail()) + return false; + + uint8_t length_and_negative = process_sp->ReadUnsignedIntegerFromMemory( + valobj_addr + ptr_size + 1, 1, 0, error); + if (error.Fail()) + return false; + + // Fifth bit marks negativity. + const bool is_negative = (length_and_negative >> 4) & 1; + + // Zero length and negative means NaN. + uint8_t length = length_and_negative & 0xf; + const bool is_nan = is_negative && (length == 0); + + if (is_nan) { + stream.Printf("NaN"); + return true; + } + + if (length == 0) { + stream.Printf("0"); + return true; + } + + uint64_t mantissa = process_sp->ReadUnsignedIntegerFromMemory( + valobj_addr + ptr_size + 4, 8, 0, error); + if (error.Fail()) + return false; + + if (is_negative) + stream.Printf("-"); + + stream.Printf("%" PRIu64 " x 10^%" PRIi8, mantissa, exponent); + return true; +} + bool lldb_private::formatters::NSURLSummaryProvider( ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) { ProcessSP process_sp = valobj.GetProcessSP(); @@ -766,9 +817,9 @@ bool lldb_private::formatters::NSDateSummaryProvider( stream.Printf("0001-12-30 00:00:00 +0000"); return true; } - // this snippet of code assumes that time_t == seconds since Jan-1-1970 - // this is generally true and POSIXly happy, but might break if a library - // vendor decides to get creative + // this snippet of code assumes that time_t == seconds since Jan-1-1970 this + // is generally true and POSIXly happy, but might break if a library vendor + // decides to get creative time_t epoch = GetOSXEpoch(); epoch = epoch + (time_t)date_value; tm *tm_date = gmtime(&epoch); @@ -871,28 +922,34 @@ bool lldb_private::formatters::NSDataSummaryProvider( uint64_t value = 0; - const char *class_name = descriptor->GetClassName().GetCString(); + llvm::StringRef class_name = descriptor->GetClassName().GetCString(); - if (!class_name || !*class_name) + if (class_name.empty()) return false; - if (!strcmp(class_name, "NSConcreteData") || - !strcmp(class_name, "NSConcreteMutableData") || - !strcmp(class_name, "__NSCFData")) { - uint32_t offset = (is_64bit ? 16 : 8); + bool isNSConcreteData = class_name == "NSConcreteData"; + bool isNSConcreteMutableData = class_name == "NSConcreteMutableData"; + bool isNSCFData = class_name == "__NSCFData"; + if (isNSConcreteData || isNSConcreteMutableData || isNSCFData) { + uint32_t offset; + if (isNSConcreteData) + offset = is_64bit ? 8 : 4; + else + offset = is_64bit ? 16 : 8; + Status error; value = process_sp->ReadUnsignedIntegerFromMemory( valobj_addr + offset, is_64bit ? 8 : 4, 0, error); if (error.Fail()) return false; - } else if (!strcmp(class_name, "_NSInlineData")) { + } else if (class_name == "_NSInlineData") { uint32_t offset = (is_64bit ? 8 : 4); Status error; value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + offset, 2, 0, error); if (error.Fail()) return false; - } else if (!strcmp(class_name, "_NSZeroData")) { + } else if (class_name == "_NSZeroData") { value = 0; } else return false; diff --git a/source/Plugins/Language/ObjC/Cocoa.h b/source/Plugins/Language/ObjC/Cocoa.h index 10ff3bce3b98..0f2ca5496302 100644 --- a/source/Plugins/Language/ObjC/Cocoa.h +++ b/source/Plugins/Language/ObjC/Cocoa.h @@ -32,6 +32,9 @@ bool NSDataSummaryProvider(ValueObject &valobj, Stream &stream, bool NSNumberSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options); +bool NSDecimalNumberSummaryProvider(ValueObject &valobj, Stream &stream, + const TypeSummaryOptions &options); + bool NSNotificationSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options); diff --git a/source/Plugins/Language/ObjC/NSDictionary.cpp b/source/Plugins/Language/ObjC/NSDictionary.cpp index c564aa1a8571..5be051b46bd6 100644 --- a/source/Plugins/Language/ObjC/NSDictionary.cpp +++ b/source/Plugins/Language/ObjC/NSDictionary.cpp @@ -396,6 +396,8 @@ bool lldb_private::formatters::NSDictionarySummaryProvider( static const ConstString g_DictionaryMLegacy("__NSDictionaryM_Legacy"); static const ConstString g_DictionaryMImmutable("__NSDictionaryM_Immutable"); static const ConstString g_Dictionary1("__NSSingleEntryDictionaryI"); + static const ConstString g_Dictionary0("__NSDictionary0"); + static const ConstString g_DictionaryCF("__NSCFDictionary"); if (class_name.IsEmpty()) return false; @@ -407,7 +409,8 @@ bool lldb_private::formatters::NSDictionarySummaryProvider( if (error.Fail()) return false; value &= (is_64bit ? ~0xFC00000000000000UL : ~0xFC000000U); - } else if (class_name == g_DictionaryM || class_name == g_DictionaryMLegacy) { + } else if (class_name == g_DictionaryM || class_name == g_DictionaryMLegacy || + class_name == g_DictionaryCF) { AppleObjCRuntime *apple_runtime = llvm::dyn_cast_or_null<AppleObjCRuntime>(runtime); Status error; @@ -423,17 +426,9 @@ bool lldb_private::formatters::NSDictionarySummaryProvider( return false; } else if (class_name == g_Dictionary1) { value = 1; + } else if (class_name == g_Dictionary0) { + value = 0; } - /*else if (!strcmp(class_name,"__NSCFDictionary")) - { - Status error; - value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + (is_64bit ? - 20 : 12), 4, 0, error); - if (error.Fail()) - return false; - if (is_64bit) - value &= ~0x0f1f000000000000UL; - }*/ else { auto &map(NSDictionary_Additionals::GetAdditionalSummaries()); for (auto &candidate : map) { @@ -491,6 +486,7 @@ lldb_private::formatters::NSDictionarySyntheticFrontEndCreator( static const ConstString g_Dictionary1("__NSSingleEntryDictionaryI"); static const ConstString g_DictionaryImmutable("__NSDictionaryM_Immutable"); static const ConstString g_DictionaryMLegacy("__NSDictionaryM_Legacy"); + static const ConstString g_Dictionary0("__NSDictionary0"); if (class_name.IsEmpty()) return nullptr; @@ -673,11 +669,7 @@ lldb_private::formatters::NSDictionary1SyntheticFrontEnd:: size_t lldb_private::formatters::NSDictionary1SyntheticFrontEnd:: GetIndexOfChildWithName(const ConstString &name) { static const ConstString g_zero("[0]"); - - if (name == g_zero) - return 0; - - return UINT32_MAX; + return name == g_zero ? 0 : UINT32_MAX; } size_t lldb_private::formatters::NSDictionary1SyntheticFrontEnd:: diff --git a/source/Plugins/Language/ObjC/NSError.cpp b/source/Plugins/Language/ObjC/NSError.cpp index 4365a12b54e1..77721e2db326 100644 --- a/source/Plugins/Language/ObjC/NSError.cpp +++ b/source/Plugins/Language/ObjC/NSError.cpp @@ -177,12 +177,11 @@ public: private: // the child here can be "real" (i.e. an actual child of the root) or - // synthetized from raw memory - // if the former, I need to store a plain pointer to it - or else a loop of - // references will cause this entire hierarchy of values to leak - // if the latter, then I need to store a SharedPointer to it - so that it only - // goes away when everyone else in the cluster goes away - // oh joy! + // synthetized from raw memory if the former, I need to store a plain pointer + // to it - or else a loop of references will cause this entire hierarchy of + // values to leak if the latter, then I need to store a SharedPointer to it - + // so that it only goes away when everyone else in the cluster goes away oh + // joy! ValueObject *m_child_ptr; ValueObjectSP m_child_sp; }; diff --git a/source/Plugins/Language/ObjC/NSException.cpp b/source/Plugins/Language/ObjC/NSException.cpp index 1da4f6de19a0..c6970efae4d3 100644 --- a/source/Plugins/Language/ObjC/NSException.cpp +++ b/source/Plugins/Language/ObjC/NSException.cpp @@ -171,12 +171,11 @@ public: private: // the child here can be "real" (i.e. an actual child of the root) or - // synthetized from raw memory - // if the former, I need to store a plain pointer to it - or else a loop of - // references will cause this entire hierarchy of values to leak - // if the latter, then I need to store a SharedPointer to it - so that it only - // goes away when everyone else in the cluster goes away - // oh joy! + // synthetized from raw memory if the former, I need to store a plain pointer + // to it - or else a loop of references will cause this entire hierarchy of + // values to leak if the latter, then I need to store a SharedPointer to it - + // so that it only goes away when everyone else in the cluster goes away oh + // joy! ValueObject *m_child_ptr; ValueObjectSP m_child_sp; }; diff --git a/source/Plugins/Language/ObjC/NSSet.cpp b/source/Plugins/Language/ObjC/NSSet.cpp index fa2483ecc094..2da4bc034f32 100644 --- a/source/Plugins/Language/ObjC/NSSet.cpp +++ b/source/Plugins/Language/ObjC/NSSet.cpp @@ -269,7 +269,8 @@ bool lldb_private::formatters::NSSetSummaryProvider( if (!class_name || !*class_name) return false; - if (!strcmp(class_name, "__NSSetI")) { + if (!strcmp(class_name, "__NSSetI") || + !strcmp(class_name, "__NSOrderedSetI")) { Status error; value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error); @@ -289,32 +290,7 @@ bool lldb_private::formatters::NSSetSummaryProvider( } if (error.Fail()) return false; - } - /*else if (!strcmp(class_name,"__NSCFSet")) - { - Status error; - value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + (is_64bit ? - 20 : 12), 4, 0, error); - if (error.Fail()) - return false; - if (is_64bit) - value &= ~0x1fff000000000000UL; - } - else if (!strcmp(class_name,"NSCountedSet")) - { - Status error; - value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, - ptr_size, 0, error); - if (error.Fail()) - return false; - value = process_sp->ReadUnsignedIntegerFromMemory(value + (is_64bit ? 20 : - 12), 4, 0, error); - if (error.Fail()) - return false; - if (is_64bit) - value &= ~0x1fff000000000000UL; - }*/ - else { + } else { auto &map(NSSet_Additionals::GetAdditionalSummaries()); auto iter = map.find(class_name_cs), end = map.end(); if (iter != end) @@ -371,7 +347,8 @@ lldb_private::formatters::NSSetSyntheticFrontEndCreator( if (!class_name || !*class_name) return nullptr; - if (!strcmp(class_name, "__NSSetI")) { + if (!strcmp(class_name, "__NSSetI") || + !strcmp(class_name, "__NSOrderedSetI")) { return (new NSSetISyntheticFrontEnd(valobj_sp)); } else if (!strcmp(class_name, "__NSSetM")) { AppleObjCRuntime *apple_runtime = diff --git a/source/Plugins/Language/ObjC/NSString.cpp b/source/Plugins/Language/ObjC/NSString.cpp index 3b4edf68e063..0b12edb53d7a 100644 --- a/source/Plugins/Language/ObjC/NSString.cpp +++ b/source/Plugins/Language/ObjC/NSString.cpp @@ -256,8 +256,7 @@ bool lldb_private::formatters::NSStringSummaryProvider( uint64_t location = valobj_addr + 2 * ptr_size; if (!has_explicit_length) { // in this kind of string, the byte before the string content is a length - // byte - // so let's try and use it to handle the embedded NUL case + // byte so let's try and use it to handle the embedded NUL case Status error; explicit_length = process_sp->ReadUnsignedIntegerFromMemory(location, 1, 0, error); @@ -368,9 +367,7 @@ bool lldb_private::formatters::NSTaggedString_SummaryProvider( } // this is a fairly ugly trick - pretend that the numeric value is actually a - // char* - // this works under a few assumptions: - // little endian architecture + // char* this works under a few assumptions: little endian architecture // sizeof(uint64_t) > g_MaxNonBitmaskedLen if (len_bits <= g_MaxNonBitmaskedLen) { stream.Printf("%s", prefix.c_str()); diff --git a/source/Plugins/Language/ObjC/ObjCLanguage.cpp b/source/Plugins/Language/ObjC/ObjCLanguage.cpp index ea2eec7b33b7..47874b3be8fd 100644 --- a/source/Plugins/Language/ObjC/ObjCLanguage.cpp +++ b/source/Plugins/Language/ObjC/ObjCLanguage.cpp @@ -90,9 +90,8 @@ bool ObjCLanguage::MethodName::SetName(llvm::StringRef name, bool strict) { if (name.empty()) return IsValid(strict); - // 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 + // 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.size() > 1 && (name[0] == '+' || name[0] == '-')) { @@ -108,7 +107,7 @@ bool ObjCLanguage::MethodName::SetName(llvm::StringRef name, bool strict) { if (valid_prefix) { int name_len = name.size(); - // Objective C methods must have at least: + // Objective-C methods must have at least: // "-[" or "+[" prefix // One character for a class name // One character for the space between the class name @@ -134,8 +133,8 @@ const ConstString &ObjCLanguage::MethodName::GetClassName() { 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). + // 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) { @@ -164,8 +163,8 @@ const ConstString &ObjCLanguage::MethodName::GetClassNameWithCategory() { // contain a '(', then we can also fill in the m_class if (!m_class && strchr(m_class_category.GetCString(), '(') == nullptr) { m_class = m_class_category; - // No '(' was found in the full name, we can definitively say - // that our category was valid (and empty). + // No '(' was found in the full name, we can definitively say that + // our category was valid (and empty). m_category_is_valid = true; } } @@ -764,6 +763,10 @@ static void LoadObjCFormatters(TypeCategoryImplSP objc_category_sp) { AddCXXSummary( objc_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("NSCFNumber"), appkit_flags); + AddCXXSummary(objc_category_sp, + lldb_private::formatters::NSNumberSummaryProvider, + "NSDecimalNumber summary provider", + ConstString("NSDecimalNumber"), appkit_flags); AddCXXSummary(objc_category_sp, lldb_private::formatters::NSURLSummaryProvider, @@ -796,8 +799,8 @@ static void LoadObjCFormatters(TypeCategoryImplSP objc_category_sp) { objc_category_sp, lldb_private::formatters::NSTimeZoneSummaryProvider, "NSTimeZone summary provider", ConstString("__NSTimeZone"), appkit_flags); - // CFAbsoluteTime is actually a double rather than a pointer to an object - // we do not care about the numeric value, since it is probably meaningless to + // CFAbsoluteTime is actually a double rather than a pointer to an object we + // do not care about the numeric value, since it is probably meaningless to // users appkit_flags.SetDontShowValue(true); AddCXXSummary(objc_category_sp, |