* script.cc (class Lazy_demangler): Recreate--revert part of patch
[deliverable/binutils-gdb.git] / gdb / record.c
index 12b74a59fd938e4b92af5afa80cfa760eccb3bf0..1f68d0496f55d36f1bc3e90b79a12de66bbe2ec1 100644 (file)
@@ -1,6 +1,6 @@
 /* Process record and replay target for GDB, the GNU debugger.
 
-   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -224,6 +224,9 @@ static int (*record_beneath_to_insert_breakpoint) (struct gdbarch *,
                                                   struct bp_target_info *);
 static int (*record_beneath_to_remove_breakpoint) (struct gdbarch *,
                                                   struct bp_target_info *);
+static int (*record_beneath_to_stopped_by_watchpoint) (void);
+static int (*record_beneath_to_stopped_data_address) (struct target_ops *,
+                                                     CORE_ADDR *);
 
 /* Alloc and free functions for record_reg, record_mem, and record_end 
    entries.  */
@@ -569,17 +572,11 @@ record_arch_list_cleanups (void *ignore)
    record the running message of inferior and set them to
    record_arch_list, and add it to record_list.  */
 
-struct record_message_args {
-  struct regcache *regcache;
-  enum target_signal signal;
-};
-
 static int
-record_message (void *args)
+record_message (struct regcache *regcache, enum target_signal signal)
 {
   int ret;
-  struct record_message_args *myargs = args;
-  struct gdbarch *gdbarch = get_regcache_arch (myargs->regcache);
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   struct cleanup *old_cleanups = make_cleanup (record_arch_list_cleanups, 0);
 
   record_arch_list_head = NULL;
@@ -613,18 +610,18 @@ record_message (void *args)
   if (record_list != &record_first)    /* FIXME better way to check */
     {
       gdb_assert (record_list->type == record_end);
-      record_list->u.end.sigval = myargs->signal;
+      record_list->u.end.sigval = signal;
     }
 
-  if (myargs->signal == TARGET_SIGNAL_0
+  if (signal == TARGET_SIGNAL_0
       || !gdbarch_process_record_signal_p (gdbarch))
     ret = gdbarch_process_record (gdbarch,
-                                 myargs->regcache,
-                                 regcache_read_pc (myargs->regcache));
+                                 regcache,
+                                 regcache_read_pc (regcache));
   else
     ret = gdbarch_process_record_signal (gdbarch,
-                                        myargs->regcache,
-                                        myargs->signal);
+                                        regcache,
+                                        signal);
 
   if (ret > 0)
     error (_("Process record: inferior program stopped."));
@@ -645,15 +642,29 @@ record_message (void *args)
   return 1;
 }
 
+struct record_message_args {
+  struct regcache *regcache;
+  enum target_signal signal;
+};
+
 static int
-do_record_message (struct regcache *regcache,
-                  enum target_signal signal)
+record_message_wrapper (void *args)
+{
+  struct record_message_args *record_args = args;
+
+  return record_message (record_args->regcache, record_args->signal);
+}
+
+static int
+record_message_wrapper_safe (struct regcache *regcache,
+                             enum target_signal signal)
 {
   struct record_message_args args;
 
   args.regcache = regcache;
   args.signal = signal;
-  return catch_errors (record_message, &args, NULL, RETURN_MASK_ALL);
+
+  return catch_errors (record_message_wrapper, &args, NULL, RETURN_MASK_ALL);
 }
 
 /* Set to 1 if record_store_registers and record_xfer_partial
@@ -673,6 +684,9 @@ record_gdb_operation_disable_set (void)
   return old_cleanups;
 }
 
+/* Flag set to TRUE for target_stopped_by_watchpoint.  */
+static int record_hw_watchpoint = 0;
+
 /* Execute one instruction from the record log.  Each instruction in
    the log will be represented by an arbitrary sequence of register
    entries and memory entries, followed by an 'end' entry.  */
@@ -739,7 +753,22 @@ record_exec_insn (struct regcache *regcache, struct gdbarch *gdbarch,
                                entry->u.mem.len);
                   }
                 else
-                  memcpy (record_get_loc (entry), mem, entry->u.mem.len);
+                 {
+                   memcpy (record_get_loc (entry), mem, entry->u.mem.len);
+
+                   /* We've changed memory --- check if a hardware
+                      watchpoint should trap.  Note that this
+                      presently assumes the target beneath supports
+                      continuable watchpoints.  On non-continuable
+                      watchpoints target, we'll want to check this
+                      _before_ actually doing the memory change, and
+                      not doing the change at all if the watchpoint
+                      traps.  */
+                   if (hardware_watchpoint_inserted_in_range
+                       (get_regcache_aspace (regcache),
+                        entry->u.mem.addr, entry->u.mem.len))
+                     record_hw_watchpoint = 1;
+                 }
               }
           }
       }
@@ -770,6 +799,8 @@ static int (*tmp_to_insert_breakpoint) (struct gdbarch *,
                                        struct bp_target_info *);
 static int (*tmp_to_remove_breakpoint) (struct gdbarch *,
                                        struct bp_target_info *);
