summaryrefslogtreecommitdiffstats
path: root/lldb/tools/debugserver/source/DNB.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-07-19 02:45:35 +0000
committerGreg Clayton <gclayton@apple.com>2012-07-19 02:45:35 +0000
commit7dab2be287603946988a94b48e150c4809ea4140 (patch)
tree3cb7629e86d145640a96e5ea624defd772d6173f /lldb/tools/debugserver/source/DNB.cpp
parent9efaf227d1adf15cc74f25089a262deacb649b88 (diff)
downloadbcm5719-llvm-7dab2be287603946988a94b48e150c4809ea4140.tar.gz
bcm5719-llvm-7dab2be287603946988a94b48e150c4809ea4140.zip
<rdar://problem/11908082>
Allow debugserver to match process names that are longer than MAXCOMLEN (16) characters. We do this by digging up argv[0] from another sysctl if the process name supplied is longer than 16 characters. llvm-svn: 160487
Diffstat (limited to 'lldb/tools/debugserver/source/DNB.cpp')
-rw-r--r--lldb/tools/debugserver/source/DNB.cpp51
1 files changed, 46 insertions, 5 deletions
diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp
index 820da8b86a2..0a29eaa8202 100644
--- a/lldb/tools/debugserver/source/DNB.cpp
+++ b/lldb/tools/debugserver/source/DNB.cpp
@@ -440,10 +440,11 @@ GetAllInfosMatchingName(const char *full_process_name, std::vector<struct kinfo_
const char *process_name;
process_name = strrchr (full_process_name, '/');
if (process_name == NULL)
- process_name = full_process_name;
+ process_name = full_process_name;
else
- process_name++;
+ process_name++;
+ const int process_name_len = strlen(process_name);
std::vector<struct kinfo_proc> proc_infos;
const size_t num_proc_infos = GetAllInfos(proc_infos);
if (num_proc_infos > 0)
@@ -457,10 +458,50 @@ 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(proc_infos[i].kp_proc.p_comm, process_name, MAXCOMLEN) == 0)
+ if (::strncasecmp(process_name, proc_infos[i].kp_proc.p_comm, MAXCOMLEN) == 0)
{
- // We found a matching process, add it to our list
- matching_proc_infos.push_back(proc_infos[i]);
+ 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.
+
+ int proc_args_mib[3] = { CTL_KERN, KERN_PROCARGS2, proc_infos[i].kp_proc.p_pid };
+
+ // 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)
+ {
+ const char *argv_basename = strrchr(argv0, '/');
+ if (argv_basename)
+ {
+ // Skip the '/'
+ ++argv_basename;
+ }
+ else
+ {
+ // We didn't find a directory delimiter in the process argv[0], just use what was in there
+ argv_basename = argv0;
+ }
+
+ if (argv_basename)
+ {
+ if (::strncasecmp(process_name, argv_basename, PATH_MAX) == 0)
+ {
+ matching_proc_infos.push_back(proc_infos[i]);
+ }
+ }
+ }
+ }
+ else
+ {
+ // We found a matching process, add it to our list
+
+ matching_proc_infos.push_back(proc_infos[i]);
+ }
}
}
}
OpenPOWER on IntegriCloud