This is the mail archive of the gdb-cvs@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]

[binutils-gdb] Constify execute_command


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=95a6b0a106fac6ea35670421534d461a3663c0ba

commit 95a6b0a106fac6ea35670421534d461a3663c0ba
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Oct 15 08:36:51 2017 -0600

    Constify execute_command
    
    This constifies execute_command and fixes up the callers.
    
    gdb/ChangeLog
    2017-11-07  Tom Tromey  <tom@tromey.com>
    
    	* event-top.h (command_handler): Constify.
    	* record-full.c (cmd_record_full_start): Update.
    	* thread.c (thread_apply_all_command): Update.
    	* printcmd.c (eval_command): Update.
    	* mi/mi-main.c (mi_execute_cli_command): Update.
    	(mi_execute_async_cli_command): Update.
    	* tui/tui-stack.c (tui_update_command): Update.
    	* cli/cli-interp.c (safe_execute_command): Constify.
    	* record.c (record_start): Update.
    	(record_start, record_stop, cmd_record_start): Update.
    	* record-btrace.c (cmd_record_btrace_bts_start): Update.
    	(cmd_record_btrace_pt_start): Update.
    	(cmd_record_btrace_start): Update.
    	(cmd_record_btrace_start): Update.
    	* reverse.c (exec_reverse_once): Update.
    	* python/python.c (execute_gdb_command): Don't copy the command.
    	* event-top.c (command_line_handler): Update.
    	(command_handler): Constify.
    	* defs.h (deprecated_call_command_hook): Constify.
    	* cli/cli-script.h (execute_user_command): Constify.
    	* cli/cli-script.c (execute_user_command): Constify.
    	(execute_cmd_pre_hook, execute_cmd_post_hook): Constify.
    	(enum command_control_type): Update.
    	* main.c (catch_command_errors): Remove non-const overload.
    	(catch_command_errors_ftype): Remove.
    	* python/py-cmd.c (cmdpy_function): Constify.
    	* guile/scm-cmd.c (cmdscm_function): Constify.
    	* cli/cli-dump.c (call_dump_func): Constify.
    	* cli/cli-decode.c (do_const_cfunc): Constify.
    	(do_sfunc): Constify.
    	(cmd_func): Constify.
    	* gdbcmd.h (execute_command, execute_command_to_string): Constify.
    	* top.h (execute_command): Constify.
    	* top.c (execute_command): Constify.
    	(execute_command_to_string): Constify.
    	(deprecated_call_command_hook): Constify.
    	* command.h (cmd_func): Constify.
    	* cli/cli-decode.h (struct cmd_list_element) <func>: Constify.

Diff:
---
 gdb/ChangeLog        | 41 +++++++++++++++++++++++++++++++++++++++++
 gdb/cli/cli-decode.c |  6 +++---
 gdb/cli/cli-decode.h |  2 +-
 gdb/cli/cli-dump.c   |  2 +-
 gdb/cli/cli-interp.c | 12 ++++--------
 gdb/cli/cli-script.c |  8 ++++----
 gdb/cli/cli-script.h |  2 +-
 gdb/command.h        |  2 +-
 gdb/defs.h           |  2 +-
 gdb/event-top.c      |  6 +++---
 gdb/event-top.h      |  2 +-
 gdb/gdbcmd.h         |  4 ++--
 gdb/guile/scm-cmd.c  |  3 +--
 gdb/main.c           | 29 +----------------------------
 gdb/mi/mi-main.c     |  4 ++--
 gdb/printcmd.c       |  2 +-
 gdb/python/py-cmd.c  |  3 +--
 gdb/python/python.c  |  6 ++----
 gdb/record-btrace.c  |  8 ++++----
 gdb/record-full.c    |  2 +-
 gdb/record.c         | 14 +++++++-------
 gdb/reverse.c        |  2 +-
 gdb/thread.c         | 16 +++-------------
 gdb/top.c            | 30 +++++++++++++++++++-----------
 gdb/top.h            |  2 +-
 gdb/tui/tui-stack.c  |  5 +----
 26 files changed, 108 insertions(+), 107 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ad03356..67f65c4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,46 @@
 2017-11-07  Tom Tromey  <tom@tromey.com>
 
+	* event-top.h (command_handler): Constify.
+	* record-full.c (cmd_record_full_start): Update.
+	* thread.c (thread_apply_all_command): Update.
+	* printcmd.c (eval_command): Update.
+	* mi/mi-main.c (mi_execute_cli_command): Update.
+	(mi_execute_async_cli_command): Update.
+	* tui/tui-stack.c (tui_update_command): Update.
+	* cli/cli-interp.c (safe_execute_command): Constify.
+	* record.c (record_start): Update.
+	(record_start, record_stop, cmd_record_start): Update.
+	* record-btrace.c (cmd_record_btrace_bts_start): Update.
+	(cmd_record_btrace_pt_start): Update.
+	(cmd_record_btrace_start): Update.
+	(cmd_record_btrace_start): Update.
+	* reverse.c (exec_reverse_once): Update.
+	* python/python.c (execute_gdb_command): Don't copy the command.
+	* event-top.c (command_line_handler): Update.
+	(command_handler): Constify.
+	* defs.h (deprecated_call_command_hook): Constify.
+	* cli/cli-script.h (execute_user_command): Constify.
+	* cli/cli-script.c (execute_user_command): Constify.
+	(execute_cmd_pre_hook, execute_cmd_post_hook): Constify.
+	(enum command_control_type): Update.
+	* main.c (catch_command_errors): Remove non-const overload.
+	(catch_command_errors_ftype): Remove.
+	* python/py-cmd.c (cmdpy_function): Constify.
+	* guile/scm-cmd.c (cmdscm_function): Constify.
+	* cli/cli-dump.c (call_dump_func): Constify.
+	* cli/cli-decode.c (do_const_cfunc): Constify.
+	(do_sfunc): Constify.
+	(cmd_func): Constify.
+	* gdbcmd.h (execute_command, execute_command_to_string): Constify.
+	* top.h (execute_command): Constify.
+	* top.c (execute_command): Constify.
+	(execute_command_to_string): Constify.
+	(deprecated_call_command_hook): Constify.
+	* command.h (cmd_func): Constify.
+	* cli/cli-decode.h (struct cmd_list_element) <func>: Constify.
+
+2017-11-07  Tom Tromey  <tom@tromey.com>
+
 	* ada-lang.c (catch_ada_exception_command): Constify.
 	(catch_assert_command): Constify.
 	* break-catch-throw.c (catch_catch_command, catch_throw_command)
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index c3e7228..b911097 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -101,7 +101,7 @@ print_help_for_command (struct cmd_list_element *c, const char *prefix,
    bounce function (unless cfunc / sfunc is NULL that is).  */
 
 static void
-do_const_cfunc (struct cmd_list_element *c, char *args, int from_tty)
+do_const_cfunc (struct cmd_list_element *c, const char *args, int from_tty)
 {
   c->function.const_cfunc (args, from_tty);
 }
@@ -117,7 +117,7 @@ set_cmd_cfunc (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc)
 }
 
 static void
-do_sfunc (struct cmd_list_element *c, char *args, int from_tty)
+do_sfunc (struct cmd_list_element *c, const char *args, int from_tty)
 {
   c->function.sfunc (args, from_tty, c);
 }
@@ -1909,7 +1909,7 @@ cmd_func_p (struct cmd_list_element *cmd)
 
 /* Call the command function.  */
 void
