1 // Copyright (c) 2006-2010 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 // Tests the functionality of the run mode debug device driver. |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <e32base_private.h> |
|
20 #include <e32cons.h> |
|
21 #include <e32test.h> |
|
22 #include <e32ldr.h> |
|
23 #include <e32cmn.h> |
|
24 #include <e32cmn_private.h> |
|
25 #include <f32dbg.h> |
|
26 #include <f32file.h> |
|
27 #include <hal.h> |
|
28 #include <u32hal.h> |
|
29 #include <e32property.h> |
|
30 |
|
31 #include "t_rmdebug_dll.h" |
|
32 |
|
33 #include <rm_debug_api.h> |
|
34 #include "d_rmdebugthread2.h" |
|
35 #include "t_rmdebug2.h" |
|
36 #include "t_rmdebug_app.h" |
|
37 |
|
38 #ifdef __MARM_ARMV4__ |
|
39 #include "d_rmdebug_step_test_armv4.h" |
|
40 #endif |
|
41 |
|
42 #ifdef __MARM_ARMV5__ |
|
43 #include "d_rmdebug_step_test.h" |
|
44 #include "d_rmdebug_bkpt_test.h" |
|
45 #endif |
|
46 |
|
47 #include "d_demand_paging.h" |
|
48 |
|
49 #ifdef KERNEL_OOM_TESTING |
|
50 #ifdef USER_OOM_TESTING |
|
51 #error "Cannot define both KERNEL_OOM_TESTING and USER_OOM_TESTING" |
|
52 #endif |
|
53 #endif |
|
54 |
|
55 _LIT8(KCrashDummyData, "This is a sample write"); |
|
56 |
|
57 using namespace Debug; |
|
58 |
|
59 const TVersion securityServerVersion(0,1,1); |
|
60 |
|
61 const TVersion testVersion(2,1,0); |
|
62 |
|
63 IMPORT_C TInt StartDebugThread(RThread& aServerThread, const TDesC& aDebugThreadName); |
|
64 IMPORT_D extern TInt TestData; |
|
65 IMPORT_D extern TTestFunction FunctionChooser; |
|
66 IMPORT_D extern TBuf8<SYMBIAN_RMDBG_MEMORYSIZE> gMemoryAccessBytes; |
|
67 IMPORT_C TInt TestFunction(); |
|
68 IMPORT_C void TestPagedCode(); |
|
69 IMPORT_C extern TInt RMDebugDemandPagingTest(); |
|
70 |
|
71 // Device driver name |
|
72 _LIT(KDebugDriverFileName,"rm_debug.ldd"); |
|
73 |
|
74 #ifdef SYMBIAN_STANDARDDEBUG |
|
75 LOCAL_D RTest test(_L("T_RMDEBUG2")); |
|
76 #endif |
|
77 |
|
78 #ifdef SYMBIAN_OEMDEBUG |
|
79 LOCAL_D RTest test(_L("T_RMDEBUG2_OEM")); |
|
80 #endif |
|
81 |
|
82 #ifdef SYMBIAN_OEM2DEBUG |
|
83 LOCAL_D RTest test(_L("T_RMDEBUG2_OEM2")); |
|
84 #endif |
|
85 |
|
86 TBool gUseDelay; |
|
87 |
|
88 CRunModeAgent::CRunModeAgent() |
|
89 // |
|
90 // CRunModeAgent constructor |
|
91 // |
|
92 { |
|
93 FillArray(); |
|
94 RProcess thisProcess; |
|
95 iFileName = thisProcess.FileName(); |
|
96 thisProcess.Close(); |
|
97 } |
|
98 |
|
99 CRunModeAgent* CRunModeAgent::NewL() |
|
100 // |
|
101 // CRunModeAgent::NewL |
|
102 // |
|
103 { |
|
104 CRunModeAgent* self = new(ELeave) CRunModeAgent(); |
|
105 |
|
106 self->ConstructL(); |
|
107 |
|
108 return self; |
|
109 } |
|
110 |
|
111 CRunModeAgent::~CRunModeAgent() |
|
112 // |
|
113 // CRunModeAgent destructor |
|
114 // |
|
115 { |
|
116 User::FreeLogicalDevice(KDebugDriverFileName); |
|
117 iServSession.Close(); |
|
118 iDebugThread.Close(); |
|
119 } |
|
120 |
|
121 void CRunModeAgent::ConstructL() |
|
122 // |
|
123 // CRunModeAgent::ConstructL |
|
124 // |
|
125 { |
|
126 // nothing to do here |
|
127 } |
|
128 |
|
129 void CRunModeAgent::SetupAndAttachToDSS() |
|
130 // |
|
131 // CRunModeAgent::SetupAndAttachToDSS |
|
132 // |
|
133 { |
|
134 TInt err = StartDebugThread(iDebugThread, KDebugThreadName); |
|
135 |
|
136 // get the thread id for use in the tests |
|
137 iThreadID = iDebugThread.Id(); |
|
138 |
|
139 if (err != KErrNone) |
|
140 { |
|
141 User::Panic(_L("Can't start debug thread"), err); |
|
142 } |
|
143 |
|
144 err = iServSession.Connect(securityServerVersion); |
|
145 if (err != KErrNone) |
|
146 { |
|
147 User::Panic(_L("Can't open server session"), err); |
|
148 } |
|
149 } |
|
150 |
|
151 CRunModeAgent *RunModeAgent; |
|
152 |
|
153 // helper function to check whether the listing of type aListId is supported for a scope of aListScope |
|
154 TBool CRunModeAgent::ListingSupported(const TListId aListId, const TListScope aListScope) |
|
155 { |
|
156 TTag tag = GetTag(ETagHeaderList, aListId); |
|
157 |
|
158 return (tag.iValue) & aListScope; |
|
159 } |
|
160 |
|
161 //--------------------------------------------- |
|
162 //! @SYMTestCaseID KBase-T-RMDEBUG2-0426 |
|
163 //! @SYMTestType |
|
164 //! @SYMPREQ PREQ1426 |
|
165 //! @SYMTestCaseDesc Test getting the list of XIP libraries |
|
166 //! @SYMTestActions The XIP library list should be successfully obtained |
|
167 //! @SYMTestExpectedResults The specified ldd file should be present in the obtained listing |
|
168 //! @SYMTestPriority High |
|
169 //! @SYMTestStatus Implemented |
|
170 //--------------------------------------------- |
|
171 void CRunModeAgent::TestGetXipLibrariesList() |
|
172 { |
|
173 test.Next(_L("TestGetXipLibrariesList\n")); |
|
174 |
|
175 test(ListingSupported(EXipLibraries, EScopeGlobal)); |
|
176 test(!ListingSupported(EXipLibraries, EScopeProcessSpecific)); |
|
177 test(!ListingSupported(EXipLibraries, EScopeThreadSpecific)); |
|
178 |
|
179 //allocate a very small buffer so the GetList call initially fails |
|
180 RBuf8 buffer; |
|
181 test(KErrNone == buffer.Create(1)); |
|
182 TUint32 size = 0; |
|
183 |
|
184 //get the list data |
|
185 DoGetList(EXipLibraries, EScopeGlobal, buffer, size); |
|
186 |
|
187 //search the buffer for entry corresponding to the debug kernel driver |
|
188 //which should be in the rom |
|
189 _LIT(KRmDebugLddName, "z:\\sys\\bin\\rm_debug.ldd"); |
|
190 |
|
191 //iterate through the buffer and set found to ETrue if we find the driver |
|
192 TBool found = EFalse; |
|
193 TUint8* ptr = (TUint8*)buffer.Ptr(); |
|
194 const TUint8* ptrEnd = ptr + size; |
|
195 while(ptr < ptrEnd) |
|
196 { |
|
197 TXipLibraryListEntry& xipLibrary = *(TXipLibraryListEntry*)ptr; |
|
198 |
|
199 //get the name of the library |
|
200 TPtr name(&xipLibrary.iName[0], xipLibrary.iNameLength, xipLibrary.iNameLength); |
|
201 if(name.CompareF(KRmDebugLddName()) == 0) |
|
202 { |
|
203 //found the library but continue reading the rest of the buffer to |
|
204 //check nothing bad happens towards the end |
|
205 found = ETrue; |
|
206 } |
|
207 //move pointer on to next library |
|
208 ptr += Align4(xipLibrary.GetSize()); |
|
209 } |
|
210 test(found); |
|
211 |
|
212 //do cleanup |
|
213 buffer.Close(); |
|
214 } |
|
215 |
|
216 //--------------------------------------------- |
|
217 //! @SYMTestCaseID KBase-T-RMDEBUG2-0427 |
|
218 //! @SYMTestType |
|
219 //! @SYMPREQ PREQ1426 |
|
220 //! @SYMTestCaseDesc Test getting the list of executables |
|
221 //! @SYMTestActions The list of debuggable executable files should be obtained |
|
222 //! @SYMTestExpectedResults The client exe should appear in the list |
|
223 //! @SYMTestPriority High |
|
224 //! @SYMTestStatus Implemented |
|
225 //--------------------------------------------- |
|
226 void CRunModeAgent::TestGetExecutablesList() |
|
227 { |
|
228 test.Next(_L("TestGetExecutablesList\n")); |
|
229 |
|
230 test(ListingSupported(EExecutables, EScopeGlobal)); |
|
231 test(!ListingSupported(EExecutables, EScopeProcessSpecific)); |
|
232 test(!ListingSupported(EExecutables, EScopeThreadSpecific)); |
|
233 |
|
234 //allocate a very small buffer so the GetList call initially fails |
|
235 RBuf8 buffer; |
|
236 test(KErrNone == buffer.Create(1)); |
|
237 TUint32 size = 0; |
|
238 |
|
239 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
240 |
|
241 //get the list data |
|
242 DoGetList(EExecutables, EScopeGlobal, buffer, size); |
|
243 |
|
244 //get this process' name |
|
245 RProcess thisProcess; |
|
246 TFileName thisProcessName = thisProcess.FileName(); |
|
247 |
|
248 //look through the buffer and check if the target debug thread is there |
|
249 TBool found = EFalse; |
|
250 TUint8* ptr = (TUint8*)buffer.Ptr(); |
|
251 const TUint8* ptrEnd = ptr + size; |
|
252 while(ptr < ptrEnd) |
|
253 { |
|
254 TExecutablesListEntry& entry = *(TExecutablesListEntry*)ptr; |
|
255 //get name |
|
256 TPtr name(&entry.iName[0], entry.iNameLength, entry.iNameLength); |
|
257 if( (entry.iIsActivelyDebugged != 0) && (0 == thisProcessName.CompareF(name)) ) |
|
258 { |
|
259 //found this process and asserted it is being actively debugged |
|
260 found = ETrue; |
|
261 } |
|
262 //move pointer on to next entry |
|
263 ptr += Align4(entry.GetSize()); |
|
264 } |
|
265 test(found); |
|
266 |
|
267 //clean up |
|
268 buffer.Close(); |
|
269 |
|
270 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
271 } |
|
272 |
|
273 //--------------------------------------------- |
|
274 //! @SYMTestCaseID KBase-T-RMDEBUG2-0428 |
|
275 //! @SYMTestType |
|
276 //! @SYMPREQ PREQ1426 |
|
277 //! @SYMTestCaseDesc Test error conditions for the GetList calls |
|
278 //! @SYMTestActions Multiple calls to test calling GetList with bad arguments |
|
279 //! @SYMTestExpectedResults All tests should fail with the appropriate error codes |
|
280 //! @SYMTestPriority High |
|
281 //! @SYMTestStatus Implemented |
|
282 //--------------------------------------------- |
|
283 void CRunModeAgent::TestGetListInvalidData() |
|
284 { |
|
285 test.Next(_L("TestGetListInvalidData\n")); |
|
286 |
|
287 //allocate a buffer, the size should not matter as expecting all calls to fail |
|
288 RBuf8 buffer; |
|
289 test(KErrNone == buffer.Create(1)); |
|
290 TUint32 size = 0; |
|
291 |
|
292 //test what happens if we ask for an unsupported list type globally |
|
293 test(KErrNotSupported == iServSession.GetList((TListId)1234, buffer, size)); |
|
294 |
|
295 //test what happens if we ask for an unsupported list type |
|
296 test(KErrNotSupported == iServSession.GetList(RThread().Id(), (TListId)1234, buffer, size)); |
|
297 |
|
298 //test what happens if we try to get a non-global libraries list |
|
299 test(KErrArgument == iServSession.GetList(RThread().Id(), EXipLibraries, buffer, size)); |
|
300 |
|
301 //test what happens if we try to get a non-global executables list |
|
302 test(KErrArgument == iServSession.GetList(RThread().Id(), EExecutables, buffer, size)); |
|
303 |
|
304 //test what happens if we try to get a non-global process list |
|
305 test(KErrArgument == iServSession.GetList(RThread().Id(), EProcesses, buffer, size)); |
|
306 |
|
307 //check that using a process id fails |
|
308 test(KErrArgument == iServSession.GetList(RProcess().Id(), EProcesses, buffer, size)); |
|
309 |
|
310 //check that specifying a non-existant thread id fails |
|
311 test(KErrArgument == iServSession.GetList((TThreadId)0x12345678, EThreads, buffer, size)); |
|
312 |
|
313 //check that specifying a non-existant process id fails |
|
314 test(KErrArgument == iServSession.GetList((TProcessId)0x12345678, EThreads, buffer, size)); |
|
315 |
|
316 //check that specifying a non-existant thread id fails |
|
317 test(KErrArgument == iServSession.GetList((TThreadId)0x12345678, ECodeSegs, buffer, size)); |
|
318 |
|
319 //check that specifying a non-existant process id fails |
|
320 test(KErrArgument == iServSession.GetList((TProcessId)0x12345678, ECodeSegs, buffer, size)); |
|
321 |
|
322 //cleanup |
|
323 buffer.Close(); |
|
324 } |
|
325 |
|
326 //--------------------------------------------- |
|
327 //! @SYMTestCaseID KBase-T-RMDEBUG2-0429 |
|
328 //! @SYMTestType |
|
329 //! @SYMPREQ PREQ1426 |
|
330 //! @SYMTestCaseDesc Test getting the process list |
|
331 //! @SYMTestActions Get the process listing |
|
332 //! @SYMTestExpectedResults The process listing should be successfully obtained and the current process should be present in the list |
|
333 //! @SYMTestPriority High |
|
334 //! @SYMTestStatus Implemented |
|
335 //--------------------------------------------- |
|
336 void CRunModeAgent::TestGetProcessList() |
|
337 { |
|
338 test.Next(_L("TestGetProcessList\n")); |
|
339 |
|
340 test(ListingSupported(EProcesses, EScopeGlobal)); |
|
341 test(!ListingSupported(EProcesses, EScopeProcessSpecific)); |
|
342 test(!ListingSupported(EProcesses, EScopeThreadSpecific)); |
|
343 |
|
344 //allocate a very small buffer so the GetList call fails |
|
345 RBuf8 buffer; |
|
346 test(KErrNone == buffer.Create(1)); |
|
347 TUint32 size = 0; |
|
348 |
|
349 //get the list data |
|
350 DoGetList(EProcesses, EScopeGlobal, buffer, size); |
|
351 |
|
352 //initialise data about the target debug thread to compare the kernel's data against |
|
353 RProcess thisProcess; |
|
354 TFileName thisProcessName = thisProcess.FileName(); |
|
355 TUint32 processId = thisProcess.Id().Id(); |
|
356 |
|
357 //look through the buffer and check if the target debug thread is there |
|
358 TBool found = EFalse; |
|
359 TUint8* ptr = (TUint8*)buffer.Ptr(); |
|
360 const TUint8* ptrEnd = ptr + size; |
|
361 while(ptr < ptrEnd) |
|
362 { |
|
363 TProcessListEntry& entry = *(TProcessListEntry*)ptr; |
|
364 if( (RProcess().Id().Id() == entry.iProcessId) && |
|
365 (0 == thisProcessName.CompareF(TPtr(&(entry.iNames[0]), entry.iFileNameLength, entry.iFileNameLength))) && |
|
366 (0 == thisProcess.FullName().CompareF(TPtr(&(entry.iNames[0]) + entry.iFileNameLength, entry.iDynamicNameLength, entry.iDynamicNameLength))) && |
|
367 0x4321bbbb /* Magic */ == entry.iUid3) |
|
368 { |
|
369 //if all match then we've found it |
|
370 found = ETrue; |
|
371 } |
|
372 ptr += Align4(entry.GetSize()); |
|
373 } |
|
374 |
|
375 //check whether the expected result happened |
|
376 test(found); |
|
377 |
|
378 //clean up |
|
379 buffer.Close(); |
|
380 } |
|
381 |
|
382 //--------------------------------------------- |
|
383 //! @SYMTestCaseID KBase-T-RMDEBUG2-0430 |
|
384 //! @SYMTestType |
|
385 //! @SYMPREQ PREQ1426 |
|
386 //! @SYMTestCaseDesc Test getting the thread list |
|
387 //! @SYMTestActions Get the thread listing globally and for a specified thread or process |
|
388 //! @SYMTestExpectedResults The thread listings should all be successfully obtained and the current thread should be present in all listings |
|
389 //! @SYMTestPriority High |
|
390 //! @SYMTestStatus Implemented |
|
391 //--------------------------------------------- |
|
392 void CRunModeAgent::TestGetThreadList() |
|
393 { |
|
394 test.Next(_L("TestGetThreadList\n")); |
|
395 |
|
396 test(ListingSupported(EThreads, EScopeGlobal)); |
|
397 test(ListingSupported(EThreads, EScopeProcessSpecific)); |
|
398 test(ListingSupported(EThreads, EScopeThreadSpecific)); |
|
399 |
|
400 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
401 test(KErrNone == iServSession.SuspendThread(iThreadID)); |
|
402 |
|
403 TBool found = EFalse; |
|
404 |
|
405 /* We need these loops because on some system the kernel run mode debugger does not |
|
406 immediately present the thread in the thread list. |
|
407 */ |
|
408 |
|
409 for(TInt retryCount = 0; retryCount < 10 && !found; retryCount++ ) |
|
410 { |
|
411 //test getting this process's thread list, ETrue as should find the target debug thread |
|
412 User::After(50000); |
|
413 found = DoTestGetThreadList(ETrue, EScopeProcessSpecific, RProcess().Id().Id()); |
|
414 } |
|
415 test( found ); |
|
416 found = EFalse; |
|
417 |
|
418 for(TInt retryCount = 0; retryCount < 10 && !found; retryCount++ ) |
|
419 { |
|
420 //test getting the global list, ETrue as should find the target debug thread |
|
421 User::After(50000); |
|
422 found = DoTestGetThreadList(ETrue, EScopeGlobal); |
|
423 } |
|
424 test( found ); |
|
425 |
|
426 found = EFalse; |
|
427 for(TInt retryCount = 0; retryCount < 10 && !found; retryCount++ ) |
|
428 { |
|
429 //test getting this thread's thread list, ETrue as should find the target debug thread |
|
430 User::After(50000); |
|
431 found = DoTestGetThreadList(ETrue, EScopeThreadSpecific, RThread().Id().Id()); |
|
432 } |
|
433 test( found ); |
|
434 |
|
435 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
436 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
437 } |
|
438 |
|
439 TBool CRunModeAgent::DoTestGetThreadList(const TBool aShouldPass, const TListScope aListScope, const TUint64 aTargetId) |
|
440 { |
|
441 //create data to pass |
|
442 RBuf8 buffer; |
|
443 TUint32 size = 0; |
|
444 |
|
445 //perform the call to get the thread list |
|
446 DoGetList(EThreads, aListScope, buffer, size, aTargetId); |
|
447 |
|
448 //initialise data about the target debug thread to compare the kernel's data against |
|
449 TFileName name = iDebugThread.FullName(); |
|
450 RProcess thisProcess; |
|
451 TUint64 processId = thisProcess.Id(); |
|
452 TUint64 threadId = iDebugThread.Id(); |
|
453 |
|
454 //look through the buffer and check if the target debug thread is there |
|
455 TBool found = EFalse; |
|
456 TUint8* ptr = (TUint8*)buffer.Ptr(); |
|
457 const TUint8* ptrEnd = ptr + size; |
|
458 while(ptr < ptrEnd) |
|
459 { |
|
460 TThreadListEntry* entry = (TThreadListEntry*)ptr; |
|
461 TPtr entryName(&(entry->iName[0]), entry->iNameLength, entry->iNameLength); |
|
462 |
|
463 if( (threadId == entry->iThreadId) && (processId == entry->iProcessId) && (0 == name.CompareF(entryName)) ) |
|
464 { |
|
465 test(entry->iSupervisorStackBaseValid); |
|
466 test(entry->iSupervisorStackSizeValid); |
|
467 //if all match then we've found it |
|
468 found = ETrue; |
|
469 break; |
|
470 } |
|
471 |
|
472 ptr += Align4(entry->GetSize()); |
|
473 } |
|
474 |
|
475 //clean up |
|
476 buffer.Close(); |
|
477 return found; |
|
478 |
|
479 } |
|
480 |
|
481 //--------------------------------------------- |
|
482 //! @SYMTestCaseID KBase-T-RMDEBUG2-0431 |
|
483 //! @SYMTestType |
|
484 //! @SYMPREQ PREQ1426 |
|
485 //! @SYMTestCaseDesc Test getting the code segment list |
|
486 //! @SYMTestActions Get the code segment list global and for a specified thread |
|
487 //! @SYMTestExpectedResults The listings should be returned successfully |
|
488 //! @SYMTestPriority High |
|
489 //! @SYMTestStatus Implemented |
|
490 //--------------------------------------------- |
|
491 void CRunModeAgent::TestGetCodeSegsList() |
|
492 { |
|
493 test.Next(_L("TestGetCodeSegsList\n")); |
|
494 |
|
495 test(ListingSupported(ECodeSegs, EScopeGlobal)); |
|
496 test(ListingSupported(ECodeSegs, EScopeProcessSpecific)); |
|
497 test(ListingSupported(ECodeSegs, EScopeThreadSpecific)); |
|
498 |
|
499 // Cannot perform this test with OEM2 debug token, as the t_rmdebug2 app |
|
500 // needs AllFiles, and the OEM2 debug token does not authorise this. |
|
501 // It seems reasonable to suppose that it would work anyway |
|
502 |
|
503 #ifndef SYMBIAN_OEM2DEBUG |
|
504 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
505 |
|
506 //test getting the global list, ETrue as should find this process' main codeSeg |
|
507 DoTestGetCodeSegsList(ETrue, EScopeGlobal); |
|
508 |
|
509 //test getting this process' codeSegs, ETrue as should find this process' main codeSeg |
|
510 DoTestGetCodeSegsList(ETrue, EScopeProcessSpecific, RProcess().Id().Id()); |
|
511 |
|
512 //test getting this thread's codeSegs, ETrue as should find this process' main codeSeg |
|
513 DoTestGetCodeSegsList(ETrue, EScopeThreadSpecific, RThread().Id().Id()); |
|
514 |
|
515 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
516 #endif // SYMBIAN_OEM2DEBUG |
|
517 |
|
518 } |
|
519 |
|
520 void CRunModeAgent::DoTestGetCodeSegsList(const TBool aShouldPass, const TListScope aListScope, const TUint64 aTargetId) |
|
521 { |
|
522 //create data to pass |
|
523 RBuf8 buffer; |
|
524 TUint32 size = 0; |
|
525 |
|
526 //perform the call to get the Code segs |
|
527 DoGetList(ECodeSegs, aListScope, buffer, size, aTargetId); |
|
528 |
|
529 //create memoryInfo to contain info about this process |
|
530 RProcess thisProcess; |
|
531 TModuleMemoryInfo memoryInfo; |
|
532 test(KErrNone == thisProcess.GetMemoryInfo(memoryInfo)); |
|
533 |
|
534 // check whether this process came from a file in ROM so we know whether to |
|
535 // expect the code seg to be XIP or not. |
|
536 RFs fs; |
|
537 test(KErrNone == fs.Connect()); |
|
538 TBool thisFileIsInRom = EFalse; |
|
539 if(fs.IsFileInRom(iFileName)) |
|
540 { |
|
541 thisFileIsInRom = ETrue; |
|
542 } |
|
543 |
|
544 //look through the buffer to find this process' main code seg |
|
545 TBool found = EFalse; |
|
546 TUint8* ptr = (TUint8*)buffer.Ptr(); |
|
547 const TUint8* ptrEnd = ptr + size; |
|
548 while(ptr < ptrEnd) |
|
549 { |
|
550 TCodeSegListEntry* codeSeg = (TCodeSegListEntry*)ptr; |
|
551 |
|
552 if( (codeSeg->iIsXip == thisFileIsInRom) && (0 == iFileName.CompareF(TPtr(&(codeSeg->iName[0]), codeSeg->iNameLength, codeSeg->iNameLength))) ) |
|
553 { |
|
554 if( (memoryInfo.iCodeBase == codeSeg->iCodeBase) && |
|
555 (memoryInfo.iCodeSize == codeSeg->iCodeSize) && |
|
556 (memoryInfo.iConstDataSize == codeSeg->iConstDataSize) && |
|
557 (memoryInfo.iInitialisedDataBase == codeSeg->iInitialisedDataBase) && |
|
558 (memoryInfo.iInitialisedDataSize == codeSeg->iInitialisedDataSize) && |
|
559 (memoryInfo.iUninitialisedDataSize == codeSeg->iUninitialisedDataSize)) |
|
560 { |
|
561 //all matched so means we've found the codeSeg we're looking for |
|
562 found = ETrue; |
|
563 } |
|
564 } |
|
565 ptr += Align4(codeSeg->GetSize()); |
|
566 } |
|
567 |
|
568 //check whether the result was as expected |
|
569 test(found == aShouldPass); |
|
570 |
|
571 // only care about rm_debug.ldd if we have global scope (belongs to the system not this process) |
|
572 if (aListScope == EScopeGlobal) |
|
573 { |
|
574 // Search for rm_debug.ldd library and check its UID3 is correct |
|
575 found = EFalse; |
|
576 |
|
577 _LIT(KRMDebugDriverFileName,"Z:\\sys\bin\\rm_debug.ldd"); |
|
578 |
|
579 TFileName rmdebugFilename(KRMDebugDriverFileName); |
|
580 |
|
581 // reset the Ptr |
|
582 ptr = (TUint8*)buffer.Ptr(); |
|
583 ptrEnd = ptr+size; |
|
584 while(ptr < ptrEnd) |
|
585 { |
|
586 TCodeSegListEntry* codeSeg = (TCodeSegListEntry*)ptr; |
|
587 |
|
588 if( rmdebugFilename.CompareF(TPtr(&(codeSeg->iName[0]), codeSeg->iNameLength, codeSeg->iNameLength))) |
|
589 { |
|
590 if(codeSeg->iUid3 == 0x101f7157 /* Magic */) |
|
591 { |
|
592 //all matched so means we've found the codeSeg we're looking for |
|
593 found = ETrue; |
|
594 } |
|
595 } |
|
596 ptr += Align4(codeSeg->GetSize()); |
|
597 } |
|
598 test((TUint32)found == (TUint32)ETrue); |
|
599 } |
|
600 |
|
601 //clean up |
|
602 buffer.Close(); |
|
603 |
|
604 } |
|
605 |
|
606 |
|
607 /** |
|
608 * Get a list from the run mode debug system. Most list calls will initially return KErrTooBig, |
|
609 * since the initial size of the buffer is 0. However it is sometimes valid for a list to be empty |
|
610 * given its filtering and scope. These calls should return KErrNone. |
|
611 */ |
|
612 void CRunModeAgent::DoGetList(const TListId aListId, const TListScope aListScope, RBuf8& aBuffer, TUint32& aSize, const TUint64 aTargetId) |
|
613 { |
|
614 //close the buffer in case there's stuff allocated in it |
|
615 aBuffer.Close(); |
|
616 //initialise it to be one byte big, which will guarantee data won't fit in it |
|
617 test(KErrNone == aBuffer.Create(1)); |
|
618 aSize = 0; |
|
619 |
|
620 TInt ret = KErrNone; |
|
621 //should pass this test (assuming we've passed in sensible arguments above...) |
|
622 if(EScopeGlobal == aListScope) |
|
623 { |
|
624 ret = iServSession.GetList(aListId, aBuffer, aSize); |
|
625 } |
|
626 else if(EScopeThreadSpecific == aListScope) |
|
627 { |
|
628 ret = iServSession.GetList((TThreadId)aTargetId, aListId, aBuffer, aSize); |
|
629 } |
|
630 else if(EScopeProcessSpecific == aListScope) |
|
631 { |
|
632 ret = iServSession.GetList((TProcessId)aTargetId, aListId, aBuffer, aSize); |
|
633 } |
|
634 else |
|
635 { |
|
636 // unknown list scope |
|
637 test(0); |
|
638 } |
|
639 |
|
640 if( KErrNone == ret ) |
|
641 { |
|
642 /* In the case that there is no data, just return and let the caller check |
|
643 the buffer. It is valid for a caller to not expect any data to be returned. |
|
644 */ |
|
645 return; |
|
646 } |
|
647 |
|
648 // The only other allowed return is KErrTooBig |
|
649 test( ret == KErrTooBig ); |
|
650 |
|
651 //keep allocating larger buffers, beginning with the aSize returned by the above call, |
|
652 //and hopefully we'll eventually make a large enough one |
|
653 test(KErrNone == aBuffer.ReAlloc(aSize)); |
|
654 |
|
655 for(;;) |
|
656 { |
|
657 TInt err = KErrNone; |
|
658 if(EScopeGlobal == aListScope) |
|
659 { |
|
660 err = iServSession.GetList(aListId, aBuffer, aSize); |
|
661 } |
|
662 else if(EScopeThreadSpecific == aListScope) |
|
663 { |
|
664 err = iServSession.GetList((TThreadId)aTargetId, aListId, aBuffer, aSize); |
|
665 } |
|
666 else if(EScopeProcessSpecific == aListScope) |
|
667 { |
|
668 err = iServSession.GetList((TProcessId)aTargetId, aListId, aBuffer, aSize); |
|
669 } |
|
670 else |
|
671 { |
|
672 // unknown list scope |
|
673 test(0); |
|
674 } |
|
675 if(err == KErrTooBig) |
|
676 { |
|
677 //wasn't big enough so double it |
|
678 aSize = aSize << 1; |
|
679 err = aBuffer.ReAlloc(aSize); |
|
680 if(err != KErrNone) |
|
681 { |
|
682 //print out a message if couldn't allocate memory and quit |
|
683 test.Printf(_L("Out ot memory when attempting to allocate %d bytes."), aSize); |
|
684 test(KErrNone == err); |
|
685 } |
|
686 |
|
687 //fairly arbitrary test, we don't have a max size for these calls. |
|
688 //In reality a list would have to have many thousands of elements |
|
689 //to break this test which shouldn't really happen |
|
690 test(aSize <= 0x4000); |
|
691 } |
|
692 else |
|
693 { |
|
694 test(KErrNone == err); |
|
695 test(aBuffer.Length() == aSize); |
|
696 //break out of the loop if the list has been successfully read in |
|
697 break; |
|
698 } |
|
699 } |
|
700 } |
|
701 |
|
702 //--------------------------------------------- |
|
703 //! @SYMTestCaseID KBase-T-RMDEBUG2-0432 |
|
704 //! @SYMTestType |
|
705 //! @SYMPREQ PREQ1426 |
|
706 //! @SYMTestCaseDesc Test reading and writing memory |
|
707 //! @SYMTestActions Multiple calls to read and write memory, with various sizes and at various locations. |
|
708 //! Also test that bad input values cause appropriate errors to be returned. |
|
709 //! @SYMTestExpectedResults All tests should pass and the target process should be left unaffected |
|
710 //! @SYMTestPriority High |
|
711 //! @SYMTestStatus Implemented |
|
712 //--------------------------------------------- |
|
713 void CRunModeAgent::TestMemoryAccess() |
|
714 { |
|
715 TInt err; |
|
716 |
|
717 test.Next(_L("TestMemoryAccess - Read Memory\n")); |
|
718 |
|
719 //initialise buffer |
|
720 gMemoryAccessBytes.SetLength(0); |
|
721 for (TInt i=0; i<SYMBIAN_RMDBG_MEMORYSIZE; i++) |
|
722 { |
|
723 gMemoryAccessBytes.Append(i); |
|
724 } |
|
725 |
|
726 TUint32 address = (TUint32)(&gMemoryAccessBytes[0]); |
|
727 TUint32 dataSize = SYMBIAN_RMDBG_MEMORYSIZE; |
|
728 |
|
729 //create size for buffer that is rounded up to nearest 4 bytes if not |
|
730 //already 4 byte aligned |
|
731 TUint32 size = dataSize; |
|
732 if(size % 4 != 0) |
|
733 { |
|
734 size += (4 - (size % 4)); |
|
735 } |
|
736 |
|
737 RBuf8 dataBlock; |
|
738 err = dataBlock.Create(size); |
|
739 test(err==KErrNone); |
|
740 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
741 |
|
742 //suspend the thread prior to memory operations |
|
743 test(KErrNone == iServSession.SuspendThread(iThreadID)); |
|
744 |
|
745 err = iServSession.ReadMemory(iThreadID, address, size, dataBlock, EAccess32, EEndLE8); |
|
746 test(err==KErrNone); |
|
747 |
|
748 for (TInt i=0; i<dataSize; i++) |
|
749 { |
|
750 test(dataBlock.Ptr()[i] == gMemoryAccessBytes[i]); |
|
751 } |
|
752 |
|
753 test.Next(_L("TestMemoryAccess - Write Memory\n")); |
|
754 |
|
755 // Now reset the buffer |
|
756 for (TInt i=0; i<dataSize; i++) |
|
757 { |
|
758 gMemoryAccessBytes[i] = 0; |
|
759 } |
|
760 |
|
761 // Write our data into the buffer |
|
762 err = iServSession.WriteMemory(iThreadID, address, size, dataBlock, EAccess32, EEndLE8); |
|
763 test(err==KErrNone); |
|
764 |
|
765 for (TInt i=0; i<dataSize; i++) |
|
766 { |
|
767 test(dataBlock.Ptr()[i] == gMemoryAccessBytes[i]); |
|
768 } |
|
769 |
|
770 //final test that everything's not been going wrong |
|
771 test(gMemoryAccessBytes[5] != 0); |
|
772 |
|
773 test.Next(_L("TestMemoryAccess - Invalid arguments\n")); |
|
774 test.Printf(_L("This test may emit crash-like information. This is intended.\n")); |
|
775 |
|
776 //test address that is not 32 bit aligned |
|
777 err = iServSession.ReadMemory(iThreadID, address + 1, size, dataBlock, EAccess32, EEndLE8); |
|
778 test(err == KErrArgument); |
|
779 |
|
780 //test size that is not multiple of 4 bytes |
|
781 err = iServSession.WriteMemory(iThreadID, address, size + 2, dataBlock, EAccess32, EEndLE8); |
|
782 test(err == KErrArgument); |
|
783 |
|
784 //test size > max block size |
|
785 err = iServSession.ReadMemory(iThreadID, address, (1<<15), dataBlock, EAccess32, EEndLE8); |
|
786 test(err == KErrArgument); |
|
787 |
|
788 //test access size == 2 bytes |
|
789 err = iServSession.ReadMemory(iThreadID, address, size, dataBlock, EAccess16, EEndLE8); |
|
790 test(err == KErrNotSupported); |
|
791 |
|
792 //test access size == 1 byte |
|
793 err = iServSession.WriteMemory(iThreadID, address, size, dataBlock, EAccess8, EEndLE8); |
|
794 test(err == KErrNotSupported); |
|
795 |
|
796 //test endianess == EEndBE8 |
|
797 err = iServSession.ReadMemory(iThreadID, address, size, dataBlock, EAccess32, EEndBE8); |
|
798 test(err == KErrNotSupported); |
|
799 |
|
800 //test endianess == EEndBE32 |
|
801 err = iServSession.WriteMemory(iThreadID, address, size, dataBlock, EAccess32, EEndBE32); |
|
802 test(err == KErrNotSupported); |
|
803 |
|
804 //test reading off end of memory |
|
805 err = iServSession.ReadMemory(iThreadID, 0xffffff00, 0x00000101, dataBlock, EAccess32, EEndLE8); |
|
806 test(err == KErrArgument); |
|
807 |
|
808 //The following three tests check that edge conditions in the range check are handled correctly. |
|
809 err = iServSession.ReadMemory(iThreadID, 0xffffff00, 0x000000FF, dataBlock, EAccess32, EEndLE8); |
|
810 test(err == KErrArgument); |
|
811 |
|
812 err = iServSession.ReadMemory(iThreadID, 0xffffff00, 0x000000F0, dataBlock, EAccess32, EEndLE8); |
|
813 test(err == KErrBadDescriptor); |
|
814 |
|
815 //Third range check test. Check that range check is handled correctly even when base + size wraps to 0. |
|
816 err = iServSession.ReadMemory(iThreadID, 0xffffff00, 0x00000100, dataBlock, EAccess32, EEndLE8); |
|
817 test(err == KErrBadDescriptor); |
|
818 //end of range check tests |
|
819 |
|
820 //test size == 0 |
|
821 err = iServSession.WriteMemory(iThreadID, address, 0, dataBlock, EAccess32, EEndLE8); |
|
822 test(err == KErrArgument); |
|
823 |
|
824 //attempt to write to address outside of process data segments, |
|
825 //this address corresponds to the vectors so shouldn't be able to write |
|
826 err = iServSession.WriteMemory(iThreadID, 0xffff0000, size, dataBlock, EAccess32, EEndLE8); |
|
827 test(err == KErrBadDescriptor); |
|
828 |
|
829 //attempt to read and write to address in process code segment |
|
830 |
|
831 //open a handle to the thread |
|
832 RThread debugThread; |
|
833 test(debugThread.Open(iThreadID) == KErrNone); |
|
834 |
|
835 //get a reference to the debug process |
|
836 RProcess debugProcess; |
|
837 test(debugThread.Process(debugProcess) == KErrNone); |
|
838 |
|
839 //get the memory info for the process |
|
840 TProcessMemoryInfo info; |
|
841 test(debugProcess.GetMemoryInfo(info) == KErrNone); |
|
842 |
|
843 address = info.iCodeBase; |
|
844 if(size <= info.iCodeSize) |
|
845 { |
|
846 test(KErrNone == iServSession.ReadMemory(iThreadID, address, size, dataBlock, EAccess32, EEndLE8)); |
|
847 test(KErrBadDescriptor == iServSession.WriteMemory(iThreadID, address, size, dataBlock, EAccess32, EEndLE8)); |
|
848 } |
|
849 |
|
850 // Some performance tests now |
|
851 TUint32 bytesRead = 0; |
|
852 |
|
853 // Allocate a data buffer |
|
854 TUint32* p = (TUint32*)User::Alloc(size); |
|
855 test(p != 0); |
|
856 |
|
857 TInt nanokernel_tick_period; |
|
858 HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period); |
|
859 test (nanokernel_tick_period != 0); |
|
860 |
|
861 static const TInt KOneMillion = 1000000; |
|
862 |
|
863 TInt nkTicksPerSecond = KOneMillion/nanokernel_tick_period; |
|
864 |
|
865 TUint32 stopTickCount = User::NTickCount() + nkTicksPerSecond; |
|
866 |
|
867 while (User::NTickCount() < stopTickCount) |
|
868 { |
|
869 err = iServSession.ReadMemory(iThreadID, (TUint32)p, size, dataBlock, EAccess32, EEndLE8); |
|
870 test(err==KErrNone); |
|
871 |
|
872 // Increase the count of bytes read |
|
873 bytesRead += size; |
|
874 } |
|
875 |
|
876 test(bytesRead != 0); |
|
877 iMemoryReadKbytesPerSecond = bytesRead/1024; |
|
878 |
|
879 // write memory test |
|
880 TUint32 bytesWritten = 0; |
|
881 |
|
882 stopTickCount = User::NTickCount() + nkTicksPerSecond; |
|
883 |
|
884 while (User::NTickCount() < stopTickCount) |
|
885 { |
|
886 err = iServSession.WriteMemory(iThreadID, (TUint32)p, size, dataBlock, EAccess32, EEndLE8); |
|
887 test(err==KErrNone); |
|
888 |
|
889 // Increase the count of bytes read |
|
890 bytesWritten += size; |
|
891 } |
|
892 |
|
893 test (bytesWritten != 0); |
|
894 iMemoryWriteKbytesPerSecond = bytesWritten/1024; |
|
895 |
|
896 User::Free(p); |
|
897 |
|
898 //resume the thread |
|
899 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
900 |
|
901 debugThread.Close(); |
|
902 dataBlock.Close(); |
|
903 |
|
904 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
905 } |
|
906 |
|
907 //--------------------------------------------- |
|
908 //! @SYMTestCaseID KBase-T-RMDEBUG2-0433 |
|
909 //! @SYMTestType |
|
910 //! @SYMPREQ PREQ1426 |
|
911 //! @SYMTestCaseDesc Test suspending and resuming threads |
|
912 //! @SYMTestActions Multiple calls to suspend and resume threads with and without attaching to the thread |
|
913 //! @SYMTestExpectedResults All tests should pass and the target process should be left unaffected |
|
914 //! @SYMTestPriority High |
|
915 //! @SYMTestStatus Implemented |
|
916 //--------------------------------------------- |
|
917 void CRunModeAgent::TestSuspendResume() |
|
918 { |
|
919 TInt err; |
|
920 |
|
921 test.Next(_L("TestSuspendResume - Suspend\n")); |
|
922 |
|
923 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
924 // Suspend the thread |
|
925 err = iServSession.SuspendThread(iThreadID); |
|
926 test(err==KErrNone); |
|
927 TInt localtestdata; |
|
928 localtestdata = TestData; |
|
929 |
|
930 // Wait 3 seconds (suspends this thread) and hopefully resumes the |
|
931 // thread we are controlling via the iServSession.SuspendThread request |
|
932 User::After(3000000); |
|
933 |
|
934 // Now check data hasnt changed |
|
935 test(localtestdata==TestData); |
|
936 |
|
937 // Resume the thread |
|
938 test.Next(_L("TestSuspendResume - Resume\n")); |
|
939 err = iServSession.ResumeThread(iThreadID); |
|
940 test(err==KErrNone); |
|
941 |
|
942 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
943 |
|
944 // Wait 3 seconds (suspends this thread) and hopefully resumes the |
|
945 // thread we are controlling via the iServSession.SuspendThread request |
|
946 User::After(3000000); |
|
947 |
|
948 // Now check that the thread being controlled has resumed and is |
|
949 // updating the variable |
|
950 test(localtestdata!=TestData); |
|
951 |
|
952 // check that agent can resume thread which it previously detached from |
|
953 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
954 test(KErrNone == iServSession.SuspendThread(iThreadID)); |
|
955 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
956 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
957 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
958 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
959 |
|
960 // check that agent cannot suspend thread which it previously suspended and then detached from |
|
961 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
962 test(KErrNone == iServSession.SuspendThread(iThreadID)); |
|
963 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
964 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
965 test(KErrAlreadyExists == iServSession.SuspendThread(iThreadID)); |
|
966 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
967 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
968 } |
|
969 |
|
970 //--------------------------------------------- |
|
971 //! @SYMTestCaseID KBase-T-RMDEBUG2-0434 |
|
972 //! @SYMTestType |
|
973 //! @SYMPREQ PREQ1426 |
|
974 //! @SYMTestCaseDesc Test getting the debug functionality from the driver |
|
975 //! @SYMTestActions Get the size and contents of the debug functionality block |
|
976 //! @SYMTestExpectedResults All tests should pass and the expected data should appear in the functionality block |
|
977 //! @SYMTestPriority High |
|
978 //! @SYMTestStatus Implemented |
|
979 //--------------------------------------------- |
|
980 void CRunModeAgent::TestDebugFunctionality() |
|
981 { |
|
982 |
|
983 TInt err; |
|
984 |
|
985 test.Next(_L("TestDebugFunctionality - GetDebugFunctionalityBufSize\n")); |
|
986 |
|
987 TUint32 bufsize = 0; // Safe default size |
|
988 |
|
989 // Get functionality block size |
|
990 err = iServSession.GetDebugFunctionalityBufSize(&bufsize); |
|
991 test(err==KErrNone); |
|
992 test.Next(_L("TestDebugFunctionality - GetDebugFunctionality\n")); |
|
993 |
|
994 // Ensure we have a finite buffer size |
|
995 test(bufsize!=0); |
|
996 |
|
997 // Allocate space for the functionality data |
|
998 HBufC8* dftext = HBufC8::NewLC(bufsize); |
|
999 |
|
1000 // create an empty TPtr8 refering to dftext |
|
1001 TPtr8 dftextPtr(dftext->Des()); |
|
1002 |
|
1003 // Get the functionality block |
|
1004 err = iServSession.GetDebugFunctionality(dftextPtr); |
|
1005 test(err==KErrNone); |
|
1006 |
|
1007 // Check that the first entry is correct |
|
1008 TTagHeader RefHdr = |
|
1009 { |
|
1010 ETagHeaderIdCore,ECoreLast, |
|
1011 }; |
|
1012 |
|
1013 // First header passed from rm_debug.ldd |
|
1014 TTagHeader* TestHdr = (TTagHeader*)dftextPtr.Ptr(); |
|
1015 |
|
1016 // Check |
|
1017 test(RefHdr.iTagHdrId==TestHdr->iTagHdrId); |
|
1018 // this test might fail if the agent is used with a Debug Security Server different from |
|
1019 // the one it was compiled against. So removing it for now. |
|
1020 //test(RefHdr.iNumTags==TestHdr->iNumTags); |
|
1021 |
|
1022 // read a value from the data to check it has come through as expected |
|
1023 TTagHeader* header = GetTagHdr(dftext->Des(), ETagHeaderIdApiConstants); |
|
1024 test(header != NULL); |
|
1025 TTag* tag = GetTag(header, EApiConstantsTEventInfoSize); |
|
1026 test(tag != NULL); |
|
1027 // this test might fail if the agent is used with a Debug Security Server different from |
|
1028 // the one it was compiled against. So removing it for now. |
|
1029 //test(sizeof(TEventInfo) == tag->iValue); |
|
1030 |
|
1031 // Remove our temporary buffer |
|
1032 CleanupStack::PopAndDestroy(dftext); |
|
1033 } |
|
1034 |
|
1035 //--------------------------------------------- |
|
1036 //! @SYMTestCaseID KBase-T-RMDEBUG2-0435 |
|
1037 //! @SYMTestType |
|
1038 //! @SYMPREQ PREQ1426 |
|
1039 //! @SYMTestCaseDesc Test setting and clearing consecutive breakpoints |
|
1040 //! @SYMTestActions Set and clear consecutive breakpoints of all combinations of breakpoint types |
|
1041 //! @SYMTestExpectedResults All breakpoints should be set and cleared without error |
|
1042 //! @SYMTestPriority High |
|
1043 //! @SYMTestStatus Implemented |
|
1044 //--------------------------------------------- |
|
1045 void CRunModeAgent::TestConsecutiveBreakPoints() |
|
1046 { |
|
1047 test.Next(_L("TestConsecutiveBreakPoints\n")); |
|
1048 |
|
1049 test(KErrNone == iServSession.SuspendThread(iThreadID)); |
|
1050 |
|
1051 // just a temporary structure for storing info about a breakpoint |
|
1052 struct TBreakPoint |
|
1053 { |
|
1054 public: |
|
1055 TBreakPoint() |
|
1056 :iId(0), |
|
1057 iMode((TArchitectureMode)0), |
|
1058 iAddress(0) |
|
1059 {} |
|
1060 TBreakId iId; |
|
1061 TArchitectureMode iMode; |
|
1062 TUint32 iAddress; |
|
1063 inline TInt Size() { return (EArmMode == iMode) ? 4 : 2; } |
|
1064 }; |
|
1065 |
|
1066 //an address in the target debug thread |
|
1067 TUint32 address = (TUint32)(&TestFunction); |
|
1068 |
|
1069 // there are six orders in which three breakpoints can be set, these are looped |
|
1070 // through below to check setting and clearing consecutive breakpoints works |
|
1071 TUint8 order[6][3] = |
|
1072 { |
|
1073 {0,1,2}, |
|
1074 {0,2,1}, |
|
1075 {1,0,2}, |
|
1076 {1,2,0}, |
|
1077 {2,0,1}, |
|
1078 {2,1,0} |
|
1079 }; |
|
1080 |
|
1081 // The following code checks that setting and clearing consecutive breakpoints works correctly: |
|
1082 // It checks that setting all combinations of three arm and thumb breakpoints succeeds, and check that the |
|
1083 // breakpoints can be set in any order, and then cleared in any order |
|
1084 |
|
1085 // the 3 least significant bits of i control whether each of the three breakpoints should be arm or thumb |
|
1086 for(TInt i=0; i<8; i++) |
|
1087 { |
|
1088 // controls the order in which the breakpoints should be set |
|
1089 for(TInt j=0; j<6; j++) |
|
1090 { |
|
1091 // create the three breakpoints and set their modes |
|
1092 TBreakPoint bp[3]; |
|
1093 bp[0].iMode = (i&1) ? EArmMode : EThumbMode; |
|
1094 bp[1].iMode = (i&2) ? EArmMode : EThumbMode; |
|
1095 bp[2].iMode = (i&4) ? EArmMode : EThumbMode; |
|
1096 |
|
1097 // set the address of each of the breakpoints |
|
1098 bp[0].iAddress = address; |
|
1099 if(EArmMode == bp[0].iMode) |
|
1100 { // if an arm breakpoint then must be on a four byte boundary |
|
1101 bp[0].iAddress = Align4(bp[0].iAddress); |
|
1102 } |
|
1103 bp[1].iAddress = bp[0].iAddress + bp[0].Size(); |
|
1104 if(EArmMode == bp[1].iMode) |
|
1105 { // if an arm breakpoint then must be on a four byte boundary |
|
1106 bp[1].iAddress = Align4(bp[1].iAddress); |
|
1107 } |
|
1108 bp[2].iAddress = bp[1].iAddress + bp[1].Size(); |
|
1109 if(EArmMode == bp[2].iMode) |
|
1110 { // if an arm breakpoint then must be on a four byte boundary |
|
1111 bp[2].iAddress = Align4(bp[2].iAddress); |
|
1112 } |
|
1113 for(TInt k=0; k<6; k++) |
|
1114 { |
|
1115 // set the three breakpoints in the order defined by j and then clear them in the order defined by k |
|
1116 test(KErrNone==iServSession.SetBreak(bp[order[j][0]].iId, iThreadID, bp[order[j][0]].iAddress, bp[order[j][0]].iMode)); |
|
1117 test(KErrNone==iServSession.SetBreak(bp[order[j][1]].iId, iThreadID, bp[order[j][1]].iAddress, bp[order[j][1]].iMode)); |
|
1118 test(KErrNone==iServSession.SetBreak(bp[order[j][2]].iId, iThreadID, bp[order[j][2]].iAddress, bp[order[j][2]].iMode)); |
|
1119 test(KErrNone==iServSession.ClearBreak(bp[order[k][0]].iId)); |
|
1120 test(KErrNone==iServSession.ClearBreak(bp[order[k][1]].iId)); |
|
1121 test(KErrNone==iServSession.ClearBreak(bp[order[k][2]].iId)); |
|
1122 } |
|
1123 } |
|
1124 } |
|
1125 |
|
1126 // resume the thread |
|
1127 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
1128 } |
|
1129 |
|
1130 //--------------------------------------------- |
|
1131 //! @SYMTestCaseID KBase-T-RMDEBUG2-0436 |
|
1132 //! @SYMTestType |
|
1133 //! @SYMPREQ PREQ1426 |
|
1134 //! @SYMTestCaseDesc Test breakpoint functionality |
|
1135 //! @SYMTestActions Multiple calls to set and clear breakpoints. Checking bad input produces appropriate errors. |
|
1136 //! @SYMTestExpectedResults All tests should pass and the target debug thread should be left unaffected |
|
1137 //! @SYMTestPriority High |
|
1138 //! @SYMTestStatus Implemented |
|
1139 //--------------------------------------------- |
|
1140 void CRunModeAgent::TestBreakPoints() |
|
1141 { |
|
1142 TInt err; |
|
1143 |
|
1144 test.Next(_L("TestBreakPoints - Set\n")); |
|
1145 |
|
1146 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
1147 |
|
1148 TestConsecutiveBreakPoints(); |
|
1149 |
|
1150 //an address in the target debug thread |
|
1151 TUint32 address = (TUint32)(&TestFunction); |
|
1152 |
|
1153 /* |
|
1154 * Ensure that breakpoint operations don't |
|
1155 * affect memory read/write by checking that reads/writes |
|
1156 * in locations containing breakpoints don't change behaviour |
|
1157 * because of the breakpoints. |
|
1158 */ |
|
1159 |
|
1160 TUint32 size = SYMBIAN_RMDBG_MEMORYSIZE; |
|
1161 |
|
1162 RBuf8 originalDataBlock; |
|
1163 err = originalDataBlock.Create(size); |
|
1164 test(err==KErrNone); |
|
1165 |
|
1166 //suspend the thread |
|
1167 test(KErrNone == iServSession.SuspendThread(iThreadID)); |
|
1168 |
|
1169 err = iServSession.ReadMemory(iThreadID, address, size, originalDataBlock, EAccess32, EEndLE8); |
|
1170 test(err==KErrNone); |
|
1171 |
|
1172 // Test data block for comparison |
|
1173 RBuf8 testDataBlock; |
|
1174 err = testDataBlock.Create(size); |
|
1175 test(err==KErrNone); |
|
1176 |
|
1177 /* |
|
1178 * set an arm breakpoint |
|
1179 */ |
|
1180 TBreakId armBreakId = 0; |
|
1181 err = iServSession.SetBreak(armBreakId, iThreadID, address, EArmMode); |
|
1182 test(err == KErrNone); |
|
1183 |
|
1184 // Ensure that memory read is not corrupted |
|
1185 err = iServSession.ReadMemory(iThreadID, address, size, testDataBlock, EAccess32, EEndLE8); |
|
1186 test(err==KErrNone); |
|
1187 |
|
1188 test (testDataBlock == originalDataBlock); |
|
1189 |
|
1190 /* |
|
1191 * set a thumb breakpoint |
|
1192 */ |
|
1193 TBreakId thumbBreakId = 0; |
|
1194 err = iServSession.SetBreak(thumbBreakId, iThreadID, address+4, EThumbMode); |
|
1195 test(err == KErrNone); |
|
1196 |
|
1197 /* |
|
1198 * set a thumb2EE breakpoint |
|
1199 */ |
|
1200 TBreakId thumb2EEBreakId = 0; |
|
1201 err = iServSession.SetBreak(thumb2EEBreakId, iThreadID, address+8, EThumb2EEMode); |
|
1202 test(err == KErrNotSupported); |
|
1203 |
|
1204 /* |
|
1205 * overlapping breakpoint (same address/threadId/mode) |
|
1206 */ |
|
1207 TBreakId overlapBreakId = 0; |
|
1208 err = iServSession.SetBreak(overlapBreakId, iThreadID, address, EArmMode); |
|
1209 test(err == KErrAlreadyExists); |
|
1210 |
|
1211 /* |
|
1212 * overlapping breakpoint (different address/same threadId/different mode) |
|
1213 * |
|
1214 * address - EArmBreakpoint |
|
1215 * address+2 - EThumbBreakpoint |
|
1216 */ |
|
1217 TBreakId overlap2BreakId = 0; |
|
1218 err = iServSession.SetBreak(overlap2BreakId, iThreadID, address+2, EThumbMode); |
|
1219 test(err == KErrAlreadyExists); |
|
1220 |
|
1221 /* |
|
1222 * Un-aligned address (arm) |
|
1223 */ |
|
1224 TBreakId armUnalignedBreakId = 0; |
|
1225 err = iServSession.SetBreak(armUnalignedBreakId, iThreadID, address+6, EArmMode); |
|
1226 test(err == KErrArgument); |
|
1227 |
|
1228 /* |
|
1229 * Un-aligned address (thumb) |
|
1230 */ |
|
1231 TBreakId thumbUnalignedBreakId = 0; |
|
1232 err = iServSession.SetBreak(thumbUnalignedBreakId, iThreadID, address+7, EThumbMode); |
|
1233 test(err == KErrArgument); |
|
1234 |
|
1235 /* |
|
1236 * Invalid address (arm) |
|
1237 */ |
|
1238 TBreakId armBadAddressBreakId = 0; |
|
1239 err = iServSession.SetBreak(armBadAddressBreakId, iThreadID, 0 /* address */, EThumbMode); |
|
1240 test(err == KErrBadDescriptor); |
|
1241 |
|
1242 /* |
|
1243 * Different thread, same address. Should fail for the same process, but succeed |
|
1244 * for a different process. |
|
1245 */ |
|
1246 |
|
1247 /* |
|
1248 * Invalid thread |
|
1249 */ |
|
1250 TBreakId invalidThreadBreakId = 0; |
|
1251 err = iServSession.SetBreak(invalidThreadBreakId, 0xbabababa, address, EThumbMode); |
|
1252 test(err == KErrPermissionDenied); |
|
1253 |
|
1254 // Clear the ARM breakpoint |
|
1255 err = iServSession.ClearBreak(armBreakId); |
|
1256 test(err == KErrNone); |
|
1257 |
|
1258 // Clear the Thumb breakpoint |
|
1259 err = iServSession.ClearBreak(thumbBreakId); |
|
1260 test(err == KErrNone); |
|
1261 |
|
1262 // to do : two threads at the same address |
|
1263 // to do : two processes at the same address |
|
1264 |
|
1265 // Ensure that memory read is not corrupted after clearing the breakpoints |
|
1266 err = iServSession.ReadMemory(iThreadID, address, size, testDataBlock, EAccess32, EEndLE8); |
|
1267 test(err==KErrNone); |
|
1268 |
|
1269 test (testDataBlock == originalDataBlock); |
|
1270 |
|
1271 /* |
|
1272 * How fast can we set breakpoints? |
|
1273 * |
|
1274 * Measure the time by setting/clearing breakpoints for 1 second. |
|
1275 */ |
|
1276 TInt nanokernel_tick_period; |
|
1277 HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period); |
|
1278 test (nanokernel_tick_period != 0); |
|
1279 |
|
1280 TInt nkTicksPerSecond = HelpTicksPerSecond(); |
|
1281 |
|
1282 TInt breaksPerSecond = 0; |
|
1283 |
|
1284 TUint32 stopTickCount = User::NTickCount() + nkTicksPerSecond; |
|
1285 |
|
1286 while (User::NTickCount() < stopTickCount) |
|
1287 { |
|
1288 // set the breakpoint |
|
1289 TBreakId armBreakId = 0; |
|
1290 err = iServSession.SetBreak(armBreakId, iThreadID, address, EArmMode); |
|
1291 test(err == KErrNone); |
|
1292 |
|
1293 // Clear the breakpoint |
|
1294 err = iServSession.ClearBreak(armBreakId); |
|
1295 test(err == KErrNone); |
|
1296 |
|
1297 // Update the count of breakpoints |
|
1298 breaksPerSecond++; |
|
1299 |
|
1300 // Gone wrong if we wrap to negative breakpoints (cannot set 2billion/second!) |
|
1301 test(breaksPerSecond >0); |
|
1302 } |
|
1303 |
|
1304 // Store the results for later |
|
1305 iBreakpointsPerSecond = breaksPerSecond; |
|
1306 |
|
1307 /* |
|
1308 * How many breakpoints can we set? |
|
1309 */ |
|
1310 |
|
1311 TBool done = EFalse; |
|
1312 |
|
1313 // We assume all the breakpoints id's are issued in ascending order |
|
1314 TInt maxBreakPoints = 0; |
|
1315 |
|
1316 // Temporary buffer |
|
1317 RArray<TBreakId> breakIdList; |
|
1318 |
|
1319 TUint32 testAddress = address; |
|
1320 |
|
1321 while(!done) |
|
1322 { |
|
1323 TBreakId breakId = 0; |
|
1324 |
|
1325 // set the breakpoint |
|
1326 testAddress += 4; // ensure the addresses don't overlap |
|
1327 |
|
1328 err = iServSession.SetBreak(breakId, iThreadID, testAddress, EArmMode); |
|
1329 test (err == KErrNone || err == KErrOverflow); |
|
1330 if (err != KErrNone) |
|
1331 { |
|
1332 // we've reached the limit of the number of breaks we can set |
|
1333 done = ETrue; |
|
1334 break; |
|
1335 } |
|
1336 |
|
1337 // store the id of this breakpoint |
|
1338 breakIdList.Append(breakId); |
|
1339 |
|
1340 // Increase the count of breakpoints |
|
1341 maxBreakPoints++; |
|
1342 test(maxBreakPoints > 0); |
|
1343 } |
|
1344 |
|
1345 // How many breakpoints can we set? |
|
1346 iMaxBreakpoints = maxBreakPoints; |
|
1347 |
|
1348 // now clear all those breakpoints again |
|
1349 while(breakIdList.Count() != 0) |
|
1350 { |
|
1351 // Place it into a TBreakId |
|
1352 TBreakId id = breakIdList[0]; |
|
1353 |
|
1354 err = iServSession.ClearBreak(id); |
|
1355 test(err == KErrNone); |
|
1356 |
|
1357 // next id |
|
1358 breakIdList.Remove(0); |
|
1359 } |
|
1360 |
|
1361 breakIdList.Close(); |
|
1362 |
|
1363 // close our temporary buffers |
|
1364 originalDataBlock.Close(); |
|
1365 testDataBlock.Close(); |
|
1366 |
|
1367 err = iServSession.ResumeThread(iThreadID); |
|
1368 test (err == KErrNone); |
|
1369 |
|
1370 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
1371 } |
|
1372 |
|
1373 //--------------------------------------------- |
|
1374 //! @SYMTestCaseID KBase-T-RMDEBUG2-0437 |
|
1375 //! @SYMTestType |
|
1376 //! @SYMPREQ PREQ1426 |
|
1377 //! @SYMTestCaseDesc Test modifying breakpoints |
|
1378 //! @SYMTestActions Several calls to modify breakpoints |
|
1379 //! @SYMTestExpectedResults Valid requests should result in the breakpoints being changed, invalid requests should return errors |
|
1380 //! @SYMTestPriority High |
|
1381 //! @SYMTestStatus Implemented |
|
1382 //--------------------------------------------- |
|
1383 void CRunModeAgent::TestModifyBreak() |
|
1384 { |
|
1385 test.Next(_L("TestModifyBreak\n")); |
|
1386 |
|
1387 DoTestModifyBreak(ETrue); |
|
1388 DoTestModifyBreak(EFalse); |
|
1389 } |
|
1390 |
|
1391 void CRunModeAgent::DoTestModifyBreak(TBool aThreadSpecific) |
|
1392 { |
|
1393 test.Printf(_L("DoTestModifyBreak: aThreadSpecific: %d\n"), aThreadSpecific?1:0); |
|
1394 |
|
1395 TInt err; |
|
1396 |
|
1397 RProcess process; |
|
1398 TProcessId processId = process.Id(); |
|
1399 process.Close(); |
|
1400 |
|
1401 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
1402 |
|
1403 //suspend the thread |
|
1404 test(KErrNone == iServSession.SuspendThread(iThreadID)); |
|
1405 |
|
1406 //an address in the target debug thread |
|
1407 TUint32 address = (TUint32)(&TestFunction); |
|
1408 |
|
1409 //set an arm mode break point |
|
1410 TBreakId armBreakId = 0; |
|
1411 err = aThreadSpecific |
|
1412 ? iServSession.SetBreak(armBreakId, iThreadID, address, EArmMode) |
|
1413 : iServSession.SetProcessBreak(armBreakId, processId, address, EArmMode); |
|
1414 test(err == KErrNone); |
|
1415 |
|
1416 /* |
|
1417 * Invalid thread |
|
1418 */ |
|
1419 err = aThreadSpecific |
|
1420 ? iServSession.ModifyBreak(armBreakId, 0xbabababa, address, EArmMode) |
|
1421 : iServSession.ModifyProcessBreak(armBreakId, 0xbabababa, address, EArmMode); |
|
1422 test(err == KErrPermissionDenied); |
|
1423 |
|
1424 /* |
|
1425 * Valid address |
|
1426 */ |
|
1427 err = aThreadSpecific |
|
1428 ? iServSession.ModifyBreak(armBreakId, iThreadID, address+4, EArmMode) |
|
1429 : iServSession.ModifyProcessBreak(armBreakId, processId, address+4, EArmMode); |
|
1430 test(err == KErrNone); |
|
1431 |
|
1432 /* |
|
1433 * Invalid address |
|
1434 */ |
|
1435 err = aThreadSpecific |
|
1436 ? iServSession.ModifyBreak(armBreakId, iThreadID, 0, EArmMode) |
|
1437 : iServSession.ModifyProcessBreak(armBreakId, processId, 0, EArmMode); |
|
1438 test(err == KErrBadDescriptor); |
|
1439 |
|
1440 /* |
|
1441 * Thumb mode |
|
1442 */ |
|
1443 err = aThreadSpecific |
|
1444 ? iServSession.ModifyBreak(armBreakId, iThreadID, address, EThumbMode) |
|
1445 : iServSession.ModifyProcessBreak(armBreakId, processId, address, EThumbMode); |
|
1446 test(err == KErrNone); |
|
1447 |
|
1448 /* |
|
1449 * Thumb2EE mode |
|
1450 */ |
|
1451 err = aThreadSpecific |
|
1452 ? iServSession.ModifyBreak(armBreakId, iThreadID, address, EThumb2EEMode) |
|
1453 : iServSession.ModifyProcessBreak(armBreakId, processId, address, EThumb2EEMode); |
|
1454 test(err == KErrNotSupported); |
|
1455 |
|
1456 /* |
|
1457 * Arm mode |
|
1458 */ |
|
1459 err = aThreadSpecific |
|
1460 ? iServSession.ModifyBreak(armBreakId, iThreadID, address, EArmMode) |
|
1461 : iServSession.ModifyProcessBreak(armBreakId, processId, address, EArmMode); |
|
1462 test(err == KErrNone); |
|
1463 |
|
1464 // Finally, clear the breakpoint |
|
1465 err = iServSession.ClearBreak(armBreakId); |
|
1466 test(err == KErrNone); |
|
1467 |
|
1468 //resume the thread |
|
1469 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
1470 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
1471 } |
|
1472 |
|
1473 //--------------------------------------------- |
|
1474 //! @SYMTestCaseID KBase-T-RMDEBUG2-0438 |
|
1475 //! @SYMTestType |
|
1476 //! @SYMPREQ PREQ1426 |
|
1477 //! @SYMTestCaseDesc Test extracting information about breakpoints |
|
1478 //! @SYMTestActions Several calls to get information about breakpoints |
|
1479 //! @SYMTestExpectedResults All tests should pass and the target process should be left unaffected |
|
1480 //! @SYMTestPriority High |
|
1481 //! @SYMTestStatus Implemented |
|
1482 //--------------------------------------------- |
|
1483 void CRunModeAgent::TestBreakInfo() |
|
1484 { |
|
1485 test.Next(_L("TestBreakInfo\n")); |
|
1486 |
|
1487 DoTestBreakInfo(ETrue); |
|
1488 DoTestBreakInfo(EFalse); |
|
1489 } |
|
1490 |
|
1491 void CRunModeAgent::DoTestBreakInfo(TBool aThreadSpecific) |
|
1492 { |
|
1493 test.Printf(_L("DoTestModifyBreak: aThreadSpecific: %d\n"), aThreadSpecific?1:0); |
|
1494 |
|
1495 TInt err; |
|
1496 |
|
1497 RProcess process; |
|
1498 TProcessId processId = process.Id(); |
|
1499 process.Close(); |
|
1500 |
|
1501 //an address in the target debug thread |
|
1502 TUint32 address = (TUint32)(&TestFunction); |
|
1503 |
|
1504 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
1505 |
|
1506 //suspend thread |
|
1507 test(KErrNone == iServSession.SuspendThread(iThreadID)); |
|
1508 |
|
1509 //set an arm mode break point |
|
1510 TBreakId armBreakId = 0; |
|
1511 err = aThreadSpecific |
|
1512 ? iServSession.SetBreak(armBreakId, iThreadID, address, EArmMode) |
|
1513 : iServSession.SetProcessBreak(armBreakId, processId, address, EArmMode); |
|
1514 test(err == KErrNone); |
|
1515 |
|
1516 // Read back the information and check it is correct |
|
1517 TThreadId testThreadId = TThreadId(0); |
|
1518 TProcessId testProcessId = TProcessId(0); |
|
1519 TUint32 testAddress = 0; |
|
1520 TArchitectureMode testMode = EArmMode; |
|
1521 |
|
1522 err = aThreadSpecific |
|
1523 ? iServSession.BreakInfo(armBreakId,testThreadId,testAddress, testMode) |
|
1524 : iServSession.ProcessBreakInfo(armBreakId, testProcessId, testAddress, testMode); |
|
1525 test (err == KErrNone); |
|
1526 test (aThreadSpecific ? (testThreadId == iThreadID) : (testProcessId == processId)); |
|
1527 test (testAddress == address); |
|
1528 test (testMode == EArmMode); |
|
1529 |
|
1530 //change the address |
|
1531 TUint32 changeAddress = address + 64; |
|
1532 err = aThreadSpecific |
|
1533 ? iServSession.ModifyBreak(armBreakId, iThreadID, changeAddress,EArmMode) |
|
1534 : iServSession.ModifyProcessBreak(armBreakId, processId, changeAddress, EArmMode); |
|
1535 test(err == KErrNone); |
|
1536 |
|
1537 // Check the address has changed |
|
1538 err = aThreadSpecific |
|
1539 ? iServSession.BreakInfo(armBreakId,testThreadId,testAddress, testMode) |
|
1540 : iServSession.ProcessBreakInfo(armBreakId, testProcessId, testAddress, testMode); |
|
1541 test (err == KErrNone); |
|
1542 test (testAddress == changeAddress); |
|
1543 |
|
1544 // change the architecture type |
|
1545 TArchitectureMode checkMode = EThumbMode; |
|
1546 err = aThreadSpecific |
|
1547 ? iServSession.ModifyBreak(armBreakId, iThreadID, address,checkMode) |
|
1548 : iServSession.ModifyProcessBreak(armBreakId, processId, address, checkMode); |
|
1549 test (err == KErrNone); |
|
1550 |
|
1551 // Check the mode has changed |
|
1552 err = aThreadSpecific |
|
1553 ? iServSession.BreakInfo(armBreakId,testThreadId,testAddress,testMode) |
|
1554 : iServSession.ProcessBreakInfo(armBreakId, testProcessId, testAddress, testMode); |
|
1555 test (err == KErrNone); |
|
1556 test (testMode == checkMode); |
|
1557 |
|
1558 // clear the breakpoint again |
|
1559 err = iServSession.ClearBreak(armBreakId); |
|
1560 test (err == KErrNone); |
|
1561 |
|
1562 //resume thread |
|
1563 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
1564 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
1565 } |
|
1566 |
|
1567 // Needed for the RunToBreak test |
|
1568 IMPORT_C extern void RMDebug_BranchTst1(); |
|
1569 IMPORT_C extern void RMDebug_BranchTst2(); |
|
1570 |
|
1571 //--------------------------------------------- |
|
1572 //! @SYMTestCaseID KBase-T-RMDEBUG2-0439 |
|
1573 //! @SYMTestType |
|
1574 //! @SYMPREQ PREQ1426 |
|
1575 //! @SYMTestCaseDesc Test hitting various types of breakpoints |
|
1576 //! @SYMTestActions Several calls to register to observe breakpoints and to hit breakpoints of different types |
|
1577 //! @SYMTestExpectedResults All tests should pass and the target process should be left unaffected |
|
1578 //! @SYMTestPriority High |
|
1579 //! @SYMTestStatus Implemented |
|
1580 //--------------------------------------------- |
|
1581 void CRunModeAgent::TestRunToBreak() |
|
1582 { |
|
1583 test.Next(_L("TestRunToBreak\n")); |
|
1584 |
|
1585 DoTestRunToBreak(ETrue); |
|
1586 DoTestRunToBreak(EFalse); |
|
1587 } |
|
1588 |
|
1589 void CRunModeAgent::DoTestRunToBreak(TBool aThreadSpecific) |
|
1590 { |
|
1591 test.Printf(_L("DoTestRunToBreak: aThreadSpecific: %d\n"), aThreadSpecific?1:0); |
|
1592 |
|
1593 TInt err = KErrNone; |
|
1594 |
|
1595 RProcess process; |
|
1596 TProcessId processId = process.Id(); |
|
1597 process.Close(); |
|
1598 |
|
1599 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
1600 // we should suspend the thread first, then set the breakpoint |
|
1601 err = iServSession.SuspendThread(iThreadID); |
|
1602 test (err == KErrNone); |
|
1603 |
|
1604 // Try to set the breakpoint |
|
1605 TBreakId armBreakId; |
|
1606 TUint32 address = (TUint32)(&RMDebug_BranchTst1); |
|
1607 |
|
1608 err = aThreadSpecific |
|
1609 ? iServSession.SetBreak(armBreakId,iThreadID,address,EArmMode) |
|
1610 : iServSession.SetProcessBreak(armBreakId, processId, address, EArmMode); |
|
1611 test(err == KErrNone); |
|
1612 |
|
1613 err = aThreadSpecific |
|
1614 ? iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionContinue) |
|
1615 : iServSession.SetEventAction(iFileName,EEventsProcessBreakPoint, EActionContinue); |
|
1616 test (err == KErrNone); |
|
1617 |
|
1618 // Continue the thread |
|
1619 err = iServSession.ResumeThread(iThreadID); |
|
1620 test (err == KErrNone); |
|
1621 |
|
1622 // wait for the breakpoint to be hit |
|
1623 TEventInfo info; |
|
1624 static TRequestStatus status; |
|
1625 |
|
1626 TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo)); |
|
1627 |
|
1628 iServSession.GetEvent(iFileName,status,infoPtr); |
|
1629 |
|
1630 // Wait for notification of the breakpoint hit event |
|
1631 User::WaitForRequest(status); |
|
1632 test(status==KErrNone); |
|
1633 |
|
1634 // info should now be filled with the details |
|
1635 test(info.iEventType == (aThreadSpecific ? EEventsBreakPoint : EEventsProcessBreakPoint)); |
|
1636 test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address); |
|
1637 test(info.iProcessIdValid); |
|
1638 test(info.iThreadIdValid); |
|
1639 |
|
1640 // Not interested in breakpoint events any more |
|
1641 err = aThreadSpecific |
|
1642 ? iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionIgnore) |
|
1643 : iServSession.SetEventAction(iFileName, EEventsProcessBreakPoint, EActionIgnore); |
|
1644 test (err == KErrNone); |
|
1645 |
|
1646 // Clear the breakpoint again |
|
1647 err = iServSession.ClearBreak(armBreakId); |
|
1648 test(err == KErrNone); |
|
1649 |
|
1650 // continue the thread again |
|
1651 err = iServSession.ResumeThread(iThreadID); |
|
1652 test (err == KErrNone); |
|
1653 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
1654 } |
|
1655 |
|
1656 //--------------------------------------------- |
|
1657 //! @SYMTestCaseID KBASE-rmdebug2-2704 |
|
1658 //! @SYMTestType |
|
1659 //! @SYMPREQ PREQ1426 |
|
1660 //! @SYMTestCaseDesc Test breakpoints in a loop |
|
1661 //! @SYMTestActions Several calls to register to verify breakpoints are stopping at correct address |
|
1662 //! @SYMTestExpectedResults All tests should pass and the target thread should be left unaffected |
|
1663 //! @SYMTestPriority High |
|
1664 //! @SYMTestStatus Implemented |
|
1665 //--------------------------------------------- |
|
1666 void CRunModeAgent::TestBreakPointsInLoop() |
|
1667 { |
|
1668 test.Next(_L("TestBreakPointsInLoop\n")); |
|
1669 |
|
1670 DoTestBreakPointsInLoop(ETrue); |
|
1671 DoTestBreakPointsInLoop(EFalse); |
|
1672 } |
|
1673 |
|
1674 void CRunModeAgent::DoTestBreakPointsInLoop(TBool aThreadSpecific) |
|
1675 { |
|
1676 test.Printf(_L("DoTestBreakPointsInLoop: aThreadSpecific: %d\n"), aThreadSpecific?1:0); |
|
1677 |
|
1678 TInt err = KErrNone; |
|
1679 TProcessId processId = RProcess().Id(); |
|
1680 |
|
1681 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
1682 |
|
1683 // We should suspend the thread first, then set the breakpoint |
|
1684 err = iServSession.SuspendThread(iThreadID); |
|
1685 test (err == KErrNone); |
|
1686 |
|
1687 // 2 breakpoints are sufficient to find issues with hitting breakpoints in a loop |
|
1688 const TInt numOfBreakPointsInLoop = 2; |
|
1689 |
|
1690 TBreakId armBreakId[numOfBreakPointsInLoop]; |
|
1691 TUint32 address[numOfBreakPointsInLoop]; |
|
1692 |
|
1693 TUint32 entryAddress = (TUint32)(&RMDebug_Bkpt_Test_Entry); |
|
1694 TBreakId entryArmBreakId; |
|
1695 |
|
1696 // Copy breakpoint address's in array |
|
1697 address[0] = (TUint32)(&RMDebug_Bkpt_Test_Loop_Break_1); |
|
1698 address[1] = (TUint32)(&RMDebug_Bkpt_Test_Loop_Break_2); |
|
1699 |
|
1700 err = aThreadSpecific |
|
1701 ? iServSession.SetBreak(entryArmBreakId,iThreadID,entryAddress,EArmMode) |
|
1702 : iServSession.SetProcessBreak(entryArmBreakId, processId, entryAddress, EArmMode); |
|
1703 test(err == KErrNone); |
|
1704 |
|
1705 // Try to set the breakpoints inside loop |
|
1706 for (TInt i = 0; i < numOfBreakPointsInLoop; i++) |
|
1707 { |
|
1708 err = aThreadSpecific |
|
1709 ? iServSession.SetBreak(armBreakId[i],iThreadID,address[i],EArmMode) |
|
1710 : iServSession.SetProcessBreak(armBreakId[i], processId, address[i], EArmMode); |
|
1711 test(err == KErrNone); |
|
1712 } |
|
1713 |
|
1714 err = aThreadSpecific |
|
1715 ? iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionContinue) |
|
1716 : iServSession.SetEventAction(iFileName,EEventsProcessBreakPoint, EActionContinue); |
|
1717 test (err == KErrNone); |
|
1718 |
|
1719 // Continue the thread |
|
1720 err = iServSession.ResumeThread(iThreadID); |
|
1721 test (err == KErrNone); |
|
1722 |
|
1723 // Wait for the breakpoint to be hit |
|
1724 TEventInfo info; |
|
1725 TRequestStatus status; |
|
1726 |
|
1727 TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo)); |
|
1728 iServSession.GetEvent(iFileName,status,infoPtr); |
|
1729 |
|
1730 // Wait for notification of breakpoint event |
|
1731 User::WaitForRequest(status); |
|
1732 test(status==KErrNone); |
|
1733 |
|
1734 // Info should now be filled with the details |
|
1735 test(info.iEventType == (aThreadSpecific ? EEventsBreakPoint : EEventsProcessBreakPoint)); |
|
1736 |
|
1737 // Have we stopped at the correct breakpoint? |
|
1738 test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == entryAddress); |
|
1739 test(info.iProcessIdValid); |
|
1740 test(info.iThreadIdValid); |
|
1741 |
|
1742 // Don't require the entry breakpoint anymore |
|
1743 err = iServSession.ClearBreak(entryArmBreakId); |
|
1744 test(err == KErrNone); |
|
1745 |
|
1746 // Stress the system by setting loop count to 100 |
|
1747 const TUint32 loopCount = 100; |
|
1748 |
|
1749 for (TInt i = 0; i < loopCount; i++) |
|
1750 { |
|
1751 // Continue the thread |
|
1752 err = iServSession.ResumeThread(iThreadID); |
|
1753 test (err == KErrNone); |
|
1754 |
|
1755 // Wait for the breakpoint to be hit |
|
1756 iServSession.GetEvent(iFileName,status,infoPtr); |
|
1757 |
|
1758 // Wait for notification of the breakpoint hit event |
|
1759 User::WaitForRequest(status); |
|
1760 test(status==KErrNone); |
|
1761 |
|
1762 // Info should now be filled with the details |
|
1763 test(info.iEventType == (aThreadSpecific ? EEventsBreakPoint : EEventsProcessBreakPoint)); |
|
1764 |
|
1765 // Have we stopped at the correct breakpoint? |
|
1766 test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address[i%numOfBreakPointsInLoop]); |
|
1767 |
|
1768 // Check process and thread id too |
|
1769 test(info.iProcessIdValid); |
|
1770 test(info.iThreadIdValid); |
|
1771 } |
|
1772 |
|
1773 // Not interested in breakpoint events any more |
|
1774 err = aThreadSpecific |
|
1775 ? iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionIgnore) |
|
1776 : iServSession.SetEventAction(iFileName, EEventsProcessBreakPoint, EActionIgnore); |
|
1777 test (err == KErrNone); |
|
1778 |
|
1779 // Clear breakpoints |
|
1780 for (TInt i = 0; i < numOfBreakPointsInLoop; i++) |
|
1781 { |
|
1782 err = iServSession.ClearBreak(armBreakId[i]); |
|
1783 test(err == KErrNone); |
|
1784 } |
|
1785 |
|
1786 // Continue the thread again |
|
1787 err = iServSession.ResumeThread(iThreadID); |
|
1788 test (err == KErrNone); |
|
1789 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
1790 } |
|
1791 |
|
1792 //---------------------------------------------------------------------------------------------- |
|
1793 //! @SYMTestCaseID KBase-T-RMDEBUG2-0440 |
|
1794 //! @SYMTestType |
|
1795 //! @SYMPREQ PREQ1426 |
|
1796 //! @SYMTestCaseDesc Test access to target user-side registers. |
|
1797 //! @SYMTestActions Suspends a target thread, and reads/writes target thread register contents |
|
1798 //! |
|
1799 //! @SYMTestExpectedResults KErrNone. Should access target registers without problems. |
|
1800 //! @SYMTestPriority High |
|
1801 //! @SYMTestStatus Implemented |
|
1802 //---------------------------------------------------------------------------------------------- |
|
1803 |
|
1804 void CRunModeAgent::TestRegisterAccess() |
|
1805 { |
|
1806 TInt err; |
|
1807 |
|
1808 test.Next(_L("TestRegisterAccess - Read\n")); |
|
1809 |
|
1810 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
1811 |
|
1812 //suspend the thread to read registers |
|
1813 err = iServSession.SuspendThread(iThreadID); |
|
1814 test(err==KErrNone); |
|
1815 |
|
1816 //we'll try to read/write registers ERegisterR0 - ERegisterCPSR and ERegisterR13_IRQ |
|
1817 //this way should get valid register values back, invalid ones and not supported ones, and it |
|
1818 //means that the register IDs are not completely contiguous |
|
1819 |
|
1820 TInt firstRegister = 0; |
|
1821 TInt lastRegister = 17; |
|
1822 TInt numberOfRegisters = (lastRegister - firstRegister) + 1; |
|
1823 |
|
1824 RBuf8 ids; |
|
1825 err = ids.Create(numberOfRegisters * sizeof(TRegisterInfo)); |
|
1826 test(err == KErrNone); |
|
1827 |
|
1828 for(TInt i=0; i<numberOfRegisters - 1; i++) |
|
1829 { |
|
1830 TRegisterInfo reg = (TRegisterInfo)((i + firstRegister)<<8); |
|
1831 ids.Append(reinterpret_cast<const TUint8*>(®), sizeof(TRegisterInfo)); |
|
1832 } |
|
1833 |
|
1834 TRegisterInfo reg = ERegisterR13Irq; |
|
1835 ids.Append(reinterpret_cast<const TUint8*>(®), sizeof(TRegisterInfo)); |
|
1836 |
|
1837 //create a buffer to store the register values in |
|
1838 RBuf8 originalValues; |
|
1839 err = originalValues.Create(numberOfRegisters*sizeof(TUint32)); |
|
1840 test(err == KErrNone); |
|
1841 |
|
1842 //create a buffer to store the register flags in |
|
1843 RBuf8 originalFlags; |
|
1844 err = originalFlags.Create(numberOfRegisters*sizeof(TUint8)); |
|
1845 test(err == KErrNone); |
|
1846 |
|
1847 //read register values |
|
1848 err = iServSession.ReadRegisters(iThreadID, ids, originalValues, originalFlags); |
|
1849 test(err == KErrNone); |
|
1850 |
|
1851 //create a buffer containing data to write into the registers |
|
1852 RBuf8 tempValues; |
|
1853 err = tempValues.Create(numberOfRegisters*sizeof(TUint32)); |
|
1854 test(err == KErrNone); |
|
1855 |
|
1856 TUint cpsrId = 16; |
|
1857 for(TUint8 i=0; i<numberOfRegisters*sizeof(TUint32); i++) |
|
1858 { |
|
1859 if(i/sizeof(TUint32) == cpsrId) |
|
1860 { |
|
1861 //For the CPSR we wish to write data that makes sense - for USR mode we are |
|
1862 //allowed change all except the mode, ie. we must stay in usr mode. We try that here |
|
1863 //(allowedCPSRValue[4:0] = 10000) thus not changing the mode. |
|
1864 TUint32 allowedCPSRValue = 0x50000010; |
|
1865 tempValues.Append((TUint8*)&allowedCPSRValue, 4); |
|
1866 i += 3; |
|
1867 } |
|
1868 else |
|
1869 { |
|
1870 tempValues.Append(&i, 1); |
|
1871 } |
|
1872 } |
|
1873 |
|
1874 test.Next(_L("TestRegisterAccess - Write\n")); |
|
1875 |
|
1876 //create a buffer to store the register flags in |
|
1877 RBuf8 tempWriteFlags; |
|
1878 err = tempWriteFlags.Create(numberOfRegisters*sizeof(TUint8)); |
|
1879 test(err == KErrNone); |
|
1880 |
|
1881 //write the temp data into the registers |
|
1882 err = iServSession.WriteRegisters(iThreadID, ids, tempValues, tempWriteFlags); |
|
1883 test(err == KErrNone); |
|
1884 |
|
1885 //create another buffer to store the register flags in |
|
1886 RBuf8 tempReadFlags; |
|
1887 err = tempReadFlags.Create(numberOfRegisters*sizeof(TUint8)); |
|
1888 test(err == KErrNone); |
|
1889 |
|
1890 RBuf8 tempReadValues; |
|
1891 err = tempReadValues.Create(numberOfRegisters*sizeof(TUint32)); |
|
1892 test(err == KErrNone); |
|
1893 |
|
1894 //read the temp data out again |
|
1895 err = iServSession.ReadRegisters(iThreadID, ids, tempReadValues, tempReadFlags); |
|
1896 test(err == KErrNone); |
|
1897 |
|
1898 //check values are correct |
|
1899 for(TInt i=0; i<numberOfRegisters; i++) |
|
1900 { |
|
1901 TRegisterFlag writeFlag; |
|
1902 err = GetFlag(tempWriteFlags, i, writeFlag); |
|
1903 test(err == KErrNone); |
|
1904 |
|
1905 TRegisterFlag readFlag; |
|
1906 err = GetFlag(tempReadFlags, i, readFlag); |
|
1907 test(err == KErrNone); |
|
1908 |
|
1909 if((writeFlag == EValid) && (readFlag == EValid)) |
|
1910 { |
|
1911 TUint8 offset = i * sizeof(TUint32); |
|
1912 for(TUint j = offset; j< offset + sizeof(TUint32); j++) |
|
1913 { |
|
1914 test(tempValues.Ptr()[j] == tempReadValues.Ptr()[j]); |
|
1915 } |
|
1916 } |
|
1917 } |
|
1918 |
|
1919 //write the original data into the registers |
|
1920 err = iServSession.WriteRegisters(iThreadID, ids, originalValues, originalFlags); |
|
1921 test(err == KErrNone); |
|
1922 |
|
1923 //read the data out again |
|
1924 err = iServSession.ReadRegisters(iThreadID, ids, tempValues, tempReadFlags); |
|
1925 test(err == KErrNone); |
|
1926 |
|
1927 //check values are correct |
|
1928 for(TInt i=0; i<numberOfRegisters; i++) |
|
1929 { |
|
1930 TRegisterFlag writeFlag; |
|
1931 err = GetFlag(originalFlags, i, writeFlag); |
|
1932 test(err == KErrNone); |
|
1933 |
|
1934 TRegisterFlag readFlag; |
|
1935 err = GetFlag(tempReadFlags, i, readFlag); |
|
1936 test(err == KErrNone); |
|
1937 |
|
1938 if((writeFlag == EValid) && (readFlag == EValid)) |
|
1939 { |
|
1940 TUint8 offset = i * sizeof(TUint32); |
|
1941 for(TUint j = offset; j< offset + sizeof(TUint32); j++) |
|
1942 { |
|
1943 test(tempValues.Ptr()[j] == originalValues.Ptr()[j]); |
|
1944 } |
|
1945 } |
|
1946 } |
|
1947 |
|
1948 test.Next(_L("TestRegisterAccess - Invalid data\n")); |
|
1949 |
|
1950 //create a buffer of max size 1 |
|
1951 RBuf8 emptyBuffer; |
|
1952 emptyBuffer.Create(1); |
|
1953 |
|
1954 //test register IDs buffer not being a multiple of sizeof(TRegisterInfo) |
|
1955 err = iServSession.ReadRegisters(iThreadID, emptyBuffer, tempValues, tempReadFlags); |
|
1956 test(err == KErrArgument); |
|
1957 |
|
1958 //test register values buffer not being a multiple of sizeof(TUint32) |
|
1959 err = iServSession.ReadRegisters(iThreadID, ids, emptyBuffer, tempReadFlags); |
|
1960 test(err == KErrArgument); |
|
1961 |
|
1962 //test flags buffer being representing different number of registers from other two |
|
1963 err = iServSession.ReadRegisters(iThreadID, ids, tempValues, emptyBuffer); |
|
1964 test(err == KErrArgument); |
|
1965 |
|
1966 //set max length to 0 |
|
1967 emptyBuffer.ReAlloc(0); |
|
1968 |
|
1969 //test ids buffer being of 0 max length |
|
1970 err = iServSession.ReadRegisters(iThreadID, emptyBuffer, tempValues, tempReadFlags); |
|
1971 test(err == KErrArgument); |
|
1972 |
|
1973 //do cleanup |
|
1974 emptyBuffer.Close(); |
|
1975 tempValues.Close(); |
|
1976 tempWriteFlags.Close(); |
|
1977 tempReadFlags.Close(); |
|
1978 tempReadValues.Close(); |
|
1979 |
|
1980 test.Next(_L("TestRegisterAccess - Setting PC value\n")); |
|
1981 |
|
1982 //create buffer containing PC register ID |
|
1983 RBuf8 pcId; |
|
1984 err = pcId.Create(sizeof(TRegisterInfo)); |
|
1985 test(err == KErrNone); |
|
1986 TRegisterInfo reg1 = (TRegisterInfo)0x00000f00; |
|
1987 pcId.Append(reinterpret_cast<const TUint8*>(®1), sizeof(TRegisterInfo)); |
|
1988 |
|
1989 //create buffer containing desired PC value |
|
1990 RBuf8 pcValue; |
|
1991 err = pcValue.Create(sizeof(TUint32)); |
|
1992 test(err == KErrNone); |
|
1993 TUint32 address = (TUint32)(&TestFunction); |
|
1994 pcValue.Append(reinterpret_cast<const TUint8*>(&address), sizeof(TUint32)); |
|
1995 |
|
1996 //craete buffer for PC flag value |
|
1997 RBuf8 pcFlag; |
|
1998 err = pcFlag.Create(sizeof(TUint8)); |
|
1999 |
|
2000 //write the new PC value |
|
2001 err = iServSession.WriteRegisters(iThreadID, pcId, pcValue, pcFlag); |
|
2002 test(err==KErrNone); |
|
2003 |
|
2004 //get the flag and check the PC value was written ok |
|
2005 TRegisterFlag flag = ENotSupported; |
|
2006 err = GetFlag(pcFlag, 0, flag); |
|
2007 test(err==KErrNone); |
|
2008 |
|
2009 if(flag == EValid) |
|
2010 { |
|
2011 /* The PC value was changed to execute the function TestFunction. |
|
2012 * TestFunction changes the value of TestData to a given value and |
|
2013 * then calls RMDebug_BranchTst1. |
|
2014 * We place a breakpoint on RMDebug_BranchTst1 so that to we are able |
|
2015 * to test the value of TestData. |
|
2016 */ |
|
2017 |
|
2018 test(KErrNone == iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionSuspend)); |
|
2019 TBreakId armBreakId; |
|
2020 TUint32 address = (TUint32)(&RMDebug_BranchTst1); |
|
2021 test(KErrNone == iServSession.SetBreak(armBreakId,iThreadID,address,EArmMode)); |
|
2022 |
|
2023 // Continue the thread |
|
2024 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
2025 |
|
2026 // wait for the breakpoint to be hit |
|
2027 TEventInfo info; |
|
2028 static TRequestStatus status; |
|
2029 |
|
2030 TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo)); |
|
2031 iServSession.GetEvent(iFileName,status,infoPtr); |
|
2032 |
|
2033 // Wait for notification of the breakpoint hit event |
|
2034 User::WaitForRequest(status); |
|
2035 test(status==KErrNone); |
|
2036 |
|
2037 // info should now be filled with the details |
|
2038 test(info.iEventType == EEventsBreakPoint); |
|
2039 test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address); |
|
2040 test(info.iProcessIdValid); |
|
2041 test(info.iThreadIdValid); |
|
2042 |
|
2043 test(KErrNone == iServSession.ClearBreak(armBreakId)); |
|
2044 |
|
2045 // Finally test the value |
|
2046 test(TestData == 0xffeeddcc); |
|
2047 } |
|
2048 |
|
2049 //Make sure we cannot change the CPSR |
|
2050 test.Next(_L("Verifying we cannot change the CPSR mode from USR Mode")); |
|
2051 |
|
2052 TUint32 disallowedCpsr = 0x50000013; |
|
2053 |
|
2054 RBuf8 cpsrRegId; |
|
2055 err = cpsrRegId.Create(sizeof(TUint32)); |
|
2056 test(err == KErrNone); |
|
2057 |
|
2058 TRegisterInfo cpsr = (TRegisterInfo)((cpsrId + firstRegister)<<8); |
|
2059 cpsrRegId.Append(reinterpret_cast<const TUint8*>(&cpsr), sizeof(TRegisterInfo)); |
|
2060 |
|
2061 RBuf8 cpsrRegFlags; |
|
2062 err = cpsrRegFlags.Create(sizeof(TUint8)); |
|
2063 test(err == KErrNone); |
|
2064 |
|
2065 RBuf8 cpsrVal; |
|
2066 err = cpsrVal.Create(sizeof(TUint32)); |
|
2067 test(err == KErrNone); |
|
2068 |
|
2069 cpsrVal.Append((TUint8*)&disallowedCpsr, 4); |
|
2070 |
|
2071 //attempt to write disallowed CPSR in |
|
2072 err = iServSession.WriteRegisters(iThreadID, cpsrRegId, cpsrVal, cpsrRegFlags); |
|
2073 test(err == KErrNone); |
|
2074 |
|
2075 RBuf8 cpsrReadVal; |
|
2076 err = cpsrReadVal.Create(sizeof(TUint32)); |
|
2077 test(err == KErrNone); |
|
2078 |
|
2079 //Read back the CPSR |
|
2080 err = iServSession.ReadRegisters(iThreadID, cpsrRegId, cpsrReadVal, cpsrRegFlags); |
|
2081 test(err == KErrNone); |
|
2082 |
|
2083 //Make sure we havent switched modes ie. its not what we wrote |
|
2084 TUint32* readVal = (TUint32*)cpsrReadVal.Ptr(); |
|
2085 test(*readVal != disallowedCpsr); |
|
2086 |
|
2087 cpsrRegId.Close(); |
|
2088 cpsrRegFlags.Close(); |
|
2089 cpsrVal.Close(); |
|
2090 cpsrReadVal.Close(); |
|
2091 |
|
2092 //write the original values back into here |
|
2093 err = iServSession.WriteRegisters(iThreadID, ids, originalValues, originalFlags); |
|
2094 test(err == KErrNone); |
|
2095 |
|
2096 // Resume the thread |
|
2097 err = iServSession.ResumeThread(iThreadID); |
|
2098 test(err==KErrNone); |
|
2099 |
|
2100 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
2101 |
|
2102 //do cleanup |
|
2103 pcId.Close(); |
|
2104 pcValue.Close(); |
|
2105 pcFlag.Close(); |
|
2106 ids.Close(); |
|
2107 originalValues.Close(); |
|
2108 originalFlags.Close(); |
|
2109 } |
|
2110 |
|
2111 //---------------------------------------------------------------------------------------------- |
|
2112 //! @SYMTestCaseID KBase-T-RMDEBUG2-0441 |
|
2113 //! @SYMTestType |
|
2114 //! @SYMPREQ PREQ1426 |
|
2115 //! @SYMTestCaseDesc Test registration/de-registration of debug interest in target exe with the Debug Security Server |
|
2116 //! @SYMTestActions As per description |
|
2117 //! |
|
2118 //! @SYMTestExpectedResults KErrNone. |
|
2119 //! @SYMTestPriority High |
|
2120 //! @SYMTestStatus Implemented |
|
2121 //---------------------------------------------------------------------------------------------- |
|
2122 |
|
2123 void CRunModeAgent::TestAttachExecutable() |
|
2124 { |
|
2125 |
|
2126 test.Next(_L("TestAttachExecutable - Attach\n")); |
|
2127 |
|
2128 //attach to process passively |
|
2129 test(KErrNone == iServSession.AttachExecutable(iFileName, ETrue)); |
|
2130 |
|
2131 //make a thread id for a non-existent thread |
|
2132 TThreadId threadId(0x12345678); |
|
2133 |
|
2134 //get a handle to the target thread |
|
2135 RThread targetThread; |
|
2136 TInt err = targetThread.Open(threadId); |
|
2137 test(err != KErrNone); |
|
2138 |
|
2139 //not registered for this thread's process (as it doesn't exist) |
|
2140 //so should fail security check |
|
2141 err = iServSession.ResumeThread(threadId); |
|
2142 test(err==KErrPermissionDenied); |
|
2143 |
|
2144 //try to attach to the same process (and fail) |
|
2145 test(KErrAlreadyExists == iServSession.AttachExecutable(iFileName, EFalse)); |
|
2146 |
|
2147 test.Next(_L("TestAttachExecutable - Detach\n")); |
|
2148 |
|
2149 //detach from process |
|
2150 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
2151 |
|
2152 //attach non-passively |
|
2153 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
2154 |
|
2155 //not registered for this thread's process (as it doesn't exist) |
|
2156 //so should fail security check |
|
2157 err = iServSession.ResumeThread(0x12345678); |
|
2158 test(err==KErrPermissionDenied); |
|
2159 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
2160 } |
|
2161 |
|
2162 //---------------------------------------------------------------------------------------------- |
|
2163 //! @SYMTestCaseID KBase-T-RMDEBUG2-0442 |
|
2164 //! @SYMTestType |
|
2165 //! @SYMPREQ PREQ1426 |
|
2166 //! @SYMTestCaseDesc Tests single-stepping target threads. |
|
2167 //! @SYMTestActions Steps target thread assembly level instructions, mainly branch/change PC |
|
2168 //! |
|
2169 //! @SYMTestExpectedResults KErrNone. |
|
2170 //! @SYMTestPriority High |
|
2171 //! @SYMTestStatus Implemented |
|
2172 //---------------------------------------------------------------------------------------------- |
|
2173 |
|
2174 void CRunModeAgent::TestStep() |
|
2175 { |
|
2176 test.Next(_L("TestStep\n")); |
|
2177 |
|
2178 DoTestStep(EFalse); |
|
2179 DoTestStep(ETrue); |
|
2180 } |
|
2181 |
|
2182 void CRunModeAgent::DoTestStep(TBool aThreadSpecific) |
|
2183 { |
|
2184 test.Printf(_L("DoTestStep: aThreadSpecific: %d\n"), aThreadSpecific?1:0); |
|
2185 |
|
2186 TInt err = KErrNone; |
|
2187 |
|
2188 RProcess process; |
|
2189 TProcessId processId = process.Id(); |
|
2190 process.Close(); |
|
2191 |
|
2192 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
2193 //set the target thread to execute the stepping functions |
|
2194 test(KErrNone == SwitchTestFunction(EStepFunction)); |
|
2195 |
|
2196 err = iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionContinue); |
|
2197 test (err == KErrNone); |
|
2198 |
|
2199 if(!aThreadSpecific) |
|
2200 { |
|
2201 err = iServSession.SetEventAction(iFileName, EEventsProcessBreakPoint, EActionContinue); |
|
2202 test (err == KErrNone); |
|
2203 } |
|
2204 |
|
2205 TUint32 startAddress; |
|
2206 TUint32 endAddress; |
|
2207 |
|
2208 /* |
|
2209 * RMDebug_StepTest_Non_PC_Modifying |
|
2210 */ |
|
2211 test.Next(_L("TestStep - Non-PC modifying\n")); |
|
2212 |
|
2213 startAddress = (TUint32)(&RMDebug_StepTest_Non_PC_Modifying); |
|
2214 |
|
2215 endAddress = (TUint32)(&RMDebug_StepTest_Non_PC_Modifying_OK); |
|
2216 |
|
2217 err = aThreadSpecific |
|
2218 ? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1) |
|
2219 : HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId); |
|
2220 test(err==KErrNone); |
|
2221 |
|
2222 /* |
|
2223 * RMDebug_StepTest_Branch |
|
2224 */ |
|
2225 test.Next(_L("TestStep - Branch\n")); |
|
2226 |
|
2227 startAddress = (TUint32)(&RMDebug_StepTest_Branch); |
|
2228 |
|
2229 endAddress = (TUint32)(&RMDebug_StepTest_Branch_1); |
|
2230 |
|
2231 err = aThreadSpecific |
|
2232 ? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1) |
|
2233 : HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId); |
|
2234 test(err==KErrNone); |
|
2235 |
|
2236 /* |
|
2237 * RMDebug_StepTest_Branch_And_Link |
|
2238 */ |
|
2239 test.Next(_L("TestStep - Branch_And_Link\n")); |
|
2240 |
|
2241 startAddress = (TUint32)(&RMDebug_StepTest_Branch_And_Link_1); |
|
2242 |
|
2243 endAddress = (TUint32)(&RMDebug_StepTest_Branch_And_Link_2); |
|
2244 |
|
2245 err = aThreadSpecific |
|
2246 ? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1) |
|
2247 : HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId); |
|
2248 test(err==KErrNone); |
|
2249 |
|
2250 /* |
|
2251 * RMDebug_StepTest_MOV_PC |
|
2252 */ |
|
2253 test.Next(_L("TestStep - MOV PC,X\n")); |
|
2254 |
|
2255 startAddress = (TUint32)(&RMDebug_StepTest_MOV_PC_1); |
|
2256 |
|
2257 endAddress = (TUint32)(&RMDebug_StepTest_MOV_PC_2); |
|
2258 |
|
2259 err = aThreadSpecific |
|
2260 ? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1) |
|
2261 : HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId); |
|
2262 test(err==KErrNone); |
|
2263 |
|
2264 /* |
|
2265 * RMDebug_StepTest_LDR_PC |
|
2266 */ |
|
2267 test.Next(_L("TestStep - LDR PC\n")); |
|
2268 |
|
2269 startAddress = (TUint32)(&RMDebug_StepTest_LDR_PC); |
|
2270 |
|
2271 endAddress = (TUint32)(&RMDebug_StepTest_LDR_PC_1); |
|
2272 |
|
2273 err = aThreadSpecific |
|
2274 ? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1) |
|
2275 : HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId); |
|
2276 test(err==KErrNone); |
|
2277 |
|
2278 // thumb and interworking tests are not supported on armv4 |
|
2279 #ifdef __MARM_ARMV5__ |
|
2280 |
|
2281 /* |
|
2282 * RMDebug_StepTest_Thumb_Non_PC_Modifying |
|
2283 */ |
|
2284 test.Next(_L("TestStep - Thumb Non PC-Modifying\n")); |
|
2285 |
|
2286 startAddress = (TUint32)(&RMDebug_StepTest_Thumb_Non_PC_Modifying_1); |
|
2287 |
|
2288 endAddress = (TUint32)(&RMDebug_StepTest_Thumb_Non_PC_Modifying_2); |
|
2289 |
|
2290 err = aThreadSpecific |
|
2291 ? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1) |
|
2292 : HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId); |
|
2293 test(err==KErrNone); |
|
2294 |
|
2295 /* |
|
2296 * RMDebug_StepTest_Thumb_Branch |
|
2297 */ |
|
2298 test.Next(_L("TestStep - Thumb Branch\n")); |
|
2299 |
|
2300 startAddress = (TUint32)(&RMDebug_StepTest_Thumb_Branch_1); |
|
2301 |
|
2302 endAddress = (TUint32)(&RMDebug_StepTest_Thumb_Branch_2); |
|
2303 |
|
2304 err = aThreadSpecific |
|
2305 ? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1) |
|
2306 : HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId); |
|
2307 test(err==KErrNone); |
|
2308 |
|
2309 /* |
|
2310 * RMDebug_StepTest_Thumb_Branch_And_Link |
|
2311 */ |
|
2312 test.Next(_L("TestStep - Thumb Branch_And_Link\n")); |
|
2313 |
|
2314 startAddress = (TUint32)(&RMDebug_StepTest_Thumb_Branch_And_Link_2); |
|
2315 |
|
2316 endAddress = (TUint32)(&RMDebug_StepTest_Thumb_Branch_And_Link_3); |
|
2317 |
|
2318 TInt muid=0; |
|
2319 test(HAL::Get(HAL::EMachineUid, muid)==KErrNone); |
|
2320 |
|
2321 // check if running on ARMv7 core |
|
2322 if(muid==HAL::EMachineUid_OmapH6 || muid==HAL::EMachineUid_OmapZoom || muid==HAL::EMachineUid_EmuBoard) |
|
2323 { |
|
2324 // Note: ARMv7 treats BL instructions as single 32-bit instructions |
|
2325 err = aThreadSpecific |
|
2326 ? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1) |
|
2327 : HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId); |
|
2328 } |
|
2329 else |
|
2330 { |
|
2331 // Note: Due to the fact that the stepper treats BL instructions |
|
2332 // as two instructions (as the hardware does), then we must step |
|
2333 // the first half instruction first) |
|
2334 |
|
2335 err = aThreadSpecific |
|
2336 ? HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1) |
|
2337 : HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1, EFalse, processId); |
|
2338 test(err==KErrNone); |
|
2339 |
|
2340 // Now we actually do the BL |
|
2341 err = aThreadSpecific |
|
2342 ? HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1) |
|
2343 : HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1, EFalse, processId); |
|
2344 } |
|
2345 test(err==KErrNone); |
|
2346 |
|
2347 /* |
|
2348 * RMDebug_StepTest_Thumb_Back_Branch_And_Link |
|
2349 */ |
|
2350 test.Next(_L("TestStep - Thumb Back_Branch_And_Link\n")); |
|
2351 |
|
2352 startAddress = (TUint32)(&RMDebug_StepTest_Thumb_Back_Branch_And_Link_2); |
|
2353 |
|
2354 endAddress = (TUint32)(&RMDebug_StepTest_Thumb_Back_Branch_And_Link_3); |
|
2355 |
|
2356 // check if running on ARMv7 core |
|
2357 if(muid==HAL::EMachineUid_OmapH6 || muid==HAL::EMachineUid_OmapZoom || muid==HAL::EMachineUid_EmuBoard) |
|
2358 { |
|
2359 // Note: ARMv7 treats BL instructions as single 32-bit instructions |
|
2360 err = aThreadSpecific |
|
2361 ? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1) |
|
2362 : HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId); |
|
2363 } |
|
2364 else |
|
2365 { |
|
2366 // Note: Due to the fact that the stepper treats BL instructions |
|
2367 // as two instructions (as the hardware does), then we must step |
|
2368 // the first half instruction first) |
|
2369 |
|
2370 err = aThreadSpecific |
|
2371 ? HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1) |
|
2372 : HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1, EFalse, processId); |
|
2373 test(err==KErrNone); |
|
2374 |
|
2375 // Now we actually do the BL |
|
2376 err = aThreadSpecific |
|
2377 ? HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1) |
|
2378 : HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1, EFalse, processId); |
|
2379 } |
|
2380 test(err==KErrNone); |
|
2381 |
|
2382 /* |
|
2383 * RMDebug_StepTest_Thumb_AddPC |
|
2384 */ |
|
2385 test.Next(_L("TestStep - Thumb ADD PC, PC, R0\n")); |
|
2386 |
|
2387 startAddress = (TUint32)(&RMDebug_StepTest_Thumb_AddPC_2); |
|
2388 |
|
2389 endAddress = (TUint32)(&RMDebug_StepTest_Thumb_AddPC_3); |
|
2390 |
|
2391 err = aThreadSpecific |
|
2392 ? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1) |
|
2393 : HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId); |
|
2394 test(err==KErrNone); |
|
2395 |
|
2396 /* |
|
2397 * RMDebug_StepTest_Interwork ARM to Thumb |
|
2398 */ |
|
2399 test.Next(_L("TestStep - Interworking ARM to Thumb - BLX \n")); |
|
2400 |
|
2401 startAddress = (TUint32)(&RMDebug_StepTest_Interwork_1); |
|
2402 |
|
2403 endAddress = (TUint32)(&RMDebug_StepTest_Interwork_2); |
|
2404 |
|
2405 err = aThreadSpecific // nb initial breakpoint in ARM code |
|
2406 ? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1) |
|
2407 : HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,1, EFalse, processId); |
|
2408 |
|
2409 test(err==KErrNone); |
|
2410 |
|
2411 /* |
|
2412 * RMDebug_StepTest_Interwork Thumb to ARM |
|
2413 */ |
|
2414 test.Next(_L("TestStep - Interworking Thumb to ARM - BLX\n")); |
|
2415 |
|
2416 startAddress = (TUint32)(&RMDebug_StepTest_Interwork_2); |
|
2417 |
|
2418 endAddress = (TUint32)(&RMDebug_StepTest_Interwork_3); |
|
2419 |
|
2420 // check if running on ARMv7 core |
|
2421 if(muid==HAL::EMachineUid_OmapH6 || muid==HAL::EMachineUid_OmapZoom || muid==HAL::EMachineUid_EmuBoard) |
|
2422 { |
|
2423 // ARMv7 treats BLX instructions as single 32-bit instructions |
|
2424 err = aThreadSpecific |
|
2425 ? HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1) |
|
2426 : HelpTestStep(iThreadID,startAddress,endAddress,EThumbMode,1, EFalse, processId); |
|
2427 } |
|
2428 else |
|
2429 { |
|
2430 // Stepper treats this as a two-stage instruction (just like the hardware) |
|
2431 err = aThreadSpecific |
|
2432 ? HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1) |
|
2433 : HelpTestStep(iThreadID,startAddress,startAddress+2,EThumbMode,1, EFalse, processId); |
|
2434 test(err == KErrNone); |
|
2435 |
|
2436 err = aThreadSpecific |
|
2437 ? HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1) |
|
2438 : HelpTestStep(iThreadID,startAddress+2,endAddress,EThumbMode,1, EFalse, processId); |
|
2439 } |
|
2440 test(err == KErrNone); |
|
2441 |
|
2442 #endif // __MARM_ARMV5__ |
|
2443 |
|
2444 /* |
|
2445 * Test multiple-step of ARM code |
|
2446 */ |
|
2447 test.Next(_L("TestStep - ARM Multiple instruction step\n")); |
|
2448 |
|
2449 startAddress = (TUint32)(&RMDebug_StepTest_ARM_Step_Multiple); |
|
2450 |
|
2451 endAddress = (TUint32)(&RMDebug_StepTest_ARM_Step_Multiple_1); |
|
2452 |
|
2453 err = aThreadSpecific |
|
2454 ? HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,5) |
|
2455 : HelpTestStep(iThreadID,startAddress,endAddress,EArmMode,5, EFalse, processId); |
|
2456 test(err == KErrNone); |
|
2457 // stepping performance |
|
2458 test.Next(_L("TestStep - Steps per second\n")); |
|
2459 |
|
2460 // run until we reach RMDebug_StepTest_Count_1 |
|
2461 TBreakId stepBreakId; |
|
2462 startAddress = (TUint32)(&RMDebug_StepTest_Count_1); |
|
2463 endAddress = (TUint32)(&RMDebug_StepTest_Count_2); |
|
2464 |
|
2465 err = aThreadSpecific |
|
2466 ? HelpTestStepSetBreak(stepBreakId,iThreadID,startAddress,EArmMode) |
|
2467 : HelpTestStepSetBreak(stepBreakId,iThreadID,startAddress,EArmMode,EFalse,processId); |
|
2468 test (err == KErrNone); |
|
2469 |
|
2470 // wait until we hit the breakpoint |
|
2471 TEventInfo info; |
|
2472 err = HelpTestStepWaitForBreak(iFileName,info); |
|
2473 test (err == KErrNone); |
|
2474 |
|
2475 // Now clear the breakpoint |
|
2476 err = iServSession.ClearBreak(stepBreakId); |
|
2477 test(err == KErrNone); |
|
2478 |
|
2479 if(aThreadSpecific) |
|
2480 { |
|
2481 // now step the code |
|
2482 TInt stepsPerSecond = 0; |
|
2483 |
|
2484 TUint32 stopTickCount = User::NTickCount() + HelpTicksPerSecond(); |
|
2485 |
|
2486 while (User::NTickCount() < stopTickCount) |
|
2487 { |
|
2488 err = iServSession.Step(iThreadID,1); |
|
2489 test (err == KErrNone); |
|
2490 |
|
2491 // we need to wait now until the step completes before asking for the next step |
|
2492 { |
|
2493 TEventInfo info; |
|
2494 static TRequestStatus status; |
|
2495 |
|
2496 TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo)); |
|
2497 |
|
2498 iServSession.GetEvent(iFileName,status,infoPtr); |
|
2499 |
|
2500 // Wait for notification of the breakpoint hit event |
|
2501 User::WaitForRequest(status); |
|
2502 test(status==KErrNone); |
|
2503 } |
|
2504 |
|
2505 // Update the count of steps |
|
2506 stepsPerSecond += 1; |
|
2507 |
|
2508 // Gone wrong if we do too many |
|
2509 test(stepsPerSecond < 10000); |
|
2510 } |
|
2511 |
|
2512 iStepsPerSecond = stepsPerSecond; |
|
2513 test(iStepsPerSecond != 0); |
|
2514 } |
|
2515 |
|
2516 // finally resume the thread |
|
2517 err = iServSession.ResumeThread(iThreadID); |
|
2518 test (err == KErrNone); |
|
2519 |
|
2520 err = iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionIgnore); |
|
2521 test (err == KErrNone); |
|
2522 |
|
2523 if(!aThreadSpecific) |
|
2524 { |
|
2525 err = iServSession.SetEventAction(iFileName, EEventsProcessBreakPoint, EActionIgnore); |
|
2526 test (err == KErrNone); |
|
2527 } |
|
2528 |
|
2529 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
2530 } |
|
2531 |
|
2532 //---------------------------------------------------------------------------------------------- |
|
2533 //! @SYMTestCaseID KBase-T-RMDEBUG2-0443 |
|
2534 //! @SYMTestType |
|
2535 //! @SYMPREQ PREQ1426 |
|
2536 //! @SYMTestCaseDesc Tests registration and occurrence of target thread event (in this case panic) |
|
2537 //! @SYMTestActions Registers for a panic in the target thread, causes it, and catches the panic notification. |
|
2538 //! |
|
2539 //! @SYMTestExpectedResults KErrNone. |
|
2540 //! @SYMTestPriority High |
|
2541 //! @SYMTestStatus Implemented |
|
2542 //---------------------------------------------------------------------------------------------- |
|
2543 |
|
2544 void CRunModeAgent::TestEvents() |
|
2545 { |
|
2546 TInt err = KErrNone; |
|
2547 |
|
2548 test.Next(_L("TestEvents\n")); |
|
2549 |
|
2550 TInt panicReason = 12345; |
|
2551 |
|
2552 test.Printf(_L("Thread t_rmdebug.exe::DebugThread should panic with reason %d.\n"), panicReason); |
|
2553 |
|
2554 //attach non-passively |
|
2555 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
2556 |
|
2557 RThread threadToPanic; |
|
2558 test(KErrNone == StartDebugThread(threadToPanic, _L("EventsThread"))); |
|
2559 TThreadId threadToPanicId = threadToPanic.Id(); |
|
2560 TEventInfo info; |
|
2561 |
|
2562 // Set things up to wait for a thread kill event |
|
2563 err = iServSession.SetEventAction(iFileName, EEventsKillThread, EActionContinue); |
|
2564 test(err==KErrNone); |
|
2565 |
|
2566 // Wait for an event to occur in this process - nothing should have happened yet. |
|
2567 static TRequestStatus status; |
|
2568 |
|
2569 TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo)); |
|
2570 |
|
2571 iServSession.GetEvent(iFileName,status,infoPtr); |
|
2572 |
|
2573 // Test Request cancellation |
|
2574 err = iServSession.CancelGetEvent(iFileName); |
|
2575 test (err==KErrNone); |
|
2576 |
|
2577 // Again wait for an event to occur in our process - we will provoke the |
|
2578 // thread kill event by panic'ing the test thread. |
|
2579 iServSession.GetEvent(iFileName,status,infoPtr); |
|
2580 |
|
2581 // Panic the debug thread to cause a thread kill event |
|
2582 threadToPanic.Panic(_L("t_rmdebug panic thread test"), panicReason); |
|
2583 |
|
2584 // Wait for notification of the Thread Kill event |
|
2585 User::WaitForRequest(status); |
|
2586 test(status==KErrNone); |
|
2587 |
|
2588 // Check we are really recieving information about the panic |
|
2589 test(info.iProcessIdValid); |
|
2590 test(info.iThreadIdValid); |
|
2591 test(info.iProcessId==RProcess().Id()); |
|
2592 test(info.iThreadId==threadToPanicId); |
|
2593 test(info.iEventType==EEventsKillThread); |
|
2594 test(info.iThreadKillInfo.iExitType==EExitPanic); |
|
2595 |
|
2596 // Ignore other panic events |
|
2597 err = iServSession.SetEventAction(iFileName, EEventsKillThread, EActionIgnore); |
|
2598 test(err==KErrNone); |
|
2599 |
|
2600 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
2601 } |
|
2602 |
|
2603 //---------------------------------------------------------------------------------------------- |
|
2604 //! @SYMTestCaseID KBase-T-RMDEBUG2-0444 |
|
2605 //! @SYMTestType |
|
2606 //! @SYMPREQ PREQ1426 |
|
2607 //! @SYMTestCaseDesc Tests registration and occurence of target thread events in separate process. |
|
2608 //! @SYMTestActions Registers for a hardware exception and kill thread events, and receives them. |
|
2609 //! |
|
2610 //! @SYMTestExpectedResults KErrNone. |
|
2611 //! @SYMTestPriority High |
|
2612 //! @SYMTestStatus Implemented |
|
2613 //---------------------------------------------------------------------------------------------- |
|
2614 void CRunModeAgent::TestEventsForExternalProcess() |
|
2615 { |
|
2616 test.Next(_L("TestEventsForExternalProcess\n")); |
|
2617 |
|
2618 for(TInt main=0; main<3; main++) |
|
2619 { |
|
2620 for(TInt extra=0; extra<3; extra++) |
|
2621 { |
|
2622 TestEventsWithExtraThreads((TKernelEventAction)main, (TKernelEventAction)extra, 0); |
|
2623 TestEventsWithExtraThreads((TKernelEventAction)main, (TKernelEventAction)extra, 2); |
|
2624 } |
|
2625 } |
|
2626 } |
|
2627 |
|
2628 void CRunModeAgent::TestEventsWithExtraThreads(TKernelEventAction aActionMain, TKernelEventAction aActionExtra, TUint32 aExtraThreads) |
|
2629 { |
|
2630 const TInt KNumberOfTypes = 8; |
|
2631 struct TEventStruct |
|
2632 { |
|
2633 public: |
|
2634 TDebugFunctionType iDebugFunctionType; |
|
2635 TEventType iEventType; |
|
2636 }; |
|
2637 |
|
2638 TEventStruct type[KNumberOfTypes] = |
|
2639 { |
|
2640 {EStackOverflowFunction, EEventsHwExc}, |
|
2641 {EUserPanicFunction, EEventsKillThread}, |
|
2642 {EPrefetchAbortFunction, EEventsHwExc}, |
|
2643 {EDataAbortFunction, EEventsHwExc}, |
|
2644 {EUndefInstructionFunction, EEventsHwExc}, |
|
2645 {EDataReadErrorFunction, EEventsHwExc}, |
|
2646 {EDataWriteErrorFunction, EEventsHwExc}, |
|
2647 {EUserExceptionFunction, EEventsSwExc}, |
|
2648 }; |
|
2649 |
|
2650 for(TInt j=0; j<KNumberOfTypes; j++) |
|
2651 { |
|
2652 if( gUseDelay ) User::After(500000); |
|
2653 |
|
2654 RDebug::Printf("CRunModeAgent::TestEventsWithExtraThreads type: %d, main action: %d, extra action: %d, extraThreads: %d", |
|
2655 j, (TUint32)aActionMain, (TUint32)aActionExtra, aExtraThreads); |
|
2656 |
|
2657 // do this check as it seems to hard to do these cases with the current set up |
|
2658 if(EEventsKillThread == type[j].iEventType) |
|
2659 { |
|
2660 if(EActionSuspend != aActionMain) |
|
2661 { |
|
2662 if(aActionMain != aActionExtra) |
|
2663 { |
|
2664 return; |
|
2665 } |
|
2666 } |
|
2667 } |
|
2668 // attach to KRMDebugTestApplication |
|
2669 test(KErrNone == iServSession.AttachExecutable(KRMDebugTestApplication, EFalse)); |
|
2670 |
|
2671 // Set things up to wait for the expected exception in KRMDebugTestApplication |
|
2672 test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication, type[j].iEventType, aActionMain)); |
|
2673 |
|
2674 if(EActionSuspend != aActionMain) |
|
2675 { |
|
2676 test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication, EEventsKillThread, aActionExtra)); |
|
2677 } |
|
2678 |
|
2679 // declare a TRequestStatus object for asynchronous calls |
|
2680 TRequestStatus status; |
|
2681 |
|
2682 TEventInfo info; |
|
2683 TPtr8 infoBuffer = TPtr8((TUint8*)&info,0,sizeof(TEventInfo)); |
|
2684 if(EActionIgnore != aActionMain) |
|
2685 { |
|
2686 iServSession.GetEvent(KRMDebugTestApplication(), status, infoBuffer); |
|
2687 } |
|
2688 |
|
2689 // launch the target process to trigger the expected exception |
|
2690 RProcess targetProcess; |
|
2691 test(KErrNone == LaunchProcess(targetProcess, KRMDebugTestApplication(), type[j].iDebugFunctionType, 0, aExtraThreads)); |
|
2692 TProcessId processId(targetProcess.Id()); |
|
2693 targetProcess.Close(); |
|
2694 |
|
2695 if(EActionIgnore != aActionMain) |
|
2696 { |
|
2697 // wait for notification of the exception |
|
2698 User::WaitForRequest(status); |
|
2699 test(KErrNone == status.Int()); |
|
2700 |
|
2701 // check that this is the event we were expecting |
|
2702 test(info.iProcessIdValid); |
|
2703 test(info.iThreadIdValid); |
|
2704 test(info.iProcessId==processId); |
|
2705 test(info.iEventType==type[j].iEventType); |
|
2706 } |
|
2707 |
|
2708 if(EActionSuspend == aActionMain) |
|
2709 { |
|
2710 //RDebug::Printf("CRunModeAgent::TestEventsWithExtraThreads EActionSuspend == aActionMain, j=%d", j); |
|
2711 // read the thread list, partly to check the call works, and partly to check the thread still exists |
|
2712 test(ThreadExistsForProcess(info.iThreadId, info.iProcessId)); |
|
2713 |
|
2714 // register to catch all the thread kills which will occur |
|
2715 test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication, EEventsKillThread, aActionExtra)); |
|
2716 // we specified EActionSuspend earlier so need to call resume on this thread |
|
2717 test(KErrNone == iServSession.ResumeThread(info.iThreadId)); |
|
2718 } |
|
2719 |
|
2720 // find out how many threads there are in the process and catch all the thread kill events, |
|
2721 // the number of kill thread events should correspond to the number of extra threads launched, |
|
2722 // plus one if the main thread panicked with a Sw/Hw exception |
|
2723 if(EActionIgnore != aActionExtra) |
|
2724 { |
|
2725 TInt dyingThreads = aExtraThreads + ( (type[j].iEventType != EEventsKillThread) ? 1 : 0); |
|
2726 for(TInt k=0; k<dyingThreads; k++) |
|
2727 { |
|
2728 //RDebug::Printf("CRunModeAgent::TestEventsWithExtraThreads dyingThreads, k=%d, j=%d", k,j); |
|
2729 iServSession.GetEvent(KRMDebugTestApplication(), status, infoBuffer); |
|
2730 |
|
2731 // wait for notification of the kill thread |
|
2732 User::WaitForRequest(status); |
|
2733 test(KErrNone == status.Int()); |
|
2734 |
|
2735 // check that this is the event we were expecting |
|
2736 test(info.iProcessIdValid); |
|
2737 test(info.iThreadIdValid); |
|
2738 test(info.iProcessId==processId); |
|
2739 test(info.iEventType==EEventsKillThread); |
|
2740 if(EActionSuspend == aActionExtra) |
|
2741 { |
|
2742 // do some calls to check listings work ok at this stage |
|
2743 test(ProcessExists(info.iProcessId)); |
|
2744 test(ThreadExistsForProcess(info.iThreadId, info.iProcessId)); |
|
2745 // we specified EActionSuspend earlier so need to call resume on this thread |
|
2746 test(KErrNone == iServSession.ResumeThread(info.iThreadId)); |
|
2747 } |
|
2748 } |
|
2749 } |
|
2750 |
|
2751 if( gUseDelay ) User::After(500000); |
|
2752 |
|
2753 // reset the thread kill event |
|
2754 test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication(), EEventsKillThread, EActionIgnore)); |
|
2755 |
|
2756 // reset events for KRMDebugTestApplication |
|
2757 test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication(), type[j].iEventType, EActionIgnore)); |
|
2758 |
|
2759 // finished debugging KRMDebugTestApplication so detach |
|
2760 test(KErrNone == iServSession.DetachExecutable(KRMDebugTestApplication())); |
|
2761 |
|
2762 // want to validate that the process has really exited, i.e. we're not accidentally keeping a handle to it... |
|
2763 TInt waitCount = 10; |
|
2764 while((waitCount-- > 0) && ProcessExists(processId)) |
|
2765 { |
|
2766 /* Wait a little while and try again, just in case the process is still being removed. |
|
2767 This can happen on a very busy system or when a popup for the events is still active |
|
2768 */ |
|
2769 RDebug::Printf("CRunModeAgent::TestEventsWithExtraThreads. ProcessExists(id=%d), waiting count exit=%d", |
|
2770 I64LOW(processId), waitCount); |
|
2771 User::After(50000); |
|
2772 } |
|
2773 test(!ProcessExists(processId)); |
|
2774 } |
|
2775 } |
|
2776 |
|
2777 // helper function to check whether a thread with id aThreadId exists in the process with id aProcessId |
|
2778 TBool CRunModeAgent::ThreadExistsForProcess(const TThreadId aThreadId, const TProcessId aProcessId) |
|
2779 { |
|
2780 RThread lThread; |
|
2781 TInt ret = lThread.Open( aThreadId.Id() ); |
|
2782 |
|
2783 if( ret != KErrNone ) |
|
2784 { |
|
2785 RDebug::Printf("ThreadExistsForProcess: thread id=%d opening returned %d", |
|
2786 I64LOW( aThreadId.Id() ), ret ); |
|
2787 lThread.Close(); |
|
2788 return EFalse; |
|
2789 } |
|
2790 |
|
2791 RProcess lProcess; |
|
2792 ret = lThread.Process( lProcess ); |
|
2793 |
|
2794 lThread.Close(); |
|
2795 |
|
2796 if( ret != KErrNone ) |
|
2797 { |
|
2798 RDebug::Printf("ThreadExistsForProcess: proc opening returned %d", ret ); |
|
2799 ret = KErrNotFound; |
|
2800 } |
|
2801 else if( lProcess.Id() != aProcessId ) |
|
2802 { |
|
2803 RDebug::Printf("ThreadExistsForProcess: lProcess.Id()(%d)!= aProcessId(%d)", |
|
2804 I64LOW(lProcess.Id().Id()), I64LOW(aProcessId.Id())); |
|
2805 ret = KErrNotFound; |
|
2806 } |
|
2807 |
|
2808 lProcess.Close(); |
|
2809 |
|
2810 return ( ret == KErrNone ); |
|
2811 } |
|
2812 |
|
2813 // helper function to check whether a process with id aProcessId exists |
|
2814 TBool CRunModeAgent::ProcessExists(const TProcessId aProcessId) |
|
2815 { |
|
2816 TUint32 size; |
|
2817 RBuf8 buffer; |
|
2818 test(KErrNone == buffer.Create(1024)); |
|
2819 TInt err = iServSession.GetList(EProcesses, buffer, size); |
|
2820 while(KErrTooBig == err) |
|
2821 { |
|
2822 size*=2; |
|
2823 test(size<=16*1024); |
|
2824 test(KErrNone == buffer.ReAlloc(size)); |
|
2825 err = iServSession.GetList(EProcesses, buffer, size); |
|
2826 } |
|
2827 test(KErrNone == err); |
|
2828 |
|
2829 //look through the buffer and check if the target debug thread is there |
|
2830 TUint8* ptr = (TUint8*)buffer.Ptr(); |
|
2831 const TUint8* ptrEnd = ptr + size; |
|
2832 while(ptr < ptrEnd) |
|
2833 { |
|
2834 TProcessListEntry& entry = *(TProcessListEntry*)ptr; |
|
2835 if(aProcessId.Id() == entry.iProcessId) |
|
2836 { |
|
2837 buffer.Close(); |
|
2838 return ETrue; |
|
2839 } |
|
2840 ptr += Align4(entry.GetSize()); |
|
2841 } |
|
2842 buffer.Close(); |
|
2843 return EFalse; |
|
2844 } |
|
2845 |
|
2846 //---------------------------------------------------------------------------------------------- |
|
2847 //! @SYMTestCaseID KBase-T-RMDEBUG2-0445 |
|
2848 //! @SYMTestType |
|
2849 //! @SYMPREQ PREQ1426 |
|
2850 //! @SYMTestCaseDesc Tests basic debug functions work on demand-paged target threads |
|
2851 //! @SYMTestActions Checks it can r/w memory, set breakpoints etc in a demand paged target. |
|
2852 //! |
|
2853 //! @SYMTestExpectedResults KErrNone. |
|
2854 //! @SYMTestPriority High |
|
2855 //! @SYMTestStatus Implemented |
|
2856 //---------------------------------------------------------------------------------------------- |
|
2857 |
|
2858 void CRunModeAgent::TestDemandPaging(void) |
|
2859 { |
|
2860 test.Next(_L("TestDemandPaging\n")); |
|
2861 |
|
2862 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
2863 test(KErrNone == iServSession.SuspendThread(iThreadID)); |
|
2864 |
|
2865 // get the address of a function in code that will be paged in |
|
2866 TUint32 address = (TUint32)(&RMDebugDemandPagingTest); |
|
2867 const TUint32 armInstSize = 4; |
|
2868 |
|
2869 // read the memory at &RMDebugDemandPagingTest to check that reading memory in demand paged code works |
|
2870 TUint32 demandPagedInst = 0; |
|
2871 TPtr8 demandPagedInstBuf((TUint8*)&demandPagedInst, armInstSize); |
|
2872 test(KErrNone == iServSession.ReadMemory(iThreadID, address, armInstSize, demandPagedInstBuf, EAccess32, EEndLE8)); |
|
2873 |
|
2874 // this is the MOVS instruction that we expect to find in RMDebugDemandPagingTest |
|
2875 TUint32 expectedDemandPagedInst = 0xe1b02000; |
|
2876 |
|
2877 // check that the instruction we read is as expected |
|
2878 test(demandPagedInst == expectedDemandPagedInst); |
|
2879 |
|
2880 // set event action for break points |
|
2881 test(KErrNone == iServSession.SetEventAction(RProcess().FileName(), EEventsBreakPoint, EActionContinue)); |
|
2882 |
|
2883 // set an arm breakpoint on RMDebugDemandPagingTest |
|
2884 TBreakId armBreakId = 0; |
|
2885 test(KErrNone == iServSession.SetBreak(armBreakId, iThreadID, address, EArmMode)); |
|
2886 |
|
2887 // Ensure that after setting the breakpoint the memory read returns the correct value |
|
2888 TUint32 demandPagedInstWithBreakPoint = 0; |
|
2889 TPtr8 spinForeverInstWithBreakPointBuf((TUint8*)&demandPagedInstWithBreakPoint, armInstSize); |
|
2890 test(KErrNone == iServSession.ReadMemory(iThreadID, address, armInstSize, spinForeverInstWithBreakPointBuf, EAccess32, EEndLE8)); |
|
2891 test(demandPagedInst == demandPagedInstWithBreakPoint); |
|
2892 |
|
2893 // switch the target thread to run the demand paging function |
|
2894 test(KErrNone == SwitchTestFunction(EDemandPagingFunction)); |
|
2895 |
|
2896 // set up event watcher to catch breakpoint being hit in demand paged code |
|
2897 TEventInfo info; |
|
2898 static TRequestStatus status; |
|
2899 TPtr8 infoPtr((TUint8*)&info,sizeof(TEventInfo)); |
|
2900 iServSession.GetEvent(RProcess().FileName(), status, infoPtr); |
|
2901 |
|
2902 // resume the thread |
|
2903 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
2904 // wait for notification of the breakpoint hit event |
|
2905 User::WaitForRequest(status); |
|
2906 test(status==KErrNone); |
|
2907 |
|
2908 // info should now be filled with the details |
|
2909 test(info.iProcessIdValid); |
|
2910 test(info.iThreadIdValid); |
|
2911 test(info.iEventType == EEventsBreakPoint); |
|
2912 test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address); |
|
2913 |
|
2914 // remove the break point and resume the thread |
|
2915 test(KErrNone == iServSession.ClearBreak(armBreakId)); |
|
2916 |
|
2917 // switch the target thread to run the default function |
|
2918 test(KErrNone == SwitchTestFunction(EDefaultFunction)); |
|
2919 |
|
2920 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
2921 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
2922 } |
|
2923 |
|
2924 // Names of some test programs used for testing security |
|
2925 _LIT(KRMDebugSecurity0FileName,"z:\\sys\\bin\\t_rmdebug_security0.exe"); // Debuggable |
|
2926 _LIT(KRMDebugSecurity1FileName,"z:\\sys\\bin\\t_rmdebug_security1.exe"); // Not debuggable |
|
2927 _LIT(KRMDebugSecurity2FileName,"z:\\sys\\bin\\t_rmdebug_security2.exe"); // AllFiles |
|
2928 _LIT(KRMDebugSecurity3FileName,"z:\\sys\\bin\\t_rmdebug_security3.exe"); // TCB AllFiles |
|
2929 |
|
2930 // include the test header file here |
|
2931 #include "rm_debug_kerneldriver.h" |
|
2932 |
|
2933 //---------------------------------------------------------------------------------------------- |
|
2934 //! @SYMTestCaseID KBase-T-RMDEBUG2-0446 |
|
2935 //! @SYMTestType |
|
2936 //! @SYMPREQ PREQ1426 |
|
2937 //! @SYMTestCaseDesc Tests Debug Device Driver is locked to the SID of the Debug Security Svr. |
|
2938 //! @SYMTestActions Loads rm-debug.ldd and tries to open a handle to it. This should fail. |
|
2939 //! |
|
2940 //! @SYMTestExpectedResults KErrPermissionDenied. |
|
2941 //! @SYMTestPriority High |
|
2942 //! @SYMTestStatus Implemented |
|
2943 //---------------------------------------------------------------------------------------------- |
|
2944 |
|
2945 void CRunModeAgent::TestDriverSecurity(void) |
|
2946 { |
|
2947 test.Next(_L("TestDriverSecurity\n")); |
|
2948 |
|
2949 RRM_DebugDriver kernelDriver; |
|
2950 |
|
2951 // Load the debug device driver |
|
2952 TInt err = User::LoadLogicalDevice( KDebugDriverFileName ); |
|
2953 test((KErrNone == err) || (KErrAlreadyExists == err)); |
|
2954 |
|
2955 // we were allowed to load the driver, or its already loaded. |
|
2956 |
|
2957 // Try to open a handle to the driver - this should return KErrPermissionDenied as we don't have the DSS SID |
|
2958 TRM_DebugDriverInfo driverInfo; |
|
2959 driverInfo.iUserLibraryEnd = 0; |
|
2960 err = kernelDriver.Open(driverInfo); |
|
2961 test((err == KErrInUse) || (err == KErrPermissionDenied)); |
|
2962 |
|
2963 } |
|
2964 |
|
2965 //---------------------------------------------------------------------------------------------- |
|
2966 //! @SYMTestCaseID KBase-T-RMDEBUG2-0447 |
|
2967 //! @SYMTestType |
|
2968 //! @SYMPREQ PREQ1426 |
|
2969 //! @SYMTestCaseDesc Tests Debug driver can only be access via the DSS. Also tests DSS cannot |
|
2970 //! be subverted. Tests functionality of two representative OEM Debug Tokens. |
|
2971 //! @SYMTestActions Tries to open rm_debug.ldd (should fail). Tries to debug various processes |
|
2972 //! (only debuggable one should succeed). Checks that DSS behaves correctly |
|
2973 //! when different versions are passed in to Connect(). |
|
2974 //! |
|
2975 //! @SYMTestExpectedResults KErrPermissionDenied. |
|
2976 //! @SYMTestPriority High |
|
2977 //! @SYMTestStatus Implemented |
|
2978 //---------------------------------------------------------------------------------------------- |
|
2979 |
|
2980 void CRunModeAgent::TestSecurity(void) |
|
2981 { |
|
2982 // Things to test |
|
2983 // |
|
2984 // try to use debug driver directly ( should have the wrong UID/SID value!) |
|
2985 test.Next(_L("TestSecurity - Bypass Debug Security Server to Debug Device Driver - DSS running\n")); |
|
2986 |
|
2987 // Things to test |
|
2988 // |
|
2989 // Load the debug device driver |
|
2990 RRM_DebugDriver kernelDriver; |
|
2991 TInt err = User::LoadLogicalDevice( KDebugDriverFileName ); |
|
2992 test((KErrNone == err) || (KErrAlreadyExists == err)); |
|
2993 |
|
2994 // we were allowed to load the driver, or its already loaded. |
|
2995 |
|
2996 // Try to open handle a to the driver - this should return KErrPermission/KErrInUse as we don't have the DSS SID |
|
2997 // and we expect the DSS to already be using it. |
|
2998 TRM_DebugDriverInfo driverInfo; |
|
2999 driverInfo.iUserLibraryEnd = 0; |
|
3000 err = kernelDriver.Open(driverInfo); |
|
3001 test(err == KErrInUse); |
|
3002 |
|
3003 // Try requesting an unsupported version of DSS |
|
3004 test.Next(_L("TestSecurity - requesting unsupported versions of DSS\n")); |
|
3005 RSecuritySvrSession dss; |
|
3006 err = dss.Connect(TVersion(999999, 0, 0)); |
|
3007 test(err == KErrNotSupported); // Prior to DEF142018 this would crash, causing a KErrServerTerminated |
|
3008 err = dss.Connect(TVersion(KDebugServMajorVersionNumber, 999999, 0)); |
|
3009 test(err == KErrNotSupported); // Explicitly asking for a minor version should give KErrNotSupported too if it's newer than what's running. |
|
3010 err = dss.Connect(TVersion(KDebugServMajorVersionNumber, 0, 0)); |
|
3011 test(err == KErrNone); // But the correct major version and no explicit minor version should always succeed |
|
3012 dss.Close(); |
|
3013 |
|
3014 // |
|
3015 // Attach to the Debug Security Server (passive) |
|
3016 // |
|
3017 test.Next(_L("TestSecurity - Attach to the Debug Security Server (passive)\n")); |
|
3018 |
|
3019 _LIT(KSecurityServerProcessName, "z:\\sys\\bin\\rm_debug_svr.exe"); |
|
3020 |
|
3021 test(KErrPermissionDenied == iServSession.AttachExecutable(KSecurityServerProcessName, ETrue)); |
|
3022 |
|
3023 // |
|
3024 // Attach to the Debug Security Server (active) |
|
3025 // |
|
3026 test.Next(_L("TestSecurity - Attach to the Debug Security Server (active)\n")); |
|
3027 |
|
3028 test(KErrPermissionDenied == iServSession.AttachExecutable(KSecurityServerProcessName, EFalse)); |
|
3029 |
|
3030 // |
|
3031 // Attach to Process 0 |
|
3032 // |
|
3033 // Target: Debuggable |
|
3034 // |
|
3035 test.Next(_L("TestSecurity - Attach to test process 0\n")); |
|
3036 |
|
3037 // Agent can debug the target app as it is marked debuggable - ie capabilities are ignored) |
|
3038 HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity0FileName,ETrue); |
|
3039 |
|
3040 // |
|
3041 // Attach to Process - 1 |
|
3042 // |
|
3043 // Target: Non-debuggable for ordinary debug agent, debuggable for OEM/OEM2 token authorised agent |
|
3044 // |
|
3045 // Note: This target app has no PlatSec capabilities |
|
3046 // |
|
3047 // Agent cannot debug the app unless it has an OEM/OEM2 Debug Token |
|
3048 test.Next(_L("TestSecurity - Attach to test process 1\n")); |
|
3049 |
|
3050 #ifdef SYMBIAN_STANDARDDEBUG |
|
3051 HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity1FileName,EFalse); |
|
3052 #endif |
|
3053 |
|
3054 #ifdef SYMBIAN_OEMDEBUG |
|
3055 HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity1FileName,ETrue); |
|
3056 #endif |
|
3057 |
|
3058 #ifdef SYMBIAN_OEM2DEBUG |
|
3059 HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity1FileName,ETrue); |
|
3060 #endif |
|
3061 |
|
3062 // |
|
3063 // Attach to Process - 2 |
|
3064 // |
|
3065 // Target: Non-debuggable for ordinary debug agent, non-debuggable for OEM2 authorised agent (insufficient caps) |
|
3066 // |
|
3067 // Note: This target app has AllFiles capability |
|
3068 // |
|
3069 // Agent cannot debug the app unless it has an OEM Debug Token |
|
3070 test.Next(_L("TestSecurity - Attach to test process 2\n")); |
|
3071 |
|
3072 #ifdef SYMBIAN_STANDARDDEBUG |
|
3073 HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity2FileName,EFalse); |
|
3074 #endif |
|
3075 |
|
3076 #ifdef SYMBIAN_OEMDEBUG |
|
3077 HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity2FileName,ETrue); |
|
3078 #endif |
|
3079 |
|
3080 #ifdef SYMBIAN_OEM2DEBUG |
|
3081 HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity2FileName,EFalse); |
|
3082 #endif |
|
3083 |
|
3084 // |
|
3085 // Attach to Process - 3 |
|
3086 // |
|
3087 // Target: Non-debuggable for ordinary debug agent, non-debuggable for OEM authorised agent (insufficient caps) |
|
3088 // |
|
3089 // Note: This target app has AllFiles and TCB and NetworkControl capabilities |
|
3090 // |
|
3091 test.Next(_L("TestSecurity - Attach to test process 3\n")); |
|
3092 |
|
3093 HelpTestSecurityAttachDetachExecutable(KRMDebugSecurity3FileName,EFalse); |
|
3094 |
|
3095 } |
|
3096 |
|
3097 //---------------------------------------------------------------------------------------------- |
|
3098 //! @SYMTestCaseID KBase-T-RMDEBUG2-0543 |
|
3099 //! @SYMTestType |
|
3100 //! @SYMPREQ PREQ1426 |
|
3101 //! @SYMTestCaseDesc Validates that a dll can be built which #include's the rm_debug_api.h header, i.e. rm_debug_api.h contains no static data. |
|
3102 //! @SYMTestActions Calls a dummy function in t_rmdebug_dll.dll which implies the dll has been built correctly. |
|
3103 //! |
|
3104 //! @SYMTestExpectedResults KErrNone. |
|
3105 //! @SYMTestPriority High |
|
3106 //! @SYMTestStatus Implemented |
|
3107 //---------------------------------------------------------------------------------------------- |
|
3108 void CRunModeAgent::TestDllUsage(void) |
|
3109 { |
|
3110 test.Next(_L("TestDllUsage\n")); |
|
3111 test(KUidDebugSecurityServer == GetDSSUid()); |
|
3112 } |
|
3113 |
|
3114 //---------------------------------------------------------------------------------------------- |
|
3115 //! @SYMTestCaseID KBase-T-RMDEBUG2-0812 |
|
3116 //! @SYMTestType |
|
3117 //! @SYMPREQ PREQ1700 |
|
3118 //! @SYMTestCaseDesc Writes a known data to the crash flash and validates the data written |
|
3119 //! using the read operation and finally erase the data. In the absence |
|
3120 //! of an OEM debug token, access to the crash partition should not be allowed |
|
3121 //! @SYMTestActions Invoke the flash write method in DSS and call the read method in DSS |
|
3122 //! to validate the data is written correctly and then erase the written area |
|
3123 //! |
|
3124 //! @SYMTestExpectedResults KErrNone. |
|
3125 //! @SYMTestPriority High |
|
3126 //! @SYMTestStatus Implemented |
|
3127 //---------------------------------------------------------------------------------------------- |
|
3128 void CRunModeAgent::TestCrashFlash(void) |
|
3129 { |
|
3130 #if defined (SYMBIAN_STANDARDDEBUG) || defined (SYMBIAN_OEM2DEBUG) |
|
3131 |
|
3132 test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-006 Testing We cannot Erase the Crash Flash with insufficient privileges")); |
|
3133 |
|
3134 TUint32 size = 0; |
|
3135 TInt err = iServSession.EraseCrashLog(0, 1); |
|
3136 test(KErrPermissionDenied == err); |
|
3137 |
|
3138 test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-005 Testing We can't Write to the Crash Flash with insufficient privileges")); |
|
3139 |
|
3140 err = iServSession.WriteCrashConfig(0, KCrashDummyData, size); |
|
3141 test(KErrPermissionDenied == err); |
|
3142 test(size == 0); |
|
3143 |
|
3144 test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-008 Testing We can't Read from the Crash Flash with insufficient privileges")); |
|
3145 |
|
3146 TUint32 readSize = 0x10; |
|
3147 RBuf8 buf; |
|
3148 buf.CleanupClosePushL(); |
|
3149 err = buf.Create(readSize); |
|
3150 |
|
3151 test(err == KErrNone); |
|
3152 |
|
3153 err = iServSession.ReadCrashLog(0, buf, readSize); |
|
3154 test(KErrPermissionDenied == err); |
|
3155 |
|
3156 test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-004 Testing Writing To an invalid location")); |
|
3157 |
|
3158 TUint32 writeSize = 0; |
|
3159 err = iServSession.WriteCrashConfig(0xFFFFFFFF, KCrashDummyData, writeSize); |
|
3160 |
|
3161 test(err == KErrPermissionDenied); |
|
3162 |
|
3163 test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-003 Testing Reading from an invalid location")); |
|
3164 |
|
3165 buf.FillZ(); |
|
3166 err = iServSession.ReadCrashLog(0, buf, writeSize); |
|
3167 |
|
3168 test(err == KErrPermissionDenied); |
|
3169 |
|
3170 CleanupStack::PopAndDestroy(&buf); |
|
3171 |
|
3172 #endif |
|
3173 |
|
3174 #ifdef SYMBIAN_OEMDEBUG |
|
3175 |
|
3176 TInt err = KErrNone; |
|
3177 |
|
3178 test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-007 Testing We can Erase the Crash Flash with sufficient privileges")); |
|
3179 |
|
3180 err = iServSession.EraseCrashLog(0, 1); |
|
3181 |
|
3182 // For platforms where NAND flash is not currently supported we get a KErrNotSupported - this is still a pass |
|
3183 if (KErrNotSupported == err) |
|
3184 { |
|
3185 test.Printf(_L("Nand flash not supported - continue")); |
|
3186 return; |
|
3187 } |
|
3188 |
|
3189 //For platforms without a flash partition we get KErrNotFound - this is still a pass |
|
3190 if(KErrNotFound == err) |
|
3191 { |
|
3192 test.Printf(_L("Platform has no flash partition - continue")); |
|
3193 return; |
|
3194 } |
|
3195 |
|
3196 test(KErrNone == err); |
|
3197 |
|
3198 //Read back the start of the block to make sure its 0xFFFFFFFF |
|
3199 const TUint numBytesToCheck = 0x80; //We dont know the block size |
|
3200 TBuf8<numBytesToCheck> eraseCheck; |
|
3201 eraseCheck.SetLength(numBytesToCheck); |
|
3202 |
|
3203 err = iServSession.ReadCrashLog(0, eraseCheck, numBytesToCheck); |
|
3204 test(err == KErrNone); |
|
3205 |
|
3206 TBool dataIsOk = ETrue; |
|
3207 for(TUint cnt = 0; cnt < numBytesToCheck; cnt++) |
|
3208 { |
|
3209 if(eraseCheck[cnt] != 0xFF) |
|
3210 { |
|
3211 dataIsOk = EFalse; |
|
3212 } |
|
3213 } |
|
3214 |
|
3215 test(dataIsOk); |
|
3216 |
|
3217 test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-002 Testing We can Write to the Crash Flash with sufficient privileges")); |
|
3218 |
|
3219 TUint32 writeSize = 0; |
|
3220 err = iServSession.WriteCrashConfig(0, KCrashDummyData, writeSize); |
|
3221 |
|
3222 test(writeSize == KCrashDummyData().Length()); |
|
3223 |
|
3224 test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-001 Testing We can Read from the Crash Flash with sufficient privileges")); |
|
3225 |
|
3226 RBuf8 buf; |
|
3227 buf.CleanupClosePushL(); |
|
3228 err = buf.Create(writeSize); |
|
3229 |
|
3230 test(err == KErrNone); |
|
3231 |
|
3232 buf.FillZ(); |
|
3233 |
|
3234 err = iServSession.ReadCrashLog(0, buf, writeSize); |
|
3235 |
|
3236 test(0 == buf.Compare(KCrashDummyData)); |
|
3237 |
|
3238 test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-004 Testing Writing To an invalid location")); |
|
3239 |
|
3240 writeSize = 0; |
|
3241 err = iServSession.WriteCrashConfig(0xFFFFFFFF, KCrashDummyData, writeSize); |
|
3242 |
|
3243 test(err == KErrArgument); |
|
3244 |
|
3245 test.Next(_L("@SYMTestCaseID:DT-debug-securityserver-003 Testing Reading from an invalid location")); |
|
3246 |
|
3247 buf.FillZ(); |
|
3248 err = iServSession.ReadCrashLog(0xFFFFFFFF, buf, writeSize); |
|
3249 |
|
3250 test(err == KErrArgument); |
|
3251 |
|
3252 CleanupStack::PopAndDestroy(&buf); |
|
3253 |
|
3254 #endif |
|
3255 } |
|
3256 //---------------------------------------------------------------------------------------------- |
|
3257 //! @SYMTestCaseID KBase-T-RMDEBUG2-0735 |
|
3258 //! @SYMTestType |
|
3259 //! @SYMPREQ PREQ1426 |
|
3260 //! @SYMTestCaseDesc Tests the Kill Process functionality. Only can kill a debuggable process. |
|
3261 //! @SYMTestActions Launches a debuggable and non-debuggable process and tries to kill both. |
|
3262 //! |
|
3263 //! @SYMTestExpectedResults KErrNone. |
|
3264 //! @SYMTestPriority High |
|
3265 //! @SYMTestStatus Implemented |
|
3266 //---------------------------------------------------------------------------------------------- |
|
3267 void CRunModeAgent::TestKillProcess(void) |
|
3268 { |
|
3269 test.Next(_L("TestKillProcess\n")); |
|
3270 |
|
3271 // Kill a debuggable process |
|
3272 |
|
3273 // check that killing a process is supported |
|
3274 TTag tag = GetTag(ETagHeaderIdKillObjects, EFunctionalityKillProcess); |
|
3275 test(tag.iValue); |
|
3276 // check that killing a thread is not supported |
|
3277 tag = GetTag(ETagHeaderIdKillObjects, EFunctionalityKillThread); |
|
3278 test(!tag.iValue); |
|
3279 |
|
3280 // attach first! |
|
3281 TInt err = iServSession.AttachExecutable(KRMDebugTestApplication, EFalse /* Active */); |
|
3282 test(err == KErrNone); |
|
3283 |
|
3284 // first launch a debuggable process |
|
3285 RProcess process; |
|
3286 err = LaunchProcess(process, KRMDebugTestApplication(),ESpinForever, 0, 0); |
|
3287 test (err == KErrNone); |
|
3288 |
|
3289 // try to find the process in the list |
|
3290 _LIT(KRMDebugAppName, "t_rmdebug_app"); |
|
3291 |
|
3292 TBool found = ProcessExists(KRMDebugAppName); |
|
3293 test (found); |
|
3294 |
|
3295 TInt processId = process.Id(); |
|
3296 process.Close(); |
|
3297 |
|
3298 // program now running, so try to kill it |
|
3299 err = iServSession.KillProcess(processId, 0 /* kill reason */); |
|
3300 test(err == KErrNone); |
|
3301 |
|
3302 User::After(2000000); // should die within two seconds. |
|
3303 |
|
3304 // can we still find it? Should be gone |
|
3305 found = ProcessExists(KRMDebugAppName); |
|
3306 test (!found); |
|
3307 |
|
3308 // release the program again. |
|
3309 err = iServSession.DetachExecutable(KRMDebugTestApplication); |
|
3310 test(err == KErrNone); |
|
3311 |
|
3312 // Try to kill a non-debuggable process and fail. |
|
3313 |
|
3314 // first launch a non-debuggable process |
|
3315 RProcess process2; |
|
3316 err = LaunchProcess(process2, KRMDebugSecurity1FileName(),ESpinForever, 0, 0); |
|
3317 test (err == KErrNone); |
|
3318 |
|
3319 // try to find the process in the list |
|
3320 _LIT(KRMDebugAppName2, "t_rmdebug_security1"); |
|
3321 |
|
3322 TBool found2 = ProcessExists(KRMDebugAppName2); |
|
3323 test (found2); |
|
3324 |
|
3325 TInt process2Id = process2.Id(); |
|
3326 process2.Close(); |
|
3327 |
|
3328 // program now running, so try to kill it |
|
3329 err = iServSession.KillProcess(process2Id, 0 /* kill reason */); |
|
3330 test(err == KErrPermissionDenied); |
|
3331 |
|
3332 User::After(2000000); // should die within two seconds if it is going to die. |
|
3333 |
|
3334 // can we still find it? Should be still around! |
|
3335 found2 = ProcessExists(KRMDebugAppName2); |
|
3336 test (found2); |
|
3337 |
|
3338 } |
|
3339 |
|
3340 //---------------------------------------------------------------------------------------------- |
|
3341 //! @SYMTestCaseID KBase-T-RMDEBUG2-1388 |
|
3342 //! @SYMTestType |
|
3343 //! @SYMPREQ PREQ1426 |
|
3344 //! @SYMTestCaseDesc Tests the correct operation of the AddProcess and Remove Process |
|
3345 //! @SYMTestActions 1. Registers for AddProcess and Remove Process events |
|
3346 //! 2. Starts a test process z:\sys\bin\t_rmdebug_security0.exe |
|
3347 //! 3. Wait for the AddProcess event to be reported |
|
3348 //! 4. Kill the newly started test process |
|
3349 //! 5. Wait for the RemoveProcess event to be reported |
|
3350 //! 6. Tell the DSS it is no longer interested in AddProcess and RemoveProcess events |
|
3351 //! |
|
3352 //! @SYMTestExpectedResults KErrNone. |
|
3353 //! @SYMTestPriority High |
|
3354 //! @SYMTestStatus Implemented |
|
3355 //---------------------------------------------------------------------------------------------- |
|
3356 |
|
3357 void CRunModeAgent::TestAddRemoveProcessEvents() |
|
3358 { |
|
3359 test.Next(_L("TestAddRemoveProcessEvents\n")); |
|
3360 |
|
3361 // attach to a process (e.g. one of the simple security test programs) |
|
3362 // launch the security program |
|
3363 // wait for the add event |
|
3364 // continue the program. |
|
3365 // wait for the remove event |
|
3366 // detach process |
|
3367 |
|
3368 test(KErrNone == iServSession.AttachExecutable(KRMDebugSecurity0FileName, EFalse)); |
|
3369 |
|
3370 test(KErrNone == iServSession.SetEventAction(KRMDebugSecurity0FileName,EEventsAddProcess, EActionContinue)); |
|
3371 |
|
3372 test(KErrNone == iServSession.SetEventAction(KRMDebugSecurity0FileName,EEventsRemoveProcess, EActionContinue)); |
|
3373 |
|
3374 // Creator thread ID of the current thread (to be creator of test application) |
|
3375 TInt creatorThreadId = RThread().Id(); |
|
3376 |
|
3377 RProcess process; |
|
3378 TInt err = process.Create(KRMDebugSecurity0FileName, KNullDesC, EOwnerProcess); |
|
3379 test (err == KErrNone); |
|
3380 |
|
3381 // Rendezvous with process |
|
3382 TRequestStatus status; |
|
3383 process.Rendezvous(status); |
|
3384 |
|
3385 // Start the test program |
|
3386 process.Resume(); |
|
3387 User::WaitForRequest(status); |
|
3388 test(status==KErrNone); |
|
3389 |
|
3390 // Wait for the addprocess event |
|
3391 TEventInfo info; |
|
3392 TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo)); |
|
3393 |
|
3394 iServSession.GetEvent(KRMDebugSecurity0FileName,status,infoPtr); |
|
3395 |
|
3396 // Wait for notification of the addprocess hit event |
|
3397 User::WaitForRequest(status); |
|
3398 test(status==KErrNone); |
|
3399 |
|
3400 // Check this was the right kind of event |
|
3401 test(info.iEventType == EEventsAddProcess); |
|
3402 |
|
3403 const TInt uid3offset = 2; |
|
3404 |
|
3405 // Get UID3 for current process |
|
3406 TUint32 Uid3 = process.Type()[uid3offset].iUid; |
|
3407 |
|
3408 // Check correct UID3 is returned from the driver |
|
3409 test(info.iAddProcessInfo.iUid3 == Uid3); |
|
3410 |
|
3411 // Check correct creator ID for test application is returned from the driver |
|
3412 test(info.iAddProcessInfo.iCreatorThreadId == creatorThreadId); |
|
3413 |
|
3414 // Kill the process, as we don't need it anymore |
|
3415 process.Kill(KErrNone); |
|
3416 |
|
3417 // Wait for the remove process event |
|
3418 iServSession.GetEvent(KRMDebugSecurity0FileName,status,infoPtr); |
|
3419 |
|
3420 // Wait for notification of the remove process hit event |
|
3421 User::WaitForRequest(status); |
|
3422 test(status==KErrNone); |
|
3423 |
|
3424 // Check this was the right kind of event |
|
3425 test(info.iEventType == EEventsRemoveProcess); |
|
3426 |
|
3427 test(KErrNone == iServSession.SetEventAction(KRMDebugSecurity0FileName,EEventsRemoveProcess, EActionIgnore)); |
|
3428 |
|
3429 test(KErrNone == iServSession.SetEventAction(KRMDebugSecurity0FileName,EEventsAddProcess, EActionIgnore)); |
|
3430 |
|
3431 test(KErrNone == iServSession.DetachExecutable(KRMDebugSecurity0FileName)); |
|
3432 |
|
3433 } |
|
3434 |
|
3435 //---------------------------------------------------------------------------------------------- |
|
3436 //! @SYMTestCaseID KBase-T-RMDEBUG2-0736 |
|
3437 //! @SYMTestType |
|
3438 //! @SYMPREQ PREQ1426 |
|
3439 //! @SYMTestCaseDesc Checks that process break points can be set, and that they can co-exist alongside thread breakpoints |
|
3440 //! @SYMTestActions Checks that process break points can be set, and that they can co-exist alongside thread breakpoints |
|
3441 //! |
|
3442 //! @SYMTestExpectedResults KErrNone. |
|
3443 //! @SYMTestPriority High |
|
3444 //! @SYMTestStatus Implemented |
|
3445 //---------------------------------------------------------------------------------------------- |
|
3446 void CRunModeAgent::TestProcessBreakPoints(void) |
|
3447 { |
|
3448 test.Next(_L("TestProcessBreakPoints\n")); |
|
3449 |
|
3450 // check that process breakpoints are supported |
|
3451 TTag tag = GetTag(ETagHeaderIdBreakpoints, EBreakpointProcess); |
|
3452 test(tag.iValue); |
|
3453 |
|
3454 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
3455 test(KErrNone == iServSession.SuspendThread(iThreadID)); |
|
3456 |
|
3457 // Try to set the breakpoint |
|
3458 TBreakId breakId; |
|
3459 TUint32 address = (TUint32)(&RMDebug_BranchTst1); |
|
3460 RProcess process; |
|
3461 TProcessId processId = process.Id(); |
|
3462 process.Close(); |
|
3463 |
|
3464 test(KErrNone == iServSession.SetProcessBreak(breakId, processId, address, EArmMode)); |
|
3465 test(KErrAlreadyExists == iServSession.SetBreak(breakId, iThreadID, address, EArmMode)); |
|
3466 test(KErrAlreadyExists == iServSession.SetBreak(breakId, iThreadID, address, EThumbMode)); |
|
3467 test(KErrAlreadyExists == iServSession.SetProcessBreak(breakId, processId, address, EArmMode)); |
|
3468 test(KErrAlreadyExists == iServSession.SetProcessBreak(breakId, processId, address, EThumbMode)); |
|
3469 test(KErrNone == iServSession.ClearBreak(breakId)); |
|
3470 |
|
3471 test(KErrNone == iServSession.SetBreak(breakId, iThreadID, address, EArmMode)); |
|
3472 test(KErrAlreadyExists == iServSession.SetProcessBreak(breakId, processId, address, EArmMode)); |
|
3473 test(KErrAlreadyExists == iServSession.SetProcessBreak(breakId, processId, address, EThumbMode)); |
|
3474 test(KErrNone == iServSession.ClearBreak(breakId)); |
|
3475 |
|
3476 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
3477 |
|
3478 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
3479 } |
|
3480 |
|
3481 //---------------------------------------------------------------------------------------------- |
|
3482 //! @SYMTestCaseID KBase-T-RMDEBUG2-1309 |
|
3483 //! @SYMTestType |
|
3484 //! @SYMPREQ PREQ1426 |
|
3485 //! @SYMTestCaseDesc Checks that in the case of multiple low priority events (user traces in this case) we can still receive higher |
|
3486 //! priority events should the buffer reach a critical level |
|
3487 //! @SYMTestActions Run to first breakpoint in our test code. Then multiple trace events are issued. We should still be able to hit |
|
3488 //! the second breakpoint |
|
3489 //! |
|
3490 //! @SYMTestExpectedResults KErrNone. |
|
3491 //! @SYMTestPriority High |
|
3492 //! @SYMTestStatus Implemented |
|
3493 //---------------------------------------------------------------------------------------------- |
|
3494 |
|
3495 void CRunModeAgent::TestMultipleTraceEvents(void) |
|
3496 { |
|
3497 test.Next(_L("TestMultipleTraceEvents\n")); |
|
3498 |
|
3499 //attach to target debug process |
|
3500 test(KErrNone == iServSession.AttachExecutable(iFileName, EFalse)); |
|
3501 |
|
3502 //and suspend the thread |
|
3503 test(KErrNone == iServSession.SuspendThread(iThreadID)); |
|
3504 |
|
3505 //register interest in BP's & trace events and trace ignored events |
|
3506 test(KErrNone == iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionSuspend)); |
|
3507 test(KErrNone == iServSession.SetEventAction(iFileName,EEventsUserTrace, EActionContinue)); |
|
3508 test(KErrNone == iServSession.SetEventAction(iFileName,EEventsUserTracesLost, EActionContinue)); |
|
3509 |
|
3510 // Try to set the breakpoints |
|
3511 TBreakId armBreakId; |
|
3512 TBreakId armBreakId2; |
|
3513 TUint32 address = (TUint32)(&RMDebug_BranchTst1); |
|
3514 TUint32 address2 = (TUint32)(&RMDebug_StepTest_Non_PC_Modifying); |
|
3515 |
|
3516 test(KErrNone == iServSession.SetBreak(armBreakId,iThreadID,address,EArmMode)); |
|
3517 test(KErrNone == iServSession.SetBreak(armBreakId2,iThreadID,address2,EArmMode)); |
|
3518 |
|
3519 //set the target thread to execute the trace test function |
|
3520 test(KErrNone == SwitchTestFunction(EMultipleTraceCalls)); |
|
3521 |
|
3522 // Continue the thread |
|
3523 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
3524 |
|
3525 // wait for the breakpoint to be hit |
|
3526 TEventInfo info; |
|
3527 static TRequestStatus status; |
|
3528 |
|
3529 TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo)); |
|
3530 iServSession.GetEvent(iFileName,status,infoPtr); |
|
3531 |
|
3532 // Wait for notification of the 1st breakpoint hit event |
|
3533 User::WaitForRequest(status); |
|
3534 test(status==KErrNone); |
|
3535 |
|
3536 // info should now be filled with the details |
|
3537 test(info.iEventType == EEventsBreakPoint); |
|
3538 test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address); |
|
3539 test(info.iProcessIdValid); |
|
3540 test(info.iThreadIdValid); |
|
3541 |
|
3542 // Continue the thread |
|
3543 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
3544 |
|
3545 //Now we try to hit the second breakpoint. This will occur after a number of trace calls. If we hit this breakpoint it |
|
3546 //means many trace calls are not preventing us hitting breakpoints. |
|
3547 iServSession.GetEvent(iFileName,status,infoPtr); |
|
3548 |
|
3549 // Wait for notification of the 2nd breakpoint hit event |
|
3550 User::WaitForRequest(status); |
|
3551 test(status==KErrNone); |
|
3552 |
|
3553 TBool receivedTracesLost = EFalse; |
|
3554 |
|
3555 while(info.iEventType == EEventsUserTrace || info.iEventType == EEventsUserTracesLost) |
|
3556 { |
|
3557 //ensure we get told traces are being thrown away - we generate enough to flood the buffer |
|
3558 if(info.iEventType == EEventsUserTracesLost) |
|
3559 { |
|
3560 receivedTracesLost = ETrue; |
|
3561 |
|
3562 // Now stop the target thread from generating trace events |
|
3563 test(KErrNone == SwitchTestFunction(EDoNothing)); |
|
3564 } |
|
3565 else |
|
3566 { |
|
3567 // Its EEventsUserTrace, so delay us in getting the next event so that it will be more |
|
3568 // likely to get a EEventsUserTracesLost next time. |
|
3569 // This is important on SMP since the platform can process lots of events, and thus |
|
3570 // withouth the delay it is difficult for this test to reproduce the abnormal situation of |
|
3571 // lost trace packets |
|
3572 User::After(200000); |
|
3573 } |
|
3574 |
|
3575 iServSession.GetEvent(iFileName,status,infoPtr); |
|
3576 |
|
3577 // Wait for notification of the 2nd breakpoint hit event |
|
3578 User::WaitForRequest(status); |
|
3579 test(status==KErrNone); |
|
3580 } |
|
3581 |
|
3582 //make sure we got told traces were lost |
|
3583 test(receivedTracesLost != EFalse); |
|
3584 |
|
3585 // info should now be filled with the details of our breakpoint. |
|
3586 test(info.iEventType == EEventsBreakPoint); |
|
3587 test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address2); |
|
3588 test(info.iProcessIdValid); |
|
3589 test(info.iThreadIdValid); |
|
3590 |
|
3591 //dont care for breakpoints or trace events no more |
|
3592 test(KErrNone == iServSession.SetEventAction(iFileName,EEventsBreakPoint, EActionIgnore)); |
|
3593 test(KErrNone == iServSession.SetEventAction(iFileName,EEventsUserTrace, EActionIgnore)); |
|
3594 test(KErrNone == iServSession.SetEventAction(iFileName,EEventsUserTracesLost, EActionIgnore)); |
|
3595 |
|
3596 //clear the breaks we set |
|
3597 test(KErrNone == iServSession.ClearBreak(armBreakId)); |
|
3598 test(KErrNone == iServSession.ClearBreak(armBreakId2)); |
|
3599 |
|
3600 // Continue the thread |
|
3601 test(KErrNone == iServSession.ResumeThread(iThreadID)); |
|
3602 |
|
3603 //attach to target debug process |
|
3604 test(KErrNone == iServSession.DetachExecutable(iFileName)); |
|
3605 |
|
3606 } |
|
3607 |
|
3608 //---------------------------------------------------------------------------------------------- |
|
3609 //! @SYMTestCaseID KBase-T-RMDEBUG2-2441 |
|
3610 //! @SYMTestType |
|
3611 //! @SYMPREQ PREQ1426 |
|
3612 //! @SYMTestCaseDesc Test clearing of a process breakpoint once the process has been killed. |
|
3613 //! @SYMTestActions Creates a new process then tries to set a process breakpoint and then kills the process which should clear the previously set breakpoint. Then repeat the step once again. |
|
3614 //! @SYMTestExpectedResults KErrNone |
|
3615 //! @SYMTestPriority High |
|
3616 //! @SYMTestStatus Implemented |
|
3617 //---------------------------------------------------------------------------------------------- |
|
3618 |
|
3619 void CRunModeAgent::TestProcessKillBreakpoint(void) |
|
3620 { |
|
3621 test.Next(_L("TestProcessKillBreakpoint\n")); |
|
3622 //SID retrieved, used in Define/Attach of the property |
|
3623 iMySid.iUid = RProcess().SecureId(); |
|
3624 |
|
3625 static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); |
|
3626 |
|
3627 //define a property to pass on the address from the other process we would try to debug |
|
3628 test ( KErrNone == RProperty::Define(iMySid, EMyPropertyInteger, RProperty::EInt, KAllowAllPolicy, KAllowAllPolicy)); |
|
3629 //define a global semaphore to synchronise with debuggable process publishing the property |
|
3630 test ( KErrNone == iAddressGlobSem.CreateGlobal(_L("RMDebugGlobSem"), 0) ); |
|
3631 |
|
3632 DoTestProcessKillBreakpoint(); |
|
3633 // called once again |
|
3634 // to check if we can set the breakpoint once again after the process gets killed |
|
3635 DoTestProcessKillBreakpoint(); |
|
3636 |
|
3637 //delete the property |
|
3638 test ( KErrNone == RProperty::Delete(iMySid, EMyPropertyInteger)); |
|
3639 //close the semaphore |
|
3640 iAddressGlobSem.Close(); |
|
3641 } |
|
3642 |
|
3643 void CRunModeAgent::DoTestProcessKillBreakpoint() |
|
3644 { |
|
3645 test.Printf(_L("\nDoTestProcessKillBreakpoint\n")); |
|
3646 |
|
3647 TInt err = KErrNone; |
|
3648 |
|
3649 // check that killing a process is supported |
|
3650 TTag tag = GetTag(ETagHeaderIdKillObjects, EFunctionalityKillProcess); |
|
3651 test(tag.iValue); |
|
3652 // check that killing a thread is not supported |
|
3653 tag = GetTag(ETagHeaderIdKillObjects, EFunctionalityKillThread); |
|
3654 test(!tag.iValue); |
|
3655 |
|
3656 // attach first! |
|
3657 test ( KErrNone == iServSession.AttachExecutable(KRMDebugTestApplication, EFalse/* Active */)); |
|
3658 |
|
3659 // first launch a debuggable process |
|
3660 RProcess processDebug; |
|
3661 test ( KErrNone == LaunchProcess(processDebug, KRMDebugTestApplication(),ESpinForeverWithBreakPoint, 0, 0)); |
|
3662 |
|
3663 // try to find the process in the list |
|
3664 _LIT(KRMDebugAppName, "t_rmdebug_app"); |
|
3665 TBool found = ProcessExists(KRMDebugAppName); |
|
3666 test (found); |
|
3667 |
|
3668 //search for the main thread created |
|
3669 _LIT(KThreadWildCard, "t_rmdebug_app*"); |
|
3670 TProcessId processDebugId = processDebug.Id(); |
|
3671 TThreadId threadDebugId; |
|
3672 |
|
3673 TFindThread find(KThreadWildCard); |
|
3674 TFullName name; |
|
3675 found = EFalse; |
|
3676 while(find.Next(name)==KErrNone && !found) |
|
3677 { |
|
3678 RThread thread; |
|
3679 err = thread.Open(find); |
|
3680 if (err == KErrNone) |
|
3681 { |
|
3682 RProcess process; |
|
3683 thread.Process(process); |
|
3684 if (((TUint32)process.Id() == processDebugId)) |
|
3685 { |
|
3686 TFullName fullname = thread.FullName(); |
|
3687 test.Printf(_L("Match Found Name %lS Process ID%ld Thread Id %ld"), &fullname, process.Id().Id(), thread.Id().Id()); |
|
3688 found = ETrue; |
|
3689 threadDebugId = thread.Id(); |
|
3690 } |
|
3691 process.Close(); |
|
3692 } |
|
3693 thread.Close(); |
|
3694 } |
|
3695 |
|
3696 test (found); //check if we actually found the thread we want to debug |
|
3697 |
|
3698 //get the value(property) for the breakpoint address for the process to debug |
|
3699 TInt address; |
|
3700 RProperty integerProperty; |
|
3701 test ( KErrNone == integerProperty.Attach(iMySid, EMyPropertyInteger, EOwnerThread)); |
|
3702 |
|
3703 //waiting on semaphore to be sure that the property is set |
|
3704 iAddressGlobSem.Wait(); |
|
3705 |
|
3706 test ( KErrNone == integerProperty.Get(address)); |
|
3707 integerProperty.Close(); |
|
3708 |
|
3709 test.Printf(_L("Address retrieved to set breakpoint 0x%8x"), address); |
|
3710 |
|
3711 //suspend the thread before we set a breakpoint |
|
3712 test ( KErrNone == iServSession.SuspendThread(threadDebugId)); |
|
3713 |
|
3714 //set a process breakpoint |
|
3715 TBreakId breakId; |
|
3716 test(KErrNone == iServSession.SetProcessBreak(breakId, processDebugId, address, EArmMode)); |
|
3717 |
|
3718 test(KErrNone ==iServSession.SetEventAction(KRMDebugTestApplication,EEventsProcessBreakPoint, EActionContinue)); |
|
3719 |
|
3720 //resume the thread now |
|
3721 test(KErrNone == iServSession.ResumeThread(threadDebugId)); |
|
3722 |
|
3723 // wait for the breakpoint to be hit |
|
3724 static TRequestStatus status; |
|
3725 TEventInfo info; |
|
3726 TPtr8 infoPtr((TUint8*)&info,0,sizeof(TEventInfo)); |
|
3727 iServSession.GetEvent(KRMDebugTestApplication,status,infoPtr); |
|
3728 // Wait for notification of the breakpoint hit event |
|
3729 User::WaitForRequest(status); |
|
3730 test(status==KErrNone); |
|
3731 |
|
3732 // info should now be filled with the details |
|
3733 test(info.iEventType == EEventsProcessBreakPoint); |
|
3734 test(info.iThreadBreakPointInfo.iRmdArmExcInfo.iR15 == address); |
|
3735 test(info.iProcessIdValid); |
|
3736 test(info.iThreadIdValid); |
|
3737 |
|
3738 // Not interested in breakpoint events any more |
|
3739 test(KErrNone == iServSession.SetEventAction(KRMDebugTestApplication, EEventsProcessBreakPoint, EActionIgnore)); |
|
3740 |
|
3741 // program now running, so try to kill it which should clear all the breakpoints |
|
3742 test(KErrNone == iServSession.KillProcess(processDebugId, 0 /* kill reason */ )); |
|
3743 |
|
3744 processDebug.Close(); |
|
3745 User::After(2000000); // should die within two seconds. |
|
3746 |
|
3747 // can we still find it? Should be gone |
|
3748 found = ProcessExists(KRMDebugAppName); |
|
3749 test (!found); |
|
3750 |
|
3751 // release the program again |
|
3752 test(KErrNone == iServSession.DetachExecutable(KRMDebugTestApplication)); |
|
3753 |
|
3754 } |
|
3755 |
|
3756 void CRunModeAgent::HelpTestSecurityAttachDetachExecutable(const TDesC& aProcessName, TBool aExpectSuccess) |
|
3757 { |
|
3758 RProcess process; |
|
3759 TInt err = process.Create(aProcessName, KNullDesC, EOwnerProcess); |
|
3760 test (err == KErrNone); |
|
3761 |
|
3762 // rendezvous with process |
|
3763 TRequestStatus status; |
|
3764 process.Rendezvous(status); |
|
3765 |
|
3766 // start the test program |
|
3767 process.Resume(); |
|
3768 User::WaitForRequest(status); |
|
3769 test(status==KErrNone); |
|
3770 |
|
3771 // attach to the program (passively) |
|
3772 err = iServSession.AttachExecutable(aProcessName, EFalse); |
|
3773 |
|
3774 if( gUseDelay ) User::After(500000); |
|
3775 |
|
3776 // Do we expect to successfully attach |
|
3777 if (aExpectSuccess) |
|
3778 { |
|
3779 // Yes |
|
3780 test(KErrNone == err); |
|
3781 |
|
3782 // Now detach again |
|
3783 test(KErrNone == iServSession.DetachExecutable(aProcessName)); |
|
3784 if( gUseDelay ) User::After(500000); |
|
3785 } |
|
3786 else |
|
3787 { |
|
3788 // No |
|
3789 test(KErrPermissionDenied == err); |
|
3790 |
|
3791 // Just to be sure, try active attachment |
|
3792 test(KErrPermissionDenied == iServSession.AttachExecutable(aProcessName, ETrue)); |
|
3793 if( gUseDelay ) User::After(500000); |
|
3794 } |
|
3795 |
|
3796 // Kill the process, as we don't need it anymore |
|
3797 process.Kill(KErrNone); |
|
3798 if( gUseDelay ) User::After(500000); |
|
3799 } |
|
3800 |
|
3801 void CRunModeAgent::ReportPerformance(void) |
|
3802 // |
|
3803 // Reports performance metrics from all the tests |
|
3804 // |
|
3805 { |
|
3806 test.Printf(_L("\nPerformance\n")); |
|
3807 test.Printf(_L("========================\n")); |
|
3808 |
|
3809 // Memory |
|
3810 test.Printf(_L("Memory read: %d KBytes/sec\n"),iMemoryReadKbytesPerSecond); |
|
3811 test.Printf(_L("Memory write: %d KBytes/sec\n"),iMemoryWriteKbytesPerSecond); |
|
3812 |
|
3813 // Registers |
|
3814 // to do |
|
3815 |
|
3816 // events |
|
3817 // to do |
|
3818 |
|
3819 // Breakpoints |
|
3820 test.Printf(_L("Breakpoint set/clear: %d/sec\n"),iBreakpointsPerSecond); |
|
3821 test.Printf(_L("Maximum number of breakpoints: %d\n"),iMaxBreakpoints); |
|
3822 |
|
3823 // Stepping |
|
3824 test.Printf(_L("Stepping speed: %d/sec\n"),iStepsPerSecond); |
|
3825 |
|
3826 // Runtime |
|
3827 TInt ticks = HelpGetTestTicks(); |
|
3828 test (ticks != 0); |
|
3829 |
|
3830 TInt nkTicksPerSecond = HelpTicksPerSecond(); |
|
3831 test (nkTicksPerSecond != 0); |
|
3832 |
|
3833 test.Printf(_L("Total test runtime: %d seconds\n"),ticks/nkTicksPerSecond); |
|
3834 |
|
3835 // Final sizes of executables/rom/ram etc |
|
3836 // to do |
|
3837 |
|
3838 test.Printf(_L("\n")); |
|
3839 } |
|
3840 |
|
3841 /** |
|
3842 * Helper code for the stepping tests. Sets a breakpoint in a running thread. |
|
3843 * It suspends the thread, sets the breakpoint, and resumes the thread. |
|
3844 * |
|
3845 * @param aBreakId - Reference to a TBreakId which will be set when the breakpoint is set |
|
3846 * @param aThreadId - The thread id for which we should set the breakpoint. |
|
3847 * @param aBreakAddress - The address to set the breakpoint |
|
3848 * @param aMode - The architecture of the breakpoint to be set (ARM/Thumb/Thumb2EE) |
|
3849 * @return KErrNone if successful. One of the other system wide error codes otherwise. |
|
3850 */ |
|
3851 TInt CRunModeAgent::HelpTestStepSetBreak(TBreakId& aBreakId, TThreadId aThreadId, const TUint32 aBreakAddress, TArchitectureMode aMode, TBool aThreadSpecific, TProcessId aProcessId) |
|
3852 { |
|
3853 TInt err = KErrNone; |
|
3854 |
|
3855 // Suspend the thread |
|
3856 err = iServSession.SuspendThread(aThreadId); |
|
3857 if (err != KErrNone) |
|
3858 { |
|
3859 test.Printf(_L("HelpTestStepSetBreak - Failed to suspend thread\n")); |
|
3860 return err; |
|
3861 } |
|
3862 |
|
3863 // Set the breakpoint |
|
3864 err = aThreadSpecific |
|
3865 ? iServSession.SetBreak(aBreakId,aThreadId,aBreakAddress,aMode) |
|
3866 : iServSession.SetProcessBreak(aBreakId, aProcessId, aBreakAddress, aMode); |
|
3867 if (err != KErrNone) |
|
3868 { |
|
3869 test.Printf(_L("HelpTestStepSetBreak - Failed to set breakpoint\n")); |
|
3870 return err; |
|
3871 } |
|
3872 |
|
3873 // Continue the thread |
|
3874 err = iServSession.ResumeThread(aThreadId); |
|
3875 if (err != KErrNone) |
|
3876 { |
|
3877 test.Printf(_L("HelpTestStepSetBreak - Failed to resume thread\n")); |
|
3878 return err; |
|
3879 } |
|
3880 |
|
3881 return KErrNone; |
|
3882 } |
|
3883 |
|
3884 /** |
|
3885 * Helper code for the stepping tests. Clears a breakpoint in a running thread. |
|
3886 * It suspends the thread, clears the breakpoint, and resumes the thread. |
|
3887 * |
|
3888 * @param aBreakId - Reference to a TBreakId which will be set when the breakpoint is set |
|
3889 * @return KErrNone if successful. One of the other system wide error codes otherwise. |
|
3890 */ |
|
3891 TInt CRunModeAgent::HelpTestStepClearBreak(TBreakId aBreakId, const TThreadId aThreadId, TBool aThreadSpecific) |
|
3892 { |
|
3893 TInt err = KErrNone; |
|
3894 |
|
3895 // Find out what thread id we need to suspend |
|
3896 TThreadId threadId; |
|
3897 TProcessId processId; |
|
3898 TUint32 address; |
|
3899 TArchitectureMode mode; |
|
3900 |
|
3901 err = aThreadSpecific |
|
3902 ? iServSession.BreakInfo(aBreakId, threadId, address, mode) |
|
3903 : iServSession.ProcessBreakInfo(aBreakId, processId, address, mode); |
|
3904 if (err != KErrNone ) |
|
3905 { |
|
3906 test.Printf(_L("HelpTestStepClearBreak - failed to obtain information for breakpoint\n")); |
|
3907 return err; |
|
3908 } |
|
3909 if(aThreadSpecific && aThreadId != threadId) |
|
3910 { |
|
3911 test.Printf(_L("HelpTestStepClearBreak - mismatched thread Ids\n")); |
|
3912 return KErrGeneral; |
|
3913 } |
|
3914 |
|
3915 // Suspend the thread |
|
3916 err = iServSession.SuspendThread(aThreadId); |
|
3917 if (!(err == KErrNone || err == KErrAlreadyExists)) |
|
3918 { |
|
3919 test.Printf(_L("HelpTestStepClearBreak - failed to suspend thread\n")); |
|
3920 return err; |
|
3921 } |
|
3922 |
|
3923 // Clear the breakpoint |
|
3924 err = iServSession.ClearBreak(aBreakId); |
|
3925 if (err != KErrNone) |
|
3926 { |
|
3927 test.Printf(_L("HelpTestStepClearBreak - failed to clear breakpoint\n")); |
|
3928 return err; |
|
3929 } |
|
3930 |
|
3931 // Continue the thread |
|
3932 err = iServSession.ResumeThread(aThreadId); |
|
3933 if (!(err == KErrNone || err == KErrNotFound)) |
|
3934 { |
|
3935 test.Printf(_L("HelpTestStepClearBreak - failed to resume thread\n")); |
|
3936 return err; |
|
3937 } |
|
3938 |
|
3939 return KErrNone; |
|
3940 } |
|
3941 |
|
3942 /** |
|
3943 * Helper code for the stepping tests. Waits for a previously set breakpoint to be hit. |
|
3944 * |
|
3945 * @param aProcessName - The name of the process in which the breakpoint is set. E.g. z:\sys\bin\app.exe |
|
3946 * @param aEventInfo - The event information block which is filled in when the breakpoint is hit. |
|
3947 * @return KErrNone if successful. One of the other system wide error codes otherwise. |
|
3948 */ |
|
3949 TInt CRunModeAgent::HelpTestStepWaitForBreak(const TDesC& aProcessName, TEventInfo& aEventInfo) |
|
3950 { |
|
3951 static TRequestStatus status; |
|
3952 |
|
3953 TPtr8 infoPtr((TUint8*)&aEventInfo,0,sizeof(TEventInfo)); |
|
3954 |
|
3955 iServSession.GetEvent(aProcessName,status,infoPtr); |
|
3956 |
|
3957 // Wait for notification of the breakpoint hit event |
|
3958 User::WaitForRequest(status); |
|
3959 if (status == KErrNone) |
|
3960 { |
|
3961 return KErrNone; |
|
3962 } |
|
3963 else |
|
3964 { |
|
3965 return KErrGeneral; |
|
3966 } |
|
3967 } |
|
3968 |
|
3969 /** |
|
3970 * Helper code for the stepping tests. Reads the current target PC for a given thread. |
|
3971 * |
|
3972 * @param aThreadId - Thread id for which to read the current target PC. |
|
3973 * @param aPc - Reference to a TUint32 which will be set to the current target PC. |
|
3974 * @return KErrNone if successful. One of the other system wide error codes otherwise. |
|
3975 */ |
|
3976 TInt CRunModeAgent::HelpTestStepReadPC(TThreadId aThreadId, TUint32& aPC) |
|
3977 { |
|
3978 TInt err = KErrNone; |
|
3979 |
|
3980 //create buffer containing PC register ID |
|
3981 RBuf8 pcId; |
|
3982 err = pcId.Create(sizeof(TRegisterInfo)); |
|
3983 if (err != KErrNone) |
|
3984 { |
|
3985 return err; |
|
3986 } |
|
3987 |
|
3988 TRegisterInfo reg1 = (TRegisterInfo)0x00000f00; |
|
3989 pcId.Append(reinterpret_cast<const TUint8*>(®1), sizeof(TRegisterInfo)); |
|
3990 |
|
3991 //create buffer containing desired PC value |
|
3992 TPtr8 pcValue((TUint8*)&aPC,4,4); |
|
3993 |
|
3994 //create buffer for PC flag value |
|
3995 RBuf8 pcFlag; |
|
3996 err = pcFlag.Create(sizeof(TUint8)); |
|
3997 |
|
3998 //read the new PC value |
|
3999 err = iServSession.ReadRegisters(aThreadId, pcId, pcValue, pcFlag); |
|
4000 if (err != KErrNone) |
|
4001 { |
|
4002 //delete temporary buffers |
|
4003 pcId.Close(); |
|
4004 pcFlag.Close(); |
|
4005 return err; |
|
4006 } |
|
4007 |
|
4008 //get the flag and check the PC value was read ok |
|
4009 TRegisterFlag flag = ENotSupported; |
|
4010 err = GetFlag(pcFlag, 0, flag); |
|
4011 if (err != KErrNone) |
|
4012 { |
|
4013 //delete temporary buffers |
|
4014 pcId.Close(); |
|
4015 pcFlag.Close(); |
|
4016 return err; |
|
4017 } |
|
4018 |
|
4019 if (flag == EValid) |
|
4020 { |
|
4021 //delete temporary buffers |
|
4022 pcId.Close(); |
|
4023 pcFlag.Close(); |
|
4024 return KErrNone; |
|
4025 } |
|
4026 else |
|
4027 { |
|
4028 //delete temporary buffers |
|
4029 pcId.Close(); |
|
4030 pcFlag.Close(); |
|
4031 return err; |
|
4032 } |
|
4033 } |
|
4034 |
|
4035 /** |
|
4036 * Helper code for the stepping tests. Single steps a given thread from aStartAddress to aEndAddress. Note |
|
4037 * that it reaches aStartAddress by setting a breakpoint at that address and waiting until it is hit. |
|
4038 * |
|
4039 * @param aThreadId - Thread id for which to read the current target PC. |
|
4040 * @param aStartAddress - The target address at which stepping will start. |
|
4041 * @param aEndAddress - The target address at which stepping will end. |
|
4042 * @param aMode - The architecture of the breakpoint which must be set at the start address (ARM/Thumb/Thumb2EE). |
|
4043 * @return KErrNone if successful. One of the other system wide error codes otherwise. |
|
4044 */ |
|
4045 TInt CRunModeAgent::HelpTestStep(TThreadId aThreadId, TUint32 aStartAddress, TUint32 aEndAddress, TArchitectureMode aMode, TUint aNumSteps, TBool aThreadSpecific, TProcessId aProcessId) |
|
4046 { |
|
4047 TInt err = KErrNone; |
|
4048 |
|
4049 // Ensure that the supplied addresses are word/half-word aligned as appropriate. |
|
4050 if (aMode == EArmMode) |
|
4051 { |
|
4052 // ARM breakpoints must be word-aligned (2 lsb must be zero) |
|
4053 aStartAddress &= 0xFFFFFFFC; |
|
4054 aEndAddress &= 0xFFFFFFFC; |
|
4055 } |
|
4056 else if (aMode == EThumbMode) |
|
4057 { |
|
4058 // Thumb breakpoints must be half-word aligned (lsb must be zero) |
|
4059 aStartAddress &= 0xFFFFFFFE; |
|
4060 aEndAddress &= 0xFFFFFFFE; |
|
4061 } |
|
4062 else if (aMode == EThumb2EEMode) |
|
4063 { |
|
4064 // Thumb2EE breakpoints are not currently supported |
|
4065 return KErrNotSupported; |
|
4066 } |
|
4067 |
|
4068 // Set breakpoint at the start address |
|
4069 TBreakId tempBreakId; |
|
4070 TEventInfo info; |
|
4071 |
|
4072 err = HelpTestStepSetBreak(tempBreakId,aThreadId,aStartAddress,aMode,aThreadSpecific,aProcessId); |
|
4073 if (err != KErrNone) |
|
4074 { |
|
4075 test.Printf(_L("HelpTestStep - Failed to set breakpoint at aStartAddress 0x%08x\n"),aStartAddress); |
|
4076 return err; |
|
4077 } |
|
4078 |
|
4079 // wait for the breakpoint to be hit |
|
4080 err = HelpTestStepWaitForBreak(iFileName,info); |
|
4081 if (err != KErrNone) |
|
4082 { |
|
4083 test.Printf(_L("HelpTestStep - Failed to hit the breakpoint at aStartAddress 0x%08x\n"),aStartAddress); |
|
4084 return err; |
|
4085 } |
|
4086 |
|
4087 // Check the PC == aStartAddress |
|
4088 TUint32 pc = 0; |
|
4089 err = HelpTestStepReadPC(aThreadId,pc); |
|
4090 if (err != KErrNone) |
|
4091 { |
|
4092 test.Printf(_L("HelpTestStep - Failed to read the PC after hitting breakpoint at aStartAddress 0x%08x\n"),aStartAddress); |
|
4093 return err; |
|
4094 } |
|
4095 |
|
4096 if (pc != aStartAddress) |
|
4097 { |
|
4098 test.Printf(_L("HelpTestStep - Incorrect PC value after hitting breakpoint (expected 0x%08x actual 0x%08x)\n"),aStartAddress,pc); |
|
4099 return KErrGeneral; |
|
4100 } |
|
4101 |
|
4102 err = iServSession.Step(aThreadId,aNumSteps); |
|
4103 if (err != KErrNone) |
|
4104 { |
|
4105 test.Printf(_L("HelpTestStep - Failed to do step from 0x%08x to 0x%08x\n"),aStartAddress,aEndAddress,aNumSteps); |
|
4106 return err; |
|
4107 } |
|
4108 |
|
4109 // only one 'completed step' event in the buffer. |
|
4110 err = HelpTestStepWaitForBreak(iFileName,info); |
|
4111 if (err != KErrNone) |
|
4112 { |
|
4113 test.Printf(_L("HelpTestStep - Could not read breakpoint event info after stepping")); |
|
4114 return err; |
|
4115 } |
|
4116 // end |
|
4117 |
|
4118 // Check PC == aEndAddress |
|
4119 err = HelpTestStepReadPC(aThreadId,pc); |
|
4120 if (err != KErrNone) |
|
4121 { |
|
4122 test.Printf(_L("HelpTestStep - failed read the PC after stepping\n")); |
|
4123 return err; |
|
4124 } |
|
4125 if (pc != aEndAddress) |
|
4126 { |
|
4127 test.Printf(_L("HelpTestStep - Incorrect PC value after stepping (expected 0x%08x actual 0x%08x)\n"),aEndAddress,pc); |
|
4128 return KErrGeneral; |
|
4129 } |
|
4130 |
|
4131 // Clear the breakpoint |
|
4132 err = HelpTestStepClearBreak(tempBreakId, aThreadId, aThreadSpecific); |
|
4133 if (err != KErrNone) |
|
4134 { |
|
4135 test.Printf(_L("HelpTestStep - failed to clear temporary breakpoint\n")); |
|
4136 return err; |
|
4137 } |
|
4138 |
|
4139 return KErrNone; |
|
4140 } |
|
4141 |
|
4142 /** |
|
4143 * Helper code for the stepping tests. Returns the number of nanokernel ticks in one second. |
|
4144 * |
|
4145 * @return Number of nanokernel ticks. 0 if unsuccesful. |
|
4146 */ |
|
4147 TInt CRunModeAgent::HelpTicksPerSecond(void) |
|
4148 { |
|
4149 TInt nanokernel_tick_period; |
|
4150 HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period); |
|
4151 |
|
4152 ASSERT(nanokernel_tick_period != 0); |
|
4153 |
|
4154 static const TInt KOneMillion = 1000000; |
|
4155 |
|
4156 return KOneMillion/nanokernel_tick_period; |
|
4157 } |
|
4158 |
|
4159 /** |
|
4160 Given aTestNumber runs the appropriate test inside heap markers |
|
4161 |
|
4162 @param aTestNumber test to run, corresponds to an entry in iTestArray |
|
4163 |
|
4164 @panic Panic if aTestNumber is not in valid range |
|
4165 */ |
|
4166 void CRunModeAgent::RunTest(TInt aTestNumber) |
|
4167 { |
|
4168 if( (aTestNumber<0) || (aTestNumber>=KMaxTests) ) |
|
4169 { |
|
4170 User::Panic(_L("Test number out of range"), aTestNumber); |
|
4171 } |
|
4172 __UHEAP_MARK; |
|
4173 (this->*(iTestArray[aTestNumber].iFunctionPtr))(); |
|
4174 __UHEAP_MARKEND; |
|
4175 } |
|
4176 |
|
4177 void CRunModeAgent::PrintVersion() |
|
4178 { |
|
4179 test.Printf(_L("\nt_rmdebug2.exe\nVersion: %S\n"), &(testVersion.Name())); |
|
4180 test.Printf(_L("Press any key...\n")); |
|
4181 test.Getch(); |
|
4182 } |
|
4183 |
|
4184 void CRunModeAgent::PrintUsage() |
|
4185 { |
|
4186 test.Printf(_L("Invoke with arguments:\n")); |
|
4187 test.Printf(_L("-r: run specified tests in reverse order\n")); |
|
4188 test.Printf(_L("-h: display usage information\n")); |
|
4189 test.Printf(_L("-v: display version\n")); |
|
4190 test.Printf(_L("-d: use delays\n")); |
|
4191 test.Printf(_L("<number>: test number to run, can specify more than one from the following list:\n")); |
|
4192 test.Printf(_L("Press any key for list...\n")); |
|
4193 test.Getch(); |
|
4194 // if there are too many of these they won't fit on the screen! Stick another Getch() in if there get too many |
|
4195 for(TInt i=0; i<KMaxTests; i++) |
|
4196 { |
|
4197 test.Printf(_L("%2d: %S\n"), i, &(iTestArray[i].iFunctionName)); |
|
4198 } |
|
4199 test.Printf(_L("Press any key...\n")); |
|
4200 test.Getch(); |
|
4201 } |
|
4202 |
|
4203 /** |
|
4204 Parse the command line, see CRunModeAgent::PrintUsage for syntax |
|
4205 */ |
|
4206 void CRunModeAgent::ParseCommandLineL(TUint32& aMode, RArray<TInt>& aTests) |
|
4207 { |
|
4208 // get the length of the command line arguments |
|
4209 TInt argc = User::CommandLineLength(); |
|
4210 |
|
4211 // allocate a buffer for the command line arguments and extract the data to it |
|
4212 HBufC* commandLine = HBufC::NewLC(argc); |
|
4213 TPtr commandLineBuffer = commandLine->Des(); |
|
4214 User::CommandLine(commandLineBuffer); |
|
4215 |
|
4216 // reset mode |
|
4217 aMode = (TTestMode)0; |
|
4218 |
|
4219 // create a lexer and read through the command line |
|
4220 TLex lex(*commandLine); |
|
4221 while (!lex.Eos()) |
|
4222 { |
|
4223 // expecting the first character to be a '-' |
|
4224 if (lex.Get() == '-') |
|
4225 { |
|
4226 TChar arg = lex.Get(); |
|
4227 switch (arg) |
|
4228 { |
|
4229 case 'v': |
|
4230 //print out the help |
|
4231 aMode |= EModeVersion; |
|
4232 break; |
|
4233 case 'h': |
|
4234 //print out the help |
|
4235 aMode |= EModeHelp; |
|
4236 break; |
|
4237 case 'r': |
|
4238 //store the fact that we want to run in reverse |
|
4239 aMode |= EModeReverse; |
|
4240 break; |
|
4241 case 'd': |
|
4242 //store the fact that we want to run in reverse |
|
4243 gUseDelay = EFalse; |
|
4244 RDebug::Printf("Not using delays"); |
|
4245 break; |
|
4246 default: |
|
4247 // unknown argument so leave |
|
4248 User::Leave(KErrArgument); |
|
4249 } |
|
4250 } |
|
4251 else |
|
4252 { |
|
4253 lex.UnGet(); |
|
4254 TInt testNumber; |
|
4255 User::LeaveIfError(lex.Val(testNumber)); |
|
4256 if( (testNumber<0) || (testNumber>=KMaxTests) ) |
|
4257 { |
|
4258 User::Leave(KErrArgument); |
|
4259 } |
|
4260 aTests.AppendL(testNumber); |
|
4261 } |
|
4262 lex.SkipSpace(); |
|
4263 } |
|
4264 // if no tests specified then run them all |
|
4265 if(aTests.Count() == 0) |
|
4266 { |
|
4267 aMode |= EModeAll; |
|
4268 } |
|
4269 |
|
4270 // do clean up |
|
4271 CleanupStack::PopAndDestroy(commandLine); |
|
4272 } |
|
4273 |
|
4274 void CRunModeAgent::ClientAppL() |
|
4275 // |
|
4276 // Performs each test in turn |
|
4277 // |
|
4278 { |
|
4279 test.Start(_L("ClientAppL")); |
|
4280 |
|
4281 RArray<TInt> testsToRun; |
|
4282 TUint32 testMode = 0; |
|
4283 ParseCommandLineL(testMode, testsToRun); |
|
4284 |
|
4285 //if help or version mode specified then just print out the relevant stuff and quit |
|
4286 if((testMode & EModeHelp) || (testMode & EModeVersion)) |
|
4287 { |
|
4288 if(testMode & EModeHelp) |
|
4289 { |
|
4290 PrintUsage(); |
|
4291 } |
|
4292 if(testMode & EModeVersion) |
|
4293 { |
|
4294 PrintVersion(); |
|
4295 } |
|
4296 test.End(); |
|
4297 return; |
|
4298 } |
|
4299 |
|
4300 if(testMode & EModeAll) |
|
4301 { |
|
4302 for(TInt i=0; i<KMaxTests; i++) |
|
4303 { |
|
4304 testsToRun.AppendL(i); |
|
4305 } |
|
4306 } |
|
4307 |
|
4308 // if EModeReverse specified then reverse the array elements |
|
4309 TInt numberOfTests = testsToRun.Count(); |
|
4310 if(testMode & EModeReverse) |
|
4311 { |
|
4312 for(TInt i=0; i<(numberOfTests>>1); i++) |
|
4313 { |
|
4314 TInt temp = testsToRun[i]; |
|
4315 testsToRun[i] = testsToRun[numberOfTests - (i+1)]; |
|
4316 testsToRun[numberOfTests - (i+1)] = temp; |
|
4317 } |
|
4318 } |
|
4319 |
|
4320 __UHEAP_MARK; |
|
4321 SetupAndAttachToDSS(); |
|
4322 __UHEAP_MARKEND; |
|
4323 |
|
4324 HelpStartTestTimer(); |
|
4325 for(TInt i=0; i<numberOfTests; i++) |
|
4326 { |
|
4327 RunTest(testsToRun[i]); |
|
4328 if( gUseDelay ) User::After(500000); |
|
4329 } |
|
4330 testsToRun.Close(); |
|
4331 |
|
4332 HelpStopTestTimer(); |
|
4333 |
|
4334 ReportPerformance(); |
|
4335 |
|
4336 test.End(); |
|
4337 } |
|
4338 |
|
4339 /** |
|
4340 Fill the test array with pointers to each test. |
|
4341 */ |
|
4342 void CRunModeAgent::FillArray() |
|
4343 { |
|
4344 iTestArray[0].iFunctionPtr = &CRunModeAgent::TestDriverSecurity; |
|
4345 iTestArray[0].iFunctionName = _L("TestDriverSecurity"); |
|
4346 iTestArray[1].iFunctionPtr = &CRunModeAgent::TestDllUsage; |
|
4347 iTestArray[1].iFunctionName = _L("TestDllUsage"); |
|
4348 iTestArray[2].iFunctionPtr = &CRunModeAgent::TestSecurity; |
|
4349 iTestArray[2].iFunctionName = _L("TestSecurity"); |
|
4350 iTestArray[3].iFunctionPtr = &CRunModeAgent::TestAttachExecutable; |
|
4351 iTestArray[3].iFunctionName = _L("TestAttachExecutable"); |
|
4352 iTestArray[4].iFunctionPtr = &CRunModeAgent::TestGetExecutablesList; |
|
4353 iTestArray[4].iFunctionName = _L("TestGetExecutablesList"); |
|
4354 iTestArray[5].iFunctionPtr = &CRunModeAgent::TestGetProcessList; |
|
4355 iTestArray[5].iFunctionName = _L("TestGetProcessList"); |
|
4356 iTestArray[6].iFunctionPtr = &CRunModeAgent::TestGetXipLibrariesList; |
|
4357 iTestArray[6].iFunctionName = _L("TestGetXipLibrariesList"); |
|
4358 iTestArray[7].iFunctionPtr = &CRunModeAgent::TestGetThreadList; |
|
4359 iTestArray[7].iFunctionName = _L("TestGetThreadList"); |
|
4360 iTestArray[8].iFunctionPtr = &CRunModeAgent::TestGetCodeSegsList; |
|
4361 iTestArray[8].iFunctionName = _L("TestGetCodeSegsList"); |
|
4362 iTestArray[9].iFunctionPtr = &CRunModeAgent::TestGetListInvalidData; |
|
4363 iTestArray[9].iFunctionName = _L("TestGetListInvalidData"); |
|
4364 iTestArray[10].iFunctionPtr = &CRunModeAgent::TestMemoryAccess; |
|
4365 iTestArray[10].iFunctionName = _L("TestMemoryAccess"); |
|
4366 iTestArray[11].iFunctionPtr = &CRunModeAgent::TestDebugFunctionality; |
|
4367 iTestArray[11].iFunctionName = _L("TestDebugFunctionality"); |
|
4368 iTestArray[12].iFunctionPtr = &CRunModeAgent::TestSuspendResume; |
|
4369 iTestArray[12].iFunctionName = _L("TestSuspendResume"); |
|
4370 iTestArray[13].iFunctionPtr = &CRunModeAgent::TestBreakPoints; |
|
4371 iTestArray[13].iFunctionName = _L("TestBreakPoints"); |
|
4372 iTestArray[14].iFunctionPtr = &CRunModeAgent::TestModifyBreak; |
|
4373 iTestArray[14].iFunctionName = _L("TestModifyBreak"); |
|
4374 iTestArray[15].iFunctionPtr = &CRunModeAgent::TestBreakInfo; |
|
4375 iTestArray[15].iFunctionName = _L("TestBreakInfo"); |
|
4376 iTestArray[16].iFunctionPtr = &CRunModeAgent::TestRunToBreak; |
|
4377 iTestArray[16].iFunctionName = _L("TestRunToBreak"); |
|
4378 iTestArray[17].iFunctionPtr = &CRunModeAgent::TestBreakPointsInLoop; |
|
4379 iTestArray[17].iFunctionName = _L("TestBreakPointsInLoop"); |
|
4380 iTestArray[18].iFunctionPtr = &CRunModeAgent::TestRegisterAccess; |
|
4381 iTestArray[18].iFunctionName = _L("TestRegisterAccess"); |
|
4382 iTestArray[19].iFunctionPtr = &CRunModeAgent::TestStep; |
|
4383 iTestArray[19].iFunctionName = _L("TestStep"); |
|
4384 iTestArray[20].iFunctionPtr = &CRunModeAgent::TestDemandPaging; |
|
4385 iTestArray[20].iFunctionName = _L("TestDemandPaging"); |
|
4386 iTestArray[21].iFunctionPtr = &CRunModeAgent::TestEventsForExternalProcess; |
|
4387 iTestArray[21].iFunctionName = _L("TestEventsForExternalProcess"); |
|
4388 iTestArray[22].iFunctionPtr = &CRunModeAgent::TestEvents; |
|
4389 iTestArray[22].iFunctionName = _L("TestEvents"); |
|
4390 iTestArray[23].iFunctionPtr = &CRunModeAgent::TestKillProcess; |
|
4391 iTestArray[23].iFunctionName = _L("TestKillProcess"); |
|
4392 iTestArray[24].iFunctionPtr = &CRunModeAgent::TestProcessBreakPoints; |
|
4393 iTestArray[24].iFunctionName = _L("TestProcessBreakPoints"); |
|
4394 iTestArray[25].iFunctionPtr = &CRunModeAgent::TestMultipleTraceEvents; |
|
4395 iTestArray[25].iFunctionName = _L("TestMultipleTraceEvents"); |
|
4396 iTestArray[26].iFunctionPtr = &CRunModeAgent::TestAddRemoveProcessEvents; |
|
4397 iTestArray[26].iFunctionName = _L("TestAddRemoveProcessEvents"); |
|
4398 iTestArray[27].iFunctionPtr = &CRunModeAgent::TestCrashFlash; |
|
4399 iTestArray[27].iFunctionName = _L("TestCrashFlash"); |
|
4400 iTestArray[28].iFunctionPtr = &CRunModeAgent::TestProcessKillBreakpoint; |
|
4401 iTestArray[28].iFunctionName = _L("TestProcessKillBreakpoint"); |
|
4402 }; |
|
4403 |
|
4404 GLDEF_C TInt E32Main() |
|
4405 // |
|
4406 // Entry point for run mode debug driver test |
|
4407 // |
|
4408 { |
|
4409 TInt ret = KErrNone; |
|
4410 |
|
4411 // client |
|
4412 CTrapCleanup* trap = CTrapCleanup::New(); |
|
4413 if (!trap) |
|
4414 return KErrNoMemory; |
|
4415 test.Title(); |
|
4416 RunModeAgent = CRunModeAgent::NewL(); |
|
4417 if (RunModeAgent != NULL) |
|
4418 { |
|
4419 __UHEAP_MARK; |
|
4420 TRAP(ret,RunModeAgent->ClientAppL()); |
|
4421 __UHEAP_MARKEND; |
|
4422 |
|
4423 delete RunModeAgent; |
|
4424 } |
|
4425 |
|
4426 delete trap; |
|
4427 |
|
4428 return ret; |
|
4429 } |
|
4430 |
|
4431 /** |
|
4432 Helper function to get the aOffset'th value from aFlags |
|
4433 |
|
4434 @param aFlags descriptor containing TRegisterFlag type flags |
|
4435 @param aOffset index of flag value to extract from aFlags |
|
4436 @param aFlagValue the flag value if function returned successfully |
|
4437 |
|
4438 @return KErrNone if value was read successfully, KErrTooBig if aOffset is |
|
4439 greater than aFlags.Length() |
|
4440 */ |
|
4441 TInt CRunModeAgent::GetFlag(const TDes8& aFlags, const TUint aOffset, TRegisterFlag &aFlagValue) const |
|
4442 { |
|
4443 //get pointer to data |
|
4444 const TUint8 *ptr = aFlags.Ptr(); |
|
4445 |
|
4446 //check aOffset is valid |
|
4447 TUint length = aFlags.Length(); |
|
4448 if(aOffset >= length) |
|
4449 return KErrTooBig; |
|
4450 |
|
4451 //get flag value |
|
4452 aFlagValue = (TRegisterFlag)ptr[aOffset]; |
|
4453 return KErrNone; |
|
4454 } |
|
4455 |
|
4456 /** |
|
4457 Helper function to set the value of FunctionChooser in the target debug thread. |
|
4458 |
|
4459 @param aTestFunction TTestFunction enum to set FunctionChooser to |
|
4460 |
|
4461 @return KErrNone if the value was set correctly, or one of the other system wide error codes |
|
4462 */ |
|
4463 TInt CRunModeAgent::SwitchTestFunction(TTestFunction aTestFunction) |
|
4464 { |
|
4465 //suspend the target thread |
|
4466 TInt suspendError = iServSession.SuspendThread(iThreadID); |
|
4467 if(! ( (suspendError == KErrNone) || (suspendError == KErrAlreadyExists) ) ) |
|
4468 { |
|
4469 //the thread is not suspended so exit |
|
4470 return suspendError; |
|
4471 } |
|
4472 |
|
4473 //get the address of FunctionChooser |
|
4474 TUint32 functionChooserAddress = (TUint32)&FunctionChooser; |
|
4475 //put the new value for FunctionChooser into a descriptor |
|
4476 TPtr8 functionBuf((TUint8*)&aTestFunction, sizeof(TTestFunction), sizeof(TTestFunction)); |
|
4477 //write the new value into the target thread |
|
4478 TInt writeError = iServSession.WriteMemory(iThreadID, functionChooserAddress, sizeof(TTestFunction), functionBuf, EAccess32, EEndLE8); |
|
4479 |
|
4480 if(KErrNone == suspendError) |
|
4481 { |
|
4482 //if this function suspended the target thread then we need to resume it |
|
4483 TInt resumeError = iServSession.ResumeThread(iThreadID); |
|
4484 if(KErrNone != resumeError) |
|
4485 { |
|
4486 //resuming failed so return the error |
|
4487 return resumeError; |
|
4488 } |
|
4489 } |
|
4490 |
|
4491 //suspending and resuming was successful so return the error code from the WriteMemory call |
|
4492 return writeError; |
|
4493 } |
|
4494 |
|
4495 /** |
|
4496 Launch a separate process to debug. |
|
4497 |
|
4498 @param aProcess the RProcess object to use to create the process |
|
4499 @param aFileName file name of the executable to create the process from |
|
4500 @param aFunctionType function that the target process should call on execution |
|
4501 @param aDelay delay before the new process should call the function represented by aFunctionType |
|
4502 @param aExtraThreads number of extra threads to create in the child process |
|
4503 |
|
4504 @return KErrNone on success, or one of the other system wide error codes |
|
4505 */ |
|
4506 TInt CRunModeAgent::LaunchProcess(RProcess& aProcess, const TDesC& aFileName, TDebugFunctionType aFunctionType, TUint32 aDelay, TUint32 aExtraThreads) |
|
4507 { |
|
4508 // at the moment we support two arguments, this number might have to be increased to support arguments |
|
4509 const TUint KMaxCommandLineLength = 32; |
|
4510 |
|
4511 // create a command line buffer |
|
4512 RBuf commandLine; |
|
4513 commandLine.Create(KMaxCommandLineLength); |
|
4514 |
|
4515 // append the command line arguments to the buffer |
|
4516 _LIT(KFArg, "-f"); |
|
4517 commandLine.Append(KFArg()); |
|
4518 commandLine.AppendNum(aFunctionType); |
|
4519 |
|
4520 _LIT(KSpace, " "); |
|
4521 commandLine.Append(KSpace()); |
|
4522 |
|
4523 _LIT(KDArg, "-d"); |
|
4524 commandLine.Append(KDArg()); |
|
4525 commandLine.AppendNum(aDelay); |
|
4526 |
|
4527 commandLine.Append(KSpace()); |
|
4528 |
|
4529 _LIT(KEArg, "-e"); |
|
4530 commandLine.Append(KEArg()); |
|
4531 commandLine.AppendNum(aExtraThreads); |
|
4532 |
|
4533 // create the new process, matching on file name only, not specifying uid values |
|
4534 TInt err = aProcess.Create(aFileName, commandLine); // owned by the process |
|
4535 |
|
4536 // check that there was no error raised |
|
4537 if(err != KErrNone) |
|
4538 { |
|
4539 commandLine.Close(); |
|
4540 return err; |
|
4541 } |
|
4542 |
|
4543 TRequestStatus status = KRequestPending; |
|
4544 aProcess.Rendezvous(status); |
|
4545 |
|
4546 commandLine.Close(); // after target thread starts |
|
4547 |
|
4548 if(KRequestPending != status.Int()) |
|
4549 { |
|
4550 // startup failed so kill the process |
|
4551 aProcess.Kill(KErrNone); |
|
4552 return status.Int(); |
|
4553 } |
|
4554 else |
|
4555 { |
|
4556 // start up succeeded so resume the process |
|
4557 aProcess.Resume(); |
|
4558 User::WaitForRequest(status); |
|
4559 if(KErrNone != status.Int()) |
|
4560 { |
|
4561 aProcess.Kill(KErrNone); |
|
4562 } |
|
4563 return status.Int(); |
|
4564 } |
|
4565 } |
|
4566 |
|
4567 /** |
|
4568 Helper function to read a tag header from a debug functionality block |
|
4569 |
|
4570 @param aDebugFunctionalityBlock block to read header from |
|
4571 @param aTagHdrId header type to find |
|
4572 |
|
4573 @return pointer to the header, or NULL if not available |
|
4574 */ |
|
4575 TTagHeader* CRunModeAgent::GetTagHdr(const TDesC8& aDebugFunctionalityBlock, const TTagHeaderId aTagHdrId) const |
|
4576 { |
|
4577 TUint8* ptr = (TUint8*) aDebugFunctionalityBlock.Ptr(); |
|
4578 TUint8* blockEnd = ptr + aDebugFunctionalityBlock.Size(); |
|
4579 |
|
4580 while(ptr < blockEnd) |
|
4581 { |
|
4582 TTagHeader* header = (TTagHeader*)ptr; |
|
4583 if(header->iTagHdrId == aTagHdrId) |
|
4584 { |
|
4585 return header; |
|
4586 } |
|
4587 ptr += sizeof(TTagHeader) + (header->iNumTags * sizeof(TTag)); |
|
4588 } |
|
4589 return NULL; |
|
4590 } |
|
4591 |
|
4592 /** |
|
4593 Helper function to read a tag from a debug functionality block |
|
4594 |
|
4595 @param aTagHdr pointer to a tag header in a debug functionality block |
|
4596 @param aElement element to return from the header's data |
|
4597 |
|
4598 @return pointer to the tag, or NULL if not available |
|
4599 */ |
|
4600 TTag* CRunModeAgent::GetTag(const TTagHeader* aTagHdr, const TInt aElement) const |
|
4601 { |
|
4602 TUint8* ptr = (TUint8*)aTagHdr + sizeof(TTagHeader); |
|
4603 TUint8* blockEnd = ptr + (aTagHdr->iNumTags * sizeof(TTag)); |
|
4604 |
|
4605 while(ptr < blockEnd) |
|
4606 { |
|
4607 TTag* tag = (TTag*)ptr; |
|
4608 if(tag->iTagId == aElement) |
|
4609 { |
|
4610 return tag; |
|
4611 } |
|
4612 ptr += sizeof(TTag); |
|
4613 } |
|
4614 return NULL; |
|
4615 } |
|
4616 |
|
4617 TTag CRunModeAgent::GetTag(const TTagHeaderId aTagHdrId, const TInt aElement) |
|
4618 { |
|
4619 TUint32 bufsize = 0; // Safe default size |
|
4620 |
|
4621 // Get functionality block size |
|
4622 test(KErrNone == iServSession.GetDebugFunctionalityBufSize(&bufsize)); |
|
4623 |
|
4624 // Ensure we have a finite buffer size |
|
4625 test(bufsize!=0); |
|
4626 |
|
4627 // Allocate space for the functionality data |
|
4628 HBufC8* dftext = HBufC8::NewLC(bufsize); |
|
4629 |
|
4630 // create an empty TPtr8 refering to dftext |
|
4631 TPtr8 dftextPtr(dftext->Des()); |
|
4632 |
|
4633 // Get the functionality block |
|
4634 test(KErrNone == iServSession.GetDebugFunctionality(dftextPtr)); |
|
4635 |
|
4636 // read a value from the data to check it has come through as expected |
|
4637 TTagHeader* header = GetTagHdr(dftext->Des(), aTagHdrId); |
|
4638 test(header != NULL); |
|
4639 TTag* tag = GetTag(header, aElement); |
|
4640 test(tag != NULL); |
|
4641 |
|
4642 TTag tagToReturn = *tag; |
|
4643 |
|
4644 // Remove our temporary buffer |
|
4645 CleanupStack::PopAndDestroy(dftext); |
|
4646 |
|
4647 return tagToReturn; |
|
4648 } |
|
4649 |
|
4650 /** |
|
4651 Helper function which returns a Boolean indicating with a process with the |
|
4652 specified name is currently running. |
|
4653 |
|
4654 @param aProcessName - Name of the process to find |
|
4655 @return ETrue if found, EFalse otherwise |
|
4656 */ |
|
4657 TBool CRunModeAgent::ProcessExists(const TDesC& aProcessName) |
|
4658 { |
|
4659 TInt err=KErrNone; |
|
4660 TBool found = FALSE; |
|
4661 |
|
4662 _LIT(KWildCard,"*"); |
|
4663 |
|
4664 TFindProcess find(KWildCard); |
|
4665 TFullName name; |
|
4666 while(find.Next(name)==KErrNone) |
|
4667 { |
|
4668 RProcess process; |
|
4669 err = process.Open(find); |
|
4670 if (err == KErrNone) |
|
4671 { |
|
4672 if (name.Find(aProcessName) != KErrNotFound) |
|
4673 { |
|
4674 found = TRUE; |
|
4675 } |
|
4676 process.Close(); |
|
4677 } |
|
4678 } |
|
4679 |
|
4680 return found; |
|
4681 } |
|