*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / record.c
index 9a4fbba6287437c41b870182e5d1b61a7f8ee2f6..08ffb687e2e0502900e3cba2c12036d198e60f6f 100644 (file)
@@ -1,6 +1,6 @@
 /* Process record and replay target for GDB, the GNU debugger.
 
-   Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2008-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -32,6 +32,8 @@
 #include "gcore.h"
 #include "event-loop.h"
 #include "inf-loop.h"
+#include "gdb_bfd.h"
+#include "observer.h"
 
 #include <signal.h>
 
@@ -100,7 +102,7 @@ struct record_reg_entry
 
 struct record_end_entry
 {
-  enum target_signal sigval;
+  enum gdb_signal sigval;
   ULONGEST insn_num;
 };
 
@@ -152,7 +154,7 @@ struct record_entry
 };
 
 /* This is the debug switch for process record.  */
-int record_debug = 0;
+unsigned int record_debug = 0;
 
 /* If true, query if PREC cannot record memory
    change of next instruction.  */
@@ -209,7 +211,7 @@ static struct target_ops record_core_ops;
 /* The beneath function pointers.  */
 static struct target_ops *record_beneath_to_resume_ops;
 static void (*record_beneath_to_resume) (struct target_ops *, ptid_t, int,
-                                         enum target_signal);
+                                         enum gdb_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 *,
@@ -484,6 +486,20 @@ record_arch_list_add_reg (struct regcache *regcache, int regnum)
   return 0;
 }
 
+int
+record_read_memory (struct gdbarch *gdbarch,
+                   CORE_ADDR memaddr, gdb_byte *myaddr,
+                   ssize_t len)
+{
+  int ret = target_read_memory (memaddr, myaddr, len);
+
+  if (ret && record_debug)
+    printf_unfiltered (_("Process record: error reading memory "
+                        "at addr %s len = %ld.\n"),
+                      paddress (gdbarch, memaddr), (long) len);
+  return ret;
+}
+
 /* Record the value of a region of memory whose address is ADDR and
    length is LEN to record_arch_list.  */
 
@@ -496,20 +512,15 @@ record_arch_list_add_mem (CORE_ADDR addr, int len)
     fprintf_unfiltered (gdb_stdlog,
                        "Process record: add mem addr = %s len = %d to "
                        "record list.\n",
-                       paddress (target_gdbarch, addr), len);
+                       paddress (target_gdbarch (), addr), len);
 
   if (!addr)   /* FIXME: Why?  Some arch must permit it...  */
     return 0;
 
   rec = record_mem_alloc (addr, len);
 
-  if (target_read_memory (addr, record_get_loc (rec), len))
+  if (record_read_memory (target_gdbarch (), addr, record_get_loc (rec), len))
     {
-      if (record_debug)
-       fprintf_unfiltered (gdb_stdlog,
-                           "Process record: error reading memory at "
-                           "addr = %s len = %d.\n",
-                           paddress (target_gdbarch, addr), len);
       record_mem_release (rec);
       return -1;
     }
@@ -531,7 +542,7 @@ record_arch_list_add_end (void)
                        "Process record: add end to arch list.\n");
 
   rec = record_end_alloc ();
-  rec->u.end.sigval = TARGET_SIGNAL_0;
+  rec->u.end.sigval = GDB_SIGNAL_0;
   rec->u.end.insn_num = ++record_insn_count;
 
   record_arch_list_add (rec);
@@ -581,7 +592,7 @@ record_arch_list_cleanups (void *ignore)
    record_arch_list, and add it to record_list.  */
 
 static int
-record_message (struct regcache *regcache, enum target_signal signal)
+record_message (struct regcache *regcache, enum gdb_signal signal)
 {
   int ret;
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
@@ -621,7 +632,7 @@ record_message (struct regcache *regcache, enum target_signal signal)
       record_list->u.end.sigval = signal;
     }
 
