[quoted text, click to view] > In my code again initialize STACKFRAME64 using a CONTEXT I get calling
> GetThreadContext. In your code your are using the intrinsic
> _ReturnAddress and some asm to get esp and ebp.
>
> when I compare context.Esp/context.Ebp and esp/ebp (retrieved using asm)
> they are the same.
Have you compared them on XP SP2?
On my test SP2 system the EBP returned by GetThreadContext
is not the same, actually it is far below than the EBP of the function that called it.
(And therefore I assume that it is not safe to ask StackWalk64 to walk the stack
frames which can be overwritten by the code that calls StackWalk64 and analyzes
its output).
That is why I try to get the initialization data for STACKFRAME64 myself,
without relying on GetThreadContext.
What happens with your code if you set up STACKFRAME64 exactly as
in the example?
[quoted text, click to view] > But when I compare context.Eip with the value
> returned by _ReturnAddress they are different.
EIP returned by GetThreadContext should be somewhere inside GetThreadContext.
EIP returned by _ReturnAddress belongs to the CStackWalk::Walk().
[quoted text, click to view] > - why do you get eip/esp/ebp using intrinsic and asm instead of getting
> the CONTEXT ?
Because I think the context returned by GetThreadContext on SP2 is not safe to use
for stack walking, because the stack walking code writes over the same stack space
it attempts to analyze.
[quoted text, click to view] > - why do you use #pragma optimize ( "", off ) ?
>
To disable optimizations in CStackWalk::Walk(), and FPO optimizations in particular,
so that I can be sure that EBP register really stores the frame base pointer.
Oleg