home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 322_01 / tracmacr.doc < prev   
Text File  |  1990-08-06  |  3KB  |  119 lines

  1.  
  2.  
  3.  
  4.         
  5.  
  6.  
  7.                           Macros for Debugging C Programs
  8.  
  9.                                    by Bill Rogers
  10.  
  11.         Although  symbolic  debuggers  have  reduced  the  need  for  use of
  12.         inserting "printf"  commands  in  C  programs  for  debugging,  this
  13.         approach still has its use. 
  14.  
  15.         The  following  characteristics  would  make  "printf" commands even
  16.         easier to use:
  17.  
  18.             Conditionally compiled commands,
  19.             Simple commands,
  20.             Easy definition of where the command is located. 
  21.  
  22.         Using the "stringizing", "__FILE__" and "__LINE__" features of  ANSI
  23.         C,  a  compact  set  of  debugging macros can be constructed.  These
  24.         macros are constructed in the spirit of the ANSI C "assert" macro. 
  25.  
  26.         Although these macros can be readily modified,  they  now  assume  a
  27.         revision control constant:
  28.  
  29.             const static char RCsid[] = <rcsid string>;
  30.  
  31.         of file scope, and a macro for the function name:
  32.  
  33.             T_FUNC(<func>)
  34.  
  35.         of function scope. 
  36.  
  37.         These macros are activated by the compiler command line argument (in
  38.         Lattice C/6.0):
  39.  
  40.                 -dTRACE
  41.  
  42.         The forms of the printed line to "stderr" are:
  43.  
  44.                 <file>:<line>:<func>:Begin RCsid=
  45.                     <rcsid string>
  46.                 <file>:<line>:<func>:<type> <var name>=<var value>
  47.                 <file>:<line>:<func>:End
  48.  
  49.         The macros are:
  50.  
  51.                 T_FUNC(x)   Define function name
  52.  
  53.                 T_BEGIN()   Display function "begin"
  54.                 T_END()     Display function "end"
  55.  
  56.                 T_BOOL(x)   Display boolean
  57.                 T_CHAR(x)   Display character
  58.                 T_DBL(x)    Display double
  59.         
  60.  
  61.  
  62.  
  63.         
  64.                 T_HEX(x)    Display unsigned integer in hexadecimal
  65.                 T_INT(x)    Display integer
  66.                 T_FLOAT(x)  Display float
  67.                 T_LHEX(x)   Display unsigned long integer in hexadecimal
  68.                 T_LONG(x)   Display long
  69.                 T_PTR(x)    Display pointer as segment:offset
  70.                 T_STR(x)    Display string
  71.  
  72.         These macros are defined in the header "trace.h" given in Figure 1. 
  73.  
  74.                           --------------------------------
  75.  
  76.                           --------------------------------
  77.                                 Figure 1. "trace.h"
  78.  
  79.         A demonstration of the use of these macros is given in Figure 2 with
  80.         the output given in Figure 3. 
  81.  
  82.                           --------------------------------
  83.  
  84.                           --------------------------------
  85.                                Figure 2. "tracdemo.c"
  86.  
  87.                           --------------------------------
  88.  
  89.                           --------------------------------
  90.                               Figure 3. "tracdemo.lst"
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.         
  119.