74 DTargetProcess* tmpProcess = new DTargetProcess; |
74 DTargetProcess* tmpProcess = new DTargetProcess; |
75 if (tmpProcess == 0) |
75 if (tmpProcess == 0) |
76 { |
76 { |
77 return KErrNoMemory; |
77 return KErrNoMemory; |
78 } |
78 } |
79 |
79 LOG_MSG2(" AttachProcess: < new DTargetProcess=0x%08x", tmpProcess ); |
|
80 |
80 // Set the name |
81 // Set the name |
81 TInt err = KErrNone; |
82 TInt err = KErrNone; |
82 err = tmpProcess->SetProcessName(aProcessName); |
83 err = tmpProcess->SetProcessName(aProcessName); |
83 if (err != KErrNone) |
84 if (err != KErrNone) |
84 { |
85 { |
|
86 LOG_MSG2(" AttachProcess: < SetProcessName returned %d", err ); |
85 return err; |
87 return err; |
86 } |
88 } |
87 |
89 |
88 // Is this process being debugged (ie already attached?) |
90 // Is this process being debugged (ie already attached?) |
89 TInt index; |
91 TInt index; |
90 TBool found = EFalse; |
92 TBool found = EFalse; |
91 for(index=0;index<iProcesses.Count();index++) |
93 |
|
94 TInt numberOfProcesses = iProcesses.Count(); |
|
95 for(index=0; index<numberOfProcesses; index++) |
92 { |
96 { |
93 const TPtr8& tmpPtr8(iProcesses[index]->ProcessName() ); |
97 const TPtr8& tmpPtr8(iProcesses[index]->ProcessName() ); |
94 |
98 |
95 if ( tmpPtr8.CompareF(aProcessName) == 0) |
99 if ( tmpPtr8.CompareF(aProcessName) == 0) |
96 { |
100 { |
|
101 LOG_MSG3(" Proc count=%d, found proc in iProcesses at %d. Count=%d", |
|
102 index, iProcesses.Count() ); |
97 found = ETrue; |
103 found = ETrue; |
98 break; |
104 break; |
99 } |
105 } |
100 } |
106 } |
101 |
107 |
102 if (found) |
108 if (found) |
103 { |
109 { |
104 // Yes, it is being debugged |
110 // Yes, it is being debugged |
105 |
111 |
106 // Add the agent to the list of agents for this process |
112 // Add the agent to the list of agents for this process |
|
113 LOG_MSG3(" > AddAgent(agent id %d) to existing iProcesses[%d]", I64LOW(aAgentId), index ); |
|
114 |
107 iProcesses[index]->AddAgent(aAgentId); |
115 iProcesses[index]->AddAgent(aAgentId); |
108 |
116 |
109 return KErrNone; |
117 return KErrNone; |
110 } |
118 } |
111 else |
119 else |
112 { |
120 { |
113 // No, it is not being debugged |
121 // No, it is not being debugged |
114 |
122 |
115 // Add the agent to the list of agents for this process |
123 // Add the agent to the list of agents for this process |
|
124 LOG_MSG2(" > AddAgent(agent %d) to new proc at index 0", I64LOW(aAgentId) ); |
|
125 |
116 tmpProcess->AddAgent(aAgentId); |
126 tmpProcess->AddAgent(aAgentId); |
117 |
127 |
118 // Add the process to the list of processes being debugged |
128 // Add the process to the list of processes being debugged |
119 return iProcesses.Insert(tmpProcess,0); |
129 return iProcesses.Insert(tmpProcess,0); |
120 } |
130 } |
141 |
151 |
142 // Are we debugging this process? |
152 // Are we debugging this process? |
143 TInt i; |
153 TInt i; |
144 TBool found = EFalse; |
154 TBool found = EFalse; |
145 DTargetProcess* foundProcess = 0; |
155 DTargetProcess* foundProcess = 0; |
146 for(i=0;i<iProcesses.Count();i++) |
156 |
|
157 TInt numberOfProcesses = iProcesses.Count(); |
|
158 for(i=0; i<numberOfProcesses; i++) |
147 { |
159 { |
148 foundProcess = iProcesses[i]; |
160 foundProcess = iProcesses[i]; |
149 |
161 |
150 const TPtr8& tmpPtr8( foundProcess->ProcessName() ); |
162 const TPtr8& tmpPtr8( foundProcess->ProcessName() ); |
151 |
163 |
184 * from the debug security server and has not supplied a specific process name from which to detach. |
196 * from the debug security server and has not supplied a specific process name from which to detach. |
185 */ |
197 */ |
186 TInt DProcessTracker::DetachAgent(const TUint64 aAgentId) |
198 TInt DProcessTracker::DetachAgent(const TUint64 aAgentId) |
187 { |
199 { |
188 // Remove this agent from all the processes being tracked. |
200 // Remove this agent from all the processes being tracked. |
189 for(TInt i=0;i<iProcesses.Count();i++) |
201 TInt numberOfProcesses = iProcesses.Count(); |
|
202 for(TInt i=0; i<numberOfProcesses; i++) |
190 { |
203 { |
191 // remove the agent from the process (we don't care about the return code) |
204 // remove the agent from the process (we don't care about the return code) |
192 iProcesses[i]->RemoveAgent(aAgentId); |
205 iProcesses[i]->RemoveAgent(aAgentId); |
193 } |
206 } |
194 |
207 |
224 { |
237 { |
225 // Valid ProcessName? |
238 // Valid ProcessName? |
226 if (aProcessName.Length() < 1 || aProcessName.Length() >= KMaxPath) |
239 if (aProcessName.Length() < 1 || aProcessName.Length() >= KMaxPath) |
227 { |
240 { |
228 return 0; // not found |
241 return 0; // not found |
229 }; |
242 } |
230 |
243 |
231 // Can we find this in the array? |
244 // Can we find this in the array? |
232 TInt i; |
245 TInt i; |
233 TBool found = EFalse; |
246 TBool found = EFalse; |
234 DTargetProcess* foundProcess = 0; |
247 DTargetProcess* foundProcess = 0; |
235 for(i=0;i<iProcesses.Count();i++) |
248 |
|
249 TInt numberOfProcesses = iProcesses.Count(); |
|
250 for(i=0; i<numberOfProcesses; i++) |
236 { |
251 { |
237 foundProcess = iProcesses[i]; |
252 foundProcess = iProcesses[i]; |
238 |
253 |
239 const TPtr8& tmpPtr8( foundProcess->ProcessName() ); |
254 const TPtr8& tmpPtr8( foundProcess->ProcessName() ); |
240 |
255 |
270 * @return DTargetProcess* pointer to an object representing the internal mapping of a process to all associated |
286 * @return DTargetProcess* pointer to an object representing the internal mapping of a process to all associated |
271 * debug agents. Returns 0 if the mapping cannot be found or the aProcessName is invalid. |
287 * debug agents. Returns 0 if the mapping cannot be found or the aProcessName is invalid. |
272 */ |
288 */ |
273 DTargetProcess* DProcessTracker::FuzzyFindProcess(const TDesC8& aProcessName) |
289 DTargetProcess* DProcessTracker::FuzzyFindProcess(const TDesC8& aProcessName) |
274 { |
290 { |
275 |
|
276 // Valid ProcessName? |
291 // Valid ProcessName? |
277 if (aProcessName.Length() < 1 || aProcessName.Length() >= KMaxPath) |
292 if (aProcessName.Length() < 1 || aProcessName.Length() >= KMaxPath) |
278 { |
293 { |
279 return 0; // not found |
294 return 0; // not found |
280 }; |
295 } |
281 |
296 |
282 // Can we find this in the array? |
297 // Can we find this in the array? |
283 TInt i; |
|
284 TBool found = EFalse; |
298 TBool found = EFalse; |
285 DTargetProcess* foundProcess = 0; |
299 DTargetProcess* foundProcess = 0; |
286 for(i=0;i<iProcesses.Count();i++) |
300 const TChar KBackSlash('\\'); |
|
301 |
|
302 TInt numberOfProcesses = iProcesses.Count(); |
|
303 for(TInt i=0; i < numberOfProcesses; i++) |
287 { |
304 { |
288 foundProcess = iProcesses[i]; |
305 foundProcess = iProcesses[i]; |
289 |
306 |
290 const TPtr8& tmpPtr8( foundProcess->ProcessName() ); |
307 TInt procListBackSlash = foundProcess->ProcessName().LocateReverse( KBackSlash ); |
291 |
308 if( procListBackSlash == KErrNotFound ) |
292 if ( tmpPtr8.CompareF(aProcessName) == 0) |
309 { |
293 { |
310 procListBackSlash = 0; |
|
311 } |
|
312 else |
|
313 { |
|
314 //Now move to the char after the backlash |
|
315 procListBackSlash++; |
|
316 } |
|
317 |
|
318 TInt eventBackSlash = aProcessName.LocateReverse( KBackSlash ); |
|
319 if( eventBackSlash == KErrNotFound ) |
|
320 { |
|
321 eventBackSlash = 0; |
|
322 } |
|
323 else |
|
324 { |
|
325 //Now move to the char after the backlash |
|
326 eventBackSlash++; |
|
327 } |
|
328 |
|
329 if( ( procListBackSlash == 0 ) && ( eventBackSlash == 0 ) ) |
|
330 { |
|
331 //There were no backslashes on either name, so no point in continuing |
|
332 break; |
|
333 } |
|
334 |
|
335 TPtrC8 eventCleanName( aProcessName.Mid( eventBackSlash ) ); |
|
336 TPtrC8 procListCleanName( foundProcess->ProcessName().Mid( procListBackSlash ) ); |
|
337 |
|
338 if ( eventCleanName.CompareF( procListCleanName ) == 0 ) |
|
339 { |
|
340 LOG_MSG2("DProcessTracker::FuzzyFindProcess() found a match : process list[%d]", i ); |
294 found = ETrue; |
341 found = ETrue; |
295 break; |
342 break; |
296 } |
|
297 else |
|
298 { |
|
299 // need to compare centre of this string |
|
300 // |
|
301 // e.g. |
|
302 // z:\sys\bin\foobar.exe |
|
303 // might be seen as: |
|
304 // foobar.exe |
|
305 // |
|
306 // Algorithm is start at the right side of foundProcess->ProcessName |
|
307 // move left until we have some backslash, then finish. |
|
308 TInt right= tmpPtr8.Size() - 1; |
|
309 TInt left = right; |
|
310 |
|
311 // search for the rightmost backslash |
|
312 while(left > 0) |
|
313 { |
|
314 if(tmpPtr8[left] == (TUint8)'\\') |
|
315 break; |
|
316 |
|
317 --left; // move left one character |
|
318 } |
|
319 // now we have |
|
320 // left = index of rightmost backslash in foundProcess->ProcessName() |
|
321 // right = index of rightmost character in foundProcess->ProcessName() |
|
322 |
|
323 // We must expect that the size of names matches |
|
324 TInt foundSize = right - left; // == sizeof("foobar.exe") |
|
325 TInt suppliedSize = aProcessName.Size(); |
|
326 |
|
327 if (foundSize != suppliedSize) |
|
328 { |
|
329 // must be something else |
|
330 break; |
|
331 } |
|
332 |
|
333 for(TInt i=0;i< foundSize;i++) |
|
334 { |
|
335 if (tmpPtr8[left+i] != aProcessName[1+i]) |
|
336 { |
|
337 break; |
|
338 } |
|
339 } |
|
340 // All the characters match if we get here |
|
341 found = ETrue; |
|
342 } |
343 } |
343 } |
344 } |
344 |
345 |
345 if (found == EFalse) |
346 if (found == EFalse) |
346 { |
347 { |