dda8c8dadeae548cc00d541f6d31929e27b5ac3a
[profile/ivi/navit.git] / navit / navit / debug.h
1 /**
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2008 Navit Team
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19
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 #endif
33
34 extern int debug_level;
35 #define dbg_str2(x) #x
36 #define dbg_str1(x) dbg_str2(x)
37 #define dbg_module dbg_str1(MODULE)
38 #define dbg(level,...) { if (debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,__VA_ARGS__); }
39 #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)))
40
41 #define DEBUG_MODULE_GLOBAL "global"
42
43 #ifdef DEBUG_MALLOC
44 #undef g_new
45 #undef g_new0
46 #define g_new(type, size) (type *)debug_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,sizeof(type)*(size))
47 #define g_new0(type, size) (type *)debug_malloc0(__FILE__,__LINE__,__PRETTY_FUNCTION__,sizeof(type)*(size))
48 #define g_malloc(size) debug_malloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,(size))
49 #define g_malloc0(size) debug_malloc0(__FILE__,__LINE__,__PRETTY_FUNCTION__,(size))
50 #define g_realloc(ptr,size) debug_realloc(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr,(size))
51 #define g_free(ptr) debug_free(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr)
52 #define g_strdup(ptr) debug_strdup(__FILE__,__LINE__,__PRETTY_FUNCTION__,ptr)
53 #define g_strdup_printf(fmt...) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,g_strdup_printf(fmt))
54 #define graphics_icon_path(x) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,graphics_icon_path(x))
55 #define dbg_guard(x) debug_guard(__FILE__,__LINE__,__PRETTY_FUNCTION__,x)
56 #define g_free_func debug_free_func
57 #else
58 #define g_free_func g_free
59 #define dbg_guard(x) x
60 #endif
61
62 /* prototypes */
63 struct attr;
64 struct debug;
65 void debug_init(const char *program_name);
66 void debug_level_set(const char *name, int level);
67 struct debug *debug_new(struct attr *parent, struct attr **attrs);
68 int debug_level_get(const char *name);
69 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);
70 void debug_printf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, ...);
71 void debug_assert_fail(const char *module, const int mlen, const char *function, const int flen, const char *file, int line, const char *expr);
72 void debug_destroy(void);
73 void debug_set_logfile(const char *path);
74 void debug_dump_mallocs(void);
75 void *debug_malloc(const char *where, int line, const char *func, int size);
76 void *debug_malloc0(const char *where, int line, const char *func, int size);
77 char *debug_strdup(const char *where, int line, const char *func, const char *ptr);
78 char *debug_guard(const char *where, int line, const char *func, char *str);
79 void debug_free(const char *where, int line, const char *func, void *ptr);
80 void debug_free_func(void *ptr);
81 void debug_finished(void);
82 void *debug_realloc(const char *where, int line, const char *func, void *ptr, int size);
83 /* end of prototypes */
84
85 #ifdef __cplusplus
86 }
87 #endif
88
89 #endif
90