[comp.lang.c] DEBUG talk

law@cis.udel.edu (113EVN) (05/04/90)

I've been sitting here watching everyone talk about how to get 
debugging output into programs cleanly.  All fine and nice, but 
I dont think anyone hit one of the real nice features of C+Unix+adb.

in code i work on i usually have something like this:

#if DEBUG
int vmdebug =0

#define VMALLOCDEBUG	0x1
#define VMSTUPIDDEBUG	0x2
... for the rest of the bit fields as necessary
#endif
..... insert your code here.....


#if DEBUG
if (vmdebug & VMALLOCDEBUG)
	printf("stupid message about vmalloc
#endif

.....

#if DEBUG
if (vmdebug & VMSTUPIDDEBUG)
	printf("stupid message about vmstupid
#endif


this way you compile with -DDEBUG but you dont have to actually turn the 
debugging on. (quite helpful when debugging kernel events are happen real
real often and debugging is a dog!).  when you actually want to monitor
something you adb your running executable (like vmunix!) patch the 
debug variable for whatever debugging mask you like...  when you're done
reset it to zero for normal operation.

I use such code usually in kernel modules, it is clean and efficient as 
debugging comes and allows a great run-time flexibility on what portions
of code is monitored.  I've even used such code in conjunction with 
university of utah's flog to monitor large portions of the 4.3 scheduling
and virtual memory facilities in real time.

Jeff Law
University of Delaware  PHONE: (302)-451-8005 work, (302) 731-1462 home
E-Mail: law@ee.udel.edu, UUCP: ...!<your_favorite_arpa_gateway>!udel.edu!law
Jeff Law
University of Delaware  PHONE: (302)-451-8005 work, (302) 731-1462 home
E-Mail: law@ee.udel.edu, UUCP: ...!<your_favorite_arpa_gateway>!udel.edu!law