private void KillActiveGdbServerSessions()
{
LoggingUtils.PrintFunction ();
//
// Killing GDB server instances requires use of run-as [package-name],
// but it's very difficult to get the parent package of lib/gdbserver as the PPID
// will always refer to the zygote. This hack uses the sand-boxed 'user' to try all combinations.
//
m_gdbSetup.Process.HostDevice.Refresh ();
uint [] activeDevicePids = m_gdbSetup.Process.HostDevice.GetActivePids ();
List <AndroidProcess> activeGdbProcesses = new List<AndroidProcess> ();
foreach (uint pid in activeDevicePids)
{
AndroidProcess process = m_gdbSetup.Process.HostDevice.GetProcessFromPid (pid);
if (process.Name.Contains ("lib/gdbserver"))
{
activeGdbProcesses.Add (process);
}
}
foreach (AndroidProcess gdbProcess in activeGdbProcesses)
{
foreach (uint pid in activeDevicePids)
{
AndroidProcess process = m_gdbSetup.Process.HostDevice.GetProcessFromPid (pid);
if ((gdbProcess != process) && (gdbProcess.User.Equals (process.User)))
{
LoggingUtils.Print (string.Format ("[GdbServer] Attempting to terminate existing GDB debugging session: {0} ({1}).", gdbProcess.Name, gdbProcess.Pid));
m_gdbSetup.Process.HostDevice.Shell ("run-as", string.Format ("{0} kill -9 {1}", process.Name, gdbProcess.Pid));
}
}
}
}