+static int (*tmp_to_stopped_by_watchpoint) (void);
+static int (*tmp_to_stopped_data_address) (struct target_ops *, CORE_ADDR *);
 
 static void record_restore (void);
 
@@ -894,6 +925,10 @@ record_open (char *name, int from_tty)
        tmp_to_insert_breakpoint = t->to_insert_breakpoint;
       if (!tmp_to_remove_breakpoint)
        tmp_to_remove_breakpoint = t->to_remove_breakpoint;
+      if (!tmp_to_stopped_by_watchpoint)
+       tmp_to_stopped_by_watchpoint = t->to_stopped_by_watchpoint;
+      if (!tmp_to_stopped_data_address)
+       tmp_to_stopped_data_address = t->to_stopped_data_address;
     }
   if (!tmp_to_xfer_partial)
     error (_("Could not find 'to_xfer_partial' method on the target stack."));
@@ -915,6 +950,8 @@ record_open (char *name, int from_tty)
   record_beneath_to_xfer_partial = tmp_to_xfer_partial;
   record_beneath_to_insert_breakpoint = tmp_to_insert_breakpoint;
   record_beneath_to_remove_breakpoint = tmp_to_remove_breakpoint;
+  record_beneath_to_stopped_by_watchpoint = tmp_to_stopped_by_watchpoint;
+  record_beneath_to_stopped_data_address = tmp_to_stopped_data_address;
 
   if (current_target.to_stratum == core_stratum)
     record_core_open_1 (name, from_tty);
@@ -954,7 +991,6 @@ record_close (int quitting)
 }
 
 static int record_resume_step = 0;
-static int record_resume_error;
 
 /* "to_resume" target method.  Resume the process record target.  */
 
