Maybe a thread with a sticky would be nice if this thread grows.
I like programming and this kind of things.
My 5 cents:
1) My debug system is around two statements:
- Code: Select all
print_board("<tag>");
Print("<tag>","printf like format", args.....)
I have lot of this around my code. Say I like to debug passed pawn.
After the code I write:
- Code: Select all
print_board("PASSED_PAWN");
Print("PASSED_PAWN","There is a passed pawn on the %s square\n",
strSquare(sq));
When I want to debug something, at the initialization of my program
I switch on or off the tags I want to debug. (default off).
Of course, I #define a DEBUG vars. If don't define, all above
statements are avoided and no code is generated.
Also I have and initialization statemente with a parameter that says
if screen dump, file dump, both or none.
I use this system for doing a trace. Example
- Code: Select all
Print("TRACE","Entrance to search function. Node number %d. Time: %s.\n",nodes,strTime(time));
If you write lots of Print with the TRACE tag, and you switch that tag on you will be able to know how your program works.
2) Also I have a profile system to measure how many time a function take.
When enter a function I call PROFILE_START("myfunc()");
Before returning, PROFILE_STOP("myfunc()");
It run like a stack. When a new profile start statement is called,
it stop previous timers and put it on the stack. When it returns
it put the timer of the stack on. Again, a #define controls if code
is beeing or not generated.
A PRINT_PROFILE would show all info.
3) I use "artistic style" tool. It is nice. I use this command:
- Code: Select all
astyle -a -t4 -T4 -K -L -w -M -m0 -f -p -o -O -X -Z -v *.c *.h
4) When commeting, I do it as follow:
- Code: Select all
/*
myfunc()
if (x=y) {
...
}
...
mufun2(); /**/
So when I want to uncomment, I only remove the first line. It is
a faster way than usual, where you need to remove the */ also.
5) I have a stadistical system that works similar to debug system. I
don't need to declare one vars per stats I want. The only thing I
need is to call:
- Code: Select all
STAT("<tag>",counter);
i.e.
- Code: Select all
STAT("check extension",1);
If the tag does not exits, it create a new counter for that tag,
inicializated to the counter.
Again, I have a #define STATS. Ifndef then no code is created at
compile.
A PRINT_STATS would show all info.
The systems described let me dont need to write #ifdef var in each statemnte, as they are define as void when no #define is declared.
I would like to hear about your tips. Specially I would like to know
a good system to make a tree dump, or if you use any trick to access in a faster way to global vars (which for default they are not in cache), coding tips, and so on.....
FS