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

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

#1 arrange some code and change windows project name from lower case to upper case

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