2009-09-02 Hui Zhu <teawater@gmail.com>
[deliverable/binutils-gdb.git] / gdb / record.c
index 40cc1745a9cb8ad7dedeed5bc6f1aef96a4d5582..650f2a1399e3a75981d9ec66abc1312e4765c959 100644 (file)
@@ -51,6 +51,9 @@ struct record_mem_entry
 {
   CORE_ADDR addr;
   int len;
+  /* Set this flag if target memory for this entry
+     can no longer be accessed.  */
+  int mem_entry_not_accessible;
   gdb_byte *val;
 };
 
@@ -98,7 +101,8 @@ static void (*record_beneath_to_resume) (struct target_ops *, ptid_t, int,
                                          enum target_signal);
 static struct target_ops *record_beneath_to_wait_ops;
 static ptid_t (*record_beneath_to_wait) (struct target_ops *, ptid_t,
-                                        struct target_waitstatus *);
+                                        struct target_waitstatus *,
+                                        int);
 static struct target_ops *record_beneath_to_store_registers_ops;
 static void (*record_beneath_to_store_registers) (struct target_ops *,
                                                   struct regcache *,
@@ -111,8 +115,10 @@ static LONGEST (*record_beneath_to_xfer_partial) (struct target_ops *ops,
                                                  const gdb_byte *writebuf,
                                                  ULONGEST offset,
                                                  LONGEST len);
-static int (*record_beneath_to_insert_breakpoint) (struct bp_target_info *);
-static int (*record_beneath_to_remove_breakpoint) (struct bp_target_info *);
+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 void
 record_list_release (struct record_entry *rec)
@@ -151,7 +157,7 @@ record_list_release_next (void)
   while (tmp)
     {
       rec = tmp->next;
-      if (tmp->type == record_reg)
+      if (tmp->type == record_end)
        record_insn_num--;
       else if (tmp->type == record_reg)
        xfree (tmp->u.reg.val);
@@ -258,9 +264,9 @@ record_arch_list_add_mem (CORE_ADDR addr, int len)
 
   if (record_debug > 1)
     fprintf_unfiltered (gdb_stdlog,
-                       "Process record: add mem addr = 0x%s len = %d to "
+                       "Process record: add mem addr = %s len = %d to "
                        "record list.\n",
-                       paddr_nz (addr), len);
+                       paddress (target_gdbarch, addr), len);
 
   if (!addr)
     return 0;
@@ -272,14 +278,15 @@ record_arch_list_add_mem (CORE_ADDR addr, int len)
   rec->type = record_mem;
   rec->u.mem.addr = addr;
   rec->u.mem.len = len;
+  rec->u.mem.mem_entry_not_accessible = 0;
 
   if (target_read_memory (addr, rec->u.mem.val, len))
     {
       if (record_debug)
        fprintf_unfiltered (gdb_stdlog,
                            "Process record: error reading memory at "
-                           "addr = 0x%s len = %d.\n",
-                           paddr_nz (addr), len);
+                           "addr = %s len = %d.\n",
+                           paddress (target_gdbarch, addr), len);
       xfree (rec->u.mem.val);
       xfree (rec);
       return -1;
@@ -427,7 +434,7 @@ record_open (char *name, int from_tty)
     error (_("Process record target can't debug inferior in asynchronous "
             "mode (target-async)."));
 
-  if (!gdbarch_process_record_p (current_gdbarch))
+  if (!gdbarch_process_record_p (target_gdbarch))
     error (_("Process record: the current architecture doesn't support "
             "record function."));
 
@@ -507,7 +514,6 @@ record_close (int quitting)
 }
 
 static int record_resume_step = 0;
-static enum target_signal record_resume_siggnal;
 static int record_resume_error;
 
 static void
