2 Unix SMB/Netbios implementation.
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.
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
40 int Debug1( char *, ... ) PRINTF_ATTRIBUTE(1,2);
41 BOOL dbgtext( char *, ... ) PRINTF_ATTRIBUTE(1,2);
45 /* If we have these macros, we can add additional info to the header. */
46 #ifdef HAVE_FILE_MACRO
47 #define FILE_MACRO (__FILE__)
49 #define FILE_MACRO ("")
52 #ifdef HAVE_FUNCTION_MACRO
53 #define FUNCTION_MACRO (__FUNCTION__)
55 #define FUNCTION_MACRO ("")
59 * Redefine DEBUGLEVEL because so we don't have to change every source file
60 * that *unnecessarily* references it. Source files neeed not extern reference
61 * DEBUGLEVEL, as it's extern in includes.h (which all source files include).
62 * Eventually, all these references should be removed, and all references to
63 * DEBUGLEVEL should be references to DEBUGLEVEL_CLASS[DBGC_ALL]. This could
64 * still be through a macro still called DEBUGLEVEL. This cannot be done now
65 * because some references would expand incorrectly.
67 #define DEBUGLEVEL *debug_level
71 * Define all new debug classes here. A class is represented by an entry in
72 * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
73 * old DEBUGLEVEL. Any source file that does NOT add the following lines:
76 * #define DBGC_CLASS DBGC_<your class name here>
78 * at the start of the file (after #include "includes.h") will default to
79 * using index zero, so it will behaive just like it always has.
81 #define DBGC_CLASS 0 /* override as shown above */
82 #define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
85 #define DBGC_PRINTDRIVERS 2
89 #define DBGC_RPC_HDR 6
92 #define DBGC_LAST 8 /* MUST be last class value + 1 */
94 extern int DEBUGLEVEL_CLASS[DBGC_LAST];
95 extern BOOL DEBUGLEVEL_CLASS_ISSET[DBGC_LAST];
97 struct debuglevel_message {
98 int debuglevel_class[DBGC_LAST];
99 BOOL debuglevel_class_isset[DBGC_LAST];
105 * If the 'file specific' debug class level >= level OR the system-wide
106 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
107 * generate a header using the default macros for file, line, and
108 * function name. Returns True if the debug level was <= DEBUGLEVEL.
110 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
113 * If the 'macro specified' debug class level >= level OR the system-wide
114 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
115 * generate a header using the default macros for file, line, and
116 * function name. Returns True if the debug level was <= DEBUGLEVEL.
118 * Example: if( DEBUGLVLC( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
121 * If the 'file specific' 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( 2, ("Some text and a value %d.\n", value) );
131 * If the 'macro specified' debug class level >= level OR the system-wide
132 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
133 * generate a header using the default macros for file, line, and
134 * function name. Each call to DEBUG() generates a new header *unless* the
135 * previous debug output was unterminated (i.e. no '\n').
136 * See debug.c:dbghdr() for more info.
138 * Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
140 * DEBUGADD(), DEBUGADDC()
141 * Same as DEBUG() and DEBUGC() except the text is appended to the previous
142 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
145 * Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
146 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
148 * Note: If the debug class has not be redeined (see above) then the optimizer
149 * will remove the extra conditional test.
152 #define DEBUGLVL( level ) \
153 ( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
154 (!DEBUGLEVEL_CLASS[ DBGC_CLASS ] && \
155 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
156 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
159 #define DEBUGLVLC( dbgc_class, level ) \
160 ( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
161 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
162 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
163 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
166 #define DEBUG( level, body ) \
167 (void)( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
168 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
169 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
170 && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
173 #define DEBUGC( dbgc_class, level, body ) \
174 (void)( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
175 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
176 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
177 && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
180 #define DEBUGADD( level, body ) \
181 (void)( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
182 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
183 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
186 #define DEBUGADDC( dbgc_class, level, body ) \
187 (void)( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
188 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
189 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \