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); \
43 #define HERE TRACE("file %s, line %d, func %s\n", __FILE__, __LINE__, __FUNCTION__)
47 #define ASSERT(exp) { \
49 TRACE("ASSERTION (%s) FAILED in %s (%s:%d)\n", \
50 (#exp), __FUNCTION__, __FILE__, __LINE__); \
54 #define ASSERT(exp) 1 ? (void)0 : (exp)
57 /*--------------------------------------------------------------
58 macros used for debugging memory leaks
59 if DEBUG_MEMORY_LEAK is enabled, we track down all the memory
60 allocation/freeing to count the number of allocations
61 -------------------------------------------------------------*/
62 //#define DEBUG_MEMORY_LEAK
64 #ifndef DEBUG_MEMORY_LEAK
66 #define xcalloc(nmemb, size) calloc(nmemb, size)
67 #define xmalloc(size) malloc(size)
68 #define xrealloc(ptr, size) realloc(ptr, size)
69 #define xstrdup(s) strdup(s)
70 #define xfree(ptr) free(ptr)
74 #define xcalloc(nmemb, size) dbgcalloc(nmemb, size, __FUNCTION__, \
76 #define xmalloc(size) dbgmalloc(size, __FUNCTION__,\
78 #define xrealloc(ptr, size) dbgrealloc(ptr, size, __FUNCTION__,\
80 #define xstrdup(s) dbgstrdup(s, __FUNCTION__, __FILE__, __LINE__)
81 #define xfree(ptr) dbgfree(ptr, __FUNCTION__, __FILE__, __LINE__)
83 void *dbgcalloc(size_t nmemb, size_t size,
84 const char* func, const char* file, const int line);
85 void *dbgmalloc(size_t size,
86 const char* func, const char* file, const int line);
87 void *dbgrealloc(void *ptr, size_t size,
88 const char* func, const char* file, const int line);
89 char *dbgstrdup(const char *s,
90 const char* func, const char* file, const int line);
91 void dbgfree(void *ptr, const char* func, const char* file, const int line);
92 void dbg_print_memtrace(void);
94 #endif /* DEBUG_MEMOTY_LEAK */
96 #endif /* _DEBUG_H_ */