Visual Studio 断点被移动

发布于 2025-01-07 18:36:33 字数 501 浏览 2 评论 0原文

我最初使用 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

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

I originally used Visual Studio C++ Express, i've switched to ultimate and im currently confused as to why the debugger is moving my breakpoints, for example:

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

or

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

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

It seems to do this at random locations in the code. Is there sometime i'm doing wrong here? I've never had an issue with the express version like this happening.

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

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

发布评论

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

评论(1

我是男神闪亮亮 2025-01-14 18:36:33

您正在发布模式下进行调试。

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 执行二进制代码,则无法在那里设置断点。

以下是通过在发布模式下编译生成的:

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;             

You are debugging in release mode.

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

Usually debuggers set hooks inside binary code. If no binary code is executed for int z = x/y, you can't set a breakpoint there.

The following is generated by compiling this in release mode:

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)]

To test this, you can perform this simple change:

if(x > y) {
    int z = x/y;
    std::cout << z << endl; // <-- set breakpoint here, this should work
}
int h = x+y;             
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文