0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
#include <d32btrace.h>
|
|
17 |
|
|
18 |
#include "utraceformatter.h"
|
|
19 |
|
|
20 |
|
|
21 |
/**
|
|
22 |
1st stage construction
|
|
23 |
@return pointer to the newly created object, caller takes ownership of the object.
|
|
24 |
*/
|
|
25 |
CUtraceFormatter* CUtraceFormatter::NewL()
|
|
26 |
{
|
|
27 |
LOG_MSG("->CUtraceFormatter::NewL()\n");
|
|
28 |
CUtraceFormatter* self = CUtraceFormatter::NewLC();
|
|
29 |
CleanupStack::Pop(self);
|
|
30 |
return self;
|
|
31 |
}
|
|
32 |
|
|
33 |
/**
|
|
34 |
1st stage construction
|
|
35 |
@return pointer to the newly created object, caller takes ownership of the object.
|
|
36 |
*/
|
|
37 |
CUtraceFormatter* CUtraceFormatter::NewLC()
|
|
38 |
{
|
|
39 |
LOG_MSG("->CUtraceFormatter::NewLC()\n");
|
|
40 |
CUtraceFormatter* self = new(ELeave) CUtraceFormatter();
|
|
41 |
CleanupStack::PushL(self);
|
|
42 |
self->ConstructL();
|
|
43 |
return self;
|
|
44 |
}
|
|
45 |
|
|
46 |
/**
|
|
47 |
dtor
|
|
48 |
*/
|
|
49 |
CUtraceFormatter::~CUtraceFormatter()
|
|
50 |
{
|
|
51 |
LOG_MSG("->~CDexcFormatter()\n");
|
|
52 |
iConfigList.ResetAndDestroy();
|
|
53 |
}
|
|
54 |
|
|
55 |
/**
|
|
56 |
2nd stage construction
|
|
57 |
*/
|
|
58 |
void CUtraceFormatter::ConstructL()
|
|
59 |
{
|
|
60 |
LOG_MSG("->CDexcFormatter::ConstructL()\n");
|
|
61 |
|
|
62 |
//Configure the plugin
|
|
63 |
COptionConfig * config = NULL;
|
|
64 |
|
|
65 |
iConfigList.ReserveL( (TInt) ETraceGuard );
|
|
66 |
|
|
67 |
_LIT(KTraceSize, "How much trace data to dump? (Kb)");
|
|
68 |
|
|
69 |
config = COptionConfig::NewL( (TInt) ETraceSize,
|
|
70 |
KUtraceFormatterUID,
|
|
71 |
COptionConfig::EFormatterPlugin,
|
|
72 |
COptionConfig::ETInt,
|
|
73 |
KTraceSize,
|
|
74 |
1,
|
|
75 |
KNullDesC,
|
|
76 |
100,
|
|
77 |
KNullDesC);
|
|
78 |
|
|
79 |
TInt error = iConfigList.Append(config);
|
|
80 |
|
|
81 |
if(error != KErrNone)
|
|
82 |
{
|
|
83 |
delete config;
|
|
84 |
LOG_MSG2("\tCDexcFormatter::ConstructL() - unable to store COptionConfig object in param list: %d", error);
|
|
85 |
}
|
|
86 |
|
|
87 |
}
|
|
88 |
|
|
89 |
/**
|
|
90 |
Called by CDS to ask for the configuration parameters that the writer needs (see Plugin Configuration)
|
|
91 |
@return actual number of implemented config parameters
|
|
92 |
*/
|
|
93 |
TInt CUtraceFormatter::GetNumberConfigParametersL()
|
|
94 |
{
|
|
95 |
TInt count = iConfigList.Count();
|
|
96 |
LOG_MSG2("->CUtraceFormatter::GetNumberConfigParametersL() : returns:%d\n", count );
|
|
97 |
return count;
|
|
98 |
}
|
|
99 |
|
|
100 |
/**
|
|
101 |
Called by CDS to ask for configuration parameter prompt (see Plugin Configuration)
|
|
102 |
|
|
103 |
@param aIndex indicates which parameter to return
|
|
104 |
@return pointer to COptionConfig object representing the requested config parameter. Caller doesn't take ownership of the object!
|
|
105 |
@leave KErrBadHandle if index is out of bounds
|
|
106 |
@see COptionConfig
|
|
107 |
*/
|
|
108 |
COptionConfig* CUtraceFormatter::GetConfigParameterL(const TInt aIndex)
|
|
109 |
{
|
|
110 |
// return the config identified by aIndex
|
|
111 |
if( ( aIndex < 0 ) || ( aIndex >= iConfigList.Count() ) )
|
|
112 |
{
|
|
113 |
User::Leave( KErrBadHandle );
|
|
114 |
}
|
|
115 |
|
|
116 |
return iConfigList[aIndex];
|
|
117 |
}
|
|
118 |
|
|
119 |
/**
|
|
120 |
Change a configuration parameter.
|
|
121 |
@param aIndex Index of parameter to change
|
|
122 |
@param aValue Unused
|
|
123 |
@param aDescValue Path and filename to use
|
|
124 |
@leave KErrBadHandle if index is out of bounds or one of the other system wide error codes
|
|
125 |
*/
|
|
126 |
void CUtraceFormatter::SetConfigParameterL( const TInt aIndex, const TInt32 & aValue, const TDesC & aDescValue )
|
|
127 |
{
|
|
128 |
|
|
129 |
if( ( aIndex < 0 ) || ( aIndex >= iConfigList.Count() ) )
|
|
130 |
{
|
|
131 |
User::Leave( KErrBadHandle );
|
|
132 |
}
|
|
133 |
|
|
134 |
COptionConfig & config = *(iConfigList[aIndex]);
|
|
135 |
|
|
136 |
if( ( aIndex != (TInt)ETraceSize ) )
|
|
137 |
{
|
|
138 |
LOG_MSG( "\tLeaving : aIndex != ETraceSize " );
|
|
139 |
User::Leave( KErrArgument );
|
|
140 |
}
|
|
141 |
|
|
142 |
//For the moment, we care not for the aDescValue
|
|
143 |
if(aValue > 0)
|
|
144 |
{
|
|
145 |
config.Value(aValue);
|
|
146 |
config.ValueL(KNullDesC);
|
|
147 |
}
|
|
148 |
|
|
149 |
}
|
|
150 |
|
|
151 |
/**
|
|
152 |
Sets pointer to the writer plugin.
|
|
153 |
Configures formatter's dump data save plugin.
|
|
154 |
|
|
155 |
@param aDataSave pointer to writer plugin object.
|
|
156 |
@leave KErrNoMemory if aDataSave is NULL
|
|
157 |
*/
|
|
158 |
void CUtraceFormatter::ConfigureDataSaveL(CCrashDataSave* aDataSave)
|
|
159 |
{
|
|
160 |
LOG_MSG2("\tConfigureDataSaveL(%d)", aDataSave);
|
|
161 |
User::LeaveIfNull(aDataSave);
|
|
162 |
iDataSave = aDataSave;
|
|
163 |
}
|
|
164 |
|
|
165 |
/**
|
|
166 |
Sets pointer to the crash data server.
|
|
167 |
Configures formatter's crash data source plugin.
|
|
168 |
|
|
169 |
@param aDataSource pointer to core dump server object.
|
|
170 |
@leave KErrNoMemory if aDataSource is NULL
|
|
171 |
*/
|
|
172 |
void CUtraceFormatter::ConfigureDataSourceL(CCrashDataSource* aDataSource)
|
|
173 |
{
|
|
174 |
LOG_MSG2("\tConfigureDataSourceL(%d)", aDataSource);
|
|
175 |
User::LeaveIfNull(aDataSource);
|
|
176 |
iDataSource = aDataSource;
|
|
177 |
}
|
|
178 |
|
|
179 |
void CUtraceFormatter::GetDescription(TDes& aPluginDescription)
|
|
180 |
{
|
|
181 |
LOG_MSG("\tCDexcFormatter::GetDescription()");
|
|
182 |
aPluginDescription.Copy(KPluginDescription());
|
|
183 |
}
|
|
184 |
|
|
185 |
void CUtraceFormatter::CrashEventL(TCrashInfo* aCrashInfo)
|
|
186 |
{
|
|
187 |
LOG_MSG("->CUtraceFormatter::CrashEventL\n");
|
|
188 |
|
|
189 |
User::LeaveIfNull(aCrashInfo);
|
|
190 |
User::LeaveIfNull(iDataSource);
|
|
191 |
User::LeaveIfNull(iDataSave);
|
|
192 |
|
|
193 |
TInt traceDataToCapture = iConfigList[ (TInt)ETraceSize ]->Value();
|
|
194 |
if(traceDataToCapture == 0)
|
|
195 |
{
|
|
196 |
LOG_MSG("CUtraceFormatter::WriteTraceBufferL - not configured to dump trace data");
|
|
197 |
return;
|
|
198 |
}
|
|
199 |
|
|
200 |
//update notifier
|
|
201 |
UpdateCrashProgressL( KUTraceCrashStart );
|
|
202 |
|
|
203 |
iDataSave->OpenL( DumpFileNameLC(aCrashInfo->iTime ));
|
|
204 |
CleanupStack::PopAndDestroy(); //filename
|
|
205 |
|
|
206 |
TUint traceAvailable = 0;
|
|
207 |
TRAPD(err, traceAvailable = iDataSource->GetAvailableTraceSizeL());
|
|
208 |
if(err != KErrNone)
|
|
209 |
{
|
|
210 |
LOG_MSG2("Unable to get available trace size. Err = [%d] ", err);
|
|
211 |
User::Leave(err);
|
|
212 |
}
|
|
213 |
|
|
214 |
//Write the data to the file
|
|
215 |
LOG_MSG2("\tWriting Trace data: iDataSave->WriteL() at Offset =0, size =%d bytes", traceAvailable);
|
|
216 |
TUint size = 0;
|
|
217 |
|
|
218 |
TRAP(err, size = HelpWriteTraceBufferL(traceAvailable, traceDataToCapture * 1024, 0));
|
|
219 |
if(err == KErrNotSupported)
|
|
220 |
{
|
|
221 |
LOG_MSG("Unable to use data source to dump trace so reverting to the live trace framework");
|
|
222 |
TRAP(err, size = HelpWriteTraceBufferWithTraceFrameWorkL(traceDataToCapture * 1024, 0));
|
|
223 |
}
|
|
224 |
|
|
225 |
if(err != KErrNone)
|
|
226 |
{
|
|
227 |
//This error is not fatal but worth logging
|
|
228 |
LOG_MSG2("Trace writing didnt succeed. Error = [%d]", err);
|
|
229 |
}
|
|
230 |
|
|
231 |
LOG_MSG2("\tTrace data and info succesfully written - [%d] bytes", size);
|
|
232 |
|
|
233 |
iDataSave->CloseL();
|
|
234 |
}
|
|
235 |
|
|
236 |
/**
|
|
237 |
* This gets trace from the data source. This is for use when you dont want trace from the live system and want
|
|
238 |
* the data source to decide how we obtain the trace. The data source may not support this, and leaving with
|
|
239 |
* KErrNotSupported will mean that you should be using the live trace system to get the data
|
|
240 |
* @param aTraceAvailable The amount of availbale trace data
|
|
241 |
* @param aTraceWanted The amount of trace data we wish to dump
|
|
242 |
* @param aOffset The position in the file to write the trace
|
|
243 |
* @see HelpWriteTraceBufferWithTraceFrameWorkL
|
|
244 |
*/
|
|
245 |
TUint CUtraceFormatter::HelpWriteTraceBufferL(TUint aTraceAvailable, TUint aTraceWanted, TUint aOffset)
|
|
246 |
{
|
|
247 |
LOG_MSG4("CUtraceFormatter::HelpWriteTraceBufferL aTraceAvailable = [%d] aTraceWanted = [%d] aOffset = [%d]", aTraceAvailable, aTraceWanted, aOffset);
|
|
248 |
|
|
249 |
TUint dataReq = (aTraceAvailable >= aTraceWanted) ? aTraceWanted : aTraceAvailable;
|
|
250 |
TUint bufferSize = dataReq;
|
|
251 |
RBuf8 theTraceData;
|
|
252 |
TBool bufferCreated = EFalse;
|
|
253 |
|
|
254 |
//Try and allocate the buffer
|
|
255 |
while(!bufferCreated)
|
|
256 |
{
|
|
257 |
LOG_MSG2("Trying to create a buffer of size [%d] bytes", bufferSize);
|
|
258 |
|
|
259 |
if(bufferSize == 0)
|
|
260 |
{
|
|
261 |
User::LeaveNoMemory();
|
|
262 |
}
|
|
263 |
|
|
264 |
TInt err = theTraceData.Create(bufferSize);
|
|
265 |
if(KErrNone == err)
|
|
266 |
{
|
|
267 |
bufferCreated = ETrue;
|
|
268 |
theTraceData.CleanupClosePushL();
|
|
269 |
}
|
|
270 |
else
|
|
271 |
{
|
|
272 |
bufferSize = bufferSize/4;
|
|
273 |
}
|
|
274 |
}
|
|
275 |
|
|
276 |
//Now we read the trace data bit by bit
|
|
277 |
TUint sizeWritten = 0;
|
|
278 |
while(sizeWritten < dataReq)
|
|
279 |
{
|
|
280 |
iDataSource->ReadTraceBufferL(theTraceData, sizeWritten);
|
|
281 |
|
|
282 |
LOG_MSG3("Writing [%d] bytes of raw trace data at [%d]", theTraceData.Size(), aOffset);
|
|
283 |
iDataSave->WriteL( aOffset, const_cast<TUint8*>(theTraceData.Ptr()), theTraceData.Size());
|
|
284 |
|
|
285 |
sizeWritten += theTraceData.Length();
|
|
286 |
aOffset += theTraceData.Length();
|
|
287 |
}
|
|
288 |
|
|
289 |
CleanupStack::PopAndDestroy(&theTraceData);
|
|
290 |
|
|
291 |
return sizeWritten;
|
|
292 |
}
|
|
293 |
|
|
294 |
/**
|
|
295 |
* Writes trace to the file using the trace framework. This is to use when you want trace from the live system.
|
|
296 |
* @param aTraceWanted The amount of trace data we wish to dump
|
|
297 |
* @param aOffset The position in the file to write the trace
|
|
298 |
* @see HelpWriteTraceBufferL
|
|
299 |
*/
|
|
300 |
TUint CUtraceFormatter::HelpWriteTraceBufferWithTraceFrameWorkL(TUint aTraceWanted, TUint aOffset)
|
|
301 |
{
|
|
302 |
LOG_MSG3("CUtraceFormatter::HelpWriteTraceBufferWithTraceFrameWorkL aTraceWanted = [%d] aOffset = [%d]", aTraceWanted, aOffset);
|
|
303 |
|
|
304 |
RBTrace trace;
|
|
305 |
User::LeaveIfError(trace.Open());
|
|
306 |
CleanupClosePushL(trace);
|
|
307 |
|
|
308 |
TUint8 *data = NULL;
|
|
309 |
TInt size = trace.GetData(data);
|
|
310 |
|
|
311 |
if(!data)
|
|
312 |
{
|
|
313 |
User::Leave(KErrNotFound);
|
|
314 |
}
|
|
315 |
|
|
316 |
TUint sizeToDump = (aTraceWanted >= size) ? size : aTraceWanted;
|
|
317 |
|
|
318 |
LOG_MSG2("Adding [%d] bytes to the file", sizeToDump);
|
|
319 |
iDataSave->WriteL( aOffset, data, sizeToDump);
|
|
320 |
|
|
321 |
CleanupStack::PopAndDestroy(&trace);
|
|
322 |
|
|
323 |
return size;
|
|
324 |
}
|
|
325 |
|
|
326 |
/**
|
|
327 |
Prepares the name of the dump file. Checks DataSave filename option, if it is provided by the user
|
|
328 |
it appends the time stamp, if not it uses default name appended with the time stamp.
|
|
329 |
@param aStamp lower 32 bits of the time stamp
|
|
330 |
@return descriptor holding the final dump file name, caller is responsible to pop it from the cleanup stack
|
|
331 |
@leave err one of system wide error codes
|
|
332 |
*/
|
|
333 |
const TDesC& CUtraceFormatter::DumpFileNameLC(TUint64 aStamp)
|
|
334 |
{
|
|
335 |
LOG_MSG("->CUtraceFormatter::DumpFileNameLC()\n");
|
|
336 |
COptionConfig *option = iDataSave->GetConfigParameterL(CCrashDataSave::ECoreFilePath);
|
|
337 |
const TDesC &userFileName = option->ValueAsDesc();
|
|
338 |
HBufC *filename = HBufC::NewLC(userFileName.Length() + KUTraceDumpFileLength);
|
|
339 |
if(userFileName.Length() > 0)
|
|
340 |
{
|
|
341 |
*filename = userFileName;
|
|
342 |
_LIT(KStampFormat, "%u");
|
|
343 |
filename->Des().AppendFormat(KStampFormat, I64LOW(aStamp));
|
|
344 |
}
|
|
345 |
else
|
|
346 |
{
|
|
347 |
_LIT(KTxtFileFormat, "e:\\trace%u");
|
|
348 |
filename->Des().Format(KTxtFileFormat, aStamp);
|
|
349 |
}
|
|
350 |
return *filename;
|
|
351 |
}
|
|
352 |
|
|
353 |
/**
|
|
354 |
Checks the value of the crash cancel property. If set to cancel, it closes the
|
|
355 |
data save and then leaves with KErrAbort.
|
|
356 |
Otherwise it updates the crash progress with the argument value.
|
|
357 |
|
|
358 |
@param aProgress Progress description.
|
|
359 |
@leave KErrAbort if crash cancel property has been set
|
|
360 |
*/
|
|
361 |
void CUtraceFormatter::UpdateCrashProgressL( const TDesC &aProgress )
|
|
362 |
{
|
|
363 |
|
|
364 |
LOG_MSG("->CUtraceFormatter::UpdateCrashProgress()\n");
|
|
365 |
TInt cancelCrash;
|
|
366 |
_LIT(KNoProgress, "");
|
|
367 |
RProperty::Get( KCoreDumpServUid, ECancelCrash, cancelCrash );
|
|
368 |
|
|
369 |
if( cancelCrash )
|
|
370 |
{
|
|
371 |
RProperty::Set( KCoreDumpServUid, ECrashProgress, KNoProgress );
|
|
372 |
|
|
373 |
|
|
374 |
LOG_MSG(" iDataSave->CloseL();\n");
|
|
375 |
iDataSave->CloseL();
|
|
376 |
|
|
377 |
LOG_MSG(" UpdateCrashProgress() -> User::Leave( KErrAbort )\n");
|
|
378 |
User::Leave( KErrAbort );
|
|
379 |
}
|
|
380 |
|
|
381 |
RProperty::Set( KCoreDumpServUid, ECrashProgress, aProgress );
|
|
382 |
|
|
383 |
}
|