My Project
Debug.h
Go to the documentation of this file.
1 #ifndef __DEBUG_H__
2 #define __DEBUG_H__
3 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #include <stdio.h>
43 
54 void debugInit(int* argc, const char* argv[]);
55 
59 void debugToFile(const char* fileName);
60 
63 void debugClose(void);
64 
68 extern int debugLevel;
69 
73 extern FILE* debugFile;
74 
75 #ifdef DEBUG
76 #define DEBUG_ENABLED 1 // debug code available at runtime
77 #else
78 
83 #define DEBUG_ENABLED 0 // all debug code optimized out
84 #endif
85 
87 #define HERE debug("HERE")
88 
92 #define debugV(name) #name,(name)
93 
98 #define vDebug(fmt, name) debug("%s=(" fmt ")" , debugV(name))
99 
101 #define debug(fmt, ...) lDebug(1, fmt, ##__VA_ARGS__)
102 
108 #define lDebug(level, fmt, ...) \
109  do { \
110  if (DEBUG_ENABLED && (debugLevel >= level)) \
111  fprintf((debugFile ? debugFile : stderr), "DEBUG %s[%d] %s() " fmt "\n", \
112  __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
113  } while(0)
114 
115 #ifdef __cplusplus
116 }
117 #endif
118 
119 #endif
120 
void debugToFile(const char *fileName)
Definition: Debug.c:54
void debugClose(void)
Definition: Debug.c:63
int debugLevel
Definition: Debug.c:27
void debugInit(int *argc, const char *argv[])
Definition: Debug.c:33
FILE * debugFile
Definition: Debug.c:29