diff options
author | John Baldwin <jhb@FreeBSD.org> | 2016-06-27 13:19:09 -0700 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2016-07-01 07:00:38 -0700 |
commit | a3405d124e1388b613a35af49f19f0cc1b8d959d (patch) | |
tree | e12adad3ac9eb9de413f8b570c89bef61ebbeaa4 /gdb/i386bsd-nat.c | |
parent | 98a4fc78f9dab76b5ada3551a7bef36db8a3ed05 (diff) | |
download | gdb-a3405d124e1388b613a35af49f19f0cc1b8d959d.zip gdb-a3405d124e1388b613a35af49f19f0cc1b8d959d.tar.gz gdb-a3405d124e1388b613a35af49f19f0cc1b8d959d.tar.bz2 |
Consolidate x86 debug register code for BSD native targets.
Move the debug register support code from amd64bsd-nat.c and
i386bsd-nat.c into a shared x86bsd-nat.c.
Instead of setting up x86_dr_low in amd64fbsd-nat.c and
i386fbsd-nat.c, add a x86bsd_target function that creates a new target
that inherits from inf_ptrace and sets up x86 debug registers if
supported. In addition to initializing x86_dr_low, the x86bsd target
installs a custom mourn_inferior target operation to clean up the
x86 debug register state. Previously this was only done on amd64.
Now it will be done for both i386 and amd64. The i386bsd_target and
amd64bsd_target functions create targets that inherit from x86bsd
rather than inf_ptrace.
gdb/ChangeLog:
* Makefile.in [HFILES_NO_SRCDIR]: Replace 'amd64bsd-nat.h' with
'x86bsd-nat.h'.
* amd64bsd-nat.c: Include 'x86bsd-nat.h' instead of
'amd64bsd-nat.h'.
(amd64bsd_xsave_len): Rename and move to x86bsd-nat.c.
(amd64bsd_fetch_inferior_registers): Replace 'amd64bsd_xsave_len'
with 'x86bsd_xsave_len'.
(amd64bsd_store_inferior_registers): Likewise.
(amd64bsd_target): Inherit from x86bsd_target.
(amd64bsd_dr_get): Rename and move to x86bsd-nat.c.
(amd64bsd_dr_set): Likewise.
(amd64bsd_dr_set_control): Likewise.
(amd64bsd_dr_set_addr): Likewise.
(amd64bsd_dr_get_addr): Likewise.
(amd64bsd_dr_get_status): Likewise.
(amd64bsd_dr_get_control): Likewise.
* amd64fbsd-nat.c: Include 'x86bsd-nat.h' instead of
'amd64bsd-nat.h'.
(super_mourn_inferior): Move to x86bsd-nat.c.
(amd64fbsd_mourn_inferior): Rename and move to x86bsd-nat.c.
(amd64fbsd_read_description): Replace 'amd64bsd_xsave_len' with
'x86bsd_xsave_len'.
(_initialize_amd64fbsd_nat): Remove x86 watchpoint setup and
mourn_inferior' target op.
* config/i386/fbsd.mh (NATDEPFILES): Add x86bsd-nat.o.
* config/i386/fbsd64.mh: Likewise.
* config/i386/nbsd64.mh: Likewise.
* config/i386/nbsdelf.mh: Likewise.
* config/i386/obsd.mh: Likewise.
* config/i386/obsd64.mh: Likewise.
* i386bsd-nat.c: Include 'x86bsd-nat.h'.
(i386bsd_xsave_len): Rename and move to x86bsd-nat.c.
(i386bsd_fetch_inferior_registers): Replace 'i386bsd_xsave_len'
with 'x86bsd_xsave_len'.
(i386bsd_store_inferior_registers): Likewise.
(i386bsd_target): Inherit from x86bsd_target.
(i386bsd_dr_get): Rename and move to x86bsd-nat.c.
(i386bsd_dr_set): Likewise.
(i386bsd_dr_set_control): Likewise.
(i386bsd_dr_set_addr): Likewise.
(i386bsd_dr_get_addr): Likewise.
(i386bsd_dr_get_status): Likewise.
(i386bsd_dr_get_control): Likewise.
* i386bsd-nat.h (i386bsd_xsave_len): Remove.
(i386bsd_dr_set_control): Remove.
(i386bsd_dr_set_addr): Remove.
(i386bsd_dr_get_addr): Remove.
(i386bsd_dr_get_status): Remove.
(i386bsd_dr_get_control): Remove.
* i386fbsd-nat.c: Include 'x86bsd-nat.h'.
(i386fbsd_read_description): Replace 'i386bsd_xsave_len' with
'x86bsd_xsave_len'.
(_initialize_i386fbsd_nat): Remove x86 watchpoint setup and
mourn_inferior' target op.
* x86bsd-nat.c: New file.
* x86bsd-nat.h: New file.
Diffstat (limited to 'gdb/i386bsd-nat.c')
-rw-r--r-- | gdb/i386bsd-nat.c | 95 |
1 files changed, 7 insertions, 88 deletions
diff --git a/gdb/i386bsd-nat.c b/gdb/i386bsd-nat.c index f5f4a0f..b6b143b 100644 --- a/gdb/i386bsd-nat.c +++ b/gdb/i386bsd-nat.c @@ -29,6 +29,7 @@ #include "i386-tdep.h" #include "i387-tdep.h" +#include "x86bsd-nat.h" #include "i386bsd-nat.h" #include "inf-ptrace.h" @@ -81,10 +82,6 @@ static int i386bsd_r_reg_offset[] = so that we try PT_GETXMMREGS the first time around. */ static int have_ptrace_xmmregs = -1; #endif - -#ifdef PT_GETXSTATE_INFO -size_t i386bsd_xsave_len; -#endif /* Supply the general-purpose registers in GREGS, to REGCACHE. */ @@ -155,11 +152,11 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops, #endif #ifdef PT_GETXSTATE_INFO - if (i386bsd_xsave_len != 0) + if (x86bsd_xsave_len != 0) { void *xstateregs; - xstateregs = alloca (i386bsd_xsave_len); + xstateregs = alloca (x86bsd_xsave_len); if (ptrace (PT_GETXSTATE, get_ptrace_pid (inferior_ptid), (PTRACE_TYPE_ARG3) xstateregs, 0) == -1) perror_with_name (_("Couldn't get extended state status")); @@ -225,11 +222,11 @@ i386bsd_store_inferior_registers (struct target_ops *ops, #endif #ifdef PT_GETXSTATE_INFO - if (i386bsd_xsave_len != 0) + if (x86bsd_xsave_len != 0) { void *xstateregs; - xstateregs = alloca (i386bsd_xsave_len); + xstateregs = alloca (x86bsd_xsave_len); if (ptrace (PT_GETXSTATE, get_ptrace_pid (inferior_ptid), (PTRACE_TYPE_ARG3) xstateregs, 0) == -1) perror_with_name (_("Couldn't get extended state status")); @@ -237,7 +234,7 @@ i386bsd_store_inferior_registers (struct target_ops *ops, i387_collect_xsave (regcache, -1, xstateregs, 0); if (ptrace (PT_SETXSTATE, get_ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) xstateregs, i386bsd_xsave_len) == -1) + (PTRACE_TYPE_ARG3) xstateregs, x86bsd_xsave_len) == -1) perror_with_name (_("Couldn't write extended state status")); return; } @@ -283,91 +280,13 @@ i386bsd_target (void) { struct target_ops *t; - t = inf_ptrace_target (); + t = x86bsd_target (); t->to_fetch_registers = i386bsd_fetch_inferior_registers; t->to_store_registers = i386bsd_store_inferior_registers; return t; } -/* Support for debug registers. */ - -#ifdef HAVE_PT_GETDBREGS - -/* Not all versions of FreeBSD/i386 that support the debug registers - have this macro. */ -#ifndef DBREG_DRX -#define DBREG_DRX(d, x) ((&d->dr0)[x]) -#endif - -static unsigned long -i386bsd_dr_get (ptid_t ptid, int regnum) -{ - struct dbreg dbregs; - - if (ptrace (PT_GETDBREGS, get_ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) - perror_with_name (_("Couldn't read debug registers")); - - return DBREG_DRX ((&dbregs), regnum); -} - -static void -i386bsd_dr_set (int regnum, unsigned int value) -{ - struct dbreg dbregs; - - if (ptrace (PT_GETDBREGS, get_ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) - perror_with_name (_("Couldn't get debug registers")); - - /* For some mysterious reason, some of the reserved bits in the - debug control register get set. Mask these off, otherwise the - ptrace call below will fail. */ - DBREG_DRX ((&dbregs), 7) &= ~(0x0000fc00); - - DBREG_DRX ((&dbregs), regnum) = value; - - if (ptrace (PT_SETDBREGS, get_ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) - perror_with_name (_("Couldn't write debug registers")); -} - -void -i386bsd_dr_set_control (unsigned long control) -{ - i386bsd_dr_set (7, control); -} - -void -i386bsd_dr_set_addr (int regnum, CORE_ADDR addr) -{ - gdb_assert (regnum >= 0 && regnum <= 4); - - i386bsd_dr_set (regnum, addr); -} - -CORE_ADDR -i386bsd_dr_get_addr (int regnum) -{ - return i386bsd_dr_get (inferior_ptid, regnum); -} - -unsigned long -i386bsd_dr_get_status (void) -{ - return i386bsd_dr_get (inferior_ptid, 6); -} - -unsigned long -i386bsd_dr_get_control (void) -{ - return i386bsd_dr_get (inferior_ptid, 7); -} - -#endif /* PT_GETDBREGS */ - - /* Provide a prototype to silence -Wmissing-prototypes. */ void _initialize_i386bsd_nat (void); |