[Lldb-commits] [lldb] r115184 - in /lldb/trunk/tools/debugserver/source/MacOSX: MachTask.cpp MachTask.h

Greg Clayton gclayton at apple.com
Thu Sep 30 11:10:44 PDT 2010


Author: gclayton
Date: Thu Sep 30 13:10:44 2010
New Revision: 115184

URL: http://llvm.org/viewvc/llvm-project?rev=115184&view=rev
Log:
Retry task_for_pid a few times to avoid some cases where task_for_pid fails.


Modified:
    lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachTask.h

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp?rev=115184&r1=115183&r2=115184&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp Thu Sep 30 13:10:44 2010
@@ -214,29 +214,40 @@
 // MachTask::TaskPortForProcessID
 //----------------------------------------------------------------------
 task_t
-MachTask::TaskPortForProcessID (pid_t pid, DNBError &err)
+MachTask::TaskPortForProcessID (pid_t pid, DNBError &err, uint32_t num_retries, uint32_t usec_interval)
 {
-    task_t task = TASK_NULL;
-    if (pid != INVALID_NUB_PROCESS)
-    {
-        mach_port_t task_self = mach_task_self ();
-        err = ::task_for_pid ( task_self, pid, &task);
-        if (DNBLogCheckLogBit(LOG_TASK) || err.Fail())
-        {
-            char str[1024];
-            ::snprintf (str,
-                        sizeof(str),
-                        "::task_for_pid ( target_tport = 0x%4.4x, pid = %d, &task ) => err = 0x%8.8x (%s)",
-                        task_self,
-                        pid,
-                        err.Error(),
-                        err.AsString() ? err.AsString() : "success");
-            if (err.Fail())
-                err.SetErrorString(str);
-            err.LogThreaded(str);
-        }
-    }
-    return task;
+	if (pid != INVALID_NUB_PROCESS)
+	{
+		DNBError err;
+		mach_port_t task_self = mach_task_self ();	
+		task_t task = TASK_NULL;
+		for (uint32_t i=0; i<num_retries; i++)
+		{	
+			err = ::task_for_pid ( task_self, pid, &task);
+
+            if (DNBLogCheckLogBit(LOG_TASK) || err.Fail())
+            {
+                char str[1024];
+                ::snprintf (str,
+                            sizeof(str),
+                            "::task_for_pid ( target_tport = 0x%4.4x, pid = %d, &task ) => err = 0x%8.8x (%s)",
+                            task_self,
+                            pid,
+                            err.Error(),
+                            err.AsString() ? err.AsString() : "success");
+                if (err.Fail())
+                    err.SetErrorString(str);
+                err.LogThreaded(str);
+            }
+
+			if (err.Success())
+				return task;
+
+			// Sleep a bit and try again
+			::usleep (usec_interval);
+		}
+	}
+	return TASK_NULL;
 }
 
 

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachTask.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachTask.h?rev=115184&r1=115183&r2=115184&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachTask.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachTask.h Thu Sep 30 13:10:44 2010
@@ -66,7 +66,7 @@
     static  void *          ExceptionThread (void *arg);
             task_t          TaskPort () const { return m_task; }
             task_t          TaskPortForProcessID (DNBError &err);
-    static  task_t          TaskPortForProcessID (pid_t pid, DNBError &err);
+    static  task_t          TaskPortForProcessID (pid_t pid, DNBError &err, uint32_t num_retries = 10, uint32_t usec_interval = 10000);
 
             MachProcess *   Process () { return m_process; }
     const   MachProcess *   Process () const { return m_process; }





More information about the lldb-commits mailing list