-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_rtfl.hh
461 lines (359 loc) · 16.2 KB
/
debug_rtfl.hh
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
// WARNING: This file has been generated. Do not edit!
/*
* This file is part of RTFL, see <http://home.gna.org/rtfl/>
* for details.
*
* This file (but not RTFL itself) is in the public domain, since it is only a
* simple implementation of a protocol, containing nothing more than trivial
* work. However, it would be nice to keep this notice, along with the URL
* above.
*
* ----------------------------------------------------------------------------
*
* Defines macros for printing RTFL commands. See documentation for detail
* (online at <http://home.gna.org/rtfl/doc/rtfl.html>). These macros are only
* active, when the pre-processor variable DBG_RTFL is defined. If not,
* alternatives are defined, which have no effect.
*
* This variant assumes that __FILE__ is only the base of the source file name,
* so, to get the full path, CUR_WORKING_DIR has to be defined. See RTFL
* documentation for more details.
*/
#ifndef __DEBUG_RTFL_HH__
#define __DEBUG_RTFL_HH__
#ifdef DBG_RTFL
// =======================================
// Used by all modules
// =======================================
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <sys/time.h>
#define DBG_IF_RTFL if(1)
#define STMT_START do
#define STMT_END while (0)
// Prints an RTFL message to stdout. "fmt" contains simple format
// characters how to deal with the additional arguments (no "%"
// preceeding, as in printf) or "q" (which additionally
// (double-)quotes quotation marks) or "c" (short for "#%06x" and used
// for colors), or other characters, which are simply printed. No
// quoting: this function cannot be used to print the characters "d",
// "p", "s" and "q" directly.
inline void rtfl_print (const char *module, const char *version,
const char *file, int line, int processId,
const char *fmt, ...)
{
// "\n" at the beginning just in case that the previous line is not
// finished yet.
printf ("\n[rtfl-%s-%s]%s:%d:%d:", module, version, file, line, processId);
va_list args;
va_start (args, fmt);
for (int i = 0; fmt[i]; i++) {
int n;
void *p;
char *s;
switch (fmt[i]) {
case 'd':
n = va_arg(args, int);
printf ("%d", n);
break;
case 'p':
p = va_arg(args, void*);
printf ("%p", p);
break;
case 's':
s = va_arg (args, char*);
for (int j = 0; s[j]; j++) {
if (s[j] == ':' || s[j] == '\\')
putchar ('\\');
putchar (s[j]);
}
break;
case 'q':
s = va_arg (args, char*);
for (int j = 0; s[j]; j++) {
if (s[j] == ':' || s[j] == '\\')
putchar ('\\');
else if (s[j] == '\"')
printf ("\\\\"); // a quoted quoting character
putchar (s[j]);
}
break;
case 'c':
n = va_arg(args, int);
printf ("#%06x", n);
break;
default:
putchar (fmt[i]);
break;
}
}
va_end (args);
putchar ('\n');
fflush (stdout);
}
#define RTFL_PRINT(module, version, cmd, fmt, ...) \
rtfl_print (module, version, CUR_WORKING_DIR "/" __FILE__, __LINE__, \
getpid (), "s:" fmt, cmd, __VA_ARGS__)
// ==================================
// General module
// ==================================
#define RTFL_GEN_VERSION "1.0"
#define RTFL_GEN_PRINT(cmd, fmt, ...) \
RTFL_PRINT ("gen", RTFL_GEN_VERSION, cmd, fmt, __VA_ARGS__)
#define DBG_GEN_TIME() \
STMT_START { \
struct timeval tv; \
gettimeofday(&tv, NULL); \
char buf[32]; \
snprintf (buf, sizeof (buf), "%ld%06ld", tv.tv_sec, tv.tv_usec); \
RTFL_GEN_PRINT ("time", "s", buf); \
} STMT_END
// ==================================
// Objects module
// ==================================
#define RTFL_OBJ_VERSION "1.0"
#define RTFL_OBJ_PRINT(cmd, fmt, ...) \
RTFL_PRINT ("obj", RTFL_OBJ_VERSION, cmd, fmt, __VA_ARGS__)
#define DBG_OBJ_MSG(aspect, prio, msg) \
DBG_OBJ_MSG_O (aspect, prio, this, msg)
#define DBG_OBJ_MSG_O(aspect, prio, obj, msg) \
RTFL_OBJ_PRINT ("msg", "p:s:d:s", obj, aspect, prio, msg)
#define DBG_OBJ_MSGF(aspect, prio, fmt, ...) \
STMT_START { \
char msg[256]; \
snprintf (msg, sizeof (msg), fmt, __VA_ARGS__); \
DBG_OBJ_MSG (aspect, prio, msg); \
} STMT_END
#define DBG_OBJ_MSGF_O(aspect, prio, obj, fmt, ...) \
STMT_START { \
char msg[256]; \
snprintf (msg, sizeof (msg), fmt, __VA_ARGS__); \
DBG_OBJ_MSG_O (aspect, prio, obj, msg); \
} STMT_END
#define DBG_OBJ_MARK(aspect, prio, mark) \
DBG_OBJ_MARK_O (aspect, prio, this, mark)
#define DBG_OBJ_MARK_O(aspect, prio, obj, mark) \
RTFL_OBJ_PRINT ("mark", "p:s:d:s", obj, aspect, prio, mark)
#define DBG_OBJ_MARKF(aspect, prio, fmt, ...) \
STMT_START { \
char mark[256]; \
snprintf (mark, sizeof (mark), fmt, __VA_ARGS__); \
DBG_OBJ_MARK (aspect, prio, mark); \
} STMT_END
#define DBG_OBJ_MARKF_O(aspect, prio, obj, fmt, ...) \
STMT_START { \
char mark[256]; \
snprintf (mark, sizeof (mark), fmt, __VA_ARGS__); \
DBG_OBJ_MARK_O (aspect, prio, obj, mark); \
} STMT_END
#define DBG_OBJ_MSG_START() \
DBG_OBJ_MSG_START_O (this)
#define DBG_OBJ_MSG_START_O(obj) \
RTFL_OBJ_PRINT ("msg-start", "p", obj)
#define DBG_OBJ_MSG_END() \
DBG_OBJ_MSG_END_O (this)
#define DBG_OBJ_MSG_END_O(obj) \
RTFL_OBJ_PRINT ("msg-end", "p", obj)
#define DBG_OBJ_ENTER0(aspect, prio, funname) \
DBG_OBJ_ENTER0_O (aspect, prio, this, funname)
#define DBG_OBJ_ENTER0_O(aspect, prio, obj, funname) \
RTFL_OBJ_PRINT ("enter", "p:s:d:s:", obj, aspect, prio, funname);
#define DBG_OBJ_ENTER(aspect, prio, funname, fmt, ...) \
STMT_START { \
char args[256]; \
snprintf (args, sizeof (args), fmt, __VA_ARGS__); \
RTFL_OBJ_PRINT ("enter", "p:s:d:s:s", this, aspect, prio, funname, \
args); \
} STMT_END
#define DBG_OBJ_ENTER_O(aspect, prio, obj, funname, fmt, ...) \
STMT_START { \
char args[256]; \
snprintf (args, sizeof (args), fmt, __VA_ARGS__); \
RTFL_OBJ_PRINT ("enter", "p:s:d:s:s", obj, aspect, prio, funname, \
args); \
} STMT_END
#define DBG_OBJ_LEAVE() \
DBG_OBJ_LEAVE_O (this)
#define DBG_OBJ_LEAVE_O(obj) \
RTFL_OBJ_PRINT ("leave", "p", obj);
#define DBG_OBJ_LEAVE_VAL(fmt, ...) \
STMT_START { \
char vals[256]; \
snprintf (vals, sizeof (vals), fmt, __VA_ARGS__); \
RTFL_OBJ_PRINT ("leave", "p:s", this, vals); \
} STMT_END
#define DBG_OBJ_LEAVE_VAL_O(obj, fmt, ...) \
STMT_START { \
char vals[256]; \
snprintf (vals, sizeof (vals), fmt, __VA_ARGS__); \
RTFL_OBJ_PRINT ("leave", "p:s", obj, vals); \
} STMT_END
#define DBG_OBJ_LEAVE_VAL0(val) \
DBG_OBJ_LEAVE_VAL0_O (this, val)
#define DBG_OBJ_LEAVE_VAL0_O(obj, val) \
RTFL_OBJ_PRINT ("leave", "p:s:", obj, val)
#define DBG_OBJ_CREATE(klass) \
DBG_OBJ_CREATE_O (this, klass)
#define DBG_OBJ_CREATE_O(obj, klass) \
RTFL_OBJ_PRINT ("create", "p:s", obj, klass);
#define DBG_OBJ_DELETE() \
DBG_OBJ_DELETE_O (this)
#define DBG_OBJ_DELETE_O(obj) \
RTFL_OBJ_PRINT ("delete", "p", obj);
#define DBG_OBJ_BASECLASS(klass) \
RTFL_OBJ_PRINT ("ident", "p:p", this, (klass*)this);
#define DBG_OBJ_ASSOC(parent, child) \
RTFL_OBJ_PRINT ("assoc", "p:p", parent, child); \
#define DBG_OBJ_ASSOC_PARENT(parent) \
DBG_OBJ_ASSOC (parent, this);
#define DBG_OBJ_ASSOC_CHILD(child) \
DBG_OBJ_ASSOC (this, child);
#define DBG_OBJ_SET_NUM(var, val) \
DBG_OBJ_SET_NUM_O (this, var, val)
#define DBG_OBJ_SET_NUM_O(obj, var, val) \
RTFL_OBJ_PRINT ("set", "p:s:d", obj, var, val)
#define DBG_OBJ_SET_SYM(var, val) \
DBG_OBJ_SET_SYM_O (this, var, val)
#define DBG_OBJ_SET_SYM_O(obj, var, val) \
RTFL_OBJ_PRINT ("set", "p:s:s", obj, var, val)
#define DBG_OBJ_SET_BOOL(var, val) \
DBG_OBJ_SET_BOOL_O (this, var, val)
#define DBG_OBJ_SET_BOOL_O(obj, var, val) \
RTFL_OBJ_PRINT ("set", "p:s:s", obj, var, (val) ? "true" : "false")
#define DBG_OBJ_SET_STR(var, val) \
DBG_OBJ_SET_STR_O (this, var, val)
#define DBG_OBJ_SET_STR_O(obj, var, val) \
RTFL_OBJ_PRINT ("set", "p:s:\"q\"", obj, var, val)
#define DBG_OBJ_SET_PTR(var, val) \
DBG_OBJ_SET_PTR_O (this, var, val)
#define DBG_OBJ_SET_PTR_O(obj, var, val) \
RTFL_OBJ_PRINT ("set", "p:s:p", obj, var, val)
#define DBG_OBJ_SET_COL(var, val) \
DBG_OBJ_SET_COL_O (this, var, val)
#define DBG_OBJ_SET_COL_O(obj, var, val) \
RTFL_OBJ_PRINT ("set", "p:s:c", obj, var, val)
#define DBG_OBJ_ARRSET_NUM(var, ind, val) \
DBG_OBJ_ARRSET_NUM_O (this, var, ind, val)
#define DBG_OBJ_ARRSET_NUM_O(obj, var, ind, val) \
RTFL_OBJ_PRINT ("set", "p:s.d:d", obj, var, ind, val)
#define DBG_OBJ_ARRSET_SYM(var, ind, val) \
DBG_OBJ_ARRSET_SYM_O (this, var, ind, val)
#define DBG_OBJ_ARRSET_SYM_O(obj, var, ind, val) \
RTFL_OBJ_PRINT ("set", "p:s.d:s", obj, var, ind, val)
#define DBG_OBJ_ARRSET_BOOL(var, ind, val) \
DBG_OBJ_ARRSET_BOOL_O (this, var, ind, val)
#define DBG_OBJ_ARRSET_BOOL_O(obj, var, ind, val) \
RTFL_OBJ_PRINT ("set", "p:s.d:s", obj, var, ind, (val) ? "true" : "false")
#define DBG_OBJ_ARRSET_STR(var, ind, val) \
DBG_OBJ_ARRSET_STR_O (this, var, ind, val)
#define DBG_OBJ_ARRSET_STR_O(obj, var, ind, val) \
RTFL_OBJ_PRINT ("set", "p:s.d:\"q\"", obj, var, ind, val)
#define DBG_OBJ_ARRSET_PTR(var, ind, val) \
DBG_OBJ_ARRSET_PTR_O (this, var, ind, val)
#define DBG_OBJ_ARRSET_PTR_O(obj, var, ind, val) \
RTFL_OBJ_PRINT ("set", "p:s.d:p", obj, var, ind, val)
#define DBG_OBJ_ARRSET_COL(var, ind, val) \
DBG_OBJ_ARRSET_COL_O (this, var, ind, val)
#define DBG_OBJ_ARRSET_COL_O(obj, var, ind, val) \
RTFL_OBJ_PRINT ("set", "p:s.d:c", obj, var, ind, val)
#define DBG_OBJ_ARRATTRSET_NUM(var, ind, attr, val) \
DBG_OBJ_ARRATTRSET_NUM_O (this, var, ind, attr, val)
#define DBG_OBJ_ARRATTRSET_NUM_O(obj, var, ind, attr, val) \
RTFL_OBJ_PRINT ("set", "p:s.d.s:d", obj, var, ind, attr, val)
#define DBG_OBJ_ARRATTRSET_SYM(var, ind, attr, val) \
DBG_OBJ_ARRATTRSET_SYM_O (this, var, ind, attr, val)
#define DBG_OBJ_ARRATTRSET_SYM_O(obj, var, ind, attr, val) \
RTFL_OBJ_PRINT ("set", "p:s.d.s:s", obj, var, ind, attr, val)
#define DBG_OBJ_ARRATTRSET_BOOL(var, ind, attr, val) \
DBG_OBJ_ARRATTRSET_BOOL_O (this, var, ind, attr, val)
#define DBG_OBJ_ARRATTRSET_BOOL_O(obj, var, ind, attr, val) \
RTFL_OBJ_PRINT ("set", "p:s.d.s:s", obj, var, ind, attr, \
(val) ? "true" : "false")
#define DBG_OBJ_ARRATTRSET_STR(var, ind, attr, val) \
DBG_OBJ_ARRATTRSET_STR_O (this, var, ind, attr, val)
#define DBG_OBJ_ARRATTRSET_STR_O(obj, var, ind, attr, val) \
RTFL_OBJ_PRINT ("set", "p:s.d.s:\"q\"", obj, var, ind, attr, val)
#define DBG_OBJ_ARRATTRSET_PTR(var, ind, attr, val) \
DBG_OBJ_ARRATTRSET_PTR_O (this, var, ind, attr, val)
#define DBG_OBJ_ARRATTRSET_PTR_O(obj, var, ind, attr, val) \
RTFL_OBJ_PRINT ("set", "p:s.d.s:p", obj, var, ind, attr, val)
#define DBG_OBJ_ARRATTRSET_COL(var, ind, attr, val) \
DBG_OBJ_ARRATTRSET_COL_O (this, var, ind, attr, val)
#define DBG_OBJ_ARRATTRSET_COL_O(obj, var, ind, attr, val) \
RTFL_OBJ_PRINT ("set", "p:s.d.s:c", obj, var, ind, attr, val)
#define DBG_OBJ_CLASS_COLOR(klass, color) \
RTFL_OBJ_PRINT ("class-color", "s:s", klass, color)
#else /* DBG_RTFL */
#define STMT_NOP do { } while (0)
#define DBG_IF_RTFL if(0)
#define DBG_GEN_TIME() STMT_NOP
#define DBG_OBJ_MSG(aspect, prio, msg) STMT_NOP
#define DBG_OBJ_MSG_O(aspect, prio, obj, msg) STMT_NOP
#define DBG_OBJ_MSGF(aspect, prio, fmt, ...) STMT_NOP
#define DBG_OBJ_MSGF_O(aspect, prio, obj, fmt, ...) STMT_NOP
#define DBG_OBJ_MARK(aspect, prio, mark) STMT_NOP
#define DBG_OBJ_MARK_O(aspect, prio, obj, mark) STMT_NOP
#define DBG_OBJ_MARKF(aspect, prio, fmt, ...) STMT_NOP
#define DBG_OBJ_MARKF_O(aspect, prio, obj, fmt, ...) STMT_NOP
#define DBG_OBJ_MSG_START() STMT_NOP
#define DBG_OBJ_MSG_START_O(obj) STMT_NOP
#define DBG_OBJ_MSG_END() STMT_NOP
#define DBG_OBJ_MSG_END_O(obj) STMT_NOP
#define DBG_OBJ_ENTER0(aspect, prio, funname) STMT_NOP
#define DBG_OBJ_ENTER0_O(aspect, prio, obj, funname) STMT_NOP
#define DBG_OBJ_ENTER(aspect, prio, funname, fmt, ...) STMT_NOP
#define DBG_OBJ_ENTER_O(aspect, prio, obj, funname, fmt, ...) STMT_NOP
#define DBG_OBJ_LEAVE() STMT_NOP
#define DBG_OBJ_LEAVE_O(obj) STMT_NOP
#define DBG_OBJ_LEAVE_VAL(fmt, ...) STMT_NOP
#define DBG_OBJ_LEAVE_VAL_O(obj, fmt, ...) STMT_NOP
#define DBG_OBJ_LEAVE_VAL0(val) STMT_NOP
#define DBG_OBJ_LEAVE_VAL0_O(obj, val) STMT_NOP
#define DBG_OBJ_CREATE(klass) STMT_NOP
#define DBG_OBJ_CREATE_O(obj, klass) STMT_NOP
#define DBG_OBJ_DELETE() STMT_NOP
#define DBG_OBJ_DELETE_O(obj) STMT_NOP
#define DBG_OBJ_BASECLASS(klass) STMT_NOP
#define DBG_OBJ_ASSOC(parent, child) STMT_NOP
#define DBG_OBJ_ASSOC_PARENT(parent) STMT_NOP
#define DBG_OBJ_ASSOC_CHILD(child) STMT_NOP
#define DBG_OBJ_SET_NUM(var, val) STMT_NOP
#define DBG_OBJ_SET_NUM_O(obj, var, val) STMT_NOP
#define DBG_OBJ_SET_SYM(var, val) STMT_NOP
#define DBG_OBJ_SET_SYM_O(obj, var, val) STMT_NOP
#define DBG_OBJ_SET_BOOL(var, val) STMT_NOP
#define DBG_OBJ_SET_BOOL_O(obj, var, val) STMT_NOP
#define DBG_OBJ_SET_STR(var, val) STMT_NOP
#define DBG_OBJ_SET_STR_O(obj, var, val) STMT_NOP
#define DBG_OBJ_SET_PTR(var, val) STMT_NOP
#define DBG_OBJ_SET_PTR_O(obj, var, val) STMT_NOP
#define DBG_OBJ_SET_COL(var, val) STMT_NOP
#define DBG_OBJ_SET_COL_O(obj, var, val) STMT_NOP
#define DBG_OBJ_ARRSET_NUM(var, ind, val) STMT_NOP
#define DBG_OBJ_ARRSET_NUM_O(obj, var, ind, val) STMT_NOP
#define DBG_OBJ_ARRSET_SYM(var, ind, val) STMT_NOP
#define DBG_OBJ_ARRSET_SYM_O(obj, var, ind, val) STMT_NOP
#define DBG_OBJ_ARRSET_BOOL(var, ind, val) STMT_NOP
#define DBG_OBJ_ARRSET_BOOL_O(obj, var, ind, val) STMT_NOP
#define DBG_OBJ_ARRSET_STR(var, ind, val) STMT_NOP
#define DBG_OBJ_ARRSET_STR_O(obj, var, ind, val) STMT_NOP
#define DBG_OBJ_ARRSET_PTR(var, ind, val) STMT_NOP
#define DBG_OBJ_ARRSET_PTR_O(obj, var, ind, val) STMT_NOP
#define DBG_OBJ_ARRSET_COL(var, ind, val) STMT_NOP
#define DBG_OBJ_ARRSET_COL_O(obj, var, ind, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_NUM(var, ind, attr, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_NUM_O(obj, var, ind, attr, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_SYM(var, ind, attr, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_SYM_O(obj, var, ind, attr, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_BOOL(var, ind, attr, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_BOOL_O(obj, var, ind, attr, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_STR(var, ind, attr, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_STR_O(obj, var, ind, attr, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_PTR(var, ind, attr, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_PTR_O(obj, var, ind, attr, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_COL(var, ind, attr, val) STMT_NOP
#define DBG_OBJ_ARRATTRSET_COL_O(obj, var, ind, attr, val) STMT_NOP
#define DBG_OBJ_CLASS_COLOR(klass, color) STMT_NOP
#endif /* DBG_RTFL */
#endif /* __DEBUG_RTFL_HH__ */