aGrUM
0.14.2
debug.h
Go to the documentation of this file.
1
/***************************************************************************
2
* Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3
* {prenom.nom}_at_lip6.fr *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
9
* *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
14
* *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
20
#ifndef GUM_DEBUG_H
21
#define GUM_DEBUG_H
22
23
#ifndef DOXYGEN_SHOULD_SKIP_THIS
24
25
// WARNING : Do not include this file directlty : instead include
26
// <agrum/config.h>
27
28
# include <algorithm>
29
# include <iomanip>
30
# include <iostream>
31
# include <sstream>
32
# include <string>
33
# include <vector>
34
35
36
# ifdef GUM_DEBUG_MODE
37
# ifndef GUM_TRACE_ON
38
# define GUM_TRACE_ON // in DEBUG MODE we force TRACE to be ON
39
# else // GUM_TRACE_ON on mode debug add TRACE_CONSTRUCTION_ON (tracing
40
// construction/destruction of object)
41
# define GUM_DEEP_TRACE_ON
42
# endif // GUM_TRACE_ON
43
44
# define GUM_ASSERT(condition) \
45
do { \
46
if (!(condition)) { \
47
std::cout << std::endl \
48
<< __FILE__ << ":" << __LINE__ << " [aGrUM] assert (" \
49
<< #condition << ") failed" << std::endl; \
50
std::abort(); \
51
} \
52
} while (0)
53
54
# define GUM_DEBUG_ONLY(x) \
55
{ x }
56
57
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
58
// DEFINITION OF GUM_CONSTRUCTOR
59
# define GUM_CONSTRUCTOR_BASIC(x) \
60
{ \
61
gum::__debug__::__inc_creation( \
62
#x, __FILE__, __LINE__, "constructor of", (void*)this, sizeof(x)); \
63
}
64
# define GUM_CONSTRUCTOR(x) GUM_CONSTRUCTOR_BASIC(x)
65
66
// FOR EXPANSION OF MACRO IN ARGS OF GUM_DESTRUCTOR, WE NEED TO USE A 2-LEVEL
67
// DEFINITION OF GUM_DESTRUCTOR
68
# define GUM_DESTRUCTOR_BASIC(x) \
69
{ \
70
gum::__debug__::__inc_deletion( \
71
#x, __FILE__, __LINE__, "destructor of", (void*)this); \
72
}
73
# define GUM_DESTRUCTOR(x) GUM_DESTRUCTOR_BASIC(x)
74
75
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONS_CPY, WE NEED TO USE A 2-LEVEL
76
// DEFINITION OF GUM_CONS_CPY
77
# define GUM_CONS_CPY_BASIC(x) \
78
{ \
79
gum::__debug__::__inc_creation(#x, \
80
__FILE__, \
81
__LINE__, \
82
"copy constructor of", \
83
(void*)this, \
84
sizeof(x)); \
85
}
86
# define GUM_CONS_CPY(x) GUM_CONS_CPY_BASIC(x)
87
88
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONS_MOV, WE NEED TO USE A 2-LEVEL
89
// DEFINITION OF GUM_CONS_MOV
90
# define GUM_CONS_MOV_BASIC(x) \
91
{ \
92
gum::__debug__::__inc_creation(#x, \
93
__FILE__, \
94
__LINE__, \
95
"move constructor of", \
96
(void*)this, \
97
sizeof(x)); \
98
}
99
# define GUM_CONS_MOV(x) GUM_CONS_MOV_BASIC(x)
100
101
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
102
// DEFINITION OF GUM_CONSTRUCTOR
103
# define GUM_OP_CPY_BASIC(x) \
104
{ \
105
gum::__debug__::__show_trace( \
106
#x, __FILE__, __LINE__, "copy operator of", (void*)this); \
107
}
108
# define GUM_OP_CPY(x) GUM_OP_CPY_BASIC(x)
109
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
110
// DEFINITION OF GUM_CONSTRUCTOR
111
# define GUM_OP_MOV_BASIC(x) \
112
{ \
113
gum::__debug__::__show_trace( \
114
#x, __FILE__, __LINE__, "move operator of", (void*)this); \
115
}
116
# define GUM_OP_MOV(x) GUM_OP_MOV_BASIC(x)
117
# else // GUM_DEBUG_MODE
119
# define GUM_ASSERT(condition) ((void)0)
121
# define GUM_CONSTRUCTOR(x) ((void)0)
122
# define GUM_DESTRUCTOR(x) ((void)0)
123
# define GUM_CONS_CPY(x) ((void)0)
124
# define GUM_CONS_MOV(x) ((void)0)
125
# define GUM_OP_CPY(x) ((void)0)
126
# define GUM_OP_MOV(x) ((void)0)
127
128
# define GUM_DEBUG_ONLY(x)
129
# endif // GUM_DEBUG_MODE
131
132
# ifdef GUM_TRACE_ON
133
# define GUM__PRINT(file, line, x) \
134
{ std::cout << std::endl << file << ":" << line << x << std::endl; }
135
136
# define GUM_CHECKPOINT GUM__PRINT(__FILE__, __LINE__, " GUMcheckpoint")
137
# define GUM_TRACE(x) \
138
GUM__PRINT(__FILE__, __LINE__, std::endl << " --> GUMtrace: " << x)
139
# define GUM_TRACE_VAR(x) \
140
GUM__PRINT(__FILE__, \
141
__LINE__, \
142
std::endl \
143
<< " --> GUMtrace of <" << #x << ">: " << x)
144
145
# define GUM_TRACE_NEWLINE \
146
{ std::cout << std::endl; }
147
# else // GUM_TRACE_ON
148
# define GUM__PRINT(line, file, x)
149
# define GUM_CHECKPOINT
150
# define GUM_TRACE(x)
151
# define GUM_TRACE_VAR(x)
152
# define GUM_TRACE_NEWLINE
153
# endif // GUM_TRACE_ON
154
155
namespace
gum
{
156
157
# ifdef GUM_DEBUG_MODE
158
159
namespace
__debug__ {
160
161
std::string __getFile(
const
char
* f);
162
163
void
__show_trace(
const
char
* zeKey,
164
const
char
* zeFile,
165
long
zeLine,
166
const
char
* zeMsg,
167
const
void
* zePtr);
168
void
__inc_creation(
const
char
* zeKey,
169
const
char
* zeFile,
170
long
zeLine,
171
const
char
* zeMsg,
172
const
void
* zePtr,
173
int
zeSize = -1);
174
void
__inc_deletion(
const
char
* zeKey,
175
const
char
* zeFile,
176
long
zeLine,
177
const
char
* zeMsg,
178
const
void
* zePtr);
179
void
__dec_creation(
const
char
* zeKey,
180
const
char
* zeFile,
181
long
zeLine,
182
const
char
* zeMsg,
183
const
void
* zePtr);
184
void
__dumpObjects();
185
void
__atexit
();
186
187
}
// namespace __debug__
188
189
# endif // GUM_DEBUG_MODE
190
191
// ===========================================================================
192
// === A CLASS USED FOR MAKING VALGRIND HAPPY IN DEBUG MODE ===
193
// ===========================================================================
194
195
class
Debug :
public
std::string {
196
public
:
197
Debug(
const
std::string& str) :
std
::string(str) {}
198
199
Debug(
const
char
*
const
str) :
std
::string(str) {}
200
};
201
202
}
/* namespace gum */
203
204
#endif // DOXYGEN_SHOULD_SKIP_THIS
205
206
#endif // GUM_DEBUG_H
std
STL namespace.
gum::__atexit
void __atexit()
Used for debug purpose.
Definition:
utils_misc.cpp:47
gum
gum is the global namespace for all aGrUM entities
Definition:
agrum.h:25