|
1 /* |
|
2 * Copyright (c) 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: Debug definitions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef PLATFORMENVDEBUG_H |
|
20 #define PLATFORMENVDEBUG_H |
|
21 |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32debug.h> |
|
25 |
|
26 // Function trace |
|
27 // #define PLATFORM_ENV_FUNC_LOG |
|
28 |
|
29 // Informative trace |
|
30 // #define PLATFORM_ENV_INFO_LOG |
|
31 |
|
32 // Error trace |
|
33 // #define PLATFORM_ENV_ERROR_LOG |
|
34 |
|
35 // Client trace (used with function trace) |
|
36 #define PLATFORM_ENV_CLIENT_LOG |
|
37 |
|
38 #ifdef _DEBUG |
|
39 #ifndef PLATFORM_ENV_ERROR_LOG |
|
40 #define PLATFORM_ENV_ERROR_LOG |
|
41 #endif // PLATFORM_ENV_ERROR_LOG |
|
42 #endif // _DEBUG |
|
43 |
|
44 |
|
45 // Function logging |
|
46 #ifdef PLATFORM_ENV_FUNC_LOG |
|
47 |
|
48 _LIT8( KFuncNameTerminator, "(" ); |
|
49 _LIT8( KFuncLeavePatternL, "L" ); |
|
50 const TInt KFuncCanLeave = 0x1; |
|
51 const TInt KFuncLeft = 0x2; |
|
52 const TInt KFuncLogClient = 0x4; |
|
53 |
|
54 class TFuncLog |
|
55 { |
|
56 public: |
|
57 static void Cleanup( TAny* aPtr ) |
|
58 { |
|
59 TFuncLog* self = static_cast< TFuncLog* >( aPtr ); |
|
60 self->iFlags |= KFuncLeft; |
|
61 RDebug::Printf( "%S-LEAVE", &self->iFunc ); // Leave detected |
|
62 } |
|
63 |
|
64 inline void LogClientStart() |
|
65 { |
|
66 #ifdef PLATFORM_ENV_CLIENT_LOG |
|
67 if ( iFlags & KFuncLogClient ) |
|
68 { |
|
69 _LIT( KMsg, "Client=%S-START" ); |
|
70 TName name( RThread().Name() ); |
|
71 RDebug::Print( KMsg, &name ); |
|
72 } |
|
73 #endif // PLATFORM_ENV_CLIENT_LOG |
|
74 } |
|
75 |
|
76 inline void LogClientEnd() |
|
77 { |
|
78 #ifdef PLATFORM_ENV_CLIENT_LOG |
|
79 if ( iFlags & KFuncLogClient ) |
|
80 { |
|
81 _LIT( KMsg, "Client=%S-END" ); |
|
82 TName name( RThread().Name() ); |
|
83 RDebug::Print( KMsg, &name ); |
|
84 } |
|
85 #endif // PLATFORM_ENV_CLIENT_LOG |
|
86 } |
|
87 |
|
88 // For non leaving and L methods |
|
89 inline TFuncLog( const char* aFunc, TUint aFlags ) : |
|
90 iFunc( aFunc ? _S8( aFunc ) : _S8("") ), |
|
91 iFlags( aFlags ), |
|
92 iCleanupItem( Cleanup, this ), |
|
93 iLCPtr( NULL ) |
|
94 { |
|
95 TInt pos( iFunc.Find( KFuncNameTerminator ) ); |
|
96 if( pos != KErrNotFound ) |
|
97 { |
|
98 iFunc.Set( iFunc.Left( pos ) ); |
|
99 if( !iFunc.Right( KFuncLeavePatternL().Length() ).Compare( KFuncLeavePatternL ) ) |
|
100 { |
|
101 iFlags |= KFuncCanLeave; |
|
102 CleanupStack::PushL( iCleanupItem ); // Ignore warnings |
|
103 } |
|
104 } |
|
105 RDebug::Printf( "%S-START", &iFunc ); |
|
106 LogClientStart(); |
|
107 } |
|
108 |
|
109 // For LC methods only |
|
110 inline TFuncLog( const char* aFunc, TUint aFlags, TAny** aLCPtr ) : |
|
111 iFunc( aFunc ? _S8( aFunc ) : _S8("") ), |
|
112 iFlags( aFlags ), |
|
113 iCleanupItem( Cleanup, this ), |
|
114 iLCPtr( NULL ) |
|
115 { |
|
116 TInt pos( iFunc.Find( KFuncNameTerminator ) ); |
|
117 if( pos != KErrNotFound ) |
|
118 { |
|
119 iFunc.Set( iFunc.Left( pos ) ); |
|
120 iFlags |= KFuncCanLeave; |
|
121 iLCPtr = aLCPtr; |
|
122 CleanupStack::PushL( iCleanupItem ); // Ignore warnings |
|
123 } |
|
124 RDebug::Printf( "%S-START", &iFunc ); |
|
125 LogClientStart(); |
|
126 } |
|
127 |
|
128 inline ~TFuncLog() |
|
129 { |
|
130 if ( !( iFlags & KFuncLeft ) ) |
|
131 { |
|
132 if ( iFlags & KFuncCanLeave ) |
|
133 { |
|
134 if ( iLCPtr && *iLCPtr) |
|
135 { |
|
136 CleanupStack::Pop(); // Pop LC ptr first |
|
137 CleanupStack::Pop( this ); // Pop the cleanup item |
|
138 CleanupStack::PushL( *iLCPtr ); // Push LC ptr back |
|
139 } |
|
140 else |
|
141 { |
|
142 CleanupStack::Pop( this ); // Pop the cleanup item |
|
143 } |
|
144 } |
|
145 LogClientEnd(); |
|
146 RDebug::Printf( "%S-END", &iFunc ); // Normally finished |
|
147 } |
|
148 } |
|
149 |
|
150 private: // Data |
|
151 TPtrC8 iFunc; |
|
152 TUint iFlags; |
|
153 TCleanupItem iCleanupItem; |
|
154 TAny** iLCPtr; |
|
155 }; |
|
156 |
|
157 #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__, 0 ); |
|
158 |
|
159 #define FUNC_LOG_LC( ptr ) TFuncLog _fl( __PRETTY_FUNCTION__, 0, (TAny**)&ptr ); |
|
160 |
|
161 #define FUNC_LOG_WITH_CLIENT_NAME TFuncLog _fl( __PRETTY_FUNCTION__, KFuncLogClient ); |
|
162 |
|
163 #define FUNC_LOG_WITH_CLIENT_NAME_LC( ptr )\ |
|
164 TFuncLog _fl( __PRETTY_FUNCTION__, KFuncLogClient, (TAny**)&ptr ); |
|
165 |
|
166 #else // PLATFORM_ENV_FUNC_LOG |
|
167 |
|
168 #define FUNC_LOG |
|
169 |
|
170 #define FUNC_LOG_LC( ptr ) |
|
171 |
|
172 #define FUNC_LOG_WITH_CLIENT_NAME |
|
173 |
|
174 #define FUNC_LOG_WITH_CLIENT_NAME_LC( ptr ) |
|
175 |
|
176 #endif // PLATFORM_ENV_FUNC_LOG |
|
177 |
|
178 // Informative logging |
|
179 #ifdef PLATFORM_ENV_INFO_LOG |
|
180 |
|
181 #define INFO_LOG( aMsg ) { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } |
|
182 |
|
183 #define INFO_LOG1( aMsg, aArg1 )\ |
|
184 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } |
|
185 |
|
186 #define INFO_LOG2( aMsg, aArg1, aArg2 )\ |
|
187 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } |
|
188 |
|
189 #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )\ |
|
190 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } |
|
191 |
|
192 #else // PLATFORM_ENV_INFO_LOG |
|
193 |
|
194 #define INFO_LOG( aMsg ) |
|
195 |
|
196 #define INFO_LOG1( aMsg, aArg1 ) |
|
197 |
|
198 #define INFO_LOG2( aMsg, aArg1, aArg2 ) |
|
199 |
|
200 #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 ) |
|
201 |
|
202 #endif // PLATFORM_ENV_INFO_LOG |
|
203 |
|
204 |
|
205 // Error logging |
|
206 #ifdef PLATFORM_ENV_ERROR_LOG |
|
207 |
|
208 #define ERROR_LOG( aMsg ) { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } |
|
209 |
|
210 #define ERROR_LOG1( aMsg, aArg1 )\ |
|
211 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } |
|
212 |
|
213 #define ERROR_LOG2( aMsg, aArg1, aArg2 )\ |
|
214 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } |
|
215 |
|
216 #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )\ |
|
217 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } |
|
218 |
|
219 #define LOG_IF_ERROR( aErr, aMsg )\ |
|
220 if ( ( aErr ) != KErrNone )\ |
|
221 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } |
|
222 |
|
223 #define LOG_IF_ERROR1( aErr, aMsg, aArg1 )\ |
|
224 if ( ( aErr ) != KErrNone )\ |
|
225 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } |
|
226 |
|
227 #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 )\ |
|
228 if ( ( aErr ) != KErrNone )\ |
|
229 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } |
|
230 |
|
231 #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 )\ |
|
232 if ( ( aErr ) != KErrNone )\ |
|
233 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } |
|
234 |
|
235 #else // PLATFORM_ENV_ERROR_LOG |
|
236 |
|
237 #define ERROR_LOG( aMsg ) |
|
238 |
|
239 #define ERROR_LOG1( aMsg, aArg1 ) |
|
240 |
|
241 #define ERROR_LOG2( aMsg, aArg1, aArg2 ) |
|
242 |
|
243 #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 ) |
|
244 |
|
245 #define LOG_IF_ERROR( aErr, aMsg ) |
|
246 |
|
247 #define LOG_IF_ERROR1( aErr, aMsg, aArg1 ) |
|
248 |
|
249 #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 ) |
|
250 |
|
251 #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 ) |
|
252 |
|
253 #endif // PLATFORM_ENV_ERROR_LOG |
|
254 |
|
255 |
|
256 #endif // PLATFORMENVDEBUG_H |
|
257 |
|
258 // End of File |