-cmd_func (struct cmd_list_element *cmd, char *args, int from_tty)
+cmd_func (struct cmd_list_element *cmd, const char *args, int from_tty)
 {
   if (cmd_func_p (cmd))
     {
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index 9b2d598..09d5c49 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -107,7 +107,7 @@ struct cmd_list_element
        cagney/2002-02-02: This function signature is evolving.  For
        the moment suggest sticking with either set_cmd_cfunc() or
        set_cmd_sfunc().  */
-    void (*func) (struct cmd_list_element *c, char *args, int from_tty);
+    void (*func) (struct cmd_list_element *c, const char *args, int from_tty);
     /* The command's real callback.  At present func() bounces through
        to one of the below.  */
     union
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 3443299..e97dabf 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -344,7 +344,7 @@ struct dump_context
 };
 
 static void
-call_dump_func (struct cmd_list_element *c, char *args, int from_tty)
+call_dump_func (struct cmd_list_element *c, const char *args, int from_tty)
 {
   struct dump_context *d = (struct dump_context *) get_cmd_context (c);
 
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 609a419..9477ac8 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -80,7 +80,7 @@ as_cli_interp (struct interp *interp)
 
 /* Longjmp-safe wrapper for "execute_command".  */
 static struct gdb_exception safe_execute_command (struct ui_out *uiout,
-						  char *command, 
+						  const char *command, 
 						  int from_tty);
 
 /* See cli-interp.h.
@@ -332,11 +332,6 @@ cli_interp::exec (const char *command_str)
   struct ui_file *old_stream;
   struct gdb_exception result;
 
-  /* FIXME: cagney/2003-02-01: Need to const char *propogate
-     safe_execute_command.  */
-  char *str = (char *) alloca (strlen (command_str) + 1);
-  strcpy (str, command_str);
-
   /* gdb_stdout could change between the time cli_uiout was
      initialized and now.  Since we're probably using a different
      interpreter which has a new ui_file for gdb_stdout, use that one
@@ -345,7 +340,7 @@ cli_interp::exec (const char *command_str)
      It is important that it gets reset everytime, since the user
      could set gdb to use a different interpreter.  */
   old_stream = cli->cli_uiout->set_stream (gdb_stdout);
-  result = safe_execute_command (cli->cli_uiout, str, 1);
+  result = safe_execute_command (cli->cli_uiout, command_str, 1);
   cli->cli_uiout->set_stream (old_stream);
   return result;
 }
@@ -357,7 +352,8 @@ cli_interp_base::supports_command_editing ()
 }
 
 static struct gdb_exception
-safe_execute_command (struct ui_out *command_uiout, char *command, int from_tty)
+safe_execute_command (struct ui_out *command_uiout, const char *command,
+		      int from_tty)
 {
   struct gdb_exception e = exception_none;
   struct ui_out *saved_uiout;
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index b06dbc2..4df714e 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -369,7 +369,7 @@ execute_cmd_pre_hook (struct cmd_list_element *c)
     {
       scoped_restore_hook_in restore_hook (c);
       c->hook_in = 1; /* Prevent recursive hooking.  */
-      execute_user_command (c->hook_pre, (char *) 0);
+      execute_user_command (c->hook_pre, nullptr);
     }
 }
 
@@ -380,12 +380,12 @@ execute_cmd_post_hook (struct cmd_list_element *c)
     {
       scoped_restore_hook_in restore_hook (c);
       c->hook_in = 1; /* Prevent recursive hooking.  */
-      execute_user_command (c->hook_post, (char *) 0);
+      execute_user_command (c->hook_post, nullptr);
     }
 }
 
 void
-execute_user_command (struct cmd_list_element *c, char *args)
+execute_user_command (struct cmd_list_element *c, const char *args)
 {
   struct ui *ui = current_ui;
   struct command_line *cmdlines;
@@ -484,7 +484,7 @@ execute_control_command_1 (struct command_line *cmd)
       {
 	/* A simple command, execute it and return.  */
 	std::string new_line = insert_user_defined_cmd_args (cmd->line);
-	execute_command (&new_line[0], 0);
+	execute_command (new_line.c_str (), 0);
 	ret = cmd->control_type;
 	break;
       }
diff --git a/gdb/cli/cli-script.h b/gdb/cli/cli-script.h
index 234faf7..eaca0cd 100644
--- a/gdb/cli/cli-script.h
+++ b/gdb/cli/cli-script.h
@@ -122,7 +122,7 @@ extern command_line_up copy_command_lines (struct command_line *cmds);
 
 /* Exported to gdb/infrun.c */
 
-extern void execute_user_command (struct cmd_list_element *c, char *args);
+extern void execute_user_command (struct cmd_list_element *c, const char *args);
 
 /* If we're in a user-defined command, replace any $argc/$argN
    reference found in LINE with the arguments that were passed to the
diff --git a/gdb/command.h b/gdb/command.h
index 69e903f..505375e 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -453,6 +453,6 @@ extern int cmd_func_p (struct cmd_list_element *cmd);
 
 /* Call the command function.  */
 extern void cmd_func (struct cmd_list_element *cmd,
-		      char *args, int from_tty);
+		      const char *args, int from_tty);
 
 #endif /* !defined (COMMAND_H) */
