[LC++]Producing a log of routine entry and exit

Keith Schincke kschin at unf.edu
Fri Aug 30 03:56:05 UTC 2002


I have borrowed the debuging macro's from the pam system on Linux. It
gives good messages that help in tracing and debuging code.


With a little bit of modification, you can generate debug messages for
various levels of debuging. I kept mine simple.

The code from one of my header files follow below the sig but the usage is
easy.

Ex:
D(("Check variable = %d",check_var));
produces
[main.c:main(15)] Check variable = 55

I often add D(("called")) to the top and bottom of functions of interest
to see if they are being called and are returning

Hope this and the other suggestions help.

-- 
Keith Schincke           My dawg is always with me.
Jacksonville, Fl               00 Spool - Wild at Heart
http://www.unf.edu/~kschin                           Email: kschin at unf.edu

#ifdef DEBUG
#include <stdarg.h>

static void _pam_output_debug_info(const char *file, const char *fn
                                   , const int line)
{
    fprintf(stderr,"[%s:%s(%d)] ",file, fn, line);
}

static void _pam_output_debug(const char *format, ...)
{
    va_list args;
    FILE *logfile;
    int must_close = 1;

    va_start(args, format);

    vfprintf(stderr, format, args);
    fprintf(stderr, "\n");

    va_end(args);
}

#define D(x) do { \
    _pam_output_debug_info(__FILE__, __FUNCTION__, __LINE__); \
    _pam_output_debug x ; \
} while (0)


#else

#define D(x)                             do { } while (0)

#endif







More information about the tuxCPProgramming mailing list