Fix a small typo in a comment and pretty it up a bit.
[Samba/gebeck_regimport.git] / source3 / include / debug.h
blob70f9f7706de7a2c8bd732146b811791933252d43
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 arguemnts to DEBUG() right. We have got them wrong too often in the
37 past.
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 );
43 extern XFILE *dbf;
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__)
50 #else
51 #define FUNCTION_MACRO ("")
52 #endif
54 /*
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:
71 * #undef DBGC_CLASS
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 */
79 #define DBGC_TDB 1
80 #define DBGC_PRINTDRIVERS 2
81 #define DBGC_LANMAN 3
82 #define DBGC_SMB 4
83 #define DBGC_RPC_PARSE 5
84 #define DBGC_RPC_SRV 6
85 #define DBGC_RPC_CLI 7
86 #define DBGC_PASSDB 8
87 #define DBGC_SAM 9
88 #define DBGC_AUTH 10
89 #define DBGC_WINBIND 11
90 #define DBGC_VFS 12
91 #define DBGC_IDMAP 13
93 /* So you can define DBGC_CLASS before including debug.h */
94 #ifndef DBGC_CLASS
95 #define DBGC_CLASS 0 /* override as shown above */
96 #endif
98 extern int *DEBUGLEVEL_CLASS;
99 extern BOOL *DEBUGLEVEL_CLASS_ISSET;
101 /* Debugging macros
103 * DEBUGLVL()
104 * If the 'file specific' debug class level >= level OR the system-wide
105 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
106 * generate a header using the default macros for file, line, and
107 * function name. Returns True if the debug level was <= DEBUGLEVEL.
109 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
111 * DEBUGLVLC()
112 * If the 'macro specified' debug class level >= level OR the system-wide
113 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
114 * generate a header using the default macros for file, line, and
115 * function name. Returns True if the debug level was <= DEBUGLEVEL.
117 * Example: if( DEBUGLVLC( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
119 * DEBUG()
120 * If the 'file specific' debug class level >= level OR the system-wide
121 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
122 * generate a header using the default macros for file, line, and
123 * function name. Each call to DEBUG() generates a new header *unless* the
124 * previous debug output was unterminated (i.e. no '\n').
125 * See debug.c:dbghdr() for more info.
127 * Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
129 * DEBUGC()
130 * If the 'macro specified' debug class level >= level OR the system-wide
131 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
132 * generate a header using the default macros for file, line, and
133 * function name. Each call to DEBUG() generates a new header *unless* the
134 * previous debug output was unterminated (i.e. no '\n').
135 * See debug.c:dbghdr() for more info.
137 * Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
139 * DEBUGADD(), DEBUGADDC()
140 * Same as DEBUG() and DEBUGC() except the text is appended to the previous
141 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
142 * header.
144 * Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
145 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
147 * Note: If the debug class has not be redeined (see above) then the optimizer
148 * will remove the extra conditional test.
151 #define DEBUGLVL( level ) \
152 ( ((level) <= MAX_DEBUG_LEVEL) && \
153 ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
154 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
155 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
156 && dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) ) )
159 #define DEBUGLVLC( dbgc_class, level ) \
160 ( ((level) <= MAX_DEBUG_LEVEL) && \
161 ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
162 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
163 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
164 && dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) ) )
167 #define DEBUG( level, body ) \
168 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
169 ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
170 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
171 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
172 && (dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) )) \
173 && (dbgtext body) )
175 #define DEBUGC( dbgc_class, level, body ) \
176 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
177 ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
178 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
179 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
180 && (dbghdr( level, __FILE__, FUNCTION_MACRO, (__LINE__) )) \
181 && (dbgtext body) )
183 #define DEBUGADD( level, body ) \
184 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
185 ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
186 (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
187 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
188 && (dbgtext body) )
190 #define DEBUGADDC( dbgc_class, level, body ) \
191 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
192 ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
193 (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
194 DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
195 && (dbgtext body) )
197 #endif