|
1 // Copyright (c) 2007-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 // |
|
15 |
|
16 #include "d_driver_event_info.h" |
|
17 #include "debug_logging.h" |
|
18 #include <kernel/kernel.h> |
|
19 #include <kernel/kern_priv.h> |
|
20 |
|
21 using namespace Debug; |
|
22 |
|
23 TDriverEventInfo::TDriverEventInfo() |
|
24 { |
|
25 Reset(); |
|
26 } |
|
27 |
|
28 void TDriverEventInfo::Reset() |
|
29 { |
|
30 iProcessId = 0; |
|
31 iThreadId = 0; |
|
32 iCurrentPC = 0; |
|
33 iExceptionNumber = 0; |
|
34 iFileName.Zero(); |
|
35 iPanicCategory.Zero(); |
|
36 iCodeAddress = 0; |
|
37 iDataAddress = 0; |
|
38 iThreadIdValid = (TUint8)EFalse; |
|
39 iProcessIdValid = (TUint8)EFalse; |
|
40 iEventType = EEventsUnknown; |
|
41 iUidsValid = (TUint8)EFalse; |
|
42 iActionTaken = EActionIgnore; |
|
43 iThreadFlags = 0; |
|
44 }; |
|
45 |
|
46 /** |
|
47 Copy the data from this object into the object pointed to by aEventInfo in |
|
48 the client thread aClientThread. It is assumed that the write is performed |
|
49 on behalf of aClientThread. |
|
50 |
|
51 @param aClientThread client thread to write the data to |
|
52 @param aEventInfo TEventInfo object in the client thread to populate with data |
|
53 @param aAsyncGetValueRequest TClientDataRequest object used for pinning user memory |
|
54 |
|
55 @return KErrNone on success, or one of the other system wide error codes |
|
56 */ |
|
57 TInt TDriverEventInfo::WriteEventToClientThread(TClientDataRequest<TEventInfo>* aAsyncGetValueRequest, DThread* aClientThread) const |
|
58 { |
|
59 // create a temporary TEventInfo to populate with the relevant data |
|
60 TEventInfo eventInfo; |
|
61 TInt err = KErrNone; |
|
62 |
|
63 // populate the data that is common to all events |
|
64 err = PopulateCommonEventInfo(eventInfo); |
|
65 |
|
66 if(KErrNone != err) |
|
67 { |
|
68 return err; |
|
69 } |
|
70 |
|
71 // populate the event specific data (means filling in the correct union member) |
|
72 err = PopulateEventSpecificInfo(eventInfo); |
|
73 |
|
74 // write the data to the client and return any error |
|
75 if(KErrNone == err) |
|
76 { |
|
77 aAsyncGetValueRequest->Data() = eventInfo; |
|
78 } |
|
79 |
|
80 return err; |
|
81 } |
|
82 |
|
83 /** |
|
84 Write the common event values into aEventInfo |
|
85 |
|
86 @param aEventInfo TEventInfo object to write data into |
|
87 */ |
|
88 TInt TDriverEventInfo::PopulateCommonEventInfo(TEventInfo& aEventInfo) const |
|
89 { |
|
90 aEventInfo.iEventType = iEventType; |
|
91 aEventInfo.iProcessId = iProcessId; |
|
92 aEventInfo.iProcessIdValid = iProcessIdValid; |
|
93 aEventInfo.iThreadId = iThreadId; |
|
94 aEventInfo.iThreadIdValid = iThreadIdValid; |
|
95 aEventInfo.iActionTaken = iActionTaken; |
|
96 LOG_MSG5("TDriverEventInfo:: PopulateCommon : eventType=%d, tidValid=%d, tid=0x%x, actionTaken=%d", |
|
97 iEventType, iThreadIdValid, TUint(iThreadId), iActionTaken ); |
|
98 return KErrNone; |
|
99 } |
|
100 |
|
101 /** |
|
102 Write the event specific values into aEventInfo |
|
103 |
|
104 @param aEventInfo TEventInfo object to write data into |
|
105 */ |
|
106 TInt TDriverEventInfo::PopulateEventSpecificInfo(TEventInfo& aEventInfo) const |
|
107 { |
|
108 TInt ret = KErrNone; |
|
109 |
|
110 switch(aEventInfo.iEventType) |
|
111 { |
|
112 case EEventsBreakPoint: |
|
113 ret = PopulateThreadBreakPointInfo(aEventInfo); |
|
114 return ret; |
|
115 case EEventsProcessBreakPoint: |
|
116 ret = PopulateThreadBreakPointInfo(aEventInfo); |
|
117 return ret; |
|
118 case EEventsSwExc: |
|
119 ret = PopulateThreadSwExceptionInfo(aEventInfo); |
|
120 return ret; |
|
121 case EEventsHwExc: |
|
122 ret = PopulateThreadHwExceptionInfo(aEventInfo); |
|
123 return ret; |
|
124 case EEventsKillThread: |
|
125 ret = PopulateThreadKillInfo(aEventInfo); |
|
126 return ret; |
|
127 case EEventsAddLibrary: |
|
128 ret = PopulateLibraryLoadedInfo(aEventInfo); |
|
129 return ret; |
|
130 case EEventsRemoveLibrary: |
|
131 ret = PopulateLibraryUnloadedInfo(aEventInfo); |
|
132 return ret; |
|
133 case EEventsUserTrace: |
|
134 ret = PopulateUserTraceInfo(aEventInfo); |
|
135 return ret; |
|
136 case EEventsStartThread: |
|
137 ret = PopulateStartThreadInfo(aEventInfo); |
|
138 return ret; |
|
139 case EEventsUserTracesLost: |
|
140 //no event specific data to be filled here |
|
141 return KErrNone; |
|
142 case EEventsAddProcess: |
|
143 ret = PopulateAddProcessInfo(aEventInfo); |
|
144 return ret; |
|
145 case EEventsRemoveProcess: |
|
146 ret = PopulateRemoveProcessInfo(aEventInfo); |
|
147 return ret; |
|
148 } |
|
149 |
|
150 return KErrArgument; |
|
151 } |
|
152 |
|
153 /** |
|
154 Write the event specific values for a break point event into TEventInfo |
|
155 |
|
156 @param aEventInfo TEventInfo object to write data into |
|
157 */ |
|
158 TInt TDriverEventInfo::PopulateThreadBreakPointInfo(TEventInfo& aEventInfo) const |
|
159 { |
|
160 aEventInfo.iThreadBreakPointInfo.iExceptionNumber = (TExcType)iExceptionNumber; |
|
161 TInt ret = PopulateRmdArmExcInfo(aEventInfo); |
|
162 |
|
163 return ret; |
|
164 } |
|
165 |
|
166 /** |
|
167 Write the event specific values for a thread exception event into TEventInfo |
|
168 |
|
169 @param aEventInfo TEventInfo object to write data into |
|
170 */ |
|
171 TInt TDriverEventInfo::PopulateThreadSwExceptionInfo(TEventInfo& aEventInfo) const |
|
172 { |
|
173 aEventInfo.iThreadSwExceptionInfo.iCurrentPC = iCurrentPC; |
|
174 aEventInfo.iThreadSwExceptionInfo.iExceptionNumber = (TExcType)iExceptionNumber; |
|
175 |
|
176 return KErrNone; |
|
177 } |
|
178 |
|
179 /** |
|
180 Write the event specific values for a thread exception event into TEventInfo |
|
181 |
|
182 @param aEventInfo TEventInfo object to write data into |
|
183 */ |
|
184 TInt TDriverEventInfo::PopulateThreadHwExceptionInfo(TEventInfo& aEventInfo) const |
|
185 { |
|
186 aEventInfo.iThreadHwExceptionInfo.iExceptionNumber = (TExcType)iExceptionNumber; |
|
187 TInt ret = PopulateRmdArmExcInfo(aEventInfo); |
|
188 return ret; |
|
189 } |
|
190 |
|
191 /** |
|
192 Write the event specific values for a thread panic event into TEventInfo |
|
193 |
|
194 @param aEventInfo TEventInfo object to write data into |
|
195 */ |
|
196 TInt TDriverEventInfo::PopulateThreadKillInfo(TEventInfo& aEventInfo) const |
|
197 { |
|
198 aEventInfo.iThreadKillInfo.iCurrentPC = iCurrentPC; |
|
199 aEventInfo.iThreadKillInfo.iExitReason = iExceptionNumber; |
|
200 aEventInfo.iThreadKillInfo.iExitType = iExitType; |
|
201 aEventInfo.iThreadKillInfo.iPanicCategoryLength = iPanicCategory.Length(); |
|
202 TPtr8 panicCategoryPtr(&(aEventInfo.iThreadKillInfo.iPanicCategory[0]), iPanicCategory.Length()); |
|
203 panicCategoryPtr = iPanicCategory; |
|
204 |
|
205 return KErrNone; |
|
206 } |
|
207 |
|
208 /** |
|
209 Write the event specific values for a library loaded event into TEventInfo |
|
210 |
|
211 @param aEventInfo TEventInfo object to write data into |
|
212 */ |
|
213 TInt TDriverEventInfo::PopulateStartThreadInfo(TEventInfo& aEventInfo) const |
|
214 { |
|
215 aEventInfo.iStartThreadInfo.iFileNameLength = iFileName.Length(); |
|
216 TPtr8 fileNamePtr(&(aEventInfo.iStartThreadInfo.iFileName[0]), iFileName.Length()); |
|
217 fileNamePtr = iFileName; |
|
218 |
|
219 return KErrNone; |
|
220 } |
|
221 |
|
222 /** |
|
223 Write the event specific values for an AddProcess event into TEventInfo |
|
224 |
|
225 @param aEventInfo TEventInfo object to write data into |
|
226 */ |
|
227 TInt TDriverEventInfo::PopulateAddProcessInfo(TEventInfo& aEventInfo) const |
|
228 { |
|
229 aEventInfo.iAddProcessInfo.iFileNameLength = iFileName.Length(); |
|
230 TPtr8 fileNamePtr(&(aEventInfo.iAddProcessInfo.iFileName[0]), iFileName.Length()); |
|
231 fileNamePtr = iFileName; |
|
232 |
|
233 const TInt uid3offset = 2; |
|
234 aEventInfo.iAddProcessInfo.iUid3 = iUids.iUid[uid3offset].iUid; |
|
235 aEventInfo.iAddProcessInfo.iCreatorThreadId = iCreatorThreadId; |
|
236 |
|
237 return KErrNone; |
|
238 } |
|
239 |
|
240 /** |
|
241 Write the event specific values for a RemoveProcess event into TEventInfo |
|
242 |
|
243 @param aEventInfo TEventInfo object to write data into |
|
244 */ |
|
245 TInt TDriverEventInfo::PopulateRemoveProcessInfo(TEventInfo& aEventInfo) const |
|
246 { |
|
247 aEventInfo.iRemoveProcessInfo.iFileNameLength = iFileName.Length(); |
|
248 TPtr8 fileNamePtr(&(aEventInfo.iRemoveProcessInfo.iFileName[0]), iFileName.Length()); |
|
249 fileNamePtr = iFileName; |
|
250 |
|
251 return KErrNone; |
|
252 } |
|
253 |
|
254 /** |
|
255 Write the event specific values for a library loaded event into TEventInfo |
|
256 |
|
257 @param aEventInfo TEventInfo object to write data into |
|
258 */ |
|
259 TInt TDriverEventInfo::PopulateLibraryLoadedInfo(TEventInfo& aEventInfo) const |
|
260 { |
|
261 aEventInfo.iLibraryLoadedInfo.iCodeAddress = iCodeAddress; |
|
262 aEventInfo.iLibraryLoadedInfo.iDataAddress = iDataAddress; |
|
263 aEventInfo.iLibraryLoadedInfo.iFileNameLength = iFileName.Length(); |
|
264 TPtr8 fileNamePtr(&(aEventInfo.iLibraryLoadedInfo.iFileName[0]), iFileName.Length()); |
|
265 fileNamePtr = iFileName; |
|
266 |
|
267 return KErrNone; |
|
268 } |
|
269 |
|
270 /** |
|
271 Write the event specific values for a library unloaded event into TEventInfo |
|
272 |
|
273 @param aEventInfo TEventInfo object to write data into |
|
274 */ |
|
275 TInt TDriverEventInfo::PopulateLibraryUnloadedInfo(TEventInfo& aEventInfo) const |
|
276 { |
|
277 aEventInfo.iLibraryUnloadedInfo.iFileNameLength = iFileName.Length(); |
|
278 TPtr8 fileNamePtr(&(aEventInfo.iLibraryUnloadedInfo.iFileName[0]), iFileName.Length()); |
|
279 fileNamePtr = iFileName; |
|
280 |
|
281 return KErrNone; |
|
282 } |
|
283 |
|
284 /** |
|
285 Write the ArmExcInfo values into TEventInfo |
|
286 |
|
287 @param aEventInfo TEventInfo object to write data into |
|
288 */ |
|
289 TInt TDriverEventInfo::PopulateRmdArmExcInfo(TEventInfo& aEventInfo) const |
|
290 { |
|
291 switch(iEventType) |
|
292 { |
|
293 case EEventsProcessBreakPoint: |
|
294 case EEventsBreakPoint: |
|
295 aEventInfo.iThreadBreakPointInfo.iRmdArmExcInfo = iRmdArmExcInfo; |
|
296 break; |
|
297 case EEventsHwExc: |
|
298 aEventInfo.iThreadHwExceptionInfo.iRmdArmExcInfo = iRmdArmExcInfo; |
|
299 break; |
|
300 } |
|
301 |
|
302 return KErrNone; |
|
303 } |
|
304 |
|
305 /** |
|
306 * Writes the user trace into TEventInfo |
|
307 * |
|
308 * @param aEventInfo TEventInfo object to write data into |
|
309 */ |
|
310 TInt TDriverEventInfo::PopulateUserTraceInfo(TEventInfo& aEventInfo) const |
|
311 { |
|
312 aEventInfo.iUserTraceInfo.iUserTraceLength = (TInt)iArg2; |
|
313 |
|
314 TPtr8 ptr(aEventInfo.iUserTraceInfo.iUserTraceText, (TInt)iArg2, TUserTraceSize ); |
|
315 ptr.Copy(iUserTraceText, (TInt)iArg2); |
|
316 |
|
317 return KErrNone; |
|
318 } |
|
319 |
|
320 TBool TDriverEventInfo::FreezeOnSuspend() const |
|
321 { |
|
322 switch(iEventType) |
|
323 { |
|
324 case EEventsHwExc: |
|
325 case EEventsBreakPoint: |
|
326 case EEventsProcessBreakPoint: |
|
327 return ETrue; |
|
328 case EEventsKillThread: |
|
329 { |
|
330 return (iExitType == EExitPanic); |
|
331 } |
|
332 } |
|
333 return EFalse; |
|
334 } |
|
335 |
|
336 TBool TDriverEventInfo::TookException() const |
|
337 { |
|
338 return iExitType == EExitPanic && |
|
339 iExceptionNumber == ECausedException && |
|
340 iPanicCategory == KLitKernExec; |
|
341 } |
|
342 |