Is it possible to inspect the return value of a function in lldb assuming the return value is not assigned to a variable?
3 Answers
Answer is wrong so I will post correct one.
To inspect return value you need to (lldb) finish
(abbr. for thread step-out
) from function which return value you want to examine and then use:
(lldb) thread info
This will give you output similar to this:
thread #1: tid = 0x28955, (frame variables and stuff), stop reason = step out
Return value: (NSMenu *) $3 = 0x0000600000065280
Having this you can just:
(lldb) po $3
Note that gdb
way of inspecting return value by just using finish
doesn't print anything for lldb.
Additionally as SFeng pointed out if you use Xcode you can just see it in UI inspector after you stepped out from previous function or method.

- 4,312
- 2
- 26
- 30
-
Im not seeing any info printed after `finish`. But `po $x0` seems to have the right value – Hari Honor Mar 25 '17 at 09:41
-
@HariKaramSingh That's exactly what I have said, finish for lldb doesn't print anything. – solgar Mar 26 '17 at 19:11
-
2@tboyce12 This doesn't work for Swift in Xcode 8.3.2. Don't know about other versions. – solgar Jun 27 '17 at 11:52
-
@solgar You are second only to clive1. – mondaugen Apr 04 '18 at 14:43
-
Doesn't work on latest clang/lldb lldb-1000.11.38.2 – TCSGrad Apr 18 '19 at 00:28
-
@TCSGrad It doesn't work for swift up to 4. Haven't checked Swift 5. I'll add this note to answer. – solgar Apr 18 '19 at 14:28
Step out of the function, and see return value in inspector. Here is my screenshot:
See article for more details: https://gist.github.com/schwa/7812916
-
7Note this only works if you exit the function with a "step out". lldb doesn't yet track all step over's and step-in's to see if one of them exited a function. – Jim Ingham Jan 07 '14 at 21:59
-
4
You can setting a breakpoint on function's return point(similar to thread step-out
) and print out the return value. Try this(working on ARM platform):
#1 (lldb) br set -n "__FUNCTION_NAME_YOUR_WANT_TO_TRACE" -K false
#2 (lldb) br set -a $lr -o true -G true -C "po $x0"
At #1 we create a breakpoint on a __FUNCTION_NAME_YOUR_WANT_TO_TRACE,\ -K false
make sure we do not skip the prologue in assembly.
Since we do not skip prologue, when the first breakpoint hit, we can retrieve the return address of this function(bl
and ble
instruction set the return address to link register, aka lr
).
At this time we create a breakpoint at return address in #2.
-o true
means it is a one-shot breakpoint, it would delete itself after hitting;
-G true
means auto-continue;
-C "po $x0"
means adding a po $x0
command to this breakpoint, to print content at x0 register, which stores return value of targeting function.

- 51
- 6