[PATCH 06/10] Add netbsd_nat::enable_proc_events in gdb/nat

Kamil Rytarowski
2020-09-02T18:00:11Z

Add generic function to enable debugger events in a process.

gdb/ChangeLog:

* netbsd-nat.h (netbsd_nat::enable_proc_events): Add.
* netbsd-nat.c (netbsd_nat::enable_proc_events): Likewise.
---
gdb/ChangeLog | 5 +++++
gdb/nat/netbsd-nat.c | 18 ++++++++++++++++++
gdb/nat/netbsd-nat.h | 2 ++
3 files changed, 25 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8b9ca1e9b32..06d3476c137 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2020-08-13 Kamil Rytarowski <n54@gmx.com>
+
+ * netbsd-nat.h (netbsd_nat::enable_proc_events): Add.
+ * netbsd-nat.c (netbsd_nat::enable_proc_events): Likewise.
+
2020-08-13 Kamil Rytarowski <n54@gmx.com>

* netbsd-nat.h (netbsd_nat::thread_alive, netbsd_nat::thread_name)
diff --git a/gdb/nat/netbsd-nat.c b/gdb/nat/netbsd-nat.c
index 5f005c38bf2..88c70ebe1bb 100644
--- a/gdb/nat/netbsd-nat.c
+++ b/gdb/nat/netbsd-nat.c
@@ -22,6 +22,7 @@
#include "gdbsupport/common-debug.h"

#include <sys/types.h>
+#include <sys/ptrace.h>
#include <sys/sysctl.h>

#include <cstring>
@@ -162,4 +163,21 @@ list_threads (pid_t pid, gdb::function_view<void (ptid_t)> callback)
netbsd_thread_lister (pid, fn);
}

+/* Enable additional event reporting in a new process specified by PID. */
+
+void
+enable_proc_events (pid_t pid)
+{
+ int events;
+
+ if (ptrace (PT_GET_EVENT_MASK, pid, &events, sizeof (events)) == -1)
+ perror_with_name (("ptrace"));
+
+ events |= PTRACE_LWP_CREATE;
+ events |= PTRACE_LWP_EXIT;
+
+ if (ptrace (PT_SET_EVENT_MASK, pid, &events, sizeof (events)) == -1)
+ perror_with_name (("ptrace"));
+}
+
}
diff --git a/gdb/nat/netbsd-nat.h b/gdb/nat/netbsd-nat.h
index b6885e1a9a6..c93e5d4822d 100644
--- a/gdb/nat/netbsd-nat.h
+++ b/gdb/nat/netbsd-nat.h
@@ -35,6 +35,8 @@ extern const char *thread_name (ptid_t ptid);

extern void list_threads (pid_t pid,
gdb::function_view<void (ptid_t)> callback);
+
+extern void enable_proc_events (pid_t pid);
}

#endif
--
2.28.0