sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\misc\thrdlist.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32svr.h>
|
sl@0
|
19 |
#include <f32file.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
_LIT(KFileName,"C:\\THRDLIST.TXT");
|
sl@0
|
22 |
_LIT(KLitAsterisk,"*");
|
sl@0
|
23 |
_LIT(KLitProblem,"Could not open thread");
|
sl@0
|
24 |
|
sl@0
|
25 |
struct SArmRegSet
|
sl@0
|
26 |
{
|
sl@0
|
27 |
TUint32 iR0;
|
sl@0
|
28 |
TUint32 iR1;
|
sl@0
|
29 |
TUint32 iR2;
|
sl@0
|
30 |
TUint32 iR3;
|
sl@0
|
31 |
TUint32 iR4;
|
sl@0
|
32 |
TUint32 iR5;
|
sl@0
|
33 |
TUint32 iR6;
|
sl@0
|
34 |
TUint32 iR7;
|
sl@0
|
35 |
TUint32 iR8;
|
sl@0
|
36 |
TUint32 iR9;
|
sl@0
|
37 |
TUint32 iR10;
|
sl@0
|
38 |
TUint32 iR11;
|
sl@0
|
39 |
TUint32 iR12;
|
sl@0
|
40 |
TUint32 iR13;
|
sl@0
|
41 |
TUint32 iR14;
|
sl@0
|
42 |
TUint32 iR15;
|
sl@0
|
43 |
TUint32 iFlags;
|
sl@0
|
44 |
TUint32 iDacr;
|
sl@0
|
45 |
};
|
sl@0
|
46 |
|
sl@0
|
47 |
TUint ThreadId(const RThread& aThread)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
TThreadId id=aThread.Id();
|
sl@0
|
50 |
TUint* p=(TUint*)&id;
|
sl@0
|
51 |
return *p;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
TUint ProcessId(const RProcess& aProcess)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
TProcessId id=aProcess.Id();
|
sl@0
|
57 |
TUint* p=(TUint*)&id;
|
sl@0
|
58 |
return *p;
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
GLDEF_C TInt E32Main()
|
sl@0
|
62 |
{
|
sl@0
|
63 |
RThread().SetPriority(EPriorityAbsoluteHigh);
|
sl@0
|
64 |
RFs fs;
|
sl@0
|
65 |
TInt r=fs.Connect();
|
sl@0
|
66 |
if (r!=KErrNone)
|
sl@0
|
67 |
User::Panic(_L("THRDLIST FS"),r);
|
sl@0
|
68 |
RFile file;
|
sl@0
|
69 |
r=file.Open(fs,KFileName,EFileWrite);
|
sl@0
|
70 |
if (r==KErrNotFound)
|
sl@0
|
71 |
r=file.Create(fs,KFileName,EFileWrite);
|
sl@0
|
72 |
if (r==KErrNone)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
TInt p=0;
|
sl@0
|
75 |
r=file.Seek(ESeekEnd,p);
|
sl@0
|
76 |
}
|
sl@0
|
77 |
if (r!=KErrNone)
|
sl@0
|
78 |
User::Panic(_L("THRDLIST FILE"),r);
|
sl@0
|
79 |
TTime now;
|
sl@0
|
80 |
now.HomeTime();
|
sl@0
|
81 |
TBuf<1024> buf;
|
sl@0
|
82 |
TDateTime dt=now.DateTime();
|
sl@0
|
83 |
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());
|
sl@0
|
84 |
r=file.Write(buf);
|
sl@0
|
85 |
if (r!=KErrNone)
|
sl@0
|
86 |
User::Panic(_L("THRDLIST WRITE"),r);
|
sl@0
|
87 |
TFindThread ft(KLitAsterisk);
|
sl@0
|
88 |
TFullName fn;
|
sl@0
|
89 |
while (ft.Next(fn)==KErrNone)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
RThread t;
|
sl@0
|
92 |
r=t.Open(ft);
|
sl@0
|
93 |
TExitType exitType=EExitKill;
|
sl@0
|
94 |
TInt exitReason=0;
|
sl@0
|
95 |
TBuf<32> exitCat;
|
sl@0
|
96 |
TFullName procName;
|
sl@0
|
97 |
TUint tid=0xffffffff;
|
sl@0
|
98 |
TUint pid=0xffffffff;
|
sl@0
|
99 |
SArmRegSet regs;
|
sl@0
|
100 |
Mem::FillZ(®s,sizeof(regs));
|
sl@0
|
101 |
TPckg<SArmRegSet> regPckg(regs);
|
sl@0
|
102 |
if (r==KErrNone)
|
sl@0
|
103 |
{
|
sl@0
|
104 |
t.Context(regPckg);
|
sl@0
|
105 |
exitType=t.ExitType();
|
sl@0
|
106 |
exitReason=t.ExitReason();
|
sl@0
|
107 |
exitCat=t.ExitCategory();
|
sl@0
|
108 |
tid=ThreadId(t);
|
sl@0
|
109 |
RProcess p;
|
sl@0
|
110 |
r=t.Process(p);
|
sl@0
|
111 |
if (r==KErrNone)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
procName=p.FullName();
|
sl@0
|
114 |
pid=ProcessId(p);
|
sl@0
|
115 |
p.Close();
|
sl@0
|
116 |
}
|
sl@0
|
117 |
}
|
sl@0
|
118 |
else
|
sl@0
|
119 |
fn=KLitProblem;
|
sl@0
|
120 |
buf.Format(_L("Thread %S (id=%d) in process %S (id=%d)\n"),&fn,tid,&procName,pid);
|
sl@0
|
121 |
file.Write(buf);
|
sl@0
|
122 |
buf.Format(_L("Exit info %d,%d,%S\n"),exitType,exitReason,&exitCat);
|
sl@0
|
123 |
file.Write(buf);
|
sl@0
|
124 |
buf.Format(_L(" R0=%08x R1=%08x R2=%08x R3=%08x\n"),regs.iR0,regs.iR1,regs.iR2,regs.iR3);
|
sl@0
|
125 |
file.Write(buf);
|
sl@0
|
126 |
buf.Format(_L(" R4=%08x R5=%08x R6=%08x R7=%08x\n"),regs.iR4,regs.iR5,regs.iR6,regs.iR7);
|
sl@0
|
127 |
file.Write(buf);
|
sl@0
|
128 |
buf.Format(_L(" R8=%08x R9=%08x R10=%08x R11=%08x\n"),regs.iR8,regs.iR9,regs.iR10,regs.iR11);
|
sl@0
|
129 |
file.Write(buf);
|
sl@0
|
130 |
buf.Format(_L(" R12=%08x R13=%08x R14=%08x R15=%08x\n"),regs.iR12,regs.iR13,regs.iR14,regs.iR15);
|
sl@0
|
131 |
file.Write(buf);
|
sl@0
|
132 |
buf.Format(_L("CPSR=%08x DACR=%08x\n\n"),regs.iFlags,regs.iDacr);
|
sl@0
|
133 |
file.Write(buf);
|
sl@0
|
134 |
t.Close();
|
sl@0
|
135 |
}
|
sl@0
|
136 |
file.Close();
|
sl@0
|
137 |
fs.Close();
|
sl@0
|
138 |
return KErrNone;
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|