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