diff options
author | Jim Ingham <jingham@apple.com> | 2012-11-01 01:04:46 +0000 |
---|---|---|
committer | Jim Ingham <jingham@apple.com> | 2012-11-01 01:04:46 +0000 |
commit | 490bccd6596c496e9307fbc8639794f7fa2c165f (patch) | |
tree | f474f4fe8ab55c1d6c05b8f1f207c5321afad20b /lldb/tools/debugserver/source/DNB.cpp | |
parent | d6bdafc858957891a1a1d0632beb9ffcfafa2f3a (diff) | |
download | bcm5719-llvm-490bccd6596c496e9307fbc8639794f7fa2c165f.tar.gz bcm5719-llvm-490bccd6596c496e9307fbc8639794f7fa2c165f.zip |
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>
llvm-svn: 167194
Diffstat (limited to 'lldb/tools/debugserver/source/DNB.cpp')
-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) |