-  if (signal == TARGET_SIGNAL_0
+  if (signal == GDB_SIGNAL_0
       || !gdbarch_process_record_signal_p (gdbarch))
     ret = gdbarch_process_record (gdbarch,
                                  regcache,
@@ -652,7 +663,7 @@ record_message (struct regcache *regcache, enum target_signal signal)
 
 struct record_message_args {
   struct regcache *regcache;
-  enum target_signal signal;
+  enum gdb_signal signal;
 };
 
 static int
@@ -665,7 +676,7 @@ record_message_wrapper (void *args)
 
 static int
 record_message_wrapper_safe (struct regcache *regcache,
-                             enum target_signal signal)
+                             enum gdb_signal signal)
 {
   struct record_message_args args;
 
@@ -738,15 +749,9 @@ record_exec_insn (struct regcache *regcache, struct gdbarch *gdbarch,
                                   paddress (gdbarch, entry->u.mem.addr),
                                   entry->u.mem.len);
 
-            if (target_read_memory (entry->u.mem.addr, mem, entry->u.mem.len))
-              {
-                entry->u.mem.mem_entry_not_accessible = 1;
-                if (record_debug)
-                  warning (_("Process record: error reading memory at "
-                            "addr = %s len = %d."),
-                           paddress (gdbarch, entry->u.mem.addr),
-                           entry->u.mem.len);
-              }
+            if (record_read_memory (gdbarch,
+                                   entry->u.mem.addr, mem, entry->u.mem.len))
+             entry->u.mem.mem_entry_not_accessible = 1;
             else
               {
                 if (target_write_memory (entry->u.mem.addr, 
@@ -786,7 +791,7 @@ record_exec_insn (struct regcache *regcache, struct gdbarch *gdbarch,
 
 static struct target_ops *tmp_to_resume_ops;
 static void (*tmp_to_resume) (struct target_ops *, ptid_t, int,
-                             enum target_signal);
+                             enum gdb_signal);
 static struct target_ops *tmp_to_wait_ops;
 static ptid_t (*tmp_to_wait) (struct target_ops *, ptid_t,
                              struct target_waitstatus *,
@@ -869,7 +874,7 @@ record_open_1 (char *name, int from_tty)
     error (_("Process record target can't debug inferior in non-stop mode "
             "(non-stop)."));
 
-  if (!gdbarch_process_record_p (target_gdbarch))
+  if (!gdbarch_process_record_p (target_gdbarch ()))
     error (_("Process record: the current architecture doesn't support "
             "record function."));
 
@@ -896,6 +901,8 @@ record_open_1 (char *name, int from_tty)
   push_target (&record_ops);
 }
 
+static void record_init_record_breakpoints (void);
+
 /* "to_open" target method.  Open the process record target.  */
 
 static void
@@ -993,6 +1000,10 @@ record_open (char *name, int from_tty)
   record_async_inferior_event_token
     = create_async_event_handler (record_async_inferior_event_handler,
                                  NULL);
+
+  record_init_record_breakpoints ();
+
+  observer_notify_record_changed (current_inferior (),  1);
 }
 
 /* "to_close" target method.  Close the process record target.  */
@@ -1056,7 +1067,7 @@ static enum exec_direction_kind record_execution_dir = EXEC_FORWARD;
 
 static void
 record_resume (struct target_ops *ops, ptid_t ptid, int step,
-               enum target_signal signal)
+               enum gdb_signal signal)
 {
   record_resume_step = step;
   record_resumed = 1;
@@ -1099,6 +1110,9 @@ record_resume (struct target_ops *ops, ptid_t ptid, int step,
             }
         }
 
+      /* Make sure the target beneath reports all signals.  */
+      target_pass_signals (0, NULL);
+
       record_beneath_to_resume (record_beneath_to_resume_ops,
                                 ptid, step, signal);
     }
@@ -1219,7 +1233,7 @@ record_wait_1 (struct target_ops *ops,
 
              /* Is this a SIGTRAP?  */
              if (status->kind == TARGET_WAITKIND_STOPPED
-                 && status->value.sig == TARGET_SIGNAL_TRAP)
+                 && status->value.sig == GDB_SIGNAL_TRAP)
                {
                  struct regcache *regcache;
                  struct address_space *aspace;
@@ -1261,10 +1275,10 @@ record_wait_1 (struct target_ops *ops,
                       int step = 1;
 
                      if (!record_message_wrapper_safe (regcache,
-                                                        TARGET_SIGNAL_0))
+                                                        GDB_SIGNAL_0))
                        {
                            status->kind = TARGET_WAITKIND_STOPPED;
-                           status->value.sig = TARGET_SIGNAL_0;
+                           status->value.sig = GDB_SIGNAL_0;
                            break;
                        }
 
@@ -1286,7 +1300,7 @@ record_wait_1 (struct target_ops *ops,
                                            "issuing one more step in the target beneath\n");
                      record_beneath_to_resume (record_beneath_to_resume_ops,
                                                ptid, step,
-                                               TARGET_SIGNAL_0);
+                                               GDB_SIGNAL_0);
                      continue;
                    }
                }
