navit  0.5.1-trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups
debug.h
Go to the documentation of this file.
1 
20 #ifndef NAVIT_DEBUG_H
21 #define NAVIT_DEBUG_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include <stdarg.h>
28 #include <string.h>
29 
30 #ifdef _MSC_VER
31 #define __PRETTY_FUNCTION__ __FUNCTION__
32 
33 /* Uncomment the following define to enable MSVC's memory debugging support */
34 /*#define _CRTDBG_MAP_ALLOC*/
35 #ifdef _CRTDBG_MAP_ALLOC
36 #include <stdlib.h>
37 #include <crtdbg.h>
38 #endif
39 #endif
40 
42 typedef enum {
53 } dbg_level;
54 
56 #define dbg_str2(x) #x
57 #define dbg_str1(x) dbg_str2(x)
58 #define dbg_module dbg_str1(MODULE)
59 #define dbg(level,...) { if (max_debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,__VA_ARGS__); }
60 #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)))
61 
62 #define DEBUG_MODULE_GLOBAL "global"
63 
64 #ifdef DEBUG_MALLOC
65 #undef g_new
66 #undef g_new0
67 #define g_new(type, size) (type *)debug_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,sizeof(type)*(size))
68 #define g_new0(type, size) (type *)debug_malloc0(__FILE__,__LINE__,__PRETTY_FUNCTION__,sizeof(type)*(size))
69 #define g_malloc(size) debug_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,(size))
70 #define g_malloc0(size) debug_malloc0(__FILE__,__LINE__,__PRETTY_FUNCTION__,(size))
71 #define g_realloc(ptr,size) debug_realloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr,(size))
72 #define g_free(ptr) debug_free(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr)
73 #define g_strdup(ptr) debug_strdup(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr)
74 #define g_strdup_printf(fmt...) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,g_strdup_printf(fmt))
75 #define graphics_icon_path(x) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,graphics_icon_path(x))
76 #define dbg_guard(x) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,x)
77 #define g_free_func debug_free_func
78 #else
79 #define g_free_func g_free
80 #define dbg_guard(x) x
81 #endif
82 
83 /* prototypes */
84 struct attr;
85 struct debug;
86 void debug_init(const char *program_name);
87 void debug_level_set(const char *name, dbg_level level);
88 struct debug *debug_new(struct attr *parent, struct attr **attrs);
89 dbg_level debug_level_get(const char *name);
90 void debug_vprintf(dbg_level level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap);
91 void debug_printf(dbg_level level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, ...)
92 #ifdef __GNUC__
93  __attribute__ ((format (printf, 7, 8)))
94 #endif
95 ;
96 void debug_assert_fail(const char *module, const int mlen, const char *function, const int flen, const char *file, int line, const char *expr);
97 void debug_destroy(void);
98 void debug_set_logfile(const char *path);
99 void debug_dump_mallocs(void);
100 void *debug_malloc(const char *where, int line, const char *func, int size);
101 void *debug_malloc0(const char *where, int line, const char *func, int size);
102 char *debug_strdup(const char *where, int line, const char *func, const char *ptr);
103 char *debug_guard(const char *where, int line, const char *func, char *str);
104 void debug_free(const char *where, int line, const char *func, void *ptr);
105 void debug_free_func(void *ptr);
106 void debug_finished(void);
107 void *debug_realloc(const char *where, int line, const char *func, void *ptr, int size);
108 void debug_set_global_level(dbg_level level, int override_old_value);
109 /* end of prototypes */
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif
116 
void debug_level_set(const char *name, dbg_level level)
Definition: debug.c:122
Definition: debug.h:50
void debug_free(const char *where, int line, const char *func, void *ptr)
Definition: debug.c:488
void debug_free_func(void *ptr)
Definition: debug.c:514
void * debug_realloc(const char *where, int line, const char *func, void *ptr, int size)
Definition: debug.c:456
Definition: gpx2navit_txt.h:51
int size
Definition: garmin_img.c:131
Definition: garmin_img.c:513
struct map_priv __attribute__
Definition: debug.h:44
void * debug_malloc0(const char *where, int line, const char *func, int size)
Definition: debug.c:447
char * debug_strdup(const char *where, int line, const char *func, const char *ptr)
Definition: debug.c:466
void debug_assert_fail(const char *module, const int mlen, const char *function, const int flen, const char *file, int line, const char *expr)
Definition: debug.c:345
Definition: debug.h:48
dbg_level
Definition: debug.h:42
Definition: debug.h:46
Definition: debug.h:52
dbg_level debug_level_get(const char *name)
Definition: debug.c:210
void * debug_malloc(const char *where, int line, const char *func, int size)
Definition: debug.c:407
void debug_set_logfile(const char *path)
Definition: debug.c:362
dbg_level max_debug_level
Definition: debug.c:56
void debug_finished(void)
Definition: debug.c:519
void debug_set_global_level(dbg_level level, int override_old_value)
Definition: debug.c:112
Definition: attr.h:156
struct debug * debug_new(struct attr *parent, struct attr **attrs)
Definition: debug.c:169
FILE * debug
Definition: pedestrian.c:385
void debug_dump_mallocs(void)
Definition: debug.c:390
void debug_printf(dbg_level level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt,...)
Definition: debug.c:336
char name[0]
Definition: street.c:559
void debug_destroy(void)
Definition: debug.c:352
char * debug_guard(const char *where, int line, const char *func, char *str)
Definition: debug.c:480
void debug_vprintf(dbg_level level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap)
Definition: debug.c:285
void debug_init(const char *program_name)
Definition: debug.c:89
Definition: file.h:36