constify get_bookmark and goto_bookmark
authorTom Tromey <tromey@redhat.com>
Mon, 15 Apr 2013 14:59:03 +0000 (08:59 -0600)
committerTom Tromey <tromey@redhat.com>
Thu, 26 Jun 2014 15:14:16 +0000 (09:14 -0600)
This makes arguments to to_get_bookmark and to_goto_bookmark const and
fixes the fallout.  Tested by rebuilding.  The only thing of note is
the new split between cmd_record_goto and record_goto -- basically
separating the CLI function from a new internal API, to allow const
propagation.

2014-06-26  Tom Tromey  <tromey@redhat.com>

* record-full.c (record_full_get_bookmark): Make "args" const.
(record_full_goto_bookmark): Make "raw_bookmark" const.
* record.c (record_goto): New function.
(cmd_record_goto): Use it.  Now static.
* record.h (record_goto): Declare.
(cmd_record_goto): Remove declaration.
* target-delegates.c: Rebuild.
* target.h (struct target_ops) <to_get_bookmark,
to_goto_bookmark>: Make parameter const.

gdb/ChangeLog
gdb/record-full.c
gdb/record.c
gdb/record.h
gdb/target-delegates.c
gdb/target.h

index 5ebae5e..49d41fc 100644 (file)
@@ -1,5 +1,17 @@
 2014-06-26  Tom Tromey  <tromey@redhat.com>
 
+       * record-full.c (record_full_get_bookmark): Make "args" const.
+       (record_full_goto_bookmark): Make "raw_bookmark" const.
+       * record.c (record_goto): New function.
+       (cmd_record_goto): Use it.  Now static.
+       * record.h (record_goto): Declare.
+       (cmd_record_goto): Remove declaration.
+       * target-delegates.c: Rebuild.
+       * target.h (struct target_ops) <to_get_bookmark,
+       to_goto_bookmark>: Make parameter const.
+
+2014-06-26  Tom Tromey  <tromey@redhat.com>
+
        * defs.h (generic_load): Update.
        * m32r-rom.c (m32r_load_gen): Make "filename" const.
        * monitor.c (monitor_load): Make "args" const.
index a496cf3..fcd7790 100644 (file)
@@ -1703,7 +1703,8 @@ record_full_can_execute_reverse (struct target_ops *self)
 /* "to_get_bookmark" method for process record and prec over core.  */
 
 static gdb_byte *
