Rabbit Tree
Radix bit tries for implementing associative arrays and sets in C.
debug.h
Go to the documentation of this file.
1
7#ifndef RBT_HEADER_DEBUG
8#define RBT_HEADER_DEBUG
9
10#ifndef RBT_DEBUG_USE_COLOR
11#ifdef RBT_USE_COLOR
12#define RBT_DEBUG_USE_COLOR 1
13#endif //RBT_USE_COLOR
14#endif //RBT_DEBUG_USE_COLOR
15
19#ifndef RBT_DEBUG
20#define RBT_DEBUG 0
21#endif //RBT_DEBUG
22
26#ifndef RBT_DEBUG_FD
27#define RBT_DEBUG_FD stderr
28#endif //RBT_DEBUG_FD
29
33#ifndef RBT_DEBUG_INDENT
34#define RBT_DEBUG_INDENT 0
35#endif //RBT_DEBUG_INDENT
36
37// Nested debug messages to facilitate tracing.
38#if RBT_DEBUG_INDENT>0
42unsigned int RBT_NESTING_LEVEL = 0;
43#ifdef __GNUC__
44void
45__cyg_profile_func_enter(void * this_fn, void * call_site)
46{
47 RBT_NESTING_LEVEL += RBT_DEBUG_INDENT;
48}
49
50void
51__cyg_profile_func_exit(void * this_fn, void * call_site)
52{
53 RBT_NESTING_LEVEL -= RBT_DEBUG_INDENT;
54}
55#else
56#error RBT_DEBUG_INDENT is currently only supported when using GCC.
57#endif //__GNUC__
58#endif //RBT_DEBUG_INDENT>0
59
60#ifdef RBT_DEBUG_USE_COLOR
64#define RBT_DEBUG_FILENAME_COLOR "\033[34m"
68#define RBT_DEBUG_LINENUMBER_COLOR "\033[36m"
72#define RBT_DEBUG_FUNCTIONNAME_COLOR "\033[35m"
76#define RBT_DEBUG_RESET_COLOR "\033[0m"
77#else
81#define RBT_DEBUG_FILENAME_COLOR ""
82#define RBT_DEBUG_LINENUMBER_COLOR ""
83#define RBT_DEBUG_FUNCTIONNAME_COLOR ""
84#define RBT_DEBUG_RESET_COLOR ""
88#endif //RBT_DEBUG_USE_COLOR
89
90
91
95#define debug_print_prefix_flat \
96 fprintf(\
97 RBT_DEBUG_FD, \
98 "%s%s %s%d %s%s(): %s", \
99 RBT_DEBUG_FILENAME_COLOR, \
100 __FILE__, \
101 RBT_DEBUG_LINENUMBER_COLOR, \
102 __LINE__, \
103 RBT_DEBUG_FUNCTIONNAME_COLOR, \
104 __func__, \
105 RBT_DEBUG_RESET_COLOR \
106 )
107
108
109
115#if RBT_DEBUG_INDENT>0
116#define debug_print_prefix \
117 int i = RBT_NESTING_LEVEL; \
118 while(i--) \
119 { \
120 fprintf(stderr, " "); \
121 } \
122 debug_print_prefix_flat
123#else
124#define debug_print_prefix debug_print_prefix_flat
125#endif //RBT_DEBUG_INDENT>0
126
127
128
138#define debug_printf(fmt, ...) \
139do \
140{ \
141 if (RBT_DEBUG) \
142 { \
143 debug_print_prefix; \
144 fprintf(\
145 RBT_DEBUG_FD, \
146 fmt, \
147 __VA_ARGS__ \
148 ); \
149 } \
150} while (0)
151
152
153
160#define debug_print(msg) \
161do \
162{ \
163 if (RBT_DEBUG) \
164 { \
165 debug_print_prefix; \
166 fprintf(\
167 RBT_DEBUG_FD, \
168 msg \
169 ); \
170 } \
171} while (0)
172
173
174
175
190#define debug_print_func(func, print_newline, ...) \
191do \
192{ \
193 if (RBT_DEBUG) \
194 { \
195 debug_print_prefix; \
196 func(RBT_DEBUG_FD, ##__VA_ARGS__); \
197 if (print_newline) \
198 { \
199 fprintf(RBT_DEBUG_FD, "\n"); \
200 } \
201 } \
202} while (0)
203
204
205
215#define error_printf(fmt, ...) \
216do \
217{ \
218 fprintf( \
219 RBT_DEBUG_FD, \
220 "%s %d %s(): " fmt, \
221 __FILE__, __LINE__, __func__, fmt, __VA_ARGS__ \
222 ); \
223} \
224while (0) \
225
226
227
234#define error_print(msg) \
235do \
236{ \
237 fprintf( \
238 RBT_DEBUG_FD, \
239 "%s %d %s(): %s", \
240 __FILE__, __LINE__, __func__, msg \
241 ); \
242} \
243while (0) \
244
245
246
247#endif // RBT_HEADER_DEBUG
#define RBT_DEBUG_INDENT
Definition: debug.h:34
Contact
echo xyne.archlinux.org | sed 's/\./@/'