Debugging unmanaged code while debugging managed code
Asked Answered
O

3

21

The .NET 3.5 application I am working on consists of bunch of different solutions. Some of these solutions consist of managed code(C#) and others have unmanaged code(C++). Methods written in C# communicate with the ones written in C++. I am trying to trace the dependencies between these various functions and I thought setting breakpoints on the solution consisting my C++ functions. One of the C# solutions have the startup project. I run this solution in debug mode with the expectation that the breakpoints in my unmanaged code will be hit but nothing really happens. Can somebody guide me through the process of debugging mixed applications such as these using the Visual Studio IDE?

Thanks

Obtrude answered 25/3, 2010 at 21:38 Comment(0)
L
27

By default a managed project will only start the debugger with managed debugging enabled. It doesn't consider that there are unmanaged projects in the same solution. In order to debug both you need to explicitly enable unmanaged code debugging.

  • Right Click on the project and select properties
  • Go to the Debug tab
  • Check "Enable Unmanaged code debugging"
Lorenzoloresz answered 25/3, 2010 at 21:41 Comment(5)
Thanks Jared. If my unmanaged code is in one solution and my manged code is in another Visual Studio solution, do I need to run the debugger from both my solutions in order to hit the breakpoints. I did what you suggested but I still cannot hit the breakpoints.Obtrude
You are compiling the debug version of the C++ classes?Deandeana
@sc_ray: If you're attaching to a process: in the Attach to Process box, click select and check both the "Managed" and "Native" boxes.Gannes
Minor addition...it appears that in VS2013 the text now says "Enable native code debugging"Fiche
@RaphaëlSaint-Pierre thanks for that reminder. That was the missing piece. We have a .NET 4.0 project so we selected "Managed (v4.0)" and "Native" and it worked fine.Hilariahilario
D
4
  1. Go to the Managed project property.
  2. Right click on it and go to the debug tab.
  3. There is a section called enable debugger under that section.
  4. Check the "Enable native code debugging" option

then you will be able to debug the native code. Good luck !!!

Please refer the below attached image highlighted with red rectangle.

enter image description here

Dunaway answered 23/1, 2014 at 9:34 Comment(0)
C
2

In Visual Studio 2019, the option is enabled as follows:

  • Right Click on the project and selecting properties
  • Go to the Debugging submenu under Configuration
  • From the Debugger Type drop down values select Mixed
Conceptacle answered 28/11, 2019 at 15:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.