source: libcf/trunk/include/cf_debug.h@ 25

Last change on this file since 25 was 25, checked in by cheese, 11 years ago

#1 fix logging bug and debugging macros

File size: 3.2 KB
Line 
1/**
2 * cf_debug.h
3 */
4#ifndef __CF_DEBUG_H__
5#define __CF_DEBUG_H__
6
7#include "cf_base.h"
8
9#include <stdio.h>
10
11#define CF_ERROR_DEBUG_INVALID_CTX CF_ERROR_DEBUG - 1
12#define CF_ERROR_DEBUG_SET_OUTPUT_FD CF_ERROR_DEBUG - 2
13#define CF_ERROR_DEBUG_PUSH_CALLSTACK CF_ERROR_DEBUG - 3
14#define CF_ERROR_DEBUG_POP_CALLSTACK CF_ERROR_DEBUG - 4
15
16#ifdef _WIN32
17# define __func__ __FUNCTION__
18#endif
19
20#ifdef _DEBUG
21# define CF_DEBUG_CREATE_CTX() \
22 CF_Debug_CreateCtx ()
23
24# define CF_DEBUG_DESTROY_CTX(__ctx) \
25 CF_Debug_DestroyCtx (__ctx)
26
27# define CF_UPDATE_CTX(__ctx) \
28 CF_Debug_UpdateCtx (__ctx,__FILE__,__func__,__LINE__)
29
30# define CF_DEBUG_PRINT(__fp,__fmt,...) \
31 CF_Debug_Print (__fp,__FILE__,__func__,__LINE__,__fmt,##__VA_ARGS__)
32
33# define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) \
34 CF_Debug_PrintBin (__fp,__FILE__,__func__,__LINE__,__bin,__len,__fmt,##__VA_ARGS__)
35
36# define CF_DEBUG_TRACE(__ctx,__fmt,...) \
37 do { \
38 CF_UPDATE_CTX (__ctx); \
39 CF_Debug_Trace (__ctx,__fmt,##__VA_ARGS__); \
40 } while (0)
41
42# define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...) \
43 do { \
44 CF_UPDATE_CTX (__ctx); \
45 CF_Debug_TraceBin (__ctx,__bin,__len,__fmt,##__VA_ARGS__); \
46 } while (0)
47
48# define CF_DEBUG_CALLSTACK_PUSH(__ctx) \
49 CF_Debug_CallStackPush (__ctx,__FILE__,__func__,__LINE__)
50
51# define CF_DEBUG_CALLSTACK_POP \
52 CF_Debug_CallStackPop
53#else // #ifdef _DEBUG
54# define CF_DEBUG_CREATE_CTX() NULL
55# define CF_DEBUG_DESTROY_CTX(__ctx)
56# define CF_UPDATE_CTX(__ctx)
57# define CF_DEBUG_PRINT(__fp,__fmt,...)
58# define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...)
59# define CF_DEBUG_TRACE(__ctx,__fmt,...)
60# define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...)
61# define CF_DEBUG_CALLSTACK_PUSH(__ctx)
62# define CF_DEBUG_CALLSTACK_POP(__ctx,__callstack) 1
63#endif // #ifdef _DEBUG
64
65typedef void * CF_Debug_Ctx;
66typedef struct cf_debug_callStack {
67 char file[NAME_LENGTH + 1];
68 char function[NAME_LENGTH + 1];
69 int line;
70} CF_Debug_CallStack;
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76CF_EXPORT CF_Debug_Ctx
77CF_Debug_CreateCtx (void);
78
79CF_EXPORT int
80CF_Debug_DestroyCtx (CF_Debug_Ctx ctx);
81
82CF_EXPORT int
83CF_Debug_SetOutputFD (CF_Debug_Ctx ctx,
84 int fd);
85
86CF_EXPORT int
87CF_Debug_Print (FILE * fp,
88 const char * file,
89 const char * func,
90 const int line,
91 const char * fmt, ...);
92
93int
94CF_Debug_PrintBin (FILE * fp,
95 const char * file,
96 const char * func,
97 const int line,
98 const unsigned char * bin,
99 const int len,
100 const char * fmt, ...);
101
102CF_EXPORT int
103CF_Debug_UpdateCtx (CF_Debug_Ctx ctx,
104 const char * file,
105 const char * func,
106 const int line);
107
108CF_EXPORT int
109CF_Debug_Trace (CF_Debug_Ctx ctx,
110 const char * fmt, ...);
111
112CF_EXPORT int
113CF_Debug_TraceBin (CF_Debug_Ctx ctx,
114 const unsigned char * bin,
115 const int len,
116 const char * fmt, ...);
117
118CF_EXPORT int
119CF_Debug_CallStackPush (CF_Debug_Ctx ctx,
120 const char * file,
121 const char * func,
122 const int line);
123
124CF_EXPORT int
125CF_Debug_CallStackPop (CF_Debug_Ctx ctx,
126 CF_Debug_CallStack * callstack);
127
128#ifdef __cplusplus
129}
130#endif
131
132#endif // #ifndef __CF_DEBUG_H__
Note: See TracBrowser for help on using the repository browser.