[Lldb-commits] [lldb] 2c91d5b - LanguageRuntime: Simplify NSException::GetSummary() output

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Fri Dec 13 12:33:58 PST 2019


Author: Med Ismail Bennani
Date: 2019-12-13T12:33:31-08:00
New Revision: 2c91d5ba83156900944c82bb8feb1e340adb8ae4

URL: https://github.com/llvm/llvm-project/commit/2c91d5ba83156900944c82bb8feb1e340adb8ae4
DIFF: https://github.com/llvm/llvm-project/commit/2c91d5ba83156900944c82bb8feb1e340adb8ae4.diff

LOG: LanguageRuntime: Simplify NSException::GetSummary() output

Summary:
Right now, NSException::GetSummary() has the following output:
"name: $exception_name - reason: $exception_reason"

It would be better to simplify the output by removing the name and only
showing the exception's reason. This way, annotations would look nicer in
the editor, and would be a shorter summary in the Variables Inspector.

Accessing the exception's name can still be done by expanding the
NSException object in the Variables Inspector.

rdar://54770115

Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71311

Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py
    lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m
    lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
    lldb/source/Plugins/Language/ObjC/NSException.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py
index d304dcc289ca..6265c05c5b70 100644
--- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py
@@ -24,11 +24,11 @@ def nsexception_data_formatter_commands(self):
             'frame variable except0 except1 except2 except3',
             substrs=[
                 '(NSException *) except0 = ',
-                'name: @"TheGuyWhoHasNoName" - reason: @"cuz it\'s funny"',
+                '@"First"',
                 '(NSException *) except1 = ',
-                'name: @"TheGuyWhoHasNoName~1" - reason: @"cuz it\'s funny"',
+                '@"Second"',
                 '(NSException *) except2 = ',
-                'name: @"TheGuyWhoHasNoName`2" - reason: @"cuz it\'s funny"',
+                ' @"Third"',
                 '(NSException *) except3 = ',
-                'name: @"TheGuyWhoHasNoName/3" - reason: @"cuz it\'s funny"'
+                ' @"Fourth"'
             ])

diff  --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m
index a370a48739c8..f0dc2055976a 100644
--- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m
@@ -492,10 +492,10 @@ int main (int argc, const char * argv[])
 	        nsurl0 = [bundle bundleURL];
 	    }
 
-	    NSException* except0 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName" reason:@"cuz it's funny" userInfo:nil];
-	    NSException* except1 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName~1" reason:@"cuz it's funny" userInfo:nil];
-	    NSException* except2 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName`2" reason:@"cuz it's funny" userInfo:nil];
-	    NSException* except3 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName/3" reason:@"cuz it's funny" userInfo:nil];
+	    NSException* except0 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName" reason:@"First" userInfo:nil];
+	    NSException* except1 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName~1" reason:@"Second" userInfo:nil];
+	    NSException* except2 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName`2" reason:@"Third" userInfo:nil];
+	    NSException* except3 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName/3" reason:@"Fourth" userInfo:nil];
 
 	    NSURL *nsurl = [[NSURL alloc] initWithString:@"http://www.foo.bar"];
 	    NSURL *nsurl2 = [NSURL URLWithString:@"page.html" relativeToURL:nsurl];

diff  --git a/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py b/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
index dbf6287bb20a..ce9ee8e027ff 100644
--- a/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
+++ b/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
@@ -30,7 +30,7 @@ def test_objc_exceptions_at_throw(self):
 
         self.expect('thread exception', substrs=[
                 '(NSException *) exception = ',
-                'name: "ThrownException" - reason: "SomeReason"',
+                '"SomeReason"',
             ])
 
         target = self.dbg.GetSelectedTarget()
