diff options
-rw-r--r-- | lldb/tools/debugserver/source/DNB.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp index bb5e72c9869..401cefce13c 100644 --- a/lldb/tools/debugserver/source/DNB.cpp +++ b/lldb/tools/debugserver/source/DNB.cpp @@ -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 @@ GetAllInfos (std::vector<struct kinfo_proc>& proc_infos) 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 @@ GetAllInfosMatchingName(const char *full_process_name, std::vector<struct kinfo_ // 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 @@ GetAllInfosMatchingName(const char *full_process_name, std::vector<struct kinfo_ 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) |