JWM Source Documentation

debug.h
Go to the documentation of this file.
00001 
00010 /*
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  */
00026 
00027 #ifndef DEBUG_H
00028 #define DEBUG_H
00029 
00030 #ifndef MAKE_DEPEND
00031 #   include <stdarg.h>
00032 #   include <stdio.h>
00033 #   include <stdlib.h>
00034 #   include <string.h>
00035 #   ifdef HAVE_ALLOCA_H
00036 #      include <alloca.h>
00037 #   endif
00038 #endif /* MAKE_DEPEND */
00039 
00040 void Debug(const char *str, ...);
00041 
00042 #ifdef HAVE_ALLOCA_H
00043 
00044 #   define AllocateStack( x ) alloca( x )
00045 #   define ReleaseStack( x ) ((void)0)
00046 
00047 #else
00048 
00049 #   define AllocateStack( x ) Allocate( x )
00050 #   define ReleaseStack( x ) Release( x )
00051 
00052 #endif
00053 
00054 #ifdef DEBUG
00055 
00056 #   define Assert( x ) \
00057       if(!( x )) {     \
00058          Debug("ASSERT FAILED: %s[%u]", __FILE__, __LINE__ ); \
00059          abort(); \
00060       }
00061 
00062 #   define SetCheckpoint() \
00063       DEBUG_SetCheckpoint( __FILE__, __LINE__ )
00064 #   define ShowCheckpoint() \
00065       DEBUG_ShowCheckpoint()
00066 
00067 #   define StartDebug() \
00068       DEBUG_StartDebug( __FILE__, __LINE__ )
00069 #   define StopDebug() \
00070       DEBUG_StopDebug( __FILE__, __LINE__ )
00071 
00072 #   define Allocate( x ) \
00073       DEBUG_Allocate( (x), __FILE__, __LINE__ )
00074 #   define Reallocate( x, y ) \
00075       DEBUG_Reallocate( (x), (y), __FILE__, __LINE__ )
00076 #   define Release( x ) \
00077       DEBUG_Release( (void*)(& x), __FILE__, __LINE__ )
00078 
00079    void DEBUG_SetCheckpoint(const char*, unsigned int);
00080    void DEBUG_ShowCheckpoint();
00081 
00082    void DEBUG_StartDebug(const char*, unsigned int);
00083    void DEBUG_StopDebug(const char*, unsigned int);
00084 
00085    void *DEBUG_Allocate(size_t, const char*, unsigned int);
00086    void *DEBUG_Reallocate(void*, size_t, const char*, unsigned int);
00087    void DEBUG_Release(void**, const char*, unsigned int);
00088 
00089 #else /* DEBUG */
00090 
00091 #   define Assert( x )           ((void)0)
00092 
00093 #   define SetCheckpoint()       ((void)0)
00094 #   define ShowCheckpoint()      ((void)0)
00095 
00096 #   define StartDebug()          ((void)0)
00097 #   define StopDebug()           ((void)0)
00098 
00099 #   define Allocate( x )         malloc( (x) )
00100 #   define Reallocate( x, y )    realloc( (x), (y) )
00101 #   define Release( x )          free( (x) )
00102 
00103 #endif /* DEBUG */
00104 
00105 #endif /* DEBUG_H */
00106