1 /**
2  * @file debug.h
3  * @author Joe Wingbermuehle
4  * @date 2003-2006
5  *
6  * @brief Header for the debug functions.
7  *
8  */
9 
10 #ifndef DEBUG_H
11 #define DEBUG_H
12 
13 #include "../config.h"
14 
15 #ifndef MAKE_DEPEND
16 #   include <stdlib.h>
17 #   ifdef HAVE_ALLOCA_H
18 #      include <alloca.h>
19 #   elif defined __GNUC__
20 #      define alloca __builtin_alloca
21 #   elif defined _AIX
22 #      define alloca __alloca
23 #   elif defined _MSC_VER
24 #      include <malloc.h>
25 #      define alloca _alloca
26 #   elif defined HAVE_ALLOCA
27 void *alloca(size_t);
28 #   endif
29 #endif /* MAKE_DEPEND */
30 
31 void Debug(const char *str, ...);
32 
33 #ifdef HAVE_ALLOCA
34 
35 #   define AllocateStack( x ) alloca( x )
36 #   define ReleaseStack( x ) ((void)0)
37 
38 #else
39 
40 #   define AllocateStack( x ) Allocate( x )
41 #   define ReleaseStack( x ) Release( x )
42 
43 #endif
44 
45 #ifdef DEBUG
46 
47 #   define Assert( x ) \
48       if(!( x )) {     \
49          Debug("ASSERT FAILED: %s[%u]", __FILE__, __LINE__ ); \
50          abort(); \
51       }
52 
53 #   define SetCheckpoint() \
54       DEBUG_SetCheckpoint( __FILE__, __LINE__ )
55 #   define ShowCheckpoint() \
56       DEBUG_ShowCheckpoint()
57 
58 #   define StartDebug() \
59       DEBUG_StartDebug( __FILE__, __LINE__ )
60 #   define StopDebug() \
61       DEBUG_StopDebug( __FILE__, __LINE__ )
62 
63 #   define Allocate( x ) \
64       DEBUG_Allocate( (x), __FILE__, __LINE__ )
65 #   define Reallocate( x, y ) \
66       DEBUG_Reallocate( (x), (y), __FILE__, __LINE__ )
67 #   define Release( x ) \
68       DEBUG_Release( (void*)(& x), __FILE__, __LINE__ )
69 
70    void DEBUG_SetCheckpoint(const char*, unsigned int);
71    void DEBUG_ShowCheckpoint(void);
72 
73    void DEBUG_StartDebug(const char*, unsigned int);
74    void DEBUG_StopDebug(const char*, unsigned int);
75 
76    void *DEBUG_Allocate(size_t, const char*, unsigned int);
77    void *DEBUG_Reallocate(void*, size_t, const char*, unsigned int);
78    void DEBUG_Release(void**, const char*, unsigned int);
79 
80 #else /* DEBUG */
81 
82 #   define Assert( x )           ((void)0)
83 
84 #   define SetCheckpoint()       ((void)0)
85 #   define ShowCheckpoint()      ((void)0)
86 
87 #   define StartDebug()          ((void)0)
88 #   define StopDebug()           ((void)0)
89 
90 #   define Allocate( x )         malloc( (x) )
91 #   define Reallocate( x, y )    realloc( (x), (y) )
92 #   define Release( x )          free( (x) )
93 
94 #endif /* DEBUG */
95 
96 #endif /* DEBUG_H */
97 
98