
Assert
#include <assert.h>
….
assert(predicate that must be true);
See the man page for more info.
Simple TRACE macro
- Useful so your fprintf(stderr,…) is not
hard-coded in your code
- Basically what is present in MS
Visual Studio C++ (and many other compilers no doubt…)
- Code: trace.h
More Complex DEBUG
Macro
- Have a debug flag bit
array set at runtime in an environment variable to change what debug
printouts happen without recompiling your code
- Also can have other
information printed out on the debug line before the debug statement
(thread ID, thread state, …)
- Template: DEBUG(FLAGS, FORMAT, a1, a2, a3);
- Real example: DEBUG (D_SPAWN, "r%06lX spawn p%06lX", CUR_RES,
pr, 0);
- Can also use multiple
flags in code: DEBUG(D_FLAG1|D_FLAG2,
…)
- Must first initialize
at startup by calling sr_init_debug()
- Code (note: details
not testable (they are hairy!), main ideas/benefits are): debug.h, debug.c
- Note: it was coded
before __VA_ARGS__ was
defined for macros, but for portability they would still probably use
this version