9 TRACE : print with function name
10 TRACE0 : print without function name
11 TRACE1 : print "buf" whose size is "size"
16 extern HANDLE hdebugLog;
17 extern int defaultTraceSync;
18 #define TRACE0(fmt, msg...) { \
21 snprintf(__buf, sizeof(__buf), fmt, ##msg); \
22 WriteLog(hdebugLog, __buf, strlen(__buf), defaultTraceSync); \
25 #define TRACE1(buf, size) { \
26 WriteLog(hdebugLog, buf, size, defaultTraceSync); \
28 #define TRACE(fmt, msg...) { \
31 snprintf(__buf, sizeof(__buf), "[%s] " fmt, __FUNCTION__, ##msg); \
32 WriteLog(hdebugLog, __buf, strlen(__buf), defaultTraceSync); \
35 #define TRACEX(fmt) { \
38 snprintf(__buf, sizeof(__buf), "[%s] " fmt, __FUNCTION__); \
39 WriteLog(hdebugLog, __buf, strlen(__buf), defaultTraceSync); \
44 #define HERE TRACE("file %s, line %d, func %s\n", __FILE__, __LINE__, __FUNCTION__)
48 #define ASSERT(exp) { \
50 TRACE("ASSERTION (%s) FAILED in %s (%s:%d)\n", \
51 (#exp), __FUNCTION__, __FILE__, __LINE__); \
55 #define ASSERT(exp) 1 ? (void)0 : (exp)
58 /*--------------------------------------------------------------
59 macros used for debugging memory leaks
60 if DEBUG_MEMORY_LEAK is enabled, we track down all the memory
61 allocation/freeing to count the number of allocations
62 -------------------------------------------------------------*/
63 //#define DEBUG_MEMORY_LEAK
65 #ifndef DEBUG_MEMORY_LEAK
67 #define xcalloc(nmemb, size) calloc(nmemb, size)
68 #define xmalloc(size) malloc(size)
69 #define xrealloc(ptr, size) realloc(ptr, size)
70 #define xstrdup(s) strdup(s)
71 #define xfree(ptr) free(ptr)
75 #define xcalloc(nmemb, size) dbgcalloc(nmemb, size, __FUNCTION__, \
77 #define xmalloc(size) dbgmalloc(size, __FUNCTION__,\
79 #define xrealloc(ptr, size) dbgrealloc(ptr, size, __FUNCTION__,\
81 #define xstrdup(s) dbgstrdup(s, __FUNCTION__, __FILE__, __LINE__)
82 #define xfree(ptr) dbgfree(ptr, __FUNCTION__, __FILE__, __LINE__)
84 void *dbgcalloc(size_t nmemb, size_t size,
85 const char* func, const char* file, const int line);
86 void *dbgmalloc(size_t size,
87 const char* func, const char* file, const int line);
88 void *dbgrealloc(void *ptr, size_t size,
89 const char* func, const char* file, const int line);
90 char *dbgstrdup(const char *s,
91 const char* func, const char* file, const int line);
92 void dbgfree(void *ptr, const char* func, const char* file, const int line);
93 void dbg_print_memtrace(void);
95 #endif /* DEBUG_MEMOTY_LEAK */
97 #endif /* _DEBUG_H_ */