debug.h revision 98121
1276792Sdim/* 2276792Sdim * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. 3276792Sdim * All rights reserved. 4276792Sdim * 5276792Sdim * By using this file, you agree to the terms and conditions set 6276792Sdim * forth in the LICENSE file which can be found at the top level of 7276792Sdim * the sendmail distribution. 8276792Sdim * 9276792Sdim * $Id: debug.h,v 1.15 2001/03/08 03:23:07 ca Exp $ 10276792Sdim */ 11276792Sdim 12276792Sdim/* 13276792Sdim** libsm debugging and tracing 14276792Sdim** See libsm/debug.html for documentation. 15276792Sdim*/ 16276792Sdim 17276792Sdim#ifndef SM_DEBUG_H 18276792Sdim# define SM_DEBUG_H 19276792Sdim 20276792Sdim# include <sm/gen.h> 21276792Sdim# include <sm/io.h> 22276792Sdim 23276792Sdim/* 24276792Sdim** abstractions for printing trace messages 25276792Sdim*/ 26276792Sdim 27276792Sdimextern SM_FILE_T * 28276792Sdimsm_debug_file __P((void)); 29276792Sdim 30276792Sdimextern void 31276792Sdimsm_debug_setfile __P(( 32276792Sdim SM_FILE_T *)); 33276792Sdim 34276792Sdimextern void PRINTFLIKE(1, 2) 35276792Sdimsm_dprintf __P(( 36276792Sdim char *_fmt, 37276792Sdim ...)); 38276792Sdim 39276792Sdimextern void 40276792Sdimsm_dflush __P((void)); 41276792Sdim 42276792Sdim/* 43276792Sdim** abstractions for setting and testing debug activation levels 44276792Sdim*/ 45276792Sdim 46276792Sdimextern void 47276792Sdimsm_debug_addsettings_x __P(( 48276792Sdim const char *)); 49276792Sdim 50276792Sdimextern void 51276792Sdimsm_debug_addsetting_x __P(( 52276792Sdim const char *, 53276792Sdim int)); 54276792Sdim 55276792Sdim# define SM_DEBUG_UNKNOWN ((SM_ATOMIC_UINT_T)(-1)) 56276792Sdim 57276792Sdimextern const char SmDebugMagic[]; 58276792Sdim 59276792Sdimtypedef struct sm_debug SM_DEBUG_T; 60276792Sdimstruct sm_debug 61276792Sdim{ 62276792Sdim const char *sm_magic; /* points to SmDebugMagic */ 63276792Sdim 64276792Sdim /* 65276792Sdim ** debug_level is the activation level of this debug 66276792Sdim ** object. Level 0 means no debug activity. 67276792Sdim ** It is initialized to SM_DEBUG_UNKNOWN, which indicates 68276792Sdim ** that the true value is unknown. If debug_level == 69276792Sdim ** SM_DEBUG_UNKNOWN, then the access functions will look up 70276792Sdim ** its true value in the internal table of debug settings. 71276792Sdim */ 72276792Sdim 73276792Sdim SM_ATOMIC_UINT_T debug_level; 74276792Sdim 75276792Sdim /* 76276792Sdim ** debug_name is the name used to reference this SM_DEBUG 77276792Sdim ** structure via the sendmail -d option. 78276792Sdim */ 79276792Sdim 80276792Sdim char *debug_name; 81276792Sdim 82276792Sdim /* 83276792Sdim ** debug_desc is a literal character string of the form 84276792Sdim ** "@(#)$Debug: <name> - <short description> $" 85276792Sdim */ 86276792Sdim 87276792Sdim char *debug_desc; 88276792Sdim 89276792Sdim /* 90276792Sdim ** We keep a linked list of initialized SM_DEBUG structures 91276792Sdim ** so that when sm_debug_addsetting is called, we can reset 92276792Sdim ** them all back to the uninitialized state. 93276792Sdim */ 94276792Sdim 95276792Sdim SM_DEBUG_T *debug_next; 96276792Sdim}; 97276792Sdim 98276792Sdim# ifndef SM_DEBUG_CHECK 99276792Sdim# define SM_DEBUG_CHECK 1 100276792Sdim# endif /* ! SM_DEBUG_CHECK */ 101276792Sdim 102276792Sdim# if SM_DEBUG_CHECK 103276792Sdim/* 104276792Sdim** This macro is cleverly designed so that if the debug object is below 105276792Sdim** the specified level, then the only overhead is a single comparison 106276792Sdim** (except for the first time this macro is invoked). 107276792Sdim*/ 108276792Sdim 109276792Sdim# define sm_debug_active(debug, level) \ 110276792Sdim ((debug)->debug_level >= (level) && \ 111276792Sdim ((debug)->debug_level != SM_DEBUG_UNKNOWN || \ 112276792Sdim sm_debug_loadactive(debug, level))) 113276792Sdim 114276792Sdim# define sm_debug_level(debug) \ 115276792Sdim ((debug)->debug_level == SM_DEBUG_UNKNOWN \ 116276792Sdim ? sm_debug_loadlevel(debug) : (debug)->debug_level) 117276792Sdim 118276792Sdim# define sm_debug_unknown(debug) ((debug)->debug_level == SM_DEBUG_UNKNOWN) 119276792Sdim# else /* SM_DEBUG_CHECK */ 120276792Sdim# define sm_debug_active(debug, level) 0 121276792Sdim# define sm_debug_level(debug) 0 122276792Sdim# define sm_debug_unknown(debug) 0 123276792Sdim# endif /* SM_DEBUG_CHECK */ 124276792Sdim 125276792Sdimextern bool 126276792Sdimsm_debug_loadactive __P(( 127276792Sdim SM_DEBUG_T *, 128276792Sdim int)); 129276792Sdim 130276792Sdimextern int 131276792Sdimsm_debug_loadlevel __P(( 132276792Sdim SM_DEBUG_T *)); 133276792Sdim 134276792Sdim# define SM_DEBUG_INITIALIZER(name, desc) { \ 135276792Sdim SmDebugMagic, \ 136276792Sdim SM_DEBUG_UNKNOWN, \ 137276792Sdim name, \ 138276792Sdim desc, \ 139276792Sdim NULL} 140276792Sdim 141276792Sdim#endif /* ! SM_DEBUG_H */ 142276792Sdim