diff --git a/gdb/defs.h b/gdb/defs.h
index 675c239..f76293f 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -660,7 +660,7 @@ extern ptid_t (*deprecated_target_wait_hook) (ptid_t ptid,
 extern void (*deprecated_attach_hook) (void);
 extern void (*deprecated_detach_hook) (void);
 extern void (*deprecated_call_command_hook) (struct cmd_list_element * c,
-					     char *cmd, int from_tty);
+					     const char *cmd, int from_tty);
 
 extern int (*deprecated_ui_load_progress_hook) (const char *section,
 						unsigned long num);
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 7377189..8993696 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -565,10 +565,10 @@ async_disable_stdin (void)
    a whole command.  */
 
 void
-command_handler (char *command)
+command_handler (const char *command)
 {
   struct ui *ui = current_ui;
-  char *c;
+  const char *c;
 
   if (ui->instream == ui->stdin_stream)
     reinitialize_more_filter ();
@@ -759,7 +759,7 @@ command_line_handler (char *rl)
 	 hung up but GDB is still alive.  In such a case, we just quit
 	 gdb killing the inferior program too.  */
       printf_unfiltered ("quit\n");
-      execute_command ((char *) "quit", 1);
+      execute_command ("quit", 1);
     }
   else if (cmd == NULL)
     {
diff --git a/gdb/event-top.h b/gdb/event-top.h
index d069c56..e80eb27 100644
--- a/gdb/event-top.h
+++ b/gdb/event-top.h
@@ -36,7 +36,7 @@ extern void async_init_signals (void);
 extern void change_line_handler (int);
 
 extern void command_line_handler (char *rl);
-extern void command_handler (char *command);
+extern void command_handler (const char *command);
 
 #ifdef SIGTSTP
 extern void handle_sigtstp (int sig);
diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h
index 3191ecd..4a3e94a 100644
--- a/gdb/gdbcmd.h
+++ b/gdb/gdbcmd.h
@@ -132,8 +132,8 @@ extern struct cmd_list_element *showchecklist;
 
 extern struct cmd_list_element *save_cmdlist;
 
-extern void execute_command (char *, int);
-extern std::string execute_command_to_string (char *p, int from_tty);
+extern void execute_command (const char *, int);
+extern std::string execute_command_to_string (const char *p, int from_tty);
 
 enum command_control_type execute_control_command (struct command_line *);
 
diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c
index 0bd5105..4745def 100644
--- a/gdb/guile/scm-cmd.c
+++ b/gdb/guile/scm-cmd.c
@@ -292,9 +292,8 @@ cmdscm_destroyer (struct cmd_list_element *self, void *context)
 
 static void
 cmdscm_function (struct cmd_list_element *command,
-		 char *args_entry, int from_tty)
+		 const char *args, int from_tty)
 {
-  const char *args = args_entry;
   command_smob *c_smob/*obj*/ = (command_smob *) get_cmd_context (command);
   SCM arg_scm, tty_scm, result;
 
diff --git a/gdb/main.c b/gdb/main.c
index 835ae24..61168fa 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -360,39 +360,12 @@ handle_command_errors (struct gdb_exception e)
   return 1;
 }
 
-/* Type of the command callback passed to catch_command_errors.  */
-
-typedef void (catch_command_errors_ftype) (char *, int);
-
-/* Wrap calls to commands run before the event loop is started.  */
-
-static int
-catch_command_errors (catch_command_errors_ftype *command,
-		      char *arg, int from_tty)
-{
-  TRY
-    {
-      int was_sync = current_ui->prompt_state == PROMPT_BLOCKED;
-
-      command (arg, from_tty);
-
-      maybe_wait_sync_command_done (was_sync);
-    }
-  CATCH (e, RETURN_MASK_ALL)
-    {
-      return handle_command_errors (e);
-    }
-  END_CATCH
-
-  return 1;
-}
-
 /* Type of the command callback passed to the const
    catch_command_errors.  */
 
 typedef void (catch_command_errors_const_ftype) (const char *, int);
 
