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

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

#1 add more omitted code and enhance stability

File size: 1.8 KB
Line 
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#define NAME_LENGTH 128
35
36typedef void * CF_Debug_Ctx;
37typedef struct cf_debug_callStack {
38 char function[NAME_LENGTH + 1];
39 int line;
40} CF_Debug_CallStack;
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46CF_EXPORT CF_Debug_Ctx
47CF_Debug_CreateCtx (void);
48
49CF_EXPORT int
50CF_Debug_DestroyCtx (CF_Debug_Ctx ctx);
51
52CF_EXPORT int
53CF_Debug_SetOutputFD (CF_Debug_Ctx ctx,
54 int fd);
55
56CF_EXPORT int
57CF_Debug_Trace (CF_Debug_Ctx ctx,
58 const char * fmt, ...);
59
60CF_EXPORT int
61CF_Debug_TraceBin (CF_Debug_Ctx ctx,
62 const unsigned char * bin,
63 const int len,
64 const char * fmt, ...);
65
66CF_EXPORT int
67CF_Debug_CallStackPush (CF_Debug_Ctx ctx,
68 const char * file,
69 const char * func,
70 const int line);
71
72CF_EXPORT int
73CF_Debug_CallStackPop (CF_Debug_Ctx ctx,
74 CF_Debug_CallStack * callstack);
75
76#endif // #ifndef __CF_DEBUG_H__
Note: See TracBrowser for help on using the repository browser.