@@ -1425,7 +1439,7 @@ record_wait_1 (struct target_ops *ops,
                      continue_flag = 0;
                    }
                  /* Check target signal */
-                 if (record_list->u.end.sigval != TARGET_SIGNAL_0)
+                 if (record_list->u.end.sigval != GDB_SIGNAL_0)
                    /* FIXME: better way to check */
                    continue_flag = 0;
                }
@@ -1449,12 +1463,12 @@ record_wait_1 (struct target_ops *ops,
 
 replay_out:
       if (record_get_sig)
-       status->value.sig = TARGET_SIGNAL_INT;
-      else if (record_list->u.end.sigval != TARGET_SIGNAL_0)
+       status->value.sig = GDB_SIGNAL_INT;
+      else if (record_list->u.end.sigval != GDB_SIGNAL_0)
        /* FIXME: better way to check */
        status->value.sig = record_list->u.end.sigval;
       else
-       status->value.sig = TARGET_SIGNAL_TRAP;
+       status->value.sig = GDB_SIGNAL_TRAP;
 
       discard_cleanups (old_cleanups);
     }
@@ -1672,7 +1686,7 @@ record_xfer_partial (struct target_ops *ops, enum target_object object,
          if (!query (_("Because GDB is in replay mode, writing to memory "
                        "will make the execution log unusable from this "
                        "point onward.  Write memory at address %s?"),
-                      paddress (target_gdbarch, offset)))
+                      paddress (target_gdbarch (), offset)))
            error (_("Process record canceled the operation."));
 
          /* Destroy the record from here forward.  */
@@ -1718,24 +1732,97 @@ record_xfer_partial (struct target_ops *ops, enum target_object object,
                                          offset, len);
 }
 
