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

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

#1 remove unused symbol from doxygen comment

File size: 5.5 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 *
[36]85 * @see CF_Debug_Trace
[26]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 *
[36]99 * @see CF_Debug_TraceBin
[26]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)
127# define CF_DEBUG_PRINT(__fp,__fmt,...)
128# define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...)
[6]129# define CF_DEBUG_TRACE(__ctx,__fmt,...)
130# define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...)
131# define CF_DEBUG_CALLSTACK_PUSH(__ctx)
[25]132# define CF_DEBUG_CALLSTACK_POP(__ctx,__callstack) 1
[6]133#endif // #ifdef _DEBUG
134
[26]135/** 디버그 컨텍스트 */
[6]136typedef void * CF_Debug_Ctx;
[26]137
138/** 콜스택 데이터 */
[6]139typedef struct cf_debug_callStack {
[26]140 char file[NAME_LENGTH + 1]; /**< 파일 이름 */
141 char function[NAME_LENGTH + 1]; /**< 함수 이름 */
142 int line; /**< 라인 넘버 */
[6]143} CF_Debug_CallStack;
144
145#ifdef __cplusplus
146extern "C" {
147#endif
148
149CF_EXPORT CF_Debug_Ctx
150CF_Debug_CreateCtx (void);
151
152CF_EXPORT int
153CF_Debug_DestroyCtx (CF_Debug_Ctx ctx);
154
155CF_EXPORT int
156CF_Debug_SetOutputFD (CF_Debug_Ctx ctx,
157 int fd);
158
159CF_EXPORT int
[16]160CF_Debug_Print (FILE * fp,
161 const char * file,
162 const char * func,
163 const int line,
164 const char * fmt, ...);
165
[26]166CF_EXPORT int
[16]167CF_Debug_PrintBin (FILE * fp,
168 const char * file,
169 const char * func,
170 const int line,
171 const unsigned char * bin,
172 const int len,
173 const char * fmt, ...);
174
175CF_EXPORT int
[6]176CF_Debug_Trace (CF_Debug_Ctx ctx,
[29]177 const char * file,
178 const char * func,
179 const int line,
[6]180 const char * fmt, ...);
181
182CF_EXPORT int
183CF_Debug_TraceBin (CF_Debug_Ctx ctx,
[29]184 const char * file,
185 const char * func,
186 const int line,
[6]187 const unsigned char * bin,
188 const int len,
189 const char * fmt, ...);
190
191CF_EXPORT int
192CF_Debug_CallStackPush (CF_Debug_Ctx ctx,
[9]193 const char * file,
[6]194 const char * func,
195 const int line);
196
197CF_EXPORT int
198CF_Debug_CallStackPop (CF_Debug_Ctx ctx,
199 CF_Debug_CallStack * callstack);
200
[10]201#ifdef __cplusplus
202}
203#endif
204
[6]205#endif // #ifndef __CF_DEBUG_H__
Note: See TracBrowser for help on using the repository browser.