From c2bcbb1d04bb46a130f2c84de05cbbdccc0645fc Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 15 Apr 2013 08:59:03 -0600 Subject: [PATCH] constify get_bookmark and goto_bookmark 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 * 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) : Make parameter const. --- gdb/ChangeLog | 12 ++++++++++++ gdb/record-full.c | 24 ++++++++++++++---------- gdb/record.c | 18 +++++++++++++----- gdb/record.h | 4 ++-- gdb/target-delegates.c | 8 ++++---- gdb/target.h | 4 ++-- 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5ebae5e9c2d..49d41fcad79 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +2014-06-26 Tom Tromey + + * 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) : Make parameter const. + 2014-06-26 Tom Tromey * defs.h (generic_load): Update. diff --git a/gdb/record-full.c b/gdb/record-full.c index a496cf32e17..fcd77908632 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -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 diff --git a/gdb/record.c b/gdb/record.c index b801b7fc340..acdbc1a0a50 100644 --- a/gdb/record.c +++ b/gdb/record.c @@ -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 diff --git a/gdb/record.h b/gdb/record.h index 29784ad1ac9..702d7b6ca21 100644 --- a/gdb/record.h +++ b/gdb/record.h @@ -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); diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 38ca2b44c46..eac70188c93 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -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 (); } diff --git a/gdb/target.h b/gdb/target.h index a0a0d30c67f..d0601b8d555 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -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 -- 2.30.2