State of the debugging flags.
Ian Bruene
ianbruene at gmail.com
Tue May 30 21:34:07 UTC 2017
At ESRs request I've trawled through the C sources to see how debug
logging is handled. First, by way of summary let me present you with a
couple bits of code:
# define DPRINTF(lvl, arg) \
do { \
if (debug >= (lvl)) \
mprintf arg; \
} while (0)
#define TRACE(lvl, arg) \
do { \
if (debug >= (lvl)) \
mprintf arg; \
} while (0)
#define parseprintf(LEVEL, ARGS) if (debug > LEVEL) printf ARGS
Yeah.............
Debug printing is controlled by the debug variable, defined as int debug
in lib_srbuf.c and extern int debug in declcond.h (both the one in
include/ and ntpd/) (why isn't this unsigned?). debug==0 is no debug,
with each level above that including more data as is typical.
The ntpd -d flag increments the debug variable by one for every time it
appears in the argument list, and also sets nofork.
The ntpd -D n flag sets the debug variable to n, but does not set nofork.
From there the actual logging is handled through several methods: some
functions with complicated logging requirements directly use debug to
setup their own printing, similarly some modules with module-wide
special requirements define their own debug logging functions.
But in most cases debug logging requires only a simple if (debug>0)
{printf("blah")}, this is handled through four (4!) different methods
I've seen so far:
DPRINTF, which is defined in ntpd.h
TRACE, which is defined in ntp_debug.h, and is identical to DPRINTF
parseprintf, which is defined in include/parse.h, and is used
exclusively in libparse/
adhoc if (debug>n) statements. many of the level one statements also
merely ask if (debug), rather than a proper if (debug > 0)
Every instance I've seen has the logging code enclosed in an #ifdef
block for the debug compilation switch, whether directly where it is
used, of inside of a macro. It would appear that someone began to
replace the explicit if debugs with macros, but never completed it for
unknown reasons.
--
In the end; what separates a Man, from a Slave? Money? Power?
No. A Man Chooses, a Slave Obeys. -- Andrew Ryan
More information about the devel
mailing list