tags:

views:

509

answers:

6

If I break in line 3:

1  int foo()
2  {
3      return func();
4  }

is there a way to examine the return value of func()?

Thanks.

A: 

After line three the return value will be in EAX, so you can

print $eax

Hope this helps

Cipher
That's true only on i386/amd64.
David Schmitt
A: 

In C, the return value of a function is returned in register %EAX, so you can get the return value of func() if you set a breakpoint for immediately after func() returns and then call

print $eax

or

info registers

which gives you information about all of the registers, including %EAX.

In this case, if your break point is at line 3, you may need to use s to step through to after func() returns but before foo() does.

Marquis Wang
+2  A: 

Use the finish command.

David Schmitt
A: 

I answered a simular question here, info frame is a platform independent way todo this.

RandomNickName42
A: 

If you step into "func()", and then say "finish", gdb will return to foo and print the return value of func.

Michael Snyder
A: 

is there a way without "hacks" to do it? e.g. line in MS Visual Studio? $eax is architecture dependent, finish i might wont want to use? RandomNickName42 suggests 'info frame' but does not do that either.