Skip to main content
GameDev.net gamedev.net
🔒 Locked

Debugging Hints

Started by methinks Apr 15, 2005 at 10:15 AM 1 replies 700+ views
Original Post
methinks
methinks
When most people learn programming, they don't learn the finer points of the craft, such as debugging. (I've heard stories of people making it all the way through their comp-sci course without knowing there was such a thing as a debugger.) Here are a some basic debugging tips to make your life easier. Please note, I'm just a begginer, so my knowlege is severely limited... If you have any advice of your own, please share it here. The following are based on vc++ 7 (.net) I would imagine that other compilers have comprarable debugging features, but I haven't actually used them. Breakpoints - Breakpoints allow you to pause your program during execution so that you can take a look inside, check variable values, etc. Step into/over/out - Stepping makes your program run one step at a time, allowing you to follow the program's flow as it executes. That way you can track how it deals with certain conditions, desision gates (if/else), or variable values. Flagging - One way to track where a program goes is to make certain functions throw up a flag when they are called. Probably the easiest way to do this is to get them to print a short message, such as "init called", "creating object", "deleting texture". I personally use these to track resource management, to make sure that everything is being cleaned up properly. The problem with this is that once you're done with the testing, you want to get rid of the flags, and it's a real pain to go through all your code, looking for these flags to remove them. Luckilly, there's another way. At the begining of the program, we tell the compiler that we are doing debug. #define DEBUG then, when we set a flag, we do it as follows: #if defined(DEBUG) printf("Output message here"); #endif This way, the program looks to see if we're still debugging before compiling the print line. When we want to get rid of the flags, we just remove the #define DUBUG, and the compiler will ignore the flags. [Edited by - methinks on April 15, 2005 11:10:16 AM]
Anon Mike
Anon Mike
Quote:
At the begining of the program, we tell the compiler that we are doing debug.
#define DEBUG

If you're using VC it automatically defines _DEBUG for debug builds and NDEBUG for retail builds. If you use these you don't have to modify the source to switch between debug and non-debug.
-Mike
SirLuthor
SirLuthor
In general, for most debugging, I simply run it in the debugger until the point where it crashes, inspect the callstack, formulate an opinion on why I think it crashed, implement a fix, find out it wasn't that, rinse and repeat.

Only in dire need do I implement messages, because they clutter code, have to be taken out afterwords, and are just a very general mess.
Free speech for the living, dead men tell no tales,Your laughing finger will never point again...Omerta!Sing for me now!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.