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