Visual Studio中断点移动

问题描述:

我最初使用Visual Studio的C++ Express中,我已经切换到最终和IM目前困惑,为什么调试器是移动我的断点,例如:Visual Studio中断点移动

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 

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

您正在以发行模式进行调试。

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;    
+0

我同意这是最likly原因,我会还要注意,在过去,由于线路终端差异(NL vs CR NL),我看到通过调试器和IDE报告的线路之间存在不一致(disconects)。我记得Borland Delphi产品中存在一个大问题,但我不认为这是是VS的问题。 – tletnes 2012-02-21 20:20:11

+0

@tletnes嗯有趣,我从来没有遇到过这个虽然在VS. – 2012-02-21 20:23:01

+0

对!我完全忽略了我处于发布模式。谢谢! – kbirk 2012-02-21 21:37:31