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]

[RFA] Constify mi_interpreter_exec and remove dup


Hi,

This is the follow-on patch that I promised Tom which constifies mi_interpreter_exec and removes a memory allocation copying the input string (so that parse_exp_1 doesn't mutate it).

Keith

ChangeLog
2013-03-12  Keith Seitz  <keiths@redhat.com>

	* mi/mi-cmds.h (mi_execute_command): Make "cmd" const.
	* mi/mi-interp.c (mi_interpreter_exec): Make "command" const.
	Remove temporary copy of input string.
	(mi_execute_command_wrapper): Make "cmd" const.
	* mi/mi-main.c (mi_execute_command): Make "string_ptr" const.
	(mi_parse_argv): Make "args" const.
	Use const strings.
	(mi_parse): Make "cmd" const.
	Use const strings.
	* mi/mi-parse.h (mi_parse): Make "cmd" const.

Index: mi/mi-cmds.h
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v
retrieving revision 1.58
diff -u -p -r1.58 mi-cmds.h
--- mi/mi-cmds.h	1 Jan 2013 06:33:00 -0000	1.58
+++ mi/mi-cmds.h	12 Mar 2013 17:37:18 -0000
@@ -157,6 +157,6 @@ extern int mi_debug_p;
 /* Raw console output - FIXME: should this be a parameter? */
 extern struct ui_file *raw_stdout;
 
-extern void mi_execute_command (char *cmd, int from_tty);
+extern void mi_execute_command (const char *cmd, int from_tty);
 
 #endif
Index: mi/mi-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-interp.c,v
retrieving revision 1.83
diff -u -p -r1.83 mi-interp.c
--- mi/mi-interp.c	6 Feb 2013 14:45:19 -0000	1.83
+++ mi/mi-interp.c	12 Mar 2013 17:37:18 -0000
@@ -41,7 +41,7 @@
 /* These are the interpreter setup, etc. functions for the MI
    interpreter.  */
 
-static void mi_execute_command_wrapper (char *cmd);
+static void mi_execute_command_wrapper (const char *cmd);
 static void mi_execute_command_input_handler (char *cmd);
 static void mi_command_loop (int mi_version);
 
@@ -217,10 +217,7 @@ mi_interpreter_suspend (void *data)
 static struct gdb_exception
 mi_interpreter_exec (void *data, const char *command)
 {
-  char *tmp = alloca (strlen (command) + 1);
-
-  strcpy (tmp, command);
-  mi_execute_command_wrapper (tmp);
+  mi_execute_command_wrapper (command);
   return exception_none;
 }
 
@@ -309,7 +306,7 @@ mi_interp_query_hook (const char *ctlstr
 }
 
 static void
-mi_execute_command_wrapper (char *cmd)
+mi_execute_command_wrapper (const char *cmd)
 {
   mi_execute_command (cmd, stdin == instream);
 }
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.227
diff -u -p -r1.227 mi-main.c
--- mi/mi-main.c	14 Feb 2013 10:19:39 -0000	1.227
+++ mi/mi-main.c	12 Mar 2013 17:37:18 -0000
@@ -1962,7 +1962,7 @@ mi_print_exception (const char *token, s
 }
 
 void
-mi_execute_command (char *cmd, int from_tty)
+mi_execute_command (const char *cmd, int from_tty)
 {
   char *token;
   struct mi_parse *command = NULL;
Index: mi/mi-parse.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-parse.c,v
retrieving revision 1.30
diff -u -p -r1.30 mi-parse.c
--- mi/mi-parse.c	7 Mar 2013 21:57:30 -0000	1.30
+++ mi/mi-parse.c	12 Mar 2013 17:37:18 -0000
@@ -32,7 +32,7 @@
    target char.  */
 
 static int
-mi_parse_escape (char **string_ptr)
+mi_parse_escape (const char **string_ptr)
 {
   int c = *(*string_ptr)++;
 
@@ -103,9 +103,9 @@ mi_parse_escape (char **string_ptr)
 }
 
 static void
-mi_parse_argv (char *args, struct mi_parse *parse)
+mi_parse_argv (const char *args, struct mi_parse *parse)
 {
-  char *chp = args;
+  const char *chp = args;
   int argc = 0;
   char **argv = xmalloc ((argc + 1) * sizeof (char *));
 
@@ -115,7 +115,7 @@ mi_parse_argv (char *args, struct mi_par
       char *arg;
 
       /* Skip leading white space.  */
-      chp = skip_spaces (chp);
+      chp = skip_spaces_const (chp);
       /* Three possibilities: EOF, quoted string, or other text. */
       switch (*chp)
 	{
@@ -127,7 +127,7 @@ mi_parse_argv (char *args, struct mi_par
 	  {
 	    /* A quoted string.  */
 	    int len;
-	    char *start = chp + 1;
+	    const char *start = chp + 1;
 
 	    /* Determine the buffer size.  */
 	    chp = start;
@@ -184,7 +184,7 @@ mi_parse_argv (char *args, struct mi_par
 	    /* An unquoted string.  Accumulate all non-blank
 	       characters into a buffer.  */
 	    int len;
-	    char *start = chp;
+	    const char *start = chp;
 
 	    while (*chp != '\0' && !isspace (*chp))
 	      {
@@ -229,9 +229,9 @@ mi_parse_cleanup (void *arg)
 }
 
 struct mi_parse *
-mi_parse (char *cmd, char **token)
+mi_parse (const char *cmd, char **token)
 {
-  char *chp;
+  const char *chp;
   struct mi_parse *parse = XMALLOC (struct mi_parse);
   struct cleanup *cleanup;
 
@@ -244,7 +244,7 @@ mi_parse (char *cmd, char **token)
   cleanup = make_cleanup (mi_parse_cleanup, parse);
 
   /* Before starting, skip leading white space.  */
-  cmd = skip_spaces (cmd);
+  cmd = skip_spaces_const (cmd);
 
   /* Find/skip any token and then extract it.  */
   for (chp = cmd; *chp >= '0' && *chp <= '9'; chp++)
@@ -256,7 +256,7 @@ mi_parse (char *cmd, char **token)
   /* This wasn't a real MI command.  Return it as a CLI_COMMAND.  */
   if (*chp != '-')
     {
-      chp = skip_spaces (chp);
+      chp = skip_spaces_const (chp);
       parse->command = xstrdup (chp);
       parse->op = CLI_COMMAND;
 
@@ -267,7 +267,7 @@ mi_parse (char *cmd, char **token)
 
   /* Extract the command.  */
   {
-    char *tmp = chp + 1;	/* discard ``-'' */
+    const char *tmp = chp + 1;	/* discard ``-'' */
 
     for (; *chp && !isspace (*chp); chp++)
       ;
@@ -282,7 +282,7 @@ mi_parse (char *cmd, char **token)
     error (_("Undefined MI command: %s"), parse->command);
 
   /* Skip white space following the command.  */
-  chp = skip_spaces (chp);
+  chp = skip_spaces_const (chp);
 
   /* Parse the --thread and --frame options, if present.  At present,
      some important commands, like '-break-*' are implemented by
@@ -310,6 +310,8 @@ mi_parse (char *cmd, char **token)
         }
       if (strncmp (chp, "--thread-group ", tgs) == 0)
 	{
+	  char *endp;
+
 	  option = "--thread-group";
 	  if (parse->thread_group != -1)
 	    error (_("Duplicate '--thread-group' option"));
@@ -317,30 +319,37 @@ mi_parse (char *cmd, char **token)
 	  if (*chp != 'i')
 	    error (_("Invalid thread group id"));
 	  chp += 1;
-	  parse->thread_group = strtol (chp, &chp, 10);
+	  parse->thread_group = strtol (chp, &endp, 10);
+	  chp = endp;
 	}
       else if (strncmp (chp, "--thread ", ts) == 0)
 	{
+	  char *endp;
+
 	  option = "--thread";
 	  if (parse->thread != -1)
 	    error (_("Duplicate '--thread' option"));
 	  chp += ts;
-	  parse->thread = strtol (chp, &chp, 10);
+	  parse->thread = strtol (chp, &endp, 10);
+	  chp = endp;
 	}
       else if (strncmp (chp, "--frame ", fs) == 0)
 	{
+	  char *endp;
+
 	  option = "--frame";
 	  if (parse->frame != -1)
 	    error (_("Duplicate '--frame' option"));
 	  chp += fs;
-	  parse->frame = strtol (chp, &chp, 10);
+	  parse->frame = strtol (chp, &endp, 10);
+	  chp = endp;
 	}
       else
 	break;
 
       if (*chp != '\0' && !isspace (*chp))
 	error (_("Invalid value for the '%s' option"), option);
-      chp = skip_spaces (chp);
+      chp = skip_spaces_const (chp);
     }
 
   /* For new argv commands, attempt to return the parsed argument
Index: mi/mi-parse.h
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-parse.h,v
retrieving revision 1.19
diff -u -p -r1.19 mi-parse.h
--- mi/mi-parse.h	1 Jan 2013 06:33:01 -0000	1.19
+++ mi/mi-parse.h	12 Mar 2013 17:37:18 -0000
@@ -60,7 +60,7 @@ struct mi_parse
    the TOKEN field of the resultant mi_parse object, to be freed by
    mi_parse_free.  */
 
-extern struct mi_parse *mi_parse (char *cmd, char **token);
+extern struct mi_parse *mi_parse (const char *cmd, char **token);
 
 /* Free a command returned by mi_parse_command.  */
 

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