00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CU_DEBUG_H
00020 #define CU_DEBUG_H
00021
00022 #include <cu/fwd.h>
00023 #include <cu/conf.h>
00024 #include <cu/inherit.h>
00025 #include <cu/logging.h>
00026 #include <cu/diag.h>
00027 #include <stdio.h>
00028
00029 CU_BEGIN_DECLARATIONS
00030
00031
00032
00033 #if !defined(CU_NDEBUG) || defined(CU_IN_DOXYGEN)
00034 # ifndef CU_IN_DOXYGEN
00035 # define cuP_dlog_def(storage, name, ...) \
00036 storage char const *name##_debug_keys[] = {__VA_ARGS__, NULL}; \
00037 storage struct cu_log_facility name##_debug_log = \
00038 CU_LOG_FACILITY_INITIALISER( \
00039 CU_LOG_DEBUG, CU_LOG_LOGIC, name##_debug_keys, \
00040 CU_LOG_FLAG_DEBUG_FACILITY | CU_LOG_FLAG_PERMANENT)
00041 # define cuP_dlogf(name, fmt, ...) \
00042 cu_logf(&name##_debug_log, fmt, __FILE__, __LINE__, __VA_ARGS__)
00043 # endif
00044
00045
00046
00047
00048
00049
00050
00051
00052 # define cu_dlog_def(name, ...) cuP_dlog_def(static, name, __VA_ARGS__)
00053
00054
00055
00056 # define cu_dlog_edef(name, ...) cuP_dlog_def(, name, __VA_ARGS__)
00057
00058
00059 # define cu_dlog_edec(name) extern struct cu_log_facility name##_debug_log
00060
00061
00062
00063 # define cu_dlogf(name, ...) cuP_dlogf(name, __VA_ARGS__, NULL)
00064
00065
00066
00067 #define cu_debug_error(...) cu_bugf_fl(__FILE__, __LINE__, __VA_ARGS__)
00068
00069
00070 #define cu_debug_assert(test) \
00071 ((test)? (void)0 : (void)cu_debug_error("assertion '%s' failed", #test))
00072
00073
00074
00075 #define cu_debug_assert_once() \
00076 do { \
00077 static int cuL_cnt = 0; \
00078 if (cuL_cnt++ != 0) \
00079 cu_debug_error("This point should only have been reached once."); \
00080 } while (0)
00081
00082
00083
00084 #define cu_debug_unreachable() cu_bug_unreachable()
00085
00086 #else
00087 # define cu_dlog_def(name, ...) CU_END_BOILERPLATE
00088 # define cu_dlog_edef(name, ...) CU_END_BOILERPLATE
00089 # define cu_dlog_edec(name) CU_END_BOILERPLATE
00090 # define cu_dlogf(...) ((void)0)
00091 # define cu_debug_error(...) ((void)0)
00092 # define cu_debug_assert(test) ((void)0)
00093 # define cu_debug_assert_once() ((void)0)
00094 # define cu_debug_unreachable() ((void)0)
00095 #endif
00096
00097
00098
00099
00100
00101 void cu_dtag_enable(char const *dtag);
00102
00103
00104
00105 void cu_dtag_disable(char const *dtag);
00106
00107
00108
00109 cu_bool_t cu_dtag_get(char const *dtag);
00110
00111
00112
00113
00114
00115 typedef enum {
00116 cu_debug_flag_info = 1 << 0,
00117 cu_debug_show_alloc_flag = 1 << 1,
00118 cu_debug_soft_exit_flag = 1 << 2,
00119 cu_debug_show_collect_flag = 1 << 3,
00120 cu_debug_expensive_typing = 1 << 4
00121 } cu_debug_flags_t;
00122
00123 cu_debug_flags_t cu_debug_enable(cu_debug_flags_t);
00124 cu_debug_flags_t cu_debug_disable(cu_debug_flags_t);
00125 cu_debug_flags_t cu_debug_select(cu_debug_flags_t);
00126
00127
00128
00129
00130 extern void (*cuP_debug_bug_report)(const char *, int, const char *, ...);
00131
00132 void cu_findent(FILE *fp, int i);
00133 void cu_debug_abort(void) CU_ATTR_NORETURN;
00134 void cu_debug_trap(void);
00135
00136
00137
00138
00139
00140 #ifdef CUCONF_DEBUG_CLIENT
00141 # define cu_check_arg(argnum, argname, test) \
00142 ((test)? ((void)0) \
00143 : cu_bugf_domain(argnum, #argname, "must fulfil "#test))
00144 #else
00145 # define cu_check_arg(argnum, argname, test) ((void)0)
00146 #endif
00147
00148
00149
00150
00151 void cuP_dprintf(char const *, int, char const *, char const *, ...)
00152 CU_ATTR_DEPRECATED;
00153 void cuP_debug_msg(const char *, int, const char *, int, const char *, ...)
00154 CU_ATTR_DEPRECATED;
00155 extern cu_bool_t cuP_debug_is_enabled;
00156 #ifndef CU_NDEBUG
00157 # define cu_dprintf(...) cuP_dprintf(__FILE__, __LINE__, __VA_ARGS__)
00158 # define cu_debug_inform(...) \
00159 cuP_debug_msg(__FILE__,__LINE__,"debug",cu_debug_flag_info,__VA_ARGS__)
00160 # define cu_debug_warning(...) \
00161 cuP_debug_msg(__FILE__,__LINE__,"warning", 0, __VA_ARGS__)
00162 # define cu_debug_here() cu_debug_inform("here")
00163 cu_bool_t cu_debug_is_enabled(cu_debug_flags_t);
00164 void cu_debug_indent() CU_ATTR_DEPRECATED;
00165 void cu_debug_unindent() CU_ATTR_DEPRECATED;
00166 #else
00167 # define cu_dprintf(...) ((void)0)
00168 # define cu_debug_inform(...) ((void)0)
00169 # define cu_debug_warning(...) ((void)0)
00170 # define cu_debug_here() ((void)0)
00171 # define cu_debug_is_enabled(flags) cu_false
00172 # define cu_debug_indent() ((void)0)
00173 # define cu_debug_unindent() ((void)0)
00174 #endif
00175 #define cu_unreachable() cu_debug_unreachable()
00176 #define cu_debug_key cu_dtag_get
00177
00178 CU_END_DECLARATIONS
00179 #endif