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