Visual Studio断点被移动
我最初使用Visual Studio C ++ 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
或
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.
您正在发布模式下调试。
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
通常调试器在二进制代码中设置钩子。如果没有为 int z = x / y
执行任何二进制代码,则无法在此处设置断点。
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;