How to obtain the native stacktrace from native exceptions caught in managed code

后端 未结 2 551
情书的邮戳
情书的邮戳 2021-01-18 17:54

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 ca

2条回答
  •  有刺的猬
    2021-01-18 18:45

    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.

    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.

提交回复
热议问题