Download

Support

lib/ewl_debug.h

Go to the documentation of this file.
00001 /* vim: set sw=8 ts=8 sts=8 expandtab: */
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 int  ewl_cast_pointer_to_integer(void *ptr);
00018 
00022 typedef struct Ewl_Config_Cache Ewl_Config_Cache;
00023 
00027 struct Ewl_Config_Cache
00028 {
00029         int level;                        
00030         unsigned char enable:1;                
00031         unsigned char segv:1;                
00032         unsigned char backtrace:1;        
00033         unsigned char evas_render:1;        
00034         unsigned char gc_reap:1;        
00036         unsigned char print_signals:1;        
00037         unsigned char print_keys:1;        
00038 };
00039 
00040 extern Ewl_Config_Cache ewl_config_cache; 
00042 #ifdef __GNUC__
00043 #define DSTATIC_ASSERT_HELPER(expr) \
00044     (!!sizeof \
00045      (struct { unsigned int STATIC_ASSERTION: (expr) ? 1 : -1; }))
00046 #define DSTATIC_ASSERT(expr) \
00047     extern int (*assert_function__(void)) [DSTATIC_ASSERT_HELPER(expr)]
00048 #else
00049     #define DSTATIC_ASSERT(expr)   \
00050     extern char STATIC_ASSERTION[1]; \
00051     extern char STATIC_ASSERTION[(expr)?1:2]
00052 #endif
00053 
00054 #if EWL_ENABLE_DEBUG
00055 
00056 #define DEBUGGING(lvl) (ewl_config_cache.enable && (ewl_config_cache.level >= (lvl)))
00057 
00058 #define DENTER_FUNCTION(lvl) \
00059 do { \
00060         if (DEBUGGING(lvl)) \
00061           { \
00062                 ewl_debug_indent_print(1); \
00063                 fprintf(stderr, "--> %f - %s:%i\tEntering %s();\n", \
00064                         ecore_time_get(), __FILE__, __LINE__, __func__); \
00065           } \
00066 } while (0)
00067 
00068 #define DLEAVE_FUNCTION(lvl) \
00069 do { \
00070         if (DEBUGGING(lvl)) \
00071           { \
00072                 ewl_debug_indent_print(-1); \
00073                 fprintf(stderr, "<--  %f - %s:%i\tLeaving  %s();\n", \
00074                         ecore_time_get(), __FILE__, __LINE__, __func__); \
00075           } \
00076 } while (0)
00077 
00078 #define DRETURN(lvl) \
00079 do { \
00080         DLEAVE_FUNCTION(lvl); \
00081         if (DEBUGGING(lvl)) \
00082           { \
00083                 ewl_debug_indent_print(0); \
00084                 fprintf(stderr, "<-- %f - %s:%i\tReturn in %s();\n", \
00085                         ecore_time_get(), __FILE__, __LINE__, __func__); \
00086           } \
00087         return; \
00088 } while (0)
00089 
00090 #define DRETURN_PTR(ptr, lvl) \
00091 do { \
00092         DLEAVE_FUNCTION(lvl); \
00093         if (DEBUGGING(lvl)) \
00094           { \
00095                 ewl_debug_indent_print(0); \
00096                 fprintf(stderr, "<-- %f - %s:%i\tReturning %p in %s();\n", \
00097                         ecore_time_get(), __FILE__, __LINE__, (void *) (ptr), __func__); \
00098           } \
00099         return ptr; \
00100 } while (0)
00101 
00102 #define DRETURN_FLOAT(num, lvl) \
00103 do { \
00104         DLEAVE_FUNCTION(lvl); \
00105         if (DEBUGGING(lvl)) \
00106           { \
00107                 ewl_debug_indent_print(0); \
00108                 fprintf(stderr, "<-- %f - %s:%i\tReturning %f in %s();\n", \
00109                         ecore_time_get(), __FILE__, __LINE__, (float) (num), __func__); \
00110           } \
00111         return num; \
00112 } while (0)
00113 
00114 #define DRETURN_INT(num, lvl) \
00115 do { \
00116         DLEAVE_FUNCTION(lvl); \
00117         if (DEBUGGING(lvl)) \
00118           { \
00119                 ewl_debug_indent_print(0); \
00120                 fprintf(stderr, "<-- %f - %s:%i\tReturning %i in %s();\n", \
00121                         ecore_time_get(), __FILE__, __LINE__, (int) (num), __func__); \
00122           } \
00123         return num; \
00124 } while (0)
00125 
00126 #define DWARNING(fmt, args...) \
00127 do { \
00128         ewl_print_warning(); \
00129         fprintf(stderr, "\tIn function:\n\n" \
00130                         "\t%s();\n\n", __func__); \
00131         fprintf(stderr, fmt, ## args); \
00132         fprintf(stderr, "\n"); \
00133         ewl_backtrace(); \
00134         ewl_segv(); \
00135 } while (0)
00136 
00137 #define DCHECK_PARAM_PTR(ptr) \
00138 do { \
00139         if ((ptr) == NULL) \
00140           { \
00141                 ewl_print_warning(); \
00142                 fprintf(stderr, "\tThis program is calling:\n\n" \
00143                                 "\t%s();\n\n" \
00144                                 "\tWith the parameter:\n\n" \
00145                                 "\t%s\n\n" \
00146                                 "\tbeing NULL. Please fix your program.\n", \
00147                                 __func__, # ptr); \
00148                 ewl_backtrace(); \
00149                 ewl_segv(); \
00150                 return; \
00151           } \
00152 } while (0)
00153 
00154 #define DCHECK_PARAM_PTR_RET(ptr, ret) \
00155 do { \
00156         if ((ptr) == NULL) \
00157           { \
00158                 ewl_print_warning(); \
00159                 fprintf(stderr, "\tThis program is calling:\n\n" \
00160                                 "\t%s();\n\n" \
00161                                 "\tWith the parameter:\n\n" \
00162                                 "\t%s\n\n" \
00163                                 "\tbeing NULL. Please fix your program.\n", \
00164                                 __func__, # ptr); \
00165                 ewl_backtrace(); \
00166                 ewl_segv(); \
00167                 return ret; \
00168           } \
00169 } while (0)
00170 
00171 #define DCHECK_TYPE(ptr, type) \
00172 do { \
00173         if (ptr && !ewl_widget_type_is(EWL_WIDGET(ptr), type)) \
00174         { \
00175                 ewl_print_warning(); \
00176                 fprintf(stderr, "\tThis program is calling:\n\n" \
00177                                 "\t%s();\n\n" \
00178                                 "\tWith the paramter:\n\n" \
00179                                 "\t%s\n\n" \
00180                                 "\tas the wrong type. (%s) instead of (%s).\n" \
00181                                 "\tPlease fix your program.\n", \
00182                                 __func__, # ptr, \
00183                                 (EWL_WIDGET(ptr)->inheritance ? \
00184                                         EWL_WIDGET(ptr)->inheritance : \
00185                                         "NULL") , type); \
00186                 ewl_backtrace(); \
00187                 ewl_segv(); \
00188                 return; \
00189         } \
00190 } while (0)
00191 
00192 #define DCHECK_TYPE_RET(ptr, type, ret) \
00193 do { \
00194         if (ptr && !ewl_widget_type_is(EWL_WIDGET(ptr), type)) \
00195         { \
00196                 ewl_print_warning(); \
00197                 fprintf(stderr, "\tThis program is calling:\n\n" \
00198                                 "\t%s();\n\n" \
00199                                 "\tWith the paramter:\n\n" \
00200                                 "\t%s\n\n" \
00201                                 "\tas the wrong type. (%s) instead of (%s).\n" \
00202                                 "\tPlease fix your program.\n", \
00203                                 __func__, # ptr, \
00204                                 (EWL_WIDGET(ptr)->inheritance ? \
00205                                         EWL_WIDGET(ptr)->inheritance : \
00206                                         "NULL") , type); \
00207                 ewl_backtrace(); \
00208                 ewl_segv(); \
00209                 return ret; \
00210         } \
00211 } while (0)
00212 
00213 #else
00214 
00215 #define DENTER_FUNCTION(lvl) {}
00216 #define DLEAVE_FUNCTION(lvl) {}
00217 #define DRETURN(lvl) return
00218 #define DRETURN_PTR(ptr, lvl) return (ptr)
00219 #define DRETURN_FLOAT(num, lvl) return num
00220 #define DRETURN_INT(num, lvl) return num
00221 #define DWARNING(fmt, args...) {}
00222 #define DCHECK_PARAM_PTR(ptr) \
00223 do { \
00224         if (!(ptr)) { \
00225                 return; \
00226         } \
00227 } while (0)
00228 #define DCHECK_PARAM_PTR_RET(ptr, ret) \
00229 do { \
00230         if (!(ptr)) { \
00231                 return ret; \
00232         } \
00233 } while (0)
00234 #define DCHECK_TYPE(ptr, type) {}
00235 #define DCHECK_TYPE_RET(ptr, type, ret) {}
00236 #endif
00237 
00238 #define DERROR(fmt) \
00239 do { \
00240         ewl_print_warning(); \
00241         fprintf(stderr, "\tIn function:\n\n" \
00242                         "\t%s();\n\n", __func__); \
00243         fprintf(stderr, fmt); \
00244 } while (0)
00245 
00246 #endif
00247 

Copyright © Enlightenment.org

Enlightened Widget Library Documentation Generated: Sun Sep 27 01:48:49 2009