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

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

#1 change the debugging utiltity to support single context with mutex

File size: 2.7 KB
Line 
1/**
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 * (단, 콜스택의 푸시/팝은 컨텍스트를 이용해야만 사용 가능)
13 *
14 * @example debug.c
15 */
16#ifndef __CF_DEBUG_H__
17#define __CF_DEBUG_H__
18
19#include "cf_base.h"
20
21#include <stdio.h>
22
23/** Windows 함수 이름 매크로 재정의 */
24#if defined(_WIN32) || defined(_WIN64)
25# define __func__ __FUNCTION__
26#endif
27
28#ifdef _DEBUG
29
30/**
31 * 디버그 메시지를 지정된 파일 포인터로 출력
32 *
33 * @param __fmt 포맷 스트링
34 * @param ... 가변 인자
35 *
36 * @see CF_Debug_Print
37 */
38# define CF_DEBUG_PRINT(__fp,__fmt,...) \
39 CF_Debug_Print (__fp,__FILE__,__func__,__LINE__,__fmt,##__VA_ARGS__)
40
41/**
42 * 바이너리 데이터를 디버그 메시지와 함께 지정된 파일 포인터로 출력
43 *
44 * @param __bin 바이너리 데이터
45 * @param __len 바이너리 길이
46 * @param __fmt 포맷 스트링
47 * @param ... 가변 인자
48 *
49 * @see CF_Debug_PrintBin
50 */
51# define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) \
52 CF_Debug_PrintBin (__fp,__FILE__,__func__,__LINE__,__bin,__len,__fmt,##__VA_ARGS__)
53
54/**
55 * 함수에 진입
56 *
57 * @see CF_Debug_EnterFunction
58 */
59# define CF_DEBUG_BEGIN_FUNCTION \
60 CF_Debug_EnterFunction (__FILE__,__func__,__LINE__)
61
62/**
63 * 함수에서 종료
64 *
65 * @see CF_Debug_LeaveFunction
66 */
67# define CF_DEBUG_END_FUNCTION \
68 CF_Debug_LeaveFunction ()
69
70#else // #ifdef _DEBUG
71# define CF_DEBUG_PRINT(__fp,__fmt,...)
72# define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...)
73# define CF_DEBUG_BEGIN_FUNCTION
74# define CF_DEBUG_END_FUNCTION
75#endif // #ifdef _DEBUG
76
77#ifdef __cplusplus
78extern "C" {
79#endif
80
81CF_EXPORT int
82CF_Debug_Print (FILE * fp,
83 const char * file,
84 const char * func,
85 const int line,
86 const char * fmt, ...);
87
88CF_EXPORT int
89CF_Debug_PrintBin (FILE * fp,
90 const char * file,
91 const char * func,
92 const int line,
93 const unsigned char * bin,
94 const int len,
95 const char * fmt, ...);
96
97CF_EXPORT int
98CF_Debug_PrintCallStack (FILE * fp);
99
100CF_EXPORT int
101CF_Debug_EnterFunction (const char * file,
102 const char * func,
103 const int line);
104
105CF_EXPORT int
106CF_Debug_LeaveFunction (void);
107
108#ifdef __cplusplus
109}
110#endif
111
112#endif // #ifndef __CF_DEBUG_H__
Note: See TracBrowser for help on using the repository browser.