00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __DEBUG_H__
00026 #define __DEBUG_H__
00027
00028 #include "mconfig.h"
00029
00030
00031
00033
00034
00035
00036
00037
00038
00039
00041
00042 #ifndef NODEBUG
00043
00044 #define TRACELINE {fprintf (dbgout, "File:%s, Line#%d %s\n", __FILE__, __LINE__, __FUNCTION__); fflush (dbgout);}
00045 #define TRACE(expr) {fprintf (dbgout, "File:%s, Line#%d %s: ", __FILE__, __LINE__, __FUNCTION__); fprintf (dbgout, expr); fprintf (dbgout, "\n"); fflush (dbgout);}
00046 #define TRACE1(expr,par1) {fprintf (dbgout, "File:%s, Line#%d %s: ", __FILE__, __LINE__, __FUNCTION__); fprintf (dbgout, expr, par1); fprintf (dbgout, "\n"); fflush (dbgout);}
00047 #define TRACE2(expr,par1,par2) {fprintf (dbgout, "File:%s, Line#%d %s: ", __FILE__, __LINE__, __FUNCTION__); fprintf (dbgout, expr, par1, par2); fprintf (dbgout, "\n"); fflush (dbgout);}
00048 #define TRACE3(expr,par1,par2,par3) {fprintf (dbgout, "File:%s, Line#%d %s: ", __FILE__, __LINE__, __FUNCTION__); fprintf (dbgout, expr, par1, par2, par3); fprintf (dbgout, "\n"); fflush (dbgout);}
00049 #define TRACE4(expr,par1,par2,par3,par4) {fprintf (dbgout, "File:%s, Line#%d %s: ", __FILE__, __LINE__, __FUNCTION__); fprintf (dbgout, expr, par1, par2, par3, par4); fprintf (dbgout, "\n"); fflush (dbgout);}
00050
00051
00052 #ifndef QT_VERSION
00053 #define ASSERT(expr) {if (!(expr)) assertwith (__FILE__, __LINE__, __FUNCTION__, #expr);}
00054 #endif
00055
00056 #define ASSERTWITH(expr,message) {if (!(expr)) assertwith (__FILE__, __LINE__, __FUNCTION__, #expr, message);}
00057 #define PRE(expr) ASSERTWITH(expr, "Violation of precondition");
00058 #define POST(expr) ASSERTWITH(expr, "Violation of postcondition");
00059
00060 #else
00061
00062 #define TRACELINE
00063 #define ASSERT(expr)
00064 #define ASSERTWITH(expr,message)
00065 #define PRE(expr)
00066 #define POST(expr)
00067 #define TRACE(msg) {}
00068 #define TRACE1(msg,p1) {}
00069 #define TRACE2(msg,p1,p2) {}
00070 #define TRACE3(msg,p1,p2,p3) {}
00071 #define TRACE4(msg,p1,p2,p3,p4) {}
00072 #endif
00073
00074
00075
00077
00078
00079
00080
00081
00082
00083
00085
00086
00087 #ifndef DISABLE_ALL_MEMORY_DEBUGGING
00088
00089
00090 #define DEBUG_NEW new(__FILE__,__LINE__,__FUNCTION__)
00091 #ifdef new
00092 #undef new
00093 #define new_UNDEFD
00094 #define renew(p,ns) _renew (p,ns,__FILE__,__LINE__,__FUNCTION__)
00095 #else
00096 #define renew realloc
00097 #warning "Renew is realloc"
00098 #endif
00099
00100 extern void* operator new[] (size_t size, const char* filen, int lineno, const char* funcn);
00101 extern void* operator new (size_t size, const char* filen, int lineno, const char* funcn);
00102 extern void operator delete (void* p);
00103 extern void list_allocations (int number=100, FILE* out=stderr);
00104 extern void* _renew (void* p, size_t newsize, const char* filen, int lineno, const char* funcn);
00105 extern "C" void newComment (const char* comment);
00106
00107 #ifdef new_UNDEFD
00108 #define new DEBUG_NEW
00109 #undef new_UNDEFD
00110 #endif
00111
00112 struct mallocinfostr {
00113 char startsym[6];
00114 int size;
00115 const char* filename;
00116 int lineno;
00117 const char* funcname;
00118 char* newcomment;
00119 bool renewed;
00120 bool isObject;
00121 mallocinfostr* next;
00122 mallocinfostr* prev;
00123
00124
00125
00126 char padding[4];
00127 };
00128
00129 extern mallocinfostr* lastmalloced;
00130 extern int dbgnewmalloced;
00131
00132 #else // DISABLE_ALL_MEMORY_DEBUGGING
00133
00134
00135 #include <stdlib.h>
00136
00137 inline void* _renew (void* p, size_t newsize, const char* filen, int lineno, const char* funcn) {
00138 return realloc (p, newsize);
00139 }
00140 #define renew(p,ns) _renew (p,ns,__FILE__,__LINE__,__FUNCTION__)
00141
00142 inline void newComment (const char* comment) {}
00143
00144 #endif // DISABLE_ALL_MEMORY_DEBUGGING
00145
00146 #endif