In C, if you have a function that returns “always” the same result you can do:
(gdb) p foo()
But if this function always returns a random result, how to print THAT value without use a variable. Other detail, if you don’t have debug information of the function, it’s from a stripped lib.
(gdb) p myRandom() can’t be used, it will result in something different than the value used by application.
You may ask: “Why would you use a random function and don’t use its results”, lets say that the return is just an extra thing of what that func does.
Presumably you want to examine the value that was returned to the application in the particular place where the application called
myRandom().You need to set a breakpoint on the instruction that immediately follows the
CALL, then examine the register in which the value is returned. For example, oni*86, the value is returned ineaxregister, so you’ll doprint $eax.Alternatively, set a breakpoint on
myRandom(), then dofinishcommand (you don’t need debug info to do that), then examine the return register.