From 9bb9e8ade770027f5cced2856574e2d317b15254 Mon Sep 17 00:00:00 2001 From: Pierre Muller Date: Thu, 14 May 2009 09:37:00 +0000 Subject: [PATCH] Remove all i386 debug register low level macros in config nm files. (I386_DR_LOW_SET_ADDR, I386_DR_LOW_RESET_ADDR): Remove. (I386_DR_LOW_GET_STATUS, I386_DR_LOW_SET_CONTROL): Remove. (I386_USE_GENERIC_WATCHPOIINTS): Remove. * i386-nat.h: New file (adapted from config/i386/nm-i386.h). (struct i386_dr_low_type): New type. (i386_dr_low): New global variable. * i386-nat.c (TARGET_HAS_DR_LEN_8): Update macro. (i386_insert_aligned_watchpoint): Replace i386 dr low macros by i386_dr_low struct variable fields. (i386_remove_aligned_watchpoint): Likewise. (i386_stopped_data_address): Likewise. (i386_stopped_by_hwbp): Likewise. (show_debug_regs_command_added): New static variable. (add_show_debug_regs_command): New static function. (i386_use_watchpoints): Call add_show_debug_regs_command if not done. (i386_set_debug_register_length): New function. (_initialize_i386_nat): Delete. * amd64-linux-nat.c: Include "i386-nat.h". (amd64_linux_dr_set_control): Change to static. (amd64_linux_dr_get_status): Change to static. (amd64_linux_dr_set_addr,amd64_linux_dr_reset_addr): Likewise. (_initialize_amd64_linux_nat): Set i386_dr_low variable fields. * go32-nat.c: Include "i386-nat.h". (go32_set_addr): Change to static. (go32_set_dr7): Change to static. Change arg type to unisgned long. (go32_get_dr6): Change to static. Change return type to unisnged long. (init_go32_ops): Set i386_dr_low variable fields. * i386-linux-nat.c: Include "i386-nat.h". (i386_linux_dr_set_control, i386_linux_dr_get_status): Change to static. (i386_linux_dr_set_addr, i386_linux_dr_reset_addr): Idem. (_initialize_i386_linux_nat): Set i386_dr_low variable fields. * i386bsd-nat.h: Declare functions used for i386_dr_low fields in i386fbsd-nat.c. * i386fbsd-nat.c: Include "i386-nat.h". (_initialize_i386fbsd_nat): Set i386_dr_low variable fields. * windows-nat.c: Include "i386-nat.h". (cygwin_set_dr, cygwin_get_dr6, cygwin_set_dr7): Add prototypes. Change to static. (cygwin_get_dr6): Change return type to unisnged long. (cygwin_set_dr7): Change arg type to unisgned long. (init_windows_ops): Set i386_dr_low function fields. * amd64-windows-nat.c (_initialize_amd64_windows_nat): Call i386_set_debug_register_length. * i386-windows-nat.c (_initialize_i386_windows_nat): Likewise. * config/i386/nm-cygwin.h: Remove all I386_* macros. * config/i386/nm-cygwin64.h: Likewise. * config/i386/nm-fbsd.h: Likewise. * config/i386/nm-linux.h: Likewise. * config/i386/nm-i386.h: Remove completely. * config/i386/nm-go32.h: Remove completely. * config/i386/nm-linux64.h: Remove completely. * config/i386/go32.mh (NAT_FILE): Remove entry. * config/i386/linux64.h (NAT_FILE): Change to config/nm-linux.h. --- gdb/ChangeLog | 62 ++++++++++++++++++ gdb/amd64-linux-nat.c | 15 +++-- gdb/amd64-windows-nat.c | 3 +- gdb/config/i386/go32.mh | 1 - gdb/config/i386/linux64.mh | 2 +- gdb/config/i386/nm-cygwin.h | 17 ----- gdb/config/i386/nm-cygwin64.h | 17 ----- gdb/config/i386/nm-fbsd.h | 25 ------- gdb/config/i386/nm-go32.h | 35 ---------- gdb/config/i386/nm-i386.h | 72 -------------------- gdb/config/i386/nm-linux.h | 23 ------- gdb/config/i386/nm-linux64.h | 53 --------------- gdb/go32-nat.c | 16 +++-- gdb/i386-linux-nat.c | 15 +++-- gdb/i386-nat.c | 120 +++++++++++++++------------------- gdb/i386-nat.h | 89 +++++++++++++++++++++++++ gdb/i386-windows-nat.c | 2 + gdb/i386bsd-nat.h | 10 +++ gdb/i386fbsd-nat.c | 14 ++++ gdb/windows-nat.c | 27 ++++++-- 20 files changed, 288 insertions(+), 330 deletions(-) delete mode 100644 gdb/config/i386/nm-go32.h delete mode 100644 gdb/config/i386/nm-i386.h delete mode 100644 gdb/config/i386/nm-linux64.h create mode 100644 gdb/i386-nat.h diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f4055d40d09..8c60e85e863 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,65 @@ +2009-05-14 Pierre Muller + + Remove all i386 debug register low level macros in config nm files. + (I386_DR_LOW_SET_ADDR, I386_DR_LOW_RESET_ADDR): Remove. + (I386_DR_LOW_GET_STATUS, I386_DR_LOW_SET_CONTROL): Remove. + (I386_USE_GENERIC_WATCHPOIINTS): Remove. + + * i386-nat.h: New file (adapted from config/i386/nm-i386.h). + (struct i386_dr_low_type): New type. + (i386_dr_low): New global variable. + * i386-nat.c (TARGET_HAS_DR_LEN_8): Update macro. + (i386_insert_aligned_watchpoint): Replace i386 dr low macros by + i386_dr_low struct variable fields. + (i386_remove_aligned_watchpoint): Likewise. + (i386_stopped_data_address): Likewise. + (i386_stopped_by_hwbp): Likewise. + (show_debug_regs_command_added): New static variable. + (add_show_debug_regs_command): New static function. + (i386_use_watchpoints): Call add_show_debug_regs_command if not done. + (i386_set_debug_register_length): New function. + (_initialize_i386_nat): Delete. + + * amd64-linux-nat.c: Include "i386-nat.h". + (amd64_linux_dr_set_control): Change to static. + (amd64_linux_dr_get_status): Change to static. + (amd64_linux_dr_set_addr,amd64_linux_dr_reset_addr): Likewise. + (_initialize_amd64_linux_nat): Set i386_dr_low variable fields. + + * go32-nat.c: Include "i386-nat.h". + (go32_set_addr): Change to static. + (go32_set_dr7): Change to static. Change arg type to unisgned long. + (go32_get_dr6): Change to static. Change return type to unisnged long. + (init_go32_ops): Set i386_dr_low variable fields. + * i386-linux-nat.c: Include "i386-nat.h". + (i386_linux_dr_set_control, i386_linux_dr_get_status): Change to static. + (i386_linux_dr_set_addr, i386_linux_dr_reset_addr): Idem. + (_initialize_i386_linux_nat): Set i386_dr_low variable fields. + * i386bsd-nat.h: Declare functions used for + i386_dr_low fields in i386fbsd-nat.c. + * i386fbsd-nat.c: Include "i386-nat.h". + (_initialize_i386fbsd_nat): Set i386_dr_low variable fields. + * windows-nat.c: Include "i386-nat.h". + (cygwin_set_dr, cygwin_get_dr6, cygwin_set_dr7): Add prototypes. + Change to static. + (cygwin_get_dr6): Change return type to unisnged long. + (cygwin_set_dr7): Change arg type to unisgned long. + (init_windows_ops): Set i386_dr_low function fields. + + * amd64-windows-nat.c (_initialize_amd64_windows_nat): Call + i386_set_debug_register_length. + * i386-windows-nat.c (_initialize_i386_windows_nat): Likewise. + + * config/i386/nm-cygwin.h: Remove all I386_* macros. + * config/i386/nm-cygwin64.h: Likewise. + * config/i386/nm-fbsd.h: Likewise. + * config/i386/nm-linux.h: Likewise. + * config/i386/nm-i386.h: Remove completely. + * config/i386/nm-go32.h: Remove completely. + * config/i386/nm-linux64.h: Remove completely. + * config/i386/go32.mh (NAT_FILE): Remove entry. + * config/i386/linux64.h (NAT_FILE): Change to config/nm-linux.h. + 2009-05-14 Jon Beniston * MAINTAINERS: Add Jon Beniston to write after approval list. diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c index 2a1b690b2d5..149ba2fc674 100644 --- a/gdb/amd64-linux-nat.c +++ b/gdb/amd64-linux-nat.c @@ -50,6 +50,7 @@ #include "amd64-tdep.h" #include "i386-linux-tdep.h" #include "amd64-nat.h" +#include "i386-nat.h" /* Mapping between the general-purpose registers in GNU/Linux x86-64 `struct user' format and GDB's register cache layout. */ @@ -285,7 +286,7 @@ amd64_linux_dr_set (ptid_t ptid, int regnum, unsigned long value) perror_with_name (_("Couldn't write debug register")); } -void +static void amd64_linux_dr_set_control (unsigned long control) { struct lwp_info *lp; @@ -296,7 +297,7 @@ amd64_linux_dr_set_control (unsigned long control) amd64_linux_dr_set (ptid, DR_CONTROL, control); } -void +static void amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr) { struct lwp_info *lp; @@ -309,13 +310,13 @@ amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr) amd64_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr); } -void +static void amd64_linux_dr_reset_addr (int regnum) { amd64_linux_dr_set_addr (regnum, 0); } -unsigned long +static unsigned long amd64_linux_dr_get_status (void) { return amd64_linux_dr_get (inferior_ptid, DR_STATUS); @@ -667,6 +668,12 @@ _initialize_amd64_linux_nat (void) i386_use_watchpoints (t); + i386_dr_low.set_control = amd64_linux_dr_set_control; + i386_dr_low.set_addr = amd64_linux_dr_set_addr; + i386_dr_low.reset_addr = amd64_linux_dr_reset_addr; + i386_dr_low.get_status = amd64_linux_dr_get_status; + i386_set_debug_register_length (8); + /* Override the GNU/Linux inferior startup hook. */ super_post_startup_inferior = t->to_post_startup_inferior; t->to_post_startup_inferior = amd64_linux_child_post_startup_inferior; diff --git a/gdb/amd64-windows-nat.c b/gdb/amd64-windows-nat.c index d440de1be1f..0e45aae884b 100644 --- a/gdb/amd64-windows-nat.c +++ b/gdb/amd64-windows-nat.c @@ -17,7 +17,7 @@ #include "defs.h" #include "windows-nat.h" - +#include "i386-nat.h" #include #define context_offset(x) (offsetof (CONTEXT, x)) @@ -89,4 +89,5 @@ void _initialize_amd64_windows_nat (void) { windows_set_context_register_offsets (mappings); + i386_set_debug_register_length (8); } diff --git a/gdb/config/i386/go32.mh b/gdb/config/i386/go32.mh index 73dc70ecdff..9cebf01b993 100644 --- a/gdb/config/i386/go32.mh +++ b/gdb/config/i386/go32.mh @@ -3,7 +3,6 @@ # We include several header files from config/djgpp MH_CFLAGS= -I$(srcdir)/config/djgpp -NAT_FILE= nm-go32.h NATDEPFILES= go32-nat.o i386-nat.o HOST_IPC= diff --git a/gdb/config/i386/linux64.mh b/gdb/config/i386/linux64.mh index 1c03d7172c6..e2001ce5560 100644 --- a/gdb/config/i386/linux64.mh +++ b/gdb/config/i386/linux64.mh @@ -2,7 +2,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \ i386-nat.o amd64-nat.o amd64-linux-nat.o linux-nat.o \ proc-service.o linux-thread-db.o gcore.o linux-fork.o -NAT_FILE= nm-linux64.h +NAT_FILE= config/nm-linux.h # The dynamically loaded libthread_db needs access to symbols in the # gdb executable. diff --git a/gdb/config/i386/nm-cygwin.h b/gdb/config/i386/nm-cygwin.h index 9daa74db383..24aa749d740 100644 --- a/gdb/config/i386/nm-cygwin.h +++ b/gdb/config/i386/nm-cygwin.h @@ -18,20 +18,3 @@ #define ADD_SHARED_SYMBOL_FILES dll_symbol_command void dll_symbol_command (char *, int); - -#define I386_USE_GENERIC_WATCHPOINTS - -#include "i386/nm-i386.h" - -/* Support for hardware-assisted breakpoints and watchpoints. */ - -#define I386_DR_LOW_SET_CONTROL(VAL) cygwin_set_dr7 (VAL) -extern void cygwin_set_dr7 (unsigned); - -#define I386_DR_LOW_SET_ADDR(N,ADDR) cygwin_set_dr (N,ADDR) -extern void cygwin_set_dr (int, CORE_ADDR); - -#define I386_DR_LOW_RESET_ADDR(N) - -#define I386_DR_LOW_GET_STATUS() cygwin_get_dr6 () -extern unsigned cygwin_get_dr6 (void); diff --git a/gdb/config/i386/nm-cygwin64.h b/gdb/config/i386/nm-cygwin64.h index 71b26829a0f..345423f3ea7 100644 --- a/gdb/config/i386/nm-cygwin64.h +++ b/gdb/config/i386/nm-cygwin64.h @@ -17,20 +17,3 @@ #define ADD_SHARED_SYMBOL_FILES dll_symbol_command void dll_symbol_command (char *, int); - -#define I386_USE_GENERIC_WATCHPOINTS - -#include "i386/nm-i386.h" - -/* Support for hardware-assisted breakpoints and watchpoints. */ - -#define I386_DR_LOW_SET_CONTROL(VAL) cygwin_set_dr7 (VAL) -extern void cygwin_set_dr7 (unsigned); - -#define I386_DR_LOW_SET_ADDR(N,ADDR) cygwin_set_dr (N,ADDR) -extern void cygwin_set_dr (int, CORE_ADDR); - -#define I386_DR_LOW_RESET_ADDR(N) - -#define I386_DR_LOW_GET_STATUS() cygwin_get_dr6 () -extern unsigned cygwin_get_dr6 (void); diff --git a/gdb/config/i386/nm-fbsd.h b/gdb/config/i386/nm-fbsd.h index 77875dacfff..adfd6d17465 100644 --- a/gdb/config/i386/nm-fbsd.h +++ b/gdb/config/i386/nm-fbsd.h @@ -21,33 +21,8 @@ #ifndef NM_FBSD_H #define NM_FBSD_H -#ifdef HAVE_PT_GETDBREGS -#define I386_USE_GENERIC_WATCHPOINTS -#endif - -#include "i386/nm-i386.h" - #ifdef HAVE_SYS_PARAM_H #include #endif -/* Provide access to the i386 hardware debugging registers. */ - -#define I386_DR_LOW_SET_CONTROL(control) \ - i386bsd_dr_set_control (control) -extern void i386bsd_dr_set_control (unsigned long control); - -#define I386_DR_LOW_SET_ADDR(regnum, addr) \ - i386bsd_dr_set_addr (regnum, addr) -extern void i386bsd_dr_set_addr (int regnum, CORE_ADDR addr); - -#define I386_DR_LOW_RESET_ADDR(regnum) \ - i386bsd_dr_reset_addr (regnum) -extern void i386bsd_dr_reset_addr (int regnum); - -#define I386_DR_LOW_GET_STATUS() \ - i386bsd_dr_get_status () -extern unsigned long i386bsd_dr_get_status (void); - - #endif /* nm-fbsd.h */ diff --git a/gdb/config/i386/nm-go32.h b/gdb/config/i386/nm-go32.h deleted file mode 100644 index 3a6fd1b54c0..00000000000 --- a/gdb/config/i386/nm-go32.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Native definitions for Intel x86 running DJGPP. - Copyright 1997, 1998, 1999, 2001, 2002, 2007, 2008, 2009 - Free Software Foundation, Inc. - - This file is part of GDB. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#define I386_USE_GENERIC_WATCHPOINTS - -#include "i386/nm-i386.h" - -/* Support for hardware-assisted breakpoints and watchpoints. */ - -#define I386_DR_LOW_SET_CONTROL(VAL) go32_set_dr7 (VAL) -extern void go32_set_dr7 (unsigned); - -#define I386_DR_LOW_SET_ADDR(N,ADDR) go32_set_dr (N,ADDR) -extern void go32_set_dr (int, CORE_ADDR); - -#define I386_DR_LOW_RESET_ADDR(N) - -#define I386_DR_LOW_GET_STATUS() go32_get_dr6 () -extern unsigned go32_get_dr6 (void); diff --git a/gdb/config/i386/nm-i386.h b/gdb/config/i386/nm-i386.h deleted file mode 100644 index aafa188c8c4..00000000000 --- a/gdb/config/i386/nm-i386.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Native macro definitions for GDB on an Intel i[3456]86. - Copyright 2001, 2004, 2007, 2008, 2009 Free Software Foundation, Inc. - - This file is part of GDB. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#ifndef NM_I386_H -#define NM_I386_H 1 - -/* Hardware-assisted breakpoints and watchpoints. */ - -/* Targets should define this to use the generic x86 watchpoint support. */ -#ifdef I386_USE_GENERIC_WATCHPOINTS - -/* Add watchpoint methods to the provided target_ops. - Targets which define I386_USE_GENERIC_WATCHPOINTS must - call this function. */ -struct target_ops; -void i386_use_watchpoints (struct target_ops *); - -/* Clear the reference counts and forget everything we knew about DRi. */ -extern void i386_cleanup_dregs (void); - -/* Insert a watchpoint to watch a memory region which starts at - address ADDR and whose length is LEN bytes. Watch memory accesses - of the type TYPE. Return 0 on success, -1 on failure. */ -extern int i386_insert_watchpoint (CORE_ADDR addr, int len, int type); - -/* Remove a watchpoint that watched the memory region which starts at - address ADDR, whose length is LEN bytes, and for accesses of the - type TYPE. Return 0 on success, -1 on failure. */ -extern int i386_remove_watchpoint (CORE_ADDR addr, int len, int type); - -/* Return non-zero if we can watch a memory region that starts at - address ADDR and whose length is LEN bytes. */ -extern int i386_region_ok_for_watchpoint (CORE_ADDR addr, int len); - -/* Return non-zero if the inferior has some break/watchpoint that - triggered. */ -extern int i386_stopped_by_hwbp (void); - -/* If the inferior has some break/watchpoint that triggered, set - the address associated with that break/watchpoint and return - true. Otherwise, return false. */ -extern int i386_stopped_data_address (struct target_ops *, CORE_ADDR *); - -/* Insert a hardware-assisted breakpoint at BP_TGT->placed_address. - Return 0 on success, EBUSY on failure. */ -struct bp_target_info; -extern int i386_insert_hw_breakpoint (struct bp_target_info *bp_tgt); - -/* Remove a hardware-assisted breakpoint at BP_TGT->placed_address. - Return 0 on success, -1 on failure. */ -extern int i386_remove_hw_breakpoint (struct bp_target_info *bp_tgt); - -extern int i386_stopped_by_watchpoint (void); - -#endif /* I386_USE_GENERIC_WATCHPOINTS */ - -#endif /* NM_I386_H */ diff --git a/gdb/config/i386/nm-linux.h b/gdb/config/i386/nm-linux.h index 7fcbfc78df1..589a9f2eec5 100644 --- a/gdb/config/i386/nm-linux.h +++ b/gdb/config/i386/nm-linux.h @@ -22,31 +22,8 @@ #ifndef NM_LINUX_H #define NM_LINUX_H -/* GNU/Linux supports the i386 hardware debugging registers. */ -#define I386_USE_GENERIC_WATCHPOINTS - -#include "i386/nm-i386.h" #include "config/nm-linux.h" -/* Provide access to the i386 hardware debugging registers. */ - -extern void i386_linux_dr_set_control (unsigned long control); -#define I386_DR_LOW_SET_CONTROL(control) \ - i386_linux_dr_set_control (control) - -extern void i386_linux_dr_set_addr (int regnum, CORE_ADDR addr); -#define I386_DR_LOW_SET_ADDR(regnum, addr) \ - i386_linux_dr_set_addr (regnum, addr) - -extern void i386_linux_dr_reset_addr (int regnum); -#define I386_DR_LOW_RESET_ADDR(regnum) \ - i386_linux_dr_reset_addr (regnum) - -extern unsigned long i386_linux_dr_get_status (void); -#define I386_DR_LOW_GET_STATUS() \ - i386_linux_dr_get_status () - - #ifdef HAVE_PTRACE_GETFPXREGS /* Include register set support for the SSE registers. */ #define FILL_FPXREGSET diff --git a/gdb/config/i386/nm-linux64.h b/gdb/config/i386/nm-linux64.h deleted file mode 100644 index cb9166113aa..00000000000 --- a/gdb/config/i386/nm-linux64.h +++ /dev/null @@ -1,53 +0,0 @@ -/* Native support for GNU/Linux x86-64. - - Copyright 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 - Free Software Foundation, Inc. - - Contributed by Jiri Smid, SuSE Labs. - - This file is part of GDB. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#ifndef NM_LINUX64_H -#define NM_LINUX64_H - -/* GNU/Linux supports the i386 hardware debugging registers. */ -#define I386_USE_GENERIC_WATCHPOINTS - -#include "i386/nm-i386.h" -#include "config/nm-linux.h" - -/* Support for 8-byte wide hardware watchpoints. */ -#define TARGET_HAS_DR_LEN_8 1 - -/* Provide access to the i386 hardware debugging registers. */ - -extern void amd64_linux_dr_set_control (unsigned long control); -#define I386_DR_LOW_SET_CONTROL(control) \ - amd64_linux_dr_set_control (control) - -extern void amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr); -#define I386_DR_LOW_SET_ADDR(regnum, addr) \ - amd64_linux_dr_set_addr (regnum, addr) - -extern void amd64_linux_dr_reset_addr (int regnum); -#define I386_DR_LOW_RESET_ADDR(regnum) \ - amd64_linux_dr_reset_addr (regnum) - -extern unsigned long amd64_linux_dr_get_status (void); -#define I386_DR_LOW_GET_STATUS() \ - amd64_linux_dr_get_status () - -#endif /* nm-linux64.h */ diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c index 0f525bf1cae..5af281959b5 100644 --- a/gdb/go32-nat.c +++ b/gdb/go32-nat.c @@ -85,6 +85,7 @@ #include #include "defs.h" +#include "i386-nat.h" #include "inferior.h" #include "gdbthread.h" #include "gdb_wait.h" @@ -768,7 +769,7 @@ go32_can_run (void) /* Pass the address ADDR to the inferior in the I'th debug register. Here we just store the address in D_REGS, the watchpoint will be actually set up when go32_wait runs the debuggee. */ -void +static void go32_set_dr (int i, CORE_ADDR addr) { if (i < 0 || i > 3) @@ -780,8 +781,8 @@ go32_set_dr (int i, CORE_ADDR addr) /* Pass the value VAL to the inferior in the DR7 debug control register. Here we just store the address in D_REGS, the watchpoint will be actually set up when go32_wait runs the debuggee. */ -void -go32_set_dr7 (unsigned val) +static void +go32_set_dr7 (unsigned long val) { CONTROL = val; } @@ -789,7 +790,7 @@ go32_set_dr7 (unsigned val) /* Get the value of the DR6 debug status register from the inferior. Here we just return the value stored in D_REGS, as we've got it from the last go32_wait call. */ -unsigned +static unsigned long go32_get_dr6 (void) { return STATUS; @@ -975,6 +976,13 @@ init_go32_ops (void) i386_use_watchpoints (&go32_ops); + + i386_dr_low.set_control = go32_set_dr7; + i386_dr_low.set_addr = go32_set_dr; + i386_dr_low.reset_addr = NULL; + i386_dr_low.get_status = go32_get_dr6; + i386_set_debug_register_length (4); + go32_ops.to_magic = OPS_MAGIC; /* Initialize child's cwd as empty to be initialized when starting diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c index 2366474657a..8ed39304b13 100644 --- a/gdb/i386-linux-nat.c +++ b/gdb/i386-linux-nat.c @@ -19,6 +19,7 @@ along with this program. If not, see . */ #include "defs.h" +#include "i386-nat.h" #include "inferior.h" #include "gdbcore.h" #include "regcache.h" @@ -629,7 +630,7 @@ i386_linux_dr_set (ptid_t ptid, int regnum, unsigned long value) perror_with_name (_("Couldn't write debug register")); } -void +static void i386_linux_dr_set_control (unsigned long control) { struct lwp_info *lp; @@ -640,7 +641,7 @@ i386_linux_dr_set_control (unsigned long control) i386_linux_dr_set (ptid, DR_CONTROL, control); } -void +static void i386_linux_dr_set_addr (int regnum, CORE_ADDR addr) { struct lwp_info *lp; @@ -653,13 +654,13 @@ i386_linux_dr_set_addr (int regnum, CORE_ADDR addr) i386_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr); } -void +static void i386_linux_dr_reset_addr (int regnum) { i386_linux_dr_set_addr (regnum, 0); } -unsigned long +static unsigned long i386_linux_dr_get_status (void) { return i386_linux_dr_get (inferior_ptid, DR_STATUS); @@ -825,6 +826,12 @@ _initialize_i386_linux_nat (void) i386_use_watchpoints (t); + i386_dr_low.set_control = i386_linux_dr_set_control; + i386_dr_low.set_addr = i386_linux_dr_set_addr; + i386_dr_low.reset_addr = i386_linux_dr_reset_addr; + i386_dr_low.get_status = i386_linux_dr_get_status; + i386_set_debug_register_length (4); + /* Override the default ptrace resume method. */ t->to_resume = i386_linux_resume; diff --git a/gdb/i386-nat.c b/gdb/i386-nat.c index f7cf112738b..49339b0ee95 100644 --- a/gdb/i386-nat.c +++ b/gdb/i386-nat.c @@ -18,11 +18,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "i386-nat.h" #include "defs.h" #include "breakpoint.h" #include "command.h" #include "gdbcmd.h" #include "target.h" +#include "gdb_assert.h" /* Support for hardware watchpoints and breakpoints using the i386 debug registers. @@ -32,38 +34,14 @@ more of the watchpoints triggered and at what address, checking whether a given region can be watched, etc. - A target which wants to use these functions should define several - macros, such as `target_insert_watchpoint' and - `target_stopped_data_address', listed in target.h, to call the - appropriate functions below. It should also define - I386_USE_GENERIC_WATCHPOINTS in its tm.h file. - - In addition, each target should provide several low-level macros - that will be called to insert watchpoints and hardware breakpoints - into the inferior, remove them, and check their status. These - macros are: - - I386_DR_LOW_SET_CONTROL -- set the debug control (DR7) - register to a given value - - I386_DR_LOW_SET_ADDR -- put an address into one debug - register - - I386_DR_LOW_RESET_ADDR -- reset the address stored in - one debug register - - I386_DR_LOW_GET_STATUS -- return the value of the debug - status (DR6) register. - The functions below implement debug registers sharing by reference counts, and allow to watch regions up to 16 bytes long. */ -#ifdef I386_USE_GENERIC_WATCHPOINTS +struct i386_dr_low_type i386_dr_low; + /* Support for 8-byte wide hw watchpoints. */ -#ifndef TARGET_HAS_DR_LEN_8 -#define TARGET_HAS_DR_LEN_8 0 -#endif +#define TARGET_HAS_DR_LEN_8 (i386_dr_low.debug_register_length == 8) /* Debug registers' indices. */ #define DR_NADDR 4 /* The number of debug address registers. */ @@ -168,7 +146,7 @@ /* Mirror the inferior's DRi registers. We keep the status and control registers separated because they don't hold addresses. */ static CORE_ADDR dr_mirror[DR_NADDR]; -static unsigned dr_status_mirror, dr_control_mirror; +static unsigned long dr_status_mirror, dr_control_mirror; /* Reference counts for each debug register. */ static int dr_ref_count[DR_NADDR]; @@ -256,8 +234,8 @@ i386_show_dr (const char *func, CORE_ADDR addr, here. */ : "??unknown??")))); puts_unfiltered (":\n"); - printf_unfiltered ("\tCONTROL (DR7): %08x STATUS (DR6): %08x\n", - dr_control_mirror, dr_status_mirror); + printf_unfiltered ("\tCONTROL (DR7): %s STATUS (DR6): %s\n", + phex (dr_control_mirror, 8), phex (dr_status_mirror, 8)); ALL_DEBUG_REGISTERS(i) { printf_unfiltered ("\ @@ -330,6 +308,9 @@ i386_insert_aligned_watchpoint (CORE_ADDR addr, unsigned len_rw_bits) { int i; + if (!i386_dr_low.set_addr || !i386_dr_low.set_control) + return -1; + /* First, look for an occupied debug register with the same address and the same RW and LEN definitions. If we find one, we can reuse it for this watchpoint as well (and save a register). */ @@ -373,8 +354,8 @@ i386_insert_aligned_watchpoint (CORE_ADDR addr, unsigned len_rw_bits) dr_control_mirror &= I386_DR_CONTROL_MASK; /* Finally, actually pass the info to the inferior. */ - I386_DR_LOW_SET_ADDR (i, addr); - I386_DR_LOW_SET_CONTROL (dr_control_mirror); + i386_dr_low.set_addr (i, addr); + i386_dr_low.set_control (dr_control_mirror); return 0; } @@ -402,8 +383,9 @@ i386_remove_aligned_watchpoint (CORE_ADDR addr, unsigned len_rw_bits) dr_mirror[i] = 0; I386_DR_DISABLE (i); /* Reset it in the inferior. */ - I386_DR_LOW_SET_CONTROL (dr_control_mirror); - I386_DR_LOW_RESET_ADDR (i); + i386_dr_low.set_control (dr_control_mirror); + if (i386_dr_low.reset_addr) + i386_dr_low.reset_addr (i); } retval = 0; } @@ -492,7 +474,7 @@ Invalid value %d of operation in i386_handle_nonaligned_watchpoint.\n"), address ADDR and whose length is LEN bytes. Watch memory accesses of the type TYPE. Return 0 on success, -1 on failure. */ -int +static int i386_insert_watchpoint (CORE_ADDR addr, int len, int type) { int retval; @@ -516,7 +498,7 @@ i386_insert_watchpoint (CORE_ADDR addr, int len, int type) /* Remove a watchpoint that watched the memory region which starts at address ADDR, whose length is LEN bytes, and for accesses of the type TYPE. Return 0 on success, -1 on failure. */ -int +static int i386_remove_watchpoint (CORE_ADDR addr, int len, int type) { int retval; @@ -540,7 +522,7 @@ i386_remove_watchpoint (CORE_ADDR addr, int len, int type) /* Return non-zero if we can watch a memory region that starts at address ADDR and whose length is LEN bytes. */ -int +static int i386_region_ok_for_watchpoint (CORE_ADDR addr, int len) { int nregs; @@ -555,14 +537,14 @@ i386_region_ok_for_watchpoint (CORE_ADDR addr, int len) address associated with that watchpoint and return non-zero. Otherwise, return zero. */ -int +static int i386_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p) { CORE_ADDR addr = 0; int i; int rc = 0; - dr_status_mirror = I386_DR_LOW_GET_STATUS (); + dr_status_mirror = i386_dr_low.get_status (); ALL_DEBUG_REGISTERS(i) { @@ -588,7 +570,7 @@ i386_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p) return rc; } -int +static int i386_stopped_by_watchpoint (void) { CORE_ADDR addr = 0; @@ -598,12 +580,12 @@ i386_stopped_by_watchpoint (void) /* Return non-zero if the inferior has some break/watchpoint that triggered. */ -int +static int i386_stopped_by_hwbp (void) { int i; - dr_status_mirror = I386_DR_LOW_GET_STATUS (); + dr_status_mirror = i386_dr_low.get_status (); if (maint_show_dr) i386_show_dr ("stopped_by_hwbp", 0, 0, hw_execute); @@ -618,7 +600,7 @@ i386_stopped_by_hwbp (void) /* Insert a hardware-assisted breakpoint at BP_TGT->placed_address. Return 0 on success, EBUSY on failure. */ -int +static int i386_insert_hw_breakpoint (struct bp_target_info *bp_tgt) { unsigned len_rw = i386_length_and_rw_bits (1, hw_execute); @@ -634,7 +616,7 @@ i386_insert_hw_breakpoint (struct bp_target_info *bp_tgt) /* Remove a hardware-assisted breakpoint at BP_TGT->placed_address. Return 0 on success, -1 on failure. */ -int +static int i386_remove_hw_breakpoint (struct bp_target_info *bp_tgt) { unsigned len_rw = i386_length_and_rw_bits (1, hw_execute); @@ -670,6 +652,27 @@ i386_can_use_hw_breakpoint (int type, int cnt, int othertype) return 1; } +static void +add_show_debug_regs_command (void) +{ + /* A maintenance command to enable printing the internal DRi mirror + variables. */ + add_setshow_boolean_cmd ("show-debug-regs", class_maintenance, + &maint_show_dr, _("\ +Set whether to show variables that mirror the x86 debug registers."), _("\ +Show whether to show variables that mirror the x86 debug registers."), _("\ +Use \"on\" to enable, \"off\" to disable.\n\ +If enabled, the debug registers values are shown when GDB inserts\n\ +or removes a hardware breakpoint or watchpoint, and when the inferior\n\ +triggers a breakpoint or watchpoint."), + NULL, + NULL, + &maintenance_set_cmdlist, + &maintenance_show_cmdlist); +} + +/* There are only two global functions left. */ + void i386_use_watchpoints (struct target_ops *t) { @@ -688,29 +691,12 @@ i386_use_watchpoints (struct target_ops *t) t->to_remove_hw_breakpoint = i386_remove_hw_breakpoint; } -#endif /* I386_USE_GENERIC_WATCHPOINTS */ - - -/* Provide a prototype to silence -Wmissing-prototypes. */ -void _initialize_i386_nat (void); - void -_initialize_i386_nat (void) +i386_set_debug_register_length (int len) { -#ifdef I386_USE_GENERIC_WATCHPOINTS - /* A maintenance command to enable printing the internal DRi mirror - variables. */ - add_setshow_boolean_cmd ("show-debug-regs", class_maintenance, - &maint_show_dr, _("\ -Set whether to show variables that mirror the x86 debug registers."), _("\ -Show whether to show variables that mirror the x86 debug registers."), _("\ -Use \"on\" to enable, \"off\" to disable.\n\ -If enabled, the debug registers values are shown when GDB inserts\n\ -or removes a hardware breakpoint or watchpoint, and when the inferior\n\ -triggers a breakpoint or watchpoint."), - NULL, - NULL, - &maintenance_set_cmdlist, - &maintenance_show_cmdlist); -#endif + /* This function should be called only once for each native target. */ + gdb_assert (i386_dr_low.debug_register_length == 0); + gdb_assert (len == 4 || len == 8); + i386_dr_low.debug_register_length = len; + add_show_debug_regs_command (); } diff --git a/gdb/i386-nat.h b/gdb/i386-nat.h new file mode 100644 index 00000000000..f49b9f60bfd --- /dev/null +++ b/gdb/i386-nat.h @@ -0,0 +1,89 @@ +/* Native-dependent code for the i386. + + Low level functions to implement Oeprating System specific + code to manipulate I386 debug registers. + + Copyright (C) 2009 + Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "defs.h" + +#ifndef I386_NAT_H +#define I386_NAT_H 1 + +/* Hardware-assisted breakpoints and watchpoints. */ + +/* Add watchpoint methods to the provided target_ops. + Targets using i386 family debug registers for watchpoints should call + this. */ +struct target_ops; +extern void i386_use_watchpoints (struct target_ops *); + +/* Support for hardware watchpoints and breakpoints using the i386 + debug registers. + + This provides several functions for inserting and removing + hardware-assisted breakpoints and watchpoints, testing if one or + more of the watchpoints triggered and at what address, checking + whether a given region can be watched, etc. + + In addition, each target should provide several low-level functions + regrouped into i386_dr_low_type struct below. These functions + that will be called to insert watchpoints and hardware breakpoints + into the inferior, remove them, and check their status. These + functions are: + + set_control -- set the debug control (DR7) + register to a given value + + set_addr -- put an address into one debug + register + + reset_addr -- reset the address stored in + one debug register + + get_status -- return the value of the debug + status (DR6) register. + + Additionally, the native file should set the debug_register_length + field to 4 or 8 depending on the number of bytes used for + deubg registers. */ + +struct i386_dr_low_type + { + void (*set_control) (unsigned long); + void (*set_addr) (int, CORE_ADDR); + void (*reset_addr) (int); + unsigned long (*get_status) (void); + int debug_register_length; + }; + +extern struct i386_dr_low_type i386_dr_low; + +/* Use this function to set i386_dr_low debug_register_length field + rather than setting it directly to check that the length is only + set once. It also enables the 'maint set/show show-debug-regs' + command. */ + +extern void i386_set_debug_register_length (int len); + +/* Use this function to reset the i386-nat.c debug register state. */ + +extern void i386_cleanup_dregs (void); + +#endif /* I386_NAT_H */ diff --git a/gdb/i386-windows-nat.c b/gdb/i386-windows-nat.c index 5d339453e64..da756e573b4 100644 --- a/gdb/i386-windows-nat.c +++ b/gdb/i386-windows-nat.c @@ -17,6 +17,7 @@ #include "defs.h" #include "windows-nat.h" +#include "i386-nat.h" #include @@ -73,4 +74,5 @@ void _initialize_i386_windows_nat (void) { windows_set_context_register_offsets (mappings); + i386_set_debug_register_length (4); } diff --git a/gdb/i386bsd-nat.h b/gdb/i386bsd-nat.h index f9772c7c747..7bf53f3c0c3 100644 --- a/gdb/i386bsd-nat.h +++ b/gdb/i386bsd-nat.h @@ -25,4 +25,14 @@ extern struct target_ops *i386bsd_target (void); +/* low level i386 debug register functions used in i386fbsd-nat.c. */ + +extern void i386bsd_dr_set_control (unsigned long control); + +extern void i386bsd_dr_set_addr (int regnum, CORE_ADDR addr); + +extern void i386bsd_dr_reset_addr (int regnum); + +extern unsigned long i386bsd_dr_get_status (void); + #endif /* i386bsd-nat.h */ diff --git a/gdb/i386fbsd-nat.c b/gdb/i386fbsd-nat.c index 0fb7a4aca18..ad5689234b1 100644 --- a/gdb/i386fbsd-nat.c +++ b/gdb/i386fbsd-nat.c @@ -29,6 +29,7 @@ #include "fbsd-nat.h" #include "i386-tdep.h" +#include "i386-nat.h" #include "i386bsd-nat.h" /* Resume execution of the inferior process. If STEP is nonzero, @@ -126,7 +127,20 @@ _initialize_i386fbsd_nat (void) /* Add some extra features to the common *BSD/i386 target. */ t = i386bsd_target (); + +#ifdef HAVE_PT_GETDBREGS + i386_use_watchpoints (t); + + i386_dr_low.set_control = i386bsd_dr_set_control; + i386_dr_low.set_addr = i386bsd_dr_set_addr; + i386_dr_low.reset_addr = i386bsd_dr_reset_addr; + i386_dr_low.get_status = i386bsd_dr_get_status; + i386_set_debug_register_length (4); + +#endif /* HAVE_PT_GETDBREGS */ + + t->to_resume = i386fbsd_resume; t->to_pid_to_exec_file = fbsd_pid_to_exec_file; t->to_find_memory_regions = fbsd_find_memory_regions; diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 09c134c6491..5b9b6f9700a 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -63,6 +63,7 @@ #include "windows-tdep.h" #include "windows-nat.h" +#include "i386-nat.h" #define AdjustTokenPrivileges dyn_AdjustTokenPrivileges #define DebugActiveProcessStop dyn_DebugActiveProcessStop @@ -140,6 +141,10 @@ static void windows_stop (ptid_t); static int windows_thread_alive (struct target_ops *, ptid_t); static void windows_kill_inferior (struct target_ops *); +static void cygwin_set_dr (int i, CORE_ADDR addr); +static void cygwin_set_dr7 (unsigned long val); +static unsigned long cygwin_get_dr6 (void); + static enum target_signal last_sig = TARGET_SIGNAL_0; /* Set if a signal was received from the debugged process */ @@ -2166,8 +2171,18 @@ init_windows_ops (void) windows_ops.to_has_execution = 1; windows_ops.to_pid_to_exec_file = windows_pid_to_exec_file; windows_ops.to_get_ada_task_ptid = windows_get_ada_task_ptid; + i386_use_watchpoints (&windows_ops); + i386_dr_low.set_control = cygwin_set_dr7; + i386_dr_low.set_addr = cygwin_set_dr; + i386_dr_low.reset_addr = NULL; + i386_dr_low.get_status = cygwin_get_dr6; + + /* i386_dr_low.debug_register_length field is set by + calling i386_set_debug_register_length function + in processor windows specific native file. */ + windows_ops.to_magic = OPS_MAGIC; } @@ -2265,7 +2280,7 @@ Show whether to display kernel exceptions in child process."), NULL, /* Pass the address ADDR to the inferior in the I'th debug register. Here we just store the address in dr array, the registers will be actually set up when windows_continue is called. */ -void +static void cygwin_set_dr (int i, CORE_ADDR addr) { if (i < 0 || i > 3) @@ -2279,10 +2294,10 @@ cygwin_set_dr (int i, CORE_ADDR addr) /* Pass the value VAL to the inferior in the DR7 debug control register. Here we just store the address in D_REGS, the watchpoint will be actually set up in windows_wait. */ -void -cygwin_set_dr7 (unsigned val) +static void +cygwin_set_dr7 (unsigned long val) { - dr[7] = val; + dr[7] = (CORE_ADDR) val; debug_registers_changed = 1; debug_registers_used = 1; } @@ -2290,10 +2305,10 @@ cygwin_set_dr7 (unsigned val) /* Get the value of the DR6 debug status register from the inferior. Here we just return the value stored in dr[6] by the last call to thread_rec for current_event.dwThreadId id. */ -unsigned +static unsigned long cygwin_get_dr6 (void) { - return dr[6]; + return (unsigned long) dr[6]; } /* Determine if the thread referenced by "ptid" is alive -- 2.30.2