您如何使用 dbghelp!StackWalk64 遍历混合模式(托管+本机)堆栈? [英] How do you walk a mixed-mode (managed+native) stack with dbghelp!StackWalk64?

查看:33
本文介绍了您如何使用 dbghelp!StackWalk64 遍历混合模式(托管+本机)堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 StackWalk64 在 x64 进程上遍历包含托管帧和本机帧的调用堆栈.一切正常,直到第一个或第二个托管框架,之后 StackWalk64 无法找出框架的返回地址并失败.

I'm trying to walk a callstack that contains both managed and native frames on a x64 process using StackWalk64. Everything works fine until the first or second managed frame, after which StackWalk64 can't figure out the return address of the frame and fails.

我将 SymFunctionTableAccess64 用于函数表访问回调,并且符号处理程序已使用 SymInitialize() 进行初始化.是否需要在 dbghelp 中执行一些魔术才能使其正确遍历托管帧?

I'm using SymFunctionTableAccess64 for the function table access callback and the symbol handler has been initialized with SymInitialize(). Is there some magic I need to do in dbghelp to get it to walk over managed frames correctly?

失败的调用堆栈示例:

UnmanagedFrame1
UnmanagedFrame2
UnmanagedFrame3
ManagedFrame1 <----- (StackWalk64 在此帧后失败)
ManagedFrame2
UnmanagedFrame4
UnmanagedFrame5
ntdll!RtlUserThreadStart

注意:这个问题不是关于如何将托管帧解析为符号/方法名称/等,我只想遍历整个堆栈而不考虑符号解析/等.

Note: this question IS NOT about how to resolve the managed frames to symbols/method names/etc, I simply want to walk the full stack with no regard to symbol resolution/etc.

此外,IDebugControl4::GetContextStackTrace 工作正常,但 DbgEng 使用自定义函数表回调,而不是简单地委托给 SymFunctionTableAccess64.我怀疑问题在于 CLR 使用 RtlInstallFunctionTableCallback 来安装回调函数表(指向 mscordacwks),而 SymFunctionTableAccess64 不够聪明,无法遵循该表.

Also, IDebugControl4::GetContextStackTrace works correctly, but DbgEng uses a custom function table callback, and doesn't simply delegate to SymFunctionTableAccess64. I suspect the issue is that the CLR uses RtlInstallFunctionTableCallback to install a callback function table (which points to mscordacwks), and SymFunctionTableAccess64 isn't smart enough to follow that.

我花了一些时间尝试编写一个自定义函数表访问回调来遍历函数表链并在 mscordacwks 中调用该回调,但它变得非常粗略,无论如何都没有真正起作用.

I spent some time trying to write a custom function table access callback to traverse the function table chain and call the callback in mscordacwks, but it got pretty sketchy and didn't really work anyways.

推荐答案

SOS 调试器扩展有帮助吗?它提供了从 windbgVisual Studio 完全按照您希望的方式遍历堆栈的能力.

Does the SOS debugger extension help at all? It provides the ability, from windbg and Visual Studio to walk the stack exactly the way you wish.

或者 .NET Framework 2.0 中的 Profiler Stack Walking:基础和超越 可能有点用.

这篇关于您如何使用 dbghelp!StackWalk64 遍历混合模式(托管+本机)堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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