从托管调用时调试本机代码

发布于 2024-10-06 08:38:57 字数 172 浏览 0 评论 0原文

我编写了一个 C# 应用程序,其中大部分工作是在 C++ 后端完成的。现在我一直在积极开发双方,后端的当前迭代在特定函数中引发了访问冲突。我该如何去调试这个? VS 不会因本机代码中的异常或断点而中断,也不会显示本机代码的调用堆栈或局部变量,即使两个项目都是在同一解决方案中构建的。我宁愿避免返回并用日志语句乱扔我的所有本机代码。

I've written a C# application, where much of the work is done in a C++ back-end. Now I've been actively developing both sides, and the current iteration of the back end throws an access violation in a specific function. How can I go and debug this? VS won't break on exceptions or breakpoints in native code, nor show the call stack or locals of the native code, even though both projects are built in the same solution. I'd rather avoid having to go back and litter all my native code with logging statements.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

长不大的小祸害 2024-10-13 08:38:57

如果您打开混合模式调试(并重新编译项目),VS 也会调试本机代码。

请参阅微软的解释: http://msdn.microsoft.com/en-us/库/kbaht4dh.aspx

VS will debug the native code, too, if you switch on mixed-mode debugging (and recompile your project).

See the Microsoft's explanation: http://msdn.microsoft.com/en-us/library/kbaht4dh.aspx

菩提树下叶撕阳。 2024-10-13 08:38:57

来自 Visual Studio 2016

  1. 项目>右键单击>属性
  2. 调试>启用本机代码调试。

输入图像描述这里

From Visual Studio 2016

  1. Project > Right Click > Properties
  2. Debug > Enable native code debugging.

enter image description here

二货你真萌 2024-10-13 08:38:57

使用 Visual Studio 您可以将调试器从本机 C++ 项目附加到正在运行的 C# 应用程序。

在附加调试器并运行 C# 应用程序之前

  1. 在 VS 中打开您的本机 C++ 项目。
  2. 确保您已配置为调试模式。然后重建你的原生
    C++ 代码。

  3. 在要中断的位置添加断点并开始单步执行
    代码。确保您已在代码中放置断点
    C# 应用程序调用的对象。

  4. 如果您的 C# 应用程序是您的解决方案的启动项目,
    在项目属性页的“调试”节点下,确保
    检查“启用本机代码调试”,然后重建整个
    解决方案。

    否则,您将需要重建 C# 应用程序并引用
    新编译的 DLL。运行应用程序并附加 VS 调试器
    将 C++ 项目移植到 C# 应用程序。
    为此,请转到“调试”选项卡 ->附加到进程 ->选择 C# 应用程序。

Using Visual Studio you can attach the debugger from your native C++ project to your running C# application.

Before attaching the debugger and running your C# application

  1. Open your native C++ project in VS.
  2. Make sure you are configured to Debug mode. Then rebuild your native
    C++ code.

  3. Add breakpoints where you want to break and begin stepping through
    the code. Make sure your have placed your breakpoints in code
    which the C# application calls into.

  4. If your C# application is the start up project of your solution,
    under the Debug node in your projects Properties Pages make sure to
    check the ‘Enable Native Code debugging’, then rebuild the entire
    solution.

    Otherwise you will need to rebuild the C# application referencing the
    newly compiled DLLs. Run the application and attach the VS debugger
    of the C++ project to the C# application.
    To do this go to the Debug Tab -> Attach to Process -> select the C# application.

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