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

Kamil Rytarowski
2020-09-04T00:30:05Z

Add generic function to enable debugger events in a process.

gdb/ChangeLog:

* netbsd-nat.h (netbsd_nat::enable_proc_events): Add.
* netbsd-nat.c: Include <sys/ptrace.h>.
* (netbsd_nat::enable_proc_events): Add.
---
gdb/ChangeLog | 6 ++++++
gdb/nat/netbsd-nat.c | 18 ++++++++++++++++++
gdb/nat/netbsd-nat.h | 2 ++
3 files changed, 26 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b9b028ebe68..0db297a6cdd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2020-09-04 Kamil Rytarowski <n54@gmx.com>
+
+ * netbsd-nat.h (netbsd_nat::enable_proc_events): Add.
+ * netbsd-nat.c: Include <sys/ptrace.h>.
+ * (netbsd_nat::enable_proc_events): Add.
+
2020-09-04 Kamil Rytarowski <n54@gmx.com>

* netbsd-nat.h: Include "gdbsupport/function-view.h".
diff --git a/gdb/nat/netbsd-nat.c b/gdb/nat/netbsd-nat.c
index bd28e116b56..1220b272c8c 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 @@ for_each_thread (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 c3a58ae7f49..58021b2398e 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 for_each_thread (pid_t pid,
gdb::function_view<void (ptid_t)> callback);
+
+extern void enable_proc_events (pid_t pid);
}

#endif
--
2.28.0