Skip to content

Commit 3ef999b

Browse files
committed
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 <[email protected]> Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D71311 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 43cf344 commit 3ef999b

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def nsexception_data_formatter_commands(self):
2525
'frame variable except0 except1 except2 except3',
2626
substrs=[
2727
'(NSException *) except0 = ',
28-
'name: @"TheGuyWhoHasNoName" - reason: @"cuz it\'s funny"',
28+
'@"First"',
2929
'(NSException *) except1 = ',
30-
'name: @"TheGuyWhoHasNoName~1" - reason: @"cuz it\'s funny"',
30+
'@"Second"',
3131
'(NSException *) except2 = ',
32-
'name: @"TheGuyWhoHasNoName`2" - reason: @"cuz it\'s funny"',
32+
' @"Third"',
3333
'(NSException *) except3 = ',
34-
'name: @"TheGuyWhoHasNoName/3" - reason: @"cuz it\'s funny"'
34+
' @"Fourth"'
3535
])

lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,10 @@ int main (int argc, const char * argv[])
492492
nsurl0 = [bundle bundleURL];
493493
}
494494

495-
NSException* except0 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName" reason:@"cuz it's funny" userInfo:nil];
496-
NSException* except1 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName~1" reason:@"cuz it's funny" userInfo:nil];
497-
NSException* except2 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName`2" reason:@"cuz it's funny" userInfo:nil];
498-
NSException* except3 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName/3" reason:@"cuz it's funny" userInfo:nil];
495+
NSException* except0 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName" reason:@"First" userInfo:nil];
496+
NSException* except1 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName~1" reason:@"Second" userInfo:nil];
497+
NSException* except2 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName`2" reason:@"Third" userInfo:nil];
498+
NSException* except3 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName/3" reason:@"Fourth" userInfo:nil];
499499

500500
NSURL *nsurl = [[NSURL alloc] initWithString:@"http://www.foo.bar"];
501501
NSURL *nsurl2 = [NSURL URLWithString:@"page.html" relativeToURL:nsurl];

lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_objc_exceptions_at_throw(self):
3131

3232
self.expect('thread exception', substrs=[
3333
'(NSException *) exception = ',
34-
'name: "ThrownException" - reason: "SomeReason"',
34+
'"SomeReason"',
3535
])
3636

3737
target = self.dbg.GetSelectedTarget()
@@ -63,7 +63,7 @@ def test_objc_exceptions_at_throw(self):
6363
'frame variable e1',
6464
substrs=[
6565
'(NSException *) e1 = ',
66-
'name: "ExceptionName" - reason: "SomeReason"'
66+
'"SomeReason"'
6767
])
6868

6969
self.expect(
@@ -79,7 +79,7 @@ def test_objc_exceptions_at_throw(self):
7979
e1 = frame.FindVariable("e1")
8080
self.assertTrue(e1)
8181
self.assertEqual(e1.type.name, "NSException *")
82-
self.assertEqual(e1.GetSummary(), 'name: "ExceptionName" - reason: "SomeReason"')
82+
self.assertEqual(e1.GetSummary(), '"SomeReason"')
8383
self.assertEqual(e1.GetChildMemberWithName("name").description, "ExceptionName")
8484
self.assertEqual(e1.GetChildMemberWithName("reason").description, "SomeReason")
8585
userInfo = e1.GetChildMemberWithName("userInfo").dynamic
@@ -92,7 +92,7 @@ def test_objc_exceptions_at_throw(self):
9292
'frame variable e2',
9393
substrs=[
9494
'(NSException *) e2 = ',
95-
'name: "ThrownException" - reason: "SomeReason"'
95+
'"SomeReason"'
9696
])
9797

9898
self.expect(
@@ -108,7 +108,7 @@ def test_objc_exceptions_at_throw(self):
108108
e2 = frame.FindVariable("e2")
109109
self.assertTrue(e2)
110110
self.assertEqual(e2.type.name, "NSException *")
111-
self.assertEqual(e2.GetSummary(), 'name: "ThrownException" - reason: "SomeReason"')
111+
self.assertEqual(e2.GetSummary(), '"SomeReason"')
112112
self.assertEqual(e2.GetChildMemberWithName("name").description, "ThrownException")
113113
self.assertEqual(e2.GetChildMemberWithName("reason").description, "SomeReason")
114114
userInfo = e2.GetChildMemberWithName("userInfo").dynamic
@@ -141,7 +141,7 @@ def test_objc_exceptions_at_abort(self):
141141

142142
self.expect('thread exception', substrs=[
143143
'(NSException *) exception = ',
144-
'name: "ThrownException" - reason: "SomeReason"',
144+
'"SomeReason"',
145145
'libobjc.A.dylib`objc_exception_throw',
146146
'a.out`foo', 'at main.mm:24',
147147
'a.out`rethrow', 'at main.mm:35',

lldb/source/Plugins/Language/ObjC/NSException.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,19 @@ static bool ExtractFields(ValueObject &valobj, ValueObjectSP *name_sp,
9696

9797
bool lldb_private::formatters::NSException_SummaryProvider(
9898
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
99-
lldb::ValueObjectSP name_sp;
10099
lldb::ValueObjectSP reason_sp;
101-
if (!ExtractFields(valobj, &name_sp, &reason_sp, nullptr, nullptr))
100+
if (!ExtractFields(valobj, nullptr, &reason_sp, nullptr, nullptr))
102101
return false;
103102

104-
if (!name_sp || !reason_sp)
103+
if (!reason_sp) {
104+
stream.Printf("No reason");
105105
return false;
106+
}
106107

107-
StreamString name_str_summary;
108108
StreamString reason_str_summary;
109-
if (NSStringSummaryProvider(*name_sp, name_str_summary, options) &&
110-
NSStringSummaryProvider(*reason_sp, reason_str_summary, options) &&
111-
!name_str_summary.Empty() && !reason_str_summary.Empty()) {
112-
stream.Printf("name: %s - reason: %s", name_str_summary.GetData(),
113-
reason_str_summary.GetData());
109+
if (NSStringSummaryProvider(*reason_sp, reason_str_summary, options) &&
110+
!reason_str_summary.Empty()) {
111+
stream.Printf("%s", reason_str_summary.GetData());
114112
return true;
115113
} else
116114
return false;

0 commit comments

Comments
 (0)