Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 355
aaa Avatar asked Oct 26 '22 14:10

aaa


1 Answers

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.

like image 51
Stephen Cleary Avatar answered Nov 14 '22 13:11

Stephen Cleary