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