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