如何在混合(C#/C++)调试中设置数据断点?
我用 C# 启动程序,然后调用一些非托管 C++。
当我在非托管 C++ 中中断一行时,“新数据断点”菜单项呈灰色。
有没有办法解决?
I launch my program in C#, which then calls some unmanaged C++.
When I break on a line in the unmanaged C++, the 'New Data Breakpoint' menu item is grayed out.
Is there anyway around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
因此,要执行此操作,我必须:
yech
So to do this I had to:
yech
要在混合模式进程的本机部分设置数据断点,请参阅jyoung 发布的答案。
当运行纯本机代码以外的任何内容时,Visual Studio 会禁用数据断点。 请参阅此 VS 项目经理发帖部分解释原因。
To set a data breakpoint in the native portion of a mixed mode process, see the answer posted by jyoung.
Visual Studio disables data breakpoints when running anything but pure, native code. See this post for a partial explanation why from a VS Program Manager.
建议的解决方案并不总是有效。 即使在本机模式下调试时,程序在本机代码段中被破坏,当尝试设置“新数据断点”时,我也会收到一个弹出窗口“无法设置断点。数据断点不受支持公共语言运行时”
另一种方法是直接从代码添加数据断点。 请参阅此处文章。
这在混合模式下效果很好,它只需要激活本机调试模式(如上所述)
The suggested solution doesn't work all the time. Even when debugging in Native mode, with the program broken in Native piece of code, when trying to set a 'New Data Breakpoint' I get a popup "The breakpoint cannot be set. Data breakpoints are not supported in the Common Language Runtime"
The alternative is to add data breakpoints from code directly. See the article here.
This works well in mixed-mode, it only requires Native debugging mode to be active (as suggested above)
一个非常有用且适用于任何地方的技巧是在特殊条件下从代码中调用断点:
A very useful trick which works everywhere is to call breakpoints from code in special conditions:
另一种方法是附加到进程。
无需调试器即可正常构建并运行您的软件。
然后在 Visual Studio 中,顶部菜单中的“调试/附加到进程”,找到该进程,在列表中选择它。 然后,在“附加到”面板的右侧,单击“选择...”按钮,单击“调试这些代码类型”单选按钮,取消选中除本机之外的所有内容,单击“确定”,单击“附加”。
然后使用 Debug / Break All 命令中断执行,或者在应用程序的 C++ 部分中的某个位置命中正常断点。 然后您将能够使用数据断点。
Another way is attaching to the process.
Build and run your software normally without debugger.
Then in Visual Studio, “Debug / Attach to Process” in the top menu, find the process, select it in the list. Then, to the right of “Attach to” panel, click “Select…” button, click the “Debug these code types” radio button, uncheck everything except Native, click OK, click Attach.
Then either break execution with Debug / Break All command, or hit a normal breakpoint somewhere in C++ parts of the app. You’ll then be able to use data breakpoints.