Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging native code when called from managed

Tags:

c++

c#

.net-4.0

I've written a C# application, where much of the work is done in a C++ back-end. Now I've been actively developing both sides, and the current iteration of the back end throws an access violation in a specific function. How can I go and debug this? VS won't break on exceptions or breakpoints in native code, nor show the call stack or locals of the native code, even though both projects are built in the same solution. I'd rather avoid having to go back and litter all my native code with logging statements.

like image 877
Puppy Avatar asked Dec 04 '10 16:12

Puppy


People also ask

How do I debug the native code?

For Visual Basic, select Debug in the left pane, select the Enable native code debugging check box, and then close the properties page to save the changes. Select Debug in the left pane, select the Enable native code debugging check box, and then close the properties page to save the changes.

What is managed debugging?

Managed debugging assistants (MDAs) are debugging aids that work with the common language runtime (CLR) to provide information on runtime state. The assistants generate informational messages about runtime events that you cannot otherwise trap.

How do I debug a specific thread?

Select Debug > Start Debugging, or press F5. The app starts in debug mode, and pauses at the breakpoint. While in break mode, open the Threads window by selecting Debug > Windows > Threads. You must be in a debugging session to open or see the Threads and other debugging windows.


2 Answers

VS will debug the native code, too, if you switch on mixed-mode debugging (and recompile your project).

See the Microsoft's explanation: http://msdn.microsoft.com/en-us/library/kbaht4dh.aspx

like image 74
Vlad Avatar answered Oct 23 '22 21:10

Vlad


From Visual Studio 2016

  1. Project > Right Click > Properties
  2. Debug > Enable native code debugging.

enter image description here

like image 4
Shaun Luttin Avatar answered Oct 23 '22 21:10

Shaun Luttin