OROCHI
 
Loading...
Searching...
No Matches
GxP2PDebug.h
Go to the documentation of this file.
1//===========================================================================
10//===========================================================================
11// note:
12// デバッグOFF(!GX_DEVELOP)の場合に、全てのインスタンス・関数実体を
13// 消去する必要があるので、アクセスは全て提供マクロ群から行ってください。
14//===========================================================================
15#pragma once
16
17/* GxP2PCommon.h内にincludeされる前提 */
18
19#if GX_DEVELOP
20
21GX_P2P_NAMESPACE_BEGIN()
22
23//===========================================================================
25//===========================================================================
26class GxP2PDebug
27{
28 //-----------------------------------------------------------
30 //-----------------------------------------------------------
32public:
34 enum class PRINT_LV
35 {
36 _0 = 0,
37 _1,
38 _2,
39 _3,
40 _4,
41 _5
42 };
43
45 //-----------------------------------------------------------
47 //-----------------------------------------------------------
49private:
51 GxP2PDebug(void) : _printLV(PRINT_LV::_3){}
53 ~GxP2PDebug(void){}
54
56 //-----------------------------------------------------------
58 //-----------------------------------------------------------
60public:
62 static GxP2PDebug* getInstance(void)
63 {
64 static GxP2PDebug _instance;
65 return &_instance;
66 };
68 constexpr void setPrintLV(GxP2PDebug::PRINT_LV printLV){ _printLV = printLV; }
70 constexpr GxP2PDebug::PRINT_LV getPrintLV(void) const { return _printLV; }
71
73 //-----------------------------------------------------------
75 //-----------------------------------------------------------
77public:
79 inline void trace(PRINT_LV printLV, GX_CSTR function, ...);
81 inline void breakStop(GX_CSTR check, ...);
83 inline void breakStop(void);
84
85private:
87 inline void print(GX_CSTR buffer);
88
90 //-----------------------------------------------------------
92 //-----------------------------------------------------------
94private:
95 PRINT_LV _printLV;
96
98};
99
100//---------------------------------------------------------------------------
101// フォーマット文字列作成マクロ
105//---------------------------------------------------------------------------
106#ifndef GET_FORMAT_STRING
107#if defined(__GOT_SECURE_LIB__) && __GOT_SECURE_LIB__ >= 200402L
108#define GET_FORMAT_STRING(dst, len, start) \
109{ \
110 va_list va; \
111 va_start(va, start); \
112 GX_STR __format = va_arg(va, GX_STR); \
113 _vsnprintf_s(dst, len, _TRUNCATE, __format, va); \
114 va_end(va); \
115}
116#else // __GOT_SECURE_LIB__ && __GOT_SECURE_LIB__ >= 200402L
117#define GET_FORMAT_STRING(dst, len, start) \
118{ \
119 va_list va; \
120 va_start(va, start); \
121 GX_STR __format = va_arg(va, GX_STR); \
122 vsnprintf(dst, len, __format, va); \
123 va_end(va); \
124}
125#endif // !(__GOT_SECURE_LIB__ && __GOT_SECURE_LIB__ >= 200402L)
126#endif // !GET_FORMAT_STRING
127
128//---------------------------------------------------------------------------
129// トレース
133//---------------------------------------------------------------------------
134inline void GxP2PDebug::trace(PRINT_LV printLV, GX_CSTR function, ...)
135{
136 GX_CHAR buffer[GxMath::VALUE_256];
137
138 // 出力LVチェック
139 if (printLV <= _printLV)
140 {
141 // 関数名出力
142 GX_MEMSET(buffer, 0, sizeof(buffer));
143#if defined(_PS4)
144 sprintf(buffer, "<%s> ", function);
145#elif defined(WIN32)
146 sprintf_s(buffer, "<%s> ", function);
147#endif // WIN32
148 GxP2PDebug::print(buffer);
149
150 // フォーマット文字列出力
151 GX_MEMSET(buffer, 0, sizeof(buffer));
152 GET_FORMAT_STRING(buffer, sizeof(buffer), function);
153 GxP2PDebug::print(buffer);
154 }
155}
156
157//---------------------------------------------------------------------------
158// ブレーク (アサート出力後)
161//---------------------------------------------------------------------------
162inline void GxP2PDebug::breakStop(GX_CSTR check, ...)
163{
164 // 出力文字列作成
165 GX_CHAR buffer[GxMath::VALUE_256];
166
167 GET_FORMAT_STRING(buffer, sizeof(buffer), check);
168
169 // 文字列出力
170 trace(PRINT_LV::_1, __FUNCTION__, "Assert failed!! %s(%d)\n%s <%s> ", __FILE__, __LINE__, check, buffer);
171
172 //---- ブレーク
173 breakStop();
174}
175
176//---------------------------------------------------------------------------
177// ブレーク
178//---------------------------------------------------------------------------
179inline void GxP2PDebug::breakStop(void)
180{
181 GX_ASSERT(false, "");
182}
183
184//---------------------------------------------------------------------------
185// 文字列出力 (private)
187//---------------------------------------------------------------------------
188inline void GxP2PDebug::print(GX_CSTR buffer)
189{
190 GX_TRACE(GX_TRACE_CATEGORY_P2P, buffer);
191}
192
193GX_P2P_NAMESPACE_END()
194
195#endif //GX_DEVELOP
196
197//===========================================================================
199//===========================================================================
200#if GX_DEVELOP
201#define GXP2P_DEBUG_SETPRINTLV(__LEVEL__) gx::p2p::GxP2PDebug::getInstance()->setPrintLV(__LEVEL__)
202#else //GX_DEVELOP
203#define GXP2P_DEBUG_SETPRINTLV(__LEVEL__)
204#endif // !GX_DEVELOP
205
206//===========================================================================
208//===========================================================================
209#if GX_DEVELOP
210#define GXP2P_DEBUG_GETPRINTLV(__LEVEL__) gx::p2p::GxP2PDebug::getInstance()->getPrintLV()
211#else // GX_DEVELOP
212#define GXP2P_DEBUG_GETPRINTLV(__LEVEL__)
213#endif // !GX_DEVELOP
214
215//===========================================================================
217//===========================================================================
218#if GX_DEVELOP
219#define GXP2P_DEBUG_TRACE(__LEVEL__, ...) gx::p2p::GxP2PDebug::getInstance()->trace(__LEVEL__, __FUNCTION__, __VA_ARGS__)
220#else // GX_DEVELOP
221#define GXP2P_DEBUG_TRACE(__LEVEL__, ...) ((void)0)
222#endif // !GX_DEVELOP
223
224//===========================================================================
226//===========================================================================
227#if GX_DEVELOP
228#define GXP2P_DEBUG_ASSERT(a, ...) if( !(a) ) \
229 { \
230 gx::p2p::GxP2PDebug::getInstance()->breakStop(#a, __VA_ARGS__); \
231 }
232#else // GX_DEVELOP
233#define GXP2P_DEBUG_ASSERT(a, ...)
234#endif // !GX_DEVELOP
235
236//===========================================================================
238//===========================================================================
239#if GX_DEVELOP
240#define GXP2P_DEBUG_VERIFY(a, ...) GXP2P_DEBUG_ASSERT(a, __VA_ARGS__)
241#else // GX_DEVELOP
242#define GXP2P_DEBUG_VERIFY(a, ...) a
243#endif // !GX_DEVELOP
244
245//===========================================================================
247//===========================================================================
248#if GX_DEVELOP
249#define GXP2P_DEBUG_BREAK() gx::p2p::GxP2PDebug::getInstance()->breakStop()
250#else // GX_DEVELOP
251#define GXP2P_DEBUG_BREAK()
252#endif // !GX_DEVELOP
253
254//===========================================================================
256//===========================================================================
257#define GXP2P_ERROR_PRINT(...) GXP2P_DEBUG_TRACE(gx::p2p::GxP2PDebug::PRINT_LV::_1, __VA_ARGS__)
258#define GXP2P_SYSTEM_PRINT(...) GXP2P_DEBUG_TRACE(gx::p2p::GxP2PDebug::PRINT_LV::_2, __VA_ARGS__)
259#define GXP2P_APPLICATION_PRINT(...) GXP2P_DEBUG_TRACE(gx::p2p::GxP2PDebug::PRINT_LV::_3, __VA_ARGS__)
260#define GXP2P_CALLBACK_PRINT(...) GXP2P_DEBUG_TRACE(gx::p2p::GxP2PDebug::PRINT_LV::_4, __VA_ARGS__)
261#define GXP2P_FUNCTION_PRINT(...) GXP2P_DEBUG_TRACE(gx::p2p::GxP2PDebug::PRINT_LV::_5, __VA_ARGS__)
262
263//===========================================================================
265//===========================================================================
266#define GXP2P_FUNCTION_PRINT_START() GXP2P_FUNCTION_PRINT("start\n")
267#define GXP2P_FUNCTION_PRINT_END(__RESULT__) GXP2P_FUNCTION_PRINT("end (%d)\n", __RESULT__)
@ _2
ビュー2
@ _1
ビュー1
@ _0
ビュー0
@ _4
ビュー4
@ _3
ビュー3
@ _5
ビュー5
static constexpr u32 VALUE_256
256
Definition GxMath.h:127