reverting patch back to localhost in smbd_running()
[Samba.git] / source / include / debug.h
blob240da0d6fc583bd18025479d707c3006d9952b15
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 SMB debug stuff
5 Copyright (C) Andrew Tridgell 1992-1998
6 Copyright (C) John H Terpstra 1996-1998
7 Copyright (C) Luke Kenneth Casson Leighton 1996-1998
8 Copyright (C) Paul Ashton 1998
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #ifndef _DEBUG_H
26 #define _DEBUG_H
28 /* -------------------------------------------------------------------------- **
29 * Debugging code. See also debug.c
32 /* mkproto.awk has trouble with ifdef'd function definitions (it ignores
33 * the #ifdef directive and will read both definitions, thus creating two
34 * diffferent prototype declarations), so we must do these by hand.
36 /* I know the __attribute__ stuff is ugly, but it does ensure we get the
37 arguemnts to DEBUG() right. We have got them wrong too often in the
38 past.
40 int Debug1( char *, ... ) PRINTF_ATTRIBUTE(1,2);
41 BOOL dbgtext( char *, ... ) PRINTF_ATTRIBUTE(1,2);
43 /* If we have these macros, we can add additional info to the header. */
44 #ifdef HAVE_FILE_MACRO
45 #define FILE_MACRO (__FILE__)
46 #else
47 #define FILE_MACRO ("")
48 #endif
50 #ifdef HAVE_FUNCTION_MACRO
51 #define FUNCTION_MACRO (__FUNCTION__)
52 #else
53 #define FUNCTION_MACRO ("")
54 #endif
56 /*
57 * Redefine DEBUGLEVEL because so we don't have to change every source file
58 * that *unnecessarily* references it. Source files neeed not extern reference
59 * DEBUGLEVEL, as it's extern in includes.h (which all source files include).
60 * Eventually, all these references should be removed, and all references to
61 * DEBUGLEVEL should be references to DEBUGLEVEL_CLASS[DBGC_ALL]. This could
62 * still be through a macro still called DEBUGLEVEL. This cannot be done now
63 * because some references would expand incorrectly.
65 #define DEBUGLEVEL *debug_level
69 * Define all new debug classes here. A class is represented by an entry in
70 * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
71 * old DEBUGLEVEL. Any source file that does NOT add the following lines:
73 * #undef DBGC_CLASS
74 * #define DBGC_CLASS DBGC_<your class name here>
76 * at the start of the file (after #include "includes.h") will default to
77 * using index zero, so it will behaive just like it always has.
79 #define DBGC_CLASS 0 /* override as shown above */
80 #define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
82 #define DBGC_TDB 1
83 #define DBGC_PRINTDRIVERS 2
84 #define DBGC_LANMAN 3
86 #define DBGC_LAST 4 /* MUST be last class value + 1 */
89 extern int DEBUGLEVEL_CLASS[DBGC_LAST];
92 /* Debugging macros
94 * DEBUGLVL()
95 * If the 'file specific' debug class level >= level OR the system-wide
96 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
97 * generate a header using the default macros for file, line, and
98 * function name. Returns True if the debug level was <= DEBUGLEVEL.
100 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
102 * DEBUGLVLC()
103 * If the 'macro specified' debug class level >= level OR the system-wide
104 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
105 * generate a header using the default macros for file, line, and
106 * function name. Returns True if the debug level was <= DEBUGLEVEL.
108 * Example: if( DEBUGLVL( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
110 * DEBUG()
111 * If the 'file specific' debug class level >= level OR the system-wide
112 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
113 * generate a header using the default macros for file, line, and
114 * function name. Each call to DEBUG() generates a new header *unless* the
115 * previous debug output was unterminated (i.e. no '\n').
116 * See debug.c:dbghdr() for more info.
118 * Example: DEBUG( 2, ("Some text and a valu %d.\n", value) );
120 * DEBUGC()
121 * If the 'macro specified' debug class level >= level OR the system-wide
122 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
123 * generate a header using the default macros for file, line, and
124 * function name. Each call to DEBUG() generates a new header *unless* the
125 * previous debug output was unterminated (i.e. no '\n').
126 * See debug.c:dbghdr() for more info.
128 * Example: DEBUG( DBGC_TDB, 2, ("Some text and a valu %d.\n", value) );
130 * DEBUGADD(), DEBUGADDC()
131 * Same as DEBUG() and DEBUGC() except the text is appended to the previous
132 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
133 * header.
135 * Example: DEBUGADD( 2, ("Some text and a valu %d.\n", value) );
136 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a valu %d.\n", value) );
138 * Note: If the debug class has not be redeined (see above) then the optimizer
139 * will remove the extra conditional test.
142 #define DEBUGLVL( level ) \
143 ( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
144 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
145 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
148 #define DEBUGLVLC( dbgc_class, level ) \
149 ( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
150 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
151 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
154 #define DEBUG( level, body ) \
155 (void)( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
156 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
157 && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
158 && (dbgtext body) )
160 #define DEBUGC( dbgc_class, level, body ) \
161 (void)( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
162 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
163 && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
164 && (dbgtext body) )
166 #define DEBUGADD( level, body ) \
167 (void)( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
168 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
169 && (dbgtext body) )
171 #define DEBUGADDC( dbgc_class, level, body ) \
172 (void)( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
173 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
174 && (dbgtext body) )
176 #endif