-/* Behavior is conditional on RECORD_IS_REPLAY.
-   We will not actually insert or remove breakpoints when replaying,
-   nor when recording.  */
+/* This structure represents a breakpoint inserted while the record
+   target is active.  We use this to know when to install/remove
+   breakpoints in/from the target beneath.  For example, a breakpoint
+   may be inserted while recording, but removed when not replaying nor
+   recording.  In that case, the breakpoint had not been inserted on
+   the target beneath, so we should not try to remove it there.  */
+
+struct record_breakpoint
+{
+  /* The address and address space the breakpoint was set at.  */
+  struct address_space *address_space;
+  CORE_ADDR addr;
+
+  /* True when the breakpoint has been also installed in the target
+     beneath.  This will be false for breakpoints set during replay or
+     when recording.  */
+  int in_target_beneath;
+};
+
+typedef struct record_breakpoint *record_breakpoint_p;
+DEF_VEC_P(record_breakpoint_p);
+
+/* The list of breakpoints inserted while the record target is
+   active.  */
+VEC(record_breakpoint_p) *record_breakpoints = NULL;
+
+static void
+record_sync_record_breakpoints (struct bp_location *loc, void *data)
+{
+  if (loc->loc_type != bp_loc_software_breakpoint)
+      return;
+
+  if (loc->inserted)
+    {
+      struct record_breakpoint *bp = XNEW (struct record_breakpoint);
+
+      bp->addr = loc->target_info.placed_address;
+      bp->address_space = loc->target_info.placed_address_space;
+
+      bp->in_target_beneath = 1;
+
+      VEC_safe_push (record_breakpoint_p, record_breakpoints, bp);
+    }
+}
+
+/* Sync existing breakpoints to record_breakpoints.  */
+
+static void
+record_init_record_breakpoints (void)
+{
+  VEC_free (record_breakpoint_p, record_breakpoints);
+
+  iterate_over_bp_locations (record_sync_record_breakpoints);
+}
+
+/* Behavior is conditional on RECORD_IS_REPLAY.  We will not actually
+   insert or remove breakpoints in the real target when replaying, nor
+   when recording.  */
 
 static int
 record_insert_breakpoint (struct gdbarch *gdbarch,
                          struct bp_target_info *bp_tgt)
 {
+  struct record_breakpoint *bp;
+  int in_target_beneath = 0;
+
   if (!RECORD_IS_REPLAY)
     {
-      struct cleanup *old_cleanups = record_gdb_operation_disable_set ();
-      int ret = record_beneath_to_insert_breakpoint (gdbarch, bp_tgt);
-
+      /* When recording, we currently always single-step, so we don't
+        really need to install regular breakpoints in the inferior.
+        However, we do have to insert software single-step
+        breakpoints, in case the target can't hardware step.  To keep
+        things single, we always insert.  */
+      struct cleanup *old_cleanups;
+      int ret;
+
+      old_cleanups = record_gdb_operation_disable_set ();
+      ret = record_beneath_to_insert_breakpoint (gdbarch, bp_tgt);
       do_cleanups (old_cleanups);
 
-      return ret;
+      if (ret != 0)
+       return ret;
+
+      in_target_beneath = 1;
     }
 
+  bp = XNEW (struct record_breakpoint);
+  bp->addr = bp_tgt->placed_address;
+  bp->address_space = bp_tgt->placed_address_space;
+  bp->in_target_beneath = in_target_beneath;
+  VEC_safe_push (record_breakpoint_p, record_breakpoints, bp);
   return 0;
 }
 
@@ -1745,17 +1832,35 @@ static int
 record_remove_breakpoint (struct gdbarch *gdbarch,
                          struct bp_target_info *bp_tgt)
 {
-  if (!RECORD_IS_REPLAY)
+  struct record_breakpoint *bp;
+  int ix;
+
+  for (ix = 0;
+       VEC_iterate (record_breakpoint_p, record_breakpoints, ix, bp);
+       ++ix)
     {
-      struct cleanup *old_cleanups = record_gdb_operation_disable_set ();
-      int ret = record_beneath_to_remove_breakpoint (gdbarch, bp_tgt);
+      if (bp->addr == bp_tgt->placed_address
+         && bp->address_space == bp_tgt->placed_address_space)
+       {
+         if (bp->in_target_beneath)
+           {
+             struct cleanup *old_cleanups;
+             int ret;
 
-      do_cleanups (old_cleanups);
+             old_cleanups = record_gdb_operation_disable_set ();
+             ret = record_beneath_to_remove_breakpoint (gdbarch, bp_tgt);
+             do_cleanups (old_cleanups);
+
+             if (ret != 0)
+               return ret;
+           }
 
-      return ret;
+         VEC_unordered_remove (record_breakpoint_p, record_breakpoints, ix);
+         return 0;
+       }
     }
 
-  return 0;
+  gdb_assert_not_reached ("removing unknown breakpoint");
 }
 
 /* "to_can_execute_reverse" method for process record target.  */
@@ -1817,16 +1922,10 @@ record_goto_bookmark (gdb_byte *bookmark, int from_tty)
   return;
 }
 
