apoos-maximus updated this revision to Diff 370769.
apoos-maximus added a comment.
moved the error message building logic to Target::Attach()
where the ptrace policy related mesasge gets appended only
if the debugee process is running on LinuxOS
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D106226/new/
https://reviews.llvm.org/D106226
Files:
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Target/Target.cpp
Index: lldb/source/Target/Target.cpp
===================================================================
--- lldb/source/Target/Target.cpp
+++ 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);
Index: lldb/source/Commands/CommandObjectProcess.cpp
===================================================================
--- lldb/source/Commands/CommandObjectProcess.cpp
+++ 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())
Index: lldb/source/Target/Target.cpp
===================================================================
--- lldb/source/Target/Target.cpp
+++ 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);
Index: lldb/source/Commands/CommandObjectProcess.cpp
===================================================================
--- lldb/source/Commands/CommandObjectProcess.cpp
+++ 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())
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits