[Lldb-commits] [lldb] r334638 - [ObjC] Add dataformatter for NSDecimalNumber
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Jun 13 11:47:05 PDT 2018
Author: jdevlieghere
Date: Wed Jun 13 11:47:04 2018
New Revision: 334638
URL: http://llvm.org/viewvc/llvm-project?rev=334638&view=rev
Log:
[ObjC] Add dataformatter for NSDecimalNumber
This patch adds a data formatter for NSDecimalNumber. The latter is a
Foundation object used for representing and performing arithmetic on
base-10 numbers that bridges to Decimal.
Differential revision: https://reviews.llvm.org/D48114
Modified:
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m
lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp
lldb/trunk/source/Plugins/Language/ObjC/Cocoa.h
lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp
Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py?rev=334638&r1=334637&r2=334638&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py Wed Jun 13 11:47:04 2018
@@ -215,6 +215,14 @@ class ObjCDataFormatterTestCase(TestBase
'(NSNumber *) num_at3 = ', ' (double)12.5',
'(NSNumber *) num_at4 = ', ' (double)-12.5'])
+ def nsdecimalnumber_data_formatter_commands(self):
+ self.expect('frame variable decimal_number decimal_neg_number decimal_one decimal_zero decimal_nan',
+ substrs=['(NSDecimalNumber *) decimal_number = ', '123456 x 10^-10',
+ '(NSDecimalNumber *) decimal_neg_number = ', '-123456 x 10^10',
+ '(NSDecimalNumber *) decimal_one = ', '1 x 10^0',
+ '(NSDecimalNumber *) decimal_zero = ', '0',
+ '(NSDecimalNumber *) decimal_nan = ', 'NaN'])
+
def nscontainers_data_formatter_commands(self):
self.expect(
'frame variable newArray newDictionary newMutableDictionary cfarray_ref mutable_array_ref',
Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m?rev=334638&r1=334637&r2=334638&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m Wed Jun 13 11:47:04 2018
@@ -169,7 +169,11 @@ int main (int argc, const char * argv[])
NSNumber* num_at3 = @12.5;
NSNumber* num_at4 = @-12.5;
- NSDecimalNumber* decimal_one = [NSDecimalNumber one];
+ NSDecimalNumber* decimal_number = [NSDecimalNumber decimalNumberWithMantissa:123456 exponent:-10 isNegative:NO];
+ NSDecimalNumber* decimal_number_neg = [NSDecimalNumber decimalNumberWithMantissa:123456 exponent:10 isNegative:YES];
+ NSDecimalNumber* decimal_one = [NSDecimalNumber one];
+ NSDecimalNumber* decimal_zero = [NSDecimalNumber zero];
+ NSDecimalNumber* decimal_nan = [NSDecimalNumber notANumber];
NSString *str0 = [num6 stringValue];
Modified: lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp?rev=334638&r1=334637&r2=334638&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp (original)
+++ lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp Wed Jun 13 11:47:04 2018
@@ -458,6 +458,9 @@ bool lldb_private::formatters::NSNumberS
if (class_name == "__NSCFBoolean")
return ObjCBooleanSummaryProvider(valobj, stream, options);
+ 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;
@@ -625,6 +628,55 @@ bool lldb_private::formatters::NSNumberS
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();
Modified: lldb/trunk/source/Plugins/Language/ObjC/Cocoa.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/Cocoa.h?rev=334638&r1=334637&r2=334638&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/ObjC/Cocoa.h (original)
+++ lldb/trunk/source/Plugins/Language/ObjC/Cocoa.h Wed Jun 13 11:47:04 2018
@@ -32,6 +32,9 @@ bool NSDataSummaryProvider(ValueObject &
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);
Modified: lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp?rev=334638&r1=334637&r2=334638&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp (original)
+++ lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp Wed Jun 13 11:47:04 2018
@@ -763,6 +763,10 @@ static void LoadObjCFormatters(TypeCateg
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,
More information about the lldb-commits
mailing list