more debug classess activated
[gd/samba/.git] / source3 / include / debug.h
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
8    
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.
13    
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.
18    
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.
22 */
23
24 #ifndef _DEBUG_H
25 #define _DEBUG_H
26
27 /* -------------------------------------------------------------------------- **
28  * Debugging code.  See also debug.c
29  */
30
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.
34  */
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.
38  */
39 int  Debug1( char *, ... ) PRINTF_ATTRIBUTE(1,2);
40 BOOL dbgtext( char *, ... ) PRINTF_ATTRIBUTE(1,2);
41 BOOL dbghdr( int level, char *file, char *func, int line );
42
43 extern XFILE *dbf;
44 extern pstring debugf;
45
46 /* If we have these macros, we can add additional info to the header. */
47 #ifdef HAVE_FILE_MACRO
48 #define FILE_MACRO (__FILE__)
49 #else
50 #define FILE_MACRO ("")
51 #endif
52
53 #ifdef HAVE_FUNCTION_MACRO
54 #define FUNCTION_MACRO  (__FUNCTION__)
55 #else
56 #define FUNCTION_MACRO  ("")
57 #endif
58
59 /* 
60  * Redefine DEBUGLEVEL because so we don't have to change every source file
61  * that *unnecessarily* references it. Source files neeed not extern reference 
62  * DEBUGLEVEL, as it's extern in includes.h (which all source files include).
63  * Eventually, all these references should be removed, and all references to
64  * DEBUGLEVEL should be references to DEBUGLEVEL_CLASS[DBGC_ALL]. This could
65  * still be through a macro still called DEBUGLEVEL. This cannot be done now
66  * because some references would expand incorrectly.
67  */
68 #define DEBUGLEVEL *debug_level
69 extern int DEBUGLEVEL;
70
71 /*
72  * Define all new debug classes here. A class is represented by an entry in
73  * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
74  * old DEBUGLEVEL. Any source file that does NOT add the following lines:
75  *
76  *   #undef  DBGC_CLASS
77  *   #define DBGC_CLASS DBGC_<your class name here>
78  *
79  * at the start of the file (after #include "includes.h") will default to
80  * using index zero, so it will behaive just like it always has. 
81  */
82 #define DBGC_ALL                0 /* index equivalent to DEBUGLEVEL */
83
84 #define DBGC_TDB                1
85 #define DBGC_PRINTDRIVERS       2
86 #define DBGC_LANMAN             3
87 #define DBGC_SMB                4
88 #define DBGC_RPC_PARSE          5
89 #define DBGC_RPC_SRV            6
90 #define DBGC_RPC_CLI            7
91 #define DBGC_PASSDB             8
92 #define DBGC_AUTH               9
93 #define DBGC_WINBIND            10
94
95
96 /* So you can define DBGC_CLASS before including debug.h */
97 #ifndef DBGC_CLASS
98 #define DBGC_CLASS            0     /* override as shown above */
99 #endif
100
101 extern int  *DEBUGLEVEL_CLASS;
102 extern BOOL *DEBUGLEVEL_CLASS_ISSET;
103
104 /* Debugging macros
105  *
106  * DEBUGLVL()
107  *   If the 'file specific' debug class level >= level OR the system-wide 
108  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
109  *   generate a header using the default macros for file, line, and 
110  *   function name. Returns True if the debug level was <= DEBUGLEVEL.
111  * 
112  *   Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
113  *
114  * DEBUGLVLC()
115  *   If the 'macro specified' debug class level >= level OR the system-wide 
116  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 
117  *   generate a header using the default macros for file, line, and 
118  *   function name. Returns True if the debug level was <= DEBUGLEVEL.
119  * 
120  *   Example: if( DEBUGLVLC( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
121  *
122  * DEBUG()
123  *   If the 'file specific' debug class level >= level OR the system-wide 
124  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 
125  *   generate a header using the default macros for file, line, and 
126  *   function name. Each call to DEBUG() generates a new header *unless* the 
127  *   previous debug output was unterminated (i.e. no '\n').
128  *   See debug.c:dbghdr() for more info.
129  *
130  *   Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
131  *
132  * DEBUGC()
133  *   If the 'macro specified' debug class level >= level OR the system-wide 
134  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 
135  *   generate a header using the default macros for file, line, and 
136  *   function name. Each call to DEBUG() generates a new header *unless* the 
137  *   previous debug output was unterminated (i.e. no '\n').
138  *   See debug.c:dbghdr() for more info.
139  *
140  *   Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
141  *
142  *  DEBUGADD(), DEBUGADDC()
143  *    Same as DEBUG() and DEBUGC() except the text is appended to the previous
144  *    DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening 
145  *    header.
146  *
147  *    Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
148  *             DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
149  *
150  * Note: If the debug class has not be redeined (see above) then the optimizer 
151  * will remove the extra conditional test.
152  */
153
154 #define DEBUGLVL( level ) \
155   ( ((level) <= MAX_DEBUG_LEVEL) && \
156      ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
157      (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
158       DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
159    && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
160
161
162 #define DEBUGLVLC( dbgc_class, level ) \
163   ( ((level) <= MAX_DEBUG_LEVEL) && \
164      ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
165      (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
166       DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
167    && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
168
169
170 #define DEBUG( level, body ) \
171   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
172            ((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) )
177
178 #define DEBUGC( dbgc_class, level, body ) \
179   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
180            ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
181            (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
182             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
183        && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
184        && (dbgtext body) )
185
186 #define DEBUGADD( level, body ) \
187   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
188            ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
189            (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
190             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
191        && (dbgtext body) )
192
193 #define DEBUGADDC( dbgc_class, level, body ) \
194   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
195           ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
196            (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
197             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
198        && (dbgtext body) )
199
200 #endif