diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -410,7 +410,7 @@ "no error returned from Target::Attach, and target has no process"); } } else { - result.AppendErrorWithFormat("attach failed: %s\n", error.AsCString()); + result.AppendErrorWithFormat("attach failed: %s", error.AsCString()); } if (!result.Succeeded()) diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -3118,6 +3118,16 @@ return CreateTrace(); } +const char *fetchPtracePolicyIfApplicable(lldb::PlatformSP platform_sp) { + Platform *platform = platform_sp.get(); + + // read value of /proc/sys/kernel/yama/ptrace_scope + return "Could not attach to process. If your uid matches the uid of the " + "target process, \n" + "check the setting of /proc/sys/kernel/yama/ptrace_scope, \n" + "or try again as the root user. \n"; +} + Status Target::Attach(ProcessAttachInfo &attach_info, Stream *stream) { auto state = eStateInvalid; auto process_sp = GetProcessSP(); @@ -3188,9 +3198,14 @@ if (state != eStateStopped) { const char *exit_desc = process_sp->GetExitDescription(); - if (exit_desc) - error.SetErrorStringWithFormat("%s", exit_desc); - else + const char *ptrace_reason = ""; + if (exit_desc) { + // If we are on a linux flavoured system + if (platform_sp->GetSystemArchitecture().GetTriple().isOSLinux()) { + ptrace_reason = fetchPtracePolicyIfApplicable(platform_sp); + } + error.SetErrorStringWithFormat("%s\n%s", exit_desc, ptrace_reason); + } else error.SetErrorString( "process did not stop (no such process or permission problem?)"); process_sp->Destroy(false);