8 TRACE : print with function name
9 TRACE0 : print without function name
10 TRACE1 : print "buf" whose size is "size"
15 extern HANDLE hdebugLog;
16 extern int defaultTraceSync;
17 #define TRACE0(fmt, msg...) { \
20 snprintf(__buf, sizeof(__buf), fmt, ##msg); \
21 WriteLog(hdebugLog, __buf, strlen(__buf), defaultTraceSync); \
24 #define TRACE1(buf, size) { \
25 WriteLog(hdebugLog, buf, size, defaultTraceSync); \
27 #define TRACE(fmt, msg...) { \
30 snprintf(__buf, sizeof(__buf), "[%s] " fmt, __FUNCTION__, ##msg); \
31 WriteLog(hdebugLog, __buf, strlen(__buf), defaultTraceSync); \
34 #define TRACEX(fmt) { \
37 snprintf(__buf, sizeof(__buf), "[%s] " fmt, __FUNCTION__); \
38 WriteLog(hdebugLog, __buf, strlen(__buf), defaultTraceSync); \
42 #define TRACE0(fmt, msg...) (void)0
43 #define TRACE1(fmt, msg...) (void)0
44 #define TRACE(fmt, msg...) (void)0
45 #define TRACEX(fmt) (void)0
48 /*--------------------------------------------------------------
49 macros used for debugging memory leaks
50 if DEBUG_MEMORY_LEAK is enabled, we track down all the memory
51 allocation/freeing to count the number of allocations
52 -------------------------------------------------------------*/
53 //#define DEBUG_MEMORY_LEAK
55 #ifndef DEBUG_MEMORY_LEAK
57 #define xcalloc(nmemb, size) calloc(nmemb, size)
58 #define xmalloc(size) malloc(size)
59 #define xrealloc(ptr, size) realloc(ptr, size)
60 #define xstrdup(s) strdup(s)
61 #define xfree(ptr) free(ptr)
66 #error "define DEBUG first to make DEBUG_MEMORY_LEAK work"
69 #define xcalloc(nmemb, size) dbgcalloc(nmemb, size, __FUNCTION__, \
71 #define xmalloc(size) dbgmalloc(size, __FUNCTION__, \
73 #define xrealloc(ptr, size) dbgrealloc(ptr, size, __FUNCTION__, \
75 #define xstrdup(s) dbgstrdup(s, __FUNCTION__, __FILE__, __LINE__)
76 #define xfree(ptr) dbgfree(ptr, __FUNCTION__, __FILE__, __LINE__)
78 void *dbgcalloc(size_t nmemb, size_t size,
79 const char* func, const char* file, const int line);
80 void *dbgmalloc(size_t size,
81 const char* func, const char* file, const int line);
82 void *dbgrealloc(void *ptr, size_t size,
83 const char* func, const char* file, const int line);
84 char *dbgstrdup(const char *s,
85 const char* func, const char* file, const int line);
86 void dbgfree(void *ptr, const char* func, const char* file, const int line);
87 void dbg_print_memtrace(void);
89 #endif /* DEBUG_MEMOTY_LEAK */
91 #endif /* _DEBUG_H_ */