comparison src/define.h @ 350:7a91e30826d8 stable-0-6-65

Hans Liss - debug level output
author Carl Byington <carl@five-ten-sg.com>
date Fri, 11 Sep 2015 10:18:03 -0700
parents cc8ee701f190
children 506e266f930d
comparison
equal deleted inserted replaced
349:a57c15b3108a 350:7a91e30826d8
133 #endif 133 #endif
134 134
135 135
136 void pst_debug_lock(); 136 void pst_debug_lock();
137 void pst_debug_unlock(); 137 void pst_debug_unlock();
138 void pst_debug_setlevel(int level);
138 void pst_debug_init(const char* fname, void* output_mutex); 139 void pst_debug_init(const char* fname, void* output_mutex);
139 void pst_debug_func(const char* function); 140 void pst_debug_func(int level, const char* function);
140 void pst_debug_func_ret(); 141 void pst_debug_func_ret(int level);
141 void pst_debug(int line, const char *file, const char *fmt, ...); 142 void pst_debug(int level, int line, const char *file, const char *fmt, ...);
142 void pst_debug_hexdump(int line, const char *file, const char* buf, size_t size, int cols, int delta); 143 void pst_debug_hexdump(int level, int line, const char *file, const char* buf, size_t size, int cols, int delta);
143 void pst_debug_hexdumper(FILE* out, const char* buf, size_t size, int cols, int delta); 144 void pst_debug_hexdumper(FILE* out, const char* buf, size_t size, int cols, int delta);
144 void pst_debug_close(void); 145 void pst_debug_close();
145 void* pst_malloc(size_t size); 146 void* pst_malloc(size_t size);
146 void *pst_realloc(void *ptr, size_t size); 147 void *pst_realloc(void *ptr, size_t size);
147 148
148 #define MESSAGEPRINT(...) pst_debug(__LINE__, __FILE__, __VA_ARGS__) 149 #define MESSAGEPRINT1(...) pst_debug(1, __LINE__, __FILE__, __VA_ARGS__)
150 #define MESSAGEPRINT2(...) pst_debug(2, __LINE__, __FILE__, __VA_ARGS__)
151 #define MESSAGEPRINT3(...) pst_debug(3, __LINE__, __FILE__, __VA_ARGS__)
149 152
150 #define WARN(x) { \ 153 #define WARN(x) { \
151 MESSAGEPRINT x; \ 154 MESSAGEPRINT3 x; \
152 pst_debug_lock(); \ 155 pst_debug_lock(); \
153 printf x; \ 156 printf x; \
154 fflush(stdout); \ 157 fflush(stdout); \
155 pst_debug_unlock(); \ 158 pst_debug_unlock(); \
156 } 159 }
158 #define DIE(x) { \ 161 #define DIE(x) { \
159 WARN(x); \ 162 WARN(x); \
160 exit(EXIT_FAILURE); \ 163 exit(EXIT_FAILURE); \
161 } 164 }
162 165
163 #define DEBUG_WARN(x) MESSAGEPRINT x 166 #define DEBUG_WARN(x) MESSAGEPRINT3 x
164 #define DEBUG_INFO(x) MESSAGEPRINT x 167 #define DEBUG_INFO(x) MESSAGEPRINT2 x
165 #define DEBUG_HEXDUMP(x, s) pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, 0x10, 0) 168 #define DEBUG_HEXDUMP(x, s) pst_debug_hexdump(1, __LINE__, __FILE__, (char*)x, s, 0x10, 0)
166 #define DEBUG_HEXDUMPC(x, s, c) pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, c, 0) 169 #define DEBUG_HEXDUMPC(x, s, c) pst_debug_hexdump(1, __LINE__, __FILE__, (char*)x, s, c, 0)
167 170
168 171
169 #define DEBUG_ENT(x) \ 172 #define DEBUG_ENT(x) \
170 { \ 173 { \
171 pst_debug_func(x); \ 174 pst_debug_func(1, x); \
172 pst_debug(__LINE__, __FILE__, "Entering function\n"); \ 175 pst_debug(1, __LINE__, __FILE__, "Entering function\n"); \
173 } 176 }
174 #define DEBUG_RET() \ 177 #define DEBUG_RET() \
175 { \ 178 { \
176 pst_debug(__LINE__, __FILE__, "Leaving function\n"); \ 179 pst_debug(1, __LINE__, __FILE__, "Leaving function\n"); \
177 pst_debug_func_ret(); \ 180 pst_debug_func_ret(1); \
178 } 181 }
179 182
180 #define DEBUG_INIT(fname,mutex) {pst_debug_init(fname,mutex);} 183 #define DEBUG_INIT(fname,mutex) {pst_debug_init(fname,mutex);}
181 #define DEBUG_CLOSE() {pst_debug_close();} 184 #define DEBUG_CLOSE() {pst_debug_close();}
182 #define RET_DERROR(res, ret_val, x) if (res) { DIE(x);} 185 #define RET_DERROR(res, ret_val, x) if (res) { DIE(x);}