From: Mike Frysinger Date: Thu, 20 Feb 2014 05:28:17 +0000 (-0500) Subject: sim: constify arg to sim_do_command X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=60d847df0b9691b7cb38bfba41b9d6aafd97efc2;p=binutils-gdb.git 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. --- diff --git a/include/gdb/ChangeLog b/include/gdb/ChangeLog index f6d49328cf8..135391d4242 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 03f87f5a553..c335d4f81b0 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 69e3447ae0c..9910633ca71 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 c475962bc42..064962b1255 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 56f79be8c3b..2b73b24b086 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 1ee6507eec8..7c8f81b593d 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 9bf58e27af3..4d9fc3b4e89 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 7fa2b1faa5f..86eac0322fd 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 ed10dfe8954..281a47f3b23 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 778f4c15443..4c318f941b0 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 9903ad4fa6f..dda7e60456a 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 48da9167d93..e04ccc4db0c 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 4a878b03306..f13f83cbfb1 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 f07520ed1a1..86b5e5eba42 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 15926937385..fbf8813dc03 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 84229cd54d7..63b3f38c97e 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 e202191e452..2abe64336db 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 bec9d48838a..a617b7cb1c2 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 c97a2c5c7c8..d65fda293b5 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 9b08de051af..73da9168e6d 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 911a8b3769b..ba17d357428 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 8fcf9d964cd..cc612788a4f 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 33a27852ffd..691d41ad7df 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 32687322297..a3f238a0066 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 3f279fec114..3ec45a58e79 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 27ee1fea1a7..4e61335c2d4 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 4b556cc8beb..654d1d6a870 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 6c4b5b5fc89..f8712bf7f74 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 3ce615e0ade..674b82e9cfb 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 77048a0a0f9..3ccea98df3d 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 d479841edb7..ac5f9548c4f 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 cf6fd8dae06..c854174d2bd 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')