RIP BOOL. Convert BOOL -> bool. I found a few interesting
[tprouty/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 3 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, see <http://www.gnu.org/licenses/>.
21 */
22
23 #ifndef _DEBUG_H
24 #define _DEBUG_H
25
26 /* -------------------------------------------------------------------------- **
27  * Debugging code.  See also debug.c
28  */
29
30 /* mkproto.awk has trouble with ifdef'd function definitions (it ignores
31  * the #ifdef directive and will read both definitions, thus creating two
32  * diffferent prototype declarations), so we must do these by hand.
33  */
34 /* I know the __attribute__ stuff is ugly, but it does ensure we get the 
35    arguments to DEBUG() right. We have got them wrong too often in the 
36    past.
37    The PRINTFLIKE comment does the equivalent for SGI MIPSPro.
38  */
39 /* PRINTFLIKE1 */
40 int  Debug1( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
41 /* PRINTFLIKE1 */
42 bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
43 bool dbghdr( int level, int cls, const char *file, const char *func, int line );
44
45 #if defined(sgi) && (_COMPILER_VERSION >= 730)
46 #pragma mips_frequency_hint NEVER Debug1
47 #pragma mips_frequency_hint NEVER dbgtext
48 #pragma mips_frequency_hint NEVER dbghdr
49 #endif
50
51 extern XFILE *dbf;
52 extern pstring debugf;
53
54 /* If we have these macros, we can add additional info to the header. */
55
56 #ifdef HAVE_FUNCTION_MACRO
57 #define FUNCTION_MACRO  (__FUNCTION__)
58 #else
59 #define FUNCTION_MACRO  ("")
60 #endif
61
62 /* 
63  * Redefine DEBUGLEVEL because so we don't have to change every source file
64  * that *unnecessarily* references it. Source files neeed not extern reference 
65  * DEBUGLEVEL, as it's extern in includes.h (which all source files include).
66  * Eventually, all these references should be removed, and all references to
67  * DEBUGLEVEL should be references to DEBUGLEVEL_CLASS[DBGC_ALL]. This could
68  * still be through a macro still called DEBUGLEVEL. This cannot be done now
69  * because some references would expand incorrectly.
70  */
71 #define DEBUGLEVEL *debug_level
72 extern int DEBUGLEVEL;
73
74 /*
75  * Define all new debug classes here. A class is represented by an entry in
76  * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
77  * old DEBUGLEVEL. Any source file that does NOT add the following lines:
78  *
79  *   #undef  DBGC_CLASS
80  *   #define DBGC_CLASS DBGC_<your class name here>
81  *
82  * at the start of the file (after #include "includes.h") will default to
83  * using index zero, so it will behaive just like it always has. 
84  */
85 #define DBGC_ALL                0 /* index equivalent to DEBUGLEVEL */
86
87 #define DBGC_TDB                1
88 #define DBGC_PRINTDRIVERS       2
89 #define DBGC_LANMAN             3
90 #define DBGC_SMB                4
91 #define DBGC_RPC_PARSE          5
92 #define DBGC_RPC_SRV            6
93 #define DBGC_RPC_CLI            7
94 #define DBGC_PASSDB             8
95 #define DBGC_SAM                9
96 #define DBGC_AUTH               10
97 #define DBGC_WINBIND            11
98 #define DBGC_VFS                12
99 #define DBGC_IDMAP              13
100 #define DBGC_QUOTA              14
101 #define DBGC_ACLS               15
102 #define DBGC_LOCKING            16
103 #define DBGC_MSDFS              17
104 #define DBGC_DMAPI              18
105 #define DBGC_REGISTRY           19
106
107 /* So you can define DBGC_CLASS before including debug.h */
108 #ifndef DBGC_CLASS
109 #define DBGC_CLASS            0     /* override as shown above */
110 #endif
111
112 extern int  *DEBUGLEVEL_CLASS;
113 extern bool *DEBUGLEVEL_CLASS_ISSET;
114
115 /* Debugging macros
116  *
117  * DEBUGLVL()
118  *   If the 'file specific' debug class level >= level OR the system-wide 
119  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
120  *   generate a header using the default macros for file, line, and 
121  *   function name. Returns True if the debug level was <= DEBUGLEVEL.
122  * 
123  *   Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
124  *
125  * DEBUGLVLC()
126  *   If the 'macro specified' debug class level >= level OR the system-wide 
127  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 
128  *   generate a header using the default macros for file, line, and 
129  *   function name. Returns True if the debug level was <= DEBUGLEVEL.
130  * 
131  *   Example: if( DEBUGLVLC( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
132  *
133  * DEBUG()
134  *   If the 'file specific' debug class level >= level OR the system-wide 
135  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 
136  *   generate a header using the default macros for file, line, and 
137  *   function name. Each call to DEBUG() generates a new header *unless* the 
138  *   previous debug output was unterminated (i.e. no '\n').
139  *   See debug.c:dbghdr() for more info.
140  *
141  *   Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
142  *
143  * DEBUGC()
144  *   If the 'macro specified' debug class level >= level OR the system-wide 
145  *   DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 
146  *   generate a header using the default macros for file, line, and 
147  *   function name. Each call to DEBUG() generates a new header *unless* the 
148  *   previous debug output was unterminated (i.e. no '\n').
149  *   See debug.c:dbghdr() for more info.
150  *
151  *   Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
152  *
153  *  DEBUGADD(), DEBUGADDC()
154  *    Same as DEBUG() and DEBUGC() except the text is appended to the previous
155  *    DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening 
156  *    header.
157  *
158  *    Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
159  *             DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
160  *
161  * Note: If the debug class has not be redeined (see above) then the optimizer 
162  * will remove the extra conditional test.
163  */
164
165 #define DEBUGLVL( level ) \
166   ( ((level) <= MAX_DEBUG_LEVEL) && \
167      ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
168      (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
169       DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
170    && dbghdr( level, DBGC_CLASS, __FILE__, FUNCTION_MACRO, (__LINE__) ) )
171
172
173 #define DEBUGLVLC( dbgc_class, level ) \
174   ( ((level) <= MAX_DEBUG_LEVEL) && \
175      ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
176      (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
177       DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
178    && dbghdr( level, DBGC_CLASS, __FILE__, FUNCTION_MACRO, (__LINE__) ) )
179
180
181 #define DEBUG( level, body ) \
182   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
183            ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
184            (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
185             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
186        && (dbghdr( level, DBGC_CLASS, __FILE__, FUNCTION_MACRO, (__LINE__) )) \
187        && (dbgtext body) )
188
189 #define DEBUGC( dbgc_class, level, body ) \
190   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
191            ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
192            (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
193             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
194        && (dbghdr( level, DBGC_CLASS, __FILE__, FUNCTION_MACRO, (__LINE__) )) \
195        && (dbgtext body) )
196
197 #define DEBUGADD( level, body ) \
198   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
199            ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))||  \
200            (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
201             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
202        && (dbgtext body) )
203
204 #define DEBUGADDC( dbgc_class, level, body ) \
205   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
206           ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))||  \
207            (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
208             DEBUGLEVEL_CLASS[ DBGC_ALL   ] >= (level))  ) \
209        && (dbgtext body) )
210
211 /* Print a separator to the debug log. */
212 #define DEBUGSEP(level)\
213         DEBUG((level),("===============================================================\n"))
214
215 #endif