Index: source/Host/freebsd/Host.cpp =================================================================== --- source/Host/freebsd/Host.cpp +++ source/Host/freebsd/Host.cpp @@ -52,6 +52,24 @@ using namespace lldb; using namespace lldb_private; +static bool GetFreeBSDProcessName(ProcessInstanceInfo &process_info) { + if (process_info.ProcessIDIsValid()) { + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, + (int)process_info.GetProcessID()}; + + char pathname[PATH_MAX] = {0}; + size_t maxlen = PATH_MAX; + + if (::sysctl(mib, 4, pathname, &maxlen, NULL, 0) == 0) { + if (*pathname) { + process_info.GetExecutableFile().SetFile(pathname, false); + return true; + } + } + } + return false; +} + static bool GetFreeBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr, ProcessInstanceInfo &process_info) { @@ -69,8 +87,14 @@ cstr = data.GetCStr(&offset); if (cstr) { - process_info.GetExecutableFile().SetFile(cstr, false); + // we can get the exe name along with KERN_PROC_ARGS but we couldn't get + // absolute path + // which let us attach to process irrespective of directory while + // attaching + if (!GetFreeBSDProcessName(process_info)) + return false; + if (!(match_info_ptr == NULL || NameMatches( process_info.GetExecutableFile().GetFilename().GetCString(),