在调试器中的功能评估期间中断 [英] Breaking During Function Evaluation in the Debugger

查看:273
本文介绍了在调试器中的功能评估期间中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让这个工作: http://msdn.microsoft.com/en-us/library/ms171381%28v=vs.100%29.aspx

更多,如在此其他页面上所述 ,当使用立即窗口调用方法时,如果函数或子程序包含断点,Visual Studio将在适当的时候中断执行。

More specifically, as mentioned on this other page, when using the immediate window to call a method, "If the function or subroutine contains a breakpoint, Visual Studio will break execution at the appropriate point."

除了...它不,至少对我来说。您可以尝试使用这个虚拟c ++测试用例:

Except... it doesn't, at least for me. You can try it with this dummy c++ test case :

#include "Windows.h"

void dbgbreak()
{
    DebugBreak(); // set a second breakpoint here
}

int main ()
{
    int i = 0;
    i++; // set a first breakpoint here
    return i;
}

设置源和运行中提到的断点。当调试器在 停止时,从立即窗口调用 dbgbreak()

Set the breakpoints mentioned in the source and run. When the debugger stops at i++, call dbgbreak() from the immediate window.

不会再停止,即使有两个原因这样做(在方法调用的明确的第二个断点,加上事实,win32 API DebugBreak()应该触发一个断点)。

For me, the debugger does not stop again, even with two reasons to do so (an explicit second breakpoint inside the method called, plus the fact that the win32 API DebugBreak() should trigger a breakpoint).

这是预期的行为吗?这似乎与文档说的完全相反...我误解了什么?

Is this expected behavior ? That seems to be the exact opposite of what the documentation says... am I misunderstanding something ?

推荐答案

,只是不是你希望它的工作方式。将函数更改为:

Well, that actually works, just not the way you hope it works. Change the function to this:

void dbgbreak()
{
    OutputDebugString(L"Before\n");
    DebugBreak();
    OutputDebugString(L"After\n");
}

当我使用立即窗口时,我看到:

And when I use the Immediate window, I see this:

dbgbreak()
Before
The evaluation was aborted because an unhandled exception occurred.

这是相当准确的,DebugBreak()产生一个异常。调试器通常会拦截程序使其处于中断状态。问题是,它已经处于中断状态。缺少的功能是调试器不支持嵌套断点状态。因为Windows调试api不支持它。

Which is pretty accurate, DebugBreak() generates an exception. Which the debugger normally intercepts to put the program into a break state. Problem is, it is already in a break state. The feature that is missing is that the debugger doesn't support nested break states. For which it can be forgiven, that ought to be hard to implement since the Windows debugging api doesn't support it.

注意,你链接的MSDN页面讨论关于管理码。其中使用了非常不同的调试器。 CLR启动一个专用线程,调试器用它来评估监视表达式和立即命令,这是非常有帮助的。并支持Debugger.Break()语句。在本地代码中没有类似的东西,托管代码是工具制作者的喜悦。

Beware that the MSDN page you linked talks about managed code. Which uses a very different kind of debugger. It is greatly aided by the CLR starting a dedicated thread that the debugger uses to evaluate watch expressions and immediate commands. And supports Debugger.Break() statements. Nothing similar exists in native code, managed code is a tool-builder's delight.

这篇关于在调试器中的功能评估期间中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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