
Assert(3)
·      
Usage: 
#include <assert.h>
void assert(scalar
expression);
·      
Use assert religiously any time you know certain relationships that MUST hold between variables
to another or a variable to a constant.
·      
It is helpful for the programmer,
not the user.
o  Sample output: “Assertion failed in file foo.c,
function do_bar, line 1287”.
·      
Leave in your code FOREVER
o  If symbol NDEBUG is defined, the macro goes to nothing.
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
 
  - TRACE gives you EVERY
      output ALL THE TIME.
 
  - This debug macro setup
      lets you turn on and of individual debug “topics” (up to 32)
      – MUCH finer-grained control over the debug output
 
  - Implementation: 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_FLAG2|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