Moving Visual Studio Breakpoints

I originally used Visual Studio C ++ Express, I switched to the final one, and im is 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 

This seems to be done at random places in the code. Am I ever mistaken? I never had a problem with the express version of how this happened.

+6
source share
1 answer

Debugging in release mode.

 if(x > y) { //this statement does nothing //z is a local variable that 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 

Typically, debuggers set hooks inside binary code. If binary code is not executed for int z = x/y , you cannot set a breakpoint there.

The following compilation in release mode is generated:

 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 verify this, you can make this simple change:

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

Source: https://habr.com/ru/post/909011/


All Articles