@@ -966,15 +1002,7 @@ record_resume (struct target_ops *ops, ptid_t ptid, int step,
 
   if (!RECORD_IS_REPLAY)
     {
-      if (do_record_message (get_current_regcache (), signal))
-        {
-          record_resume_error = 0;
-        }
-      else
-        {
-          record_resume_error = 1;
-          return;
-        }
+      record_message (get_current_regcache (), signal);
       record_beneath_to_resume (record_beneath_to_resume_ops, ptid, 1,
                                 signal);
     }
@@ -1038,14 +1066,6 @@ record_wait (struct target_ops *ops,
 
   if (!RECORD_IS_REPLAY && ops != &record_core_ops)
     {
-      if (record_resume_error)
-       {
-         /* If record_resume get error, return directly.  */
-         status->kind = TARGET_WAITKIND_STOPPED;
-         status->value.sig = TARGET_SIGNAL_ABRT;
-         return inferior_ptid;
-       }
-
       if (record_resume_step)
        {
          /* This is a single step.  */
@@ -1068,30 +1088,46 @@ record_wait (struct target_ops *ops,
                  && status->value.sig == TARGET_SIGNAL_TRAP)
                {
                  struct regcache *regcache;
+                 struct address_space *aspace;
+
+                 /* Yes -- this is likely our single-step finishing,
+                    but check if there's any reason the core would be
+                    interested in the event.  */
 
-                 /* Yes -- check if there is a breakpoint.  */
                  registers_changed ();
                  regcache = get_current_regcache ();
                  tmp_pc = regcache_read_pc (regcache);
-                 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
-                                                 tmp_pc))
+                 aspace = get_regcache_aspace (regcache);
+
+                 if (target_stopped_by_watchpoint ())
                    {
-                     /* There is a breakpoint.  GDB will want to stop.  */
-                     struct gdbarch *gdbarch = get_regcache_arch (regcache);
-                     CORE_ADDR decr_pc_after_break
-                       = gdbarch_decr_pc_after_break (gdbarch);
-                     if (decr_pc_after_break)
-                       regcache_write_pc (regcache,
-                                          tmp_pc + decr_pc_after_break);
+                     /* Always interested in watchpoints.  */
+                   }
+                 else if (breakpoint_inserted_here_p (aspace, tmp_pc))
+                   {
+                     /* There is a breakpoint here.  Let the core
+                        handle it.  */
+                     if (software_breakpoint_inserted_here_p (aspace, tmp_pc))
+                       {
+                         struct gdbarch *gdbarch = get_regcache_arch (regcache);
+                         CORE_ADDR decr_pc_after_break
+                           = gdbarch_decr_pc_after_break (gdbarch);
+                         if (decr_pc_after_break)
+                           regcache_write_pc (regcache,
+                                              tmp_pc + decr_pc_after_break);
+                       }
                    }
                  else
                    {
-                     /* There is not a breakpoint, and gdb is not
-                        stepping, therefore gdb will not stop.
-                        Therefore we will not return to gdb.
-                        Record the insn and resume.  */
-                     if (!do_record_message (regcache, TARGET_SIGNAL_0))
-                       break;
+                     /* This must be a single-step trap.  Record the
+                        insn and issue another step.  */
+                     if (!record_message_wrapper_safe (regcache,
+                                                        TARGET_SIGNAL_0))
+                       {
+                           status->kind = TARGET_WAITKIND_STOPPED;
+                           status->value.sig = TARGET_SIGNAL_0;
+                           break;
+                       }
 
                      record_beneath_to_resume (record_beneath_to_resume_ops,
                                                ptid, 1,
@@ -1111,29 +1147,33 @@ record_wait (struct target_ops *ops,
     {
       struct regcache *regcache = get_current_regcache ();
       struct gdbarch *gdbarch = get_regcache_arch (regcache);
+      struct address_space *aspace = get_regcache_aspace (regcache);
       int continue_flag = 1;
       int first_record_end = 1;
       struct cleanup *old_cleanups = make_cleanup (record_wait_cleanups, 0);
       CORE_ADDR tmp_pc;
 
+      record_hw_watchpoint = 0;
       status->kind = TARGET_WAITKIND_STOPPED;
 
       /* Check breakpoint when forward execute.  */
       if (execution_direction == EXEC_FORWARD)
        {
          tmp_pc = regcache_read_pc (regcache);
-         if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
-                                         tmp_pc))
+         if (breakpoint_inserted_here_p (aspace, tmp_pc))
            {
+             int decr_pc_after_break = gdbarch_decr_pc_after_break (gdbarch);
+
              if (record_debug)
                fprintf_unfiltered (gdb_stdlog,
                                    "Process record: break at %s.\n",
                                    paddress (gdbarch, tmp_pc));
-             if (gdbarch_decr_pc_after_break (gdbarch)
-                 && !record_resume_step)
+
+             if (decr_pc_after_break
+                 && !record_resume_step
+                 && software_breakpoint_inserted_here_p (aspace, tmp_pc))
                regcache_write_pc (regcache,
-                                  tmp_pc +
-                                  gdbarch_decr_pc_after_break (gdbarch));
+                                  tmp_pc + decr_pc_after_break);
              goto replay_out;
            }
        }
@@ -1203,20 +1243,31 @@ record_wait (struct target_ops *ops,
 
                  /* check breakpoint */
                  tmp_pc = regcache_read_pc (regcache);
-                 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
-                                                 tmp_pc))
+                 if (breakpoint_inserted_here_p (aspace, tmp_pc))
                    {
+                     int decr_pc_after_break
+                       = gdbarch_decr_pc_after_break (gdbarch);
+
                      if (record_debug)
                        fprintf_unfiltered (gdb_stdlog,
                                            "Process record: break "
                                            "at %s.\n",
                                            paddress (gdbarch, tmp_pc));
-                     if (gdbarch_decr_pc_after_break (gdbarch)
+                     if (decr_pc_after_break
                          && execution_direction == EXEC_FORWARD
-                         && !record_resume_step)
+                         && !record_resume_step
+                         && software_breakpoint_inserted_here_p (aspace,
+                                                                 tmp_pc))
                        regcache_write_pc (regcache,
-                                          tmp_pc +
-                                          gdbarch_decr_pc_after_break (gdbarch));
+                                          tmp_pc + decr_pc_after_break);
+                     continue_flag = 0;
+                   }
+
+                 if (record_hw_watchpoint)
+                   {
+                     if (record_debug)
+                       fprintf_unfiltered (gdb_stdlog, "\
+Process record: hit hw watchpoint.\n");
                      continue_flag = 0;
                    }
                  /* Check target signal */
@@ -1260,6 +1311,24 @@ replay_out:
   return inferior_ptid;
 }
 
+static int
+record_stopped_by_watchpoint (void)
+{
+  if (RECORD_IS_REPLAY)
+    return record_hw_watchpoint;
+  else
+    return record_beneath_to_stopped_by_watchpoint ();
+}
+
+static int
+record_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
+{
+  if (RECORD_IS_REPLAY)
+    return 0;
+  else
+    return record_beneath_to_stopped_data_address (ops, addr_p);
+}
+
 /* "to_disconnect" method for process record target.  */
 
 static void
@@ -1594,6 +1663,8 @@ init_record_ops (void)
   record_ops.to_xfer_partial = record_xfer_partial;
   record_ops.to_insert_breakpoint = record_insert_breakpoint;
   record_ops.to_remove_breakpoint = record_remove_breakpoint;
+  record_ops.to_stopped_by_watchpoint = record_stopped_by_watchpoint;
+  record_ops.to_stopped_data_address = record_stopped_data_address;
   record_ops.to_can_execute_reverse = record_can_execute_reverse;
   record_ops.to_stratum = record_stratum;
   /* Add bookmark target methods.  */
@@ -1801,6 +1872,8 @@ init_record_core_ops (void)
   record_core_ops.to_xfer_partial = record_core_xfer_partial;
   record_core_ops.to_insert_breakpoint = record_core_insert_breakpoint;
   record_core_ops.to_remove_breakpoint = record_core_remove_breakpoint;
+  record_core_ops.to_stopped_by_watchpoint = record_stopped_by_watchpoint;
+  record_core_ops.to_stopped_data_address = record_stopped_data_address;
   record_core_ops.to_can_execute_reverse = record_can_execute_reverse;
   record_core_ops.to_has_execution = record_core_has_execution;
   record_core_ops.to_stratum = record_stratum;
This page took 0.027444 seconds and 4 git commands to generate.