aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
debug.h
Go to the documentation of this file.
1
/****************************************************************************
2
* This file is part of the aGrUM/pyAgrum library. *
3
* *
4
* Copyright (c) 2005-2026 by *
5
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
6
* - Christophe GONZALES(_at_AMU) *
7
* *
8
* The aGrUM/pyAgrum library is free software; you can redistribute it *
9
* and/or modify it under the terms of either : *
10
* *
11
* - the GNU Lesser General Public License as published by *
12
* the Free Software Foundation, either version 3 of the License, *
13
* or (at your option) any later version, *
14
* - the MIT license (MIT), *
15
* - or both in dual license, as here. *
16
* *
17
* (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18
* *
19
* This aGrUM/pyAgrum library is distributed in the hope that it will be *
20
* useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26
* OTHER DEALINGS IN THE SOFTWARE. *
27
* *
28
* See LICENCES for more details. *
29
* *
30
* SPDX-FileCopyrightText: Copyright 2005-2026 *
31
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
32
* - Christophe GONZALES(_at_AMU) *
33
* SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34
* *
35
* Contact : info_at_agrum_dot_org *
36
* homepage : http://agrum.gitlab.io *
37
* gitlab : https://gitlab.com/agrumery/agrum *
38
* *
39
****************************************************************************/
40
41
42
#ifndef GUM_DEBUG_H
43
#define GUM_DEBUG_H
44
45
#ifndef DOXYGEN_SHOULD_SKIP_THIS
46
47
// WARNING : Do not include this file directlty : instead include
48
// <agrum/config.h>
49
50
# include <algorithm>
51
# include <iomanip>
52
# include <iostream>
53
# include <sstream>
54
# include <string>
55
# include <vector>
56
57
58
# ifdef GUM_DEBUG_MODE
59
# ifndef GUM_TRACE_ON
60
# define GUM_TRACE_ON
// in DEBUG MODE we force TRACE to be ON
61
# else
// GUM_TRACE_ON on mode debug add TRACE_CONSTRUCTION_ON (tracing
62
// construction/destruction of object)
63
# define GUM_DEEP_TRACE_ON
64
# endif
// GUM_TRACE_ON
65
66
# define GUM_ASSERT(condition) \
67
{ \
68
do { \
69
if (!(condition)) { \
70
std::cout << std::endl \
71
<< __FILE__ << ":" << __LINE__ << " [aGrUM] assert (" << #condition \
72
<< ") failed" << std::endl; \
73
std::abort(); \
74
} \
75
} while (0); \
76
}
77
78
# define GUM_DEBUG_ONLY(x) {x}
79
80
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
81
// DEFINITION OF GUM_CONSTRUCTOR
82
# define GUM_CONSTRUCTOR_BASIC(x) \
83
{ \
84
gum::__debug__::_inc_creation_(#x, \
85
__FILE__, \
86
__LINE__, \
87
"constructor of", \
88
(void*)this, \
89
sizeof(x)); \
90
}
91
# define GUM_CONSTRUCTOR(x) GUM_CONSTRUCTOR_BASIC(x);
92
93
// FOR EXPANSION OF MACRO IN ARGS OF GUM_DESTRUCTOR, WE NEED TO USE A 2-LEVEL
94
// DEFINITION OF GUM_DESTRUCTOR
95
# define GUM_DESTRUCTOR_BASIC(x) \
96
{ gum::__debug__::_inc_deletion_(#x, __FILE__, __LINE__, "destructor of", (void*)this); }
97
# define GUM_DESTRUCTOR(x) GUM_DESTRUCTOR_BASIC(x);
98
99
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONS_CPY, WE NEED TO USE A 2-LEVEL
100
// DEFINITION OF GUM_CONS_CPY
101
# define GUM_CONS_CPY_BASIC(x) \
102
{ \
103
gum::__debug__::_inc_creation_(#x, \
104
__FILE__, \
105
__LINE__, \
106
"copy constructor of", \
107
(void*)this, \
108
sizeof(x)); \
109
}
110
# define GUM_CONS_CPY(x) GUM_CONS_CPY_BASIC(x);
111
112
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONS_MOV, WE NEED TO USE A 2-LEVEL
113
// DEFINITION OF GUM_CONS_MOV
114
# define GUM_CONS_MOV_BASIC(x) \
115
{ \
116
gum::__debug__::_inc_creation_(#x, \
117
__FILE__, \
118
__LINE__, \
119
"move constructor of", \
120
(void*)this, \
121
sizeof(x)); \
122
}
123
# define GUM_CONS_MOV(x) GUM_CONS_MOV_BASIC(x)
124
125
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
126
// DEFINITION OF GUM_CONSTRUCTOR
127
# define GUM_OP_CPY_BASIC(x) \
128
{ gum::__debug__::_show_trace_(#x, __FILE__, __LINE__, "copy operator of", (void*)this); }
129
# define GUM_OP_CPY(x) GUM_OP_CPY_BASIC(x)
130
// FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
131
// DEFINITION OF GUM_CONSTRUCTOR
132
# define GUM_OP_MOV_BASIC(x) \
133
{ gum::__debug__::_show_trace_(#x, __FILE__, __LINE__, "move operator of", (void*)this); }
134
# define GUM_OP_MOV(x) GUM_OP_MOV_BASIC(x)
136
# else
// GUM_DEBUG_MODE
138
# define GUM_ASSERT(condition)
139
# define GUM_CONSTRUCTOR(x) ;
140
# define GUM_DESTRUCTOR(x) ;
141
# define GUM_CONS_CPY(x) ;
142
# define GUM_CONS_MOV(x) ;
143
# define GUM_OP_CPY(x) ;
144
# define GUM_OP_MOV(x) ;
145
146
# define GUM_DEBUG_ONLY(x)
148
# endif
// GUM_DEBUG_MODE
149
150
# ifdef GUM_TRACE_ON
151
# define GUM_FILE_LINE_PRINT(file, line, msg) \
152
{ std::cout << std::endl << file << ":" << line << " [GUM] " << msg << std::endl; }
153
154
# define GUM_CHECKPOINT GUM_FILE_LINE_PRINT(__FILE__, __LINE__, "******** checkpoint ********")
155
# define GUM_TRACE(msg) GUM_FILE_LINE_PRINT(__FILE__, __LINE__, msg)
156
# define GUM_TRACE_VAR(var) GUM_FILE_LINE_PRINT(__FILE__, __LINE__, "<" << #var << ">: " << var)
157
# define GUM_TRACE_NEWLINE \
158
{ std::cout << std::endl; }
159
# else
// GUM_TRACE_ON
160
# define GUM_FILE_LINE_PRINT(line, file, x)
161
# define GUM_CHECKPOINT
162
# define GUM_TRACE(msg)
163
# define GUM_TRACE_VAR(var)
164
# define GUM_TRACE_NEWLINE
165
# endif
// GUM_TRACE_ON
166
167
namespace
gum
{
168
169
# ifdef GUM_DEBUG_MODE
170
171
namespace
__debug__
{
172
173
std::string _getFile_(
const
char
* f);
174
175
void
_show_trace_(
const
char
* zeKey,
176
const
char
* zeFile,
177
long
zeLine,
178
const
char
* zeMsg,
179
const
void
* zePtr);
180
void
_inc_creation_(
const
char
* zeKey,
181
const
char
* zeFile,
182
long
zeLine,
183
const
char
* zeMsg,
184
const
void
* zePtr,
185
int
zeSize = -1);
186
void
_inc_deletion_(
const
char
* zeKey,
187
const
char
* zeFile,
188
long
zeLine,
189
const
char
* zeMsg,
190
const
void
* zePtr);
191
void
_dec_creation_(
const
char
* zeKey,
192
const
char
* zeFile,
193
long
zeLine,
194
const
char
* zeMsg,
195
const
void
* zePtr);
196
void
_dumpObjects_();
197
void
_atexit_
();
198
199
}
// namespace __debug__
200
201
# endif
// GUM_DEBUG_MODE
202
203
// ===========================================================================
204
// === A CLASS USED FOR MAKING VALGRIND HAPPY IN DEBUG MODE ===
205
// ===========================================================================
206
207
class
Debug:
public
std::string {
208
using
std::string::string;
209
};
210
211
}
/* namespace gum */
212
213
#endif
// DOXYGEN_SHOULD_SKIP_THIS
214
215
#endif
// GUM_DEBUG_H
gum::_atexit_
void _atexit_()
Used for debug purpose.
Definition
utils_misc.cpp:67
gum::__debug__
Internal namespace for aGrUM debugging tools.
Definition
agrum.h:52
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0