kernel/eka/drivers/debug/rmdebug/d_process_tracker.cpp
branchRCL_3
changeset 81 e7d2d738d3c2
parent 0 a41df078684a
child 258 880ff05ad710
--- a/kernel/eka/drivers/debug/rmdebug/d_process_tracker.cpp	Fri Mar 12 15:50:11 2010 +0200
+++ b/kernel/eka/drivers/debug/rmdebug/d_process_tracker.cpp	Mon Mar 15 12:45:50 2010 +0200
@@ -76,24 +76,30 @@
 		{
 		return KErrNoMemory;
 		}
-
+	LOG_MSG2(" AttachProcess: < new DTargetProcess=0x%08x", tmpProcess );
+	
 	// Set the name
 	TInt err = KErrNone;
 	err = tmpProcess->SetProcessName(aProcessName);
 	if (err != KErrNone)
 		{
+		LOG_MSG2(" AttachProcess: < SetProcessName returned %d", err );
 		return err;
 		}
 
 	// Is this process being debugged (ie already attached?)
 	TInt index;
 	TBool found = EFalse;
-	for(index=0;index<iProcesses.Count();index++)
+	
+	TInt numberOfProcesses = iProcesses.Count();
+	for(index=0; index<numberOfProcesses; index++)
 		{
 		const TPtr8& tmpPtr8(iProcesses[index]->ProcessName() );
 
 		if ( tmpPtr8.CompareF(aProcessName) == 0)
 			{
+			LOG_MSG3(" Proc count=%d, found proc in iProcesses at %d. Count=%d",
+				index, iProcesses.Count() );
 			found = ETrue;
 			break;
 			}
@@ -104,6 +110,8 @@
 		// Yes, it is being debugged
 
 		// Add the agent to the list of agents for this process
+		LOG_MSG3(" > AddAgent(agent id %d) to existing iProcesses[%d]", I64LOW(aAgentId), index ); 
+
 		iProcesses[index]->AddAgent(aAgentId);
 
 		return KErrNone;
@@ -113,6 +121,8 @@
 		// No, it is not being debugged
 			
 		// Add the agent to the list of agents for this process
+		LOG_MSG2(" > AddAgent(agent %d) to new proc at index 0", I64LOW(aAgentId) ); 
+
 		tmpProcess->AddAgent(aAgentId);
 
 		// Add the process to the list of processes being debugged
@@ -143,7 +153,9 @@
 	TInt i;
 	TBool found = EFalse;
 	DTargetProcess* foundProcess = 0;
-	for(i=0;i<iProcesses.Count();i++)
+
+	TInt numberOfProcesses = iProcesses.Count();
+	for(i=0; i<numberOfProcesses; i++)
 		{
 		foundProcess = iProcesses[i];
 
@@ -186,7 +198,8 @@
 TInt DProcessTracker::DetachAgent(const TUint64 aAgentId)
 	{
 	// Remove this agent from all the processes being tracked.
-	for(TInt i=0;i<iProcesses.Count();i++)
+	TInt numberOfProcesses = iProcesses.Count();
+	for(TInt i=0; i<numberOfProcesses; i++)
 		{
 		// remove the agent from the process (we don't care about the return code)
 		iProcesses[i]->RemoveAgent(aAgentId);
@@ -226,13 +239,15 @@
 	if (aProcessName.Length() < 1 || aProcessName.Length() >= KMaxPath)
 		{
 		return 0;	// not found
-		};
+		}
 
 	// Can we find this in the array?
 	TInt i;
 	TBool found = EFalse;
 	DTargetProcess* foundProcess = 0;
-	for(i=0;i<iProcesses.Count();i++)
+
+	TInt numberOfProcesses = iProcesses.Count();
+	for(i=0; i<numberOfProcesses; i++)
 		{
 		foundProcess = iProcesses[i];
 
@@ -247,6 +262,7 @@
 
 	if (found == EFalse)
 		{
+		LOG_EVENT_MSG("DProcessTracker::FindProcess, not found" );
 		return 0;	// not found
 		}
 
@@ -272,73 +288,58 @@
  */
 DTargetProcess*	DProcessTracker::FuzzyFindProcess(const TDesC8& aProcessName)
 	{
-
 	// Valid ProcessName?
 	if (aProcessName.Length() < 1 || aProcessName.Length() >= KMaxPath)
 		{
 		return 0;	// not found
-		};
+		}
 
 	// Can we find this in the array?
-	TInt i;
 	TBool found = EFalse;
 	DTargetProcess* foundProcess = 0;
-	for(i=0;i<iProcesses.Count();i++)
+	const TChar KBackSlash('\\');
+
+	TInt numberOfProcesses = iProcesses.Count();
+	for(TInt i=0; i < numberOfProcesses; i++)
 		{
 		foundProcess = iProcesses[i];
 
-		const TPtr8& tmpPtr8( foundProcess->ProcessName() );
-
-		if ( tmpPtr8.CompareF(aProcessName) == 0)
+		TInt procListBackSlash = foundProcess->ProcessName().LocateReverse( KBackSlash );
+		if( procListBackSlash == KErrNotFound )
 			{
-			found = ETrue;
-			break;
+			procListBackSlash = 0;
 			}
 		else
 			{
-			// need to compare centre of this string
-			//
-			// e.g. 
-			//		z:\sys\bin\foobar.exe
-			// might be seen as:
-			//		foobar.exe
-			//
-			// Algorithm is start at the right side of foundProcess->ProcessName
-			// move left until we have some backslash, then finish.
-			TInt right= tmpPtr8.Size() - 1;
-			TInt left = right;
+			//Now move to the char after the backlash
+			procListBackSlash++;
+			}
+
+		TInt eventBackSlash = aProcessName.LocateReverse( KBackSlash );
+		if( eventBackSlash == KErrNotFound )
+			{
+			eventBackSlash = 0;
+			}
+		else
+			{
+			//Now move to the char after the backlash
+			eventBackSlash++;
+			}
 
-			// search for the rightmost backslash
-			while(left > 0)
-				{
-				if(tmpPtr8[left] == (TUint8)'\\')
-					break;
-				
-				--left;	// move left one character
-				}
-			// now we have
-			// left = index of rightmost backslash in foundProcess->ProcessName()
-			// right = index of rightmost character in foundProcess->ProcessName()
-
-			// We must expect that the size of names matches
-			TInt foundSize = right - left;	// == sizeof("foobar.exe")
-			TInt suppliedSize = aProcessName.Size();		
+		if( ( procListBackSlash == 0 ) && ( eventBackSlash == 0 ) )
+			{
+			//There were no backslashes on either name, so no point in continuing
+			break;
+			}
 
-			if (foundSize != suppliedSize)
-				{
-				// must be something else
-				break;
-				}
+		TPtrC8 eventCleanName( aProcessName.Mid( eventBackSlash ) );		
+		TPtrC8 procListCleanName( foundProcess->ProcessName().Mid( procListBackSlash ) );
 
-			for(TInt i=0;i< foundSize;i++)
-				{
-				if (tmpPtr8[left+i] != aProcessName[1+i])
-					{
-					break;
-					}
-				}
-			// All the characters match if we get here
+		if ( eventCleanName.CompareF( procListCleanName ) == 0 )
+			{
+			LOG_MSG2("DProcessTracker::FuzzyFindProcess() found a match : process list[%d]", i );
 			found = ETrue;
+			break;
 			}
 		}
 
@@ -360,7 +361,8 @@
 		}
 
 	//iterate through the processes trying to match the name, and check suspended if found
-	for(TInt i=0; i<iProcesses.Count(); i++)
+	TInt numberOfProcesses = iProcesses.Count();
+	for(TInt i=0; i < numberOfProcesses; i++)
 		{
 		if(iProcesses[i]->ProcessName().CompareF(*name) == 0)
 			{
@@ -407,7 +409,8 @@
 		}
 
 	//iterate through the processes trying to match the name, try to suspend the thread if found
-	for(TInt i=0; i<iProcesses.Count(); i++)
+	TInt numberOfProcesses = iProcesses.Count();
+	for(TInt i=0; i < numberOfProcesses; i++)
 		{
 		if(iProcesses[i]->ProcessName().CompareF(*name) == 0)
 			{
@@ -421,7 +424,8 @@
 
 void DProcessTracker::FSWait()
 	{
-	for(TInt i=0; i<iProcesses.Count(); i++)
+	TInt numberOfProcesses = iProcesses.Count();
+	for(TInt i=0; i < numberOfProcesses; i++)
 		{
 		iProcesses[i]->FSWait();
 		}
@@ -447,7 +451,8 @@
 		}
 
 	//iterate through the processes trying to match the name, try to resume the thread if found
-	for(TInt i=0; i<iProcesses.Count(); i++)
+	TInt numberOfProcesses = iProcesses.Count();
+	for(TInt i=0; i < numberOfProcesses; i++)
 		{
 		if(iProcesses[i]->ProcessName().CompareF(*name) == 0)
 			{