Thread: vs2005 debugger stepover erratic

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    10

    vs2005 debugger stepover erratic

    The debugger step over command jumps up and down randomly in the if-else block in the code below. It skips a line, goes back to the top, back down, up again?? I fixed the problem by changing the two return statements in the conditional (if-else) block to a single return statement after it. I would like to know why the erratic behaviour was happening though, for future reference, any help much appreciated.

    Code:
    pair<Node, bool> NodeStore::GetNode(const int &comparisonNodeID) const{
    	pair<Node, bool> rtnNodePair;
    	Node comparisonNode;
    	comparisonNode.SetNodeID(comparisonNodeID); 
    	
    	vector<Node>::const_iterator begin = iteTable.begin();
    	vector<Node>::const_iterator end = iteTable.end();
    	vector<Node>::const_iterator foundPos;
    
    	foundPos = find(begin, end, comparisonNode);
    
    	if (foundPos == end){ // debug mode moves erratically through this
    		rtnNodePair.second = false;
    		return rtnNodePair;
    	}
    	else{
    		rtnNodePair.first = *foundPos;
    		rtnNodePair.second = true;
    		return rtnNodePair;
    	}
    	
    }
    cheers

    sean

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Are you trying to debug code which is also optimised?

    The compiler will rearrange code in order to optimise it, and that can lead to all sorts of odd effects which you describe.

    Despite that, does it actually produce the right answer?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Also note that when returning from functions the debugger will move to the bottom of the function (it will go from the return statement to the function's closing brace). You can sometimes enter destructors of objects allocated locally in the function by stepping into when the location is the function's closing brace.

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    Hi thanks for the responses.

    Salem - I think you may well be correct, it is tracing through the code in certain sections in an unpredictable (and seemingly illogical) manner.

    The settings in my Visual Studio seem to have been messed up recently, for example when I debug a new project the default project configuration settings cause an error "debugging information missing or not found".

    I managed to fix this by copying the configuration settings (manually) from a previous project. Not sure how the default settings have changed, seems to be since I made an asp.net project??? No idea how to get them back either, I even resorted to re-installation of VS2005, but the settings have remained.

    This supports your theory Salem, the optimisation settings may also have been changed. However I have checked the configuration settings and can't see where? Is there a particular setting I need to set/deselect?

    In answer to your second question, it does appear to be working correctly, although it is making debugging difficult (for example by missing out my breakpoints).

    Sorry for the long response,

    Cheers Sean

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    PS

    Optimization under C/C++ in the configuration settings is set to: Disabled (/0d)

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    By default, the Debug configuration has optimizations turned off and the Release configuration has them on. Are you writing a standard C++ console application? Create a new project of the type Win32 Console Application and check Empty Project in the Application Settings tab/page of the wizard. Then add your code. You should be in the Win32 Debug configuration by default.

    In the code above, where is a breakpoint that you place that it skips over or misses?

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    Hi Daved.

    It's in Win32 Debug configuration, this console project was created through Empty Project. This is how it traces through the If block in the code above (when foundPos != end):
    Hits first if line (which should evaluate to false). Misses next line. Hits the next line (should not even be entering this block!). Jumps to the line immediately after the else statement (despite hitting previous return statement). Hits next line. Hits the next (return) line. Goes to end of "GetNode" function (last line of code). Jumps back up to If statement line (????). Jumps back down to last line of code. Jumps back up to If statement line again. Exits function (returning to line that called function).

    As you can see, it appears totally random and non-sensical.

    As I said, if I do start a new empty project and attempt debugging then I get a "Debugging information missing" error and debug mode exits (after clicking continue). I have to change the configuration settings to get the debugging info back.

    Is there any way to restore VS2005 to default settings? I think this would probably solve all my problems.

    Thanks,

    Sean

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> Is there any way to restore VS2005 to default settings?
    There might be, but I do not know it.

    If you select the line with the return inside the if block (that should not be being executed) and you hit F9 to set a breakpoint, does a red breakpoint dot appear? Does it have a question mark inside it? What happens if you hit Ctrl-F7 to compile just that file? If that does nothing, can you find that file in the solution explorer, right-click and then compile it? If that succeeds, double click on the file in the solution explorer and verify that it doesn't open up a different copy. Then build the solution to ensure that it has built that file recently. This should be done after you have turned on the debug information for that project.

    The symptoms you describe also occur if the debug information is out of date, either because the file hasn't been compiled recently, or because you are editing a different copy of the file (like from a different directory), or possibly even because the debug information got turned off so it is using an old version of that. You might have already tried these things, but these are the steps I would go through to try to get it working again.

  9. #9
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    Thanks for the reply.

    I can set a breakpoint on the line with the return statement. If I then hit F5 and debug, an exclamation mark temporarily appears on the breakpoints (hovering over which gives "Breakpoint will not be hit, invalid file line"). The breakpoint is not hit. If however, I place a breakpoint in my code a few lines before the If statement, this breakpoint is hit (as it should be) and I can then go line by line (F10) and the breakpoint on the return statement is then hit (that was previously missed).

    The file can be seperately compiled. I verified it was the same file when I double clicked on it in the solution explorer. I have built, rebuilt, cleaned etc the solution, all to no avail.

    The behaviour is occuring in other parts of my program as well (although not so erratically), missing out lines initialising variables for instance, but these variables are still being initialised even though they are missed.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    At this point I have no other ideas. If the project wasn't too big, I might consider starting a new project and verifying that the settins are how you want them, then create new files from scratch and copy and paste the old code into the new files. Obviously, this is just another version of everything else you've tried, but if the projects is only a few files big it might be worth a try.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting a C# program with a manifest file to run in the debugger
    By Xarzu Athanasop in forum C# Programming
    Replies: 0
    Last Post: 01-18-2008, 06:34 PM
  2. executing from debugger
    By hedwin in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2007, 04:05 PM
  3. Replies: 3
    Last Post: 07-24-2007, 04:25 PM
  4. VS2005 Professional & designated initializers
    By Hansie in forum C Programming
    Replies: 12
    Last Post: 05-25-2007, 12:26 AM