make proto
[Samba/gbeck.git] / source / include / debug.h
blobd2c3b1d37ef44d8eac5443a3ae1bb03dd3d64636
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
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.
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.
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.
25 #ifndef _DEBUG_H
26 #define _DEBUG_H
28 /* -------------------------------------------------------------------------- **
29 * Debugging code. See also debug.c
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.
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.
40 #ifdef HAVE_STDARG_H
41 int Debug1( char *, ... )
42 #ifdef __GNUC__
43 __attribute__ ((format (__printf__, 1, 2)))
44 #endif
46 BOOL dbgtext( char *, ... )
47 #ifdef __GNUC__
48 __attribute__ ((format (__printf__, 1, 2)))
49 #endif
51 #else
52 int Debug1();
53 BOOL dbgtext();
54 #endif
56 /* If we have these macros, we can add additional info to the header. */
57 #ifdef HAVE_FILE_MACRO
58 #define FILE_MACRO (__FILE__)
59 #else
60 #define FILE_MACRO ("")
61 #endif
63 #ifdef HAVE_FUNCTION_MACRO
64 #define FUNCTION_MACRO (__FUNCTION__)
65 #else
66 #define FUNCTION_MACRO ("")
67 #endif
69 /*
70 * Redefine DEBUGLEVEL because so we don't have to change every source file
71 * that *unnecessarily* references it. Source files neeed not extern reference
72 * DEBUGLEVEL, as it's extern in includes.h (which all source files include).
73 * Eventually, all these references should be removed, and all references to
74 * DEBUGLEVEL should be references to DEBUGLEVEL_CLASS[DBGC_ALL]. This could
75 * still be through a macro still called DEBUGLEVEL. This cannot be done now
76 * because some references would expand incorrectly.
78 #define DEBUGLEVEL *debug_level
82 * Define all new debug classes here. A class is represented by an entry in
83 * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
84 * old DEBUGLEVEL. Any source file that does NOT add the following lines:
86 * #undef DBGC_CLASS
87 * #define DBGC_CLASS DBGC_<your class name here>
89 * at the start of the file (after #include "includes.h") will default to
90 * using index zero, so it will behaive just like it always has.
92 #define DBGC_CLASS 0 /* override as shown above */
93 #define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
95 #define DBGC_TDB 1
96 #define DBGC_PRINTDRIVERS 2
97 #define DBGC_LANMAN 3
99 #define DBGC_LAST 4 /* MUST be last class value + 1 */
102 extern int DEBUGLEVEL_CLASS[DBGC_LAST];
105 /* Debugging macros
107 * DEBUGLVL()
108 * If the 'file specific' debug class level >= level OR the system-wide
109 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
110 * generate a header using the default macros for file, line, and
111 * function name. Returns True if the debug level was <= DEBUGLEVEL.
113 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
115 * DEBUGLVLC()
116 * If the 'macro specified' debug class level >= level OR the system-wide
117 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
118 * generate a header using the default macros for file, line, and
119 * function name. Returns True if the debug level was <= DEBUGLEVEL.
121 * Example: if( DEBUGLVL( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
123 * DEBUG()
124 * If the 'file specific' debug class level >= level OR the system-wide
125 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
126 * generate a header using the default macros for file, line, and
127 * function name. Each call to DEBUG() generates a new header *unless* the
128 * previous debug output was unterminated (i.e. no '\n').
129 * See debug.c:dbghdr() for more info.
131 * Example: DEBUG( 2, ("Some text and a valu %d.\n", value) );
133 * DEBUGC()
134 * If the 'macro specified' 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.
141 * Example: DEBUG( DBGC_TDB, 2, ("Some text and a valu %d.\n", value) );
143 * DEBUGADD(), DEBUGADDC()
144 * Same as DEBUG() and DEBUGC() except the text is appended to the previous
145 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
146 * header.
148 * Example: DEBUGADD( 2, ("Some text and a valu %d.\n", value) );
149 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a valu %d.\n", value) );
151 * Note: If the debug class has not be redeined (see above) then the optimizer
152 * will remove the extra conditional test.
155 #define DEBUGLVL( level ) \
156 ( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
157 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
158 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
161 #define DEBUGLVLC( dbgc_class, level ) \
162 ( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
163 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
164 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
167 #define DEBUG( level, body ) \
168 (void)( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
169 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
170 && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
171 && (dbgtext body) )
173 #define DEBUGC( dbgc_class, level, body ) \
174 (void)( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
175 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
176 && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
177 && (dbgtext body) )
179 #define DEBUGADD( level, body ) \
180 (void)( ((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
181 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
182 && (dbgtext body) )
184 #define DEBUGADDC( dbgc_class, level, body ) \
185 (void)( ((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
186 (DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
187 && (dbgtext body) )
189 #endif