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);
50 * Define all new debug classes here. A class is represented by an entry in
51 * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
52 * old DEBUGLEVEL. Any source file that does NOT add the following lines:
55 * #define DBGC_CLASS DBGC_<your class name here>
57 * at the start of the file (after #include "includes.h") will default to
58 * using index zero, so it will behaive just like it always has.
60 #define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
63 #define DBGC_PRINTDRIVERS 2
66 #define DBGC_RPC_PARSE 5
67 #define DBGC_RPC_SRV 6
68 #define DBGC_RPC_CLI 7
72 #define DBGC_WINBIND 11
77 #define DBGC_LOCKING 16
80 #define DBGC_REGISTRY 19
81 #define DBGC_SCAVENGER 20
84 #define DBGC_TEVENT 23
85 #define DBGC_AUTH_AUDIT 24
86 #define DBGC_AUTH_AUDIT_JSON 25
87 #define DBGC_KERBEROS 26
88 #define DBGC_DRS_REPL 27
90 #define DBGC_SMB2_CREDITS 29
91 #define DBGC_DSDB_AUDIT 30
92 #define DBGC_DSDB_AUDIT_JSON 31
93 #define DBGC_DSDB_PWD_AUDIT 32
94 #define DBGC_DSDB_PWD_AUDIT_JSON 33
95 #define DBGC_DSDB_TXN_AUDIT 34
96 #define DBGC_DSDB_TXN_AUDIT_JSON 35
97 #define DBGC_DSDB_GROUP_AUDIT 36
98 #define DBGC_DSDB_GROUP_AUDIT_JSON 37
100 /* So you can define DBGC_CLASS before including debug.h */
102 #define DBGC_CLASS 0 /* override as shown above */
105 #define DEBUGLEVEL debuglevel_get()
107 #define debuglevel_get() debuglevel_get_class(DBGC_ALL)
108 #define debuglevel_set(lvl) debuglevel_set_class(DBGC_ALL, (lvl))
113 * If the 'file specific' 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.
118 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
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.
128 * Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
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.
138 * Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
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
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) );
148 * Note: If the debug class has not be redeined (see above) then the optimizer
149 * will remove the extra conditional test.
156 /* these macros gain us a few percent of speed on gcc */
158 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
159 as its first argument */
161 #define likely(x) __builtin_expect(!!(x), 1)
164 #define unlikely(x) __builtin_expect(!!(x), 0)
168 #define likely(x) (x)
171 #define unlikely(x) (x)
175 int debuglevel_get_class(size_t idx);
176 void debuglevel_set_class(size_t idx, int level);
178 #define CHECK_DEBUGLVL( level ) \
179 ( ((level) <= MAX_DEBUG_LEVEL) && \
180 unlikely(debuglevel_get_class(DBGC_CLASS) >= (level)))
182 #define CHECK_DEBUGLVLC( dbgc_class, level ) \
183 ( ((level) <= MAX_DEBUG_LEVEL) && \
184 unlikely(debuglevel_get_class(dbgc_class) >= (level)))
186 #define DEBUGLVL( level ) \
187 ( CHECK_DEBUGLVL(level) \
188 && dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ ) )
190 #define DEBUGLVLC( dbgc_class, level ) \
191 ( CHECK_DEBUGLVLC( dbgc_class, level ) \
192 && dbghdrclass( level, dbgc_class, __location__, __FUNCTION__ ) )
194 #define DEBUG( level, body ) \
195 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
196 unlikely(debuglevel_get_class(DBGC_CLASS) >= (level)) \
197 && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
200 #define DEBUGC( dbgc_class, level, body ) \
201 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
202 unlikely(debuglevel_get_class(dbgc_class) >= (level)) \
203 && (dbghdrclass( level, dbgc_class, __location__, __FUNCTION__ )) \
206 #define DEBUGADD( level, body ) \
207 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
208 unlikely(debuglevel_get_class(DBGC_CLASS) >= (level)) \
211 #define DEBUGADDC( dbgc_class, level, body ) \
212 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
213 unlikely((debuglevel_get_class(dbgc_class) >= (level))) \
216 /* Print a separator to the debug log. */
217 #define DEBUGSEP(level)\
218 DEBUG((level),("===============================================================\n"))
220 /* Prefix messages with the function name */
221 #define DBG_PREFIX(level, body ) \
222 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
223 unlikely(debuglevel_get_class(DBGC_CLASS) >= (level)) \
224 && (dbghdrclass(level, DBGC_CLASS, __location__, __func__ )) \
225 && (dbgtext("%s: ", __func__)) \
228 /* Prefix messages with the function name - class specific */
229 #define DBGC_PREFIX(dbgc_class, level, body ) \
230 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
231 unlikely(debuglevel_get_class(dbgc_class) >= (level)) \
232 && (dbghdrclass(level, dbgc_class, __location__, __func__ )) \
233 && (dbgtext("%s: ", __func__)) \
237 * Debug levels matching RFC 3164
239 #define DBGLVL_ERR 0 /* error conditions */
240 #define DBGLVL_WARNING 1 /* warning conditions */
241 #define DBGLVL_NOTICE 3 /* normal, but significant, condition */
242 #define DBGLVL_INFO 5 /* informational message */
243 #define DBGLVL_DEBUG 10 /* debug-level message */
245 #define DBG_ERR(...) DBG_PREFIX(DBGLVL_ERR, (__VA_ARGS__))
246 #define DBG_WARNING(...) DBG_PREFIX(DBGLVL_WARNING, (__VA_ARGS__))
247 #define DBG_NOTICE(...) DBG_PREFIX(DBGLVL_NOTICE, (__VA_ARGS__))
248 #define DBG_INFO(...) DBG_PREFIX(DBGLVL_INFO, (__VA_ARGS__))
249 #define DBG_DEBUG(...) DBG_PREFIX(DBGLVL_DEBUG, (__VA_ARGS__))
251 #define DBGC_ERR(dbgc_class, ...) DBGC_PREFIX(dbgc_class, \
252 DBGLVL_ERR, (__VA_ARGS__))
253 #define DBGC_WARNING(dbgc_class, ...) DBGC_PREFIX(dbgc_class, \
254 DBGLVL_WARNING, (__VA_ARGS__))
255 #define DBGC_NOTICE(dbgc_class, ...) DBGC_PREFIX(dbgc_class, \
256 DBGLVL_NOTICE, (__VA_ARGS__))
257 #define DBGC_INFO(dbgc_class, ...) DBGC_PREFIX(dbgc_class, \
258 DBGLVL_INFO, (__VA_ARGS__))
259 #define DBGC_DEBUG(dbgc_class, ...) DBGC_PREFIX(dbgc_class, \
260 DBGLVL_DEBUG, (__VA_ARGS__))
262 #define D_ERR(...) DEBUG(DBGLVL_ERR, (__VA_ARGS__))
263 #define D_WARNING(...) DEBUG(DBGLVL_WARNING, (__VA_ARGS__))
264 #define D_NOTICE(...) DEBUG(DBGLVL_NOTICE, (__VA_ARGS__))
265 #define D_INFO(...) DEBUG(DBGLVL_INFO, (__VA_ARGS__))
266 #define D_DEBUG(...) DEBUG(DBGLVL_DEBUG, (__VA_ARGS__))
268 #define DC_ERR(...) DEBUGC(dbgc_class, \
269 DBGLVL_ERR, (__VA_ARGS__))
270 #define DC_WARNING(...) DEBUGC(dbgc_class, \
271 DBGLVL_WARNING, (__VA_ARGS__))
272 #define DC_NOTICE(...) DEBUGC(dbgc_class, \
273 DBGLVL_NOTICE, (__VA_ARGS__))
274 #define DC_INFO(...) DEBUGC(dbgc_class, \
275 DBGLVL_INFO, (__VA_ARGS__))
276 #define DC_DEBUG(...) DEBUGC(dbgc_class, \
277 DBGLVL_DEBUG, (__VA_ARGS__))
279 /* The following definitions come from lib/debug.c */
281 /** Possible destinations for the debug log (in order of precedence -
282 * once set to DEBUG_FILE, it is not possible to reset to DEBUG_STDOUT
283 * for example. This makes it easy to override for debug to stderr on
284 * the command line, as the smb.conf cannot reset it back to
285 * file-based logging */
287 DEBUG_DEFAULT_STDERR = 0,
288 DEBUG_DEFAULT_STDOUT = 1,
295 struct debug_settings {
298 bool debug_prefix_timestamp;
299 bool debug_hires_timestamp;
305 void setup_logging(const char *prog_name, enum debug_logtype new_logtype);
307 void gfree_debugsyms(void);
308 int debug_add_class(const char *classname);
309 bool debug_parse_levels(const char *params_str);
310 void debug_setup_talloc_log(void);
311 void debug_set_logfile(const char *name);
312 void debug_set_settings(struct debug_settings *settings,
313 const char *logging_param,
314 int syslog_level, bool syslog_only);
315 bool reopen_logs_internal( void );
316 void force_check_log_size( void );
317 bool need_to_check_log_size( void );
318 void check_log_size( void );
319 void dbgflush( void );
320 bool debug_get_output_is_stderr(void);
321 bool debug_get_output_is_stdout(void);
322 void debug_schedule_reopen_logs(void);
323 char *debug_list_class_names_and_levels(void);
325 typedef void (*debug_callback_fn)(void *private_ptr, int level, const char *msg);
328 Set a callback for all debug messages. Use in dlz_bind9 to push output to the bind logs
330 void debug_set_callback(void *private_ptr, debug_callback_fn fn);
332 char *debug_get_ringbuf(void);
333 size_t debug_get_ringbuf_size(void);
335 #endif /* _SAMBA_DEBUG_H */