|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Implementation of the new MemSpyServer |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <e32svr.h> |
|
20 #include <e32cmn.h> |
|
21 #include <e32base.h> |
|
22 #include <w32std.h> |
|
23 //#include <apgtask.h> |
|
24 //#include <apgwgnam.h> |
|
25 |
|
26 //user includes |
|
27 #include "MemSpyServerSession.h" |
|
28 |
|
29 // User includes |
|
30 #include <memspy/engine/memspyengine.h> |
|
31 #include <memspy/engine/memspyenginelogger.h> |
|
32 #include <memspyengineclientinterface.h> |
|
33 #include <memspy/engine/memspyengineobjectthread.h> |
|
34 #include <memspy/engine/memspyengineobjectprocess.h> |
|
35 #include <memspy/engine/memspyengineobjectcontainer.h> |
|
36 #include <memspy/engine/memspyenginehelperchunk.h> |
|
37 #include <memspy/engine/memspyenginehelpercodesegment.h> |
|
38 #include <memspy/engine/memspyenginehelperheap.h> |
|
39 #include <memspy/engine/memspyenginehelperstack.h> |
|
40 #include <memspy/engine/memspyenginehelperthread.h> |
|
41 #include <memspy/engine/memspyenginehelperprocess.h> |
|
42 #include <memspy/engine/memspyenginehelperfilesystem.h> |
|
43 #include <memspy/engine/memspyenginehelperram.h> |
|
44 #include <memspy/engine/memspyenginehelpersysmemtracker.h> |
|
45 #include <memspy/engine/memspyenginehelpersysmemtrackerconfig.h> |
|
46 #include <memspy/engine/memspyenginehelperkernelcontainers.h> |
|
47 #include <memspy/engine/memspyenginehelperserver.h> |
|
48 |
|
49 //cigasto |
|
50 #include <memspysession.h> |
|
51 //#include <memspy/driver/memspydriverclient.h> |
|
52 |
|
53 // --------------------------------------------------------- |
|
54 // CMemSpyServerSession( CMemSpyEngine& aEngine ) |
|
55 // --------------------------------------------------------- |
|
56 // |
|
57 CMemSpyServerSession::CMemSpyServerSession( CMemSpyEngine& aEngine ) |
|
58 : iEngine( aEngine ) |
|
59 { |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // ~CMemSpyServerSession() |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 CMemSpyServerSession::~CMemSpyServerSession() |
|
67 { |
|
68 #ifdef _DEBUG |
|
69 TPtrC pThreadName( KNullDesC ); |
|
70 if ( iClientThreadName ) |
|
71 { |
|
72 pThreadName.Set( *iClientThreadName ); |
|
73 } |
|
74 |
|
75 RDebug::Print( _L("[MemSpy] CMemSpyServerSession::~CMemSpyServerSession() - DEAD SESSION - this: 0x%08x, id: %4d, name: %S"), this, iClientThreadId, iClientThreadName ); |
|
76 #endif |
|
77 |
|
78 delete iClientThreadName; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // ConstructL( const RMessage2& aMessage ) |
|
83 // --------------------------------------------------------- |
|
84 // |
|
85 void CMemSpyServerSession::ConstructL( const RMessage2& aMessage ) |
|
86 { |
|
87 RThread thread; |
|
88 const TInt error = aMessage.Client( thread ); |
|
89 CleanupClosePushL( thread ); |
|
90 |
|
91 TRACE( RDebug::Printf( "[MemSpy] CMemSpyServerSession::ConstructL() - this: 0x%08x - opening client thread - err: %d", this, error ) ); |
|
92 |
|
93 User::LeaveIfError( error ); |
|
94 |
|
95 const TFullName threadName( thread.FullName() ); |
|
96 iClientThreadName = threadName.AllocL(); |
|
97 iClientThreadId = thread.Id(); |
|
98 |
|
99 CleanupStack::PopAndDestroy( &thread ); |
|
100 |
|
101 TRACE( RDebug::Print( _L("[MemSpy] CMemSpyServerSession::ConstructL() - NEW SESSION - this: 0x%08x, id: %4d, client: %S"), this, iClientThreadId, iClientThreadName ) ); |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------- |
|
105 // NewL( CMemSpyEngine& aEngine, const RMessage2& aMessage ) |
|
106 // Two-phased constructor |
|
107 // --------------------------------------------------------- |
|
108 // |
|
109 CMemSpyServerSession* CMemSpyServerSession::NewL( CMemSpyEngine& aEngine, const RMessage2& aMessage ) |
|
110 { |
|
111 CMemSpyServerSession* self = new(ELeave) CMemSpyServerSession( aEngine ); |
|
112 CleanupStack::PushL( self ); |
|
113 self->ConstructL( aMessage ); |
|
114 CleanupStack::Pop( self ); |
|
115 return self; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------- |
|
119 // ServiceL( const RMessage2& aMessage ) |
|
120 // Method from which the clients request arrives |
|
121 // --------------------------------------------------------- |
|
122 // |
|
123 void CMemSpyServerSession::ServiceL( const RMessage2& aMessage ) |
|
124 { |
|
125 TRACE( RDebug::Print( _L("[MemSpy] CMemSpyServerSession::ServiceL() - START - this: 0x%08x, fn: 0x%08x, id: %4d, client: %S"), this, aMessage.Function(), iClientThreadId, iClientThreadName ) ); |
|
126 |
|
127 TRAPD( error, DoServiceL( aMessage ) ); |
|
128 if ( error != KErrNone ) |
|
129 { |
|
130 RDebug::Print( _L("[MemSpy] CMemSpyServerSession::ServiceL() - SERVICE ERROR - this: 0x%08x, fn: %d, err: %d, client: %S"), this, aMessage.Function(), error, iClientThreadName ); |
|
131 } |
|
132 aMessage.Complete( error ); |
|
133 |
|
134 TRACE( RDebug::Print( _L("[MemSpy] CMemSpyServerSession::ServiceL() - END - this: 0x%08x, fn: 0x%08x, id: %4d, client: %S"), this, aMessage.Function(), iClientThreadId, iClientThreadName ) ); |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------- |
|
138 // DoServiceL( const RMessage2& aMessage ) |
|
139 // --------------------------------------------------------- |
|
140 // |
|
141 void CMemSpyServerSession::DoServiceL( const RMessage2& aMessage ) |
|
142 { |
|
143 TInt error = KErrNone; |
|
144 |
|
145 // Check function attributes |
|
146 const TInt function = aMessage.Function() & KMemSpyOpFlagsTypeMask; |
|
147 const TInt argSpec = aMessage.Function() & KMemSpyOpFlagsInclusionMask; |
|
148 const TBool byThreadId = ( argSpec == KMemSpyOpFlagsIncludesThreadId ); |
|
149 const TBool byThreadName = ( argSpec == KMemSpyOpFlagsIncludesThreadName ); |
|
150 |
|
151 TRACE( RDebug::Printf( "[MemSpy] CMemSpyServerSession::DoServiceL() - START - unmodified function: 0x%08x, opCode: %d [TID: %d, TN: %d]", aMessage.Function(), function, byThreadId, byThreadName ) ); |
|
152 |
|
153 switch (function) |
|
154 { |
|
155 case EGetProcessCount: |
|
156 { |
|
157 aMessage.WriteL(0, TPckgBuf<TInt>(iEngine.Container().Count())); |
|
158 break; |
|
159 } |
|
160 case EGetProcesses: |
|
161 { |
|
162 CMemSpyEngineObjectContainer& list = iEngine.Container(); |
|
163 |
|
164 TPckgBuf<TInt> a0; |
|
165 aMessage.ReadL(0, a0); |
|
166 TInt realCount = Min(a0(), list.Count()); |
|
167 |
|
168 for(TInt i=0, offset = 0; i<realCount; i++, offset += sizeof(TMemSpyProcessData)) |
|
169 { |
|
170 CMemSpyProcess& process = iEngine.Container().At(i); |
|
171 TMemSpyProcessData data; |
|
172 data.iId = process.Id(); |
|
173 data.iName.Copy(process.Name()); |
|
174 |
|
175 TPckgBuf<TMemSpyProcessData> buffer(data); |
|
176 aMessage.WriteL(1, buffer, offset); |
|
177 } |
|
178 |
|
179 a0 = list.Count(); |
|
180 aMessage.WriteL(0, a0); |
|
181 |
|
182 break; |
|
183 } |
|
184 case EProcessSystemPermanentOrCritical: |
|
185 { |
|
186 TBool ret = EFalse; |
|
187 TPckgBuf<TProcessId> id; |
|
188 aMessage.ReadL( 0, id ); |
|
189 |
|
190 CMemSpyEngineObjectContainer& container = iEngine.Container(); |
|
191 CMemSpyProcess& process = container.ProcessByIdL( id() ); |
|
192 |
|
193 process.Open(); |
|
194 |
|
195 if ( process.IsSystemPermanent() || process.IsSystemCritical() ) |
|
196 { |
|
197 ret = ETrue; |
|
198 } |
|
199 TPckgBuf<TBool> retBuf( ret ); |
|
200 aMessage.WriteL( 1, retBuf ); |
|
201 |
|
202 break; |
|
203 } |
|
204 case EEndProcess: |
|
205 { |
|
206 TPckgBuf<TProcessId> id; |
|
207 aMessage.ReadL( 0, id ); |
|
208 TPckgBuf<TEndType> type; |
|
209 aMessage.ReadL( 1, type ); |
|
210 |
|
211 CMemSpyEngineObjectContainer& container = iEngine.Container(); |
|
212 CMemSpyProcess& process = container.ProcessByIdL( id() ); |
|
213 |
|
214 switch ( type() ) |
|
215 { |
|
216 case ETerminate: |
|
217 { |
|
218 process.TerminateL(); |
|
219 break; |
|
220 } |
|
221 case EPanic: |
|
222 { |
|
223 process.PanicL(); |
|
224 break; |
|
225 } |
|
226 case EKill: |
|
227 { |
|
228 process.KillL(); |
|
229 break; |
|
230 } |
|
231 } |
|
232 break; |
|
233 } |
|
234 case ESwitchToProcess: |
|
235 {/* |
|
236 TInt wgCount; |
|
237 RWsSession wsSession; |
|
238 User::LeaveIfError( wsSession.Connect() ); |
|
239 CleanupClosePushL( wsSession ); |
|
240 User::LeaveIfError( wgCount = wsSession.NumWindowGroups() ); |
|
241 RArray<RWsSession::TWindowGroupChainInfo> wgArray; |
|
242 CleanupClosePushL( wgArray ); |
|
243 User::LeaveIfError( wsSession.WindowGroupList( &wgArray ) ); |
|
244 TApaTask task( wsSession ); |
|
245 TBool brought( EFalse ); |
|
246 TInt wgId( KErrNotFound ); |
|
247 TThreadId threadId; |
|
248 |
|
249 TPckgBuf<TProcessId> id; |
|
250 aMessage.ReadL( 0, id ); |
|
251 CMemSpyEngineObjectContainer& container = iEngine.Container(); |
|
252 CMemSpyProcess& process = container.ProcessByIdL( id() ); |
|
253 |
|
254 // loop trough threads in a process |
|
255 for ( TInt i = 0; i < process.MdcaCount(); i++ ) |
|
256 { |
|
257 TInt wgCountLocal = wgCount; |
|
258 |
|
259 // loop trough all window groups and see if a thread id matches |
|
260 while( !brought && wgCountLocal-- ) |
|
261 { |
|
262 wgId = wgArray[wgCountLocal].iId; |
|
263 User::LeaveIfError( wsSession.GetWindowGroupClientThreadId( wgId, threadId ) ); |
|
264 if ( threadId == process.At( i ).Id() ) |
|
265 { |
|
266 CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( wsSession, wgId ); |
|
267 task.SetWgId( wgId ); |
|
268 if ( !wgName->Hidden() && task.Exists() ) |
|
269 { |
|
270 task.BringToForeground(); |
|
271 brought = ETrue; |
|
272 } |
|
273 CleanupStack::PopAndDestroy( wgName ); |
|
274 } |
|
275 } |
|
276 } |
|
277 |
|
278 TPckgBuf<TBool> ret( brought ); |
|
279 aMessage.WriteL( 1, ret ); |
|
280 |
|
281 break;*/ |
|
282 } |
|
283 case EGetThreadCount: |
|
284 { |
|
285 TPckgBuf<TProcessId> pid; |
|
286 aMessage.ReadL(1, pid); |
|
287 CMemSpyProcess& process = iEngine.Container().ProcessByIdL(pid()); |
|
288 process.Open(); |
|
289 aMessage.WriteL(0, TPckgBuf<TInt>(process.Count())); |
|
290 process.Close(); |
|
291 break; |
|
292 } |
|
293 case EGetThreads: |
|
294 { |
|
295 TPckgBuf<TProcessId> pid; |
|
296 aMessage.ReadL(2, pid); |
|
297 |
|
298 CMemSpyProcess& list = iEngine.Container().ProcessByIdL(pid()); |
|
299 list.Open(); |
|
300 |
|
301 TPckgBuf<TInt> a0; |
|
302 aMessage.ReadL(0, a0); |
|
303 TInt realCount = Min(a0(), list.Count()); |
|
304 |
|
305 for(TInt i=0, offset = 0; i<realCount; i++, offset += sizeof(TMemSpyThreadData)) |
|
306 { |
|
307 CMemSpyThread& thread = list.At(i); |
|
308 thread.Open(); |
|
309 |
|
310 TMemSpyThreadData data; |
|
311 data.iId = thread.Id(); |
|
312 data.iName.Copy(thread.Name()); |
|
313 data.iThreadPriority = thread.Priority(); |
|
314 |
|
315 TPckgBuf<TMemSpyThreadData> buffer(data); |
|
316 aMessage.WriteL(1, buffer, offset); |
|
317 |
|
318 thread.Close(); |
|
319 } |
|
320 |
|
321 a0 = list.Count(); |
|
322 aMessage.WriteL(0, a0); |
|
323 |
|
324 list.Close(); |
|
325 |
|
326 break; |
|
327 } |
|
328 case ESetThreadPriority: |
|
329 { |
|
330 TPckgBuf<TThreadId> tid; |
|
331 TPckgBuf<TInt> priority; |
|
332 aMessage.ReadL(0, tid); |
|
333 aMessage.ReadL(1, priority); |
|
334 |
|
335 CMemSpyProcess* process = NULL; |
|
336 CMemSpyThread* thread = NULL; |
|
337 User::LeaveIfError(iEngine.Container().ProcessAndThreadByThreadId(tid(), process, thread)); |
|
338 |
|
339 if (thread) |
|
340 { |
|
341 thread->Open(); |
|
342 thread->SetPriorityL(static_cast<TThreadPriority>(priority())); |
|
343 thread->Close(); |
|
344 } |
|
345 break; |
|
346 } |
|
347 case EThreadSystemPermanentOrCritical: |
|
348 { |
|
349 TBool ret = EFalse; |
|
350 TPckgBuf<TThreadId> id; |
|
351 aMessage.ReadL( 0, id ); |
|
352 |
|
353 CMemSpyEngineObjectContainer& container = iEngine.Container(); |
|
354 CMemSpyProcess* process = NULL; |
|
355 CMemSpyThread* thread = NULL; |
|
356 User::LeaveIfError( container.ProcessAndThreadByThreadId( id(), process, thread ) ); |
|
357 |
|
358 if ( thread ) |
|
359 { |
|
360 thread->Open(); |
|
361 |
|
362 if ( thread->IsSystemPermanent() || thread->IsSystemCritical() ) |
|
363 { |
|
364 ret = ETrue; |
|
365 } |
|
366 thread->Close(); |
|
367 } |
|
368 TPckgBuf<TBool> retBuf( ret ); |
|
369 aMessage.WriteL( 1, retBuf ); |
|
370 |
|
371 break; |
|
372 } |
|
373 case EEndThread: |
|
374 { |
|
375 TPckgBuf<TThreadId> id; |
|
376 aMessage.ReadL( 0, id ); |
|
377 TPckgBuf<TEndType> type; |
|
378 aMessage.ReadL( 1, type ); |
|
379 |
|
380 CMemSpyEngineObjectContainer& container = iEngine.Container(); |
|
381 CMemSpyProcess* process = NULL; |
|
382 CMemSpyThread* thread = NULL; |
|
383 User::LeaveIfError( container.ProcessAndThreadByThreadId( id(), process, thread ) ); |
|
384 |
|
385 if( thread ) |
|
386 { |
|
387 switch ( type() ) |
|
388 { |
|
389 case ETerminate: |
|
390 { |
|
391 thread->TerminateL(); |
|
392 break; |
|
393 } |
|
394 case EPanic: |
|
395 { |
|
396 thread->PanicL(); |
|
397 break; |
|
398 } |
|
399 case EKill: |
|
400 { |
|
401 thread->KillL(); |
|
402 break; |
|
403 } |
|
404 } |
|
405 } |
|
406 break; |
|
407 } |
|
408 // --- KernelObjects related functions --- |
|
409 case EGetKernelObjectTypeCount: |
|
410 { |
|
411 TInt iCount = EMemSpyDriverContainerTypeChunk - EMemSpyDriverContainerTypeFirst; |
|
412 //TInt iCount = EMemSpyDriverContainerTypeLast - EMemSpyDriverContainerTypeFirst; |
|
413 TPckgBuf<TInt> ret( iCount ); |
|
414 aMessage.WriteL(0, ret); |
|
415 break; |
|
416 } |
|
417 case EGetKernelObjects: |
|
418 { |
|
419 TPckgBuf<TInt> count; |
|
420 aMessage.ReadL(0, count); |
|
421 |
|
422 CMemSpyEngineGenericKernelObjectContainer* model = iEngine.HelperKernelContainers().ObjectsAllL(); //contains all the objects |
|
423 CleanupStack::PushL( model ); |
|
424 |
|
425 for( TInt i=0, offset = 0; i<count(); i++, offset += sizeof( TMemSpyKernelObjectData ) ) |
|
426 { |
|
427 TMemSpyKernelObjectData data; |
|
428 |
|
429 data.iName.Append( model->At(i).Name() ); |
|
430 data.iType = model->At(i).Type(); |
|
431 data.iCount = model->At(i).Count(); |
|
432 data.iSize = model->At(i).Count() * model->At(i).Count(); |
|
433 |
|
434 TPckgBuf<TMemSpyKernelObjectData> buffer(data); |
|
435 aMessage.WriteL(1, buffer, offset); |
|
436 } |
|
437 aMessage.WriteL(0, count); |
|
438 CleanupStack::PopAndDestroy( model ); |
|
439 break; |
|
440 } |
|
441 case EGetKernelObjectItemsCount: |
|
442 { |
|
443 TPckgBuf<TMemSpyDriverContainerType> tempType; |
|
444 aMessage.ReadL(1, tempType); //get type of kernel object |
|
445 TMemSpyDriverContainerType type = tempType(); |
|
446 |
|
447 CMemSpyEngineHelperKernelContainers& kernelContainerManager = iEngine.HelperKernelContainers(); |
|
448 CMemSpyEngineGenericKernelObjectList* iObjectList = kernelContainerManager.ObjectsForSpecificContainerL( type ); |
|
449 CleanupStack::PushL( iObjectList ); |
|
450 |
|
451 TInt count = iObjectList->Count(); |
|
452 TPckgBuf<TInt> ret( count ); |
|
453 aMessage.WriteL( 0, ret ); |
|
454 |
|
455 CleanupStack::PopAndDestroy( iObjectList ); |
|
456 break; |
|
457 } |
|
458 case EGetKernelObjectItems: |
|
459 { |
|
460 TPckgBuf<TInt> count; |
|
461 TPckgBuf<TMemSpyDriverContainerType> tempType; |
|
462 aMessage.ReadL( 0, count ); //get count of items |
|
463 aMessage.ReadL(1, tempType); //get type of kernel object |
|
464 TInt c = count(); |
|
465 |
|
466 CMemSpyEngineHelperKernelContainers& kernelContainerManager = iEngine.HelperKernelContainers(); |
|
467 CMemSpyEngineGenericKernelObjectList* iObjectList = kernelContainerManager.ObjectsForSpecificContainerL( tempType() ); |
|
468 CleanupStack::PushL( iObjectList ); |
|
469 |
|
470 for( TInt i=0, offset = 0; i<c; i++, offset += sizeof( TMemSpyDriverHandleInfoGeneric ) ) |
|
471 { |
|
472 TMemSpyDriverHandleInfoGeneric data; |
|
473 |
|
474 data = iObjectList->At( i ); |
|
475 |
|
476 TPckgBuf<TMemSpyDriverHandleInfoGeneric> buffer(data); |
|
477 aMessage.WriteL(2, buffer, offset); |
|
478 } |
|
479 |
|
480 CleanupStack::PopAndDestroy( iObjectList ); |
|
481 break; |
|
482 } |
|
483 // --- Kernel Heap related functions --- |
|
484 case EGetHeap: |
|
485 { |
|
486 TMemSpyHeapInfo heapInfo; |
|
487 iEngine.HelperHeap().GetHeapInfoKernelL( heapInfo ); |
|
488 TMemSpyHeapData data = iEngine.HelperHeap().NewHeapRawInfo( heapInfo ); |
|
489 |
|
490 TPckgBuf<TMemSpyHeapData> buffer(data); |
|
491 aMessage.WriteL(0, buffer); |
|
492 |
|
493 break; |
|
494 } |
|
495 } |
|
496 // else if( function == EProcessByIndex ) |
|
497 // { |
|
498 // TMemSpyProcess iProcess; |
|
499 // TInt in; |
|
500 // TPckgBuf<TInt> index( in ); |
|
501 // aMessage.ReadL( 0, index ); |
|
502 // CMemSpyProcess& process = iEngine.Container().At( index() ); |
|
503 // //fill the data structure |
|
504 // iProcess.iId = process.Id(); //process ID |
|
505 // iProcess.iName.Append( process.Name() ); //raw process name |
|
506 // iProcess.iThreadCount = process.Count(); //thread count |
|
507 // iProcess.iPriority = process.Priority(); |
|
508 // // |
|
509 // TPckgBuf<TMemSpyProcess> buf( iProcess ); |
|
510 // aMessage.WriteL( 1, buf ); |
|
511 // aMessage.Complete( KErrNone ); |
|
512 // } |
|
513 // else if( function == EProcessIndexById ) |
|
514 // { |
|
515 // TProcessId iId; |
|
516 // TPckgBuf<TProcessId> buf( iId ); |
|
517 // aMessage.ReadL( 0, buf ); |
|
518 // TInt index = iEngine.Container().ProcessIndexById( buf() ); |
|
519 // TPckgBuf<TInt> out( index ); |
|
520 // aMessage.WriteL( 1, out ); |
|
521 // aMessage.Complete( KErrNone ); |
|
522 // } |
|
523 // else if( function == EOutputProcessInfo ) |
|
524 // { |
|
525 // TProcessId iId; |
|
526 // TPckgBuf<TProcessId> buf( iId ); |
|
527 // aMessage.ReadL( 0, buf ); |
|
528 // CMemSpyProcess& process = iEngine.Container().ProcessByIdL( buf() ); |
|
529 // iEngine.HelperProcess().OutputProcessInfoL( process ); |
|
530 // } |
|
531 // else if( function == EProcessIsDead ) |
|
532 // { |
|
533 // TProcessId iId; |
|
534 // TPckgBuf<TProcessId> buf( iId ); |
|
535 // aMessage.ReadL( 0, buf ); |
|
536 // CMemSpyProcess& process = iEngine.Container().ProcessByIdL( buf() ); |
|
537 // TBool dead = process.IsDead(); |
|
538 // TPckgBuf<TBool> out( dead ); |
|
539 // aMessage.WriteL( 1, out ); |
|
540 // aMessage.Complete( KErrNone ); |
|
541 // } |
|
542 // else if( function == ESortProcessesBy ) |
|
543 // { |
|
544 // TSortType type; |
|
545 // TPckgBuf<TSortType> buf(type); |
|
546 // aMessage.ReadL( 0, buf ); |
|
547 // if( buf() == ESortProcById ) |
|
548 // { |
|
549 // iEngine.Container().SortById(); |
|
550 // } |
|
551 // else if( buf() == ESortProcByName ) |
|
552 // { |
|
553 // iEngine.Container().SortByName(); |
|
554 // } |
|
555 // else if( buf() == ESortProcByThreadCount ) |
|
556 // { |
|
557 // iEngine.Container().SortByThreadCount(); |
|
558 // } |
|
559 // else if( buf() == ESortProcByCodeSegs ) |
|
560 // { |
|
561 // iEngine.Container().SortByCodeSegs(); |
|
562 // } |
|
563 // else if( buf() == ESortProcByHeapUsage ) |
|
564 // { |
|
565 // iEngine.Container().SortByHeapUsage(); |
|
566 // } |
|
567 // else if( buf() == ESortProcByStackUsage ) |
|
568 // { |
|
569 // iEngine.Container().SortByStackUsage(); |
|
570 // } |
|
571 // } |
|
572 // else if( function == EOpenCloseCurrentProcess ) |
|
573 // { |
|
574 // TProcessId id; |
|
575 // TBool open; |
|
576 // TPckgBuf<TProcessId> buf(id); |
|
577 // TPckgBuf<TBool> buf2(open); |
|
578 // aMessage.ReadL( 0, buf ); |
|
579 // aMessage.ReadL( 1, buf2 ); |
|
580 // if( buf2() == 1 ) |
|
581 // { |
|
582 // iEngine.Container().ProcessByIdL( buf() ).Open(); |
|
583 // } |
|
584 // else |
|
585 // { |
|
586 // iEngine.Container().ProcessByIdL( buf() ).Close(); |
|
587 // } |
|
588 // } |
|
589 |
|
590 // // Check function is supported and argument combination is valid |
|
591 // error = ValidateFunction( function, byThreadId, byThreadName ); |
|
592 // TRACE( RDebug::Printf( "[MemSpy] CMemSpyServerSession::DoServiceL() - validation result: %d", error ) ); |
|
593 // |
|
594 // // Process function request |
|
595 // if ( error == KErrNone ) |
|
596 // { |
|
597 // if ( byThreadId ) |
|
598 // { |
|
599 // TRACE( RDebug::Printf( "[MemSpy] CMemSpyServerSession::DoServiceL() - [TID] thread-specific..." ) ); |
|
600 // |
|
601 // const TThreadId threadId( aMessage.Int0() ); |
|
602 // HandleThreadSpecificOpL( function, threadId ); |
|
603 // } |
|
604 // else if ( byThreadName ) |
|
605 // { |
|
606 // TRACE( RDebug::Printf( "[MemSpy] CMemSpyServerSession::DoServiceL() - [TN] thread-specific..." ) ); |
|
607 // |
|
608 // error = aMessage.GetDesLength( 0 /*slot 0*/ ); |
|
609 // |
|
610 // if ( error > 0 && error <= KMaxFullName ) |
|
611 // { |
|
612 // TFullName* threadName = new(ELeave) TFullName(); |
|
613 // CleanupStack::PushL( threadName ); |
|
614 // aMessage.ReadL( 0, *threadName ); |
|
615 // HandleThreadSpecificOpL( function, *threadName ); |
|
616 // CleanupStack::PopAndDestroy( threadName ); |
|
617 // } |
|
618 // else |
|
619 // { |
|
620 // error = KErrArgument; |
|
621 // } |
|
622 // } |
|
623 // else |
|
624 // { |
|
625 // TRACE( RDebug::Printf( "[MemSpy] CMemSpyServerSession::DoServiceL() - thread-agnostic..." ) ); |
|
626 // |
|
627 // HandleThreadAgnosticOpL( function, aMessage ); |
|
628 // } |
|
629 // } |
|
630 |
|
631 User::LeaveIfError( error ); |
|
632 |
|
633 TRACE( RDebug::Printf( "[MemSpy] CMemSpyServerSession::DoServiceL() - HELLOOOOOO" ) ); |
|
634 TRACE( RDebug::Printf( "[MemSpy] CMemSpyServerSession::DoServiceL() - END" ) ); |
|
635 } |
|
636 |
|
637 // --------------------------------------------------------- |
|
638 // ValidateFunction( TInt aFunction, TBool aIncludesThreadId, TBool aIncludesThreadName ) |
|
639 // Validates the MemSpy operation types |
|
640 // --------------------------------------------------------- |
|
641 // |
|
642 TInt CMemSpyServerSession::ValidateFunction( TInt aFunction, TBool aIncludesThreadId, TBool aIncludesThreadName ) |
|
643 { |
|
644 TInt err = KErrNotSupported; |
|
645 |
|
646 // Check the operation is within op-code range |
|
647 if ( aFunction >= EMemSpyClientServerOpMarkerFirst && aFunction < EMemSpyClientServerOpMarkerLast ) |
|
648 { |
|
649 // Check the operation doesn't include unnecessary or not supported information |
|
650 const TBool includesThreadIdentifier = ( aIncludesThreadId || aIncludesThreadName ); |
|
651 if ( includesThreadIdentifier && aFunction >= EMemSpyClientServerOpMarkerThreadAgnosticFirst ) |
|
652 { |
|
653 // Passing a thread identifier to a thread agnostic operation |
|
654 err = KErrArgument; |
|
655 } |
|
656 else |
|
657 { |
|
658 err = KErrNone; |
|
659 } |
|
660 } |
|
661 // |
|
662 if ( err != KErrNone ) |
|
663 { |
|
664 RDebug::Printf( "[MemSpy] CMemSpyServerSession::ValidateFunction() - function request did not validate - [withId: %d, withName: %d]", aIncludesThreadId, aIncludesThreadName ); |
|
665 } |
|
666 // |
|
667 return err; |
|
668 } |
|
669 |
|
670 // --------------------------------------------------------- |
|
671 // HandleThreadSpecificOpL( TInt aFunction, const TThreadId& aThreadId ) |
|
672 // --------------------------------------------------------- |
|
673 // |
|
674 void CMemSpyServerSession::HandleThreadSpecificOpL( TInt aFunction, const TThreadId& aThreadId ) |
|
675 { |
|
676 // TRACE( RDebug::Printf( "[MemSpy] CMemSpyServerSession::HandleThreadSpecificOpL() - START - aFunction: %d, aThreadId: %d", aFunction, (TUint) aThreadId ) ); |
|
677 // |
|
678 // ASSERT( (TUint) aThreadId != 0 ); |
|
679 // TInt error = KErrNone; |
|
680 // |
|
681 // // Check if its a kernel thread identifier |
|
682 // const TBool isKernel = ( static_cast<TUint32>( aThreadId ) == KMemSpyClientServerThreadIdKernel ); |
|
683 // |
|
684 // // Treat as thread specific operation |
|
685 // CMemSpyProcess* process = NULL; |
|
686 // CMemSpyThread* thread = NULL; |
|
687 // if ( !isKernel ) |
|
688 // { |
|
689 // error = iEngine.Container().ProcessAndThreadByThreadId( aThreadId, process, thread ); |
|
690 // TRACE( RDebug::Printf( "[MemSpy] CMemSpyServerSession::HandleThreadSpecificOpL() - search result: %d, proc: 0x%08x, thread: 0x%08x", error, process, thread ) ); |
|
691 // } |
|
692 // else |
|
693 // { |
|
694 // // Kernel is only supported for a couple of operations |
|
695 // if ( aFunction == EMemSpyClientServerOpHeapInfo || aFunction == EMemSpyClientServerOpHeapData ) |
|
696 // { |
|
697 // } |
|
698 // else |
|
699 // { |
|
700 // TRACE( RDebug::Printf( "[MemSpy] CMemSpyServerSession::HandleThreadSpecificOpL() - trying to call unsupported function for kernel thread!" ) ); |
|
701 // error = KErrArgument; |
|
702 // } |
|
703 // } |
|
704 // |
|
705 // // Must be no error so far and we must have a valid thread & process when performing a non-kernel op |
|
706 // // or then if we are performing a kernel op, we don't need the thread or process. |
|
707 // if ( error == KErrNone && ( ( thread && process && !isKernel ) || ( isKernel ) ) ) |
|
708 // { |
|
709 //#ifdef _DEBUG |
|
710 // if ( thread ) |
|
711 // { |
|
712 // HBufC* threadName = thread->FullName().AllocLC(); |
|
713 // _LIT( KTrace2, "[MemSpy] CMemSpyServerSession::HandleThreadSpecificOpL() - thread: %S" ); |
|
714 // RDebug::Print( KTrace2, threadName ); |
|
715 // CleanupStack::PopAndDestroy( threadName ); |
|
716 // } |
|
717 // else if ( isKernel ) |
|
718 // { |
|
719 // _LIT( KTrace2, "[MemSpy] CMemSpyServerSession::HandleThreadSpecificOpL() - thread: Kernel" ); |
|
720 // RDebug::Print( KTrace2 ); |
|
721 // } |
|
722 //#endif |
|
723 // |
|
724 // // Got a valid thread object - now work out which operation to perform... |
|
725 // switch( aFunction ) |
|
726 // { |
|
727 // case EMemSpyClientServerOpSummaryInfo: |
|
728 // iEngine.HelperProcess().OutputProcessInfoL( *process ); |
|
729 // break; |
|
730 // case EMemSpyClientServerOpSummaryInfoDetailed: |
|
731 // iEngine.HelperProcess().OutputProcessInfoDetailedL( *process ); |
|
732 // break; |
|
733 // case EMemSpyClientServerOpHeapInfo: |
|
734 // if ( isKernel ) |
|
735 // { |
|
736 // iEngine.HelperHeap().OutputHeapInfoKernelL(); |
|
737 // } |
|
738 // else |
|
739 // { |
|
740 // iEngine.HelperHeap().OutputHeapInfoUserL( *thread ); |
|
741 // } |
|
742 // break; |
|
743 // case EMemSpyClientServerOpHeapCellListing: |
|
744 // iEngine.HelperHeap().OutputCellListingUserL( *thread ); |
|
745 // break; |
|
746 // case EMemSpyClientServerOpHeapData: |
|
747 // if ( isKernel ) |
|
748 // { |
|
749 // iEngine.HelperHeap().OutputHeapDataKernelL(); |
|
750 // } |
|
751 // else |
|
752 // { |
|
753 // iEngine.HelperHeap().OutputHeapDataUserL( *thread ); |
|
754 // } |
|
755 // break; |
|
756 // case EMemSpyClientServerOpStackInfo: |
|
757 // iEngine.HelperStack().OutputStackInfoL( *thread ); |
|
758 // break; |
|
759 // case EMemSpyClientServerOpStackDataUser: |
|
760 // iEngine.HelperStack().OutputStackDataL( *thread, EMemSpyDriverDomainUser, EFalse ); |
|
761 // break; |
|
762 // case EMemSpyClientServerOpStackDataKernel: |
|
763 // iEngine.HelperStack().OutputStackDataL( *thread, EMemSpyDriverDomainKernel, EFalse ); |
|
764 // break; |
|
765 // case EMemSpyClientServerOpOpenFiles: |
|
766 // iEngine.HelperFileSystem().ListOpenFilesL( aThreadId ); |
|
767 // break; |
|
768 // |
|
769 // default: |
|
770 // error = KErrNotSupported; |
|
771 // break; |
|
772 // } |
|
773 // } |
|
774 // |
|
775 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadSpecificOpL() - END - aFunction: %d, aThreadId: %d, error: %d", aFunction, (TUint) aThreadId, error ) ); |
|
776 // User::LeaveIfError( error ); |
|
777 } |
|
778 |
|
779 // --------------------------------------------------------- |
|
780 // HandleThreadSpecificOpL( TInt aFunction, const TDesC& aThreadName ) |
|
781 // Gets thread ID from aThreadName |
|
782 // and calls HandleThreadSpecificOpL( , const TThreadId& aThreadId ) |
|
783 // --------------------------------------------------------- |
|
784 // |
|
785 void CMemSpyServerSession::HandleThreadSpecificOpL( TInt aFunction, const TDesC& aThreadName ) |
|
786 { |
|
787 // TRACE( RDebug::Print( _L("[MemSpy] CMemSpyServerSession::HandleThreadSpecificOpL() - START - aFunction: %d, aThreadName: %S"), aFunction, &aThreadName ) ); |
|
788 // // |
|
789 // CMemSpyProcess* process = NULL; |
|
790 // CMemSpyThread* thread = NULL; |
|
791 // TInt error = iEngine.Container().ProcessAndThreadByPartialName( aThreadName, process, thread ); |
|
792 // User::LeaveIfError( error ); |
|
793 // // |
|
794 // const TThreadId threadId( thread->Id() ); |
|
795 // HandleThreadSpecificOpL( aFunction, threadId ); |
|
796 // // |
|
797 // TRACE( RDebug::Print( _L("[MemSpy] CMemSpyServerSession::HandleThreadSpecificOpL() - END - aFunction: %d, aThreadName: %S"), aFunction, &aThreadName ) ); |
|
798 } |
|
799 |
|
800 // --------------------------------------------------------- |
|
801 // HandleThreadAgnosticOpL( TInt aFunction, const RMessage2& aMessage ) |
|
802 // --------------------------------------------------------- |
|
803 // |
|
804 void CMemSpyServerSession::HandleThreadAgnosticOpL( TInt aFunction, const RMessage2& aMessage ) |
|
805 { |
|
806 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - START" ) ); |
|
807 // // |
|
808 // if ( aFunction == EMemSpyClientServerOpHeapInfoCompact ) |
|
809 // { |
|
810 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpHeapInfoCompact") ); |
|
811 // iEngine.HelperHeap().OutputHeapInfoForDeviceL(); |
|
812 // } |
|
813 // else if ( aFunction == EMemSpyClientServerOpStackInfoCompact ) |
|
814 // { |
|
815 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpStackInfoCompact") ); |
|
816 // iEngine.HelperStack().OutputStackInfoForDeviceL(); |
|
817 // } |
|
818 // else if ( aFunction == EMemSpyClientServerOpSystemWideMemoryTrackingTimerStart ) |
|
819 // { |
|
820 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpSystemWideMemoryTrackingTimerStart") ); |
|
821 // iEngine.HelperSysMemTracker().StartL(); |
|
822 // } |
|
823 // else if ( aFunction == EMemSpyClientServerOpSystemWideMemoryTrackingTimerStop ) |
|
824 // { |
|
825 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpSystemWideMemoryTrackingTimerStop") ); |
|
826 // iEngine.HelperSysMemTracker().StopL(); |
|
827 // } |
|
828 // else if ( aFunction == EMemSpyClientServerOpSystemWideMemoryTrackingReset ) |
|
829 // { |
|
830 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpSystemWideMemoryTrackingReset") ); |
|
831 // iEngine.HelperSysMemTracker().Reset(); |
|
832 // } |
|
833 // else if ( aFunction == EMemSpyClientServerOpSystemWideMemoryTrackingForceUpdate ) |
|
834 // { |
|
835 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpSystemWideMemoryTrackingForceUpdate") ); |
|
836 // iEngine.HelperSysMemTracker().CheckForChangesNowL(); |
|
837 // } |
|
838 // else if ( aFunction == EMemSpyClientServerOpSystemWideMemoryTrackingTimerPeriodSet ) |
|
839 // { |
|
840 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpSystemWideMemoryTrackingTimerPeriodSet") ); |
|
841 // |
|
842 // // Get current config |
|
843 // TMemSpyEngineHelperSysMemTrackerConfig config; |
|
844 // iEngine.HelperSysMemTracker().GetConfig( config ); |
|
845 // |
|
846 // // Set new timer value |
|
847 // config.iTimerPeriod = aMessage.Int0(); |
|
848 // |
|
849 // // And update config... which will leave if the config is invalid |
|
850 // iEngine.HelperSysMemTracker().SetConfigL( config ); |
|
851 // } |
|
852 // else if ( aFunction == EMemSpyClientServerOpSystemWideMemoryTrackingCategoriesSet ) |
|
853 // { |
|
854 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpSystemWideMemoryTrackingCategoriesSet") ); |
|
855 // // Get current config |
|
856 // TMemSpyEngineHelperSysMemTrackerConfig config; |
|
857 // iEngine.HelperSysMemTracker().GetConfig( config ); |
|
858 // |
|
859 // // Set new categories |
|
860 // config.iEnabledCategories = aMessage.Int0(); |
|
861 // |
|
862 // // And update config... which will leave if the config is invalid |
|
863 // iEngine.HelperSysMemTracker().SetConfigL( config ); |
|
864 // } |
|
865 // else if ( aFunction == EMemSpyClientServerOpSystemWideMemoryTrackingThreadNameFilterSet ) |
|
866 // { |
|
867 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpSystemWideMemoryTrackingThreadNameFilterSet") ); |
|
868 // // Get current config |
|
869 // TMemSpyEngineHelperSysMemTrackerConfig config; |
|
870 // iEngine.HelperSysMemTracker().GetConfig( config ); |
|
871 // |
|
872 // // Set new filter |
|
873 // RBuf buf; |
|
874 // buf.CleanupClosePushL(); |
|
875 // TInt len = aMessage.GetDesLength( 0 ); |
|
876 // if ( len > 0 ) |
|
877 // { |
|
878 // buf.CreateL( len ); |
|
879 // aMessage.ReadL( 0, buf, 0 ); |
|
880 // config.iThreadNameFilter.Copy( buf ); |
|
881 // } |
|
882 // else |
|
883 // { |
|
884 // config.iThreadNameFilter.Zero(); |
|
885 // } |
|
886 // CleanupStack::PopAndDestroy( &buf ); |
|
887 // |
|
888 // // And update config... which will leave if the config is invalid |
|
889 // iEngine.HelperSysMemTracker().SetConfigL( config ); |
|
890 // } |
|
891 // else if ( aFunction == EMemSpyClientServerOpSystemWideMemoryTrackingHeapDumpSet ) |
|
892 // { |
|
893 // // Get current config |
|
894 // TMemSpyEngineHelperSysMemTrackerConfig config; |
|
895 // iEngine.HelperSysMemTracker().GetConfig( config ); |
|
896 // |
|
897 // // Set new Heap Dump value |
|
898 // config.iDumpData = aMessage.Int0(); |
|
899 // |
|
900 // // And update config... which will leave if the config is invalid |
|
901 // iEngine.HelperSysMemTracker().SetConfigL( config ); |
|
902 // } |
|
903 // else if ( aFunction == EMemSpyClientServerOpSwitchOutputSinkTrace ) |
|
904 // { |
|
905 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpSwitchOutputSinkTrace") ); |
|
906 // iEngine.InstallSinkL( ESinkTypeDebug ); |
|
907 // } |
|
908 // else if ( aFunction == EMemSpyClientServerOpSwitchOutputSinkFile ) |
|
909 // { |
|
910 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpSwitchOutputSinkFile") ); |
|
911 // iEngine.InstallSinkL( ESinkTypeFile ); |
|
912 // } |
|
913 // else if ( aFunction == EMemSpyClientServerOpEnumerateKernelContainer ) |
|
914 // { |
|
915 // const TMemSpyDriverContainerType type = CMemSpyEngineHelperKernelContainers::MapToType( static_cast< TObjectType >( aMessage.Int0() ) ); |
|
916 // |
|
917 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpEnumerateKernelContainer - type: %d", type ) ); |
|
918 // |
|
919 // CMemSpyEngineGenericKernelObjectList* model = iEngine.HelperKernelContainers().ObjectsForSpecificContainerL( type ); |
|
920 // CleanupStack::PushL( model ); |
|
921 // model->OutputL( iEngine.Sink() ); |
|
922 // CleanupStack::PopAndDestroy( model ); |
|
923 // } |
|
924 // else if ( aFunction == EMemSpyClientServerOpEnumerateKernelContainerAll ) |
|
925 // { |
|
926 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpEnumerateKernelContainerAll") ); |
|
927 // CMemSpyEngineGenericKernelObjectContainer* model = iEngine.HelperKernelContainers().ObjectsAllL(); |
|
928 // CleanupStack::PushL( model ); |
|
929 // model->OutputL( iEngine.Sink() ); |
|
930 // CleanupStack::PopAndDestroy( model ); |
|
931 // } |
|
932 // else if ( aFunction == EMemSpyClientServerOpOpenFiles ) |
|
933 // { |
|
934 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpOpenFiles") ); |
|
935 // iEngine.ListOpenFilesL(); |
|
936 // } |
|
937 // else if ( aFunction == EMemSpyClientServerOpDisableAknIconCache ) |
|
938 // { |
|
939 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - EMemSpyClientServerOpDisableAknIconCache") ); |
|
940 // iEngine.HelperRAM().SetAknIconCacheStatusL( EFalse ); |
|
941 // } |
|
942 // else |
|
943 // { |
|
944 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - [device-wide operation] => invoking UI") ); |
|
945 // iEngine.NotifyClientServerOperationRequestL( aFunction ); |
|
946 // } |
|
947 // // |
|
948 // TRACE( RDebug::Printf("[MemSpy] CMemSpyServerSession::HandleThreadAgnosticOpL() - END" ) ); |
|
949 } |