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

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

#1 separate example code and doxygen comment and fix logging push logic by vfire

File size: 5.6 KB
RevLine 
[6]1/**
[26]2 * @file cf_debug.h
3 * @author myusgun <myusgun@gmail.com>
4 * @version 0.1
5 *
6 * @remark
7 * 디버그 함수를 직접 호출하지 않고 정의된 매크로를 사용하면,
8 * Preprocessor에 _DEBUG가 정의되어 있는 경우에 만
9 * 디버그 코드가 동작하도록 할 수 있음 <br />
10 * 디버그 메시지는 stdout 및 stderr를 이용한 파일 포인터 출력을 지원하고,
11 * 환경에 적합하도록 사용자가 구성한 컨텍스트를 이용하여 사용할 수도 있음 <br />
12 * (단, 콜스택의 푸시/팝은 컨텍스트를 이용해야만 사용 가능)
[34]13 *
[35]14 * @example debug.c
[6]15 */
16#ifndef __CF_DEBUG_H__
17#define __CF_DEBUG_H__
18
19#include "cf_base.h"
20
[16]21#include <stdio.h>
22
[6]23#define CF_ERROR_DEBUG_INVALID_CTX CF_ERROR_DEBUG - 1
24#define CF_ERROR_DEBUG_SET_OUTPUT_FD CF_ERROR_DEBUG - 2
[9]25#define CF_ERROR_DEBUG_PUSH_CALLSTACK CF_ERROR_DEBUG - 3
26#define CF_ERROR_DEBUG_POP_CALLSTACK CF_ERROR_DEBUG - 4
[6]27
[26]28/** Windows 함수 이름 매크로 재정의 */
[6]29#ifdef _WIN32
30# define __func__ __FUNCTION__
31#endif
32
33#ifdef _DEBUG
[26]34/**
35 * 디버그 컨텍스트 생성
36 *
37 * @see CF_Debug_CreateCtx
38 */
[25]39# define CF_DEBUG_CREATE_CTX() \
40 CF_Debug_CreateCtx ()
41
[26]42/**
43 * 디버그 컨텍스트 해제
44 *
45 * @param __ctx 디버그 컨텍스트
46 *
47 * @see CF_Debug_DestroyCtx
48 */
[25]49# define CF_DEBUG_DESTROY_CTX(__ctx) \
50 CF_Debug_DestroyCtx (__ctx)
51
[26]52/**
53 * 디버그 메시지를 지정된 파일 포인터로 출력
54 *
55 * @param __fp 파일 포인터. 표준출력(stdout) 및 표준오류(stderr) 사용 가능
56 * @param __fmt 포맷 스트링
57 * @param ... 가변 인자
58 *
59 * @see CF_Debug_Print
60 */
[16]61# define CF_DEBUG_PRINT(__fp,__fmt,...) \
62 CF_Debug_Print (__fp,__FILE__,__func__,__LINE__,__fmt,##__VA_ARGS__)
[25]63
[26]64/**
65 * 바이너리 데이터를 디버그 메시지와 함께 지정된 파일 포인터로 출력
66 *
67 * @param __fp 파일 포인터. 표준출력(stdout) 및 표준오류(stderr) 사용 가능
68 * @param __bin 바이너리 데이터
69 * @param __len 바이너리 길이
70 * @param __fmt 포맷 스트링
71 * @param ... 가변 인자
72 *
73 * @see CF_Debug_PrintBin
74 */
[16]75# define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) \
76 CF_Debug_PrintBin (__fp,__FILE__,__func__,__LINE__,__bin,__len,__fmt,##__VA_ARGS__)
[25]77
[26]78/**
79 * 컨텍스트를 업데이트하고 디버그 메시지를 출력
80 *
81 * @param __ctx 디버그 컨텍스트
82 * @param __fmt 포맷 스트링
83 * @param ... 가변 인자
84 *
85 * @see CF_DEBUG_UPDATE_CTX, CF_Debug_Trace
86 */
[6]87# define CF_DEBUG_TRACE(__ctx,__fmt,...) \
[26]88 CF_Debug_Trace (__ctx,__FILE__,__func__,__LINE__,__fmt,##__VA_ARGS__)
[25]89
[26]90/**
91 * 컨텍스트를 업데이트하고 바이너리 데이터를 디버그 메시지와 함께 출력
92 *
93 * @param __ctx 디버그 컨텍스트
94 * @param __bin 바이너리 데이터
95 * @param __len 바이너리 길이
96 * @param __fmt 포맷 스트링
97 * @param ... 가변 인자
98 *
99 * @see CF_DEBUG_UPDATE_CTX, CF_Debug_TraceBin
100 */
[6]101# define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...) \
[26]102 CF_Debug_TraceBin (__ctx,__FILE__,__func__,__LINE__,__bin,__len,__fmt,##__VA_ARGS__)
[25]103
[26]104/**
105 * 컨텍스트에 콜스택 푸시
106 *
107 * @param __ctx 디버그 컨텍스트
108 *
109 * @see CF_Debug_CallStackPush
110 */
[6]111# define CF_DEBUG_CALLSTACK_PUSH(__ctx) \
[14]112 CF_Debug_CallStackPush (__ctx,__FILE__,__func__,__LINE__)
[25]113
[26]114/**
115 * 컨텍스트에서 콜스택 팝
116 *
117 * @param __ctx 디버그 컨텍스트
118 * @param __callstack 콜스택 정보를 가져올 콜스택 데이터 구조체 포인터
119 *
120 * @see CF_Debug_CallStackPop, CF_Debug_CallStack
121 */
122# define CF_DEBUG_CALLSTACK_POP(__ctx,__callstack) \
123 CF_Debug_CallStackPop (__ctx,__callstack)
[6]124#else // #ifdef _DEBUG
[25]125# define CF_DEBUG_CREATE_CTX() NULL
126# define CF_DEBUG_DESTROY_CTX(__ctx)
[26]127# define CF_DEBUG_UPDATE_CTX(__ctx)
[25]128# define CF_DEBUG_PRINT(__fp,__fmt,...)
129# define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...)
[6]130# define CF_DEBUG_TRACE(__ctx,__fmt,...)
131# define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...)
132# define CF_DEBUG_CALLSTACK_PUSH(__ctx)
[25]133# define CF_DEBUG_CALLSTACK_POP(__ctx,__callstack) 1
[6]134#endif // #ifdef _DEBUG
135
[26]136/** 디버그 컨텍스트 */
[6]137typedef void * CF_Debug_Ctx;
[26]138
139/** 콜스택 데이터 */
[6]140typedef struct cf_debug_callStack {
[26]141 char file[NAME_LENGTH + 1]; /**< 파일 이름 */
142 char function[NAME_LENGTH + 1]; /**< 함수 이름 */
143 int line; /**< 라인 넘버 */
[6]144} CF_Debug_CallStack;
145
146#ifdef __cplusplus
147extern "C" {
148#endif
149
150CF_EXPORT CF_Debug_Ctx
151CF_Debug_CreateCtx (void);
152
153CF_EXPORT int
154CF_Debug_DestroyCtx (CF_Debug_Ctx ctx);
155
156CF_EXPORT int
157CF_Debug_SetOutputFD (CF_Debug_Ctx ctx,
158 int fd);
159
160CF_EXPORT int
[16]161CF_Debug_Print (FILE * fp,
162 const char * file,
163 const char * func,
164 const int line,
165 const char * fmt, ...);
166
[26]167CF_EXPORT int
[16]168CF_Debug_PrintBin (FILE * fp,
169 const char * file,
170 const char * func,
171 const int line,
172 const unsigned char * bin,
173 const int len,
174 const char * fmt, ...);
175
176CF_EXPORT int
[6]177CF_Debug_Trace (CF_Debug_Ctx ctx,
[29]178 const char * file,
179 const char * func,
180 const int line,
[6]181 const char * fmt, ...);
182
183CF_EXPORT int
184CF_Debug_TraceBin (CF_Debug_Ctx ctx,
[29]185 const char * file,
186 const char * func,
187 const int line,
[6]188 const unsigned char * bin,
189 const int len,
190 const char * fmt, ...);
191
192CF_EXPORT int
193CF_Debug_CallStackPush (CF_Debug_Ctx ctx,
[9]194 const char * file,
[6]195 const char * func,
196 const int line);
197
198CF_EXPORT int
199CF_Debug_CallStackPop (CF_Debug_Ctx ctx,
200 CF_Debug_CallStack * callstack);
201
[10]202#ifdef __cplusplus
203}
204#endif
205
[6]206#endif // #ifndef __CF_DEBUG_H__
Note: See TracBrowser for help on using the repository browser.