@@ -48,20 +48,38 @@ static Status EnsureFDFlags(int fd, int flags) {
48
48
return error;
49
49
}
50
50
51
+ static Status CanTrace () {
52
+ int proc_debug, ret;
53
+ size_t len = sizeof (proc_debug);
54
+ ret = ::sysctlbyname (" security.bsd.unprivileged_proc_debug" , &proc_debug,
55
+ &len, nullptr , 0 );
56
+ if (ret != 0 )
57
+ return Status (" sysctlbyname() security.bsd.unprivileged_proc_debug failed" );
58
+
59
+ if (proc_debug < 1 )
60
+ return Status (
61
+ " process debug disabled by security.bsd.unprivileged_proc_debug oid" );
62
+
63
+ return {};
64
+ }
65
+
51
66
// Public Static Methods
52
67
53
68
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
54
69
NativeProcessFreeBSD::Manager::Launch (ProcessLaunchInfo &launch_info,
55
70
NativeDelegate &native_delegate) {
56
71
Log *log = GetLog (POSIXLog::Process);
57
-
58
72
Status status;
73
+
59
74
::pid_t pid = ProcessLauncherPosixFork ()
60
75
.LaunchProcess (launch_info, status)
61
76
.GetProcessId ();
62
77
LLDB_LOG (log, " pid = {0:x}" , pid);
63
78
if (status.Fail ()) {
79
+ auto error = CanTrace ();
64
80
LLDB_LOG (log, " failed to launch process: {0}" , status);
81
+ if (status.Fail ())
82
+ return error.ToError ();
65
83
return status.ToError ();
66
84
}
67
85
@@ -392,8 +410,11 @@ Status NativeProcessFreeBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
392
410
ret =
393
411
ptrace (req, static_cast <::pid_t >(pid), static_cast <caddr_t >(addr), data);
394
412
395
- if (ret == -1 )
396
- error.SetErrorToErrno ();
413
+ if (ret == -1 ) {
414
+ error = CanTrace ();
415
+ if (error.Success ())
416
+ error.SetErrorToErrno ();
417
+ }
397
418
398
419
if (result)
399
420
*result = ret;
@@ -707,8 +728,12 @@ Status NativeProcessFreeBSD::SetBreakpoint(lldb::addr_t addr, uint32_t size,
707
728
Status NativeProcessFreeBSD::GetLoadedModuleFileSpec (const char *module_path,
708
729
FileSpec &file_spec) {
709
730
Status error = PopulateMemoryRegionCache ();
710
- if (error.Fail ())
731
+ if (error.Fail ()) {
732
+ auto status = CanTrace ();
733
+ if (status.Fail ())
734
+ return status;
711
735
return error;
736
+ }
712
737
713
738
FileSpec module_file_spec (module_path);
714
739
FileSystem::Instance ().Resolve (module_file_spec);
@@ -729,8 +754,12 @@ NativeProcessFreeBSD::GetFileLoadAddress(const llvm::StringRef &file_name,
729
754
lldb::addr_t &load_addr) {
730
755
load_addr = LLDB_INVALID_ADDRESS;
731
756
Status error = PopulateMemoryRegionCache ();
732
- if (error.Fail ())
757
+ if (error.Fail ()) {
758
+ auto status = CanTrace ();
759
+ if (status.Fail ())
760
+ return status;
733
761
return error;
762
+ }
734
763
735
764
FileSpec file (file_name);
736
765
for (const auto &it : m_mem_region_cache) {
0 commit comments