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