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