0
|
1 |
// Copyright (c) 2004-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 the License "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 |
// e32\kernel\smonlog.cpp
|
|
15 |
// Automatic (non-iteractive) crash logger.
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include <kernel/monitor.h>
|
|
20 |
#include <crashflash.h>
|
|
21 |
#include <assp.h>
|
|
22 |
|
|
23 |
#ifdef _CRASHLOG_COMPR
|
|
24 |
#include "crashlog_gzip.h"
|
|
25 |
#endif
|
|
26 |
|
|
27 |
const TInt KRestartType = CrashLogger::ESoftRestart;
|
|
28 |
|
|
29 |
/** Number of seconds elapsed between 01/01/0000 AD and 01/01/2000 AD.
|
|
30 |
Value is the number of days multiplied by the number of seconds per day:
|
|
31 |
730497 * 86400
|
|
32 |
*/
|
|
33 |
const TInt64 KYear2000ADInSeconds = I64LIT(63114940800);
|
|
34 |
|
|
35 |
IMPORT_C TInt64 CrashTime();
|
|
36 |
|
|
37 |
|
|
38 |
#ifdef _CRASHLOG_COMPR
|
|
39 |
LOCAL_D TCrashLogGzip gDebugGzip;
|
|
40 |
#endif
|
|
41 |
|
|
42 |
GLDEF_D CrashLogger TheCrashLogger;
|
|
43 |
|
|
44 |
CrashLogger::CrashLogger()
|
|
45 |
#ifdef _CRASHLOG_COMPR
|
|
46 |
: iEncoder(&gDebugGzip)
|
|
47 |
#endif
|
|
48 |
{}
|
|
49 |
|
|
50 |
void CrashLogger::Print(const TDesC8& aDes)
|
|
51 |
{
|
|
52 |
#ifdef _CRASHLOG_COMPR
|
|
53 |
if (!iTruncated)
|
|
54 |
{
|
|
55 |
iTruncated = iEncoder->Write(aDes);
|
|
56 |
}
|
|
57 |
#else
|
|
58 |
TheCrashLogger.iFlash->Write(aDes);
|
|
59 |
#endif
|
|
60 |
}
|
|
61 |
|
|
62 |
TInt CrashLogger::Init2(TAny* aCategory, TInt aReason)
|
|
63 |
{
|
|
64 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Starting Crash Logger..."));
|
|
65 |
|
|
66 |
if(KDebugNum(KCRASHLOGGERDISABLE))
|
|
67 |
{
|
|
68 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Crash Logger Disabled; Closing."));
|
|
69 |
return KErrNone;
|
|
70 |
}
|
|
71 |
|
|
72 |
if(!iFlash)
|
|
73 |
{
|
|
74 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Crash logger has not been fully initialised, exiting..."));
|
|
75 |
return KRestartType;
|
|
76 |
}
|
|
77 |
iFrame=NULL;
|
|
78 |
iFaultCategory=*(const TDesC8*)aCategory;
|
|
79 |
iFaultReason=aReason;
|
|
80 |
Epoc::SetMonitorExceptionHandler((TLinAddr)HandleException);
|
|
81 |
CpuInit();
|
|
82 |
|
|
83 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Crash Logger initialised"));
|
|
84 |
|
|
85 |
iFlash->StartTransaction();
|
|
86 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Started transaction..."));
|
|
87 |
|
|
88 |
if(SignatureExists())
|
|
89 |
{
|
|
90 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Refusing to overwrite existing crash log, exiting..."));
|
|
91 |
return KRestartType;
|
|
92 |
}
|
|
93 |
__KTRACE_OPT(KALWAYS,Kern::Printf("No existing crash log found. Proceeding with crash log dump..."));
|
|
94 |
|
|
95 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Erasing log area..."));
|
|
96 |
iFlash->EraseLogArea();
|
|
97 |
|
|
98 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping crashinfo..."));
|
|
99 |
DumpCrashInfo();
|
|
100 |
|
|
101 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Writing signature..."));
|
|
102 |
WriteSignature();
|
|
103 |
|
|
104 |
iFlash->EndTransaction();
|
|
105 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Transaction completed."));
|
|
106 |
return KRestartType;
|
|
107 |
}
|
|
108 |
|
|
109 |
TBool CrashLogger::SignatureExists()
|
|
110 |
{
|
|
111 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf(">CrashLogger::SignatureExists()."));
|
|
112 |
iFlash->SetReadPos(KCrashLogSizeFieldBytes);
|
|
113 |
TBuf8<KCrashLogSignatureBytes> buf(0);
|
|
114 |
buf.Copy(KCrashLogSignature);
|
|
115 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf("Expected signature: %S", &KCrashLogSignature));
|
|
116 |
buf.SetLength(KCrashLogSignatureBytes);
|
|
117 |
iFlash->Read(buf);
|
|
118 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf("Found signature: %S", &buf));
|
|
119 |
if(buf.Compare(KCrashLogSignature) != 0)
|
|
120 |
{
|
|
121 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf("<CrashLogger::SignatureExists():EFalse."));
|
|
122 |
return EFalse;
|
|
123 |
}
|
|
124 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf("<CrashLogger::SignatureExists():ETrue."));
|
|
125 |
return ETrue;
|
|
126 |
}
|
|
127 |
|
|
128 |
void CrashLogger::DumpCrashInfo()
|
|
129 |
{
|
|
130 |
volatile TInt state = ERomInfo;
|
|
131 |
#ifdef _CRASHLOG_COMPR
|
|
132 |
iTruncated = EFalse;
|
|
133 |
iEncoder->SetOutput(TheCrashLogger.iFlash);
|
|
134 |
#endif //_CRASHLOG_COMPR
|
|
135 |
for(state=0; state <= EFinished; )
|
|
136 |
{
|
|
137 |
MTRAPD(r, DoDumpCrashInfo(state))
|
|
138 |
if(r!=KErrNone)
|
|
139 |
{
|
|
140 |
ProcessError(r);
|
|
141 |
}
|
|
142 |
}
|
|
143 |
#ifdef _CRASHLOG_COMPR
|
|
144 |
iEncoder->FlushEnd();
|
|
145 |
#endif //_CRASHLOG_COMPR
|
|
146 |
}
|
|
147 |
|
|
148 |
void CrashLogger::DoDumpCrashInfo(volatile TInt& aState)
|
|
149 |
{
|
|
150 |
volatile TInt j = 0;
|
|
151 |
switch(aState)
|
|
152 |
{
|
|
153 |
case ERomInfo:
|
|
154 |
++aState;
|
|
155 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping rom information..."));
|
|
156 |
PrintLine("===Dumping rom information...===");
|
|
157 |
DumpRomInfo();
|
|
158 |
break;
|
|
159 |
case ECrashTime:
|
|
160 |
++aState;
|
|
161 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping crash time..."));
|
|
162 |
PrintLine("===Dumping crash time...===");
|
|
163 |
DumpCrashTime();
|
|
164 |
break;
|
|
165 |
case EFaultInfo:
|
|
166 |
++aState;
|
|
167 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping fault information..."));
|
|
168 |
PrintLine("===Dumping fault information...===");
|
|
169 |
DisplayFaultInfo();
|
|
170 |
break;
|
|
171 |
case EGeneralInfo:
|
|
172 |
++aState;
|
|
173 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping general crash info..."));
|
|
174 |
PrintLine("===Dumping general crash info...===");
|
|
175 |
TInt i;
|
|
176 |
ProcessInfoCommand(KNullDesC8, i);
|
|
177 |
break;
|
|
178 |
case EObjectContainers:
|
|
179 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping object containers..."));
|
|
180 |
PrintLine("===Dumping object containers...===");
|
|
181 |
for(; j < ENumObjectTypes; j++)
|
|
182 |
{
|
|
183 |
MTRAPD(r,DumpObjectContainer(j,EFalse));
|
|
184 |
if(r!=KErrNone)
|
|
185 |
{
|
|
186 |
ProcessError(r);
|
|
187 |
}
|
|
188 |
}
|
|
189 |
//Once we are done all the various containers advance the aState
|
|
190 |
++aState;
|
|
191 |
break;
|
|
192 |
|
|
193 |
case ERegisters:
|
|
194 |
++aState;
|
|
195 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping cpu registers..."));
|
|
196 |
PrintLine("===Dumping cpu registers...===");
|
|
197 |
DumpCpuRegisters();
|
|
198 |
break;
|
|
199 |
|
|
200 |
case ECurrentThreadStack:
|
|
201 |
++aState;
|
|
202 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping the current thread's stack..."));
|
|
203 |
PrintLine("===Dumping the current thread's stack...===");
|
|
204 |
DumpThreadStack(&Kern::CurrentThread());
|
|
205 |
break;
|
|
206 |
|
|
207 |
case EExceptionStacks:
|
|
208 |
++aState;
|
|
209 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping the exception stacks..."));
|
|
210 |
PrintLine("===Dumping Exception stacks...");
|
|
211 |
DumpExceptionStacks();
|
|
212 |
break;
|
|
213 |
|
|
214 |
case EVariantSpecific:
|
|
215 |
++aState;
|
|
216 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping variant specifc debug information..."));
|
|
217 |
PrintLine("===Dumping variant specifc debug information...===");
|
|
218 |
DumpVariantSpecific();
|
|
219 |
break;
|
|
220 |
|
|
221 |
case ECodeSegs:
|
|
222 |
++aState;
|
|
223 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping code segments..."));
|
|
224 |
PrintLine("===Dumping code segments...===");
|
|
225 |
DisplayCodeSeg(EFalse);
|
|
226 |
break;
|
|
227 |
|
|
228 |
case EOtherThreadStacks:
|
|
229 |
++aState;
|
|
230 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Dumping other thread stacks..."));
|
|
231 |
PrintLine("===Dumping other thread stacks...===");
|
|
232 |
DumpThreadStacks(EFalse);
|
|
233 |
break;
|
|
234 |
|
|
235 |
case EFinished:
|
|
236 |
++aState;
|
|
237 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Finished automatic debug dump."));
|
|
238 |
PrintLine("===Finished automatic debug dump.===");
|
|
239 |
break;
|
|
240 |
|
|
241 |
default:
|
|
242 |
++aState;
|
|
243 |
__KTRACE_OPT(KALWAYS,Kern::Printf("Unknown Auto Print State. Restarting..."));
|
|
244 |
PrintLine("===Unknown Auto Print State===");
|
|
245 |
Kern::Restart(0);
|
|
246 |
break;
|
|
247 |
}
|
|
248 |
}
|
|
249 |
|
|
250 |
void CrashLogger::WriteSignature()
|
|
251 |
{
|
|
252 |
#ifndef _CRASHLOG_COMPR
|
|
253 |
TBuf8<KCrashLogHeaderSize> sig(0);
|
|
254 |
*(TUint32*)(sig.Ptr()) = iFlash->BytesWritten() + KCrashLogHeaderSize;
|
|
255 |
sig.SetLength(KCrashLogSizeFieldBytes);
|
|
256 |
|
|
257 |
// Add the signature string
|
|
258 |
sig.Append(KCrashLogSignature);
|
|
259 |
iFlash->WriteSignature(sig);
|
|
260 |
#else
|
|
261 |
TBuf8<KCrashLogHeaderSize> sig(0);
|
|
262 |
TUint32* ptr = (TUint32*)sig.Ptr();
|
|
263 |
// The crashlog size in bytes including the header
|
|
264 |
*ptr = iFlash->BytesWritten() + KCrashLogHeaderSize;
|
|
265 |
__KTRACE_OPT(KALWAYS,Kern::Printf("WriteSignature: Size=%d",iFlash->BytesWritten() + KCrashLogHeaderSize));
|
|
266 |
|
|
267 |
// Add the signature string
|
|
268 |
sig.SetLength(KCrashLogSizeFieldBytes);
|
|
269 |
sig.Append(KCrashLogSignature);
|
|
270 |
ptr += (sig.Length()>>2); // seek to end of sig so far
|
|
271 |
|
|
272 |
// The crashlog uncompressed size
|
|
273 |
*ptr = iEncoder->GetDataCompressed();
|
|
274 |
ptr++;
|
|
275 |
__KTRACE_OPT(KALWAYS,Kern::Printf("WriteSignature: Uncompr Size=%d",iEncoder->GetDataCompressed()));
|
|
276 |
|
|
277 |
// The log flags
|
|
278 |
TUint32 flags = KCrashLogFlagGzip;
|
|
279 |
flags |= (iTruncated)?KCrashLogFlagTruncated : 0;
|
|
280 |
flags |= iFlash->GetLogOffset()<<KCrashLogFlagOffShift;
|
|
281 |
*ptr = flags;
|
|
282 |
__KTRACE_OPT(KALWAYS,Kern::Printf("WriteSignature: Flags=%08x",flags));
|
|
283 |
|
|
284 |
sig.SetLength(KCrashLogHeaderSize);
|
|
285 |
|
|
286 |
iFlash->WriteSignature(sig);
|
|
287 |
#endif //_CRASHLOG_COMPR
|
|
288 |
}
|
|
289 |
|
|
290 |
void CrashLogger::DumpExceptionStacks()
|
|
291 |
{
|
|
292 |
#if defined(__EPOC32__) && !defined(__CPU_X86)
|
|
293 |
|
|
294 |
TStackInfo& stackInfo = Kern::SuperPage().iStackInfo;
|
|
295 |
|
|
296 |
PrintLine(" Dumping IRQ stack...");
|
|
297 |
MTRAPD(r1,DoMemoryDumpL((TLinAddr)stackInfo.iIrqStackBase, stackInfo.iIrqStackSize));
|
|
298 |
if(r1!=KErrNone)
|
|
299 |
ProcessError(r1);
|
|
300 |
|
|
301 |
PrintLine(" Dumping FIQ stack...");
|
|
302 |
MTRAPD(r2,DoMemoryDumpL((TLinAddr)stackInfo.iFiqStackBase, stackInfo.iFiqStackSize));
|
|
303 |
if(r2!=KErrNone)
|
|
304 |
ProcessError(r2);
|
|
305 |
|
|
306 |
#else
|
|
307 |
PrintLine("Not Supported");
|
|
308 |
#endif
|
|
309 |
}
|
|
310 |
|
|
311 |
void CrashLogger::DumpRomInfo()
|
|
312 |
{
|
|
313 |
TVersion romVersion = Epoc::RomHeader().iVersion;
|
|
314 |
TVersionName v = romVersion.Name();
|
|
315 |
Printf("Rom Version: %S",&v);
|
|
316 |
|
|
317 |
TInt64 time = Epoc::RomHeader().iTime;
|
|
318 |
Printf("Rom built %x%xh seconds after 0 AD.",I64HIGH(time),I64LOW(time));
|
|
319 |
NewLine();
|
|
320 |
}
|
|
321 |
|
|
322 |
void CrashLogger::DumpCrashTime()
|
|
323 |
{
|
|
324 |
// We want time from 2000AD when SystemTime starts from 0AD hence the adjustment.
|
|
325 |
TTimeK secsSince0AD = CrashTime();
|
|
326 |
|
|
327 |
if(!secsSince0AD)
|
|
328 |
{
|
|
329 |
Printf("Data corruption prevented determining timestamp");
|
|
330 |
}
|
|
331 |
else
|
|
332 |
{
|
|
333 |
TTimeK secsSince2000AD = secsSince0AD - KYear2000ADInSeconds;
|
|
334 |
Printf("Crashed %xh seconds after 01/01/00 00:00:00.", secsSince2000AD);
|
|
335 |
}
|
|
336 |
|
|
337 |
NewLine();
|
|
338 |
}
|
|
339 |
|
|
340 |
void StartSecondary(TAny*)
|
|
341 |
{
|
|
342 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf("Initialising flash for crash logger"));
|
|
343 |
//InitFlash is implemented in the variant as it creates a variant
|
|
344 |
//specific derived CrashFlash
|
|
345 |
TheCrashLogger.InitFlash();
|
|
346 |
}
|
|
347 |
|
|
348 |
GLDEF_C TDfc StartSecondaryDfc(&StartSecondary, NULL, Kern::SvMsgQue(), KMaxDfcPriority-1);
|
|
349 |
|
|
350 |
GLDEF_C TInt KernelModuleEntry(TInt aReason)
|
|
351 |
{
|
|
352 |
if(aReason==KModuleEntryReasonVariantInit0)
|
|
353 |
{
|
|
354 |
#ifdef _CRASHLOG_COMPR
|
|
355 |
new(&gDebugGzip) TCrashLogGzip;
|
|
356 |
#endif
|
|
357 |
new(&TheCrashLogger) CrashLogger;
|
|
358 |
TheCrashLogger.iFlash = 0;
|
|
359 |
// We are going to register the crash logger here so that the order
|
|
360 |
// the monitor modules are placed in rom is preserved. However, since
|
|
361 |
// we haven't been entirely initialised, this monitor will have to be
|
|
362 |
// skipped if we crash prior to its full initialisation (in
|
|
363 |
// ExtensionInit1)
|
|
364 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf("Installing crash logger extension"));
|
|
365 |
Monitor::RegisterMonitorImpl(&TheCrashLogger);
|
|
366 |
return KErrNone;
|
|
367 |
}
|
|
368 |
else if(aReason==KModuleEntryReasonExtensionInit0)
|
|
369 |
{
|
|
370 |
// Returning KErrNone here ensures we are called later with aReason ==
|
|
371 |
// KModuleEntryReasonExtensionInit1.
|
|
372 |
return KErrNone;
|
|
373 |
}
|
|
374 |
else if(aReason==KModuleEntryReasonExtensionInit1)
|
|
375 |
{
|
|
376 |
// We have to be called at ExtensionInit1 as we require the kernel heap
|
|
377 |
// to allocate a DPlatChunkHw in CrashLogger::InitFlash(). The kernel
|
|
378 |
// heap doesn't exist until after ExtensionInit0
|
|
379 |
|
|
380 |
// Added later... In addition to requiring a kernel heap, we also need
|
|
381 |
// all nand flash drivers to have been loaded such that they initialise
|
|
382 |
// the hardware correctly for us. To do this, rather than initialising
|
|
383 |
// here, we enque a dfc to be handled after all modules have been
|
|
384 |
// loaded (exstart.cpp employs a similar scheme). We've given the dfc
|
|
385 |
// a highish priority to ensure that the crash logger is ready before
|
|
386 |
// the file system and most of the rest of the system boots. This
|
|
387 |
// should ensure that one can capture crashes that occur here.
|
|
388 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf("Enqueing dfc to init crash flash after all modules loaded"));
|
|
389 |
StartSecondaryDfc.Enque();
|
|
390 |
return KErrNone;
|
|
391 |
}
|
|
392 |
return KErrArgument;
|
|
393 |
}
|