aGrUM
0.16.0
debug.h
Go to the documentation of this file.
1
23
#ifndef GUM_DEBUG_H
24
#define GUM_DEBUG_H
25
26
#ifndef DOXYGEN_SHOULD_SKIP_THIS
27
28
// WARNING : Do not include this file directlty : instead include
29
// <agrum/config.h>
30
31
# include <algorithm>
32
# include <iomanip>
33
# include <iostream>
34
# include <sstream>
35
# include <string>
36
# include <vector>
37
38
39
# ifdef GUM_DEBUG_MODE
40
# ifndef GUM_TRACE_ON
41
# define GUM_TRACE_ON // in DEBUG MODE we force TRACE to be ON
42
# else // GUM_TRACE_ON on mode debug add TRACE_CONSTRUCTION_ON (tracing
43
// construction/destruction of object)
44
# define GUM_DEEP_TRACE_ON
45
# endif // GUM_TRACE_ON
46
47
# define GUM_ASSERT(condition) \
48
do { \
49
if (!(condition)) { \
50
std::cout << std::endl \
51
<< __FILE__ << ":" << __LINE__ << " [aGrUM] assert (" \
52
<< #condition << ") failed" << std::endl; \
53
std::abort(); \
54
} \
55
} while (0)
56
57
# define GUM_DEBUG_ONLY(x) \
58
{ x }
59
60
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
61
// DEFINITION OF GUM_CONSTRUCTOR
62
# define GUM_CONSTRUCTOR_BASIC(x) \
63
{ \
64
gum::__debug__::__inc_creation( \
65
#x, __FILE__, __LINE__, "constructor of", (void*)this, sizeof(x)); \
66
}
67
# define GUM_CONSTRUCTOR(x) GUM_CONSTRUCTOR_BASIC(x)
68
69
// FOR EXPANSION OF MACRO IN ARGS OF GUM_DESTRUCTOR, WE NEED TO USE A 2-LEVEL
70
// DEFINITION OF GUM_DESTRUCTOR
71
# define GUM_DESTRUCTOR_BASIC(x) \
72
{ \
73
gum::__debug__::__inc_deletion( \
74
#x, __FILE__, __LINE__, "destructor of", (void*)this); \
75
}
76
# define GUM_DESTRUCTOR(x) GUM_DESTRUCTOR_BASIC(x)
77
78
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONS_CPY, WE NEED TO USE A 2-LEVEL
79
// DEFINITION OF GUM_CONS_CPY
80
# define GUM_CONS_CPY_BASIC(x) \
81
{ \
82
gum::__debug__::__inc_creation(#x, \
83
__FILE__, \
84
__LINE__, \
85
"copy constructor of", \
86
(void*)this, \
87
sizeof(x)); \
88
}
89
# define GUM_CONS_CPY(x) GUM_CONS_CPY_BASIC(x)
90
91
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONS_MOV, WE NEED TO USE A 2-LEVEL
92
// DEFINITION OF GUM_CONS_MOV
93
# define GUM_CONS_MOV_BASIC(x) \
94
{ \
95
gum::__debug__::__inc_creation(#x, \
96
__FILE__, \
97
__LINE__, \
98
"move constructor of", \
99
(void*)this, \
100
sizeof(x)); \
101
}
102
# define GUM_CONS_MOV(x) GUM_CONS_MOV_BASIC(x)
103
104
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
105
// DEFINITION OF GUM_CONSTRUCTOR
106
# define GUM_OP_CPY_BASIC(x) \
107
{ \
108
gum::__debug__::__show_trace( \
109
#x, __FILE__, __LINE__, "copy operator of", (void*)this); \
110
}
111
# define GUM_OP_CPY(x) GUM_OP_CPY_BASIC(x)
112
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
113
// DEFINITION OF GUM_CONSTRUCTOR
114
# define GUM_OP_MOV_BASIC(x) \
115
{ \
116
gum::__debug__::__show_trace( \
117
#x, __FILE__, __LINE__, "move operator of", (void*)this); \
118
}
119
# define GUM_OP_MOV(x) GUM_OP_MOV_BASIC(x)
120
# else // GUM_DEBUG_MODE
122
# define GUM_ASSERT(condition) ((void)0)
124
# define GUM_CONSTRUCTOR(x) ((void)0)
125
# define GUM_DESTRUCTOR(x) ((void)0)
126
# define GUM_CONS_CPY(x) ((void)0)
127
# define GUM_CONS_MOV(x) ((void)0)
128
# define GUM_OP_CPY(x) ((void)0)
129
# define GUM_OP_MOV(x) ((void)0)
130
131
# define GUM_DEBUG_ONLY(x)
132
# endif // GUM_DEBUG_MODE
134
135
# ifdef GUM_TRACE_ON
136
# define GUM__PRINT(file, line, x) \
137
{ std::cout << std::endl << file << ":" << line << x << std::endl; }
138
139
# define GUM_CHECKPOINT GUM__PRINT(__FILE__, __LINE__, " GUMcheckpoint")
140
# define GUM_TRACE(x) \
141
GUM__PRINT(__FILE__, __LINE__, std::endl << " --> GUMtrace: " << x)
142
# define GUM_TRACE_VAR(x) \
143
GUM__PRINT(__FILE__, \
144
__LINE__, \
145
std::endl \
146
<< " --> GUMtrace of <" << #x << ">: " << x)
147
148
# define GUM_TRACE_NEWLINE \
149
{ std::cout << std::endl; }
150
# else // GUM_TRACE_ON
151
# define GUM__PRINT(line, file, x)
152
# define GUM_CHECKPOINT
153
# define GUM_TRACE(x)
154
# define GUM_TRACE_VAR(x)
155
# define GUM_TRACE_NEWLINE
156
# endif // GUM_TRACE_ON
157
158
namespace
gum
{
159
160
# ifdef GUM_DEBUG_MODE
161
162
namespace
__debug__ {
163
164
std::string __getFile(
const
char
* f);
165
166
void
__show_trace(
const
char
* zeKey,
167
const
char
* zeFile,
168
long
zeLine,
169
const
char
* zeMsg,
170
const
void
* zePtr);
171
void
__inc_creation(
const
char
* zeKey,
172
const
char
* zeFile,
173
long
zeLine,
174
const
char
* zeMsg,
175
const
void
* zePtr,
176
int
zeSize = -1);
177
void
__inc_deletion(
const
char
* zeKey,
178
const
char
* zeFile,
179
long
zeLine,
180
const
char
* zeMsg,
181
const
void
* zePtr);
182
void
__dec_creation(
const
char
* zeKey,
183
const
char
* zeFile,
184
long
zeLine,
185
const
char
* zeMsg,
186
const
void
* zePtr);
187
void
__dumpObjects();
188
void
__atexit
();
189
190
}
// namespace __debug__
191
192
# endif // GUM_DEBUG_MODE
193
194
// ===========================================================================
195
// === A CLASS USED FOR MAKING VALGRIND HAPPY IN DEBUG MODE ===
196
// ===========================================================================
197
198
class
Debug :
public
std::string {
199
public
:
200
Debug(
const
std::string& str) :
std
::string(str) {}
201
202
Debug(
const
char
*
const
str) :
std
::string(str) {}
203
};
204
205
}
/* namespace gum */
206
207
#endif // DOXYGEN_SHOULD_SKIP_THIS
208
209
#endif // GUM_DEBUG_H
std
STL namespace.
gum::__atexit
void __atexit()
Used for debug purpose.
Definition:
utils_misc.cpp:50
gum
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition:
agrum.h:25