如果您进入 func2 - 然后使用“完成”命令再次退出,lldb 将显示您退出的函数的返回值。例如:
(lldb) br s -n func2
Breakpoint 2: where = step-into`func2() + 18 at step-into.cpp:12, address = 0x0000000100000d62
(lldb) c
Process 29307 resuming
Process 29307 stopped
* thread #1: tid = 0x300436, function: func2() , stop reason = breakpoint 2.1
frame #0: 0x0000000100000d62 step-into`func2() at step-into.cpp:12
9 std::string
10 func2()
11 {
-> 12 return std::string("some string");
13 }
14
15 int
好的,现在你在函数中停止了,所以当你finish out 时,lldb 会收集返回值并显示在线程打印中:
(lldb) fin
Process 29307 stopped
进程 29333 已停止
*线程#1:tid = 0x300e94, 0x0000000100000def step-into`main + 31 at step-into.cpp:18, queue = 'com.apple.main-thread', stop reason = step out
返回值: (std::__1::basic_string, std::__1::allocator >) $0 = "some string"
frame #0: 0x0000000100000def step-into`main at step-into.cpp:18
15 int
16 main ()
17 {
-> 18 func(func2());
19 return 0;
20 }
或者如果您有一个没有返回值的自定义“线程格式”,您可以通过 SB API 获得它:
(lldb) script print lldb.thread.GetStopReturnValue()
(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) $0 = "some string"
如果您使用的是 Xcode,它还会在本地视图顶部添加一个项目,显示您刚刚退出的函数的返回值。