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/>.
26 /* -------------------------------------------------------------------------- **
27 * Debugging code. See also debug.c
30 /* the maximum debug level to compile into the code. This assumes a good
31 optimising compiler that can remove unused code
32 for embedded or low-memory systems set this to a value like 2 to get
33 only important messages. This gives *much* smaller binaries
35 #ifndef MAX_DEBUG_LEVEL
36 #define MAX_DEBUG_LEVEL 1000
39 int Debug1( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
40 bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
41 bool dbghdrclass( int level
, int cls
, const char *location
, const char *func
);
42 bool dbghdr( int level
, const char *location
, const char *func
);
45 * Redefine DEBUGLEVEL because so we don't have to change every source file
46 * that *unnecessarily* references it.
48 #define DEBUGLEVEL DEBUGLEVEL_CLASS[DBGC_ALL]
51 * Define all new debug classes here. A class is represented by an entry in
52 * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
53 * old DEBUGLEVEL. Any source file that does NOT add the following lines:
56 * #define DBGC_CLASS DBGC_<your class name here>
58 * at the start of the file (after #include "includes.h") will default to
59 * using index zero, so it will behaive just like it always has.
61 #define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
64 #define DBGC_PRINTDRIVERS 2
67 #define DBGC_RPC_PARSE 5
68 #define DBGC_RPC_SRV 6
69 #define DBGC_RPC_CLI 7
73 #define DBGC_WINBIND 11
78 #define DBGC_LOCKING 16
81 #define DBGC_REGISTRY 19
82 #define DBGC_SCAVENGER 20
85 /* Always ensure this is updated when new fixed classes area added, to ensure the array in debug.c is the right size */
86 #define DBGC_MAX_FIXED 21
88 /* So you can define DBGC_CLASS before including debug.h */
90 #define DBGC_CLASS 0 /* override as shown above */
93 extern int *DEBUGLEVEL_CLASS
;
98 * If the 'file specific' debug class level >= level OR the system-wide
99 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
100 * generate a header using the default macros for file, line, and
101 * function name. Returns True if the debug level was <= DEBUGLEVEL.
103 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
106 * If the 'file specific' debug class level >= level OR the system-wide
107 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
108 * generate a header using the default macros for file, line, and
109 * function name. Each call to DEBUG() generates a new header *unless* the
110 * previous debug output was unterminated (i.e. no '\n').
111 * See debug.c:dbghdr() for more info.
113 * Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
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. Each call to DEBUG() generates a new header *unless* the
120 * previous debug output was unterminated (i.e. no '\n').
121 * See debug.c:dbghdr() for more info.
123 * Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
125 * DEBUGADD(), DEBUGADDC()
126 * Same as DEBUG() and DEBUGC() except the text is appended to the previous
127 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
130 * Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
131 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
133 * Note: If the debug class has not be redeined (see above) then the optimizer
134 * will remove the extra conditional test.
141 /* these macros gain us a few percent of speed on gcc */
143 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
144 as its first argument */
146 #define likely(x) __builtin_expect(!!(x), 1)
149 #define unlikely(x) __builtin_expect(!!(x), 0)
153 #define likely(x) (x)
156 #define unlikely(x) (x)
160 #define CHECK_DEBUGLVL( level ) \
161 ( ((level) <= MAX_DEBUG_LEVEL) && \
162 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)))
164 #define CHECK_DEBUGLVLC( dbgc_class, level ) \
165 ( ((level) <= MAX_DEBUG_LEVEL) && \
166 unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)))
168 #define DEBUGLVL( level ) \
169 ( CHECK_DEBUGLVL(level) \
170 && dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ ) )
172 #define DEBUGLVLC( dbgc_class, level ) \
173 ( CHECK_DEBUGLVLC( dbgc_class, level ) \
174 && dbghdrclass( level, dbgc_class, __location__, __FUNCTION__ ) )
176 #define DEBUG( level, body ) \
177 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
178 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
179 && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
182 #define DEBUGC( dbgc_class, level, body ) \
183 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
184 unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)) \
185 && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
188 #define DEBUGADD( level, body ) \
189 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
190 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
193 #define DEBUGADDC( dbgc_class, level, body ) \
194 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
195 unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))) \
198 /* Print a separator to the debug log. */
199 #define DEBUGSEP(level)\
200 DEBUG((level),("===============================================================\n"))
202 /* The following definitions come from lib/debug.c */
204 /** Possible destinations for the debug log (in order of precedence -
205 * once set to DEBUG_FILE, it is not possible to reset to DEBUG_STDOUT
206 * for example. This makes it easy to override for debug to stderr on
207 * the command line, as the smb.conf cannot reset it back to
208 * file-based logging */
209 enum debug_logtype
{DEBUG_DEFAULT_STDERR
= 0, DEBUG_DEFAULT_STDOUT
= 1, DEBUG_FILE
= 2, DEBUG_STDOUT
= 3, DEBUG_STDERR
= 4, DEBUG_CALLBACK
= 5};
211 struct debug_settings
{
216 bool debug_prefix_timestamp
;
217 bool debug_hires_timestamp
;
223 void setup_logging(const char *prog_name
, enum debug_logtype new_logtype
);
225 void debug_close_dbf(void);
226 void gfree_debugsyms(void);
227 int debug_add_class(const char *classname
);
228 int debug_lookup_classname(const char *classname
);
229 bool debug_parse_levels(const char *params_str
);
230 void debug_setup_talloc_log(void);
231 void debug_set_logfile(const char *name
);
232 void debug_set_settings(struct debug_settings
*settings
);
233 bool reopen_logs_internal( void );
234 void force_check_log_size( void );
235 bool need_to_check_log_size( void );
236 void check_log_size( void );
237 void dbgflush( void );
238 bool dbghdrclass(int level
, int cls
, const char *location
, const char *func
);
239 bool dbghdr(int level
, const char *location
, const char *func
);
240 bool debug_get_output_is_stderr(void);
241 bool debug_get_output_is_stdout(void);
242 void debug_schedule_reopen_logs(void);
243 char *debug_list_class_names_and_levels(void);
245 typedef void (*debug_callback_fn
)(void *private_ptr
, int level
, const char *msg
);
248 Set a callback for all debug messages. Use in dlz_bind9 to push output to the bind logs
250 void debug_set_callback(void *private_ptr
, debug_callback_fn fn
);
253 log suspicious usage - print comments and backtrace
255 _PUBLIC_
void log_suspicious_usage(const char *from
, const char *info
);
258 print suspicious usage - print comments and backtrace
260 _PUBLIC_
void print_suspicious_usage(const char* from
, const char* info
);
261 _PUBLIC_
uint32_t get_task_id(void);
262 _PUBLIC_
void log_task_id(void);
264 /* the debug operations structure - contains function pointers to
265 various debug implementations of each operation */
267 /* function to log (using DEBUG) suspicious usage of data structure */
268 void (*log_suspicious_usage
)(const char* from
, const char* info
);
270 /* function to log (using printf) suspicious usage of data structure.
271 * To be used in circumstances when using DEBUG would cause loop. */
272 void (*print_suspicious_usage
)(const char* from
, const char* info
);
274 /* function to return process/thread id */
275 uint32_t (*get_task_id
)(void);
277 /* function to log process/thread id */
278 void (*log_task_id
)(int fd
);
282 register a set of debug handlers.
284 _PUBLIC_
void register_debug_handlers(const char *name
, struct debug_ops
*ops
);