1 | /**
|
---|
2 | * @file cf_debug.h
|
---|
3 | * @author myusgun <myusgun@gmail.com>
|
---|
4 | *
|
---|
5 | * @remark
|
---|
6 | * 디버그 함수를 직접 호출하지 않고 정의된 매크로를 사용하면,
|
---|
7 | * Preprocessor에 _DEBUG가 정의되어 있는 경우에 만
|
---|
8 | * 디버그 코드가 동작하도록 할 수 있음 <br />
|
---|
9 | * 디버그 메시지는 stdout 및 stderr 등의 파일 포인터 출력을 지원함
|
---|
10 | *
|
---|
11 | * @example debug.c
|
---|
12 | */
|
---|
13 | #ifndef __CF_DEBUG_H__
|
---|
14 | #define __CF_DEBUG_H__
|
---|
15 |
|
---|
16 | #include "cf_base.h"
|
---|
17 |
|
---|
18 | #include <stdio.h>
|
---|
19 | #include <stddef.h>
|
---|
20 |
|
---|
21 | /** Windows 함수 이름 매크로 재정의 */
|
---|
22 | #if defined(_WIN32) || defined(_WIN64)
|
---|
23 | # define __func__ __FUNCTION__
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | #ifdef _DEBUG
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * 디버그 메시지를 지정된 파일 포인터로 출력
|
---|
30 | *
|
---|
31 | & @param __fp 출력할 파일 포인터
|
---|
32 | * @param __fmt 포맷 스트링
|
---|
33 | * @param ... 가변 인자
|
---|
34 | *
|
---|
35 | * @see CF_Debug_Print
|
---|
36 | */
|
---|
37 | # define CF_DEBUG_PRINT(__fp,__fmt,...) \
|
---|
38 | CF_Debug_Print (__fp,__FILE__,__func__,__LINE__,__fmt,##__VA_ARGS__)
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * 바이너리 데이터를 디버그 메시지와 함께 지정된 파일 포인터로 출력
|
---|
42 | *
|
---|
43 | & @param __fp 출력할 파일 포인터
|
---|
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_Initialize
|
---|
58 | */
|
---|
59 | # define CF_DEBUG_INITIALIZE \
|
---|
60 | CF_Debug_Initialize ()
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * 디버깅 모듈 해제
|
---|
64 | *
|
---|
65 | * @see CF_Debug_Finalize
|
---|
66 | */
|
---|
67 | # define CF_DEBUG_FINALIZE \
|
---|
68 | CF_Debug_Finalize ()
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * 함수에 진입
|
---|
72 | *
|
---|
73 | * @see CF_Debug_EnterFunction
|
---|
74 | */
|
---|
75 | # define CF_DEBUG_BEGIN_FUNCTION \
|
---|
76 | CF_Debug_EnterFunction (__FILE__,__func__,__LINE__)
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * 함수에서 리턴
|
---|
80 | *
|
---|
81 | * @see CF_Debug_LeaveFunction
|
---|
82 | */
|
---|
83 | # define CF_DEBUG_END_FUNCTION \
|
---|
84 | CF_Debug_LeaveFunction ()
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * 콜스택 을 지정된 파일 포인터로 출력
|
---|
88 | *
|
---|
89 | * @see CF_Debug_PrintCallStack
|
---|
90 | */
|
---|
91 | # define CF_DEBUG_PRINT_CALLSTACK(__fp) \
|
---|
92 | CF_Debug_PrintCallStack (__fp)
|
---|
93 |
|
---|
94 | #else // #ifdef _DEBUG
|
---|
95 | # define CF_DEBUG_PRINT(__fp,__fmt,...)
|
---|
96 | # define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...)
|
---|
97 | # define CF_DEBUG_INITIALIZE
|
---|
98 | # define CF_DEBUG_FINALIZE
|
---|
99 | # define CF_DEBUG_BEGIN_FUNCTION
|
---|
100 | # define CF_DEBUG_END_FUNCTION
|
---|
101 | # define CF_DEBUG_PRINT_CALLSTACK(__fp)
|
---|
102 | #endif // #ifdef _DEBUG
|
---|
103 |
|
---|
104 | #ifdef __cplusplus
|
---|
105 | extern "C" {
|
---|
106 | #endif
|
---|
107 |
|
---|
108 | CF_EXPORT int
|
---|
109 | CF_Debug_Print (FILE * fp,
|
---|
110 | const char * file,
|
---|
111 | const char * func,
|
---|
112 | const int line,
|
---|
113 | const char * fmt, ...);
|
---|
114 |
|
---|
115 | CF_EXPORT int
|
---|
116 | CF_Debug_PrintBin (FILE * fp,
|
---|
117 | const char * file,
|
---|
118 | const char * func,
|
---|
119 | const int line,
|
---|
120 | const unsigned char * bin,
|
---|
121 | const size_t len,
|
---|
122 | const char * fmt, ...);
|
---|
123 |
|
---|
124 | CF_EXPORT int
|
---|
125 | CF_Debug_Initialize (void);
|
---|
126 |
|
---|
127 | CF_EXPORT int
|
---|
128 | CF_Debug_Finalize (void);
|
---|
129 |
|
---|
130 | CF_EXPORT int
|
---|
131 | CF_Debug_PrintCallStack (FILE * fp);
|
---|
132 |
|
---|
133 | CF_EXPORT int
|
---|
134 | CF_Debug_EnterFunction (const char * file,
|
---|
135 | const char * func,
|
---|
136 | const int line);
|
---|
137 |
|
---|
138 | CF_EXPORT int
|
---|
139 | CF_Debug_LeaveFunction (void);
|
---|
140 |
|
---|
141 | #ifdef __cplusplus
|
---|
142 | }
|
---|
143 | #endif
|
---|
144 |
|
---|
145 | #endif // #ifndef __CF_DEBUG_H__
|
---|