在 VS 2005 中使用托管/非托管代码在 dll 中进行调试失败。为什么?
我想调试一段用C++编写的代码。 问题在于该 dll 是混合的 - 它同时包含 C++ 和 CLI(托管 C++)。 环境是VS 2005。
我的入口点是一个非常简单的可执行项目,用C++编写,只启动混合dll中的代码。
问题是:
如果我将两个项目的“调试类型”设置为“自动”,则不会命中我的断点。 (后来编辑:这是正常的,因为自动是基于可执行项目的内容)。
如果我将其设置为“混合”,则会命中断点,但非托管监视为空。 例如,我看不到 std::string 的值。 然而我可以看到像 int 和 bool 这样的基本类型。
I want to debug a piece of code written in C++. The problem is that the dll is mixed - it contains both C++ and CLI (managed C++). The environment is VS 2005.
My entry point is a very simple executable project, written in C++ that just starts the code in the mixed dll.
The problem is that:
if I let the "Debug type" as Auto for both projects, my breakpoints are not hit. (later edit: this is normal, since Auto is based on the contents of executable project).
if I set it to "mixed", the breakpoints are hit but the unmanaged watches are empty. For example, I cannot see the value of an std::string. I can however see basic types like int and bool.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我可以通过在项目属性(在“调试”选项卡上)中将“调试器类型”设置为“混合”,在 VS2005 中以混合模式进行调试。 有时,在良好的重新启动和干净的重建后,这些事情就会消失。
如果这不起作用,您可以尝试在应用程序开始运行后附加到该应用程序(调试|附加到进程)。 您可以通过按“附加到:”部分旁边中间的“选择”按钮来选择调试模式。
您是否拥有 Microsoft 的所有更新? 也许有人可以解决您的问题。
一般来说,混合模式调试似乎在 VS2008 中工作得更好。 如果可以的话我建议升级。 有一个免费版本,但我认为它在某种程度上受到限制。
I can debug in mixed mode in VS2005 by setting the Debugger Type to mixed in the Project Properties (on the Debugging tab). Sometimes these sort of things go away after a nice reboot and a clean rebuild.
If that doesn't work you try attaching to the application after it starts running (Debug | Attach to Process). You can pick the debugging mode by pressing the "Select" button in the middle next to the "Attach to:" section.
Do you have all of the updates from Microsoft? There might be one out there that solves your problem.
In general, mixed mode debugging seems to work much better in VS2008. I recommend upgrading if you can. There is a free version available but I think its limited in some way.
您确定启用了所有调试选项吗? 当我尝试在 C++ 选项的迷宫中导航时“忘记”一些内容时,我就看到过这种情况的发生。
You sure you enabled all the debugging options? I have seen this happen when 'forgetting' some when trying to navigate the maze of C++ options.
我面前没有 2005/2008 环境,但我似乎记得需要在项目设置中启用一个选项(我相信调试选项卡)才能进行非托管调试。 启用此功能后,您应该不会遇到任何问题。
I don't have my 2005/2008 environment in front of me, however I seem to recall there is an option that needs to be enabled in the project settings(I believe the debugging tab) in order to do unmanaged debugging. Once this is enabled, you shouldn't have any problems.
您需要告诉 Visual Studio 调试的不仅仅是托管代码。 转到工具| 选项,选择调试 | 一般的。 取消选中“仅启用我的代码(仅限托管)”旁边的框。
You need to tell Visual Studio to debug more than just your managed code. Go to Tools | Options, select Debugging | General. Uncheck the box next to, "Enable Just My Code (Managed-only)".
LanceSc 的建议确实很有帮助。
转到工具| 选项,选择调试 | 一般。
取消选中“仅启用我的代码(仅限托管)”旁边的框
这样就解决了VS2008中的问题。
LanceSc's advice really helps.
Go to Tools | Options, select Debugging | General.
Uncheck the box next to "Enable Just My Code (Managed-only)"
This solves the problem in VS2008.
另外,尝试将调试器设置为“混合”。 这将允许调试托管和非托管代码。
Also, try setting your debugger to Mixed. This will allow debugging of both managed and unmanaged code.