-record_full_get_bookmark (struct target_ops *self, char *args, int from_tty)
+record_full_get_bookmark (struct target_ops *self, const char *args,
+                         int from_tty)
 {
   char *ret = NULL;
 
@@ -1727,9 +1728,10 @@ record_full_get_bookmark (struct target_ops *self, char *args, int from_tty)
 
 static void
 record_full_goto_bookmark (struct target_ops *self,
-                          gdb_byte *raw_bookmark, int from_tty)
+                          const gdb_byte *raw_bookmark, int from_tty)
 {
-  char *bookmark = (char *) raw_bookmark;
+  const char *bookmark = (const char *) raw_bookmark;
+  struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
 
   if (record_debug)
     fprintf_unfiltered (gdb_stdlog,
@@ -1737,18 +1739,20 @@ record_full_goto_bookmark (struct target_ops *self,
 
   if (bookmark[0] == '\'' || bookmark[0] == '\"')
     {
+      char *copy;
+
       if (bookmark[strlen (bookmark) - 1] != bookmark[0])
        error (_("Unbalanced quotes: %s"), bookmark);
 
-      /* Strip trailing quote.  */
-      bookmark[strlen (bookmark) - 1] = '\0';
-      /* Strip leading quote.  */
-      bookmark++;
-      /* Pass along to cmd_record_full_goto.  */
+
+      copy = savestring (bookmark + 1, strlen (bookmark) - 2);
+      make_cleanup (xfree, copy);
+      bookmark = copy;
     }
 
-  cmd_record_goto (bookmark, from_tty);
-  return;
+  record_goto (bookmark);
+
+  do_cleanups (cleanup);
 }
 
 static enum exec_direction_kind
index b801b7f..acdbc1a 100644 (file)
@@ -311,13 +311,10 @@ cmd_record_save (char *args, int from_tty)
   target_save_record (recfilename);
 }
 
-/* "record goto" command.  Argument is an instruction number,
-   as given by "info record".
-
-   Rewinds the recording (forward or backward) to the given instruction.  */
+/* See record.h.  */
 
 void
-cmd_record_goto (char *arg, int from_tty)
+record_goto (const char *arg)
 {
   ULONGEST insn;
 
@@ -330,6 +327,17 @@ cmd_record_goto (char *arg, int from_tty)
   target_goto_record (insn);
 }
 
+/* "record goto" command.  Argument is an instruction number,
+   as given by "info record".
+
+   Rewinds the recording (forward or backward) to the given instruction.  */
+
+static void
+cmd_record_goto (char *arg, int from_tty)
+{
+  record_goto (arg);
+}
+
 /* The "record goto begin" command.  */
 
 static void
index 29784ad..702d7b6 100644 (file)
@@ -53,8 +53,8 @@ extern int record_read_memory (struct gdbarch *gdbarch,
                               CORE_ADDR memaddr, gdb_byte *myaddr,
                               ssize_t len);
 
-/* The "record goto" command.  */
-extern void cmd_record_goto (char *arg, int from_tty);
+/* A wrapper for target_goto_record that parses ARG as a number.  */
+extern void record_goto (const char *arg);
 
 /* The default "to_disconnect" target method for record targets.  */
 extern void record_disconnect (struct target_ops *, const char *, int);
index 38ca2b4..eac7018 100644 (file)
@@ -742,27 +742,27 @@ delegate_make_corefile_notes (struct target_ops *self, bfd *arg1, int *arg2)
 }
 
 static gdb_byte * 
-delegate_get_bookmark (struct target_ops *self, char *arg1, int arg2)
+delegate_get_bookmark (struct target_ops *self, const char *arg1, int arg2)
 {
   self = self->beneath;
   return self->to_get_bookmark (self, arg1, arg2);
 }
 
 static gdb_byte * 
-tdefault_get_bookmark (struct target_ops *self, char *arg1, int arg2)
+tdefault_get_bookmark (struct target_ops *self, const char *arg1, int arg2)
 {
   tcomplain ();
 }
 
 static void
-delegate_goto_bookmark (struct target_ops *self, gdb_byte *arg1, int arg2)
+delegate_goto_bookmark (struct target_ops *self, const gdb_byte *arg1, int arg2)
 {
   self = self->beneath;
   self->to_goto_bookmark (self, arg1, arg2);
 }
 
 static void
-tdefault_goto_bookmark (struct target_ops *self, gdb_byte *arg1, int arg2)
+tdefault_goto_bookmark (struct target_ops *self, const gdb_byte *arg1, int arg2)
 {
   tcomplain ();
 }
index a0a0d30..d0601b8 100644 (file)
@@ -596,10 +596,10 @@ struct target_ops
     char * (*to_make_corefile_notes) (struct target_ops *, bfd *, int *)
       TARGET_DEFAULT_FUNC (dummy_make_corefile_notes);
     /* get_bookmark support method for bookmarks */
-    gdb_byte * (*to_get_bookmark) (struct target_ops *, char *, int)
+    gdb_byte * (*to_get_bookmark) (struct target_ops *, const char *, int)
       TARGET_DEFAULT_NORETURN (tcomplain ());
     /* goto_bookmark support method for bookmarks */
-    void (*to_goto_bookmark) (struct target_ops *, gdb_byte *, int)
+    void (*to_goto_bookmark) (struct target_ops *, const gdb_byte *, int)
       TARGET_DEFAULT_NORETURN (tcomplain ());
     /* Return the thread-local address at OFFSET in the
        thread-local storage for the thread PTID and the shared library