r1383: sync from 3.0 tree
[Samba.git] / source / include / debug.h
blob05a9a3f0c523426deb900b243f83514045dd5621
1 /*
2 Unix SMB/CIFS implementation.
3 SMB debug stuff
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.
24 #ifndef _DEBUG_H
25 #define _DEBUG_H
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 arguments to DEBUG() right. We have got them wrong too often in the
37 past.
38 The PRINTFLIKE comment does the equivalent for SGI MIPSPro.
40 /* PRINTFLIKE1 */
41 int Debug1( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
42 /* PRINTFLIKE1 */
43 BOOL dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
44 BOOL dbghdr( int level, const char *file, const char *func, int line );
46 extern XFILE *dbf;
47 extern pstring debugf;
49 /* If we have these macros, we can add additional info to the header. */
51 #ifdef HAVE_FUNCTION_MACRO
52 #define FUNCTION_MACRO (__FUNCTION__)
53 #else
54 #define FUNCTION_MACRO ("")
55 #endif
57 /*
58 * Redefine DEBUGLEVEL because so we don't have to change every source file
59 * that *unnecessarily* references it. Source files neeed not extern reference
60 * DEBUGLEVEL, as it's extern in includes.h (which all source files include).
61 * Eventually, all these references should be removed, and all references to
62 * DEBUGLEVEL should be references to DEBUGLEVEL_CLASS[DBGC_ALL]. This could
63 * still be through a macro still called DEBUGLEVEL. This cannot be done now
64 * because some references would expand incorrectly.
66 #define DEBUGLEVEL *debug_level
67 extern int DEBUGLEVEL;
70 * Define all new debug classes here. A class is represented by an entry in
71 * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
72 * old DEBUGLEVEL. Any source file that does NOT add the following lines:
74 * #undef DBGC_CLASS
75 * #define DBGC_CLASS DBGC_<your class name here>
77 * at the start of the file (after #include "includes.h") will default to
78 * using index zero, so it will behaive just like it always has.
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_PARSE 5
87 #define DBGC_RPC_SRV 6
88 #define DBGC_RPC_CLI 7
89 #define DBGC_PASSDB 8
90 #define DBGC_SAM 9
91 #define DBGC_AUTH 10
92 #define DBGC_WINBIND 11
93 #define DBGC_VFS 12
94 #define DBGC_IDMAP 13
95 #define DBGC_QUOTA 14
96 #define DBGC_ACLS 15
98 /* So you can define DBGC_CLASS before including debug.h */
99 #ifndef DBGC_CLASS
100 #define DBGC_CLASS 0 /* override as shown above */
101 #endif
103 extern int *DEBUGLEVEL_CLASS;
104 extern BOOL *DEBUGLEVEL_CLASS_ISSET;
106 /* Debugging macros
108 * DEBUGLVL()
109 * If the 'file specific' debug class level >= level OR the system-wide
110 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
111 * generate a header using the default macros for file, line, and
112 * function name. Returns True if the debug level was <= DEBUGLEVEL.
114 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
116 * DEBUGLVLC()
117 * If the 'macro specified' debug class level >= level OR the system-wide
118 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
119 * generate a header using the default macros for file, line, and
120 * function name. Returns True if the debug level was <= DEBUGLEVEL.
122 * Example: if( DEBUGLVLC( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
124 * DEBUG()
125 * If the 'file specific' debug class level >= level OR the system-wide
126 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
127 * generate a header using the default macros for file, line, and
128 * function name. Each call to DEBUG() generates a new header *unless* the
129 * previous debug output was unterminated (i.e. no '\n').
130 * See debug.c:dbghdr() for more info.
132 * Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
134 * DEBUGC()
135 * If the 'macro specified' 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: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
144 * DEBUGADD(), DEBUGADDC()
145 * Same as DEBUG() and DEBUGC() except the text is appended to the previous
146 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
147 * header.
149 * Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
150 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
152 * Note: If the debug class has not be redeined (see above) then the optimizer
153 * will remove the extra conditional test.
156 #define DEBUGLVL( level ) \
157 ( ((level) <= MAX_DEBUG_LEVEL) && \
158 ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
159 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
160 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
161 && dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) ) )
164 #define DEBUGLVLC( dbgc_class, level ) \
165 ( ((level) <= MAX_DEBUG_LEVEL) && \
166 ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
167 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
168 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
169 && dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) ) )
172 #define DEBUG( level, body ) \
173 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
174 ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
175 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
176 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
177 && (dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) )) \
178 && (dbgtext body) )
180 #define DEBUGC( dbgc_class, level, body ) \
181 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
182 ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
183 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
184 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
185 && (dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) )) \
186 && (dbgtext body) )
188 #define DEBUGADD( level, body ) \
189 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
190 ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
191 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
192 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
193 && (dbgtext body) )
195 #define DEBUGADDC( dbgc_class, level, body ) \
196 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
197 ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
198 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
199 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
200 && (dbgtext body) )
202 #endif