-/* Const-correct catch_command_errors.  */
+/* Wrap calls to commands run before the event loop is started.  */
 
 static int
 catch_command_errors (catch_command_errors_const_ftype command,
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index d875d80..d3ea139 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -2206,7 +2206,7 @@ mi_execute_cli_command (const char *cmd, int args_p, const char *args)
 	/* FIXME: gdb_???? */
 	fprintf_unfiltered (gdb_stdout, "cli=%s run=%s\n",
 			    cmd, run.c_str ());
-      execute_command (&run[0], 0 /* from_tty */ );
+      execute_command (run.c_str (), 0 /* from_tty */ );
     }
 }
 
@@ -2220,7 +2220,7 @@ mi_execute_async_cli_command (const char *cli_command, char **argv, int argc)
   if (mi_async_p ())
     run += "&";
 
-  execute_command (&run[0], 0 /* from_tty */ );
+  execute_command (run.c_str (), 0 /* from_tty */ );
 }
 
 void
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 707b331..2e596d1 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2617,7 +2617,7 @@ eval_command (const char *arg, int from_tty)
 
   std::string expanded = insert_user_defined_cmd_args (stb.c_str ());
 
-  execute_command (&expanded[0], from_tty);
+  execute_command (expanded.c_str (), from_tty);
 }
 
 void
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index d969b12..d848600 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -110,9 +110,8 @@ cmdpy_destroyer (struct cmd_list_element *self, void *context)
 
 static void
 cmdpy_function (struct cmd_list_element *command,
-		char *args_entry, int from_tty)
+		const char *args, int from_tty)
 {
-  const char *args = args_entry;
   cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command);
 
   gdbpy_enter enter_py (get_current_arch (), current_language);
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 88a31b0..03ea5d5 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -584,8 +584,6 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
 
   TRY
     {
-      /* Copy the argument text in case the command modifies it.  */
-      std::string copy (arg);
       struct interp *interp;
 
       scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
@@ -599,9 +597,9 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
 
       scoped_restore preventer = prevent_dont_repeat ();
       if (to_string)
-	to_string_res = execute_command_to_string (&copy[0], from_tty);
+	to_string_res = execute_command_to_string (arg, from_tty);
       else
-	execute_command (&copy[0], from_tty);
+	execute_command (arg, from_tty);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index b7e379b..07ef912 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -2892,7 +2892,7 @@ cmd_record_btrace_bts_start (const char *args, int from_tty)
 
   TRY
     {
-      execute_command ((char *) "target record-btrace", from_tty);
+      execute_command ("target record-btrace", from_tty);
     }
   CATCH (exception, RETURN_MASK_ALL)
     {
@@ -2914,7 +2914,7 @@ cmd_record_btrace_pt_start (const char *args, int from_tty)
 
   TRY
     {
-      execute_command ((char *) "target record-btrace", from_tty);
+      execute_command ("target record-btrace", from_tty);
     }
   CATCH (exception, RETURN_MASK_ALL)
     {
@@ -2936,7 +2936,7 @@ cmd_record_btrace_start (const char *args, int from_tty)
 
   TRY
     {
-      execute_command ((char *) "target record-btrace", from_tty);
+      execute_command ("target record-btrace", from_tty);
     }
   CATCH (exception, RETURN_MASK_ALL)
     {
@@ -2944,7 +2944,7 @@ cmd_record_btrace_start (const char *args, int from_tty)
 
       TRY
 	{
-	  execute_command ((char *) "target record-btrace", from_tty);
+	  execute_command ("target record-btrace", from_tty);
 	}
       CATCH (exception, RETURN_MASK_ALL)
 	{
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 4249c04..ec6fc69 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2756,7 +2756,7 @@ record_full_goto_insn (struct record_full_entry *entry,
 static void
 cmd_record_full_start (const char *args, int from_tty)
 {
-  execute_command ((char *) "target record-full", from_tty);
+  execute_command ("target record-full", from_tty);
 }
 
 static void
diff --git a/gdb/record.c b/gdb/record.c
index 8de871a..b53c0bc 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -99,25 +99,25 @@ record_start (const char *method, const char *format, int from_tty)
   if (method == NULL)
     {
       if (format == NULL)
-	execute_command_to_string ((char *) "record", from_tty);
+	execute_command_to_string ("record", from_tty);
       else
 	error (_("Invalid format."));
     }
   else if (strcmp (method, "full") == 0)
     {
       if (format == NULL)
-	execute_command_to_string ((char *) "record full", from_tty);
+	execute_command_to_string ("record full", from_tty);
       else
 	error (_("Invalid format."));
     }
   else if (strcmp (method, "btrace") == 0)
     {
       if (format == NULL)
-	execute_command_to_string ((char *) "record btrace", from_tty);
+	execute_command_to_string ("record btrace", from_tty);
       else if (strcmp (format, "bts") == 0)
-	execute_command_to_string ((char *) "record btrace bts", from_tty);
+	execute_command_to_string ("record btrace bts", from_tty);
       else if (strcmp (format, "pt") == 0)
-	execute_command_to_string ((char *) "record btrace pt", from_tty);
+	execute_command_to_string ("record btrace pt", from_tty);
       else
 	error (_("Invalid format."));
     }
@@ -130,7 +130,7 @@ record_start (const char *method, const char *format, int from_tty)
 void
 record_stop (int from_tty)
 {
-  execute_command_to_string ((char *) "record stop", from_tty);
+  execute_command_to_string ("record stop", from_tty);
 }
 
 /* See record.h.  */
@@ -266,7 +266,7 @@ show_record_debug (struct ui_file *file, int from_tty,
 static void
 cmd_record_start (const char *args, int from_tty)
 {
-  execute_command ((char *) "target record-full", from_tty);
+  execute_command ("target record-full", from_tty);
 }
 
 /* Truncate the record log from the present point
diff --git a/gdb/reverse.c b/gdb/reverse.c
index 7362f32..35d5019 100644
--- a/gdb/reverse.c
+++ b/gdb/reverse.c
@@ -50,7 +50,7 @@ exec_reverse_once (const char *cmd, const char *args, int from_tty)
   std::string reverse_command = string_printf ("%s %s", cmd, args ? args : "");
   scoped_restore restore_exec_dir
     = make_scoped_restore (&execution_direction, EXEC_REVERSE);
-  execute_command (&reverse_command[0], from_tty);
+  execute_command (reverse_command.c_str (), from_tty);
 }
 
 static void
diff --git a/gdb/thread.c b/gdb/thread.c
index 1e81a61..d71568e 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1704,10 +1704,7 @@ thread_apply_all_command (const char *cmd, int from_tty)
 			     print_thread_id (thr),
 			     target_pid_to_str (inferior_ptid));
 
-	    /* Use a copy of the command in case it is clobbered by
-	       execute_command.  */
-	    std::string copy = cmd;
-	    execute_command (&copy[0], from_tty);
+	    execute_command (cmd, from_tty);
 	  }
     }
 }
@@ -1717,7 +1714,7 @@ thread_apply_all_command (const char *cmd, int from_tty)
 static void
 thread_apply_command (const char *tidlist, int from_tty)
 {
-  char *cmd = NULL;
+  const char *cmd = NULL;
   tid_range_parser parser;
 
   if (tidlist == NULL || *tidlist == '\000')
@@ -1730,7 +1727,7 @@ thread_apply_command (const char *tidlist, int from_tty)
 
       if (!parser.get_tid_range (&inf_num, &thr_start, &thr_end))
 	{
-	  cmd = (char *) parser.cur_tok ();
+	  cmd = parser.cur_tok ();
 	  break;
 	}
     }
@@ -1741,10 +1738,6 @@ thread_apply_command (const char *tidlist, int from_tty)
   if (tidlist == cmd || !isalpha (cmd[0]))
     invalid_thread_id_error (cmd);
 
-  /* Save a copy of the command in case it is clobbered by
-     execute_command.  */
-  std::string saved_cmd = cmd;
-
   scoped_restore_current_thread restore_thread;
 
   parser.init (tidlist, current_inferior ()->num);
@@ -1798,9 +1791,6 @@ thread_apply_command (const char *tidlist, int from_tty)
       printf_filtered (_("\nThread %s (%s):\n"), print_thread_id (tp),
 		       target_pid_to_str (inferior_ptid));
       execute_command (cmd, from_tty);
-
-      /* Restore exact command used previously.  */
-      strcpy (cmd, saved_cmd.c_str ());
     }
 }
 
diff --git a/gdb/top.c b/gdb/top.c
index 63e61e7..8cd7c99 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -237,7 +237,7 @@ ptid_t (*deprecated_target_wait_hook) (ptid_t ptid,
    things like enabling/disabling buttons, etc...  */
 
 void (*deprecated_call_command_hook) (struct cmd_list_element * c, 
-				      char *cmd, int from_tty);
+				      const char *cmd, int from_tty);
 
 /* Called when the current thread changes.  Argument is thread id.  */
 
@@ -539,11 +539,12 @@ set_repeat_arguments (const char *args)
    Pass FROM_TTY as second argument to the defining function.  */
 
 void
-execute_command (char *p, int from_tty)
+execute_command (const char *p, int from_tty)
 {
   struct cleanup *cleanup_if_error;
   struct cmd_list_element *c;
-  char *line;
+  const char *line;
+  const char *cmd_start = p;
 
   cleanup_if_error = make_bpstat_clear_actions_cleanup ();
   scoped_value_mark cleanup = prepare_execute_command ();
@@ -566,7 +567,7 @@ execute_command (char *p, int from_tty)
   if (*p)
     {
       const char *cmd = p;
-      char *arg;
+      const char *arg;
       int was_sync = current_ui->prompt_state == PROMPT_BLOCKED;
 
       line = p;
@@ -575,11 +576,11 @@ execute_command (char *p, int from_tty)
       print_command_trace (p);
 
       c = lookup_cmd (&cmd, cmdlist, "", 0, 1);
-      p = (char *) cmd;
+      p = cmd;
 
       scoped_restore save_repeat_args
 	= make_scoped_restore (&repeat_arguments, nullptr);
-      char *args_pointer = p;
+      const char *args_pointer = p;
 
       /* Pass null arg rather than an empty one.  */
       arg = *p ? p : 0;
@@ -594,14 +595,20 @@ execute_command (char *p, int from_tty)
          is_complete_command hack is testing for.  */
       /* Clear off trailing whitespace, except for set and complete
          command.  */
+      std::string without_whitespace;
       if (arg
 	  && c->type != set_cmd
 	  && !is_complete_command (c))
 	{
-	  p = arg + strlen (arg) - 1;
+	  const char *old_end = arg + strlen (arg) - 1;
+	  p = old_end;
 	  while (p >= arg && (*p == ' ' || *p == '\t'))
 	    p--;
-	  *(p + 1) = '\0';
+	  if (p != old_end)
+	    {
+	      without_whitespace = std::string (arg, p + 1);
+	      arg = without_whitespace.c_str ();
+	    }
 	}
 
       /* If this command has been pre-hooked, run the hook first.  */
@@ -629,10 +636,11 @@ execute_command (char *p, int from_tty)
       /* If this command has been post-hooked, run the hook last.  */
       execute_cmd_post_hook (c);
 
-      if (repeat_arguments != NULL)
+      if (repeat_arguments != NULL && cmd_start == saved_command_line)
 	{
 	  gdb_assert (strlen (args_pointer) >= strlen (repeat_arguments));
-	  strcpy (args_pointer, repeat_arguments);
+	  strcpy (saved_command_line + (args_pointer - cmd_start),
+		  repeat_arguments);
 	}
     }
 
@@ -646,7 +654,7 @@ execute_command (char *p, int from_tty)
    temporarily set to true.  */
 
 std::string
-execute_command_to_string (char *p, int from_tty)
+execute_command_to_string (const char *p, int from_tty)
 {
   /* GDB_STDOUT should be better already restored during these
      restoration callbacks.  */
diff --git a/gdb/top.h b/gdb/top.h
index 65d1f08..26fe878 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -232,7 +232,7 @@ extern int quit_confirm (void);
 extern void quit_force (int *, int);
 extern void quit_command (const char *, int);
 extern void quit_cover (void);
-extern void execute_command (char *, int);
+extern void execute_command (const char *, int);
 
 /* If the interpreter is in sync mode (we're running a user command's
    list, running command hooks or similars), and we just ran a
diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index 4a69b97..d5d18e2 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -499,8 +499,5 @@ _initialize_tui_stack (void)
 static void
 tui_update_command (const char *arg, int from_tty)
 {
-  char cmd[sizeof("frame 0")];
-
-  strcpy (cmd, "frame 0");
-  execute_command (cmd, from_tty);
+  execute_command ("frame 0", from_tty);
 }


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