executing from debugger

This is a discussion on executing from debugger within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm currently developing a c++ application using DevC++. It's a 3d graphics application and in some part I have ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    4

    Exclamation executing from debugger

    Hi,
    I'm currently developing a c++ application using DevC++. It's a 3d graphics application and in some part I have to execute a Collision detection function in order to make objects recoil. I have however encountered a problem I have never seen. After compiling a demo application i execute it and see that either the collision detection or the collision response does not work as intended. Meaning that objects continue to move as they were non-solid (they pass through each other). Obviously thinking of an error in the code I try to execute the debugger, and I've noticed that running under the debugger (without setting any breakpoints) the application works perfectly! How is this possible?
    I'm not looking for help in the actual programming, but I want to know if there is someone that can give me some direction for resolving this issue. What is different in the debugger? What is, in general, that is executed differently in the debugger with respect to the common executable? Has anyone had a similar problem before?

    Ed.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    The timing is different. In debugging, this can matter, e.g. if you use time deltas in your calculations.

    I can't think of anything else.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Are you running DEBUG version of the code in the debugger, and release (optimized) code without the debugger? Compilers sometimes generate quite different code when you enable debug mode, since a lot of the heavy optimization goes out the window. [When this makes a difference, it usually means that you are doing something dodgy without the compiler undersanding that this is the case, such as aliasing pointers in a way that conflicts with the optimisation, not using volatile on variables that change out of scope, etc, etc]

    Other than that, I can only think of the fact that running in the debugger may change the timing, or perhaps variables have different initial values when you start the application - uninitialized variables may not have the same value if you start the application in a different way.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    By the way, bugs that change or disappear when you start debugging them are known as "Heisenbugs", after the Heisenbergs uncertainty principle.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    4

    Talking

    Thank you!
    Looking for the pointers initializations I have noticed that somewhere in the class hierarchy there was a bool variable that was not initialized (I put the initialization in the destructor instead of the constructor). Executing the program normally there was no error (maybe a bool variable default value is false?), but an if condition was not met, while executing the debugger the variable was initialized to true by default.
    It's very difficult to find these errors, especially if you are developing something that has many classes.....

    Ed.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Indeed, it can be VERY difficult to find these things.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,160
    Quote Originally Posted by matsp View Post
    Indeed, it can be VERY difficult to find these things.
    Or you could just run the program through Valgrind and it would have spat out the exact line number where the uninitialized variable was used in the condition.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Glad you figured it out. In the future, consider initializing member variables in the initializer list. That's where you should be doing it anyway, and if you try to add an initializer list to a destructor the compiler will complain.

  9. #9
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    I got used to: if a add a variable, my next step will be to put it in the initializer list before doing _anything_ else (including going to toilet or grab my coffee cup again)

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, 05:34 PM
  2. Replies: 3
    Last Post: 07-24-2007, 04:25 PM
  3. MSVC++ Debugger (it kills me)
    By lightatdawn in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 06-29-2002, 07:37 PM
  4. Debugger in Visual C++ UNDER Win 2000
    By porecha_jp in forum Windows Programming
    Replies: 0
    Last Post: 11-22-2001, 08:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21