0
|
1 |
// Copyright (c) 2008-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 <e32debug.h>
|
|
17 |
#include <d32btrace.h>
|
|
18 |
#include <crashlogwalker.h>
|
|
19 |
#include <optionconfig.h>
|
|
20 |
#include "flashdatasource.h"
|
|
21 |
|
|
22 |
// Required for interface to Debug Security Server via RSecuritySvrSession
|
|
23 |
#include "coredumpsession.h"
|
|
24 |
|
|
25 |
using namespace Debug;
|
|
26 |
|
|
27 |
CFlashDataSource::CFlashDataSource(RSecuritySvrSession &aSource) :
|
|
28 |
iSecSess(aSource),
|
|
29 |
iLockData(NULL),
|
|
30 |
iRomBuildInfo(NULL),
|
|
31 |
iTraceDump(NULL),
|
|
32 |
iVarSpecData(NULL),
|
|
33 |
iWalker(iFlashBuf),
|
|
34 |
iScmConfig(NULL),
|
|
35 |
iCrashFound(EFalse)
|
|
36 |
{
|
|
37 |
//no implementation
|
|
38 |
}
|
|
39 |
|
|
40 |
/**
|
|
41 |
* This looks at the crash logs header and keeps note of where all the different types of data reside
|
|
42 |
* @return one of the OS wide system codes
|
|
43 |
*/
|
|
44 |
TInt CFlashDataSource::ProcessCrashHeaderL(TInt aCrashStart)
|
|
45 |
{
|
|
46 |
LOG_MSG("CFlashDataSource::ProcessCrashHeader()");
|
|
47 |
|
|
48 |
//record where the crash started
|
|
49 |
TInt iCrashStart = aCrashStart;
|
|
50 |
|
|
51 |
User::LeaveIfError(ReadCrashLog(iCrashStart, Debug::KMaxCoreHeaderSize));
|
|
52 |
User::LeaveIfError(iWalker.ReadLogHeader(0));
|
|
53 |
|
|
54 |
iHdr = iWalker.GetCrashHeader();
|
|
55 |
iOffsetsHdr = iWalker.GetOffsetsHeader();
|
|
56 |
|
|
57 |
if(iOffsetsHdr.iId == ESCMOffsetsHeader)
|
|
58 |
{
|
|
59 |
iOffsetsPresent = ETrue;
|
|
60 |
}
|
|
61 |
|
|
62 |
return KErrNone;
|
|
63 |
}
|
|
64 |
|
|
65 |
/**
|
|
66 |
* attempts to read the scm config block from start of flash to see if its there
|
|
67 |
* @return The configuration block if found. Check for NULL and ownership is passed to caller
|
|
68 |
*/
|
|
69 |
SCMConfiguration* CFlashDataSource::GetSCMConfigFromFlashL()
|
|
70 |
{
|
|
71 |
LOG_MSG("CFlashDataSource::GetSCMConfigFromFlashL()");
|
|
72 |
|
|
73 |
//Always at start of flash
|
|
74 |
TInt scmLocation = 0;
|
|
75 |
Debug::SCMConfiguration* config = new Debug::SCMConfiguration();
|
|
76 |
CleanupStack::PushL(config);
|
|
77 |
|
|
78 |
User::LeaveIfError(ReadCrashLog(scmLocation, SCMConfiguration::KScmConfigMaxSize));
|
|
79 |
CleanupStack::Pop();
|
|
80 |
//Put a reader on the buffer
|
|
81 |
TByteStreamReader rdr(const_cast<TUint8*>(iFlashBuf.Ptr()));
|
|
82 |
if(config->Deserialize(rdr) == KErrNone)
|
|
83 |
{
|
|
84 |
|
|
85 |
LOG_MSG3("CFlashDataSource::GetSCMConfigFromFlashL() Config found. It is [%d] [0x%X] bytes in size",
|
|
86 |
config->GetSize(), config->GetSize());
|
|
87 |
|
|
88 |
LOG_MSG("CFlashDataSource::GetSCMConfigFromFlashL() #2");
|
|
89 |
return config;
|
|
90 |
}
|
|
91 |
else
|
|
92 |
{
|
|
93 |
LOG_MSG("CFlashDataSource::GetSCMConfigFromFlashL() No config found");
|
|
94 |
delete config;
|
|
95 |
return NULL;
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
/**
|
|
100 |
* This looks at the entire log partition looking for where the crash of this ID
|
|
101 |
* begins
|
|
102 |
* @param aCrashId ID we are looking for
|
|
103 |
* @return TInt where crash starts
|
|
104 |
* @leave One of the OS wide codes
|
|
105 |
*/
|
|
106 |
TInt CFlashDataSource::GetCrashStartFromCrashIDL(TInt aCrashId)
|
|
107 |
{
|
|
108 |
LOG_MSG2("CFlashDataSource::GetCrashStartFromCrashIDL(TInt aCrashId) ID = %d", aCrashId);
|
|
109 |
|
|
110 |
TInt crashStart = 0;
|
|
111 |
TInt readStatus = KErrNone;
|
|
112 |
|
|
113 |
//Start looking where the config ends if it exists
|
|
114 |
Debug::SCMConfiguration* config = GetSCMConfigFromFlashL();
|
|
115 |
if(config)
|
|
116 |
{
|
|
117 |
crashStart = config->GetSize();
|
|
118 |
}
|
|
119 |
|
|
120 |
delete config;
|
|
121 |
|
|
122 |
while(readStatus == KErrNone)
|
|
123 |
{
|
|
124 |
User::LeaveIfError(ReadCrashLog(crashStart, Debug::KMaxCoreHeaderSize));
|
|
125 |
|
|
126 |
readStatus = iWalker.ReadLogHeader(0); //Look at header from start of buffer
|
|
127 |
|
|
128 |
if(readStatus != KErrNone)
|
|
129 |
{
|
|
130 |
CLTRACE("CFlashDataSource::GetCrashStartFromCrashIDL ReadCrashLogL leaving with KErrNotFound #1");
|
|
131 |
User::Leave(KErrNotFound);
|
|
132 |
}
|
|
133 |
else if(iWalker.GetCrashHeader().iCrashId == aCrashId)
|
|
134 |
{
|
|
135 |
return crashStart;
|
|
136 |
}
|
|
137 |
|
|
138 |
const TCrashInfoHeader currentHdr = iWalker.GetCrashHeader();
|
|
139 |
|
|
140 |
TUint32 flashPadding = currentHdr.iFlashBlockSize - (crashStart + currentHdr.iLogSize)%currentHdr.iFlashBlockSize;
|
|
141 |
crashStart += (currentHdr.iLogSize + flashPadding);
|
|
142 |
}
|
|
143 |
|
|
144 |
CLTRACE("CFlashDataSource::GetCrashStartFromCrashIDL ReadCrashLogL leaving with KErrNotFound #2");
|
|
145 |
User::Leave(KErrNotFound);
|
|
146 |
|
|
147 |
return 0; //avoid comp warnings
|
|
148 |
}
|
|
149 |
|
|
150 |
/**
|
|
151 |
* This walks the crash log verifying it is not corrupt and builds up a map of the log so that we can get the
|
|
152 |
* data required faster later on when the appropriate call is made.
|
|
153 |
* @param Crash ID to look at
|
|
154 |
* @leave One of the system wide error codes
|
|
155 |
*/
|
|
156 |
void CFlashDataSource::AnalyseCrashL(TInt aCrashId)
|
|
157 |
{
|
|
158 |
LOG_MSG2("CFlashDataSource::AnalyseCrashL(TInt aCrashId = [%d])", aCrashId);
|
|
159 |
|
|
160 |
//Reset the state
|
|
161 |
iOffsetsPresent = EFalse;
|
|
162 |
iCrashMemoryMap.Reset();
|
|
163 |
iCodeSegMap.Reset();
|
|
164 |
iHdrProcd = EFalse;
|
|
165 |
|
|
166 |
if(iCurrentCodeSegSet)
|
|
167 |
{
|
|
168 |
delete iCurrentCodeSegSet;
|
|
169 |
iCurrentCodeSegSet = NULL;
|
|
170 |
}
|
|
171 |
|
|
172 |
if(iLockData)
|
|
173 |
{
|
|
174 |
delete iLockData;
|
|
175 |
iLockData = NULL;
|
|
176 |
}
|
|
177 |
|
|
178 |
if(iRomBuildInfo)
|
|
179 |
{
|
|
180 |
delete iRomBuildInfo;
|
|
181 |
iRomBuildInfo = NULL;
|
|
182 |
}
|
|
183 |
|
|
184 |
TInt crashStart = GetCrashStartFromCrashIDL(aCrashId);
|
|
185 |
ProcessCrashHeaderL(crashStart);
|
|
186 |
|
|
187 |
TInt dataSizeRead = 0;
|
|
188 |
TInt flashPos = crashStart;
|
|
189 |
|
|
190 |
//either read the defined amt or the log size, whichever is less
|
|
191 |
TInt rdSize = READ_SIZE;
|
|
192 |
|
|
193 |
/**
|
|
194 |
* Our conditions to keep reading or decide log is corrupt are:
|
|
195 |
* 1. Have we read logSize bytes?
|
|
196 |
* No - Keep Going
|
|
197 |
* Yes - Finished
|
|
198 |
* More - Corrupt
|
|
199 |
* 2. There is no more data of interest to be read. Is the number of bytes read = log size?
|
|
200 |
*/
|
|
201 |
|
|
202 |
TInt recommendedReadSize = 0;
|
|
203 |
|
|
204 |
while(dataSizeRead != iHdr.iLogSize)
|
|
205 |
{
|
|
206 |
//We need to decide how much to read here. It is possible that we need to read greater than the log size
|
|
207 |
//as the reader can't know in advance the exact size of a struct, so it has to assume the worst case scenario
|
|
208 |
//of the largest size it could be
|
|
209 |
rdSize = (rdSize < READ_SIZE) ? READ_SIZE : rdSize; //resize this to be large
|
|
210 |
|
|
211 |
TInt bytesRemaining = iHdr.iLogSize - dataSizeRead;
|
|
212 |
if(rdSize > bytesRemaining)
|
|
213 |
{
|
|
214 |
rdSize = bytesRemaining;
|
|
215 |
}
|
|
216 |
|
|
217 |
//always be at least the rec read size
|
|
218 |
rdSize = (rdSize < recommendedReadSize) ? recommendedReadSize : rdSize;
|
|
219 |
|
|
220 |
User::LeaveIfError(ReadCrashLog(flashPos, rdSize));
|
|
221 |
|
|
222 |
//Get what we can out of this buffer read
|
|
223 |
SCMStructId id = ESCMFirst;
|
|
224 |
TInt bufferPos = 0;
|
|
225 |
MByteStreamSerializable* data = NULL;
|
|
226 |
|
|
227 |
do
|
|
228 |
{
|
|
229 |
//Have we got to end of crash?
|
|
230 |
if(dataSizeRead == iHdr.iLogSize)
|
|
231 |
{
|
|
232 |
break;
|
|
233 |
}
|
|
234 |
|
|
235 |
data = iWalker.GetNextDataTypeL(bufferPos, id, recommendedReadSize);
|
|
236 |
|
|
237 |
//Analyse what we got
|
|
238 |
if(data)
|
|
239 |
{
|
|
240 |
CleanupStack::PushL(data);
|
|
241 |
dataSizeRead += data->GetSize();
|
|
242 |
|
|
243 |
//check we are within range
|
|
244 |
if(dataSizeRead > iHdr.iLogSize)
|
|
245 |
{
|
|
246 |
LOG_MSG4("CFlashDataSource::AnalyseCrashL: Corrupt --> dataSizeRead [%d] > iHdr.iLogSize [%d] at line [%d]", dataSizeRead, iHdr.iLogSize, __LINE__);
|
|
247 |
User::Leave(KErrCorrupt);
|
|
248 |
}
|
|
249 |
|
|
250 |
HelpAnalyseCrashL(data, id, flashPos + bufferPos - data->GetSize());
|
|
251 |
CleanupStack::PopAndDestroy(data);
|
|
252 |
}
|
|
253 |
else
|
|
254 |
{
|
|
255 |
//if data was NULL, that means there wasnt enough room in the buffer to read the next one
|
|
256 |
flashPos += bufferPos;
|
|
257 |
}
|
|
258 |
}
|
|
259 |
while(data);
|
|
260 |
}
|
|
261 |
}
|
|
262 |
|
|
263 |
/**
|
|
264 |
* Helper for crash analysis. Takes a pointer to a data type, an ID to tell us what type it is, and where
|
|
265 |
* in the flash it has been found. If it is a type of interest, we record its position
|
|
266 |
* @param aData Data Type of interest
|
|
267 |
* @param aStructId ID to describe data type
|
|
268 |
* @param aPosFound Where it was found in the flash
|
|
269 |
* @leave
|
|
270 |
*/
|
|
271 |
void CFlashDataSource::HelpAnalyseCrashL(const MByteStreamSerializable* aData, TInt aStructId, TInt aPosFound)
|
|
272 |
{
|
|
273 |
|
|
274 |
switch(aStructId)
|
|
275 |
{
|
|
276 |
case ESCMMemory :
|
|
277 |
{
|
|
278 |
//we want to keep track of this objects
|
|
279 |
TObjectLocation map;
|
|
280 |
map.iOffset = aPosFound;
|
|
281 |
map.iObjectId = static_cast<const TMemoryDump*>(aData)->iPid;
|
|
282 |
|
|
283 |
iCrashMemoryMap.AppendL(map);
|
|
284 |
|
|
285 |
break;
|
|
286 |
}
|
|
287 |
case ESCMCodeSegSet :
|
|
288 |
{
|
|
289 |
//The set contains the PID for the code segs to follow - copy to our cached version
|
|
290 |
if(iCurrentCodeSegSet)
|
|
291 |
{
|
|
292 |
delete iCurrentCodeSegSet;
|
|
293 |
iCurrentCodeSegSet = NULL;
|
|
294 |
}
|
|
295 |
|
|
296 |
iCurrentCodeSegSet = new TCodeSegmentSet();
|
|
297 |
*iCurrentCodeSegSet = *(static_cast<const TCodeSegmentSet*>(aData));
|
|
298 |
|
|
299 |
break;
|
|
300 |
}
|
|
301 |
case ESCMCodeSeg :
|
|
302 |
{
|
|
303 |
//ensure we have a code segment set for this
|
|
304 |
__ASSERT_ALWAYS(iCurrentCodeSegSet, User::Leave(KErrCorrupt));
|
|
305 |
|
|
306 |
//we want to keep track of these objects
|
|
307 |
TObjectLocation map;
|
|
308 |
map.iOffset = aPosFound;
|
|
309 |
map.iObjectId = iCurrentCodeSegSet->iPid;
|
|
310 |
|
|
311 |
iCodeSegMap.AppendL(map);
|
|
312 |
|
|
313 |
break;
|
|
314 |
}
|
|
315 |
case ESCMRomHeader :
|
|
316 |
{
|
|
317 |
if(iRomBuildInfo)
|
|
318 |
{
|
|
319 |
delete iRomBuildInfo;
|
|
320 |
iRomBuildInfo = NULL;
|
|
321 |
}
|
|
322 |
|
|
323 |
iRomBuildInfo = new TRomHeaderData();
|
|
324 |
*iRomBuildInfo = *(static_cast<const TRomHeaderData*>(aData));
|
|
325 |
|
|
326 |
break;
|
|
327 |
}
|
|
328 |
case ESCMLocks:
|
|
329 |
{
|
|
330 |
if(iLockData)
|
|
331 |
{
|
|
332 |
delete iLockData;
|
|
333 |
iLockData = NULL;
|
|
334 |
}
|
|
335 |
|
|
336 |
iLockData = new TSCMLockData();
|
|
337 |
*iLockData = *(static_cast<const TSCMLockData*>(aData));
|
|
338 |
|
|
339 |
break;
|
|
340 |
}
|
|
341 |
case ESCMTCrashInfo :
|
|
342 |
{
|
|
343 |
iHeaderStart = aPosFound;
|
|
344 |
|
|
345 |
break;
|
|
346 |
}
|
|
347 |
case ESCMTraceData :
|
|
348 |
{
|
|
349 |
if(iTraceDump)
|
|
350 |
{
|
|
351 |
delete iTraceDump;
|
|
352 |
iTraceDump = NULL;
|
|
353 |
}
|
|
354 |
|
|
355 |
iTraceDump = new TTraceDump();
|
|
356 |
*iTraceDump = *(static_cast<const TTraceDump*>(aData));
|
|
357 |
|
|
358 |
break;
|
|
359 |
}
|
|
360 |
case ESCMVariantData:
|
|
361 |
{
|
|
362 |
if(iVarSpecData)
|
|
363 |
{
|
|
364 |
delete iVarSpecData;
|
|
365 |
iVarSpecData = NULL;
|
|
366 |
}
|
|
367 |
|
|
368 |
iVarSpecData = new TVariantSpecificData();
|
|
369 |
*iVarSpecData = *(static_cast<const TVariantSpecificData*>(aData));
|
|
370 |
|
|
371 |
break;
|
|
372 |
}
|
|
373 |
case ESCMOffsetsHeader :
|
|
374 |
case ESCMProcessData :
|
|
375 |
case ESCMThreadData :
|
|
376 |
case ESCMThreadStack :
|
|
377 |
case ESCMRegisterValue :
|
|
378 |
case ESCMRegisterSet :
|
|
379 |
case ESCMRawData :
|
|
380 |
{
|
|
381 |
//No problem if we arent interested in the object, carry on, nothing to see here
|
|
382 |
break;
|
|
383 |
}
|
|
384 |
default :
|
|
385 |
{
|
|
386 |
LOG_MSG2("CFlashDataSource::HelpAnalyseCrashL --> Dont recognise struct ID = [%d] therefore corrupt", aStructId);
|
|
387 |
|
|
388 |
//if we dont recognise the object, then oddness is afoot and the mist of corruption reigns thick
|
|
389 |
User::Leave(KErrCorrupt);
|
|
390 |
}
|
|
391 |
}
|
|
392 |
|
|
393 |
}
|
|
394 |
|
|
395 |
/**
|
|
396 |
* This Reads the portion of the crash log of interest into our buffer for processing later
|
|
397 |
*
|
|
398 |
* @param aPos Position of crash log to begin reading
|
|
399 |
* @param aSize amount of data to read
|
|
400 |
* @return KErrArgument if aSize exceeds the maximum read allowed or one of the other OS wide codes
|
|
401 |
*/
|
|
402 |
TInt CFlashDataSource::ReadCrashLog(const TInt aPos, const TUint aSize)
|
|
403 |
{
|
|
404 |
//ensure parameters are ok
|
|
405 |
if(aPos < 0)
|
|
406 |
{
|
|
407 |
return KErrArgument;
|
|
408 |
}
|
|
409 |
|
|
410 |
TInt err = ReallocFlashBuf(aSize);
|
|
411 |
if(err != KErrNone)
|
|
412 |
{
|
|
413 |
return err;
|
|
414 |
}
|
|
415 |
|
|
416 |
iWalker.UpdateBuffer(iFlashBuf);
|
|
417 |
|
|
418 |
iFlashBuf.Zero();
|
|
419 |
|
|
420 |
//Read the data from the flash buffer
|
|
421 |
return iSecSess.ReadCrashLog(aPos, iFlashBuf, aSize);
|
|
422 |
}
|
|
423 |
|
|
424 |
/**
|
|
425 |
* Two Phase Constructor for CFlashDataSource
|
|
426 |
* @param aSource Reference to Security Server session
|
|
427 |
* @return Pointer to new CFlashDataSource object
|
|
428 |
* @leave
|
|
429 |
*/
|
|
430 |
CFlashDataSource* CFlashDataSource::NewL(RSecuritySvrSession &aSource)
|
|
431 |
{
|
|
432 |
CFlashDataSource *self = new(ELeave) CFlashDataSource(aSource);
|
|
433 |
CleanupStack::PushL(self);
|
|
434 |
self->ConstructL();
|
|
435 |
CleanupStack::Pop();
|
|
436 |
return self;
|
|
437 |
}
|
|
438 |
|
|
439 |
/**
|
|
440 |
* second-phase constructor
|
|
441 |
*/
|
|
442 |
void CFlashDataSource::ConstructL()
|
|
443 |
{
|
|
444 |
//Create flash buffer. Will be resized as required
|
|
445 |
iFlashBuf.CreateL(KInitialBufferSize);
|
|
446 |
iFlashBuf.FillZ();
|
|
447 |
|
|
448 |
iScmConfig = new (ELeave) Debug::SCMConfiguration();
|
|
449 |
iScmConfig->SetDefaultConfig();
|
|
450 |
|
|
451 |
}
|
|
452 |
|
|
453 |
/**
|
|
454 |
* Destructor
|
|
455 |
*/
|
|
456 |
CFlashDataSource::~CFlashDataSource()
|
|
457 |
{
|
|
458 |
LOG_MSG( "server_crashdatasource.cpp::CFlashDataSource::~CFlashDataSource()\n" );
|
|
459 |
iFlashBuf.Close();
|
|
460 |
iFirstBlockBuf.Close();
|
|
461 |
|
|
462 |
iCodeSegMap.Close();
|
|
463 |
iCrashMemoryMap.Close();
|
|
464 |
iThreadOwners.Close();
|
|
465 |
|
|
466 |
if(iScmConfig)
|
|
467 |
{
|
|
468 |
delete iScmConfig;
|
|
469 |
iScmConfig = NULL;
|
|
470 |
}
|
|
471 |
|
|
472 |
if(iCurrentCodeSegSet)
|
|
473 |
{
|
|
474 |
delete iCurrentCodeSegSet;
|
|
475 |
iCurrentCodeSegSet = NULL;
|
|
476 |
}
|
|
477 |
|
|
478 |
if(iLockData)
|
|
479 |
{
|
|
480 |
delete iLockData;
|
|
481 |
iLockData = NULL;
|
|
482 |
}
|
|
483 |
|
|
484 |
if(iRomBuildInfo)
|
|
485 |
{
|
|
486 |
delete iRomBuildInfo;
|
|
487 |
iRomBuildInfo = NULL;
|
|
488 |
}
|
|
489 |
|
|
490 |
if(iTraceDump)
|
|
491 |
{
|
|
492 |
delete iTraceDump;
|
|
493 |
iTraceDump = NULL;
|
|
494 |
}
|
|
495 |
|
|
496 |
if(iVarSpecData)
|
|
497 |
{
|
|
498 |
delete iVarSpecData;
|
|
499 |
iVarSpecData = NULL;
|
|
500 |
}
|
|
501 |
|
|
502 |
}
|
|
503 |
|
|
504 |
void CFlashDataSource::GetRegisterListL( RRegisterList & aRegisterList )
|
|
505 |
{
|
|
506 |
//Not used
|
|
507 |
User::Leave(KErrNotSupported);
|
|
508 |
}
|
|
509 |
|
|
510 |
/**
|
|
511 |
* Reads registers from flash for a given thread
|
|
512 |
* @param aThreadId Thread of interest
|
|
513 |
* @param aRegisterList Appends any registers found to this list
|
|
514 |
* @leave OS wide code
|
|
515 |
*/
|
|
516 |
void CFlashDataSource::ReadRegistersL( const TUint64 aThreadId, RRegisterList & aRegisterList )
|
|
517 |
{
|
|
518 |
LOG_MSG("CFlashDataSource::ReadRegistersL()");
|
|
519 |
|
|
520 |
// Delete any objects in the array, since we will replace them.
|
|
521 |
aRegisterList.Reset();
|
|
522 |
|
|
523 |
/**
|
|
524 |
* We keep 3 sets of registers in the flash at different points.
|
|
525 |
* The first is the FullCPU register set for the thread that has crashed.
|
|
526 |
* The second are the supervisor registers for a given thread (may not all be available)
|
|
527 |
* The third are the user registers for a given thread (may not all be available)
|
|
528 |
* These corrospond to 3 different configuration options
|
|
529 |
*/
|
|
530 |
|
|
531 |
//See if it is the crashed threads full CPU set
|
|
532 |
if(aThreadId == iHdr.iTid)
|
|
533 |
{
|
|
534 |
//Put regs into list
|
|
535 |
HelpReadRegistersL(iOffsetsHdr.iCTFullRegOffset, iHdr.iLogSize, aThreadId, aRegisterList);
|
|
536 |
return;
|
|
537 |
}
|
|
538 |
|
|
539 |
//Now we look at SVR registers
|
|
540 |
HelpReadRegistersL(iOffsetsHdr.iSysSvrRegOffset, iOffsetsHdr.iSysUsrRegOffset, aThreadId, aRegisterList);
|
|
541 |
|
|
542 |
//And finally the USR registers
|
|
543 |
HelpReadRegistersL(iOffsetsHdr.iSysUsrRegOffset, iOffsetsHdr.iSysSvrRegOffset, aThreadId, aRegisterList);
|
|
544 |
|
|
545 |
}
|
|
546 |
|
|
547 |
/**
|
|
548 |
* This takes in a register list and looks at our flash buffer. It reads any registers it can out of the buffer
|
|
549 |
* and appends them to the list.
|
|
550 |
* @param aRegStartPoint Position in flash to begin searching from
|
|
551 |
* @param aMaxReadPoint Position beyond which we shall not read
|
|
552 |
* @param aThreadId Thread whose registers we want
|
|
553 |
* @param aRegList List in which to store found registers
|
|
554 |
* @leave KErrCorrupt if the buffer doesnt contain valid buffer data
|
|
555 |
*/
|
|
556 |
void CFlashDataSource::HelpReadRegistersL(TInt aRegStartPoint, TInt aMaxReadPoint, TUint64 aThreadId, RRegisterList& aRegList)
|
|
557 |
{
|
|
558 |
TRegisterValue* regVal;
|
|
559 |
TBool stillMoreDataToBeHad = ETrue;
|
|
560 |
TInt flashPos = aRegStartPoint;
|
|
561 |
TInt rdSize = READ_SIZE;
|
|
562 |
|
|
563 |
//cycle through the flash partition, rdSize bytes at a time until there is no more data of interest to be had
|
|
564 |
while(stillMoreDataToBeHad)
|
|
565 |
{
|
|
566 |
User::LeaveIfError(ReadCrashLog(flashPos, rdSize));
|
|
567 |
|
|
568 |
//Get what we can out of this buffer read
|
|
569 |
TInt pos, bufferSize = 0;
|
|
570 |
SCMStructId id = ESCMLast;
|
|
571 |
MByteStreamSerializable* data = NULL;
|
|
572 |
|
|
573 |
TRAPD(err, data = iWalker.GetNextDataTypeL(pos, id, bufferSize));
|
|
574 |
if(err != KErrNone)
|
|
575 |
{
|
|
576 |
return; //We dont mind if this returns corrupt. This is only relevant during initial analysis
|
|
577 |
}
|
|
578 |
|
|
579 |
while(data && stillMoreDataToBeHad)
|
|
580 |
{
|
|
581 |
CleanupStack::PushL(data);
|
|
582 |
|
|
583 |
switch(id)
|
|
584 |
{
|
|
585 |
case ESCMRegisterSet :
|
|
586 |
{
|
|
587 |
break;
|
|
588 |
}
|
|
589 |
case ESCMRegisterValue :
|
|
590 |
{
|
|
591 |
regVal = static_cast<TRegisterValue*>(data);
|
|
592 |
|
|
593 |
//See if its for the right thread
|
|
594 |
if(regVal->iOwnId != aThreadId)
|
|
595 |
{
|
|
596 |
break;
|
|
597 |
}
|
|
598 |
|
|
599 |
TRegisterData newData;
|
|
600 |
ConvertFlashFormatRegL(newData, *regVal);
|
|
601 |
aRegList.AppendL(newData);
|
|
602 |
|
|
603 |
break;
|
|
604 |
}
|
|
605 |
|
|
606 |
//Dont care bout these
|
|
607 |
case ESCMFirst :
|
|
608 |
case ESCMOffsetsHeader :
|
|
609 |
case ESCMTCrashInfo :
|
|
610 |
case ESCMThreadData :
|
|
611 |
case ESCMThreadStack :
|
|
612 |
case ESCMMemory :
|
|
613 |
case ESCMCodeSegSet :
|
|
614 |
case ESCMCodeSeg :
|
|
615 |
case ESCMRawData :
|
|
616 |
case ESCMLast :
|
|
617 |
default :
|
|
618 |
{
|
|
619 |
//No more registers mean no more interest
|
|
620 |
stillMoreDataToBeHad = EFalse;
|
|
621 |
}
|
|
622 |
}
|
|
623 |
|
|
624 |
CleanupStack::PopAndDestroy(data);
|
|
625 |
|
|
626 |
//ignore beyond the max point
|
|
627 |
if(pos + flashPos == aMaxReadPoint)
|
|
628 |
{
|
|
629 |
return;
|
|
630 |
}
|
|
631 |
|
|
632 |
if(stillMoreDataToBeHad)
|
|
633 |
{
|
|
634 |
//Get next type
|
|
635 |
TRAPD(err, data = iWalker.GetNextDataTypeL(pos, id, bufferSize));
|
|
636 |
if(err != KErrNone)
|
|
637 |
{
|
|
638 |
//We dont mind if this returns corrupt. This is only relevant during initial analysis
|
|
639 |
return;
|
|
640 |
}
|
|
641 |
}
|
|
642 |
}
|
|
643 |
|
|
644 |
//if data was null but there is still more data to be had, that means we need to read more data
|
|
645 |
//from the flash to give to our walker. it will need a buffer size of at least bufferSize, starting
|
|
646 |
//from flashPos + pos
|
|
647 |
flashPos += pos;
|
|
648 |
rdSize = (bufferSize > rdSize) ? bufferSize : rdSize;
|
|
649 |
|
|
650 |
}
|
|
651 |
}
|
|
652 |
|
|
653 |
/**
|
|
654 |
* Helper to convert between register value formats
|
|
655 |
* @param aData Output format of the register data
|
|
656 |
* @param aOriginalVal register format as it appears in flash
|
|
657 |
*/
|
|
658 |
void CFlashDataSource::ConvertFlashFormatRegL(TRegisterData& aData, const TRegisterValue& aOriginalVal)
|
|
659 |
{
|
|
660 |
|
|
661 |
aData.iRegClass = aOriginalVal.iClass;
|
|
662 |
aData.iSubId = aOriginalVal.iSubId;
|
|
663 |
aData.iId = aOriginalVal.iType;
|
|
664 |
aData.iSize = aOriginalVal.iSize;
|
|
665 |
aData.iAvailable = ETrue;
|
|
666 |
|
|
667 |
switch(aOriginalVal.iSize)
|
|
668 |
{
|
|
669 |
case 0:
|
|
670 |
{
|
|
671 |
aData.iValue8 = aOriginalVal.iValue8;
|
|
672 |
break;
|
|
673 |
}
|
|
674 |
case 1:
|
|
675 |
{
|
|
676 |
aData.iValue16 = aOriginalVal.iValue16;
|
|
677 |
break;
|
|
678 |
}
|
|
679 |
case 2:
|
|
680 |
{
|
|
681 |
aData.iValue32 = aOriginalVal.iValue32;
|
|
682 |
break;
|
|
683 |
}
|
|
684 |
case 3:
|
|
685 |
{
|
|
686 |
aData.iValue64 = aOriginalVal.iValue64;
|
|
687 |
break;
|
|
688 |
}
|
|
689 |
//funny data, run for the hills
|
|
690 |
default: User::Leave(KErrCorrupt);
|
|
691 |
}
|
|
692 |
}
|
|
693 |
|
|
694 |
/**
|
|
695 |
Purpose:
|
|
696 |
Read memory if dumped into the flash. The parameters relate to those when
|
|
697 |
the system was live and running. If this memory region has not been dumped
|
|
698 |
this leaves with a KErrNotFound
|
|
699 |
|
|
700 |
@param aThreadId - The id of the thread relative to which the read should take place
|
|
701 |
@param aAddress - The virtual address to read from
|
|
702 |
@param aLength - The number of bytes to read
|
|
703 |
@param aData - The buffer to read into
|
|
704 |
@leave KErrNotFound if memory not available or one of the system wide codes
|
|
705 |
*/
|
|
706 |
void CFlashDataSource::ReadMemoryL(
|
|
707 |
const TUint64 aThreadId,
|
|
708 |
const TUint32 aAddress,
|
|
709 |
const TUint32 aLength,
|
|
710 |
TDes8 & aData )
|
|
711 |
{
|
|
712 |
LOG_MSG4("CFlashDataSource::ReadMemoryL ThreadID = [%ld] aAddress = [0x%X] aLength = [%d]", aThreadId, aAddress, aLength);
|
|
713 |
|
|
714 |
if(aLength == 0)
|
|
715 |
{
|
|
716 |
return;
|
|
717 |
}
|
|
718 |
|
|
719 |
//check arguments
|
|
720 |
if(aData.MaxLength() < aLength)
|
|
721 |
{
|
|
722 |
User::Leave(KErrOverflow);
|
|
723 |
}
|
|
724 |
|
|
725 |
const TUint64 procId = GetThreadOwnerL(aThreadId);
|
|
726 |
TInt errFound = KErrNone;
|
|
727 |
|
|
728 |
//Look through our memory map to see if we have anything for this thread
|
|
729 |
TInt cnt = iCrashMemoryMap.Count() - 1;
|
|
730 |
for(; cnt >= 0; cnt-- )
|
|
731 |
{
|
|
732 |
TObjectLocation& m = iCrashMemoryMap[cnt];
|
|
733 |
|
|
734 |
if(m.iObjectId == procId)
|
|
735 |
{
|
|
736 |
TInt sizeToRead = TMemoryDump::KSCMMemDumpMaxSize;
|
|
737 |
|
|
738 |
//we must read this struct to check if we are interested in it
|
|
739 |
User::LeaveIfError(ReadCrashLog(m.iOffset, sizeToRead));
|
|
740 |
|
|
741 |
TInt pos = 0;
|
|
742 |
SCMStructId id = ESCMLast;
|
|
743 |
|
|
744 |
MByteStreamSerializable* data = iWalker.GetNextDataTypeL(pos, id, sizeToRead);
|
|
745 |
|
|
746 |
if(id != ESCMMemory)
|
|
747 |
{
|
|
748 |
delete data;
|
|
749 |
errFound = KErrCorrupt;
|
|
750 |
//Still keep looking through the memory list
|
|
751 |
continue;
|
|
752 |
}
|
|
753 |
|
|
754 |
TMemoryDump* memDump = static_cast<TMemoryDump*>(data);
|
|
755 |
CleanupStack::PushL(memDump);
|
|
756 |
|
|
757 |
//have we dumped this memory
|
|
758 |
if(aAddress >= memDump->iStartAddress && (aAddress + aLength) <= (memDump->iStartAddress + memDump->iLength))
|
|
759 |
{
|
|
760 |
//Now we need to read in the Raw data structure
|
|
761 |
User::LeaveIfError(ReadCrashLog(m.iOffset + memDump->GetSize(), TRawData::KSCMRawDataMaxSize + memDump->iLength));
|
|
762 |
|
|
763 |
TInt bufSize = 0;
|
|
764 |
TRawData* rawData = iWalker.GetRawDataTypeL(pos, bufSize, aData, aAddress - memDump->iStartAddress);
|
|
765 |
if(!rawData)
|
|
766 |
{
|
|
767 |
//descriptor not big enough
|
|
768 |
errFound = KErrOverflow;
|
|
769 |
CleanupStack::PopAndDestroy();
|
|
770 |
|
|
771 |
//Still keep looking through the memory list
|
|
772 |
continue;
|
|
773 |
}
|
|
774 |
|
|
775 |
CleanupStack::PushL(rawData);
|
|
776 |
|
|
777 |
//Now we need to copy into the buffer supplied
|
|
778 |
//aData.Copy(rawData->iData.Mid(memDump->iStartAddress - aAddress , aLength));
|
|
779 |
|
|
780 |
CleanupStack::PopAndDestroy(2);
|
|
781 |
|
|
782 |
return;
|
|
783 |
}
|
|
784 |
|
|
785 |
CleanupStack::PopAndDestroy();
|
|
786 |
}
|
|
787 |
}
|
|
788 |
|
|
789 |
if(errFound == KErrNone)
|
|
790 |
User::Leave(KErrNotFound);
|
|
791 |
else
|
|
792 |
User::Leave(errFound);
|
|
793 |
|
|
794 |
}
|
|
795 |
|
|
796 |
void CFlashDataSource::GetProcessListL( RProcessPointerList & aProcessList,
|
|
797 |
TUint & aTotalProcessListDescSize )
|
|
798 |
{
|
|
799 |
LOG_MSG("CFlashDataSource::GetProcessListL()");
|
|
800 |
|
|
801 |
// Delete any objects in the array, since we will replace them.
|
|
802 |
aProcessList.ResetAndDestroy();
|
|
803 |
aTotalProcessListDescSize = 0;
|
|
804 |
|
|
805 |
//Find out where in flash to read from
|
|
806 |
TInt flashPos = iOffsetsHdr.iPLstOffset;
|
|
807 |
TInt rdSize = READ_SIZE;
|
|
808 |
TBool stillMoreDataToBeHad = ETrue;
|
|
809 |
|
|
810 |
//cycle through the flash partition, rdSize bytes at a time until there is no more data of interest to be had
|
|
811 |
while(stillMoreDataToBeHad)
|
|
812 |
{
|
|
813 |
User::LeaveIfError(ReadCrashLog(flashPos, rdSize));
|
|
814 |
|
|
815 |
//Get what we can out of this buffer read
|
|
816 |
TInt pos, bufferSize = 0;
|
|
817 |
SCMStructId id = ESCMLast;
|
|
818 |
MByteStreamSerializable* data = NULL;
|
|
819 |
TProcessData* proc = NULL;
|
|
820 |
|
|
821 |
TRAPD(err, data = iWalker.GetNextDataTypeL(pos, id, bufferSize));
|
|
822 |
if(err != KErrNone)
|
|
823 |
{
|
|
824 |
return; //We dont mind if this returns corrupt. This is only relevant during initial analysis
|
|
825 |
}
|
|
826 |
|
|
827 |
while(data && stillMoreDataToBeHad)
|
|
828 |
{
|
|
829 |
CleanupStack::PushL(data);
|
|
830 |
|
|
831 |
switch(id)
|
|
832 |
{
|
|
833 |
case ESCMProcessData :
|
|
834 |
{
|
|
835 |
proc = static_cast<TProcessData*>(data);
|
|
836 |
|
|
837 |
//Now we need to widen the name descriptor to 16 bits
|
|
838 |
RBuf name16;
|
|
839 |
name16.CreateL(proc->iNamesize);
|
|
840 |
name16.CleanupClosePushL();
|
|
841 |
|
|
842 |
name16.Copy(proc->iName);
|
|
843 |
|
|
844 |
//create the new process object
|
|
845 |
CProcessInfo* pi = CProcessInfo::NewL(proc->iPid, name16);
|
|
846 |
aProcessList.AppendL(pi);
|
|
847 |
|
|
848 |
aTotalProcessListDescSize += pi->Size();
|
|
849 |
|
|
850 |
CleanupStack::PopAndDestroy();
|
|
851 |
|
|
852 |
break;
|
|
853 |
}
|
|
854 |
case ESCMFirst :
|
|
855 |
case ESCMOffsetsHeader :
|
|
856 |
case ESCMTCrashInfo :
|
|
857 |
case ESCMThreadData :
|
|
858 |
case ESCMThreadStack :
|
|
859 |
case ESCMRegisterValue :
|
|
860 |
case ESCMRegisterSet :
|
|
861 |
case ESCMMemory :
|
|
862 |
case ESCMCodeSegSet :
|
|
863 |
case ESCMCodeSeg :
|
|
864 |
case ESCMRawData :
|
|
865 |
case ESCMLast :
|
|
866 |
default :
|
|
867 |
{
|
|
868 |
//No more registers mean no more interest
|
|
869 |
stillMoreDataToBeHad = EFalse;
|
|
870 |
}
|
|
871 |
}
|
|
872 |
|
|
873 |
CleanupStack::PopAndDestroy(data);
|
|
874 |
|
|
875 |
//Get next type
|
|
876 |
TRAPD(err, data = iWalker.GetNextDataTypeL(pos, id, bufferSize));
|
|
877 |
if(err != KErrNone)
|
|
878 |
{
|
|
879 |
//We dont mind if this returns corrupt. This is only relevant during initial analysis
|
|
880 |
return;
|
|
881 |
}
|
|
882 |
|
|
883 |
}
|
|
884 |
|
|
885 |
if(data)
|
|
886 |
{
|
|
887 |
delete data;
|
|
888 |
}
|
|
889 |
|
|
890 |
//if data was null but there is still more data to be had, that means we need to read more data
|
|
891 |
//from the flash to give to our walker. it will need a buffer size of at least bufferSize, starting
|
|
892 |
//from flashPos + pos
|
|
893 |
flashPos += pos;
|
|
894 |
rdSize = (bufferSize > rdSize) ? bufferSize : rdSize;
|
|
895 |
|
|
896 |
}
|
|
897 |
}
|
|
898 |
|
|
899 |
void CFlashDataSource::GetExecutableListL( RExecutablePointerList & aExecutableList,
|
|
900 |
TUint & aTotalExecutableListDescSize )
|
|
901 |
{
|
|
902 |
//TODO
|
|
903 |
User::Leave(KErrNotSupported);
|
|
904 |
}
|
|
905 |
|
|
906 |
/**
|
|
907 |
* Creates an ownership relation between a thread and a process. As when the board crashes we cant
|
|
908 |
* find this out from the system, we need to generate it as we go
|
|
909 |
* @param aOwningProcessId The owning process ID
|
|
910 |
* @param aThreadId The child thread ID
|
|
911 |
*/
|
|
912 |
void CFlashDataSource::AssignOwner(TInt64 aOwningProcessId, TInt64 aThreadId)
|
|
913 |
{
|
|
914 |
TChildOwnerPair pair(aOwningProcessId, aThreadId);
|
|
915 |
iThreadOwners.Append(pair);
|
|
916 |
}
|
|
917 |
|
|
918 |
/**
|
|
919 |
* Obtain the thread list. If aProcessId is (TUint64 -1), we obtain the entire system
|
|
920 |
* thread list. If aProcessId is positive we get the thread list for that process
|
|
921 |
*
|
|
922 |
* @param aProcessId Process to gather threads for
|
|
923 |
* @param aThreadList Thread list stored here
|
|
924 |
* @param aTotalThreadListDescSize list size
|
|
925 |
* @leave One of the OS wide system codes
|
|
926 |
*/
|
|
927 |
void CFlashDataSource::GetThreadListL( const TUint64 aProcessId,
|
|
928 |
RThreadPointerList & aThreadList,
|
|
929 |
TUint & aTotalThreadListDescSize )
|
|
930 |
{
|
|
931 |
LOG_MSG("CFlashDataSource::GetThreadListL()");
|
|
932 |
|
|
933 |
// Delete any objects in the array, since we will replace them.
|
|
934 |
aThreadList.ResetAndDestroy();
|
|
935 |
aTotalThreadListDescSize = 0;
|
|
936 |
|
|
937 |
//Find out where in flash to read from
|
|
938 |
TInt flashPos = iOffsetsHdr.iTLstOffset;
|
|
939 |
TInt rdSize = READ_SIZE;
|
|
940 |
TBool stillMoreDataToBeHad = ETrue;
|
|
941 |
|
|
942 |
//cycle through the flash partition, rdSize bytes at a time until there is no more data of interest to be had
|
|
943 |
while(stillMoreDataToBeHad)
|
|
944 |
{
|
|
945 |
User::LeaveIfError(ReadCrashLog(flashPos, rdSize));
|
|
946 |
|
|
947 |
//Get what we can out of this buffer read
|
|
948 |
TInt pos, bufferSize = 0;
|
|
949 |
SCMStructId id = ESCMLast;
|
|
950 |
MByteStreamSerializable* data = NULL;
|
|
951 |
TThreadData* thread = NULL;
|
|
952 |
|
|
953 |
TRAPD(err, data = iWalker.GetNextDataTypeL(pos, id, bufferSize));
|
|
954 |
if(err != KErrNone)
|
|
955 |
{
|
|
956 |
return; //We dont mind if this returns corrupt. This is only relevant during initial analysis
|
|
957 |
}
|
|
958 |
|
|
959 |
while(data && stillMoreDataToBeHad)
|
|
960 |
{
|
|
961 |
CleanupStack::PushL(data);
|
|
962 |
|
|
963 |
switch(id)
|
|
964 |
{
|
|
965 |
case ESCMThreadData :
|
|
966 |
{
|
|
967 |
thread = static_cast<TThreadData*>(data);
|
|
968 |
|
|
969 |
AssignOwner(thread->iOwnerId, thread->iTid);
|
|
970 |
|
|
971 |
if(aProcessId == thread->iOwnerId || aProcessId == ((TUint64)-1))
|
|
972 |
{
|
|
973 |
//Now we need to widen this descriptor to 16 bits
|
|
974 |
RBuf name16;
|
|
975 |
name16.CreateL(thread->iNamesize);
|
|
976 |
name16.CleanupClosePushL();
|
|
977 |
name16.Copy(thread->iName);
|
|
978 |
|
|
979 |
//Get the thread info object and add it to the thread list
|
|
980 |
CThreadInfo* tinfo = CThreadInfo::NewL(thread->iTid,
|
|
981 |
name16,
|
|
982 |
thread->iOwnerId,
|
|
983 |
thread->iPriority,
|
|
984 |
thread->iSvcSP,
|
|
985 |
thread->iSvcStack,
|
|
986 |
thread->iSvcStacksize,
|
|
987 |
thread->iUsrStack,
|
|
988 |
thread->iUsrStacksize);
|
|
989 |
|
|
990 |
// note - to minimize changes elsewhere last cpu id not added
|
|
991 |
// to CThreadInfo c'tor - rather
|
|
992 |
//Until the SMP work is done: tinfo->SetLastCpuId(thread->iLastCpu);
|
|
993 |
tinfo->SetHeapBase(thread->iSvcHeap);
|
|
994 |
tinfo->SetHeapSize(thread->iSvcHeapSize);
|
|
995 |
aThreadList.AppendL(tinfo);
|
|
996 |
aTotalThreadListDescSize += tinfo->Size();
|
|
997 |
|
|
998 |
CleanupStack::PopAndDestroy();
|
|
999 |
}
|
|
1000 |
|
|
1001 |
break;
|
|
1002 |
}
|
|
1003 |
case ESCMFirst :
|
|
1004 |
case ESCMOffsetsHeader :
|
|
1005 |
case ESCMTCrashInfo :
|
|
1006 |
case ESCMProcessData :
|
|
1007 |
case ESCMThreadStack :
|
|
1008 |
case ESCMRegisterValue :
|
|
1009 |
case ESCMRegisterSet :
|
|
1010 |
case ESCMMemory :
|
|
1011 |
case ESCMCodeSegSet :
|
|
1012 |
case ESCMCodeSeg :
|
|
1013 |
case ESCMRawData :
|
|
1014 |
case ESCMLast :
|
|
1015 |
case ESCMTraceData :
|
|
1016 |
default :
|
|
1017 |
{
|
|
1018 |
//No more registers mean no more interest
|
|
1019 |
stillMoreDataToBeHad = EFalse;
|
|
1020 |
}
|
|
1021 |
}
|
|
1022 |
|
|
1023 |
CleanupStack::PopAndDestroy(data);
|
|
1024 |
|
|
1025 |
//Get next type
|
|
1026 |
TRAPD(err, data = iWalker.GetNextDataTypeL(pos, id, bufferSize));
|
|
1027 |
if(err != KErrNone)
|
|
1028 |
{
|
|
1029 |
//We dont mind if this returns corrupt. This is only relevant during initial analysis
|
|
1030 |
return;
|
|
1031 |
}
|
|
1032 |
|
|
1033 |
}
|
|
1034 |
|
|
1035 |
if(data)
|
|
1036 |
{
|
|
1037 |
delete data;
|
|
1038 |
}
|
|
1039 |
|
|
1040 |
//if data was null but there is still more data to be had, that means we need to read more data
|
|
1041 |
//from the flash to give to our walker. it will need a buffer size of at least bufferSize, starting
|
|
1042 |
//from flashPos + pos
|
|
1043 |
flashPos += pos;
|
|
1044 |
rdSize = (bufferSize > rdSize) ? bufferSize : rdSize;
|
|
1045 |
|
|
1046 |
}
|
|
1047 |
}
|
|
1048 |
|
|
1049 |
/**
|
|
1050 |
* Gets the owning process of this thread id
|
|
1051 |
* @param aThreadId Thread ID of interest
|
|
1052 |
* @return Owning process ID
|
|
1053 |
* @leave One of the OS wide codes
|
|
1054 |
*/
|
|
1055 |
TUint64 CFlashDataSource::GetThreadOwnerL(TUint64 aThreadId)
|
|
1056 |
{
|
|
1057 |
for(TInt cnt = 0; cnt < iThreadOwners.Count(); cnt++)
|
|
1058 |
{
|
|
1059 |
TChildOwnerPair pair = iThreadOwners[cnt];
|
|
1060 |
if(pair.iChildId == aThreadId)
|
|
1061 |
{
|
|
1062 |
return pair.iOwnerId;
|
|
1063 |
}
|
|
1064 |
}
|
|
1065 |
|
|
1066 |
User::Leave(KErrNotFound);
|
|
1067 |
|
|
1068 |
return 0; //avoid warnings
|
|
1069 |
}
|
|
1070 |
|
|
1071 |
/**
|
|
1072 |
* Obtains the code segment list for a given thread.
|
|
1073 |
* @param aTid Thread identifier to obtain code segments for.
|
|
1074 |
* @param aCodeSegList Array of code segments.
|
|
1075 |
* @param aTotalCodeSegListDescSize Size in bytes of the descriptor
|
|
1076 |
* @leave One of the OS wide system codes
|
|
1077 |
*/
|
|
1078 |
void CFlashDataSource::GetCodeSegmentsL( const TUint64 aTid, RCodeSegPointerList &aCodeSegList, TUint & aTotalCodeSegListDescSize )
|
|
1079 |
{
|
|
1080 |
TUint64 ownerId = 0;
|
|
1081 |
TRAPD(err, ownerId = GetThreadOwnerL(aTid));
|
|
1082 |
|
|
1083 |
if(KErrNone == err)
|
|
1084 |
{
|
|
1085 |
GetCodeSegmentsFromPIDL(ownerId, aCodeSegList, aTotalCodeSegListDescSize);
|
|
1086 |
}
|
|
1087 |
}
|
|
1088 |
|
|
1089 |
/**
|
|
1090 |
* Obtains the code segment list for a given thread.
|
|
1091 |
* @param aPid Process identifier to obtain code segments for.
|
|
1092 |
* @param aCodeSegList Array of code segments.
|
|
1093 |
* @param aTotalCodeSegListDescSize Size in bytes of the descriptor
|
|
1094 |
* @leave One of the OS wide system codes
|
|
1095 |
*/
|
|
1096 |
void CFlashDataSource::GetCodeSegmentsFromPIDL( const TUint64 aPid, RCodeSegPointerList &aCodeSegList, TUint & aTotalCodeSegListDescSize )
|
|
1097 |
{
|
|
1098 |
LOG_MSG("CFlashDataSource::GetCodeSegmentsL()");
|
|
1099 |
|
|
1100 |
//sort out arguments
|
|
1101 |
aTotalCodeSegListDescSize = 0;
|
|
1102 |
aCodeSegList.ResetAndDestroy();
|
|
1103 |
|
|
1104 |
//Look through our code seg map to see if we have anything for this process
|
|
1105 |
TInt cnt = iCodeSegMap.Count() - 1;
|
|
1106 |
|
|
1107 |
for(; cnt >= 0; cnt-- )
|
|
1108 |
{
|
|
1109 |
//Look through
|
|
1110 |
TObjectLocation location = iCodeSegMap[cnt];
|
|
1111 |
|
|
1112 |
//see if we have code segments for this thread ID
|
|
1113 |
if(location.iObjectId == aPid)
|
|
1114 |
{
|
|
1115 |
TInt bufferSize = TCodeSegment::KSCMCodeSegMaxSize;
|
|
1116 |
|
|
1117 |
//we must read this struct to check if we are interested in it
|
|
1118 |
User::LeaveIfError(ReadCrashLog(location.iOffset, bufferSize));
|
|
1119 |
|
|
1120 |
TInt pos = 0;
|
|
1121 |
SCMStructId id = ESCMLast;
|
|
1122 |
|
|
1123 |
MByteStreamSerializable* data = iWalker.GetNextDataTypeL(pos, id, bufferSize);
|
|
1124 |
CleanupStack::PushL(data);
|
|
1125 |
|
|
1126 |
if(id != ESCMCodeSeg || !data)
|
|
1127 |
{
|
|
1128 |
CleanupStack::PopAndDestroy(data);
|
|
1129 |
break;
|
|
1130 |
}
|
|
1131 |
|
|
1132 |
TCodeSegment* seg = static_cast<TCodeSegment*>(data);
|
|
1133 |
|
|
1134 |
//take our flash structure and turn it into what we need
|
|
1135 |
TCodeSegInfo* segInfo = new TCodeSegInfo();
|
|
1136 |
CleanupStack::PushL(segInfo);
|
|
1137 |
|
|
1138 |
segInfo->iXIP = seg->iXip;
|
|
1139 |
segInfo->iType = seg->iCodeSegType;
|
|
1140 |
|
|
1141 |
TModuleMemoryInfo memInfo = seg->iCodeSegMemInfo;
|
|
1142 |
|
|
1143 |
segInfo->iCodeSize = memInfo.iCodeSize;
|
|
1144 |
segInfo->iCodeRunAddr = memInfo.iCodeBase;
|
|
1145 |
segInfo->iRoDataSize = memInfo.iConstDataSize;
|
|
1146 |
segInfo->iRoDataRunAddr = memInfo.iCodeBase + memInfo.iCodeSize;
|
|
1147 |
segInfo->iDataSize = memInfo.iInitialisedDataSize + memInfo.iUninitialisedDataSize;
|
|
1148 |
segInfo->iDataRunAddr = memInfo.iInitialisedDataBase;
|
|
1149 |
|
|
1150 |
//if the code seg is XIP then these are the same
|
|
1151 |
if(segInfo->iXIP)
|
|
1152 |
{
|
|
1153 |
segInfo->iCodeLoadAddr = segInfo->iCodeRunAddr;
|
|
1154 |
segInfo->iRoDataLoadAddr = segInfo->iRoDataRunAddr;
|
|
1155 |
segInfo->iDataLoadAddr = segInfo->iDataRunAddr;
|
|
1156 |
}
|
|
1157 |
else
|
|
1158 |
{
|
|
1159 |
segInfo->iRoDataLoadAddr = 0; // as per current serverdatasource (dont worry for the moment)
|
|
1160 |
segInfo->iCodeLoadAddr = 0; // as per current serverdatasource (dont worry for the moment)
|
|
1161 |
segInfo->iDataLoadAddr = 0; // as per current serverdatasource (dont worry for the moment)
|
|
1162 |
}
|
|
1163 |
|
|
1164 |
TFileName name;
|
|
1165 |
name.Copy(seg->iName);
|
|
1166 |
|
|
1167 |
segInfo->iName = name;
|
|
1168 |
|
|
1169 |
// crashed process code segments may have been added twice to the list as they are added
|
|
1170 |
// for the crashed process and for all processes
|
|
1171 |
|
|
1172 |
TBool found = EFalse;
|
|
1173 |
for(TInt k=0;k<aCodeSegList.Count();k++)
|
|
1174 |
{
|
|
1175 |
const TCodeSegInfo& si = * aCodeSegList[k];
|
|
1176 |
if(si.iDataRunAddr == segInfo->iDataRunAddr && si.iDataSize == segInfo->iDataSize)
|
|
1177 |
{
|
|
1178 |
found = ETrue;
|
|
1179 |
|
|
1180 |
LOG_MSG4("XXX CFlashDataSource::GetCodeSegmentsFromPIDL FOUND DUPLICATE MATCH k[%d]segInfo->iDataRunAddr[%x] segInfo->iDataSize[%d]"
|
|
1181 |
, k
|
|
1182 |
, segInfo->iDataRunAddr
|
|
1183 |
, segInfo->iDataSize );
|
|
1184 |
|
|
1185 |
break;
|
|
1186 |
}
|
|
1187 |
}
|
|
1188 |
|
|
1189 |
if(!found)
|
|
1190 |
{
|
|
1191 |
aCodeSegList.AppendL(segInfo);
|
|
1192 |
CleanupStack::Pop(segInfo);
|
|
1193 |
}
|
|
1194 |
else
|
|
1195 |
{
|
|
1196 |
CleanupStack::PopAndDestroy(segInfo);
|
|
1197 |
}
|
|
1198 |
|
|
1199 |
CleanupStack::PopAndDestroy(data);
|
|
1200 |
}
|
|
1201 |
}
|
|
1202 |
|
|
1203 |
}
|
|
1204 |
|
|
1205 |
/**
|
|
1206 |
* Gets the size of the trace buffer that is available
|
|
1207 |
*/
|
|
1208 |
TUint CFlashDataSource::GetAvailableTraceSizeL()
|
|
1209 |
{
|
|
1210 |
CLTRACE("Start CFlashDataSource::GetAvailableTraceSizeL()");
|
|
1211 |
|
|
1212 |
if(iTraceDump)
|
|
1213 |
{
|
|
1214 |
return iTraceDump->iSizeOfMemory;
|
|
1215 |
}
|
|
1216 |
else
|
|
1217 |
{
|
|
1218 |
User::Leave(KErrNotFound);
|
|
1219 |
}
|
|
1220 |
|
|
1221 |
return 0; //comp warnings
|
|
1222 |
}
|
|
1223 |
|
|
1224 |
/**
|
|
1225 |
Reads data from the trace buffer into the supplied descriptor
|
|
1226 |
@param aTraceData The buffer to be read into
|
|
1227 |
@param aPos Position in trace buffer to read from
|
|
1228 |
@leave KErrArgument if aPos is greater than the memory available or one of the other system wide codes
|
|
1229 |
*/
|
|
1230 |
void CFlashDataSource::ReadTraceBufferL(TDes8 &aTraceData, TUint aPos)
|
|
1231 |
{
|
|
1232 |
CLTRACE2("CFlashDataSource::ReadTraceBufferL() from aPos = [%d] into a buffer of [%d]", aPos, aTraceData.MaxLength());
|
|
1233 |
|
|
1234 |
aTraceData.Zero();
|
|
1235 |
|
|
1236 |
if(!iTraceDump)
|
|
1237 |
User::Leave(KErrNotFound);
|
|
1238 |
|
|
1239 |
CLTRACE1("traceDump->iNumberOfParts=%d", iTraceDump->iNumberOfParts);
|
|
1240 |
TUint nextRawDataPos = iOffsetsHdr.iTraceOffset + iTraceDump->GetSize();
|
|
1241 |
TInt currentTracePos = 0;
|
|
1242 |
|
|
1243 |
//Because the trace is a circular buffer it must be read in parts and therefore dumped on the flash
|
|
1244 |
//in parts - ie. TRawData structs. Must read each of these and append to trace data
|
|
1245 |
for(TInt part = 0; part < iTraceDump->iNumberOfParts; part++)
|
|
1246 |
{
|
|
1247 |
User::LeaveIfError(ReadCrashLog(nextRawDataPos, TRawData::KSCMRawDataMaxSize));
|
|
1248 |
|
|
1249 |
TInt nextRead = 0;
|
|
1250 |
SCMStructId id = ESCMLast;
|
|
1251 |
TInt nextBufSize = 0;
|
|
1252 |
|
|
1253 |
MByteStreamSerializable* theRawness = iWalker.GetNextDataTypeL(nextRead, id, nextBufSize);
|
|
1254 |
if(theRawness && id == ESCMRawData)
|
|
1255 |
{
|
|
1256 |
TRawData* raw = static_cast<TRawData*>(theRawness);
|
|
1257 |
CleanupStack::PushL(theRawness);
|
|
1258 |
|
|
1259 |
//Read the trace into the trace buffer
|
|
1260 |
TUint rdSize = raw->iLength;
|
|
1261 |
TUint rdPos = nextRawDataPos + TRawData::KSCMRawDataMaxSize;
|
|
1262 |
|
|
1263 |
if(aPos >= (currentTracePos + raw->iLength))
|
|
1264 |
{
|
|
1265 |
//no dumpage
|
|
1266 |
}
|
|
1267 |
else
|
|
1268 |
{
|
|
1269 |
if(aPos >= currentTracePos)
|
|
1270 |
{
|
|
1271 |
rdSize = currentTracePos + raw->iLength - aPos;
|
|
1272 |
rdPos += aPos - currentTracePos;
|
|
1273 |
}
|
|
1274 |
|
|
1275 |
ReadRawFlashL(aTraceData, rdPos, rdSize);
|
|
1276 |
}
|
|
1277 |
|
|
1278 |
nextRawDataPos += raw->GetSize();
|
|
1279 |
currentTracePos += raw->iLength;
|
|
1280 |
|
|
1281 |
CleanupStack::PopAndDestroy(theRawness);
|
|
1282 |
}
|
|
1283 |
else
|
|
1284 |
{
|
|
1285 |
User::Leave(KErrNotFound);
|
|
1286 |
}
|
|
1287 |
}
|
|
1288 |
}
|
|
1289 |
|
|
1290 |
/**
|
|
1291 |
* This allows us to read directly from the flash into a buffer of our choosing
|
|
1292 |
* @param aDestinationBuffer This is the buffer we will read that data into. It will be appended on to the end of this descriptor
|
|
1293 |
* @param aReadPos Point in flash from which to read
|
|
1294 |
* @param aReadSize Amount of data to read. If this is greater than the space in aDestinationBuffer, not all the data will be read
|
|
1295 |
* @leave one of the system wide codes
|
|
1296 |
*/
|
|
1297 |
void CFlashDataSource::ReadRawFlashL(TDes8& aDestinationBuffer, TUint aReadPos, TUint aReadSize)
|
|
1298 |
{
|
|
1299 |
TUint8* destination = const_cast<TUint8*>(aDestinationBuffer.Ptr());
|
|
1300 |
TUint spaceInBuffer = aDestinationBuffer.MaxLength() - aDestinationBuffer.Length();
|
|
1301 |
TUint rdSize = (aReadSize > spaceInBuffer) ? spaceInBuffer : aReadSize;
|
|
1302 |
|
|
1303 |
//Give it a ptr starting at the end of the desc so it doesnt overwrite any data already there (ReadCrashLog always writes the data from 0)
|
|
1304 |
TPtr8 ptr(destination + aDestinationBuffer.Length(), aDestinationBuffer.MaxLength() - aDestinationBuffer.Length());
|
|
1305 |
|
|
1306 |
User::LeaveIfError(iSecSess.ReadCrashLog(aReadPos, ptr, rdSize));
|
|
1307 |
|
|
1308 |
aDestinationBuffer.SetLength(aDestinationBuffer.Length() + ptr.Length());
|
|
1309 |
}
|
|
1310 |
|
|
1311 |
/**
|
|
1312 |
* Read the SCM configuration data from flash buffer
|
|
1313 |
*/
|
|
1314 |
void CFlashDataSource::ReadSCMConfigL(RConfigParameterList& aScmConfigList)
|
|
1315 |
{
|
|
1316 |
|
|
1317 |
LOG_MSG("CFlashDataSource::ReadSCMConfigL");
|
|
1318 |
|
|
1319 |
aScmConfigList.ResetAndDestroy();
|
|
1320 |
|
|
1321 |
Debug::SCMConfiguration* theConfig = GetSCMConfigFromFlashL();
|
|
1322 |
|
|
1323 |
if(!theConfig)
|
|
1324 |
{
|
|
1325 |
CLTRACE("(CFlashDataSource::ReadSCMConfigL) no config saved - using default");
|
|
1326 |
iScmConfig->SetDefaultConfig();
|
|
1327 |
}
|
|
1328 |
else
|
|
1329 |
{
|
|
1330 |
|
|
1331 |
CLTRACE("(CFlashDataSource::ReadSCMConfigL) config FOUND");
|
|
1332 |
delete iScmConfig;
|
|
1333 |
iScmConfig = theConfig;
|
|
1334 |
|
|
1335 |
// ok we have a config - now read to see if we have a crash following
|
|
1336 |
ReallocFlashBuf(Align4(TCrashInfoHeader::KSCMCrashInfoMaxSize));
|
|
1337 |
User::LeaveIfError(iSecSess.ReadCrashLog(Align4(iScmConfig->GetSize()), iFlashBuf, TCrashInfoHeader::KSCMCrashInfoMaxSize));
|
|
1338 |
|
|
1339 |
TCrashInfoHeader header;
|
|
1340 |
TByteStreamReader r2(const_cast<TUint8*>((iFlashBuf).Ptr()));
|
|
1341 |
if( header.Deserialize(r2) == KErrNone)
|
|
1342 |
{
|
|
1343 |
CLTRACE("(CFlashDataSource::ReadSCMConfigL) HEADER found OK");
|
|
1344 |
|
|
1345 |
// we should now have a blocksize in the header
|
|
1346 |
iCrashFound = ETrue;
|
|
1347 |
// create a buffer big enough to hold the entire first block
|
|
1348 |
iFirstBlockBuf.Close();
|
|
1349 |
iFirstBlockBuf.Create(header.iFlashBlockSize);
|
|
1350 |
|
|
1351 |
// read the whole block into the buffer
|
|
1352 |
TInt err = iSecSess.ReadCrashLog(0, iFirstBlockBuf, header.iFlashBlockSize);
|
|
1353 |
|
|
1354 |
if(err != KErrNone)
|
|
1355 |
{
|
|
1356 |
CLTRACE1("(CFlashDataSource::ReadSCMConfigL) Error reading cache block %d", err);
|
|
1357 |
}
|
|
1358 |
}
|
|
1359 |
else
|
|
1360 |
{
|
|
1361 |
CLTRACE("(CFlashDataSource::ReadSCMConfigL) NO crash header found");
|
|
1362 |
}
|
|
1363 |
|
|
1364 |
}
|
|
1365 |
|
|
1366 |
TConfigItem* item = iScmConfig->ConfigList();
|
|
1367 |
TInt i = 0;
|
|
1368 |
while(item)
|
|
1369 |
{
|
|
1370 |
// transfer the TCongigItems into the array
|
|
1371 |
COptionConfig* config = COptionConfig::NewL( i,
|
|
1372 |
item->GetDataType(),
|
|
1373 |
COptionConfig::ESCMConfig,
|
|
1374 |
COptionConfig::ETInt,
|
|
1375 |
TConfigItem::GetSCMConfigOptionText(item->GetDataType()),
|
|
1376 |
0,
|
|
1377 |
KNullDesC,
|
|
1378 |
item->GetPriority(),
|
|
1379 |
KNullDesC );
|
|
1380 |
config->Instance(item->GetDataType());
|
|
1381 |
i++;
|
|
1382 |
aScmConfigList.AppendL(config);
|
|
1383 |
item = item->Next();
|
|
1384 |
}
|
|
1385 |
}
|
|
1386 |
|
|
1387 |
void CFlashDataSource::WriteSCMConfigL()
|
|
1388 |
{
|
|
1389 |
// if we have a crash found then use the appropriate buffer
|
|
1390 |
RBuf8& buf = iCrashFound ? iFirstBlockBuf : iFlashBuf;
|
|
1391 |
|
|
1392 |
CLTRACE2("(CFlashDataSource::WriteSCMConfigL) - Writing config buf.Length() = %d iCrashFound %d",
|
|
1393 |
buf.Length(), iCrashFound );
|
|
1394 |
|
|
1395 |
TByteStreamWriter writer(const_cast<TUint8*>(buf.Ptr()));
|
|
1396 |
iScmConfig->Serialize(writer);
|
|
1397 |
|
|
1398 |
iSecSess.EraseCrashLog(0, 1);
|
|
1399 |
TUint32 size = 0;
|
|
1400 |
TInt res = iSecSess.WriteCrashConfig(0, buf, size);
|
|
1401 |
|
|
1402 |
CLTRACE2("(CFlashDataSource::WriteSCMConfigL) RESULT res = %d size = %d", res, size);
|
|
1403 |
}
|
|
1404 |
|
|
1405 |
void CFlashDataSource::ModifySCMConfigItemL(TUint32 aDataType, TInt32 aPriority)
|
|
1406 |
{
|
|
1407 |
CLTRACE2("(CFlashDataSource::ModifySCMConfigItemL) - modifying aDataType %d with priority %d", aDataType, aPriority);
|
|
1408 |
|
|
1409 |
//check for Priority value to be within 0-255 otherwise leave with KErrArgument
|
|
1410 |
if( (aPriority < 0) || (aPriority > 255) )
|
|
1411 |
{
|
|
1412 |
LOG_MSG( " ERROR: SCM Priority out of bounds, should be within 0-255\n");
|
|
1413 |
User::Leave(KErrArgument);
|
|
1414 |
}
|
|
1415 |
|
|
1416 |
TInt err = iScmConfig->ModifyConfigItemPriority((Debug::TConfigItem::TSCMDataType)aDataType, aPriority);
|
|
1417 |
|
|
1418 |
if( err == KErrNone)
|
|
1419 |
{
|
|
1420 |
// also write change through to flash
|
|
1421 |
WriteSCMConfigL();
|
|
1422 |
}
|
|
1423 |
else
|
|
1424 |
{
|
|
1425 |
CLTRACE3("CFlashDataSource::ModifySCMConfigItemL) failed to modify err = %d aDataType = %d aPriority = %d"
|
|
1426 |
, err, aDataType, aPriority );
|
|
1427 |
}
|
|
1428 |
}
|
|
1429 |
|
|
1430 |
Debug::SCMConfiguration& CFlashDataSource::SCMConfiguration()
|
|
1431 |
{
|
|
1432 |
return *iScmConfig;
|
|
1433 |
}
|
|
1434 |
|
|
1435 |
/**
|
|
1436 |
* Cleanup item implementation for Code Seg List
|
|
1437 |
* @param aArray pointer to the list that is supposed to be freed
|
|
1438 |
*/
|
|
1439 |
void CFlashDataSource::CleanupCodeSegList(TAny *aArray)
|
|
1440 |
{
|
|
1441 |
LOG_MSG("->CFlashDataSource::CleanupCodeSegList()\n");
|
|
1442 |
RCodeSegPointerList *codeSegList = static_cast<RCodeSegPointerList*> (aArray);
|
|
1443 |
codeSegList->ResetAndDestroy();
|
|
1444 |
codeSegList->Close();
|
|
1445 |
delete codeSegList;
|
|
1446 |
}
|
|
1447 |
|
|
1448 |
/**
|
|
1449 |
* Cleanup item implementation for process list.
|
|
1450 |
* @param aArray pointer to the list that is supposed to be freed
|
|
1451 |
*/
|
|
1452 |
void CFlashDataSource::CleanupProcessList(TAny *aArray)
|
|
1453 |
{
|
|
1454 |
LOG_MSG("->CFlashDataSource::CleanupProcessList()\n");
|
|
1455 |
RProcessPointerList *processList = static_cast<RProcessPointerList*> (aArray);
|
|
1456 |
processList->ResetAndDestroy();
|
|
1457 |
processList->Close();
|
|
1458 |
delete processList;
|
|
1459 |
}
|
|
1460 |
|
|
1461 |
/**
|
|
1462 |
* Cleanup item implementation for thread list.
|
|
1463 |
* @param aArray pointer to the list that is supposed to be freed
|
|
1464 |
*/
|
|
1465 |
void CFlashDataSource::CleanupThreadList(TAny *aArray)
|
|
1466 |
{
|
|
1467 |
LOG_MSG("->CFlashDataSource::CleanupThreadList()\n");
|
|
1468 |
RThreadPointerList *threadList = static_cast<RThreadPointerList*> (aArray);
|
|
1469 |
threadList->ResetAndDestroy();
|
|
1470 |
threadList->Close();
|
|
1471 |
delete threadList;
|
|
1472 |
}
|
|
1473 |
|
|
1474 |
/**
|
|
1475 |
* CalculateChecksum - calsulates the checksum for the given length of
|
|
1476 |
* the flash buffer (if this is the entire length it should not include
|
|
1477 |
* the checksum footer)
|
|
1478 |
* @param aLogSize - the total size of flash buf to check
|
|
1479 |
* @param aChecksum - the checksum where the result will be placed - as this checksum is
|
|
1480 |
* commutative the aChecksum value may be reset or already hold data as required
|
|
1481 |
* @return void
|
|
1482 |
*/
|
|
1483 |
void CFlashDataSource::CalculateChecksumL(TInt aStart, TInt aLength, TScmChecksum& aChecksum)
|
|
1484 |
{
|
|
1485 |
if( aLength <= 0)
|
|
1486 |
{
|
|
1487 |
// invalid block length
|
|
1488 |
User::Leave(KErrGeneral);
|
|
1489 |
}
|
|
1490 |
|
|
1491 |
const TInt KDefaultBlockSize = 0xFF;
|
|
1492 |
const TInt KBlocksize = aLength > KDefaultBlockSize ? KDefaultBlockSize : aLength;
|
|
1493 |
|
|
1494 |
TInt remaining = aLength;
|
|
1495 |
TInt pos = aStart;
|
|
1496 |
|
|
1497 |
while(remaining > KBlocksize)
|
|
1498 |
{
|
|
1499 |
//CLTRACE2("->CFlashDataSource::CalculateChecksum rem = %d blksz = %d\n", remaining, KBlocksize);
|
|
1500 |
User::LeaveIfError(ReadCrashLog(pos, KBlocksize));
|
|
1501 |
pos += KBlocksize;
|
|
1502 |
remaining -= KBlocksize;
|
|
1503 |
aChecksum.ChecksumBlock(iFlashBuf);
|
|
1504 |
}
|
|
1505 |
|
|
1506 |
if(remaining > 0)
|
|
1507 |
{
|
|
1508 |
User::LeaveIfError(ReadCrashLog(pos, remaining));
|
|
1509 |
aChecksum.ChecksumBlock(iFlashBuf);
|
|
1510 |
|
|
1511 |
pos += remaining;
|
|
1512 |
if(pos != aLength)
|
|
1513 |
{
|
|
1514 |
User::Leave(KErrCorrupt);
|
|
1515 |
}
|
|
1516 |
}
|
|
1517 |
}
|
|
1518 |
|
|
1519 |
/**
|
|
1520 |
* Retrieves ROM build information from flash partition if available
|
|
1521 |
* @param aRomHeader stores the rom build info
|
|
1522 |
* @leave one of the OS wide codes
|
|
1523 |
*/
|
|
1524 |
void CFlashDataSource::GetROMBuildInfoL(TRomHeaderData& aRomHeader)
|
|
1525 |
{
|
|
1526 |
if(iRomBuildInfo)
|
|
1527 |
{
|
|
1528 |
aRomHeader = *iRomBuildInfo;
|
|
1529 |
return;
|
|
1530 |
}
|
|
1531 |
|
|
1532 |
User::Leave(KErrNotFound);
|
|
1533 |
}
|
|
1534 |
|
|
1535 |
/**
|
|
1536 |
* Retrieves System lock data
|
|
1537 |
* @param aLockData Contains the data for the system locks
|
|
1538 |
* @leave one of the OS wide codes
|
|
1539 |
*/
|
|
1540 |
void CFlashDataSource::GetLocksL(TSCMLockData& aLockData)
|
|
1541 |
{
|
|
1542 |
if(iLockData)
|
|
1543 |
{
|
|
1544 |
aLockData = *iLockData;
|
|
1545 |
return;
|
|
1546 |
}
|
|
1547 |
|
|
1548 |
User::Leave(KErrNotFound);
|
|
1549 |
}
|
|
1550 |
|
|
1551 |
TInt CFlashDataSource::ReallocFlashBuf(const TUint aSize)
|
|
1552 |
{
|
|
1553 |
//Reallocate the flash buffer to be the size required
|
|
1554 |
|
|
1555 |
if(aSize > iFlashBuf.MaxLength())
|
|
1556 |
{
|
|
1557 |
TInt err = iFlashBuf.ReAlloc(aSize);
|
|
1558 |
if (KErrNone != err)
|
|
1559 |
{
|
|
1560 |
CLTRACE2("(CFlashDataSource::ReallocFlashBuf) - ERROR alloc on iFlashBuf err = %d. Trying to alloc aSize [0x%x] bytes", err, aSize);
|
|
1561 |
return err;
|
|
1562 |
}
|
|
1563 |
}
|
|
1564 |
else
|
|
1565 |
{
|
|
1566 |
iFlashBuf.SetLength(aSize);
|
|
1567 |
}
|
|
1568 |
|
|
1569 |
return KErrNone;
|
|
1570 |
}
|
|
1571 |
|
|
1572 |
void CFlashDataSource::PrintFlashBuf()
|
|
1573 |
{
|
|
1574 |
CLTRACE1("(CFlashDataSource::PrintFlashBuf) iFlashBuf.Length = %d ", iFlashBuf.Length());
|
|
1575 |
for(TInt i=0;i<iFlashBuf.Length();i++)
|
|
1576 |
{
|
|
1577 |
CLTRACE4("iFlashBuf[%d] = char<%c> dec<%d> hex<%x>", i, iFlashBuf[i], iFlashBuf[i] ,iFlashBuf[i]);
|
|
1578 |
}
|
|
1579 |
}
|
|
1580 |
|
|
1581 |
void CFlashDataSource::ReleaseFirstBlockBuf()
|
|
1582 |
{
|
|
1583 |
iFirstBlockBuf.Close();
|
|
1584 |
iCrashFound = EFalse;
|
|
1585 |
}
|
|
1586 |
|
|
1587 |
void CFlashDataSource::GetExceptionStackL(const Debug::TArmProcessorModes aMode, TDes8& aStack, TUint aStartReadPoint)
|
|
1588 |
{
|
|
1589 |
//Not implemented
|
|
1590 |
}
|
|
1591 |
|
|
1592 |
/**
|
|
1593 |
* @see CCrashDataSource::GetVersion
|
|
1594 |
*/
|
|
1595 |
TVersion CFlashDataSource::GetVersion() const
|
|
1596 |
{
|
|
1597 |
return KFlashCrashDataSourceVersion;
|
|
1598 |
}
|
|
1599 |
|
|
1600 |
/**
|
|
1601 |
* @see CCrashDataSource::GetDataSourceFunctionalityBufSize
|
|
1602 |
*/
|
|
1603 |
TInt CFlashDataSource::GetDataSourceFunctionalityBufSize(TUint& aBufSize)
|
|
1604 |
{
|
|
1605 |
return KErrNotSupported;
|
|
1606 |
}
|
|
1607 |
|
|
1608 |
/**
|
|
1609 |
* @see CCrashDataSource::GetDataSourceFunctionality
|
|
1610 |
*/
|
|
1611 |
TInt CFlashDataSource::GetDataSourceFunctionality(TDes8& aFuncBuffer)
|
|
1612 |
{
|
|
1613 |
return KErrNotSupported;
|
|
1614 |
}
|
|
1615 |
/**
|
|
1616 |
* @see CCrashDataSource::GetExceptionStackSizeL
|
|
1617 |
*/
|
|
1618 |
TUint CFlashDataSource::GetExceptionStackSizeL(const Debug::TArmProcessorModes aMode)
|
|
1619 |
{
|
|
1620 |
/* TInt bufferSize = 0;
|
|
1621 |
TInt pos = 0;
|
|
1622 |
SCMStructId id = ESCMLast;
|
|
1623 |
|
|
1624 |
TBool validStack = ETrue;
|
|
1625 |
TUint32 rdPoint = iOffsetsHdr.iExcStkOffset;
|
|
1626 |
|
|
1627 |
while(validStack)
|
|
1628 |
{
|
|
1629 |
//Read in the thread stack, memory dump and raw data structs each time
|
|
1630 |
User::LeaveIfError(ReadCrashLog(rdPoint, TThreadStack::MAX_SIZE + TMemoryDump::MAX_SIZE + TRawData::MAX_SIZE));
|
|
1631 |
|
|
1632 |
MByteStreamSerializable* data = iWalker.GetNextDataTypeL(pos, id, bufferSize);
|
|
1633 |
CleanupStack::PushL(data);
|
|
1634 |
|
|
1635 |
//Make sure we have a valid TRawData or TMemory or TThreadStack
|
|
1636 |
if(id == ESCMThreadStack)
|
|
1637 |
{
|
|
1638 |
TThreadStack* thread = static_cast<TThreadStack*>(data);
|
|
1639 |
|
|
1640 |
//The enums here dont match so gotta case
|
|
1641 |
switch(aMode)
|
|
1642 |
{
|
|
1643 |
case Debug::EFiqMode :
|
|
1644 |
{
|
|
1645 |
if(thread->iStackType == TThreadStack::EFIQStack)
|
|
1646 |
{
|
|
1647 |
CleanupStack::PopAndDestroy(data);
|
|
1648 |
return thread.iStackSize;
|
|
1649 |
}
|
|
1650 |
//otherwise fall through to default
|
|
1651 |
}
|
|
1652 |
case Debug::EIrqMode :
|
|
1653 |
{
|
|
1654 |
if(thread->iStackType == TThreadStack::EIRQStack)
|
|
1655 |
{
|
|
1656 |
CleanupStack::PopAndDestroy(data);
|
|
1657 |
return thread.iStackSize;
|
|
1658 |
}
|
|
1659 |
|
|
1660 |
//otherwise fall through to default
|
|
1661 |
}
|
|
1662 |
//Not supported for now
|
|
1663 |
case Debug::ESvcMode :
|
|
1664 |
case Debug::EAbortMode :
|
|
1665 |
case Debug::EUndefMode :
|
|
1666 |
case Debug::EMaskMode :
|
|
1667 |
default:
|
|
1668 |
{
|
|
1669 |
CleanupStack::PopAndDestroy(data);
|
|
1670 |
continue;
|
|
1671 |
}
|
|
1672 |
}
|
|
1673 |
|
|
1674 |
//Now is it the stack of interest
|
|
1675 |
}
|
|
1676 |
else
|
|
1677 |
{
|
|
1678 |
CleanupStack::PopAndDestroy(data);
|
|
1679 |
User::Leave(KErrNotFound);
|
|
1680 |
}
|
|
1681 |
}
|
|
1682 |
|
|
1683 |
*/
|
|
1684 |
return 0;
|
|
1685 |
}
|
|
1686 |
|
|
1687 |
/**
|
|
1688 |
* @see CCrashDataSource::GetVariantSpecificDataSize
|
|
1689 |
*/
|
|
1690 |
TInt CFlashDataSource::GetVariantSpecificDataSize(TUint& aDataSize)
|
|
1691 |
{
|
|
1692 |
CLTRACE("Start CFlashDataSource::GetVariantSpecificDataSize()");
|
|
1693 |
|
|
1694 |
if(iVarSpecData)
|
|
1695 |
{
|
|
1696 |
aDataSize = iVarSpecData->iSize;
|
|
1697 |
return KErrNone;
|
|
1698 |
}
|
|
1699 |
else
|
|
1700 |
{
|
|
1701 |
return KErrNotSupported;
|
|
1702 |
}
|
|
1703 |
}
|
|
1704 |
|
|
1705 |
/**
|
|
1706 |
* @see CCrashDataSource::GetVariantSpecificData
|
|
1707 |
*/
|
|
1708 |
TInt CFlashDataSource::GetVariantSpecificData(TDes8 &aVarSpecData)
|
|
1709 |
{
|
|
1710 |
aVarSpecData.Zero();
|
|
1711 |
|
|
1712 |
if(!iVarSpecData)
|
|
1713 |
{
|
|
1714 |
CLTRACE("CFlashDataSource::GetVariantSpecificData --> No variant specific data in flash");
|
|
1715 |
return KErrNotFound;
|
|
1716 |
}
|
|
1717 |
|
|
1718 |
if(aVarSpecData.MaxSize() != iVarSpecData->iSize)
|
|
1719 |
{
|
|
1720 |
CLTRACE1("CFlashDataSource::GetVariantSpecificData --> Supplied descriptor was not big enough for data. Need at least [%d] bytes", iVarSpecData->iSize);
|
|
1721 |
return KErrBadDescriptor;
|
|
1722 |
}
|
|
1723 |
|
|
1724 |
TUint rawDataPos = iOffsetsHdr.iVarSpecInfOffset + iVarSpecData->GetSize();
|
|
1725 |
|
|
1726 |
TInt err = ReadCrashLog(rawDataPos, TRawData::KSCMRawDataMaxSize);
|
|
1727 |
if(KErrNone != err)
|
|
1728 |
{
|
|
1729 |
CLTRACE1("CFlashDataSource::GetVariantSpecificData -- Unable to read variant data from crash log: [%d]", err);
|
|
1730 |
return err;
|
|
1731 |
}
|
|
1732 |
|
|
1733 |
SCMStructId id = ESCMLast;
|
|
1734 |
TInt nextBufferSizeIfNull = 0;
|
|
1735 |
TInt nextBufferRead = 0;
|
|
1736 |
|
|
1737 |
//We now walk the data that we just buffered in the ReadCrashLog call (our data is at start of buffer)
|
|
1738 |
MByteStreamSerializable* theRawness = iWalker.GetNextDataTypeL(nextBufferRead, id, nextBufferSizeIfNull);
|
|
1739 |
if(theRawness && id == ESCMRawData)
|
|
1740 |
{
|
|
1741 |
TRawData* raw = static_cast<TRawData*>(theRawness);
|
|
1742 |
CleanupStack::PushL(theRawness);
|
|
1743 |
|
|
1744 |
//Read the raw data into supplied buffer
|
|
1745 |
TRAP(err, ReadRawFlashL(aVarSpecData, rawDataPos + TRawData::KSCMRawDataMaxSize, raw->iLength));
|
|
1746 |
CleanupStack::PopAndDestroy(theRawness);
|
|
1747 |
if(KErrNone != err)
|
|
1748 |
{
|
|
1749 |
CLTRACE1("CFlashDataSource::GetVariantSpecificData -- Reading raw data fromn flash failed: [%d]", err);
|
|
1750 |
aVarSpecData.Zero();
|
|
1751 |
return err;
|
|
1752 |
}
|
|
1753 |
}
|
|
1754 |
else
|
|
1755 |
{
|
|
1756 |
//The read crash log gave it the correct values (size etc) so if its NULL it means it's not been found
|
|
1757 |
//(Perhaps this should be a KErrCorrupt as to get this far, the crash log has been telling us there is
|
|
1758 |
//var specific data. Don't want to make the parsing too strict though.)
|
|
1759 |
return KErrNotFound;
|
|
1760 |
}
|
|
1761 |
|
|
1762 |
return KErrNone;
|
|
1763 |
}
|
|
1764 |
|
|
1765 |
//eof flashdatasource.cpp
|