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]

Re: [RFC/RFA PATCH] Constify strings in tracepoint.c, lookup_cmd and the completers.


On 03/13/2013 05:22 PM, Keith Seitz wrote:
> The only thing "wrong" that I found was missing comment on the new output_command_const; 

Good catch.  I've added one now.  I also removed the declaration of
output_command and made it static.

> just to be maintainer-pedantic (even though I am not a maintainer). :-P

The way to become a maintainer is to just act like a maintainer a
lot of times. :-)

> When I'm done rebasing my current work, I'll see if I can dig up the rest of my patches on this subject.

Awesome.

On 03/13/2013 05:28 PM, Tom Tromey wrote:

> Pedro> I think the only non-really-super-obvious changes are
> Pedro> tracepoint.c:validate_actionline, and tracepoint.c:trace_dump_actions.
> 
> In trace_dump_actions, I think that the "line" local variable is now
> dead, and the code would be clearer if you just removed it.

Removed.

> Pedro> +static struct expression *
> Pedro> +parse_exp_in_context (const char **stringptr, CORE_ADDR pc, const struct block *block,
> 
> Over-long line.
> 
> Pedro> +parse_exp_in_context_1 (char **stringptr, CORE_ADDR pc, const struct block *block,
> 
> Here too.

Both fixed.  I looked over for other cases, but couldn't find any.

Thanks both.  Here's what I'm applying.

-- >8 --
Subject: [PATCH] Constify strings in tracepoint.c, lookup_cmd and the completers.

This is sort of a continuation of Keith's parse_exp_1 constification
patch.  It started out by undoing these bits:

  @@ -754,9 +754,12 @@ validate_actionline (char **line, struct
   	  tmp_p = p;
   	  for (loc = t->base.loc; loc; loc = loc->next)
   	    {
  -	      p = tmp_p;
  -	      exp = parse_exp_1 (&p, loc->address,
  +	      const char *q;
  +
  +	      q = tmp_p;
  +	      exp = parse_exp_1 (&q, loc->address,
   				 block_for_pc (loc->address), 1);
  +	      p = (char *) q;

and progressively making more things const upwards, fixing fallout,
rinse repeat, until GDB built again (--enable-targets=all).

That ended up constifying lookup_cmd/add_cmd and (lots of) friends,
and the completers.

I didn't try to constify the command hooks themselves, because I know
upfront there are commands that write to the command string argument,
and I think I managed to stop at a nice non-hacky split point already.

I think the only non-really-super-obvious changes are
tracepoint.c:validate_actionline, and tracepoint.c:trace_dump_actions.

The rest is just mostly about 'char *' => 'const char *', 'char **'=>
'const char **', and the occasional (e.g., deprecated_cmd_warning)
case of 'char **'=> 'const char *', where/when I noticed that nothing
actually cares about the pointer to pointer output.

Tested on x86_64 Fedora 17, native and gdbserver.

gdb/
2013-03-12  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (struct add_partial_datum) <text, text0, word>: Make
	fields const.
	(ada_make_symbol_completion_list): Make "text0" parameter const.
	* ax-gdb.c (agent_eval_command_one): Make "exp" parameter const.
	* breakpoint.c (condition_completer): Make "text" and "word"
	parameters const.  Adjust.
	(check_tracepoint_command): Adjust to validate_actionline
	prototype change.
	(catch_syscall_completer): Make "text" and "word" parameters
	const.
	* cli/cli-cmds.c (show_user): Make "comname" local const.
	(valid_command_p): Make "command" parameter const.
	(alias_command): Make "alias_prefix" and "command_prefix" locals
	const.
	* cli/cli-decode.c (add_cmd): Make "name" parameter const.
	(add_alias_cmd): Make "name" and "oldname" parameters const.
	Adjust.  No longer make copy of OLDNAME.
	(add_prefix_cmd, add_abbrev_prefix_cmd, add_set_or_show_cmd)
	(add_setshow_cmd_full, add_setshow_enum_cmd)
	(add_setshow_auto_boolean_cmd, add_setshow_boolean_cmd)
	(add_setshow_filename_cmd, add_setshow_string_cmd)
	(add_setshow_string_noescape_cmd)
	(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
	(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
	(add_setshow_zuinteger_unlimited_cmd, add_setshow_zuinteger_cmd)
	(delete_cmd, add_info, add_info_alias, add_com, add_com_alias):
	Make "name" parameter const.
	(help_cmd): Rename "command" parameter to "arg".  New const local
	"command".
	(find_cmd): Make "command" parameter const.
	(lookup_cmd_1): Make "text" parameter pointer to const.  Adjust to
	deprecated_cmd_warning prototype change.
	(undef_cmd_error): Make "cmdtype" parameter const.
	(lookup_cmd): Make "line" parameter const.
	(deprecated_cmd_warning): Change type of "text" parameter to
	pointer to const char, from pointer to pointer to char.  Adjust.
	(lookup_cmd_composition): Make "text" parameter const.
	(complete_on_cmdlist, complete_on_enum): Make "text" and "word"
	parameters const.
	* cli/cli-decode.h (struct cmd_list_element) <name>: Make field
	const.
	* cli/cli-script.c (validate_comname): Make "tem" local const.
	(define_command): New const local "tem_c".  Use it in calls to
	lookup_cmd.
	(document_command): Make "tem" and "comfull" locals const.
	(show_user_1): Make "prefix" and "name" parameters const.
	* cli-script.h (show_user_1): Make "prefix" and "name" parameters
	const.
	* command.h (add_cmd, add_alias_cmd, add_prefix_cmd)
	(add_abbrev_prefix_cmd, completer_ftype, lookup_cmd, lookup_cmd_1)
	(deprecated_cmd_warning, lookup_cmd_composition, add_com)
	(add_com_alias, add_info, add_info_alias, complete_on_cmdlist)
	(complete_on_enum, add_setshow_enum_cmd)
	(add_setshow_auto_boolean_cmd, add_setshow_boolean_cmd)
	(add_setshow_filename_cmd, add_setshow_string_cmd)
	(add_setshow_string_noescape_cmd)
	(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
	(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
	(add_setshow_zuinteger_cmd, add_setshow_zuinteger_unlimited_cmd):
	Change prototypes, constifying strings.
	* completer.c (noop_completer, filename_completer): Make "text"
	and "prefix" parameters const.
	(location_completer, expression_completer)
	(complete_line_internal): Make "text" and "prefix" parameters
	const and adjust.
	(command_completer, signal_completer): Make "text" and "prefix"
	parameters const.
	* completer.h (noop_completer, filename_completer)
	(expression_completer, location_completer, command_completer)
	(signal_completer): Change prototypes.
	* corefile.c (complete_set_gnutarget): Make "text" and "word"
	parameters const.
	* cp-abi.c (cp_abi_completer): Likewise.
	* expression.h (parse_expression_for_completion): Change
	prototype.
	* f-lang.c (f_make_symbol_completion_list): Make "text" and "word"
	parameters const.
	* infcmd.c (_initialize_infcmd): Make "cmd_name" local const.
	* infrun.c (handle_completer): Make "text" and "word" parameters
	const.
	* interps.c (interpreter_completer): Make "text" and "word"
	parameters const.
	* language.h (struct language_defn)
	<la_make_symbol_completion_list>: Make "text" and "word"
	parameters const.
	* parse.c (parse_exp_1): Move const hack to parse_exp_in_context.
	(parse_exp_in_context): Rename to ...
	(parse_exp_in_context_1): ... this.
	(parse_exp_in_context): Reimplement, with const hack from
	parse_exp_1.
	(parse_expression_for_completion): Make "string" parameter const.
	* printcmd.c (decode_format): Make "string_ptr" parameter pointer
	to pointer to const char.  Adjust.
	(print_command_1): Make "exp" parameter const.
	(output_command): Rename to ...
	(output_command_const): ... this.  Make "exp" parameter const.
	(output_command): Reimplement.
	(x_command): Adjust.
	(display_command): Rename "exp" parameter to "arg".  New "exp"
	local, const version of "arg".
	* python/py-auto-load.c (gdbpy_initialize_auto_load): Make
	"cmd_name" local const.
	* python/py-cmd.c (cmdpy_destroyer): Cast const away in xfree
	call.
	(cmdpy_completer): Make "text" and "word" parameters const.
	(gdbpy_parse_command_name): Make "prefix_text2" local const.
	* python/py-param.c (add_setshow_generic): Make "tmp_name" local
	const.
	* remote.c (_initialize_remote): Make "cmd_name" local const.
	* symtab.c (language_search_unquoted_string): Make "text" and "p"
	parameters const.  Adjust.
	(completion_list_add_fields): Make "sym_text", "text" and "word"
	parameters const.
	(struct add_name_data) <sym_text, text, word>: Make fields const.
	(default_make_symbol_completion_list_break_on): Make "text" and
	"word" parameters const.  Adjust locals.
	(default_make_symbol_completion_list)
	(make_symbol_completion_list, make_symbol_completion_type)
	(make_symbol_completion_list_fn): Make "text" and "word"
	parameters const.
	(make_file_symbol_completion_list): Make "text", "word" and
	"srcfile" parameters const.  Adjust locals.
	(add_filename_to_list): Make "text" and "word" parameters const.
	(struct add_partial_filename_data) <text, word>: Make fields
	const.
	(make_source_files_completion_list): Make "text" and "word"
	parameters const.
	* symtab.h (default_make_symbol_completion_list_break_on)
	(default_make_symbol_completion_list, make_symbol_completion_list)
	(make_symbol_completion_type enum type_code)
	(make_symbol_completion_list_fn make_file_symbol_completion_list)
	(make_source_files_completion_list): Change prototype.
	* top.c (execute_command): Adjust to pass pointer to pointer to
	const char to lookup_cmd, and to deprecated_cmd_warning prototype
	change.
	(set_verbose): Make "cmdname" local const.
	* tracepoint.c (decode_agent_options): Make "exp" parameter const,
	and adjust.
	(validate_actionline): Make "line" parameter a pointer to const
	char, and adjust.
	(encode_actions_1): Make "action_exp" local const, and adjust.
	(encode_actions): Adjust.
	(replace_comma): Delete.
	(trace_dump_actions): Make "action_exp" and "next_comma" locals
	const, and adjust.  Don't frob the action string while splitting
	it at commas.  Instead, make a copy of each split substring in
	turn.
	(trace_dump_command): Adjust to validate_actionline prototype
	change.
	* tracepoint.h (decode_agent_options, decode_agent_options)
	(encode_actions, validate_actionline): Change prototypes.
	* valprint.h (output_command): Delete declaration.
	(output_command_const): Declare.
	* value.c (function_destroyer): Cast const away in xfree call.
---
 gdb/ada-lang.c            |   9 ++--
 gdb/ax-gdb.c              |   2 +-
 gdb/breakpoint.c          |  15 +++---
 gdb/cli/cli-cmds.c        |   6 +--
 gdb/cli/cli-decode.c      |  94 +++++++++++++++++------------------
 gdb/cli/cli-decode.h      |   2 +-
 gdb/cli/cli-script.c      |  17 ++++---
 gdb/cli/cli-script.h      |   6 ++-
 gdb/command.h             |  54 ++++++++++----------
 gdb/completer.c           |  46 +++++++++--------
 gdb/completer.h           |  12 ++---
 gdb/corefile.c            |   3 +-
 gdb/cp-abi.c              |   2 +-
 gdb/expression.h          |   2 +-
 gdb/f-lang.c              |   3 +-
 gdb/infcmd.c              |   2 +-
 gdb/infrun.c              |   2 +-
 gdb/interps.c             |   3 +-
 gdb/language.h            |   3 +-
 gdb/parse.c               |  23 +++++++--
 gdb/printcmd.c            |  27 +++++++---
 gdb/python/py-auto-load.c |   2 +-
 gdb/python/py-cmd.c       |   8 +--
 gdb/python/py-param.c     |   2 +-
 gdb/remote.c              |   2 +-
 gdb/symtab.c              |  52 +++++++++++---------
 gdb/symtab.h              |  20 +++++---
 gdb/top.c                 |   8 +--
 gdb/tracepoint.c          | 122 ++++++++++++++++++++++------------------------
 gdb/tracepoint.h          |   4 +-
 gdb/valprint.h            |   6 ++-
 gdb/value.c               |   2 +-
 32 files changed, 305 insertions(+), 256 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 1e5c55e..43d6e3c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5807,10 +5807,10 @@ symbol_completion_add (VEC(char_ptr) **sv,
 struct add_partial_datum
 {
   VEC(char_ptr) **completions;
-  char *text;
+  const char *text;
   int text_len;
-  char *text0;
-  char *word;
+  const char *text0;
+  const char *word;
   int wild_match;
   int encoded;
 };
@@ -5829,7 +5829,8 @@ ada_expand_partial_symbol_name (const char *name, void *user_data)
    the entire command on which completion is made.  */
 
 static VEC (char_ptr) *
-ada_make_symbol_completion_list (char *text0, char *word, enum type_code code)
+ada_make_symbol_completion_list (const char *text0, const char *word,
+				 enum type_code code)
 {
   char *text;
   int text_len;
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 74824d3..93c87e7 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -2603,7 +2603,7 @@ gen_printf (CORE_ADDR scope, struct gdbarch *gdbarch,
 }
 
 static void
-agent_eval_command_one (char *exp, int eval, CORE_ADDR pc)
+agent_eval_command_one (const char *exp, int eval, CORE_ADDR pc)
 {
   struct cleanup *old_chain = 0;
   struct expression *expr;
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index e5ee4d0..0ff4683 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -991,12 +991,13 @@ set_breakpoint_condition (struct breakpoint *b, char *exp,
 /* Completion for the "condition" command.  */
 
 static VEC (char_ptr) *
-condition_completer (struct cmd_list_element *cmd, char *text, char *word)
+condition_completer (struct cmd_list_element *cmd,
+		     const char *text, const char *word)
 {
-  char *space;
+  const char *space;
 
-  text = skip_spaces (text);
-  space = skip_to_space (text);
+  text = skip_spaces_const (text);
+  space = skip_to_space_const (text);
   if (*space == '\0')
     {
       int len;
@@ -1041,7 +1042,7 @@ condition_completer (struct cmd_list_element *cmd, char *text, char *word)
     }
 
   /* We're completing the expression part.  */
-  text = skip_spaces (space);
+  text = skip_spaces_const (space);
   return expression_completer (cmd, text, word);
 }
 
@@ -1264,7 +1265,7 @@ check_tracepoint_command (char *line, void *closure)
 {
   struct breakpoint *b = closure;
 
-  validate_actionline (&line, b);
+  validate_actionline (line, b);
 }
 
 /* A structure used to pass information through
@@ -15084,7 +15085,7 @@ catching_syscall_number (int syscall_number)
 /* Complete syscall names.  Used by "catch syscall".  */
 static VEC (char_ptr) *
 catch_syscall_completer (struct cmd_list_element *cmd,
-                         char *text, char *word)
+                         const char *text, const char *word)
 {
   const char **list = get_syscall_names ();
   VEC (char_ptr) *retlist
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 77da738..c05f77f 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1213,7 +1213,7 @@ show_user (char *args, int from_tty)
 
   if (args)
     {
-      char *comname = args;
+      const char *comname = args;
 
       c = lookup_cmd (&comname, cmdlist, "", 0, 1);
       /* c->user_commands would be NULL if it's a python command.  */
@@ -1291,7 +1291,7 @@ argv_to_dyn_string (char **argv, int n)
    Return TRUE if COMMAND exists, unambiguously.  Otherwise FALSE.  */
 
 static int
-valid_command_p (char *command)
+valid_command_p (const char *command)
 {
   struct cmd_list_element *c;
 
@@ -1400,7 +1400,7 @@ alias_command (char *args, int from_tty)
   else
     {
       dyn_string_t alias_prefix_dyn_string, command_prefix_dyn_string;
-      char *alias_prefix, *command_prefix;
+      const char *alias_prefix, *command_prefix;
       struct cmd_list_element *c_alias, *c_command;
 
       if (alias_argc != command_argc)
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index a8f7747..61a7b5a 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -34,16 +34,16 @@
 
 /* Prototypes for local functions.  */
 
-static void undef_cmd_error (char *, char *);
+static void undef_cmd_error (const char *, const char *);
 
-static struct cmd_list_element *delete_cmd (char *name,
+static struct cmd_list_element *delete_cmd (const char *name,
 					    struct cmd_list_element **list,
 					    struct cmd_list_element **prehook,
 					    struct cmd_list_element **prehookee,
 					    struct cmd_list_element **posthook,
 					    struct cmd_list_element **posthookee);
 
-static struct cmd_list_element *find_cmd (char *command,
+static struct cmd_list_element *find_cmd (const char *command,
 					  int len,
 					  struct cmd_list_element *clist,
 					  int ignore_help_classes,
@@ -189,7 +189,7 @@ set_cmd_completer (struct cmd_list_element *cmd, completer_ftype *completer)
    of *LIST).  */
 
 struct cmd_list_element *
-add_cmd (char *name, enum command_class class, void (*fun) (char *, int),
+add_cmd (const char *name, enum command_class class, void (*fun) (char *, int),
 	 char *doc, struct cmd_list_element **list)
 {
   struct cmd_list_element *c
@@ -278,18 +278,15 @@ deprecate_cmd (struct cmd_list_element *cmd, char *replacement)
 }
 
 struct cmd_list_element *
-add_alias_cmd (char *name, char *oldname, enum command_class class,
+add_alias_cmd (const char *name, const char *oldname, enum command_class class,
 	       int abbrev_flag, struct cmd_list_element **list)
 {
-  /* Must do this since lookup_cmd tries to side-effect its first
-     arg.  */
-  char *copied_name;
+  const char *tmp;
   struct cmd_list_element *old;
   struct cmd_list_element *c;
 
-  copied_name = (char *) alloca (strlen (oldname) + 1);
-  strcpy (copied_name, oldname);
-  old = lookup_cmd (&copied_name, *list, "", 1, 1);
+  tmp = oldname;
+  old = lookup_cmd (&tmp, *list, "", 1, 1);
 
   if (old == 0)
     {
@@ -333,7 +330,7 @@ add_alias_cmd (char *name, char *oldname, enum command_class class,
    containing that list.  */
 
 struct cmd_list_element *
-add_prefix_cmd (char *name, enum command_class class,
+add_prefix_cmd (const char *name, enum command_class class,
 		void (*fun) (char *, int),
 		char *doc, struct cmd_list_element **prefixlist,
 		char *prefixname, int allow_unknown,
@@ -361,7 +358,7 @@ add_prefix_cmd (char *name, enum command_class class,
 /* Like add_prefix_cmd but sets the abbrev_flag on the new command.  */
 
 struct cmd_list_element *
-add_abbrev_prefix_cmd (char *name, enum command_class class,
+add_abbrev_prefix_cmd (const char *name, enum command_class class,
 		       void (*fun) (char *, int), char *doc,
 		       struct cmd_list_element **prefixlist, char *prefixname,
 		       int allow_unknown, struct cmd_list_element **list)
@@ -398,7 +395,7 @@ empty_sfunc (char *args, int from_tty, struct cmd_list_element *c)
    DOC is the documentation string.  */
 
 static struct cmd_list_element *
-add_set_or_show_cmd (char *name,
+add_set_or_show_cmd (const char *name,
 		     enum cmd_types type,
 		     enum command_class class,
 		     var_types var_type,
@@ -428,7 +425,7 @@ add_set_or_show_cmd (char *name,
    structures.  */
 
 static void
-add_setshow_cmd_full (char *name,
+add_setshow_cmd_full (const char *name,
 		      enum command_class class,
 		      var_types var_type, void *var,
 		      const char *set_doc, const char *show_doc,
@@ -481,7 +478,7 @@ add_setshow_cmd_full (char *name,
    which will contain the matching string (from ENUMLIST).  */
 
 void
-add_setshow_enum_cmd (char *name,
+add_setshow_enum_cmd (const char *name,
 		      enum command_class class,
 		      const char *const *enumlist,
 		      const char **var,
@@ -510,7 +507,7 @@ const char * const auto_boolean_enums[] = { "on", "off", "auto", NULL };
    variable which will contain the value.  DOC is the documentation
    string.  FUNC is the corresponding callback.  */
 void
-add_setshow_auto_boolean_cmd (char *name,
+add_setshow_auto_boolean_cmd (const char *name,
 			      enum command_class class,
 			      enum auto_boolean *var,
 			      const char *set_doc, const char *show_doc,
@@ -535,7 +532,7 @@ add_setshow_auto_boolean_cmd (char *name,
    add_cmd.  VAR is address of the variable which will contain the
    value.  SET_DOC and SHOW_DOC are the documentation strings.  */
 void
-add_setshow_boolean_cmd (char *name, enum command_class class, int *var,
+add_setshow_boolean_cmd (const char *name, enum command_class class, int *var,
 			 const char *set_doc, const char *show_doc,
 			 const char *help_doc,
 			 cmd_sfunc_ftype *set_func,
@@ -557,7 +554,7 @@ add_setshow_boolean_cmd (char *name, enum command_class class, int *var,
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  */
 void
-add_setshow_filename_cmd (char *name, enum command_class class,
+add_setshow_filename_cmd (const char *name, enum command_class class,
 			  char **var,
 			  const char *set_doc, const char *show_doc,
 			  const char *help_doc,
@@ -579,7 +576,7 @@ add_setshow_filename_cmd (char *name, enum command_class class,
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  */
 void
-add_setshow_string_cmd (char *name, enum command_class class,
+add_setshow_string_cmd (const char *name, enum command_class class,
 			char **var,
 			const char *set_doc, const char *show_doc,
 			const char *help_doc,
@@ -598,7 +595,7 @@ add_setshow_string_cmd (char *name, enum command_class class,
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  */
 struct cmd_list_element *
-add_setshow_string_noescape_cmd (char *name, enum command_class class,
+add_setshow_string_noescape_cmd (const char *name, enum command_class class,
 				 char **var,
 				 const char *set_doc, const char *show_doc,
 				 const char *help_doc,
@@ -620,7 +617,7 @@ add_setshow_string_noescape_cmd (char *name, enum command_class class,
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  */
 void
-add_setshow_optional_filename_cmd (char *name, enum command_class class,
+add_setshow_optional_filename_cmd (const char *name, enum command_class class,
 				   char **var,
 				   const char *set_doc, const char *show_doc,
 				   const char *help_doc,
@@ -647,7 +644,7 @@ add_setshow_optional_filename_cmd (char *name, enum command_class class,
    value.  SET_DOC and SHOW_DOC are the documentation strings.  This
    function is only used in Python API.  Please don't use it elsewhere.  */
 void
-add_setshow_integer_cmd (char *name, enum command_class class,
+add_setshow_integer_cmd (const char *name, enum command_class class,
 			 int *var,
 			 const char *set_doc, const char *show_doc,
 			 const char *help_doc,
@@ -668,7 +665,7 @@ add_setshow_integer_cmd (char *name, enum command_class class,
    add_cmd.  VAR is address of the variable which will contain the
    value.  SET_DOC and SHOW_DOC are the documentation strings.  */
 void
-add_setshow_uinteger_cmd (char *name, enum command_class class,
+add_setshow_uinteger_cmd (const char *name, enum command_class class,
 			  unsigned int *var,
 			  const char *set_doc, const char *show_doc,
 			  const char *help_doc,
@@ -689,7 +686,7 @@ add_setshow_uinteger_cmd (char *name, enum command_class class,
    add_cmd.  VAR is address of the variable which will contain the
    value.  SET_DOC and SHOW_DOC are the documentation strings.  */
 void
-add_setshow_zinteger_cmd (char *name, enum command_class class,
+add_setshow_zinteger_cmd (const char *name, enum command_class class,
 			  int *var,
 			  const char *set_doc, const char *show_doc,
 			  const char *help_doc,
@@ -706,7 +703,7 @@ add_setshow_zinteger_cmd (char *name, enum command_class class,
 }
 
 void
-add_setshow_zuinteger_unlimited_cmd (char *name,
+add_setshow_zuinteger_unlimited_cmd (const char *name,
 				     enum command_class class,
 				     int *var,
 				     const char *set_doc,
@@ -729,7 +726,7 @@ add_setshow_zuinteger_unlimited_cmd (char *name,
    add_cmd.  VAR is address of the variable which will contain the
    value.  SET_DOC and SHOW_DOC are the documentation strings.  */
 void
-add_setshow_zuinteger_cmd (char *name, enum command_class class,
+add_setshow_zuinteger_cmd (const char *name, enum command_class class,
 			   unsigned int *var,
 			   const char *set_doc, const char *show_doc,
 			   const char *help_doc,
@@ -753,7 +750,7 @@ add_setshow_zuinteger_cmd (char *name, enum command_class class,
    set to NULL.  */
 
 static struct cmd_list_element *
-delete_cmd (char *name, struct cmd_list_element **list,
+delete_cmd (const char *name, struct cmd_list_element **list,
 	    struct cmd_list_element **prehook,
 	    struct cmd_list_element **prehookee,
 	    struct cmd_list_element **posthook,
@@ -823,7 +820,7 @@ delete_cmd (char *name, struct cmd_list_element **list,
 /* Add an element to the list of info subcommands.  */
 
 struct cmd_list_element *
-add_info (char *name, void (*fun) (char *, int), char *doc)
+add_info (const char *name, void (*fun) (char *, int), char *doc)
 {
   return add_cmd (name, no_class, fun, doc, &infolist);
 }
@@ -831,7 +828,7 @@ add_info (char *name, void (*fun) (char *, int), char *doc)
 /* Add an alias to the list of info subcommands.  */
 
 struct cmd_list_element *
-add_info_alias (char *name, char *oldname, int abbrev_flag)
+add_info_alias (const char *name, char *oldname, int abbrev_flag)
 {
   return add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
 }
@@ -839,7 +836,7 @@ add_info_alias (char *name, char *oldname, int abbrev_flag)
 /* Add an element to the list of commands.  */
 
 struct cmd_list_element *
-add_com (char *name, enum command_class class, void (*fun) (char *, int),
+add_com (const char *name, enum command_class class, void (*fun) (char *, int),
 	 char *doc)
 {
   return add_cmd (name, class, fun, doc, &cmdlist);
@@ -848,7 +845,7 @@ add_com (char *name, enum command_class class, void (*fun) (char *, int),
 /* Add an alias or abbreviation command to the list of commands.  */
 
 struct cmd_list_element *
-add_com_alias (char *name, char *oldname, enum command_class class,
+add_com_alias (const char *name, const char *oldname, enum command_class class,
 	       int abbrev_flag)
 {
   return add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
@@ -914,9 +911,10 @@ apropos_cmd (struct ui_file *stream,
    help_list.  */
 
 void
-help_cmd (char *command, struct ui_file *stream)
+help_cmd (char *arg, struct ui_file *stream)
 {
   struct cmd_list_element *c;
+  const char *command = arg;
 
   if (!command)
     {
@@ -1184,7 +1182,7 @@ help_cmd_list (struct cmd_list_element *list, enum command_class class,
    found in nfound.  */
 
 static struct cmd_list_element *
-find_cmd (char *command, int len, struct cmd_list_element *clist,
+find_cmd (const char *command, int len, struct cmd_list_element *clist,
 	  int ignore_help_classes, int *nfound)
 {
   struct cmd_list_element *found, *c;
@@ -1305,13 +1303,13 @@ valid_user_defined_cmd_name_p (const char *name)
    the struct cmd_list_element is NULL).  */
 
 struct cmd_list_element *
-lookup_cmd_1 (char **text, struct cmd_list_element *clist,
+lookup_cmd_1 (const char **text, struct cmd_list_element *clist,
 	      struct cmd_list_element **result_list, int ignore_help_classes)
 {
   char *command;
   int len, tmp, nfound;
   struct cmd_list_element *found, *c;
-  char *line = *text;
+  const char *line = *text;
 
   while (**text == ' ' || **text == '\t')
     (*text)++;
@@ -1376,7 +1374,7 @@ lookup_cmd_1 (char **text, struct cmd_list_element *clist,
        flags.  */
       
       if (found->flags & DEPRECATED_WARN_USER)
-	deprecated_cmd_warning (&line);
+	deprecated_cmd_warning (line);
       found = found->cmd_pointer;
     }
   /* If we found a prefix command, keep looking.  */
@@ -1423,7 +1421,7 @@ lookup_cmd_1 (char **text, struct cmd_list_element *clist,
 /* All this hair to move the space to the front of cmdtype */
 
 static void
-undef_cmd_error (char *cmdtype, char *q)
+undef_cmd_error (const char *cmdtype, const char *q)
 {
   error (_("Undefined %scommand: \"%s\".  Try \"help%s%.*s\"."),
 	 cmdtype,
@@ -1448,7 +1446,7 @@ undef_cmd_error (char *cmdtype, char *q)
    the function field of the struct cmd_list_element is 0).  */
 
 struct cmd_list_element *
-lookup_cmd (char **line, struct cmd_list_element *list, char *cmdtype,
+lookup_cmd (const char **line, struct cmd_list_element *list, char *cmdtype,
 	    int allow_unknown, int ignore_help_classes)
 {
   struct cmd_list_element *last_list = 0;
@@ -1544,14 +1542,14 @@ lookup_cmd (char **line, struct cmd_list_element *list, char *cmdtype,
   return 0;
 }
 
-/* We are here presumably because an alias or command in *TEXT is
+/* We are here presumably because an alias or command in TEXT is
    deprecated and a warning message should be generated.  This
-   function decodes *TEXT and potentially generates a warning message
+   function decodes TEXT and potentially generates a warning message
    as outlined below.
    
    Example for 'set endian big' which has a fictitious alias 'seb'.
    
-   If alias wasn't used in *TEXT, and the command is deprecated:
+   If alias wasn't used in TEXT, and the command is deprecated:
    "warning: 'set endian big' is deprecated." 
    
    If alias was used, and only the alias is deprecated:
@@ -1567,13 +1565,13 @@ lookup_cmd (char **line, struct cmd_list_element *list, char *cmdtype,
    
 */
 void
-deprecated_cmd_warning (char **text)
+deprecated_cmd_warning (const char *text)
 {
   struct cmd_list_element *alias = NULL;
   struct cmd_list_element *prefix_cmd = NULL;
   struct cmd_list_element *cmd = NULL;
 
-  if (!lookup_cmd_composition (*text, &alias, &prefix_cmd, &cmd))
+  if (!lookup_cmd_composition (text, &alias, &prefix_cmd, &cmd))
     /* Return if text doesn't evaluate to a command.  */
     return;
 
@@ -1641,7 +1639,7 @@ deprecated_cmd_warning (char **text)
    
 */
 int
-lookup_cmd_composition (char *text,
+lookup_cmd_composition (const char *text,
                       struct cmd_list_element **alias,
                       struct cmd_list_element **prefix_cmd, 
                       struct cmd_list_element **cmd)
@@ -1738,7 +1736,8 @@ lookup_cmd_composition (char *text,
    "oobar"; if WORD is "baz/foo", return "baz/foobar".  */
 
 VEC (char_ptr) *
-complete_on_cmdlist (struct cmd_list_element *list, char *text, char *word,
+complete_on_cmdlist (struct cmd_list_element *list,
+		     const char *text, const char *word,
 		     int ignore_help_classes)
 {
   struct cmd_list_element *ptr;
@@ -1808,8 +1807,7 @@ complete_on_cmdlist (struct cmd_list_element *list, char *text, char *word,
 
 VEC (char_ptr) *
 complete_on_enum (const char *const *enumlist,
-		  char *text,
-		  char *word)
+		  const char *text, const char *word)
 {
   VEC (char_ptr) *matchlist = NULL;
   int textlen = strlen (text);
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index 47e3a3b..bf4dd1d 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -59,7 +59,7 @@ struct cmd_list_element
     struct cmd_list_element *next;
 
     /* Name of this command.  */
-    char *name;
+    const char *name;
 
     /* Command class; class values are chosen by application program.  */
     enum command_class class;
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index a968866..3b24799 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1416,7 +1416,8 @@ validate_comname (char **comname)
   if (last_word != *comname)
     {
       struct cmd_list_element *c;
-      char saved_char, *tem = *comname;
+      char saved_char;
+      const char *tem = *comname;
 
       /* Separate the prefix and the command.  */
       saved_char = last_word[-1];
@@ -1461,6 +1462,7 @@ define_command (char *comname, int from_tty)
   struct command_line *cmds;
   struct cmd_list_element *c, *newc, *hookc = 0, **list;
   char *tem, *comfull;
+  const char *tem_c;
   char tmpbuf[MAX_TMPBUF];
   int  hook_type      = CMD_NO_HOOK;
   int  hook_name_size = 0;
@@ -1474,8 +1476,8 @@ define_command (char *comname, int from_tty)
   list = validate_comname (&comname);
 
   /* Look it up, and verify that we got an exact match.  */
-  tem = comname;
-  c = lookup_cmd (&tem, *list, "", -1, 1);
+  tem_c = comname;
+  c = lookup_cmd (&tem_c, *list, "", -1, 1);
   if (c && strcmp (comname, c->name) != 0)
     c = 0;
 
@@ -1509,8 +1511,8 @@ define_command (char *comname, int from_tty)
   if (hook_type != CMD_NO_HOOK)
     {
       /* Look up cmd it hooks, and verify that we got an exact match.  */
-      tem = comname + hook_name_size;
-      hookc = lookup_cmd (&tem, *list, "", -1, 0);
+      tem_c = comname + hook_name_size;
+      hookc = lookup_cmd (&tem_c, *list, "", -1, 0);
       if (hookc && strcmp (comname + hook_name_size, hookc->name) != 0)
 	hookc = 0;
       if (!hookc)
@@ -1570,7 +1572,8 @@ document_command (char *comname, int from_tty)
 {
   struct command_line *doclines;
   struct cmd_list_element *c, **list;
-  char *tem, *comfull;
+  const char *tem;
+  char *comfull;
   char tmpbuf[128];
 
   comfull = comname;
@@ -1676,7 +1679,7 @@ script_from_file (FILE *stream, const char *file)
    (recursively).  PREFIX and NAME combined are the name of the
    current command.  */
 void
-show_user_1 (struct cmd_list_element *c, char *prefix, char *name,
+show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name,
 	     struct ui_file *stream)
 {
   struct command_line *cmdlines;
diff --git a/gdb/cli/cli-script.h b/gdb/cli/cli-script.h
index d02cb36..31db811 100644
--- a/gdb/cli/cli-script.h
+++ b/gdb/cli/cli-script.h
@@ -25,8 +25,10 @@ struct cmd_list_element;
 
 extern void script_from_file (FILE *stream, const char *file);
 
-extern void show_user_1 (struct cmd_list_element *c, char *prefix,
-			 char *name, struct ui_file *stream);
+extern void show_user_1 (struct cmd_list_element *c,
+			 const char *prefix,
+			 const char *name,
+			 struct ui_file *stream);
 
 /* Exported to gdb/breakpoint.c */
 
diff --git a/gdb/command.h b/gdb/command.h
index a25fe04..81edc43 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -119,22 +119,22 @@ struct cmd_list_element;
 
 extern int valid_user_defined_cmd_name_p (const char *name);
 
-extern struct cmd_list_element *add_cmd (char *, enum command_class,
+extern struct cmd_list_element *add_cmd (const char *, enum command_class,
 					 void (*fun) (char *, int), char *,
 					 struct cmd_list_element **);
 
-extern struct cmd_list_element *add_alias_cmd (char *, char *,
+extern struct cmd_list_element *add_alias_cmd (const char *, const char *,
 					       enum command_class, int,
 					       struct cmd_list_element **);
 
-extern struct cmd_list_element *add_prefix_cmd (char *, enum command_class,
+extern struct cmd_list_element *add_prefix_cmd (const char *, enum command_class,
 						void (*fun) (char *, int),
 						char *,
 						struct cmd_list_element **,
 						char *, int,
 						struct cmd_list_element **);
 
-extern struct cmd_list_element *add_abbrev_prefix_cmd (char *,
+extern struct cmd_list_element *add_abbrev_prefix_cmd (const char *,
 						       enum command_class,
 						       void (*fun) (char *,
 								    int),
@@ -156,7 +156,7 @@ extern void set_cmd_sfunc (struct cmd_list_element *cmd,
 			   cmd_sfunc_ftype *sfunc);
 
 typedef VEC (char_ptr) *completer_ftype (struct cmd_list_element *,
-					 char *, char *);
+					 const char *, const char *);
 
 extern void set_cmd_completer (struct cmd_list_element *, completer_ftype *);
 
@@ -183,11 +183,11 @@ extern enum cmd_types cmd_type (struct cmd_list_element *cmd);
 /* Flag for an ambiguous cmd_list result.  */
 #define CMD_LIST_AMBIGUOUS ((struct cmd_list_element *) -1)
 
-extern struct cmd_list_element *lookup_cmd (char **,
+extern struct cmd_list_element *lookup_cmd (const char **,
 					    struct cmd_list_element *, char *,
 					    int, int);
 
-extern struct cmd_list_element *lookup_cmd_1 (char **,
+extern struct cmd_list_element *lookup_cmd_1 (const char **,
 					      struct cmd_list_element *,
 					      struct cmd_list_element **,
 					      int);
@@ -195,31 +195,31 @@ extern struct cmd_list_element *lookup_cmd_1 (char **,
 extern struct cmd_list_element *deprecate_cmd (struct cmd_list_element *,
 					       char * );
 
-extern void deprecated_cmd_warning (char **);
+extern void deprecated_cmd_warning (const char *);
 
-extern int lookup_cmd_composition (char *text,
+extern int lookup_cmd_composition (const char *text,
 				   struct cmd_list_element **alias,
 				   struct cmd_list_element **prefix_cmd,
 				   struct cmd_list_element **cmd);
 
-extern struct cmd_list_element *add_com (char *, enum command_class,
+extern struct cmd_list_element *add_com (const char *, enum command_class,
 					 void (*fun) (char *, int),
 					 char *);
 
-extern struct cmd_list_element *add_com_alias (char *, char *,
+extern struct cmd_list_element *add_com_alias (const char *, const char *,
 					       enum command_class, int);
 
-extern struct cmd_list_element *add_info (char *,
+extern struct cmd_list_element *add_info (const char *,
 					  void (*fun) (char *, int),
 					  char *);
 
-extern struct cmd_list_element *add_info_alias (char *, char *, int);
+extern struct cmd_list_element *add_info_alias (const char *, char *, int);
 
 extern VEC (char_ptr) *complete_on_cmdlist (struct cmd_list_element *,
-					    char *, char *, int);
+					    const char *, const char *, int);
 
 extern VEC (char_ptr) *complete_on_enum (const char *const *enumlist,
-					 char *, char *);
+					 const char *, const char *);
 
 /* Functions that implement commands about CLI commands.  */
 
@@ -237,7 +237,7 @@ typedef void (show_value_ftype) (struct ui_file *file,
    instead print the value out directly.  */
 extern show_value_ftype deprecated_show_value_hack;
 
-extern void add_setshow_enum_cmd (char *name,
+extern void add_setshow_enum_cmd (const char *name,
 				  enum command_class class,
 				  const char *const *enumlist,
 				  const char **var,
@@ -249,7 +249,7 @@ extern void add_setshow_enum_cmd (char *name,
 				  struct cmd_list_element **set_list,
 				  struct cmd_list_element **show_list);
 
-extern void add_setshow_auto_boolean_cmd (char *name,
+extern void add_setshow_auto_boolean_cmd (const char *name,
 					  enum command_class class,
 					  enum auto_boolean *var,
 					  const char *set_doc,
@@ -260,7 +260,7 @@ extern void add_setshow_auto_boolean_cmd (char *name,
 					  struct cmd_list_element **set_list,
 					  struct cmd_list_element **show_list);
 
-extern void add_setshow_boolean_cmd (char *name,
+extern void add_setshow_boolean_cmd (const char *name,
 				     enum command_class class,
 				     int *var,
 				     const char *set_doc, const char *show_doc,
@@ -270,7 +270,7 @@ extern void add_setshow_boolean_cmd (char *name,
 				     struct cmd_list_element **set_list,
 				     struct cmd_list_element **show_list);
 
-extern void add_setshow_filename_cmd (char *name,
+extern void add_setshow_filename_cmd (const char *name,
 				      enum command_class class,
 				      char **var,
 				      const char *set_doc,
@@ -281,7 +281,7 @@ extern void add_setshow_filename_cmd (char *name,
 				      struct cmd_list_element **set_list,
 				      struct cmd_list_element **show_list);
 
-extern void add_setshow_string_cmd (char *name,
+extern void add_setshow_string_cmd (const char *name,
 				    enum command_class class,
 				    char **var,
 				    const char *set_doc,
@@ -293,7 +293,7 @@ extern void add_setshow_string_cmd (char *name,
 				    struct cmd_list_element **show_list);
 
 extern struct cmd_list_element *add_setshow_string_noescape_cmd
-		      (char *name,
+		      (const char *name,
 		       enum command_class class,
 		       char **var,
 		       const char *set_doc,
@@ -304,7 +304,7 @@ extern struct cmd_list_element *add_setshow_string_noescape_cmd
 		       struct cmd_list_element **set_list,
 		       struct cmd_list_element **show_list);
 
-extern void add_setshow_optional_filename_cmd (char *name,
+extern void add_setshow_optional_filename_cmd (const char *name,
 					       enum command_class class,
 					       char **var,
 					       const char *set_doc,
@@ -315,7 +315,7 @@ extern void add_setshow_optional_filename_cmd (char *name,
 					       struct cmd_list_element **set_list,
 					       struct cmd_list_element **show_list);
 
-extern void add_setshow_integer_cmd (char *name,
+extern void add_setshow_integer_cmd (const char *name,
 				     enum command_class class,
 				     int *var,
 				     const char *set_doc,
@@ -326,7 +326,7 @@ extern void add_setshow_integer_cmd (char *name,
 				     struct cmd_list_element **set_list,
 				     struct cmd_list_element **show_list);
 
-extern void add_setshow_uinteger_cmd (char *name,
+extern void add_setshow_uinteger_cmd (const char *name,
 				      enum command_class class,
 				      unsigned int *var,
 				      const char *set_doc,
@@ -337,7 +337,7 @@ extern void add_setshow_uinteger_cmd (char *name,
 				      struct cmd_list_element **set_list,
 				      struct cmd_list_element **show_list);
 
-extern void add_setshow_zinteger_cmd (char *name,
+extern void add_setshow_zinteger_cmd (const char *name,
 				      enum command_class class,
 				      int *var,
 				      const char *set_doc,
@@ -348,7 +348,7 @@ extern void add_setshow_zinteger_cmd (char *name,
 				      struct cmd_list_element **set_list,
 				      struct cmd_list_element **show_list);
 
-extern void add_setshow_zuinteger_cmd (char *name,
+extern void add_setshow_zuinteger_cmd (const char *name,
 				       enum command_class class,
 				       unsigned int *var,
 				       const char *set_doc,
@@ -360,7 +360,7 @@ extern void add_setshow_zuinteger_cmd (char *name,
 				       struct cmd_list_element **show_list);
 
 extern void
-  add_setshow_zuinteger_unlimited_cmd (char *name,
+  add_setshow_zuinteger_unlimited_cmd (const char *name,
 				       enum command_class class,
 				       int *var,
 				       const char *set_doc,
diff --git a/gdb/completer.c b/gdb/completer.c
index 3b14fc9..e132651 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -107,7 +107,7 @@ readline_line_completion_function (const char *text, int matches)
    symbols but don't want to complete on anything else either.  */
 VEC (char_ptr) *
 noop_completer (struct cmd_list_element *ignore, 
-		char *text, char *prefix)
+		const char *text, const char *prefix)
 {
   return NULL;
 }
@@ -115,7 +115,7 @@ noop_completer (struct cmd_list_element *ignore,
 /* Complete on filenames.  */
 VEC (char_ptr) *
 filename_completer (struct cmd_list_element *ignore, 
-		    char *text, char *word)
+		    const char *text, const char *word)
 {
   int subsequent_name;
   VEC (char_ptr) *return_val = NULL;
@@ -184,19 +184,19 @@ filename_completer (struct cmd_list_element *ignore,
 
 VEC (char_ptr) *
 location_completer (struct cmd_list_element *ignore, 
-		    char *text, char *word)
+		    const char *text, const char *word)
 {
   int n_syms, n_files, ix;
   VEC (char_ptr) *fn_list = NULL;
   VEC (char_ptr) *list = NULL;
-  char *p;
+  const char *p;
   int quote_found = 0;
   int quoted = *text == '\'' || *text == '"';
   int quote_char = '\0';
-  char *colon = NULL;
+  const char *colon = NULL;
   char *file_to_match = NULL;
-  char *symbol_start = text;
-  char *orig_text = text;
+  const char *symbol_start = text;
+  const char *orig_text = text;
   size_t text_len;
 
   /* Do we have an unquoted colon, as in "break foo.c:bar"?  */
@@ -285,8 +285,10 @@ location_completer (struct cmd_list_element *ignore,
     }
   else
     {
-      for (ix = 0; VEC_iterate (char_ptr, fn_list, ix, p); ++ix)
-	VEC_safe_push (char_ptr, list, p);
+      char *fn;
+
+      for (ix = 0; VEC_iterate (char_ptr, fn_list, ix, fn); ++ix)
+	VEC_safe_push (char_ptr, list, fn);
       VEC_free (char_ptr, fn_list);
     }
 
@@ -296,6 +298,8 @@ location_completer (struct cmd_list_element *ignore,
     }
   else if (n_files)
     {
+      char *fn;
+
       /* If we only have file names as possible completion, we should
 	 bring them in sync with what rl_complete expects.  The
 	 problem is that if the user types "break /foo/b TAB", and the
@@ -311,10 +315,10 @@ location_completer (struct cmd_list_element *ignore,
 	 completion, because rl_complete will prepend "/foo/" to each
 	 candidate completion.  The loop below removes that leading
 	 part.  */
-      for (ix = 0; VEC_iterate (char_ptr, list, ix, p); ++ix)
+      for (ix = 0; VEC_iterate (char_ptr, list, ix, fn); ++ix)
 	{
-	  memmove (p, p + (word - text),
-		   strlen (p) + 1 - (word - text));
+	  memmove (fn, fn + (word - text),
+		   strlen (fn) + 1 - (word - text));
 	}
     }
   else if (!n_syms)
@@ -385,10 +389,11 @@ add_struct_fields (struct type *type, VEC (char_ptr) **output,
    field names.  */
 VEC (char_ptr) *
 expression_completer (struct cmd_list_element *ignore, 
-		      char *text, char *word)
+		      const char *text, const char *word)
 {
   struct type *type = NULL;
-  char *fieldname, *p;
+  char *fieldname;
+  const char *p;
   volatile struct gdb_exception except;
   enum type_code code = TYPE_CODE_UNDEF;
 
@@ -506,11 +511,12 @@ complete_line_internal_reason;
 
 static VEC (char_ptr) *
 complete_line_internal (const char *text, 
-			char *line_buffer, int point,
+			const char *line_buffer, int point,
 			complete_line_internal_reason reason)
 {
   VEC (char_ptr) *list = NULL;
-  char *tmp_command, *p;
+  char *tmp_command;
+  const char *p;
   int ignore_help_classes;
   /* Pointer within tmp_command which corresponds to text.  */
   char *word;
@@ -567,7 +573,7 @@ complete_line_internal (const char *text,
     }
   else if (c == CMD_LIST_AMBIGUOUS)
     {
-      char *q;
+      const char *q;
 
       /* lookup_cmd_1 advances p up to the first ambiguous thing, but
 	 doesn't advance over that thing itself.  Do so now.  */
@@ -682,7 +688,7 @@ complete_line_internal (const char *text,
 		 complete on the command itself, e.g. "p" which is a
 		 command itself but also can complete to "print", "ptype"
 		 etc.  */
-	      char *q;
+	      const char *q;
 
 	      /* Find the command we are completing on.  */
 	      q = p;
@@ -775,7 +781,7 @@ complete_line (const char *text, char *line_buffer, int point)
 /* Complete on command names.  Used by "help".  */
 VEC (char_ptr) *
 command_completer (struct cmd_list_element *ignore, 
-		   char *text, char *word)
+		   const char *text, const char *word)
 {
   return complete_line_internal (word, text, 
 				 strlen (text), handle_help);
@@ -785,7 +791,7 @@ command_completer (struct cmd_list_element *ignore,
 
 VEC (char_ptr) *
 signal_completer (struct cmd_list_element *ignore,
-		  char *text, char *word)
+		  const char *text, const char *word)
 {
   VEC (char_ptr) *return_val = NULL;
   size_t len = strlen (word);
diff --git a/gdb/completer.h b/gdb/completer.h
index f7fea60..d6090f4 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -27,22 +27,22 @@ extern char *readline_line_completion_function (const char *text,
 						int matches);
 
 extern VEC (char_ptr) *noop_completer (struct cmd_list_element *,
-				       char *, char *);
+				       const char *, const char *);
 
 extern VEC (char_ptr) *filename_completer (struct cmd_list_element *,
-					   char *, char *);
+					   const char *, const char *);
 
 extern VEC (char_ptr) *expression_completer (struct cmd_list_element *,
-					     char *, char *);
+					     const char *, const char *);
 
 extern VEC (char_ptr) *location_completer (struct cmd_list_element *,
-					   char *, char *);
+					   const char *, const char *);
 
 extern VEC (char_ptr) *command_completer (struct cmd_list_element *,
-					  char *, char *);
+					  const char *, const char *);
 
 extern VEC (char_ptr) *signal_completer (struct cmd_list_element *,
-					 char *, char *);
+					 const char *, const char *);
 
 extern char *get_gdb_completer_quote_characters (void);
 
diff --git a/gdb/corefile.c b/gdb/corefile.c
index 9c795b8..a86f4b3 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -434,7 +434,8 @@ set_gnutarget_command (char *ignore, int from_tty,
 /* A completion function for "set gnutarget".  */
 
 static VEC (char_ptr) *
-complete_set_gnutarget (struct cmd_list_element *cmd, char *text, char *word)
+complete_set_gnutarget (struct cmd_list_element *cmd,
+			const char *text, const char *word)
 {
   static const char **bfd_targets;
 
diff --git a/gdb/cp-abi.c b/gdb/cp-abi.c
index 366ba30..8e9d545 100644
--- a/gdb/cp-abi.c
+++ b/gdb/cp-abi.c
@@ -318,7 +318,7 @@ set_cp_abi_cmd (char *args, int from_tty)
 
 static VEC (char_ptr) *
 cp_abi_completer (struct cmd_list_element *ignore,
-		  char *text, char *word)
+		  const char *text, const char *word)
 {
   static const char **cp_abi_names;
 
diff --git a/gdb/expression.h b/gdb/expression.h
index eea47dc..6b96b12 100644
--- a/gdb/expression.h
+++ b/gdb/expression.h
@@ -97,7 +97,7 @@ struct expression
 
 extern struct expression *parse_expression (const char *);
 
-extern struct type *parse_expression_for_completion (char *, char **,
+extern struct type *parse_expression_for_completion (const char *, char **,
 						     enum type_code *);
 
 extern struct expression *parse_exp_1 (const char **, CORE_ADDR pc,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 652da79..f40e98d 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -229,7 +229,8 @@ f_word_break_characters (void)
    class.  */
 
 static VEC (char_ptr) *
-f_make_symbol_completion_list (char *text, char *word, enum type_code code)
+f_make_symbol_completion_list (const char *text, const char *word,
+			       enum type_code code)
 {
   return default_make_symbol_completion_list_break_on (text, word, ":", code);
 }
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 866388f..0b40f22 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2938,7 +2938,7 @@ _initialize_infcmd (void)
 {
   static struct cmd_list_element *info_proc_cmdlist;
   struct cmd_list_element *c = NULL;
-  char *cmd_name;
+  const char *cmd_name;
 
   /* Add the filename of the terminal connected to inferior I/O.  */
   add_setshow_filename_cmd ("inferior-tty", class_run,
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 92874e2..7031ecc 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -6471,7 +6471,7 @@ Are you sure you want to change it? "),
 
 static VEC (char_ptr) *
 handle_completer (struct cmd_list_element *ignore,
-		  char *text, char *word)
+		  const char *text, const char *word)
 {
   VEC (char_ptr) *vec_signals, *vec_keywords, *return_val;
   static const char * const keywords[] =
diff --git a/gdb/interps.c b/gdb/interps.c
index 9ddbf6d..bd23118 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -456,7 +456,8 @@ interpreter_exec_cmd (char *args, int from_tty)
 
 /* List the possible interpreters which could complete the given text.  */
 static VEC (char_ptr) *
-interpreter_completer (struct cmd_list_element *ignore, char *text, char *word)
+interpreter_completer (struct cmd_list_element *ignore,
+		       const char *text, const char *word)
 {
   int textlen;
   VEC (char_ptr) *matches = NULL;
diff --git a/gdb/language.h b/gdb/language.h
index b191b36..e36da31 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -286,7 +286,8 @@ struct language_defn
        completion is being made.  If CODE is TYPE_CODE_UNDEF, then all
        symbols should be examined; otherwise, only STRUCT_DOMAIN
        symbols whose type has a code of CODE should be matched.  */
-    VEC (char_ptr) *(*la_make_symbol_completion_list) (char *text, char *word,
+    VEC (char_ptr) *(*la_make_symbol_completion_list) (const char *text,
+						       const char *word,
 						       enum type_code code);
 
     /* The per-architecture (OS/ABI) language information.  */
diff --git a/gdb/parse.c b/gdb/parse.c
index 4c84b2b..095d63d 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -120,9 +120,12 @@ static void free_funcalls (void *ignore);
 static int prefixify_subexp (struct expression *, struct expression *, int,
 			     int);
 
-static struct expression *parse_exp_in_context (char **, CORE_ADDR,
+static struct expression *parse_exp_in_context (const char **, CORE_ADDR,
 						const struct block *, int, 
 						int, int *);
+static struct expression *parse_exp_in_context_1 (char **, CORE_ADDR,
+						  const struct block *, int,
+						  int, int *);
 
 void _initialize_parse (void);
 
@@ -1128,12 +1131,21 @@ struct expression *
 parse_exp_1 (const char **stringptr, CORE_ADDR pc, const struct block *block,
 	     int comma)
 {
+  return parse_exp_in_context (stringptr, pc, block, comma, 0, NULL);
+}
+
+static struct expression *
+parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
+		      const struct block *block,
+		      int comma, int void_context_p, int *out_subexp)
+{
   struct expression *expr;
   char *const_hack = *stringptr ? xstrdup (*stringptr) : NULL;
   char *orig = const_hack;
   struct cleanup *back_to = make_cleanup (xfree, const_hack);
 
-  expr = parse_exp_in_context (&const_hack, pc, block, comma, 0, NULL);
+  expr = parse_exp_in_context_1 (&const_hack, pc, block, comma,
+				 void_context_p, out_subexp);
   (*stringptr) += const_hack - orig;
   do_cleanups (back_to);
   return expr;
@@ -1147,8 +1159,9 @@ parse_exp_1 (const char **stringptr, CORE_ADDR pc, const struct block *block,
    is left untouched.  */
 
 static struct expression *
-parse_exp_in_context (char **stringptr, CORE_ADDR pc, const struct block *block,
-		      int comma, int void_context_p, int *out_subexp)
+parse_exp_in_context_1 (char **stringptr, CORE_ADDR pc,
+			const struct block *block,
+			int comma, int void_context_p, int *out_subexp)
 {
   volatile struct gdb_exception except;
   struct cleanup *old_chain, *inner_chain;
@@ -1291,7 +1304,7 @@ parse_expression (const char *string)
    *NAME must be freed by the caller.  */
 
 struct type *
-parse_expression_for_completion (char *string, char **name,
+parse_expression_for_completion (const char *string, char **name,
 				 enum type_code *code)
 {
   struct expression *exp = NULL;
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 695c180..3e1d026 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -191,10 +191,10 @@ static void do_one_display (struct display *);
    past the specification and past all whitespace following it.  */
 
 static struct format_data
-decode_format (char **string_ptr, int oformat, int osize)
+decode_format (const char **string_ptr, int oformat, int osize)
 {
   struct format_data val;
-  char *p = *string_ptr;
+  const char *p = *string_ptr;
 
   val.format = '?';
   val.size = '?';
@@ -933,7 +933,7 @@ validate_format (struct format_data fmt, char *cmdname)
    first argument ("/x myvar" for example, to print myvar in hex).  */
 
 static void
-print_command_1 (char *exp, int voidprint)
+print_command_1 (const char *exp, int voidprint)
 {
   struct expression *expr;
   struct cleanup *old_chain = 0;
@@ -1013,9 +1013,19 @@ call_command (char *exp, int from_tty)
   print_command_1 (exp, 0);
 }
 
-void
+/* Implementation of the "output" command.  */
+
+static void
 output_command (char *exp, int from_tty)
 {
+  output_command_const (exp, from_tty);
+}
+
+/* Like output_command, but takes a const string as argument.  */
+
+void
+output_command_const (const char *exp, int from_tty)
+{
   struct expression *expr;
   struct cleanup *old_chain;
   char format = 0;
@@ -1402,8 +1412,10 @@ x_command (char *exp, int from_tty)
 
   if (exp && *exp == '/')
     {
-      exp++;
-      fmt = decode_format (&exp, last_format, last_size);
+      const char *tmp = exp + 1;
+
+      fmt = decode_format (&tmp, last_format, last_size);
+      exp = (char *) tmp;
     }
 
   /* If we have an expression, evaluate it and use it as the address.  */
@@ -1473,12 +1485,13 @@ x_command (char *exp, int from_tty)
    Specify the expression.  */
 
 static void
-display_command (char *exp, int from_tty)
+display_command (char *arg, int from_tty)
 {
   struct format_data fmt;
   struct expression *expr;
   struct display *new;
   int display_it = 1;
+  const char *exp = arg;
 
 #if defined(TUI)
   /* NOTE: cagney/2003-02-13 The `tui_active' was previously
diff --git a/gdb/python/py-auto-load.c b/gdb/python/py-auto-load.c
index a8cb79c..53a8eb5 100644
--- a/gdb/python/py-auto-load.c
+++ b/gdb/python/py-auto-load.c
@@ -242,7 +242,7 @@ void
 gdbpy_initialize_auto_load (void)
 {
   struct cmd_list_element *cmd;
-  char *cmd_name;
+  const char *cmd_name;
 
   add_setshow_boolean_cmd ("python-scripts", class_support,
 			   &auto_load_python_scripts, _("\
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 76670ea..161b4bc 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -103,7 +103,7 @@ cmdpy_destroyer (struct cmd_list_element *self, void *context)
 
   /* We allocated the name, doc string, and perhaps the prefix
      name.  */
-  xfree (self->name);
+  xfree ((char *) self->name);
   xfree (self->doc);
   xfree (self->prefixname);
 
@@ -207,7 +207,8 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
 /* Called by gdb for command completion.  */
 
 static VEC (char_ptr) *
-cmdpy_completer (struct cmd_list_element *command, char *text, char *word)
+cmdpy_completer (struct cmd_list_element *command,
+		 const char *text, const char *word)
 {
   cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command);
   PyObject *textobj, *wordobj, *resultobj = NULL;
@@ -319,7 +320,8 @@ gdbpy_parse_command_name (const char *name,
   struct cmd_list_element *elt;
   int len = strlen (name);
   int i, lastchar;
-  char *prefix_text, *prefix_text2;
+  char *prefix_text;
+  const char *prefix_text2;
   char *result;
 
   /* Skip trailing whitespace.  */
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index 1970714..acb48cd 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -470,7 +470,7 @@ add_setshow_generic (int parmclass, enum command_class cmdclass,
 		     struct cmd_list_element **show_list)
 {
   struct cmd_list_element *param = NULL;
-  char *tmp_name = NULL;
+  const char *tmp_name = NULL;
 
   switch (parmclass)
     {
diff --git a/gdb/remote.c b/gdb/remote.c
index c4824e9..21d86f7 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -11612,7 +11612,7 @@ _initialize_remote (void)
 {
   struct remote_state *rs;
   struct cmd_list_element *cmd;
-  char *cmd_name;
+  const char *cmd_name;
 
   /* architecture specific data */
   remote_gdbarch_data_handle =
diff --git a/gdb/symtab.c b/gdb/symtab.c
index c0e5884..346c162 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4108,8 +4108,8 @@ completion_list_objc_symbol (struct minimal_symbol *msymbol,
 /* Break the non-quoted text based on the characters which are in
    symbols.  FIXME: This should probably be language-specific.  */
 
-static char *
-language_search_unquoted_string (char *text, char *p)
+static const char *
+language_search_unquoted_string (const char *text, const char *p)
 {
   for (; p > text; --p)
     {
@@ -4125,7 +4125,7 @@ language_search_unquoted_string (char *text, char *p)
 		p -= 2;             /* Beginning of a method name.  */
 	      else if (p[-1] == ' ' || p[-1] == '(' || p[-1] == ')')
 		{                   /* Might be part of a method name.  */
-		  char *t = p;
+		  const char *t = p;
 
 		  /* Seeing a ' ' or a '(' is not conclusive evidence
 		     that we are in the middle of a method name.  However,
@@ -4152,8 +4152,9 @@ language_search_unquoted_string (char *text, char *p)
 }
 
 static void
-completion_list_add_fields (struct symbol *sym, char *sym_text,
-			    int sym_text_len, char *text, char *word)
+completion_list_add_fields (struct symbol *sym, const char *sym_text,
+			    int sym_text_len, const char *text,
+			    const char *word)
 {
   if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
     {
@@ -4174,10 +4175,10 @@ completion_list_add_fields (struct symbol *sym, char *sym_text,
    needed by completion_list_add_name.  */
 struct add_name_data
 {
-  char *sym_text;
+  const char *sym_text;
   int sym_text_len;
-  char *text;
-  char *word;
+  const char *text;
+  const char *word;
 };
 
 /* A callback used with macro_for_each and macro_for_each_in_scope.
@@ -4206,7 +4207,8 @@ expand_partial_symbol_name (const char *name, void *user_data)
 }
 
 VEC (char_ptr) *
-default_make_symbol_completion_list_break_on (char *text, char *word,
+default_make_symbol_completion_list_break_on (const char *text,
+					      const char *word,
 					      const char *break_on,
 					      enum type_code code)
 {
@@ -4222,7 +4224,7 @@ default_make_symbol_completion_list_break_on (char *text, char *word,
   const struct block *surrounding_static_block, *surrounding_global_block;
   struct block_iterator iter;
   /* The symbol we are completing on.  Points in same buffer as text.  */
-  char *sym_text;
+  const char *sym_text;
   /* Length of sym_text.  */
   int sym_text_len;
   struct add_name_data datum;
@@ -4230,9 +4232,9 @@ default_make_symbol_completion_list_break_on (char *text, char *word,
 
   /* Now look for the symbol we are supposed to complete on.  */
   {
-    char *p;
+    const char *p;
     char quote_found;
-    char *quote_pos = NULL;
+    const char *quote_pos = NULL;
 
     /* First see if this is a quoted string.  */
     quote_found = '\0';
@@ -4437,7 +4439,7 @@ default_make_symbol_completion_list_break_on (char *text, char *word,
 }
 
 VEC (char_ptr) *
-default_make_symbol_completion_list (char *text, char *word,
+default_make_symbol_completion_list (const char *text, const char *word,
 				     enum type_code code)
 {
   return default_make_symbol_completion_list_break_on (text, word, "", code);
@@ -4448,7 +4450,7 @@ default_make_symbol_completion_list (char *text, char *word,
    is NULL.  */
 
 VEC (char_ptr) *
-make_symbol_completion_list (char *text, char *word)
+make_symbol_completion_list (const char *text, const char *word)
 {
   return current_language->la_make_symbol_completion_list (text, word,
 							   TYPE_CODE_UNDEF);
@@ -4458,7 +4460,8 @@ make_symbol_completion_list (char *text, char *word)
    symbols whose type code is CODE.  */
 
 VEC (char_ptr) *
-make_symbol_completion_type (char *text, char *word, enum type_code code)
+make_symbol_completion_type (const char *text, const char *word,
+			     enum type_code code)
 {
   gdb_assert (code == TYPE_CODE_UNION
 	      || code == TYPE_CODE_STRUCT
@@ -4472,7 +4475,7 @@ make_symbol_completion_type (char *text, char *word, enum type_code code)
 
 VEC (char_ptr) *
 make_symbol_completion_list_fn (struct cmd_list_element *ignore,
-				char *text, char *word)
+				const char *text, const char *word)
 {
   return make_symbol_completion_list (text, word);
 }
@@ -4481,23 +4484,24 @@ make_symbol_completion_list_fn (struct cmd_list_element *ignore,
    defined in a source file FILE.  */
 
 VEC (char_ptr) *
-make_file_symbol_completion_list (char *text, char *word, char *srcfile)
+make_file_symbol_completion_list (const char *text, const char *word,
+				  const char *srcfile)
 {
   struct symbol *sym;
   struct symtab *s;
   struct block *b;
   struct block_iterator iter;
   /* The symbol we are completing on.  Points in same buffer as text.  */
-  char *sym_text;
+  const char *sym_text;
   /* Length of sym_text.  */
   int sym_text_len;
 
   /* Now look for the symbol we are supposed to complete on.
      FIXME: This should be language-specific.  */
   {
-    char *p;
+    const char *p;
     char quote_found;
-    char *quote_pos = NULL;
+    const char *quote_pos = NULL;
 
     /* First see if this is a quoted string.  */
     quote_found = '\0';
@@ -4579,7 +4583,7 @@ make_file_symbol_completion_list (char *text, char *word, char *srcfile)
    list as necessary.  */
 
 static void
-add_filename_to_list (const char *fname, char *text, char *word,
+add_filename_to_list (const char *fname, const char *text, const char *word,
 		      VEC (char_ptr) **list)
 {
   char *new;
@@ -4630,8 +4634,8 @@ not_interesting_fname (const char *fname)
 struct add_partial_filename_data
 {
   struct filename_seen_cache *filename_seen_cache;
-  char *text;
-  char *word;
+  const char *text;
+  const char *word;
   int text_len;
   VEC (char_ptr) **list;
 };
@@ -4670,7 +4674,7 @@ maybe_add_partial_symtab_filename (const char *filename, const char *fullname,
    NULL.  */
 
 VEC (char_ptr) *
-make_source_files_completion_list (char *text, char *word)
+make_source_files_completion_list (const char *text, const char *word)
 {
   struct symtab *s;
   struct objfile *objfile;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 378e933..7f0a4e6 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1176,20 +1176,24 @@ extern void forget_cached_source_info (void);
 extern void select_source_symtab (struct symtab *);
 
 extern VEC (char_ptr) *default_make_symbol_completion_list_break_on
-  (char *text, char *word, const char *break_on,
+  (const char *text, const char *word, const char *break_on,
    enum type_code code);
-extern VEC (char_ptr) *default_make_symbol_completion_list (char *, char *,
+extern VEC (char_ptr) *default_make_symbol_completion_list (const char *,
+							    const char *,
 							    enum type_code);
-extern VEC (char_ptr) *make_symbol_completion_list (char *, char *);
-extern VEC (char_ptr) *make_symbol_completion_type (char *, char *,
+extern VEC (char_ptr) *make_symbol_completion_list (const char *, const char *);
+extern VEC (char_ptr) *make_symbol_completion_type (const char *, const char *,
 						    enum type_code);
 extern VEC (char_ptr) *make_symbol_completion_list_fn (struct cmd_list_element *,
-						       char *, char *);
+						       const char *,
+						       const char *);
 
-extern VEC (char_ptr) *make_file_symbol_completion_list (char *,
-							 char *, char *);
+extern VEC (char_ptr) *make_file_symbol_completion_list (const char *,
+							 const char *,
+							 const char *);
 
-extern VEC (char_ptr) *make_source_files_completion_list (char *, char *);
+extern VEC (char_ptr) *make_source_files_completion_list (const char *,
+							  const char *);
 
 /* symtab.c */
 
diff --git a/gdb/top.c b/gdb/top.c
index e9a40fc..3c6371c 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -432,13 +432,15 @@ execute_command (char *p, int from_tty)
     p++;
   if (*p)
     {
+      const char *cmd = p;
       char *arg;
       line = p;
 
       /* If trace-commands is set then this will print this command.  */
       print_command_trace (p);
 
-      c = lookup_cmd (&p, cmdlist, "", 0, 1);
+      c = lookup_cmd (&cmd, cmdlist, "", 0, 1);
+      p = (char *) cmd;
 
       /* Pass null arg rather than an empty one.  */
       arg = *p ? p : 0;
@@ -467,7 +469,7 @@ execute_command (char *p, int from_tty)
       execute_cmd_pre_hook (c);
 
       if (c->flags & DEPRECATED_WARN_USER)
-	deprecated_cmd_warning (&line);
+	deprecated_cmd_warning (line);
 
       /* c->user_commands would be NULL in the case of a python command.  */
       if (c->class == class_user && c->user_commands)
@@ -1475,7 +1477,7 @@ int info_verbose = 0;		/* Default verbose msgs off.  */
 void
 set_verbose (char *args, int from_tty, struct cmd_list_element *c)
 {
-  char *cmdname = "verbose";
+  const char *cmdname = "verbose";
   struct cmd_list_element *showcmd;
 
   showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 513dccc..4db93ca 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -610,8 +610,8 @@ teval_pseudocommand (char *args, int from_tty)
 
 /* Parse any collection options, such as /s for strings.  */
 
-char *
-decode_agent_options (char *exp)
+const char *
+decode_agent_options (const char *exp)
 {
   struct value_print_options opts;
 
@@ -643,7 +643,7 @@ decode_agent_options (char *exp)
   else
     error (_("Undefined collection format \"%c\"."), *exp);
 
-  exp = skip_spaces (exp);
+  exp = skip_spaces_const (exp);
 
   return exp;
 }
@@ -700,21 +700,22 @@ report_agent_reqs_errors (struct agent_expr *aexpr)
 
 /* worker function */
 void
-validate_actionline (char **line, struct breakpoint *b)
+validate_actionline (const char *line, struct breakpoint *b)
 {
   struct cmd_list_element *c;
   struct expression *exp = NULL;
   struct cleanup *old_chain = NULL;
-  char *p, *tmp_p;
+  const char *tmp_p;
+  const char *p;
   struct bp_location *loc;
   struct agent_expr *aexpr;
   struct tracepoint *t = (struct tracepoint *) b;
 
   /* If EOF is typed, *line is NULL.  */
-  if (*line == NULL)
+  if (line == NULL)
     return;
 
-  p = skip_spaces (*line);
+  p = skip_spaces_const (line);
 
   /* Symbol lookup etc.  */
   if (*p == '\0')	/* empty line: just prompt for another line.  */
@@ -736,7 +737,7 @@ validate_actionline (char **line, struct breakpoint *b)
       do
 	{			/* Repeat over a comma-separated list.  */
 	  QUIT;			/* Allow user to bail out with ^C.  */
-	  p = skip_spaces (p);
+	  p = skip_spaces_const (p);
 
 	  if (*p == '$')	/* Look for special pseudo-symbols.  */
 	    {
@@ -754,12 +755,9 @@ validate_actionline (char **line, struct breakpoint *b)
 	  tmp_p = p;
 	  for (loc = t->base.loc; loc; loc = loc->next)
 	    {
-	      const char *q;
-
-	      q = tmp_p;
-	      exp = parse_exp_1 (&q, loc->address,
+	      p = tmp_p;
+	      exp = parse_exp_1 (&p, loc->address,
 				 block_for_pc (loc->address), 1);
-	      p = (char *) q;
 	      old_chain = make_cleanup (free_current_contents, &exp);
 
 	      if (exp->elts[0].opcode == OP_VAR_VALUE)
@@ -804,18 +802,16 @@ validate_actionline (char **line, struct breakpoint *b)
       do
 	{			/* Repeat over a comma-separated list.  */
 	  QUIT;			/* Allow user to bail out with ^C.  */
-	  p = skip_spaces (p);
+	  p = skip_spaces_const (p);
 
 	  tmp_p = p;
 	  for (loc = t->base.loc; loc; loc = loc->next)
 	    {
-	      const char *q;
+	      p = tmp_p;
 
-	      q = tmp_p;
 	      /* Only expressions are allowed for this action.  */
-	      exp = parse_exp_1 (&q, loc->address,
+	      exp = parse_exp_1 (&p, loc->address,
 				 block_for_pc (loc->address), 1);
-	      p = (char *) q;
 	      old_chain = make_cleanup (free_current_contents, &exp);
 
 	      /* We have something to evaluate, make sure that the expr to
@@ -838,20 +834,20 @@ validate_actionline (char **line, struct breakpoint *b)
 
   else if (cmd_cfunc_eq (c, while_stepping_pseudocommand))
     {
-      char *steparg;		/* In case warning is necessary.  */
-
-      p = skip_spaces (p);
-      steparg = p;
+      char *endp;
 
-      if (*p == '\0' || (t->step_count = strtol (p, &p, 0)) == 0)
-	error (_("while-stepping step count `%s' is malformed."), *line);
+      p = skip_spaces_const (p);
+      t->step_count = strtol (p, &endp, 0);
+      if (endp == p || t->step_count == 0)
+	error (_("while-stepping step count `%s' is malformed."), line);
+      p = endp;
     }
 
   else if (cmd_cfunc_eq (c, end_actions_pseudocommand))
     ;
 
   else
-    error (_("`%s' is not a supported tracepoint action."), *line);
+    error (_("`%s' is not a supported tracepoint action."), line);
 }
 
 enum {
@@ -1375,7 +1371,7 @@ encode_actions_1 (struct command_line *action,
 		  struct collection_list *collect,
 		  struct collection_list *stepping_list)
 {
-  char *action_exp;
+  const char *action_exp;
   struct expression *exp = NULL;
   int i;
   struct value *tempval;
@@ -1386,7 +1382,7 @@ encode_actions_1 (struct command_line *action,
     {
       QUIT;			/* Allow user to bail out with ^C.  */
       action_exp = action->line;
-      action_exp = skip_spaces (action_exp);
+      action_exp = skip_spaces_const (action_exp);
 
       cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
       if (cmd == 0)
@@ -1401,7 +1397,7 @@ encode_actions_1 (struct command_line *action,
 	  do
 	    {			/* Repeat over a comma-separated list.  */
 	      QUIT;		/* Allow user to bail out with ^C.  */
-	      action_exp = skip_spaces (action_exp);
+	      action_exp = skip_spaces_const (action_exp);
 
 	      if (0 == strncasecmp ("$reg", action_exp, 4))
 		{
@@ -1476,12 +1472,9 @@ encode_actions_1 (struct command_line *action,
 		  unsigned long addr;
 		  struct cleanup *old_chain = NULL;
 		  struct cleanup *old_chain1 = NULL;
-		  const char *q;
 
-		  q = action_exp;
-		  exp = parse_exp_1 (&q, tloc->address,
+		  exp = parse_exp_1 (&action_exp, tloc->address,
 				     block_for_pc (tloc->address), 1);
-		  action_exp = (char *) q;
 		  old_chain = make_cleanup (free_current_contents, &exp);
 
 		  switch (exp->elts[0].opcode)
@@ -1565,17 +1558,14 @@ encode_actions_1 (struct command_line *action,
 	  do
 	    {			/* Repeat over a comma-separated list.  */
 	      QUIT;		/* Allow user to bail out with ^C.  */
-	      action_exp = skip_spaces (action_exp);
+	      action_exp = skip_spaces_const (action_exp);
 
 		{
 		  struct cleanup *old_chain = NULL;
 		  struct cleanup *old_chain1 = NULL;
-		  const char *q;
 
-		  q = action_exp;
-		  exp = parse_exp_1 (&q, tloc->address,
+		  exp = parse_exp_1 (&action_exp, tloc->address,
 				     block_for_pc (tloc->address), 1);
-		  action_exp = (char *) q;
 		  old_chain = make_cleanup (free_current_contents, &exp);
 
 		  aexpr = gen_eval_for_expr (tloc->address, exp);
@@ -1643,18 +1633,15 @@ encode_actions (struct breakpoint *t, struct bp_location *tloc,
      the fly, and don't cache it.  */
   if (*default_collect)
     {
-      char *line;
-
       default_collect_line =  xstrprintf ("collect %s", default_collect);
       make_cleanup (xfree, default_collect_line);
 
-      line = default_collect_line;
-      validate_actionline (&line, t);
+      validate_actionline (default_collect_line, t);
 
       default_collect_action = xmalloc (sizeof (struct command_line));
       make_cleanup (xfree, default_collect_action);
       default_collect_action->next = actions;
-      default_collect_action->line = line;
+      default_collect_action->line = default_collect_line;
       actions = default_collect_action;
     }
   encode_actions_1 (actions, t, tloc, frame_reg, frame_offset,
@@ -2800,15 +2787,6 @@ scope_info (char *args, int from_tty)
 		     save_args);
 }
 
-/* worker function (cleanup) */
-static void
-replace_comma (void *data)
-{
-  char *comma = data;
-  *comma = ',';
-}
-
-
 /* Helper for trace_dump_command.  Dump the action list starting at
    ACTION.  STEPPING_ACTIONS is true if we're iterating over the
    actions of the body of a while-stepping action.  STEPPING_FRAME is
@@ -2820,7 +2798,7 @@ trace_dump_actions (struct command_line *action,
 		    int stepping_actions, int stepping_frame,
 		    int from_tty)
 {
-  char *action_exp, *next_comma;
+  const char *action_exp, *next_comma;
 
   for (; action != NULL; action = action->next)
     {
@@ -2828,7 +2806,7 @@ trace_dump_actions (struct command_line *action,
 
       QUIT;			/* Allow user to bail out with ^C.  */
       action_exp = action->line;
-      action_exp = skip_spaces (action_exp);
+      action_exp = skip_spaces_const (action_exp);
 
       /* The collection actions to be done while stepping are
          bracketed by the commands "while-stepping" and "end".  */
@@ -2858,6 +2836,10 @@ trace_dump_actions (struct command_line *action,
 	     STEPPING_ACTIONS should be equal.  */
 	  if (stepping_frame == stepping_actions)
 	    {
+	      char *cmd = NULL;
+	      struct cleanup *old_chain
+		= make_cleanup (free_current_contents, &cmd);
+
 	      if (*action_exp == '/')
 		action_exp = decode_agent_options (action_exp);
 
@@ -2866,7 +2848,7 @@ trace_dump_actions (struct command_line *action,
 		  QUIT;		/* Allow user to bail out with ^C.  */
 		  if (*action_exp == ',')
 		    action_exp++;
-		  action_exp = skip_spaces (action_exp);
+		  action_exp = skip_spaces_const (action_exp);
 
 		  next_comma = strchr (action_exp, ',');
 
@@ -2880,20 +2862,31 @@ trace_dump_actions (struct command_line *action,
 		    args_info (NULL, from_tty);
 		  else
 		    {		/* variable */
-		      if (next_comma)
+		      if (next_comma != NULL)
 			{
-			  make_cleanup (replace_comma, next_comma);
-			  *next_comma = '\0';
+			  size_t len = next_comma - action_exp;
+
+			  cmd = xrealloc (cmd, len + 1);
+			  memcpy (cmd, action_exp, len);
+			  cmd[len] = 0;
+			}
+		      else
+			{
+			  size_t len = strlen (action_exp);
+
+			  cmd = xrealloc (cmd, len + 1);
+			  memcpy (cmd, action_exp, len + 1);
 			}
-		      printf_filtered ("%s = ", action_exp);
-		      output_command (action_exp, from_tty);
+
+		      printf_filtered ("%s = ", cmd);
+		      output_command_const (cmd, from_tty);
 		      printf_filtered ("\n");
 		    }
-		  if (next_comma)
-		    *next_comma = ',';
 		  action_exp = next_comma;
 		}
 	      while (action_exp && *action_exp == ',');
+
+	      do_cleanups (old_chain);
 	    }
 	}
     }
@@ -2908,7 +2901,7 @@ trace_dump_command (char *args, int from_tty)
   struct tracepoint *t;
   int stepping_frame = 0;
   struct bp_location *loc;
-  char *line, *default_collect_line = NULL;
+  char *default_collect_line = NULL;
   struct command_line *actions, *default_collect_action = NULL;
   struct cleanup *old_chain = NULL;
 
@@ -2952,12 +2945,11 @@ trace_dump_command (char *args, int from_tty)
     {
       default_collect_line = xstrprintf ("collect %s", default_collect);
       old_chain = make_cleanup (xfree, default_collect_line);
-      line = default_collect_line;
-      validate_actionline (&line, &t->base);
+      validate_actionline (default_collect_line, &t->base);
       default_collect_action = xmalloc (sizeof (struct command_line));
       make_cleanup (xfree, default_collect_action);
       default_collect_action->next = actions;
-      default_collect_action->line = line;
+      default_collect_action->line = default_collect_line;
       actions = default_collect_action;
     }
 
diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h
index b2b9d7c..b03c95b 100644
--- a/gdb/tracepoint.h
+++ b/gdb/tracepoint.h
@@ -237,12 +237,12 @@ struct cleanup *make_cleanup_restore_traceframe_number (void);
 
 void free_actions (struct breakpoint *);
 
-extern char *decode_agent_options (char *exp);
+extern const char *decode_agent_options (const char *exp);
 
 extern void encode_actions (struct breakpoint *t, struct bp_location *tloc,
 			    char ***tdp_actions, char ***stepping_actions);
 
-extern void validate_actionline (char **, struct breakpoint *);
+extern void validate_actionline (const char *, struct breakpoint *);
 extern void validate_trace_state_variable_name (const char *name);
 
 extern struct trace_state_variable *find_trace_state_variable (const char *name);
diff --git a/gdb/valprint.h b/gdb/valprint.h
index 1aa5a19..7baef2f 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -203,6 +203,10 @@ extern void generic_printstr (struct ui_file *stream, struct type *type,
 			      int quote_char, int c_style_terminator,
 			      const struct value_print_options *options);
 
-extern void output_command (char *exp, int from_tty);
+/* Run the "output" command.  ARGS and FROM_TTY are the usual
+   arguments passed to all command implementations, except ARGS is
+   const.  */
+
+extern void output_command_const (const char *args, int from_tty);
 
 #endif
diff --git a/gdb/value.c b/gdb/value.c
index 4b70ece..90bc415 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2130,7 +2130,7 @@ function_command (char *command, int from_tty)
 static void
 function_destroyer (struct cmd_list_element *self, void *ignore)
 {
-  xfree (self->name);
+  xfree ((char *) self->name);
   xfree (self->doc);
 }
 
-- 
1.7.11.7



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