Reindent cli-out.h
[deliverable/binutils-gdb.git] / gdb / record-full.c
index 37836e75d09e3b32d042df6815bfa6be4143da6f..4d8dd61bcaaa9d18108ec840a60df82f742f7335 100644 (file)
@@ -1,6 +1,6 @@
 /* Process record and replay target for GDB, the GNU debugger.
 
-   Copyright (C) 2013-2017 Free Software Foundation, Inc.
+   Copyright (C) 2013-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -33,7 +33,7 @@
 #include "event-loop.h"
 #include "inf-loop.h"
 #include "gdb_bfd.h"
-#include "observer.h"
+#include "observable.h"
 #include "infrun.h"
 #include "common/gdb_unlinker.h"
 #include "common/byte-vector.h"
@@ -168,7 +168,7 @@ struct record_full_core_buf_entry
 };
 
 /* Record buf with core target.  */
-static gdb_byte *record_full_core_regbuf = NULL;
+static detached_regcache *record_full_core_regbuf = NULL;
 static struct target_section *record_full_core_start;
 static struct target_section *record_full_core_end;
 static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
@@ -244,7 +244,7 @@ static inline struct record_full_entry *
 record_full_reg_alloc (struct regcache *regcache, int regnum)
 {
   struct record_full_entry *rec;
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
 
   rec = XCNEW (struct record_full_entry);
   rec->type = record_full_reg;
@@ -569,7 +569,7 @@ static void
 record_full_message (struct regcache *regcache, enum gdb_signal signal)
 {
   int ret;
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   struct cleanup *old_cleanups
     = make_cleanup (record_full_arch_list_cleanups, 0);
 
@@ -702,8 +702,7 @@ record_full_exec_insn (struct regcache *regcache,
        /* Nothing to do if the entry is flagged not_accessible.  */
         if (!entry->u.mem.mem_entry_not_accessible)
           {
-            gdb_byte *mem = (gdb_byte *) xmalloc (entry->u.mem.len);
-            struct cleanup *cleanup = make_cleanup (xfree, mem);
+           gdb::byte_vector mem (entry->u.mem.len);
 
             if (record_debug > 1)
               fprintf_unfiltered (gdb_stdlog,
@@ -714,7 +713,8 @@ record_full_exec_insn (struct regcache *regcache,
                                   entry->u.mem.len);
 
             if (record_read_memory (gdbarch,
-                                   entry->u.mem.addr, mem, entry->u.mem.len))
+                                   entry->u.mem.addr, mem.data (),
+                                   entry->u.mem.len))
              entry->u.mem.mem_entry_not_accessible = 1;
             else
               {
@@ -731,7 +731,7 @@ record_full_exec_insn (struct regcache *regcache,
                   }
                 else
                  {
-                   memcpy (record_full_get_loc (entry), mem,
+                   memcpy (record_full_get_loc (entry), mem.data (),
                            entry->u.mem.len);
 
                    /* We've changed memory --- check if a hardware
@@ -743,13 +743,11 @@ record_full_exec_insn (struct regcache *regcache,
                       not doing the change at all if the watchpoint
                       traps.  */
                    if (hardware_watchpoint_inserted_in_range
-                       (get_regcache_aspace (regcache),
+                       (regcache->aspace (),
                         entry->u.mem.addr, entry->u.mem.len))
                      record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
                  }
               }
-
-           do_cleanups (cleanup);
           }
       }
       break;
@@ -775,21 +773,21 @@ static void
 record_full_core_open_1 (const char *name, int from_tty)
 {
   struct regcache *regcache = get_current_regcache ();
-  int regnum = gdbarch_num_regs (get_regcache_arch (regcache));
+  int regnum = gdbarch_num_regs (regcache->arch ());
   int i;
 
   /* Get record_full_core_regbuf.  */
   target_fetch_registers (regcache, -1);
-  record_full_core_regbuf = (gdb_byte *) xmalloc (MAX_REGISTER_SIZE * regnum);
+  record_full_core_regbuf = new detached_regcache (regcache->arch (), false);
+
   for (i = 0; i < regnum; i ++)
-    regcache_raw_collect (regcache, i,
-                         record_full_core_regbuf + MAX_REGISTER_SIZE * i);
+    record_full_core_regbuf->raw_supply (i, *regcache);
 
   /* Get record_full_core_start and record_full_core_end.  */
   if (build_section_table (core_bfd, &record_full_core_start,
                           &record_full_core_end))
     {
-      xfree (record_full_core_regbuf);
+      delete record_full_core_regbuf;
       record_full_core_regbuf = NULL;
       error (_("\"%s\": Can't find sections: %s"),
             bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
@@ -828,8 +826,6 @@ static void record_full_init_record_breakpoints (void);
 static void
 record_full_open (const char *name, int from_tty)
 {
-  struct target_ops *t;
-
   if (record_debug)
     fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
 
@@ -853,7 +849,7 @@ record_full_open (const char *name, int from_tty)
 
   record_full_init_record_breakpoints ();
 
-  observer_notify_record_changed (current_inferior (),  1, "full", NULL);
+  gdb::observers::record_changed.notify (current_inferior (),  1, "full", NULL);
 }
 
 /* "to_close" target method.  Close the process record target.  */
@@ -871,7 +867,7 @@ record_full_close (struct target_ops *self)
   /* Release record_full_core_regbuf.  */
   if (record_full_core_regbuf)
     {
-      xfree (record_full_core_regbuf);
+      delete record_full_core_regbuf;
       record_full_core_regbuf = NULL;
     }
 
@@ -1098,7 +1094,6 @@ record_full_wait_1 (struct target_ops *ops,
                  && status->value.sig == GDB_SIGNAL_TRAP)
                {
                  struct regcache *regcache;
-                 struct address_space *aspace;
                  enum target_stop_reason *stop_reason_p
                    = &record_full_stop_reason;
 
@@ -1109,7 +1104,7 @@ record_full_wait_1 (struct target_ops *ops,
                  registers_changed ();
                  regcache = get_current_regcache ();
                  tmp_pc = regcache_read_pc (regcache);
-                 aspace = get_regcache_aspace (regcache);
+                 const struct address_space *aspace = regcache->aspace ();
 
                  if (target_stopped_by_watchpoint ())
                    {
@@ -1171,8 +1166,8 @@ record_full_wait_1 (struct target_ops *ops,
   else
     {
       struct regcache *regcache = get_current_regcache ();
-      struct gdbarch *gdbarch = get_regcache_arch (regcache);
-      struct address_space *aspace = get_regcache_aspace (regcache);
+      struct gdbarch *gdbarch = regcache->arch ();
+      const struct address_space *aspace = regcache->aspace ();
       int continue_flag = 1;
       int first_record_full_end = 1;
       struct cleanup *old_cleanups
@@ -1405,7 +1400,7 @@ record_full_registers_change (struct regcache *regcache, int regnum)
     {
       int i;
 
-      for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
+      for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
        {
          if (record_full_arch_list_add_reg (regcache, i))
            {
@@ -1462,7 +1457,7 @@ record_full_store_registers (struct target_ops *ops,
              query (_("Because GDB is in replay mode, changing the value "
                       "of a register will make the execution log unusable "
                       "from this point onward.  Change register %s?"),
-                     gdbarch_register_name (get_regcache_arch (regcache),
+                     gdbarch_register_name (regcache->arch (),
                                               regno));
 
          if (!n)
@@ -1474,7 +1469,7 @@ record_full_store_registers (struct target_ops *ops,
                  int i;
 
                  for (i = 0;
-                      i < gdbarch_num_regs (get_regcache_arch (regcache));
+                      i < gdbarch_num_regs (regcache->arch ());
                       i++)
                    regcache_invalidate (regcache, i);
                }
@@ -1753,28 +1748,22 @@ record_full_goto_bookmark (struct target_ops *self,
                           const gdb_byte *raw_bookmark, int from_tty)
 {
   const char *bookmark = (const char *) raw_bookmark;
-  struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
 
   if (record_debug)
     fprintf_unfiltered (gdb_stdlog,
                        "record_full_goto_bookmark receives %s\n", bookmark);
 
+  std::string name_holder;
   if (bookmark[0] == '\'' || bookmark[0] == '\"')
     {
-      char *copy;
-
       if (bookmark[strlen (bookmark) - 1] != bookmark[0])
        error (_("Unbalanced quotes: %s"), bookmark);
 
-
-      copy = savestring (bookmark + 1, strlen (bookmark) - 2);
-      make_cleanup (xfree, copy);
-      bookmark = copy;
+      name_holder = std::string (bookmark + 1, strlen (bookmark) - 2);
+      bookmark = name_holder.c_str ();
     }
 
   record_goto (bookmark);
-
-  do_cleanups (cleanup);
 }
 
 static enum exec_direction_kind
@@ -2029,16 +2018,14 @@ record_full_core_fetch_registers (struct target_ops *ops,
 {
   if (regno < 0)
     {
-      int num = gdbarch_num_regs (get_regcache_arch (regcache));
+      int num = gdbarch_num_regs (regcache->arch ());
       int i;
 
       for (i = 0; i < num; i ++)
-        regcache_raw_supply (regcache, i,
-                             record_full_core_regbuf + MAX_REGISTER_SIZE * i);
+       regcache->raw_supply (i, *record_full_core_regbuf);
     }
   else
-    regcache_raw_supply (regcache, regno,
-                         record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
+    regcache->raw_supply (regno, *record_full_core_regbuf);
 }
 
 /* "to_prepare_to_store" method for prec over corefile.  */
@@ -2057,8 +2044,7 @@ record_full_core_store_registers (struct target_ops *ops,
                              int regno)
 {
   if (record_full_gdb_operation_disable)
-    regcache_raw_collect (regcache, regno,
-                          record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
+    record_full_core_regbuf->raw_supply (regno, *regcache);
   else
     error (_("You can't do that without a process to debug."));
 }
@@ -2548,7 +2534,7 @@ record_full_save (struct target_ops *self, const char *recfilename)
 
   /* Get the values of regcache and gdbarch.  */
   regcache = get_current_regcache ();
-  gdbarch = get_regcache_arch (regcache);
+  gdbarch = regcache->arch ();
 
   /* Disable the GDB operation record.  */
   scoped_restore restore_operation_disable
@@ -2734,7 +2720,7 @@ record_full_goto_insn (struct record_full_entry *entry,
   scoped_restore restore_operation_disable
     = record_full_gdb_operation_disable_set ();
   struct regcache *regcache = get_current_regcache ();
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
 
   /* Assume everything is valid: we will hit the entry,
      and we will not hit the end of the recording.  */
@@ -2757,11 +2743,11 @@ record_full_goto_insn (struct record_full_entry *entry,
 static void
 cmd_record_full_start (const char *args, int from_tty)
 {
-  execute_command ((char *) "target record-full", from_tty);
+  execute_command ("target record-full", from_tty);
 }
 
 static void
-set_record_full_insn_max_num (char *args, int from_tty,
+set_record_full_insn_max_num (const char *args, int from_tty,
                              struct cmd_list_element *c)
 {
   if (record_full_insn_num > record_full_insn_max_num)
This page took 0.028911 seconds and 4 git commands to generate.