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 /* 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.
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
37 The PRINTFLIKE comment does the equivalent for SGI MIPSPro.
40 int Debug1( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
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
);
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
55 /* If we have these macros, we can add additional info to the header. */
57 #ifdef HAVE_FUNCTION_MACRO
58 #define FUNCTION_MACRO (__FUNCTION__)
60 #define FUNCTION_MACRO ("")
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.
72 #define DEBUGLEVEL *debug_level
73 extern int DEBUGLEVEL
;
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:
81 * #define DBGC_CLASS DBGC_<your class name here>
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.
86 #define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
89 #define DBGC_PRINTDRIVERS 2
92 #define DBGC_RPC_PARSE 5
93 #define DBGC_RPC_SRV 6
94 #define DBGC_RPC_CLI 7
98 #define DBGC_WINBIND 11
100 #define DBGC_IDMAP 13
101 #define DBGC_QUOTA 14
103 #define DBGC_LOCKING 16
104 #define DBGC_MSDFS 17
105 #define DBGC_DMAPI 18
106 #define DBGC_REGISTRY 19
108 /* So you can define DBGC_CLASS before including debug.h */
110 #define DBGC_CLASS 0 /* override as shown above */
113 extern int *DEBUGLEVEL_CLASS
;
114 extern bool *DEBUGLEVEL_CLASS_ISSET
;
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.
124 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
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.
132 * Example: if( DEBUGLVLC( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
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.
142 * Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
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.
152 * Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
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
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) );
162 * Note: If the debug class has not be redeined (see above) then the optimizer
163 * will remove the extra conditional test.
170 /* these macros gain us a few percent of speed on gcc */
172 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
173 as its first argument */
175 #define likely(x) __builtin_expect(!!(x), 1)
178 #define unlikely(x) __builtin_expect(!!(x), 0)
182 #define likely(x) (x)
185 #define unlikely(x) (x)
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)) ) )
195 #define DEBUGLVL( level ) \
196 ( CHECK_DEBUGLVL(level) \
197 && dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO ) )
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) )
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 )) \
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)) \
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)) ) \
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)) ) \
238 /* Print a separator to the debug log. */
239 #define DEBUGSEP(level)\
240 DEBUG((level),("===============================================================\n"))