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

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

#1 add test code for multi-threading, socket and multi-threaded logging

File size: 2.9 KB
RevLine 
[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
[14]21# define CF_UPDATE_CTX(__ctx) \
22 CF_Debug_UpdateCtx (__ctx,__FILE__,__func__,__LINE__)
[16]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__)
[6]27# define CF_DEBUG_TRACE(__ctx,__fmt,...) \
[14]28 do { \
29 CF_UPDATE_CTX (__ctx); \
30 CF_Debug_Trace (__ctx,__fmt,##__VA_ARGS__); \
31 } while (0)
[6]32# define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...) \
[14]33 do { \
34 CF_UPDATE_CTX (__ctx); \
[21]35 CF_Debug_TraceBin (__ctx,__bin,__len,__fmt,##__VA_ARGS__); \
[14]36 } while (0)
[6]37# define CF_DEBUG_CALLSTACK_PUSH(__ctx) \
[14]38 CF_Debug_CallStackPush (__ctx,__FILE__,__func__,__LINE__)
[6]39# define CF_DEBUG_CALLSTACK_POP \
[14]40 CF_Debug_CallStackPop
[6]41#else // #ifdef _DEBUG
[14]42# define CF_UPDATE_CTX(__ctx)
[6]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
49typedef void * CF_Debug_Ctx;
50typedef struct cf_debug_callStack {
[14]51 char file[NAME_LENGTH + 1];
[6]52 char function[NAME_LENGTH + 1];
53 int line;
54} CF_Debug_CallStack;
55
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60CF_EXPORT CF_Debug_Ctx
61CF_Debug_CreateCtx (void);
62
63CF_EXPORT int
64CF_Debug_DestroyCtx (CF_Debug_Ctx ctx);
65
66CF_EXPORT int
67CF_Debug_SetOutputFD (CF_Debug_Ctx ctx,
68 int fd);
69
70CF_EXPORT int
[16]71CF_Debug_Print (FILE * fp,
72 const char * file,
73 const char * func,
74 const int line,
75 const char * fmt, ...);
76
77int
78CF_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
86CF_EXPORT int
[14]87CF_Debug_UpdateCtx (CF_Debug_Ctx ctx,
88 const char * file,
89 const char * func,
90 const int line);
91
92CF_EXPORT int
[6]93CF_Debug_Trace (CF_Debug_Ctx ctx,
94 const char * fmt, ...);
95
96CF_EXPORT int
97CF_Debug_TraceBin (CF_Debug_Ctx ctx,
98 const unsigned char * bin,
99 const int len,
100 const char * fmt, ...);
101
102CF_EXPORT int
103CF_Debug_CallStackPush (CF_Debug_Ctx ctx,
[9]104 const char * file,
[6]105 const char * func,
106 const int line);
107
108CF_EXPORT int
109CF_Debug_CallStackPop (CF_Debug_Ctx ctx,
110 CF_Debug_CallStack * callstack);
111
[10]112#ifdef __cplusplus
113}
114#endif
115
[6]116#endif // #ifndef __CF_DEBUG_H__
Note: See TracBrowser for help on using the repository browser.