14 // Purpose: The DProcessTracker object tracks which processes are being |
14 // Purpose: The DProcessTracker object tracks which processes are being |
15 // debugged. The DProcessTracker class uses a DTargetProcess object for |
15 // debugged. The DProcessTracker class uses a DTargetProcess object for |
16 // each process being debugged. |
16 // each process being debugged. |
17 // Note: Although TheDProcessTracker object is a global, it should be unique |
17 // Note: Although TheDProcessTracker object is a global, it should be unique |
18 // as only the Debug Security Server should load and use this driver. |
18 // as only the Debug Security Server should load and use this driver. |
19 // |
19 // |
20 // |
20 // |
21 |
21 |
22 #include <e32def.h> |
22 #include <e32def.h> |
23 #include <e32def_private.h> |
23 #include <e32def_private.h> |
24 #include <e32cmn.h> |
24 #include <e32cmn.h> |
99 // Returns a pointer to the DDebugAgent with aAgentId. |
99 // Returns a pointer to the DDebugAgent with aAgentId. |
100 // If the agent is not in the list, it returns NULL. |
100 // If the agent is not in the list, it returns NULL. |
101 DDebugAgent* DTargetProcess::Agent(TUint64 aAgentId) |
101 DDebugAgent* DTargetProcess::Agent(TUint64 aAgentId) |
102 { |
102 { |
103 for(TInt i = 0; i < iAgentList.Count(); i++) |
103 for(TInt i = 0; i < iAgentList.Count(); i++) |
104 { |
104 { |
105 if (iAgentList[i]->Id() == aAgentId) |
105 if (iAgentList[i]->Id() == aAgentId) |
106 { |
106 { |
107 return iAgentList[i]; |
107 return iAgentList[i]; |
108 } |
108 } |
109 } |
109 } |
110 |
110 |
111 // what do we return if we don't have any agents? |
111 // what do we return if we don't have any agents? |
112 return NULL; |
112 return NULL; |
113 } |
113 } |
114 |
114 |
115 // Adds aAgentId as a tracking agent for this process. |
115 // Adds aAgentId as a tracking agent for this process. |
116 TInt DTargetProcess::AddAgent(TUint64 aAgentId) |
116 TInt DTargetProcess::AddAgent(TUint64 aAgentId) |
117 { |
117 { |
118 LOG_MSG("DTargetProcess::AddAgent()"); |
118 |
119 DDebugAgent* agent = DDebugAgent::New(aAgentId); |
119 DDebugAgent* agent = DDebugAgent::New(aAgentId); |
|
120 LOG_MSG4("DTargetProcess::AddAgent(), agentId=%d, curr iAgentList.Count=%d, new agent=0x%08x", |
|
121 I64LOW(aAgentId), iAgentList.Count(), agent ); |
|
122 |
120 if(agent == NULL) |
123 if(agent == NULL) |
121 { |
124 { |
122 LOG_MSG("DTargetProcess::AddAgent() couldn't allocate memory for DDebugAgent"); |
125 LOG_MSG("DTargetProcess::AddAgent() couldn't allocate memory for DDebugAgent"); |
123 return KErrNoMemory; |
126 return KErrNoMemory; |
124 } |
127 } |
170 TInt err2 = ResumeFrozenThread(aThread->iNThread); |
173 TInt err2 = ResumeFrozenThread(aThread->iNThread); |
171 LOG_MSG2("DTargetProcess::ResumeFrozenThread(): ret=%d)", err2); |
174 LOG_MSG2("DTargetProcess::ResumeFrozenThread(): ret=%d)", err2); |
172 //if resuming the suspended thread failed for an obscure reason return it |
175 //if resuming the suspended thread failed for an obscure reason return it |
173 if((err1 != KErrNotFound) && (err1 != KErrNone)) |
176 if((err1 != KErrNotFound) && (err1 != KErrNone)) |
174 { |
177 { |
175 LOG_MSG2("DTargetProcess::ResumeThread() unexpected exit, err1: %d", err1); |
178 LOG_MSG2("DTargetProcess::ResumeThread() BUG : unexpected exit, err1: %d", err1); |
176 return err1; |
179 return err1; |
177 } |
180 } |
178 //if resuming the frozen thread failed for an obscure reason return it |
181 //if resuming the frozen thread failed for an obscure reason return it |
179 if((err2 != KErrNotFound) && (err2 != KErrNone)) |
182 if((err2 != KErrNotFound) && (err2 != KErrNone)) |
180 { |
183 { |
181 LOG_MSG2("DTargetProcess::ResumeThread() unexpected exit, err2: %d", err2); |
184 LOG_MSG2("DTargetProcess::ResumeThread() BUG : unexpected exit, err2: %d", err2); |
182 return err2; |
185 return err2; |
183 } |
186 } |
184 // if resuming the suspended thread succeeded in both cases, we have a consistency problem |
187 // if resuming the suspended thread succeeded in both cases, we have a consistency problem |
185 if ((err1 == KErrNone) && (err2 == KErrNone)) |
188 if ((err1 == KErrNone) && (err2 == KErrNone)) |
186 { |
189 { |
187 LOG_MSG("DTargetProcess::ResumeThread() unexpected exit, err1 == err2 == KErrNone"); |
190 LOG_MSG("DTargetProcess::ResumeThread() BUG : unexpected exit, err1 == err2 == KErrNone"); |
188 } |
191 } |
189 |
192 |
190 //if the thread was in neither list return KErrNotFound, otherwise KErrNone |
193 //if the thread was in neither list return KErrNotFound, otherwise KErrNone |
191 return ((err1 == KErrNone) || (err2 == KErrNone)) ? KErrNone : KErrNotFound; |
194 return ((err1 == KErrNone) || (err2 == KErrNone)) ? KErrNone : KErrNotFound; |
192 } |
195 } |
230 for(TInt i=0; i<iSuspendedThreads.Count(); i++) |
233 for(TInt i=0; i<iSuspendedThreads.Count(); i++) |
231 { |
234 { |
232 if(iSuspendedThreads[i] == threadId) |
235 if(iSuspendedThreads[i] == threadId) |
233 { |
236 { |
234 iSuspendedThreads.Remove(i); |
237 iSuspendedThreads.Remove(i); |
235 LOG_MSG2("DTargetProcess::ResumeSuspendedThread()> Kern::ThreadResume() 0x%x", aThread); |
238 LOG_MSG2("DTargetProcess::ResumeSuspendedThread()> Kern::ThreadResume() 0x%08x", aThread); |
236 Kern::ThreadResume(*aThread); |
239 Kern::ThreadResume(*aThread); |
237 return KErrNone; |
240 return KErrNone; |
238 } |
241 } |
239 } |
242 } |
240 return KErrNotFound; |
243 return KErrNotFound; |
290 // create and store a fast semaphore to stop the thread on |
293 // create and store a fast semaphore to stop the thread on |
291 NKern::ThreadEnterCS(); |
294 NKern::ThreadEnterCS(); |
292 NFastSemaphore* sem = new NFastSemaphore(); |
295 NFastSemaphore* sem = new NFastSemaphore(); |
293 NKern::ThreadLeaveCS(); |
296 NKern::ThreadLeaveCS(); |
294 sem->iOwningThread = &(Kern::CurrentThread().iNThread); |
297 sem->iOwningThread = &(Kern::CurrentThread().iNThread); |
295 LOG_EVENT_MSG2("DTargetProcess::FreezeThread(): new NFastSemaphore() curr thread=0x%x", sem->iOwningThread); |
298 LOG_MSG3("DTargetProcess::FreezeThread(): new NFastSemaphore() owning thread==curr NThread=0x%08x, DThread=0x%08x", |
|
299 sem->iOwningThread, &(Kern::CurrentThread()) ); |
296 return iFrozenThreadSemaphores.Append(sem); |
300 return iFrozenThreadSemaphores.Append(sem); |
297 } |
301 } |
298 |
302 |
299 /** |
303 /** |
300 Suspend the specified thread |
304 Suspend the specified thread |
339 as it needs to be FSSignal()'d by another thread to resume |
344 as it needs to be FSSignal()'d by another thread to resume |
340 again. |
345 again. |
341 */ |
346 */ |
342 void DTargetProcess::FSWait() |
347 void DTargetProcess::FSWait() |
343 { |
348 { |
344 LOG_MSG2("DTargetProcess::NotifyEvent(): number of attached agents: %d", AgentCount()); |
349 NThread* currentNThread = &(Kern::CurrentThread().iNThread); |
345 NThread* currentThread = &(Kern::CurrentThread().iNThread); |
|
346 for(TInt i=0; i<iFrozenThreadSemaphores.Count(); i++) |
350 for(TInt i=0; i<iFrozenThreadSemaphores.Count(); i++) |
347 { |
351 { |
348 if(iFrozenThreadSemaphores[i]->iOwningThread == currentThread) |
352 if(iFrozenThreadSemaphores[i]->iOwningThread == currentNThread) |
349 { |
353 { |
350 LOG_MSG3("DTargetProcess::FSWait(): > FSWait frozen sem %d, curr thread=0x%x", i, currentThread); |
354 LOG_MSG4("DTargetProcess::FSWait(): > FSWait frozen sem %d, currentNThread=0x%08x, id=0x%x", |
|
355 i, currentNThread, Kern::CurrentThread().iId ); |
351 NKern::FSWait(iFrozenThreadSemaphores[i]); |
356 NKern::FSWait(iFrozenThreadSemaphores[i]); |
352 return; |
357 return; |
353 } |
358 } |
354 } |
359 } |
355 } |
360 } |
397 } |
402 } |
398 |
403 |
399 void DTargetProcess::NotifyEvent(const TDriverEventInfo& aEventInfo) |
404 void DTargetProcess::NotifyEvent(const TDriverEventInfo& aEventInfo) |
400 { |
405 { |
401 // Stuff the event info into all the tracking agents event queues |
406 // Stuff the event info into all the tracking agents event queues |
402 LOG_MSG2("DTargetProcess::NotifyEvent(): number of attached agents: %d", AgentCount()); |
407 LOG_MSG4("DTargetProcess::NotifyEvent(): num attached agents: %d, iEventType=%d, this=0x%08x", |
|
408 AgentCount(), aEventInfo.iEventType, this); |
403 |
409 |
404 for(TInt i = 0; i < AgentCount(); i++) |
410 for(TInt i = 0; i < AgentCount(); i++) |
405 { |
411 { |
406 // Index through all the relevant debug agents |
412 // Index through all the relevant debug agents |
407 DDebugAgent* debugAgent = iAgentList[i]; |
413 DDebugAgent* debugAgent = iAgentList[i]; |