#define DEBUG... (using printf for debugging)

"Mr. Mike" Passaretti passaret at brahe.crd.ge.com
Fri May 4 23:18:42 AEST 1990


In article <40628 at cornell.UUCP> 
gordon at mimir.cs.cornell.edu (Jeffrey  Adam Gordon) writes:
#
#    I want to have a DEBUG flag which controls whether diagnostic printfs
#    are executed or not.
#
#	 [....]
#
#    - Jeff

Fred Fish has produced an excellent set of macros for C
which do just this and a lot more.  The basic form of use is
as follows (forgive me if this is a bit long).

    #include "dbug.h"

	main(argc, argv)
	int argc;
	char *argv[];
	{
	int foo;

	DBUG_ENTER("main");
	DBUG_PROCESS(argv[0]);
	for (i=1;i<argc && argv[i][0]=='-';i++)
            {
		switch(argv[i][1])
		{
		case '#' :
		    {
		    DBUG_PUSH(&(argv[i][2]));
		    }
		    break;
		[...]
		}
	    }

	foo = bar_bar_bar();
	DBUG_PRINT("bar", ("Foo = %d\n", foo));

	foo = blah_blah_blah();
	DBUG_PRINT("blah", ("Foo = %d\n", foo));
	DBUG_VOID_RETURN(0);
	}	

Now, at run-time the program can be called with a command
line like 'a.out #d:t mumble'.   This is a flag which the
DBUG macros use (through DBUG_PROCESS and DBUG_PUSH) to
enable and disable various functions.  There is tracing,
which is an output like

	>main
	->bar_bar_bar
	-<bar_bar_bar
	->blah_blah_blah
	-<blah_blah_blah
	<main

for simple level tracing.  There is also "flag" type printf
enabling, where a command line like 'a.out #dbar,:t mumble'
would cause all DBUG_PRINTFs with the keyword (1st arg)
"bar" to get printed.  There are also global enables and
disables, including the #define DBUG_OFF, which removes all
of the debug code entirely (for production usage).

my dbug.h has the following author notice in it, but I think
it's outdated.  Fred's whereabouts should be easy to
determine, if by no other method than eavesdropping on
 comp.sys.amiga for a while.

  *  AUTHOR
  *
  *	Fred Fish
  *	(Currently employed by Motorola Computer Division, Tempe, Az.)
  *	hao!noao!mcdsun!fnf
  *	(602) 438-3614

                                                        - MM

-- 
passaretti at crd.ge.com                     {whatever}!crdgw1!brahe!passaret



More information about the Comp.unix.wizards mailing list