aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbserver/linux-x86-low.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2014-10-22 13:51:07 +0100
committerPedro Alves <palves@redhat.com>2015-02-27 17:30:09 +0000
commit4180215b9db1549b88da2da2fcc320fe28233481 (patch)
treed9be89fd130a2c8c727f8e091753ee3567bff668 /gdb/gdbserver/linux-x86-low.c
parent2f56f7c302c8d4012cc47d8bd261b151b2ddfa22 (diff)
downloadgdb-4180215b9db1549b88da2da2fcc320fe28233481.zip
gdb-4180215b9db1549b88da2da2fcc320fe28233481.tar.gz
gdb-4180215b9db1549b88da2da2fcc320fe28233481.tar.bz2
x86 Linux/ptrace: fix offsetof usage in C++ mode
In C++ mode, we get: gdb/gdbserver/linux-x86-low.c: In function ‘void x86_linux_dr_set(ptid_t, int, long unsigned int)’: gdb/gdbserver/linux-x86-low.c:558:38: error: ‘regnum’ cannot appear in a constant-expression offsetof (struct user, u_debugreg[regnum]), value); ^ gdb/gdbserver/ChangeLog: 2015-02-27 Pedro Alves <palves@redhat.com> * linux-x86-low.c (u_debugreg_offset): New function. (x86_linux_dr_get, x86_linux_dr_set): Use it. gdb/ChangeLog: 2015-02-27 Pedro Alves <palves@redhat.com> * x86-linux-nat.c (u_debugreg_offset): New function. (x86_linux_dr_get, x86_linux_dr_set): Use it.
Diffstat (limited to 'gdb/gdbserver/linux-x86-low.c')
-rw-r--r--gdb/gdbserver/linux-x86-low.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index 171735c..c376cab 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -530,6 +530,18 @@ x86_breakpoint_at (CORE_ADDR pc)
return 0;
}
+
+/* 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. */
static unsigned long
@@ -541,8 +553,7 @@ 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)
error ("Couldn't read debug register");
@@ -557,8 +568,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)
error ("Couldn't write debug register");
}