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 2 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, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /* -------------------------------------------------------------------------- **
28 * Debugging code. See also debug.c
31 /* mkproto.awk has trouble with ifdef'd function definitions (it ignores
32 * the #ifdef directive and will read both definitions, thus creating two
33 * diffferent prototype declarations), so we must do these by hand.
35 /* I know the __attribute__ stuff is ugly, but it does ensure we get the
36 arguemnts to DEBUG() right. We have got them wrong too often in the
39 int Debug1( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
40 BOOL
dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
41 BOOL
dbghdr( int level
, const char *file
, const char *func
, int line
);
44 extern pstring debugf
;
46 /* If we have these macros, we can add additional info to the header. */
48 #ifdef HAVE_FUNCTION_MACRO
49 #define FUNCTION_MACRO (__FUNCTION__)
51 #define FUNCTION_MACRO ("")
55 * Redefine DEBUGLEVEL because so we don't have to change every source file
56 * that *unnecessarily* references it. Source files neeed not extern reference
57 * DEBUGLEVEL, as it's extern in includes.h (which all source files include).
58 * Eventually, all these references should be removed, and all references to
59 * DEBUGLEVEL should be references to DEBUGLEVEL_CLASS[DBGC_ALL]. This could
60 * still be through a macro still called DEBUGLEVEL. This cannot be done now
61 * because some references would expand incorrectly.
63 #define DEBUGLEVEL *debug_level
64 extern int DEBUGLEVEL
;
67 * Define all new debug classes here. A class is represented by an entry in
68 * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
69 * old DEBUGLEVEL. Any source file that does NOT add the following lines:
72 * #define DBGC_CLASS DBGC_<your class name here>
74 * at the start of the file (after #include "includes.h") will default to
75 * using index zero, so it will behaive just like it always has.
77 #define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
80 #define DBGC_PRINTDRIVERS 2
83 #define DBGC_RPC_PARSE 5
84 #define DBGC_RPC_SRV 6
85 #define DBGC_RPC_CLI 7
89 #define DBGC_WINBIND 11
92 /* So you can define DBGC_CLASS before including debug.h */
94 #define DBGC_CLASS 0 /* override as shown above */
97 extern int *DEBUGLEVEL_CLASS
;
98 extern BOOL
*DEBUGLEVEL_CLASS_ISSET
;
103 * If the 'file specific' 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( 2 ) ) dbgtext( "Some text.\n" );
111 * If the 'macro specified' 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. Returns True if the debug level was <= DEBUGLEVEL.
116 * Example: if( DEBUGLVLC( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
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. Each call to DEBUG() generates a new header *unless* the
123 * previous debug output was unterminated (i.e. no '\n').
124 * See debug.c:dbghdr() for more info.
126 * Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
129 * If the 'macro specified' debug class level >= level OR the system-wide
130 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
131 * generate a header using the default macros for file, line, and
132 * function name. Each call to DEBUG() generates a new header *unless* the
133 * previous debug output was unterminated (i.e. no '\n').
134 * See debug.c:dbghdr() for more info.
136 * Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
138 * DEBUGADD(), DEBUGADDC()
139 * Same as DEBUG() and DEBUGC() except the text is appended to the previous
140 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
143 * Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
144 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
146 * Note: If the debug class has not be redeined (see above) then the optimizer
147 * will remove the extra conditional test.
150 #define DEBUGLVL( level ) \
151 ( ((level) <= MAX_DEBUG_LEVEL) && \
152 ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
153 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
154 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
155 && dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) ) )
158 #define DEBUGLVLC( dbgc_class, level ) \
159 ( ((level) <= MAX_DEBUG_LEVEL) && \
160 ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
161 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
162 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
163 && dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) ) )
166 #define DEBUG( level, body ) \
167 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
168 ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
169 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
170 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
171 && (dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) )) \
174 #define DEBUGC( dbgc_class, level, body ) \
175 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
176 ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
177 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
178 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
179 && (dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) )) \
182 #define DEBUGADD( level, body ) \
183 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
184 ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
185 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
186 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
189 #define DEBUGADDC( dbgc_class, level, body ) \
190 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
191 ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
192 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
193 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \