StackWalker 代码中的疑问 [英] Doubt in StackWalker code

查看:25
本文介绍了StackWalker 代码中的疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是项目页面http://www.codeproject.com/KB/threads/StackWalker.aspx

[STACKFRAME64][1] s;

//s contains the current stack frame filled by calling [StackWalk64][2] WinAPI

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

我的问题是什么时候才能满足这个条件?s.AddrPC.Offset, s.AddrReturn.Offset 包含哪些地址?栈上最后一帧的返回地址是否为0?

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?

推荐答案

希望永远不会,但这是一个基本的健全性检查,以防堆栈帧被踩踏.当您尝试在由诸如 AccessViolation 之类的令人讨厌的硬件异常触发的异常处理程序中遍历堆栈时,这并非不可能.如果没有那个检查,代码将进入无限循环,不断地找到相同的堆栈帧.

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 是调用指令的地址,AddrReturn 是返回地址,上一条调用指令的地址(+5).不确定堆栈 0"可能意味着什么.

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.

这篇关于StackWalker 代码中的疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