From 7dab2be287603946988a94b48e150c4809ea4140 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Thu, 19 Jul 2012 02:45:35 +0000 Subject: 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 --- lldb/tools/debugserver/source/DNB.cpp | 51 +++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) (limited to 'lldb/tools/debugserver/source/DNB.cpp') 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 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 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]); + } } } } -- cgit v1.2.3