ReactOS 0.4.15-dev-8102-g108db8f
debug.h
Go to the documentation of this file.
1/*
2 debug.h:
3 if DEBUG defined: debugging macro fprintf wrappers
4 else: macros defined to do nothing
5 That saves typing #ifdef DEBUG all the time and still preserves
6 lean code without debugging.
7
8 public domain (or LGPL / GPL, if you like that more;-)
9 generated by debugdef.pl, what was
10 trivially written by Thomas Orgis <thomas@orgis.org>
11*/
12
13#include "config.h"
14
15/*
16 I could do that with variadic macros available:
17 #define sdebug(me, s) fprintf(stderr, "[location] " s "\n")
18 #define debug(me, s, ...) fprintf(stderr, "[location] " s "}n", __VA_ARGS__)
19
20 Variadic macros are a C99 feature...
21 Now just predefining stuff non-variadic for up to 15 arguments.
22 It's cumbersome to have them all with different names, though...
23
24 Update: Also adding variadic macros now. We star to use some C99.
25*/
26
27#ifdef ME
28#define DBGPRFX ME": "
29#else
30#define DBGPRFX ""
31#endif
32
33#ifdef DEBUG
34
35#include <stdio.h>
36
37// The future (from about 20 years ago;-):
38#define mdebug(s, ...) fprintf(stderr, DBGPRFX "[" __FILE__ ":%i] debug: " s "\n", __LINE__, __VA_ARGS__)
39
40#define debug(s) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__)
41#define debug1(s, a) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a)
42#define debug2(s, a, b) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b)
43#define debug3(s, a, b, c) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c)
44#define debug4(s, a, b, c, d) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d)
45#define debug5(s, a, b, c, d, e) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e)
46#define debug6(s, a, b, c, d, e, f) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f)
47#define debug7(s, a, b, c, d, e, f, g) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g)
48#define debug8(s, a, b, c, d, e, f, g, h) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h)
49#define debug9(s, a, b, c, d, e, f, g, h, i) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i)
50#define debug10(s, a, b, c, d, e, f, g, h, i, j) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j)
51#define debug11(s, a, b, c, d, e, f, g, h, i, j, k) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k)
52#define debug12(s, a, b, c, d, e, f, g, h, i, j, k, l) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l)
53#define debug13(s, a, b, c, d, e, f, g, h, i, j, k, l, m) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m)
54#define debug14(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
55#define debug15(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] debug: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
56#else
57
58#define mdebug(s, ...)
59
60#define debug(s)
61#define debug1(s, a)
62#define debug2(s, a, b)
63#define debug3(s, a, b, c)
64#define debug4(s, a, b, c, d)
65#define debug5(s, a, b, c, d, e)
66#define debug6(s, a, b, c, d, e, f)
67#define debug7(s, a, b, c, d, e, f, g)
68#define debug8(s, a, b, c, d, e, f, g, h)
69#define debug9(s, a, b, c, d, e, f, g, h, i)
70#define debug10(s, a, b, c, d, e, f, g, h, i, j)
71#define debug11(s, a, b, c, d, e, f, g, h, i, j, k)
72#define debug12(s, a, b, c, d, e, f, g, h, i, j, k, l)
73#define debug13(s, a, b, c, d, e, f, g, h, i, j, k, l, m)
74#define debug14(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
75#define debug15(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
76#endif
77
78/* warning macros also here... */
79#ifndef NO_WARNING
80
81#define mwarning(s, ...) fprintf(stderr, DBGPRFX "[" __FILE__ ":%i] warning: " s "\n", __LINE__, __VA_ARGS__)
82
83#define warning(s) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__)
84#define warning1(s, a) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a)
85#define warning2(s, a, b) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b)
86#define warning3(s, a, b, c) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c)
87#define warning4(s, a, b, c, d) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d)
88#define warning5(s, a, b, c, d, e) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e)
89#define warning6(s, a, b, c, d, e, f) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f)
90#define warning7(s, a, b, c, d, e, f, g) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g)
91#define warning8(s, a, b, c, d, e, f, g, h) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h)
92#define warning9(s, a, b, c, d, e, f, g, h, i) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i)
93#define warning10(s, a, b, c, d, e, f, g, h, i, j) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j)
94#define warning11(s, a, b, c, d, e, f, g, h, i, j, k) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k)
95#define warning12(s, a, b, c, d, e, f, g, h, i, j, k, l) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l)
96#define warning13(s, a, b, c, d, e, f, g, h, i, j, k, l, m) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m)
97#define warning14(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
98#define warning15(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] warning: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
99#else
100#define mwarning(s, ...)
101#define warning(s)
102#define warning1(s, a)
103#define warning2(s, a, b)
104#define warning3(s, a, b, c)
105#define warning4(s, a, b, c, d)
106#define warning5(s, a, b, c, d, e)
107#define warning6(s, a, b, c, d, e, f)
108#define warning7(s, a, b, c, d, e, f, g)
109#define warning8(s, a, b, c, d, e, f, g, h)
110#define warning9(s, a, b, c, d, e, f, g, h, i)
111#define warning10(s, a, b, c, d, e, f, g, h, i, j)
112#define warning11(s, a, b, c, d, e, f, g, h, i, j, k)
113#define warning12(s, a, b, c, d, e, f, g, h, i, j, k, l)
114#define warning13(s, a, b, c, d, e, f, g, h, i, j, k, l, m)
115#define warning14(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
116#define warning15(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
117#endif
118
119/* error macros also here... */
120#ifndef NO_ERRORMSG
121
122#define merror(s, ...) fprintf(stderr, DBGPRFX "[" __FILE__ ":%i] error: " s "\n", __LINE__, __VA_ARGS__)
123
124#define error(s) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__)
125#define error1(s, a) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a)
126#define error2(s, a, b) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b)
127#define error3(s, a, b, c) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c)
128#define error4(s, a, b, c, d) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d)
129#define error5(s, a, b, c, d, e) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e)
130#define error6(s, a, b, c, d, e, f) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f)
131#define error7(s, a, b, c, d, e, f, g) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g)
132#define error8(s, a, b, c, d, e, f, g, h) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h)
133#define error9(s, a, b, c, d, e, f, g, h, i) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i)
134#define error10(s, a, b, c, d, e, f, g, h, i, j) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j)
135#define error11(s, a, b, c, d, e, f, g, h, i, j, k) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k)
136#define error12(s, a, b, c, d, e, f, g, h, i, j, k, l) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l)
137#define error13(s, a, b, c, d, e, f, g, h, i, j, k, l, m) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m)
138#define error14(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
139#define error15(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] error: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
140#else
141#define merror(s, ...)
142#define error(s)
143#define error1(s, a)
144#define error2(s, a, b)
145#define error3(s, a, b, c)
146#define error4(s, a, b, c, d)
147#define error5(s, a, b, c, d, e)
148#define error6(s, a, b, c, d, e, f)
149#define error7(s, a, b, c, d, e, f, g)
150#define error8(s, a, b, c, d, e, f, g, h)
151#define error9(s, a, b, c, d, e, f, g, h, i)
152#define error10(s, a, b, c, d, e, f, g, h, i, j)
153#define error11(s, a, b, c, d, e, f, g, h, i, j, k)
154#define error12(s, a, b, c, d, e, f, g, h, i, j, k, l)
155#define error13(s, a, b, c, d, e, f, g, h, i, j, k, l, m)
156#define error14(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
157#define error15(s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
158#endif
159
160/* ereturn macros also here... */
161#ifndef NO_ERETURN
162
163#define mereturn(rv, s, ...) do{ fprintf(stderr, DBGPRFX "[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, __VA_ARGS__); return rv; }while(0)
164
165#define ereturn(rv, s) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__); return rv; }while(0)
166#define ereturn1(rv, s, a) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a); return rv; }while(0)
167#define ereturn2(rv, s, a, b) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b); return rv; }while(0)
168#define ereturn3(rv, s, a, b, c) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c); return rv; }while(0)
169#define ereturn4(rv, s, a, b, c, d) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d); return rv; }while(0)
170#define ereturn5(rv, s, a, b, c, d, e) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e); return rv; }while(0)
171#define ereturn6(rv, s, a, b, c, d, e, f) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f); return rv; }while(0)
172#define ereturn7(rv, s, a, b, c, d, e, f, g) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g); return rv; }while(0)
173#define ereturn8(rv, s, a, b, c, d, e, f, g, h) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h); return rv; }while(0)
174#define ereturn9(rv, s, a, b, c, d, e, f, g, h, i) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i); return rv; }while(0)
175#define ereturn10(rv, s, a, b, c, d, e, f, g, h, i, j) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j); return rv; }while(0)
176#define ereturn11(rv, s, a, b, c, d, e, f, g, h, i, j, k) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k); return rv; }while(0)
177#define ereturn12(rv, s, a, b, c, d, e, f, g, h, i, j, k, l) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l); return rv; }while(0)
178#define ereturn13(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m); return rv; }while(0)
179#define ereturn14(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n); return rv; }while(0)
180#define ereturn15(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) do{ fprintf(stderr, DBGPRFX"[" __FILE__ ":%i] ereturn: " s "\n", __LINE__, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o); return rv; }while(0)
181#else
182#define mereturn(rv, s, ...) return rv
183#define ereturn(rv, s) return rv
184#define ereturn1(rv, s, a) return rv
185#define ereturn2(rv, s, a, b) return rv
186#define ereturn3(rv, s, a, b, c) return rv
187#define ereturn4(rv, s, a, b, c, d) return rv
188#define ereturn5(rv, s, a, b, c, d, e) return rv
189#define ereturn6(rv, s, a, b, c, d, e, f) return rv
190#define ereturn7(rv, s, a, b, c, d, e, f, g) return rv
191#define ereturn8(rv, s, a, b, c, d, e, f, g, h) return rv
192#define ereturn9(rv, s, a, b, c, d, e, f, g, h, i) return rv
193#define ereturn10(rv, s, a, b, c, d, e, f, g, h, i, j) return rv
194#define ereturn11(rv, s, a, b, c, d, e, f, g, h, i, j, k) return rv
195#define ereturn12(rv, s, a, b, c, d, e, f, g, h, i, j, k, l) return rv
196#define ereturn13(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m) return rv
197#define ereturn14(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n) return rv
198#define ereturn15(rv, s, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) return rv
199#endif