aboutsummaryrefslogtreecommitdiff
path: root/gdb/x86-linux-nat.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/x86-linux-nat.c')
-rw-r--r--gdb/x86-linux-nat.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index 9d82be2..c58c01a 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -51,6 +51,16 @@ struct arch_lwp_info
int have_ptrace_getregset = -1;
+/* Return the offset of REGNUM in the u_debugreg field of struct
+ user. */
+
+static int
+u_debugreg_offset (int regnum)
+{
+ return (offsetof (struct user, u_debugreg)
+ + sizeof (((struct user *) 0)->u_debugreg[0]) * regnum);
+}
+
/* Support for debug registers. */
/* Get debug register REGNUM value from only the one LWP of PTID. */
@@ -65,8 +75,8 @@ x86_linux_dr_get (ptid_t ptid, int regnum)
tid = ptid_get_lwp (ptid);
errno = 0;
- value = ptrace (PTRACE_PEEKUSER, tid,
- offsetof (struct user, u_debugreg[regnum]), 0);
+ value = ptrace (PTRACE_PEEKUSER, tid, u_debugreg_offset (regnum), 0);
+
if (errno != 0)
perror_with_name (_("Couldn't read debug register"));
@@ -84,8 +94,7 @@ x86_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
tid = ptid_get_lwp (ptid);
errno = 0;
- ptrace (PTRACE_POKEUSER, tid,
- offsetof (struct user, u_debugreg[regnum]), value);
+ ptrace (PTRACE_POKEUSER, tid, u_debugreg_offset (regnum), value);
if (errno != 0)
perror_with_name (_("Couldn't write debug register"));
}