2 Unix SMB/CIFS implementation.
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 3 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, see <http://www.gnu.org/licenses/>.
23 #ifndef _SAMBA_DEBUG_H
24 #define _SAMBA_DEBUG_H
32 /* -------------------------------------------------------------------------- **
33 * Debugging code. See also debug.c
36 /* the maximum debug level to compile into the code. This assumes a good
37 optimising compiler that can remove unused code
38 for embedded or low-memory systems set this to a value like 2 to get
39 only important messages. This gives *much* smaller binaries
41 #ifndef MAX_DEBUG_LEVEL
42 #define MAX_DEBUG_LEVEL 1000
45 bool dbgtext_va(const char *, va_list ap
) PRINTF_ATTRIBUTE(1,0);
46 bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
47 bool dbghdrclass( int level
, int cls
, const char *location
, const char *func
);
48 bool dbghdr( int level
, const char *location
, const char *func
);
51 * Redefine DEBUGLEVEL because so we don't have to change every source file
52 * that *unnecessarily* references it.
54 #define DEBUGLEVEL DEBUGLEVEL_CLASS[DBGC_ALL]
57 * Define all new debug classes here. A class is represented by an entry in
58 * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
59 * old DEBUGLEVEL. Any source file that does NOT add the following lines:
62 * #define DBGC_CLASS DBGC_<your class name here>
64 * at the start of the file (after #include "includes.h") will default to
65 * using index zero, so it will behaive just like it always has.
67 #define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
70 #define DBGC_PRINTDRIVERS 2
73 #define DBGC_RPC_PARSE 5
74 #define DBGC_RPC_SRV 6
75 #define DBGC_RPC_CLI 7
79 #define DBGC_WINBIND 11
84 #define DBGC_LOCKING 16
87 #define DBGC_REGISTRY 19
88 #define DBGC_SCAVENGER 20
91 #define DBGC_TEVENT 23
92 #define DBGC_AUTH_AUDIT 24
93 #define DBGC_AUTH_AUDIT_JSON 25
94 #define DBGC_KERBEROS 26
95 #define DBGC_DRS_REPL 27
97 /* So you can define DBGC_CLASS before including debug.h */
99 #define DBGC_CLASS 0 /* override as shown above */
102 extern int *DEBUGLEVEL_CLASS
;
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.
112 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
115 * If the 'file specific' 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. Each call to DEBUG() generates a new header *unless* the
119 * previous debug output was unterminated (i.e. no '\n').
120 * See debug.c:dbghdr() for more info.
122 * Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
125 * If the 'macro specified' debug class level >= level OR the system-wide
126 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
127 * generate a header using the default macros for file, line, and
128 * function name. Each call to DEBUG() generates a new header *unless* the
129 * previous debug output was unterminated (i.e. no '\n').
130 * See debug.c:dbghdr() for more info.
132 * Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
134 * DEBUGADD(), DEBUGADDC()
135 * Same as DEBUG() and DEBUGC() except the text is appended to the previous
136 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
139 * Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
140 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
142 * Note: If the debug class has not be redeined (see above) then the optimizer
143 * will remove the extra conditional test.
150 /* these macros gain us a few percent of speed on gcc */
152 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
153 as its first argument */
155 #define likely(x) __builtin_expect(!!(x), 1)
158 #define unlikely(x) __builtin_expect(!!(x), 0)
162 #define likely(x) (x)
165 #define unlikely(x) (x)
169 #define CHECK_DEBUGLVL( level ) \
170 ( ((level) <= MAX_DEBUG_LEVEL) && \
171 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)))
173 #define CHECK_DEBUGLVLC( dbgc_class, level ) \
174 ( ((level) <= MAX_DEBUG_LEVEL) && \
175 unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)))
177 #define DEBUGLVL( level ) \
178 ( CHECK_DEBUGLVL(level) \
179 && dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ ) )
181 #define DEBUGLVLC( dbgc_class, level ) \
182 ( CHECK_DEBUGLVLC( dbgc_class, level ) \
183 && dbghdrclass( level, dbgc_class, __location__, __FUNCTION__ ) )
185 #define DEBUG( level, body ) \
186 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
187 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
188 && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
191 #define DEBUGC( dbgc_class, level, body ) \
192 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
193 unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)) \
194 && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
197 #define DEBUGADD( level, body ) \
198 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
199 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
202 #define DEBUGADDC( dbgc_class, level, body ) \
203 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
204 unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))) \
207 /* Print a separator to the debug log. */
208 #define DEBUGSEP(level)\
209 DEBUG((level),("===============================================================\n"))
211 /* Prefix messages with the function name */
212 #define DBG_PREFIX(level, body ) \
213 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
214 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
215 && (dbghdrclass(level, DBGC_CLASS, __location__, __func__ )) \
216 && (dbgtext("%s: ", __func__)) \
220 * Debug levels matching RFC 3164
222 #define DBGLVL_ERR 0 /* error conditions */
223 #define DBGLVL_WARNING 1 /* warning conditions */
224 #define DBGLVL_NOTICE 3 /* normal, but significant, condition */
225 #define DBGLVL_INFO 5 /* informational message */
226 #define DBGLVL_DEBUG 10 /* debug-level message */
228 #define DBG_ERR(...) DBG_PREFIX(DBGLVL_ERR, (__VA_ARGS__))
229 #define DBG_WARNING(...) DBG_PREFIX(DBGLVL_WARNING, (__VA_ARGS__))
230 #define DBG_NOTICE(...) DBG_PREFIX(DBGLVL_NOTICE, (__VA_ARGS__))
231 #define DBG_INFO(...) DBG_PREFIX(DBGLVL_INFO, (__VA_ARGS__))
232 #define DBG_DEBUG(...) DBG_PREFIX(DBGLVL_DEBUG, (__VA_ARGS__))
234 #define D_ERR(...) DEBUG(DBGLVL_ERR, (__VA_ARGS__))
235 #define D_WARNING(...) DEBUG(DBGLVL_WARNING, (__VA_ARGS__))
236 #define D_NOTICE(...) DEBUG(DBGLVL_NOTICE, (__VA_ARGS__))
237 #define D_INFO(...) DEBUG(DBGLVL_INFO, (__VA_ARGS__))
238 #define D_DEBUG(...) DEBUG(DBGLVL_DEBUG, (__VA_ARGS__))
240 /* The following definitions come from lib/debug.c */
242 /** Possible destinations for the debug log (in order of precedence -
243 * once set to DEBUG_FILE, it is not possible to reset to DEBUG_STDOUT
244 * for example. This makes it easy to override for debug to stderr on
245 * the command line, as the smb.conf cannot reset it back to
246 * file-based logging */
248 DEBUG_DEFAULT_STDERR
= 0,
249 DEBUG_DEFAULT_STDOUT
= 1,
256 struct debug_settings
{
259 bool debug_prefix_timestamp
;
260 bool debug_hires_timestamp
;
266 void setup_logging(const char *prog_name
, enum debug_logtype new_logtype
);
268 void gfree_debugsyms(void);
269 int debug_add_class(const char *classname
);
270 bool debug_parse_levels(const char *params_str
);
271 void debug_setup_talloc_log(void);
272 void debug_set_logfile(const char *name
);
273 void debug_set_settings(struct debug_settings
*settings
,
274 const char *logging_param
,
275 int syslog_level
, bool syslog_only
);
276 bool reopen_logs_internal( void );
277 void force_check_log_size( void );
278 bool need_to_check_log_size( void );
279 void check_log_size( void );
280 void dbgflush( void );
281 bool dbghdrclass(int level
, int cls
, const char *location
, const char *func
);
282 bool debug_get_output_is_stderr(void);
283 bool debug_get_output_is_stdout(void);
284 void debug_schedule_reopen_logs(void);
285 char *debug_list_class_names_and_levels(void);
287 typedef void (*debug_callback_fn
)(void *private_ptr
, int level
, const char *msg
);
290 Set a callback for all debug messages. Use in dlz_bind9 to push output to the bind logs
292 void debug_set_callback(void *private_ptr
, debug_callback_fn fn
);
294 char *debug_get_ringbuf(void);
295 size_t debug_get_ringbuf_size(void);
297 #endif /* _SAMBA_DEBUG_H */