aGrUM  0.13.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 <cassert>
30 # include <iomanip>
31 # include <iostream>
32 # include <sstream>
33 # include <string>
34 # include <vector>
35 
36 
37 # ifndef NDEBUG
38 # ifndef GUM_TRACE_ON
39 # define GUM_TRACE_ON // in DEBUG MODE we force TRACE to be ON
40 # else // GUM_TRACE_ON on mode debug add TRACE_CONSTRUCTION_ON (tracing
41 // construction/destruction of object)
42 # define GUM_DEEP_TRACE_ON
43 # endif // GUM_TRACE_ON
44 
45 # define GUM_ASSERT(condition) \
46  { assert(condition); }
47 # define GUM_DEBUG_ONLY(x) \
48  { x }
49 
50 // FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
51 // DEFINITION OF GUM_CONSTRUCTOR
52 # define GUM_CONSTRUCTOR_BASIC(x) \
53  { \
54  gum::__debug__::__inc_creation( \
55  #x, __FILE__, __LINE__, "constructor of", (void*)this, sizeof(x)); \
56  }
57 # define GUM_CONSTRUCTOR(x) GUM_CONSTRUCTOR_BASIC(x)
58 
59 // FOR EXPANSION OF MACRO IN ARGS OF GUM_DESTRUCTOR, WE NEED TO USE A 2-LEVEL
60 // DEFINITION OF GUM_DESTRUCTOR
61 # define GUM_DESTRUCTOR_BASIC(x) \
62  { \
63  gum::__debug__::__inc_deletion( \
64  #x, __FILE__, __LINE__, "destructor of", (void*)this); \
65  }
66 # define GUM_DESTRUCTOR(x) GUM_DESTRUCTOR_BASIC(x)
67 
68 // FOR EXPANSION OF MACRO IN ARGS OF GUM_CONS_CPY, WE NEED TO USE A 2-LEVEL
69 // DEFINITION OF GUM_CONS_CPY
70 # define GUM_CONS_CPY_BASIC(x) \
71  { \
72  gum::__debug__::__inc_creation( \
73  #x, __FILE__, __LINE__, "copy constructor of", (void*)this, sizeof(x)); \
74  }
75 # define GUM_CONS_CPY(x) GUM_CONS_CPY_BASIC(x)
76 
77 // FOR EXPANSION OF MACRO IN ARGS OF GUM_CONS_MOV, WE NEED TO USE A 2-LEVEL
78 // DEFINITION OF GUM_CONS_MOV
79 # define GUM_CONS_MOV_BASIC(x) \
80  { \
81  gum::__debug__::__inc_creation( \
82  #x, __FILE__, __LINE__, "move constructor of", (void*)this, sizeof(x)); \
83  }
84 # define GUM_CONS_MOV(x) GUM_CONS_MOV_BASIC(x)
85 
86 // FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
87 // DEFINITION OF GUM_CONSTRUCTOR
88 # define GUM_OP_CPY_BASIC(x) \
89  { \
90  gum::__debug__::__show_trace( \
91  #x, __FILE__, __LINE__, "copy operator of", (void*)this); \
92  }
93 # define GUM_OP_CPY(x) GUM_OP_CPY_BASIC(x)
94 // FOR EXPANSION OF MACRO IN ARGS OF GUM_CONSTRUCTOR, WE NEED TO USE A 2-LEVEL
95 // DEFINITION OF GUM_CONSTRUCTOR
96 # define GUM_OP_MOV_BASIC(x) \
97  { \
98  gum::__debug__::__show_trace( \
99  #x, __FILE__, __LINE__, "move operator of", (void*)this); \
100  }
101 # define GUM_OP_MOV(x) GUM_OP_MOV_BASIC(x)
102 # else // NDEBUG
104 # define GUM_ASSERT(condition)
106 # define GUM_DEBUG_ONLY(x)
107 # define GUM_CONSTRUCTOR(x)
108 # define GUM_DESTRUCTOR(x)
109 # define GUM_CONS_CPY(x)
110 # define GUM_CONS_MOV(x)
111 # define GUM_OP_CPY(x)
112 # define GUM_OP_MOV(x)
113 # endif // NDEBUG
115 
116 # ifdef GUM_TRACE_ON
117 # define GUM__PRINT(file, line, x) \
118  { \
119  std::cout << std::endl \
120  << file << ":" << line << ": trace : " << x << std::endl; \
121  }
122 
123 # define GUM_CHECKPOINT \
124  GUM__PRINT(__FILE__, __LINE__, ": warning : aGrUM checkpoint")
125 # define GUM_TRACE(x) GUM__PRINT(__FILE__, __LINE__, ": trace : " << x)
126 # define GUM_TRACE_VAR(x) \
127  GUM__PRINT(__FILE__, __LINE__, ": trace " << #x << ": " << x)
128 
129 # define GUM_TRACE_NEWLINE \
130  { std::cout << std::endl; }
131 # else // GUM_TRACE_ON
132 # define GUM__PRINT(line, file, x)
133 # define GUM_CHECKPOINT
134 # define GUM_TRACE(x)
135 # define GUM_TRACE_VAR(x)
136 # define GUM_TRACE_NEWLINE
137 # endif // GUM_TRACE_ON
138 
139 namespace gum {
140 
141 # ifndef NDEBUG
142 
143  namespace __debug__ {
144 
145  std::string __getFile(const char* f);
146 
147  void __show_trace(const char* zeKey,
148  const char* zeFile,
149  long zeLine,
150  const char* zeMsg,
151  const void* zePtr);
152  void __inc_creation(const char* zeKey,
153  const char* zeFile,
154  long zeLine,
155  const char* zeMsg,
156  const void* zePtr,
157  int zeSize = -1);
158  void __inc_deletion(const char* zeKey,
159  const char* zeFile,
160  long zeLine,
161  const char* zeMsg,
162  const void* zePtr);
163  void __dec_creation(const char* zeKey,
164  const char* zeFile,
165  long zeLine,
166  const char* zeMsg,
167  const void* zePtr);
168  void __dumpObjects();
169  void __atexit();
170 
171  } // namespace __debug__
172 
173 # endif // NDEBUG
174 
175  // ===========================================================================
176  // === A CLASS USED FOR MAKING VALGRIND HAPPY IN DEBUG MODE ===
177  // ===========================================================================
178 
179  class Debug : public std::string {
180  public:
181  Debug(const std::string& str) : std::string(str) {}
182 
183  Debug(const char* const str) : std::string(str) {}
184  };
185 
186 } /* namespace gum */
187 
188 #endif // DOXYGEN_SHOULD_SKIP_THIS
189 
190 #endif // GUM_DEBUG_H
STL namespace.
void __atexit()
Used for debug purpose.
Definition: utils_misc.cpp:41
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25