Is it possible to inspect the return value of a function in lldb assuming the return value is not assigned to a variable?
View return values for functions If the window is closed, use Debug > Windows > Autos to open the Autos window. In addition, you can enter functions in the Immediate window to view return values. (Open it using Debug > Windows > Immediate.)
What is LLDB? A low-level debugger (LLDB) is the default debugger used in Xcode and is part of the LLVM project. LLDB replaced GDB in XCode 5 and has several advantages, such as performance and scriptability.
It is built as a set of reusable components which highly leverage existing libraries in the larger LLVM Project, such as the Clang expression parser and LLVM disassembler. LLDB is the default debugger in Xcode on macOS and supports debugging C, Objective-C and C++ on the desktop and iOS devices and simulator.
There are 2 places where we can see the method return value: 1 In the Debugger Immediate window, using the $ReturnValue keyword. To open the Immediate window while debugging, choose... 2 In the Debugger Autos window. To open the Autos window while debugging, choose Debug -> Windows -> Autos (or press... More ...
For most functions, the return value is stored in that register, even if it's not used. The exceptions to this are functions returning types larger than 32 bits, specifically 64-bit integers ( long long ), double s, and structs or classes. The other exception is if you're not running on an Intel architecture.
The fopen () function returns NULL if a file is not opened successfully. For information about the ILE C/C++ function return values, see ILE C/C++ Runtime Library Functions. To verify that each runtime library function has completed successfully, a program should check the function return values.
Yes, just examine the EAX register by typing print $eax. For most functions, the return value is stored in that register, even if it's not used. The exceptions to this are functions returning types larger than 32 bits, specifically 64-bit integers ( long long ), double s, and structs or classes.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With