From 490bccd6596c496e9307fbc8639794f7fa2c165f Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Thu, 1 Nov 2012 01:04:46 +0000 Subject: [PATCH] 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... llvm-svn: 167194 --- lldb/tools/debugserver/source/DNB.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp index bb5e72c..401cefc 100644 --- a/lldb/tools/debugserver/source/DNB.cpp +++ b/lldb/tools/debugserver/source/DNB.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "MacOSX/MachProcess.h" #include "MacOSX/MachTask.h" @@ -429,7 +430,6 @@ GetAllInfos (std::vector& proc_infos) return proc_infos.size(); } - static size_t GetAllInfosMatchingName(const char *full_process_name, std::vector& matching_proc_infos) { @@ -460,24 +460,27 @@ GetAllInfosMatchingName(const char *full_process_name, std::vector 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 @@ GetAllInfosMatchingName(const char *full_process_name, std::vector