Jump to content
  • Advertisement
Sign in to follow this  
Concentrate

Debugging

This topic is 2949 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just wanted to ask something debugging programs. In a typical program I would
do something like this :

//main.h
#include "AllNeededHeaders.h"

#define DEBUG_MODE_

#ifdef DEBUG_MODE_
#include "DebugHeader.h"
#else
#define RUN_NORMAL_MODE_
#endif

int main(){
#ifdef DEBUG_MODE_
startDebug()
#endif

doStuff();

#ifdef DEBUG_MODE_
endDebug();
#endif
}



But the problem with that was that I had to do this for each file. So I
started to use a Debug.h file in my program. Its basically contains this :

//#define DEBUG_MODE_ON_

#ifndef DEBUG_MODE_ON_
#define NORMAL_MODE_ON_
#endif


I just comment out "#define DEBUG_MODE_ON_" if I want the program to run normal.

So I was wondering if someone else had a construct for debugging program thats been useful. I am open for suggestions. Thanks

Share this post


Link to post
Share on other sites
Advertisement
What? what does startDebugging and stopDebugging do? Why aren't you just placing breakpoints and stepping through the code in your debugger (Visual Studio, Code::Blocks or whatever)?

-me

Share this post


Link to post
Share on other sites
also, i think you can define preprocessor variables, just like compilers do (ie: _DEBUG or _NDEBUG). This way you don't have to create your specific header file.

Share this post


Link to post
Share on other sites
two things (both assuming you have a good reason for doing what you're doing).

First, you set up your project settings to define things for you. Your project probably already includes a debug preprocessor token for debug builds.

Second, if the code you showed occurs like that everywhere in a "start debugging, stop debugging" format... you could wrap the behavior in an object and have the constructor "start debugging" and the destructor "stop debugging". Then you just create an object at the start of a scope and let it be destroyed at the end of the scope. Instead of ifdef'ing every occurance of your debug code you keep the debugger object in both release and debug builds. You just make it so the debug build doesn't do anything inside the debugger object. I'm not sure that's clear so here's some example code:
struct Debugger
{
Debugger() {
#ifdef DEBUG_MODE_
startDebug();
#endif
}
~Debugger() {
#ifdef DEBUG_MODE_
endDebug();
#endif
}
}

...
int main() {
Debugger debug;
dostuff();
}
Again, this assumes you have a good reason for writing the code you do and I wouldn't use this personally.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!