cctools
debug.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
3 Copyright (C) 2022 The University of Notre Dame
4 This software is distributed under the GNU General Public License.
5 See the file COPYING for details.
6 */
7 
8 #ifndef DEBUG_H
9 #define DEBUG_H
10 
35 #include "int_sizes.h"
36 
37 #include <unistd.h>
38 #include <execinfo.h>
39 
40 #include <sys/types.h>
41 
42 #include <stdarg.h>
43 #include <stdio.h>
44 
45 /* priority */
46 #define D_INFO (0LL)
47 #define D_FATAL (1LL<<0)
48 #define D_ERROR (1LL<<1)
49 #define D_NOTICE (1LL<<2)
50 #define D_DEBUG (1LL<<3)
52 /* subsystem */
53 #define D_SYSCALL (1LL<<4)
54 #define D_CHANNEL (1LL<<5)
55 #define D_PROCESS (1LL<<6)
56 #define D_RESOLVE (1LL<<7)
57 #define D_LIBCALL (1LL<<8)
58 #define D_LOCAL (1LL<<9)
59 #define D_DNS (1LL<<10)
60 #define D_TCP (1LL<<11)
61 #define D_AUTH (1LL<<12)
62 #define D_IRODS (1LL<<13)
63 #define D_CVMFS (1LL<<14)
64 #define D_HTTP (1LL<<15)
65 #define D_FTP (1LL<<16)
66 #define D_NEST (1LL<<17)
67 #define D_GROW (1LL<<18)
68 #define D_CHIRP (1LL<<19)
69 #define D_DCAP (1LL<<20)
70 #define D_RFIO (1LL<<21)
71 #define D_GLITE (1LL<<22)
72 #define D_MULTI (1LL<<23)
73 #define D_PSTREE (1LL<<24)
74 #define D_ALLOC (1LL<<25)
75 #define D_LFC (1LL<<26)
76 #define D_GFAL (1LL<<27)
77 #define D_SUMMARY (1LL<<28)
78 #define D_LOGIN (1LL<<29)
79 #define D_CACHE (1LL<<30)
80 #define D_POLL (1LL<<31)
81 #define D_HDFS (1LL<<32)
82 #define D_WQ (1LL<<33)
83 #define D_BXGRID (1LL<<34)
84 #define D_USER (1LL<<35)
85 #define D_XROOTD (1LL<<36)
86 #define D_MPI (1LL<<37)
87 #define D_BATCH (1LL<<38)
88 #define D_RMON (1LL<<39)
89 #define D_MAKEFLOW_RUN (1LL<<40)
90 #define D_MAKEFLOW_LEXER (1LL<<41)
91 #define D_MAKEFLOW_PARSER (1LL<<42)
92 #define D_MAKEFLOW_ALLOC (1LL<<43)
93 #define D_CONFUGA (1LL<<44)
94 #define D_JX (1LL<<45)
95 #define D_MAKEFLOW_HOOK (1LL<<46)
96 #define D_EXT (1LL<<47)
97 #define D_VINE (1LL<<48)
98 #define D_TLQ (1LL<<49)
99 #define D_SSL (1LL<<50)
100 #define D_BUCKETING (1LL<<51)
103 #define D_REMOTE (D_HTTP|D_FTP|D_NEST|D_CHIRP|D_DCAP|D_RFIO|D_LFC|D_GFAL|D_MULTI|D_GROW|D_IRODS|D_HDFS|D_BXGRID|D_XROOTD|D_CVMFS)
104 
106 #define D_MAKEFLOW (D_MAKEFLOW_RUN|D_MAKEFLOW_LEXER|D_MAKEFLOW_PARSER)
107 
109 #define D_ALL (~(0LL))
110 
111 /*
112 It turns out that many libraries and tools make use of symbols like "debug" and
113 "fatal". This causes strange failures when we link against such codes. Rather
114 than change all of our code, we simply insert these defines to transparently
115 modify the linker namespace we are using.
116 */
117 
118 #ifndef DOXYGEN
119 
120 #define debug cctools_debug
121 #define fatal cctools_fatal
122 #define notice cctools_notice
123 #define warn cctools_warn
124 #define debug_config cctools_debug_config
125 #define debug_config_file cctools_debug_config_file
126 #define debug_config_file_size cctools_debug_config_file_size
127 #define debug_config_fatal cctools_debug_config_fatal
128 #define debug_config_child_getpid cctools_debug_config_child_getpid
129 #define debug_flags_set cctools_debug_flags_set
130 #define debug_flags_print cctools_debug_flags_print
131 #define debug_flags_clear cctools_debug_flags_clear
132 #define debug_flags_restore cctools_debug_flags_restore
133 #define debug_set_flag_name cctools_debug_set_flag_name
134 #define debug_rename cctools_debug_rename
135 
136 #endif
137 
144 void debug(int64_t flags, const char *fmt, ...)
145 #ifndef SWIG
146 __attribute__ (( format(printf,2,3) ))
147 #endif
148 ;
149 
157 void vdebug(int64_t flags, const char *fmt, va_list args);
158 
165 void warn(int64_t flags, const char *fmt, ...);
166 
172 void fatal(const char *fmt, ...);
173 
174 
180 void notice(int64_t flags, const char *fmt, ...);
181 
187 void debug_config(const char *name);
188 
195 void debug_config_file(const char *file);
196 
197 int debug_config_file_e(const char *file);
198 
206 void debug_config_file_size(off_t size);
207 
208 void debug_config_fatal(void (*callback) (void));
209 
210 void debug_config_child_getpid (pid_t (*getpidf)(void));
211 
220 int debug_flags_set(const char *flagname);
221 
228 void debug_flags_print(FILE * stream);
229 
235 int64_t debug_flags_clear(void);
236 
243 void debug_set_flag_name(int64_t flag, const char *name);
244 
248 void debug_flags_restore(int64_t flags);
249 
253 void debug_rename(const char *suffix);
254 
257 void debug_reopen(void);
258 
261 void debug_close(void);
262 
263 /* LDEBUG likes debug, but also print the code location.
264  * NOTE: the caller of this macro must supply at least one argument after the format string.
265  */
266 #define LDEBUG(fmt, ...) debug(D_DEBUG, "%s:%s:%d[%s]: " fmt, __func__, __FILE__, __LINE__, CCTOOLS_SOURCE, __VA_ARGS__)
267 
268 
269 #define DEBUG_BT_SIZE 100
270 
271 /* Use offset info (+0x...) with addr2line -f -e [exe or .so] */
272 #define debug_backtrace \
273  { debug(D_ERROR, "%s:%s:%d[%s]", __func__, __FILE__, __LINE__, CCTOOLS_SOURCE); \
274  void *buffer[DEBUG_BT_SIZE]; \
275  size_t nptrs = backtrace(buffer, DEBUG_BT_SIZE); \
276  char **strings = backtrace_symbols(buffer, nptrs); \
277  if (!strings) { \
278  debug(D_ERROR, "%s", "No backtrace available."); \
279  } else { \
280  for (size_t bt_ct = 0; bt_ct < nptrs; bt_ct++) { \
281  debug(D_ERROR, "%s", strings[bt_ct]); \
282  } \
283  } \
284  free(strings); \
285  } // generate a core if possible
286 
287 
288 #define debug_assert(cond)\
289  if (!(cond)) {\
290  debug(D_ERROR, "Assertion failed: %s", #cond);\
291  debug_backtrace;\
292  abort(); }
293 
294 #endif
debug_config_file
void debug_config_file(const char *file)
Direct debug output to a file.
debug_set_flag_name
void debug_set_flag_name(int64_t flag, const char *name)
Set name of flag combination Sets the string value associated with flag.
debug_config
void debug_config(const char *name)
Initialize the debugging system.
debug_flags_set
int debug_flags_set(const char *flagname)
Set debugging flags to enable output.
debug_config_file_size
void debug_config_file_size(off_t size)
Set the maximum debug file size.
debug_flags_clear
int64_t debug_flags_clear(void)
Clear all debugging flags.
vdebug
void void vdebug(int64_t flags, const char *fmt, va_list args)
Emit a debugging message.
notice
void notice(int64_t flags, const char *fmt,...)
Emit a notice message.
debug_reopen
void debug_reopen(void)
Reopen the debug stream.
debug_rename
void debug_rename(const char *suffix)
Rename debug file with given suffix.
debug_flags_restore
void debug_flags_restore(int64_t flags)
Restore debug flags.
fatal
void fatal(const char *fmt,...)
Emit a fatal debugging message and terminate with SIGTERM.
debug_close
void debug_close(void)
Close the debug stream (only for disk files, no stderr or stdout).
warn
void warn(int64_t flags, const char *fmt,...)
Emit a warning message.
debug_flags_print
void debug_flags_print(FILE *stream)
Display the available debug flags.
debug
void debug(int64_t flags, const char *fmt,...) __attribute__((format(printf
Emit a debugging message.