@@ -62,7 +62,7 @@ def test_objc_exceptions_at_throw(self):
             'frame variable e1',
             substrs=[
                 '(NSException *) e1 = ',
-                'name: "ExceptionName" - reason: "SomeReason"'
+                '"SomeReason"'
             ])
 
         self.expect(
@@ -78,7 +78,7 @@ def test_objc_exceptions_at_throw(self):
         e1 = frame.FindVariable("e1")
         self.assertTrue(e1)
         self.assertEqual(e1.type.name, "NSException *")
-        self.assertEqual(e1.GetSummary(), 'name: "ExceptionName" - reason: "SomeReason"')
+        self.assertEqual(e1.GetSummary(), '"SomeReason"')
         self.assertEqual(e1.GetChildMemberWithName("name").description, "ExceptionName")
         self.assertEqual(e1.GetChildMemberWithName("reason").description, "SomeReason")
         userInfo = e1.GetChildMemberWithName("userInfo").dynamic
@@ -91,7 +91,7 @@ def test_objc_exceptions_at_throw(self):
             'frame variable e2',
             substrs=[
                 '(NSException *) e2 = ',
-                'name: "ThrownException" - reason: "SomeReason"'
+                '"SomeReason"'
             ])
 
         self.expect(
@@ -107,7 +107,7 @@ def test_objc_exceptions_at_throw(self):
         e2 = frame.FindVariable("e2")
         self.assertTrue(e2)
         self.assertEqual(e2.type.name, "NSException *")
-        self.assertEqual(e2.GetSummary(), 'name: "ThrownException" - reason: "SomeReason"')
+        self.assertEqual(e2.GetSummary(), '"SomeReason"')
         self.assertEqual(e2.GetChildMemberWithName("name").description, "ThrownException")
         self.assertEqual(e2.GetChildMemberWithName("reason").description, "SomeReason")
         userInfo = e2.GetChildMemberWithName("userInfo").dynamic
@@ -140,7 +140,7 @@ def test_objc_exceptions_at_abort(self):
 
         self.expect('thread exception', substrs=[
                 '(NSException *) exception = ',
-                'name: "ThrownException" - reason: "SomeReason"',
+                '"SomeReason"',
                 'libobjc.A.dylib`objc_exception_throw',
                 'a.out`foo', 'at main.mm:24',
                 'a.out`rethrow', 'at main.mm:35',

diff  --git a/lldb/source/Plugins/Language/ObjC/NSException.cpp b/lldb/source/Plugins/Language/ObjC/NSException.cpp
index 6f3c356f5f28..9150787361c5 100644
--- a/lldb/source/Plugins/Language/ObjC/NSException.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSException.cpp
@@ -98,21 +98,19 @@ static bool ExtractFields(ValueObject &valobj, ValueObjectSP *name_sp,
 
 bool lldb_private::formatters::NSException_SummaryProvider(
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
-  lldb::ValueObjectSP name_sp;
   lldb::ValueObjectSP reason_sp;
-  if (!ExtractFields(valobj, &name_sp, &reason_sp, nullptr, nullptr))
+  if (!ExtractFields(valobj, nullptr, &reason_sp, nullptr, nullptr))
     return false;
 
-  if (!name_sp || !reason_sp)
+  if (!reason_sp) {
+    stream.Printf("No reason");
     return false;
+  }
 
-  StreamString name_str_summary;
   StreamString reason_str_summary;
-  if (NSStringSummaryProvider(*name_sp, name_str_summary, options) &&
-      NSStringSummaryProvider(*reason_sp, reason_str_summary, options) &&
-      !name_str_summary.Empty() && !reason_str_summary.Empty()) {
-    stream.Printf("name: %s - reason: %s", name_str_summary.GetData(),
-                  reason_str_summary.GetData());
+  if (NSStringSummaryProvider(*reason_sp, reason_str_summary, options) &&
+      !reason_str_summary.Empty()) {
+    stream.Printf("%s", reason_str_summary.GetData());
     return true;
   } else
     return false;


        


More information about the lldb-commits mailing list