00001
00002
00003
00004
00006
00007 #ifndef __DEBUG_H__
00008 #define __DEBUG_H__
00009
00010 #define USE_DEBUG_ROUTINES (TRUE)
00011 #define DEBUG_USE_MEMGUARD (FALSE)
00012 #define DEBUG_GUARD_BYTE (0xE3)
00013
00015
00016
00017
00018
00019
00020
00021
00023
00024 #if USE_DEBUG_ROUTINES
00025 #define malloc(x) DebugMalloc(x, __LINE__, __FILE__)
00026 #define free(x) DebugFree(x, __LINE__, __FILE__)
00027 #define ReleaseMalloc(x) ((void *)(LocalAlloc(LMEM_FIXED, (x))))
00028 #define ReleaseFree(x) (LocalFree((HLOCAL)(x)))
00029 #else
00030 #define malloc(x) ((void *)(LocalAlloc(LMEM_FIXED, (x))))
00031 #define free(x) (LocalFree((HLOCAL)(x)))
00032 #define ReleaseMalloc(x) malloc(x)
00033 #define ReleaseFree(x) free(x)
00034 #endif
00035
00036 #if DEBUG_USE_MEMGUARD
00037 #define DEBUG_MEMGUARD_TYPE long
00038 #define DEBUG_MEMGUARD_SIZE (sizeof(long))
00039 #define DEBUG_MEMGUARD_CONTENTS (0xe3e3e3e3)
00040 #else
00041 #define DEBUG_MEMGUARD_SIZE (0)
00042 #endif
00043
00044 typedef struct MemStorageStruct {
00045 void *Ptr;
00046 size_t Size;
00047 char *File;
00048 int Line;
00049
00050 struct MemStorageStruct *Prev;
00051 struct MemStorageStruct *Next;
00052 } MEMSTORE;
00053
00054 extern void *DebugMalloc(size_t size, int line, char *file);
00055 extern void DebugFree(void *p, int line, char *file);
00056 extern void CheckMemoryAllocation(void);
00057 extern void Error(char *mod, char *func, char *mess, long errno);
00058
00059
00060 extern size_t DBG_AllocatedRAM;
00061 extern char *DBG_LogFile;;
00062 extern bool TellChris;
00063
00065
00066
00067
00069
00070 #ifdef USE_DEBUG_ROUTINES
00071 #define Assert(x) DebugAssert((x), __LINE__, __FILE__)
00072 #else
00073 #define Assert(x) (NULL)
00074 #endif
00075
00076 extern void DebugAssert(bool ExpResult, int line, char *file);
00077
00078
00079
00080
00082
00083
00084
00086
00087 extern void InitLogFile();
00088 extern void WriteLogEntry(char *s);
00089
00090
00091 #endif