*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / record.c
index d2c6b77d2a984ca6bd302e5fe2f54dcd25d065ba..fa6cfbbee89d99364cc4a15c86ba9c273e93f0bc 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.
 
@@ -572,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;
@@ -616,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."));
@@ -648,15 +642,29 @@ record_message (void *args)
   return 1;
 }
 
+struct record_message_args {
+  struct regcache *regcache;
+  enum target_signal signal;
+};
+
+static int
+record_message_wrapper (void *args)
+{
+  struct record_message_args *record_args = args;
+
+  return record_message (record_args->regcache, record_args->signal);
+}
+
 static int
-do_record_message (struct regcache *regcache,
-                  enum target_signal signal)
+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
@@ -859,6 +867,10 @@ record_open_1 (char *name, int from_tty)
     error (_("Could not find 'to_insert_breakpoint' method on the target stack."));
   if (!tmp_to_remove_breakpoint)
     error (_("Could not find 'to_remove_breakpoint' method on the target stack."));
+  if (!tmp_to_stopped_by_watchpoint)
+    error (_("Could not find 'to_stopped_by_watchpoint' method on the target stack."));
+  if (!tmp_to_stopped_data_address)
+    error (_("Could not find 'to_stopped_data_address' method on the target stack."));
 
   push_target (&record_ops);
 }
@@ -889,6 +901,8 @@ record_open (char *name, int from_tty)
   tmp_to_xfer_partial = NULL;
   tmp_to_insert_breakpoint = NULL;
   tmp_to_remove_breakpoint = NULL;
+  tmp_to_stopped_by_watchpoint = NULL;
+  tmp_to_stopped_data_address = NULL;
 
   /* Set the beneath function pointers.  */
   for (t = current_target.beneath; t != NULL; t = t->beneath)
@@ -983,7 +997,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.  */
 
@@ -995,15 +1008,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);
     }
@@ -1067,14 +1072,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.  */
@@ -1097,6 +1094,7 @@ 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
@@ -1105,29 +1103,37 @@ record_wait (struct target_ops *ops,
                  registers_changed ();
                  regcache = get_current_regcache ();
                  tmp_pc = regcache_read_pc (regcache);
+                 aspace = get_regcache_aspace (regcache);
 
                  if (target_stopped_by_watchpoint ())
                    {
                      /* Always interested in watchpoints.  */
                    }
-                 else if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
-                                                      tmp_pc))
+                 else if (breakpoint_inserted_here_p (aspace, tmp_pc))
                    {
                      /* There is a breakpoint here.  Let the core
                         handle it.  */
-                     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);
+                     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
                    {
                      /* This must be a single-step trap.  Record the
                         insn and issue another step.  */
-                     if (!do_record_message (regcache, TARGET_SIGNAL_0))
-                       break;
+                     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,
@@ -1147,6 +1153,7 @@ 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);
@@ -1159,18 +1166,20 @@ record_wait (struct target_ops *ops,
       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;
            }
        }
@@ -1240,28 +1249,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");
+                       fprintf_unfiltered (gdb_stdlog, "\
+Process record: hit hw watchpoint.\n");
                      continue_flag = 0;
                    }
                  /* Check target signal */
@@ -1658,6 +1670,7 @@ init_record_ops (void)
   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.  */
@@ -1866,6 +1879,7 @@ init_record_core_ops (void)
   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;
@@ -2161,16 +2175,16 @@ record_restore (void)
   while (1)
     {
       int ret;
-      uint8_t tmpu8;
+      uint8_t rectype;
       uint32_t regnum, len, signal, count;
       uint64_t addr;
 
       /* We are finished when offset reaches osec_size.  */
       if (bfd_offset >= osec_size)
        break;
-      bfdcore_read (core_bfd, osec, &tmpu8, sizeof (tmpu8), &bfd_offset);
+      bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
 
-      switch (tmpu8)
+      switch (rectype)
         {
         case record_reg: /* reg */
           /* Get register number to regnum.  */
This page took 0.030132 seconds and 4 git commands to generate.