Go to the documentation of this file.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
00026
00027
00028 #ifndef MEMORYCHECKERPRIVATE_H
00029 #define MEMORYCHECKERPRIVATE_H
00030
00031 #ifdef MEMORY_CHECKER
00032
00033 #include <QtCore>
00034
00035 namespace QGpCoreTools {
00036
00037 #ifdef Q_WS_X11 // dll mechanism does not allow a secure allocation
00038
00039 #define DO_MEMORY_CHECK
00040 #endif
00041 #define ABORT_ON_WARNING
00042
00043
00044 #undef new
00045 #undef isBlockDamaged
00046 #undef printBlockInfo
00047
00048 #ifdef DO_MEMORY_CHECK
00049
00050 struct BlockInfo
00051 {
00052 void * blockAddress;
00053 unsigned int sz;
00054 bool record;
00055 const char * fName;
00056 int fLine;
00057 BlockInfo * next;
00058 BlockInfo * previous;
00059 };
00060
00061 #define NOMANSLAND_SIZE 16
00062 #define HEADER_SIZE (sizeof(BlockInfo *)+NOMANSLAND_SIZE)
00063 #define TAIL_SIZE NOMANSLAND_SIZE
00064
00065 class MemoryCheckerPrivate
00066 {
00067 public:
00068 static inline void* allocateBlock(std::size_t sz, const char* file, int line);
00069 static inline void freeBlock(void* v);
00070
00071 static void setEnabled(bool e) {_enabled=e;}
00072 static bool isEnabled() {return _enabled;}
00073
00074 static void setRecord(bool r) {_record=r;}
00075 static void setVerbose(bool v) {_verbose=v;}
00076
00077 static void checkBlocks(bool showLib, bool showUndeleted, const char* file, int line);
00078 static bool isBlockDamaged(void* v, const char* file, int line);
00079 static void printBlockInfo(void * ptr, const char* file, int line);
00080 private:
00081 static void printHeader(FILE * f, const char * prefix, unsigned char * ptr);
00082 static inline bool testNoMansLand(unsigned char * ptr);
00083 static inline BlockInfo * addBlock(void * blockAddress, unsigned int sz, const char * fName, int fLine);
00084 static inline void delBlock(BlockInfo * b);
00085 static inline BlockInfo * findBlock(void * blockAddress);
00086 static inline void srcLocation(const char * fName, int fLine);
00087 static inline void srcLocation(BlockInfo * b);
00088
00089 static bool _enabled;
00090 static bool _record;
00091 static bool _verbose;
00092 static BlockInfo * _infos;
00093 static QMutex _mutex;
00094 };
00095
00096 #endif // DO_MEMORY_CHECK
00097
00098 }
00099
00100 #endif // MEMORY_CHECKER
00101
00102 #endif // MEMORYCHECKERPRIVATE_H