00001
00002 #ifndef EWL_DEBUG_H
00003 #define EWL_DEBUG_H
00004
00005 #include "ewl_misc.h"
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <string.h>
00009
00010 #define DLEVEL_UNSTABLE 0
00011 #define DLEVEL_TESTING 10
00012 #define DLEVEL_STABLE 20
00013
00014 void ewl_print_warning(void);
00015 void ewl_segv(void);
00016 void ewl_backtrace(void);
00017
00021 typedef struct Ewl_Config_Cache Ewl_Config_Cache;
00022
00026 struct Ewl_Config_Cache
00027 {
00028 int level;
00029 unsigned char enable:1;
00030 unsigned char segv:1;
00031 unsigned char backtrace:1;
00032 unsigned char evas_render:1;
00033 unsigned char gc_reap:1;
00035 unsigned char print_signals:1;
00036 unsigned char print_keys:1;
00037 };
00038
00039 extern Ewl_Config_Cache ewl_config_cache;
00041 #if EWL_ENABLE_DEBUG
00042
00043 #define DEBUGGING(lvl) (ewl_config_cache.enable && (ewl_config_cache.level >= (lvl)))
00044
00045 #define DENTER_FUNCTION(lvl) \
00046 { \
00047 if (DEBUGGING(lvl)) \
00048 { \
00049 ewl_debug_indent_print(1); \
00050 fprintf(stderr, "--> %f - %s:%i\tEntering %s();\n", \
00051 ecore_time_get(), __FILE__, __LINE__, __func__); \
00052 } \
00053 }
00054
00055 #define DLEAVE_FUNCTION(lvl) \
00056 { \
00057 if (DEBUGGING(lvl)) \
00058 { \
00059 ewl_debug_indent_print(-1); \
00060 fprintf(stderr, "<-- %f - %s:%i\tLeaving %s();\n", \
00061 ecore_time_get(), __FILE__, __LINE__, __func__); \
00062 } \
00063 }
00064
00065 #define DRETURN(lvl) \
00066 { \
00067 DLEAVE_FUNCTION(lvl); \
00068 if (DEBUGGING(lvl)) \
00069 { \
00070 ewl_debug_indent_print(0); \
00071 fprintf(stderr, "<-- %f - %s:%i\tReturn in %s();\n", \
00072 ecore_time_get(), __FILE__, __LINE__, __func__); \
00073 } \
00074 return; \
00075 }
00076
00077 #define DRETURN_PTR(ptr, lvl) \
00078 { \
00079 DLEAVE_FUNCTION(lvl); \
00080 if (DEBUGGING(lvl)) \
00081 { \
00082 ewl_debug_indent_print(0); \
00083 fprintf(stderr, "<-- %f - %s:%i\tReturning %p in %s();\n", \
00084 ecore_time_get(), __FILE__, __LINE__, (void *) (ptr), __func__); \
00085 } \
00086 return (void *)(ptr); \
00087 }
00088
00089 #define DRETURN_FLOAT(num, lvl) \
00090 { \
00091 DLEAVE_FUNCTION(lvl); \
00092 if (DEBUGGING(lvl)) \
00093 { \
00094 ewl_debug_indent_print(0); \
00095 fprintf(stderr, "<-- %f - %s:%i\tReturning %f in %s();\n", \
00096 ecore_time_get(), __FILE__, __LINE__, (float) (num), __func__); \
00097 } \
00098 return num; \
00099 }
00100
00101 #define DRETURN_INT(num, lvl) \
00102 { \
00103 DLEAVE_FUNCTION(lvl); \
00104 if (DEBUGGING(lvl)) \
00105 { \
00106 ewl_debug_indent_print(0); \
00107 fprintf(stderr, "<-- %f - %s:%i\tReturning %i in %s();\n", \
00108 ecore_time_get(), __FILE__, __LINE__, (int) (num), __func__); \
00109 } \
00110 return num; \
00111 }
00112
00113 #define DWARNING(fmt, args...) \
00114 { \
00115 ewl_print_warning(); \
00116 fprintf(stderr, "\tIn function:\n\n" \
00117 "\t%s();\n\n", __func__); \
00118 fprintf(stderr, fmt, ## args); \
00119 fprintf(stderr, "\n"); \
00120 ewl_backtrace(); \
00121 ewl_segv(); \
00122 }
00123
00124 #define DCHECK_PARAM_PTR(ptr) \
00125 { \
00126 if (!(ptr)) \
00127 { \
00128 ewl_print_warning(); \
00129 fprintf(stderr, "\tThis program is calling:\n\n" \
00130 "\t%s();\n\n" \
00131 "\tWith the parameter:\n\n" \
00132 "\t%s\n\n" \
00133 "\tbeing NULL. Please fix your program.\n", \
00134 __func__, # ptr); \
00135 ewl_backtrace(); \
00136 ewl_segv(); \
00137 return; \
00138 } \
00139 }
00140
00141 #define DCHECK_PARAM_PTR_RET(ptr, ret) \
00142 { \
00143 if (!(ptr)) \
00144 { \
00145 ewl_print_warning(); \
00146 fprintf(stderr, "\tThis program is calling:\n\n" \
00147 "\t%s();\n\n" \
00148 "\tWith the parameter:\n\n" \
00149 "\t%s\n\n" \
00150 "\tbeing NULL. Please fix your program.\n", \
00151 __func__, # ptr); \
00152 ewl_backtrace(); \
00153 ewl_segv(); \
00154 return ret; \
00155 } \
00156 }
00157
00158 #define DCHECK_TYPE(ptr, type) \
00159 { \
00160 if (ptr && !ewl_widget_type_is(EWL_WIDGET(ptr), type)) \
00161 { \
00162 ewl_print_warning(); \
00163 fprintf(stderr, "\tThis program is calling:\n\n" \
00164 "\t%s();\n\n" \
00165 "\tWith the paramter:\n\n" \
00166 "\t%s\n\n" \
00167 "\tas the wrong type. (%s) instead of (%s).\n" \
00168 "\tPlease fix your program.\n", \
00169 __func__, # ptr, \
00170 (EWL_WIDGET(ptr)->inheritance ? \
00171 EWL_WIDGET(ptr)->inheritance : \
00172 "NULL") , type); \
00173 ewl_backtrace(); \
00174 ewl_segv(); \
00175 return; \
00176 } \
00177 }
00178
00179 #define DCHECK_TYPE_RET(ptr, type, ret) \
00180 { \
00181 if (ptr && !ewl_widget_type_is(EWL_WIDGET(ptr), type)) \
00182 { \
00183 ewl_print_warning(); \
00184 fprintf(stderr, "\tThis program is calling:\n\n" \
00185 "\t%s();\n\n" \
00186 "\tWith the paramter:\n\n" \
00187 "\t%s\n\n" \
00188 "\tas the wrong type. (%s) instead of (%s).\n" \
00189 "\tPlease fix your program.\n", \
00190 __func__, # ptr, \
00191 (EWL_WIDGET(ptr)->inheritance ? \
00192 EWL_WIDGET(ptr)->inheritance : \
00193 "NULL") , type); \
00194 ewl_backtrace(); \
00195 ewl_segv(); \
00196 return ret; \
00197 } \
00198 }
00199
00200 #else
00201
00202 #define DENTER_FUNCTION(lvl) {}
00203 #define DLEAVE_FUNCTION(lvl) {}
00204 #define DRETURN(lvl) return
00205 #define DRETURN_PTR(ptr, lvl) return (void *)(ptr)
00206 #define DRETURN_FLOAT(num, lvl) return num
00207 #define DRETURN_INT(num, lvl) return num
00208 #define DWARNING(fmt, args...) {}
00209 #define DCHECK_PARAM_PTR(ptr) \
00210 { \
00211 if (!(ptr)) { \
00212 return; \
00213 } \
00214 }
00215 #define DCHECK_PARAM_PTR_RET(ptr, ret) \
00216 { \
00217 if (!(ptr)) { \
00218 return ret; \
00219 } \
00220 }
00221 #define DCHECK_TYPE(ptr, type) {}
00222 #define DCHECK_TYPE_RET(ptr, type, ret) {}
00223 #endif
00224
00225 #define DERROR(fmt) \
00226 { \
00227 ewl_print_warning(); \
00228 fprintf(stderr, "\tIn function:\n\n" \
00229 "\t%s();\n\n", __func__); \
00230 fprintf(stderr, fmt); \
00231 }
00232
00233 #endif
00234