如何在混合(C#/C++)调试中设置数据断点?

发布于 2024-07-07 06:30:05 字数 94 浏览 7 评论 0原文

我用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

七色彩虹 2024-07-14 06:30:05

因此,要执行此操作,我必须:

  • 将非托管 dll 设置为启动项目
  • 将托管程序设置为启动命令
  • 将调试模式设置为 Native
  • “中断执行”或命中断点,以便您处于“调试”状态

yech

So to do this I had to:

  • set the unmanaged dll as the startup project
  • set the managed program as the startup command
  • set debug mode as Native
  • "break execution" or hit a breakpoint so that you are in the "debugging" state

yech

等你爱我 2024-07-14 06:30:05

要在混合模式进程的本机部分设置数据断点,请参阅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.

春花秋月 2024-07-14 06:30:05

建议的解决方案并不总是有效。 即使在本机模式下调试时,程序在本机代码段中被破坏,当尝试设置“新数据断点”时,我也会收到一个弹出窗口“无法设置断点。数据断点不受支持公共语言运行时”

另一种方法是直接从代码添加数据断点。 请参阅此处文章。

这在混合模式下效果很好,它只需要激活本机调试模式(如上所述)

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)

浮光之海 2024-07-14 06:30:05

一个非常有用且适用于任何地方的技巧是在特殊条件下从代码中调用断点:

If (Condition)
    System.Diagnostics.Debugger.Break()

A very useful trick which works everywhere is to call breakpoints from code in special conditions:

If (Condition)
    System.Diagnostics.Debugger.Break()
甜心 2024-07-14 06:30:05

另一种方法是附加到进程。

无需调试器即可正常构建并运行您的软件。

然后在 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.

enter image description here

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文