/** * cf_debug.h */ #ifndef __CF_DEBUG_H__ #define __CF_DEBUG_H__ #include "cf_base.h" #include #define CF_ERROR_DEBUG_INVALID_CTX CF_ERROR_DEBUG - 1 #define CF_ERROR_DEBUG_SET_OUTPUT_FD CF_ERROR_DEBUG - 2 #define CF_ERROR_DEBUG_PUSH_CALLSTACK CF_ERROR_DEBUG - 3 #define CF_ERROR_DEBUG_POP_CALLSTACK CF_ERROR_DEBUG - 4 #ifdef _WIN32 # define __func__ __FUNCTION__ #endif #ifdef _DEBUG # define CF_DEBUG_CREATE_CTX() \ CF_Debug_CreateCtx () # define CF_DEBUG_DESTROY_CTX(__ctx) \ CF_Debug_DestroyCtx (__ctx) # define CF_UPDATE_CTX(__ctx) \ CF_Debug_UpdateCtx (__ctx,__FILE__,__func__,__LINE__) # define CF_DEBUG_PRINT(__fp,__fmt,...) \ CF_Debug_Print (__fp,__FILE__,__func__,__LINE__,__fmt,##__VA_ARGS__) # define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) \ CF_Debug_PrintBin (__fp,__FILE__,__func__,__LINE__,__bin,__len,__fmt,##__VA_ARGS__) # define CF_DEBUG_TRACE(__ctx,__fmt,...) \ do { \ CF_UPDATE_CTX (__ctx); \ CF_Debug_Trace (__ctx,__fmt,##__VA_ARGS__); \ } while (0) # define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...) \ do { \ CF_UPDATE_CTX (__ctx); \ CF_Debug_TraceBin (__ctx,__bin,__len,__fmt,##__VA_ARGS__); \ } while (0) # define CF_DEBUG_CALLSTACK_PUSH(__ctx) \ CF_Debug_CallStackPush (__ctx,__FILE__,__func__,__LINE__) # define CF_DEBUG_CALLSTACK_POP \ CF_Debug_CallStackPop #else // #ifdef _DEBUG # define CF_DEBUG_CREATE_CTX() NULL # define CF_DEBUG_DESTROY_CTX(__ctx) # define CF_UPDATE_CTX(__ctx) # define CF_DEBUG_PRINT(__fp,__fmt,...) # define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) # define CF_DEBUG_TRACE(__ctx,__fmt,...) # define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...) # define CF_DEBUG_CALLSTACK_PUSH(__ctx) # define CF_DEBUG_CALLSTACK_POP(__ctx,__callstack) 1 #endif // #ifdef _DEBUG typedef void * CF_Debug_Ctx; typedef struct cf_debug_callStack { char file[NAME_LENGTH + 1]; char function[NAME_LENGTH + 1]; int line; } CF_Debug_CallStack; #ifdef __cplusplus extern "C" { #endif CF_EXPORT CF_Debug_Ctx CF_Debug_CreateCtx (void); CF_EXPORT int CF_Debug_DestroyCtx (CF_Debug_Ctx ctx); CF_EXPORT int CF_Debug_SetOutputFD (CF_Debug_Ctx ctx, int fd); CF_EXPORT int CF_Debug_Print (FILE * fp, const char * file, const char * func, const int line, const char * fmt, ...); int CF_Debug_PrintBin (FILE * fp, const char * file, const char * func, const int line, const unsigned char * bin, const int len, const char * fmt, ...); CF_EXPORT int CF_Debug_UpdateCtx (CF_Debug_Ctx ctx, const char * file, const char * func, const int line); CF_EXPORT int CF_Debug_Trace (CF_Debug_Ctx ctx, const char * fmt, ...); CF_EXPORT int CF_Debug_TraceBin (CF_Debug_Ctx ctx, const unsigned char * bin, const int len, const char * fmt, ...); CF_EXPORT int CF_Debug_CallStackPush (CF_Debug_Ctx ctx, const char * file, const char * func, const int line); CF_EXPORT int CF_Debug_CallStackPop (CF_Debug_Ctx ctx, CF_Debug_CallStack * callstack); #ifdef __cplusplus } #endif #endif // #ifndef __CF_DEBUG_H__