【问题标题】:Visual Studio breakpoints being moved正在移动的 Visual Studio 断点
【发布时间】:2023-03-17 21:24:01
【问题描述】:

我最初使用 Visual Studio C++ Express,我已切换到 Ultimate,但我目前对调试器移动断点的原因感到困惑,例如:

if(x > y) {
    int z = x/y;         < --- breakpoint set here
}
int h = x+y;             < --- breakpoint is moved here during run time

random line of code      < --- breakpoint set here
random line of code

return someValue;        < --- breakpoint is moved here during run time

它似乎在代码中的随机位置执行此操作。有时我在这里做错了吗?我从来没有遇到过这样的快速版本问题。

【问题讨论】:

    标签: c++ visual-studio debugging visual-c++ breakpoints


    【解决方案1】:

    您正在发布模式下调试。

    if(x > y) {
        //this statement does nothing
        //z is a local variable that's never used
        //no executable code is generated for this line
        int z = x/y;         < --- breakpoint set here
    }
    //the breakpoint is set on the next executable line
    //which happens to be this one
    int h = x+y;             < --- breakpoint is moved here during run time
    

    通常调试器会在二进制代码中设置挂钩。如果int z = x/y没有执行二进制代码,则不能在此处设置断点。

    以下是在release模式下编译生成的:

    if(x > y) 
    {
        int z = x/y;//         < --- breakpoint set here
    }
    int h = x+y;
    cout << h;
    003B1000  mov         ecx,dword ptr [__imp_std::cout (3B203Ch)] 
    003B1006  push        7    
    003B1008  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (3B2038h)]
    

    要对此进行测试,您可以执行以下简单更改:

    if(x > y) {
        int z = x/y;
        std::cout << z << endl; // <-- set breakpoint here, this should work
    }
    int h = x+y;             
    

    【讨论】:

    • 我同意这是最可能的原因,我还要指出,过去我曾看到由于线路终止差异(NL 与 CR NL)通过调试器和 IDE 报告的线路之间存在不一致我记得这个 bing 在 Borland Delphi 产品中是一个大问题,但我认为这不是 VS 的问题。
    • @tletnes 嗯,有趣,我在 VS 中从未遇到过。
    • 正确!我完全忽略了我处于发布模式。谢谢!
    • 确实如此。如果断点被禁用或向前移动,VC6 会显示一个消息框。 VC 版本均不显示消息框,但禁用/移动 BP。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多