-/* Helper function which checks if ptrace is probably restricted
- (i.e., if ERR is either EACCES or EPERM), and returns a string with
- possible workarounds. */
-
-static std::string
-linux_ptrace_restricted_fail_reason (int err)
-{
- if (err != EACCES && err != EPERM)
- {
- /* It just makes sense to perform the checks below if errno was
- either EACCES or EPERM. */
- return {};
- }
-
- std::string ret;
- gdb_dlhandle_up handle;
-
- try
- {
- handle = gdb_dlopen ("libselinux.so.1");
- }
- catch (const gdb_exception_error &e)
- {
- handle.reset (nullptr);
- }
-
- if (handle != nullptr)
- {
- selinux_ftype selinux_get_bool
- = (selinux_ftype) gdb_dlsym (handle, "security_get_boolean_active");
-
- if (selinux_get_bool != NULL
- && (*selinux_get_bool) ("deny_ptrace") == 1)
- string_appendf (ret,
- _("\n\
-The SELinux 'deny_ptrace' option is enabled and preventing GDB\n\
-from using 'ptrace'. You can disable it by executing (as root):\n\
-\n\
- setsebool deny_ptrace off\n"));
- }
-
- gdb_file_up yama_ptrace_scope
- = gdb_fopen_cloexec ("/proc/sys/kernel/yama/ptrace_scope", "r");
-
- if (yama_ptrace_scope != nullptr)
- {
- char yama_scope = fgetc (yama_ptrace_scope.get ());
-
- if (yama_scope != '0')
- string_appendf (ret,
- _("\n\
-The Linux kernel's Yama ptrace scope is in effect, which can prevent\n\
-GDB from using 'ptrace'. You can disable it by executing (as root):\n\
-\n\
- echo 0 > /proc/sys/kernel/yama/ptrace_scope\n"));
- }
-
- if (ret.empty ())
- {
- /* It wasn't possible to determine the exact reason for the
- ptrace error. Let's just emit a generic error message
- pointing the user to our documentation, where she can find
- instructions on how to try to diagnose the problem. */
- ret = _("\n\
-There might be restrictions preventing ptrace from working. Please see\n\
-the appendix \"Linux kernel ptrace restrictions\" in the GDB documentation\n\
-for more details.");
- }
-
- /* The user may be debugging remotely, so we have to warn that
- the instructions above should be performed in the target. */
- string_appendf (ret,
- _("\n\
-If you are debugging the inferior remotely, the ptrace restriction(s) must\n\
-be disabled in the target system (e.g., where GDBserver is running)."));
-
- return ret;
-}
-
-/* Find all possible reasons we could fail to attach PID and return
- these as a string. An empty string is returned if we didn't find
- any reason. Helper for linux_ptrace_attach_fail_reason and
- linux_ptrace_attach_fail_reason_lwp. */
-
-static std::string
-linux_ptrace_attach_fail_reason_1 (pid_t pid)