How do I debug a native code project from inside a managed code project? C++/C#

倾然丶 夕夏残阳落幕 提交于 2020-01-01 05:36:15

问题


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.


回答1:


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.)




回答2:


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.



来源:https://stackoverflow.com/questions/6738006/how-do-i-debug-a-native-code-project-from-inside-a-managed-code-project-c-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!