Navit SVN

/work/compile/navit/src/navit/debug.h

00001 
00020 #ifndef NAVIT_DEBUG_H
00021 #define NAVIT_DEBUG_H
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 #include <stdarg.h>
00028 #include <string.h>
00029 
00030 #ifdef _MSC_VER
00031 #define __PRETTY_FUNCTION__ __FUNCTION__
00032 #endif
00033 
00034 extern int debug_level;
00035 #define dbg_str2(x) #x
00036 #define dbg_str1(x) dbg_str2(x)
00037 #define dbg_module dbg_str1(MODULE)
00038 #define dbg(level,...) { if (debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,__VA_ARGS__); }
00039 #define dbg_assert(expr) ((expr) ? (void) 0 : debug_assert_fail(dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),__FILE__,__LINE__,dbg_str1(expr)))
00040 
00041 #define DEBUG_MODULE_GLOBAL "global"
00042 
00043 #ifdef DEBUG_MALLOC
00044 #undef g_new
00045 #undef g_new0
00046 #define g_new(type, size) (type *)debug_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,sizeof(type)*(size))
00047 #define g_new0(type, size) (type *)debug_malloc0(__FILE__,__LINE__,__PRETTY_FUNCTION__,sizeof(type)*(size))
00048 #define g_malloc(size) debug_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,(size))
00049 #define g_malloc0(size) debug_malloc0(__FILE__,__LINE__,__PRETTY_FUNCTION__,(size))
00050 #define g_realloc(ptr,size) debug_realloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr,(size))
00051 #define g_free(ptr) debug_free(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr)
00052 #define g_strdup(ptr) debug_strdup(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr)
00053 #define g_strdup_printf(fmt...) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,g_strdup_printf(fmt))
00054 #define graphics_icon_path(x) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,graphics_icon_path(x))
00055 #define dbg_guard(x) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,x)
00056 #define g_free_func debug_free_func
00057 #else
00058 #define g_free_func g_free
00059 #define dbg_guard(x) x
00060 #endif
00061 
00062 /* prototypes */
00063 struct attr;
00064 struct debug;
00065 void debug_init(const char *program_name);
00066 void debug_level_set(const char *name, int level);
00067 struct debug *debug_new(struct attr *parent, struct attr **attrs);
00068 int debug_level_get(const char *name);
00069 void debug_vprintf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap);
00070 void debug_printf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, ...);
00071 void debug_assert_fail(const char *module, const int mlen, const char *function, const int flen, const char *file, int line, const char *expr);
00072 void debug_destroy(void);
00073 void debug_set_logfile(const char *path);
00074 void debug_dump_mallocs(void);
00075 void *debug_malloc(const char *where, int line, const char *func, int size);
00076 void *debug_malloc0(const char *where, int line, const char *func, int size);
00077 char *debug_strdup(const char *where, int line, const char *func, const char *ptr);
00078 char *debug_guard(const char *where, int line, const char *func, char *str);
00079 void debug_free(const char *where, int line, const char *func, void *ptr);
00080 void debug_free_func(void *ptr);
00081 void debug_finished(void);
00082 void *debug_realloc(const char *where, int line, const char *func, void *ptr, int size);
00083 /* end of prototypes */
00084 
00085 #ifdef __cplusplus
00086 }
00087 #endif
00088 
00089 #endif
00090