Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio breakpoints being moved

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.

like image 588
kbirk Avatar asked Feb 21 '12 20:02

kbirk


People also ask

How do I keep breakpoints in Visual Studio?

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

Why are my breakpoints not working?

If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.

Where are Visual Studio breakpoints stored?

They are saved in the <solutionname>. suo file. SUO stands for Solution User Options, and should not be added to source control.


1 Answers

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;             
like image 181
Luchian Grigore Avatar answered Oct 01 '22 08:10

Luchian Grigore