If a debug class was explicitly set to zero the debug system would not
[Samba/gbeck.git] / source / include / debug.h
blob0bde9e69cff390a070f97b2b5e4a44ecf98a2c0a
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
85 #define DBGC_SMB 4
86 #define DBGC_RPC 5
87 #define DBGC_RPC_HDR 6
88 #define DBGC_BDC 7
90 #define DBGC_LAST 8 /* MUST be last class value + 1 */
92 extern int DEBUGLEVEL_CLASS[DBGC_LAST];
93 extern BOOL DEBUGLEVEL_CLASS_ISSET[DBGC_LAST];
95 struct debuglevel_message {
96 int debuglevel_class[DBGC_LAST];
97 BOOL debuglevel_class_isset[DBGC_LAST];
100 /* Debugging macros
102 * DEBUGLVL()
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" );
110 * DEBUGLVLC()
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" );
118 * DEBUG()
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) );
128 * DEBUGC()
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
141 * header.
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 ( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
152 (!DEBUGLEVEL_CLASS[ DBGC_CLASS ] && \
153 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
154 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
157 #define DEBUGLVLC( dbgc_class, level ) \
158 ( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
159 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
160 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
161 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
164 #define DEBUG( level, body ) \
165 (void)( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
166 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
167 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
168 && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
169 && (dbgtext body) )
171 #define DEBUGC( dbgc_class, level, body ) \
172 (void)( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
173 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
174 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
175 && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
176 && (dbgtext body) )
178 #define DEBUGADD( level, body ) \
179 (void)( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
180 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
181 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
182 && (dbgtext body) )
184 #define DEBUGADDC( dbgc_class, level, body ) \
185 (void)( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
186 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
187 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
188 && (dbgtext body) )
190 #endif