Skip to content

[lldb] Fix building on NetBSD 8.x #74191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

brad0
Copy link
Contributor

@brad0 brad0 commented Dec 2, 2023

PT_STOP was introduced with NetBSD 9.0.

@brad0 brad0 requested a review from JDevlieghere as a code owner December 2, 2023 11:08
@llvmbot llvmbot added the lldb label Dec 2, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 2, 2023

@llvm/pr-subscribers-lldb

Author: Brad Smith (brad0)

Changes

PT_STOP was introduced with NetBSD 9.0.


Full diff: https://github.com/llvm/llvm-project/pull/74191.diff

2 Files Affected:

  • (modified) lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp (+25-2)
  • (modified) lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h (+1)
diff --git a/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp b/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
index 26c562bd479050b..7f3e1a008727862 100644
--- a/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ b/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -379,6 +379,29 @@ void NativeProcessNetBSD::MonitorSignal(lldb::pid_t pid, int signal) {
   SetState(StateType::eStateStopped, true);
 }
 
+Status NativeProcessNetBSD::StopProcess(lldb::pid_t pid) {
+#ifdef PT_STOP
+  return PtraceWrapper(PT_STOP, pid);
+#else
+  Log *log = GetLog(POSIXLog::Ptrace);
+  Status error;
+  int ret;
+
+  errno = 0;
+  ret = kill(pid, SIGSTOP);
+
+  if (ret == -1)
+    error.SetErrorToErrno();
+
+  LLDB_LOG(log, "kill({0}, SIGSTOP)", pid);
+
+  if (error.Fail())
+    LLDB_LOG(log, "kill() failed: {0}", error);
+
+  return error;
+#endif
+}
+
 Status NativeProcessNetBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
                                           int data, int *result) {
   Log *log = GetLog(POSIXLog::Ptrace);
@@ -531,7 +554,7 @@ Status NativeProcessNetBSD::Resume(const ResumeActionList &resume_actions) {
   return ret;
 }
 
-Status NativeProcessNetBSD::Halt() { return PtraceWrapper(PT_STOP, GetID()); }
+Status NativeProcessNetBSD::Halt() { return StopProcess(GetID()); }
 
 Status NativeProcessNetBSD::Detach() {
   Status error;
@@ -556,7 +579,7 @@ Status NativeProcessNetBSD::Signal(int signo) {
 }
 
 Status NativeProcessNetBSD::Interrupt() {
-  return PtraceWrapper(PT_STOP, GetID());
+  return StopProcess(GetID());
 }
 
 Status NativeProcessNetBSD::Kill() {
diff --git a/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h b/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
index 86724fdd5b7e5dd..f3d07651384fe9f 100644
--- a/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
+++ b/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
@@ -88,6 +88,7 @@ class NativeProcessNetBSD : public NativeProcessELF {
   // Interface used by NativeRegisterContext-derived classes.
   static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
                               int data = 0, int *result = nullptr);
+  static Status StopProcess(lldb::pid_t pid);
 
   llvm::Expected<std::string> SaveCore(llvm::StringRef path_hint) override;
 

Copy link

github-actions bot commented Dec 2, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@brad0 brad0 force-pushed the lldb_netbsd_build_fix_pt_stop branch 2 times, most recently from 7b61f0c to fc90291 Compare December 2, 2023 11:46
@brad0 brad0 requested review from mgorny and bulbazord December 2, 2023 12:14
PT_STOP was introduced with NetBSD 9.0.
@brad0 brad0 force-pushed the lldb_netbsd_build_fix_pt_stop branch from fc90291 to 855c6cb Compare December 2, 2023 12:19
Copy link
Member

@mgorny mgorny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though I don;t have an environment to test it.

@brad0 brad0 merged commit b96bae2 into llvm:main Dec 4, 2023
@brad0 brad0 deleted the lldb_netbsd_build_fix_pt_stop branch December 4, 2023 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants