From 60d847df0b9691b7cb38bfba41b9d6aafd97efc2 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 20 Feb 2014 00:28:17 -0500 Subject: [PATCH] sim: constify arg to sim_do_command It is rare for people to want to modify the cmd arg. In general, they really shouldn't be, but a few still do. For those who misbehave, dupe the string locally so they can bang on it. --- include/gdb/ChangeLog | 4 ++++ include/gdb/remote-sim.h | 2 +- sim/arm/ChangeLog | 4 ++++ sim/arm/wrapper.c | 2 +- sim/avr/ChangeLog | 4 ++++ sim/avr/interp.c | 2 +- sim/common/ChangeLog | 6 ++++++ sim/common/sim-command.c | 2 +- sim/common/sim-options.c | 2 +- sim/common/sim-options.h | 2 +- sim/cr16/ChangeLog | 4 ++++ sim/cr16/interp.c | 2 +- sim/d10v/ChangeLog | 4 ++++ sim/d10v/interp.c | 2 +- sim/erc32/ChangeLog | 4 ++++ sim/erc32/interf.c | 2 +- sim/m32c/ChangeLog | 5 +++++ sim/m32c/gdb-if.c | 10 ++++++---- sim/mcore/ChangeLog | 4 ++++ sim/mcore/interp.c | 2 +- sim/microblaze/ChangeLog | 4 ++++ sim/microblaze/interp.c | 2 +- sim/moxie/ChangeLog | 4 ++++ sim/moxie/interp.c | 2 +- sim/ppc/ChangeLog | 4 ++++ sim/ppc/sim_calls.c | 2 +- sim/rl78/ChangeLog | 5 +++++ sim/rl78/gdb-if.c | 9 +++++---- sim/rx/ChangeLog | 5 +++++ sim/rx/gdb-if.c | 10 ++++++---- sim/sh/ChangeLog | 5 +++++ sim/sh/interp.c | 8 ++++---- 32 files changed, 100 insertions(+), 29 deletions(-) diff --git a/include/gdb/ChangeLog b/include/gdb/ChangeLog index f6d49328cf..135391d424 100644 --- a/include/gdb/ChangeLog +++ b/include/gdb/ChangeLog @@ -1,3 +1,7 @@ +2014-03-10 Mike Frysinger + + * remote-sim.h (sim_do_command): Add const to cmd. + 2014-03-05 Alan Modra Update copyright notice. diff --git a/include/gdb/remote-sim.h b/include/gdb/remote-sim.h index 03f87f5a55..c335d4f81b 100644 --- a/include/gdb/remote-sim.h +++ b/include/gdb/remote-sim.h @@ -273,7 +273,7 @@ void sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc); Simulators should be prepared to deal with any combination of NULL or empty CMD. */ -void sim_do_command (SIM_DESC sd, char *cmd); +void sim_do_command (SIM_DESC sd, const char *cmd); /* Complete a command based on the available sim commands. Returns an array of possible matches. */ diff --git a/sim/arm/ChangeLog b/sim/arm/ChangeLog index 69e3447ae0..9910633ca7 100644 --- a/sim/arm/ChangeLog +++ b/sim/arm/ChangeLog @@ -1,3 +1,7 @@ +2014-03-10 Mike Frysinger + + * wrapper.c (sim_do_command): Add const to cmd. + 2014-03-05 Mike Frysinger * wrapper.c (sim_load): Add const to prog. diff --git a/sim/arm/wrapper.c b/sim/arm/wrapper.c index c475962bc4..064962b125 100644 --- a/sim/arm/wrapper.c +++ b/sim/arm/wrapper.c @@ -936,7 +936,7 @@ sim_stop_reason (sd, reason, sigrc) void sim_do_command (sd, cmd) SIM_DESC sd ATTRIBUTE_UNUSED; - char *cmd ATTRIBUTE_UNUSED; + const char *cmd ATTRIBUTE_UNUSED; { (*sim_callback->printf_filtered) (sim_callback, diff --git a/sim/avr/ChangeLog b/sim/avr/ChangeLog index 56f79be8c3..2b73b24b08 100644 --- a/sim/avr/ChangeLog +++ b/sim/avr/ChangeLog @@ -1,3 +1,7 @@ +2014-03-10 Mike Frysinger + + * interp.c (sim_do_command): Add const to cmd. + 2014-03-05 Mike Frysinger * interp.c (sim_load): Add const to prog. diff --git a/sim/avr/interp.c b/sim/avr/interp.c index 1ee6507eec..7c8f81b593 100644 --- a/sim/avr/interp.c +++ b/sim/avr/interp.c @@ -1831,7 +1831,7 @@ sim_kill (SIM_DESC sd) } void -sim_do_command (SIM_DESC sd, char *cmd) +sim_do_command (SIM_DESC sd, const char *cmd) { /* Nothing there yet; it's all an error. */ diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 9bf58e27af..4d9fc3b4e8 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,9 @@ +2014-03-10 Mike Frysinger + + * sim-command.c (sim_do_command): Add const to cmd. + * sim-options.c (sim_args_command): Add const to cmd. + * sim-options.h (sim_args_command): Add const to cmd. + 2014-03-05 Mike Frysinger * sim-hload.c (sim_load): Add const to prog. diff --git a/sim/common/sim-command.c b/sim/common/sim-command.c index 7fa2b1faa5..86eac0322f 100644 --- a/sim/common/sim-command.c +++ b/sim/common/sim-command.c @@ -26,7 +26,7 @@ which add custom options via sim_add_option_table(). */ void -sim_do_command (SIM_DESC sd, char *cmd) +sim_do_command (SIM_DESC sd, const char *cmd) { if (sim_args_command (sd, cmd) != SIM_RC_OK) sim_io_eprintf (sd, "Unknown sim command: \"%s\". Try \"sim help\".\n", diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c index ed10dfe895..281a47f3b2 100644 --- a/sim/common/sim-options.c +++ b/sim/common/sim-options.c @@ -971,7 +971,7 @@ sim_complete_command (SIM_DESC sd, const char *text, const char *word) } SIM_RC -sim_args_command (SIM_DESC sd, char *cmd) +sim_args_command (SIM_DESC sd, const char *cmd) { /* something to do? */ if (cmd == NULL) diff --git a/sim/common/sim-options.h b/sim/common/sim-options.h index 778f4c1544..4c318f941b 100644 --- a/sim/common/sim-options.h +++ b/sim/common/sim-options.h @@ -143,6 +143,6 @@ void sim_print_help (SIM_DESC sd, int is_command); /* Try to parse the command as if it is an option, Only fail when totally unsuccessful */ -SIM_RC sim_args_command (SIM_DESC sd, char *cmd); +SIM_RC sim_args_command (SIM_DESC sd, const char *cmd); #endif /* SIM_OPTIONS_H */ diff --git a/sim/cr16/ChangeLog b/sim/cr16/ChangeLog index 9903ad4fa6..dda7e60456 100644 --- a/sim/cr16/ChangeLog +++ b/sim/cr16/ChangeLog @@ -1,3 +1,7 @@ +2014-03-10 Mike Frysinger + + * interp.c (sim_do_command): Add const to cmd. + 2014-03-05 Mike Frysinger * interp.c (sim_load): Add const to prog. diff --git a/sim/cr16/interp.c b/sim/cr16/interp.c index 48da9167d9..e04ccc4db0 100644 --- a/sim/cr16/interp.c +++ b/sim/cr16/interp.c @@ -1561,7 +1561,7 @@ sim_complete_command (SIM_DESC sd, const char *text, const char *word) void sim_do_command (sd, cmd) SIM_DESC sd; - char *cmd; + const char *cmd; { (*cr16_callback->printf_filtered) (cr16_callback, "sim_do_command: %s\n",cmd); } diff --git a/sim/d10v/ChangeLog b/sim/d10v/ChangeLog index 4a878b0330..f13f83cbfb 100644 --- a/sim/d10v/ChangeLog +++ b/sim/d10v/ChangeLog @@ -1,3 +1,7 @@ +2014-03-10 Mike Frysinger + + * interp.c (sim_do_command): Add const to cmd. + 2014-03-05 Mike Frysinger * interp.c (sim_load): Add const to prog. diff --git a/sim/d10v/interp.c b/sim/d10v/interp.c index f07520ed1a..86b5e5eba4 100644 --- a/sim/d10v/interp.c +++ b/sim/d10v/interp.c @@ -1482,7 +1482,7 @@ sim_store_register (sd, rn, memory, length) void sim_do_command (sd, cmd) SIM_DESC sd; - char *cmd; + const char *cmd; { (*d10v_callback->printf_filtered) (d10v_callback, "sim_do_command: %s\n",cmd); } diff --git a/sim/erc32/ChangeLog b/sim/erc32/ChangeLog index 1592693738..fbf8813dc0 100644 --- a/sim/erc32/ChangeLog +++ b/sim/erc32/ChangeLog @@ -1,3 +1,7 @@ +2014-03-10 Mike Frysinger + + * interf.c (sim_do_command): Add const to cmd. + 2014-03-05 Mike Frysinger * interf.c (sim_load): Add const to prog. diff --git a/sim/erc32/interf.c b/sim/erc32/interf.c index 84229cd54d..63b3f38c97 100644 --- a/sim/erc32/interf.c +++ b/sim/erc32/interf.c @@ -479,7 +479,7 @@ sim_trace (sd) void sim_do_command(sd, cmd) SIM_DESC sd; - char *cmd; + const char *cmd; { exec_cmd(&sregs, cmd); } diff --git a/sim/m32c/ChangeLog b/sim/m32c/ChangeLog index e202191e45..2abe64336d 100644 --- a/sim/m32c/ChangeLog +++ b/sim/m32c/ChangeLog @@ -1,3 +1,8 @@ +2014-03-10 Mike Frysinger + + * gdb-if.c (sim_do_command): Add const to cmd. Move args + to top and add const. Call strdup on cmd and free at end. + 2014-03-05 Mike Frysinger * gdb-if.c (sim_load): Add const to prog. diff --git a/sim/m32c/gdb-if.c b/sim/m32c/gdb-if.c index bec9d48838..a617b7cb1c 100644 --- a/sim/m32c/gdb-if.c +++ b/sim/m32c/gdb-if.c @@ -650,11 +650,12 @@ sim_stop_reason (SIM_DESC sd, enum sim_stop *reason_p, int *sigrc_p) } void -sim_do_command (SIM_DESC sd, char *cmd) +sim_do_command (SIM_DESC sd, const char *cmd) { - check_desc (sd); + const char *args; + char *p = strdup (cmd); - char *p = cmd; + check_desc (sd); /* Skip leading whitespace. */ while (isspace (*p)) @@ -667,7 +668,6 @@ sim_do_command (SIM_DESC sd, char *cmd) /* Null-terminate the command word, and record the start of any further arguments. */ - char *args; if (*p) { *p = '\0'; @@ -701,6 +701,8 @@ sim_do_command (SIM_DESC sd, char *cmd) else printf ("The 'sim' command expects either 'trace' or 'verbose'" " as a subcommand.\n"); + + free (p); } char ** diff --git a/sim/mcore/ChangeLog b/sim/mcore/ChangeLog index c97a2c5c7c..d65fda293b 100644 --- a/sim/mcore/ChangeLog +++ b/sim/mcore/ChangeLog @@ -1,3 +1,7 @@ +2014-03-10 Mike Frysinger + + * interp.c (sim_do_command): Add const to cmd. + 2014-03-05 Mike Frysinger * interp.c (sim_load): Add const to prog. diff --git a/sim/mcore/interp.c b/sim/mcore/interp.c index 9b08de051a..73da9168e6 100644 --- a/sim/mcore/interp.c +++ b/sim/mcore/interp.c @@ -2130,7 +2130,7 @@ sim_kill (sd) void sim_do_command (sd, cmd) SIM_DESC sd; - char * cmd; + const char *cmd; { /* Nothing there yet; it's all an error. */ diff --git a/sim/microblaze/ChangeLog b/sim/microblaze/ChangeLog index 911a8b3769..ba17d35742 100644 --- a/sim/microblaze/ChangeLog +++ b/sim/microblaze/ChangeLog @@ -1,3 +1,7 @@ +2014-03-10 Mike Frysinger + + * interp.c (sim_do_command): Add const to cmd. + 2014-03-05 Mike Frysinger * interp.c (sim_load): Add const to prog. diff --git a/sim/microblaze/interp.c b/sim/microblaze/interp.c index 8fcf9d964c..cc612788a4 100644 --- a/sim/microblaze/interp.c +++ b/sim/microblaze/interp.c @@ -1006,7 +1006,7 @@ sim_kill (SIM_DESC sd) } void -sim_do_command (SIM_DESC sd, char * cmd) +sim_do_command (SIM_DESC sd, const char *cmd) { /* Nothing there yet; it's all an error. */ diff --git a/sim/moxie/ChangeLog b/sim/moxie/ChangeLog index 33a27852ff..691d41ad7d 100644 --- a/sim/moxie/ChangeLog +++ b/sim/moxie/ChangeLog @@ -1,3 +1,7 @@ +2014-03-10 Mike Frysinger + + * interp.c (sim_do_command): Add const to cmd. + 2014-03-05 Mike Frysinger * interp.c (sim_load): Add const to prog. diff --git a/sim/moxie/interp.c b/sim/moxie/interp.c index 3268732229..a3f238a006 100644 --- a/sim/moxie/interp.c +++ b/sim/moxie/interp.c @@ -1350,7 +1350,7 @@ sim_kill (sd) void sim_do_command (sd, cmd) SIM_DESC sd; - char * cmd; + const char *cmd; { if (sim_args_command (sd, cmd) != SIM_RC_OK) sim_io_printf (sd, diff --git a/sim/ppc/ChangeLog b/sim/ppc/ChangeLog index 3f279fec11..3ec45a58e7 100644 --- a/sim/ppc/ChangeLog +++ b/sim/ppc/ChangeLog @@ -1,3 +1,7 @@ +2014-03-10 Mike Frysinger + + * sim_calls.c (sim_do_command): Add const to cmd. + 2014-03-05 Mike Frysinger * sim_calls.c (sim_load): Add const to prog. diff --git a/sim/ppc/sim_calls.c b/sim/ppc/sim_calls.c index 27ee1fea1a..4e61335c2d 100644 --- a/sim/ppc/sim_calls.c +++ b/sim/ppc/sim_calls.c @@ -247,7 +247,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal) } void -sim_do_command (SIM_DESC sd, char *cmd) +sim_do_command (SIM_DESC sd, const char *cmd) { TRACE(trace_gdb, ("sim_do_commands(cmd=%s) called\n", cmd ? cmd : "(null)")); diff --git a/sim/rl78/ChangeLog b/sim/rl78/ChangeLog index 4b556cc8be..654d1d6a87 100644 --- a/sim/rl78/ChangeLog +++ b/sim/rl78/ChangeLog @@ -1,3 +1,8 @@ +2014-03-10 Mike Frysinger + + * gdb-if.c (sim_do_command): Add const to cmd. Move args + to top and add const. Call strdup on cmd and free at end. + 2014-03-05 Mike Frysinger * gdb-if.c (sim_load): Add const to prog. diff --git a/sim/rl78/gdb-if.c b/sim/rl78/gdb-if.c index 6c4b5b5fc8..f8712bf7f7 100644 --- a/sim/rl78/gdb-if.c +++ b/sim/rl78/gdb-if.c @@ -499,9 +499,10 @@ sim_stop_reason (SIM_DESC sd, enum sim_stop *reason_p, int *sigrc_p) command. */ void -sim_do_command (SIM_DESC sd, char *cmd) +sim_do_command (SIM_DESC sd, const char *cmd) { - char *args; + const char *args; + char *p = strdup (cmd); check_desc (sd); @@ -512,8 +513,6 @@ sim_do_command (SIM_DESC sd, char *cmd) } else { - char *p = cmd; - /* Skip leading whitespace. */ while (isspace (*p)) p++; @@ -561,6 +560,8 @@ sim_do_command (SIM_DESC sd, char *cmd) else printf ("The 'sim' command expects either 'trace' or 'verbose'" " as a subcommand.\n"); + + free (p); } /* Stub for command completion. */ diff --git a/sim/rx/ChangeLog b/sim/rx/ChangeLog index 3ce615e0ad..674b82e9cf 100644 --- a/sim/rx/ChangeLog +++ b/sim/rx/ChangeLog @@ -1,3 +1,8 @@ +2014-03-10 Mike Frysinger + + * gdb-if.c (sim_do_command): Add const to cmd. Move args + to top and add const. Call strdup on cmd and free at end. + 2014-03-05 Mike Frysinger * gdb-if.c (sim_load): Add const to prog. diff --git a/sim/rx/gdb-if.c b/sim/rx/gdb-if.c index 77048a0a0f..3ccea98df3 100644 --- a/sim/rx/gdb-if.c +++ b/sim/rx/gdb-if.c @@ -791,11 +791,12 @@ sim_stop_reason (SIM_DESC sd, enum sim_stop *reason_p, int *sigrc_p) } void -sim_do_command (SIM_DESC sd, char *cmd) +sim_do_command (SIM_DESC sd, const char *cmd) { - check_desc (sd); + const char *args; + char *p = strdup (cmd); - char *p = cmd; + check_desc (sd); /* Skip leading whitespace. */ while (isspace (*p)) @@ -808,7 +809,6 @@ sim_do_command (SIM_DESC sd, char *cmd) /* Null-terminate the command word, and record the start of any further arguments. */ - char *args; if (*p) { *p = '\0'; @@ -844,6 +844,8 @@ sim_do_command (SIM_DESC sd, char *cmd) else printf ("The 'sim' command expects either 'trace' or 'verbose'" " as a subcommand.\n"); + + free (p); } char ** diff --git a/sim/sh/ChangeLog b/sim/sh/ChangeLog index d479841edb..ac5f9548c4 100644 --- a/sim/sh/ChangeLog +++ b/sim/sh/ChangeLog @@ -1,3 +1,8 @@ +2014-03-10 Mike Frysinger + + * interp.c (parse_and_set_memory_size): Add const to str. + (sim_do_command): Add const to cmd and sms_cmd. + 2014-03-05 Mike Frysinger * interp.c (sim_load): Add const to prog. diff --git a/sim/sh/interp.c b/sim/sh/interp.c index cf6fd8dae0..c854174d2b 100644 --- a/sim/sh/interp.c +++ b/sim/sh/interp.c @@ -473,7 +473,7 @@ int valid[16]; #define UNDEF(x) #endif -static void parse_and_set_memory_size (char *str); +static void parse_and_set_memory_size (const char *str); static int IOMEM (int addr, int write, int value); static struct loop_bounds get_loop_bounds (int, int, unsigned char *, unsigned char *, int, int); @@ -2663,7 +2663,7 @@ sim_open (kind, cb, abfd, argv) static void parse_and_set_memory_size (str) - char *str; + const char *str; { int n; @@ -2739,9 +2739,9 @@ sim_create_inferior (sd, prog_bfd, argv, env) void sim_do_command (sd, cmd) SIM_DESC sd; - char *cmd; + const char *cmd; { - char *sms_cmd = "set-memory-size"; + const char *sms_cmd = "set-memory-size"; int cmdsize; if (cmd == NULL || *cmd == '\0') -- 2.34.1