forked from solidoss/solidframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.hpp
303 lines (249 loc) · 6.84 KB
/
debug.hpp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// solid/system/debug.hpp
//
// Copyright (c) 2007, 2008 Valentin Palade (vipalade @ gmail . com)
//
// This file is part of SolidFrame framework.
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.
//
#ifndef SYSTEM_DEBUG_HPP
#define SYSTEM_DEBUG_HPP
#include "solid/system/common.hpp"
#ifdef SOLID_HAS_STATISTICS
#define COLLECT_DATA_0(om)\
om()\
#define COLLECT_DATA_1(om,p1)\
om(p1)\
#define COLLECT_DATA_2(om,p1,p2)\
om(p1, p2)\
#else
#define COLLECT_DATA_0(om)
#define COLLECT_DATA_1(om,p1)
#define COLLECT_DATA_2(om,p1,p2)
#endif
#include <ostream>
#include <string>
#include "solid/system/common.hpp"
/*#ifdef SOLID_ON_WINDOWS
#ifdef DO_EXPORT_DLL
#define EXPORT_DLL __declspec(dllexport)
#else
#define EXPORT_DLL __declspec(dllimport)
#endif
#endif
#ifndef EXPORT_DLL
#define EXPORT_DLL
#endif
*/
namespace solid{
struct /*EXPORT_DLL*/ Debug{
static const unsigned any;
static const unsigned system;
static const unsigned specific;
static const unsigned proto_txt;
static const unsigned proto_bin;
static const unsigned ser_bin;
static const unsigned utility;
static const unsigned frame;
static const unsigned ipc;
static const unsigned tcp;
static const unsigned udp;
static const unsigned file;
static const unsigned log;
static const unsigned aio;
static Debug& the();
enum Level{
Info = 1,
Error = 2,
Warn = 4,
Report = 8,
Verbose = 16,
Trace = 32,
AllLevels = 1 + 2 + 4 + 8 + 16 + 32
};
static void once_cbk();
~Debug();
void initStdErr(
bool _buffered = true,
std::string *_output = nullptr
);
void initFile(
const char * _fname,
bool _buffered = true,
ulong _respincnt = 2,
ulong _respinsize = 1024 * 1024 * 1024,
std::string *_output = nullptr
);
void initSocket(
const char * _addr,
const char * _port,
bool _buffered = true,
std::string *_output = nullptr
);
void levelMask(const char *_msk = nullptr);
void moduleMask(const char *_msk = nullptr);
void moduleNames(std::string &_ros);
void setAllModuleBits();
void resetAllModuleBits();
void setModuleBit(unsigned _v);
void resetModuleBit(unsigned _v);
unsigned registerModule(const char *_name);
std::ostream& print();
std::ostream& print(
const char _t,
const char *_file,
const char *_fnc,
int _line
);
std::ostream& print(
const char _t,
unsigned _module,
const char *_file,
const char *_fnc,
int _line
);
std::ostream& printTraceIn(
const char _t,
unsigned _module,
const char *_file,
const char *_fnc,
int _line
);
std::ostream& printTraceOut(
const char _t,
unsigned _module,
const char *_file,
const char *_fnc,
int _line
);
void done();
void doneTraceIn();
void doneTraceOut();
bool isSet(Level _lvl, unsigned _v)const;
private:
static Debug& dbg_the();
Debug();
Debug(Debug const&);
Debug& operator=(Debug const&);
struct Data;
Data &d;
};
struct DebugTraceTest{
DebugTraceTest(
int _mod,
const char *_file,
const char *_fnc,
int _line):v(1), mod(_mod), file(_file), fnc(_fnc),line(_line){}
~DebugTraceTest();
int v;
int mod;
const char *file;
const char *fnc;
int line;
};
}//namespace solid
#ifndef CRT_FUNCTION_NAME
#ifdef SOLID_ON_WINDOWS
#define CRT_FUNCTION_NAME __func__
#else
#define CRT_FUNCTION_NAME __FUNCTION__
#endif
#endif
#ifdef SOLID_HAS_DEBUG
#define idbg(x)\
do{\
if(solid::Debug::the().isSet(solid::Debug::Info, solid::Debug::any)){\
solid::Debug::the().print('I', solid::Debug::any, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().done();}\
}while(false);
#define idbgx(a,x)\
do{\
if(solid::Debug::the().isSet(solid::Debug::Info, a)){\
solid::Debug::the().print('I', a, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().done();}\
}while(false);
#define edbg(x)\
do{\
if(solid::Debug::the().isSet(solid::Debug::Error, solid::Debug::any)){\
solid::Debug::the().print('E', solid::Debug::any, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().done();}\
}while(false);
#define edbgx(a,x)\
do{\
if(solid::Debug::the().isSet(solid::Debug::Error, a)){\
solid::Debug::the().print('E', a, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().done();}\
}while(false);
#define wdbg(x)\
do{\
if(solid::Debug::the().isSet(solid::Debug::Warn, solid::Debug::any)){\
solid::Debug::the().print('W', solid::Debug::any, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().done();}\
}while(false);
#define wdbgx(a,x)\
do{\
if(solid::Debug::the().isSet(solid::Debug::Warn, a)){\
solid::Debug::the().print('W', a, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().done();}\
}while(false);
#define rdbg(x)\
do{\
if(solid::Debug::the().isSet(solid::Debug::Report, solid::Debug::any)){\
solid::Debug::the().print('R', solid::Debug::any, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().done();}\
}while(false);
#define rdbgx(a,x)\
do{\
if(solid::Debug::the().isSet(solid::Debug::Report, a)){\
solid::Debug::the().print('R', a, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().done();}\
}while(false);
#define vdbg(x)\
do{\
if(solid::Debug::the().isSet(solid::Debug::Verbose, solid::Debug::any)){\
solid::Debug::the().print('V', solid::Debug::any, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().done();}\
}while(false);
#define vdbgx(a,x)\
do{\
if(solid::Debug::the().isSet(solid::Debug::Verbose, a)){\
solid::Debug::the().print('V', a, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().done();}\
}while(false);
#ifdef SOLID_HAS_DEBUG_TRACE
#define tdbgi(a,x)\
solid::DebugTraceTest __dbgtrace__(a, __FILE__, CRT_FUNCTION_NAME, __LINE__);\
if(solid::Debug::the().isSet(solid::Debug::Trace, a)){\
solid::Debug::the().printTraceIn('T', a, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().doneTraceIn();}else{\
__dbgtrace__.v = 0;}
#define tdbgo(a,x)\
do{\
if(solid::Debug::the().isSet(solid::Debug::Trace, a)){\
__dbgtrace__.v = 0;\
solid::Debug::the().printTraceOut('T', a, __FILE__, CRT_FUNCTION_NAME, __LINE__)<<x;solid::Debug::the().doneTraceOut();}\
}while(false);
#else
#define tdbgi(a,x)
#define tdbgo(a,x)
#endif
#define pdbg(f, ln, fnc, x)\
do{solid::Debug::the().print('P', solid::Debug::any, f, fnc, ln)<<x;solid::Debug::the().done();}while(false);
#define writedbg(x,sz)
#define writedbgx(a, x, sz)
#define check_call(a, v, c) \
do{\
if((c) != v){\
edbgx(a, "Error while calling ##c: "<<last_system_error().message())\
SOLID_ASSERT(false);\
}\
}while(false);
#else
#define idbg(x)
#define idbgx(a,x)
#define edbg(x)
#define edbgx(a,x)
#define wdbg(x)
#define wdbgx(a,x)
#define rdbg(x)
#define rdbgx(a,x)
#define vdbg(x)
#define vdbgx(a,x)
#define tdbgi(a,x)
#define tdbgo(a,x)
#define pdbg(f, ln, fnc, x)
#define writedbg(x,sz)
#define writedbgx(a, x, sz)
#define check_call(a, v, c) c
#endif
#endif