sl@0
|
1 |
// Copyright (c) 2002-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 |
// e32utils\d_exc\minkda.h
|
sl@0
|
15 |
// API exposed by example of kernel-side debug agent.
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#ifndef __MINKDA_H__
|
sl@0
|
20 |
#define __MINKDA_H__
|
sl@0
|
21 |
|
sl@0
|
22 |
_LIT(KKdaLddName, "MINKDA");
|
sl@0
|
23 |
|
sl@0
|
24 |
inline TVersion KKdaLddVersion() { return TVersion(1, 0, 1); }
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
#if defined(__MARM__)
|
sl@0
|
28 |
|
sl@0
|
29 |
/**
|
sl@0
|
30 |
ARM user registers.
|
sl@0
|
31 |
Size must be multiple of 4 bytes.
|
sl@0
|
32 |
*/
|
sl@0
|
33 |
|
sl@0
|
34 |
class TDbgRegSet
|
sl@0
|
35 |
{
|
sl@0
|
36 |
public:
|
sl@0
|
37 |
enum { KRegCount = 16 };
|
sl@0
|
38 |
TUint32 iRn[KRegCount];
|
sl@0
|
39 |
TUint32 iCpsr;
|
sl@0
|
40 |
};
|
sl@0
|
41 |
|
sl@0
|
42 |
|
sl@0
|
43 |
/**
|
sl@0
|
44 |
ARM-specific exception-related data.
|
sl@0
|
45 |
Size must be multiple of 4 bytes.
|
sl@0
|
46 |
*/
|
sl@0
|
47 |
|
sl@0
|
48 |
class TDbgCpuExcInfo
|
sl@0
|
49 |
{
|
sl@0
|
50 |
public:
|
sl@0
|
51 |
enum TExcCode
|
sl@0
|
52 |
{
|
sl@0
|
53 |
EPrefetchAbort=0,
|
sl@0
|
54 |
EDataAbort=1,
|
sl@0
|
55 |
EUndefinedOpcode=2,
|
sl@0
|
56 |
};
|
sl@0
|
57 |
public:
|
sl@0
|
58 |
TExcCode iExcCode;
|
sl@0
|
59 |
/** Point to instruction which caused exception */
|
sl@0
|
60 |
TUint32 iFaultPc;
|
sl@0
|
61 |
/**
|
sl@0
|
62 |
Address which caused exception (System Control Coprocessor Fault
|
sl@0
|
63 |
Address Register)
|
sl@0
|
64 |
*/
|
sl@0
|
65 |
TUint32 iFaultAddress;
|
sl@0
|
66 |
/** System Control Coprocessor Fault Status Register */
|
sl@0
|
67 |
TUint32 iFaultStatus;
|
sl@0
|
68 |
/** R13 supervisor mode banked register */
|
sl@0
|
69 |
TUint32 iR13Svc;
|
sl@0
|
70 |
/** R14 supervisor mode banked register */
|
sl@0
|
71 |
TUint32 iR14Svc;
|
sl@0
|
72 |
/** SPSR supervisor mode banked register */
|
sl@0
|
73 |
TUint32 iSpsrSvc;
|
sl@0
|
74 |
};
|
sl@0
|
75 |
|
sl@0
|
76 |
#else
|
sl@0
|
77 |
|
sl@0
|
78 |
class TDbgRegSet
|
sl@0
|
79 |
{
|
sl@0
|
80 |
};
|
sl@0
|
81 |
|
sl@0
|
82 |
class TDbgCpuExcInfo
|
sl@0
|
83 |
{
|
sl@0
|
84 |
};
|
sl@0
|
85 |
|
sl@0
|
86 |
#endif
|
sl@0
|
87 |
|
sl@0
|
88 |
|
sl@0
|
89 |
/**
|
sl@0
|
90 |
Exception or panic information block.
|
sl@0
|
91 |
Size must be multiple of 4 bytes.
|
sl@0
|
92 |
*/
|
sl@0
|
93 |
|
sl@0
|
94 |
class TDbgCrashInfo
|
sl@0
|
95 |
{
|
sl@0
|
96 |
public:
|
sl@0
|
97 |
enum TType { EException, EPanic };
|
sl@0
|
98 |
public:
|
sl@0
|
99 |
TType iType;
|
sl@0
|
100 |
/** ID of thread which crashed */
|
sl@0
|
101 |
TUint iTid;
|
sl@0
|
102 |
/** CPU-specific information (exception only) */
|
sl@0
|
103 |
TDbgCpuExcInfo iCpu;
|
sl@0
|
104 |
};
|
sl@0
|
105 |
|
sl@0
|
106 |
|
sl@0
|
107 |
/**
|
sl@0
|
108 |
Thread information block.
|
sl@0
|
109 |
Size must be multiple of 4 bytes.
|
sl@0
|
110 |
*/
|
sl@0
|
111 |
|
sl@0
|
112 |
class TDbgThreadInfo
|
sl@0
|
113 |
{
|
sl@0
|
114 |
public:
|
sl@0
|
115 |
TFullName iFullName;
|
sl@0
|
116 |
/** ID of owning process */
|
sl@0
|
117 |
TUint iPid;
|
sl@0
|
118 |
/** user stack base address */
|
sl@0
|
119 |
TLinAddr iStackBase;
|
sl@0
|
120 |
/** user stack size */
|
sl@0
|
121 |
TInt iStackSize;
|
sl@0
|
122 |
TExitCategoryName iExitCategory;
|
sl@0
|
123 |
TInt iExitReason;
|
sl@0
|
124 |
/** User context */
|
sl@0
|
125 |
TDbgRegSet iCpu;
|
sl@0
|
126 |
};
|
sl@0
|
127 |
|
sl@0
|
128 |
|
sl@0
|
129 |
/**
|
sl@0
|
130 |
Code Segment Information Block
|
sl@0
|
131 |
Size must be multiple of 4 bytes.
|
sl@0
|
132 |
*/
|
sl@0
|
133 |
|
sl@0
|
134 |
class TDbgCodeSegInfo
|
sl@0
|
135 |
{
|
sl@0
|
136 |
public:
|
sl@0
|
137 |
TPath iPath;
|
sl@0
|
138 |
TUint32 iCodeBase;
|
sl@0
|
139 |
TUint32 iCodeSize;
|
sl@0
|
140 |
};
|
sl@0
|
141 |
|
sl@0
|
142 |
|
sl@0
|
143 |
/**
|
sl@0
|
144 |
API exposed by minimal kernel debug agent.
|
sl@0
|
145 |
|
sl@0
|
146 |
This API is provided as an example only. There are no guarantees of
|
sl@0
|
147 |
binary/source compatibility.
|
sl@0
|
148 |
*/
|
sl@0
|
149 |
|
sl@0
|
150 |
class RMinKda : public RBusLogicalChannel
|
sl@0
|
151 |
{
|
sl@0
|
152 |
public:
|
sl@0
|
153 |
enum TControl
|
sl@0
|
154 |
{
|
sl@0
|
155 |
ETrap,
|
sl@0
|
156 |
ECancelTrap,
|
sl@0
|
157 |
EKillCrashedThread,
|
sl@0
|
158 |
EGetThreadInfo,
|
sl@0
|
159 |
EReadMem,
|
sl@0
|
160 |
EGetCodeSegs,
|
sl@0
|
161 |
EGetCodeSegInfo,
|
sl@0
|
162 |
};
|
sl@0
|
163 |
// Size of following structs must be multiple of 4 bytes.
|
sl@0
|
164 |
struct TCodeSnapshotParams
|
sl@0
|
165 |
{
|
sl@0
|
166 |
TUint iPid;
|
sl@0
|
167 |
TAny** iHandles;
|
sl@0
|
168 |
TInt* iCountPtr;
|
sl@0
|
169 |
};
|
sl@0
|
170 |
struct TCodeInfoParams
|
sl@0
|
171 |
{
|
sl@0
|
172 |
TUint iPid;
|
sl@0
|
173 |
TAny* iHandle;
|
sl@0
|
174 |
TDes8* iPathPtr;
|
sl@0
|
175 |
TUint32 iCodeBase;
|
sl@0
|
176 |
TUint32 iCodeSize;
|
sl@0
|
177 |
};
|
sl@0
|
178 |
struct TReadMemParams
|
sl@0
|
179 |
{
|
sl@0
|
180 |
TUint iTid;
|
sl@0
|
181 |
TLinAddr iAddr;
|
sl@0
|
182 |
TDes8* iDes;
|
sl@0
|
183 |
};
|
sl@0
|
184 |
struct TDbgInfoParams
|
sl@0
|
185 |
{
|
sl@0
|
186 |
TBuf8<KMaxFullName> iFullName;
|
sl@0
|
187 |
TUint iPid;
|
sl@0
|
188 |
TLinAddr iStackBase;
|
sl@0
|
189 |
TInt iStackSize;
|
sl@0
|
190 |
TBuf8<KMaxExitCategoryName> iExitCategory;
|
sl@0
|
191 |
TInt iExitReason;
|
sl@0
|
192 |
TDbgRegSet iCpu;
|
sl@0
|
193 |
};
|
sl@0
|
194 |
public:
|
sl@0
|
195 |
#ifndef __KERNEL_MODE__
|
sl@0
|
196 |
inline TInt Open();
|
sl@0
|
197 |
inline void Trap(TRequestStatus& aStatus, TDbgCrashInfo& aInfo);
|
sl@0
|
198 |
inline void CancelTrap();
|
sl@0
|
199 |
inline void KillCrashedThread();
|
sl@0
|
200 |
inline TInt GetThreadInfo(TUint aTid, TDbgThreadInfo& aInfo);
|
sl@0
|
201 |
inline TInt ReadMem(TUint aTid, TLinAddr aSrc, TDes8& aDest);
|
sl@0
|
202 |
inline TInt GetCodeSegs(TUint aPid, TAny** aHandleArray, TInt& aHandleCount);
|
sl@0
|
203 |
inline TInt GetCodeSegInfo(TAny* aHandle, TUint aPid, TDbgCodeSegInfo& aInfo);
|
sl@0
|
204 |
#endif
|
sl@0
|
205 |
};
|
sl@0
|
206 |
|
sl@0
|
207 |
|
sl@0
|
208 |
#ifndef __KERNEL_MODE__
|
sl@0
|
209 |
|
sl@0
|
210 |
inline TInt RMinKda::Open()
|
sl@0
|
211 |
{
|
sl@0
|
212 |
return DoCreate(KKdaLddName, KKdaLddVersion(), KNullUnit, NULL, NULL, EOwnerThread);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
/**
|
sl@0
|
216 |
Ask to be notified of the next panic or exception occurence.
|
sl@0
|
217 |
|
sl@0
|
218 |
The crashed thread will remain suspended until KillCrashedThread() is
|
sl@0
|
219 |
called allowing more information to be gathered (e.g. stack content).
|
sl@0
|
220 |
|
sl@0
|
221 |
If more threads panic or take an exception, they will be suspended
|
sl@0
|
222 |
too until the first one is killed.
|
sl@0
|
223 |
|
sl@0
|
224 |
@param aStatus Request to complete when panic/exception occurs
|
sl@0
|
225 |
@param aInfo Filled when request completes
|
sl@0
|
226 |
*/
|
sl@0
|
227 |
|
sl@0
|
228 |
inline void RMinKda::Trap(TRequestStatus& aStatus, TDbgCrashInfo& aInfo)
|
sl@0
|
229 |
{
|
sl@0
|
230 |
DoControl(ETrap, &aStatus, &aInfo);
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
/** Cancel previous call to Trap() */
|
sl@0
|
234 |
|
sl@0
|
235 |
inline void RMinKda::CancelTrap()
|
sl@0
|
236 |
{
|
sl@0
|
237 |
DoControl(ECancelTrap, NULL, NULL);
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
/**
|
sl@0
|
241 |
Kill the thread which crashed causing the Trap() request to complete.
|
sl@0
|
242 |
*/
|
sl@0
|
243 |
|
sl@0
|
244 |
inline void RMinKda::KillCrashedThread()
|
sl@0
|
245 |
{
|
sl@0
|
246 |
DoControl(EKillCrashedThread, NULL, NULL);
|
sl@0
|
247 |
}
|
sl@0
|
248 |
|
sl@0
|
249 |
|
sl@0
|
250 |
/**
|
sl@0
|
251 |
Return information about thread identified by its ID.
|
sl@0
|
252 |
*/
|
sl@0
|
253 |
|
sl@0
|
254 |
inline TInt RMinKda::GetThreadInfo(TUint aTid, TDbgThreadInfo& aInfo)
|
sl@0
|
255 |
{
|
sl@0
|
256 |
TDbgInfoParams params;
|
sl@0
|
257 |
TInt r=DoControl(EGetThreadInfo, (TAny*)aTid, ¶ms);
|
sl@0
|
258 |
if (r==KErrNone)
|
sl@0
|
259 |
{
|
sl@0
|
260 |
aInfo.iFullName.Copy(params.iFullName);
|
sl@0
|
261 |
aInfo.iPid = params.iPid;
|
sl@0
|
262 |
aInfo.iStackBase = params.iStackBase;
|
sl@0
|
263 |
aInfo.iStackSize = params.iStackSize;
|
sl@0
|
264 |
aInfo.iExitCategory.Copy(params.iExitCategory);
|
sl@0
|
265 |
aInfo.iExitReason = params.iExitReason;
|
sl@0
|
266 |
aInfo.iCpu = params.iCpu;
|
sl@0
|
267 |
}
|
sl@0
|
268 |
return r;
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
/**
|
sl@0
|
272 |
Read memory from designated thread address space.
|
sl@0
|
273 |
|
sl@0
|
274 |
@param aTid Thread id
|
sl@0
|
275 |
@param aSrc Source address
|
sl@0
|
276 |
@param aDest Destination descriptor. Number of bytes to read is
|
sl@0
|
277 |
aDes.MaxSize().
|
sl@0
|
278 |
|
sl@0
|
279 |
@return standard error code
|
sl@0
|
280 |
*/
|
sl@0
|
281 |
|
sl@0
|
282 |
inline TInt RMinKda::ReadMem(TUint aTid, TLinAddr aSrc, TDes8& aDest)
|
sl@0
|
283 |
{
|
sl@0
|
284 |
TReadMemParams params;
|
sl@0
|
285 |
params.iTid = aTid;
|
sl@0
|
286 |
params.iAddr = aSrc;
|
sl@0
|
287 |
params.iDes = &aDest;
|
sl@0
|
288 |
return DoControl(EReadMem, ¶ms, NULL);
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
inline TInt RMinKda::GetCodeSegs(TUint aPid, TAny** aHandleArray, TInt& aHandleCount)
|
sl@0
|
292 |
{
|
sl@0
|
293 |
TCodeSnapshotParams params;
|
sl@0
|
294 |
params.iPid = aPid;
|
sl@0
|
295 |
params.iHandles = aHandleArray;
|
sl@0
|
296 |
params.iCountPtr = &aHandleCount;
|
sl@0
|
297 |
return DoControl(EGetCodeSegs, ¶ms, NULL);
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
inline TInt RMinKda::GetCodeSegInfo(TAny* aHandle, TUint aPid, TDbgCodeSegInfo& aInfo)
|
sl@0
|
301 |
{
|
sl@0
|
302 |
TBuf8<KMaxPath> path;
|
sl@0
|
303 |
TCodeInfoParams params;
|
sl@0
|
304 |
params.iPid = aPid;
|
sl@0
|
305 |
params.iHandle = aHandle;
|
sl@0
|
306 |
params.iPathPtr = &path;
|
sl@0
|
307 |
TInt r = DoControl(EGetCodeSegInfo, ¶ms, NULL);
|
sl@0
|
308 |
if (r == KErrNone)
|
sl@0
|
309 |
{
|
sl@0
|
310 |
aInfo.iCodeBase = params.iCodeBase;
|
sl@0
|
311 |
aInfo.iCodeSize = params.iCodeSize;
|
sl@0
|
312 |
aInfo.iPath.Copy(path);
|
sl@0
|
313 |
}
|
sl@0
|
314 |
return r;
|
sl@0
|
315 |
}
|
sl@0
|
316 |
|
sl@0
|
317 |
#endif
|
sl@0
|
318 |
|
sl@0
|
319 |
#endif
|