[Lldb-commits] [lldb] r167194 - /lldb/trunk/tools/debugserver/source/DNB.cpp
Jim Ingham
jingham at apple.com
Wed Oct 31 18:04:46 PDT 2012
Author: jingham
Date: Wed Oct 31 20:04:46 2012
New Revision: 167194
URL: http://llvm.org/viewvc/llvm-project?rev=167194&view=rev
Log:
Switch from using KERN_PROCARGS2 to get the path to the executed process to proc_pidpath. The former was flakey, and the whole point of libproc is to protect us from potential flakiness at that level...
<rdar://problem/12594781>
Modified:
lldb/trunk/tools/debugserver/source/DNB.cpp
Modified: lldb/trunk/tools/debugserver/source/DNB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.cpp?rev=167194&r1=167193&r2=167194&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/DNB.cpp (original)
+++ lldb/trunk/tools/debugserver/source/DNB.cpp Wed Oct 31 20:04:46 2012
@@ -23,6 +23,7 @@
#include <sys/sysctl.h>
#include <map>
#include <vector>
+#include <libproc.h>
#include "MacOSX/MachProcess.h"
#include "MacOSX/MachTask.h"
@@ -429,7 +430,6 @@
return proc_infos.size();
}
-
static size_t
GetAllInfosMatchingName(const char *full_process_name, std::vector<struct kinfo_proc>& matching_proc_infos)
{
@@ -460,24 +460,27 @@
// Check for process by name. We only check the first MAXCOMLEN
// chars as that is all that kp_proc.p_comm holds.
+
if (::strncasecmp(process_name, proc_infos[i].kp_proc.p_comm, MAXCOMLEN) == 0)
{
if (process_name_len > MAXCOMLEN)
{
// We found a matching process name whose first MAXCOMLEN
// characters match, but there is more to the name than
- // this. We need to get the full process name.
+ // this. We need to get the full process name. Use proc_pidpath, which will get
+ // us the full path to the executed process.
- int proc_args_mib[3] = { CTL_KERN, KERN_PROCARGS2, proc_infos[i].kp_proc.p_pid };
+ char proc_path_buf[PATH_MAX];
- // Get PATH_MAX for argv[0] plus 4 bytes for the argc
- char arg_data[PATH_MAX+4];
- size_t arg_data_size = sizeof(arg_data);
- // Skip the 4 byte argc integer value to get to argv[0]
- const char *argv0 = arg_data + 4;
- if (::sysctl (proc_args_mib, 3, arg_data, &arg_data_size , NULL, 0) == 0)
+ int return_val = proc_pidpath (proc_infos[i].kp_proc.p_pid, proc_path_buf, PATH_MAX);
+ if (return_val > 0)
{
- const char *argv_basename = strrchr(argv0, '/');
+ // Okay, now search backwards from that to see if there is a
+ // slash in the name. Note, even though we got all the args we don't care
+ // because the list data is just a bunch of concatenated null terminated strings
+ // so strrchr will start from the end of argv0.
+
+ const char *argv_basename = strrchr(proc_path_buf, '/');
if (argv_basename)
{
// Skip the '/'
@@ -486,7 +489,7 @@
else
{
// We didn't find a directory delimiter in the process argv[0], just use what was in there
- argv_basename = argv0;
+ argv_basename = proc_path_buf;
}
if (argv_basename)
More information about the lldb-commits
mailing list