[PATCH v2 07/10] Add a common utility function to read and write siginfo_t in inferior

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

gdb/ChangeLog:

* netbsd-nat.h (netbsd_nat::qxfer_siginfo): Add.
* netbsd-nat.c (netbsd_nat::qxfer_siginfo): Likewise.
---
gdb/ChangeLog | 5 +++++
gdb/nat/netbsd-nat.c | 30 ++++++++++++++++++++++++++++++
gdb/nat/netbsd-nat.h | 4 ++++
3 files changed, 39 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0db297a6cdd..b96e7bf08e8 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2020-09-04 Kamil Rytarowski <n54@gmx.com>
+
+ * netbsd-nat.h (netbsd_nat::qxfer_siginfo): Add.
+ * netbsd-nat.c (netbsd_nat::qxfer_siginfo): Likewise.
+
2020-09-04 Kamil Rytarowski <n54@gmx.com>

* netbsd-nat.h (netbsd_nat::enable_proc_events): Add.
diff --git a/gdb/nat/netbsd-nat.c b/gdb/nat/netbsd-nat.c
index 1220b272c8c..a13b1509d5a 100644
--- a/gdb/nat/netbsd-nat.c
+++ b/gdb/nat/netbsd-nat.c
@@ -180,4 +180,34 @@ enable_proc_events (pid_t pid)
perror_with_name (("ptrace"));
}

+/* Implement reading and writing of inferior's siginfo_t specified by PID.
+ Returns -1 on failure and the number of bytes on a successful transfer. */
+
+int
+qxfer_siginfo (pid_t pid, const char *annex, unsigned char *readbuf,
+ unsigned const char *writebuf, CORE_ADDR offset, int len)
+{
+ ptrace_siginfo_t psi;
+
+ if (offset > sizeof (siginfo_t))
+ return -1;
+
+ if (ptrace (PT_GET_SIGINFO, pid, &psi, sizeof (psi)) == -1)
+ return -1;
+
+ if (offset + len > sizeof (siginfo_t))
+ len = sizeof (siginfo_t) - offset;
+
+ if (readbuf != NULL)
+ memcpy (readbuf, ((gdb_byte *) &psi.psi_siginfo) + offset, len);
+ else
+ {
+ memcpy (((gdb_byte *) &psi.psi_siginfo) + offset, writebuf, len);
+
+ if (ptrace (PT_SET_SIGINFO, pid, &psi, sizeof (psi)) == -1)
+ return -1;
+ }
+ return len;
+}
+
}
diff --git a/gdb/nat/netbsd-nat.h b/gdb/nat/netbsd-nat.h
index 58021b2398e..74b4b3ecca5 100644
--- a/gdb/nat/netbsd-nat.h
+++ b/gdb/nat/netbsd-nat.h
@@ -37,6 +37,10 @@ extern void for_each_thread (pid_t pid,
gdb::function_view<void (ptid_t)> callback);

extern void enable_proc_events (pid_t pid);
+
+extern int qxfer_siginfo (pid_t pid, const char *annex, unsigned char *readbuf,
+ unsigned const char *writebuf, CORE_ADDR offset,
+ int len);
}

#endif
--
2.28.0