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 #if EWL_ENABLE_DEBUG
00043 
00044 #define DEBUGGING(lvl) (ewl_config_cache.enable && (ewl_config_cache.level >= (lvl)))
00045 
00046 #define DENTER_FUNCTION(lvl) \
00047 do { \
00048         if (DEBUGGING(lvl)) \
00049           { \
00050                 ewl_debug_indent_print(1); \
00051                 fprintf(stderr, "--> %f - %s:%i\tEntering %s();\n", \
00052                         ecore_time_get(), __FILE__, __LINE__, __func__); \
00053           } \
00054 } while (0)
00055 
00056 #define DLEAVE_FUNCTION(lvl) \
00057 do { \
00058         if (DEBUGGING(lvl)) \
00059           { \
00060                 ewl_debug_indent_print(-1); \
00061                 fprintf(stderr, "<--  %f - %s:%i\tLeaving  %s();\n", \
00062                         ecore_time_get(), __FILE__, __LINE__, __func__); \
00063           } \
00064 } while (0)
00065 
00066 #define DRETURN(lvl) \
00067 do { \
00068         DLEAVE_FUNCTION(lvl); \
00069         if (DEBUGGING(lvl)) \
00070           { \
00071                 ewl_debug_indent_print(0); \
00072                 fprintf(stderr, "<-- %f - %s:%i\tReturn in %s();\n", \
00073                         ecore_time_get(), __FILE__, __LINE__, __func__); \
00074           } \
00075         return; \
00076 } while (0)
00077 
00078 #define DRETURN_PTR(ptr, lvl) \
00079 do { \
00080         DLEAVE_FUNCTION(lvl); \
00081         if (DEBUGGING(lvl)) \
00082           { \
00083                 ewl_debug_indent_print(0); \
00084                 fprintf(stderr, "<-- %f - %s:%i\tReturning %p in %s();\n", \
00085                         ecore_time_get(), __FILE__, __LINE__, (void *) (ptr), __func__); \
00086           } \
00087         return ptr; \
00088 } while (0)
00089 
00090 #define DRETURN_FLOAT(num, 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 %f in %s();\n", \
00097                         ecore_time_get(), __FILE__, __LINE__, (float) (num), __func__); \
00098           } \
00099         return num; \
00100 } while (0)
00101 
00102 #define DRETURN_INT(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 %i in %s();\n", \
00109                         ecore_time_get(), __FILE__, __LINE__, (int) (num), __func__); \
00110           } \
00111         return num; \
00112 } while (0)
00113 
00114 #define DWARNING(fmt, args...) \
00115 do { \
00116         ewl_print_warning(); \
00117         fprintf(stderr, "\tIn function:\n\n" \
00118                         "\t%s();\n\n", __func__); \
00119         fprintf(stderr, fmt, ## args); \
00120         fprintf(stderr, "\n"); \
00121         ewl_backtrace(); \
00122         ewl_segv(); \
00123 } while (0)
00124 
00125 #define DCHECK_PARAM_PTR(ptr) \
00126 do { \
00127         if (!(ptr)) \
00128           { \
00129                 ewl_print_warning(); \
00130                 fprintf(stderr, "\tThis program is calling:\n\n" \
00131                                 "\t%s();\n\n" \
00132                                 "\tWith the parameter:\n\n" \
00133                                 "\t%s\n\n" \
00134                                 "\tbeing NULL. Please fix your program.\n", \
00135                                 __func__, # ptr); \
00136                 ewl_backtrace(); \
00137                 ewl_segv(); \
00138                 return; \
00139           } \
00140 } while (0)
00141 
00142 #define DCHECK_PARAM_PTR_RET(ptr, ret) \
00143 do { \
00144         if (!(ptr)) \
00145           { \
00146                 ewl_print_warning(); \
00147                 fprintf(stderr, "\tThis program is calling:\n\n" \
00148                                 "\t%s();\n\n" \
00149                                 "\tWith the parameter:\n\n" \
00150                                 "\t%s\n\n" \
00151                                 "\tbeing NULL. Please fix your program.\n", \
00152                                 __func__, # ptr); \
00153                 ewl_backtrace(); \
00154                 ewl_segv(); \
00155                 return ret; \
00156           } \
00157 } while (0)
00158 
00159 #define DCHECK_TYPE(ptr, type) \
00160 do { \
00161         if (ptr && !ewl_widget_type_is(EWL_WIDGET(ptr), type)) \
00162         { \
00163                 ewl_print_warning(); \
00164                 fprintf(stderr, "\tThis program is calling:\n\n" \
00165                                 "\t%s();\n\n" \
00166                                 "\tWith the paramter:\n\n" \
00167                                 "\t%s\n\n" \
00168                                 "\tas the wrong type. (%s) instead of (%s).\n" \
00169                                 "\tPlease fix your program.\n", \
00170                                 __func__, # ptr, \
00171                                 (EWL_WIDGET(ptr)->inheritance ? \
00172                                         EWL_WIDGET(ptr)->inheritance : \
00173                                         "NULL") , type); \
00174                 ewl_backtrace(); \
00175                 ewl_segv(); \
00176                 return; \
00177         } \
00178 } while (0)
00179 
00180 #define DCHECK_TYPE_RET(ptr, type, ret) \
00181 do { \
00182         if (ptr && !ewl_widget_type_is(EWL_WIDGET(ptr), type)) \
00183         { \
00184                 ewl_print_warning(); \
00185                 fprintf(stderr, "\tThis program is calling:\n\n" \
00186                                 "\t%s();\n\n" \
00187                                 "\tWith the paramter:\n\n" \
00188                                 "\t%s\n\n" \
00189                                 "\tas the wrong type. (%s) instead of (%s).\n" \
00190                                 "\tPlease fix your program.\n", \
00191                                 __func__, # ptr, \
00192                                 (EWL_WIDGET(ptr)->inheritance ? \
00193                                         EWL_WIDGET(ptr)->inheritance : \
00194                                         "NULL") , type); \
00195                 ewl_backtrace(); \
00196                 ewl_segv(); \
00197                 return ret; \
00198         } \
00199 } while (0)
00200 
00201 #else
00202 
00203 #define DENTER_FUNCTION(lvl) {}
00204 #define DLEAVE_FUNCTION(lvl) {}
00205 #define DRETURN(lvl) return
00206 #define DRETURN_PTR(ptr, lvl) return (ptr)
00207 #define DRETURN_FLOAT(num, lvl) return num
00208 #define DRETURN_INT(num, lvl) return num
00209 #define DWARNING(fmt, args...) {}
00210 #define DCHECK_PARAM_PTR(ptr) \
00211 do { \
00212         if (!(ptr)) { \
00213                 return; \
00214         } \
00215 } while (0)
00216 #define DCHECK_PARAM_PTR_RET(ptr, ret) \
00217 do { \
00218         if (!(ptr)) { \
00219                 return ret; \
00220         } \
00221 } while (0)
00222 #define DCHECK_TYPE(ptr, type) {}
00223 #define DCHECK_TYPE_RET(ptr, type, ret) {}
00224 #endif
00225 
00226 #define DERROR(fmt) \
00227 do { \
00228         ewl_print_warning(); \
00229         fprintf(stderr, "\tIn function:\n\n" \
00230                         "\t%s();\n\n", __func__); \
00231         fprintf(stderr, fmt); \
00232 } while (0)
00233 
00234 #endif
00235 

Copyright © Enlightenment.org

Enlightened Widget Library Documentation Generated: Fri Jan 23 21:56:24 2009