aboutsummaryrefslogtreecommitdiff
path: root/src/debug.h
blob: c74f1a84265619fe520b23423aac307d0b74e096 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
 * @file debug.h
 * @author Joe Wingbermuehle
 * @date 2003-2006
 *
 * @brief Header for the debug functions.
 *
 */

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef DEBUG_H
#define DEBUG_H

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_ALLOCA_H
#	include <alloca.h>
#endif

void Debug(const char *str, ...);

#ifdef HAVE_ALLOCA_H

#	define AllocateStack( x ) alloca( x )
#	define ReleaseStack( x ) ((void)0)

#else

#	define AllocateStack( x ) Allocate( x )
#	define ReleaseStack( x ) Release( x )

#endif

#ifdef DEBUG

#	define Assert( x ) \
		if(!( x )) {     \
			Debug("ASSERT FAILED: %s[%u]", __FILE__, __LINE__ ); \
			abort(); \
		}

#	define SetCheckpoint() \
		DEBUG_SetCheckpoint( __FILE__, __LINE__ )
#	define ShowCheckpoint() \
		DEBUG_ShowCheckpoint()

#	define StartDebug() \
		DEBUG_StartDebug( __FILE__, __LINE__ )
#	define StopDebug() \
		DEBUG_StopDebug( __FILE__, __LINE__ )

#	define Allocate( x ) \
		DEBUG_Allocate( (x), __FILE__, __LINE__ )
#	define Reallocate( x, y ) \
		DEBUG_Reallocate( (x), (y), __FILE__, __LINE__ )
#	define Release( x ) \
		DEBUG_Release( (void*)(& x), __FILE__, __LINE__ )

	void DEBUG_SetCheckpoint(const char*, unsigned int);
	void DEBUG_ShowCheckpoint();

	void DEBUG_StartDebug(const char*, unsigned int);
	void DEBUG_StopDebug(const char*, unsigned int);

	void *DEBUG_Allocate(size_t, const char*, unsigned int);
	void *DEBUG_Reallocate(void*, size_t, const char*, unsigned int);
	void DEBUG_Release(void**, const char*, unsigned int);

#else

#	define Assert( x )           ((void)0)

#	define SetCheckpoint()       ((void)0)
#	define ShowCheckpoint()      ((void)0)

#	define StartDebug()          ((void)0)
#	define StopDebug()           ((void)0)

#	define Allocate( x )         malloc( (x) )
#	define Reallocate( x, y )    realloc( (x), (y) )
#	define Release( x )          free( (x) )

#endif

#endif