2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef _SAMBA_DEBUG_H_
21 #define _SAMBA_DEBUG_H_
25 * @brief Debugging macros
28 /* the debug operations structure - contains function pointers to
29 various debug implementations of each operation */
31 /* function to log (using DEBUG) suspicious usage of data structure */
32 void (*log_suspicious_usage
)(const char* from
, const char* info
);
34 /* function to log (using printf) suspicious usage of data structure.
35 * To be used in circumstances when using DEBUG would cause loop. */
36 void (*print_suspicious_usage
)(const char* from
, const char* info
);
38 /* function to return process/thread id */
39 uint32_t (*get_task_id
)(void);
41 /* function to log process/thread id */
42 void (*log_task_id
)(int fd
);
45 #define DEBUGLEVEL *debug_level
46 extern int DEBUGLEVEL
;
48 #define debug_ctx() (_debug_ctx?_debug_ctx:(_debug_ctx=talloc_new(NULL)))
50 #define DEBUGLVL(level) ((level) <= DEBUGLEVEL)
51 #define _DEBUG(level, body, header) do { \
52 if (DEBUGLVL(level)) { \
53 void* _debug_ctx=NULL; \
55 dbghdr(level, __location__, __FUNCTION__); \
58 talloc_free(_debug_ctx); \
62 * Write to the debug log.
64 #define DEBUG(level, body) _DEBUG(level, body, true)
66 * Add data to an existing debug log entry.
68 #define DEBUGADD(level, body) _DEBUG(level, body, false)
71 * Obtain indentation string for the debug log.
73 * Level specified by n.
75 #define DEBUGTAB(n) do_debug_tab(n)
77 /** Possible destinations for the debug log */
78 enum debug_logtype
{DEBUG_FILE
= 0, DEBUG_STDOUT
= 1, DEBUG_STDERR
= 2};
81 the backend for debug messages. Note that the DEBUG() macro has already
82 ensured that the log level has been met before this is called
84 _PUBLIC_
void dbghdr(int level
, const char *location
, const char *func
);
86 _PUBLIC_
void dbghdrclass(int level
, int cls
, const char *location
, const char *func
);
89 reopen the log file (usually called because the log file name might have changed)
91 _PUBLIC_
void reopen_logs(void);
94 * this global variable determines what messages are printed
96 _PUBLIC_
void debug_schedule_reopen_logs(void);
99 control the name of the logfile and whether logging will be to stdout, stderr
102 _PUBLIC_
void setup_logging(const char *prog_name
, enum debug_logtype new_logtype
);
105 return a string constant containing n tabs
106 no more than 10 tabs are returned
108 _PUBLIC_
const char *do_debug_tab(int n
);
111 log suspicious usage - print comments and backtrace
113 _PUBLIC_
void log_suspicious_usage(const char *from
, const char *info
);
116 print suspicious usage - print comments and backtrace
118 _PUBLIC_
void print_suspicious_usage(const char* from
, const char* info
);
119 _PUBLIC_
uint32_t get_task_id(void);
120 _PUBLIC_
void log_task_id(void);
123 register a set of debug handlers.
125 _PUBLIC_
void register_debug_handlers(const char *name
, struct debug_ops
*ops
);
128 the backend for debug messages. Note that the DEBUG() macro has already
129 ensured that the log level has been met before this is called
131 @note You should never have to call this function directly. Call the DEBUG()
134 _PUBLIC_
void dbgtext(const char *format
, ...) PRINTF_ATTRIBUTE(1,2);
137 extern struct _XFILE
*dbf
;