From: Kamil Rytarowski Date: Wed, 2 Sep 2020 17:21:19 +0000 (+0200) Subject: Add a common utility function to read and write siginfo_t in inferior X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1ccb2c170cea50671f7aa00eb6a2be2a33ea24a5;p=binutils-gdb.git Add a common utility function to read and write siginfo_t in inferior gdb/ChangeLog: * netbsd-nat.h (netbsd_nat::qxfer_siginfo): Add. * netbsd-nat.c (netbsd_nat::qxfer_siginfo): Likewise. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 41bd6998bb9..ecf8e37f58b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-09-10 Kamil Rytarowski + + * netbsd-nat.h (netbsd_nat::qxfer_siginfo): Add. + * netbsd-nat.c (netbsd_nat::qxfer_siginfo): Likewise. + 2020-09-10 Kamil Rytarowski * netbsd-nat.h (netbsd_nat::enable_proc_events): Add. diff --git a/gdb/nat/netbsd-nat.c b/gdb/nat/netbsd-nat.c index d805b892404..41b67cb72fc 100644 --- a/gdb/nat/netbsd-nat.c +++ b/gdb/nat/netbsd-nat.c @@ -181,4 +181,33 @@ enable_proc_events (pid_t pid) perror_with_name (("ptrace")); } +/* See netbsd-nat.h. */ + +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 6472cc56da4..d77119bb862 100644 --- a/gdb/nat/netbsd-nat.h +++ b/gdb/nat/netbsd-nat.h @@ -57,6 +57,16 @@ extern void for_each_thread (pid_t pid, traced. */ extern void enable_proc_events (pid_t pid); + +/* 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. + + This function assumes internally that the queried process is stopped and + traced. */ + +extern int qxfer_siginfo (pid_t pid, const char *annex, unsigned char *readbuf, + unsigned const char *writebuf, CORE_ADDR offset, + int len); } #endif