如何从托管代码项目内部调试本机代码项目? C++/C#
如何从托管代码项目内部调试本机代码项目?我正在使用C#调用C++代码,需要调试C++代码。否则,我必须退出项目,打开 C++ 项目,创建一个测试器,然后调试代码。这太可怕了。
How do I debug a native code project from inside a managed code project? I am using C# to call C++ code and need to debug the C++ code. Otherwise, I must exit out of the project, open the C++ project, create a tester and then debug the code. This is horrible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将您的 C++ 项目添加到包含 C# 代码的解决方案
中 在 C# 项目属性页面的“调试”选项卡下,
选中“启用非托管代码调试”
如果这不起作用,您还需要从“调试”或“工具”打开“选项”对话框菜单(在 VS2017 中)并转到“调试”->“常规”。 选项
选中“抑制模块加载时的 JIT 优化(仅限托管)”
。然后,您将能够调试 C++/CLI 和 C++ 代码。 (最后的提示来自 金·托戈·安徒生。)
Add your c++ project to the solution containing your C# code
In the C# project properties pages, under the debug tab
Check "Enable unmanaged code debugging"
If that doesn't work you also need to open the Options dialog from either the Debug or the Tools menu (in VS2017) and go to Debugging->General. Check the option
"Suppress JIT optimization on module load (Managed only)."
You will then be able to debug into your C++/CLI and C++ code. (This final tip comes from Kim Togo Andersen.)
在 Visual Studio 的调试选项中,您必须指定正确的调试器类型。
打开项目的属性对话框窗口,然后在“配置属性”下选择“调试”。对于调试器类型选项,选择适用的属性:
这可以是自动或混合。我更喜欢混合,因为它明确指出您需要托管调试和本机调试。
顺便说一句,您只能选择本机,但无法在托管代码中设置断点。我不确定这对你来说是否是一个问题。
如果您选择仅托管,则显然不会在本机代码中遇到任何断点。
In the debugging options for visual studio you HAVE to specify the correct debugger type.
Open up the property dialog window for the project, and under the Configuration Properties select Debugging. For the Debugger Type option, select the property that applies:
This can be auto, or mixed. I prefer mixed as it is explicitly stating you want both managed and native debugging.
As a side note, you can pick native only, but you won't be able to set a breakpoint in managed code. I'm not sure if this is an issue for you or not.
If you pick managed only, you obviously won't hit any breakpoints in native code.