Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

debugging in mixed mode with native C++, managed c++ cli, and c# solution

I have a multithreaded project im working on and the startup project is set to a c# project that runs my UI. Then there is a whole series of underlying c++ native projects which are connected to the C# by managed C++/CLI projects. I've enabled in the c# start up project 'Enable Unmanaged debug' and when I attempt to debug the native code, I am able to hit break points I set. However, it hangs after I try to run it again and try to hit a break point again. For example, if I have a loop I try to hit inside it in each iteration, after the second iteration the program hangs and I have to force quit. Im working in Visual Studio 2010. Debugging beginning to prove not too useful at this rate, is there any way to preclude this problem?

like image 367
jamie Avatar asked May 10 '11 19:05

jamie


People also ask

How do I Debug a mixed code in Visual Studio?

Select the C++ project in Solution Explorer and click the Properties icon, press Alt+Enter, or right-click and choose Properties. In the <Project> Property Pages dialog box, expand Configuration Properties, and then select Debugging. Set Debugger Type to Mixed or Auto. Select OK.

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 enable debugging in Visual Studio?

In the Visual Studio toolbar, make sure the configuration is set to Debug. To start debugging, select the profile name in the toolbar, such as <project profile name>, IIS Express, or <IIS profile name> in the toolbar, select Start Debugging from the Debug menu, or press F5.


2 Answers

When I want to debug native code as well as C++/CLI, I do following:

  1. In C# application, check Allow unsafe code in Build tab and Enable unmanaged code debugging in Debug tab of project properties.
  2. For C++/CLI dll project, In Debugging tab of properties, set Debugger Type to Mixed
like image 176
Tae-Sung Shin Avatar answered Oct 10 '22 10:10

Tae-Sung Shin


We also had problems debugging complex mixed code applications and found out that the Visual Studio is not that reliable in these situations. My suggestions would be to:

  • If you're trying to debug a piece of native code try to use a native project as the debugger start-up application. Under the project settings, "Debugging" tab set the "Debugger Type" to "Mixed", for us this helped sometimes (the native project can be a DLL for example, simply set your main Exe as debugging target in the project settings);

  • Use WinDbg, with it you can debug both managed/unmanaged mixed code applications much more reliably;

like image 33
floyd73 Avatar answered Oct 10 '22 11:10

floyd73