开发者

Doubt in StackWalker code

开发者 https://www.devze.com 2023-02-02 07:06 出处:网络
Here is the project page http://www.codeproject.com/KB/threads/StackWalker.aspx [STACKFRAME64][1] s; //s contains the current stack frame filled by calling [St开发者_StackOverflow中文版ackWalk64][2]

Here is the project page http://www.codeproject.com/KB/threads/StackWalker.aspx

[STACKFRAME64][1] s;

//s contains the current stack frame filled by calling [St开发者_StackOverflow中文版ackWalk64][2] WinAPI

if (s.AddrPC.Offset == s.AddrReturn.Offset)
{
  printf("StackWalk64-Endless-Callstack!");
}

My question is when will this condition be satisfied? What addresses do s.AddrPC.Offset, s.AddrReturn.Offset contain? Is the return address in the last frame on stack = 0?


Hopefully never, but it is a basic sanity check in case the stack frame got stomped. Which isn't unlikely when you try to walk the stack in an exception handler triggered by a nasty hardware exception like AccessViolation. Without that check the code would enter an endless loop, constantly finding the same stack frame back.

AddrPC is the address of the call instruction, AddrReturn is the return address, the address of the previous call instruction (+5). Not sure what "stack 0" might mean.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号