1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Interface of debugging utilities. |
|
15 * %version: 3 % |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef RUBYDEBUG_H |
|
22 #define RUBYDEBUG_H |
|
23 |
|
24 #include "rubydebugcfg.h" |
|
25 |
|
26 // INCLUDES |
|
27 #include <e32svr.h> // For RDebug |
|
28 |
|
29 #ifndef RUBY_DISABLE_FUNCTION_NAMES |
|
30 // No sense to store function name longer, than can be printed |
|
31 // 0x100 is the internal RDebug limit |
|
32 const TInt __K_RUBY_FUNCTION_NAME_LENGTH = 0x50; |
|
33 |
|
34 // Prepares function name for printing |
|
35 #define __RUBY_PREPARE_FUNCTION_NAME \ |
|
36 TBuf<__K_RUBY_FUNCTION_NAME_LENGTH> __ruby_function_name__;\ |
|
37 __ruby_function_name__.Copy( TPtrC8( (TText8*)&__PRETTY_FUNCTION__ ).Left( __K_RUBY_FUNCTION_NAME_LENGTH ) ); \ |
|
38 |
|
39 // Token to paste the function name into |
|
40 #define __K_RUBY_FUNCTION_NAME_TOKEN "%S " |
|
41 |
|
42 // Comma and function name |
|
43 #define __RUBY_FUNCTION_NAME __ruby_function_name__ |
|
44 |
|
45 // A wrapper that prepares and supplies the function name as __ruby_function_name__ |
|
46 #define __RUBY_FUNCTION_NAMED( text ) \ |
|
47 {\ |
|
48 __RUBY_PREPARE_FUNCTION_NAME;\ |
|
49 text;\ |
|
50 } |
|
51 |
|
52 #define __RUBY_FUNCTION_NAME_POINTER8 (TText8*)&__PRETTY_FUNCTION__ |
|
53 |
|
54 |
|
55 #else // RUBY_DISABLE_FUNCTION_NAMES |
|
56 |
|
57 #define __RUBY_PREPARE_FUNCTION_NAME |
|
58 |
|
59 // Don't print the function name |
|
60 #define __K_RUBY_FUNCTION_NAME_TOKEN "" |
|
61 |
|
62 // exclude the whole token, with the comma |
|
63 #define __RUBY_FUNCTION_NAME KNullDesC |
|
64 |
|
65 // no wrapping |
|
66 #define __RUBY_FUNCTION_NAMED( text ) text |
|
67 |
|
68 #define __RUBY_FUNCTION_NAME_POINTER8 NULL |
|
69 |
|
70 #endif // RUBY_DISABLE_FUNCTION_NAMES |
|
71 |
|
72 // Macro for printing filename both in unicode and non-unicode builds |
|
73 |
|
74 |
|
75 #ifdef _UNICODE |
|
76 #define __RUBY_WIDEN2(x) L ## x |
|
77 #define __RUBY_WIDEN(x) __RUBY_WIDEN2(x) |
|
78 #define __RUBY_DBG_FILE__ __RUBY_WIDEN(__FILE__) |
|
79 #else |
|
80 #define __RUBY_DBG_FILE__ __FILE__ |
|
81 #endif//_UNICODE |
|
82 |
|
83 |
|
84 |
|
85 // Debugging is enabled only in _DEBUG builds |
|
86 //#ifdef _DEBUG |
|
87 |
|
88 // Select the debug output method |
|
89 #ifndef __RUBY_DEBUG_TRACES_TO_FILE |
|
90 #define RUBY_DEBUG_METHOD RDebug::Print |
|
91 #else |
|
92 #define RUBY_DEBUG_METHOD RRubyDebug::PrintToFile |
|
93 #endif // __RUBY_DEBUG_TRACES_TO_FILE |
|
94 |
|
95 //#endif // _DEBUG |
|
96 |
|
97 #if defined(_DEBUG) && !defined(__RUBY_DEBUG_DISABLED) |
|
98 |
|
99 // #define RUBY_DEBUG_BLOCK(text) \ |
|
100 // RRubyDebug trace_trace( _S(text), _S("" ## __RUBY_DBG_FILE__) , __LINE__, EFalse ); \ |
|
101 // CleanupReleasePushL( trace_trace ) |
|
102 |
|
103 // #define RUBY_DEBUG_BLOCKL(text) \ |
|
104 // RRubyDebug trace_trace( _S(text), _S("" ## __RUBY_DBG_FILE__), __LINE__, ETrue ); \ |
|
105 // CleanupReleasePushL( trace_trace ) |
|
106 // A temporary fix to cope with builds on RVCT 530. It didn't compile with _RUBY_DBG_FILE |
|
107 #define RUBY_DEBUG_BLOCK(text) \ |
|
108 RRubyDebug trace_trace( _S(text), _S("") , __LINE__, EFalse, __RUBY_FUNCTION_NAME_POINTER8 ); \ |
|
109 CleanupReleasePushL( trace_trace ) |
|
110 |
|
111 #define RUBY_DEBUG_BLOCKL(text) \ |
|
112 RRubyDebug trace_trace( _S(text), _S(""), __LINE__, ETrue, __RUBY_FUNCTION_NAME_POINTER8 ); \ |
|
113 CleanupReleasePushL( trace_trace ) |
|
114 |
|
115 #define RUBY_DEBUG0(text) \ |
|
116 __RUBY_FUNCTION_NAMED( RUBY_DEBUG_METHOD( _L("%S %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) ) ) |
|
117 |
|
118 #define RUBY_DEBUG1(text, p1) \ |
|
119 __RUBY_FUNCTION_NAMED( RUBY_DEBUG_METHOD( _L("%S %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, p1, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) ) ) |
|
120 |
|
121 #define RUBY_DEBUG2(text, p1, p2) \ |
|
122 __RUBY_FUNCTION_NAMED( RUBY_DEBUG_METHOD( _L("%S %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, p1, p2, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) ) ) |
|
123 |
|
124 #else // Debugging disabled |
|
125 |
|
126 // Macros expand to nothing: |
|
127 #define RUBY_DEBUG_BLOCK(text) |
|
128 #define RUBY_DEBUG0(text) |
|
129 #define RUBY_DEBUG1(text, p1) |
|
130 #define RUBY_DEBUG2(text, p1, p2) |
|
131 #define RUBY_DEBUG_BLOCKL(text) |
|
132 |
|
133 #endif // defined(_DEBUG) && !defined(__RUBY_DEBUG_DISABLED) |
|
134 |
|
135 #if !defined(RUBY_DISABLE_ERRORS) || defined(_DEBUG) |
|
136 // if error messages are allowed (even for UREL) |
|
137 #define RUBY_ERROR0(text) \ |
|
138 __RUBY_FUNCTION_NAMED( \ |
|
139 RUBY_DEBUG_METHOD( _L("%S[Error!] %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) )\ |
|
140 ) |
|
141 |
|
142 #define RUBY_ERROR1(text, p1) \ |
|
143 __RUBY_FUNCTION_NAMED( \ |
|
144 RUBY_DEBUG_METHOD( _L("%S[Error!] %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, p1, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) )\ |
|
145 ) |
|
146 |
|
147 #define RUBY_ERROR2(text, p1, p2) \ |
|
148 __RUBY_FUNCTION_NAMED( \ |
|
149 RUBY_DEBUG_METHOD( _L("%S[Error!] %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, p1, p2, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) )\ |
|
150 ) |
|
151 #else |
|
152 // error reporting disabled |
|
153 // Macros expand to nothing: |
|
154 #define RUBY_ERROR_BLOCK(text) |
|
155 #define RUBY_ERROR0(text) |
|
156 #define RUBY_ERROR1(text, p1) |
|
157 #define RUBY_ERROR2(text, p1, p2) |
|
158 #endif // !defined(RUBY_DISABLE_ERRORS) |
|
159 |
|
160 #if !defined(RUBY_DISABLE_ASSERT_DEBUG) || defined(_DEBUG) |
|
161 #define RUBY_ASSERT_DEBUG(condition, action) \ |
|
162 __RUBY_FUNCTION_NAMED(\ |
|
163 __ASSERT_ALWAYS( condition, RUBY_DEBUG_METHOD( _L("%S[Error!] %S [Assert failed!] "L###condition L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id())) ); \ |
|
164 __ASSERT_DEBUG( (condition), (action) )\ |
|
165 ); |
|
166 #else |
|
167 // Macro expands to default: |
|
168 #define RUBY_ASSERT_DEBUG(condition, action) __ASSERT_DEBUG(condition,action) |
|
169 #endif |
|
170 |
|
171 // Same as TRAP_IGNORE, but in case of leave, prints the leave code via RUBY_ERROR |
|
172 // Can be disabled by RUBY_DISABLE_TRAP_IGNORE or RUBY_DISABLE_ERRORS |
|
173 // If disabled, is equivalent to TRAP_IGNORE |
|
174 // @see rubydebugcfg.h |
|
175 #ifndef RUBY_DISABLE_TRAP_IGNORE |
|
176 #define RUBY_TRAP_IGNORE( s ) \ |
|
177 {\ |
|
178 TRAPD( err, s );\ |
|
179 if( err != KErrNone )\ |
|
180 {\ |
|
181 RUBY_ERROR1( "RUBY_TRAP_IGNORE leaves with [%d]", err );\ |
|
182 }\ |
|
183 } |
|
184 #else // RUBY_DISABLE_TRAP_IGNORE |
|
185 #define RUBY_TRAP_IGNORE( s ) TRAP_IGNORE( s ) |
|
186 #endif // RUBY_DISABLE_TRAP_IGNORE |
|
187 |
|
188 // DATA TYPES |
|
189 |
|
190 // FUNCTION PROTOTYPES |
|
191 |
|
192 // FORWARD DECLARATIONS |
|
193 |
|
194 // CLASS DECLARATION |
|
195 |
|
196 /** |
|
197 * Debug class for printing START, EXIT and LEAVE messages to RDebug in every |
|
198 * code block. Must be placed in the very beginning of a code block and the |
|
199 * code block cannot leave items in the cleanup stack (like NewLC). |
|
200 * |
|
201 * @since Series 60 2.8 |
|
202 * |
|
203 * @note If this object is not the topmost item when a code block is exited, |
|
204 * E32USER-CBase 90 panic is raised (@see CleanupStack::Pop( TAny* )). |
|
205 */ |
|
206 class RRubyDebug |
|
207 { |
|
208 public: |
|
209 /** |
|
210 * C++ constructor. |
|
211 * @since Series 60 2.8 |
|
212 * @param aMsg Debug message. |
|
213 * @param aCalledFromL ETrue if called from RUBY_DEBUG_BLOCK_L |
|
214 */ |
|
215 inline RRubyDebug( const TText* aMsg, const TText* aFileName, const TInt aLine, TBool aCalledFromL, |
|
216 const TText8* aFunctionName = NULL ); |
|
217 |
|
218 /** |
|
219 * Destructor. |
|
220 */ |
|
221 inline ~RRubyDebug(); |
|
222 |
|
223 /** |
|
224 * Destructor for Cleanup support. Called when a method leaves. |
|
225 */ |
|
226 inline void Release(); |
|
227 |
|
228 /** |
|
229 * Support for writing traces to file. |
|
230 */ |
|
231 static void PrintToFile( TRefByValue<const TDesC> aFmt, ... ); |
|
232 |
|
233 private: |
|
234 /** |
|
235 * Class for truncating debug messages if they are too long. |
|
236 * @since Series 60 2.8 |
|
237 */ |
|
238 class TTruncateOverflow : public TDesOverflow |
|
239 { |
|
240 public: // Methods from TDesOverflow |
|
241 |
|
242 inline void Overflow( TDes& aDes ); |
|
243 }; |
|
244 |
|
245 private: |
|
246 // A pointer to the debug message |
|
247 TPtrC iMsg; |
|
248 |
|
249 // A pointer to the filename where RUBY_DEBUG_BLOCK is written |
|
250 TPtrC iFileName; |
|
251 |
|
252 // Number of the line where RUBY_DEBUG_BLOCK is written |
|
253 TInt iLine; |
|
254 |
|
255 // ETrue if we are called from RUBY_DEBUG_BLOCKL |
|
256 TBool iCalledFromL; |
|
257 |
|
258 // Flag that is set when a leave occurs |
|
259 TBool iLeave; |
|
260 |
|
261 #ifndef RUBY_DISABLE_FUNCTION_NAMES |
|
262 // Used only if aFunctionName is defined in constructor |
|
263 HBufC* iFunctionName; |
|
264 #endif // RUBY_DISABLE_FUNCTION_NAMES |
|
265 |
|
266 }; |
|
267 |
|
268 #include "RubyDebug.inl" |
|
269 |
|
270 #endif // RUBYDEBUG_H |
|
271 |
|
272 // End of File |
|