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

后端 未结 2 539
情书的邮戳
情书的邮戳 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.

    0 讨论(0)
  • 2021-01-18 18:48

    Obtaining a native stack trace is quite difficult. By the time it passes through the .NET/native translation layer, the native stack trace has already been lost.

    So, you need to capture it while still in native code, and this is also quite difficult. Take a look at John Robbins' work for proper native stack tracing; the latest publicly-available version of his SUPERASSERT that I could find is from MSJ, Feb 1999.

    0 讨论(0)
提交回复
热议问题