|
1 /* |
|
2 * Copyright (c) 2009 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: Implementation of tracing functions for SysLangUtil module. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifdef _DEBUG |
|
20 #include <e32debug.h> |
|
21 #include "syslangutiltrace.h" |
|
22 #endif // _DEBUG |
|
23 |
|
24 #ifdef _DEBUG |
|
25 |
|
26 _LIT( KModuleName, "SYSLANG" ); |
|
27 _LIT( KOverflowStr, "..." ); |
|
28 _LIT( KTraceFuncFmt, "%S # %S" ); |
|
29 _LIT( KTraceSeparator, " # " ); |
|
30 _LIT( KAssertionFmt, "%S # Assertion failed: file=%S, line=%d" ); |
|
31 _LIT( KFatalMemAllocFailure, "SYSLANG # Memory allocation failure during tracing" ); |
|
32 |
|
33 const TInt KTraceBufLen = 128; |
|
34 typedef TBuf<KTraceBufLen> TTraceBuf; |
|
35 |
|
36 const TInt KFileNameBufLen = 64; |
|
37 typedef TBuf<KFileNameBufLen> TFileNameBuf; |
|
38 |
|
39 #endif // _DEBUG |
|
40 |
|
41 #if defined _DEBUG && defined __SYSLANG_TRACE__ |
|
42 _LIT( KTraceFuncExitFmt, "%S # %S finished" ); |
|
43 _LIT( KTraceFuncExitRetFmt, "%S # %S finished with %d" ); |
|
44 _LIT( KTraceCallerFmt, " (caller thread: %S)" ); |
|
45 |
|
46 const TInt KFuncNameBufLen = 64; |
|
47 typedef TBuf<KFuncNameBufLen> TFuncNameBuf; |
|
48 #endif // _DEBUG && __SYSLANG_TRACE__ |
|
49 |
|
50 #ifdef _DEBUG |
|
51 |
|
52 NONSHARABLE_CLASS( TTraceOverflowHandler ) : public TDes16Overflow |
|
53 { |
|
54 public: // Functions from base classes |
|
55 |
|
56 /** |
|
57 * Handle descriptor ovewflow. |
|
58 */ |
|
59 virtual void Overflow( TDes16 &aDes ) |
|
60 { |
|
61 aDes.RightTPtr( KOverflowStr().Length() ).Copy( KOverflowStr ); |
|
62 } |
|
63 }; |
|
64 |
|
65 #endif // _DEBUG |
|
66 |
|
67 // ============================= LOCAL FUNCTIONS =============================== |
|
68 |
|
69 #ifdef _DEBUG |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // AssertTraceFunc |
|
73 // |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void AssertTraceFunc( const TDesC8& aFile, TInt aLine ) |
|
77 { |
|
78 TTraceOverflowHandler overflowHandler; |
|
79 |
|
80 TFileNameBuf name; |
|
81 name.Copy( aFile.Left( KFileNameBufLen ) ); // Change it to 16-bit descriptor |
|
82 |
|
83 TTraceBuf buf; |
|
84 buf.AppendFormat( KAssertionFmt, &overflowHandler, |
|
85 &KModuleName, &name, aLine ); |
|
86 RDebug::Print( buf ); |
|
87 } |
|
88 |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // TraceFunc |
|
92 // |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void TraceFunc( TRefByValue<const TDesC16> aFmt, ... ) |
|
96 { |
|
97 HBufC* fmtString = HBufC::New( KTraceFuncFmt().Length() + |
|
98 KModuleName().Length() + |
|
99 static_cast<const TDesC16&>( aFmt ).Length() ); |
|
100 |
|
101 if ( fmtString ) |
|
102 { |
|
103 TPtr ptr( fmtString->Des() ); |
|
104 ptr.Append( KModuleName ); |
|
105 ptr.Append( KTraceSeparator ); |
|
106 ptr.Append( aFmt ); |
|
107 |
|
108 VA_LIST list; |
|
109 VA_START( list, aFmt ); |
|
110 |
|
111 TTraceOverflowHandler overflowHandler; |
|
112 TTraceBuf buf; |
|
113 buf.AppendFormatList( *fmtString, list, &overflowHandler ); |
|
114 RDebug::Print( buf ); |
|
115 |
|
116 VA_END( list ); |
|
117 |
|
118 delete fmtString; |
|
119 } |
|
120 else |
|
121 { |
|
122 RDebug::Print( KFatalMemAllocFailure ); |
|
123 } |
|
124 } |
|
125 |
|
126 |
|
127 #endif // _DEBUG |
|
128 |
|
129 #if defined _DEBUG && defined __SYSLANG_TRACE__ |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // FuncEntryTrace |
|
133 // |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void FuncEntryTrace( const TDesC8& aFunction, TBool aPrintCaller ) |
|
137 { |
|
138 TTraceOverflowHandler overflowHandler; |
|
139 |
|
140 TFuncNameBuf name; |
|
141 name.Copy( aFunction.Left( KFuncNameBufLen ) ); // Change it to 16-bit descriptor |
|
142 |
|
143 TTraceBuf buf; |
|
144 buf.AppendFormat( KTraceFuncFmt, &overflowHandler, &KModuleName, &name ); |
|
145 |
|
146 if ( aPrintCaller ) |
|
147 { |
|
148 const TName caller = RThread().Name(); |
|
149 buf.AppendFormat( KTraceCallerFmt, &overflowHandler, &caller ); |
|
150 } |
|
151 |
|
152 RDebug::Print( buf ); |
|
153 } |
|
154 |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // FuncExitTrace |
|
158 // |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void FuncExitTrace( const TDesC8& aFunction ) |
|
162 { |
|
163 TTraceOverflowHandler overflowHandler; |
|
164 |
|
165 TFuncNameBuf name; |
|
166 name.Copy( aFunction.Left( KFuncNameBufLen ) ); // Change it to 16-bit descriptor |
|
167 |
|
168 TTraceBuf buf; |
|
169 buf.AppendFormat( KTraceFuncExitFmt, &overflowHandler, &KModuleName, &name ); |
|
170 RDebug::Print( buf ); |
|
171 } |
|
172 |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // FuncExitTrace |
|
176 // |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void FuncExitTrace( const TDesC8& aFunction, const TInt aReturnValue ) |
|
180 { |
|
181 TTraceOverflowHandler overflowHandler; |
|
182 |
|
183 TFuncNameBuf name; |
|
184 name.Copy( aFunction.Left( KFuncNameBufLen ) ); // Change it to 16-bit descriptor |
|
185 |
|
186 TTraceBuf buf; |
|
187 buf.AppendFormat( KTraceFuncExitRetFmt, &overflowHandler, |
|
188 &KModuleName, &name, aReturnValue ); |
|
189 RDebug::Print( buf ); |
|
190 } |
|
191 |
|
192 |
|
193 #endif // _DEBUG && __SYSLANG_TRACE__ |