From 207184f3457a937b1f24b475cef4c10a2c4ab35c Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Sun, 3 Sep 2017 01:41:31 +0000 Subject: [PATCH] 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 --- lldb/source/Host/freebsd/Host.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lldb/source/Host/freebsd/Host.cpp b/lldb/source/Host/freebsd/Host.cpp index 037dfc7f5e03..124a8a760133 100644 --- a/lldb/source/Host/freebsd/Host.cpp +++ b/lldb/source/Host/freebsd/Host.cpp @@ -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(),