visual-studio 在调试托管代码的同时调试非托管代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2519603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:41:42  来源:igfitidea点击:

Debugging unmanaged code while debugging managed code

c#c++visual-studiovisual-studio-2008debugging

提问by sc_ray

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?

我正在处理的 .NET 3.5 应用程序由一堆不同的解决方案组成。其中一些解决方案包含托管代码 (C#),其他解决方案包含非托管代码 (C++)。用 C# 编写的方法与用 C++ 编写的方法通信。我试图追踪这些不同函数之间的依赖关系,我想在包含我的 C++ 函数的解决方案上设置断点。C# 解决方案之一具有启动项目。我在调试模式下运行这个解决方案,期望我的非托管代码中的断点会被命中,但实际上什么也没发生。有人可以指导我完成使用 Visual Studio IDE 调试混合应用程序的过程吗?

Thanks

谢谢

回答by JaredPar

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"
  • 右键单击项目并选择属性
  • 转到调试选项卡
  • 勾选“启用非托管代码调试”

回答by Jnana

  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
  1. 转到托管项目属性。
  2. 右键单击它并转到调试选项卡。
  3. 在该部分下有一个称为启用调试器的部分。
  4. 选中“启用本机代码调试”选项

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

在此处输入图片说明

回答by ssh

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

在 Visual Studio 2019 中,该选项启用如下:

  • Right Click on the project and selecting properties
  • Go to the Debugging submenu under Configuration
  • From the Debugger Type drop down values select Mixed
  • 右键单击项目并选择属性
  • 转到配置下的调试子菜单
  • 从调试器类型下拉值中选择混合