1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     dbg_DebugString.h
4 
5   Copyright (C)2009 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 35716 $
14  *---------------------------------------------------------------------------*/
15 
16 /*!
17     @file
18 
19     :include nn/dbg.h
20 */
21 
22 #ifndef NN_DBG_DBG_DEBUGSTRING_H_
23 #define NN_DBG_DBG_DEBUGSTRING_H_
24 
25 #include <nn/config.h>
26 #include <nn/types.h>
27 #include <nn/Result.h>
28 #include <nn/dbg/dbg_Result.h>
29 
30 /*!
31     @addtogroup     nn_dbg                  dbg のマクロ定義
32     @brief          デバッグ用のマクロです。
33     @{
34 */
35 
36 /*!
37     @brief @ref NN_LOG のバッファサイズです。
38 */
39 #define NN_DBG_PRINTF_BUFFER_LENGTH     256
40 
41 // TPrintf用バッファサイズ
42 #define NN_DBG_TPRINTF_BUFFER_LENGTH    128
43 
44 //-------------------------------------------------------------------
45 // NN_LOG
46 
47 /*!
48     @param[in]  ...     標準ライブラリの printf の引数と同様です。
49 
50     @brief  文字列をデバッグウィンドウに出力します。
51 
52             バッファサイズは @ref NN_DBG_PRINTF_BUFFER_LENGTH です。
53             @ref NN_DBG_PRINTF_BUFFER_LENGTH よりも大きなサイズの文字列を扱うことはできません。
54 */
55 #ifndef NN_SWITCH_DISABLE_DEBUG_PRINT
56     #ifdef __cplusplus
57         #define NN_LOG( ... )  (void)nn::dbg::detail::Printf(__VA_ARGS__)
58     #else   // ifdef __cplusplus
59         #define NN_LOG( ... )  (void)nndbgDetailPrintf(__VA_ARGS__)
60     #endif  // ifdef __cplusplus else
61 #else   // ifndef NN_SWITCH_DISABLE_DEBUG_PRINT
62     #define NN_LOG( ... )  ((void)0)
63 #endif  // ifndef NN_SWITCH_DISABLE_DEBUG_PRINT else
64 
65 //-------------------------------------------------------------------
66 // NN_TLOG_
67 
68 /*
69     @def NN_TLOG_
70 
71     @brief 文字列をデバッグ出力します。NN_LOG の省メモリ版です。
72 
73            SDK 内部でのみ使用します。
74 */
75 #ifndef NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK
76     #ifdef __cplusplus
77         #define NN_TLOG_( ... )  (void)nn::dbg::detail::TPrintf(__VA_ARGS__)
78     #else   // ifdef __cplusplus
79         #define NN_TLOG_( ... )  (void)nndbgDetailTPrintf(__VA_ARGS__)
80     #endif  // ifdef __cplusplus else
81 #else   // ifndef NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK
82     #define NN_TLOG_( ... )  ((void)0)
83 #endif  // ifndef NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK else
84 
85 //-------------------------------------------------------------------
86 // NN_SLOG_
87 
88 /*
89     @def NN_TLOG_
90 
91     @brief 文字列をデバッグ出力します。NN_LOG の省メモリ版です。
92 
93            SDK 内部でのみ使用します。
94 */
95 #ifndef NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK
96     #ifdef __cplusplus
97         #define NN_SLOG_( ... )  (void)nn::dbg::detail::Printf(__VA_ARGS__)
98     #else   // ifdef __cplusplus
99         #define NN_SLOG_( ... )  (void)nndbgDetailPrintf(__VA_ARGS__)
100     #endif  // ifdef __cplusplus else
101 #else   // ifndef NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK
102     #define NN_SLOG_( ... )  ((void)0)
103 #endif  // ifndef NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK else
104 
105 
106 //-------------------------------------------------------------------
107 // NN_LOGV
108 
109 /*!
110     @param[in]  fmt     出力書式文字列(フォーマット文字列)を指定します。
111     @param[in]  arg     可変引数リストを指定します。
112 
113     @brief  文字列をデバッグウィンドウに出力します。
114             フォーマット文字列(出力書式文字列)に従い可変引数リストを与えることが可能です。
115 
116             バッファサイズは @ref NN_DBG_PRINTF_BUFFER_LENGTH です。
117             @ref NN_DBG_PRINTF_BUFFER_LENGTH よりも大きなサイズの文字列を扱うことはできません。
118 */
119 #ifndef NN_SWITCH_DISABLE_DEBUG_PRINT
120     #ifdef __cplusplus
121         #define NN_LOGV( fmt, arg )  (void)nn::dbg::detail::VPrintf(fmt, arg)
122     #else   // ifdef __cplusplus
123         #define NN_LOGV( fmt, arg )  (void)nndbgDetailVPrintf(fmt, arg)
124     #endif  // ifdef __cplusplus else
125 #else   // ifndef NN_SWITCH_DISABLE_DEBUG_PRINT
126     #define NN_LOGV( ... )  ((void)0)
127 #endif  // ifndef NN_SWITCH_DISABLE_DEBUG_PRINT else
128 
129 //-------------------------------------------------------------------
130 // NN_PUT
131 
132 /*!
133     @param[in]  text     出力する文字列を指定します。
134     @param[in]  length   文字列長を指定します。
135 
136     @brief  文字列をデバッグウィンドウに出力します。
137 */
138 #ifndef NN_SWITCH_DISABLE_DEBUG_PRINT
139     #ifdef __cplusplus
140         #define NN_PUT( text, length )  (void)nn::dbg::detail::PutString(text, length)
141     #else   // ifdef __cplusplus
142         #define NN_PUT( text, length )  (void)nndbgDetailPutString(text, length)
143     #endif  // ifdef __cplusplus else
144 #else   // ifndef NN_SWITCH_DISABLE_DEBUG_PRINT
145     #define NN_PUT( text, length )  ((void)0)
146 #endif  // ifndef NN_SWITCH_DISABLE_DEBUG_PRINT else
147 
148 /*!
149   @}
150 */
151 
152 //-------------------------------------------------------------------
153 // for C++
154 
155 #ifdef __cplusplus
156 namespace nn { namespace dbg {
157     namespace detail
158     {
159         /*
160             @brief 文字列をデバッグ出力します。
161 
162             @param[in] fmt 一般的な printf のフォーマット文字列
163         */
164         void Printf(const char* fmt, ...);
165 
166         /*
167             @brief 文字列をデバッグ出力します。Printf の省メモリ版です。
168 
169             @param[in] fmt 一般的な printf のフォーマット文字列。ただし、浮動小数点系のもの(%%f など) は指定できません。
170         */
171         void TPrintf(const char* fmt, ...);
172 
173          /*
174             @brief 文字列をデバッグ出力します。
175 
176                    VPrint は weak シンボルでコンパイルされているため、ユーザ独自の定義に書き換えが可能です。
177 
178             @param[in] fmt 一般的な printf のフォーマット文字列
179             @param[in] vlist 可変引数パラメータ
180         */
181         void VPrintf(const char* fmt, ::std::va_list arg);
182 
183         /*
184             @brief 文字列をデバッグ出力します。VPrintf の省メモリ版です。
185 
186                    TVPrint は weak シンボルでコンパイルされているため、ユーザ独自の定義に書き換えが可能です。
187 
188             @param[in] fmt 一般的な printf のフォーマット文字列。ただし、浮動小数点系のもの(%%f など) は指定できません。
189             @param[in] vlist 可変引数パラメータ
190         */
191         void TVPrintf(const char* fmt, ::std::va_list arg);
192 
193         /*
194             @brief 文字列をデバッグ出力します。
195 
196                    PutString は weak シンボルでコンパイルされているため、ユーザ独自の定義に書き換えが可能です。
197 
198             @param[in] text     出力文字列
199             @param[in] length   出力文字列の長さ
200         */
201         void PutString(const char* text, s32 length);
202 
203         /*
204             @brief 文字列をデバッグ出力します。
205 
206                    内部で length を指定するオーバーロードの PutString を呼び出します。
207 
208             @param[in] text 出力文字列 (NULL 終端されている必要があります)
209         */
210         void PutString(const char* text);
211     }
212 }}
213 #endif  // ifdef __cplusplus
214 
215 //-------------------------------------------------------------------
216 // for C / C++
217 
218 #include <nn/util/detail/util_CLibImpl.h>
219 
220 #include <nn/dbg/dbg_Break.h>
221 
222 #ifdef __cplusplus
223 extern "C" {
224 #endif  // ifdef __cplusplus
225 
226     /*
227         @brief 対応する C++ 関数 @ref nn::dbg::detail::Printf を参照してください。
228     */
229     void nndbgDetailPrintf(const char* fmt, ...);
230 
231     /*
232         @brief 対応する C++ 関数 @ref nn::dbg::detail::TPrintf を参照してください。
233     */
234     void nndbgDetailTPrintf(const char* fmt, ...);
235 
236     /*
237         @brief 対応する C++ 関数 @ref nn::dbg::detail::VPrintf を参照してください。
238 
239                nndbgDetailVPrintf は weak シンボルでコンパイルされているため、ユーザ独自の定義に書き換えが可能です。
240     */
241     void nndbgDetailVPrintf(const char* fmt, va_list arg);
242 
243     /*
244         @brief 対応する C++ 関数 @ref nn::dbg::detail::TVPrintf を参照してください。
245 
246                nndbgDetailTVPrintf は weak シンボルでコンパイルされているため、ユーザ独自の定義に書き換えが可能です。
247     */
248     void nndbgDetailTVPrintf(const char* fmt, va_list arg);
249 
250     /*
251         @brief 対応する C++ 関数 @ref nn::dbg::detail::PutString を参照してください。
252 
253                nndbgDetailTVPrintf は weak シンボルでコンパイルされているため、ユーザ独自の定義に書き換えが可能です。
254     */
255     void nndbgDetailPutString(const char* text, s32 length);
256 
257     /*
258         @brief 文字列を表示し、プログラムを停止します。
259 
260                nndbgAssertionFailureHandler は weak シンボルでコンパイルされているため、ユーザ独自の定義に書き換えが可能です。
261 
262         @param[in] print 文字列を表示するかどうかを決定する条件
263         @param[in] filename ファイル名
264         @param[in] lineno 行番号
265         @param[in] fmt 一般的な printf のフォーマット文字列
266 
267         @return 常に0
268     */
269     int nndbgAssertionFailureHandler(bool print, const char* filename, int lineno, const char* fmt, ...);
270 
271     /*
272         @brief 文字列を表示し、プログラムを停止します。nndbgAssertionFailureHandler の省メモリ版です。
273 
274                nndbgTAssertionFailureHandler は weak シンボルでコンパイルされているため、ユーザ独自の定義に書き換えが可能です。
275 
276         @param[in] print 文字列を表示するかどうかを決定する条件
277         @param[in] filename ファイル名
278         @param[in] lineno 行番号
279         @param[in] fmt 一般的な printf のフォーマット文字列。ただし、浮動小数点系のもの(%%f など) は指定できません。
280 
281         @return 常に0
282     */
283     int nndbgTAssertionFailureHandler(bool print, const char* filename, int lineno, const char* fmt, ...);
284 
285 #ifdef __cplusplus
286 }
287 #endif  // ifdef __cplusplus
288 
289 #endif  // NN_DBG_DBG_DEBUGSTRING_H_
290