FreeBSD: attach to pid from different cwd

attach by pid worked when running from the directory from which the
target was launched, but failed from a different directory. Use the
kern.proc.pathname sysctl to locate the target, falling back to the
original case of the target's argv[0] if that fails. Based on a patch
from Vignesh Balu.

Differential Revision:	https://reviews.llvm.org/D32271

llvm-svn: 312430
This commit is contained in:
Ed Maste
2017-09-03 01:41:31 +00:00
parent 8a6bab78f6
commit 207184f345

View File

@@ -73,7 +73,14 @@ GetFreeBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr,
if (!cstr)
return false;
process_info.GetExecutableFile().SetFile(cstr, false);
// Get pathname for pid. If that fails fall back to argv[0].
char pathname[MAXPATHLEN];
size_t pathname_len = sizeof(pathname);
mib[2] = KERN_PROC_PATHNAME;
if (::sysctl(mib, 4, pathname, &pathname_len, NULL, 0) == 0)
process_info.GetExecutableFile().SetFile(pathname, false);
else
process_info.GetExecutableFile().SetFile(cstr, false);
if (!(match_info_ptr == NULL ||
NameMatches(process_info.GetExecutableFile().GetFilename().GetCString(),