如何获得陷入托管代码异常本土原生堆栈跟踪 [英] How to obtain the native stacktrace from native exceptions caught in managed code

查看:153
本文介绍了如何获得陷入托管代码异常本土原生堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些管理,调用一些本地DLL(我有适当的符号文件)。结果
内的方法有时,本地方法抛出,我赶上我的托管代码异常代码。然而,当我从捕获的异常打印堆栈跟踪,我只看到托管代码(最后一帧是调用原生代码..但它没有看到本机代码中的stacktrack)。

I have some managed code that calls to a method inside some native DLL(i have the appropriate symbol files).
Sometimes, that native method throws an exception which I catch in my managed code. However, when i print the stacktrace from my caught exception, I see only managed code (the last frame is the call to the native code .. but it don't see the stacktrack within the native code).

我怎样才能获得本地调用堆栈呢?结果
*当我调试的代码,我是能够进入本地代码,并看到实际工作调用堆栈。

How can I obtain the native callstack as well?
*When i'm debugging the code, i am able to step into the native code, and see the actuall call stack.

推荐答案

这是不是当你捕捉异常显示本地调用堆栈一样光滑但如果你想寻找一个用户的计算机上的特定问题,用户是相当精明的,你可以让他们的WinDbg下运行你的应用程序。当本机抛出异常,并且调用堆栈可以看成这将打破。

This isn't as slick as displaying the native call stack when you catch the exception, but if you are trying to track down a specific problem on a user's computer and the user is reasonably savvy you can have them run your app under WinDbg. It will break when the native exception is thrown and the call stack can be viewed.

另一种可能是使用stackwalker。它是免费的,可以在这里找到:
http://www.codeproject.com/ KB /线程/ StackWalker.aspx
如果你知道顶级本地通话,你可以用与一_ 尝试/ 的_catch并使用stackwalker堆栈转储到日志文件。想必你也可以捕获该异常,使用stackwalker获得调用堆栈,调用堆栈添加到例外(字符串),然后重新抛出异常到你的.NET代码。然后,.NET代码可以得到调用堆栈出你的异常。

Another possibility is to use stackwalker. It's free and is available here: http://www.codeproject.com/KB/threads/StackWalker.aspx If you know the top-level native call, you can wrap that with a _try/_catch and use stackwalker to dump the stack to a log file. Presumably you could also catch the exception, get the call stack using stackwalker, add the callstack to the exception (as a string), and then rethrow the exception to your .NET code. The .NET code could then get the callstack out of your exception.

这篇关于如何获得陷入托管代码异常本土原生堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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