2 Unix SMB/CIFS implementation.
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
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.
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.
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/>.
26 /* -------------------------------------------------------------------------- **
27 * Debugging code. See also debug.c
30 /* the maximum debug level to compile into the code. This assumes a good
31 optimising compiler that can remove unused code
32 for embedded or low-memory systems set this to a value like 2 to get
33 only important messages. This gives *much* smaller binaries
35 #ifndef MAX_DEBUG_LEVEL
36 #define MAX_DEBUG_LEVEL 1000
39 /* mkproto.awk has trouble with ifdef'd function definitions (it ignores
40 * the #ifdef directive and will read both definitions, thus creating two
41 * diffferent prototype declarations), so we must do these by hand.
43 /* I know the __attribute__ stuff is ugly, but it does ensure we get the
44 arguments to DEBUG() right. We have got them wrong too often in the
46 The PRINTFLIKE comment does the equivalent for SGI MIPSPro.
49 int Debug1( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
51 bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
52 bool dbghdrclass( int level, int cls, const char *location, const char *func);
53 bool dbghdr( int level, const char *location, const char *func);
55 #if defined(sgi) && (_COMPILER_VERSION >= 730)
56 #pragma mips_frequency_hint NEVER Debug1
57 #pragma mips_frequency_hint NEVER dbgtext
58 #pragma mips_frequency_hint NEVER dbghdrclass
59 #pragma mips_frequency_hint NEVER dbghdr
64 /* If we have these macros, we can add additional info to the header. */
66 #ifdef HAVE_FUNCTION_MACRO
67 #define FUNCTION_MACRO (__FUNCTION__)
69 #define FUNCTION_MACRO ("")
73 * Redefine DEBUGLEVEL because so we don't have to change every source file
74 * that *unnecessarily* references it. Source files neeed not extern reference
75 * DEBUGLEVEL, as it's extern in includes.h (which all source files include).
76 * Eventually, all these references should be removed, and all references to
77 * DEBUGLEVEL should be references to DEBUGLEVEL_CLASS[DBGC_ALL]. This could
78 * still be through a macro still called DEBUGLEVEL. This cannot be done now
79 * because some references would expand incorrectly.
81 #define DEBUGLEVEL *debug_level
82 extern int DEBUGLEVEL;
85 * Define all new debug classes here. A class is represented by an entry in
86 * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
87 * old DEBUGLEVEL. Any source file that does NOT add the following lines:
90 * #define DBGC_CLASS DBGC_<your class name here>
92 * at the start of the file (after #include "includes.h") will default to
93 * using index zero, so it will behaive just like it always has.
95 #define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
98 #define DBGC_PRINTDRIVERS 2
101 #define DBGC_RPC_PARSE 5
102 #define DBGC_RPC_SRV 6
103 #define DBGC_RPC_CLI 7
104 #define DBGC_PASSDB 8
107 #define DBGC_WINBIND 11
109 #define DBGC_IDMAP 13
110 #define DBGC_QUOTA 14
112 #define DBGC_LOCKING 16
113 #define DBGC_MSDFS 17
114 #define DBGC_DMAPI 18
115 #define DBGC_REGISTRY 19
117 /* So you can define DBGC_CLASS before including debug.h */
119 #define DBGC_CLASS 0 /* override as shown above */
122 extern int *DEBUGLEVEL_CLASS;
123 extern bool *DEBUGLEVEL_CLASS_ISSET;
128 * If the 'file specific' debug class level >= level OR the system-wide
129 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
130 * generate a header using the default macros for file, line, and
131 * function name. Returns True if the debug level was <= DEBUGLEVEL.
133 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
136 * If the 'macro specified' debug class level >= level OR the system-wide
137 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
138 * generate a header using the default macros for file, line, and
139 * function name. Returns True if the debug level was <= DEBUGLEVEL.
141 * Example: if( DEBUGLVLC( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
144 * If the 'file specific' debug class level >= level OR the system-wide
145 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
146 * generate a header using the default macros for file, line, and
147 * function name. Each call to DEBUG() generates a new header *unless* the
148 * previous debug output was unterminated (i.e. no '\n').
149 * See debug.c:dbghdr() for more info.
151 * Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
154 * If the 'macro specified' debug class level >= level OR the system-wide
155 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
156 * generate a header using the default macros for file, line, and
157 * function name. Each call to DEBUG() generates a new header *unless* the
158 * previous debug output was unterminated (i.e. no '\n').
159 * See debug.c:dbghdr() for more info.
161 * Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
163 * DEBUGADD(), DEBUGADDC()
164 * Same as DEBUG() and DEBUGC() except the text is appended to the previous
165 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
168 * Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
169 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
171 * Note: If the debug class has not be redeined (see above) then the optimizer
172 * will remove the extra conditional test.
179 /* these macros gain us a few percent of speed on gcc */
181 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
182 as its first argument */
184 #define likely(x) __builtin_expect(!!(x), 1)
187 #define unlikely(x) __builtin_expect(!!(x), 0)
191 #define likely(x) (x)
194 #define unlikely(x) (x)
198 #define CHECK_DEBUGLVL( level ) \
199 ( ((level) <= MAX_DEBUG_LEVEL) && \
200 unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
201 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
202 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) )
204 #define DEBUGLVL( level ) \
205 ( CHECK_DEBUGLVL(level) \
206 && dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO ) )
209 #define DEBUGLVLC( dbgc_class, level ) \
210 ( ((level) <= MAX_DEBUG_LEVEL) && \
211 unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
212 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
213 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
214 && dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO) )
217 #define DEBUG( level, body ) \
218 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
219 unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
220 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
221 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
222 && (dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO )) \
225 #define DEBUGC( dbgc_class, level, body ) \
226 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
227 unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
228 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
229 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
230 && (dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO)) \
233 #define DEBUGADD( level, body ) \
234 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
235 unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
236 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
237 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
240 #define DEBUGADDC( dbgc_class, level, body ) \
241 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
242 unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
243 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
244 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
247 /* Print a separator to the debug log. */
248 #define DEBUGSEP(level)\
249 DEBUG((level),("===============================================================\n"))