1 | /**
|
---|
2 | * cf_debug.h
|
---|
3 | */
|
---|
4 | #ifndef __CF_DEBUG_H__
|
---|
5 | #define __CF_DEBUG_H__
|
---|
6 |
|
---|
7 | #include "cf_base.h"
|
---|
8 |
|
---|
9 | #define CF_ERROR_DEBUG_INVALID_CTX CF_ERROR_DEBUG - 1
|
---|
10 | #define CF_ERROR_DEBUG_SET_OUTPUT_FD CF_ERROR_DEBUG - 2
|
---|
11 | #define CF_ERROR_DEBUG_PUSH_CALLSTACK CF_ERROR_DEBUG - 3
|
---|
12 | #define CF_ERROR_DEBUG_POP_CALLSTACK CF_ERROR_DEBUG - 4
|
---|
13 |
|
---|
14 | #ifdef _WIN32
|
---|
15 | # define __func__ __FUNCTION__
|
---|
16 | #endif
|
---|
17 |
|
---|
18 | #ifdef _DEBUG
|
---|
19 | # define CF_DEBUG_TRACE(__ctx,__fmt,...) \
|
---|
20 | CF_Debug_Trace (__ctx,__fmt,##__VA_ARGS__)
|
---|
21 | # define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...) \
|
---|
22 | CF_Debug_Trace (__ctx,__bin,__len,__fmt,##__VA_ARGS__)
|
---|
23 | # define CF_DEBUG_CALLSTACK_PUSH(__ctx) \
|
---|
24 | CF_Debug_CallstackPush (__ctx,__FILE__,__func__,__LINE__)
|
---|
25 | # define CF_DEBUG_CALLSTACK_POP \
|
---|
26 | CF_Debug_CallstackPop
|
---|
27 | #else // #ifdef _DEBUG
|
---|
28 | # define CF_DEBUG_TRACE(__ctx,__fmt,...)
|
---|
29 | # define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...)
|
---|
30 | # define CF_DEBUG_CALLSTACK_PUSH(__ctx)
|
---|
31 | # define CF_DEBUG_CALLSTACK_POP()
|
---|
32 | #endif // #ifdef _DEBUG
|
---|
33 |
|
---|
34 | typedef void * CF_Debug_Ctx;
|
---|
35 | typedef struct cf_debug_callStack {
|
---|
36 | char function[NAME_LENGTH + 1];
|
---|
37 | int line;
|
---|
38 | } CF_Debug_CallStack;
|
---|
39 |
|
---|
40 | #ifdef __cplusplus
|
---|
41 | extern "C" {
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | CF_EXPORT CF_Debug_Ctx
|
---|
45 | CF_Debug_CreateCtx (void);
|
---|
46 |
|
---|
47 | CF_EXPORT int
|
---|
48 | CF_Debug_DestroyCtx (CF_Debug_Ctx ctx);
|
---|
49 |
|
---|
50 | CF_EXPORT int
|
---|
51 | CF_Debug_SetOutputFD (CF_Debug_Ctx ctx,
|
---|
52 | int fd);
|
---|
53 |
|
---|
54 | CF_EXPORT int
|
---|
55 | CF_Debug_Trace (CF_Debug_Ctx ctx,
|
---|
56 | const char * fmt, ...);
|
---|
57 |
|
---|
58 | CF_EXPORT int
|
---|
59 | CF_Debug_TraceBin (CF_Debug_Ctx ctx,
|
---|
60 | const unsigned char * bin,
|
---|
61 | const int len,
|
---|
62 | const char * fmt, ...);
|
---|
63 |
|
---|
64 | CF_EXPORT int
|
---|
65 | CF_Debug_CallStackPush (CF_Debug_Ctx ctx,
|
---|
66 | const char * file,
|
---|
67 | const char * func,
|
---|
68 | const int line);
|
---|
69 |
|
---|
70 | CF_EXPORT int
|
---|
71 | CF_Debug_CallStackPop (CF_Debug_Ctx ctx,
|
---|
72 | CF_Debug_CallStack * callstack);
|
---|
73 |
|
---|
74 | #ifdef __cplusplus
|
---|
75 | }
|
---|
76 | #endif
|
---|
77 |
|
---|
78 | #endif // #ifndef __CF_DEBUG_H__
|
---|