source: vendor/current/lib/util/debug.h

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 9.4 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 SMB debug stuff
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
8
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.
13
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.
18
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/>.
21*/
22
23#ifndef _SAMBA_DEBUG_H
24#define _SAMBA_DEBUG_H
25
26#include <stdbool.h>
27#include <stddef.h>
28#include <stdarg.h>
29#include "attr.h"
30
31
32/* -------------------------------------------------------------------------- **
33 * Debugging code. See also debug.c
34 */
35
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
40*/
41#ifndef MAX_DEBUG_LEVEL
42#define MAX_DEBUG_LEVEL 1000
43#endif
44
45bool dbgtext_va(const char *, va_list ap) PRINTF_ATTRIBUTE(1,0);
46bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
47bool dbghdrclass( int level, int cls, const char *location, const char *func);
48bool dbghdr( int level, const char *location, const char *func);
49
50/*
51 * Redefine DEBUGLEVEL because so we don't have to change every source file
52 * that *unnecessarily* references it.
53 */
54#define DEBUGLEVEL DEBUGLEVEL_CLASS[DBGC_ALL]
55
56/*
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:
60 *
61 * #undef DBGC_CLASS
62 * #define DBGC_CLASS DBGC_<your class name here>
63 *
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.
66 */
67#define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
68
69#define DBGC_TDB 1
70#define DBGC_PRINTDRIVERS 2
71#define DBGC_LANMAN 3
72#define DBGC_SMB 4
73#define DBGC_RPC_PARSE 5
74#define DBGC_RPC_SRV 6
75#define DBGC_RPC_CLI 7
76#define DBGC_PASSDB 8
77#define DBGC_SAM 9
78#define DBGC_AUTH 10
79#define DBGC_WINBIND 11
80#define DBGC_VFS 12
81#define DBGC_IDMAP 13
82#define DBGC_QUOTA 14
83#define DBGC_ACLS 15
84#define DBGC_LOCKING 16
85#define DBGC_MSDFS 17
86#define DBGC_DMAPI 18
87#define DBGC_REGISTRY 19
88#define DBGC_SCAVENGER 20
89#define DBGC_DNS 21
90#define DBGC_LDB 22
91#define DBGC_TEVENT 23
92
93/* So you can define DBGC_CLASS before including debug.h */
94#ifndef DBGC_CLASS
95#define DBGC_CLASS 0 /* override as shown above */
96#endif
97
98extern int *DEBUGLEVEL_CLASS;
99
100/* Debugging macros
101 *
102 * DEBUGLVL()
103 * If the 'file specific' debug class level >= level OR the system-wide
104 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
105 * generate a header using the default macros for file, line, and
106 * function name. Returns True if the debug level was <= DEBUGLEVEL.
107 *
108 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
109 *
110 * DEBUG()
111 * If the 'file specific' debug class level >= level OR the system-wide
112 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
113 * generate a header using the default macros for file, line, and
114 * function name. Each call to DEBUG() generates a new header *unless* the
115 * previous debug output was unterminated (i.e. no '\n').
116 * See debug.c:dbghdr() for more info.
117 *
118 * Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
119 *
120 * DEBUGC()
121 * If the 'macro specified' 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: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
129 *
130 * DEBUGADD(), DEBUGADDC()
131 * Same as DEBUG() and DEBUGC() except the text is appended to the previous
132 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
133 * header.
134 *
135 * Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
136 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
137 *
138 * Note: If the debug class has not be redeined (see above) then the optimizer
139 * will remove the extra conditional test.
140 */
141
142/*
143 * From talloc.c:
144 */
145
146/* these macros gain us a few percent of speed on gcc */
147#if (__GNUC__ >= 3)
148/* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
149 as its first argument */
150#ifndef likely
151#define likely(x) __builtin_expect(!!(x), 1)
152#endif
153#ifndef unlikely
154#define unlikely(x) __builtin_expect(!!(x), 0)
155#endif
156#else
157#ifndef likely
158#define likely(x) (x)
159#endif
160#ifndef unlikely
161#define unlikely(x) (x)
162#endif
163#endif
164
165#define CHECK_DEBUGLVL( level ) \
166 ( ((level) <= MAX_DEBUG_LEVEL) && \
167 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)))
168
169#define CHECK_DEBUGLVLC( dbgc_class, level ) \
170 ( ((level) <= MAX_DEBUG_LEVEL) && \
171 unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)))
172
173#define DEBUGLVL( level ) \
174 ( CHECK_DEBUGLVL(level) \
175 && dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ ) )
176
177#define DEBUGLVLC( dbgc_class, level ) \
178 ( CHECK_DEBUGLVLC( dbgc_class, level ) \
179 && dbghdrclass( level, dbgc_class, __location__, __FUNCTION__ ) )
180
181#define DEBUG( level, body ) \
182 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
183 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
184 && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
185 && (dbgtext body) )
186
187#define DEBUGC( dbgc_class, level, body ) \
188 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
189 unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)) \
190 && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
191 && (dbgtext body) )
192
193#define DEBUGADD( level, body ) \
194 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
195 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
196 && (dbgtext body) )
197
198#define DEBUGADDC( dbgc_class, level, body ) \
199 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
200 unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))) \
201 && (dbgtext body) )
202
203/* Print a separator to the debug log. */
204#define DEBUGSEP(level)\
205 DEBUG((level),("===============================================================\n"))
206
207/* Prefix messages with the function name */
208#define DBG_PREFIX(level, body ) \
209 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
210 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
211 && (dbghdrclass(level, DBGC_CLASS, __location__, __func__ )) \
212 && (dbgtext("%s: ", __func__)) \
213 && (dbgtext body) )
214
215/*
216 * Debug levels matching RFC 3164
217 */
218#define DBGLVL_ERR 0 /* error conditions */
219#define DBGLVL_WARNING 1 /* warning conditions */
220#define DBGLVL_NOTICE 3 /* normal, but significant, condition */
221#define DBGLVL_INFO 5 /* informational message */
222#define DBGLVL_DEBUG 10 /* debug-level message */
223
224#define DBG_ERR(...) DBG_PREFIX(DBGLVL_ERR, (__VA_ARGS__))
225#define DBG_WARNING(...) DBG_PREFIX(DBGLVL_WARNING, (__VA_ARGS__))
226#define DBG_NOTICE(...) DBG_PREFIX(DBGLVL_NOTICE, (__VA_ARGS__))
227#define DBG_INFO(...) DBG_PREFIX(DBGLVL_INFO, (__VA_ARGS__))
228#define DBG_DEBUG(...) DBG_PREFIX(DBGLVL_DEBUG, (__VA_ARGS__))
229
230/* The following definitions come from lib/debug.c */
231
232/** Possible destinations for the debug log (in order of precedence -
233 * once set to DEBUG_FILE, it is not possible to reset to DEBUG_STDOUT
234 * for example. This makes it easy to override for debug to stderr on
235 * the command line, as the smb.conf cannot reset it back to
236 * file-based logging */
237enum debug_logtype {
238 DEBUG_DEFAULT_STDERR = 0,
239 DEBUG_DEFAULT_STDOUT = 1,
240 DEBUG_FILE = 2,
241 DEBUG_STDOUT = 3,
242 DEBUG_STDERR = 4,
243 DEBUG_CALLBACK = 5
244};
245
246struct debug_settings {
247 size_t max_log_size;
248 bool timestamp_logs;
249 bool debug_prefix_timestamp;
250 bool debug_hires_timestamp;
251 bool debug_pid;
252 bool debug_uid;
253 bool debug_class;
254};
255
256void setup_logging(const char *prog_name, enum debug_logtype new_logtype);
257
258void gfree_debugsyms(void);
259int debug_add_class(const char *classname);
260bool debug_parse_levels(const char *params_str);
261void debug_setup_talloc_log(void);
262void debug_set_logfile(const char *name);
263void debug_set_settings(struct debug_settings *settings,
264 const char *logging_param,
265 int syslog_level, bool syslog_only);
266bool reopen_logs_internal( void );
267void force_check_log_size( void );
268bool need_to_check_log_size( void );
269void check_log_size( void );
270void dbgflush( void );
271bool dbghdrclass(int level, int cls, const char *location, const char *func);
272bool debug_get_output_is_stderr(void);
273bool debug_get_output_is_stdout(void);
274void debug_schedule_reopen_logs(void);
275char *debug_list_class_names_and_levels(void);
276
277typedef void (*debug_callback_fn)(void *private_ptr, int level, const char *msg);
278
279/**
280 Set a callback for all debug messages. Use in dlz_bind9 to push output to the bind logs
281 */
282void debug_set_callback(void *private_ptr, debug_callback_fn fn);
283
284#endif /* _SAMBA_DEBUG_H */
Note: See TracBrowser for help on using the repository browser.