[Lldb-commits] [lldb] r305727 - Updated NSNumber formatter for new internal representation.
Sean Callanan via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 19 11:32:22 PDT 2017
Author: spyffe
Date: Mon Jun 19 13:32:22 2017
New Revision: 305727
URL: http://llvm.org/viewvc/llvm-project?rev=305727&view=rev
Log:
Updated NSNumber formatter for new internal representation.
<rdar://problem/32780109>
Modified:
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py
lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp
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=305727&r1=305726&r2=305727&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 Mon Jun 19 13:32:22 2017
@@ -186,16 +186,27 @@ class ObjCDataFormatterTestCase(TestBase
def nsnumber_data_formatter_commands(self):
# Now enable AppKit and check we are displaying Cocoa classes correctly
- self.expect('frame variable num1 num2 num3 num4 num5 num6 num7 num9',
+ self.expect('frame variable num1 num2 num3 num5 num6 num7 num9',
substrs=['(NSNumber *) num1 = ', ' (int)5',
'(NSNumber *) num2 = ', ' (float)3.1',
'(NSNumber *) num3 = ', ' (double)3.14',
- '(NSNumber *) num4 = ', ' (long)-2',
'(NSNumber *) num5 = ', ' (char)65',
'(NSNumber *) num6 = ', ' (long)255',
'(NSNumber *) num7 = ', '2000000',
'(NSNumber *) num9 = ', ' (short)-31616'])
+
+ self.runCmd('frame variable num4', check=True)
+ output = self.res.GetOutput()
+ i128_handled_correctly = False
+
+ if output.find('long') >= 0:
+ i128_handled_correctly = (output.find('(long)-2') >= 0)
+ if output.find('int128_t') >= 0:
+ i128_handled_correctly = (output.find('(int128_t)18446744073709551614') >= 0) # deliberately broken, should be ..14
+
+ self.assertTrue(i128_handled_correctly, "Expected valid output for int128_t; got " + output)
+
self.expect('frame variable num_at1 num_at2 num_at3 num_at4',
substrs=['(NSNumber *) num_at1 = ', ' (int)12',
'(NSNumber *) num_at2 = ', ' (int)-12',
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=305727&r1=305726&r2=305727&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp (original)
+++ lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp Mon Jun 19 13:32:22 2017
@@ -31,6 +31,8 @@
#include "lldb/Utility/Status.h"
#include "lldb/Utility/Stream.h"
+#include "llvm/ADT/APInt.h"
+
#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h"
#include "NSString.h"
@@ -369,6 +371,28 @@ static void NSNumber_FormatLong(ValueObj
stream.Printf("%s%" PRId64 "%s", prefix.c_str(), value, suffix.c_str());
}
+static void NSNumber_FormatInt128(ValueObject &valobj, Stream &stream,
+ const llvm::APInt &value,
+ lldb::LanguageType lang) {
+ static ConstString g_TypeHint("NSNumber:int128_t");
+
+ std::string prefix, suffix;
+ if (Language *language = Language::FindPlugin(lang)) {
+ if (!language->GetFormatterPrefixSuffix(valobj, g_TypeHint, prefix,
+ suffix)) {
+ prefix.clear();
+ suffix.clear();
+ }
+ }
+
+ stream.PutCString(prefix.c_str());
+ const int radix = 10;
+ const bool isSigned = true;
+ std::string str = value.toString(radix, isSigned);
+ stream.PutCString(str.c_str());
+ stream.PutCString(suffix.c_str());
+}
+
static void NSNumber_FormatFloat(ValueObject &valobj, Stream &stream,
float value, lldb::LanguageType lang) {
static ConstString g_TypeHint("NSNumber:float");
@@ -462,22 +486,72 @@ bool lldb_private::formatters::NSNumberS
return true;
} else {
Status error;
- uint8_t data_type = (process_sp->ReadUnsignedIntegerFromMemory(
- valobj_addr + ptr_size, 1, 0, error) &
- 0x1F);
+
+ AppleObjCRuntime *runtime =
+ llvm::dyn_cast_or_null<AppleObjCRuntime>(
+ process_sp->GetObjCLanguageRuntime());
+
+ const bool new_format =
+ (runtime && runtime->GetFoundationVersion() >= 1400);
+
+ enum class TypeCodes : int {
+ sint8 = 0x0,
+ sint16 = 0x1,
+ sint32 = 0x2,
+ sint64 = 0x3,
+ f32 = 0x4,
+ f64 = 0x5,
+ sint128 = 0x6
+ };
+
uint64_t data_location = valobj_addr + 2 * ptr_size;
+ TypeCodes type_code;
+
+ if (new_format) {
+ uint64_t cfinfoa =
+ process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size,
+ ptr_size, 0, error);
+
+ if (error.Fail())
+ return false;
+
+ bool is_preserved_number = cfinfoa & 0x8;
+ if (is_preserved_number) {
+ lldbassert(!"We should handle preserved numbers!");
+ return false;
+ }
+
+ type_code = (TypeCodes)(cfinfoa & 0x7);
+ } else {
+ uint8_t data_type =
+ process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, 1,
+ 0, error) & 0x1F;
+
+ if (error.Fail())
+ return false;
+
+ switch (data_type) {
+ case 1: type_code = TypeCodes::sint8; break;
+ case 2: type_code = TypeCodes::sint16; break;
+ case 3: type_code = TypeCodes::sint32; break;
+ case 17: data_location += 8; LLVM_FALLTHROUGH;
+ case 4: type_code = TypeCodes::sint64; break;
+ case 5: type_code = TypeCodes::f32; break;
+ case 6: type_code = TypeCodes::f64; break;
+ default: return false;
+ }
+ }
+
uint64_t value = 0;
- if (error.Fail())
- return false;
- switch (data_type) {
- case 1: // 0B00001
+ switch (type_code) {
+ case TypeCodes::sint8:
value = process_sp->ReadUnsignedIntegerFromMemory(data_location, 1, 0,
error);
if (error.Fail())
return false;
NSNumber_FormatChar(valobj, stream, (char)value, options.GetLanguage());
break;
- case 2: // 0B0010
+ case TypeCodes::sint16:
value = process_sp->ReadUnsignedIntegerFromMemory(data_location, 2, 0,
error);
if (error.Fail())
@@ -485,24 +559,21 @@ bool lldb_private::formatters::NSNumberS
NSNumber_FormatShort(valobj, stream, (short)value,
options.GetLanguage());
break;
- case 3: // 0B0011
+ case TypeCodes::sint32:
value = process_sp->ReadUnsignedIntegerFromMemory(data_location, 4, 0,
error);
if (error.Fail())
return false;
NSNumber_FormatInt(valobj, stream, (int)value, options.GetLanguage());
break;
- case 17: // 0B10001
- data_location += 8;
- LLVM_FALLTHROUGH;
- case 4: // 0B0100
+ case TypeCodes::sint64:
value = process_sp->ReadUnsignedIntegerFromMemory(data_location, 8, 0,
error);
if (error.Fail())
return false;
NSNumber_FormatLong(valobj, stream, value, options.GetLanguage());
break;
- case 5: // 0B0101
+ case TypeCodes::f32:
{
uint32_t flt_as_int = process_sp->ReadUnsignedIntegerFromMemory(
data_location, 4, 0, error);
@@ -513,7 +584,7 @@ bool lldb_private::formatters::NSNumberS
NSNumber_FormatFloat(valobj, stream, flt_value, options.GetLanguage());
break;
}
- case 6: // 0B0110
+ case TypeCodes::f64:
{
uint64_t dbl_as_lng = process_sp->ReadUnsignedIntegerFromMemory(
data_location, 8, 0, error);
@@ -524,6 +595,21 @@ bool lldb_private::formatters::NSNumberS
NSNumber_FormatDouble(valobj, stream, dbl_value, options.GetLanguage());
break;
}
+ case TypeCodes::sint128: // internally, this is the same
+ {
+ uint64_t words[2];
+ words[1] = process_sp->ReadUnsignedIntegerFromMemory(
+ data_location, 8, 0, error);
+ if (error.Fail())
+ return false;
+ words[0] = process_sp->ReadUnsignedIntegerFromMemory(
+ data_location + 8, 8, 0, error);
+ if (error.Fail())
+ return false;
+ llvm::APInt i128_value(128, words);
+ NSNumber_FormatInt128(valobj, stream, i128_value, options.GetLanguage());
+ break;
+ }
default:
return false;
}
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=305727&r1=305726&r2=305727&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp (original)
+++ lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp Mon Jun 19 13:32:22 2017
@@ -1026,6 +1026,7 @@ bool ObjCLanguage::GetFormatterPrefixSuf
static ConstString g_NSNumberShort("NSNumber:short");
static ConstString g_NSNumberInt("NSNumber:int");
static ConstString g_NSNumberLong("NSNumber:long");
+ static ConstString g_NSNumberInt128("NSNumber:int128_t");
static ConstString g_NSNumberFloat("NSNumber:float");
static ConstString g_NSNumberDouble("NSNumber:double");
@@ -1061,6 +1062,10 @@ bool ObjCLanguage::GetFormatterPrefixSuf
prefix = "(long)";
return true;
}
+ if (type_hint == g_NSNumberInt128) {
+ prefix = "(int128_t)";
+ return true;
+ }
if (type_hint == g_NSNumberFloat) {
prefix = "(float)";
return true;
More information about the lldb-commits
mailing list