I was trying to walk through the call stack frames and extract some information from them. I am able to extract the file names, line numbers, and function names by using StackWalk64
, SymGetSymFromAddr64
, and SymGetLineFromAddr64
APIs from WinDBG.
However, the DWORD64 Params[4]
in STACKFRAME64
, which is a return value from StackWalk64
, only supports reading back four 64 bits function parameters from a frame. Even worse, on 32-bit system, only the lower 32 bits of Params[4]
are used, so a single parameter with more than 32 bits needs two or more elements.
typedef struct _tagSTACKFRAME64 {
ADDRESS64 AddrPC;
ADDRESS64 AddrReturn;
ADDRESS64 AddrFrame;
ADDRESS64 AddrStack;
ADDRESS64 AddrBStore;
PVOID FuncTableEntry;
DWORD64 Params[4];
BOOL Far;
BOOL Virtual;
DWORD64 Reserved[3];
KDHELP64 KdHelp;
} STACKFRAME64, *LPSTACKFRAME64;
I couldn't find any API to read ALL the parameters from a stack frame without limitation.
I was thinking to use ebp
/rbp
to extract the values from the stack (x86/x64) and the registers (x64). But still, only the "possible" values of the parameters can be obtained if I do this.
Is there any API I could use to get the accurate values? It would be even better if I can get the type and name of the parameters.
SymGetSymFromAddr64
where you'd give it a stackframe and a parameter index, instead of just a pointer. – DehypnotizeSymGetSymFromAddr64
gives you the symbol name of the function itself, which is a mangled C++ name. If you run that through a demangler, you can derive the parameter types, though knowing the type alone probably isn't enough to interpret theParams
member. But I think that's as close as you're going to get. – DehypnotizeParams
is correct, as that's exactly what's happening under-the-hood, and it has no way to know to combine them. – DehypnotizeIMAGEHLP_STACK_FRAME
(either by hand from other structures or by some api that i could not find), then you can useSymSetContext
andSymEnumSymbols
to find all the (visible if not optimized) function arguments. that will hive you a pointer toSYMBOL_INFO
structure that you can use to get all the information you want. – Epperson