使用用/ clr编译的C ++ - CLI库调试C可执行文件 [英] Debugging a C executable with a C++-CLI Library compiled with /clr

查看:549
本文介绍了使用用/ clr编译的C ++ - CLI库调试C可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2010调试一个大部分用C编写的应用程序。通常,我可以附加调试器很好,但是当我链接到使用C ++ / CLI编写的库时,我遇到了一些问题。

I am using Visual Studio 2010 to debug an application mostly written in C. Normally, I can attach the debugger just fine, but I am running in to some problems when I link in a library written in C++ / CLI.

如果我使用 / clr 标志来编译库(我最终必须为但未写的库),那么我失去所有的能力来调试整个C应用程序,甚至是与库调用无关的部分。我得到一个空的圆圈与黄色的三角形和感叹号,一个红色的断点圆应该是。悬停在它上面只给我一个工具提示,断点将不会被击中,没有可执行代码与此行相关联可能的原因包括:条件编译或编译器优化。

If I compile the library with the /clr flag (which I will eventually have to do for this as of yet unwritten library) then I lose all ability to debug the entire C application, even the parts that have nothing to do with the library calls. I get the empty circle with the yellow triangle and exclamation mark where a red break point circle ought to be. Hovering over it gives me only a tool tip that says "The breakpoint will not currently be hit. No executable code is associated with this line. Possible causes include: conditional compilation or compiler optimizations."

然后,如果我链接到与 / clr 标志没有编译的完全相同的库,我再次能够调试我的应用程序。

Then if I link with the exact same library compiled without the /clr flag, I am again able to debug my application.

我知道visual studio不太可能能够调试用C ++ / CLI编写的库,这是可以的。我只想保持调试其余应用程序的能力,并至少看到我调用外部库的结果。

I understand that visual studio will not likely be able to debug the library written in C++ / CLI, and that is OK. I just want to keep the ability to debug the rest of the application and at least see the results of my calls to the external library.

另一个复杂的因素是这个项目不是由视觉工作室。它是使用外部make系统编译的,使用 cl ,所以我可以自定义任何需要发布给编译器的命令。

Another complicating factor is that this project is not being built by visual studio. It is compiled using an external make system that uses cl, so I can customize any commands that need to be issued to the compiler that way.

有人知道为什么我不能调试库的方式我想要的?

Does anyone know why I can't currently debug the libraries the way I want to? Any advice for how I can?

推荐答案

当您附加时,必须选择 。注意对话框中的附加到标签。按选择按钮并勾选Native以获得调试本地代码的支持。该DLL还需要在您的任何断点可以命中之前加载。如果不确定是否这样做,那么在调试> Windows>模块调试器窗口中查看加载的DLL。

You have to select the kind of debugger when you attach. Note the "Attach to" label in the dialog. Press the Select button and tick "Native" to get support for debugging native code. The DLL also needs to be loaded before any of your breakpoints can hit. If you are not sure whether or not that was done then look in the Debug > Windows > Modules debugger window to see loaded DLLs. The breakpoint indicator turns from hollow to solid red as soon as the debugger saw the DLL load and armed the breakpoint.

调试器看到DLL加载并设置了断点后,断点指示器从空白变为纯红色。 管理和本机复选框。并在任一种代码中设置断点。唯一不支持的是单步执行从托管到本机代码和回来。

Debugging C++/CLI is otherwise supported, you can tick both the "Managed" and "Native" checkboxes. And set breakpoints in either kind of code. The only thing not supported is single-stepping from managed to native code and back. A mode-switch is required to activate the correct debugging engine, that requires code to hit a breakpoint.

并且考虑在你的本地项目中的Debug选项,你可以指定一个模式切换来启动正确的调试引擎, EXE开始。所以你可以简单地按F5开始调试和跳过附加麻烦。

And consider the Debug options in your native project, you can specify an EXE to start. So that you can simply press F5 to start debugging and skip the attach hassle.

这篇关于使用用/ clr编译的C ++ - CLI库调试C可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