Dillo
debug_rtfl.hh
Go to the documentation of this file.
1 // WARNING: This file has been generated. Do not edit!
2 
3 /*
4  * This file is part of RTFL, see <http://home.gna.org/rtfl/>
5  * for details.
6  *
7  * This file (but not RTFL itself) is in the public domain, since it is only a
8  * simple implementation of a protocol, containing nothing more than trivial
9  * work. However, it would be nice to keep this notice, along with the URL
10  * above.
11  *
12  * ----------------------------------------------------------------------------
13  *
14  * Defines macros for printing RTFL commands. See documentation for detail
15  * (online at <http://home.gna.org/rtfl/doc/rtfl.html>). These macros are only
16  * active, when the pre-processor variable DBG_RTFL is defined. If not,
17  * alternatives are defined, which have no effect.
18  *
19  * This variant assumes that __FILE__ is only the base of the source file name,
20  * so, to get the full path, CUR_WORKING_DIR has to be defined. See RTFL
21  * documentation for more details.
22  */
23 
24 #ifndef __DEBUG_RTFL_HH__
25 #define __DEBUG_RTFL_HH__
26 
27 #ifdef DBG_RTFL
28 
29 // =======================================
30 // Used by all modules
31 // =======================================
32 
33 #include <stdio.h>
34 #include <stdarg.h>
35 #include <unistd.h>
36 #include <sys/time.h>
37 
38 #define DBG_IF_RTFL if(1)
39 
40 #define STMT_START do
41 #define STMT_END while (0)
42 
43 // Prints an RTFL message to stdout. "fmt" contains simple format
44 // characters how to deal with the additional arguments (no "%"
45 // preceeding, as in printf) or "q" (which additionally
46 // (double-)quotes quotation marks) or "c" (short for "#%06x" and used
47 // for colors), or other characters, which are simply printed. No
48 // quoting: this function cannot be used to print the characters "d",
49 // "p", "s" and "q" directly.
50 
51 inline void rtfl_print (const char *module, const char *version,
52  const char *file, int line, const char *fmt, ...)
53 {
54  // "\n" at the beginning just in case that the previous line is not
55  // finished yet.
56  printf ("\n[rtfl-%s-%s]%s:%d:%d:", module, version, file, line, getpid ());
57 
58  va_list args;
59  va_start (args, fmt);
60 
61  for (int i = 0; fmt[i]; i++) {
62  int n;
63  void *p;
64  char *s;
65 
66  switch (fmt[i]) {
67  case 'd':
68  n = va_arg(args, int);
69  printf ("%d", n);
70  break;
71 
72  case 'p':
73  p = va_arg(args, void*);
74  printf ("%p", p);
75  break;
76 
77  case 's':
78  s = va_arg (args, char*);
79  for (int j = 0; s[j]; j++) {
80  if (s[j] == ':' || s[j] == '\\')
81  putchar ('\\');
82  putchar (s[j]);
83  }
84  break;
85 
86  case 'q':
87  s = va_arg (args, char*);
88  for (int j = 0; s[j]; j++) {
89  if (s[j] == ':' || s[j] == '\\')
90  putchar ('\\');
91  else if (s[j] == '\"')
92  printf ("\\\\"); // a quoted quoting character
93  putchar (s[j]);
94  }
95  break;
96 
97  case 'c':
98  n = va_arg(args, int);
99  printf ("#%06x", n);
100  break;
101 
102  default:
103  putchar (fmt[i]);
104  break;
105  }
106  }
107 
108  va_end (args);
109 
110  putchar ('\n');
111  fflush (stdout);
112 }
113 
114 #define RTFL_PRINT(module, version, cmd, fmt, ...) \
115  rtfl_print (module, version, CUR_WORKING_DIR "/" __FILE__, __LINE__, \
116  "s:" fmt, cmd, __VA_ARGS__)
117 
118 
119 // ==================================
120 // General module
121 // ==================================
122 
123 #define RTFL_GEN_VERSION "1.0"
124 
125 #define RTFL_GEN_PRINT(cmd, fmt, ...) \
126  RTFL_PRINT ("gen", RTFL_GEN_VERSION, cmd, fmt, __VA_ARGS__)
127 
128 #define DBG_GEN_TIME() \
129  STMT_START { \
130  struct timeval tv; \
131  gettimeofday(&tv, NULL); \
132  char buf[32]; \
133  snprintf (buf, sizeof (buf), "%ld%06ld", tv.tv_sec, tv.tv_usec); \
134  RTFL_GEN_PRINT ("time", "s", buf); \
135  } STMT_END
136 
137 
138 // ==================================
139 // Objects module
140 // ==================================
141 
142 #define RTFL_OBJ_VERSION "1.0"
143 
144 #define RTFL_OBJ_PRINT(cmd, fmt, ...) \
145  RTFL_PRINT ("obj", RTFL_OBJ_VERSION, cmd, fmt, __VA_ARGS__)
146 
147 #define DBG_OBJ_MSG(aspect, prio, msg) \
148  DBG_OBJ_MSG_O (aspect, prio, this, msg)
149 
150 #define DBG_OBJ_MSG_O(aspect, prio, obj, msg) \
151  RTFL_OBJ_PRINT ("msg", "p:s:d:s", obj, aspect, prio, msg)
152 
153 #define DBG_OBJ_MSGF(aspect, prio, fmt, ...) \
154  STMT_START { \
155  char msg[256]; \
156  snprintf (msg, sizeof (msg), fmt, __VA_ARGS__); \
157  DBG_OBJ_MSG (aspect, prio, msg); \
158  } STMT_END
159 
160 #define DBG_OBJ_MSGF_O(aspect, prio, obj, fmt, ...) \
161  STMT_START { \
162  char msg[256]; \
163  snprintf (msg, sizeof (msg), fmt, __VA_ARGS__); \
164  DBG_OBJ_MSG_O (aspect, prio, obj, msg); \
165  } STMT_END
166 
167 #define DBG_OBJ_MARK(aspect, prio, mark) \
168  DBG_OBJ_MARK_O (aspect, prio, this, mark)
169 
170 #define DBG_OBJ_MARK_O(aspect, prio, obj, mark) \
171  RTFL_OBJ_PRINT ("mark", "p:s:d:s", obj, aspect, prio, mark)
172 
173 #define DBG_OBJ_MARKF(aspect, prio, fmt, ...) \
174  STMT_START { \
175  char mark[256]; \
176  snprintf (mark, sizeof (mark), fmt, __VA_ARGS__); \
177  DBG_OBJ_MARK (aspect, prio, mark); \
178  } STMT_END
179 
180 #define DBG_OBJ_MARKF_O(aspect, prio, obj, fmt, ...) \
181  STMT_START { \
182  char mark[256]; \
183  snprintf (mark, sizeof (mark), fmt, __VA_ARGS__); \
184  DBG_OBJ_MARK_O (aspect, prio, obj, mark); \
185  } STMT_END
186 
187 #define DBG_OBJ_MSG_START() \
188  DBG_OBJ_MSG_START_O (this)
189 
190 #define DBG_OBJ_MSG_START_O(obj) \
191  RTFL_OBJ_PRINT ("msg-start", "p", obj)
192 
193 #define DBG_OBJ_MSG_END() \
194  DBG_OBJ_MSG_END_O (this)
195 
196 #define DBG_OBJ_MSG_END_O(obj) \
197  RTFL_OBJ_PRINT ("msg-end", "p", obj)
198 
199 #define DBG_OBJ_ENTER0(aspect, prio, funname) \
200  DBG_OBJ_ENTER0_O (aspect, prio, this, funname)
201 
202 #define DBG_OBJ_ENTER0_O(aspect, prio, obj, funname) \
203  RTFL_OBJ_PRINT ("enter", "p:s:d:s:", obj, aspect, prio, funname);
204 
205 #define DBG_OBJ_ENTER(aspect, prio, funname, fmt, ...) \
206  STMT_START { \
207  char args[256]; \
208  snprintf (args, sizeof (args), fmt, __VA_ARGS__); \
209  RTFL_OBJ_PRINT ("enter", "p:s:d:s:s", this, aspect, prio, funname, \
210  args); \
211  } STMT_END
212 
213 #define DBG_OBJ_ENTER_O(aspect, prio, obj, funname, fmt, ...) \
214  STMT_START { \
215  char args[256]; \
216  snprintf (args, sizeof (args), fmt, __VA_ARGS__); \
217  RTFL_OBJ_PRINT ("enter", "p:s:d:s:s", obj, aspect, prio, funname, \
218  args); \
219  } STMT_END
220 
221 #define DBG_OBJ_LEAVE() \
222  DBG_OBJ_LEAVE_O (this)
223 
224 #define DBG_OBJ_LEAVE_O(obj) \
225  RTFL_OBJ_PRINT ("leave", "p", obj);
226 
227 #define DBG_OBJ_LEAVE_VAL(fmt, ...) \
228  STMT_START { \
229  char vals[256]; \
230  snprintf (vals, sizeof (vals), fmt, __VA_ARGS__); \
231  RTFL_OBJ_PRINT ("leave", "p:s", this, vals); \
232  } STMT_END
233 
234 #define DBG_OBJ_LEAVE_VAL_O(obj, fmt, ...) \
235  STMT_START { \
236  char vals[256]; \
237  snprintf (vals, sizeof (vals), fmt, __VA_ARGS__); \
238  RTFL_OBJ_PRINT ("leave", "p:s", obj, vals); \
239  } STMT_END
240 
241 #define DBG_OBJ_LEAVE_VAL0(val) \
242  DBG_OBJ_LEAVE_VAL0_O (this, val)
243 
244 #define DBG_OBJ_LEAVE_VAL0_O(obj, val) \
245  RTFL_OBJ_PRINT ("leave", "p:s:", obj, val)
246 
247 #define DBG_OBJ_CREATE(klass) \
248  DBG_OBJ_CREATE_O (this, klass)
249 
250 #define DBG_OBJ_CREATE_O(obj, klass) \
251  RTFL_OBJ_PRINT ("create", "p:s", obj, klass);
252 
253 #define DBG_OBJ_DELETE() \
254  DBG_OBJ_DELETE_O (this)
255 
256 #define DBG_OBJ_DELETE_O(obj) \
257  RTFL_OBJ_PRINT ("delete", "p", obj);
258 
259 #define DBG_OBJ_BASECLASS(klass) \
260  RTFL_OBJ_PRINT ("ident", "p:p", this, (klass*)this);
261 
262 #define DBG_OBJ_ASSOC(parent, child) \
263  RTFL_OBJ_PRINT ("assoc", "p:p", parent, child); \
264 
265 #define DBG_OBJ_ASSOC_PARENT(parent) \
266  DBG_OBJ_ASSOC (parent, this);
267 
268 #define DBG_OBJ_ASSOC_CHILD(child) \
269  DBG_OBJ_ASSOC (this, child);
270 
271 #define DBG_OBJ_SET_NUM(var, val) \
272  DBG_OBJ_SET_NUM_O (this, var, val)
273 
274 #define DBG_OBJ_SET_NUM_O(obj, var, val) \
275  RTFL_OBJ_PRINT ("set", "p:s:d", obj, var, val)
276 
277 #define DBG_OBJ_SET_SYM(var, val) \
278  DBG_OBJ_SET_SYM_O (this, var, val)
279 
280 #define DBG_OBJ_SET_SYM_O(obj, var, val) \
281  RTFL_OBJ_PRINT ("set", "p:s:s", obj, var, val)
282 
283 #define DBG_OBJ_SET_BOOL(var, val) \
284  DBG_OBJ_SET_BOOL_O (this, var, val)
285 
286 #define DBG_OBJ_SET_BOOL_O(obj, var, val) \
287  RTFL_OBJ_PRINT ("set", "p:s:s", obj, var, (val) ? "true" : "false")
288 
289 #define DBG_OBJ_SET_STR(var, val) \
290  DBG_OBJ_SET_STR_O (this, var, val)
291 
292 #define DBG_OBJ_SET_STR_O(obj, var, val) \
293  RTFL_OBJ_PRINT ("set", "p:s:\"q\"", obj, var, val)
294 
295 #define DBG_OBJ_SET_PTR(var, val) \
296  DBG_OBJ_SET_PTR_O (this, var, val)
297 
298 #define DBG_OBJ_SET_PTR_O(obj, var, val) \
299  RTFL_OBJ_PRINT ("set", "p:s:p", obj, var, val)
300 
301 #define DBG_OBJ_SET_COL(var, val) \
302  DBG_OBJ_SET_COL_O (this, var, val)
303 
304 #define DBG_OBJ_SET_COL_O(obj, var, val) \
305  RTFL_OBJ_PRINT ("set", "p:s:c", obj, var, val)
306 
307 #define DBG_OBJ_ARRSET_NUM(var, ind, val) \
308  DBG_OBJ_ARRSET_NUM_O (this, var, ind, val)
309 
310 #define DBG_OBJ_ARRSET_NUM_O(obj, var, ind, val) \
311  RTFL_OBJ_PRINT ("set", "p:s.d:d", obj, var, ind, val)
312 
313 #define DBG_OBJ_ARRSET_SYM(var, ind, val) \
314  DBG_OBJ_ARRSET_SYM_O (this, var, ind, val)
315 
316 #define DBG_OBJ_ARRSET_SYM_O(obj, var, ind, val) \
317  RTFL_OBJ_PRINT ("set", "p:s.d:s", obj, var, ind, val)
318 
319 #define DBG_OBJ_ARRSET_BOOL(var, ind, val) \
320  DBG_OBJ_ARRSET_BOOL_O (this, var, ind, val)
321 
322 #define DBG_OBJ_ARRSET_BOOL_O(obj, var, ind, val) \
323  RTFL_OBJ_PRINT ("set", "p:s.d:s", obj, var, ind, (val) ? "true" : "false")
324 
325 #define DBG_OBJ_ARRSET_STR(var, ind, val) \
326  DBG_OBJ_ARRSET_STR_O (this, var, ind, val)
327 
328 #define DBG_OBJ_ARRSET_STR_O(obj, var, ind, val) \
329  RTFL_OBJ_PRINT ("set", "p:s.d:\"q\"", obj, var, ind, val)
330 
331 #define DBG_OBJ_ARRSET_PTR(var, ind, val) \
332  DBG_OBJ_ARRSET_PTR_O (this, var, ind, val)
333 
334 #define DBG_OBJ_ARRSET_PTR_O(obj, var, ind, val) \
335  RTFL_OBJ_PRINT ("set", "p:s.d:p", obj, var, ind, val)
336 
337 #define DBG_OBJ_ARRSET_COL(var, ind, val) \
338  DBG_OBJ_ARRSET_COL_O (this, var, ind, val)
339 
340 #define DBG_OBJ_ARRSET_COL_O(obj, var, ind, val) \
341  RTFL_OBJ_PRINT ("set", "p:s.d:c", obj, var, ind, val)
342 
343 #define DBG_OBJ_ARRATTRSET_NUM(var, ind, attr, val) \
344  DBG_OBJ_ARRATTRSET_NUM_O (this, var, ind, attr, val)
345 
346 #define DBG_OBJ_ARRATTRSET_NUM_O(obj, var, ind, attr, val) \
347  RTFL_OBJ_PRINT ("set", "p:s.d.s:d", obj, var, ind, attr, val)
348 
349 #define DBG_OBJ_ARRATTRSET_SYM(var, ind, attr, val) \
350  DBG_OBJ_ARRATTRSET_SYM_O (this, var, ind, attr, val)
351 
352 #define DBG_OBJ_ARRATTRSET_SYM_O(obj, var, ind, attr, val) \
353  RTFL_OBJ_PRINT ("set", "p:s.d.s:s", obj, var, ind, attr, val)
354 
355 #define DBG_OBJ_ARRATTRSET_BOOL(var, ind, attr, val) \
356  DBG_OBJ_ARRATTRSET_BOOL_O (this, var, ind, attr, val)
357 
358 #define DBG_OBJ_ARRATTRSET_BOOL_O(obj, var, ind, attr, val) \
359  RTFL_OBJ_PRINT ("set", "p:s.d.s:s", obj, var, ind, attr, \
360  (val) ? "true" : "false")
361 
362 #define DBG_OBJ_ARRATTRSET_STR(var, ind, attr, val) \
363  DBG_OBJ_ARRATTRSET_STR_O (this, var, ind, attr, val)
364 
365 #define DBG_OBJ_ARRATTRSET_STR_O(obj, var, ind, attr, val) \
366  RTFL_OBJ_PRINT ("set", "p:s.d.s:\"q\"", obj, var, ind, attr, val)
367 
368 #define DBG_OBJ_ARRATTRSET_PTR(var, ind, attr, val) \
369  DBG_OBJ_ARRATTRSET_PTR_O (this, var, ind, attr, val)
370 
371 #define DBG_OBJ_ARRATTRSET_PTR_O(obj, var, ind, attr, val) \
372  RTFL_OBJ_PRINT ("set", "p:s.d.s:p", obj, var, ind, attr, val)
373 
374 #define DBG_OBJ_ARRATTRSET_COL(var, ind, attr, val) \
375  DBG_OBJ_ARRATTRSET_COL_O (this, var, ind, attr, val)
376 
377 #define DBG_OBJ_ARRATTRSET_COL_O(obj, var, ind, attr, val) \
378  RTFL_OBJ_PRINT ("set", "p:s.d.s:c", obj, var, ind, attr, val)
379 
380 #define DBG_OBJ_CLASS_COLOR(klass, color) \
381  RTFL_OBJ_PRINT ("class-color", "s:s", klass, color)
382 
383 #else /* DBG_RTFL */
384 
385 #define STMT_NOP do { } while (0)
386 
387 #define DBG_IF_RTFL if(0)
388 
389 #define DBG_GEN_TIME() STMT_NOP
390 #define DBG_OBJ_MSG(aspect, prio, msg) STMT_NOP
391 #define DBG_OBJ_MSG_O(aspect, prio, obj, msg) STMT_NOP
392 #define DBG_OBJ_MSGF(aspect, prio, fmt, ...) STMT_NOP
393 #define DBG_OBJ_MSGF_O(aspect, prio, obj, fmt, ...) STMT_NOP
394 #define DBG_OBJ_MARK(aspect, prio, mark) STMT_NOP
395 #define DBG_OBJ_MARK_O(aspect, prio, obj, mark) STMT_NOP
396 #define DBG_OBJ_MARKF(aspect, prio, fmt, ...) STMT_NOP
397 #define DBG_OBJ_MARKF_O(aspect, prio, obj, fmt, ...) STMT_NOP
398 #define DBG_OBJ_MSG_START() STMT_NOP
399 #define DBG_OBJ_MSG_START_O(obj) STMT_NOP
400 #define DBG_OBJ_MSG_END() STMT_NOP
401 #define DBG_OBJ_MSG_END_O(obj) STMT_NOP
402 #define DBG_OBJ_ENTER0(aspect, prio, funname) STMT_NOP
403 #define DBG_OBJ_ENTER0_O(aspect, prio, obj, funname) STMT_NOP
404 #define DBG_OBJ_ENTER(aspect, prio, funname, fmt, ...) STMT_NOP
405 #define DBG_OBJ_ENTER_O(aspect, prio, obj, funname, fmt, ...) STMT_NOP
406 #define DBG_OBJ_LEAVE() STMT_NOP
407 #define DBG_OBJ_LEAVE_O(obj) STMT_NOP
408 #define DBG_OBJ_LEAVE_VAL(fmt, ...) STMT_NOP
409 #define DBG_OBJ_LEAVE_VAL_O(obj, fmt, ...) STMT_NOP
410 #define DBG_OBJ_LEAVE_VAL0(val) STMT_NOP
411 #define DBG_OBJ_LEAVE_VAL0_O(obj, val) STMT_NOP
412 #define DBG_OBJ_CREATE(klass) STMT_NOP
413 #define DBG_OBJ_CREATE_O(obj, klass) STMT_NOP
414 #define DBG_OBJ_DELETE() STMT_NOP
415 #define DBG_OBJ_DELETE_O(obj) STMT_NOP
416 #define DBG_OBJ_BASECLASS(klass) STMT_NOP
417 #define DBG_OBJ_ASSOC(parent, child) STMT_NOP
418 #define DBG_OBJ_ASSOC_PARENT(parent) STMT_NOP
419 #define DBG_OBJ_ASSOC_CHILD(child) STMT_NOP
420 #define DBG_OBJ_SET_NUM(var, val) STMT_NOP
421 #define DBG_OBJ_SET_NUM_O(obj, var, val) STMT_NOP
422 #define DBG_OBJ_SET_SYM(var, val) STMT_NOP
423 #define DBG_OBJ_SET_SYM_O(obj, var, val) STMT_NOP
424 #define DBG_OBJ_SET_BOOL(var, val) STMT_NOP
425 #define DBG_OBJ_SET_BOOL_O(obj, var, val) STMT_NOP
426 #define DBG_OBJ_SET_STR(var, val) STMT_NOP
427 #define DBG_OBJ_SET_STR_O(obj, var, val) STMT_NOP
428 #define DBG_OBJ_SET_PTR(var, val) STMT_NOP
429 #define DBG_OBJ_SET_PTR_O(obj, var, val) STMT_NOP
430 #define DBG_OBJ_SET_COL(var, val) STMT_NOP
431 #define DBG_OBJ_SET_COL_O(obj, var, val) STMT_NOP
432 #define DBG_OBJ_ARRSET_NUM(var, ind, val) STMT_NOP
433 #define DBG_OBJ_ARRSET_NUM_O(obj, var, ind, val) STMT_NOP
434 #define DBG_OBJ_ARRSET_SYM(var, ind, val) STMT_NOP
435 #define DBG_OBJ_ARRSET_SYM_O(obj, var, ind, val) STMT_NOP
436 #define DBG_OBJ_ARRSET_BOOL(var, ind, val) STMT_NOP
437 #define DBG_OBJ_ARRSET_BOOL_O(obj, var, ind, val) STMT_NOP
438 #define DBG_OBJ_ARRSET_STR(var, ind, val) STMT_NOP
439 #define DBG_OBJ_ARRSET_STR_O(obj, var, ind, val) STMT_NOP
440 #define DBG_OBJ_ARRSET_PTR(var, ind, val) STMT_NOP
441 #define DBG_OBJ_ARRSET_PTR_O(obj, var, ind, val) STMT_NOP
442 #define DBG_OBJ_ARRSET_COL(var, ind, val) STMT_NOP
443 #define DBG_OBJ_ARRSET_COL_O(obj, var, ind, val) STMT_NOP
444 #define DBG_OBJ_ARRATTRSET_NUM(var, ind, attr, val) STMT_NOP
445 #define DBG_OBJ_ARRATTRSET_NUM_O(obj, var, ind, attr, val) STMT_NOP
446 #define DBG_OBJ_ARRATTRSET_SYM(var, ind, attr, val) STMT_NOP
447 #define DBG_OBJ_ARRATTRSET_SYM_O(obj, var, ind, attr, val) STMT_NOP
448 #define DBG_OBJ_ARRATTRSET_BOOL(var, ind, attr, val) STMT_NOP
449 #define DBG_OBJ_ARRATTRSET_BOOL_O(obj, var, ind, attr, val) STMT_NOP
450 #define DBG_OBJ_ARRATTRSET_STR(var, ind, attr, val) STMT_NOP
451 #define DBG_OBJ_ARRATTRSET_STR_O(obj, var, ind, attr, val) STMT_NOP
452 #define DBG_OBJ_ARRATTRSET_PTR(var, ind, attr, val) STMT_NOP
453 #define DBG_OBJ_ARRATTRSET_PTR_O(obj, var, ind, attr, val) STMT_NOP
454 #define DBG_OBJ_ARRATTRSET_COL(var, ind, attr, val) STMT_NOP
455 #define DBG_OBJ_ARRATTRSET_COL_O(obj, var, ind, attr, val) STMT_NOP
456 #define DBG_OBJ_CLASS_COLOR(klass, color) STMT_NOP
457 
458 #endif /* DBG_RTFL */
459 
460 #endif /* __DEBUG_RTFL_HH__ */