Discussion:
Return Value for a function
(too old to reply)
Hua-Ying Ling
2006-04-13 21:27:02 UTC
Permalink
Hi,

How would I get the return value of a OS function if I don't have access to
the source. I have the symbols for the OS loaded. I am doing kernel level
debugging.

Thanks
Hua-Ying
Drew Bliss [MSFT]
2006-04-13 23:00:00 UTC
Permalink
It depends on what you mean by the return value. If you just want the raw
value look in the appropriate register when the routine returns. For
example, on x86 you would look at eax (or edx:eax for 64-bit quantities)
after the ret to see what the raw return value was. The debugger has
$retreg and $retreg64 pseudo-registers which abstract which specific
register so you can use them across all platforms. Note that certain
complex return values, like large by-value structure returns, may have more
complex conventions, such as implicitly being converted to by-reference
calls.

Finally, if you want the debugger to try and do some type-based formatting
you can use the .fnret command.

.fnret <funcaddr> [<retval>]

This command causes the debugger to look up the given function by address
and format the given return value (defaults to $retreg) according to the
type of the function return.
Post by Hua-Ying Ling
Hi,
How would I get the return value of a OS function if I don't have access to
the source. I have the symbols for the OS loaded. I am doing kernel level
debugging.
Thanks
Hua-Ying
Hua-Ying Ling
2006-04-14 15:26:01 UTC
Permalink
I'm using the following command to display the return value:

bp functionName
gu
r $retreg

.fnret doesn't seem to work in this context, it fails with Unknown or
unsupported retun type in .fnret ZwOpenFile

Is this the correct way to get the return value?

Thanks
Hua-Ying
Drew Bliss [MSFT]
2006-04-14 17:00:00 UTC
Permalink
r $retreg will work fine.

You need full symbols for .fnret to work as it has to have per-function type
info. Microsoft OS public symbols would not have such info, but your own
code would.
Post by Hua-Ying Ling
bp functionName
gu
r $retreg
.fnret doesn't seem to work in this context, it fails with Unknown or
unsupported retun type in .fnret ZwOpenFile
Is this the correct way to get the return value?
Thanks
Hua-Ying
Continue reading on narkive:
Loading...