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_UPDATE_CTX(__ctx) \
|
---|
22 | CF_Debug_UpdateCtx (__ctx,__FILE__,__func__,__LINE__)
|
---|
23 | # define CF_DEBUG_PRINT(__fp,__fmt,...) \
|
---|
24 | CF_Debug_Print (__fp,__FILE__,__func__,__LINE__,__fmt,##__VA_ARGS__)
|
---|
25 | # define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) \
|
---|
26 | CF_Debug_PrintBin (__fp,__FILE__,__func__,__LINE__,__bin,__len,__fmt,##__VA_ARGS__)
|
---|
27 | # define CF_DEBUG_TRACE(__ctx,__fmt,...) \
|
---|
28 | do { \
|
---|
29 | CF_UPDATE_CTX (__ctx); \
|
---|
30 | CF_Debug_Trace (__ctx,__fmt,##__VA_ARGS__); \
|
---|
31 | } while (0)
|
---|
32 | # define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...) \
|
---|
33 | do { \
|
---|
34 | CF_UPDATE_CTX (__ctx); \
|
---|
35 | CF_Debug_TraceBin (__ctx,__bin,__len,__fmt,##__VA_ARGS__); \
|
---|
36 | } while (0)
|
---|
37 | # define CF_DEBUG_CALLSTACK_PUSH(__ctx) \
|
---|
38 | CF_Debug_CallStackPush (__ctx,__FILE__,__func__,__LINE__)
|
---|
39 | # define CF_DEBUG_CALLSTACK_POP \
|
---|
40 | CF_Debug_CallStackPop
|
---|
41 | #else // #ifdef _DEBUG
|
---|
42 | # define CF_UPDATE_CTX(__ctx)
|
---|
43 | # define CF_DEBUG_TRACE(__ctx,__fmt,...)
|
---|
44 | # define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...)
|
---|
45 | # define CF_DEBUG_CALLSTACK_PUSH(__ctx)
|
---|
46 | # define CF_DEBUG_CALLSTACK_POP()
|
---|
47 | #endif // #ifdef _DEBUG
|
---|
48 |
|
---|
49 | typedef void * CF_Debug_Ctx;
|
---|
50 | typedef struct cf_debug_callStack {
|
---|
51 | char file[NAME_LENGTH + 1];
|
---|
52 | char function[NAME_LENGTH + 1];
|
---|
53 | int line;
|
---|
54 | } CF_Debug_CallStack;
|
---|
55 |
|
---|
56 | #ifdef __cplusplus
|
---|
57 | extern "C" {
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | CF_EXPORT CF_Debug_Ctx
|
---|
61 | CF_Debug_CreateCtx (void);
|
---|
62 |
|
---|
63 | CF_EXPORT int
|
---|
64 | CF_Debug_DestroyCtx (CF_Debug_Ctx ctx);
|
---|
65 |
|
---|
66 | CF_EXPORT int
|
---|
67 | CF_Debug_SetOutputFD (CF_Debug_Ctx ctx,
|
---|
68 | int fd);
|
---|
69 |
|
---|
70 | CF_EXPORT int
|
---|
71 | CF_Debug_Print (FILE * fp,
|
---|
72 | const char * file,
|
---|
73 | const char * func,
|
---|
74 | const int line,
|
---|
75 | const char * fmt, ...);
|
---|
76 |
|
---|
77 | int
|
---|
78 | CF_Debug_PrintBin (FILE * fp,
|
---|
79 | const char * file,
|
---|
80 | const char * func,
|
---|
81 | const int line,
|
---|
82 | const unsigned char * bin,
|
---|
83 | const int len,
|
---|
84 | const char * fmt, ...);
|
---|
85 |
|
---|
86 | CF_EXPORT int
|
---|
87 | CF_Debug_UpdateCtx (CF_Debug_Ctx ctx,
|
---|
88 | const char * file,
|
---|
89 | const char * func,
|
---|
90 | const int line);
|
---|
91 |
|
---|
92 | CF_EXPORT int
|
---|
93 | CF_Debug_Trace (CF_Debug_Ctx ctx,
|
---|
94 | const char * fmt, ...);
|
---|
95 |
|
---|
96 | CF_EXPORT int
|
---|
97 | CF_Debug_TraceBin (CF_Debug_Ctx ctx,
|
---|
98 | const unsigned char * bin,
|
---|
99 | const int len,
|
---|
100 | const char * fmt, ...);
|
---|
101 |
|
---|
102 | CF_EXPORT int
|
---|
103 | CF_Debug_CallStackPush (CF_Debug_Ctx ctx,
|
---|
104 | const char * file,
|
---|
105 | const char * func,
|
---|
106 | const int line);
|
---|
107 |
|
---|
108 | CF_EXPORT int
|
---|
109 | CF_Debug_CallStackPop (CF_Debug_Ctx ctx,
|
---|
110 | CF_Debug_CallStack * callstack);
|
---|
111 |
|
---|
112 | #ifdef __cplusplus
|
---|
113 | }
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | #endif // #ifndef __CF_DEBUG_H__
|
---|