root/source3/include/debug.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /* 
   2    Unix SMB/CIFS implementation.
   3    SMB debug stuff
   4    Copyright (C) Andrew Tridgell 1992-1998
   5    Copyright (C) John H Terpstra 1996-1998
   6    Copyright (C) Luke Kenneth Casson Leighton 1996-1998
   7    Copyright (C) Paul Ashton 1998
   8    
   9    This program is free software; you can redistribute it and/or modify
  10    it under the terms of the GNU General Public License as published by
  11    the Free Software Foundation; either version 3 of the License, or
  12    (at your option) any later version.
  13    
  14    This program is distributed in the hope that it will be useful,
  15    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17    GNU General Public License for more details.
  18    
  19    You should have received a copy of the GNU General Public License
  20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21 */
  22 
  23 #ifndef _DEBUG_H
  24 #define _DEBUG_H
  25 
  26 /* -------------------------------------------------------------------------- **
  27  * Debugging code.  See also debug.c
  28  */
  29 
  30 /* mkproto.awk has trouble with ifdef'd function definitions (it ignores
  31  * the #ifdef directive and will read both definitions, thus creating two
  32  * diffferent prototype declarations), so we must do these by hand.
  33  */
  34 /* I know the __attribute__ stuff is ugly, but it does ensure we get the 
  35    arguments to DEBUG() right. We have got them wrong too often in the 
  36    past.
  37    The PRINTFLIKE comment does the equivalent for SGI MIPSPro.
  38  */
  39 /* PRINTFLIKE1 */
  40 int  Debug1( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
  41 /* PRINTFLIKE1 */
  42 bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
  43 bool dbghdrclass( int level, int cls, const char *location, const char *func);
  44 bool dbghdr( int level, const char *location, const char *func);
  45 
  46 #if defined(sgi) && (_COMPILER_VERSION >= 730)
  47 #pragma mips_frequency_hint NEVER Debug1
  48 #pragma mips_frequency_hint NEVER dbgtext
  49 #pragma mips_frequency_hint NEVER dbghdrclass
  50 #pragma mips_frequency_hint NEVER dbghdr
  51 #endif
  52 
  53 extern XFILE *dbf;
  54 
  55 /* If we have these macros, we can add additional info to the header. */
  56 
  57 #ifdef HAVE_FUNCTION_MACRO
  58 #define FUNCTION_MACRO  (__FUNCTION__)
  59 #else
  60 #define FUNCTION_MACRO  ("")
  61 #endif
  62 
  63 /* 
  64  * Redefine DEBUGLEVEL because so we don't have to change every source file
  65  * that *unnecessarily* references it. Source files neeed not extern reference 
  66  * DEBUGLEVEL, as it's extern in includes.h (which all source files include).
  67  * Eventually, all these references should be removed, and all references to
  68  * DEBUGLEVEL should be references to DEBUGLEVEL_CLASS[DBGC_ALL]. This could
  69  * still be through a macro still called DEBUGLEVEL. This cannot be done now
  70  * because some references would expand incorrectly.
  71  */
  72 #define DEBUGLEVEL *debug_level
  73 extern int DEBUGLEVEL;
  74 
  75 /*
  76  * Define all new debug classes here. A class is represented by an entry in
  77  * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
  78  * old DEBUGLEVEL. Any source file that does NOT add the following lines:
  79  *
  80  *   #undef  DBGC_CLASS
  81  *   #define DBGC_CLASS DBGC_<your class name here>
  82  *
  83  * at the start of the file (after #include "includes.h") will default to
  84  * using index zero, so it will behaive just like it always has. 
  85  */
  86 #define DBGC_ALL                0 /* index equivalent to DEBUGLEVEL */
  87 
  88 #define DBGC_TDB                1
  89 #define DBGC_PRINTDRIVERS       2
  90 #define DBGC_LANMAN             3
  91 #define DBGC_SMB                4
  92 #define DBGC_RPC_PARSE          5
  93 #define DBGC_RPC_SRV            6
  94 #define DBGC_RPC_CLI            7
  95 #define DBGC_PASSDB             8
  96 #define DBGC_SAM                9
  97 #define DBGC_AUTH               10
  98 #define DBGC_WINBIND            11
  99 #define DBGC_VFS                12
 100 #define DBGC_IDMAP              13
 101 #define DBGC_QUOTA              14
 102 #define DBGC_ACLS               15
 103 #define DBGC_LOCKING            16
 104 #define DBGC_MSDFS              17
 105 #define DBGC_DMAPI              18
 106 #define DBGC_REGISTRY           19
 107 
 108 /* So you can define DBGC_CLASS before including debug.h */
 109 #ifndef DBGC_CLASS
 110 #define DBGC_CLASS            0     /* override as shown above */
 111 #endif
 112 
 113 extern int  *DEBUGLEVEL_CLASS;
 114 extern bool *DEBUGLEVEL_CLASS_ISSET;
 115 
 116 /* Debugging macros
 117  *
 118  * DEBUGLVL()
 119  *   If the 'file specific' debug class level >= level OR the system-wide 
 120  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
 121  *   generate a header using the default macros for file, line, and 
 122  *   function name. Returns True if the debug level was <= DEBUGLEVEL.
 123  * 
 124  *   Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
 125  *
 126  * DEBUGLVLC()
 127  *   If the 'macro specified' debug class level >= level OR the system-wide 
 128  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 
 129  *   generate a header using the default macros for file, line, and 
 130  *   function name. Returns True if the debug level was <= DEBUGLEVEL.
 131  * 
 132  *   Example: if( DEBUGLVLC( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
 133  *
 134  * DEBUG()
 135  *   If the 'file specific' debug class level >= level OR the system-wide 
 136  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 
 137  *   generate a header using the default macros for file, line, and 
 138  *   function name. Each call to DEBUG() generates a new header *unless* the 
 139  *   previous debug output was unterminated (i.e. no '\n').
 140  *   See debug.c:dbghdr() for more info.
 141  *
 142  *   Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
 143  *
 144  * DEBUGC()
 145  *   If the 'macro specified' debug class level >= level OR the system-wide 
 146  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 
 147  *   generate a header using the default macros for file, line, and 
 148  *   function name. Each call to DEBUG() generates a new header *unless* the 
 149  *   previous debug output was unterminated (i.e. no '\n').
 150  *   See debug.c:dbghdr() for more info.
 151  *
 152  *   Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
 153  *
 154  *  DEBUGADD(), DEBUGADDC()
 155  *    Same as DEBUG() and DEBUGC() except the text is appended to the previous
 156  *    DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening 
 157  *    header.
 158  *
 159  *    Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
 160  *             DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
 161  *
 162  * Note: If the debug class has not be redeined (see above) then the optimizer 
 163  * will remove the extra conditional test.
 164  */
 165 
 166 /*
 167  * From talloc.c:
 168  */
 169 
 170 /* these macros gain us a few percent of speed on gcc */
 171 #if (__GNUC__ >= 3)
 172 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
 173    as its first argument */
 174 #ifndef likely
 175 #define likely(x)   __builtin_expect(!!(x), 1)
 176 #endif
 177 #ifndef unlikely
 178 #define unlikely(x) __builtin_expect(!!(x), 0)
 179 #endif
 180 #else
 181 #ifndef likely
 182 #define likely(x) (x)
 183 #endif
 184 #ifndef unlikely
 185 #define unlikely(x) (x)
 186 #endif
 187 #endif
 188 
 189 #define CHECK_DEBUGLVL( level ) \
 190   ( ((level) <= MAX_DEBUG_LEVEL) && \
 191      unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
 192      (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
 193       DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) )
 194 
 195 #define DEBUGLVL( level ) \
 196   ( CHECK_DEBUGLVL(level) \
 197    && dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO ) )
 198 
 199 
 200 #define DEBUGLVLC( dbgc_class, level ) \
 201   ( ((level) <= MAX_DEBUG_LEVEL) && \
 202      unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
 203      (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
 204       DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
 205    && dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO) )
 206 
 207 
 208 #define DEBUG( level, body ) \
 209   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
 210            unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
 211            (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
 212             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
 213        && (dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO )) \
 214        && (dbgtext body) )
 215 
 216 #define DEBUGC( dbgc_class, level, body ) \
 217   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
 218            unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
 219            (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
 220             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
 221        && (dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO)) \
 222        && (dbgtext body) )
 223 
 224 #define DEBUGADD( level, body ) \
 225   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
 226            unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
 227            (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
 228             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
 229        && (dbgtext body) )
 230 
 231 #define DEBUGADDC( dbgc_class, level, body ) \
 232   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
 233           unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
 234            (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
 235             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
 236        && (dbgtext body) )
 237 
 238 /* Print a separator to the debug log. */
 239 #define DEBUGSEP(level)\
 240         DEBUG((level),("===============================================================\n"))
 241 
 242 #endif

/* [<][>][^][v][top][bottom][index][help] */