* dwarf2read.c (dwarf_decode_lines): Ignore rows where is_stmt is 0.
[deliverable/binutils-gdb.git] / gdb / i386-nat.c
index f7cf112738b549d28877381c99b53f4b7e406401..49339b0ee9543b501ff88365e476c4ebebddd0f5 100644 (file)
    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.
    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.  */
 /* 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 */
-\f
-
-/* 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 ();
 }
This page took 0.026299 seconds and 4 git commands to generate.