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 "dexcformatter.h"
|
|
17 |
//
|
|
18 |
// there is a line limit but what if file name is longer?
|
|
19 |
//
|
|
20 |
|
|
21 |
/**
|
|
22 |
1st stage construction
|
|
23 |
@return pointer to the newly created object, caller takes ownership of the object.
|
|
24 |
*/
|
|
25 |
CDexcFormatter* CDexcFormatter::NewL()
|
|
26 |
{
|
|
27 |
LOG_MSG("->CDexcFormatter::NewL()\n");
|
|
28 |
CDexcFormatter* self = CDexcFormatter::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 |
CDexcFormatter* CDexcFormatter::NewLC()
|
|
38 |
{
|
|
39 |
LOG_MSG("->CDexcFormatter::NewLC()\n");
|
|
40 |
CDexcFormatter* self = new(ELeave) CDexcFormatter();
|
|
41 |
CleanupStack::PushL(self);
|
|
42 |
self->ConstructL();
|
|
43 |
return self;
|
|
44 |
}
|
|
45 |
|
|
46 |
/**
|
|
47 |
2nd stage construction
|
|
48 |
Reserves config parameter list, creates config parameter objects and sets them to default values.
|
|
49 |
*/
|
|
50 |
void CDexcFormatter::ConstructL()
|
|
51 |
{
|
|
52 |
LOG_MSG("->CDexcFormatter::ConstructL()\n");
|
|
53 |
TInt err;
|
|
54 |
COptionConfig * config;
|
|
55 |
|
|
56 |
iConfigList.ReserveL( (TInt)EDexcParamsLast );
|
|
57 |
|
|
58 |
_LIT( KTrueFalseOpt, "True,False" );
|
|
59 |
_LIT( KTrueOpt, "True" );
|
|
60 |
_LIT( KFalseOpt, "False" );
|
|
61 |
|
|
62 |
_LIT( KDumpStackPrompt, "Dump stack memory?" );
|
|
63 |
config = COptionConfig::NewL( (TInt)EDumpStack,
|
|
64 |
KDEXCFormatterUid,
|
|
65 |
COptionConfig::EFormatterPlugin,
|
|
66 |
COptionConfig::ETBool,
|
|
67 |
KDumpStackPrompt,
|
|
68 |
1,
|
|
69 |
KTrueFalseOpt,
|
|
70 |
1,
|
|
71 |
KTrueOpt );
|
|
72 |
|
|
73 |
err = iConfigList.Append( config );
|
|
74 |
|
|
75 |
if(err != KErrNone)
|
|
76 |
{
|
|
77 |
delete config;
|
|
78 |
LOG_MSG("CDexcFormatter::ConstructL - unable to append dump stack config option!\n" );
|
|
79 |
User::Leave(err);
|
|
80 |
}
|
|
81 |
iDumpStack = ETrue;
|
|
82 |
|
|
83 |
_LIT( KDumpAsciiPrompt, "Stack contents in ASCII?" );
|
|
84 |
config = COptionConfig::NewL( (TInt)EAsciiStack,
|
|
85 |
KDEXCFormatterUid,
|
|
86 |
COptionConfig::EFormatterPlugin,
|
|
87 |
COptionConfig::ETBool,
|
|
88 |
KDumpAsciiPrompt,
|
|
89 |
1,
|
|
90 |
KTrueFalseOpt,
|
|
91 |
0,
|
|
92 |
KFalseOpt );
|
|
93 |
|
|
94 |
err = iConfigList.Append( config );
|
|
95 |
if(err != KErrNone)
|
|
96 |
{
|
|
97 |
delete config;
|
|
98 |
LOG_MSG("CDexcFormatter::ConstructL - unable to append dump ascii config option!\n" );
|
|
99 |
User::Leave(err);
|
|
100 |
}
|
|
101 |
iAsciiStack = EFalse;
|
|
102 |
}
|
|
103 |
|
|
104 |
/**
|
|
105 |
dtor frees config parameter list
|
|
106 |
*/
|
|
107 |
CDexcFormatter::~CDexcFormatter()
|
|
108 |
{
|
|
109 |
LOG_MSG("->~CDexcFormatter()\n");
|
|
110 |
iConfigList.ResetAndDestroy();
|
|
111 |
}
|
|
112 |
|
|
113 |
/**
|
|
114 |
Sets pointer to the writer plugin.
|
|
115 |
Configures formatter's dump data save plugin.
|
|
116 |
|
|
117 |
@param aDataSave pointer to writer plugin object.
|
|
118 |
@leave KErrNoMemory if aDataSave is NULL
|
|
119 |
*/
|
|
120 |
void CDexcFormatter::ConfigureDataSaveL(CCrashDataSave* aDataSave)
|
|
121 |
{
|
|
122 |
LOG_MSG2("->ConfigureDataSaveL(%d)\n", aDataSave);
|
|
123 |
User::LeaveIfNull(aDataSave);
|
|
124 |
iDataSave = aDataSave;
|
|
125 |
}
|
|
126 |
|
|
127 |
/**
|
|
128 |
Sets pointer to the crash data server.
|
|
129 |
Configures formatter's crash data source plugin.
|
|
130 |
|
|
131 |
@param aDataSource pointer to core dump server object.
|
|
132 |
@leave KErrNoMemory if aDataSource is NULL
|
|
133 |
*/
|
|
134 |
void CDexcFormatter::ConfigureDataSourceL(CCrashDataSource* aDataSource)
|
|
135 |
{
|
|
136 |
LOG_MSG2("->ConfigureDataSourceL(%d)\n", aDataSource);
|
|
137 |
User::LeaveIfNull(aDataSource);
|
|
138 |
iDataSource = aDataSource;
|
|
139 |
}
|
|
140 |
|
|
141 |
/**
|
|
142 |
Returns a short formatter description.
|
|
143 |
@param aPluginDescription Descriptor capable of storing a short plugin description.
|
|
144 |
*/
|
|
145 |
void CDexcFormatter::GetDescription(TDes& aPluginDescription)
|
|
146 |
{
|
|
147 |
LOG_MSG("->CDexcFormatter::GetDescription()\n");
|
|
148 |
aPluginDescription.Copy(KPluginDescription());
|
|
149 |
}
|
|
150 |
|
|
151 |
|
|
152 |
/**
|
|
153 |
Called by CDS to ask for the configuration parameters that the writer needs (see Plugin Configuration)
|
|
154 |
@return actual number of implemented config parameters
|
|
155 |
*/
|
|
156 |
TInt CDexcFormatter::GetNumberConfigParametersL( )
|
|
157 |
{
|
|
158 |
TInt count = iConfigList.Count();
|
|
159 |
LOG_MSG2("->CDexcFormatter::GetNumberConfigParametersL() : returns:%d\n", count );
|
|
160 |
return count;
|
|
161 |
}
|
|
162 |
|
|
163 |
|
|
164 |
/**
|
|
165 |
Called by CDS to ask for configuration parameter prompt (see Plugin Configuration)
|
|
166 |
|
|
167 |
@param aIndex indicates which parameter to return
|
|
168 |
@return pointer to COptionConfig object representing the requested config parameter. Caller doesn't take ownership of the object!
|
|
169 |
@leave KErrBadHandle if index is out of bounds
|
|
170 |
@see COptionConfig
|
|
171 |
*/
|
|
172 |
COptionConfig * CDexcFormatter::GetConfigParameterL( const TInt aIndex )
|
|
173 |
{
|
|
174 |
// return the config identified by aIndex
|
|
175 |
if( ( aIndex < 0 ) || ( aIndex >= iConfigList.Count() ) )
|
|
176 |
{
|
|
177 |
User::Leave( KErrBadHandle );
|
|
178 |
}
|
|
179 |
|
|
180 |
return iConfigList[aIndex];
|
|
181 |
}
|
|
182 |
|
|
183 |
/**
|
|
184 |
Change a configuration parameter.
|
|
185 |
@param aIndex Index of parameter to change
|
|
186 |
@param aValue Unused
|
|
187 |
@param aDescValue Path and filename to use
|
|
188 |
@leave KErrBadHandle if index is out of bounds or one of the other system wide error codes
|
|
189 |
*/
|
|
190 |
void CDexcFormatter::SetConfigParameterL( const TInt aIndex, const TInt32 & aValue, const TDesC & aDescValue )
|
|
191 |
{
|
|
192 |
if( ( aIndex < 0 ) || ( aIndex >= iConfigList.Count() ) )
|
|
193 |
{
|
|
194 |
User::Leave( KErrBadHandle );
|
|
195 |
}
|
|
196 |
|
|
197 |
COptionConfig & config = *(iConfigList[aIndex]);
|
|
198 |
|
|
199 |
if( ( aIndex != (TInt)EDumpStack ) && ( aIndex != (TInt)EAsciiStack ) )
|
|
200 |
{
|
|
201 |
LOG_MSG( " Leaving : aIndex != EDumpStack && aIndex != EAsciiStack" );
|
|
202 |
User::Leave( KErrArgument );
|
|
203 |
}
|
|
204 |
|
|
205 |
TBool setTo = ETrue;
|
|
206 |
|
|
207 |
if( aDescValue.Length() )
|
|
208 |
{
|
|
209 |
if( 0 == aDescValue.CompareF(_L("True") ) )
|
|
210 |
{
|
|
211 |
setTo = ETrue;
|
|
212 |
//LOG_MSG( " 0 == aDescValue.CompareF(_L(True" );
|
|
213 |
}
|
|
214 |
else if( 0 == aDescValue.CompareF(_L("False") ) )
|
|
215 |
{
|
|
216 |
//LOG_MSG( " 0 == aDescValue.CompareF(_L(False" );
|
|
217 |
setTo = EFalse;
|
|
218 |
}
|
|
219 |
else
|
|
220 |
{
|
|
221 |
LOG_MSG( " ERROR !* : CDexcFormatter::SetConfigParameterL : Invalid string for boolean" );
|
|
222 |
User::Leave( KErrArgument );
|
|
223 |
}
|
|
224 |
}
|
|
225 |
else
|
|
226 |
{
|
|
227 |
if( 1 == aValue )
|
|
228 |
{
|
|
229 |
//LOG_MSG( " 1 == aValue" );
|
|
230 |
setTo = ETrue;
|
|
231 |
}
|
|
232 |
else if ( 0 == aValue )
|
|
233 |
{
|
|
234 |
//LOG_MSG( " 0 == aValue " );
|
|
235 |
setTo = EFalse;
|
|
236 |
}
|
|
237 |
else
|
|
238 |
{
|
|
239 |
LOG_MSG( " Value of %d not valid. Must be 0 or 1\n" );
|
|
240 |
User::Leave( KErrArgument );
|
|
241 |
}
|
|
242 |
}
|
|
243 |
|
|
244 |
|
|
245 |
if( setTo )
|
|
246 |
{
|
|
247 |
config.Value( 1 );
|
|
248 |
config.ValueL( _L("True") );
|
|
249 |
}
|
|
250 |
else
|
|
251 |
{
|
|
252 |
config.Value( 0 );
|
|
253 |
config.ValueL( _L("False") );
|
|
254 |
}
|
|
255 |
|
|
256 |
if( aIndex == (TInt)EDumpStack )
|
|
257 |
{
|
|
258 |
iDumpStack = config.ValueAsBool();
|
|
259 |
}
|
|
260 |
else if( aIndex == (TInt)EAsciiStack )
|
|
261 |
{
|
|
262 |
iAsciiStack = config.ValueAsBool();
|
|
263 |
}
|
|
264 |
}
|
|
265 |
|
|
266 |
/**
|
|
267 |
Dumps basic information about the thread that crashed.
|
|
268 |
@param aThread TThreadInfo data structure holding information about the crashed thread.
|
|
269 |
@leave err one of the system wide error codes
|
|
270 |
*/
|
|
271 |
void CDexcFormatter::DumpLogL(const CThreadInfo& aThread)
|
|
272 |
{
|
|
273 |
LOG_MSG("->DumpLogL()\n");
|
|
274 |
iLine.Fill('-', 76);
|
|
275 |
iDataSave->WriteL(iLine);
|
|
276 |
|
|
277 |
_LIT8(KHdr, "\r\nEKA2 USER CRASH LOG\r\n");
|
|
278 |
iLine = KHdr;
|
|
279 |
iDataSave->WriteL(iLine);
|
|
280 |
|
|
281 |
RBuf8 filename;
|
|
282 |
filename.CreateL(KMaxFileName);
|
|
283 |
filename.Copy(aThread.Name());
|
|
284 |
_LIT8(KName, "Thread Name: %S\r\n");
|
|
285 |
iLine.Format(KName, &filename);
|
|
286 |
filename.Close();
|
|
287 |
iDataSave->WriteL(iLine);
|
|
288 |
|
|
289 |
_LIT8(KFmtTid, "Thread ID: %u\r\n");
|
|
290 |
iLine.Format(KFmtTid, aThread.Id());
|
|
291 |
iDataSave->WriteL(iLine);
|
|
292 |
|
|
293 |
_LIT8(KFmtStack, "User Stack %08X-%08X\r\n");
|
|
294 |
iLine.Format(KFmtStack, aThread.UsrStackAddr(), aThread.UsrStackAddr() + aThread.UsrStackSize());
|
|
295 |
iDataSave->WriteL(iLine);
|
|
296 |
}
|
|
297 |
/**
|
|
298 |
Dumps panic details.
|
|
299 |
@param aCrash TCrashInfo data structure holding information about the crash.
|
|
300 |
@leave err one of the system wide error codes
|
|
301 |
*/
|
|
302 |
void CDexcFormatter::DumpPanicInfoL(const TCrashInfo& aCrash)
|
|
303 |
{
|
|
304 |
LOG_MSG("->DumpPanicInfoL()\n");
|
|
305 |
//_LIT8(KFmtPanic, "\r\nPanic: %S-%d\r\n");
|
|
306 |
_LIT8(KFmtPanic, "Panic: %S-%d\r\n");
|
|
307 |
RBuf8 buf;
|
|
308 |
buf.CreateL(aCrash.iCategory.Length());
|
|
309 |
buf.Copy(aCrash.iCategory);
|
|
310 |
iLine.Format(KFmtPanic, &buf, aCrash.iReason);
|
|
311 |
buf.Close();
|
|
312 |
iDataSave->WriteL(iLine);
|
|
313 |
}
|
|
314 |
|
|
315 |
/**
|
|
316 |
Picks registers from available register list and puts them in the required register list.
|
|
317 |
Order of the output list is determined by the order of aReqIds.
|
|
318 |
|
|
319 |
@param aAllRegs input RRegisterList of all available registers.
|
|
320 |
@param aReqRegs output RRegisterList for the required registers.
|
|
321 |
@param aReqIds EDF_Register_Last terminated array of IDs of required registers.
|
|
322 |
@return KErrNone if successful, otherwise one of the other system-wide error codes.
|
|
323 |
*/
|
|
324 |
TInt CDexcFormatter::PickRegisters(const RRegisterList& aAllRegs, RRegisterList& aReqRegs,
|
|
325 |
const TFunctionalityRegister* const aReqIds) const
|
|
326 |
{
|
|
327 |
LOG_MSG("->CDexcFormatter::PickRegistersL()\n");
|
|
328 |
if(aReqIds == NULL)
|
|
329 |
{
|
|
330 |
return KErrArgument;
|
|
331 |
}
|
|
332 |
|
|
333 |
TInt regsCount = aAllRegs.Count();
|
|
334 |
const TFunctionalityRegister* reg;
|
|
335 |
for(reg = aReqIds; *reg != ERegisterLast; ++reg)
|
|
336 |
{
|
|
337 |
for(TInt i = 0; i < regsCount; ++i)
|
|
338 |
{
|
|
339 |
if(aAllRegs[i].GetId() == *reg)
|
|
340 |
{
|
|
341 |
aReqRegs.Append(aAllRegs[i]);
|
|
342 |
break;
|
|
343 |
}
|
|
344 |
}
|
|
345 |
}
|
|
346 |
|
|
347 |
if(aReqRegs.Count() != (reg - aReqIds))
|
|
348 |
{
|
|
349 |
LOG_MSG3("CDExcFormatter::PickRegisters - found only %d out of %d registers!\n", aReqRegs.Count(), (reg - aReqIds));
|
|
350 |
return KErrNotFound;
|
|
351 |
}
|
|
352 |
return KErrNone;
|
|
353 |
}
|
|
354 |
|
|
355 |
/**
|
|
356 |
Dumps exception details. Valid on ARM platform only!
|
|
357 |
|
|
358 |
@param aCrash TCrashInfo data structure holding information about the crash event.
|
|
359 |
@leave err one of the system wide error codes
|
|
360 |
*/
|
|
361 |
void CDexcFormatter::DumpExcInfoL(const TCrashInfo& aCrash)
|
|
362 |
{
|
|
363 |
LOG_MSG("-> CDexcFormatter::DumpExcInfoL()\n");
|
|
364 |
|
|
365 |
_LIT8(KHdr, "\r\nUNHANDLED EXCEPTION:\r\n");
|
|
366 |
iLine = KHdr;
|
|
367 |
iDataSave->WriteL(iLine);
|
|
368 |
|
|
369 |
_LIT8(KFmt1, "code=%d PC=%08x FAR=%08x FSR=%08x\r\n");
|
|
370 |
iLine.Format(KFmt1, aCrash.iContext.iExcCode,
|
|
371 |
aCrash.iContext.iR15,
|
|
372 |
aCrash.iContext.iFaultAddress,
|
|
373 |
aCrash.iContext.iFaultStatus);
|
|
374 |
iDataSave->WriteL(iLine);
|
|
375 |
|
|
376 |
_LIT8(KFmt2, "R13svc=%08x R14svc=%08x SPSRsvc=%08x\r\n");
|
|
377 |
iLine.Format(KFmt2, aCrash.iContext.iR13Svc,
|
|
378 |
aCrash.iContext.iR14Svc,
|
|
379 |
aCrash.iContext.iSpsrSvc);
|
|
380 |
iDataSave->WriteL(iLine);
|
|
381 |
|
|
382 |
LOG_MSG("<- CDexcFormatter::DumpExcInfoL()\n");
|
|
383 |
}
|
|
384 |
|
|
385 |
/**
|
|
386 |
Dumps register values of the crashed thread. Valid on ARM platform only!
|
|
387 |
@param aTid ID of the crashed thread
|
|
388 |
@leave err one of the system wide error codes
|
|
389 |
*/
|
|
390 |
void CDexcFormatter::DumpRegistersL(const TUint64 aTid)
|
|
391 |
{
|
|
392 |
LOG_MSG2("-> CDexcFormatter::DumpRegistersL(%Lu)\n", aTid);
|
|
393 |
|
|
394 |
TFunctionalityRegister ids[] = {ERegisterR0,
|
|
395 |
ERegisterR1,
|
|
396 |
ERegisterR2,
|
|
397 |
ERegisterR3,
|
|
398 |
ERegisterR4,
|
|
399 |
ERegisterR5,
|
|
400 |
ERegisterR6,
|
|
401 |
ERegisterR7,
|
|
402 |
ERegisterR8,
|
|
403 |
ERegisterR9,
|
|
404 |
ERegisterR10,
|
|
405 |
ERegisterR11,
|
|
406 |
ERegisterR12,
|
|
407 |
ERegisterR13,
|
|
408 |
ERegisterR14,
|
|
409 |
ERegisterR15,
|
|
410 |
ERegisterCpsr,
|
|
411 |
ERegisterLast};
|
|
412 |
|
|
413 |
RRegisterList allRegs;
|
|
414 |
CleanupClosePushL(allRegs);
|
|
415 |
RRegisterList reqRegs;
|
|
416 |
CleanupClosePushL(reqRegs);
|
|
417 |
|
|
418 |
_LIT8(KHdr, "\r\nUSER REGISTERS:\r\n");
|
|
419 |
iLine = KHdr;
|
|
420 |
iDataSave->WriteL(iLine);
|
|
421 |
|
|
422 |
LOG_MSG("CDexcFormatter::DumpRegistersL - getting list of avaliable registers\n");
|
|
423 |
iDataSource->GetRegisterListL(allRegs);
|
|
424 |
|
|
425 |
LOG_MSG("CDexcFormatter::DumpRegistersL - picking required registers\n");
|
|
426 |
User::LeaveIfError(PickRegisters(allRegs, reqRegs, ids));
|
|
427 |
|
|
428 |
LOG_MSG("CDexcFormatter::DumpRegistersL - reading data of required registers\n");
|
|
429 |
iDataSource->ReadRegistersL(aTid, reqRegs);
|
|
430 |
|
|
431 |
//display zeros when register is not available
|
|
432 |
//use AppendFormat to get rid of this macro
|
|
433 |
#define REG_VAL(i) reqRegs[i].iAvailable ? reqRegs[i].GetContent32() : 0
|
|
434 |
_LIT8(KFmtCpsr, "CPSR=%08x\r\n");
|
|
435 |
TInt regsCount = reqRegs.Count();
|
|
436 |
iLine.Format(KFmtCpsr, REG_VAL(regsCount - 1));
|
|
437 |
iDataSave->WriteL(iLine);
|
|
438 |
|
|
439 |
regsCount -= 4;
|
|
440 |
for(TInt i = 0; i < regsCount; i+=4)
|
|
441 |
{
|
|
442 |
_LIT8(KFmtReg, "r%02d=%08x %08x %08x %08x\r\n");
|
|
443 |
iLine.Format(KFmtReg, i, REG_VAL(i), REG_VAL(i+1), REG_VAL(i+2), REG_VAL(i+3));
|
|
444 |
iDataSave->WriteL(iLine);
|
|
445 |
}
|
|
446 |
#undef REG_VAL
|
|
447 |
CleanupStack::PopAndDestroy(2, &allRegs);
|
|
448 |
}
|
|
449 |
|
|
450 |
/**
|
|
451 |
Cleanup item implementation for code segment list in DumpCodeSegsL() method.
|
|
452 |
@param aArray pointer to the list that is supposed to be freed
|
|
453 |
*/
|
|
454 |
void CDexcFormatter::CleanupCodeSegList(TAny *aArray)
|
|
455 |
{
|
|
456 |
LOG_MSG("->CDexcFormatter::CleanupCodeSegList()\n");
|
|
457 |
RCodeSegPointerList *codeSegList = static_cast<RCodeSegPointerList*> (aArray);
|
|
458 |
codeSegList->ResetAndDestroy();
|
|
459 |
codeSegList->Close();
|
|
460 |
}
|
|
461 |
|
|
462 |
/**
|
|
463 |
Dumps code segments of the process that owned the crashed thread.
|
|
464 |
@param aTid ID of the crashed thread
|
|
465 |
@leave err one of the system wide error codes
|
|
466 |
*/
|
|
467 |
void CDexcFormatter::DumpCodeSegsL(const TUint64 aTid)
|
|
468 |
{
|
|
469 |
LOG_MSG2("-> CDexcFormatter::DumpCodeSegsL(%Lu)\n", aTid);
|
|
470 |
_LIT8(KHdr, "\r\nCODE SEGMENTS:\r\n");
|
|
471 |
_LIT8(KFmtSegs, "%08X-%08X %S\r\n");
|
|
472 |
|
|
473 |
iLine = KHdr;
|
|
474 |
iDataSave->WriteL(iLine);
|
|
475 |
|
|
476 |
RCodeSegPointerList segs;
|
|
477 |
TCleanupItem cleanup(CDexcFormatter::CleanupCodeSegList, (TAny*)&segs);
|
|
478 |
CleanupStack::PushL(cleanup);
|
|
479 |
|
|
480 |
//User::LeaveIfError(iDataSource->GetCodeSegments(aPid, segs));
|
|
481 |
LOG_MSG("CDexcFormatter::DumpCodeSegsL() - getting code segments data\n");
|
|
482 |
iDataSource->GetCodeSegmentsL(aTid, segs);
|
|
483 |
|
|
484 |
RBuf8 filename;
|
|
485 |
CleanupClosePushL(filename);
|
|
486 |
filename.CreateL(KMaxFileName);
|
|
487 |
for (TInt i=0; i < segs.Count(); i++)
|
|
488 |
{
|
|
489 |
filename.Copy(segs[i]->iName); //conversion
|
|
490 |
iLine.Format(KFmtSegs, segs[i]->iCodeRunAddr, segs[i]->iCodeRunAddr + segs[i]->iCodeSize, &filename);
|
|
491 |
iDataSave->WriteL(iLine);
|
|
492 |
}
|
|
493 |
LOG_MSG2("CDexcFormatter::DumpCodeSegsL - code segments count:%d\n", segs.Count());
|
|
494 |
CleanupStack::PopAndDestroy(2);
|
|
495 |
|
|
496 |
//compatibility with legacy D_EXC implementation
|
|
497 |
iLine.Zero();
|
|
498 |
iLine.Append(_L8("\r\n"));
|
|
499 |
iDataSave->WriteL(iLine);
|
|
500 |
}
|
|
501 |
|
|
502 |
/**
|
|
503 |
Dumps thread stack information and content.
|
|
504 |
@param aTid ID of the crashed thread
|
|
505 |
@param aInfo CThreadInfo data structure holding information about the crashed thread
|
|
506 |
@leave err one of the system wide error codes
|
|
507 |
*/
|
|
508 |
void CDexcFormatter::DumpStackL(const TUint64 aTid, const CThreadInfo& aInfo)
|
|
509 |
{
|
|
510 |
LOG_MSG2("-> CDexcFormatter::DumpStackL(%Lu)\n", aTid);
|
|
511 |
|
|
512 |
TInt length = KBufSize < aInfo.UsrStackSize() ? KBufSize : aInfo.UsrStackSize();
|
|
513 |
|
|
514 |
RBuf8 buf;
|
|
515 |
buf.CreateL(length);
|
|
516 |
CleanupClosePushL(buf);
|
|
517 |
|
|
518 |
TUint top = aInfo.UsrStackAddr() + aInfo.UsrStackSize();
|
|
519 |
for(TUint base = aInfo.UsrStackAddr(); base < top; base += KBufSize)
|
|
520 |
{
|
|
521 |
LOG_MSG3("CDexcFormatter::DumpStackL - reading %d bytes of memory from:0x%X\n", length, base);
|
|
522 |
iDataSource->ReadMemoryL(aTid, base, length, buf);
|
|
523 |
|
|
524 |
//6571de54: 07 00 00 10 14 04 17 f8 00 00 00 00 d4 4e 40 00 .............N@.
|
|
525 |
//<-addr-------------------------memory----------------------representation>
|
|
526 |
if(iAsciiStack)
|
|
527 |
{
|
|
528 |
TBuf8<80> out; //74 used
|
|
529 |
TBuf8<20> ascii; //16 usd
|
|
530 |
TInt len = buf.Length();
|
|
531 |
for(TUint offset = 0; offset < len; offset += 16)
|
|
532 |
{
|
|
533 |
out.Zero();
|
|
534 |
ascii.Zero();
|
|
535 |
out.AppendNumFixedWidth(base + offset, EHex, 8); //addr
|
|
536 |
out.Append(_L(": "));
|
|
537 |
|
|
538 |
for(TUint byte = 0; byte < 16; ++byte)
|
|
539 |
{
|
|
540 |
TUint8 c = *(buf.Ptr() + offset + byte);
|
|
541 |
out.AppendNumFixedWidth(c, EHex, 2); //each memory byte
|
|
542 |
out.Append(' ');
|
|
543 |
|
|
544 |
if(c < 0x20 || c >= 0x7f) //something writable
|
|
545 |
c = 0x2e; //.
|
|
546 |
ascii.Append(TChar(c)); //byte representation
|
|
547 |
}
|
|
548 |
out.Append(ascii);
|
|
549 |
out.Append(_L("\r\n"));
|
|
550 |
iDataSave->WriteL(out);
|
|
551 |
}
|
|
552 |
}
|
|
553 |
else //binary dump
|
|
554 |
iDataSave->WriteL(buf);
|
|
555 |
}
|
|
556 |
CleanupStack::PopAndDestroy(&buf);
|
|
557 |
}
|
|
558 |
|
|
559 |
/**
|
|
560 |
Retrives the 'cancel crash' property value and checks if required to abort the crash dump. Updates 'crash progress' property.
|
|
561 |
|
|
562 |
@param aProgress descriptor with the crash progress value.
|
|
563 |
@leave KErrAbort if crash cancel property has been set
|
|
564 |
*/
|
|
565 |
void CDexcFormatter::UpdateCrashProgressL(const TDesC &aProgress) const
|
|
566 |
{
|
|
567 |
LOG_MSG("->CDexcFormatter::UpdateCrashProgress()\n");
|
|
568 |
TInt cancelCrash = EFalse;
|
|
569 |
TInt err = RProperty::Get(KCoreDumpServUid, ECancelCrash, cancelCrash);
|
|
570 |
if(err != KErrNone)
|
|
571 |
{
|
|
572 |
LOG_MSG2("CDexcFormatter::UpdateCrashProgress - unable to retrive 'cancel crash' value! err:%d\n", err);
|
|
573 |
}
|
|
574 |
|
|
575 |
if(cancelCrash)
|
|
576 |
{
|
|
577 |
LOG_MSG("CDexcFormatter::UpdateCrashProgress - aborting dump in progress\n");
|
|
578 |
User::Leave(KErrAbort);
|
|
579 |
}
|
|
580 |
|
|
581 |
err = RProperty::Set(KCoreDumpServUid, ECrashProgress, aProgress);
|
|
582 |
if(err != KErrNone)
|
|
583 |
{
|
|
584 |
LOG_MSG2("CDexcFormatter::UpdateCrashProgress - unable to retrive 'crash progress' value! err:%d\n", err);
|
|
585 |
}
|
|
586 |
#ifdef DEBUG
|
|
587 |
User::After(1000000);
|
|
588 |
#endif
|
|
589 |
}
|
|
590 |
|
|
591 |
/**
|
|
592 |
Gets information about the threads of the crashed process and finds the one that caused the crash.
|
|
593 |
@return reference to the CThreadInfo data structure holding information about the crashed thread
|
|
594 |
@leave err one of the system wide error codes
|
|
595 |
*/
|
|
596 |
const CThreadInfo& CDexcFormatter::GetCrashedThreadInfoLC(const TCrashInfo &aCrashInfo) const
|
|
597 |
{
|
|
598 |
LOG_MSG("->CDexcFormatter::GetCrashedThreadInfoLC()\n");
|
|
599 |
|
|
600 |
RThreadPointerList *threadList = new(ELeave)RThreadPointerList;
|
|
601 |
TCleanupItem cleanup(CDexcFormatter::CleanupThreadList, (TAny*)threadList);
|
|
602 |
CleanupStack::PushL(cleanup);
|
|
603 |
|
|
604 |
CThreadInfo *threadInfo = NULL;
|
|
605 |
TUint totalThreadListDescSize;
|
|
606 |
iDataSource->GetThreadListL((TUint64)aCrashInfo.iPid, *threadList, totalThreadListDescSize); //for crashed process
|
|
607 |
|
|
608 |
for(TInt i = 0; i < threadList->Count(); i++)
|
|
609 |
{
|
|
610 |
if(aCrashInfo.iTid == (*threadList)[i]->Id())
|
|
611 |
{
|
|
612 |
threadInfo = (*threadList)[i]; //crashed thread
|
|
613 |
break;
|
|
614 |
}
|
|
615 |
}
|
|
616 |
|
|
617 |
if(NULL == threadInfo)
|
|
618 |
{
|
|
619 |
LOG_MSG("CDexcFormatter::CrashEventL - crashed thread not found!\n");
|
|
620 |
User::Leave( KErrNotFound );
|
|
621 |
}
|
|
622 |
|
|
623 |
return *threadInfo;
|
|
624 |
}
|
|
625 |
|
|
626 |
/**
|
|
627 |
Prepares the name of the dump file. Checks DataSave filename option, if it is provided by the user
|
|
628 |
it appends crashed thread ID and extension, if not it uses default name appended with thread ID and extension.
|
|
629 |
@param aTid ID of the crashed thread
|
|
630 |
@param aExtension descriptor holding the file extension
|
|
631 |
@return descriptor holding the final dump file name, caller is responsible to pop it from the cleanup stack
|
|
632 |
@leave err one of the system wide error codes
|
|
633 |
*/
|
|
634 |
const TDesC& CDexcFormatter::DumpFileNameLC(TUint64 aTid, const TDesC &aExtension)
|
|
635 |
{
|
|
636 |
COptionConfig *option = iDataSave->GetConfigParameterL(CCrashDataSave::ECoreFilePath);
|
|
637 |
const TDesC &userFileName = option->ValueAsDesc();
|
|
638 |
HBufC *filename = HBufC::NewLC(userFileName.Length() + KDexcFileNameLength);
|
|
639 |
if(userFileName.Length() > 0)
|
|
640 |
{
|
|
641 |
*filename = userFileName;
|
|
642 |
_LIT(KTidFormat, "%Lu");
|
|
643 |
filename->Des().AppendFormat(KTidFormat, aTid);
|
|
644 |
}
|
|
645 |
else
|
|
646 |
{
|
|
647 |
_LIT(KTxtFileFormat, "c:\\d_exc_%Lu");
|
|
648 |
filename->Des().Format(KTxtFileFormat, aTid);
|
|
649 |
}
|
|
650 |
filename->Des().Append(aExtension);
|
|
651 |
return *filename;
|
|
652 |
}
|
|
653 |
|
|
654 |
|
|
655 |
/**
|
|
656 |
Main formatter method. Handles crash event notification and drives dump process.
|
|
657 |
|
|
658 |
@param aCrashInfo pointer to the TCrashInfo data structure holding information about the crash.
|
|
659 |
@leave err one of the system wide error codes
|
|
660 |
*/
|
|
661 |
void CDexcFormatter::CrashEventL(TCrashInfo *aCrashInfo)
|
|
662 |
{
|
|
663 |
LOG_MSG("-> CrashEventL()\n");
|
|
664 |
|
|
665 |
User::LeaveIfNull(aCrashInfo);
|
|
666 |
LOG_MSG("CDexcFormatter::CrashEvenL - crash info is sane\n");
|
|
667 |
User::LeaveIfNull(iDataSource);
|
|
668 |
LOG_MSG("CDexcFormatter::CrashEvenL - data source is sane\n");
|
|
669 |
User::LeaveIfNull(iDataSave);
|
|
670 |
LOG_MSG("CDexcFormatter::CrashEvenL - data save is sane\n");
|
|
671 |
|
|
672 |
_LIT(KProgressStart, "crash dump started");
|
|
673 |
UpdateCrashProgressL(KProgressStart);
|
|
674 |
|
|
675 |
const CThreadInfo &threadInfo = GetCrashedThreadInfoLC(*aCrashInfo);
|
|
676 |
_LIT(KProgressText, "dumping text file");
|
|
677 |
UpdateCrashProgressL(KProgressText);
|
|
678 |
|
|
679 |
LOG_MSG("CDexcFormatter::CrashEventL - opening text file\n");
|
|
680 |
_LIT(KTxtFileExt, ".txt");
|
|
681 |
iDataSave->OpenL(DumpFileNameLC(aCrashInfo->iTid, KTxtFileExt));
|
|
682 |
CleanupStack::PopAndDestroy(); //filename
|
|
683 |
DumpLogL(threadInfo);
|
|
684 |
|
|
685 |
if(aCrashInfo->iType == TCrashInfo::ECrashKill)
|
|
686 |
{
|
|
687 |
LOG_MSG("CDexcFormatter::CrashEventL - dumping panic info\n");
|
|
688 |
DumpPanicInfoL(*aCrashInfo);
|
|
689 |
}
|
|
690 |
#ifdef __MARM__
|
|
691 |
else //ECrashException
|
|
692 |
{
|
|
693 |
LOG_MSG("CDexcFormatter::CrashEventL - dumping exeception info\n");
|
|
694 |
DumpExcInfoL(*aCrashInfo);
|
|
695 |
}
|
|
696 |
LOG_MSG("CDexcFormatter::CrashEventL - dumping registers info\n");
|
|
697 |
DumpRegistersL(aCrashInfo->iTid);
|
|
698 |
#endif
|
|
699 |
LOG_MSG("CDexcFormatter::CrashEventL - dumping code segments info\n");
|
|
700 |
DumpCodeSegsL(aCrashInfo->iTid);
|
|
701 |
|
|
702 |
LOG_MSG("CDexcFormatter::CrashEventL - closing text file\n");
|
|
703 |
iDataSave->CloseL();
|
|
704 |
|
|
705 |
if(iDumpStack)
|
|
706 |
{
|
|
707 |
_LIT(KProgressStack, "dumping stack file");
|
|
708 |
UpdateCrashProgressL(KProgressStack);
|
|
709 |
LOG_MSG("CDexcFormatter::CrashEventL - opening stack file\n");
|
|
710 |
_LIT(KStkFileExt, ".stk");
|
|
711 |
iDataSave->OpenL(DumpFileNameLC(aCrashInfo->iTid, KStkFileExt));
|
|
712 |
CleanupStack::PopAndDestroy();//filename
|
|
713 |
LOG_MSG("CDexcFormatter::CrashEventL - dumping stack\n");
|
|
714 |
DumpStackL(aCrashInfo->iTid, threadInfo);
|
|
715 |
LOG_MSG("CDexcFormatter::CrashEventL - closing stack file\n");
|
|
716 |
iDataSave->CloseL();
|
|
717 |
}
|
|
718 |
_LIT(KProgressCompleted, "crash dump completed");
|
|
719 |
UpdateCrashProgressL(KProgressCompleted);
|
|
720 |
CleanupStack::PopAndDestroy(); //GetCrashedThreadInfoLC()::threadList , results in a call to CleanupThreadList
|
|
721 |
LOG_MSG("CDexcFormatter::CrashEventL - crash finished\n");
|
|
722 |
}
|
|
723 |
|
|
724 |
/**
|
|
725 |
Cleanup item implementation for thread list in CrashEventL() method.
|
|
726 |
@param aArray pointer to the list that is supposed to be freed
|
|
727 |
*/
|
|
728 |
void CDexcFormatter::CleanupThreadList(TAny *aArray)
|
|
729 |
{
|
|
730 |
LOG_MSG("->CDexcFormatter::CleanupThreadList()\n");
|
|
731 |
RThreadPointerList *threadList = static_cast<RThreadPointerList*> (aArray);
|
|
732 |
threadList->ResetAndDestroy();
|
|
733 |
threadList->Close();
|
|
734 |
delete threadList;
|
|
735 |
}
|
|
736 |
|