Skip to content

Commit 2c365b6

Browse files
authored
Merge pull request #505 from medismailben/apple/apple/stable/20190619
[LLDB] Add mangled function name support & Simplify NSException::GetSummary() output
2 parents 208ec0e + 3ef999b commit 2c365b6

File tree

9 files changed

+78
-23
lines changed

9 files changed

+78
-23
lines changed

lldb/docs/use/formatting.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ A complete list of currently supported format string variables is listed below:
9292
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
9393
| ``function.name-without-args`` | The name of the current function without arguments and values (used to include a function name in-line in the ``disassembly-format``) |
9494
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
95+
| ``function.mangled-name`` | The mangled name of the current function or symbol. |
96+
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
9597
| ``function.pc-offset`` | The program counter offset within the current function or symbol |
9698
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
9799
| ``function.addr-offset`` | The offset in bytes of the current function, formatted as " + dddd" |

lldb/include/lldb/Core/FormatEntity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class FormatEntity {
8585
FunctionName,
8686
FunctionNameWithArgs,
8787
FunctionNameNoArgs,
88+
FunctionMangledName,
8889
FunctionAddrOffset,
8990
FunctionAddrOffsetConcrete,
9091
FunctionLineOffset,

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/Core/FormatEntity.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ static FormatEntity::Entry::Definition g_function_child_entries[] = {
125125
ENTRY("name", FunctionName),
126126
ENTRY("name-without-args", FunctionNameNoArgs),
127127
ENTRY("name-with-args", FunctionNameWithArgs),
128+
ENTRY("mangled-name", FunctionMangledName),
128129
ENTRY("addr-offset", FunctionAddrOffset),
129130
ENTRY("concrete-only-addr-offset-no-padding", FunctionAddrOffsetConcrete),
130131
ENTRY("line-offset", FunctionLineOffset),
@@ -351,6 +352,7 @@ const char *FormatEntity::Entry::TypeToCString(Type t) {
351352
ENUM_TO_CSTR(FunctionName);
352353
ENUM_TO_CSTR(FunctionNameWithArgs);
353354
ENUM_TO_CSTR(FunctionNameNoArgs);
355+
ENUM_TO_CSTR(FunctionMangledName);
354356
ENUM_TO_CSTR(FunctionAddrOffset);
355357
ENUM_TO_CSTR(FunctionAddrOffsetConcrete);
356358
ENUM_TO_CSTR(FunctionLineOffset);
@@ -1744,6 +1746,31 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
17441746
}
17451747
return false;
17461748

1749+
case Entry::Type::FunctionMangledName: {
1750+
const char *name = nullptr;
1751+
if (sc->symbol)
1752+
name = sc->symbol->GetMangled()
1753+
.GetName(sc->symbol->GetLanguage(), Mangled::ePreferMangled)
1754+
.AsCString();
1755+
else if (sc->function)
1756+
name = sc->function->GetMangled()
1757+
.GetName(sc->symbol->GetLanguage(), Mangled::ePreferMangled)
1758+
.AsCString();
1759+
1760+
if (!name)
1761+
return false;
1762+
s.PutCString(name);
1763+
1764+
if (Block *inline_block = sc->block->GetContainingInlinedBlock()) {
1765+
if (const InlineFunctionInfo *inline_info =
1766+
sc->block->GetInlinedFunctionInfo()) {
1767+
s.PutCString(" [inlined] ");
1768+
inline_info->GetName(sc->function->GetLanguage()).Dump(&s);
1769+
}
1770+
}
1771+
return true;
1772+
}
1773+
17471774
case Entry::Type::FunctionAddrOffset:
17481775
if (addr) {
17491776
if (DumpAddressOffsetFromFunction(s, sc, exe_ctx, *addr, false, false,

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;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class MyClass {
2+
public:
3+
MyClass() {}
4+
void foo();
5+
};
6+
7+
void MyClass::foo() {
8+
return; // Set break point at this line.
9+
}
10+
11+
int main() {
12+
MyClass mc;
13+
mc.foo();
14+
return 0;
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# UNSUPPORTED: system-windows
2+
# RUN: %clangxx_host -g -O0 %S/Inputs/main.cpp -o %t.out
3+
# RUN: %lldb -b -s %s %t.out | FileCheck %s
4+
br set -p "Set break"
5+
run
6+
frame info
7+
# CHECK: frame #0: {{.*}}MyClass::foo(
8+
set set frame-format "frame #${frame.index}: {${function.mangled-name}}\n"
9+
frame info
10+
# CHECK: frame #0: _ZN7MyClass3fooEv
11+
c
12+
q

0 commit comments

Comments
 (0)