summaryrefslogtreecommitdiff
path: root/navit/debug.h
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-05-01 10:34:46 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-05-01 10:34:46 +0000
commitfe95d3192d59f9b6baeb15011dbfdfcfe0636d5d (patch)
tree1357bee0704c91759ba52027e508735ff350528b /navit/debug.h
parent7fe94f8f1c4da2136c47dedc63411575bd5d8474 (diff)
downloadnavit-fe95d3192d59f9b6baeb15011dbfdfcfe0636d5d.tar.gz
Add:Core:Support for debugging memory leaks
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@3213 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/debug.h')
-rw-r--r--navit/debug.h32
1 files changed, 28 insertions, 4 deletions
diff --git a/navit/debug.h b/navit/debug.h
index f7d13d9de..2a5124fe0 100644
--- a/navit/debug.h
+++ b/navit/debug.h
@@ -33,17 +33,41 @@ extern int debug_level;
#define dbg(level,fmt...) ({ if (debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,fmt); })
#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)))
+#ifdef DEBUG_MALLOC
+#undef g_new
+#undef g_new0
+#define g_new(type, size) (type *)debug_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,sizeof(type)*(size))
+#define g_new0(type, size) (type *)debug_malloc0(__FILE__,__LINE__,__PRETTY_FUNCTION__,sizeof(type)*(size))
+#define g_free(ptr) debug_free(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr)
+#define g_strdup(ptr) debug_strdup(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr)
+#define g_strdup_printf(fmt...) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,g_strdup_printf(fmt))
+#define graphics_icon_path(x) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,graphics_icon_path(x))
+#define dbg_guard(x) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,x)
+#define g_free_func debug_free_func
+#else
+#define g_free_func g_free
+#define dbg_guard(x) x
+#endif
+
/* prototypes */
struct attr;
+struct debug;
void debug_init(const char *program_name);
-void debug_destroy(void);
-void debug_set_logfile(const char *path);
void debug_level_set(const char *name, int level);
-int debug_level_get(const char *name);
struct debug *debug_new(struct attr *parent, struct attr **attrs);
+int debug_level_get(const char *name);
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);
void debug_printf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, ...);
-void debug_assert_fail(char *module, const int mlen,const char *function, const int flen, char *file, int line, char *expr);
+void debug_assert_fail(char *module, const int mlen, const char *function, const int flen, char *file, int line, char *expr);
+void debug_destroy(void);
+void debug_set_logfile(const char *path);
+void debug_dump_mallocs(void);
+void *debug_malloc(const char *where, int line, const char *func, int size);
+void *debug_malloc0(const char *where, int line, const char *func, int size);
+char *debug_strdup(const char *where, int line, const char *func, const char *ptr);
+char *debug_guard(const char *where, int line, const char *func, char *str);
+void debug_free(const char *where, int line, const char *func, void *ptr);
+void debug_free_func(void *ptr);
void debug_finished(void);
/* end of prototypes */