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

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

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 06d3476c137..1dcf5d0ca81 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2020-08-13 Kamil Rytarowski <n54@gmx.com>
+
+ * netbsd-nat.h (netbsd_nat::qxfer_siginfo): Add.
+ * netbsd-nat.c (netbsd_nat::qxfer_siginfo): Likewise.
+
2020-08-13 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 88c70ebe1bb..fef273a125a 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 c93e5d4822d..9bd4e19697e 100644
--- a/gdb/nat/netbsd-nat.h
+++ b/gdb/nat/netbsd-nat.h
@@ -37,6 +37,10 @@ extern void list_threads (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