Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unmanaged call stack in c# application

I am getting an access violation error in an unmanaged dll I am writing, but when I try to debug It in a c# application it will only get the last frame of the call stack in Visual Studio's debug window.

I have debug->exceptions->System.AccessViolationException set to break the debugger when it is thrown.

myunmanaged.dll!ViolatingFunc() Line 100 + 0xc bytes
- - - -
[external code] //myunmanaged.dll!function that I want to see
- - - -
somecsharp.exe!com.somewhere.Form1.CallFuncThatCallsViolator();

I was hoping to walk up the unmanaged stack to see where the data gets turned to garbeldegook. Is this possible?

Answered enter image description here

Enabling unmanaged debugging is step 1, but to get me all the way there I enabled microsoft symbols.

that made my stack trace look more like this:

myunmanaged.dll!ViolatingFunc() 
- - - -
myunmanaged.dll!SomeFunc2() 
- - - -
myunmanaged.dll!SomeFunc()
- - - -
[managed to unmanaged code transition]
- - - -
somecsharp.exe!com.somewhere.Form1.CallFuncThatCallsViolator();
like image 786
Tom Fobear Avatar asked Feb 21 '23 19:02

Tom Fobear


1 Answers

Yes it is. You need to debug your application in 'Mixed-mode'. Right click on the project, select the 'Debug' tab and check 'Enable unmanaged code debugging'. You will see managed and native frames.

mixed mode debugging

Edit: As ChrisO mentions not having MS symbols can make native debugging weird. Add the following to your symbols path for Windows symbols: http://msdl.microsoft.com/download/symbols

like image 147
linuxuser27 Avatar answered Feb 26 '23 04:02

linuxuser27