@@ -515,7 +521,6 @@ record_resume (struct target_ops *ops, ptid_t ptid, int step,
                enum target_signal siggnal)
 {
   record_resume_step = step;
-  record_resume_siggnal = siggnal;
 
   if (!RECORD_IS_REPLAY)
     {
@@ -566,7 +571,8 @@ record_wait_cleanups (void *ignore)
 
 static ptid_t
 record_wait (struct target_ops *ops,
-              ptid_t ptid, struct target_waitstatus *status)
+            ptid_t ptid, struct target_waitstatus *status,
+            int options)
 {
   struct cleanup *set_cleanups = record_gdb_operation_disable_set ();
 
@@ -590,7 +596,7 @@ record_wait (struct target_ops *ops,
        {
          /* This is a single step.  */
          return record_beneath_to_wait (record_beneath_to_wait_ops,
-                                                      ptid, status);
+                                        ptid, status, options);
        }
       else
        {
@@ -601,14 +607,14 @@ record_wait (struct target_ops *ops,
          while (1)
            {
              ret = record_beneath_to_wait (record_beneath_to_wait_ops,
-                                           ptid, status);
+                                           ptid, status, options);
 
              if (status->kind == TARGET_WAITKIND_STOPPED
                  && status->value.sig == TARGET_SIGNAL_TRAP)
                {
                  /* Check if there is a breakpoint.  */
                  registers_changed ();
-                 tmp_pc = read_pc ();
+                 tmp_pc = regcache_read_pc (get_current_regcache ());
                  if (breakpoint_inserted_here_p (tmp_pc))
                    {
                      /* There is a breakpoint.  */
@@ -630,7 +636,7 @@ record_wait (struct target_ops *ops,
                        }
                      record_beneath_to_resume (record_beneath_to_resume_ops,
                                                ptid, 1,
-                                               record_resume_siggnal);
+                                               TARGET_SIGNAL_0);
                      continue;
                    }
                }
@@ -645,6 +651,7 @@ record_wait (struct target_ops *ops,
   else
     {
       struct regcache *regcache = get_current_regcache ();
+      struct gdbarch *gdbarch = get_regcache_arch (regcache);
       int continue_flag = 1;
       int first_record_end = 1;
       struct cleanup *old_cleanups = make_cleanup (record_wait_cleanups, 0);
@@ -660,14 +667,13 @@ record_wait (struct target_ops *ops,
            {
              if (record_debug)
                fprintf_unfiltered (gdb_stdlog,
-                                   "Process record: break at 0x%s.\n",
-                                   paddr_nz (tmp_pc));
-             if (gdbarch_decr_pc_after_break (get_regcache_arch (regcache))
+                                   "Process record: break at %s.\n",
+                                   paddress (gdbarch, tmp_pc));
+             if (gdbarch_decr_pc_after_break (gdbarch)
                  && !record_resume_step)
                regcache_write_pc (regcache,
                                   tmp_pc +
-                                  gdbarch_decr_pc_after_break
-                                  (get_regcache_arch (regcache)));
+                                  gdbarch_decr_pc_after_break (gdbarch));
              goto replay_out;
            }
        }
@@ -723,32 +729,55 @@ record_wait (struct target_ops *ops,
          else if (record_list->type == record_mem)
            {
              /* mem */
-             gdb_byte *mem = alloca (record_list->u.mem.len);
-             if (record_debug > 1)
-               fprintf_unfiltered (gdb_stdlog,
-                                   "Process record: record_mem %s to "
-                                   "inferior addr = 0x%s len = %d.\n",
-                                   host_address_to_string (record_list),
-                                   paddr_nz (record_list->u.mem.addr),
-                                   record_list->u.mem.len);
-
-             if (target_read_memory
-                 (record_list->u.mem.addr, mem, record_list->u.mem.len))
-               error (_("Process record: error reading memory at "
-                        "addr = 0x%s len = %d."),
-                      paddr_nz (record_list->u.mem.addr),
-                      record_list->u.mem.len);
-
-             if (target_write_memory
-                 (record_list->u.mem.addr, record_list->u.mem.val,
-                  record_list->u.mem.len))
-               error (_
-                      ("Process record: error writing memory at "
-                       "addr = 0x%s len = %d."),
-                      paddr_nz (record_list->u.mem.addr),
-                      record_list->u.mem.len);
-
-             memcpy (record_list->u.mem.val, mem, record_list->u.mem.len);
+             /* Nothing to do if the entry is flagged not_accessible.  */
+             if (!record_list->u.mem.mem_entry_not_accessible)
+               {
+                 gdb_byte *mem = alloca (record_list->u.mem.len);
+                 if (record_debug > 1)
+                   fprintf_unfiltered (gdb_stdlog,
+                                       "Process record: record_mem %s to "
+                                       "inferior addr = %s len = %d.\n",
+                                       host_address_to_string (record_list),
+                                       paddress (gdbarch,
+                                                 record_list->u.mem.addr),
+                                       record_list->u.mem.len);
+
+                 if (target_read_memory (record_list->u.mem.addr, mem,
+                                         record_list->u.mem.len))
+                   {
+                     if (execution_direction != EXEC_REVERSE)
+                       error (_("Process record: error reading memory at "
+                                "addr = %s len = %d."),
+                              paddress (gdbarch, record_list->u.mem.addr),
+                              record_list->u.mem.len);
+                     else
+                       /* Read failed -- 
+                          flag entry as not_accessible.  */
+                       record_list->u.mem.mem_entry_not_accessible = 1;
+                   }
+                 else
+                   {
+                     if (target_write_memory (record_list->u.mem.addr,
+                                              record_list->u.mem.val,
+                                              record_list->u.mem.len))
+                       {
+                         if (execution_direction != EXEC_REVERSE)
+                           error (_("Process record: error writing memory at "
+                                    "addr = %s len = %d."),
+                                  paddress (gdbarch, record_list->u.mem.addr),
+                                  record_list->u.mem.len);
+                         else
+                           /* Write failed -- 
+                              flag entry as not_accessible.  */
+                           record_list->u.mem.mem_entry_not_accessible = 1;
+                       }
+                     else
+                       {
+                         memcpy (record_list->u.mem.val, mem,
+                                 record_list->u.mem.len);
+                       }
+                   }
+               }
            }
          else
            {
@@ -786,15 +815,14 @@ record_wait (struct target_ops *ops,
                      if (record_debug)
                        fprintf_unfiltered (gdb_stdlog,
                                            "Process record: break "
-                                           "at 0x%s.\n",
-                                           paddr_nz (tmp_pc));
-                     if (gdbarch_decr_pc_after_break (get_regcache_arch (regcache))
+                                           "at %s.\n",
+                                           paddress (gdbarch, tmp_pc));
+                     if (gdbarch_decr_pc_after_break (gdbarch)
                          && execution_direction == EXEC_FORWARD
                          && !record_resume_step)
                        regcache_write_pc (regcache,
                                           tmp_pc +
-                                          gdbarch_decr_pc_after_break
-                                          (get_regcache_arch (regcache)));
+                                          gdbarch_decr_pc_after_break (gdbarch));
                      continue_flag = 0;
                    }
                }
@@ -929,7 +957,6 @@ record_store_registers (struct target_ops *ops, struct regcache *regcache,
       if (RECORD_IS_REPLAY)
        {
          int n;
-         struct cleanup *old_cleanups;
 
          /* Let user choose if he wants to write register or not.  */
          if (regno < 0)
@@ -992,9 +1019,9 @@ record_xfer_partial (struct target_ops *ops, enum target_object object,
          /* Let user choose if he wants to write memory or not.  */
          if (!nquery (_("Because GDB is in replay mode, writing to memory "
                         "will make the execution log unusable from this "
-                        "point onward.  Write memory at address 0x%s?"),
-                      paddr_nz (offset)))
-           return -1;
+                        "point onward.  Write memory at address %s?"),
+                      paddress (target_gdbarch, offset)))
+           error (_("Process record canceled the operation."));
 
          /* Destroy the record from here forward.  */
          record_list_release_next ();
@@ -1044,12 +1071,13 @@ record_xfer_partial (struct target_ops *ops, enum target_object object,
    nor when recording.  */
 
 static int
-record_insert_breakpoint (struct bp_target_info *bp_tgt)
+record_insert_breakpoint (struct gdbarch *gdbarch,
+                         struct bp_target_info *bp_tgt)
 {
   if (!RECORD_IS_REPLAY)
     {
       struct cleanup *old_cleanups = record_gdb_operation_disable_set ();
-      int ret = record_beneath_to_insert_breakpoint (bp_tgt);
+      int ret = record_beneath_to_insert_breakpoint (gdbarch, bp_tgt);
 
       do_cleanups (old_cleanups);
 
@@ -1060,12 +1088,13 @@ record_insert_breakpoint (struct bp_target_info *bp_tgt)
 }
 
 static int
-record_remove_breakpoint (struct bp_target_info *bp_tgt)
+record_remove_breakpoint (struct gdbarch *gdbarch,
+                         struct bp_target_info *bp_tgt)
 {
   if (!RECORD_IS_REPLAY)
     {
       struct cleanup *old_cleanups = record_gdb_operation_disable_set ();
-      int ret = record_beneath_to_remove_breakpoint (bp_tgt);
+      int ret = record_beneath_to_remove_breakpoint (gdbarch, bp_tgt);
 
       do_cleanups (old_cleanups);
 
This page took 0.029094 seconds and 4 git commands to generate.