Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inspect the return value of a function in lldb

Is it possible to inspect the return value of a function in lldb assuming the return value is not assigned to a variable?

like image 466
SFeng Avatar asked Jan 03 '14 10:01

SFeng


People also ask

How do I check the return value in Visual Studio?

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 does LLDB mean in Xcode?

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.

What is LLDB in C?

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.

Where can I see the method return value?

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 ...

Where are the return values of a function stored?

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.

What is the return value of fopen?

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.

Can a function return a value if it is not used?

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.


2 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.

like image 139
solgar Avatar answered Oct 20 '22 19:10

solgar


Step out of the function, and see return value in inspector. Here is my screenshot:

enter image description here

See article for more details: https://gist.github.com/schwa/7812916

like image 37
SFeng Avatar answered Oct 20 '22 18:10

SFeng