[Lldb-commits] [lldb] r134686 - /lldb/trunk/tools/darwin-threads/examine-threads.c

Jason Molenda jmolenda at apple.com
Thu Jul 7 22:04:01 PDT 2011


Author: jmolenda
Date: Fri Jul  8 00:04:01 2011
New Revision: 134686

URL: http://llvm.org/viewvc/llvm-project?rev=134686&view=rev
Log:
Rewrite get_kinfo_proc_for_pid() to get the kinfo_proc for
the one process we're interested in, instead of fetching all
of them and only keeping one.

(the old implementation made sense when we were doing the
initial find-this-process-by-pid-or-name by looking through
all the kinfo_procs.)


Modified:
    lldb/trunk/tools/darwin-threads/examine-threads.c

Modified: lldb/trunk/tools/darwin-threads/examine-threads.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/darwin-threads/examine-threads.c?rev=134686&r1=134685&r2=134686&view=diff
==============================================================================
--- lldb/trunk/tools/darwin-threads/examine-threads.c (original)
+++ lldb/trunk/tools/darwin-threads/examine-threads.c Fri Jul  8 00:04:01 2011
@@ -96,33 +96,16 @@
 struct kinfo_proc *
 get_kinfo_proc_for_pid (pid_t pid, const char *process_name)
 {
-  struct kinfo_proc *all_kinfos;
-  int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
-  size_t len;
-  if (sysctl (mib, 3, NULL, &len, NULL, 0) != 0)
+  struct kinfo_proc *kinfo = (struct kinfo_proc *) malloc (sizeof (struct kinfo_proc));
+  int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
+  size_t len = sizeof (struct kinfo_proc);
+  if (sysctl (mib, sizeof (mib) / sizeof (mib[0]), kinfo, &len, NULL, 0) != 0)
     {
-      printf ("Could not number of processes\n");
+      free ((void *) kinfo);
+      printf ("Could not get kinfo_proc for pid %d\n", (int) pid);
       exit (1);
     }
-  all_kinfos = (struct kinfo_proc *) malloc (len);
-  if (sysctl (mib, 3, all_kinfos, &len, NULL, 0) != 0)
-    {
-      printf ("Could not get process infos\n");
-      exit (1);
-    }
-
-  int proc_count, i;
-  proc_count = len / sizeof (struct kinfo_proc);
-  for (i = 0 ; i < proc_count; i++)
-    if (all_kinfos[i].kp_proc.p_pid == pid)
-      {
-        struct kinfo_proc *kinfo = (struct kinfo_proc *) malloc (sizeof (struct kinfo_proc));
-        memcpy (kinfo, &all_kinfos[i], sizeof (struct kinfo_proc));
-        free ((void *) all_kinfos);
-        return kinfo;
-      }
-  printf ("Did not find process '%s' when re-getting proc table.\n", process_name);
-  exit (1);
+  return kinfo;
 }
 
 /* Get the basic information (thread_basic_info_t) about a given





More information about the lldb-commits mailing list