summaryrefslogtreecommitdiff
path: root/gdb/i386-nat.c
diff options
context:
space:
mode:
authorPierre Muller <muller@ics.u-strasbg.fr>2009-05-14 09:36:58 +0000
committerPierre Muller <muller@ics.u-strasbg.fr>2009-05-14 09:36:58 +0000
commitf509aee5ba3a4016bcf8cf7ecdeceb2784ea6462 (patch)
tree76820b4cca65edf58fb4aba241bdf1c5a15472a8 /gdb/i386-nat.c
parentb6a4d59813c27fcf269044082225c6c6dcda894b (diff)
downloadgdb-f509aee5ba3a4016bcf8cf7ecdeceb2784ea6462.tar.gz
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.
Diffstat (limited to 'gdb/i386-nat.c')
-rw-r--r--gdb/i386-nat.c120
1 files changed, 53 insertions, 67 deletions
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 <http://www.gnu.org/licenses/>. */
+#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 ();
}