https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/79662
>From 746a6959e270b086184ce095b11eb4df691dc4c9 Mon Sep 17 00:00:00 2001 From: David Carlier <devne...@gmail.com> Date: Fri, 26 Jan 2024 22:47:15 +0000 Subject: [PATCH] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. before having the generic EINVAL message, we check if the `security.bsd.unprivileged_proc_debug` allows process debugging. close #79634 --- .../Process/FreeBSD/NativeProcessFreeBSD.cpp | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp index 19e0986ace31ff..24726832fa4598 100644 --- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp @@ -48,20 +48,38 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", &proc_debug, + &len, nullptr, 0); + if (ret != 0) + return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); + + if (proc_debug < 1) + return Status( + "process debug disabled by security.bsd.unprivileged_proc_debug oid"); + + return {}; +} + // Public Static Methods llvm::Expected<std::unique_ptr<NativeProcessProtocol>> NativeProcessFreeBSD::Manager::Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate) { Log *log = GetLog(POSIXLog::Process); - Status status; + ::pid_t pid = ProcessLauncherPosixFork() .LaunchProcess(launch_info, status) .GetProcessId(); LLDB_LOG(log, "pid = {0:x}", pid); if (status.Fail()) { + auto error = CanTrace(); LLDB_LOG(log, "failed to launch process: {0}", status); + if (status.Fail()) + return error.ToError(); return status.ToError(); } @@ -392,8 +410,11 @@ Status NativeProcessFreeBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr, ret = ptrace(req, static_cast<::pid_t>(pid), static_cast<caddr_t>(addr), data); - if (ret == -1) - error.SetErrorToErrno(); + if (ret == -1) { + error = CanTrace(); + if (error.Success()) + error.SetErrorToErrno(); + } if (result) *result = ret; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits