1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/misc/thrdlist.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,140 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\misc\thrdlist.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32svr.h>
1.22 +#include <f32file.h>
1.23 +
1.24 +_LIT(KFileName,"C:\\THRDLIST.TXT");
1.25 +_LIT(KLitAsterisk,"*");
1.26 +_LIT(KLitProblem,"Could not open thread");
1.27 +
1.28 +struct SArmRegSet
1.29 + {
1.30 + TUint32 iR0;
1.31 + TUint32 iR1;
1.32 + TUint32 iR2;
1.33 + TUint32 iR3;
1.34 + TUint32 iR4;
1.35 + TUint32 iR5;
1.36 + TUint32 iR6;
1.37 + TUint32 iR7;
1.38 + TUint32 iR8;
1.39 + TUint32 iR9;
1.40 + TUint32 iR10;
1.41 + TUint32 iR11;
1.42 + TUint32 iR12;
1.43 + TUint32 iR13;
1.44 + TUint32 iR14;
1.45 + TUint32 iR15;
1.46 + TUint32 iFlags;
1.47 + TUint32 iDacr;
1.48 + };
1.49 +
1.50 +TUint ThreadId(const RThread& aThread)
1.51 + {
1.52 + TThreadId id=aThread.Id();
1.53 + TUint* p=(TUint*)&id;
1.54 + return *p;
1.55 + }
1.56 +
1.57 +TUint ProcessId(const RProcess& aProcess)
1.58 + {
1.59 + TProcessId id=aProcess.Id();
1.60 + TUint* p=(TUint*)&id;
1.61 + return *p;
1.62 + }
1.63 +
1.64 +GLDEF_C TInt E32Main()
1.65 + {
1.66 + RThread().SetPriority(EPriorityAbsoluteHigh);
1.67 + RFs fs;
1.68 + TInt r=fs.Connect();
1.69 + if (r!=KErrNone)
1.70 + User::Panic(_L("THRDLIST FS"),r);
1.71 + RFile file;
1.72 + r=file.Open(fs,KFileName,EFileWrite);
1.73 + if (r==KErrNotFound)
1.74 + r=file.Create(fs,KFileName,EFileWrite);
1.75 + if (r==KErrNone)
1.76 + {
1.77 + TInt p=0;
1.78 + r=file.Seek(ESeekEnd,p);
1.79 + }
1.80 + if (r!=KErrNone)
1.81 + User::Panic(_L("THRDLIST FILE"),r);
1.82 + TTime now;
1.83 + now.HomeTime();
1.84 + TBuf<1024> buf;
1.85 + TDateTime dt=now.DateTime();
1.86 + buf.Format(_L("Time %02d:%02d:%02d:%06d Date %02d/%02d/%04d\n"),dt.Hour(),dt.Minute(),dt.Second(),dt.MicroSecond(),dt.Day()+1,dt.Month()+1,dt.Year());
1.87 + r=file.Write(buf);
1.88 + if (r!=KErrNone)
1.89 + User::Panic(_L("THRDLIST WRITE"),r);
1.90 + TFindThread ft(KLitAsterisk);
1.91 + TFullName fn;
1.92 + while (ft.Next(fn)==KErrNone)
1.93 + {
1.94 + RThread t;
1.95 + r=t.Open(ft);
1.96 + TExitType exitType=EExitKill;
1.97 + TInt exitReason=0;
1.98 + TBuf<32> exitCat;
1.99 + TFullName procName;
1.100 + TUint tid=0xffffffff;
1.101 + TUint pid=0xffffffff;
1.102 + SArmRegSet regs;
1.103 + Mem::FillZ(®s,sizeof(regs));
1.104 + TPckg<SArmRegSet> regPckg(regs);
1.105 + if (r==KErrNone)
1.106 + {
1.107 + t.Context(regPckg);
1.108 + exitType=t.ExitType();
1.109 + exitReason=t.ExitReason();
1.110 + exitCat=t.ExitCategory();
1.111 + tid=ThreadId(t);
1.112 + RProcess p;
1.113 + r=t.Process(p);
1.114 + if (r==KErrNone)
1.115 + {
1.116 + procName=p.FullName();
1.117 + pid=ProcessId(p);
1.118 + p.Close();
1.119 + }
1.120 + }
1.121 + else
1.122 + fn=KLitProblem;
1.123 + buf.Format(_L("Thread %S (id=%d) in process %S (id=%d)\n"),&fn,tid,&procName,pid);
1.124 + file.Write(buf);
1.125 + buf.Format(_L("Exit info %d,%d,%S\n"),exitType,exitReason,&exitCat);
1.126 + file.Write(buf);
1.127 + buf.Format(_L(" R0=%08x R1=%08x R2=%08x R3=%08x\n"),regs.iR0,regs.iR1,regs.iR2,regs.iR3);
1.128 + file.Write(buf);
1.129 + buf.Format(_L(" R4=%08x R5=%08x R6=%08x R7=%08x\n"),regs.iR4,regs.iR5,regs.iR6,regs.iR7);
1.130 + file.Write(buf);
1.131 + buf.Format(_L(" R8=%08x R9=%08x R10=%08x R11=%08x\n"),regs.iR8,regs.iR9,regs.iR10,regs.iR11);
1.132 + file.Write(buf);
1.133 + buf.Format(_L(" R12=%08x R13=%08x R14=%08x R15=%08x\n"),regs.iR12,regs.iR13,regs.iR14,regs.iR15);
1.134 + file.Write(buf);
1.135 + buf.Format(_L("CPSR=%08x DACR=%08x\n\n"),regs.iFlags,regs.iDacr);
1.136 + file.Write(buf);
1.137 + t.Close();
1.138 + }
1.139 + file.Close();
1.140 + fs.Close();
1.141 + return KErrNone;
1.142 + }
1.143 +