This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* remote-sim.h (sim_do_command): Add const to cmd.

sim/arm/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* wrapper.c (sim_do_command): Add const to cmd.

sim/avr/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* interp.c (sim_do_command): Add const to cmd.

sim/common/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* 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.

sim/cr16/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* interp.c (sim_do_command): Add const to cmd.

sim/d10v/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* interp.c (sim_do_command): Add const to cmd.

sim/erc32/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* interf.c (sim_do_command): Add const to cmd.

sim/m32c/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* 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.

sim/mcore/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* interp.c (sim_do_command): Add const to cmd.

sim/microblaze/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* interp.c (sim_do_command): Add const to cmd.

sim/moxie/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* interp.c (sim_do_command): Add const to cmd.

sim/ppc/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* sim_calls.c (sim_do_command): Add const to cmd.

sim/rl78/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* 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.

sim/rx/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* 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.

sim/sh/:
2014-02-19  Mike Frysinger  <vapier@gentoo.org>

	* interp.c (parse_and_set_memory_size): Add const to str.
	(sim_do_command): Add const to cmd and sms_cmd.
---
 include/gdb/remote-sim.h |  2 +-
 sim/arm/wrapper.c        |  2 +-
 sim/avr/interp.c         |  2 +-
 sim/common/sim-command.c |  2 +-
 sim/common/sim-options.c |  2 +-
 sim/common/sim-options.h |  2 +-
 sim/cr16/interp.c        |  2 +-
 sim/d10v/interp.c        |  2 +-
 sim/erc32/interf.c       |  2 +-
 sim/m32c/gdb-if.c        | 10 ++++++----
 sim/mcore/interp.c       |  2 +-
 sim/microblaze/interp.c  |  2 +-
 sim/moxie/interp.c       |  2 +-
 sim/ppc/sim_calls.c      |  2 +-
 sim/rl78/gdb-if.c        |  9 +++++----
 sim/rx/gdb-if.c          | 10 ++++++----
 sim/sh/interp.c          |  8 ++++----
 17 files changed, 34 insertions(+), 29 deletions(-)

diff --git a/include/gdb/remote-sim.h b/include/gdb/remote-sim.h
index 03f87f5..c335d4f 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/wrapper.c b/sim/arm/wrapper.c
index c475962..064962b 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/interp.c b/sim/avr/interp.c
index 1ee6507..7c8f81b 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/sim-command.c b/sim/common/sim-command.c
index 7fa2b1f..86eac03 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 ed10dfe..281a47f 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 778f4c1..4c318f9 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/interp.c b/sim/cr16/interp.c
index 48da916..e04ccc4 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/interp.c b/sim/d10v/interp.c
index f07520e..86b5e5e 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/interf.c b/sim/erc32/interf.c
index 84229cd..63b3f38 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/gdb-if.c b/sim/m32c/gdb-if.c
index bec9d48..a617b7c 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/interp.c b/sim/mcore/interp.c
index 9b08de0..73da916 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/interp.c b/sim/microblaze/interp.c
index 8fcf9d9..cc61278 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/interp.c b/sim/moxie/interp.c
index 3268732..a3f238a 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/sim_calls.c b/sim/ppc/sim_calls.c
index 27ee1fe..4e61335 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/gdb-if.c b/sim/rl78/gdb-if.c
index 6c4b5b5..f8712bf 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/gdb-if.c b/sim/rx/gdb-if.c
index 77048a0..3ccea98 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/interp.c b/sim/sh/interp.c
index cf6fd8d..c854174 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')
-- 
1.9.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]