-static int record_async_mask_value = 1;
-
 static void
 record_async (void (*callback) (enum inferior_event_type event_type,
                                void *context), void *context)
 {
-  if (record_async_mask_value == 0)
-    internal_error (__FILE__, __LINE__,
-                   _("Calling record_async when async is masked"));
-
   /* If we're on top of a line target (e.g., linux-nat, remote), then
      set it to async mode as well.  Will be NULL if we're sitting on
      top of the core target, for "record restore".  */
@@ -1834,33 +1933,18 @@ record_async (void (*callback) (enum inferior_event_type event_type,
     record_beneath_to_async (callback, context);
 }
 
-static int
-record_async_mask (int new_mask)
-{
-  int curr_mask = record_async_mask_value;
-
-  record_async_mask_value = new_mask;
-  return curr_mask;
-}
-
 static int
 record_can_async_p (void)
 {
   /* We only enable async when the user specifically asks for it.  */
-  if (!target_async_permitted)
-    return 0;
-
-  return record_async_mask_value;
+  return target_async_permitted;
 }
 
 static int
 record_is_async_p (void)
 {
   /* We only enable async when the user specifically asks for it.  */
-  if (!target_async_permitted)
-    return 0;
-
-  return record_async_mask_value;
+  return target_async_permitted;
 }
 
 static enum exec_direction_kind
@@ -1899,7 +1983,6 @@ init_record_ops (void)
   record_ops.to_async = record_async;
   record_ops.to_can_async_p = record_can_async_p;
   record_ops.to_is_async_p = record_is_async_p;
-  record_ops.to_async_mask = record_async_mask;
   record_ops.to_execution_direction = record_execution_direction;
   record_ops.to_magic = OPS_MAGIC;
 }
@@ -1908,7 +1991,7 @@ init_record_ops (void)
 
 static void
 record_core_resume (struct target_ops *ops, ptid_t ptid, int step,
-                    enum target_signal signal)
+                    enum gdb_signal signal)
 {
   record_resume_step = step;
   record_resumed = 1;
@@ -2125,7 +2208,6 @@ init_record_core_ops (void)
   record_core_ops.to_async = record_async;
   record_core_ops.to_can_async_p = record_can_async_p;
   record_core_ops.to_is_async_p = record_is_async_p;
-  record_core_ops.to_async_mask = record_async_mask;
   record_core_ops.to_execution_direction = record_execution_direction;
   record_core_ops.to_magic = OPS_MAGIC;
 }
@@ -2181,6 +2263,8 @@ cmd_record_stop (char *args, int from_tty)
       unpush_target (&record_ops);
       printf_unfiltered (_("Process record is stopped and all execution "
                            "logs are deleted.\n"));
+
+      observer_notify_record_changed (current_inferior (), 0);
     }
   else
     printf_unfiltered (_("Process record is not started.\n"));
@@ -2566,7 +2650,7 @@ record_save_cleanups (void *data)
   bfd *obfd = data;
   char *pathname = xstrdup (bfd_get_filename (obfd));
 
-  bfd_close (obfd);
+  gdb_bfd_unref (obfd);
   unlink (pathname);
   xfree (pathname);
 }
@@ -2782,7 +2866,7 @@ cmd_record_save (char *args, int from_tty)
     }
 
   do_cleanups (set_cleanups);
-  bfd_close (obfd);
+  gdb_bfd_unref (obfd);
   discard_cleanups (old_cleanups);
 
   /* Succeeded.  */
@@ -2885,6 +2969,9 @@ cmd_record_goto (char *arg, int from_tty)
   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
 }
 
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+extern initialize_file_ftype _initialize_record;
+
 void
 _initialize_record (void)
 {
@@ -2900,13 +2987,13 @@ _initialize_record (void)
   init_record_core_ops ();
   add_target (&record_core_ops);
 
-  add_setshow_zinteger_cmd ("record", no_class, &record_debug,
-                           _("Set debugging of record/replay feature."),
-                           _("Show debugging of record/replay feature."),
-                           _("When enabled, debugging output for "
-                             "record/replay feature is displayed."),
-                           NULL, show_record_debug, &setdebuglist,
-                           &showdebuglist);
+  add_setshow_zuinteger_cmd ("record", no_class, &record_debug,
+                            _("Set debugging of record/replay feature."),
+                            _("Show debugging of record/replay feature."),
+                            _("When enabled, debugging output for "
+                              "record/replay feature is displayed."),
+                            NULL, show_record_debug, &setdebuglist,
+                            &showdebuglist);
 
   c = add_prefix_cmd ("record", class_obscure, cmd_record_start,
                      _("Abbreviated form of \"target record\" command."),
This page took 0.031745 seconds and 4 git commands to generate.