Changeset 745 for trunk/server/lib/util/debug.h
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/lib/util/debug.h
r414 r745 1 1 /* 2 2 Unix SMB/CIFS implementation. 3 Samba debug defines 4 Copyright (C) Andrew Tridgell 2003 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 5 8 6 9 This program is free software; you can redistribute it and/or modify … … 8 11 the Free Software Foundation; either version 3 of the License, or 9 12 (at your option) any later version. 10 13 11 14 This program is distributed in the hope that it will be useful, 12 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 17 GNU General Public License for more details. 15 18 16 19 You should have received a copy of the GNU General Public License 17 20 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 21 */ 19 22 20 #ifndef _SAMBA_DEBUG_H_ 21 #define _SAMBA_DEBUG_H_ 22 23 /** 24 * @file 25 * @brief Debugging macros 26 */ 27 28 /* the debug operations structure - contains function pointers to 29 various debug implementations of each operation */ 30 struct debug_ops { 31 /* function to log (using DEBUG) suspicious usage of data structure */ 32 void (*log_suspicious_usage)(const char* from, const char* info); 33 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); 37 38 /* function to return process/thread id */ 39 uint32_t (*get_task_id)(void); 40 41 /* function to log process/thread id */ 42 void (*log_task_id)(int fd); 43 }; 44 45 #define DEBUGLEVEL *debug_level 46 extern int DEBUGLEVEL; 47 48 #define debug_ctx() (_debug_ctx?_debug_ctx:(_debug_ctx=talloc_new(NULL))) 49 50 #define DEBUGLVL(level) ((level) <= DEBUGLEVEL) 51 #define _DEBUG(level, body, header) do { \ 52 if (DEBUGLVL(level)) { \ 53 void* _debug_ctx=NULL; \ 54 if (header) { \ 55 dbghdr(level, __location__, __FUNCTION__); \ 56 } \ 57 dbgtext body; \ 58 talloc_free(_debug_ctx); \ 59 } \ 60 } while (0) 61 /** 62 * Write to the debug log. 63 */ 64 #define DEBUG(level, body) _DEBUG(level, body, true) 65 /** 66 * Add data to an existing debug log entry. 67 */ 68 #define DEBUGADD(level, body) _DEBUG(level, body, false) 69 70 /** 71 * Obtain indentation string for the debug log. 72 * 73 * Level specified by n. 74 */ 75 #define DEBUGTAB(n) do_debug_tab(n) 23 #ifndef _DEBUG_H 24 #define _DEBUG_H 25 26 /* -------------------------------------------------------------------------- ** 27 * Debugging code. See also debug.c 28 */ 29 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 34 */ 35 #ifndef MAX_DEBUG_LEVEL 36 #define MAX_DEBUG_LEVEL 1000 37 #endif 38 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); 43 44 /* 45 * Redefine DEBUGLEVEL because so we don't have to change every source file 46 * that *unnecessarily* references it. 47 */ 48 #define DEBUGLEVEL DEBUGLEVEL_CLASS[DBGC_ALL] 49 50 /* 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: 54 * 55 * #undef DBGC_CLASS 56 * #define DBGC_CLASS DBGC_<your class name here> 57 * 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. 60 */ 61 #define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */ 62 63 #define DBGC_TDB 1 64 #define DBGC_PRINTDRIVERS 2 65 #define DBGC_LANMAN 3 66 #define DBGC_SMB 4 67 #define DBGC_RPC_PARSE 5 68 #define DBGC_RPC_SRV 6 69 #define DBGC_RPC_CLI 7 70 #define DBGC_PASSDB 8 71 #define DBGC_SAM 9 72 #define DBGC_AUTH 10 73 #define DBGC_WINBIND 11 74 #define DBGC_VFS 12 75 #define DBGC_IDMAP 13 76 #define DBGC_QUOTA 14 77 #define DBGC_ACLS 15 78 #define DBGC_LOCKING 16 79 #define DBGC_MSDFS 17 80 #define DBGC_DMAPI 18 81 #define DBGC_REGISTRY 19 82 83 /* Always ensure this is updated when new fixed classes area added, to ensure the array in debug.c is the right size */ 84 #define DBGC_MAX_FIXED 19 85 86 /* So you can define DBGC_CLASS before including debug.h */ 87 #ifndef DBGC_CLASS 88 #define DBGC_CLASS 0 /* override as shown above */ 89 #endif 90 91 extern int *DEBUGLEVEL_CLASS; 92 93 /* Debugging macros 94 * 95 * DEBUGLVL() 96 * If the 'file specific' debug class level >= level OR the system-wide 97 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 98 * generate a header using the default macros for file, line, and 99 * function name. Returns True if the debug level was <= DEBUGLEVEL. 100 * 101 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" ); 102 * 103 * DEBUG() 104 * If the 'file specific' debug class level >= level OR the system-wide 105 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 106 * generate a header using the default macros for file, line, and 107 * function name. Each call to DEBUG() generates a new header *unless* the 108 * previous debug output was unterminated (i.e. no '\n'). 109 * See debug.c:dbghdr() for more info. 110 * 111 * Example: DEBUG( 2, ("Some text and a value %d.\n", value) ); 112 * 113 * DEBUGC() 114 * If the 'macro specified' debug class level >= level OR the system-wide 115 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then 116 * generate a header using the default macros for file, line, and 117 * function name. Each call to DEBUG() generates a new header *unless* the 118 * previous debug output was unterminated (i.e. no '\n'). 119 * See debug.c:dbghdr() for more info. 120 * 121 * Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) ); 122 * 123 * DEBUGADD(), DEBUGADDC() 124 * Same as DEBUG() and DEBUGC() except the text is appended to the previous 125 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening 126 * header. 127 * 128 * Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) ); 129 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) ); 130 * 131 * Note: If the debug class has not be redeined (see above) then the optimizer 132 * will remove the extra conditional test. 133 */ 134 135 /* 136 * From talloc.c: 137 */ 138 139 /* these macros gain us a few percent of speed on gcc */ 140 #if (__GNUC__ >= 3) 141 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1 142 as its first argument */ 143 #ifndef likely 144 #define likely(x) __builtin_expect(!!(x), 1) 145 #endif 146 #ifndef unlikely 147 #define unlikely(x) __builtin_expect(!!(x), 0) 148 #endif 149 #else 150 #ifndef likely 151 #define likely(x) (x) 152 #endif 153 #ifndef unlikely 154 #define unlikely(x) (x) 155 #endif 156 #endif 157 158 #define CHECK_DEBUGLVL( level ) \ 159 ( ((level) <= MAX_DEBUG_LEVEL) && \ 160 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))) 161 162 #define DEBUGLVL( level ) \ 163 ( CHECK_DEBUGLVL(level) \ 164 && dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ ) ) 165 166 167 #define DEBUG( level, body ) \ 168 (void)( ((level) <= MAX_DEBUG_LEVEL) && \ 169 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \ 170 && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \ 171 && (dbgtext body) ) 172 173 #define DEBUGC( dbgc_class, level, body ) \ 174 (void)( ((level) <= MAX_DEBUG_LEVEL) && \ 175 unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)) \ 176 && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \ 177 && (dbgtext body) ) 178 179 #define DEBUGADD( level, body ) \ 180 (void)( ((level) <= MAX_DEBUG_LEVEL) && \ 181 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \ 182 && (dbgtext body) ) 183 184 #define DEBUGADDC( dbgc_class, level, body ) \ 185 (void)( ((level) <= MAX_DEBUG_LEVEL) && \ 186 unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))) \ 187 && (dbgtext body) ) 188 189 /* Print a separator to the debug log. */ 190 #define DEBUGSEP(level)\ 191 DEBUG((level),("===============================================================\n")) 192 193 /* The following definitions come from lib/debug.c */ 76 194 77 195 /** Possible destinations for the debug log (in order of precedence - … … 80 198 * the command line, as the smb.conf cannot reset it back to 81 199 * file-based logging */ 82 enum debug_logtype {DEBUG_STDOUT = 0, DEBUG_FILE = 1, DEBUG_STDERR = 2}; 83 84 /** 85 the backend for debug messages. Note that the DEBUG() macro has already 86 ensured that the log level has been met before this is called 87 */ 88 _PUBLIC_ void dbghdr(int level, const char *location, const char *func); 89 90 _PUBLIC_ void dbghdrclass(int level, int cls, const char *location, const char *func); 91 92 /** 93 reopen the log file (usually called because the log file name might have changed) 94 */ 95 _PUBLIC_ void reopen_logs(void); 96 97 /** 98 * this global variable determines what messages are printed 99 */ 100 _PUBLIC_ void debug_schedule_reopen_logs(void); 101 102 /** 103 control the name of the logfile and whether logging will be to stdout, stderr 104 or a file 105 */ 106 _PUBLIC_ void setup_logging(const char *prog_name, enum debug_logtype new_logtype); 107 108 /** 109 Just run logging to stdout for this program 110 */ 111 _PUBLIC_ void setup_logging_stdout(void); 112 113 /** 114 return a string constant containing n tabs 115 no more than 10 tabs are returned 116 */ 117 _PUBLIC_ const char *do_debug_tab(int n); 200 enum debug_logtype {DEBUG_DEFAULT_STDERR = 0, DEBUG_STDOUT = 1, DEBUG_FILE = 2, DEBUG_STDERR = 3}; 201 202 struct debug_settings { 203 size_t max_log_size; 204 bool syslog; 205 bool syslog_only; 206 bool timestamp_logs; 207 bool debug_prefix_timestamp; 208 bool debug_hires_timestamp; 209 bool debug_pid; 210 bool debug_uid; 211 bool debug_class; 212 }; 213 214 void setup_logging(const char *prog_name, enum debug_logtype new_logtype); 215 216 void debug_close_dbf(void); 217 void gfree_debugsyms(void); 218 int debug_add_class(const char *classname); 219 int debug_lookup_classname(const char *classname); 220 bool debug_parse_levels(const char *params_str); 221 void debug_setup_talloc_log(void); 222 void debug_set_logfile(const char *name); 223 void debug_set_settings(struct debug_settings *settings); 224 bool reopen_logs_internal( void ); 225 void force_check_log_size( void ); 226 bool need_to_check_log_size( void ); 227 void check_log_size( void ); 228 void dbgflush( void ); 229 bool dbghdrclass(int level, int cls, const char *location, const char *func); 230 bool dbghdr(int level, const char *location, const char *func); 231 bool debug_get_output_is_stderr(void); 232 void debug_schedule_reopen_logs(void); 233 char *debug_list_class_names_and_levels(void); 118 234 119 235 /** … … 129 245 _PUBLIC_ void log_task_id(void); 130 246 247 /* the debug operations structure - contains function pointers to 248 various debug implementations of each operation */ 249 struct debug_ops { 250 /* function to log (using DEBUG) suspicious usage of data structure */ 251 void (*log_suspicious_usage)(const char* from, const char* info); 252 253 /* function to log (using printf) suspicious usage of data structure. 254 * To be used in circumstances when using DEBUG would cause loop. */ 255 void (*print_suspicious_usage)(const char* from, const char* info); 256 257 /* function to return process/thread id */ 258 uint32_t (*get_task_id)(void); 259 260 /* function to log process/thread id */ 261 void (*log_task_id)(int fd); 262 }; 263 131 264 /** 132 265 register a set of debug handlers. … … 134 267 _PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops); 135 268 136 /** 137 the backend for debug messages. Note that the DEBUG() macro has already 138 ensured that the log level has been met before this is called 139 140 @note You should never have to call this function directly. Call the DEBUG() 141 macro instead. 142 */ 143 _PUBLIC_ void dbgtext(const char *format, ...) PRINTF_ATTRIBUTE(1,2); 144 145 struct _XFILE; 146 extern struct _XFILE *dbf; 147 148 #endif 269 #endif
Note:
See TracChangeset
for help on using the changeset viewer.