|
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 // Purpose: The DProcessTracker object tracks which processes are being |
|
15 // debugged. The DProcessTracker class uses a DTargetProcess object for |
|
16 // each process being debugged. |
|
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. |
|
19 // |
|
20 // |
|
21 |
|
22 #include <e32def.h> |
|
23 #include <e32def_private.h> |
|
24 #include <e32cmn.h> |
|
25 #include <e32cmn_private.h> |
|
26 #include <kernel/kernel.h> |
|
27 #include <kernel/kern_priv.h> |
|
28 #include "nk_priv.h" |
|
29 #include <rm_debug_api.h> |
|
30 |
|
31 #include "d_target_process.h" |
|
32 #include "debug_logging.h" |
|
33 #include "debug_utils.h" |
|
34 |
|
35 // ctor |
|
36 DTargetProcess::DTargetProcess() |
|
37 :iProcessName(NULL) |
|
38 { |
|
39 } |
|
40 |
|
41 // dtor |
|
42 DTargetProcess::~DTargetProcess() |
|
43 { |
|
44 delete iProcessName; |
|
45 iAgentList.ResetAndDestroy(); |
|
46 } |
|
47 |
|
48 // Compare two DTargetProcess items. They are the same if they have the same name. |
|
49 TInt DTargetProcess::Compare(const DTargetProcess& aFirst, const DTargetProcess& aSecond) |
|
50 { |
|
51 const TDesC& left = aFirst.iProcessName ? *aFirst.iProcessName : KNullDesC(); |
|
52 const TDesC& right = aSecond.iProcessName ? *aSecond.iProcessName : KNullDesC(); |
|
53 return left.Compare(right); |
|
54 } |
|
55 |
|
56 // Set the name of the process we are tracking |
|
57 TInt DTargetProcess::SetProcessName(const TDesC8& aProcessName) |
|
58 { |
|
59 // Argument checking |
|
60 if (aProcessName.Length() < 1) |
|
61 { |
|
62 return KErrArgument; |
|
63 } |
|
64 |
|
65 if (iProcessName) |
|
66 return KErrNotReady; // You can only set the processname once |
|
67 iProcessName = HBuf8::New(aProcessName); |
|
68 if (!iProcessName) |
|
69 return KErrNoMemory; |
|
70 return KErrNone; |
|
71 } |
|
72 |
|
73 // Obtain the name of the process being tracked |
|
74 const TDesC& DTargetProcess::ProcessName() const |
|
75 { |
|
76 return iProcessName ? *iProcessName : KNullDesC(); |
|
77 } |
|
78 |
|
79 // Returns a pointer to the DDebugAgent with aAgentId. |
|
80 // If the agent is not in the list, it returns NULL. |
|
81 DDebugAgent* DTargetProcess::Agent(TUint64 aAgentId) |
|
82 { |
|
83 for(TInt i = 0; i < iAgentList.Count(); i++) |
|
84 { |
|
85 if (iAgentList[i]->Id() == aAgentId) |
|
86 { |
|
87 return iAgentList[i]; |
|
88 } |
|
89 } |
|
90 |
|
91 // what do we return if we don't have any agents? |
|
92 return NULL; |
|
93 } |
|
94 |
|
95 // Adds aAgentId as a tracking agent for this process. |
|
96 TInt DTargetProcess::AddAgent(TUint64 aAgentId) |
|
97 { |
|
98 DDebugAgent* agent = DDebugAgent::New(aAgentId); |
|
99 LOG_MSG4("DTargetProcess::AddAgent(), agentId=%d, curr iAgentList.Count=%d, new agent=0x%08x", |
|
100 I64LOW(aAgentId), iAgentList.Count(), agent ); |
|
101 |
|
102 if(agent == NULL) |
|
103 { |
|
104 LOG_MSG("DTargetProcess::AddAgent() couldn't allocate memory for DDebugAgent"); |
|
105 return KErrNoMemory; |
|
106 } |
|
107 return iAgentList.Insert(agent,0); |
|
108 } |
|
109 |
|
110 // Stops tracking the process with this agent |
|
111 TInt DTargetProcess::RemoveAgent(TUint64 aAgentId) |
|
112 { |
|
113 // We need to find and then remove the agent |
|
114 for(TUint i = 0; i < iAgentList.Count(); i++) |
|
115 { |
|
116 if (iAgentList[i]->Id() == aAgentId) |
|
117 { |
|
118 LOG_MSG4("DTargetProcess::RemoveAgent(), deleting agent[%d], id 0x%x, address=0x%x", |
|
119 i, I64LOW(aAgentId), iAgentList[i]); |
|
120 delete iAgentList[i]; |
|
121 iAgentList.Remove(i); |
|
122 return KErrNone; |
|
123 } |
|
124 } |
|
125 |
|
126 return KErrNotFound; |
|
127 } |
|
128 |
|
129 // Index through the agents by position |
|
130 DDebugAgent* DTargetProcess::operator[](TInt aIndex) |
|
131 { |
|
132 return iAgentList[aIndex]; |
|
133 } |
|
134 |
|
135 // returns the number of agents tracking this process. |
|
136 TInt DTargetProcess::AgentCount() const |
|
137 { |
|
138 return iAgentList.Count(); |
|
139 } |
|
140 |
|
141 void DTargetProcess::NotifyEvent(const TDriverEventInfo& aEventInfo) |
|
142 { |
|
143 // Stuff the event info into all the tracking agents event queues |
|
144 LOG_MSG4("DTargetProcess::NotifyEvent(): num attached agents: %d, iEventType=%d, this=0x%08x", |
|
145 AgentCount(), aEventInfo.iEventType, this); |
|
146 |
|
147 for(TInt i = 0; i < AgentCount(); i++) |
|
148 { |
|
149 // Index through all the relevant debug agents |
|
150 DDebugAgent* debugAgent = iAgentList[i]; |
|
151 if(debugAgent != NULL) |
|
152 { |
|
153 debugAgent->NotifyEvent(aEventInfo); |
|
154 } |
|
155 } |
|
156 } |
|
157 |