none
SEHException - no unmanaged stack trace? RRS feed

  • Question

  • I have a native app (Intel Fortran) that's compiled with flags to abort on IEEE exceptions.  Unfortunately, when I call it via Interop, this gets conveniently ignored and I end up with NaN's and other undesirable things in memory.  Recently the folks who write the Intel Fortran compiler came up with a way to set the "abort on IEEE exceptions" flag from within any subroutine, such as the exported subroutine.  So far, so good.

    Except, when my managed code catches one of the unmanaged exceptions, it only gives me a "SEHException" and it only has a stack trace until the point where I P/Invoke.  I don't get a unmanaged stack trace.  If it makes a difference, I load the unmanaged dll via LoadLibraryA.

    So how can I get the unmanaged stack trace?  I know it's possible because before I got this managed SEHException, I would get a MessageBox that contains the unmanaged stack trace!
    Friday, July 31, 2009 4:47 AM

Answers

  • That's not possible.  Unlike managed code, walking unmanaged stack frames accurately requires a debugger with access to debugging symbols (.pdb).  Not just to get the method names but also to identify the frames in the first place.  The "omit frame pointer" optimization is a nasty problem.

    Be careful monkeying with the FPU control word, managed code explicitly depends on the FPU exceptions being masked.

    Hans Passant.
    Friday, July 31, 2009 10:45 AM
    Moderator

All replies

  • That's not possible.  Unlike managed code, walking unmanaged stack frames accurately requires a debugger with access to debugging symbols (.pdb).  Not just to get the method names but also to identify the frames in the first place.  The "omit frame pointer" optimization is a nasty problem.

    Be careful monkeying with the FPU control word, managed code explicitly depends on the FPU exceptions being masked.

    Hans Passant.
    Friday, July 31, 2009 10:45 AM
    Moderator
  • If it's not possible, then how am I getting a message box with the unmanaged stack trace?  I'm guessing the Intel Fortran Compiler inserts some SEH voodoo to pop up the message box.  Or maybe it's something at the Kernel/Ntdll level.  (It has to be, I have plenty of try/catch blocks in my managed code).  I do not omit frame pointers, and I am able to get the unmanaged stack trace from either the console version (strictly unmanaged) of the Fortran app, or if something extra nasty happens then I get the stack trace inside the message box.  There's gotta be a way to get the unmanaged stack to follow through into the managed code...
    Friday, July 31, 2009 11:22 AM
  • Are you sure that the stack traces you get from Fortran console application are not using debugging symbols (PDBs)? Or maybe Fortran does some magic - ask them in that case.
    If you have PDBs around, then you can use StackWalk64 Windows API.

    Also check out this link: http://stackoverflow.com/questions/564177/implementing-a-stack-trace-on-windows/564347
    Friday, July 31, 2009 12:17 PM
    Moderator