Is it possible to inspect the return value of a function in gdb assuming the return value is not assigned to a variable?
To get the location of the stored return address of a specific function, you can place a breakpoint at that function and use the info frame command.
A blank line as input to GDB (typing just RET ) means to repeat the previous command. Certain commands (for example, run ) will not repeat this way; these are commands whose unintentional repetition might cause trouble and which you are unlikely to want to repeat.
To execute one line of code, type "step" or "s". If the line to be executed is a function call, gdb will step into that function and start executing its code one line at a time. If you want to execute the entire function with one keypress, type "next" or "n".
I imagine there are better ways to do it, but the finish command executes until the current stack frame is popped off and prints the return value -- given the program
int fun() { return 42; } int main( int argc, char *v[] ) { fun(); return 0; }
You can debug it as such --
(gdb) r Starting program: /usr/home/hark/a.out Breakpoint 1, fun () at test.c:2 2 return 42; (gdb) finish Run till exit from #0 fun () at test.c:2 main () at test.c:7 7 return 0; Value returned is $1 = 42 (gdb)
The finish
command can be abbreviated as fin
. Do NOT use the f
, which is abbreviation of frame
command!
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