[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
Ed Maste via lldb-commits
lldb-commits at lists.llvm.org
Fri Jan 26 18:10:54 PST 2024
================
@@ -48,14 +48,36 @@ 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;
+
+ status = CanTrace();
----------------
emaste wrote:
I might suggest moving these checks into the Fail case below, avoiding the extra syscall that's not necessary in the common case. Also, we may have other cases we could start checking for.
https://github.com/llvm/llvm-project/pull/79662
More information about the lldb-commits
mailing list