public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings)
@ 2017-04-04 17:25 Pedro Alves
  2017-04-04 17:26 ` [PATCH 08/18] -Wwrite-strings: Constify mi_cmd_argv_ftype's 'command' parameter Pedro Alves
                   ` (20 more replies)
  0 siblings, 21 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:25 UTC (permalink / raw)
  To: gdb-patches; +Cc: Binutils

"-Wwrite-strings" is enabled by default for C++ programs:

  "When compiling C++, warn about the deprecated conversion from
  string literals to char *. This warning is enabled by default for
  C++ programs. "

This warning, via -Werror, makes this be a compile-time error:

 char *str = "hello";

It forces us to write instead either

 char *str = (char *) "hello"; // I know what I'm doing! (TM)

or:

 const char *str = "hello";    // Preferable.

However, I had disabled the warning for GDB in the earlier steps of
the C++ conversion:

  https://sourceware.org/ml/gdb-patches/2015-02/msg00203.html

... as an expedient hack, since we weren't enabling it in C mode
either.

I'd like to enable the warning now, to catch more bugs at compile
time.  I spotted one related bug in review last week (storing a string
literal in a vector of heap-allocated strings, leading to a bogus
"free" call later on), which was what prompted me to do this.

"Bah, I'll just do it.  Can't take more than a couple hours..."

Yeah, right...  /me will never learn.

Tested on x86_64 Fedora 23, built with --enable-targets=all.

Compile tested GDB on Aarch64 GNU/Linux, Power 64 GNU/Linux, AIX 7.1,
and 32-bit/64-bit mingw32-w64.

Also cross built MIPS and ARM GNU/Linux gdbserver.

The first patch needs approval from the binutils side, hence the cross
post.  The rest of the series is GDB-specific, so I'm sending those
patches to gdb-patches@ only.

Pedro Alves (18):
  -Wwrite-strings: Constify struct disassemble_info's
    disassembler_options field
  -Wwrite-strings: Constify macroexp.c:init_shared_buffer
  -Wwrite-strings: Don't initialize string command variables to empty
    string
  -Wwrite-strings: Constify shell_escape and plug make_command leak
  -Wwrite-strings: Constify warning_pre_print
  -Wwrite-strings: Constify target_pid_to_str and
    target_thread_extra_thread_info
  -Wwrite-strings: Constify work break character arrays
  -Wwrite-strings: Constify mi_cmd_argv_ftype's 'command' parameter
  -Wwrite-strings: MI -info-os
  -Wwrite-strings: gdbserver's 'port' parsing
  -Wwrite-strings: gdbserver/win32-low.c and TARGET_WAITKIND_EXECD
  -Wwrite-strings: More fix-old-Python-API wrappers
  -Wwrite-strings: Wrap PyGetSetDef for construction with string
    literals
  -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *"
    overload
  -Wwrite-strings: execute_command calls with string literals
  -Wwrite-strings: Some constification in gdb/breakpoint.c
  -Wwrite-strings: The Rest
  -Wwrite-strings: Remove -Wno-write-strings

 gdb/ada-exp.y                    |   4 +-
 gdb/ada-lang.c                   |  58 +++++++++---------
 gdb/ada-lang.h                   |   8 +--
 gdb/aix-thread.c                 |   4 +-
 gdb/arc-tdep.c                   |   2 +-
 gdb/arm-tdep.c                   |   4 +-
 gdb/ax-gdb.c                     |  21 ++++---
 gdb/bcache.c                     |   2 +-
 gdb/bcache.h                     |   2 +-
 gdb/break-catch-throw.c          |  23 ++++---
 gdb/breakpoint.c                 |  38 ++++++------
 gdb/breakpoint.h                 |   8 +--
 gdb/bsd-kvm.c                    |   2 +-
 gdb/bsd-uthread.c                |   6 +-
 gdb/buildsym.c                   |   2 +-
 gdb/buildsym.h                   |   4 +-
 gdb/c-exp.y                      |   6 +-
 gdb/c-lang.h                     |   4 +-
 gdb/c-varobj.c                   |   2 +-
 gdb/charset.c                    |  11 +++-
 gdb/cli/cli-cmds.c               |  40 ++++++------
 gdb/cli/cli-decode.c             |   3 +-
 gdb/cli/cli-dump.c               |  15 ++---
 gdb/cli/cli-script.c             |   2 +-
 gdb/cli/cli-script.h             |   2 +-
 gdb/cli/cli-utils.c              |   6 +-
 gdb/cli/cli-utils.h              |  21 ++++++-
 gdb/coff-pe-read.c               |   2 +-
 gdb/command.h                    |   3 +-
 gdb/common/print-utils.c         |   2 +-
 gdb/completer.c                  |  62 +++++++++++--------
 gdb/completer.h                  |   8 ++-
 gdb/configure                    |   2 +-
 gdb/corefile.c                   |   2 +-
 gdb/corelow.c                    |   2 +-
 gdb/cp-name-parser.y             |   4 +-
 gdb/cp-valprint.c                |   2 +-
 gdb/cris-tdep.c                  |   6 +-
 gdb/d-exp.y                      |   6 +-
 gdb/d-lang.h                     |   2 +-
 gdb/darwin-nat.c                 |   4 +-
 gdb/dbxread.c                    |  80 ++++++++++++------------
 gdb/defs.h                       |   7 ++-
 gdb/disasm.c                     |   2 +-
 gdb/dwarf2read.c                 |   8 +--
 gdb/event-top.c                  |   4 +-
 gdb/exceptions.c                 |   4 +-
 gdb/exceptions.h                 |   3 +-
 gdb/expprint.c                   |  14 ++---
 gdb/expression.h                 |   6 +-
 gdb/f-exp.y                      |   8 +--
 gdb/f-lang.c                     |   2 +-
 gdb/f-lang.h                     |   2 +-
 gdb/fbsd-nat.c                   |   2 +-
 gdb/fbsd-tdep.c                  |   2 +-
 gdb/fork-child.c                 |   2 +-
 gdb/frv-tdep.c                   |   6 +-
 gdb/gdbarch.c                    |   6 +-
 gdb/gdbarch.h                    |   4 +-
 gdb/gdbarch.sh                   |   6 +-
 gdb/gdbcore.h                    |   2 +-
 gdb/gdbserver/configure          |   2 +-
 gdb/gdbserver/gdbreplay.c        |   2 +-
 gdb/gdbserver/linux-x86-low.c    |   2 +-
 gdb/gdbserver/remote-utils.c     |   8 +--
 gdb/gdbserver/remote-utils.h     |   4 +-
 gdb/gdbserver/server.c           |  13 ++--
 gdb/gdbserver/win32-low.c        |   5 --
 gdb/gnu-nat.c                    |   2 +-
 gdb/go-exp.y                     |   6 +-
 gdb/go-lang.h                    |   2 +-
 gdb/go32-nat.c                   |   4 +-
 gdb/guile/scm-breakpoint.c       |   3 +-
 gdb/guile/scm-cmd.c              |   4 +-
 gdb/guile/scm-param.c            |   2 +-
 gdb/h8300-tdep.c                 |   6 +-
 gdb/hppa-tdep.c                  |   4 +-
 gdb/i386-cygwin-tdep.c           |   2 +-
 gdb/i386-tdep.c                  |   4 +-
 gdb/ia64-tdep.c                  |   2 +-
 gdb/inf-ptrace.c                 |   2 +-
 gdb/infcmd.c                     |  12 ++--
 gdb/inferior.c                   |   2 +-
 gdb/language.c                   |  10 +--
 gdb/language.h                   |   8 +--
 gdb/linespec.c                   |   3 +-
 gdb/linux-nat.c                  |   2 +-
 gdb/linux-tdep.c                 |   2 +-
 gdb/linux-thread-db.c            |   6 +-
 gdb/lm32-tdep.c                  |   2 +-
 gdb/m2-exp.y                     |   4 +-
 gdb/m2-lang.h                    |   2 +-
 gdb/m32r-tdep.c                  |   2 +-
 gdb/m68hc11-tdep.c               |   2 +-
 gdb/m88k-tdep.c                  |   2 +-
 gdb/macroexp.c                   |  28 +++++----
 gdb/main.c                       |   6 +-
 gdb/mdebugread.c                 |  46 +++++++-------
 gdb/memattr.c                    |   2 +-
 gdb/mep-tdep.c                   |   2 +-
 gdb/mi/mi-cmd-break.c            |  12 ++--
 gdb/mi/mi-cmd-catch.c            |   8 +--
 gdb/mi/mi-cmd-disas.c            |   2 +-
 gdb/mi/mi-cmd-env.c              |  16 ++---
 gdb/mi/mi-cmd-file.c             |   6 +-
 gdb/mi/mi-cmd-info.c             |  10 +--
 gdb/mi/mi-cmd-stack.c            |  18 +++---
 gdb/mi/mi-cmd-target.c           |   6 +-
 gdb/mi/mi-cmd-var.c              |  36 +++++------
 gdb/mi/mi-cmds.h                 |   2 +-
 gdb/mi/mi-interp.c               |   2 +-
 gdb/mi/mi-main.c                 |  86 +++++++++++++-------------
 gdb/mi/mi-symbol-cmds.c          |   2 +-
 gdb/mips-tdep.c                  |   6 +-
 gdb/mn10300-tdep.c               |  10 +--
 gdb/moxie-tdep.c                 |   2 +-
 gdb/nat/linux-osdata.c           |   6 +-
 gdb/nto-tdep.c                   |   4 +-
 gdb/nto-tdep.h                   |   2 +-
 gdb/objc-lang.c                  |   8 +--
 gdb/objc-lang.h                  |   7 ++-
 gdb/objfiles.c                   |   2 +-
 gdb/objfiles.h                   |   2 +-
 gdb/obsd-nat.c                   |   2 +-
 gdb/osdata.c                     |  13 +++-
 gdb/osdata.h                     |   6 +-
 gdb/p-exp.y                      |   6 +-
 gdb/p-lang.h                     |   2 +-
 gdb/parser-defs.h                |   6 +-
 gdb/printcmd.c                   |   2 +-
 gdb/procfs.c                     |   4 +-
 gdb/psymtab.c                    |   2 +-
 gdb/python/py-arch.c             |   2 +-
 gdb/python/py-breakpoint.c       |   8 +--
 gdb/python/py-cmd.c              |  16 ++---
 gdb/python/py-event.c            |   4 +-
 gdb/python/py-event.h            |   4 +-
 gdb/python/py-evts.c             |   2 +-
 gdb/python/py-finishbreakpoint.c |   4 +-
 gdb/python/py-framefilter.c      |   2 +-
 gdb/python/py-inferior.c         |  11 ++--
 gdb/python/py-objfile.c          |   4 +-
 gdb/python/py-param.c            |   2 +-
 gdb/python/py-symbol.c           |   4 +-
 gdb/python/py-type.c             |   2 +-
 gdb/python/py-unwind.c           |   2 +-
 gdb/python/py-value.c            |   4 +-
 gdb/python/python-internal.h     | 120 ++++++++++++++++++++++++++++++++++++
 gdb/python/python.c              |   8 +--
 gdb/ravenscar-thread.c           |   8 +--
 gdb/record-btrace.c              |   8 +--
 gdb/record-full.c                |   2 +-
 gdb/record.c                     |  14 ++---
 gdb/remote-fileio.c              |   2 +-
 gdb/remote-sim.c                 |   2 +-
 gdb/remote.c                     |  12 ++--
 gdb/reverse.c                    |   2 +-
 gdb/rs6000-tdep.c                |   4 +-
 gdb/rust-exp.y                   |   2 +-
 gdb/rust-lang.c                  |   2 +-
 gdb/rust-lang.h                  |   2 +-
 gdb/serial.h                     |   2 +-
 gdb/sh-tdep.c                    |  22 +++----
 gdb/sh64-tdep.c                  |   2 +-
 gdb/sol-thread.c                 |   2 +-
 gdb/sol2-tdep.c                  |   2 +-
 gdb/sol2-tdep.h                  |   2 +-
 gdb/solib-darwin.c               |   2 +-
 gdb/spu-tdep.c                   |   4 +-
 gdb/stabsread.c                  | 129 ++++++++++++++++++++-------------------
 gdb/stabsread.h                  |  10 +--
 gdb/symfile.c                    |  12 ++--
 gdb/symfile.h                    |   2 +-
 gdb/target-delegates.c           |  18 +++---
 gdb/target-descriptions.c        |   8 ++-
 gdb/target.c                     |  18 +++---
 gdb/target.h                     |  11 ++--
 gdb/thread.c                     |   2 +-
 gdb/top.c                        |   7 ++-
 gdb/top.h                        |   2 +-
 gdb/tracefile-tfile.c            |   4 +-
 gdb/tracepoint.c                 |  24 +++++---
 gdb/tracepoint.h                 |   2 +-
 gdb/tui/tui-data.c               |   2 +-
 gdb/tui/tui-data.h               |   2 +-
 gdb/tui/tui-source.c             |   2 +-
 gdb/tui/tui-source.h             |   2 +-
 gdb/tui/tui-win.c                |  11 ++--
 gdb/tui/tui-windata.c            |   2 +-
 gdb/tui/tui-windata.h            |   2 +-
 gdb/tui/tui-winsource.c          |   2 +-
 gdb/tui/tui.c                    |   2 +-
 gdb/utils.c                      |  13 ++--
 gdb/utils.h                      |   4 +-
 gdb/varobj.c                     |   2 +-
 gdb/varobj.h                     |   2 +-
 gdb/vax-tdep.c                   |   2 +-
 gdb/warning.m4                   |   2 +-
 gdb/windows-nat.c                |   4 +-
 gdb/xcoffread.c                  |   8 +--
 gdb/xml-support.c                |  10 +--
 gdb/xml-tdesc.c                  |   3 +-
 gdb/xstormy16-tdep.c             |   2 +-
 gdb/xtensa-tdep.c                |   2 +-
 gdb/xtensa-tdep.h                |   2 +-
 include/dis-asm.h                |   8 +--
 opcodes/arc-dis.c                |   4 +-
 opcodes/arm-dis.c                |   4 +-
 opcodes/ppc-dis.c                |   2 +-
 opcodes/vax-dis.c                |   2 +-
 210 files changed, 983 insertions(+), 763 deletions(-)

-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 08/18] -Wwrite-strings: Constify mi_cmd_argv_ftype's 'command' parameter
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-04 17:26 ` [PATCH 01/18] -Wwrite-strings: Constify struct disassemble_info's disassembler_options field Pedro Alves
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches

-Wwrite-strings flags this attempt to pass a literal to a "char *":

	mi_cmd_interpreter_exec ("-interpreter-exec", argv, 2);

Fix that by constifying mi_cmd_argv_ftype's 'command' parameter and
adjusting all MI commands.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* mi/mi-cmd-break.c (mi_cmd_break_insert_1, mi_cmd_break_insert)
	(mi_cmd_dprintf_insert, mi_cmd_break_passcount)
	(mi_cmd_break_watch, mi_cmd_break_commands): Constify 'command'
	parameter.
	* mi/mi-cmd-catch.c (mi_cmd_catch_assert, mi_cmd_catch_exception)
	(mi_cmd_catch_load, mi_cmd_catch_unload): Constify cmd' parameter.
	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Constify 'command'
	parameter.
	* mi/mi-cmd-env.c (mi_cmd_env_pwd, mi_cmd_env_cd, mi_cmd_env_path)
	(mi_cmd_env_dir, mi_cmd_inferior_tty_set, _cmd_inferior_tty_show)
	* mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_file)
	(mi_cmd_file_list_exec_source_files)
	(mi_cmd_file_list_shared_libraries): Constify 'command' parameter.
	* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions)
	(mi_cmd_info_gdb_mi_command, mi_cmd_info_os): Constify 'command'
	parameter.
	* mi/mi-cmd-stack.c (mi_cmd_enable_frame_filters)
	(mi_cmd_stack_list_frames, mi_cmd_stack_info_depth)
	(mi_cmd_stack_list_locals, mi_cmd_stack_list_args)
	(mi_cmd_stack_list_variables, mi_cmd_stack_select_frame)
	(mi_cmd_stack_info_frame): Constify 'command' parameter.
	* mi/mi-cmd-target.c (mi_cmd_target_file_get)
	(mi_cmd_target_file_put, mi_cmd_target_file_delete): Constify
	'command' parameter.
	* mi/mi-cmd-var.c (mi_cmd_var_create, mi_cmd_var_delete)
	(mi_cmd_var_set_format, mi_cmd_var_set_visualizer)
	(mi_cmd_var_set_frozen, mi_cmd_var_show_format)
	(mi_cmd_var_info_num_children, mi_cmd_var_list_children)
	(mi_cmd_var_info_type, mi_cmd_var_info_path_expression)
	(mi_cmd_var_info_expression, mi_cmd_var_show_attributes)
	(mi_cmd_var_evaluate_expression, mi_cmd_var_assign)
	(mi_cmd_var_update, mi_cmd_enable_pretty_printing)
	(mi_cmd_var_set_update_range): Constify 'command' parameter.
	* mi/mi-cmds.h (mi_cmd_argv_ftype): Constify 'command' parameter.
	* mi/mi-interp.c (mi_cmd_interpreter_exec): Constify 'command'
	parameter.
	* mi/mi-main.c (mi_cmd_gdb_exit, mi_cmd_exec_next)
	(mi_cmd_exec_next_instruction, mi_cmd_exec_step)
	(mi_cmd_exec_step_instruction, mi_cmd_exec_finish)
	(mi_cmd_exec_return ,mi_cmd_exec_jump, mi_cmd_exec_continue)
	(mi_cmd_exec_interrupt, mi_cmd_exec_run, mi_cmd_target_detach)
	(mi_cmd_target_flash_erase, mi_cmd_thread_select)
	(mi_cmd_thread_list_ids, mi_cmd_thread_info)
	(mi_cmd_list_thread_groups, mi_cmd_data_list_register_names)
	(mi_cmd_data_list_changed_registers)
	(mi_cmd_data_write_register_values)
	(mi_cmd_data_evaluate_expression, mi_cmd_data_read_memory)
	(mi_cmd_data_read_memory_bytes, mi_cmd_data_write_memory)
	(mi_cmd_data_write_memory_bytes, mi_cmd_enable_timings)
	(mi_cmd_list_features, mi_cmd_list_target_features)
	(mi_cmd_add_inferior, mi_cmd_remove_inferior)
	(mi_cmd_trace_define_variable, mi_cmd_trace_list_variables)
	(mi_cmd_trace_find, mi_cmd_trace_save, mi_cmd_trace_start)
	(mi_cmd_trace_status, mi_cmd_trace_stop, mi_cmd_ada_task_info)
	(mi_cmd_trace_frame_collected): Constify 'command'
	parameter.
	* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Constify
	'command' parameter.
---
 gdb/mi/mi-cmd-break.c   | 12 ++++----
 gdb/mi/mi-cmd-catch.c   |  8 ++---
 gdb/mi/mi-cmd-disas.c   |  2 +-
 gdb/mi/mi-cmd-env.c     | 12 ++++----
 gdb/mi/mi-cmd-file.c    |  6 ++--
 gdb/mi/mi-cmd-info.c    |  6 ++--
 gdb/mi/mi-cmd-stack.c   | 16 +++++-----
 gdb/mi/mi-cmd-target.c  |  6 ++--
 gdb/mi/mi-cmd-var.c     | 34 ++++++++++-----------
 gdb/mi/mi-cmds.h        |  2 +-
 gdb/mi/mi-interp.c      |  2 +-
 gdb/mi/mi-main.c        | 80 ++++++++++++++++++++++++-------------------------
 gdb/mi/mi-symbol-cmds.c |  2 +-
 13 files changed, 94 insertions(+), 94 deletions(-)

diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index d80f35a..8cc6034 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -167,7 +167,7 @@ mi_argv_to_format (char **argv, int argc)
    If not, it will insert other type breakpoint.  */
 
 static void
-mi_cmd_break_insert_1 (int dprintf, char *command, char **argv, int argc)
+mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
 {
   char *address = NULL;
   int hardware = 0;
@@ -365,7 +365,7 @@ mi_cmd_break_insert_1 (int dprintf, char *command, char **argv, int argc)
    See the MI manual for the list of possible options.  */
 
 void
-mi_cmd_break_insert (char *command, char **argv, int argc)
+mi_cmd_break_insert (const char *command, char **argv, int argc)
 {
   mi_cmd_break_insert_1 (0, command, argv, argc);
 }
@@ -374,7 +374,7 @@ mi_cmd_break_insert (char *command, char **argv, int argc)
    See the MI manual for the list of possible options.  */
 
 void
-mi_cmd_dprintf_insert (char *command, char **argv, int argc)
+mi_cmd_dprintf_insert (const char *command, char **argv, int argc)
 {
   mi_cmd_break_insert_1 (1, command, argv, argc);
 }
@@ -387,7 +387,7 @@ enum wp_type
 };
 
 void
-mi_cmd_break_passcount (char *command, char **argv, int argc)
+mi_cmd_break_passcount (const char *command, char **argv, int argc)
 {
   int n;
   int p;
@@ -418,7 +418,7 @@ mi_cmd_break_passcount (char *command, char **argv, int argc)
    -break-watch -a <expr> --> insert an access wp.  */
 
 void
-mi_cmd_break_watch (char *command, char **argv, int argc)
+mi_cmd_break_watch (const char *command, char **argv, int argc)
 {
   char *expr = NULL;
   enum wp_type type = REG_WP;
@@ -496,7 +496,7 @@ mi_read_next_line (void)
 }
 
 void
-mi_cmd_break_commands (char *command, char **argv, int argc)
+mi_cmd_break_commands (const char *command, char **argv, int argc)
 {
   struct command_line *break_command;
   char *endptr;
diff --git a/gdb/mi/mi-cmd-catch.c b/gdb/mi/mi-cmd-catch.c
index ee189f3..a767ee7 100644
--- a/gdb/mi/mi-cmd-catch.c
+++ b/gdb/mi/mi-cmd-catch.c
@@ -30,7 +30,7 @@
 /* Handler for the -catch-assert command.  */
 
 void
-mi_cmd_catch_assert (char *cmd, char *argv[], int argc)
+mi_cmd_catch_assert (const char *cmd, char *argv[], int argc)
 {
   struct gdbarch *gdbarch = get_current_arch();
   char *condition = NULL;
@@ -91,7 +91,7 @@ mi_cmd_catch_assert (char *cmd, char *argv[], int argc)
 /* Handler for the -catch-exception command.  */
 
 void
-mi_cmd_catch_exception (char *cmd, char *argv[], int argc)
+mi_cmd_catch_exception (const char *cmd, char *argv[], int argc)
 {
   struct gdbarch *gdbarch = get_current_arch();
   char *condition = NULL;
@@ -225,7 +225,7 @@ mi_catch_load_unload (int load, char *argv[], int argc)
 /* Handler for the -catch-load.  */
 
 void
-mi_cmd_catch_load (char *cmd, char *argv[], int argc)
+mi_cmd_catch_load (const char *cmd, char *argv[], int argc)
 {
   mi_catch_load_unload (1, argv, argc);
 }
@@ -234,7 +234,7 @@ mi_cmd_catch_load (char *cmd, char *argv[], int argc)
 /* Handler for the -catch-unload.  */
 
 void
-mi_cmd_catch_unload (char *cmd, char *argv[], int argc)
+mi_cmd_catch_unload (const char *cmd, char *argv[], int argc)
 {
   mi_catch_load_unload (0, argv, argc);
 }
diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c
index 9338f7b..fa36311 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -51,7 +51,7 @@
          5 -- disassembly, source (pc-centric) and opcodes.  */
 
 void
-mi_cmd_disassemble (char *command, char **argv, int argc)
+mi_cmd_disassemble (const char *command, char **argv, int argc)
 {
   struct gdbarch *gdbarch = get_current_arch ();
   struct ui_out *uiout = current_uiout;
diff --git a/gdb/mi/mi-cmd-env.c b/gdb/mi/mi-cmd-env.c
index dd13de4..a6347ee 100644
--- a/gdb/mi/mi-cmd-env.c
+++ b/gdb/mi/mi-cmd-env.c
@@ -65,7 +65,7 @@ env_execute_cli_command (const char *cmd, const char *args)
 /* Print working directory.  */
 
 void
-mi_cmd_env_pwd (char *command, char **argv, int argc)
+mi_cmd_env_pwd (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
 
@@ -90,7 +90,7 @@ mi_cmd_env_pwd (char *command, char **argv, int argc)
 /* Change working directory.  */
 
 void
-mi_cmd_env_cd (char *command, char **argv, int argc)
+mi_cmd_env_cd (const char *command, char **argv, int argc)
 {
   if (argc == 0 || argc > 1)
     error (_("-environment-cd: Usage DIRECTORY"));
@@ -112,7 +112,7 @@ env_mod_path (char *dirname, char **which_path)
 /* Add one or more directories to start of executable search path.  */
 
 void
-mi_cmd_env_path (char *command, char **argv, int argc)
+mi_cmd_env_path (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   char *exec_path;
@@ -187,7 +187,7 @@ mi_cmd_env_path (char *command, char **argv, int argc)
 /* Add zero or more directories to the front of the source path.  */
 
 void
-mi_cmd_env_dir (char *command, char **argv, int argc)
+mi_cmd_env_dir (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   int i;
@@ -248,7 +248,7 @@ mi_cmd_env_dir (char *command, char **argv, int argc)
 /* Set the inferior terminal device name.  */
 
 void
-mi_cmd_inferior_tty_set (char *command, char **argv, int argc)
+mi_cmd_inferior_tty_set (const char *command, char **argv, int argc)
 {
   set_inferior_io_terminal (argv[0]);
 }
@@ -256,7 +256,7 @@ mi_cmd_inferior_tty_set (char *command, char **argv, int argc)
 /* Print the inferior terminal device name.  */
 
 void
-mi_cmd_inferior_tty_show (char *command, char **argv, int argc)
+mi_cmd_inferior_tty_show (const char *command, char **argv, int argc)
 {
   const char *inferior_io_terminal = get_inferior_io_terminal ();
   
diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c
index a2ad392..d166ff6 100644
--- a/gdb/mi/mi-cmd-file.c
+++ b/gdb/mi/mi-cmd-file.c
@@ -34,7 +34,7 @@
    current file being executed.  */
 
 void
-mi_cmd_file_list_exec_source_file (char *command, char **argv, int argc)
+mi_cmd_file_list_exec_source_file (const char *command, char **argv, int argc)
 {
   struct symtab_and_line st;
   struct ui_out *uiout = current_uiout;
@@ -81,7 +81,7 @@ print_partial_file_name (const char *filename, const char *fullname,
 }
 
 void
-mi_cmd_file_list_exec_source_files (char *command, char **argv, int argc)
+mi_cmd_file_list_exec_source_files (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct compunit_symtab *cu;
@@ -114,7 +114,7 @@ mi_cmd_file_list_exec_source_files (char *command, char **argv, int argc)
 /* See mi-cmds.h.  */
 
 void
-mi_cmd_file_list_shared_libraries (char *command, char **argv, int argc)
+mi_cmd_file_list_shared_libraries (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   const char *pattern;
diff --git a/gdb/mi/mi-cmd-info.c b/gdb/mi/mi-cmd-info.c
index e8d2c60..eba1ca2 100644
--- a/gdb/mi/mi-cmd-info.c
+++ b/gdb/mi/mi-cmd-info.c
@@ -25,7 +25,7 @@
 /* Implement the "-info-ada-exceptions" GDB/MI command.  */
 
 void
-mi_cmd_info_ada_exceptions (char *command, char **argv, int argc)
+mi_cmd_info_ada_exceptions (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct gdbarch *gdbarch = get_current_arch ();
@@ -74,7 +74,7 @@ mi_cmd_info_ada_exceptions (char *command, char **argv, int argc)
 /* Implement the "-info-gdb-mi-command" GDB/MI command.  */
 
 void
-mi_cmd_info_gdb_mi_command (char *command, char **argv, int argc)
+mi_cmd_info_gdb_mi_command (const char *command, char **argv, int argc)
 {
   const char *cmd_name;
   struct mi_cmd *cmd;
@@ -101,7 +101,7 @@ mi_cmd_info_gdb_mi_command (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_info_os (char *command, char **argv, int argc)
+mi_cmd_info_os (const char *command, char **argv, int argc)
 {
   switch (argc)
     {
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index acb44a2..bb56205 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -46,7 +46,7 @@ static void list_args_or_locals (enum what_to_list what,
 static int frame_filters = 0;
 
 void
-mi_cmd_enable_frame_filters (char *command, char **argv, int argc)
+mi_cmd_enable_frame_filters (const char *command, char **argv, int argc)
 {
   if (argc != 0)
     error (_("-enable-frame-filters: no arguments allowed"));
@@ -76,7 +76,7 @@ mi_apply_ext_lang_frame_filter (struct frame_info *frame, int flags,
    displayed.  */
 
 void
-mi_cmd_stack_list_frames (char *command, char **argv, int argc)
+mi_cmd_stack_list_frames (const char *command, char **argv, int argc)
 {
   int frame_low;
   int frame_high;
@@ -181,7 +181,7 @@ mi_cmd_stack_list_frames (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_stack_info_depth (char *command, char **argv, int argc)
+mi_cmd_stack_info_depth (const char *command, char **argv, int argc)
 {
   int frame_high;
   int i;
@@ -210,7 +210,7 @@ mi_cmd_stack_info_depth (char *command, char **argv, int argc)
    values.  */
 
 void
-mi_cmd_stack_list_locals (char *command, char **argv, int argc)
+mi_cmd_stack_list_locals (const char *command, char **argv, int argc)
 {
   struct frame_info *frame;
   int raw_arg = 0;
@@ -284,7 +284,7 @@ mi_cmd_stack_list_locals (char *command, char **argv, int argc)
    values.  */
 
 void
-mi_cmd_stack_list_args (char *command, char **argv, int argc)
+mi_cmd_stack_list_args (const char *command, char **argv, int argc)
 {
   int frame_low;
   int frame_high;
@@ -405,7 +405,7 @@ mi_cmd_stack_list_args (char *command, char **argv, int argc)
    parse_print_value for possible values.  */
 
 void
-mi_cmd_stack_list_variables (char *command, char **argv, int argc)
+mi_cmd_stack_list_variables (const char *command, char **argv, int argc)
 {
   struct frame_info *frame;
   int raw_arg = 0;
@@ -691,7 +691,7 @@ list_args_or_locals (enum what_to_list what, enum print_values values,
 }
 
 void
-mi_cmd_stack_select_frame (char *command, char **argv, int argc)
+mi_cmd_stack_select_frame (const char *command, char **argv, int argc)
 {
   if (argc == 0 || argc > 1)
     error (_("-stack-select-frame: Usage: FRAME_SPEC"));
@@ -700,7 +700,7 @@ mi_cmd_stack_select_frame (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_stack_info_frame (char *command, char **argv, int argc)
+mi_cmd_stack_info_frame (const char *command, char **argv, int argc)
 {
   if (argc > 0)
     error (_("-stack-info-frame: No arguments allowed"));
diff --git a/gdb/mi/mi-cmd-target.c b/gdb/mi/mi-cmd-target.c
index 8345ad8..cdf45b9 100644
--- a/gdb/mi/mi-cmd-target.c
+++ b/gdb/mi/mi-cmd-target.c
@@ -24,7 +24,7 @@
 /* Get a file from the target.  */
 
 void
-mi_cmd_target_file_get (char *command, char **argv, int argc)
+mi_cmd_target_file_get (const char *command, char **argv, int argc)
 {
   int oind = 0;
   char *oarg;
@@ -48,7 +48,7 @@ mi_cmd_target_file_get (char *command, char **argv, int argc)
 /* Send a file to the target.  */
 
 void
-mi_cmd_target_file_put (char *command, char **argv, int argc)
+mi_cmd_target_file_put (const char *command, char **argv, int argc)
 {
   int oind = 0;
   char *oarg;
@@ -72,7 +72,7 @@ mi_cmd_target_file_put (char *command, char **argv, int argc)
 /* Delete a file on the target.  */
 
 void
-mi_cmd_target_file_delete (char *command, char **argv, int argc)
+mi_cmd_target_file_delete (const char *command, char **argv, int argc)
 {
   int oind = 0;
   char *oarg;
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index fdfc726..430c07b 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -89,7 +89,7 @@ print_varobj (struct varobj *var, enum print_values print_values,
 /* VAROBJ operations */
 
 void
-mi_cmd_var_create (char *command, char **argv, int argc)
+mi_cmd_var_create (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   CORE_ADDR frameaddr = 0;
@@ -150,7 +150,7 @@ mi_cmd_var_create (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_delete (char *command, char **argv, int argc)
+mi_cmd_var_delete (const char *command, char **argv, int argc)
 {
   char *name;
   struct varobj *var;
@@ -232,7 +232,7 @@ mi_parse_format (const char *arg)
 }
 
 void
-mi_cmd_var_set_format (char *command, char **argv, int argc)
+mi_cmd_var_set_format (const char *command, char **argv, int argc)
 {
   enum varobj_display_formats format;
   struct varobj *var;
@@ -258,7 +258,7 @@ mi_cmd_var_set_format (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_set_visualizer (char *command, char **argv, int argc)
+mi_cmd_var_set_visualizer (const char *command, char **argv, int argc)
 {
   struct varobj *var;
 
@@ -274,7 +274,7 @@ mi_cmd_var_set_visualizer (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_set_frozen (char *command, char **argv, int argc)
+mi_cmd_var_set_frozen (const char *command, char **argv, int argc)
 {
   struct varobj *var;
   int frozen;
@@ -299,7 +299,7 @@ mi_cmd_var_set_frozen (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_show_format (char *command, char **argv, int argc)
+mi_cmd_var_show_format (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   enum varobj_display_formats format;
@@ -318,7 +318,7 @@ mi_cmd_var_show_format (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_info_num_children (char *command, char **argv, int argc)
+mi_cmd_var_info_num_children (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct varobj *var;
@@ -365,7 +365,7 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
 }
 
 void
-mi_cmd_var_list_children (char *command, char **argv, int argc)
+mi_cmd_var_list_children (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct varobj *var;  
@@ -434,7 +434,7 @@ mi_cmd_var_list_children (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_info_type (char *command, char **argv, int argc)
+mi_cmd_var_info_type (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct varobj *var;
@@ -450,7 +450,7 @@ mi_cmd_var_info_type (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_info_path_expression (char *command, char **argv, int argc)
+mi_cmd_var_info_path_expression (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct varobj *var;
@@ -467,7 +467,7 @@ mi_cmd_var_info_path_expression (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_info_expression (char *command, char **argv, int argc)
+mi_cmd_var_info_expression (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   const struct language_defn *lang;
@@ -488,7 +488,7 @@ mi_cmd_var_info_expression (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_show_attributes (char *command, char **argv, int argc)
+mi_cmd_var_show_attributes (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   int attr;
@@ -512,7 +512,7 @@ mi_cmd_var_show_attributes (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
+mi_cmd_var_evaluate_expression (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct varobj *var;
@@ -579,7 +579,7 @@ mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_assign (char *command, char **argv, int argc)
+mi_cmd_var_assign (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct varobj *var;
@@ -646,7 +646,7 @@ mi_cmd_var_update_iter (struct varobj *var, void *data_pointer)
 }
 
 void
-mi_cmd_var_update (char *command, char **argv, int argc)
+mi_cmd_var_update (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct cleanup *cleanup;
@@ -797,7 +797,7 @@ varobj_update_one (struct varobj *var, enum print_values print_values,
 }
 
 void
-mi_cmd_enable_pretty_printing (char *command, char **argv, int argc)
+mi_cmd_enable_pretty_printing (const char *command, char **argv, int argc)
 {
   if (argc != 0)
     error (_("-enable-pretty-printing: no arguments allowed"));
@@ -806,7 +806,7 @@ mi_cmd_enable_pretty_printing (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_var_set_update_range (char *command, char **argv, int argc)
+mi_cmd_var_set_update_range (const char *command, char **argv, int argc)
 {
   struct varobj *var;
   int from, to;
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index fcadfff..03a11c0 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -28,7 +28,7 @@ enum print_values {
    PRINT_SIMPLE_VALUES
 };
 
-typedef void (mi_cmd_argv_ftype) (char *command, char **argv, int argc);
+typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
 
 /* Declarations of the functions implementing each command.  */
 
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index b2ac800..a769fe9 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -202,7 +202,7 @@ mi_interp::exec (const char *command)
 }
 
 void
-mi_cmd_interpreter_exec (char *command, char **argv, int argc)
+mi_cmd_interpreter_exec (const char *command, char **argv, int argc)
 {
   struct interp *interp_to_use;
   int i;
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index cf4e45a..9a87657 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -145,7 +145,7 @@ static void print_diff (struct ui_file *file, struct mi_timestamp *start,
 			struct mi_timestamp *end);
 
 void
-mi_cmd_gdb_exit (char *command, char **argv, int argc)
+mi_cmd_gdb_exit (const char *command, char **argv, int argc)
 {
   struct mi_interp *mi = (struct mi_interp *) current_interpreter ();
 
@@ -160,7 +160,7 @@ mi_cmd_gdb_exit (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_exec_next (char *command, char **argv, int argc)
+mi_cmd_exec_next (const char *command, char **argv, int argc)
 {
   /* FIXME: Should call a libgdb function, not a cli wrapper.  */
   if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
@@ -170,7 +170,7 @@ mi_cmd_exec_next (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_exec_next_instruction (char *command, char **argv, int argc)
+mi_cmd_exec_next_instruction (const char *command, char **argv, int argc)
 {
   /* FIXME: Should call a libgdb function, not a cli wrapper.  */
   if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
@@ -180,7 +180,7 @@ mi_cmd_exec_next_instruction (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_exec_step (char *command, char **argv, int argc)
+mi_cmd_exec_step (const char *command, char **argv, int argc)
 {
   /* FIXME: Should call a libgdb function, not a cli wrapper.  */
   if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
@@ -190,7 +190,7 @@ mi_cmd_exec_step (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_exec_step_instruction (char *command, char **argv, int argc)
+mi_cmd_exec_step_instruction (const char *command, char **argv, int argc)
 {
   /* FIXME: Should call a libgdb function, not a cli wrapper.  */
   if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
@@ -200,7 +200,7 @@ mi_cmd_exec_step_instruction (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_exec_finish (char *command, char **argv, int argc)
+mi_cmd_exec_finish (const char *command, char **argv, int argc)
 {
   /* FIXME: Should call a libgdb function, not a cli wrapper.  */
   if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
@@ -210,7 +210,7 @@ mi_cmd_exec_finish (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_exec_return (char *command, char **argv, int argc)
+mi_cmd_exec_return (const char *command, char **argv, int argc)
 {
   /* This command doesn't really execute the target, it just pops the
      specified number of frames.  */
@@ -229,7 +229,7 @@ mi_cmd_exec_return (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_exec_jump (char *args, char **argv, int argc)
+mi_cmd_exec_jump (const char *args, char **argv, int argc)
 {
   /* FIXME: Should call a libgdb function, not a cli wrapper.  */
   mi_execute_async_cli_command ("jump", argv, argc);
@@ -336,7 +336,7 @@ exec_reverse_continue (char **argv, int argc)
 }
 
 void
-mi_cmd_exec_continue (char *command, char **argv, int argc)
+mi_cmd_exec_continue (const char *command, char **argv, int argc)
 {
   if (argc > 0 && strcmp (argv[0], "--reverse") == 0)
     exec_reverse_continue (argv + 1, argc - 1);
@@ -366,7 +366,7 @@ interrupt_thread_callback (struct thread_info *thread, void *arg)
    mi_cmd_execute.  */
 
 void
-mi_cmd_exec_interrupt (char *command, char **argv, int argc)
+mi_cmd_exec_interrupt (const char *command, char **argv, int argc)
 {
   /* In all-stop mode, everything stops, so we don't need to try
      anything specific.  */
@@ -436,7 +436,7 @@ run_one_inferior (struct inferior *inf, void *arg)
 }
 
 void
-mi_cmd_exec_run (char *command, char **argv, int argc)
+mi_cmd_exec_run (const char *command, char **argv, int argc)
 {
   int start_p = 0;
 
@@ -504,7 +504,7 @@ find_thread_of_process (struct thread_info *ti, void *p)
 }
 
 void
-mi_cmd_target_detach (char *command, char **argv, int argc)
+mi_cmd_target_detach (const char *command, char **argv, int argc)
 {
   if (argc != 0 && argc != 1)
     error (_("Usage: -target-detach [pid | thread-group]"));
@@ -552,13 +552,13 @@ mi_cmd_target_detach (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_target_flash_erase (char *command, char **argv, int argc)
+mi_cmd_target_flash_erase (const char *command, char **argv, int argc)
 {
   flash_erase_command (NULL, 0);
 }
 
 void
-mi_cmd_thread_select (char *command, char **argv, int argc)
+mi_cmd_thread_select (const char *command, char **argv, int argc)
 {
   enum gdb_rc rc;
   char *mi_error_message;
@@ -588,7 +588,7 @@ mi_cmd_thread_select (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_thread_list_ids (char *command, char **argv, int argc)
+mi_cmd_thread_list_ids (const char *command, char **argv, int argc)
 {
   enum gdb_rc rc;
   char *mi_error_message;
@@ -606,7 +606,7 @@ mi_cmd_thread_list_ids (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_thread_info (char *command, char **argv, int argc)
+mi_cmd_thread_info (const char *command, char **argv, int argc)
 {
   if (argc != 0 && argc != 1)
     error (_("Invalid MI command"));
@@ -903,7 +903,7 @@ list_available_thread_groups (VEC (int) *ids, int recurse)
 }
 
 void
-mi_cmd_list_thread_groups (char *command, char **argv, int argc)
+mi_cmd_list_thread_groups (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct cleanup *back_to;
@@ -1005,7 +1005,7 @@ mi_cmd_list_thread_groups (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_data_list_register_names (char *command, char **argv, int argc)
+mi_cmd_data_list_register_names (const char *command, char **argv, int argc)
 {
   struct gdbarch *gdbarch;
   struct ui_out *uiout = current_uiout;
@@ -1056,7 +1056,7 @@ mi_cmd_data_list_register_names (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_data_list_changed_registers (char *command, char **argv, int argc)
+mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc)
 {
   static struct regcache *this_regs = NULL;
   struct ui_out *uiout = current_uiout;
@@ -1167,7 +1167,7 @@ register_changed_p (int regnum, struct regcache *prev_regs,
    their values is returned.  */
 
 void
-mi_cmd_data_list_register_values (char *command, char **argv, int argc)
+mi_cmd_data_list_register_values (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct frame_info *frame;
@@ -1296,7 +1296,7 @@ output_register (struct frame_info *frame, int regnum, int format,
    -data-write-register-values <format>
                                [<regnum1> <value1>...<regnumN> <valueN>] */
 void
-mi_cmd_data_write_register_values (char *command, char **argv, int argc)
+mi_cmd_data_write_register_values (const char *command, char **argv, int argc)
 {
   struct regcache *regcache;
   struct gdbarch *gdbarch;
@@ -1353,7 +1353,7 @@ mi_cmd_data_write_register_values (char *command, char **argv, int argc)
    included in double quotes.  */
 
 void
-mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
+mi_cmd_data_evaluate_expression (const char *command, char **argv, int argc)
 {
   struct value *val;
   struct value_print_options opts;
@@ -1397,7 +1397,7 @@ mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
    The number of bytes read is SIZE*ROW*COL.  */
 
 void
-mi_cmd_data_read_memory (char *command, char **argv, int argc)
+mi_cmd_data_read_memory (const char *command, char **argv, int argc)
 {
   struct gdbarch *gdbarch = get_current_arch ();
   struct ui_out *uiout = current_uiout;
@@ -1578,7 +1578,7 @@ mi_cmd_data_read_memory (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_data_read_memory_bytes (char *command, char **argv, int argc)
+mi_cmd_data_read_memory_bytes (const char *command, char **argv, int argc)
 {
   struct gdbarch *gdbarch = get_current_arch ();
   struct ui_out *uiout = current_uiout;
@@ -1679,7 +1679,7 @@ mi_cmd_data_read_memory_bytes (char *command, char **argv, int argc)
    Prints nothing.  */
 
 void
-mi_cmd_data_write_memory (char *command, char **argv, int argc)
+mi_cmd_data_write_memory (const char *command, char **argv, int argc)
 {
   struct gdbarch *gdbarch = get_current_arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
@@ -1752,7 +1752,7 @@ mi_cmd_data_write_memory (char *command, char **argv, int argc)
    COUNT: number of bytes to be filled (decimal integer).  */
 
 void
-mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc)
+mi_cmd_data_write_memory_bytes (const char *command, char **argv, int argc)
 {
   CORE_ADDR addr;
   char *cdata;
@@ -1826,7 +1826,7 @@ mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_enable_timings (char *command, char **argv, int argc)
+mi_cmd_enable_timings (const char *command, char **argv, int argc)
 {
   if (argc == 0)
     do_timings = 1;
@@ -1849,7 +1849,7 @@ mi_cmd_enable_timings (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_list_features (char *command, char **argv, int argc)
+mi_cmd_list_features (const char *command, char **argv, int argc)
 {
   if (argc == 0)
     {
@@ -1879,7 +1879,7 @@ mi_cmd_list_features (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_list_target_features (char *command, char **argv, int argc)
+mi_cmd_list_target_features (const char *command, char **argv, int argc)
 {
   if (argc == 0)
     {
@@ -1899,7 +1899,7 @@ mi_cmd_list_target_features (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_add_inferior (char *command, char **argv, int argc)
+mi_cmd_add_inferior (const char *command, char **argv, int argc)
 {
   struct inferior *inf;
 
@@ -1924,7 +1924,7 @@ get_other_inferior (struct inferior *inf, void *arg)
 }
 
 void
-mi_cmd_remove_inferior (char *command, char **argv, int argc)
+mi_cmd_remove_inferior (const char *command, char **argv, int argc)
 {
   int id;
   struct inferior *inf;
@@ -2485,7 +2485,7 @@ print_diff (struct ui_file *file, struct mi_timestamp *start,
 }
 
 void
-mi_cmd_trace_define_variable (char *command, char **argv, int argc)
+mi_cmd_trace_define_variable (const char *command, char **argv, int argc)
 {
   LONGEST initval = 0;
   struct trace_state_variable *tsv;
@@ -2511,7 +2511,7 @@ mi_cmd_trace_define_variable (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_trace_list_variables (char *command, char **argv, int argc)
+mi_cmd_trace_list_variables (const char *command, char **argv, int argc)
 {
   if (argc != 0)
     error (_("-trace-list-variables: no arguments allowed"));
@@ -2520,7 +2520,7 @@ mi_cmd_trace_list_variables (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_trace_find (char *command, char **argv, int argc)
+mi_cmd_trace_find (const char *command, char **argv, int argc)
 {
   char *mode;
 
@@ -2603,7 +2603,7 @@ mi_cmd_trace_find (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_trace_save (char *command, char **argv, int argc)
+mi_cmd_trace_save (const char *command, char **argv, int argc)
 {
   int target_saves = 0;
   int generate_ctf = 0;
@@ -2653,19 +2653,19 @@ mi_cmd_trace_save (char *command, char **argv, int argc)
 }
 
 void
-mi_cmd_trace_start (char *command, char **argv, int argc)
+mi_cmd_trace_start (const char *command, char **argv, int argc)
 {
   start_tracing (NULL);
 }
 
 void
-mi_cmd_trace_status (char *command, char **argv, int argc)
+mi_cmd_trace_status (const char *command, char **argv, int argc)
 {
   trace_status_mi (0);
 }
 
 void
-mi_cmd_trace_stop (char *command, char **argv, int argc)
+mi_cmd_trace_stop (const char *command, char **argv, int argc)
 {
   stop_tracing (NULL);
   trace_status_mi (1);
@@ -2674,7 +2674,7 @@ mi_cmd_trace_stop (char *command, char **argv, int argc)
 /* Implement the "-ada-task-info" command.  */
 
 void
-mi_cmd_ada_task_info (char *command, char **argv, int argc)
+mi_cmd_ada_task_info (const char *command, char **argv, int argc)
 {
   if (argc != 0 && argc != 1)
     error (_("Invalid MI command"));
@@ -2742,7 +2742,7 @@ print_variable_or_computed (const char *expression, enum print_values values)
 /* Implement the "-trace-frame-collected" command.  */
 
 void
-mi_cmd_trace_frame_collected (char *command, char **argv, int argc)
+mi_cmd_trace_frame_collected (const char *command, char **argv, int argc)
 {
   struct cleanup *old_chain;
   struct bp_location *tloc;
diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c
index acbb27b..6614447 100644
--- a/gdb/mi/mi-symbol-cmds.c
+++ b/gdb/mi/mi-symbol-cmds.c
@@ -27,7 +27,7 @@
    in ascending PC order.  */
 
 void
-mi_cmd_symbol_list_lines (char *command, char **argv, int argc)
+mi_cmd_symbol_list_lines (const char *command, char **argv, int argc)
 {
   struct gdbarch *gdbarch;
   char *filename;
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 15/18] -Wwrite-strings: execute_command calls with string literals
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (9 preceding siblings ...)
  2017-04-04 17:26 ` [PATCH 07/18] -Wwrite-strings: Constify work break character arrays Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-05  7:13   ` Metzger, Markus T
  2017-04-04 17:26 ` [PATCH 16/18] -Wwrite-strings: Some constification in gdb/breakpoint.c Pedro Alves
                   ` (9 subsequent siblings)
  20 siblings, 1 reply; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches

This is ugly, but it's just making the uglyness explicit.

All these places would better be calling some API function directly
instead of going through execute_command & friends...

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* event-top.c (command_line_handler): Add cast to execute_command
	call.
	* record-btrace.c (cmd_record_btrace_bts_start)
	(cmd_record_btrace_pt_start, cmd_record_btrace_start)
	(cmd_record_btrace_start): Add cast to execute_command call.
	* record-full.c (record_full_goto_insn):
	* record.c (record_start, record_stop): Add cast to
	execute_command_to_string calls.
	(cmd_record_start): Add cast to execute_command calls.
---
 gdb/event-top.c     |  2 +-
 gdb/record-btrace.c |  8 ++++----
 gdb/record-full.c   |  2 +-
 gdb/record.c        | 14 +++++++-------
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/gdb/event-top.c b/gdb/event-top.c
index 5d8d077..dd2770a 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -766,7 +766,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 ("quit", 1);
+      execute_command ((char *) "quit", 1);
     }
   else if (cmd == NULL)
     {
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index af025e2..61fba1e 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -2897,7 +2897,7 @@ cmd_record_btrace_bts_start (char *args, int from_tty)
 
   TRY
     {
-      execute_command ("target record-btrace", from_tty);
+      execute_command ((char *) "target record-btrace", from_tty);
     }
   CATCH (exception, RETURN_MASK_ALL)
     {
@@ -2919,7 +2919,7 @@ cmd_record_btrace_pt_start (char *args, int from_tty)
 
   TRY
     {
-      execute_command ("target record-btrace", from_tty);
+      execute_command ((char *) "target record-btrace", from_tty);
     }
   CATCH (exception, RETURN_MASK_ALL)
     {
@@ -2941,7 +2941,7 @@ cmd_record_btrace_start (char *args, int from_tty)
 
   TRY
     {
-      execute_command ("target record-btrace", from_tty);
+      execute_command ((char *) "target record-btrace", from_tty);
     }
   CATCH (exception, RETURN_MASK_ALL)
     {
@@ -2949,7 +2949,7 @@ cmd_record_btrace_start (char *args, int from_tty)
 
       TRY
 	{
-	  execute_command ("target record-btrace", from_tty);
+	  execute_command ((char *) "target record-btrace", from_tty);
 	}
       CATCH (exception, RETURN_MASK_ALL)
 	{
diff --git a/gdb/record-full.c b/gdb/record-full.c
index bd95acc..31ff558 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2788,7 +2788,7 @@ record_full_goto_insn (struct record_full_entry *entry,
 static void
 cmd_record_full_start (char *args, int from_tty)
 {
-  execute_command ("target record-full", from_tty);
+  execute_command ((char *) "target record-full", from_tty);
 }
 
 static void
diff --git a/gdb/record.c b/gdb/record.c
index eff8fe1..16e5b03 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 ("record", from_tty);
+	execute_command_to_string ((char *) "record", from_tty);
       else
 	error (_("Invalid format."));
     }
   else if (strcmp (method, "full") == 0)
     {
       if (format == NULL)
-	execute_command_to_string ("record full", from_tty);
+	execute_command_to_string ((char *) "record full", from_tty);
       else
 	error (_("Invalid format."));
     }
   else if (strcmp (method, "btrace") == 0)
     {
       if (format == NULL)
-	execute_command_to_string ("record btrace", from_tty);
+	execute_command_to_string ((char *) "record btrace", from_tty);
       else if (strcmp (format, "bts") == 0)
-	execute_command_to_string ("record btrace bts", from_tty);
+	execute_command_to_string ((char *) "record btrace bts", from_tty);
       else if (strcmp (format, "pt") == 0)
-	execute_command_to_string ("record btrace pt", from_tty);
+	execute_command_to_string ((char *) "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 ("record stop", from_tty);
+  execute_command_to_string ((char *) "record stop", from_tty);
 }
 
 /* See record.h.  */
@@ -265,7 +265,7 @@ show_record_debug (struct ui_file *file, int from_tty,
 static void
 cmd_record_start (char *args, int from_tty)
 {
-  execute_command ("target record-full", from_tty);
+  execute_command ((char *) "target record-full", from_tty);
 }
 
 /* Truncate the record log from the present point
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 01/18] -Wwrite-strings: Constify struct disassemble_info's disassembler_options field
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
  2017-04-04 17:26 ` [PATCH 08/18] -Wwrite-strings: Constify mi_cmd_argv_ftype's 'command' parameter Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-05  7:22   ` Nick Clifton
  2017-04-04 17:26 ` [PATCH 14/18] -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overload Pedro Alves
                   ` (18 subsequent siblings)
  20 siblings, 1 reply; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Binutils

The memory disassemble_info::disassembler_options points to is always
owned by the client.  I.e., that field is an non-owning, observing
pointer.  Thus const makes sense.

Are the include/ and opcodes/ bits OK?

Tested on x86_64 Fedora 23, built with --enable-targets=all.

include/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* dis-asm.h (disassemble_info) <disassembler_options>: Now a
	"const char *".
	(next_disassembler_option): Constify.

opcodes/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* arc-dis.c (parse_option, parse_disassembler_options): Constify.
	* arm-dis.c (parse_arm_disassembler_options): Constify.
	* ppc-dis.c (powerpc_init_dialect): Constify local.
	* vax-dis.c (parse_disassembler_options): Constify.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* arm-tdep.c (show_disassembly_style_sfunc): Constify local.
	* disasm.c (set_disassembler_options): Constify local.
	* i386-tdep.c (i386_print_insn): Remove cast and FIXME comment.
---
 gdb/arm-tdep.c    | 2 +-
 gdb/disasm.c      | 2 +-
 gdb/i386-tdep.c   | 4 +---
 include/dis-asm.h | 8 ++++----
 opcodes/arc-dis.c | 4 ++--
 opcodes/arm-dis.c | 4 ++--
 opcodes/ppc-dis.c | 2 +-
 opcodes/vax-dis.c | 2 +-
 8 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index b3c3705..ade770e 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -8562,7 +8562,7 @@ show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
   char *options = get_disassembler_options (gdbarch);
   const char *style = "";
   int len = 0;
-  char *opt;
+  const char *opt;
 
   FOR_EACH_DISASSEMBLER_OPTION (opt, options)
     if (CONST_STRNEQ (opt, "reg-names-"))
diff --git a/gdb/disasm.c b/gdb/disasm.c
index ab080e2..734db2b 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -930,7 +930,7 @@ set_disassembler_options (char *prospective_options)
   char **disassembler_options = gdbarch_disassembler_options (gdbarch);
   const disasm_options_t *valid_options;
   char *options = remove_whitespace_and_extra_commas (prospective_options);
-  char *opt;
+  const char *opt;
 
   /* Allow all architectures, even ones that do not support 'set disassembler',
      to reset their disassembler options to NULL.  */
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index ec8b5d3..70bd47c 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -4009,9 +4009,7 @@ i386_print_insn (bfd_vma pc, struct disassemble_info *info)
   gdb_assert (disassembly_flavor == att_flavor
 	      || disassembly_flavor == intel_flavor);
 
-  /* FIXME: kettenis/20020915: Until disassembler_options is properly
-     constified, cast to prevent a compiler warning.  */
-  info->disassembler_options = (char *) disassembly_flavor;
+  info->disassembler_options = disassembly_flavor;
 
   return print_insn_i386 (pc, info);
 }
diff --git a/include/dis-asm.h b/include/dis-asm.h
index f054450..2ed3d7e 100644
--- a/include/dis-asm.h
+++ b/include/dis-asm.h
@@ -210,7 +210,7 @@ typedef struct disassemble_info
   bfd_vma target2;		/* Second target address for dref2 */
 
   /* Command line options specific to the target disassembler.  */
-  char * disassembler_options;
+  const char *disassembler_options;
 
   /* If non-zero then try not disassemble beyond this address, even if
      there are values left in the buffer.  This address is the address
@@ -369,10 +369,10 @@ extern char *remove_whitespace_and_extra_commas (char *);
 extern int disassembler_options_cmp (const char *, const char *);
 
 /* A helper function for FOR_EACH_DISASSEMBLER_OPTION.  */
-static inline char *
-next_disassembler_option (char *options)
+static inline const char *
+next_disassembler_option (const char *options)
 {
-  char *opt = strchr (options, ',');
+  const char *opt = strchr (options, ',');
   if (opt != NULL)
     opt++;
   return opt;
diff --git a/opcodes/arc-dis.c b/opcodes/arc-dis.c
index 3afd253..4beca68 100644
--- a/opcodes/arc-dis.c
+++ b/opcodes/arc-dis.c
@@ -733,7 +733,7 @@ operand_iterator_next (struct arc_operand_iterator *iter,
 /* Helper for parsing the options.  */
 
 static void
-parse_option (char *option)
+parse_option (const char *option)
 {
   if (CONST_STRNEQ (option, "dsp"))
     add_to_decodelist (DSP, NONE);
@@ -772,7 +772,7 @@ parse_option (char *option)
 /* Go over the options list and parse it.  */
 
 static void
-parse_disassembler_options (char *options)
+parse_disassembler_options (const char *options)
 {
   if (options == NULL)
     return;
diff --git a/opcodes/arm-dis.c b/opcodes/arm-dis.c
index e4f99b8..a3e53db 100644
--- a/opcodes/arm-dis.c
+++ b/opcodes/arm-dis.c
@@ -6101,9 +6101,9 @@ arm_symbol_is_valid (asymbol * sym,
 /* Parse the string of disassembler options.  */
 
 static void
-parse_arm_disassembler_options (char *options)
+parse_arm_disassembler_options (const char *options)
 {
-  char *opt;
+  const char *opt;
 
   FOR_EACH_DISASSEMBLER_OPTION (opt, options)
     {
diff --git a/opcodes/ppc-dis.c b/opcodes/ppc-dis.c
index ee8016a..188e90a 100644
--- a/opcodes/ppc-dis.c
+++ b/opcodes/ppc-dis.c
@@ -344,7 +344,7 @@ powerpc_init_dialect (struct disassemble_info *info)
       break;
     }
 
-  char *opt;
+  const char *opt;
   FOR_EACH_DISASSEMBLER_OPTION (opt, info->disassembler_options)
     {
       ppc_cpu_t new_cpu = 0;
diff --git a/opcodes/vax-dis.c b/opcodes/vax-dis.c
index ff240e4..4642702 100644
--- a/opcodes/vax-dis.c
+++ b/opcodes/vax-dis.c
@@ -117,7 +117,7 @@ static bfd_vma *     entry_addr = NULL;
    there's no symbol table.  Returns TRUE upon success, FALSE otherwise.  */
 
 static bfd_boolean
-parse_disassembler_options (char * options)
+parse_disassembler_options (const char *options)
 {
   const char * entry_switch = "entry:";
 
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 05/18] -Wwrite-strings: Constify warning_pre_print
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (3 preceding siblings ...)
  2017-04-04 17:26 ` [PATCH 02/18] -Wwrite-strings: Constify macroexp.c:init_shared_buffer Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-04 17:26 ` [PATCH 04/18] -Wwrite-strings: Constify shell_escape and plug make_command leak Pedro Alves
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches

-Wwrite-strings flags a warning here:

  char *warning_pre_print = "\nwarning: ";

	* main.c (captured_main_1): Use gdb::unique_xmalloc_ptr to manage
	the memory of the temporary warning_pre_print override.
	* utils.c (warning_pre_print): Constify.
	* utils.h (warning_pre_print): Constify.
---
 gdb/main.c  | 6 ++++--
 gdb/utils.c | 2 +-
 gdb/utils.h | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/gdb/main.c b/gdb/main.c
index 30e27c2..df4b111 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -545,7 +545,9 @@ captured_main_1 (struct captured_main_args *context)
 #endif
 
   /* Prefix warning messages with the command name.  */
-  warning_pre_print = xstrprintf ("%s: warning: ", gdb_program_name);
+  gdb::unique_xmalloc_ptr<char> tmp_warn_preprint
+    (xstrprintf ("%s: warning: ", gdb_program_name));
+  warning_pre_print = tmp_warn_preprint.get ();
 
   if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
     perror_warning_with_name (_("error finding working directory"));
@@ -972,7 +974,7 @@ captured_main_1 (struct captured_main_args *context)
     }
 
   /* Set off error and warning messages with a blank line.  */
-  xfree (warning_pre_print);
+  tmp_warn_preprint.reset ();
   warning_pre_print = _("\nwarning: ");
 
   /* Read and execute the system-wide gdbinit file, if it exists.
diff --git a/gdb/utils.c b/gdb/utils.c
index 39798cc..6b8f2f7 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -122,7 +122,7 @@ show_sevenbit_strings (struct ui_file *file, int from_tty,
 
 /* String to be printed before warning messages, if any.  */
 
-char *warning_pre_print = "\nwarning: ";
+const char *warning_pre_print = "\nwarning: ";
 
 int pagination_enabled = 1;
 static void
diff --git a/gdb/utils.h b/gdb/utils.h
index fb75f2e..2380bd7 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -298,7 +298,7 @@ extern void (*deprecated_error_begin_hook) (void);
 
 /* Message to be printed before the warning message, when a warning occurs.  */
 
-extern char *warning_pre_print;
+extern const char *warning_pre_print;
 
 extern void error_stream (const string_file &) ATTRIBUTE_NORETURN;
 
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 14/18] -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overload
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
  2017-04-04 17:26 ` [PATCH 08/18] -Wwrite-strings: Constify mi_cmd_argv_ftype's 'command' parameter Pedro Alves
  2017-04-04 17:26 ` [PATCH 01/18] -Wwrite-strings: Constify struct disassemble_info's disassembler_options field Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-04 18:37   ` Sergio Durigan Junior
  2017-04-04 17:26 ` [PATCH 02/18] -Wwrite-strings: Constify macroexp.c:init_shared_buffer Pedro Alves
                   ` (17 subsequent siblings)
  20 siblings, 1 reply; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches

-Wwrite-strings flags code like:

   static char *keywords[] = {"command", "from_tty", "to_string", NULL };

as needing "(char *)" casts, because string literals are "const char []".

We can get rid of the casts by changing the array like this:

 -  static char *keywords[] = {"command", "from_tty", "to_string", NULL };
 +  static const char *keywords[] = {"command", "from_tty", "to_string", NULL };

However, passing the array to PyArg_ParseTupleAndKeywords no longer
works OOTB, because PyArg_ParseTupleAndKeywords expects a "char **":

  PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw,
                              const char *format,
			      char *keywords[], ...);

and "const char **" is not implicitly convertible to "char **".  C++
is more tolerant that C here WRT aliasing, and a const_cast<char **>
would be fine.

However, to avoid having all callers add the 'const_cast<char **>'
themselves, this commit define a PyArg_ParseTupleAndKeywords overload
here with a corresponding 'keywords' parameter type that does the cast
in a single place.

As in the PyGetSetDef patch, I'd be fine with naming this
gdb_PyArg_ParseTupleAndKeywords instead, if people would find having
our own overload confusing.

BTW, this API issue was discussed years ago in the python-dev list:

 https://mail.python.org/pipermail/python-dev/2006-February/060689.html

... and an overload for C++ was suggested in there somewhere.
Unfortunately, it was never added.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* python/py-arch.c (archpy_disassemble): Constify 'keywords'
	array.
	* python/py-cmd.c (cmdpy_init): Constify 'keywords' array.
	* python/py-finishbreakpoint.c (bpfinishpy_init): Constify
	'keywords' array.
	* python/py-inferior.c (infpy_read_memory, infpy_write_memory)
	(infpy_search_memory): Constify 'keywords' array.
	* python/py-objfile.c (objfpy_add_separate_debug_file)
	(gdbpy_lookup_objfile): Constify 'keywords' array.
	* python/py-symbol.c (gdbpy_lookup_symbol)
	(gdbpy_lookup_global_symbol): Constify 'keywords' array.
	* python/py-type.c (gdbpy_lookup_type): Constify 'keywords' array.
	* python/py-value.c (valpy_lazy_string, valpy_string): Constify
	'keywords' array.
	* python/python.c (execute_gdb_command, gdbpy_write, gdbpy_flush):
	Constify 'keywords' array.
	* python/python-internal.h (PyArg_ParseTupleAndKeywords): New
	function overload.
---
 gdb/python/py-arch.c             |  2 +-
 gdb/python/py-breakpoint.c       |  4 ++--
 gdb/python/py-cmd.c              |  6 +++---
 gdb/python/py-finishbreakpoint.c |  2 +-
 gdb/python/py-inferior.c         |  6 +++---
 gdb/python/py-objfile.c          |  4 ++--
 gdb/python/py-symbol.c           |  4 ++--
 gdb/python/py-type.c             |  2 +-
 gdb/python/py-value.c            |  4 ++--
 gdb/python/python-internal.h     | 25 +++++++++++++++++++++++++
 gdb/python/python.c              |  6 +++---
 11 files changed, 45 insertions(+), 20 deletions(-)

diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 71d2989..48fae32 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -116,7 +116,7 @@ archpy_name (PyObject *self, PyObject *args)
 static PyObject *
 archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
 {
-  static char *keywords[] = { "start_pc", "end_pc", "count", NULL };
+  static const char *keywords[] = { "start_pc", "end_pc", "count", NULL };
   CORE_ADDR start, end = 0;
   CORE_ADDR pc;
   gdb_py_ulongest start_temp;
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 724a7ed..2043d42 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -637,8 +637,8 @@ bppy_get_ignore_count (PyObject *self, void *closure)
 static int
 bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 {
-  static char *keywords[] = { "spec", "type", "wp_class", "internal",
-			      "temporary", NULL };
+  static const char *keywords[] = { "spec", "type", "wp_class", "internal",
+				    "temporary", NULL };
   const char *spec;
   int type = bp_breakpoint;
   int access_type = hw_write;
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 3aaf7f9..8f61d9c 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -490,8 +490,8 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
   char *docstring = NULL;
   struct cmd_list_element **cmd_list;
   char *cmd_name, *pfx_name;
-  static char *keywords[] = { "name", "command_class", "completer_class",
-			      "prefix", NULL };
+  static const char *keywords[] = { "name", "command_class", "completer_class",
+				    "prefix", NULL };
   PyObject *is_prefix = NULL;
   int cmp;
 
@@ -506,7 +506,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
 
   if (! PyArg_ParseTupleAndKeywords (args, kw, "si|iO",
 				     keywords, &name, &cmdtype,
-			  &completetype, &is_prefix))
+				     &completetype, &is_prefix))
     return -1;
 
   if (cmdtype != no_class && cmdtype != class_run
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 106fe34..9d43d55 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -156,7 +156,7 @@ bpfinishpy_post_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
 static int
 bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 {
-  static char *keywords[] = { "frame", "internal", NULL };
+  static const char *keywords[] = { "frame", "internal", NULL };
   struct finish_breakpoint_object *self_bpfinish =
       (struct finish_breakpoint_object *) self;
   PyObject *frame_obj = NULL;
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 46a0aad..8b4782b 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -435,7 +435,7 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
   CORE_ADDR addr, length;
   gdb_byte *buffer = NULL;
   PyObject *addr_obj, *length_obj, *result;
-  static char *keywords[] = { "address", "length", NULL };
+  static const char *keywords[] = { "address", "length", NULL };
 
   if (! PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords,
 				     &addr_obj, &length_obj))
@@ -494,7 +494,7 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
   const gdb_byte *buffer;
   CORE_ADDR addr, length;
   PyObject *addr_obj, *length_obj = NULL;
-  static char *keywords[] = { "address", "buffer", "length", NULL };
+  static const char *keywords[] = { "address", "buffer", "length", NULL };
 #ifdef IS_PY3K
   Py_buffer pybuf;
 
@@ -643,7 +643,7 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
 {
   struct gdb_exception except = exception_none;
   CORE_ADDR start_addr, length;
-  static char *keywords[] = { "address", "length", "pattern", NULL };
+  static const char *keywords[] = { "address", "length", "pattern", NULL };
   PyObject *start_addr_obj, *length_obj;
   Py_ssize_t pattern_size;
   const gdb_byte *buffer;
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 105d88a..ad1ec4f 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -432,7 +432,7 @@ objfpy_is_valid (PyObject *self, PyObject *args)
 static PyObject *
 objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
 {
-  static char *keywords[] = { "file_name", NULL };
+  static const char *keywords[] = { "file_name", NULL };
   objfile_object *obj = (objfile_object *) self;
   const char *file_name;
 
@@ -559,7 +559,7 @@ objfpy_lookup_objfile_by_build_id (const char *build_id)
 PyObject *
 gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
 {
-  static char *keywords[] = { "name", "by_build_id", NULL };
+  static const char *keywords[] = { "name", "by_build_id", NULL };
   const char *name;
   PyObject *by_build_id_obj = NULL;
   int by_build_id;
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index b71cfb4..de44c06 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -373,7 +373,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
   int domain = VAR_DOMAIN;
   struct field_of_this_result is_a_field_of_this;
   const char *name;
-  static char *keywords[] = { "name", "block", "domain", NULL };
+  static const char *keywords[] = { "name", "block", "domain", NULL };
   struct symbol *symbol = NULL;
   PyObject *block_obj = NULL, *sym_obj, *bool_obj;
   const struct block *block = NULL;
@@ -443,7 +443,7 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
 {
   int domain = VAR_DOMAIN;
   const char *name;
-  static char *keywords[] = { "name", "domain", NULL };
+  static const char *keywords[] = { "name", "domain", NULL };
   struct symbol *symbol = NULL;
   PyObject *sym_obj;
 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index f071006..4f4ede1 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1347,7 +1347,7 @@ type_object_to_type (PyObject *obj)
 PyObject *
 gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
 {
-  static char *keywords[] = { "name", "block", NULL };
+  static const char *keywords[] = { "name", "block", NULL };
   const char *type_name = NULL;
   struct type *type = NULL;
   PyObject *block_obj = NULL;
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index bb42e8b..1a82af5 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -431,7 +431,7 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
   gdb_py_longest length = -1;
   struct value *value = ((value_object *) self)->value;
   const char *user_encoding = NULL;
-  static char *keywords[] = { "encoding", "length", NULL };
+  static const char *keywords[] = { "encoding", "length", NULL };
   PyObject *str_obj = NULL;
 
   if (!PyArg_ParseTupleAndKeywords (args, kw, "|s" GDB_PY_LL_ARG, keywords,
@@ -526,7 +526,7 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw)
   const char *user_encoding = NULL;
   const char *la_encoding = NULL;
   struct type *char_type;
-  static char *keywords[] = { "encoding", "errors", "length", NULL };
+  static const char *keywords[] = { "encoding", "errors", "length", NULL };
 
   if (!PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
 				    &user_encoding, &errors, &length))
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 8fc89cd..76f7443 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -318,6 +318,31 @@ struct gdb_PyGetSetDef : PyGetSetDef
 
 #define PyGetSetDef gdb_PyGetSetDef
 
+/* The 'keywords' parameter of PyArg_ParseTupleAndKeywords has type
+   'char **'.  However, string literals are const in C++, and so to
+   avoid casting at every keyword array definition, we'll need to make
+   the keywords array an array of 'const char *'.  To avoid having all
+   callers add a 'const_cast<char **>' themselves when passing such an
+   array through 'char **', we define a PyArg_ParseTupleAndKeywords
+   overload here with a corresponding 'keywords' parameter type that
+   does the cast in a single place.  */
+
+static inline int
+PyArg_ParseTupleAndKeywords (PyObject *args, PyObject *kw,
+			     const char *format, const char **keywords, ...)
+{
+  va_list ap;
+  int res;
+
+  va_start (ap, keywords);
+  res = PyArg_VaParseTupleAndKeywords (args, kw, format,
+				       const_cast<char **> (keywords),
+				       ap);
+  va_end (ap);
+
+  return res;
+}
+
 /* In order to be able to parse symtab_and_line_to_sal_object function
    a real symtab_and_line structure is needed.  */
 #include "symtab.h"
diff --git a/gdb/python/python.c b/gdb/python/python.c
index a7aff53..5a46493 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -572,7 +572,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
   const char *arg;
   PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
   int from_tty, to_string;
-  static char *keywords[] = {"command", "from_tty", "to_string", NULL };
+  static const char *keywords[] = { "command", "from_tty", "to_string", NULL };
 
   if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
 				     &PyBool_Type, &from_tty_obj,
@@ -1047,7 +1047,7 @@ static PyObject *
 gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
 {
   const char *arg;
-  static char *keywords[] = {"text", "stream", NULL };
+  static const char *keywords[] = { "text", "stream", NULL };
   int stream_type = 0;
 
   if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &arg,
@@ -1088,7 +1088,7 @@ gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
 static PyObject *
 gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
 {
-  static char *keywords[] = {"stream", NULL };
+  static const char *keywords[] = { "stream", NULL };
   int stream_type = 0;
 
   if (! PyArg_ParseTupleAndKeywords (args, kw, "|i", keywords,
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 02/18] -Wwrite-strings: Constify macroexp.c:init_shared_buffer
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (2 preceding siblings ...)
  2017-04-04 17:26 ` [PATCH 14/18] -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overload Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-04 17:26 ` [PATCH 05/18] -Wwrite-strings: Constify warning_pre_print Pedro Alves
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches

There's one call in the file that passes a string literal, like:

	init_shared_buffer (&va_arg_name, "__VA_ARGS__",
				  strlen ("__VA_ARGS__"));

Instead of adding a cast here, make init_shared_buffer take a 'const
char *', and remove the several casts in the file that are made
obsolete.

gdb/ChangeLog:
yyyy-mm-dd Pedro Alves  <palves@redhat.com>

	* macroexp.c (macro_buffer::shared): Now a bool.
	(init_buffer): Update.
	(init_shared_buffer): Constify 'addr' parameter.
	(substitute_args, expand, macro_expand, macro_expand_next): Remove
	casts.
---
 gdb/macroexp.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index 3cc2d0b..5537d9d 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -53,8 +53,9 @@ struct macro_buffer
 
   /* Zero if TEXT can be safely realloc'ed (i.e., it's its own malloc
      block).  Non-zero if TEXT is actually pointing into the middle of
-     some other block, and we shouldn't reallocate it.  */
-  int shared;
+     some other block, or to a string literal, and we shouldn't
+     reallocate it.  */
+  bool shared;
 
   /* For detecting token splicing. 
 
@@ -85,19 +86,22 @@ init_buffer (struct macro_buffer *b, int n)
   else
     b->text = NULL;
   b->len = 0;
-  b->shared = 0;
+  b->shared = false;
   b->last_token = -1;
 }
 
 
 /* Set the macro buffer *BUF to refer to the LEN bytes at ADDR, as a
    shared substring.  */
+
 static void
-init_shared_buffer (struct macro_buffer *buf, char *addr, int len)
+init_shared_buffer (struct macro_buffer *buf, const char *addr, int len)
 {
-  buf->text = addr;
+  /* The function accept a "const char *" addr so that clients can
+     pass in string literals without casts.  */
+  buf->text = (char *) addr;
   buf->len = len;
-  buf->shared = 1;
+  buf->shared = true;
   buf->size = 0;
   buf->last_token = -1;
 }
@@ -980,7 +984,7 @@ substitute_args (struct macro_buffer *dest,
      lexed.  */
   char *lookahead_rl_start;
 
-  init_shared_buffer (&replacement_list, (char *) def->replacement,
+  init_shared_buffer (&replacement_list, def->replacement,
                       strlen (def->replacement));
 
   gdb_assert (dest->len == 0);
@@ -1199,7 +1203,7 @@ expand (const char *id,
     {
       struct macro_buffer replacement_list;
 
-      init_shared_buffer (&replacement_list, (char *) def->replacement,
+      init_shared_buffer (&replacement_list, def->replacement,
                           strlen (def->replacement));
 
       scan (dest, &replacement_list, &new_no_loop, lookup_func, lookup_baton);
@@ -1236,7 +1240,7 @@ expand (const char *id,
 		     substitution parameter is the name of the formal
 		     argument without the "...".  */
 		  init_shared_buffer (&va_arg_name,
-				      (char *) def->argv[def->argc - 1],
+				      def->argv[def->argc - 1],
 				      len - 3);
 		  is_varargs = 1;
 		}
@@ -1415,7 +1419,7 @@ macro_expand (const char *source,
   struct macro_buffer src, dest;
   struct cleanup *back_to;
 
-  init_shared_buffer (&src, (char *) source, strlen (source));
+  init_shared_buffer (&src, source, strlen (source));
 
   init_buffer (&dest, 0);
   dest.last_token = 0;
@@ -1448,7 +1452,7 @@ macro_expand_next (const char **lexptr,
   struct cleanup *back_to;
 
   /* Set up SRC to refer to the input text, pointed to by *lexptr.  */
-  init_shared_buffer (&src, (char *) *lexptr, strlen (*lexptr));
+  init_shared_buffer (&src, *lexptr, strlen (*lexptr));
 
   /* Set up DEST to receive the expansion, if there is one.  */
   init_buffer (&dest, 0);
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 09/18] -Wwrite-strings: MI -info-os
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (7 preceding siblings ...)
  2017-04-04 17:26 ` [PATCH 06/18] -Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-04 17:26 ` [PATCH 07/18] -Wwrite-strings: Constify work break character arrays Pedro Alves
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches

-Wwrite-strings flags this attempt to convert a string literal to
 "char *":

      info_osdata_command ("", 0);

info_osdata_command is a command function.  We could address this by
simply passing NULL instead of "".  However, I went a little bit
further and added a new function that is called by both the CLI and
MI.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* mi/mi-cmd-info.c (mi_cmd_info_os): Call info_osdata instead of
	info_osdata_command.
	* osdata.c (info_osdata_command): Rename to ...
	(info_osdata): ... this.  Constify 'type' parameter, and remove
	the 'from_tty' parameter.  Accept NULL TYPE.
	(info_osdata_command): New function.
	* osdata.h (info_osdata_command): Remove declaration.
	(info_osdata): New declaration.
---
 gdb/mi/mi-cmd-info.c |  4 ++--
 gdb/osdata.c         | 13 +++++++++++--
 gdb/osdata.h         |  6 +++++-
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/gdb/mi/mi-cmd-info.c b/gdb/mi/mi-cmd-info.c
index eba1ca2..1a96d6f 100644
--- a/gdb/mi/mi-cmd-info.c
+++ b/gdb/mi/mi-cmd-info.c
@@ -106,10 +106,10 @@ mi_cmd_info_os (const char *command, char **argv, int argc)
   switch (argc)
     {
     case 0:
-      info_osdata_command ("", 0);
+      info_osdata (NULL);
       break;
     case 1:
-      info_osdata_command (argv[0], 0);
+      info_osdata (argv[0]);
       break;
     default:
       error (_("Usage: -info-os [INFOTYPE]"));
diff --git a/gdb/osdata.c b/gdb/osdata.c
index d63ff5a..4b33ccb 100644
--- a/gdb/osdata.c
+++ b/gdb/osdata.c
@@ -287,7 +287,7 @@ get_osdata_column (struct osdata_item *item, const char *name)
 }
 
 void
-info_osdata_command (char *type, int from_tty)
+info_osdata (const char *type)
 {
   struct ui_out *uiout = current_uiout;
   struct osdata *osdata = NULL;
@@ -297,12 +297,15 @@ info_osdata_command (char *type, int from_tty)
   int nrows;
   int col_to_skip = -1;
 
+  if (type == NULL)
+    type = "";
+
   osdata = get_osdata (type);
   old_chain = make_cleanup_osdata_free (osdata);
 
   nrows = VEC_length (osdata_item_s, osdata->items);
 
-  if (!type && nrows == 0)
+  if (*type == '\0' && nrows == 0)
     error (_("Available types of OS data not reported."));
   
   if (!VEC_empty (osdata_item_s, osdata->items))
@@ -407,6 +410,12 @@ info_osdata_command (char *type, int from_tty)
   do_cleanups (old_chain);
 }
 
+static void
+info_osdata_command (char *arg, int from_tty)
+{
+  info_osdata (arg);
+}
+
 extern initialize_file_ftype _initialize_osdata; /* -Wmissing-prototypes */
 
 void
diff --git a/gdb/osdata.h b/gdb/osdata.h
index bda0112..5921384 100644
--- a/gdb/osdata.h
+++ b/gdb/osdata.h
@@ -49,6 +49,10 @@ void osdata_free (struct osdata *);
 struct cleanup *make_cleanup_osdata_free (struct osdata *data);
 struct osdata *get_osdata (const char *type);
 const char *get_osdata_column (struct osdata_item *item, const char *name);
-void info_osdata_command (char *type, int from_tty);
+
+/* Dump TYPE info to the current uiout builder.  If TYPE is either
+   NULL or empty, then dump the top level table that lists the
+   available types of OS data.  */
+void info_osdata (const char *type);
 
 #endif /* OSDATA_H */
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 04/18] -Wwrite-strings: Constify shell_escape and plug make_command leak
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (4 preceding siblings ...)
  2017-04-04 17:26 ` [PATCH 05/18] -Wwrite-strings: Constify warning_pre_print Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-04 17:26 ` [PATCH 03/18] -Wwrite-strings: Don't initialize string command variables to empty string Pedro Alves
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves	 <palves@redhat.com>

	* cli/cli-cmds.c (shell_escape): Constify 'arg' parameter.
	(shell_command): New function.
	(make_command): Use std::string.
	(init_cli_cmds): Register shell_command instead of shell_escape.
---
 gdb/cli/cli-cmds.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index b5c9d0b..f7ffb6d 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -82,7 +82,7 @@ static void show_user (char *, int);
 
 static void make_command (char *, int);
 
-static void shell_escape (char *, int);
+static void shell_escape (const char *, int);
 
 static void edit_command (char *, int);
 
@@ -735,7 +735,7 @@ echo_command (char *text, int from_tty)
 }
 
 static void
-shell_escape (char *arg, int from_tty)
+shell_escape (const char *arg, int from_tty)
 {
 #if defined(CANT_FORK) || \
       (!defined(HAVE_WORKING_VFORK) && !defined(HAVE_WORKING_FORK))
@@ -795,6 +795,14 @@ shell_escape (char *arg, int from_tty)
 #endif /* Can fork.  */
 }
 
+/* Implementation of the "shell" command.  */
+
+static void
+shell_command (char *arg, int from_tty)
+{
+  shell_escape (arg, from_tty);
+}
+
 static void
 edit_command (char *arg, int from_tty)
 {
@@ -1306,18 +1314,14 @@ disassemble_command (char *arg, int from_tty)
 static void
 make_command (char *arg, int from_tty)
 {
-  char *p;
-
   if (arg == 0)
-    p = "make";
+    shell_escape ("make", from_tty);
   else
     {
-      p = (char *) xmalloc (sizeof ("make ") + strlen (arg));
-      strcpy (p, "make ");
-      strcpy (p + sizeof ("make ") - 1, arg);
-    }
+      std::string cmd = std::string ("make ") + arg;
 
-  shell_escape (p, from_tty);
+      shell_escape (cmd.c_str (), from_tty);
+    }
 }
 
 static void
@@ -1881,7 +1885,7 @@ from the target."),
 		  _("Generic command for showing gdb debugging flags"),
 		  &showdebuglist, "show debug ", 0, &showlist);
 
-  c = add_com ("shell", class_support, shell_escape, _("\
+  c = add_com ("shell", class_support, shell_command, _("\
 Execute the rest of the line as a shell command.\n\
 With no arguments, run an inferior shell."));
   set_cmd_completer (c, filename_completer);
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 16/18] -Wwrite-strings: Some constification in gdb/breakpoint.c
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (10 preceding siblings ...)
  2017-04-04 17:26 ` [PATCH 15/18] -Wwrite-strings: execute_command calls with string literals Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-04 17:31 ` [PATCH 10/18] -Wwrite-strings: gdbserver's 'port' parsing Pedro Alves
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches

The main motivation here is avoiding having to write a couple casts
like these:

     if (!arg)
  -    arg = "";
  +    arg = (char *) "";

in catch_exception_command_1 and catch_exec_command_1.

That requires making ep_parse_optional_if_clause and
check_for_argument take pointers to const strings.  I then tried
propagating the resulting constification all the way, but that was
spriraling out of control, so instead I settled for keeping const and
non-const overloads.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* break-catch-throw.c (handle_gnu_v3_exceptions): Constify
	'cond_string' parameter.
	(extract_exception_regexp): Constify 'string' parameter.
	(catch_exception_command_1): Constify.

	* breakpoint.c (init_catchpoint)
	(create_fork_vfork_event_catchpoint): Constify 'cond_string'
	parameter.
	(ep_parse_optional_if_clause, catch_fork_command_1)
	(catch_exec_command_1): Constify.
	* breakpoint.h (init_catchpoint): Constify 'cond_string'
	parameter.
	(ep_parse_optional_if_clause): Constify.
	* cli/cli-utils.c (remove_trailing_whitespace)
	(check_for_argument): Constify.
	* cli/cli-utils.h (remove_trailing_whitespace): Constify and add
	non-const overload.
	(check_for_argument): Likewise.
---
 gdb/break-catch-throw.c | 23 +++++++++++++----------
 gdb/breakpoint.c        | 26 ++++++++++++++------------
 gdb/breakpoint.h        |  4 ++--
 gdb/cli/cli-utils.c     |  6 +++---
 gdb/cli/cli-utils.h     | 21 +++++++++++++++++++--
 5 files changed, 51 insertions(+), 29 deletions(-)

diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index f7c7cc8..2e18d2a 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -383,7 +383,8 @@ print_recreate_exception_catchpoint (struct breakpoint *b,
 }
 
 static void
-handle_gnu_v3_exceptions (int tempflag, char *except_rx, char *cond_string,
+handle_gnu_v3_exceptions (int tempflag, char *except_rx,
+			  const char *cond_string,
 			  enum exception_event_kind ex_event, int from_tty)
 {
   regex_t *pattern = NULL;
@@ -425,18 +426,18 @@ handle_gnu_v3_exceptions (int tempflag, char *except_rx, char *cond_string,
    the end of the string.  */
 
 static char *
-extract_exception_regexp (char **string)
+extract_exception_regexp (const char **string)
 {
-  char *start;
-  char *last, *last_space;
+  const char *start;
+  const char *last, *last_space;
 
-  start = skip_spaces (*string);
+  start = skip_spaces_const (*string);
 
   last = start;
   last_space = start;
   while (*last != '\0')
     {
-      char *if_token = last;
+      const char *if_token = last;
 
       /* Check for the "if".  */
       if (check_for_argument (&if_token, "if", 2))
@@ -444,7 +445,7 @@ extract_exception_regexp (char **string)
 
       /* No "if" token here.  Skip to the next word start.  */
       last_space = skip_to_space (last);
-      last = skip_spaces (last_space);
+      last = skip_spaces_const (last_space);
     }
 
   *string = last;
@@ -457,16 +458,18 @@ extract_exception_regexp (char **string)
    commands.  */
 
 static void
-catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
+catch_exception_command_1 (enum exception_event_kind ex_event,
+			   char *arg_entry,
 			   int tempflag, int from_tty)
 {
   char *except_rx;
-  char *cond_string = NULL;
+  const char *cond_string = NULL;
   struct cleanup *cleanup;
+  const char *arg = arg_entry;
 
   if (!arg)
     arg = "";
-  arg = skip_spaces (arg);
+  arg = skip_spaces_const (arg);
 
   except_rx = extract_exception_regexp (&arg);
   cleanup = make_cleanup (xfree, except_rx);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index f0db3e4..4cd7a00 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8582,7 +8582,7 @@ catch_unload_command_1 (char *arg, int from_tty,
 void
 init_catchpoint (struct breakpoint *b,
 		 struct gdbarch *gdbarch, int tempflag,
-		 char *cond_string,
+		 const char *cond_string,
 		 const struct breakpoint_ops *ops)
 {
   struct symtab_and_line sal;
@@ -8613,7 +8613,7 @@ install_breakpoint (int internal, struct breakpoint *b, int update_gll)
 
 static void
 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
-				    int tempflag, char *cond_string,
+				    int tempflag, const char *cond_string,
                                     const struct breakpoint_ops *ops)
 {
   struct fork_catchpoint *c = new fork_catchpoint ();
@@ -11779,10 +11779,10 @@ until_break_command (char *arg, int from_tty, int anywhere)
    it updates arg to point to the first character following the parsed
    if clause in the arg string.  */
 
-char *
-ep_parse_optional_if_clause (char **arg)
+const char *
+ep_parse_optional_if_clause (const char **arg)
 {
-  char *cond_string;
+  const char *cond_string;
 
   if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
     return NULL;
@@ -11792,7 +11792,7 @@ ep_parse_optional_if_clause (char **arg)
 
   /* Skip any extra leading whitespace, and record the start of the
      condition string.  */
-  *arg = skip_spaces (*arg);
+  *arg = skip_spaces_const (*arg);
   cond_string = *arg;
 
   /* Assume that the condition occupies the remainder of the arg
@@ -11813,11 +11813,12 @@ typedef enum
 catch_fork_kind;
 
 static void
-catch_fork_command_1 (char *arg, int from_tty, 
+catch_fork_command_1 (char *arg_entry, int from_tty,
 		      struct cmd_list_element *command)
 {
+  const char *arg = arg_entry;
   struct gdbarch *gdbarch = get_current_arch ();
-  char *cond_string = NULL;
+  const char *cond_string = NULL;
   catch_fork_kind fork_kind;
   int tempflag;
 
@@ -11827,7 +11828,7 @@ catch_fork_command_1 (char *arg, int from_tty,
 
   if (!arg)
     arg = "";
-  arg = skip_spaces (arg);
+  arg = skip_spaces_const (arg);
 
   /* The allowed syntax is:
      catch [v]fork
@@ -11860,19 +11861,20 @@ catch_fork_command_1 (char *arg, int from_tty,
 }
 
 static void
-catch_exec_command_1 (char *arg, int from_tty, 
+catch_exec_command_1 (char *arg_entry, int from_tty,
 		      struct cmd_list_element *command)
 {
+  const char *arg = arg_entry;
   struct exec_catchpoint *c;
   struct gdbarch *gdbarch = get_current_arch ();
   int tempflag;
-  char *cond_string = NULL;
+  const char *cond_string = NULL;
 
   tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
 
   if (!arg)
     arg = "";
-  arg = skip_spaces (arg);
+  arg = skip_spaces_const (arg);
 
   /* The allowed syntax is:
      catch exec
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 7d08057..6940270 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1295,7 +1295,7 @@ extern void
 
 extern void init_catchpoint (struct breakpoint *b,
 			     struct gdbarch *gdbarch, int tempflag,
-			     char *cond_string,
+			     const char *cond_string,
 			     const struct breakpoint_ops *ops);
 
 /* Add breakpoint B on the breakpoint list, and notify the user, the
@@ -1641,7 +1641,7 @@ extern struct gdbarch *get_sal_arch (struct symtab_and_line sal);
 
 extern void breakpoint_free_objfile (struct objfile *objfile);
 
-extern char *ep_parse_optional_if_clause (char **arg);
+extern const char *ep_parse_optional_if_clause (const char **arg);
 
 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" to
    UIOUT iff debugging multiple threads.  */
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index b353c18..8eac7c4 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -238,8 +238,8 @@ number_is_in_list (const char *list, int number)
 
 /* See documentation in cli-utils.h.  */
 
-char *
-remove_trailing_whitespace (const char *start, char *s)
+const char *
+remove_trailing_whitespace (const char *start, const char *s)
 {
   while (s > start && isspace (*(s - 1)))
     --s;
@@ -288,7 +288,7 @@ extract_arg (char **arg)
 /* See documentation in cli-utils.h.  */
 
 int
-check_for_argument (char **str, char *arg, int arg_len)
+check_for_argument (const char **str, const char *arg, int arg_len)
 {
   if (strncmp (*str, arg, arg_len) == 0
       && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index c80bae0..b1207b6 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -137,7 +137,15 @@ extern int number_is_in_list (const char *list, int number);
 /* Reverse S to the last non-whitespace character without skipping past
    START.  */
 
-extern char *remove_trailing_whitespace (const char *start, char *s);
+extern const char *remove_trailing_whitespace (const char *start,
+					       const char *s);
+
+/* Same, for non-const S.  */
+static inline char *
+remove_trailing_whitespace (const char *start, char *s)
+{
+  return (char *) remove_trailing_whitespace (start, (const char *) s);
+}
 
 /* A helper function to extract an argument from *ARG.  An argument is
    delimited by whitespace.  The return value is either NULL if no
@@ -156,6 +164,15 @@ extern char *extract_arg_const (const char **arg);
    string.  The argument must also either be at the end of the string,
    or be followed by whitespace.  Returns 1 if it finds the argument,
    0 otherwise.  If the argument is found, it updates *STR.  */
-extern int check_for_argument (char **str, char *arg, int arg_len);
+extern int check_for_argument (const char **str, const char *arg, int arg_len);
+
+/* Same, for non-const STR.  */
+
+static inline int
+check_for_argument (char **str, const char *arg, int arg_len)
+{
+  return check_for_argument (const_cast<const char **> (str),
+			     arg, arg_len);
+}
 
 #endif /* CLI_UTILS_H */
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 06/18] -Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (6 preceding siblings ...)
  2017-04-04 17:26 ` [PATCH 03/18] -Wwrite-strings: Don't initialize string command variables to empty string Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-04 18:44   ` John Baldwin
  2017-04-04 17:26 ` [PATCH 09/18] -Wwrite-strings: MI -info-os Pedro Alves
                   ` (12 subsequent siblings)
  20 siblings, 1 reply; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches

-Wwrite-strings flagged a missing cast for example here:

   static char *
   ravenscar_extra_thread_info (struct target_ops *self, struct thread_info *tp)
   {
     return "Ravenscar task";

Since callers are not supposed to free the string returned by these
methods, change the methods' signature to return const strings.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* aix-thread.c (aix_thread_pid_to_str)
	(aix_thread_extra_thread_info): Constify.
	* bsd-kvm.c (bsd_kvm_pid_to_str): Constify.
	* bsd-uthread.c (bsd_uthread_extra_thread_info)
	(bsd_uthread_pid_to_str): Constify.
	* corelow.c (core_pid_to_str): Constify.
	* darwin-nat.c (darwin_pid_to_str): Constify.
	* fbsd-nat.c (fbsd_pid_to_str): Constify.
	* fbsd-tdep.c (fbsd_core_pid_to_str, gdbarch_core_pid_to_str):
	Constify.
	* gnu-nat.c (gnu_pid_to_str): Constify.
	* go32-nat.c (go32_pid_to_str): Constify.
	* i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Constify.
	* inf-ptrace.c (inf_ptrace_pid_to_str): Constify.
	* inferior.c (inferior_pid_to_str): Constify.
	* linux-nat.c (linux_nat_pid_to_str): Constify.
	* linux-tdep.c (linux_core_pid_to_str): Constify.
	* linux-thread-db.c (thread_db_pid_to_str)
	(thread_db_extra_thread_info): Constify.
	* nto-tdep.c (nto_extra_thread_info): Constify.
	* nto-tdep.h (nto_extra_thread_info): Constify.
	* obsd-nat.c (obsd_pid_to_str): Constify.
	* procfs.c (procfs_pid_to_str): Constify.
	* ravenscar-thread.c (ravenscar_extra_thread_info)
	(ravenscar_pid_to_str): Constify.
	* remote-sim.c (gdbsim_pid_to_str): Constify.
	* remote.c (remote_threads_extra_info, remote_pid_to_str):
	Constify.
	* sol-thread.c (solaris_pid_to_str): Constify.
	* sol2-tdep.c (sol2_core_pid_to_str): Constify.
	* sol2-tdep.h (sol2_core_pid_to_str): Constify.
	* target.c (default_pid_to_str, target_pid_to_str)
	(normal_pid_to_str, default_pid_to_str): Constify.
	* target.h (target_ops::to_pid_to_str)
	(target_ops::to_extra_thread_info): Constify.
	(target_pid_to_str, normal_pid_to_str): Constify.
	* windows-nat.c (windows_pid_to_str): Constify.
	* gdbarch.sh (core_pid_to_str): Constify.
	* target-delegates.c: Regenerate.
	* gdbarch.h, gdbarch.c: Regenerate.
---
 gdb/aix-thread.c       |  4 ++--
 gdb/bsd-kvm.c          |  2 +-
 gdb/bsd-uthread.c      |  4 ++--
 gdb/corelow.c          |  2 +-
 gdb/darwin-nat.c       |  4 ++--
 gdb/fbsd-nat.c         |  2 +-
 gdb/fbsd-tdep.c        |  2 +-
 gdb/gdbarch.c          |  2 +-
 gdb/gdbarch.h          |  4 ++--
 gdb/gdbarch.sh         |  2 +-
 gdb/gnu-nat.c          |  2 +-
 gdb/go32-nat.c         |  2 +-
 gdb/i386-cygwin-tdep.c |  2 +-
 gdb/inf-ptrace.c       |  2 +-
 gdb/inferior.c         |  2 +-
 gdb/linux-nat.c        |  2 +-
 gdb/linux-tdep.c       |  2 +-
 gdb/linux-thread-db.c  |  4 ++--
 gdb/nto-tdep.c         |  2 +-
 gdb/nto-tdep.h         |  2 +-
 gdb/obsd-nat.c         |  2 +-
 gdb/procfs.c           |  4 ++--
 gdb/ravenscar-thread.c |  8 ++++----
 gdb/remote-sim.c       |  2 +-
 gdb/remote.c           |  4 ++--
 gdb/sol-thread.c       |  2 +-
 gdb/sol2-tdep.c        |  2 +-
 gdb/sol2-tdep.h        |  2 +-
 gdb/target-delegates.c | 18 +++++++++---------
 gdb/target.c           |  8 ++++----
 gdb/target.h           |  8 ++++----
 gdb/windows-nat.c      |  2 +-
 32 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index 3fbe96a..05024df 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -1725,7 +1725,7 @@ aix_thread_thread_alive (struct target_ops *ops, ptid_t ptid)
 /* Return a printable representation of composite PID for use in
    "info threads" output.  */
 
-static char *
+static const char *
 aix_thread_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   static char *ret = NULL;
@@ -1745,7 +1745,7 @@ aix_thread_pid_to_str (struct target_ops *ops, ptid_t ptid)
 /* Return a printable representation of extra information about
    THREAD, for use in "info threads" output.  */
 
-static char *
+static const char *
 aix_thread_extra_thread_info (struct target_ops *self,
 			      struct thread_info *thread)
 {
diff --git a/gdb/bsd-kvm.c b/gdb/bsd-kvm.c
index 9f4f9e7..98e2428 100644
--- a/gdb/bsd-kvm.c
+++ b/gdb/bsd-kvm.c
@@ -329,7 +329,7 @@ bsd_kvm_thread_alive (struct target_ops *ops,
   return 1;
 }
 
-static char *
+static const char *
 bsd_kvm_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   static char buf[64];
diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index 08b8f36..5d4775c 100644
--- a/gdb/bsd-uthread.c
+++ b/gdb/bsd-uthread.c
@@ -491,7 +491,7 @@ static char *bsd_uthread_state[] =
 /* Return a string describing th state of the thread specified by
    INFO.  */
 
-static char *
+static const char *
 bsd_uthread_extra_thread_info (struct target_ops *self,
 			       struct thread_info *info)
 {
@@ -511,7 +511,7 @@ bsd_uthread_extra_thread_info (struct target_ops *self,
   return NULL;
 }
 
-static char *
+static const char *
 bsd_uthread_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   if (ptid_get_tid (ptid) != 0)
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 656c754..3267c37 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -965,7 +965,7 @@ core_read_description (struct target_ops *target)
   return target->beneath->to_read_description (target->beneath);
 }
 
-static char *
+static const char *
 core_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   static char buf[64];
diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index edee1be..e509240 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -107,7 +107,7 @@ static void darwin_create_inferior (struct target_ops *ops, char *exec_file,
 
 static void darwin_files_info (struct target_ops *ops);
 
-static char *darwin_pid_to_str (struct target_ops *ops, ptid_t tpid);
+static const char *darwin_pid_to_str (struct target_ops *ops, ptid_t tpid);
 
 static int darwin_thread_alive (struct target_ops *ops, ptid_t tpid);
 
@@ -1970,7 +1970,7 @@ darwin_files_info (struct target_ops *ops)
 {
 }
 
-static char *
+static const char *
 darwin_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   static char buf[80];
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index d99f436..96781cd 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -368,7 +368,7 @@ fbsd_thread_alive (struct target_ops *ops, ptid_t ptid)
 /* Convert PTID to a string.  Returns the string in a static
    buffer.  */
 
-static char *
+static const char *
 fbsd_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   lwpid_t lwp;
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index 46875d8..b834ce3 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -32,7 +32,7 @@
 
 /* This is how we want PTIDs from core files to be printed.  */
 
-static char *
+static const char *
 fbsd_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
 {
   static char buf[80];
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 87eafb2..6debb10 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -3691,7 +3691,7 @@ gdbarch_core_pid_to_str_p (struct gdbarch *gdbarch)
   return gdbarch->core_pid_to_str != NULL;
 }
 
-char *
+const char *
 gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
 {
   gdb_assert (gdbarch != NULL);
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 34f82a7..3264c44 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -906,8 +906,8 @@ extern void set_gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
 
 extern int gdbarch_core_pid_to_str_p (struct gdbarch *gdbarch);
 
-typedef char * (gdbarch_core_pid_to_str_ftype) (struct gdbarch *gdbarch, ptid_t ptid);
-extern char * gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid);
+typedef const char * (gdbarch_core_pid_to_str_ftype) (struct gdbarch *gdbarch, ptid_t ptid);
+extern const char * gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid);
 extern void set_gdbarch_core_pid_to_str (struct gdbarch *gdbarch, gdbarch_core_pid_to_str_ftype *core_pid_to_str);
 
 /* How the core target extracts the name of a thread from a core file. */
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 39b1f94..c471b73 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -745,7 +745,7 @@ M:ULONGEST:core_xfer_shared_libraries:gdb_byte *readbuf, ULONGEST offset, ULONGE
 M:ULONGEST:core_xfer_shared_libraries_aix:gdb_byte *readbuf, ULONGEST offset, ULONGEST len:readbuf, offset, len
 
 # How the core target converts a PTID from a core file to a string.
-M:char *:core_pid_to_str:ptid_t ptid:ptid
+M:const char *:core_pid_to_str:ptid_t ptid:ptid
 
 # How the core target extracts the name of a thread from a core file.
 M:const char *:core_thread_name:struct thread_info *thr:thr
diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index 7efb3c1..b2a975d 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -2652,7 +2652,7 @@ proc_string (struct proc *proc)
   return tid_str;
 }
 
-static char *
+static const char *
 gnu_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   struct inf *inf = gnu_current_inf;
diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c
index 1fca8e2..d2d8d7a 100644
--- a/gdb/go32-nat.c
+++ b/gdb/go32-nat.c
@@ -941,7 +941,7 @@ go32_thread_alive (struct target_ops *ops, ptid_t ptid)
   return !ptid_equal (ptid, null_ptid);
 }
 
-static char *
+static const char *
 go32_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   return normal_pid_to_str (ptid);
diff --git a/gdb/i386-cygwin-tdep.c b/gdb/i386-cygwin-tdep.c
index f200d39..c8139ff 100644
--- a/gdb/i386-cygwin-tdep.c
+++ b/gdb/i386-cygwin-tdep.c
@@ -178,7 +178,7 @@ windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
 
 /* This is how we want PTIDs from core files to be printed.  */
 
-static char *
+static const char *
 i386_windows_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
 {
   static char buf[80];
diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
index f912d28..c911001 100644
--- a/gdb/inf-ptrace.c
+++ b/gdb/inf-ptrace.c
@@ -619,7 +619,7 @@ inf_ptrace_files_info (struct target_ops *ignore)
 		   target_pid_to_str (inferior_ptid));
 }
 
-static char *
+static const char *
 inf_ptrace_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   return normal_pid_to_str (ptid);
diff --git a/gdb/inferior.c b/gdb/inferior.c
index c4ab6d7..4ae265e 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -542,7 +542,7 @@ number_of_inferiors (void)
 /* Converts an inferior process id to a string.  Like
    target_pid_to_str, but special cases the null process.  */
 
-static char *
+static const char *
 inferior_pid_to_str (int pid)
 {
   if (pid != 0)
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index dff0da5..b06e400 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -3940,7 +3940,7 @@ linux_nat_update_thread_list (struct target_ops *ops)
     }
 }
 
-static char *
+static const char *
 linux_nat_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   static char buf[64];
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 1a3e48d..016aadf 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -407,7 +407,7 @@ linux_has_shared_address_space (struct gdbarch *gdbarch)
 
 /* This is how we want PTIDs from core files to be printed.  */
 
-static char *
+static const char *
 linux_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
 {
   static char buf[80];
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index b131fc2..0e2607b 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -1372,7 +1372,7 @@ thread_db_update_thread_list (struct target_ops *ops)
   ops->beneath->to_update_thread_list (ops->beneath);
 }
 
-static char *
+static const char *
 thread_db_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   struct thread_info *thread_info = find_thread_ptid (ptid);
@@ -1397,7 +1397,7 @@ thread_db_pid_to_str (struct target_ops *ops, ptid_t ptid)
 /* Return a string describing the state of the thread specified by
    INFO.  */
 
-static char *
+static const char *
 thread_db_extra_thread_info (struct target_ops *self,
 			     struct thread_info *info)
 {
diff --git a/gdb/nto-tdep.c b/gdb/nto-tdep.c
index 96a3af3..04ad06c 100644
--- a/gdb/nto-tdep.c
+++ b/gdb/nto-tdep.c
@@ -408,7 +408,7 @@ static const char *nto_thread_state_str[] =
   "NET_REPLY"	/* 20 0x14 */
 };
 
-char *
+const char *
 nto_extra_thread_info (struct target_ops *self, struct thread_info *ti)
 {
   if (ti && ti->priv
diff --git a/gdb/nto-tdep.h b/gdb/nto-tdep.h
index 457bbc9..afe3452 100644
--- a/gdb/nto-tdep.h
+++ b/gdb/nto-tdep.h
@@ -176,7 +176,7 @@ void nto_dummy_supply_regset (struct regcache *regcache, char *regs);
 
 int nto_in_dynsym_resolve_code (CORE_ADDR pc);
 
-char *nto_extra_thread_info (struct target_ops *self, struct thread_info *);
+const char *nto_extra_thread_info (struct target_ops *self, struct thread_info *);
 
 LONGEST nto_read_auxv_from_initial_stack (CORE_ADDR inital_stack,
 					  gdb_byte *readbuf,
diff --git a/gdb/obsd-nat.c b/gdb/obsd-nat.c
index 3a73cbd..e2336a0 100644
--- a/gdb/obsd-nat.c
+++ b/gdb/obsd-nat.c
@@ -35,7 +35,7 @@
 
 #ifdef PT_GET_THREAD_FIRST
 
-static char *
+static const char *
 obsd_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   if (ptid_get_lwp (ptid) != 0)
diff --git a/gdb/procfs.c b/gdb/procfs.c
index b860f16..71d4b64 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -135,7 +135,7 @@ static target_xfer_partial_ftype procfs_xfer_partial;
 static int procfs_thread_alive (struct target_ops *ops, ptid_t);
 
 static void procfs_update_thread_list (struct target_ops *ops);
-static char *procfs_pid_to_str (struct target_ops *, ptid_t);
+static const char *procfs_pid_to_str (struct target_ops *, ptid_t);
 
 static int proc_find_memory_regions (struct target_ops *self,
 				     find_memory_region_ftype, void *);
@@ -4691,7 +4691,7 @@ procfs_thread_alive (struct target_ops *ops, ptid_t ptid)
 /* Convert PTID to a string.  Returns the string in a static
    buffer.  */
 
-static char *
+static const char *
 procfs_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   static char buf[80];
diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c
index d1bd97f..1f89ea2 100644
--- a/gdb/ravenscar-thread.c
+++ b/gdb/ravenscar-thread.c
@@ -54,8 +54,8 @@ static const char ravenscar_runtime_initializer[] =
 
 static void ravenscar_update_thread_list (struct target_ops *ops);
 static ptid_t ravenscar_running_thread (void);
-static char *ravenscar_extra_thread_info (struct target_ops *self,
-					  struct thread_info *tp);
+static const char *ravenscar_extra_thread_info (struct target_ops *self,
+						struct thread_info *tp);
 static int ravenscar_thread_alive (struct target_ops *ops, ptid_t ptid);
 static void ravenscar_fetch_registers (struct target_ops *ops,
                                        struct regcache *regcache, int regnum);
@@ -241,7 +241,7 @@ ravenscar_running_thread (void)
     return ptid_build (ptid_get_pid (base_ptid), 0, tid);
 }
 
-static char *
+static const char *
 ravenscar_extra_thread_info (struct target_ops *self, struct thread_info *tp)
 {
   return "Ravenscar task";
@@ -254,7 +254,7 @@ ravenscar_thread_alive (struct target_ops *ops, ptid_t ptid)
   return 1;
 }
 
-static char *
+static const char *
 ravenscar_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   static char buf[30];
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 0e8d657..4396d4b 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -1270,7 +1270,7 @@ gdbsim_thread_alive (struct target_ops *ops, ptid_t ptid)
 /* Convert a thread ID to a string.  Returns the string in a static
    buffer.  */
 
-static char *
+static const char *
 gdbsim_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   return normal_pid_to_str (ptid);
diff --git a/gdb/remote.c b/gdb/remote.c
index 2791ac8..956645a 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -3354,7 +3354,7 @@ remote_update_thread_list (struct target_ops *ops)
  * Optional: targets are not required to implement this function.
  */
 
-static char *
+static const char *
 remote_threads_extra_info (struct target_ops *self, struct thread_info *tp)
 {
   struct remote_state *rs = get_remote_state ();
@@ -10946,7 +10946,7 @@ init_remote_threadtests (void)
 /* Convert a thread ID to a string.  Returns the string in a static
    buffer.  */
 
-static char *
+static const char *
 remote_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   static char buf[64];
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
index 7c1620a..39dae86 100644
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -1021,7 +1021,7 @@ ps_lgetLDT (gdb_ps_prochandle_t ph, lwpid_t lwpid,
 
 /* Convert PTID to printable form.  */
 
-static char *
+static const char *
 solaris_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   static char buf[100];
diff --git a/gdb/sol2-tdep.c b/gdb/sol2-tdep.c
index 89eda53..7a06aa7 100644
--- a/gdb/sol2-tdep.c
+++ b/gdb/sol2-tdep.c
@@ -40,7 +40,7 @@ sol2_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
 /* This is how we want PTIDs from Solaris core files to be
    printed.  */
 
-char *
+const char *
 sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
 {
   static char buf[80];
diff --git a/gdb/sol2-tdep.h b/gdb/sol2-tdep.h
index d2382e3..56dd898 100644
--- a/gdb/sol2-tdep.h
+++ b/gdb/sol2-tdep.h
@@ -24,6 +24,6 @@ struct gdbarch;
 
 CORE_ADDR sol2_skip_solib_resolver (struct gdbarch *, CORE_ADDR);
 
-char *sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid);
+const char *sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid);
 
 #endif /* sol2-tdep.h */
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index 470b7e4..88e3e0b 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -1502,17 +1502,17 @@ debug_update_thread_list (struct target_ops *self)
   fputs_unfiltered (")\n", gdb_stdlog);
 }
 
-static char *
+static const char *
 delegate_pid_to_str (struct target_ops *self, ptid_t arg1)
 {
   self = self->beneath;
   return self->to_pid_to_str (self, arg1);
 }
 
-static char *
+static const char *
 debug_pid_to_str (struct target_ops *self, ptid_t arg1)
 {
-  char * result;
+  const char * result;
   fprintf_unfiltered (gdb_stdlog, "-> %s->to_pid_to_str (...)\n", debug_target.to_shortname);
   result = debug_target.to_pid_to_str (&debug_target, arg1);
   fprintf_unfiltered (gdb_stdlog, "<- %s->to_pid_to_str (", debug_target.to_shortname);
@@ -1520,28 +1520,28 @@ debug_pid_to_str (struct target_ops *self, ptid_t arg1)
   fputs_unfiltered (", ", gdb_stdlog);
   target_debug_print_ptid_t (arg1);
   fputs_unfiltered (") = ", gdb_stdlog);
-  target_debug_print_char_p (result);
+  target_debug_print_const_char_p (result);
   fputs_unfiltered ("\n", gdb_stdlog);
   return result;
 }
 
-static char *
+static const char *
 delegate_extra_thread_info (struct target_ops *self, struct thread_info *arg1)
 {
   self = self->beneath;
   return self->to_extra_thread_info (self, arg1);
 }
 
-static char *
+static const char *
 tdefault_extra_thread_info (struct target_ops *self, struct thread_info *arg1)
 {
   return NULL;
 }
 
-static char *
+static const char *
 debug_extra_thread_info (struct target_ops *self, struct thread_info *arg1)
 {
-  char * result;
+  const char * result;
   fprintf_unfiltered (gdb_stdlog, "-> %s->to_extra_thread_info (...)\n", debug_target.to_shortname);
   result = debug_target.to_extra_thread_info (&debug_target, arg1);
   fprintf_unfiltered (gdb_stdlog, "<- %s->to_extra_thread_info (", debug_target.to_shortname);
@@ -1549,7 +1549,7 @@ debug_extra_thread_info (struct target_ops *self, struct thread_info *arg1)
   fputs_unfiltered (", ", gdb_stdlog);
   target_debug_print_struct_thread_info_p (arg1);
   fputs_unfiltered (") = ", gdb_stdlog);
-  target_debug_print_char_p (result);
+  target_debug_print_const_char_p (result);
   fputs_unfiltered ("\n", gdb_stdlog);
   return result;
 }
diff --git a/gdb/target.c b/gdb/target.c
index 7c286ab..fd9181e 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -103,7 +103,7 @@ static int dummy_find_memory_regions (struct target_ops *self,
 static char *dummy_make_corefile_notes (struct target_ops *self,
 					bfd *ignore1, int *ignore2);
 
-static char *default_pid_to_str (struct target_ops *ops, ptid_t ptid);
+static const char *default_pid_to_str (struct target_ops *ops, ptid_t ptid);
 
 static enum exec_direction_kind default_execution_direction
     (struct target_ops *self);
@@ -2303,7 +2303,7 @@ default_target_wait (struct target_ops *ops,
   return minus_one_ptid;
 }
 
-char *
+const char *
 target_pid_to_str (ptid_t ptid)
 {
   return (*current_target.to_pid_to_str) (&current_target, ptid);
@@ -3344,7 +3344,7 @@ generic_mourn_inferior (void)
 /* Convert a normal process ID to a string.  Returns the string in a
    static buffer.  */
 
-char *
+const char *
 normal_pid_to_str (ptid_t ptid)
 {
   static char buf[32];
@@ -3353,7 +3353,7 @@ normal_pid_to_str (ptid_t ptid)
   return buf;
 }
 
-static char *
+static const char *
 default_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   return normal_pid_to_str (ptid);
diff --git a/gdb/target.h b/gdb/target.h
index 943a0e2..6553f49 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -639,9 +639,9 @@ struct target_ops
       TARGET_DEFAULT_RETURN (0);
     void (*to_update_thread_list) (struct target_ops *)
       TARGET_DEFAULT_IGNORE ();
-    char *(*to_pid_to_str) (struct target_ops *, ptid_t)
+    const char *(*to_pid_to_str) (struct target_ops *, ptid_t)
       TARGET_DEFAULT_FUNC (default_pid_to_str);
-    char *(*to_extra_thread_info) (struct target_ops *, struct thread_info *)
+    const char *(*to_extra_thread_info) (struct target_ops *, struct thread_info *)
       TARGET_DEFAULT_RETURN (NULL);
     const char *(*to_thread_name) (struct target_ops *, struct thread_info *)
       TARGET_DEFAULT_RETURN (NULL);
@@ -1851,9 +1851,9 @@ extern int target_is_non_stop_p (void);
    `process xyz', but on some systems it may contain
    `process xyz thread abc'.  */
 
-extern char *target_pid_to_str (ptid_t ptid);
+extern const char *target_pid_to_str (ptid_t ptid);
 
-extern char *normal_pid_to_str (ptid_t ptid);
+extern const char *normal_pid_to_str (ptid_t ptid);
 
 /* Return a short string describing extra information about PID,
    e.g. "sleeping", "runnable", "running on LWP 3".  Null return value
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 76313db..85f2030 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -2807,7 +2807,7 @@ windows_close (struct target_ops *self)
 }
 
 /* Convert pid to printable format.  */
-static char *
+static const char *
 windows_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   static char buf[80];
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 03/18] -Wwrite-strings: Don't initialize string command variables to empty string
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (5 preceding siblings ...)
  2017-04-04 17:26 ` [PATCH 04/18] -Wwrite-strings: Constify shell_escape and plug make_command leak Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-04 17:26 ` [PATCH 06/18] -Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info Pedro Alves
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches

-Wwrite-strings flags these initializations as requiring a cast.
However, these variables are command variables, and as such point to
heap-allocated memory.  The initial allocation is always done when the
corresponding command is registered.  E.g.,:

    dprintf_function = xstrdup ("printf");
    add_setshow_string_cmd ("dprintf-function", class_support,
			    &dprintf_function, _("\
  Set the function to use for dynamic printf"), _("\
  Show the function to use for dynamic printf"), NULL,
			    update_dprintf_commands, NULL,
			    &setlist, &showlist);

That's why we never reach a bogus attempt to free these string
literals.

So, just drop the incorrect initializations.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (dprintf_function, dprintf_channel): Don't initialize.
	* tracepoint.c (default_collect): Don't initialize.
---
 gdb/breakpoint.c | 4 ++--
 gdb/tracepoint.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index ab6e9c8..f0db3e4 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -345,7 +345,7 @@ static const char *dprintf_style = dprintf_style_gdb;
    copied into the command, so it can be anything that GDB can
    evaluate to a callable address, not necessarily a function name.  */
 
-static char *dprintf_function = "";
+static char *dprintf_function;
 
 /* The channel to use for dynamic printf if the preferred style is to
    call into the inferior; if a nonempty string, it will be passed to
@@ -355,7 +355,7 @@ static char *dprintf_function = "";
    "stderr", this could be an app-specific expression like
    "mystreams[curlogger]".  */
 
-static char *dprintf_channel = "";
+static char *dprintf_channel;
 
 /* True if dprintf commands should continue to operate even if GDB
    has disconnected.  */
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 2da6fdd..87ef141 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -139,7 +139,7 @@ static struct traceframe_info *traceframe_info;
 static struct cmd_list_element *tfindlist;
 
 /* List of expressions to collect by default at each tracepoint hit.  */
-char *default_collect = "";
+char *default_collect;
 
 static int disconnected_tracing;
 
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 07/18] -Wwrite-strings: Constify work break character arrays
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (8 preceding siblings ...)
  2017-04-04 17:26 ` [PATCH 09/18] -Wwrite-strings: MI -info-os Pedro Alves
@ 2017-04-04 17:26 ` Pedro Alves
  2017-04-05  8:46   ` Philipp Rudo
  2017-04-04 17:26 ` [PATCH 15/18] -Wwrite-strings: execute_command calls with string literals Pedro Alves
                   ` (10 subsequent siblings)
  20 siblings, 1 reply; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:26 UTC (permalink / raw)
  To: gdb-patches

-Wwrite-strings flags several cases of missing casts around
initializations like:

   static char *gdb_completer_command_word_break_characters =
    " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";

Obviously these could/should be const.  However, while at it, there's
no need for these variables to be pointers instead of arrays.  They
are never changed to point to anything else.

Unfortunately, readline's rl_completer_word_break_characters is "char
*", not "const char *".  So we always need a cast somewhere.  The
approach taken here is to add a new
set_rl_completer_word_break_characters function that becomes the only
place that writes to rl_completer_word_break_characters, and thus the
single place that needs the cast.

gdb/ChangeLog:
yyyy-mm-dd Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_completer_word_break_characters): Now a const
	array.
	(ada_get_gdb_completer_word_break_characters): Constify.
	* completer.c (gdb_completer_command_word_break_characters)
	(gdb_completer_file_name_break_characters)
	(gdb_completer_quote_characters): Now const arrays.
	(get_gdb_completer_quote_characters): Constify.
	(set_rl_completer_word_break_characters): New function.
	(set_gdb_completion_word_break_characters)
	(complete_line_internal): Use it.
	* completer.h (get_gdb_completer_quote_characters): Constify.
	(set_rl_completer_word_break_characters): Declare.
	* f-lang.c (f_word_break_characters): Constify.
	* language.c (default_word_break_characters): Constify.
	* language.h (language_defn::la_word_break_characters): Constify.
	(default_word_break_characters): Constify.
	* top.c (init_main): Use set_rl_completer_word_break_characters.
---
 gdb/ada-lang.c  |  4 ++--
 gdb/completer.c | 59 ++++++++++++++++++++++++++++++++++-----------------------
 gdb/completer.h |  8 +++++++-
 gdb/f-lang.c    |  2 +-
 gdb/language.c  |  2 +-
 gdb/language.h  |  4 ++--
 gdb/top.c       |  2 +-
 7 files changed, 49 insertions(+), 32 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 9b91e0c..d31e058 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -317,7 +317,7 @@ static unsigned int varsize_limit;
 
 /* FIXME: brobecker/2003-09-17: No longer a const because it is
    returned by a function that does not return a const char *.  */
-static char *ada_completer_word_break_characters =
+static const char ada_completer_word_break_characters[] =
 #ifdef VMS
   " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
 #else
@@ -558,7 +558,7 @@ add_angle_brackets (const char *str)
   return result;
 }
 
-static char *
+static const char *
 ada_get_gdb_completer_word_break_characters (void)
 {
   return ada_completer_word_break_characters;
diff --git a/gdb/completer.c b/gdb/completer.c
index 45adc62..9183e2a 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -84,29 +84,30 @@ char *line_completion_function (const char *text, int matches,
    readline library sees one in any of the current completion strings,
    it thinks that the string needs to be quoted and automatically
    supplies a leading quote.  */
-static char *gdb_completer_command_word_break_characters =
+static const char gdb_completer_command_word_break_characters[] =
 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
 
 /* When completing on file names, we remove from the list of word
    break characters any characters that are commonly used in file
    names, such as '-', '+', '~', etc.  Otherwise, readline displays
    incorrect completion candidates.  */
-#ifdef HAVE_DOS_BASED_FILE_SYSTEM
 /* MS-DOS and MS-Windows use colon as part of the drive spec, and most
    programs support @foo style response files.  */
-static char *gdb_completer_file_name_break_characters = " \t\n*|\"';?><@";
+static const char gdb_completer_file_name_break_characters[] =
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  " \t\n*|\"';?><@";
 #else
-static char *gdb_completer_file_name_break_characters = " \t\n*|\"';:?><";
+  " \t\n*|\"';:?><";
 #endif
 
 /* Characters that can be used to quote completion strings.  Note that
    we can't include '"' because the gdb C parser treats such quoted
    sequences as strings.  */
-static char *gdb_completer_quote_characters = "'";
+static const char gdb_completer_quote_characters[] = "'";
 \f
 /* Accessor for some completer data that may interest other files.  */
 
-char *
+const char *
 get_gdb_completer_quote_characters (void)
 {
   return gdb_completer_quote_characters;
@@ -652,16 +653,26 @@ expression_completer (struct cmd_list_element *ignore,
 /* See definition in completer.h.  */
 
 void
+set_rl_completer_word_break_characters (const char *break_chars)
+{
+  rl_completer_word_break_characters = (char *) break_chars;
+}
+
+/* See definition in completer.h.  */
+
+void
 set_gdb_completion_word_break_characters (completer_ftype *fn)
 {
+  const char *break_chars;
+
   /* So far we are only interested in differentiating filename
      completers from everything else.  */
   if (fn == filename_completer)
-    rl_completer_word_break_characters
-      = gdb_completer_file_name_break_characters;
+    break_chars = gdb_completer_file_name_break_characters;
   else
-    rl_completer_word_break_characters
-      = gdb_completer_command_word_break_characters;
+    break_chars = gdb_completer_command_word_break_characters;
+
+  set_rl_completer_word_break_characters (break_chars);
 }
 
 /* Here are some useful test cases for completion.  FIXME: These
@@ -743,8 +754,8 @@ complete_line_internal (const char *text,
      then we will switch to the special word break set for command
      strings, which leaves out the '-' character used in some
      commands.  */
-  rl_completer_word_break_characters =
-    current_language->la_word_break_characters();
+  set_rl_completer_word_break_characters
+    (current_language->la_word_break_characters());
 
   /* Decide whether to complete on a list of gdb commands or on
      symbols.  */
@@ -821,8 +832,8 @@ complete_line_internal (const char *text,
 	    }
 	  /* Ensure that readline does the right thing with respect to
 	     inserting quotes.  */
-	  rl_completer_word_break_characters =
-	    gdb_completer_command_word_break_characters;
+	  set_rl_completer_word_break_characters
+	    (gdb_completer_command_word_break_characters);
 	}
     }
   else
@@ -848,8 +859,8 @@ complete_line_internal (const char *text,
 
 		  /* Ensure that readline does the right thing
 		     with respect to inserting quotes.  */
-		  rl_completer_word_break_characters =
-		    gdb_completer_command_word_break_characters;
+		  set_rl_completer_word_break_characters
+		    (gdb_completer_command_word_break_characters);
 		}
 	      else if (reason == handle_help)
 		list = NULL;
@@ -857,8 +868,8 @@ complete_line_internal (const char *text,
 		{
 		  if (reason != handle_brkchars)
 		    list = complete_on_enum (c->enums, p, word);
-		  rl_completer_word_break_characters =
-		    gdb_completer_command_word_break_characters;
+		  set_rl_completer_word_break_characters
+		    (gdb_completer_command_word_break_characters);
 		}
 	      else
 		{
@@ -879,8 +890,8 @@ complete_line_internal (const char *text,
 			     && strchr (gdb_completer_file_name_break_characters, p[-1]) == NULL;
 			   p--)
 			;
-		      rl_completer_word_break_characters =
-			gdb_completer_file_name_break_characters;
+		      set_rl_completer_word_break_characters
+			(gdb_completer_file_name_break_characters);
 		    }
 		  if (reason == handle_brkchars
 		      && c->completer_handle_brkchars != NULL)
@@ -913,8 +924,8 @@ complete_line_internal (const char *text,
 
 	      /* Ensure that readline does the right thing
 		 with respect to inserting quotes.  */
-	      rl_completer_word_break_characters =
-		gdb_completer_command_word_break_characters;
+	      set_rl_completer_word_break_characters
+		(gdb_completer_command_word_break_characters);
 	    }
 	}
       else if (reason == handle_help)
@@ -947,8 +958,8 @@ complete_line_internal (const char *text,
 				    p[-1]) == NULL;
 		       p--)
 		    ;
-		  rl_completer_word_break_characters =
-		    gdb_completer_file_name_break_characters;
+		  set_rl_completer_word_break_characters
+		    (gdb_completer_file_name_break_characters);
 		}
 	      if (reason == handle_brkchars
 		  && c->completer_handle_brkchars != NULL)
diff --git a/gdb/completer.h b/gdb/completer.h
index 416b313..2aa1987 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -99,10 +99,16 @@ extern VEC (char_ptr) *reg_or_group_completer (struct cmd_list_element *,
 extern VEC (char_ptr) *reggroup_completer (struct cmd_list_element *,
 					   const char *, const char *);
 
-extern char *get_gdb_completer_quote_characters (void);
+extern const char *get_gdb_completer_quote_characters (void);
 
 extern char *gdb_completion_word_break_characters (void);
 
+/* Set the word break characters array to BREAK_CHARS.  This function
+   is useful as const-correct alternative to direct assignment to
+   rl_completer_word_break_characters, which is "char *",
+   not "const char *".  */
+extern void set_rl_completer_word_break_characters (const char *break_chars);
+
 /* Set the word break characters array to the corresponding set of
    chars, based on FN.  This function is useful for cases when the
    completer doesn't know the type of the completion until some
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 8aba5ef..3c30d75 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -203,7 +203,7 @@ f_language_arch_info (struct gdbarch *gdbarch,
 
 /* Remove the modules separator :: from the default break list.  */
 
-static char *
+static const char *
 f_word_break_characters (void)
 {
   static char *retval;
diff --git a/gdb/language.c b/gdb/language.c
index 119c07e..f1fc220 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -698,7 +698,7 @@ default_pass_by_reference (struct type *type)
    delimiting words.  This is a reasonable default value that
    most languages should be able to use.  */
 
-char *
+const char *
 default_word_break_characters (void)
 {
   return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
diff --git a/gdb/language.h b/gdb/language.h
index 3d21e4e..96080ac 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -321,7 +321,7 @@ struct language_defn
     char string_lower_bound;
 
     /* The list of characters forming word boundaries.  */
-    char *(*la_word_break_characters) (void);
+    const char *(*la_word_break_characters) (void);
 
     /* Should return a vector of all symbols which are possible
        completions for TEXT.  WORD is the entire command on which the
@@ -583,7 +583,7 @@ extern char *language_class_name_from_physname (const struct language_defn *,
 					        const char *physname);
 
 /* Splitting strings into words.  */
-extern char *default_word_break_characters (void);
+extern const char *default_word_break_characters (void);
 
 /* Print the index of an array element using the C99 syntax.  */
 extern void default_print_array_index (struct value *index_value,
diff --git a/gdb/top.c b/gdb/top.c
index 295b680..4a22be1 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2022,7 +2022,7 @@ init_main (void)
   /* Setup important stuff for command line editing.  */
   rl_completion_word_break_hook = gdb_completion_word_break_characters;
   rl_completion_entry_function = readline_line_completion_function;
-  rl_completer_word_break_characters = default_word_break_characters ();
+  set_rl_completer_word_break_characters (default_word_break_characters ());
   rl_completer_quote_characters = get_gdb_completer_quote_characters ();
   rl_completion_display_matches_hook = cli_display_match_list;
   rl_readline_name = "gdb";
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 10/18] -Wwrite-strings: gdbserver's 'port' parsing
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (11 preceding siblings ...)
  2017-04-04 17:26 ` [PATCH 16/18] -Wwrite-strings: Some constification in gdb/breakpoint.c Pedro Alves
@ 2017-04-04 17:31 ` Pedro Alves
  2017-04-04 17:32 ` [PATCH 18/18] -Wwrite-strings: Remove -Wno-write-strings Pedro Alves
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:31 UTC (permalink / raw)
  To: gdb-patches

-Wwrite-strings flags this assignment as requiring a cast:

		  port = STDIO_CONNECTION_NAME;

because 'port' is a "char *", and STDIO_CONNECTION_NAME is a string
literal.

gdb/gdbserver/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

        * remote-utils.c (remote_prepare, remote_open): Constify.
        * remote-utils.h (remote_prepare, remote_open): Constify.
        * server.c (captured_main): Constify 'port' handling.
---
 gdb/gdbserver/remote-utils.c |  8 ++++----
 gdb/gdbserver/remote-utils.h |  4 ++--
 gdb/gdbserver/server.c       | 13 +++++++++----
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index 6a2cc04..37a6402 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -217,9 +217,9 @@ handle_accept_event (int err, gdb_client_data client_data)
    NAME is the filename used for communication.  */
 
 void
-remote_prepare (char *name)
+remote_prepare (const char *name)
 {
-  char *port_str;
+  const char *port_str;
 #ifdef USE_WIN32API
   static int winsock_initialized;
 #endif
@@ -284,9 +284,9 @@ remote_prepare (char *name)
    NAME is the filename used for communication.  */
 
 void
-remote_open (char *name)
+remote_open (const char *name)
 {
-  char *port_str;
+  const char *port_str;
 
   port_str = strchr (name, ':');
 #ifdef USE_WIN32API
diff --git a/gdb/gdbserver/remote-utils.h b/gdb/gdbserver/remote-utils.h
index 9db46be..b3eab3b 100644
--- a/gdb/gdbserver/remote-utils.h
+++ b/gdb/gdbserver/remote-utils.h
@@ -35,8 +35,8 @@ int putpkt (char *buf);
 int putpkt_binary (char *buf, int len);
 int putpkt_notif (char *buf);
 int getpkt (char *buf);
-void remote_prepare (char *name);
-void remote_open (char *name);
+void remote_prepare (const char *name);
+void remote_open (const char *name);
 void remote_close (void);
 void write_ok (char *buf);
 void write_enn (char *buf);
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 4bc7f71..51f6a28 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3511,7 +3511,8 @@ captured_main (int argc, char *argv[])
 {
   int bad_attach;
   int pid;
-  char *arg_end, *port;
+  char *arg_end;
+  const char *port = NULL;
   char **next_arg = &argv[1];
   volatile int multi_mode = 0;
   volatile int attach = 0;
@@ -3608,7 +3609,8 @@ captured_main (int argc, char *argv[])
 	{
 	  /* "-" specifies a stdio connection and is a form of port
 	     specification.  */
-	  *next_arg = STDIO_CONNECTION_NAME;
+	  port = STDIO_CONNECTION_NAME;
+	  next_arg++;
 	  break;
 	}
       else if (strcmp (*next_arg, "--disable-randomization") == 0)
@@ -3627,8 +3629,11 @@ captured_main (int argc, char *argv[])
       continue;
     }
 
-  port = *next_arg;
-  next_arg++;
+  if (port == NULL)
+    {
+      port = *next_arg;
+      next_arg++;
+    }
   if (port == NULL || (!attach && !multi_mode && *next_arg == NULL))
     {
       gdbserver_usage (stderr);
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 11/18] -Wwrite-strings: gdbserver/win32-low.c and TARGET_WAITKIND_EXECD
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (14 preceding siblings ...)
  2017-04-04 17:32 ` [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals Pedro Alves
@ 2017-04-04 17:32 ` Pedro Alves
  2017-04-04 17:33 ` [PATCH 12/18] -Wwrite-strings: More fix-old-Python-API wrappers Pedro Alves
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:32 UTC (permalink / raw)
  To: gdb-patches

 src/gdb/gdbserver/win32-low.c:1499:39: error: ISO C++ forbids converting a string constant to 'char*' [-Werror=write-strings]
	ourstatus->value.execd_pathname = "Main executable";
					^

This reporting via TARGET_WAITKIND_EXECD it's totally unnecessary.
get_child_debug_event returns a TARGET_WAITKIND_SPURIOUS by default,
which works just as well here, and is what the equivalent code in
gdb/windows-nat.c does too.

gdb/gdbserver/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* win32-low.c (get_child_debug_event)
	<CREATE_PROCESS_DEBUG_EVENT>: Don't report TARGET_WAITKIND_EXECD.
	Report TARGET_WAITKIND_SPURIOUS instead.
---
 gdb/gdbserver/win32-low.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index d3ddbf5..7b09f4b 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -1495,16 +1495,12 @@ get_child_debug_event (struct target_waitstatus *ourstatus)
       current_process_handle = current_event.u.CreateProcessInfo.hProcess;
       main_thread_id = current_event.dwThreadId;
 
-      ourstatus->kind = TARGET_WAITKIND_EXECD;
-      ourstatus->value.execd_pathname = "Main executable";
-
       /* Add the main thread.  */
       child_add_thread (current_event.dwProcessId,
 			main_thread_id,
 			current_event.u.CreateProcessInfo.hThread,
 			current_event.u.CreateProcessInfo.lpThreadLocalBase);
 
-      ourstatus->value.related_pid = debug_event_ptid (&current_event);
 #ifdef _WIN32_WCE
       if (!attaching)
 	{
@@ -1632,7 +1628,6 @@ win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options)
 	  OUTMSG (("Ignoring unknown internal event, %d\n", ourstatus->kind));
 	  /* fall-through */
 	case TARGET_WAITKIND_SPURIOUS:
-	case TARGET_WAITKIND_EXECD:
 	  /* do nothing, just continue */
 	  child_continue (DBG_CONTINUE, -1);
 	  break;
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (13 preceding siblings ...)
  2017-04-04 17:32 ` [PATCH 18/18] -Wwrite-strings: Remove -Wno-write-strings Pedro Alves
@ 2017-04-04 17:32 ` Pedro Alves
  2017-04-04 18:40   ` Sergio Durigan Junior
  2017-04-05  8:49   ` Philipp Rudo
  2017-04-04 17:32 ` [PATCH 11/18] -Wwrite-strings: gdbserver/win32-low.c and TARGET_WAITKIND_EXECD Pedro Alves
                   ` (5 subsequent siblings)
  20 siblings, 2 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:32 UTC (permalink / raw)
  To: gdb-patches

Unfortunately, PyGetSetDef's 'name' and 'doc' members are 'char *'
instead of 'const char *', meaning that in order to list-initialize
PyGetSetDef arrays using string literals requires writing explicit
'char *' casts.  For example:

    static PyGetSetDef value_object_getset[] = {
   -  { "address", valpy_get_address, NULL, "The address of the value.",
   +  { (char *) "address", valpy_get_address, NULL,
   +    (char *) "The address of the value.",
	NULL },
   -  { "is_optimized_out", valpy_get_is_optimized_out, NULL,
   -    "Boolean telling whether the value is optimized "
   +  { (char *) "is_optimized_out", valpy_get_is_optimized_out, NULL,
   +    (char *) "Boolean telling whether the value is optimized "
	"out (i.e., not available).",
	NULL },
   -  { "type", valpy_get_type, NULL, "Type of the value.", NULL },
   -  { "dynamic_type", valpy_get_dynamic_type, NULL,
   -    "Dynamic type of the value.", NULL },
   -  { "is_lazy", valpy_get_is_lazy, NULL,
   -    "Boolean telling whether the value is lazy (not fetched yet\n\
   +  { (char *) "type", valpy_get_type, NULL,
   +    (char *) "Type of the value.", NULL },
   +  { (char *) "dynamic_type", valpy_get_dynamic_type, NULL,
   +    (char *) "Dynamic type of the value.", NULL },
   +  { (char *) "is_lazy", valpy_get_is_lazy, NULL,
   +    (char *) "Boolean telling whether the value is lazy (not fetched yet\n\
    from the inferior).  A lazy value is fetched when needed, or when\n\
    the \"fetch_lazy()\" method is called.", NULL },
      {NULL}  /* Sentinel */

We have 20 such arrays, and I first wrote a patch that fixed all of
them like that...  It's not pretty, and I can post it if people want
to see it.

One way to make these a bit less ugly would be add a new macro that
hides the casts, like:

  #define GDBPY_GSDEF(NAME, GET, SET, DOC, CLOSURE) \
     { (char *) NAME, GET, SET, (char *) DOC, CLOSURE }

and then use it like:

    static PyGetSetDef value_object_getset[] = {
       GDBPY_GSDEF ("address", valpy_get_address, NULL,
       		    "The address of the value.", NULL),
       GDBPY_GSDEF ("is_optimized_out", valpy_get_is_optimized_out, NULL,
       		    "Boolean telling whether the value is optimized ", NULL),
      {NULL}  /* Sentinel */
    };

But since we have C++11, which gives us constexpr and list
initialization, I thought of a way that requires no changes where the
arrays are initialized:

We add a new type that extends PyGetSetDef (called gdb_PyGetSetDef),
and add constexpr constructors that accept const 'name' and 'doc', and
then list/aggregate initialization simply "calls" these matching
constructors instead.

I put "calls" in quotes, because given "constexpr", it's all done at
compile time, and there's no overhead either in binary size or at run
time.  In fact, we get identical binaries, before/after this change.

I'm a bit undecided whether to change the places that create
PyGetSetDef arrays to explicitly name gdb_PyGetSetDef as type, like:

  -    static PyGetSetDef value_object_getset[] = {
  +    static gdb_PyGetSetDef value_object_getset[] = {

or go the

  #define PyGetSetDef gdb_PyGetSetDef

way as we do for the other Python API fixes.  This commit takes the
latter approach, but I'll change it if people prefer the other way.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* python/python-internal.h (gdb_PyGetSetDef): New type.
	(PyGetSetDef): New define.
---
 gdb/python/python-internal.h | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 55efd75..8fc89cd 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -286,6 +286,38 @@ gdb_PySys_SetPath (const GDB_PYSYS_SETPATH_CHAR *path)
 
 #define PySys_SetPath gdb_PySys_SetPath
 
+/* Wrap PyGetSetDef to allow convenient construction with string
+   literals.  Unfortunately, PyGetSetDef's 'name' and 'doc' members
+   are 'char *' instead of 'const char *', meaning that in order to
+   list-initialize PyGetSetDef arrays with string literals (and
+   without the wrapping below) would require writing explicit 'char *'
+   casts.  Instead, we extend PyGetSetDef and add onstexpr
+   constructors that accept const 'name' and 'doc', hiding the ugly
+   casts here in a single place.  */
+
+struct gdb_PyGetSetDef : PyGetSetDef
+{
+  constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter set_,
+			     const char *doc_, void *closure_)
+    : PyGetSetDef {const_cast<char *> (name_), get_, set_,
+		   const_cast<char *> (doc_), closure_}
+  {}
+
+  /* Alternative constructor that allows omitting the closure in list
+     initialization.  */
+  constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter set_,
+			     const char *doc_)
+    : gdb_PyGetSetDef {name_, get_, set_, doc_, NULL}
+  {}
+
+  /* Constructor for the sentinel entries.  */
+  constexpr gdb_PyGetSetDef (std::nullptr_t)
+    : gdb_PyGetSetDef { NULL, NULL, NULL, NULL, NULL }
+  {}
+};
+
+#define PyGetSetDef gdb_PyGetSetDef
+
 /* In order to be able to parse symtab_and_line_to_sal_object function
    a real symtab_and_line structure is needed.  */
 #include "symtab.h"
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 18/18] -Wwrite-strings: Remove -Wno-write-strings
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (12 preceding siblings ...)
  2017-04-04 17:31 ` [PATCH 10/18] -Wwrite-strings: gdbserver's 'port' parsing Pedro Alves
@ 2017-04-04 17:32 ` Pedro Alves
  2019-02-14 16:17   ` Thomas Schwinge
  2017-04-04 17:32 ` [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals Pedro Alves
                   ` (6 subsequent siblings)
  20 siblings, 1 reply; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:32 UTC (permalink / raw)
  To: gdb-patches

AFAIK GDB is now free from -Wwrite-strings warnings.  A few warnings may
be left behind in some host-specific code, but those should be few and
easy to fix.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* warning.m4 (build_warnings): Remove -Wno-write-strings.
	* configure: Regenerate.

gdb/gdbserver/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* configure: Regenerate.
---
 gdb/configure           | 2 +-
 gdb/gdbserver/configure | 2 +-
 gdb/warning.m4          | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gdb/configure b/gdb/configure
index 7fbae9f..9f05b4b 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -15108,7 +15108,7 @@ build_warnings="-Wall -Wpointer-arith \
 -Wno-unused -Wunused-value -Wunused-function \
 -Wno-switch -Wno-char-subscripts \
 -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable \
--Wno-sign-compare -Wno-write-strings -Wno-narrowing"
+-Wno-sign-compare -Wno-narrowing"
 
 # Enable -Wno-format by default when using gcc on mingw since many
 # GCC versions complain about %I64.
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index 6ae4865..64f96f5 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -7148,7 +7148,7 @@ build_warnings="-Wall -Wpointer-arith \
 -Wno-unused -Wunused-value -Wunused-function \
 -Wno-switch -Wno-char-subscripts \
 -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable \
--Wno-sign-compare -Wno-write-strings -Wno-narrowing"
+-Wno-sign-compare -Wno-narrowing"
 
 # Enable -Wno-format by default when using gcc on mingw since many
 # GCC versions complain about %I64.
diff --git a/gdb/warning.m4 b/gdb/warning.m4
index f04709e..83f69ec 100644
--- a/gdb/warning.m4
+++ b/gdb/warning.m4
@@ -40,7 +40,7 @@ build_warnings="-Wall -Wpointer-arith \
 -Wno-unused -Wunused-value -Wunused-function \
 -Wno-switch -Wno-char-subscripts \
 -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable \
--Wno-sign-compare -Wno-write-strings -Wno-narrowing"
+-Wno-sign-compare -Wno-narrowing"
 
 # Enable -Wno-format by default when using gcc on mingw since many
 # GCC versions complain about %I64.
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 12/18] -Wwrite-strings: More fix-old-Python-API wrappers
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (15 preceding siblings ...)
  2017-04-04 17:32 ` [PATCH 11/18] -Wwrite-strings: gdbserver/win32-low.c and TARGET_WAITKIND_EXECD Pedro Alves
@ 2017-04-04 17:33 ` Pedro Alves
  2017-04-04 17:36 ` [PATCH 17/18] -Wwrite-strings: The Rest Pedro Alves
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:33 UTC (permalink / raw)
  To: gdb-patches

When building against Python 2.7, -Wwrite-strings flags several cases
of passing a string literal to Python functions that expect a "char
*".  This commit addresses the issue like we already handle several
other similar cases -- wrap the Python API with our own fixed
version that adds the necessary constification.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* python/python-internal.h (gdb_PyObject_CallMethod)
	(gdb_PyErr_NewException, gdb_PySys_GetObject, gdb_PySys_SetPath):
	New functions.
	(GDB_PYSYS_SETPATH_CHAR, PyObject_CallMethod, PyErr_NewException)
	(PySys_GetObject, PySys_SetPath): New macros.
---
 gdb/python/python-internal.h | 63 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 4dd413d..55efd75 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -223,6 +223,69 @@ gdb_PyObject_HasAttrString (PyObject *obj,
 
 #define PyObject_HasAttrString(obj, attr) gdb_PyObject_HasAttrString (obj, attr)
 
+/* PyObject_CallMethod's 'method' and 'format' parameters were missing
+   the 'const' qualifier before Python 3.4.  Hence, we wrap the
+   function in our own version to avoid errors with string literals.
+   Note, this is a variadic template because PyObject_CallMethod is a
+   varargs function and Python doesn't have a "PyObject_VaCallMethod"
+   variant taking a va_list that we could defer to instead.  */
+
+template<typename... Args>
+static inline PyObject *
+gdb_PyObject_CallMethod (PyObject *o, const char *method, const char *format,
+			 Args... args) /* ARI: editCase function */
+{
+  return PyObject_CallMethod (o,
+			      const_cast<char *> (method),
+			      const_cast<char *> (format),
+			      args...);
+}
+
+#undef PyObject_CallMethod
+#define PyObject_CallMethod gdb_PyObject_CallMethod
+
+/* The 'name' parameter of PyErr_NewException was missing the 'const'
+   qualifier in Python <= 3.4.  Hence, we wrap it in a function to
+   avoid errors when compiled with -Werror.  */
+
+static inline PyObject*
+gdb_PyErr_NewException (const char *name, PyObject *base, PyObject *dict)
+{
+  return PyErr_NewException (const_cast<char *> (name), base, dict);
+}
+
+#define PyErr_NewException gdb_PyErr_NewException
+
+/* PySys_GetObject's 'name' parameter was missing the 'const'
+   qualifier before Python 3.4.  Hence, we wrap it in a function to
+   avoid errors when compiled with -Werror.  */
+
+static inline PyObject *
+gdb_PySys_GetObject (const char *name)
+{
+  return PySys_GetObject (const_cast<char *> (name));
+}
+
+#define PySys_GetObject gdb_PySys_GetObject
+
+/* PySys_SetPath's 'path' parameter was missing the 'const' qualifier
+   before Python 3.6.  Hence, we wrap it in a function to avoid errors
+   when compiled with -Werror.  */
+
+#ifdef IS_PY3K
+# define GDB_PYSYS_SETPATH_CHAR wchar_t
+#else
+# define GDB_PYSYS_SETPATH_CHAR char
+#endif
+
+static inline void
+gdb_PySys_SetPath (const GDB_PYSYS_SETPATH_CHAR *path)
+{
+  PySys_SetPath (const_cast<GDB_PYSYS_SETPATH_CHAR *> (path));
+}
+
+#define PySys_SetPath gdb_PySys_SetPath
+
 /* In order to be able to parse symtab_and_line_to_sal_object function
    a real symtab_and_line structure is needed.  */
 #include "symtab.h"
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 17/18] -Wwrite-strings: The Rest
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (16 preceding siblings ...)
  2017-04-04 17:33 ` [PATCH 12/18] -Wwrite-strings: More fix-old-Python-API wrappers Pedro Alves
@ 2017-04-04 17:36 ` Pedro Alves
  2017-04-04 18:44   ` John Baldwin
  2017-04-04 18:42 ` [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Sergio Durigan Junior
                   ` (2 subsequent siblings)
  20 siblings, 1 reply; 39+ messages in thread
From: Pedro Alves @ 2017-04-04 17:36 UTC (permalink / raw)
  To: gdb-patches

This is the remainder boring constification that all looks more of less
borderline obvious IMO.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* ada-exp.y (yyerror): Constify.
	* ada-lang.c (bound_name, get_selections)
	(ada_variant_discrim_type)
	(ada_variant_discrim_name, ada_value_struct_elt)
	(ada_lookup_struct_elt_type, is_unchecked_variant)
	(ada_which_variant_applies, standard_exc, ada_get_next_arg)
	(catch_ada_exception_command_split)
	(catch_ada_assert_command_split, catch_assert_command)
	(ada_op_name): Constify.
	* ada-lang.h (ada_yyerror, get_selections)
	(ada_variant_discrim_name, ada_value_struct_elt): Constify.
	* arc-tdep.c (arc_print_frame_cache): Constify.
	* arm-tdep.c (arm_skip_stub): Constify.
	* ax-gdb.c (gen_binop, gen_struct_ref_recursive, gen_struct_ref)
	(gen_aggregate_elt_ref): Constify.
	* bcache.c (print_bcache_statistics): Constify.
	* bcache.h (print_bcache_statistics): Constify.
	* break-catch-throw.c (catch_exception_command_1):
	* breakpoint.c (struct ep_type_description::description):
	Constify.
	(add_solib_catchpoint): Constify.
	(catch_fork_command_1): Add cast.
	(add_catch_command): Constify.
	* breakpoint.h (add_catch_command, add_solib_catchpoint):
	Constify.
	* bsd-uthread.c (bsd_uthread_state): Constify.
	* buildsym.c (patch_subfile_names): Constify.
	* buildsym.h (next_symbol_text_func, patch_subfile_names):
	Constify.
	* c-exp.y (yyerror): Constify.
	(token::oper): Constify.
	* c-lang.h (c_yyerror, cp_print_class_member): Constify.
	* c-varobj.c (cplus_describe_child): Constify.
	* charset.c (find_charset_names): Add cast.
	(find_charset_names): Constify array and add const_cast.
	* cli/cli-cmds.c (complete_command, cd_command): Constify.
	(edit_command): Constify.
	* cli/cli-decode.c (lookup_cmd): Constify.
	* cli/cli-dump.c (dump_memory_command, dump_value_command):
	Constify.
	(struct dump_context): Constify.
	(add_dump_command, restore_command): Constify.
	* cli/cli-script.c (get_command_line): Constify.
	* cli/cli-script.h (get_command_line): Constify.
	* cli/cli-utils.c (check_for_argument): Constify.
	* cli/cli-utils.h (check_for_argument): Constify.
	* coff-pe-read.c (struct read_pe_section_data): Constify.
	* command.h (lookup_cmd): Constify.
	* common/print-utils.c (decimal2str): Constify.
	* completer.c (gdb_print_filename): Constify.
	* corefile.c (set_gnutarget): Constify.
	* cp-name-parser.y (yyerror): Constify.
	* cp-valprint.c (cp_print_class_member): Constify.
	* cris-tdep.c (cris_register_name, crisv32_register_name):
	Constify.
	* d-exp.y (yyerror): Constify.
	(struct token::oper): Constify.
	* d-lang.h (d_yyerror): Constify.
	* dbxread.c (struct header_file_location::name): Constify.
	(add_old_header_file, add_new_header_file, last_function_name)
	(dbx_next_symbol_text, add_bincl_to_list)
	(find_corresponding_bincl_psymtab, set_namestring)
	(find_stab_function_addr, read_dbx_symtab, start_psymtab)
	(dbx_end_psymtab, read_ofile_symtab, process_one_symbol):
	* defs.h (command_line_input, print_address_symbolic)
	(deprecated_readline_begin_hook): Constify.
	* dwarf2read.c (anonymous_struct_prefix, dwarf_bool_name):
	Constify.
	* event-top.c (handle_line_of_input): Constify and add cast.
	* exceptions.c (catch_errors): Constify.
	* exceptions.h (catch_errors): Constify.
	* expprint.c (print_subexp_standard, op_string, op_name)
	(op_name_standard, dump_raw_expression, dump_raw_expression):
	* expression.h (op_name, op_string, dump_raw_expression):
	Constify.
	* f-exp.y (yyerror): Constify.
	(struct token::oper): Constify.
	(struct f77_boolean_val::name): Constify.
	* f-lang.c (f_word_break_characters): Constify.
	* f-lang.h (f_yyerror): Constify.
	* fbsd-tdep.c (fbsd_core_pid_to_str): Constify.
	* fork-child.c (fork_inferior): Add cast.
	* frv-tdep.c (struct gdbarch_tdep::register_names): Constify.
	(new_variant): Constify.
	* gdbarch.sh (pstring_ptr, pstring_list): Constify.
	* gdbarch.c: Regenerate.
	* gdbcore.h (set_gnutarget): Constify.
	* go-exp.y (yyerror): Constify.
	(token::oper): Constify.
	* go-lang.h (go_yyerror): Constify.
	* go32-nat.c (go32_sysinfo): Constify.
	* guile/scm-breakpoint.c (gdbscm_breakpoint_expression): Constify.
	* guile/scm-cmd.c (cmdscm_function): Constify.
	* guile/scm-param.c (pascm_param_value): Constify.
	* h8300-tdep.c (h8300_register_name, h8300s_register_name)
	(h8300sx_register_name): Constify.
	* hppa-tdep.c (hppa32_register_name, hppa64_register_name):
	Constify.
	* ia64-tdep.c (ia64_register_names): Constify.
	* infcmd.c (construct_inferior_arguments): Constify.
	(path_command, attach_post_wait): Constify.
	* inferior.c (inferior_pid_to_str): Constify.
	* language.c (show_range_command, show_case_command)
	(unk_lang_error): Constify.
	* language.h (language_defn::la_error)
	(language_defn::la_name_of_this): Constify.
	* linespec.c (decode_line_2): Constify.
	* linux-nat.c (linux_nat_pid_to_str): Constify.
	* linux-tdep.c (linux_core_pid_to_str): Constify.
	* linux-thread-db.c (thread_db_err_str, thread_db_pid_to_str)
	(thread_db_extra_thread_info): Constify.
	* lm32-tdep.c (lm32_register_name): Constify.
	* m2-exp.y (yyerror): Constify.
	* m2-lang.h (m2_yyerror): Constify.
	* m32r-tdep.c (m32r_register_names): Constify and make static.
	* m68hc11-tdep.c (m68hc11_register_names): Constify.
	* m88k-tdep.c (m88k_register_name): Constify.
	* macroexp.c (appendmem): Constify.
	* mdebugread.c (fdr_name, add_data_symbol, parse_type)
	(upgrade_type, parse_external, parse_partial_symbols)
	(mdebug_next_symbol_text, cross_ref, mylookup_symbol, new_psymtab)
	(new_symbol): Constify.
	* memattr.c (mem_info_command): Constify.
	* mep-tdep.c (register_name_from_keyword): Constify.
	* mi/mi-cmd-env.c (mi_cmd_env_path, _initialize_mi_cmd_env):
	Constify.
	* mi/mi-cmd-stack.c (list_args_or_locals): Constify.
	* mi/mi-cmd-var.c (mi_cmd_var_show_attributes): Constify.
	* mi/mi-main.c (captured_mi_execute_command): Constify and add
	cast.
	(mi_execute_async_cli_command): Constify.
	* mips-tdep.c (mips_register_name): Constify.
	* mn10300-tdep.c (register_name, mn10300_generic_register_name)
	(am33_register_name, am33_2_register_name)
	* moxie-tdep.c (moxie_register_names): Constify.
	* nat/linux-osdata.c (osdata_type): Constify fields.
	* nto-tdep.c (nto_parse_redirection): Constify.
	* objc-lang.c (lookup_struct_typedef, lookup_objc_class)
	(lookup_child_selector): Constify.
	(objc_methcall::name): Constify.
	* objc-lang.h (lookup_objc_class, lookup_child_selector)
	(lookup_struct_typedef): Constify.
	* objfiles.c (pc_in_section): Constify.
	* objfiles.h (pc_in_section): Constify.
	* p-exp.y (struct token::oper): Constify.
	(yyerror): Constify.
	* p-lang.h (pascal_yyerror): Constify.
	* parser-defs.h (op_name_standard): Constify.
	(op_print::string): Constify.
	(exp_descriptor::op_name): Constify.
	* printcmd.c (print_address_symbolic): Constify.
	* psymtab.c (print_partial_symbols): Constify.
	* python/py-breakpoint.c (stop_func): Constify.
	(bppy_get_expression): Constify.
	* python/py-cmd.c (cmdpy_completer::name): Constify.
	(cmdpy_function): Constify.
	* python/py-event.c (evpy_add_attribute)
	(gdbpy_initialize_event_generic): Constify.
	* python/py-event.h (evpy_add_attribute)
	(gdbpy_initialize_event_generic): Constify.
	* python/py-evts.c (add_new_registry): Constify.
	* python/py-finishbreakpoint.c (outofscope_func): Constify.
	* python/py-framefilter.c (get_py_iter_from_func): Constify.
	* python/py-inferior.c (get_buffer): Add cast.
	* python/py-param.c (parm_constant::name): Constify.
	* python/py-unwind.c (fprint_frame_id): Constify.
	* python/python.c (gdbpy_parameter_value): Constify.
	* remote-fileio.c (remote_fio_func_map): Make 'name' const.
	* remote.c (memory_packet_config::name): Constify.
	(show_packet_config_cmd, remote_threads_extra_info)
	(remote_write_bytes, remote_pid_to_str, remote_buffer_add_string):
	* reverse.c (exec_reverse_once): Constify.
	* rs6000-tdep.c (variant::name, variant::description): Constify.
	* rust-exp.y (rustyyerror): Constify.
	* rust-lang.c (rust_op_name): Constify.
	* rust-lang.h (rustyyerror): Constify.
	* serial.h (serial_ops::name): Constify.
	* sh-tdep.c (sh_sh_register_name, sh_sh3_register_name)
	(sh_sh3e_register_name, sh_sh2e_register_name)
	(sh_sh2a_register_name, sh_sh2a_nofpu_register_name)
	(sh_sh_dsp_register_name, sh_sh3_dsp_register_name)
	(sh_sh4_register_name, sh_sh4_nofpu_register_name)
	(sh_sh4al_dsp_register_name): Constify.
	* sh64-tdep.c (sh64_register_name): Constify.
	* solib-darwin.c (lookup_symbol_from_bfd): Constify.
	* spu-tdep.c (spu_register_name, info_spu_dma_cmdlist): Constify.
	* stabsread.c (patch_block_stabs, read_type_number)
	(ref_map::stabs, ref_add, process_reference)
	(symbol_reference_defined, define_symbol, define_symbol)
	(error_type, read_type, read_member_functions, read_cpp_abbrev)
	(read_one_struct_field, read_struct_fields, read_baseclasses)
	(read_tilde_fields, read_struct_type, read_array_type)
	(read_enum_type, read_sun_builtin_type, read_sun_floating_type)
	(read_huge_number, read_range_type, read_args, common_block_start)
	(find_name_end): Constify.
	* stabsread.h (common_block_start, define_symbol)
	(process_one_symbol, symbol_reference_defined, ref_add):
	* symfile.c (get_section_index, add_symbol_file_command):
	* symfile.h (get_section_index): Constify.
	* target-descriptions.c (tdesc_type::name): Constify.
	(tdesc_free_type): Add cast.
	* target.c (find_default_run_target):
	(add_deprecated_target_alias, find_default_run_target)
	(target_announce_detach): Constify.
	(do_option): Constify.
	* target.h (add_deprecated_target_alias): Constify.
	* thread.c (print_thread_info_1): Constify.
	* top.c (deprecated_readline_begin_hook, command_line_input):
	Constify.
	(init_main): Add casts.
	* top.h (handle_line_of_input): Constify.
	* tracefile-tfile.c (tfile_write_uploaded_tsv): Constify.
	* tracepoint.c (tvariables_info_1, trace_status_mi): Constify.
	(tfind_command): Rename to ...
	(tfind_command_1): ... this and constify.
	(tfind_command): New function.
	(tfind_end_command, tfind_start_command): Adjust.
	(encode_source_string): Constify.
	* tracepoint.h (encode_source_string): Constify.
	* tui/tui-data.c (tui_partial_win_by_name): Constify.
	* tui/tui-data.h (tui_partial_win_by_name): Constify.
	* tui/tui-source.c (tui_set_source_content_nil): Constify.
	* tui/tui-source.h (tui_set_source_content_nil): Constify.
	* tui/tui-win.c (parse_scrolling_args): Constify.
	* tui/tui-windata.c (tui_erase_data_content): Constify.
	* tui/tui-windata.h (tui_erase_data_content): Constify.
	* tui/tui-winsource.c (tui_erase_source_content): Constify.
	* tui/tui.c (tui_enable): Add cast.
	* utils.c (defaulted_query): Constify.
	(init_page_info): Add cast.
	(puts_debug, subset_compare): Constify.
	* utils.h (subset_compare): Constify.
	* varobj.c (varobj_format_string): Constify.
	* varobj.h (varobj_format_string): Constify.
	* vax-tdep.c (vax_register_name): Constify.
	* windows-nat.c (windows_detach): Constify.
	* xcoffread.c (process_linenos, xcoff_next_symbol_text): Constify.
	* xml-support.c (gdb_xml_end_element): Constify.
	* xml-tdesc.c (tdesc_start_reg): Constify.
	* xstormy16-tdep.c (xstormy16_register_name): Constify.
	* xtensa-tdep.c (xtensa_find_register_by_name): Constify.
	* xtensa-tdep.h (xtensa_register_t::name): Constify.

gdb/gdbserver/ChangeLog:

	* gdbreplay.c (sync_error): Constify.
	* linux-x86-low.c (push_opcode): Constify.
---
 gdb/ada-exp.y                    |   4 +-
 gdb/ada-lang.c                   |  54 ++++++++--------
 gdb/ada-lang.h                   |   8 +--
 gdb/arc-tdep.c                   |   2 +-
 gdb/arm-tdep.c                   |   2 +-
 gdb/ax-gdb.c                     |  21 ++++---
 gdb/bcache.c                     |   2 +-
 gdb/bcache.h                     |   2 +-
 gdb/breakpoint.c                 |   8 +--
 gdb/breakpoint.h                 |   4 +-
 gdb/bsd-uthread.c                |   2 +-
 gdb/buildsym.c                   |   2 +-
 gdb/buildsym.h                   |   4 +-
 gdb/c-exp.y                      |   6 +-
 gdb/c-lang.h                     |   4 +-
 gdb/c-varobj.c                   |   2 +-
 gdb/charset.c                    |  11 +++-
 gdb/cli/cli-cmds.c               |  14 ++---
 gdb/cli/cli-decode.c             |   3 +-
 gdb/cli/cli-dump.c               |  15 ++---
 gdb/cli/cli-script.c             |   2 +-
 gdb/cli/cli-script.h             |   2 +-
 gdb/coff-pe-read.c               |   2 +-
 gdb/command.h                    |   3 +-
 gdb/common/print-utils.c         |   2 +-
 gdb/completer.c                  |   3 +-
 gdb/corefile.c                   |   2 +-
 gdb/cp-name-parser.y             |   4 +-
 gdb/cp-valprint.c                |   2 +-
 gdb/cris-tdep.c                  |   6 +-
 gdb/d-exp.y                      |   6 +-
 gdb/d-lang.h                     |   2 +-
 gdb/dbxread.c                    |  80 ++++++++++++------------
 gdb/defs.h                       |   7 ++-
 gdb/dwarf2read.c                 |   8 +--
 gdb/event-top.c                  |   2 +-
 gdb/exceptions.c                 |   4 +-
 gdb/exceptions.h                 |   3 +-
 gdb/expprint.c                   |  14 ++---
 gdb/expression.h                 |   6 +-
 gdb/f-exp.y                      |   8 +--
 gdb/f-lang.h                     |   2 +-
 gdb/fork-child.c                 |   2 +-
 gdb/frv-tdep.c                   |   6 +-
 gdb/gdbarch.c                    |   4 +-
 gdb/gdbarch.sh                   |   4 +-
 gdb/gdbcore.h                    |   2 +-
 gdb/gdbserver/gdbreplay.c        |   2 +-
 gdb/gdbserver/linux-x86-low.c    |   2 +-
 gdb/go-exp.y                     |   6 +-
 gdb/go-lang.h                    |   2 +-
 gdb/go32-nat.c                   |   2 +-
 gdb/guile/scm-breakpoint.c       |   3 +-
 gdb/guile/scm-cmd.c              |   4 +-
 gdb/guile/scm-param.c            |   2 +-
 gdb/h8300-tdep.c                 |   6 +-
 gdb/hppa-tdep.c                  |   4 +-
 gdb/ia64-tdep.c                  |   2 +-
 gdb/infcmd.c                     |  12 ++--
 gdb/language.c                   |   8 +--
 gdb/language.h                   |   4 +-
 gdb/linespec.c                   |   3 +-
 gdb/linux-thread-db.c            |   2 +-
 gdb/lm32-tdep.c                  |   2 +-
 gdb/m2-exp.y                     |   4 +-
 gdb/m2-lang.h                    |   2 +-
 gdb/m32r-tdep.c                  |   2 +-
 gdb/m68hc11-tdep.c               |   2 +-
 gdb/m88k-tdep.c                  |   2 +-
 gdb/macroexp.c                   |   2 +-
 gdb/mdebugread.c                 |  46 +++++++-------
 gdb/memattr.c                    |   2 +-
 gdb/mep-tdep.c                   |   2 +-
 gdb/mi/mi-cmd-env.c              |   4 +-
 gdb/mi/mi-cmd-stack.c            |   2 +-
 gdb/mi/mi-cmd-var.c              |   2 +-
 gdb/mi/mi-main.c                 |   6 +-
 gdb/mips-tdep.c                  |   6 +-
 gdb/mn10300-tdep.c               |  10 +--
 gdb/moxie-tdep.c                 |   2 +-
 gdb/nat/linux-osdata.c           |   6 +-
 gdb/nto-tdep.c                   |   2 +-
 gdb/objc-lang.c                  |   8 +--
 gdb/objc-lang.h                  |   7 ++-
 gdb/objfiles.c                   |   2 +-
 gdb/objfiles.h                   |   2 +-
 gdb/p-exp.y                      |   6 +-
 gdb/p-lang.h                     |   2 +-
 gdb/parser-defs.h                |   6 +-
 gdb/printcmd.c                   |   2 +-
 gdb/psymtab.c                    |   2 +-
 gdb/python/py-breakpoint.c       |   4 +-
 gdb/python/py-cmd.c              |  10 +--
 gdb/python/py-event.c            |   4 +-
 gdb/python/py-event.h            |   4 +-
 gdb/python/py-evts.c             |   2 +-
 gdb/python/py-finishbreakpoint.c |   2 +-
 gdb/python/py-framefilter.c      |   2 +-
 gdb/python/py-inferior.c         |   5 +-
 gdb/python/py-param.c            |   2 +-
 gdb/python/py-unwind.c           |   2 +-
 gdb/python/python.c              |   2 +-
 gdb/remote-fileio.c              |   2 +-
 gdb/remote.c                     |   8 +--
 gdb/reverse.c                    |   2 +-
 gdb/rs6000-tdep.c                |   4 +-
 gdb/rust-exp.y                   |   2 +-
 gdb/rust-lang.c                  |   2 +-
 gdb/rust-lang.h                  |   2 +-
 gdb/serial.h                     |   2 +-
 gdb/sh-tdep.c                    |  22 +++----
 gdb/sh64-tdep.c                  |   2 +-
 gdb/solib-darwin.c               |   2 +-
 gdb/spu-tdep.c                   |   4 +-
 gdb/stabsread.c                  | 129 ++++++++++++++++++++-------------------
 gdb/stabsread.h                  |  10 +--
 gdb/symfile.c                    |  12 ++--
 gdb/symfile.h                    |   2 +-
 gdb/target-descriptions.c        |   8 ++-
 gdb/target.c                     |  10 +--
 gdb/target.h                     |   3 +-
 gdb/thread.c                     |   2 +-
 gdb/top.c                        |   5 +-
 gdb/top.h                        |   2 +-
 gdb/tracefile-tfile.c            |   4 +-
 gdb/tracepoint.c                 |  22 ++++---
 gdb/tracepoint.h                 |   2 +-
 gdb/tui/tui-data.c               |   2 +-
 gdb/tui/tui-data.h               |   2 +-
 gdb/tui/tui-source.c             |   2 +-
 gdb/tui/tui-source.h             |   2 +-
 gdb/tui/tui-win.c                |  11 ++--
 gdb/tui/tui-windata.c            |   2 +-
 gdb/tui/tui-windata.h            |   2 +-
 gdb/tui/tui-winsource.c          |   2 +-
 gdb/tui/tui.c                    |   2 +-
 gdb/utils.c                      |  11 ++--
 gdb/utils.h                      |   2 +-
 gdb/varobj.c                     |   2 +-
 gdb/varobj.h                     |   2 +-
 gdb/vax-tdep.c                   |   2 +-
 gdb/windows-nat.c                |   2 +-
 gdb/xcoffread.c                  |   8 +--
 gdb/xml-support.c                |  10 +--
 gdb/xml-tdesc.c                  |   3 +-
 gdb/xstormy16-tdep.c             |   2 +-
 gdb/xtensa-tdep.c                |   2 +-
 gdb/xtensa-tdep.h                |   2 +-
 148 files changed, 492 insertions(+), 452 deletions(-)

diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index d9fcdfa..1eea454 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -77,7 +77,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (char *);
+void yyerror (const char *);
 
 static void write_int (struct parser_state *, LONGEST, struct type *);
 
@@ -751,7 +751,7 @@ ada_parse (struct parser_state *par_state)
 }
 
 void
-yyerror (char *msg)
+yyerror (const char *msg)
 {
   error (_("Error in expression, near `%s'."), lexptr);
 }
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index d31e058..f581d8e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -130,7 +130,7 @@ static void replace_operator_with_call (struct expression **, int, int, int,
 
 static int possible_user_operator_p (enum exp_opcode, struct value **);
 
-static char *ada_op_name (enum exp_opcode);
+static const char *ada_op_name (enum exp_opcode);
 
 static const char *ada_decoded_op_name (enum exp_opcode);
 
@@ -150,7 +150,7 @@ static enum ada_renaming_category parse_old_style_renaming (struct type *,
 static struct symbol *find_old_style_renaming_symbol (const char *,
 						      const struct block *);
 
-static struct type *ada_lookup_struct_elt_type (struct type *, char *,
+static struct type *ada_lookup_struct_elt_type (struct type *, const char *,
                                                 int, int, int *);
 
 static struct value *evaluate_subexp_type (struct expression *, int *);
@@ -1578,7 +1578,7 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
 
 /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors.  */
 
-static char *bound_name[] = {
+static const char *bound_name[] = {
   "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3",
   "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7"
 };
@@ -4037,10 +4037,10 @@ See set/show multiple-symbol."));
 
 int
 get_selections (int *choices, int n_choices, int max_results,
-                int is_all_choice, char *annotation_suffix)
+                int is_all_choice, const char *annotation_suffix)
 {
   char *args;
-  char *prompt;
+  const char *prompt;
   int n_chosen;
   int first_choice = is_all_choice ? 2 : 1;
 
@@ -7068,7 +7068,7 @@ ada_is_variant_part (struct type *type, int field_num)
 struct type *
 ada_variant_discrim_type (struct type *var_type, struct type *outer_type)
 {
-  char *name = ada_variant_discrim_name (var_type);
+  const char *name = ada_variant_discrim_name (var_type);
 
   return ada_lookup_struct_elt_type (outer_type, name, 1, 1, NULL);
 }
@@ -7089,7 +7089,7 @@ ada_is_others_clause (struct type *type, int field_num)
    returns the name of the discriminant controlling the variant.
    The value is valid until the next call to ada_variant_discrim_name.  */
 
-char *
+const char *
 ada_variant_discrim_name (struct type *type0)
 {
   static char *result = NULL;
@@ -7486,7 +7486,7 @@ ada_index_struct_field_1 (int *index_p, struct value *arg, int offset,
    calling error.  */
 
 struct value *
-ada_value_struct_elt (struct value *arg, char *name, int no_err)
+ada_value_struct_elt (struct value *arg, const char *name, int no_err)
 {
   struct type *t, *t1;
   struct value *v;
@@ -7600,7 +7600,7 @@ type_as_string (struct type *type)
    TYPE is not a type of the right kind.  */
 
 static struct type *
-ada_lookup_struct_elt_type (struct type *type, char *name, int refok,
+ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
                             int noerr, int *dispp)
 {
   int i;
@@ -7713,7 +7713,7 @@ BadName:
 static int
 is_unchecked_variant (struct type *var_type, struct type *outer_type)
 {
-  char *discrim_name = ada_variant_discrim_name (var_type);
+  const char *discrim_name = ada_variant_discrim_name (var_type);
 
   return (ada_lookup_struct_elt_type (outer_type, discrim_name, 0, 1, NULL) 
 	  == NULL);
@@ -7731,7 +7731,7 @@ ada_which_variant_applies (struct type *var_type, struct type *outer_type,
 {
   int others_clause;
   int i;
-  char *discrim_name = ada_variant_discrim_name (var_type);
+  const char *discrim_name = ada_variant_discrim_name (var_type);
   struct value *outer;
   struct value *discrim;
   LONGEST discrim_val;
@@ -11836,7 +11836,7 @@ ada_modulus (struct type *type)
    an Ada83 compiler). As such, we do not include Numeric_Error from
    this list of standard exceptions.  */
 
-static char *standard_exc[] = {
+static const char *standard_exc[] = {
   "constraint_error",
   "program_error",
   "storage_error",
@@ -12793,19 +12793,19 @@ static struct breakpoint_ops catch_assert_breakpoint_ops;
    Return NULL if ARGPS does not contain any more tokens.  */
 
 static char *
-ada_get_next_arg (char **argsp)
+ada_get_next_arg (const char **argsp)
 {
-  char *args = *argsp;
-  char *end;
+  const char *args = *argsp;
+  const char *end;
   char *result;
 
-  args = skip_spaces (args);
+  args = skip_spaces_const (args);
   if (args[0] == '\0')
     return NULL; /* No more arguments.  */
   
   /* Find the end of the current argument.  */
 
-  end = skip_to_space (args);
+  end = skip_to_space_const (args);
 
   /* Adjust ARGSP to point to the start of the next argument.  */
 
@@ -12829,7 +12829,7 @@ ada_get_next_arg (char **argsp)
    after use).  Otherwise COND_STRING is set to NULL.  */
 
 static void
-catch_ada_exception_command_split (char *args,
+catch_ada_exception_command_split (const char *args,
                                    enum ada_exception_catchpoint_kind *ex,
 				   char **excep_string,
 				   char **cond_string)
@@ -12852,12 +12852,12 @@ catch_ada_exception_command_split (char *args,
 
   /* Check to see if we have a condition.  */
 
-  args = skip_spaces (args);
+  args = skip_spaces_const (args);
   if (startswith (args, "if")
       && (isspace (args[2]) || args[2] == '\0'))
     {
       args += 2;
-      args = skip_spaces (args);
+      args = skip_spaces_const (args);
 
       if (args[0] == '\0')
         error (_("Condition missing after `if' keyword"));
@@ -13079,9 +13079,10 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch,
 /* Implement the "catch exception" command.  */
 
 static void
-catch_ada_exception_command (char *arg, int from_tty,
+catch_ada_exception_command (char *arg_entry, int from_tty,
 			     struct cmd_list_element *command)
 {
+  const char *arg = arg_entry;
   struct gdbarch *gdbarch = get_current_arch ();
   int tempflag;
   enum ada_exception_catchpoint_kind ex_kind;
@@ -13109,16 +13110,16 @@ catch_ada_exception_command (char *arg, int from_tty,
    (the memory needs to be deallocated after use).  */
 
 static void
-catch_ada_assert_command_split (char *args, char **cond_string)
+catch_ada_assert_command_split (const char *args, char **cond_string)
 {
-  args = skip_spaces (args);
+  args = skip_spaces_const (args);
 
   /* Check whether a condition was provided.  */
   if (startswith (args, "if")
       && (isspace (args[2]) || args[2] == '\0'))
     {
       args += 2;
-      args = skip_spaces (args);
+      args = skip_spaces_const (args);
       if (args[0] == '\0')
         error (_("condition missing after `if' keyword"));
       *cond_string = xstrdup (args);
@@ -13133,9 +13134,10 @@ catch_ada_assert_command_split (char *args, char **cond_string)
 /* Implement the "catch assert" command.  */
 
 static void
-catch_assert_command (char *arg, int from_tty,
+catch_assert_command (char *arg_entry, int from_tty,
 		      struct cmd_list_element *command)
 {
+  const char *arg = arg_entry;
   struct gdbarch *gdbarch = get_current_arch ();
   int tempflag;
   char *cond_string = NULL;
@@ -13573,7 +13575,7 @@ ada_operator_check (struct expression *exp, int pos,
   return 0;
 }
 
-static char *
+static const char *
 ada_op_name (enum exp_opcode opcode)
 {
   switch (opcode)
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index 794a282..5f97a6c 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -159,7 +159,7 @@ extern int ada_get_field_index (const struct type *type,
 
 extern int ada_parse (struct parser_state *);    /* Defined in ada-exp.y */
 
-extern void ada_yyerror (char *); /* Defined in ada-exp.y */
+extern void ada_yyerror (const char *); /* Defined in ada-exp.y */
 
                         /* Defined in ada-typeprint.c */
 extern void ada_print_type (struct type *, const char *, struct ui_file *, int,
@@ -243,7 +243,7 @@ extern void ada_fill_in_ada_prototype (struct symbol *);
 
 extern int user_select_syms (struct block_symbol *, int, int);
 
-extern int get_selections (int *, int, int, int, char *);
+extern int get_selections (int *, int, int, int, const char *);
 
 extern int ada_scan_number (const char *, int, LONGEST *, int *);
 
@@ -288,9 +288,9 @@ extern int ada_is_others_clause (struct type *, int);
 
 extern int ada_in_variant (LONGEST, struct type *, int);
 
-extern char *ada_variant_discrim_name (struct type *);
+extern const char *ada_variant_discrim_name (struct type *);
 
-extern struct value *ada_value_struct_elt (struct value *, char *, int);
+extern struct value *ada_value_struct_elt (struct value *, const char *, int);
 
 extern int ada_is_aligner_type (struct type *);
 
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 657b1eb..4f866a9 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -1530,7 +1530,7 @@ arc_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
 /* Dump the frame info.  Used for internal debugging only.  */
 
 static void
-arc_print_frame_cache (struct gdbarch *gdbarch, char *message,
+arc_print_frame_cache (struct gdbarch *gdbarch, const char *message,
 		       struct arc_frame_cache *cache, int addresses_known)
 {
   debug_printf ("arc: frame_info %s\n", message);
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index ade770e..9be7943 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -8367,7 +8367,7 @@ arm_skip_stub (struct frame_info *frame, CORE_ADDR pc)
     {
       /* Use the name suffix to determine which register contains the
          target PC.  */
-      static char *table[15] =
+      static const char *table[15] =
       {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
        "r8", "r9", "sl", "fp", "ip", "sp", "lr"
       };
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 01099f5..05b1dd7 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -128,7 +128,8 @@ static void gen_binop (struct agent_expr *ax,
 		       struct axs_value *value1,
 		       struct axs_value *value2,
 		       enum agent_op op,
-		       enum agent_op op_unsigned, int may_carry, char *name);
+		       enum agent_op op_unsigned, int may_carry,
+		       const char *name);
 static void gen_logical_not (struct agent_expr *ax, struct axs_value *value,
 			     struct type *result_type);
 static void gen_complement (struct agent_expr *ax, struct axs_value *value);
@@ -144,12 +145,13 @@ static void gen_primitive_field (struct expression *exp,
 static int gen_struct_ref_recursive (struct expression *exp,
 				     struct agent_expr *ax,
 				     struct axs_value *value,
-				     char *field, int offset,
+				     const char *field, int offset,
 				     struct type *type);
 static void gen_struct_ref (struct expression *exp, struct agent_expr *ax,
 			    struct axs_value *value,
-			    char *field,
-			    char *operator_name, char *operand_name);
+			    const char *field,
+			    const char *operator_name,
+			    const char *operand_name);
 static void gen_static_field (struct gdbarch *gdbarch,
 			      struct agent_expr *ax, struct axs_value *value,
 			      struct type *type, int fieldno);
@@ -1149,7 +1151,7 @@ static void
 gen_binop (struct agent_expr *ax, struct axs_value *value,
 	   struct axs_value *value1, struct axs_value *value2,
 	   enum agent_op op, enum agent_op op_unsigned,
-	   int may_carry, char *name)
+	   int may_carry, const char *name)
 {
   /* We only handle INT op INT.  */
   if ((TYPE_CODE (value1->type) != TYPE_CODE_INT)
@@ -1434,7 +1436,7 @@ gen_primitive_field (struct expression *exp,
 static int
 gen_struct_ref_recursive (struct expression *exp, struct agent_expr *ax,
 			  struct axs_value *value,
-			  char *field, int offset, struct type *type)
+			  const char *field, int offset, struct type *type)
 {
   int i, rslt;
   int nbases = TYPE_N_BASECLASSES (type);
@@ -1498,8 +1500,8 @@ gen_struct_ref_recursive (struct expression *exp, struct agent_expr *ax,
    it operates on; we use them in error messages.  */
 static void
 gen_struct_ref (struct expression *exp, struct agent_expr *ax,
-		struct axs_value *value, char *field,
-		char *operator_name, char *operand_name)
+		struct axs_value *value, const char *field,
+		const char *operator_name, const char *operand_name)
 {
   struct type *type;
   int found;
@@ -1671,7 +1673,8 @@ static int
 gen_aggregate_elt_ref (struct expression *exp,
 		       struct agent_expr *ax, struct axs_value *value,
 		       struct type *type, char *field,
-		       char *operator_name, char *operand_name)
+		       const char *operator_name,
+		       const char *operand_name)
 {
   switch (TYPE_CODE (type))
     {
diff --git a/gdb/bcache.c b/gdb/bcache.c
index d6c0921..06ab843 100644
--- a/gdb/bcache.c
+++ b/gdb/bcache.c
@@ -356,7 +356,7 @@ print_percentage (int portion, int total)
    BCACHE holds.  Statistics are printed using `printf_filtered' and
    its ilk.  */
 void
-print_bcache_statistics (struct bcache *c, char *type)
+print_bcache_statistics (struct bcache *c, const char *type)
 {
   int occupied_buckets;
   int max_chain_length;
diff --git a/gdb/bcache.h b/gdb/bcache.h
index 8ec0bde..f9590aa 100644
--- a/gdb/bcache.h
+++ b/gdb/bcache.h
@@ -165,7 +165,7 @@ extern struct bcache *bcache_xmalloc (
    eliminating duplication.  TYPE should be a string describing the
    kind of data BCACHE holds.  Statistics are printed using
    `printf_filtered' and its ilk.  */
-extern void print_bcache_statistics (struct bcache *bcache, char *type);
+extern void print_bcache_statistics (struct bcache *bcache, const char *type);
 extern int bcache_memory_used (struct bcache *bcache);
 
 /* The hash functions */
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 4cd7a00..3925ec6 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -6215,7 +6215,7 @@ bptype_string (enum bptype type)
   struct ep_type_description
     {
       enum bptype type;
-      char *description;
+      const char *description;
     };
   static struct ep_type_description bptypes[] =
   {
@@ -8507,7 +8507,7 @@ static struct breakpoint_ops catch_solib_breakpoint_ops;
    created in an enabled state.  */
 
 void
-add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
+add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled)
 {
   struct solib_catchpoint *c;
   struct gdbarch *gdbarch = get_current_arch ();
@@ -8515,7 +8515,7 @@ add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
 
   if (!arg)
     arg = "";
-  arg = skip_spaces (arg);
+  arg = skip_spaces_const (arg);
 
   c = new solib_catchpoint ();
   cleanup = make_cleanup (xfree, c);
@@ -15857,7 +15857,7 @@ static struct cmd_list_element *catch_cmdlist;
 static struct cmd_list_element *tcatch_cmdlist;
 
 void
-add_catch_command (char *name, char *docstring,
+add_catch_command (const char *name, const char *docstring,
 		   cmd_sfunc_ftype *sfunc,
 		   completer_ftype *completer,
 		   void *user_data_catch,
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 6940270..a7f2128 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1275,7 +1275,7 @@ extern void initialize_breakpoint_ops (void);
    function.  */
 
 extern void
-  add_catch_command (char *name, char *docstring,
+  add_catch_command (const char *name, const char *docstring,
 		     cmd_sfunc_ftype *sfunc,
 		     completer_ftype *completer,
 		     void *user_data_catch,
@@ -1517,7 +1517,7 @@ extern int is_catchpoint (struct breakpoint *);
 
 /* Shared helper function (MI and CLI) for creating and installing
    a shared object event catchpoint.  */
-extern void add_solib_catchpoint (char *arg, int is_load, int is_temp,
+extern void add_solib_catchpoint (const char *arg, int is_load, int is_temp,
                                   int enabled);
 
 /* Enable breakpoints and delete when hit.  Called with ARG == NULL
diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index 5d4775c..9769d20 100644
--- a/gdb/bsd-uthread.c
+++ b/gdb/bsd-uthread.c
@@ -464,7 +464,7 @@ bsd_uthread_update_thread_list (struct target_ops *ops)
 }
 
 /* Possible states a thread can be in.  */
-static char *bsd_uthread_state[] =
+static const char *bsd_uthread_state[] =
 {
   "RUNNING",
   "SIGTHREAD",
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 76d74f8..cbad027 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -825,7 +825,7 @@ free_buildsym_compunit (void)
    directory name actually is (by checking for a trailing '/').  */
 
 void
-patch_subfile_names (struct subfile *subfile, char *name)
+patch_subfile_names (struct subfile *subfile, const char *name)
 {
   if (subfile != NULL
       && buildsym_compunit->comp_dir == NULL
diff --git a/gdb/buildsym.h b/gdb/buildsym.h
index fc5f0e7..60109a0 100644
--- a/gdb/buildsym.h
+++ b/gdb/buildsym.h
@@ -194,7 +194,7 @@ typedef void (record_line_ftype) (struct subfile *subfile, int line,
 
 /* Function to invoke get the next symbol.  Return the symbol name.  */
 
-EXTERN char *(*next_symbol_text_func) (struct objfile *);
+EXTERN const char *(*next_symbol_text_func) (struct objfile *);
 
 extern void add_symbol_to_list (struct symbol *symbol,
 				struct pending **listhead);
@@ -216,7 +216,7 @@ extern void really_free_pendings (void *dummy);
 
 extern void start_subfile (const char *name);
 
-extern void patch_subfile_names (struct subfile *subfile, char *name);
+extern void patch_subfile_names (struct subfile *subfile, const char *name);
 
 extern void push_subfile (void);
 
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 7c25641..b2fc195 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -70,7 +70,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (char *);
+void yyerror (const char *);
 
 static int type_aggregate_p (struct type *);
 
@@ -2217,7 +2217,7 @@ DEF_ENUM_FLAGS_TYPE (enum token_flag, token_flags);
 
 struct token
 {
-  char *oper;
+  const char *oper;
   int token;
   enum exp_opcode opcode;
   token_flags flags;
@@ -3265,7 +3265,7 @@ c_print_token (FILE *file, int type, YYSTYPE value)
 #endif
 
 void
-yyerror (char *msg)
+yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
diff --git a/gdb/c-lang.h b/gdb/c-lang.h
index c4b19ec..9746238 100644
--- a/gdb/c-lang.h
+++ b/gdb/c-lang.h
@@ -63,7 +63,7 @@ DEF_ENUM_FLAGS_TYPE (enum c_string_type_values, c_string_type);
 
 extern int c_parse (struct parser_state *);
 
-extern void c_yyerror (char *);
+extern void c_yyerror (const char *);
 
 extern int c_parse_escape (const char **, struct obstack *);
 
@@ -120,7 +120,7 @@ extern void c_type_print_base (struct type *, struct ui_file *,
 /* These are in cp-valprint.c */
 
 extern void cp_print_class_member (const gdb_byte *, struct type *,
-				   struct ui_file *, char *);
+				   struct ui_file *, const char *);
 
 extern void cp_print_value_fields (struct type *, struct type *,
 				   LONGEST, CORE_ADDR,
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index a5793e5..e3b097b 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -843,7 +843,7 @@ cplus_describe_child (const struct varobj *parent, int index,
 	}
       else
 	{
-	  char *access = NULL;
+	  const char *access = NULL;
 	  int children[3];
 
 	  cplus_class_num_children (type, children);
diff --git a/gdb/charset.c b/gdb/charset.c
index cc24f70..8302c59 100644
--- a/gdb/charset.c
+++ b/gdb/charset.c
@@ -706,7 +706,11 @@ static VEC (char_ptr) *charsets;
 static void
 find_charset_names (void)
 {
-  VEC_safe_push (char_ptr, charsets, GDB_DEFAULT_HOST_CHARSET);
+  /* Cast is fine here, because CHARSETS is never released.  Note that
+     the vec does not hold "const char *" pointers instead of "char *"
+     because the non-phony version stores heap-allocated strings in
+     it.  */
+  VEC_safe_push (char_ptr, charsets, (char *) GDB_DEFAULT_HOST_CHARSET);
   VEC_safe_push (char_ptr, charsets, NULL);
 }
 
@@ -775,7 +779,7 @@ static void
 find_charset_names (void)
 {
   struct pex_obj *child;
-  char *args[3];
+  const char *args[3];
   int err, status;
   int fail = 1;
   int flags;
@@ -811,7 +815,8 @@ find_charset_names (void)
 #endif
   /* Note that we simply ignore errors here.  */
   if (!pex_run_in_environment (child, flags,
-			       args[0], args, environ_vector (iconv_env),
+			       args[0], const_cast<char **> (args),
+			       environ_vector (iconv_env),
 			       NULL, NULL, &err))
     {
       FILE *in = pex_read_output (child, 0);
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index f7ffb6d..4956ba7 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -242,10 +242,11 @@ help_command (char *command, int from_tty)
    [Is that why this function writes output with *_unfiltered?]  */
 
 static void
-complete_command (char *arg, int from_tty)
+complete_command (char *arg_entry, int from_tty)
 {
+  const char *arg = arg_entry;
   int argpoint;
-  char *point, *arg_prefix;
+  char *arg_prefix;
   VEC (char_ptr) *completions;
 
   dont_repeat ();
@@ -270,7 +271,7 @@ complete_command (char *arg, int from_tty)
      within, and except for filenames at the beginning of, the word to
      be completed.  The following crude imitation of readline's
      word-breaking tries to accomodate this.  */
-  point = arg + argpoint;
+  const char *point = arg + argpoint;
   while (point > arg)
     {
       if (strchr (rl_completer_word_break_characters, point[-1]) != 0)
@@ -392,10 +393,7 @@ cd_command (char *dir, int from_tty)
      repeat might be useful but is more likely to be a mistake.  */
   dont_repeat ();
 
-  if (dir == 0)
-    dir = "~";
-
-  dir = tilde_expand (dir);
+  dir = tilde_expand (dir != NULL ? dir : "~");
   cleanup = make_cleanup (xfree, dir);
 
   if (chdir (dir) < 0)
@@ -809,7 +807,7 @@ edit_command (char *arg, int from_tty)
   struct symtabs_and_lines sals;
   struct symtab_and_line sal;
   struct symbol *sym;
-  char *editor;
+  const char *editor;
   char *p;
   const char *fn;
 
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 4e302b7..fc14465 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1479,7 +1479,8 @@ undef_cmd_error (const char *cmdtype, const char *q)
    the function field of the struct cmd_list_element is 0).  */
 
 struct cmd_list_element *
-lookup_cmd (const char **line, struct cmd_list_element *list, char *cmdtype,
+lookup_cmd (const char **line, struct cmd_list_element *list,
+	    const char *cmdtype,
 	    int allow_unknown, int ignore_help_classes)
 {
   struct cmd_list_element *last_list = 0;
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 9630261..213622d 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -247,7 +247,7 @@ dump_memory_to_file (const char *cmd, const char *mode, const char *file_format)
 }
 
 static void
-dump_memory_command (char *cmd, char *mode)
+dump_memory_command (char *cmd, const char *mode)
 {
   dump_memory_to_file (cmd, mode, "binary");
 }
@@ -298,7 +298,7 @@ dump_value_to_file (const char *cmd, const char *mode, const char *file_format)
 }
 
 static void
-dump_value_command (char *cmd, char *mode)
+dump_value_command (char *cmd, const char *mode)
 {
   dump_value_to_file (cmd, mode, "binary");
 }
@@ -377,8 +377,8 @@ append_binary_value (char *args, int from_tty)
 
 struct dump_context
 {
-  void (*func) (char *cmd, char *mode);
-  char *mode;
+  void (*func) (char *cmd, const char *mode);
+  const char *mode;
 };
 
 static void
@@ -390,8 +390,9 @@ call_dump_func (struct cmd_list_element *c, char *args, int from_tty)
 }
 
 static void
-add_dump_command (char *name, void (*func) (char *args, char *mode),
-		  char *descr)
+add_dump_command (const char *name,
+		  void (*func) (char *args, const char *mode),
+		  const char *descr)
 
 {
   struct cmd_list_element *c;
@@ -576,7 +577,7 @@ restore_command (char *args_in, int from_tty)
   filename = scan_filename_with_cleanup (&args, NULL);
   if (args != NULL && *args != '\0')
     {
-      char *binary_string = "binary";
+      static const char binary_string[] = "binary";
 
       /* Look for optional "binary" flag.  */
       if (startswith (args, binary_string))
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index c3f1c65..33b657d 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -166,7 +166,7 @@ build_command_line (enum command_control_type type, const char *args)
    such as "if" and "while".  */
 
 struct command_line *
-get_command_line (enum command_control_type type, char *arg)
+get_command_line (enum command_control_type type, const char *arg)
 {
   struct command_line *cmd;
   struct cleanup *old_chain = NULL;
diff --git a/gdb/cli/cli-script.h b/gdb/cli/cli-script.h
index 969c5c6..c885976 100644
--- a/gdb/cli/cli-script.h
+++ b/gdb/cli/cli-script.h
@@ -39,7 +39,7 @@ extern enum command_control_type
 	execute_control_command_untraced (struct command_line *cmd);
 
 extern struct command_line *get_command_line (enum command_control_type,
-					      char *);
+					      const char *);
 
 extern void print_command_lines (struct ui_out *,
 				 struct command_line *, unsigned int);
diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c
index 65004c0..e8c6b67 100644
--- a/gdb/coff-pe-read.c
+++ b/gdb/coff-pe-read.c
@@ -54,7 +54,7 @@ struct read_pe_section_data
   enum minimal_symbol_type ms_type;	/* Type to assign symbols in
 					   section.  */
   unsigned int index;		/* BFD section number.  */
-  char *section_name;		/* Recorded section name.  */
+  const char *section_name;	/* Recorded section name.  */
 };
 
 #define IMAGE_SCN_CNT_CODE 0x20
diff --git a/gdb/command.h b/gdb/command.h
index 2c86da4..ae20021 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -204,7 +204,8 @@ extern enum cmd_types cmd_type (struct cmd_list_element *cmd);
 #define CMD_LIST_AMBIGUOUS ((struct cmd_list_element *) -1)
 
 extern struct cmd_list_element *lookup_cmd (const char **,
-					    struct cmd_list_element *, char *,
+					    struct cmd_list_element *,
+					    const char *,
 					    int, int);
 
 extern struct cmd_list_element *lookup_cmd_1 (const char **,
diff --git a/gdb/common/print-utils.c b/gdb/common/print-utils.c
index a0fb541..52ecaf1 100644
--- a/gdb/common/print-utils.c
+++ b/gdb/common/print-utils.c
@@ -38,7 +38,7 @@ get_print_cell (void)
 }
 
 static char *
-decimal2str (char *sign, ULONGEST addr, int width)
+decimal2str (const char *sign, ULONGEST addr, int width)
 {
   /* Steal code from valprint.c:print_decimal().  Should this worry
      about the real size of addr as the above does?  */
diff --git a/gdb/completer.c b/gdb/completer.c
index 9183e2a..7e46416 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1684,7 +1684,8 @@ gdb_print_filename (char *to_print, char *full_pathname, int prefix_bytes,
 		    const struct match_list_displayer *displayer)
 {
   int printed_len, extension_char, slen, tlen;
-  char *s, c, *new_full_pathname, *dn;
+  char *s, c, *new_full_pathname;
+  const char *dn;
   extern int _rl_complete_mark_directories;
 
   extension_char = 0;
diff --git a/gdb/corefile.c b/gdb/corefile.c
index 54cb789..13a90b9 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -509,7 +509,7 @@ complete_set_gnutarget (struct cmd_list_element *cmd,
 
 /* Set the gnutarget.  */
 void
-set_gnutarget (char *newtarget)
+set_gnutarget (const char *newtarget)
 {
   if (gnutarget_string != NULL)
     xfree (gnutarget_string);
diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index 73a4d90..78745cb 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -173,7 +173,7 @@ static struct demangle_component *d_binary (const char *,
 
 int yyparse (void);
 static int yylex (void);
-static void yyerror (char *);
+static void yyerror (const char *);
 
 /* Enable yydebug for the stand-alone parser.  */
 #ifdef TEST_CPNAMES
@@ -1934,7 +1934,7 @@ yylex (void)
 }
 
 static void
-yyerror (char *msg)
+yyerror (const char *msg)
 {
   if (global_errmsg)
     return;
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 143bb48..73fe03d 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -759,7 +759,7 @@ cp_find_class_member (struct type **self_p, int *fieldno,
 
 void
 cp_print_class_member (const gdb_byte *valaddr, struct type *type,
-		       struct ui_file *stream, char *prefix)
+		       struct ui_file *stream, const char *prefix)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
 
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index aefd44a..a46356f 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -1695,7 +1695,7 @@ cris_special_register_name (struct gdbarch *gdbarch, int regno)
 static const char *
 cris_register_name (struct gdbarch *gdbarch, int regno)
 {
-  static char *cris_genreg_names[] =
+  static const char *cris_genreg_names[] =
   { "r0",  "r1",  "r2",  "r3", \
     "r4",  "r5",  "r6",  "r7", \
     "r8",  "r9",  "r10", "r11", \
@@ -1720,14 +1720,14 @@ cris_register_name (struct gdbarch *gdbarch, int regno)
 static const char *
 crisv32_register_name (struct gdbarch *gdbarch, int regno)
 {
-  static char *crisv32_genreg_names[] =
+  static const char *crisv32_genreg_names[] =
     { "r0",  "r1",  "r2",  "r3", \
       "r4",  "r5",  "r6",  "r7", \
       "r8",  "r9",  "r10", "r11", \
       "r12", "r13", "sp",  "acr"
     };
 
-  static char *crisv32_sreg_names[] =
+  static const char *crisv32_sreg_names[] =
     { "s0",  "s1",  "s2",  "s3", \
       "s4",  "s5",  "s6",  "s7", \
       "s8",  "s9",  "s10", "s11", \
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index 8625e41..06eef5f 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -69,7 +69,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (char *);
+void yyerror (const char *);
 
 static int type_aggregate_p (struct type *);
 
@@ -957,7 +957,7 @@ parse_string_or_char (const char *tokptr, const char **outptr,
 
 struct token
 {
-  char *oper;
+  const char *oper;
   int token;
   enum exp_opcode opcode;
 };
@@ -1648,7 +1648,7 @@ d_parse (struct parser_state *par_state)
 }
 
 void
-yyerror (char *msg)
+yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
diff --git a/gdb/d-lang.h b/gdb/d-lang.h
index 27e05a1..f47050a 100644
--- a/gdb/d-lang.h
+++ b/gdb/d-lang.h
@@ -58,7 +58,7 @@ struct builtin_d_type
 
 extern int d_parse (struct parser_state *);
 
-extern void d_yyerror (char *);
+extern void d_yyerror (const char *);
 
 /* Defined in d-lang.c  */
 
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index e95d228..daa3ce9 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -237,7 +237,7 @@ find_text_range (bfd * sym_bfd, struct objfile *objfile)
 
 struct header_file_location
 {
-  char *name;			/* Name of header file */
+  const char *name;		/* Name of header file */
   int instance;			/* See above */
   struct partial_symtab *pst;	/* Partial symtab that has the
 				   BINCL/EINCL defs for this file.  */
@@ -262,13 +262,14 @@ static void read_dbx_symtab (minimal_symbol_reader &, struct objfile *);
 
 static void free_bincl_list (struct objfile *);
 
-static struct partial_symtab *find_corresponding_bincl_psymtab (char *, int);
+static struct partial_symtab *find_corresponding_bincl_psymtab (const char *,
+								int);
 
-static void add_bincl_to_list (struct partial_symtab *, char *, int);
+static void add_bincl_to_list (struct partial_symtab *, const char *, int);
 
 static void init_bincl_list (int, struct objfile *);
 
-static char *dbx_next_symbol_text (struct objfile *);
+static const char *dbx_next_symbol_text (struct objfile *);
 
 static void fill_symbuf (bfd *);
 
@@ -284,13 +285,13 @@ static void record_minimal_symbol (minimal_symbol_reader &,
 				   const char *, CORE_ADDR, int,
 				   struct objfile *);
 
-static void add_new_header_file (char *, int);
+static void add_new_header_file (const char *, int);
 
-static void add_old_header_file (char *, int);
+static void add_old_header_file (const char *, int);
 
 static void add_this_object_header_file (int);
 
-static struct partial_symtab *start_psymtab (struct objfile *, char *,
+static struct partial_symtab *start_psymtab (struct objfile *, const char *,
 					     CORE_ADDR, int,
 					     struct partial_symbol **,
 					     struct partial_symbol **);
@@ -340,7 +341,7 @@ add_this_object_header_file (int i)
    symbol tables for the same header file.  */
 
 static void
-add_old_header_file (char *name, int instance)
+add_old_header_file (const char *name, int instance)
 {
   struct header_file *p = HEADER_FILES (dbxread_objfile);
   int i;
@@ -366,7 +367,7 @@ add_old_header_file (char *name, int instance)
    so we record the file when its "begin" is seen and ignore the "end".  */
 
 static void
-add_new_header_file (char *name, int instance)
+add_new_header_file (const char *name, int instance)
 {
   int i;
   struct header_file *hfile;
@@ -734,7 +735,7 @@ static int symbuf_end;
 
 /* Name of last function encountered.  Used in Solaris to approximate
    object file boundaries.  */
-static char *last_function_name;
+static const char *last_function_name;
 
 /* The address in memory of the string table of the object file we are
    reading (which might not be the "main" object file, but might be a
@@ -842,7 +843,7 @@ stabs_seek (int sym_offset)
    (a \ at the end of the text of a name)
    call this function to get the continuation.  */
 
-static char *
+static const char *
 dbx_next_symbol_text (struct objfile *objfile)
 {
   struct internal_nlist nlist;
@@ -873,7 +874,7 @@ init_bincl_list (int number, struct objfile *objfile)
 /* Add a bincl to the list.  */
 
 static void
-add_bincl_to_list (struct partial_symtab *pst, char *name, int instance)
+add_bincl_to_list (struct partial_symtab *pst, const char *name, int instance)
 {
   if (next_bincl >= bincl_list + bincls_allocated)
     {
@@ -895,7 +896,7 @@ add_bincl_to_list (struct partial_symtab *pst, char *name, int instance)
    with that header_file_location.  */
 
 static struct partial_symtab *
-find_corresponding_bincl_psymtab (char *name, int instance)
+find_corresponding_bincl_psymtab (const char *name, int instance)
 {
   struct header_file_location *bincl;
 
@@ -933,10 +934,10 @@ make_cleanup_free_bincl_list (struct objfile *objfile)
    give a fake name, and print a single error message per symbol file read,
    rather than abort the symbol reading or flood the user with messages.  */
 
-static char *
+static const char *
 set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
 {
-  char *namestring;
+  const char *namestring;
 
   if (nlist->n_strx + file_string_table_offset
       >= DBX_STRINGTAB_SIZE (objfile)
@@ -954,18 +955,19 @@ set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
 }
 
 static CORE_ADDR
-find_stab_function_addr (char *namestring, const char *filename,
+find_stab_function_addr (const char *namestring, const char *filename,
 			 struct objfile *objfile)
 {
   struct bound_minimal_symbol msym;
-  char *p;
   int n;
 
-  p = strchr (namestring, ':');
-  if (p == NULL)
-    p = namestring;
-  n = p - namestring;
-  p = (char *) alloca (n + 2);
+  const char *colon = strchr (namestring, ':');
+  if (colon == NULL)
+    n = 0;
+  else
+    n = colon - namestring;
+
+  char *p = (char *) alloca (n + 2);
   strncpy (p, namestring, n);
   p[n] = 0;
 
@@ -1017,10 +1019,10 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
   struct internal_nlist nlist;
   CORE_ADDR text_addr;
   int text_size;
-  char *sym_name;
+  const char *sym_name;
   int sym_len;
 
-  char *namestring;
+  const char *namestring;
   int nsl;
   int past_first_source_file = 0;
   CORE_ADDR last_function_start = 0;
@@ -1283,7 +1285,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	    static int prev_so_symnum = -10;
 	    static int first_so_symnum;
 	    const char *p;
-	    static char *dirname_nso;
+	    static const char *dirname_nso;
 	    int prev_textlow_not_set;
 
 	    valu = nlist.n_value + ANOFFSET (objfile->section_offsets,
@@ -1477,7 +1479,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	case N_M2C:		/* I suspect that I can ignore this here.  */
 	case N_SCOPE:		/* Same.   */
 	{
-	  char *p;
+	  const char *p;
 
 	  namestring = set_namestring (objfile, &nlist);
 
@@ -1631,7 +1633,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		     Accept either.  */
 		  while (*p && *p != ';' && *p != ',')
 		    {
-		      char *q;
+		      const char *q;
 
 		      /* Check for and handle cretinous dbx symbol name
 			 continuation!  */
@@ -1996,7 +1998,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
    (normal).  */
 
 static struct partial_symtab *
-start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow,
+start_psymtab (struct objfile *objfile, const char *filename, CORE_ADDR textlow,
 	       int ldsymoff, struct partial_symbol **global_syms,
 	       struct partial_symbol **static_syms)
 {
@@ -2057,15 +2059,15 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
   if (pst->texthigh == 0 && last_function_name
       && gdbarch_sofun_address_maybe_missing (gdbarch))
     {
-      char *p;
       int n;
       struct bound_minimal_symbol minsym;
 
-      p = strchr (last_function_name, ':');
-      if (p == NULL)
-	p = last_function_name;
-      n = p - last_function_name;
-      p = (char *) alloca (n + 2);
+      const char *colon = strchr (last_function_name, ':');
+      if (colon == NULL)
+	n = 0;
+      else
+	n = colon - last_function_name;
+      char *p = (char *) alloca (n + 2);
       strncpy (p, last_function_name, n);
       p[n] = 0;
 
@@ -2293,7 +2295,7 @@ dbx_read_symtab (struct partial_symtab *self, struct objfile *objfile)
 static void
 read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
 {
-  char *namestring;
+  const char *namestring;
   struct external_nlist *bufp;
   struct internal_nlist nlist;
   unsigned char type;
@@ -2499,7 +2501,7 @@ cp_set_block_scope (const struct symbol *symbol,
    is used in end_symtab.  */
 
 void
-process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
+process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
 		    const struct section_offsets *section_offsets,
 		    struct objfile *objfile)
 {
@@ -2805,7 +2807,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
          down ONE MORE function call level, which we really don't want
          to do).  */
       {
-	char *p;
+	const char *p;
 
 	/* Normal object file and NLMs have non-zero text seg offsets,
 	   but don't need their static syms offset in this fashion.
@@ -2898,7 +2900,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
       if (name)
 	{
 	  int deftype;
-	  char *colon_pos = strchr (name, ':');
+	  const char *colon_pos = strchr (name, ':');
 
 	  if (colon_pos == NULL)
 	    deftype = '\0';
@@ -3021,7 +3023,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
          definition.  If a symbol reference is being defined, go ahead
          and add it.  Otherwise, just return.  */
 
-      char *s = name;
+      const char *s = name;
       int refnum;
 
       /* If this stab defines a new reference ID that is not on the
diff --git a/gdb/defs.h b/gdb/defs.h
index aa58605..f689ec5 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -309,7 +309,7 @@ typedef void initialize_file_ftype (void);
 
 extern char *gdb_readline_wrapper (const char *);
 
-extern char *command_line_input (const char *, int, char *);
+extern char *command_line_input (const char *, int, const char *);
 
 extern void print_prompt (void);
 
@@ -324,7 +324,8 @@ extern int info_verbose;
 extern void set_next_address (struct gdbarch *, CORE_ADDR);
 
 extern int print_address_symbolic (struct gdbarch *, CORE_ADDR,
-				   struct ui_file *, int, char *);
+				   struct ui_file *, int,
+				   const char *);
 
 extern int build_address_symbolic (struct gdbarch *,
 				   CORE_ADDR addr,
@@ -678,7 +679,7 @@ extern int (*deprecated_query_hook) (const char *, va_list)
 extern void (*deprecated_warning_hook) (const char *, va_list)
      ATTRIBUTE_FPTR_PRINTF(1,0);
 extern void (*deprecated_interactive_hook) (void);
-extern void (*deprecated_readline_begin_hook) (char *, ...)
+extern void (*deprecated_readline_begin_hook) (const char *, ...)
      ATTRIBUTE_FPTR_PRINTF_1;
 extern char *(*deprecated_readline_hook) (const char *);
 extern void (*deprecated_readline_end_hook) (void);
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index f1a10c4..ebdd519 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1779,7 +1779,7 @@ static const char *dwarf_attr_name (unsigned int);
 
 static const char *dwarf_form_name (unsigned int);
 
-static char *dwarf_bool_name (unsigned int);
+static const char *dwarf_bool_name (unsigned int);
 
 static const char *dwarf_type_encoding_name (unsigned int);
 
@@ -19777,7 +19777,7 @@ guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
    prefix part in such case.  See
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510.  */
 
-static char *
+static const char *
 anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct attribute *attr;
@@ -19830,7 +19830,7 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
   struct die_info *parent, *spec_die;
   struct dwarf2_cu *spec_cu;
   struct type *parent_type;
-  char *retval;
+  const char *retval;
 
   if (cu->language != language_cplus
       && cu->language != language_fortran && cu->language != language_d
@@ -20232,7 +20232,7 @@ dwarf_form_name (unsigned form)
   return name;
 }
 
-static char *
+static const char *
 dwarf_bool_name (unsigned mybool)
 {
   if (mybool)
diff --git a/gdb/event-top.c b/gdb/event-top.c
index dd2770a..1281df8 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -650,7 +650,7 @@ command_line_append_input_line (struct buffer *cmd_line_buffer, char *rl)
 
 char *
 handle_line_of_input (struct buffer *cmd_line_buffer,
-		      char *rl, int repeat, char *annotation_suffix)
+		      char *rl, int repeat, const char *annotation_suffix)
 {
   struct ui *ui = current_ui;
   int from_tty = ui->instream == ui->stdin_stream;
diff --git a/gdb/exceptions.c b/gdb/exceptions.c
index b0f28d9..f9a80a0 100644
--- a/gdb/exceptions.c
+++ b/gdb/exceptions.c
@@ -221,8 +221,8 @@ catch_exceptions_with_msg (struct ui_out *func_uiout,
 /* This function is superseded by catch_exceptions().  */
 
 int
-catch_errors (catch_errors_ftype *func, void *func_args, char *errstring,
-	      return_mask mask)
+catch_errors (catch_errors_ftype *func, void *func_args,
+	      const char *errstring, return_mask mask)
 {
   struct gdb_exception exception = exception_none;
   volatile int val = 0;
diff --git a/gdb/exceptions.h b/gdb/exceptions.h
index cf7d0f0..b2cdee3 100644
--- a/gdb/exceptions.h
+++ b/gdb/exceptions.h
@@ -86,7 +86,8 @@ extern int catch_exceptions_with_msg (struct ui_out *uiout,
    This function is superseded by catch_exceptions().  */
 
 typedef int (catch_errors_ftype) (void *);
-extern int catch_errors (catch_errors_ftype *, void *, char *, return_mask);
+extern int catch_errors (catch_errors_ftype *, void *,
+			 const char *, return_mask);
 
 /* Compare two exception objects for print equality.  */
 extern int exception_print_same (struct gdb_exception e1,
diff --git a/gdb/expprint.c b/gdb/expprint.c
index b74d32c..9b8ac4c 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -62,7 +62,7 @@ print_subexp_standard (struct expression *exp, int *pos,
   const struct op_print *op_print_tab;
   int pc;
   unsigned nargs;
-  char *op_str;
+  const char *op_str;
   int assign_modify = 0;
   enum exp_opcode opcode;
   enum precedence myprec = PREC_NULL;
@@ -649,7 +649,7 @@ print_subexp_standard (struct expression *exp, int *pos,
 /* Return the operator corresponding to opcode OP as
    a string.   NULL indicates that the opcode was not found in the
    current language table.  */
-char *
+const char *
 op_string (enum exp_opcode op)
 {
   int tem;
@@ -669,7 +669,7 @@ static int dump_subexp_body (struct expression *exp, struct ui_file *, int);
 
 /* Name for OPCODE, when it appears in expression EXP.  */
 
-char *
+const char *
 op_name (struct expression *exp, enum exp_opcode opcode)
 {
   return exp->language_defn->la_exp_desc->op_name (opcode);
@@ -678,7 +678,7 @@ op_name (struct expression *exp, enum exp_opcode opcode)
 /* Default name for the standard operator OPCODE (i.e., one defined in
    the definition of enum exp_opcode).  */
 
-char *
+const char *
 op_name_standard (enum exp_opcode opcode)
 {
   switch (opcode)
@@ -703,10 +703,9 @@ op_name_standard (enum exp_opcode opcode)
 
 void
 dump_raw_expression (struct expression *exp, struct ui_file *stream,
-		     char *note)
+		     const char *note)
 {
   int elt;
-  char *opcode_name;
   char *eltscan;
   int eltsize;
 
@@ -722,9 +721,10 @@ dump_raw_expression (struct expression *exp, struct ui_file *stream,
   for (elt = 0; elt < exp->nelts; elt++)
     {
       fprintf_filtered (stream, "\t%5d  ", elt);
-      opcode_name = op_name (exp, exp->elts[elt].opcode);
 
+      const char *opcode_name = op_name (exp, exp->elts[elt].opcode);
       fprintf_filtered (stream, "%20s  ", opcode_name);
+
       print_longest (stream, 'd', 0, exp->elts[elt].longconst);
       fprintf_filtered (stream, "  ");
 
diff --git a/gdb/expression.h b/gdb/expression.h
index e4e96f6..8fe6b07 100644
--- a/gdb/expression.h
+++ b/gdb/expression.h
@@ -146,12 +146,12 @@ extern struct value *evaluate_subexp_standard
 
 extern void print_expression (struct expression *, struct ui_file *);
 
-extern char *op_name (struct expression *exp, enum exp_opcode opcode);
+extern const char *op_name (struct expression *exp, enum exp_opcode opcode);
 
-extern char *op_string (enum exp_opcode);
+extern const char *op_string (enum exp_opcode);
 
 extern void dump_raw_expression (struct expression *,
-				 struct ui_file *, char *);
+				 struct ui_file *, const char *);
 extern void dump_prefix_expression (struct expression *, struct ui_file *);
 
 /* In an OP_RANGE expression, either bound could be empty, indicating
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 49d797d..7e9e234 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -72,7 +72,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (char *);
+void yyerror (const char *);
 
 static void growbuf_by_size (int);
 
@@ -773,7 +773,7 @@ parse_number (struct parser_state *par_state,
 
 struct token
 {
-  char *oper;
+  const char *oper;
   int token;
   enum exp_opcode opcode;
 };
@@ -807,7 +807,7 @@ static const struct token dot_ops[] =
 
 struct f77_boolean_val 
 {
-  char *name;
+  const char *name;
   int value;
 }; 
 
@@ -1219,7 +1219,7 @@ f_parse (struct parser_state *par_state)
 }
 
 void
-yyerror (char *msg)
+yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index 08a5f25..5633b41 100644
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
@@ -25,7 +25,7 @@ struct parser_state;
 
 extern int f_parse (struct parser_state *);
 
-extern void f_yyerror (char *);	/* Defined in f-exp.y */
+extern void f_yyerror (const char *);	/* Defined in f-exp.y */
 
 extern void f_print_type (struct type *, const char *, struct ui_file *, int,
 			  int, const struct type_print_options *);
diff --git a/gdb/fork-child.c b/gdb/fork-child.c
index dc2a314..04d2cdf 100644
--- a/gdb/fork-child.c
+++ b/gdb/fork-child.c
@@ -292,7 +292,7 @@ fork_inferior (char *exec_file_arg, char *allargs, char **env,
 	 <args>".  */
       argv = (char **) alloca (4 * sizeof (char *));
       argv[0] = shell_file;
-      argv[1] = "-c";
+      argv[1] = (char *) "-c";
       argv[2] = shell_command;
       argv[3] = (char *) 0;
     }
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 87124e7..8744733 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -87,7 +87,7 @@ struct gdbarch_tdep
   int num_hw_breakpoints;
 
   /* Register names.  */
-  char **register_names;
+  const char **register_names;
 };
 
 /* Return the FR-V ABI associated with GDBARCH.  */
@@ -147,8 +147,8 @@ new_variant (void)
   /* By default, don't supply any general-purpose or floating-point
      register names.  */
   var->register_names 
-    = (char **) xmalloc ((frv_num_regs + frv_num_pseudo_regs)
-                         * sizeof (char *));
+    = (const char **) xmalloc ((frv_num_regs + frv_num_pseudo_regs)
+			       * sizeof (const char *));
   for (r = 0; r < frv_num_regs + frv_num_pseudo_regs; r++)
     var->register_names[r] = "";
 
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 6debb10..319a890 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -84,7 +84,7 @@ pstring (const char *string)
   return string;
 }
 
-static char *
+static const char *
 pstring_ptr (char **string)
 {
   if (string == NULL || *string == NULL)
@@ -95,7 +95,7 @@ pstring_ptr (char **string)
 /* Helper function to print a list of strings, represented as "const
    char *const *".  The list is printed comma-separated.  */
 
-static char *
+static const char *
 pstring_list (const char *const *list)
 {
   static char ret[100];
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index c471b73..bdfb6b2 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1678,7 +1678,7 @@ pstring (const char *string)
   return string;
 }
 
-static char *
+static const char *
 pstring_ptr (char **string)
 {
   if (string == NULL || *string == NULL)
@@ -1689,7 +1689,7 @@ pstring_ptr (char **string)
 /* Helper function to print a list of strings, represented as "const
    char *const *".  The list is printed comma-separated.  */
 
-static char *
+static const char *
 pstring_list (const char *const *list)
 {
   static char ret[100];
diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h
index 12ce466..40ae37c 100644
--- a/gdb/gdbcore.h
+++ b/gdb/gdbcore.h
@@ -167,7 +167,7 @@ extern void validate_files (void);
 
 extern char *gnutarget;
 
-extern void set_gnutarget (char *);
+extern void set_gnutarget (const char *);
 
 /* Structure to keep track of core register reading functions for
    various core file types.  */
diff --git a/gdb/gdbserver/gdbreplay.c b/gdb/gdbserver/gdbreplay.c
index 3bd9f3f..b768506 100644
--- a/gdb/gdbserver/gdbreplay.c
+++ b/gdb/gdbserver/gdbreplay.c
@@ -142,7 +142,7 @@ perror_with_name (const char *string)
 }
 
 static void
-sync_error (FILE *fp, char *desc, int expect, int got)
+sync_error (FILE *fp, const char *desc, int expect, int got)
 {
   fprintf (stderr, "\n%s\n", desc);
   fprintf (stderr, "At logfile offset %ld, expected '0x%x' got '0x%x'\n",
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index 6df1d51..b39026c 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -1067,7 +1067,7 @@ append_insns (CORE_ADDR *to, size_t len, const unsigned char *buf)
 }
 
 static int
-push_opcode (unsigned char *buf, char *op)
+push_opcode (unsigned char *buf, const char *op)
 {
   unsigned char *buf_org = buf;
 
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index c4d0d2b..1906e68 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -81,7 +81,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (char *);
+void yyerror (const char *);
 
 %}
 
@@ -936,7 +936,7 @@ parse_string_or_char (const char *tokptr, const char **outptr,
 
 struct token
 {
-  char *oper;
+  const char *oper;
   int token;
   enum exp_opcode opcode;
 };
@@ -1588,7 +1588,7 @@ go_parse (struct parser_state *par_state)
 }
 
 void
-yyerror (char *msg)
+yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
diff --git a/gdb/go-lang.h b/gdb/go-lang.h
index 101cf9d..e08b2f0 100644
--- a/gdb/go-lang.h
+++ b/gdb/go-lang.h
@@ -60,7 +60,7 @@ enum go_type
 
 extern int go_parse (struct parser_state *);
 
-extern void go_yyerror (char *);
+extern void go_yyerror (const char *);
 
 /* Defined in go-lang.c.  */
 
diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c
index d2d8d7a..a20067e 100644
--- a/gdb/go32-nat.c
+++ b/gdb/go32-nat.c
@@ -1126,7 +1126,7 @@ go32_sysinfo (char *arg, int from_tty)
   /* CPUID with EAX = 1 returns processor signature and features.  */
   if (cpuid_max >= 1)
     {
-      static char *brand_name[] = {
+      static const char *brand_name[] = {
 	"",
 	" Celeron",
 	" III",
diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c
index 71cffbb..9189446 100644
--- a/gdb/guile/scm-breakpoint.c
+++ b/gdb/guile/scm-breakpoint.c
@@ -851,7 +851,6 @@ gdbscm_breakpoint_expression (SCM self)
 {
   breakpoint_smob *bp_smob
     = bpscm_get_valid_breakpoint_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  char *str;
   struct watchpoint *wp;
 
   if (!is_watchpoint (bp_smob->bp))
@@ -859,7 +858,7 @@ gdbscm_breakpoint_expression (SCM self)
 
   wp = (struct watchpoint *) bp_smob->bp;
 
-  str = wp->exp_string;
+  const char *str = wp->exp_string;
   if (! str)
     str = "";
 
diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c
index 5f6d442..ae5d145 100644
--- a/gdb/guile/scm-cmd.c
+++ b/gdb/guile/scm-cmd.c
@@ -291,8 +291,10 @@ cmdscm_destroyer (struct cmd_list_element *self, void *context)
 /* Called by gdb to invoke the command.  */
 
 static void
-cmdscm_function (struct cmd_list_element *command, char *args, int from_tty)
+cmdscm_function (struct cmd_list_element *command,
+		 char *args_entry, 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/guile/scm-param.c b/gdb/guile/scm-param.c
index 6d2cc13..ab00fd9 100644
--- a/gdb/guile/scm-param.c
+++ b/gdb/guile/scm-param.c
@@ -602,7 +602,7 @@ pascm_param_value (enum var_types type, void *var,
     case var_filename:
     case var_enum:
       {
-	char *str = * (char **) var;
+	const char *str = *(char **) var;
 
 	if (str == NULL)
 	  str = "";
diff --git a/gdb/h8300-tdep.c b/gdb/h8300-tdep.c
index 10ef796..060e5d3 100644
--- a/gdb/h8300-tdep.c
+++ b/gdb/h8300-tdep.c
@@ -954,7 +954,7 @@ h8300_register_name (struct gdbarch *gdbarch, int regno)
 {
   /* The register names change depending on which h8300 processor
      type is selected.  */
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6",
     "sp", "", "pc", "cycles", "tick", "inst",
     "ccr",			/* pseudo register */
@@ -971,7 +971,7 @@ h8300_register_name (struct gdbarch *gdbarch, int regno)
 static const char *
 h8300s_register_name (struct gdbarch *gdbarch, int regno)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "er0", "er1", "er2", "er3", "er4", "er5", "er6",
     "sp", "", "pc", "cycles", "", "tick", "inst",
     "mach", "macl",
@@ -989,7 +989,7 @@ h8300s_register_name (struct gdbarch *gdbarch, int regno)
 static const char *
 h8300sx_register_name (struct gdbarch *gdbarch, int regno)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "er0", "er1", "er2", "er3", "er4", "er5", "er6",
     "sp", "", "pc", "cycles", "", "tick", "inst",
     "mach", "macl", "sbr", "vbr",
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index a5053c6..2636a27 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -613,7 +613,7 @@ typedef BP_MANIPULATION (hppa_break_insn) hppa_breakpoint;
 static const char *
 hppa32_register_name (struct gdbarch *gdbarch, int i)
 {
-  static char *names[] = {
+  static const char *names[] = {
     "flags",  "r1",      "rp",     "r3",
     "r4",     "r5",      "r6",     "r7",
     "r8",     "r9",      "r10",    "r11",
@@ -656,7 +656,7 @@ hppa32_register_name (struct gdbarch *gdbarch, int i)
 static const char *
 hppa64_register_name (struct gdbarch *gdbarch, int i)
 {
-  static char *names[] = {
+  static const char *names[] = {
     "flags",  "r1",      "rp",     "r3",
     "r4",     "r5",      "r6",     "r7",
     "r8",     "r9",      "r10",    "r11",
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index 4c53bc6..22e1588 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -140,7 +140,7 @@ enum pseudo_regs { FIRST_PSEUDO_REGNUM = NUM_IA64_RAW_REGS,
 /* Array of register names; There should be ia64_num_regs strings in
    the initializer.  */
 
-static char *ia64_register_names[] = 
+static const char *ia64_register_names[] =
 { "r0",   "r1",   "r2",   "r3",   "r4",   "r5",   "r6",   "r7",
   "r8",   "r9",   "r10",  "r11",  "r12",  "r13",  "r14",  "r15",
   "r16",  "r17",  "r18",  "r19",  "r20",  "r21",  "r22",  "r23",
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index d41e609..f6ffb9b 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -261,14 +261,14 @@ construct_inferior_arguments (int argc, char **argv)
 #ifdef __MINGW32__
       /* This holds all the characters considered special to the
 	 Windows shells.  */
-      char *special = "\"!&*|[]{}<>?`~^=;, \t\n";
-      const char quote = '"';
+      static const char special[] = "\"!&*|[]{}<>?`~^=;, \t\n";
+      static const char quote = '"';
 #else
       /* This holds all the characters considered special to the
 	 typical Unix shells.  We include `^' because the SunOS
 	 /bin/sh treats it as a synonym for `|'.  */
-      char *special = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
-      const char quote = '\'';
+      static const char special[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
+      static const char quote = '\'';
 #endif
       int i;
       int length = 0;
@@ -2267,7 +2267,7 @@ static void
 path_command (char *dirname, int from_tty)
 {
   char *exec_path;
-  char *env;
+  const char *env;
 
   dont_repeat ();
   env = get_in_environ (current_inferior ()->environment, path_var_name);
@@ -2681,7 +2681,7 @@ enum attach_post_wait_mode
    should be running.  Else if ATTACH, */
 
 static void
-attach_post_wait (char *args, int from_tty, enum attach_post_wait_mode mode)
+attach_post_wait (const char *args, int from_tty, enum attach_post_wait_mode mode)
 {
   struct inferior *inferior;
 
diff --git a/gdb/language.c b/gdb/language.c
index f1fc220..ee0101d 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -46,7 +46,7 @@
 
 extern void _initialize_language (void);
 
-static void unk_lang_error (char *);
+static void unk_lang_error (const char *);
 
 static int unk_lang_parser (struct parser_state *);
 
@@ -206,7 +206,7 @@ show_range_command (struct ui_file *file, int from_tty,
 {
   if (range_mode == range_mode_auto)
     {
-      char *tmp;
+      const char *tmp;
 
       switch (range_check)
 	{
@@ -280,7 +280,7 @@ show_case_command (struct ui_file *file, int from_tty,
 {
   if (case_mode == case_mode_auto)
     {
-      char *tmp = NULL;
+      const char *tmp = NULL;
 
       switch (case_sensitivity)
 	{
@@ -731,7 +731,7 @@ unk_lang_parser (struct parser_state *ps)
 }
 
 static void
-unk_lang_error (char *msg)
+unk_lang_error (const char *msg)
 {
   error (_("Attempted to parse an expression with unknown language"));
 }
diff --git a/gdb/language.h b/gdb/language.h
index 96080ac..58bcbe8 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -183,7 +183,7 @@ struct language_defn
 
     /* Parser error function.  */
 
-    void (*la_error) (char *);
+    void (*la_error) (const char *);
 
     /* Given an expression *EXPP created by prefixifying the result of
        la_parser, perform any remaining processing necessary to complete
@@ -271,7 +271,7 @@ struct language_defn
     /* If this is non-NULL, specifies the name that of the implicit
        local variable that refers to the current object instance.  */
 
-    char *la_name_of_this;
+    const char *la_name_of_this;
 
     /* This is a function that lookup_symbol will call when it gets to
        the part of symbol lookup where C looks up static and global
diff --git a/gdb/linespec.c b/gdb/linespec.c
index a3cb0cb..dcbe253 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1293,7 +1293,8 @@ decode_line_2 (struct linespec_state *self,
 	       struct symtabs_and_lines *result,
 	       const char *select_mode)
 {
-  char *args, *prompt;
+  char *args;
+  const char *prompt;
   int i;
   struct cleanup *old_chain;
   VEC (const_char_ptr) *filters = NULL;
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 0e2607b..eda3d7b 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -262,7 +262,7 @@ struct private_thread_info
 };
 \f
 
-static char *
+static const char *
 thread_db_err_str (td_err_e err)
 {
   static char buf[64];
diff --git a/gdb/lm32-tdep.c b/gdb/lm32-tdep.c
index 3cd9338..bd3e182 100644
--- a/gdb/lm32-tdep.c
+++ b/gdb/lm32-tdep.c
@@ -91,7 +91,7 @@ lm32_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 static const char *
 lm32_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
     "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index acf2e1b..9179187 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -65,7 +65,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (char *);
+void yyerror (const char *);
 
 static int parse_number (int);
 
@@ -1050,7 +1050,7 @@ m2_parse (struct parser_state *par_state)
 }
 
 void
-yyerror (char *msg)
+yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h
index 6f73394..30fddd7 100644
--- a/gdb/m2-lang.h
+++ b/gdb/m2-lang.h
@@ -22,7 +22,7 @@ struct parser_state;
 
 extern int m2_parse (struct parser_state *); /* Defined in m2-exp.y */
 
-extern void m2_yyerror (char *);	/* Defined in m2-exp.y */
+extern void m2_yyerror (const char *);	/* Defined in m2-exp.y */
 
 /* Defined in m2-typeprint.c */
 extern void m2_print_type (struct type *, const char *, struct ui_file *, int,
diff --git a/gdb/m32r-tdep.c b/gdb/m32r-tdep.c
index 40f29d3..1d0d7ed 100644
--- a/gdb/m32r-tdep.c
+++ b/gdb/m32r-tdep.c
@@ -202,7 +202,7 @@ m32r_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
 }
 
-char *m32r_register_names[] = {
+static const char *m32r_register_names[] = {
   "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
   "r8", "r9", "r10", "r11", "r12", "fp", "lr", "sp",
   "psw", "cbr", "spi", "spu", "bpc", "pc", "accl", "acch",
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index d06598f..893d9c2 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -166,7 +166,7 @@ struct m68hc11_unwind_cache
 
 /* Table of registers for 68HC11.  This includes the hard registers
    and the soft registers used by GCC.  */
-static char *
+static const char *
 m68hc11_register_names[] =
 {
   "x",    "d",    "y",    "sp",   "pc",   "a",    "b",
diff --git a/gdb/m88k-tdep.c b/gdb/m88k-tdep.c
index 6ae9590..57fe644 100644
--- a/gdb/m88k-tdep.c
+++ b/gdb/m88k-tdep.c
@@ -49,7 +49,7 @@ m88k_fetch_instruction (CORE_ADDR pc, enum bfd_endian byte_order)
 static const char *
 m88k_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  static char *register_names[] =
+  static const char *register_names[] =
   {
     "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
     "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15",
diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index 5537d9d..e7a0dad 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -170,7 +170,7 @@ appendc (struct macro_buffer *b, int c)
 
 /* Append the LEN bytes at ADDR to the buffer B.  */
 static void
-appendmem (struct macro_buffer *b, char *addr, int len)
+appendmem (struct macro_buffer *b, const char *addr, int len)
 {
   int new_len = b->len + len;
 
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 952dffb..8e27194 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -220,7 +220,7 @@ static int found_ecoff_debugging_info;
 /* Forward declarations.  */
 
 static int upgrade_type (int, struct type **, int, union aux_ext *,
-			 int, char *);
+			 int, const char *);
 
 static void parse_partial_symbols (minimal_symbol_reader &,
 				   struct objfile *);
@@ -228,9 +228,9 @@ static void parse_partial_symbols (minimal_symbol_reader &,
 static int has_opaque_xref (FDR *, SYMR *);
 
 static int cross_ref (int, union aux_ext *, struct type **, enum type_code,
-		      char **, int, char *);
+		      const char **, int, const char *);
 
-static struct symbol *new_symbol (char *);
+static struct symbol *new_symbol (const char *);
 
 static struct type *new_type (char *);
 
@@ -245,14 +245,14 @@ static struct linetable *new_linetable (int);
 static struct blockvector *new_bvect (int);
 
 static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
-				int, char *);
+				int, const char *);
 
-static struct symbol *mylookup_symbol (char *, const struct block *,
+static struct symbol *mylookup_symbol (const char *, const struct block *,
 				       domain_enum, enum address_class);
 
 static void sort_blocks (struct symtab *);
 
-static struct partial_symtab *new_psymtab (char *, struct objfile *);
+static struct partial_symtab *new_psymtab (const char *, struct objfile *);
 
 static void psymtab_to_symtab_1 (struct objfile *objfile,
 				 struct partial_symtab *, const char *);
@@ -268,7 +268,7 @@ static struct linetable *shrink_linetable (struct linetable *);
 static void handle_psymbol_enumerators (struct objfile *, FDR *, int,
 					CORE_ADDR);
 
-static char *mdebug_next_symbol_text (struct objfile *);
+static const char *mdebug_next_symbol_text (struct objfile *);
 \f
 /* Exported procedure: Builds a symtab from the partial symtab SELF.
    Restores the environment in effect when SELF was created, delegates
@@ -322,7 +322,7 @@ get_rfd (int cf, int rf)
 
 /* Return a safer print NAME for a file descriptor.  */
 
-static char *
+static const char *
 fdr_name (FDR *f)
 {
   if (f->rss == -1)
@@ -574,7 +574,7 @@ static int mdebug_regparm_index;
 static void
 add_data_symbol (SYMR *sh, union aux_ext *ax, int bigend,
 		 struct symbol *s, int aclass_index, struct block *b,
-		 struct objfile *objfile, char *name)
+		 struct objfile *objfile, const char *name)
 {
   SYMBOL_DOMAIN (s) = VAR_DOMAIN;
   SYMBOL_ACLASS_INDEX (s) = aclass_index;
@@ -596,7 +596,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
-  char *name;
+  const char *name;
   struct symbol *s;
   struct block *b;
   struct mdebug_pending *pend;
@@ -1530,7 +1530,7 @@ basic_type (int bt, struct objfile *objfile)
 
 static struct type *
 parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
-	    int bigend, char *sym_name)
+	    int bigend, const char *sym_name)
 {
   TIR t[1];
   struct type *tp = 0;
@@ -1658,7 +1658,7 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
      name.  This apparently is a MIPS extension for C sets.  */
       t->bt == btSet)
     {
-      char *name;
+      const char *name;
 
       /* Try to cross reference this type, build new type on failure.  */
       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
@@ -1718,7 +1718,7 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
      FIXME: We are not doing any guessing on range types.  */
   if (t->bt == btRange)
     {
-      char *name;
+      const char *name;
 
       /* Try to cross reference this type, build new type on failure.  */
       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
@@ -1751,7 +1751,7 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
     }
   if (t->bt == btTypedef)
     {
-      char *name;
+      const char *name;
 
       /* Try to cross reference this type, it should succeed.  */
       ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
@@ -1819,7 +1819,7 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
 
 static int
 upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend,
-	      char *sym_name)
+	      const char *sym_name)
 {
   int off;
   struct type *t;
@@ -2110,7 +2110,7 @@ parse_external (EXTR *es, int bigend, struct section_offsets *section_offsets,
   /* Reading .o files */
   if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil)
     {
-      char *what;
+      const char *what;
       switch (es->asym.st)
 	{
 	case stNil:
@@ -2851,7 +2851,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 
 		switch (type_code)
 		  {
-		    char *p;
+		    const char *p;
 
 		    /* Standard, external, non-debugger, symbols.  */
 
@@ -3205,7 +3205,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			       Accept either.  */
 			    while (*p && *p != ';' && *p != ',')
 			      {
-				char *q;
+				const char *q;
 
 				/* Check for and handle cretinous dbx
 				   symbol name continuation!  */
@@ -3887,7 +3887,7 @@ handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype,
 
 /* Get the next symbol.  OBJFILE is unused.  */
 
-static char *
+static const char *
 mdebug_next_symbol_text (struct objfile *objfile)
 {
   SYMR sh;
@@ -4360,7 +4360,7 @@ static int
 cross_ref (int fd, union aux_ext *ax, struct type **tpp,
 	   enum type_code type_code,
 	   /* Use to alloc new type if none is found.  */
-	   char **pname, int bigend, char *sym_name)
+	   const char **pname, int bigend, const char *sym_name)
 {
   RNDXR rn[1];
   unsigned int rf;
@@ -4556,7 +4556,7 @@ cross_ref (int fd, union aux_ext *ax, struct type **tpp,
    keeping the symtab sorted.  */
 
 static struct symbol *
-mylookup_symbol (char *name, const struct block *block,
+mylookup_symbol (const char *name, const struct block *block,
 		 domain_enum domain, enum address_class theclass)
 {
   struct block_iterator iter;
@@ -4742,7 +4742,7 @@ new_symtab (const char *name, int maxlines, struct objfile *objfile)
 /* Allocate a new partial_symtab NAME.  */
 
 static struct partial_symtab *
-new_psymtab (char *name, struct objfile *objfile)
+new_psymtab (const char *name, struct objfile *objfile)
 {
   struct partial_symtab *psymtab;
 
@@ -4836,7 +4836,7 @@ new_block (enum block_type type)
 /* Create a new symbol with printname NAME.  */
 
 static struct symbol *
-new_symbol (char *name)
+new_symbol (const char *name)
 {
   struct symbol *s = allocate_symbol (mdebugread_objfile);
 
diff --git a/gdb/memattr.c b/gdb/memattr.c
index e01e2c8..2493537 100644
--- a/gdb/memattr.c
+++ b/gdb/memattr.c
@@ -441,7 +441,7 @@ mem_info_command (char *args, int from_tty)
 
   for (ix = 0; VEC_iterate (mem_region_s, mem_region_list, ix, m); ix++)
     {
-      char *tmp;
+      const char *tmp;
 
       printf_filtered ("%-3d %-3c\t",
 		       m->number,
diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
index b1dcc86..5a45d6e 100644
--- a/gdb/mep-tdep.c
+++ b/gdb/mep-tdep.c
@@ -305,7 +305,7 @@ register_set_keyword_table (const CGEN_HW_ENTRY *hw)
 /* Given a keyword table KEYWORD and a register number REGNUM, return
    the name of the register, or "" if KEYWORD contains no register
    whose number is REGNUM.  */
-static char *
+static const char *
 register_name_from_keyword (CGEN_KEYWORD *keyword_table, int regnum)
 {
   const CGEN_KEYWORD_ENTRY *entry
diff --git a/gdb/mi/mi-cmd-env.c b/gdb/mi/mi-cmd-env.c
index a6347ee..4093178 100644
--- a/gdb/mi/mi-cmd-env.c
+++ b/gdb/mi/mi-cmd-env.c
@@ -116,7 +116,7 @@ mi_cmd_env_path (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   char *exec_path;
-  char *env;
+  const char *env;
   int reset = 0;
   int oind = 0;
   int i;
@@ -271,7 +271,7 @@ void
 _initialize_mi_cmd_env (void)
 {
   struct gdb_environ *environment;
-  char *env;
+  const char *env;
 
   /* We want original execution path to reset to, if desired later.
      At this point, current inferior is not created, so cannot use
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index bb56205..bd91033 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -578,7 +578,7 @@ list_args_or_locals (enum what_to_list what, enum print_values values,
   struct block_iterator iter;
   struct cleanup *cleanup_list;
   struct type *type;
-  char *name_of_result;
+  const char *name_of_result;
   struct ui_out *uiout = current_uiout;
 
   block = get_frame_block (fi, 0);
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 430c07b..78ef8e0 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -492,7 +492,7 @@ mi_cmd_var_show_attributes (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   int attr;
-  char *attstr;
+  const char *attstr;
   struct varobj *var;
 
   if (argc != 1)
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 9a87657..91fe104 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -89,7 +89,7 @@ static void mi_cmd_execute (struct mi_parse *parse);
 
 static void mi_execute_cli_command (const char *cmd, int args_p,
 				    const char *args);
-static void mi_execute_async_cli_command (char *cli_command,
+static void mi_execute_async_cli_command (const char *cli_command,
 					  char **argv, int argc);
 static int register_changed_p (int regnum, struct regcache *,
 			       struct regcache *);
@@ -2031,7 +2031,7 @@ captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
 	/* Echo the command on the console.  */
 	fprintf_unfiltered (gdb_stdlog, "%s\n", context->command);
 	/* Call the "console" interpreter.  */
-	argv[0] = INTERP_CONSOLE;
+	argv[0] = (char *) INTERP_CONSOLE;
 	argv[1] = context->command;
 	mi_cmd_interpreter_exec ("-interpreter-exec", argv, 2);
 
@@ -2344,7 +2344,7 @@ mi_execute_cli_command (const char *cmd, int args_p, const char *args)
 }
 
 void
-mi_execute_async_cli_command (char *cli_command, char **argv, int argc)
+mi_execute_async_cli_command (const char *cli_command, char **argv, int argc)
 {
   struct cleanup *old_cleanups;
   char *run;
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 41cb9d8..45d1d73 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -608,7 +608,7 @@ mips_register_name (struct gdbarch *gdbarch, int regno)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   /* GPR names for all ABIs other than n32/n64.  */
-  static char *mips_gpr_names[] = {
+  static const char *mips_gpr_names[] = {
     "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
     "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
     "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
@@ -616,7 +616,7 @@ mips_register_name (struct gdbarch *gdbarch, int regno)
   };
 
   /* GPR names for n32 and n64 ABIs.  */
-  static char *mips_n32_n64_gpr_names[] = {
+  static const char *mips_n32_n64_gpr_names[] = {
     "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
     "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
     "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
@@ -6880,7 +6880,7 @@ set_mips_command (char *args, int from_tty)
 static void
 show_mipsfpu_command (char *args, int from_tty)
 {
-  char *fpu;
+  const char *fpu;
 
   if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_mips)
     {
diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index 38356e5..0f5e10f 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -246,8 +246,8 @@ mn10300_return_value (struct gdbarch *gdbarch, struct value *function,
   return RETURN_VALUE_REGISTER_CONVENTION;
 }
 
-static char *
-register_name (int reg, char **regs, long sizeof_regs)
+static const char *
+register_name (int reg, const char **regs, long sizeof_regs)
 {
   if (reg < 0 || reg >= sizeof_regs / sizeof (regs[0]))
     return NULL;
@@ -258,7 +258,7 @@ register_name (int reg, char **regs, long sizeof_regs)
 static const char *
 mn10300_generic_register_name (struct gdbarch *gdbarch, int reg)
 {
-  static char *regs[] =
+  static const char *regs[] =
   { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
     "sp", "pc", "mdr", "psw", "lir", "lar", "", "",
     "", "", "", "", "", "", "", "",
@@ -271,7 +271,7 @@ mn10300_generic_register_name (struct gdbarch *gdbarch, int reg)
 static const char *
 am33_register_name (struct gdbarch *gdbarch, int reg)
 {
-  static char *regs[] =
+  static const char *regs[] =
   { "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
     "sp", "pc", "mdr", "psw", "lir", "lar", "",
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
@@ -283,7 +283,7 @@ am33_register_name (struct gdbarch *gdbarch, int reg)
 static const char *
 am33_2_register_name (struct gdbarch *gdbarch, int reg)
 {
-  static char *regs[] =
+  static const char *regs[] =
   {
     "d0", "d1", "d2", "d3", "a0", "a1", "a2", "a3",
     "sp", "pc", "mdr", "psw", "lir", "lar", "mdrq", "r0",
diff --git a/gdb/moxie-tdep.c b/gdb/moxie-tdep.c
index 7383f27..d0f4223 100644
--- a/gdb/moxie-tdep.c
+++ b/gdb/moxie-tdep.c
@@ -74,7 +74,7 @@ typedef BP_MANIPULATION (moxie_break_insn) moxie_breakpoint;
 
 /* Moxie register names.  */
 
-char *moxie_register_names[] = {
+static const char *moxie_register_names[] = {
   "$fp",  "$sp",  "$r0",  "$r1",  "$r2",
   "$r3",  "$r4",  "$r5", "$r6", "$r7",
   "$r8", "$r9", "$r10", "$r11", "$r12",
diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c
index 2417a46..ba2e5a5 100644
--- a/gdb/nat/linux-osdata.c
+++ b/gdb/nat/linux-osdata.c
@@ -1627,9 +1627,9 @@ linux_xfer_osdata_modules (gdb_byte *readbuf,
 }
 
 struct osdata_type {
-  char *type;
-  char *title;
-  char *description;
+  const char *type;
+  const char *title;
+  const char *description;
   LONGEST (*getter) (gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
 } osdata_table[] = {
   { "cpus", "CPUs", "Listing of all cpus/cores on the system",
diff --git a/gdb/nto-tdep.c b/gdb/nto-tdep.c
index 04ad06c..8f8d1d5 100644
--- a/gdb/nto-tdep.c
+++ b/gdb/nto-tdep.c
@@ -190,7 +190,7 @@ nto_parse_redirection (char *pargv[], const char **pin, const char **pout,
 		       const char **perr)
 {
   char **argv;
-  char *in, *out, *err, *p;
+  const char *in, *out, *err, *p;
   int argc, i, n;
 
   for (n = 0; pargv[n]; n++);
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index ad7c64e..e102b80 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -81,7 +81,7 @@ static const struct objfile_data *objc_objfile_data;
    suitably defined.  */
 
 struct symbol *
-lookup_struct_typedef (char *name, const struct block *block, int noerr)
+lookup_struct_typedef (const char *name, const struct block *block, int noerr)
 {
   struct symbol *sym;
 
@@ -106,7 +106,7 @@ lookup_struct_typedef (char *name, const struct block *block, int noerr)
 }
 
 CORE_ADDR 
-lookup_objc_class (struct gdbarch *gdbarch, char *classname)
+lookup_objc_class (struct gdbarch *gdbarch, const char *classname)
 {
   struct type *char_type = builtin_type (gdbarch)->builtin_char;
   struct value * function, *classval;
@@ -135,7 +135,7 @@ lookup_objc_class (struct gdbarch *gdbarch, char *classname)
 }
 
 CORE_ADDR
-lookup_child_selector (struct gdbarch *gdbarch, char *selname)
+lookup_child_selector (struct gdbarch *gdbarch, const char *selname)
 {
   struct type *char_type = builtin_type (gdbarch)->builtin_char;
   struct value * function, *selstring;
@@ -1233,7 +1233,7 @@ print_object_command (char *args, int from_tty)
  */
 
 struct objc_methcall {
-  char *name;
+  const char *name;
  /* Return instance method to be called.  */
   int (*stop_at) (CORE_ADDR, CORE_ADDR *);
   /* Start of pc range corresponding to method invocation.  */
diff --git a/gdb/objc-lang.h b/gdb/objc-lang.h
index 49e6878..e22b198 100644
--- a/gdb/objc-lang.h
+++ b/gdb/objc-lang.h
@@ -29,9 +29,9 @@ struct block;
 struct parser_state;
 
 extern CORE_ADDR lookup_objc_class     (struct gdbarch *gdbarch,
-					char *classname);
+					const char *classname);
 extern CORE_ADDR lookup_child_selector (struct gdbarch *gdbarch,
-					char *methodname);
+					const char *methodname);
 
 extern char *objc_demangle (const char *mangled, int options);
 
@@ -48,7 +48,8 @@ extern void start_msglist (void);
 extern void add_msglist (struct stoken *str, int addcolon);
 extern int end_msglist (struct parser_state *);
 
-struct symbol *lookup_struct_typedef (char *name, const struct block *block,
+struct symbol *lookup_struct_typedef (const char *name,
+				      const struct block *block,
 				      int noerr);
 
 #endif
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 758fa86..9500b1c 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -1469,7 +1469,7 @@ find_pc_section (CORE_ADDR pc)
 /* Return non-zero if PC is in a section called NAME.  */
 
 int
-pc_in_section (CORE_ADDR pc, char *name)
+pc_in_section (CORE_ADDR pc, const char *name)
 {
   struct obj_section *s;
   int retval = 0;
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index f719d30..58db6c9 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -514,7 +514,7 @@ extern int have_minimal_symbols (void);
 extern struct obj_section *find_pc_section (CORE_ADDR pc);
 
 /* Return non-zero if PC is in a section called NAME.  */
-extern int pc_in_section (CORE_ADDR, char *);
+extern int pc_in_section (CORE_ADDR, const char *);
 
 /* Return non-zero if PC is in a SVR4-style procedure linkage table
    section.  */
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index 5911d8d..81eb216 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -72,7 +72,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (char *);
+void yyerror (const char *);
 
 static char *uptok (const char *, int);
 %}
@@ -1047,7 +1047,7 @@ pop_current_type (void)
 
 struct token
 {
-  char *oper;
+  const char *oper;
   int token;
   enum exp_opcode opcode;
 };
@@ -1714,7 +1714,7 @@ pascal_parse (struct parser_state *par_state)
 }
 
 void
-yyerror (char *msg)
+yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
diff --git a/gdb/p-lang.h b/gdb/p-lang.h
index aa03987..96a290b 100644
--- a/gdb/p-lang.h
+++ b/gdb/p-lang.h
@@ -27,7 +27,7 @@ extern const char *pascal_main_name (void);
 
 extern int pascal_parse (struct parser_state *); /* Defined in p-exp.y */
 
-extern void pascal_yyerror (char *);	/* Defined in p-exp.y */
+extern void pascal_yyerror (const char *);	/* Defined in p-exp.y */
 
 /* Defined in p-typeprint.c */
 extern void pascal_print_type (struct type *, const char *, struct ui_file *,
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index 0913580..fadc2ef 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -262,7 +262,7 @@ extern int operator_check_standard (struct expression *exp, int pos,
 				      (struct objfile *objfile, void *data),
 				    void *data);
 
-extern char *op_name_standard (enum exp_opcode);
+extern const char *op_name_standard (enum exp_opcode);
 
 extern struct type *follow_types (struct type *);
 
@@ -312,7 +312,7 @@ enum precedence
 
 struct op_print
   {
-    char *string;
+    const char *string;
     enum exp_opcode opcode;
     /* Precedence of operator.  These values are used only by comparisons.  */
     enum precedence precedence;
@@ -352,7 +352,7 @@ struct exp_descriptor
        The returned value should never be NULL, even if EXP_OPCODE is
        an unknown opcode (a string containing an image of the numeric
        value of the opcode can be returned, for instance).  */
-    char *(*op_name) (enum exp_opcode);
+    const char *(*op_name) (enum exp_opcode);
 
     /* Dump the rest of this (prefix) expression after the operator
        itself has been printed.  See dump_subexp_body_standard in
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index e4a35a7..f09f18a 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -560,7 +560,7 @@ set_next_address (struct gdbarch *gdbarch, CORE_ADDR addr)
 int
 print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
 			struct ui_file *stream,
-			int do_demangle, char *leadin)
+			int do_demangle, const char *leadin)
 {
   char *name = NULL;
   char *filename = NULL;
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index d98a4af..bdce8f2 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -875,7 +875,7 @@ psym_forget_cached_source_info (struct objfile *objfile)
 
 static void
 print_partial_symbols (struct gdbarch *gdbarch,
-		       struct partial_symbol **p, int count, char *what,
+		       struct partial_symbol **p, int count, const char *what,
 		       struct ui_file *outfile)
 {
   fprintf_filtered (outfile, "  %s partial symbols:\n", what);
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 2043d42..15811c6 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -41,7 +41,7 @@ static int bppy_live;
 gdbpy_breakpoint_object *bppy_pending_object;
 
 /* Function that is called when a Python condition is evaluated.  */
-static char * const stop_func = "stop";
+static const char stop_func[] = "stop";
 
 /* This is used to initialize various gdb.bp_* constants.  */
 struct pybp_code
@@ -400,7 +400,7 @@ bppy_get_location (PyObject *self, void *closure)
 static PyObject *
 bppy_get_expression (PyObject *self, void *closure)
 {
-  char *str;
+  const char *str;
   gdbpy_breakpoint_object *obj = (gdbpy_breakpoint_object *) self;
   struct watchpoint *wp;
 
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 8f61d9c..d53ae84 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -32,10 +32,8 @@
 /* Struct representing built-in completion types.  */
 struct cmdpy_completer
 {
-  /* Python symbol name.
-     This isn't a const char * for Python 2.4's sake.
-     PyModule_AddIntConstant only takes a char *, sigh.  */
-  char *name;
+  /* Python symbol name.  */
+  const char *name;
   /* Completion function.  */
   completer_ftype *completer;
 };
@@ -111,8 +109,10 @@ cmdpy_destroyer (struct cmd_list_element *self, void *context)
 /* Called by gdb to invoke the command.  */
 
 static void
-cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
+cmdpy_function (struct cmd_list_element *command,
+		char *args_entry, 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/py-event.c b/gdb/python/py-event.c
index 127dcc7..d00c050 100644
--- a/gdb/python/py-event.c
+++ b/gdb/python/py-event.c
@@ -47,7 +47,7 @@ create_event_object (PyTypeObject *py_type)
    function acquires a new reference to ATTR.  */
 
 int
-evpy_add_attribute (PyObject *event, char *name, PyObject *attr)
+evpy_add_attribute (PyObject *event, const char *name, PyObject *attr)
 {
   return PyObject_SetAttrString (event, name, attr);
 }
@@ -67,7 +67,7 @@ gdbpy_initialize_event (void)
 
 int
 gdbpy_initialize_event_generic (PyTypeObject *type,
-                                char *name)
+                                const char *name)
 {
   if (PyType_Ready (type) < 0)
     return -1;
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 4b2f4c0..ccb8513 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -131,9 +131,9 @@ extern int emit_clear_objfiles_event (void);
 
 extern void evpy_dealloc (PyObject *self);
 extern int evpy_add_attribute (PyObject *event,
-                               char *name, PyObject *attr)
+                               const char *name, PyObject *attr)
   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_event_generic (PyTypeObject *type, char *name)
+int gdbpy_initialize_event_generic (PyTypeObject *type, const char *name)
   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
 
 #endif /* GDB_PY_EVENT_H */
diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c
index 4766bd6..126d18c 100644
--- a/gdb/python/py-evts.c
+++ b/gdb/python/py-evts.c
@@ -38,7 +38,7 @@ static struct PyModuleDef EventModuleDef =
 /* Initialize python events.  */
 
 static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
-add_new_registry (eventregistry_object **registryp, char *name)
+add_new_registry (eventregistry_object **registryp, const char *name)
 {
   *registryp = create_eventregistry_object ();
 
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 9d43d55..a49820a 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -33,7 +33,7 @@
 #include "py-ref.h"
 
 /* Function that is called when a Python finish bp is found out of scope.  */
-static char * const outofscope_func = "out_of_scope";
+static const char outofscope_func[] = "out_of_scope";
 
 /* struct implementing the gdb.FinishBreakpoint object by extending
    the gdb.Breakpoint class.  */
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 6db4aab..75b055c 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -301,7 +301,7 @@ py_print_value (struct ui_out *out, struct value *val,
    This function can return an iterator, or NULL.  */
 
 static PyObject *
-get_py_iter_from_func (PyObject *filter, char *func)
+get_py_iter_from_func (PyObject *filter, const char *func)
 {
   if (PyObject_HasAttrString (filter, func))
     {
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 8b4782b..9098cdc 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -577,7 +577,10 @@ get_buffer (PyObject *self, Py_buffer *buf, int flags)
   ret = PyBuffer_FillInfo (buf, self, membuf_obj->buffer,
 			   membuf_obj->length, 0,
 			   PyBUF_CONTIG);
-  buf->format = "c";
+
+  /* Despite the documentation saying this field is a "const char *",
+     in Python 3.4 at least, it's really a "char *".  */
+  buf->format = (char *) "c";
 
   return ret;
 }
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index d80b731..f0d3423 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -32,7 +32,7 @@
 /* Parameter constants and their values.  */
 struct parm_constant
 {
-  char *name;
+  const char *name;
   int value;
 };
 
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index b7821b5..a5c2873 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -204,7 +204,7 @@ unwind_infopy_str (PyObject *self)
   stb.puts ("Frame ID: ");
   fprint_frame_id (&stb, unwind_info->frame_id);
   {
-    char *sep = "";
+    const char *sep = "";
     int i;
     struct value_print_options opts;
     saved_reg *reg;
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 5a46493..18cf3ea 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -457,7 +457,7 @@ gdbpy_parameter_value (enum var_types type, void *var)
     case var_filename:
     case var_enum:
       {
-	char *str = * (char **) var;
+	const char *str = *(char **) var;
 
 	if (! str)
 	  str = "";
diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index 5f3aac2..252b423 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -1100,7 +1100,7 @@ remote_fileio_func_system (char *buf)
 }
 
 static struct {
-  char *name;
+  const char *name;
   void (*func)(char *);
 } remote_fio_func_map[] = {
   { "open", remote_fileio_func_open },
diff --git a/gdb/remote.c b/gdb/remote.c
index 956645a..68a3df1 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1025,7 +1025,7 @@ static int remote_async_terminal_ours_p;
 
 struct memory_packet_config
 {
-  char *name;
+  const char *name;
   long size;
   int fixed_p;
 };
@@ -1242,7 +1242,7 @@ static enum packet_support packet_support (int packet);
 static void
 show_packet_config_cmd (struct packet_config *config)
 {
-  char *support = "internal-error";
+  const char *support = "internal-error";
 
   switch (packet_config_support (config))
     {
@@ -8239,7 +8239,7 @@ static enum target_xfer_status
 remote_write_bytes (CORE_ADDR memaddr, const gdb_byte *myaddr, ULONGEST len,
 		    int unit_size, ULONGEST *xfered_len)
 {
-  char *packet_format = 0;
+  const char *packet_format = NULL;
 
   /* Check whether the target supports binary download.  */
   check_binary_download (memaddr);
@@ -11190,7 +11190,7 @@ remote_read_description (struct target_ops *target)
    decrease *LEFT.  Otherwise raise an error.  */
 
 static void
-remote_buffer_add_string (char **buffer, int *left, char *string)
+remote_buffer_add_string (char **buffer, int *left, const char *string)
 {
   int len = strlen (string);
 
diff --git a/gdb/reverse.c b/gdb/reverse.c
index 7f0a027..4080616 100644
--- a/gdb/reverse.c
+++ b/gdb/reverse.c
@@ -43,7 +43,7 @@ exec_direction_default (void *notused)
    Used to implement reverse-next etc. commands.  */
 
 static void
-exec_reverse_once (char *cmd, char *args, int from_tty)
+exec_reverse_once (const char *cmd, char *args, int from_tty)
 {
   char *reverse_command;
   enum exec_direction_kind dir = execution_direction;
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 67c4d51..eb784c5 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -3146,10 +3146,10 @@ rs6000_adjust_frame_regnum (struct gdbarch *gdbarch, int num, int eh_frame_p)
 struct variant
   {
     /* Name of this variant.  */
-    char *name;
+    const char *name;
 
     /* English description of the variant.  */
-    char *description;
+    const char *description;
 
     /* bfd_arch_info.arch corresponding to variant.  */
     enum bfd_architecture arch;
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index b3e0366..64b7c55 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -2471,7 +2471,7 @@ rust_parse (struct parser_state *state)
 /* The parser error handler.  */
 
 void
-rustyyerror (char *msg)
+rustyyerror (const char *msg)
 {
   const char *where = prev_lexptr ? prev_lexptr : lexptr;
   error (_("%s in expression, near `%s'."), (msg ? msg : "Error"), where);
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 4977b0a..fe8a58c 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1891,7 +1891,7 @@ rust_operator_length (const struct expression *exp, int pc, int *oplenp,
 
 /* op_name implementation for Rust.  */
 
-static char *
+static const char *
 rust_op_name (enum exp_opcode opcode)
 {
   switch (opcode)
diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h
index 8f2b682..61547d7 100644
--- a/gdb/rust-lang.h
+++ b/gdb/rust-lang.h
@@ -27,7 +27,7 @@ struct type;
 extern int rust_parse (struct parser_state *);
 
 /* The la_error implementation for Rust.  */
-extern void rustyyerror (char *);
+extern void rustyyerror (const char *);
 
 /* Return true if TYPE is a tuple type; otherwise false.  */
 extern bool rust_tuple_type_p (struct type *type);
diff --git a/gdb/serial.h b/gdb/serial.h
index b39cc33..c76ddbe 100644
--- a/gdb/serial.h
+++ b/gdb/serial.h
@@ -259,7 +259,7 @@ struct serial
 
 struct serial_ops
   {
-    char *name;
+    const char *name;
     int (*open) (struct serial *, const char *name);
     void (*close) (struct serial *);
     int (*fdopen) (struct serial *, int fd);
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 9b3692d..f4b4c48 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -111,7 +111,7 @@ sh_is_renesas_calling_convention (struct type *func_type)
 static const char *
 sh_sh_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
@@ -133,7 +133,7 @@ sh_sh_register_name (struct gdbarch *gdbarch, int reg_nr)
 static const char *
 sh_sh3_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
@@ -155,7 +155,7 @@ sh_sh3_register_name (struct gdbarch *gdbarch, int reg_nr)
 static const char *
 sh_sh3e_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
@@ -177,7 +177,7 @@ sh_sh3e_register_name (struct gdbarch *gdbarch, int reg_nr)
 static const char *
 sh_sh2e_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
@@ -199,7 +199,7 @@ sh_sh2e_register_name (struct gdbarch *gdbarch, int reg_nr)
 static const char *
 sh_sh2a_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     /* general registers 0-15 */
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
@@ -239,7 +239,7 @@ sh_sh2a_register_name (struct gdbarch *gdbarch, int reg_nr)
 static const char *
 sh_sh2a_nofpu_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     /* general registers 0-15 */
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
@@ -279,7 +279,7 @@ sh_sh2a_nofpu_register_name (struct gdbarch *gdbarch, int reg_nr)
 static const char *
 sh_sh_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
@@ -301,7 +301,7 @@ sh_sh_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
 static const char *
 sh_sh3_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
@@ -324,7 +324,7 @@ sh_sh3_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
 static const char *
 sh_sh4_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     /* general registers 0-15 */
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
@@ -362,7 +362,7 @@ sh_sh4_register_name (struct gdbarch *gdbarch, int reg_nr)
 static const char *
 sh_sh4_nofpu_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     /* general registers 0-15 */
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
@@ -398,7 +398,7 @@ sh_sh4_nofpu_register_name (struct gdbarch *gdbarch, int reg_nr)
 static const char *
 sh_sh4al_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
     "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
diff --git a/gdb/sh64-tdep.c b/gdb/sh64-tdep.c
index 23f5ade..33986fd 100644
--- a/gdb/sh64-tdep.c
+++ b/gdb/sh64-tdep.c
@@ -125,7 +125,7 @@ enum
 static const char *
 sh64_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] =
+  static const char *register_names[] =
   {
     /* SH MEDIA MODE (ISA 32) */
     /* general registers (64-bit) 0-63 */
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index 232641b..0b97556 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -170,7 +170,7 @@ struct darwin_so_list
 /* Lookup the value for a specific symbol.  */
 
 static CORE_ADDR
-lookup_symbol_from_bfd (bfd *abfd, char *symname)
+lookup_symbol_from_bfd (bfd *abfd, const char *symname)
 {
   long storage_needed;
   asymbol **symbol_table;
diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
index cd8b64d..00e59c2 100644
--- a/gdb/spu-tdep.c
+++ b/gdb/spu-tdep.c
@@ -114,7 +114,7 @@ static struct cmd_list_element *infospucmdlist = NULL;
 static const char *
 spu_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
-  static char *register_names[] = 
+  static const char *register_names[] =
     {
       "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
       "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
@@ -2300,7 +2300,7 @@ spu_mfc_get_bitfield (ULONGEST word, int first, int last)
 static void
 info_spu_dma_cmdlist (gdb_byte *buf, int nr, enum bfd_endian byte_order)
 {
-  static char *spu_mfc_opcode[256] =
+  static const char *spu_mfc_opcode[256] =
     {
     /* 00 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
              NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 1412202..8ba6bb5 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -85,14 +85,14 @@ struct field_info
   };
 
 static void
-read_one_struct_field (struct field_info *, char **, char *,
+read_one_struct_field (struct field_info *, const char **, const char *,
 		       struct type *, struct objfile *);
 
 static struct type *dbx_alloc_type (int[2], struct objfile *);
 
-static long read_huge_number (char **, int, int *, int);
+static long read_huge_number (const char **, int, int *, int);
 
-static struct type *error_type (char **, struct objfile *);
+static struct type *error_type (const char **, struct objfile *);
 
 static void
 patch_block_stabs (struct pending *, struct pending_stabs *,
@@ -100,35 +100,37 @@ patch_block_stabs (struct pending *, struct pending_stabs *,
 
 static void fix_common_block (struct symbol *, CORE_ADDR);
 
-static int read_type_number (char **, int *);
+static int read_type_number (const char **, int *);
 
-static struct type *read_type (char **, struct objfile *);
+static struct type *read_type (const char **, struct objfile *);
 
-static struct type *read_range_type (char **, int[2], int, struct objfile *);
+static struct type *read_range_type (const char **, int[2],
+				     int, struct objfile *);
 
-static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
+static struct type *read_sun_builtin_type (const char **,
+					   int[2], struct objfile *);
 
-static struct type *read_sun_floating_type (char **, int[2],
+static struct type *read_sun_floating_type (const char **, int[2],
 					    struct objfile *);
 
-static struct type *read_enum_type (char **, struct type *, struct objfile *);
+static struct type *read_enum_type (const char **, struct type *, struct objfile *);
 
 static struct type *rs6000_builtin_type (int, struct objfile *);
 
 static int
-read_member_functions (struct field_info *, char **, struct type *,
+read_member_functions (struct field_info *, const char **, struct type *,
 		       struct objfile *);
 
 static int
-read_struct_fields (struct field_info *, char **, struct type *,
+read_struct_fields (struct field_info *, const char **, struct type *,
 		    struct objfile *);
 
 static int
-read_baseclasses (struct field_info *, char **, struct type *,
+read_baseclasses (struct field_info *, const char **, struct type *,
 		  struct objfile *);
 
 static int
-read_tilde_fields (struct field_info *, char **, struct type *,
+read_tilde_fields (struct field_info *, const char **, struct type *,
 		   struct objfile *);
 
 static int attach_fn_fields_to_type (struct field_info *, struct type *);
@@ -136,24 +138,25 @@ static int attach_fn_fields_to_type (struct field_info *, struct type *);
 static int attach_fields_to_type (struct field_info *, struct type *,
 				  struct objfile *);
 
-static struct type *read_struct_type (char **, struct type *,
+static struct type *read_struct_type (const char **, struct type *,
                                       enum type_code,
 				      struct objfile *);
 
-static struct type *read_array_type (char **, struct type *,
+static struct type *read_array_type (const char **, struct type *,
 				     struct objfile *);
 
-static struct field *read_args (char **, int, struct objfile *, int *, int *);
+static struct field *read_args (const char **, int, struct objfile *,
+				int *, int *);
 
 static void add_undefined_type (struct type *, int[2]);
 
 static int
-read_cpp_abbrev (struct field_info *, char **, struct type *,
+read_cpp_abbrev (struct field_info *, const char **, struct type *,
 		 struct objfile *);
 
-static char *find_name_end (char *name);
+static const char *find_name_end (const char *name);
 
-static int process_reference (char **string);
+static int process_reference (const char **string);
 
 void stabsread_clear_cache (void);
 
@@ -381,7 +384,7 @@ patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
 {
   int ii;
   char *name;
-  char *pp;
+  const char *pp;
   struct symbol *sym;
 
   if (stabs)
@@ -461,7 +464,7 @@ patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
    Returns 0 for success, -1 for error.  */
 
 static int
-read_type_number (char **pp, int *typenums)
+read_type_number (const char **pp, int *typenums)
 {
   int nbits;
 
@@ -496,7 +499,7 @@ read_type_number (char **pp, int *typenums)
 
 struct ref_map
 {
-  char *stabs;
+  const char *stabs;
   CORE_ADDR value;
   struct symbol *sym;
 };
@@ -528,7 +531,7 @@ stabsread_clear_cache (void)
    find them, using their reference numbers as our index.
    These will be used later when we resolve references.  */
 void
-ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
+ref_add (int refnum, struct symbol *sym, const char *stabs, CORE_ADDR value)
 {
   if (ref_count == 0)
     ref_chunk = 0;
@@ -563,9 +566,9 @@ ref_search (int refnum)
    reference number.  Move STRING beyond the reference id.  */
 
 static int
-process_reference (char **string)
+process_reference (const char **string)
 {
-  char *p;
+  const char *p;
   int refnum = 0;
 
   if (**string != '#')
@@ -588,9 +591,9 @@ process_reference (char **string)
    definition for later use.  Return the reference number.  */
 
 int
-symbol_reference_defined (char **string)
+symbol_reference_defined (const char **string)
 {
-  char *p = *string;
+  const char *p = *string;
   int refnum = 0;
 
   refnum = process_reference (&p);
@@ -641,12 +644,12 @@ static int stab_register_index;
 static int stab_regparm_index;
 
 struct symbol *
-define_symbol (CORE_ADDR valu, char *string, int desc, int type,
+define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
 	       struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct symbol *sym;
-  char *p = (char *) find_name_end (string);
+  const char *p = find_name_end (string);
   int deftype;
   int synonym = 0;
   int i;
@@ -976,7 +979,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
 	  struct type *ftype = SYMBOL_TYPE (sym);
 	  int nsemi = 0;
 	  int nparams = 0;
-	  char *p1 = p;
+	  const char *p1 = p;
 
 	  /* Obtain a worst case guess for the number of arguments
 	     by counting the semicolons.  */
@@ -1490,7 +1493,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
    debugger will be able to read the new symbol tables.  */
 
 static struct type *
-error_type (char **pp, struct objfile *objfile)
+error_type (const char **pp, struct objfile *objfile)
 {
   complaint (&symfile_complaints,
 	     _("couldn't parse type; debugger out of date?"));
@@ -1523,7 +1526,7 @@ error_type (char **pp, struct objfile *objfile)
    deciding whether to call read_type.  */
 
 static struct type *
-read_type (char **pp, struct objfile *objfile)
+read_type (const char **pp, struct objfile *objfile)
 {
   struct type *type = 0;
   struct type *type1;
@@ -1595,7 +1598,7 @@ again:
 	char *type_name;
 
 	{
-	  char *from, *to, *p, *q1, *q2;
+	  const char *from, *p, *q1, *q2;
 
 	  /* Set the type code according to the following letter.  */
 	  switch ((*pp)[0])
@@ -1661,7 +1664,7 @@ again:
 	    }
 	  if (type_name == NULL)
 	    {
-	      to = type_name = (char *)
+	      char *to = type_name = (char *)
 		obstack_alloc (&objfile->objfile_obstack, p - *pp + 1);
 
 	      /* Copy the name.  */
@@ -1910,7 +1913,7 @@ again:
       else
 	/* type attribute */
 	{
-	  char *attr = *pp;
+	  const char *attr = *pp;
 
 	  /* Skip to the semicolon.  */
 	  while (**pp != ';' && **pp != '\0')
@@ -2280,8 +2283,8 @@ stabs_method_name_from_physname (const char *physname)
    Returns 1 for success, 0 for failure.  */
 
 static int
-read_member_functions (struct field_info *fip, char **pp, struct type *type,
-		       struct objfile *objfile)
+read_member_functions (struct field_info *fip, const char **pp,
+		       struct type *type, struct objfile *objfile)
 {
   int nfn_fields = 0;
   int length = 0;
@@ -2296,7 +2299,7 @@ read_member_functions (struct field_info *fip, char **pp, struct type *type,
   struct next_fnfieldlist *new_fnlist;
   struct next_fnfield *new_sublist;
   char *main_fn_name;
-  char *p;
+  const char *p;
 
   /* Process each list until we find something that is not a member function
      or find the end of the functions.  */
@@ -2770,10 +2773,10 @@ read_member_functions (struct field_info *fip, char **pp, struct type *type,
    keep parsing and it's time for error_type().  */
 
 static int
-read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
+read_cpp_abbrev (struct field_info *fip, const char **pp, struct type *type,
 		 struct objfile *objfile)
 {
-  char *p;
+  const char *p;
   const char *name;
   char cpp_abbrev;
   struct type *context;
@@ -2866,7 +2869,7 @@ read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
 }
 
 static void
-read_one_struct_field (struct field_info *fip, char **pp, char *p,
+read_one_struct_field (struct field_info *fip, const char **pp, const char *p,
 		       struct type *type, struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
@@ -3009,10 +3012,10 @@ read_one_struct_field (struct field_info *fip, char **pp, char *p,
    Returns 1 for success, 0 for failure.  */
 
 static int
-read_struct_fields (struct field_info *fip, char **pp, struct type *type,
+read_struct_fields (struct field_info *fip, const char **pp, struct type *type,
 		    struct objfile *objfile)
 {
-  char *p;
+  const char *p;
   struct nextfield *newobj;
 
   /* We better set p right now, in case there are no fields at all...    */
@@ -3107,7 +3110,7 @@ read_struct_fields (struct field_info *fip, char **pp, struct type *type,
 
 
 static int
-read_baseclasses (struct field_info *fip, char **pp, struct type *type,
+read_baseclasses (struct field_info *fip, const char **pp, struct type *type,
 		  struct objfile *objfile)
 {
   int i;
@@ -3233,10 +3236,10 @@ read_baseclasses (struct field_info *fip, char **pp, struct type *type,
    so we can look for the vptr base class info.  */
 
 static int
-read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
+read_tilde_fields (struct field_info *fip, const char **pp, struct type *type,
 		   struct objfile *objfile)
 {
-  char *p;
+  const char *p;
 
   STABS_CONTINUE (pp, objfile);
 
@@ -3509,7 +3512,7 @@ set_length_in_type_chain (struct type *type)
  */
 
 static struct type *
-read_struct_type (char **pp, struct type *type, enum type_code type_code,
+read_struct_type (const char **pp, struct type *type, enum type_code type_code,
                   struct objfile *objfile)
 {
   struct cleanup *back_to;
@@ -3583,7 +3586,7 @@ read_struct_type (char **pp, struct type *type, enum type_code type_code,
    array.  */
 
 static struct type *
-read_array_type (char **pp, struct type *type,
+read_array_type (const char **pp, struct type *type,
 		 struct objfile *objfile)
 {
   struct type *index_type, *element_type, *range_type;
@@ -3646,11 +3649,11 @@ read_array_type (char **pp, struct type *type,
    Also defines the symbols that represent the values of the type.  */
 
 static struct type *
-read_enum_type (char **pp, struct type *type,
+read_enum_type (const char **pp, struct type *type,
 		struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  char *p;
+  const char *p;
   char *name;
   long n;
   struct symbol *sym;
@@ -3772,7 +3775,7 @@ read_enum_type (char **pp, struct type *type,
    FIXME.  */
 
 static struct type *
-read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
+read_sun_builtin_type (const char **pp, int typenums[2], struct objfile *objfile)
 {
   int type_bits;
   int nbits;
@@ -3847,7 +3850,8 @@ read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
 }
 
 static struct type *
-read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
+read_sun_floating_type (const char **pp, int typenums[2],
+			struct objfile *objfile)
 {
   int nbits;
   int details;
@@ -3895,9 +3899,10 @@ read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
    If encounter garbage, set *BITS to -1 and return 0.  */
 
 static long
-read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
+read_huge_number (const char **pp, int end, int *bits,
+		  int twos_complement_bits)
 {
-  char *p = *pp;
+  const char *p = *pp;
   int sign = 1;
   int sign_bit = 0;
   long n = 0;
@@ -3932,7 +3937,7 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
 	 negative number.  */
 
       size_t len;
-      char *p1 = p;
+      const char *p1 = p;
 
       while ((c = *p1) >= '0' && c < '8')
 	p1++;
@@ -4059,11 +4064,11 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
 }
 
 static struct type *
-read_range_type (char **pp, int typenums[2], int type_size,
+read_range_type (const char **pp, int typenums[2], int type_size,
                  struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  char *orig_pp = *pp;
+  const char *orig_pp = *pp;
   int rangenums[2];
   long n2, n3;
   int n2bits, n3bits;
@@ -4267,7 +4272,7 @@ handle_true_range:
    if there is an error.  */
 
 static struct field *
-read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
+read_args (const char **pp, int end, struct objfile *objfile, int *nargsp,
 	   int *varargsp)
 {
   /* FIXME!  Remove this arbitrary limit!  */
@@ -4331,7 +4336,7 @@ static char *common_block_name;
    to remain after this function returns.  */
 
 void
-common_block_start (char *name, struct objfile *objfile)
+common_block_start (const char *name, struct objfile *objfile)
 {
   if (common_block_name != NULL)
     {
@@ -4814,10 +4819,10 @@ finish_global_stabs (struct objfile *objfile)
 
 /* Find the end of the name, delimited by a ':', but don't match
    ObjC symbols which look like -[Foo bar::]:bla.  */
-static char *
-find_name_end (char *name)
+static const char *
+find_name_end (const char *name)
 {
-  char *s = name;
+  const char *s = name;
 
   if (s[0] == '-' || *s == '+')
     {
diff --git a/gdb/stabsread.h b/gdb/stabsread.h
index 988063f..b37be1a 100644
--- a/gdb/stabsread.h
+++ b/gdb/stabsread.h
@@ -40,7 +40,7 @@ struct objfile;
 
 EXTERN struct symbol *global_sym_chain[HASHSIZE];
 
-extern void common_block_start (char *, struct objfile *);
+extern void common_block_start (const char *, struct objfile *);
 extern void common_block_end (struct objfile *);
 
 /* Kludge for xcoffread.c */
@@ -132,7 +132,7 @@ extern void cleanup_undefined_stabs_types (struct objfile *);
 
 extern long read_number (char **, int);
 
-extern struct symbol *define_symbol (CORE_ADDR, char *, int, int,
+extern struct symbol *define_symbol (CORE_ADDR, const char *, int, int,
 				     struct objfile *);
 
 extern void stabsread_init (void);
@@ -167,7 +167,7 @@ extern struct partial_symtab *dbx_end_psymtab
    struct partial_symtab **dependency_list, int number_dependencies,
    int textlow_not_set);
 
-extern void process_one_symbol (int, int, CORE_ADDR, char *,
+extern void process_one_symbol (int, int, CORE_ADDR, const char *,
 				const struct section_offsets *,
 				struct objfile *);
 
@@ -185,9 +185,9 @@ extern void coffstab_build_psymtabs
 extern void stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
 				     char *stabstr_name, char *text_name);
 
-extern int symbol_reference_defined (char **);
+extern int symbol_reference_defined (const char **);
 
-extern void ref_add (int, struct symbol *, char *, CORE_ADDR);
+extern void ref_add (int, struct symbol *, const char *, CORE_ADDR);
 
 extern struct symbol *ref_search (int);
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 8b79508..750039d 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1768,7 +1768,7 @@ symfile_bfd_open (const char *name)
    the section was not found.  */
 
 int
-get_section_index (struct objfile *objfile, char *section_name)
+get_section_index (struct objfile *objfile, const char *section_name)
 {
   asection *sect = bfd_get_section_by_name (objfile->obfd, section_name);
 
@@ -2235,8 +2235,8 @@ add_symbol_file_command (char *args, int from_tty)
 
   struct sect_opt
   {
-    char *name;
-    char *value;
+    const char *name;
+    const char *value;
   };
 
   struct section_addr_info *section_addrs;
@@ -2333,14 +2333,14 @@ add_symbol_file_command (char *args, int from_tty)
   for (i = 0; i < section_index; i++)
     {
       CORE_ADDR addr;
-      char *val = sect_opts[i].value;
-      char *sec = sect_opts[i].name;
+      const char *val = sect_opts[i].value;
+      const char *sec = sect_opts[i].name;
 
       addr = parse_and_eval_address (val);
 
       /* Here we store the section offsets in the order they were
          entered on the command line.  */
-      section_addrs->other[sec_num].name = sec;
+      section_addrs->other[sec_num].name = (char *) sec;
       section_addrs->other[sec_num].addr = addr;
       printf_unfiltered ("\t%s_addr = %s\n", sec,
 			 paddress (gdbarch, addr));
diff --git a/gdb/symfile.h b/gdb/symfile.h
index c3e7a31..6066481 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -495,7 +495,7 @@ extern void find_lowest_section (bfd *, asection *, void *);
 
 extern gdb_bfd_ref_ptr symfile_bfd_open (const char *);
 
-extern int get_section_index (struct objfile *, char *);
+extern int get_section_index (struct objfile *, const char *);
 
 extern int print_symbol_loading_p (int from_tty, int mainline, int full);
 
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 33ae1fa..9a7e2dd 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -128,8 +128,10 @@ enum tdesc_type_kind
 
 typedef struct tdesc_type
 {
-  /* The name of this type.  */
-  char *name;
+  /* The name of this type.  If this type is a built-in type, this is
+     a pointer to a constant string.  Otherwise, it's a
+     malloc-allocated string (and thus must be freed).  */
+  const char *name;
 
   /* Identify the kind of this type.  */
   enum tdesc_type_kind kind;
@@ -1335,7 +1337,7 @@ tdesc_free_type (struct tdesc_type *type)
       break;
     }
 
-  xfree (type->name);
+  xfree ((char *) type->name);
   xfree (type);
 }
 
diff --git a/gdb/target.c b/gdb/target.c
index fd9181e..10a5315 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -91,7 +91,7 @@ static int return_zero_has_execution (struct target_ops *, ptid_t);
 
 static void target_command (char *, int);
 
-static struct target_ops *find_default_run_target (char *);
+static struct target_ops *find_default_run_target (const char *);
 
 static struct gdbarch *default_thread_architecture (struct target_ops *ops,
 						    ptid_t ptid);
@@ -403,7 +403,7 @@ add_target (struct target_ops *t)
 /* See target.h.  */
 
 void
-add_deprecated_target_alias (struct target_ops *t, char *alias)
+add_deprecated_target_alias (struct target_ops *t, const char *alias)
 {
   struct cmd_list_element *c;
   char *alt;
@@ -2624,7 +2624,7 @@ show_auto_connect_native_target (struct ui_file *file, int from_tty,
    called for errors); else, return NULL on error.  */
 
 static struct target_ops *
-find_default_run_target (char *do_mesg)
+find_default_run_target (const char *do_mesg)
 {
   struct target_ops *runable = NULL;
 
@@ -3291,7 +3291,7 @@ void
 target_announce_detach (int from_tty)
 {
   pid_t pid;
-  char *exec_file;
+  const char *exec_file;
 
   if (!from_tty)
     return;
@@ -3518,7 +3518,7 @@ str_comma_list_concat_elem (char *list, const char *elem)
 
 static char *
 do_option (int *target_options, char *ret,
-	   int opt, char *opt_str)
+	   int opt, const char *opt_str)
 {
   if ((*target_options & opt) != 0)
     {
diff --git a/gdb/target.h b/gdb/target.h
index 6553f49..fac9d51 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -2324,7 +2324,8 @@ extern void complete_target_initialization (struct target_ops *t);
 /* Adds a command ALIAS for target T and marks it deprecated.  This is useful
    for maintaining backwards compatibility when renaming targets.  */
 
-extern void add_deprecated_target_alias (struct target_ops *t, char *alias);
+extern void add_deprecated_target_alias (struct target_ops *t,
+					 const char *alias);
 
 extern void push_target (struct target_ops *);
 
diff --git a/gdb/thread.c b/gdb/thread.c
index fd9022f..24347dd 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1360,7 +1360,7 @@ print_thread_info_1 (struct ui_out *uiout, char *requested_threads,
 
       if (uiout->is_mi_like_p ())
 	{
-	  char *state = "stopped";
+	  const char *state = "stopped";
 
 	  if (tp->state == THREAD_RUNNING)
 	    state = "running";
diff --git a/gdb/top.c b/gdb/top.c
index 4a22be1..3de8a26 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -218,7 +218,7 @@ void (*deprecated_warning_hook) (const char *, va_list);
    called to notify the GUI that we are done with the interaction
    window and it can close it.  */
 
-void (*deprecated_readline_begin_hook) (char *, ...);
+void (*deprecated_readline_begin_hook) (const char *, ...);
 char *(*deprecated_readline_hook) (const char *);
 void (*deprecated_readline_end_hook) (void);
 
@@ -1216,7 +1216,8 @@ gdb_safe_append_history (void)
    as the user has requested.  */
 
 char *
-command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix)
+command_line_input (const char *prompt_arg, int repeat,
+		    const char *annotation_suffix)
 {
   static struct buffer cmd_line_buffer;
   static int cmd_line_buffer_initialized;
diff --git a/gdb/top.h b/gdb/top.h
index 2da92df..452a381 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -295,6 +295,6 @@ extern void do_restore_instream_cleanup (void *stream);
 
 extern char *handle_line_of_input (struct buffer *cmd_line_buffer,
 				   char *rl, int repeat,
-				   char *annotation_suffix);
+				   const char *annotation_suffix);
 
 #endif
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index dbcd65d..5d63c16 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -192,7 +192,7 @@ static void
 tfile_write_uploaded_tsv (struct trace_file_writer *self,
 			  struct uploaded_tsv *utsv)
 {
-  char *buf = "";
+  char *buf = NULL;
   struct tfile_trace_file_writer *writer
     = (struct tfile_trace_file_writer *) self;
 
@@ -204,7 +204,7 @@ tfile_write_uploaded_tsv (struct trace_file_writer *self,
 
   fprintf (writer->fp, "tsv %x:%s:%x:%s\n",
 	   utsv->number, phex_nz (utsv->initial_value, 8),
-	   utsv->builtin, buf);
+	   utsv->builtin, buf != NULL ? buf : "");
 
   if (utsv->name)
     xfree (buf);
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 87ef141..c28aa38 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -170,7 +170,6 @@ static void actions_command (char *, int);
 static void tstart_command (char *, int);
 static void tstop_command (char *, int);
 static void tstatus_command (char *, int);
-static void tfind_command (char *, int);
 static void tfind_pc_command (char *, int);
 static void tfind_tracepoint_command (char *, int);
 static void tfind_line_command (char *, int);
@@ -508,7 +507,7 @@ tvariables_info_1 (void)
   for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
     {
       struct cleanup *back_to2;
-      char *c;
+      const char *c;
       char *name;
 
       back_to2 = make_cleanup_ui_out_tuple_begin_end (uiout, "variable");
@@ -2058,7 +2057,7 @@ trace_status_mi (int on_stop)
     }
   else
     {
-      char *stop_reason = NULL;
+      const char *stop_reason = NULL;
       int stopping_tracepoint = -1;
 
       if (!on_stop)
@@ -2343,7 +2342,7 @@ check_trace_running (struct trace_status *status)
 
 /* tfind command */
 static void
-tfind_command (char *args, int from_tty)
+tfind_command_1 (const char *args, int from_tty)
 { /* This should only be called with a numeric argument.  */
   int frameno = -1;
 
@@ -2377,18 +2376,24 @@ tfind_command (char *args, int from_tty)
   tfind_1 (tfind_number, frameno, 0, 0, from_tty);
 }
 
+static void
+tfind_command (char *args, int from_tty)
+{
+  tfind_command_1 (const_cast<char *> (args), from_tty);
+}
+
 /* tfind end */
 static void
 tfind_end_command (char *args, int from_tty)
 {
-  tfind_command ("-1", from_tty);
+  tfind_command_1 ("-1", from_tty);
 }
 
 /* tfind start */
 static void
 tfind_start_command (char *args, int from_tty)
 {
-  tfind_command ("0", from_tty);
+  tfind_command_1 ("0", from_tty);
 }
 
 /* tfind pc command */
@@ -2957,9 +2962,10 @@ tdump_command (char *args, int from_tty)
 /* This version does not do multiple encodes for long strings; it should
    return an offset to the next piece to encode.  FIXME  */
 
-extern int
+int
 encode_source_string (int tpnum, ULONGEST addr,
-		      char *srctype, const char *src, char *buf, int buf_size)
+		      const char *srctype, const char *src,
+		      char *buf, int buf_size)
 {
   if (80 + strlen (srctype) > buf_size)
     error (_("Buffer too small for source encoding"));
diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h
index 8c4dedc..474563e 100644
--- a/gdb/tracepoint.h
+++ b/gdb/tracepoint.h
@@ -339,7 +339,7 @@ extern struct trace_state_variable *
 extern struct trace_state_variable *create_trace_state_variable (const char *name);
 
 extern int encode_source_string (int num, ULONGEST addr,
-				 char *srctype, const char *src,
+				 const char *srctype, const char *src,
 				 char *buf, int buf_size);
 
 extern void parse_trace_status (char *line, struct trace_status *ts);
diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index dcf8c9b..749a62e 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -371,7 +371,7 @@ tui_prev_win (struct tui_win_info *cur_win)
 
 /* Answer the window represented by name.  */
 struct tui_win_info *
-tui_partial_win_by_name (char *name)
+tui_partial_win_by_name (const char *name)
 {
   struct tui_win_info *win_info = NULL;
 
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 63bcdf4..2a4f55b 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -317,7 +317,7 @@ extern void tui_free_data_content (tui_win_content, int);
 extern void tui_free_all_source_wins_content (void);
 extern void tui_del_window (struct tui_win_info *);
 extern void tui_del_data_windows (tui_win_content, int);
-extern struct tui_win_info *tui_partial_win_by_name (char *);
+extern struct tui_win_info *tui_partial_win_by_name (const char *);
 extern const char *tui_win_name (const struct tui_gen_win_info *);
 extern enum tui_layout_type tui_current_layout (void);
 extern void tui_set_current_layout_to (enum tui_layout_type);
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 423a455..c037648 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -251,7 +251,7 @@ tui_set_source_content (struct symtab *s,
 
 void
 tui_set_source_content_nil (struct tui_win_info *win_info, 
-			    char *warning_string)
+			    const char *warning_string)
 {
   int line_width;
   int n_lines;
diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h
index a9c591f..09ce12a 100644
--- a/gdb/tui/tui-source.h
+++ b/gdb/tui/tui-source.h
@@ -28,7 +28,7 @@ struct symtab;
 struct tui_win_info;
 
 extern void tui_set_source_content_nil (struct tui_win_info *, 
-					char *);
+					const char *);
 
 extern enum tui_status tui_set_source_content (struct symtab *, 
 					       int, int);
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 2477fa9..f49d7d5 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -1690,8 +1690,7 @@ parse_scrolling_args (char *arg,
       /* Process the window name if one is specified.  */
       if (buf_ptr != (char *) NULL)
 	{
-	  char *wname;
-	  int i;
+	  const char *wname;
 
 	  if (*buf_ptr == ' ')
 	    while (*(++buf_ptr) == ' ')
@@ -1699,11 +1698,11 @@ parse_scrolling_args (char *arg,
 
 	  if (*buf_ptr != (char) 0)
 	    {
-	      wname = buf_ptr;
-
 	      /* Validate the window name.  */
-	      for (i = 0; i < strlen (wname); i++)
-		wname[i] = tolower (wname[i]);
+	      for (char *p = buf_ptr; *p != '\0'; p++)
+		*p = tolower (*p);
+
+	      wname = buf_ptr;
 	    }
 	  else
 	    wname = "?";
diff --git a/gdb/tui/tui-windata.c b/gdb/tui/tui-windata.c
index dadae6c..8e7d55c 100644
--- a/gdb/tui/tui-windata.c
+++ b/gdb/tui/tui-windata.c
@@ -101,7 +101,7 @@ tui_delete_data_content_windows (void)
 
 
 void
-tui_erase_data_content (char *prompt)
+tui_erase_data_content (const char *prompt)
 {
   werase (TUI_DATA_WIN->generic.handle);
   tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
diff --git a/gdb/tui/tui-windata.h b/gdb/tui/tui-windata.h
index 1a68ea9..08b2f48 100644
--- a/gdb/tui/tui-windata.h
+++ b/gdb/tui/tui-windata.h
@@ -24,7 +24,7 @@
 
 #include "tui/tui-data.h"
 
-extern void tui_erase_data_content (char *);
+extern void tui_erase_data_content (const char *);
 extern void tui_display_all_data (void);
 extern void tui_check_data_values (struct frame_info *);
 extern void tui_display_data_from_line (int);
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index b444601..73ad93f 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -241,7 +241,7 @@ tui_erase_source_content (struct tui_win_info *win_info,
       tui_check_and_display_highlight_if_needed (win_info);
       if (display_prompt == EMPTY_SOURCE_PROMPT)
 	{
-	  char *no_src_str;
+	  const char *no_src_str;
 
 	  if (win_info->generic.type == SRC_WIN)
 	    no_src_str = NO_SRC_STRING;
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 7ff2a53..eb489b1 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -439,7 +439,7 @@ tui_enable (void)
       /* Check required terminal capabilities.  The MinGW port of
 	 ncurses does have them, but doesn't expose them through "cup".  */
 #ifndef __MINGW32__
-      cap = tigetstr ("cup");
+      cap = tigetstr ((char *) "cup");
       if (cap == NULL || cap == (char *) -1 || *cap == '\0')
 	{
 	  endwin ();
diff --git a/gdb/utils.c b/gdb/utils.c
index 6b8f2f7..b4332f8 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1136,7 +1136,8 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
   int retval;
   int def_value;
   char def_answer, not_def_answer;
-  char *y_string, *n_string, *question, *prompt;
+  const char *y_string, *n_string;
+  char *question, *prompt;
   struct cleanup *old_chain;
 
   /* Set up according to which answer is the default.  */
@@ -1626,7 +1627,7 @@ init_page_info (void)
       /* Readline should have fetched the termcap entry for us.
          Only try to use tgetnum function if rl_get_screen_size
          did not return a useful value. */
-      if (((rows <= 0) && (tgetnum ("li") < 0))
+      if (((rows <= 0) && (tgetnum ((char *) "li") < 0))
 	/* Also disable paging if inside Emacs.  $EMACS was used
 	   before Emacs v25.1, $INSIDE_EMACS is used since then.  */
 	  || getenv ("EMACS") || getenv ("INSIDE_EMACS"))
@@ -2137,8 +2138,8 @@ puts_debug (char *prefix, char *string, char *suffix)
   /* Print prefix and suffix after each line.  */
   static int new_line = 1;
   static int return_p = 0;
-  static char *prev_prefix = "";
-  static char *prev_suffix = "";
+  static const char *prev_prefix = "";
+  static const char *prev_suffix = "";
 
   if (*string == '\n')
     return_p = 0;
@@ -2607,7 +2608,7 @@ streq (const char *lhs, const char *rhs)
    **    at index 0.
  */
 int
-subset_compare (char *string_to_compare, char *template_string)
+subset_compare (const char *string_to_compare, const char *template_string)
 {
   int match;
 
diff --git a/gdb/utils.h b/gdb/utils.h
index 2380bd7..f3e8007 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -37,7 +37,7 @@ extern int strcmp_iw_ordered (const char *, const char *);
 
 extern int streq (const char *, const char *);
 
-extern int subset_compare (char *, char *);
+extern int subset_compare (const char *, const char *);
 
 int compare_positive_ints (const void *ap, const void *bp);
 int compare_strings (const void *ap, const void *bp);
diff --git a/gdb/varobj.c b/gdb/varobj.c
index f5d1cbf..5f21d84 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -50,7 +50,7 @@ show_varobjdebug (struct ui_file *file, int from_tty,
 }
 
 /* String representations of gdb's format codes.  */
-char *varobj_format_string[] =
+const char *varobj_format_string[] =
   { "natural", "binary", "decimal", "hexadecimal", "octal", "zero-hexadecimal" };
 
 /* True if we want to allow Python-based pretty-printing.  */
diff --git a/gdb/varobj.h b/gdb/varobj.h
index 989c8cd..e35c1b8 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -51,7 +51,7 @@ enum varobj_scope_status
   };
 
 /* String representations of gdb's format codes (defined in varobj.c).  */
-extern char *varobj_format_string[];
+extern const char *varobj_format_string[];
 
 /* Struct that describes a variable object instance.  */
 
diff --git a/gdb/vax-tdep.c b/gdb/vax-tdep.c
index 6c8de83..870d268 100644
--- a/gdb/vax-tdep.c
+++ b/gdb/vax-tdep.c
@@ -39,7 +39,7 @@
 static const char *
 vax_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  static char *register_names[] =
+  static const char *register_names[] =
   {
     "r0", "r1", "r2",  "r3",  "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc",
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 85f2030..ec0ae06 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1925,7 +1925,7 @@ windows_detach (struct target_ops *ops, const char *args, int from_tty)
 
   if (detached && from_tty)
     {
-      char *exec_file = get_exec_file (0);
+      const char *exec_file = get_exec_file (0);
       if (exec_file == 0)
 	exec_file = "";
       printf_unfiltered ("Detaching from program: %s, Pid %u\n", exec_file,
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 9c4769a..4f22cec 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -203,7 +203,7 @@ static void xcoff_initial_scan (struct objfile *, symfile_add_flags);
 static void scan_xcoff_symtab (minimal_symbol_reader &,
 			       struct objfile *);
 
-static char *xcoff_next_symbol_text (struct objfile *);
+static const char *xcoff_next_symbol_text (struct objfile *);
 
 static void record_include_begin (struct coff_symbol *);
 
@@ -771,7 +771,7 @@ process_linenos (CORE_ADDR start, CORE_ADDR end)
 	    /* Pick a fake name that will produce the same results as this
 	       one when passed to deduce_language_from_filename.  Kludge on
 	       top of kludge.  */
-	    char *fakename = strrchr (inclTable[ii].name, '.');
+	    const char *fakename = strrchr (inclTable[ii].name, '.');
 
 	    if (fakename == NULL)
 	      fakename = " ?";
@@ -963,11 +963,11 @@ static char *raw_symbol;
 /* This is the function which stabsread.c calls to get symbol
    continuations.  */
 
-static char *
+static const char *
 xcoff_next_symbol_text (struct objfile *objfile)
 {
   struct internal_syment symbol;
-  char *retval;
+  const char *retval;
 
   /* FIXME: is this the same as the passed arg?  */
   if (this_symtab_objfile)
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index cb97bee..ea0657d 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -355,27 +355,29 @@ gdb_xml_end_element (void *data, const XML_Char *name)
   /* Call the element processor.  */
   if (scope->element != NULL && scope->element->end_handler)
     {
-      char *body;
+      const char *scope_body;
 
       if (scope->body == NULL)
-	body = "";
+	scope_body = "";
       else
 	{
 	  int length;
 
 	  length = obstack_object_size (scope->body);
 	  obstack_1grow (scope->body, '\0');
-	  body = (char *) obstack_finish (scope->body);
+	  char *body = (char *) obstack_finish (scope->body);
 
 	  /* Strip leading and trailing whitespace.  */
 	  while (length > 0 && ISSPACE (body[length-1]))
 	    body[--length] = '\0';
 	  while (*body && ISSPACE (*body))
 	    body++;
+
+	  scope_body = body;
 	}
 
       scope->element->end_handler (parser, scope->element, parser->user_data,
-				   body);
+				   scope_body);
     }
   else if (scope->element == NULL)
     XML_DefaultCurrent (parser->expat_parser);
diff --git a/gdb/xml-tdesc.c b/gdb/xml-tdesc.c
index d24c5ad..522a9ba 100644
--- a/gdb/xml-tdesc.c
+++ b/gdb/xml-tdesc.c
@@ -184,7 +184,8 @@ tdesc_start_reg (struct gdb_xml_parser *parser,
   struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
   struct gdb_xml_value *attrs = VEC_address (gdb_xml_value_s, attributes);
   int ix = 0, length;
-  char *name, *group, *type;
+  char *name, *group;
+  const char *type;
   int bitsize, regnum, save_restore;
 
   length = VEC_length (gdb_xml_value_s, attributes);
diff --git a/gdb/xstormy16-tdep.c b/gdb/xstormy16-tdep.c
index 91983f8..bfa7f0a 100644
--- a/gdb/xstormy16-tdep.c
+++ b/gdb/xstormy16-tdep.c
@@ -103,7 +103,7 @@ enum
 static const char *
 xstormy16_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  static char *register_names[] = {
+  static const char *register_names[] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13",
     "psw", "sp", "pc"
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index 13f1514..7fc881f 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -228,7 +228,7 @@ extract_call_winsize (struct gdbarch *gdbarch, CORE_ADDR pc)
 
 /* Find register by name.  */
 static int
-xtensa_find_register_by_name (struct gdbarch *gdbarch, char *name)
+xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
 {
   int i;
 
diff --git a/gdb/xtensa-tdep.h b/gdb/xtensa-tdep.h
index 986aa68..68f9d0e 100644
--- a/gdb/xtensa-tdep.h
+++ b/gdb/xtensa-tdep.h
@@ -103,7 +103,7 @@ typedef struct
 
 typedef struct 
 {
-  char* name;             	/* Register name.  */
+  const char *name;            	/* Register name.  */
   int offset;             	/* Offset.  */
   xtensa_register_type_t type;  /* Register type.  */
   xtensa_register_group_t group;/* Register group.  */
-- 
2.5.5

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 14/18] -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overload
  2017-04-04 17:26 ` [PATCH 14/18] -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overload Pedro Alves
@ 2017-04-04 18:37   ` Sergio Durigan Junior
  2017-04-05 12:58     ` Pedro Alves
  0 siblings, 1 reply; 39+ messages in thread
From: Sergio Durigan Junior @ 2017-04-04 18:37 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Tuesday, April 04 2017, Pedro Alves wrote:

> -Wwrite-strings flags code like:
>
>    static char *keywords[] = {"command", "from_tty", "to_string", NULL };
>
> as needing "(char *)" casts, because string literals are "const char []".
>
> We can get rid of the casts by changing the array like this:
>
>  -  static char *keywords[] = {"command", "from_tty", "to_string", NULL };
>  +  static const char *keywords[] = {"command", "from_tty", "to_string", NULL };
>
> However, passing the array to PyArg_ParseTupleAndKeywords no longer
> works OOTB, because PyArg_ParseTupleAndKeywords expects a "char **":
>
>   PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw,
>                               const char *format,
> 			      char *keywords[], ...);
>
> and "const char **" is not implicitly convertible to "char **".  C++
> is more tolerant that C here WRT aliasing, and a const_cast<char **>
> would be fine.
>
> However, to avoid having all callers add the 'const_cast<char **>'
> themselves, this commit define a PyArg_ParseTupleAndKeywords overload
> here with a corresponding 'keywords' parameter type that does the cast
> in a single place.
>
> As in the PyGetSetDef patch, I'd be fine with naming this
> gdb_PyArg_ParseTupleAndKeywords instead, if people would find having
> our own overload confusing.

As much as I like the overloading approach in general, I prefer to see
our own overloads marked with the "gdb_", just to make things clearer.

> BTW, this API issue was discussed years ago in the python-dev list:
>
>  https://mail.python.org/pipermail/python-dev/2006-February/060689.html
>
> ... and an overload for C++ was suggested in there somewhere.
> Unfortunately, it was never added.

Interesting.  I wonder if there's an actual bug/issue opened on their
bugzilla about this.

Hm, after a quick search I didn't find anything.  Maybe it's worth
creating one.

The rest is fine by me.  Thanks!

> gdb/ChangeLog:
> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
>
> 	* python/py-arch.c (archpy_disassemble): Constify 'keywords'
> 	array.
> 	* python/py-cmd.c (cmdpy_init): Constify 'keywords' array.
> 	* python/py-finishbreakpoint.c (bpfinishpy_init): Constify
> 	'keywords' array.
> 	* python/py-inferior.c (infpy_read_memory, infpy_write_memory)
> 	(infpy_search_memory): Constify 'keywords' array.
> 	* python/py-objfile.c (objfpy_add_separate_debug_file)
> 	(gdbpy_lookup_objfile): Constify 'keywords' array.
> 	* python/py-symbol.c (gdbpy_lookup_symbol)
> 	(gdbpy_lookup_global_symbol): Constify 'keywords' array.
> 	* python/py-type.c (gdbpy_lookup_type): Constify 'keywords' array.
> 	* python/py-value.c (valpy_lazy_string, valpy_string): Constify
> 	'keywords' array.
> 	* python/python.c (execute_gdb_command, gdbpy_write, gdbpy_flush):
> 	Constify 'keywords' array.
> 	* python/python-internal.h (PyArg_ParseTupleAndKeywords): New
> 	function overload.
> ---
>  gdb/python/py-arch.c             |  2 +-
>  gdb/python/py-breakpoint.c       |  4 ++--
>  gdb/python/py-cmd.c              |  6 +++---
>  gdb/python/py-finishbreakpoint.c |  2 +-
>  gdb/python/py-inferior.c         |  6 +++---
>  gdb/python/py-objfile.c          |  4 ++--
>  gdb/python/py-symbol.c           |  4 ++--
>  gdb/python/py-type.c             |  2 +-
>  gdb/python/py-value.c            |  4 ++--
>  gdb/python/python-internal.h     | 25 +++++++++++++++++++++++++
>  gdb/python/python.c              |  6 +++---
>  11 files changed, 45 insertions(+), 20 deletions(-)
>
> diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
> index 71d2989..48fae32 100644
> --- a/gdb/python/py-arch.c
> +++ b/gdb/python/py-arch.c
> @@ -116,7 +116,7 @@ archpy_name (PyObject *self, PyObject *args)
>  static PyObject *
>  archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
>  {
> -  static char *keywords[] = { "start_pc", "end_pc", "count", NULL };
> +  static const char *keywords[] = { "start_pc", "end_pc", "count", NULL };
>    CORE_ADDR start, end = 0;
>    CORE_ADDR pc;
>    gdb_py_ulongest start_temp;
> diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
> index 724a7ed..2043d42 100644
> --- a/gdb/python/py-breakpoint.c
> +++ b/gdb/python/py-breakpoint.c
> @@ -637,8 +637,8 @@ bppy_get_ignore_count (PyObject *self, void *closure)
>  static int
>  bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
>  {
> -  static char *keywords[] = { "spec", "type", "wp_class", "internal",
> -			      "temporary", NULL };
> +  static const char *keywords[] = { "spec", "type", "wp_class", "internal",
> +				    "temporary", NULL };
>    const char *spec;
>    int type = bp_breakpoint;
>    int access_type = hw_write;
> diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
> index 3aaf7f9..8f61d9c 100644
> --- a/gdb/python/py-cmd.c
> +++ b/gdb/python/py-cmd.c
> @@ -490,8 +490,8 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
>    char *docstring = NULL;
>    struct cmd_list_element **cmd_list;
>    char *cmd_name, *pfx_name;
> -  static char *keywords[] = { "name", "command_class", "completer_class",
> -			      "prefix", NULL };
> +  static const char *keywords[] = { "name", "command_class", "completer_class",
> +				    "prefix", NULL };
>    PyObject *is_prefix = NULL;
>    int cmp;
>  
> @@ -506,7 +506,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
>  
>    if (! PyArg_ParseTupleAndKeywords (args, kw, "si|iO",
>  				     keywords, &name, &cmdtype,
> -			  &completetype, &is_prefix))
> +				     &completetype, &is_prefix))
>      return -1;
>  
>    if (cmdtype != no_class && cmdtype != class_run
> diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
> index 106fe34..9d43d55 100644
> --- a/gdb/python/py-finishbreakpoint.c
> +++ b/gdb/python/py-finishbreakpoint.c
> @@ -156,7 +156,7 @@ bpfinishpy_post_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
>  static int
>  bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
>  {
> -  static char *keywords[] = { "frame", "internal", NULL };
> +  static const char *keywords[] = { "frame", "internal", NULL };
>    struct finish_breakpoint_object *self_bpfinish =
>        (struct finish_breakpoint_object *) self;
>    PyObject *frame_obj = NULL;
> diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
> index 46a0aad..8b4782b 100644
> --- a/gdb/python/py-inferior.c
> +++ b/gdb/python/py-inferior.c
> @@ -435,7 +435,7 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
>    CORE_ADDR addr, length;
>    gdb_byte *buffer = NULL;
>    PyObject *addr_obj, *length_obj, *result;
> -  static char *keywords[] = { "address", "length", NULL };
> +  static const char *keywords[] = { "address", "length", NULL };
>  
>    if (! PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords,
>  				     &addr_obj, &length_obj))
> @@ -494,7 +494,7 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
>    const gdb_byte *buffer;
>    CORE_ADDR addr, length;
>    PyObject *addr_obj, *length_obj = NULL;
> -  static char *keywords[] = { "address", "buffer", "length", NULL };
> +  static const char *keywords[] = { "address", "buffer", "length", NULL };
>  #ifdef IS_PY3K
>    Py_buffer pybuf;
>  
> @@ -643,7 +643,7 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
>  {
>    struct gdb_exception except = exception_none;
>    CORE_ADDR start_addr, length;
> -  static char *keywords[] = { "address", "length", "pattern", NULL };
> +  static const char *keywords[] = { "address", "length", "pattern", NULL };
>    PyObject *start_addr_obj, *length_obj;
>    Py_ssize_t pattern_size;
>    const gdb_byte *buffer;
> diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
> index 105d88a..ad1ec4f 100644
> --- a/gdb/python/py-objfile.c
> +++ b/gdb/python/py-objfile.c
> @@ -432,7 +432,7 @@ objfpy_is_valid (PyObject *self, PyObject *args)
>  static PyObject *
>  objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
>  {
> -  static char *keywords[] = { "file_name", NULL };
> +  static const char *keywords[] = { "file_name", NULL };
>    objfile_object *obj = (objfile_object *) self;
>    const char *file_name;
>  
> @@ -559,7 +559,7 @@ objfpy_lookup_objfile_by_build_id (const char *build_id)
>  PyObject *
>  gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
>  {
> -  static char *keywords[] = { "name", "by_build_id", NULL };
> +  static const char *keywords[] = { "name", "by_build_id", NULL };
>    const char *name;
>    PyObject *by_build_id_obj = NULL;
>    int by_build_id;
> diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
> index b71cfb4..de44c06 100644
> --- a/gdb/python/py-symbol.c
> +++ b/gdb/python/py-symbol.c
> @@ -373,7 +373,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
>    int domain = VAR_DOMAIN;
>    struct field_of_this_result is_a_field_of_this;
>    const char *name;
> -  static char *keywords[] = { "name", "block", "domain", NULL };
> +  static const char *keywords[] = { "name", "block", "domain", NULL };
>    struct symbol *symbol = NULL;
>    PyObject *block_obj = NULL, *sym_obj, *bool_obj;
>    const struct block *block = NULL;
> @@ -443,7 +443,7 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
>  {
>    int domain = VAR_DOMAIN;
>    const char *name;
> -  static char *keywords[] = { "name", "domain", NULL };
> +  static const char *keywords[] = { "name", "domain", NULL };
>    struct symbol *symbol = NULL;
>    PyObject *sym_obj;
>  
> diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
> index f071006..4f4ede1 100644
> --- a/gdb/python/py-type.c
> +++ b/gdb/python/py-type.c
> @@ -1347,7 +1347,7 @@ type_object_to_type (PyObject *obj)
>  PyObject *
>  gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
>  {
> -  static char *keywords[] = { "name", "block", NULL };
> +  static const char *keywords[] = { "name", "block", NULL };
>    const char *type_name = NULL;
>    struct type *type = NULL;
>    PyObject *block_obj = NULL;
> diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
> index bb42e8b..1a82af5 100644
> --- a/gdb/python/py-value.c
> +++ b/gdb/python/py-value.c
> @@ -431,7 +431,7 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
>    gdb_py_longest length = -1;
>    struct value *value = ((value_object *) self)->value;
>    const char *user_encoding = NULL;
> -  static char *keywords[] = { "encoding", "length", NULL };
> +  static const char *keywords[] = { "encoding", "length", NULL };
>    PyObject *str_obj = NULL;
>  
>    if (!PyArg_ParseTupleAndKeywords (args, kw, "|s" GDB_PY_LL_ARG, keywords,
> @@ -526,7 +526,7 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw)
>    const char *user_encoding = NULL;
>    const char *la_encoding = NULL;
>    struct type *char_type;
> -  static char *keywords[] = { "encoding", "errors", "length", NULL };
> +  static const char *keywords[] = { "encoding", "errors", "length", NULL };
>  
>    if (!PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
>  				    &user_encoding, &errors, &length))
> diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
> index 8fc89cd..76f7443 100644
> --- a/gdb/python/python-internal.h
> +++ b/gdb/python/python-internal.h
> @@ -318,6 +318,31 @@ struct gdb_PyGetSetDef : PyGetSetDef
>  
>  #define PyGetSetDef gdb_PyGetSetDef
>  
> +/* The 'keywords' parameter of PyArg_ParseTupleAndKeywords has type
> +   'char **'.  However, string literals are const in C++, and so to
> +   avoid casting at every keyword array definition, we'll need to make
> +   the keywords array an array of 'const char *'.  To avoid having all
> +   callers add a 'const_cast<char **>' themselves when passing such an
> +   array through 'char **', we define a PyArg_ParseTupleAndKeywords
> +   overload here with a corresponding 'keywords' parameter type that
> +   does the cast in a single place.  */
> +
> +static inline int
> +PyArg_ParseTupleAndKeywords (PyObject *args, PyObject *kw,
> +			     const char *format, const char **keywords, ...)
> +{
> +  va_list ap;
> +  int res;
> +
> +  va_start (ap, keywords);
> +  res = PyArg_VaParseTupleAndKeywords (args, kw, format,
> +				       const_cast<char **> (keywords),
> +				       ap);
> +  va_end (ap);
> +
> +  return res;
> +}
> +
>  /* In order to be able to parse symtab_and_line_to_sal_object function
>     a real symtab_and_line structure is needed.  */
>  #include "symtab.h"
> diff --git a/gdb/python/python.c b/gdb/python/python.c
> index a7aff53..5a46493 100644
> --- a/gdb/python/python.c
> +++ b/gdb/python/python.c
> @@ -572,7 +572,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
>    const char *arg;
>    PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
>    int from_tty, to_string;
> -  static char *keywords[] = {"command", "from_tty", "to_string", NULL };
> +  static const char *keywords[] = { "command", "from_tty", "to_string", NULL };
>  
>    if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
>  				     &PyBool_Type, &from_tty_obj,
> @@ -1047,7 +1047,7 @@ static PyObject *
>  gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
>  {
>    const char *arg;
> -  static char *keywords[] = {"text", "stream", NULL };
> +  static const char *keywords[] = { "text", "stream", NULL };
>    int stream_type = 0;
>  
>    if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &arg,
> @@ -1088,7 +1088,7 @@ gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
>  static PyObject *
>  gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
>  {
> -  static char *keywords[] = {"stream", NULL };
> +  static const char *keywords[] = { "stream", NULL };
>    int stream_type = 0;
>  
>    if (! PyArg_ParseTupleAndKeywords (args, kw, "|i", keywords,
> -- 
> 2.5.5

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals
  2017-04-04 17:32 ` [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals Pedro Alves
@ 2017-04-04 18:40   ` Sergio Durigan Junior
  2017-04-05 12:35     ` Pedro Alves
  2017-04-05  8:49   ` Philipp Rudo
  1 sibling, 1 reply; 39+ messages in thread
From: Sergio Durigan Junior @ 2017-04-04 18:40 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Tuesday, April 04 2017, Pedro Alves wrote:

> Unfortunately, PyGetSetDef's 'name' and 'doc' members are 'char *'
> instead of 'const char *', meaning that in order to list-initialize
> PyGetSetDef arrays using string literals requires writing explicit
> 'char *' casts.  For example:
>
>     static PyGetSetDef value_object_getset[] = {
>    -  { "address", valpy_get_address, NULL, "The address of the value.",
>    +  { (char *) "address", valpy_get_address, NULL,
>    +    (char *) "The address of the value.",
> 	NULL },
>    -  { "is_optimized_out", valpy_get_is_optimized_out, NULL,
>    -    "Boolean telling whether the value is optimized "
>    +  { (char *) "is_optimized_out", valpy_get_is_optimized_out, NULL,
>    +    (char *) "Boolean telling whether the value is optimized "
> 	"out (i.e., not available).",
> 	NULL },
>    -  { "type", valpy_get_type, NULL, "Type of the value.", NULL },
>    -  { "dynamic_type", valpy_get_dynamic_type, NULL,
>    -    "Dynamic type of the value.", NULL },
>    -  { "is_lazy", valpy_get_is_lazy, NULL,
>    -    "Boolean telling whether the value is lazy (not fetched yet\n\
>    +  { (char *) "type", valpy_get_type, NULL,
>    +    (char *) "Type of the value.", NULL },
>    +  { (char *) "dynamic_type", valpy_get_dynamic_type, NULL,
>    +    (char *) "Dynamic type of the value.", NULL },
>    +  { (char *) "is_lazy", valpy_get_is_lazy, NULL,
>    +    (char *) "Boolean telling whether the value is lazy (not fetched yet\n\
>     from the inferior).  A lazy value is fetched when needed, or when\n\
>     the \"fetch_lazy()\" method is called.", NULL },
>       {NULL}  /* Sentinel */
>
> We have 20 such arrays, and I first wrote a patch that fixed all of
> them like that...  It's not pretty, and I can post it if people want
> to see it.
>
> One way to make these a bit less ugly would be add a new macro that
> hides the casts, like:
>
>   #define GDBPY_GSDEF(NAME, GET, SET, DOC, CLOSURE) \
>      { (char *) NAME, GET, SET, (char *) DOC, CLOSURE }
>
> and then use it like:
>
>     static PyGetSetDef value_object_getset[] = {
>        GDBPY_GSDEF ("address", valpy_get_address, NULL,
>        		    "The address of the value.", NULL),
>        GDBPY_GSDEF ("is_optimized_out", valpy_get_is_optimized_out, NULL,
>        		    "Boolean telling whether the value is optimized ", NULL),
>       {NULL}  /* Sentinel */
>     };
>
> But since we have C++11, which gives us constexpr and list
> initialization, I thought of a way that requires no changes where the
> arrays are initialized:
>
> We add a new type that extends PyGetSetDef (called gdb_PyGetSetDef),
> and add constexpr constructors that accept const 'name' and 'doc', and
> then list/aggregate initialization simply "calls" these matching
> constructors instead.
>
> I put "calls" in quotes, because given "constexpr", it's all done at
> compile time, and there's no overhead either in binary size or at run
> time.  In fact, we get identical binaries, before/after this change.
>
> I'm a bit undecided whether to change the places that create
> PyGetSetDef arrays to explicitly name gdb_PyGetSetDef as type, like:
>
>   -    static PyGetSetDef value_object_getset[] = {
>   +    static gdb_PyGetSetDef value_object_getset[] = {
>
> or go the
>
>   #define PyGetSetDef gdb_PyGetSetDef
>
> way as we do for the other Python API fixes.  This commit takes the
> latter approach, but I'll change it if people prefer the other way.

I liked the approach.  As with the other Python patch, I'm more inclined
to use an explicit "gdb_PyGetSetDef" everywhere, just to be clear that
we are using our own version of it.  This can save time when debugging.

Otherwise, the rest is fine by me.

> gdb/ChangeLog:
> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
>
> 	* python/python-internal.h (gdb_PyGetSetDef): New type.
> 	(PyGetSetDef): New define.
> ---
>  gdb/python/python-internal.h | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
> index 55efd75..8fc89cd 100644
> --- a/gdb/python/python-internal.h
> +++ b/gdb/python/python-internal.h
> @@ -286,6 +286,38 @@ gdb_PySys_SetPath (const GDB_PYSYS_SETPATH_CHAR *path)
>  
>  #define PySys_SetPath gdb_PySys_SetPath
>  
> +/* Wrap PyGetSetDef to allow convenient construction with string
> +   literals.  Unfortunately, PyGetSetDef's 'name' and 'doc' members
> +   are 'char *' instead of 'const char *', meaning that in order to
> +   list-initialize PyGetSetDef arrays with string literals (and
> +   without the wrapping below) would require writing explicit 'char *'
> +   casts.  Instead, we extend PyGetSetDef and add onstexpr
> +   constructors that accept const 'name' and 'doc', hiding the ugly
> +   casts here in a single place.  */
> +
> +struct gdb_PyGetSetDef : PyGetSetDef
> +{
> +  constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter set_,
> +			     const char *doc_, void *closure_)
> +    : PyGetSetDef {const_cast<char *> (name_), get_, set_,
> +		   const_cast<char *> (doc_), closure_}
> +  {}
> +
> +  /* Alternative constructor that allows omitting the closure in list
> +     initialization.  */
> +  constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter set_,
> +			     const char *doc_)
> +    : gdb_PyGetSetDef {name_, get_, set_, doc_, NULL}
> +  {}
> +
> +  /* Constructor for the sentinel entries.  */
> +  constexpr gdb_PyGetSetDef (std::nullptr_t)
> +    : gdb_PyGetSetDef { NULL, NULL, NULL, NULL, NULL }
> +  {}
> +};
> +
> +#define PyGetSetDef gdb_PyGetSetDef
> +
>  /* In order to be able to parse symtab_and_line_to_sal_object function
>     a real symtab_and_line structure is needed.  */
>  #include "symtab.h"
> -- 
> 2.5.5

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings)
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (17 preceding siblings ...)
  2017-04-04 17:36 ` [PATCH 17/18] -Wwrite-strings: The Rest Pedro Alves
@ 2017-04-04 18:42 ` Sergio Durigan Junior
  2017-04-04 19:37 ` Simon Marchi
  2017-04-05 18:05 ` Pedro Alves
  20 siblings, 0 replies; 39+ messages in thread
From: Sergio Durigan Junior @ 2017-04-04 18:42 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Binutils

On Tuesday, April 04 2017, Pedro Alves wrote:

> "-Wwrite-strings" is enabled by default for C++ programs:
>
>   "When compiling C++, warn about the deprecated conversion from
>   string literals to char *. This warning is enabled by default for
>   C++ programs. "
>
> This warning, via -Werror, makes this be a compile-time error:
>
>  char *str = "hello";
>
> It forces us to write instead either
>
>  char *str = (char *) "hello"; // I know what I'm doing! (TM)
>
> or:
>
>  const char *str = "hello";    // Preferable.
>
> However, I had disabled the warning for GDB in the earlier steps of
> the C++ conversion:
>
>   https://sourceware.org/ml/gdb-patches/2015-02/msg00203.html
>
> ... as an expedient hack, since we weren't enabling it in C mode
> either.
>
> I'd like to enable the warning now, to catch more bugs at compile
> time.  I spotted one related bug in review last week (storing a string
> literal in a vector of heap-allocated strings, leading to a bogus
> "free" call later on), which was what prompted me to do this.
>
> "Bah, I'll just do it.  Can't take more than a couple hours..."
>
> Yeah, right...  /me will never learn.
>
> Tested on x86_64 Fedora 23, built with --enable-targets=all.
>
> Compile tested GDB on Aarch64 GNU/Linux, Power 64 GNU/Linux, AIX 7.1,
> and 32-bit/64-bit mingw32-w64.
>
> Also cross built MIPS and ARM GNU/Linux gdbserver.
>
> The first patch needs approval from the binutils side, hence the cross
> post.  The rest of the series is GDB-specific, so I'm sending those
> patches to gdb-patches@ only.

Hey Pedro,

Thank you very much for doing this.  I love these kinds of cleanups.

I looked at all the patches (except for the last patch, which I glanced
over everything due to its size), and aside from two comments that I
already posted, the series is fine by me.

Happy to see GDB more const-correct.

Cheers,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 17/18] -Wwrite-strings: The Rest
  2017-04-04 17:36 ` [PATCH 17/18] -Wwrite-strings: The Rest Pedro Alves
@ 2017-04-04 18:44   ` John Baldwin
  2017-04-05 12:59     ` Pedro Alves
  0 siblings, 1 reply; 39+ messages in thread
From: John Baldwin @ 2017-04-04 18:44 UTC (permalink / raw)
  To: gdb-patches; +Cc: Pedro Alves

On Tuesday, April 04, 2017 06:25:50 PM Pedro Alves wrote:
> This is the remainder boring constification that all looks more of less
> borderline obvious IMO.
> 
> gdb/ChangeLog:
> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
> 
> 	* fbsd-tdep.c (fbsd_core_pid_to_str): Constify.

Tiny nit: this isn't actually changed in this patchset (was going to quickly
eyeball it).  Perhaps the changelog is stale from you breaking the
pid_to_str target method out into its own patch?

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 06/18] -Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info
  2017-04-04 17:26 ` [PATCH 06/18] -Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info Pedro Alves
@ 2017-04-04 18:44   ` John Baldwin
  0 siblings, 0 replies; 39+ messages in thread
From: John Baldwin @ 2017-04-04 18:44 UTC (permalink / raw)
  To: gdb-patches; +Cc: Pedro Alves

On Tuesday, April 04, 2017 06:25:39 PM Pedro Alves wrote:
> -Wwrite-strings flagged a missing cast for example here:
> 
>    static char *
>    ravenscar_extra_thread_info (struct target_ops *self, struct thread_info *tp)
>    {
>      return "Ravenscar task";
> 
> Since callers are not supposed to free the string returned by these
> methods, change the methods' signature to return const strings.
> 
> gdb/ChangeLog:
> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
> 
> diff --git a/gdb/bsd-kvm.c b/gdb/bsd-kvm.c
> index 9f4f9e7..98e2428 100644
> --- a/gdb/bsd-kvm.c
> +++ b/gdb/bsd-kvm.c
> @@ -329,7 +329,7 @@ bsd_kvm_thread_alive (struct target_ops *ops,
>    return 1;
>  }
>  
> -static char *
> +static const char *
>  bsd_kvm_pid_to_str (struct target_ops *ops, ptid_t ptid)
>  {
>    static char buf[64];
> diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
> index 08b8f36..5d4775c 100644
> --- a/gdb/bsd-uthread.c
> +++ b/gdb/bsd-uthread.c
> @@ -491,7 +491,7 @@ static char *bsd_uthread_state[] =
>  /* Return a string describing th state of the thread specified by
>     INFO.  */
>  
> -static char *
> +static const char *
>  bsd_uthread_extra_thread_info (struct target_ops *self,
>  			       struct thread_info *info)
>  {
> @@ -511,7 +511,7 @@ bsd_uthread_extra_thread_info (struct target_ops *self,
>    return NULL;
>  }
>  
> -static char *
> +static const char *
>  bsd_uthread_pid_to_str (struct target_ops *ops, ptid_t ptid)
>  {
>    if (ptid_get_tid (ptid) != 0)
> diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
> index d99f436..96781cd 100644
> --- a/gdb/fbsd-nat.c
> +++ b/gdb/fbsd-nat.c
> @@ -368,7 +368,7 @@ fbsd_thread_alive (struct target_ops *ops, ptid_t ptid)
>  /* Convert PTID to a string.  Returns the string in a static
>     buffer.  */
>  
> -static char *
> +static const char *
>  fbsd_pid_to_str (struct target_ops *ops, ptid_t ptid)
>  {
>    lwpid_t lwp;
> diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
> index 46875d8..b834ce3 100644
> --- a/gdb/fbsd-tdep.c
> +++ b/gdb/fbsd-tdep.c
> @@ -32,7 +32,7 @@
>  
>  /* This is how we want PTIDs from core files to be printed.  */
>  
> -static char *
> +static const char *
>  fbsd_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
>  {
>    static char buf[80];

These look fine to me (as well as the change in general).

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove  -Wno-write-strings)
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (18 preceding siblings ...)
  2017-04-04 18:42 ` [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Sergio Durigan Junior
@ 2017-04-04 19:37 ` Simon Marchi
  2017-04-05 18:05 ` Pedro Alves
  20 siblings, 0 replies; 39+ messages in thread
From: Simon Marchi @ 2017-04-04 19:37 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Binutils

On 2017-04-04 13:25, Pedro Alves wrote:
> "Bah, I'll just do it.  Can't take more than a couple hours..."
> 
> Yeah, right...  /me will never learn.

Ah!  I had the exact same thought a few weeks ago when I tried to do it. 
  I stumbled on the Python issue and didn't see an easy way out.  I'm 
glad you did!

Simon

^ permalink raw reply	[flat|nested] 39+ messages in thread

* RE: [PATCH 15/18] -Wwrite-strings: execute_command calls with string literals
  2017-04-04 17:26 ` [PATCH 15/18] -Wwrite-strings: execute_command calls with string literals Pedro Alves
@ 2017-04-05  7:13   ` Metzger, Markus T
  2017-04-05 13:10     ` Pedro Alves
  0 siblings, 1 reply; 39+ messages in thread
From: Metzger, Markus T @ 2017-04-05  7:13 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

Hello Pedro,

> All these places would better be calling some API function directly
> instead of going through execute_command & friends...

Ah, and I thought this is the preferred way.


The patch looks good to me.  But I'm wondering if we should instead change
execute_command to take a const char *.

Regards,
Markus.

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 01/18] -Wwrite-strings: Constify struct disassemble_info's disassembler_options field
  2017-04-04 17:26 ` [PATCH 01/18] -Wwrite-strings: Constify struct disassemble_info's disassembler_options field Pedro Alves
@ 2017-04-05  7:22   ` Nick Clifton
  0 siblings, 0 replies; 39+ messages in thread
From: Nick Clifton @ 2017-04-05  7:22 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches; +Cc: Binutils

Hi Pedro,

> Are the include/ and opcodes/ bits OK?

Yes - please go ahead and apply this patch.

Cheers
  Nick

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 07/18] -Wwrite-strings: Constify work break character arrays
  2017-04-04 17:26 ` [PATCH 07/18] -Wwrite-strings: Constify work break character arrays Pedro Alves
@ 2017-04-05  8:46   ` Philipp Rudo
  2017-04-05 13:17     ` Pedro Alves
  0 siblings, 1 reply; 39+ messages in thread
From: Philipp Rudo @ 2017-04-05  8:46 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Hi Pedro

great series. Just one minor thing I noticed here.

On Tue,  4 Apr 2017 18:25:40 +0100
Pedro Alves <palves@redhat.com> wrote:
[...]
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index 9b91e0c..d31e058 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -317,7 +317,7 @@ static unsigned int varsize_limit;
> 
>  /* FIXME: brobecker/2003-09-17: No longer a const because it is
>     returned by a function that does not return a const char *.  */
> -static char *ada_completer_word_break_characters =
> +static const char ada_completer_word_break_characters[] =
>  #ifdef VMS
>    " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
>  #else

The comment above doesn't make sense, especially after your
change. I think it should be removed. 

Philipp

> @@ -558,7 +558,7 @@ add_angle_brackets (const char *str)
>    return result;
>  }
> 
> -static char *
> +static const char *
>  ada_get_gdb_completer_word_break_characters (void)
>  {
>    return ada_completer_word_break_characters;
> diff --git a/gdb/completer.c b/gdb/completer.c
> index 45adc62..9183e2a 100644
> --- a/gdb/completer.c
> +++ b/gdb/completer.c
> @@ -84,29 +84,30 @@ char *line_completion_function (const char *text,
> int matches, readline library sees one in any of the current
> completion strings, it thinks that the string needs to be quoted and
> automatically supplies a leading quote.  */
> -static char *gdb_completer_command_word_break_characters =
> +static const char gdb_completer_command_word_break_characters[] =
>  " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
> 
>  /* When completing on file names, we remove from the list of word
>     break characters any characters that are commonly used in file
>     names, such as '-', '+', '~', etc.  Otherwise, readline displays
>     incorrect completion candidates.  */
> -#ifdef HAVE_DOS_BASED_FILE_SYSTEM
>  /* MS-DOS and MS-Windows use colon as part of the drive spec, and
> most programs support @foo style response files.  */
> -static char *gdb_completer_file_name_break_characters = "
> \t\n*|\"';?><@"; +static const char
> gdb_completer_file_name_break_characters[] = +#ifdef
> HAVE_DOS_BASED_FILE_SYSTEM
> +  " \t\n*|\"';?><@";
>  #else
> -static char *gdb_completer_file_name_break_characters = "
> \t\n*|\"';:?><";
> +  " \t\n*|\"';:?><";
>  #endif
> 
>  /* Characters that can be used to quote completion strings.  Note
> that we can't include '"' because the gdb C parser treats such quoted
>     sequences as strings.  */
> -static char *gdb_completer_quote_characters = "'";
> +static const char gdb_completer_quote_characters[] = "'";
>  \f
>  /* Accessor for some completer data that may interest other files.
> */
> 
> -char *
> +const char *
>  get_gdb_completer_quote_characters (void)
>  {
>    return gdb_completer_quote_characters;
> @@ -652,16 +653,26 @@ expression_completer (struct cmd_list_element
> *ignore, /* See definition in completer.h.  */
> 
>  void
> +set_rl_completer_word_break_characters (const char *break_chars)
> +{
> +  rl_completer_word_break_characters = (char *) break_chars;
> +}
> +
> +/* See definition in completer.h.  */
> +
> +void
>  set_gdb_completion_word_break_characters (completer_ftype *fn)
>  {
> +  const char *break_chars;
> +
>    /* So far we are only interested in differentiating filename
>       completers from everything else.  */
>    if (fn == filename_completer)
> -    rl_completer_word_break_characters
> -      = gdb_completer_file_name_break_characters;
> +    break_chars = gdb_completer_file_name_break_characters;
>    else
> -    rl_completer_word_break_characters
> -      = gdb_completer_command_word_break_characters;
> +    break_chars = gdb_completer_command_word_break_characters;
> +
> +  set_rl_completer_word_break_characters (break_chars);
>  }
> 
>  /* Here are some useful test cases for completion.  FIXME: These
> @@ -743,8 +754,8 @@ complete_line_internal (const char *text,
>       then we will switch to the special word break set for command
>       strings, which leaves out the '-' character used in some
>       commands.  */
> -  rl_completer_word_break_characters =
> -    current_language->la_word_break_characters();
> +  set_rl_completer_word_break_characters
> +    (current_language->la_word_break_characters());
> 
>    /* Decide whether to complete on a list of gdb commands or on
>       symbols.  */
> @@ -821,8 +832,8 @@ complete_line_internal (const char *text,
>  	    }
>  	  /* Ensure that readline does the right thing with respect
> to inserting quotes.  */
> -	  rl_completer_word_break_characters =
> -	    gdb_completer_command_word_break_characters;
> +	  set_rl_completer_word_break_characters
> +	    (gdb_completer_command_word_break_characters);
>  	}
>      }
>    else
> @@ -848,8 +859,8 @@ complete_line_internal (const char *text,
> 
>  		  /* Ensure that readline does the right thing
>  		     with respect to inserting quotes.  */
> -		  rl_completer_word_break_characters =
> -		    gdb_completer_command_word_break_characters;
> +		  set_rl_completer_word_break_characters
> +		    (gdb_completer_command_word_break_characters);
>  		}
>  	      else if (reason == handle_help)
>  		list = NULL;
> @@ -857,8 +868,8 @@ complete_line_internal (const char *text,
>  		{
>  		  if (reason != handle_brkchars)
>  		    list = complete_on_enum (c->enums, p, word);
> -		  rl_completer_word_break_characters =
> -		    gdb_completer_command_word_break_characters;
> +		  set_rl_completer_word_break_characters
> +		    (gdb_completer_command_word_break_characters);
>  		}
>  	      else
>  		{
> @@ -879,8 +890,8 @@ complete_line_internal (const char *text,
>  			     && strchr
> (gdb_completer_file_name_break_characters, p[-1]) == NULL; p--)
>  			;
> -		      rl_completer_word_break_characters =
> -			gdb_completer_file_name_break_characters;
> +		      set_rl_completer_word_break_characters
> +			(gdb_completer_file_name_break_characters);
>  		    }
>  		  if (reason == handle_brkchars
>  		      && c->completer_handle_brkchars != NULL)
> @@ -913,8 +924,8 @@ complete_line_internal (const char *text,
> 
>  	      /* Ensure that readline does the right thing
>  		 with respect to inserting quotes.  */
> -	      rl_completer_word_break_characters =
> -		gdb_completer_command_word_break_characters;
> +	      set_rl_completer_word_break_characters
> +		(gdb_completer_command_word_break_characters);
>  	    }
>  	}
>        else if (reason == handle_help)
> @@ -947,8 +958,8 @@ complete_line_internal (const char *text,
>  				    p[-1]) == NULL;
>  		       p--)
>  		    ;
> -		  rl_completer_word_break_characters =
> -		    gdb_completer_file_name_break_characters;
> +		  set_rl_completer_word_break_characters
> +		    (gdb_completer_file_name_break_characters);
>  		}
>  	      if (reason == handle_brkchars
>  		  && c->completer_handle_brkchars != NULL)
> diff --git a/gdb/completer.h b/gdb/completer.h
> index 416b313..2aa1987 100644
> --- a/gdb/completer.h
> +++ b/gdb/completer.h
> @@ -99,10 +99,16 @@ extern VEC (char_ptr) *reg_or_group_completer
> (struct cmd_list_element *, extern VEC (char_ptr) *reggroup_completer
> (struct cmd_list_element *, const char *, const char *);
> 
> -extern char *get_gdb_completer_quote_characters (void);
> +extern const char *get_gdb_completer_quote_characters (void);
> 
>  extern char *gdb_completion_word_break_characters (void);
> 
> +/* Set the word break characters array to BREAK_CHARS.  This function
> +   is useful as const-correct alternative to direct assignment to
> +   rl_completer_word_break_characters, which is "char *",
> +   not "const char *".  */
> +extern void set_rl_completer_word_break_characters (const char
> *break_chars); +
>  /* Set the word break characters array to the corresponding set of
>     chars, based on FN.  This function is useful for cases when the
>     completer doesn't know the type of the completion until some
> diff --git a/gdb/f-lang.c b/gdb/f-lang.c
> index 8aba5ef..3c30d75 100644
> --- a/gdb/f-lang.c
> +++ b/gdb/f-lang.c
> @@ -203,7 +203,7 @@ f_language_arch_info (struct gdbarch *gdbarch,
> 
>  /* Remove the modules separator :: from the default break list.  */
> 
> -static char *
> +static const char *
>  f_word_break_characters (void)
>  {
>    static char *retval;
> diff --git a/gdb/language.c b/gdb/language.c
> index 119c07e..f1fc220 100644
> --- a/gdb/language.c
> +++ b/gdb/language.c
> @@ -698,7 +698,7 @@ default_pass_by_reference (struct type *type)
>     delimiting words.  This is a reasonable default value that
>     most languages should be able to use.  */
> 
> -char *
> +const char *
>  default_word_break_characters (void)
>  {
>    return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
> diff --git a/gdb/language.h b/gdb/language.h
> index 3d21e4e..96080ac 100644
> --- a/gdb/language.h
> +++ b/gdb/language.h
> @@ -321,7 +321,7 @@ struct language_defn
>      char string_lower_bound;
> 
>      /* The list of characters forming word boundaries.  */
> -    char *(*la_word_break_characters) (void);
> +    const char *(*la_word_break_characters) (void);
> 
>      /* Should return a vector of all symbols which are possible
>         completions for TEXT.  WORD is the entire command on which the
> @@ -583,7 +583,7 @@ extern char *language_class_name_from_physname
> (const struct language_defn *, const char *physname);
> 
>  /* Splitting strings into words.  */
> -extern char *default_word_break_characters (void);
> +extern const char *default_word_break_characters (void);
> 
>  /* Print the index of an array element using the C99 syntax.  */
>  extern void default_print_array_index (struct value *index_value,
> diff --git a/gdb/top.c b/gdb/top.c
> index 295b680..4a22be1 100644
> --- a/gdb/top.c
> +++ b/gdb/top.c
> @@ -2022,7 +2022,7 @@ init_main (void)
>    /* Setup important stuff for command line editing.  */
>    rl_completion_word_break_hook =
> gdb_completion_word_break_characters; rl_completion_entry_function =
> readline_line_completion_function;
> -  rl_completer_word_break_characters = default_word_break_characters
> ();
> +  set_rl_completer_word_break_characters
> (default_word_break_characters ()); rl_completer_quote_characters =
> get_gdb_completer_quote_characters ();
> rl_completion_display_matches_hook = cli_display_match_list;
> rl_readline_name = "gdb";

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals
  2017-04-04 17:32 ` [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals Pedro Alves
  2017-04-04 18:40   ` Sergio Durigan Junior
@ 2017-04-05  8:49   ` Philipp Rudo
  2017-04-05 13:03     ` Pedro Alves
  1 sibling, 1 reply; 39+ messages in thread
From: Philipp Rudo @ 2017-04-05  8:49 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Hi Pedro

I found a typo ...

On Tue,  4 Apr 2017 18:25:46 +0100
Pedro Alves <palves@redhat.com> wrote:
[...]
> diff --git a/gdb/python/python-internal.h
> b/gdb/python/python-internal.h index 55efd75..8fc89cd 100644
> --- a/gdb/python/python-internal.h
> +++ b/gdb/python/python-internal.h
> @@ -286,6 +286,38 @@ gdb_PySys_SetPath (const GDB_PYSYS_SETPATH_CHAR
> *path)
> 
>  #define PySys_SetPath gdb_PySys_SetPath
> 
> +/* Wrap PyGetSetDef to allow convenient construction with string
> +   literals.  Unfortunately, PyGetSetDef's 'name' and 'doc' members
> +   are 'char *' instead of 'const char *', meaning that in order to
> +   list-initialize PyGetSetDef arrays with string literals (and
> +   without the wrapping below) would require writing explicit 'char *'
> +   casts.  Instead, we extend PyGetSetDef and add onstexpr
						     ^^^^^^^^
						... here

> +   constructors that accept const 'name' and 'doc', hiding the ugly
> +   casts here in a single place.  */
> +
> +struct gdb_PyGetSetDef : PyGetSetDef
> +{
> +  constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter
> set_,
> +			     const char *doc_, void *closure_)
> +    : PyGetSetDef {const_cast<char *> (name_), get_, set_,
> +		   const_cast<char *> (doc_), closure_}
> +  {}
> +
> +  /* Alternative constructor that allows omitting the closure in list
> +     initialization.  */
> +  constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter
> set_,
> +			     const char *doc_)
> +    : gdb_PyGetSetDef {name_, get_, set_, doc_, NULL}
> +  {}
> +
> +  /* Constructor for the sentinel entries.  */
> +  constexpr gdb_PyGetSetDef (std::nullptr_t)
> +    : gdb_PyGetSetDef { NULL, NULL, NULL, NULL, NULL }
> +  {}
> +};
> +
> +#define PyGetSetDef gdb_PyGetSetDef
> +
>  /* In order to be able to parse symtab_and_line_to_sal_object
> function a real symtab_and_line structure is needed.  */
>  #include "symtab.h"

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals
  2017-04-04 18:40   ` Sergio Durigan Junior
@ 2017-04-05 12:35     ` Pedro Alves
  2017-04-05 15:48       ` Sergio Durigan Junior
  0 siblings, 1 reply; 39+ messages in thread
From: Pedro Alves @ 2017-04-05 12:35 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

On 04/04/2017 07:39 PM, Sergio Durigan Junior wrote:

> I liked the approach.  As with the other Python patch, I'm more inclined
> to use an explicit "gdb_PyGetSetDef" everywhere, just to be clear that
> we are using our own version of it.  This can save time when debugging.

OK, here's what that looks like.  Commit log updated to reflect the
change too.  WDYT?

From 566fd938f2919985db6a955d769ba619534964e8 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Wed, 5 Apr 2017 13:22:25 +0100
Subject: [PATCH] -Wwrite-strings: Wrap PyGetSetDef for construction with
 string literals

Unfortunately, PyGetSetDef's 'name' and 'doc' members are 'char *'
instead of 'const char *', meaning that in order to list-initialize
PyGetSetDef arrays using string literals requires writing explicit
'char *' casts.  For example:

    static PyGetSetDef value_object_getset[] = {
   -  { "address", valpy_get_address, NULL, "The address of the value.",
   +  { (char *) "address", valpy_get_address, NULL,
   +    (char *) "The address of the value.",
	NULL },
   -  { "is_optimized_out", valpy_get_is_optimized_out, NULL,
   -    "Boolean telling whether the value is optimized "
   +  { (char *) "is_optimized_out", valpy_get_is_optimized_out, NULL,
   +    (char *) "Boolean telling whether the value is optimized "
	"out (i.e., not available).",
	NULL },
   -  { "type", valpy_get_type, NULL, "Type of the value.", NULL },
   -  { "dynamic_type", valpy_get_dynamic_type, NULL,
   -    "Dynamic type of the value.", NULL },
   -  { "is_lazy", valpy_get_is_lazy, NULL,
   -    "Boolean telling whether the value is lazy (not fetched yet\n\
   +  { (char *) "type", valpy_get_type, NULL,
   +    (char *) "Type of the value.", NULL },
   +  { (char *) "dynamic_type", valpy_get_dynamic_type, NULL,
   +    (char *) "Dynamic type of the value.", NULL },
   +  { (char *) "is_lazy", valpy_get_is_lazy, NULL,
   +    (char *) "Boolean telling whether the value is lazy (not fetched yet\n\
    from the inferior).  A lazy value is fetched when needed, or when\n\
    the \"fetch_lazy()\" method is called.", NULL },
      {NULL}  /* Sentinel */

We have ~20 such arrays, and I first wrote a patch that fixed all of
them like that...  It's not pretty...

One way to make these a bit less ugly would be add a new macro that
hides the casts, like:

  #define GDBPY_GSDEF(NAME, GET, SET, DOC, CLOSURE) \
     { (char *) NAME, GET, SET, (char *) DOC, CLOSURE }

and then use it like:

    static PyGetSetDef value_object_getset[] = {
       GDBPY_GSDEF ("address", valpy_get_address, NULL,
       		    "The address of the value.", NULL),
       GDBPY_GSDEF ("is_optimized_out", valpy_get_is_optimized_out, NULL,
       		    "Boolean telling whether the value is optimized ", NULL),
      {NULL}  /* Sentinel */
    };

But since we have C++11, which gives us constexpr and list
initialization, I thought of a way that requires no changes where the
arrays are initialized:

We add a new type that extends PyGetSetDef (called gdb_PyGetSetDef),
and add constexpr constructors that accept const 'name' and 'doc', and
then list/aggregate initialization simply "calls" these matching
constructors instead.

I put "calls" in quotes, because given "constexpr", it's all done at
compile time, and there's no overhead either in binary size or at run
time.  In fact, we get identical binaries, before/after this change.

Unlike the fixes that fix some old Python API to match the API of more
recent Python, this switches to using explicit "gdb_PyGetSetDef"
everywhere, just to be clear that we are using our own version of it.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* python/python-internal.h (gdb_PyGetSetDef): New type.
	* python/py-block.c (block_object_getset)
	(breakpoint_object_getset): Now a gdb_PyGetSetDef array.
	* python/py-event.c (event_object_getset)
	(finish_breakpoint_object_getset): Likewise.
	* python/py-inferior.c (inferior_object_getset): Likewise.
	* python/py-infthread.c (thread_object_getset): Likewise.
	* python/py-lazy-string.c (lazy_string_object_getset): Likewise.
	* python/py-linetable.c (linetable_entry_object_getset): Likewise.
	* python/py-objfile.c (objfile_getset): Likewise.
	* python/py-progspace.c (pspace_getset): Likewise.
	* python/py-record-btrace.c (btpy_insn_getset, btpy_call_getset):
	Likewise.
	* python/py-record.c (recpy_record_getset): Likewise.
	* python/py-symbol.c (symbol_object_getset): Likewise.
	* python/py-symtab.c (symtab_object_getset, sal_object_getset):
	Likewise.
	* python/py-type.c (type_object_getset, field_object_getset):
	Likewise.
	* python/py-value.c (value_object_getset): Likewise.
---
 gdb/python/py-block.c            |  2 +-
 gdb/python/py-breakpoint.c       |  2 +-
 gdb/python/py-event.c            |  2 +-
 gdb/python/py-finishbreakpoint.c |  2 +-
 gdb/python/py-inferior.c         |  2 +-
 gdb/python/py-infthread.c        |  2 +-
 gdb/python/py-lazy-string.c      |  2 +-
 gdb/python/py-linetable.c        |  2 +-
 gdb/python/py-objfile.c          |  2 +-
 gdb/python/py-progspace.c        |  2 +-
 gdb/python/py-record-btrace.c    |  4 ++--
 gdb/python/py-record.c           |  2 +-
 gdb/python/py-symbol.c           |  2 +-
 gdb/python/py-symtab.c           |  4 ++--
 gdb/python/py-type.c             |  4 ++--
 gdb/python/py-value.c            |  2 +-
 gdb/python/python-internal.h     | 30 ++++++++++++++++++++++++++++++
 17 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index f477d4a..840c842 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -461,7 +461,7 @@ Return true if this block is valid, false if not." },
   {NULL}  /* Sentinel */
 };
 
-static PyGetSetDef block_object_getset[] = {
+static gdb_PyGetSetDef block_object_getset[] = {
   { "start", blpy_get_start, NULL, "Start address of the block.", NULL },
   { "end", blpy_get_end, NULL, "End address of the block.", NULL },
   { "function", blpy_get_function, NULL,
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 724a7ed..34f46fb 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -1048,7 +1048,7 @@ local_setattro (PyObject *self, PyObject *name, PyObject *v)
   return PyObject_GenericSetAttr ((PyObject *)self, name, v);
 }
 
-static PyGetSetDef breakpoint_object_getset[] = {
+static gdb_PyGetSetDef breakpoint_object_getset[] = {
   { "enabled", bppy_get_enabled, bppy_set_enabled,
     "Boolean telling whether the breakpoint is enabled.", NULL },
   { "silent", bppy_get_silent, bppy_set_silent,
diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c
index 127dcc7..dc1d73e 100644
--- a/gdb/python/py-event.c
+++ b/gdb/python/py-event.c
@@ -114,7 +114,7 @@ evpy_emit_event (PyObject *event,
   return 0;
 }
 
-static PyGetSetDef event_object_getset[] =
+static gdb_PyGetSetDef event_object_getset[] =
 {
   { "__dict__", gdb_py_generic_dict, NULL,
     "The __dict__ for this event.", &event_object_type },
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 106fe34..76189b8 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -426,7 +426,7 @@ gdbpy_initialize_finishbreakpoints (void)
   return 0;
 }
 
-static PyGetSetDef finish_breakpoint_object_getset[] = {
+static gdb_PyGetSetDef finish_breakpoint_object_getset[] = {
   { "return_value", bpfinishpy_get_returnvalue, NULL,
   "gdb.Value object representing the return value, if any. \
 None otherwise.", NULL },
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 46a0aad..77fc543 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -827,7 +827,7 @@ gdbpy_initialize_inferior (void)
 				 &membuf_object_type);
 }
 
-static PyGetSetDef inferior_object_getset[] =
+static gdb_PyGetSetDef inferior_object_getset[] =
 {
   { "num", infpy_get_num, NULL, "ID of inferior, as assigned by GDB.", NULL },
   { "pid", infpy_get_pid, NULL, "PID of inferior, as assigned by the OS.",
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 5482bf9..626c15c 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -304,7 +304,7 @@ gdbpy_initialize_thread (void)
 				 (PyObject *) &thread_object_type);
 }
 
-static PyGetSetDef thread_object_getset[] =
+static gdb_PyGetSetDef thread_object_getset[] =
 {
   { "name", thpy_get_name, thpy_set_name,
     "The name of the thread, as set by the user or the OS.", NULL },
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index ab3f411..1999033 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -300,7 +300,7 @@ static PyMethodDef lazy_string_object_methods[] = {
 };
 
 
-static PyGetSetDef lazy_string_object_getset[] = {
+static gdb_PyGetSetDef lazy_string_object_getset[] = {
   { "address", stpy_get_address, NULL, "Address of the string.", NULL },
   { "encoding", stpy_get_encoding, NULL, "Encoding of the string.", NULL },
   { "length", stpy_get_length, NULL, "Length of the string.", NULL },
diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index a5e57b0..8d17aab 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -550,7 +550,7 @@ PyTypeObject ltpy_iterator_object_type = {
 };
 
 
-static PyGetSetDef linetable_entry_object_getset[] = {
+static gdb_PyGetSetDef linetable_entry_object_getset[] = {
   { "line", ltpy_entry_get_line, NULL,
     "The line number in the source file.", NULL },
   { "pc", ltpy_entry_get_pc, NULL,
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 105d88a..6a47c17 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -670,7 +670,7 @@ Add FILE_NAME to the list of files containing debug info for the objfile." },
   { NULL }
 };
 
-static PyGetSetDef objfile_getset[] =
+static gdb_PyGetSetDef objfile_getset[] =
 {
   { "__dict__", gdb_py_generic_dict, NULL,
     "The __dict__ for this objfile.", &objfile_object_type },
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index 1e06a75..edabba4 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -378,7 +378,7 @@ gdbpy_initialize_pspace (void)
 
 \f
 
-static PyGetSetDef pspace_getset[] =
+static gdb_PyGetSetDef pspace_getset[] =
 {
   { "__dict__", gdb_py_generic_dict, NULL,
     "The __dict__ for this progspace.", &pspace_object_type },
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index c816332..6d08121 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -903,7 +903,7 @@ recpy_bt_goto (PyObject *self, PyObject *args)
 
 /* BtraceInstruction members.  */
 
-struct PyGetSetDef btpy_insn_getset[] =
+struct gdb_PyGetSetDef btpy_insn_getset[] =
 {
   { "number", btpy_number, NULL, "instruction number", NULL},
   { "error", btpy_insn_error, NULL, "error number for gaps", NULL},
@@ -920,7 +920,7 @@ executed speculatively", NULL},
 
 /* BtraceFunctionCall members.  */
 
-static PyGetSetDef btpy_call_getset[] =
+static gdb_PyGetSetDef btpy_call_getset[] =
 {
   { "number", btpy_number, NULL, "function call number", NULL},
   { "level", btpy_call_level, NULL, "call stack level", NULL},
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index 72922a4..60c0a7c 100644
--- a/gdb/python/py-record.c
+++ b/gdb/python/py-record.c
@@ -175,7 +175,7 @@ Rewind to given location."},
 
 /* Record member list.  */
 
-static PyGetSetDef recpy_record_getset[] = {
+static gdb_PyGetSetDef recpy_record_getset[] = {
   { "ptid", recpy_ptid, NULL, "Current thread.", NULL },
   { "method", recpy_method, NULL, "Current recording method.", NULL },
   { "format", recpy_format, NULL, "Current recording format.", NULL },
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index b71cfb4..05b002f 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -560,7 +560,7 @@ gdbpy_initialize_symbols (void)
 
 \f
 
-static PyGetSetDef symbol_object_getset[] = {
+static gdb_PyGetSetDef symbol_object_getset[] = {
   { "type", sympy_get_type, NULL,
     "Type of the symbol.", NULL },
   { "symtab", sympy_get_symtab, NULL,
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 09cab22..53b160e 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -544,7 +544,7 @@ gdbpy_initialize_symtabs (void)
 
 \f
 
-static PyGetSetDef symtab_object_getset[] = {
+static gdb_PyGetSetDef symtab_object_getset[] = {
   { "filename", stpy_get_filename, NULL,
     "The symbol table's source filename.", NULL },
   { "objfile", stpy_get_objfile, NULL, "The symtab's objfile.",
@@ -606,7 +606,7 @@ PyTypeObject symtab_object_type = {
   symtab_object_getset		  /*tp_getset */
 };
 
-static PyGetSetDef sal_object_getset[] = {
+static gdb_PyGetSetDef sal_object_getset[] = {
   { "symtab", salpy_get_symtab, NULL, "Symtab object.", NULL },
   { "pc", salpy_get_pc, NULL, "Return the symtab_and_line's pc.", NULL },
   { "last", salpy_get_last, NULL,
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index f071006..12b6310 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1413,7 +1413,7 @@ gdbpy_initialize_types (void)
 
 \f
 
-static PyGetSetDef type_object_getset[] =
+static gdb_PyGetSetDef type_object_getset[] =
 {
   { "code", typy_get_code, NULL,
     "The code for this type.", NULL },
@@ -1587,7 +1587,7 @@ PyTypeObject type_object_type =
   0,				  /* tp_new */
 };
 
-static PyGetSetDef field_object_getset[] =
+static gdb_PyGetSetDef field_object_getset[] =
 {
   { "__dict__", gdb_py_generic_dict, NULL,
     "The __dict__ for this field.", &field_object_type },
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index bb42e8b..9c0470f 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1767,7 +1767,7 @@ gdbpy_initialize_values (void)
 
 \f
 
-static PyGetSetDef value_object_getset[] = {
+static gdb_PyGetSetDef value_object_getset[] = {
   { "address", valpy_get_address, NULL, "The address of the value.",
     NULL },
   { "is_optimized_out", valpy_get_is_optimized_out, NULL,
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 55efd75..d4ed170 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -286,6 +286,36 @@ gdb_PySys_SetPath (const GDB_PYSYS_SETPATH_CHAR *path)
 
 #define PySys_SetPath gdb_PySys_SetPath
 
+/* Wrap PyGetSetDef to allow convenient construction with string
+   literals.  Unfortunately, PyGetSetDef's 'name' and 'doc' members
+   are 'char *' instead of 'const char *', meaning that in order to
+   list-initialize PyGetSetDef arrays with string literals (and
+   without the wrapping below) would require writing explicit 'char *'
+   casts.  Instead, we extend PyGetSetDef and add constexpr
+   constructors that accept const 'name' and 'doc', hiding the ugly
+   casts here in a single place.  */
+
+struct gdb_PyGetSetDef : PyGetSetDef
+{
+  constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter set_,
+			     const char *doc_, void *closure_)
+    : PyGetSetDef {const_cast<char *> (name_), get_, set_,
+		   const_cast<char *> (doc_), closure_}
+  {}
+
+  /* Alternative constructor that allows omitting the closure in list
+     initialization.  */
+  constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter set_,
+			     const char *doc_)
+    : gdb_PyGetSetDef {name_, get_, set_, doc_, NULL}
+  {}
+
+  /* Constructor for the sentinel entries.  */
+  constexpr gdb_PyGetSetDef (std::nullptr_t)
+    : gdb_PyGetSetDef { NULL, NULL, NULL, NULL, NULL }
+  {}
+};
+
 /* In order to be able to parse symtab_and_line_to_sal_object function
    a real symtab_and_line structure is needed.  */
 #include "symtab.h"
-- 
2.5.5


^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 14/18] -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overload
  2017-04-04 18:37   ` Sergio Durigan Junior
@ 2017-04-05 12:58     ` Pedro Alves
  2017-04-05 15:49       ` Sergio Durigan Junior
  0 siblings, 1 reply; 39+ messages in thread
From: Pedro Alves @ 2017-04-05 12:58 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

On 04/04/2017 07:37 PM, Sergio Durigan Junior wrote:
> On Tuesday, April 04 2017, Pedro Alves wrote:

>> However, to avoid having all callers add the 'const_cast<char **>'
>> themselves, this commit define a PyArg_ParseTupleAndKeywords overload
>> here with a corresponding 'keywords' parameter type that does the cast
>> in a single place.
>>
>> As in the PyGetSetDef patch, I'd be fine with naming this
>> gdb_PyArg_ParseTupleAndKeywords instead, if people would find having
>> our own overload confusing.
> 
> As much as I like the overloading approach in general, I prefer to see
> our own overloads marked with the "gdb_", just to make things clearer.

OK, updated patch below.  WDYT?

> 
>> BTW, this API issue was discussed years ago in the python-dev list:
>>
>>  https://mail.python.org/pipermail/python-dev/2006-February/060689.html
>>
>> ... and an overload for C++ was suggested in there somewhere.
>> Unfortunately, it was never added.
> 
> Interesting.  I wonder if there's an actual bug/issue opened on their
> bugzilla about this.
> 
> Hm, after a quick search I didn't find anything.  Maybe it's worth
> creating one.

I had found that thread via this bug: https://bugs.python.org/issue1772673

From 2ea02b3a4f5e7e0a1ecfb206d8a5f04b37876bd2 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Wed, 5 Apr 2017 13:45:55 +0100
Subject: [PATCH] -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const
 char *" overload

-Wwrite-strings flags code like:

   static char *keywords[] = {"command", "from_tty", "to_string", NULL };

as needing "(char *)" casts, because string literals are "const char []".

We can get rid of the casts by changing the array type like this:

 -  static char *keywords[] = {"command", "from_tty", "to_string", NULL };
 +  static const char *keywords[] = {"command", "from_tty", "to_string", NULL };

However, passing the such array to PyArg_ParseTupleAndKeywords no longer
works OOTB, because PyArg_ParseTupleAndKeywords expects a "char **":

  PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw,
                              const char *format,
			      char *keywords[], ...);

and "const char **" is not implicitly convertible to "char **".  C++
is more tolerant that C here WRT aliasing, and a const_cast<char **>
is fine.  However, to avoid having all callers do the cast themselves,
this commit defines a gdb_PyArg_ParseTupleAndKeywords function here
with a corresponding 'keywords' parameter type that does the cast in a
single place.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* python/python-internal.h (gdb_PyArg_ParseTupleAndKeywords): New
	static inline function.
	* python/py-arch.c (archpy_disassemble): Constify 'keywords'
	array and use gdb_PyArg_ParseTupleAndKeywords.
	* python/py-cmd.c (cmdpy_init): Likewise.
	* python/py-finishbreakpoint.c (bpfinishpy_init): Likewise.
	* python/py-inferior.c (infpy_read_memory, infpy_write_memory)
	(infpy_search_memory): Likewise.
	* python/py-objfile.c (objfpy_add_separate_debug_file)
	(gdbpy_lookup_objfile): Likewise.
	* python/py-symbol.c (gdbpy_lookup_symbol)
	(gdbpy_lookup_global_symbol): Likewise.
	* python/py-type.c (gdbpy_lookup_type): Likewise.
	* python/py-value.c (valpy_lazy_string, valpy_string): Likewise.
	* python/python.c (execute_gdb_command, gdbpy_write, gdbpy_flush):
	Likewise.
---
 gdb/python/py-arch.c             |  7 ++++---
 gdb/python/py-breakpoint.c       | 10 +++++-----
 gdb/python/py-cmd.c              | 10 +++++-----
 gdb/python/py-finishbreakpoint.c |  6 +++---
 gdb/python/py-inferior.c         | 21 ++++++++++-----------
 gdb/python/py-objfile.c          | 10 +++++-----
 gdb/python/py-symbol.c           | 13 +++++++------
 gdb/python/py-type.c             |  6 +++---
 gdb/python/py-value.c            | 12 ++++++------
 gdb/python/python-internal.h     | 28 ++++++++++++++++++++++++++++
 gdb/python/python.c              | 20 ++++++++++----------
 11 files changed, 86 insertions(+), 57 deletions(-)

diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 71d2989..cfadb47 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -116,7 +116,7 @@ archpy_name (PyObject *self, PyObject *args)
 static PyObject *
 archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
 {
-  static char *keywords[] = { "start_pc", "end_pc", "count", NULL };
+  static const char *keywords[] = { "start_pc", "end_pc", "count", NULL };
   CORE_ADDR start, end = 0;
   CORE_ADDR pc;
   gdb_py_ulongest start_temp;
@@ -126,8 +126,9 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
 
   ARCHPY_REQUIRE_VALID (self, gdbarch);
 
-  if (!PyArg_ParseTupleAndKeywords (args, kw, GDB_PY_LLU_ARG "|OO", keywords,
-                                    &start_temp, &end_obj, &count_obj))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, GDB_PY_LLU_ARG "|OO",
+					keywords, &start_temp, &end_obj,
+					&count_obj))
     return NULL;
 
   start = start_temp;
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 34f46fb..a08501e 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -637,8 +637,8 @@ bppy_get_ignore_count (PyObject *self, void *closure)
 static int
 bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 {
-  static char *keywords[] = { "spec", "type", "wp_class", "internal",
-			      "temporary", NULL };
+  static const char *keywords[] = { "spec", "type", "wp_class", "internal",
+				    "temporary", NULL };
   const char *spec;
   int type = bp_breakpoint;
   int access_type = hw_write;
@@ -647,9 +647,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   int internal_bp = 0;
   int temporary_bp = 0;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
-				     &spec, &type, &access_type,
-				     &internal, &temporary))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
+					&spec, &type, &access_type,
+					&internal, &temporary))
     return -1;
 
   if (internal)
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 3aaf7f9..3e60673 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -490,8 +490,8 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
   char *docstring = NULL;
   struct cmd_list_element **cmd_list;
   char *cmd_name, *pfx_name;
-  static char *keywords[] = { "name", "command_class", "completer_class",
-			      "prefix", NULL };
+  static const char *keywords[] = { "name", "command_class", "completer_class",
+				    "prefix", NULL };
   PyObject *is_prefix = NULL;
   int cmp;
 
@@ -504,9 +504,9 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
       return -1;
     }
 
-  if (! PyArg_ParseTupleAndKeywords (args, kw, "si|iO",
-				     keywords, &name, &cmdtype,
-			  &completetype, &is_prefix))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "si|iO",
+					keywords, &name, &cmdtype,
+					&completetype, &is_prefix))
     return -1;
 
   if (cmdtype != no_class && cmdtype != class_run
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 76189b8..06f6ff9 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -156,7 +156,7 @@ bpfinishpy_post_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
 static int
 bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 {
-  static char *keywords[] = { "frame", "internal", NULL };
+  static const char *keywords[] = { "frame", "internal", NULL };
   struct finish_breakpoint_object *self_bpfinish =
       (struct finish_breakpoint_object *) self;
   PyObject *frame_obj = NULL;
@@ -169,8 +169,8 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   CORE_ADDR pc;
   struct symbol *function;
 
-  if (!PyArg_ParseTupleAndKeywords (args, kwargs, "|OO", keywords,
-                                    &frame_obj, &internal))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|OO", keywords,
+					&frame_obj, &internal))
     return -1;
 
   TRY
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 77fc543..41bedb5 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -435,10 +435,10 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
   CORE_ADDR addr, length;
   gdb_byte *buffer = NULL;
   PyObject *addr_obj, *length_obj, *result;
-  static char *keywords[] = { "address", "length", NULL };
+  static const char *keywords[] = { "address", "length", NULL };
 
-  if (! PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords,
-				     &addr_obj, &length_obj))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords,
+					&addr_obj, &length_obj))
     return NULL;
 
   if (get_addr_from_python (addr_obj, &addr) < 0
@@ -494,13 +494,12 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
   const gdb_byte *buffer;
   CORE_ADDR addr, length;
   PyObject *addr_obj, *length_obj = NULL;
-  static char *keywords[] = { "address", "buffer", "length", NULL };
+  static const char *keywords[] = { "address", "buffer", "length", NULL };
 #ifdef IS_PY3K
   Py_buffer pybuf;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kw, "Os*|O", keywords,
-				     &addr_obj, &pybuf,
-				     &length_obj))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "Os*|O", keywords,
+					&addr_obj, &pybuf, &length_obj))
     return NULL;
 
   buffer = (const gdb_byte *) pybuf.buf;
@@ -643,7 +642,7 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
 {
   struct gdb_exception except = exception_none;
   CORE_ADDR start_addr, length;
-  static char *keywords[] = { "address", "length", "pattern", NULL };
+  static const char *keywords[] = { "address", "length", "pattern", NULL };
   PyObject *start_addr_obj, *length_obj;
   Py_ssize_t pattern_size;
   const gdb_byte *buffer;
@@ -652,9 +651,9 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
 #ifdef IS_PY3K
   Py_buffer pybuf;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kw, "OOs*", keywords,
-				     &start_addr_obj, &length_obj,
-				     &pybuf))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "OOs*", keywords,
+					&start_addr_obj, &length_obj,
+					&pybuf))
     return NULL;
 
   buffer = (const gdb_byte *) pybuf.buf;
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 6a47c17..52f2e1f 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -432,13 +432,13 @@ objfpy_is_valid (PyObject *self, PyObject *args)
 static PyObject *
 objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
 {
-  static char *keywords[] = { "file_name", NULL };
+  static const char *keywords[] = { "file_name", NULL };
   objfile_object *obj = (objfile_object *) self;
   const char *file_name;
 
   OBJFPY_REQUIRE_VALID (obj);
 
-  if (!PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
     return NULL;
 
   TRY
@@ -559,14 +559,14 @@ objfpy_lookup_objfile_by_build_id (const char *build_id)
 PyObject *
 gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
 {
-  static char *keywords[] = { "name", "by_build_id", NULL };
+  static const char *keywords[] = { "name", "by_build_id", NULL };
   const char *name;
   PyObject *by_build_id_obj = NULL;
   int by_build_id;
   struct objfile *objfile;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords,
-				     &name, &PyBool_Type, &by_build_id_obj))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords,
+					&name, &PyBool_Type, &by_build_id_obj))
     return NULL;
 
   by_build_id = 0;
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 05b002f..c9f83a3 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -373,13 +373,14 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
   int domain = VAR_DOMAIN;
   struct field_of_this_result is_a_field_of_this;
   const char *name;
-  static char *keywords[] = { "name", "block", "domain", NULL };
+  static const char *keywords[] = { "name", "block", "domain", NULL };
   struct symbol *symbol = NULL;
   PyObject *block_obj = NULL, *sym_obj, *bool_obj;
   const struct block *block = NULL;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
-				     &block_object_type, &block_obj, &domain))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
+					&block_object_type, &block_obj,
+					&domain))
     return NULL;
 
   if (block_obj)
@@ -443,12 +444,12 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
 {
   int domain = VAR_DOMAIN;
   const char *name;
-  static char *keywords[] = { "name", "domain", NULL };
+  static const char *keywords[] = { "name", "domain", NULL };
   struct symbol *symbol = NULL;
   PyObject *sym_obj;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name,
-				     &domain))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name,
+					&domain))
     return NULL;
 
   TRY
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 12b6310..aa20d4c 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1347,14 +1347,14 @@ type_object_to_type (PyObject *obj)
 PyObject *
 gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
 {
-  static char *keywords[] = { "name", "block", NULL };
+  static const char *keywords[] = { "name", "block", NULL };
   const char *type_name = NULL;
   struct type *type = NULL;
   PyObject *block_obj = NULL;
   const struct block *block = NULL;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
-				     &type_name, &block_obj))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
+					&type_name, &block_obj))
     return NULL;
 
   if (block_obj)
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 9c0470f..b5a0ef8 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -431,11 +431,11 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
   gdb_py_longest length = -1;
   struct value *value = ((value_object *) self)->value;
   const char *user_encoding = NULL;
-  static char *keywords[] = { "encoding", "length", NULL };
+  static const char *keywords[] = { "encoding", "length", NULL };
   PyObject *str_obj = NULL;
 
-  if (!PyArg_ParseTupleAndKeywords (args, kw, "|s" GDB_PY_LL_ARG, keywords,
-				    &user_encoding, &length))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "|s" GDB_PY_LL_ARG,
+					keywords, &user_encoding, &length))
     return NULL;
 
   if (length < -1)
@@ -526,10 +526,10 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw)
   const char *user_encoding = NULL;
   const char *la_encoding = NULL;
   struct type *char_type;
-  static char *keywords[] = { "encoding", "errors", "length", NULL };
+  static const char *keywords[] = { "encoding", "errors", "length", NULL };
 
-  if (!PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
-				    &user_encoding, &errors, &length))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
+					&user_encoding, &errors, &length))
     return NULL;
 
   TRY
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index d4ed170..db75002 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -316,6 +316,34 @@ struct gdb_PyGetSetDef : PyGetSetDef
   {}
 };
 
+/* The 'keywords' parameter of PyArg_ParseTupleAndKeywords has type
+   'char **'.  However, string literals are const in C++, and so to
+   avoid casting at every keyword array definition, we'll need to make
+   the keywords array an array of 'const char *'.  To avoid having all
+   callers add a 'const_cast<char **>' themselves when passing such an
+   array through 'char **', we define our own version of
+   PyArg_ParseTupleAndKeywords here with a corresponding 'keywords'
+   parameter type that does the cast in a single place.  (This is not
+   an overload of PyArg_ParseTupleAndKeywords in order to make it
+   clearer that we're calling our own function instead of a function
+   that exists in some newer Python version.)  */
+
+static inline int
+gdb_PyArg_ParseTupleAndKeywords (PyObject *args, PyObject *kw,
+				 const char *format, const char **keywords, ...)
+{
+  va_list ap;
+  int res;
+
+  va_start (ap, keywords);
+  res = PyArg_VaParseTupleAndKeywords (args, kw, format,
+				       const_cast<char **> (keywords),
+				       ap);
+  va_end (ap);
+
+  return res;
+}
+
 /* In order to be able to parse symtab_and_line_to_sal_object function
    a real symtab_and_line structure is needed.  */
 #include "symtab.h"
diff --git a/gdb/python/python.c b/gdb/python/python.c
index a7aff53..25f475f 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -572,11 +572,11 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
   const char *arg;
   PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
   int from_tty, to_string;
-  static char *keywords[] = {"command", "from_tty", "to_string", NULL };
+  static const char *keywords[] = { "command", "from_tty", "to_string", NULL };
 
-  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
-				     &PyBool_Type, &from_tty_obj,
-				     &PyBool_Type, &to_string_obj))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
+					&PyBool_Type, &from_tty_obj,
+					&PyBool_Type, &to_string_obj))
     return NULL;
 
   from_tty = 0;
@@ -1047,11 +1047,11 @@ static PyObject *
 gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
 {
   const char *arg;
-  static char *keywords[] = {"text", "stream", NULL };
+  static const char *keywords[] = { "text", "stream", NULL };
   int stream_type = 0;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &arg,
-				     &stream_type))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &arg,
+					&stream_type))
     return NULL;
 
   TRY
@@ -1088,11 +1088,11 @@ gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
 static PyObject *
 gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
 {
-  static char *keywords[] = {"stream", NULL };
+  static const char *keywords[] = { "stream", NULL };
   int stream_type = 0;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kw, "|i", keywords,
-				     &stream_type))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "|i", keywords,
+					&stream_type))
     return NULL;
 
   switch (stream_type)
-- 
2.5.5


^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 17/18] -Wwrite-strings: The Rest
  2017-04-04 18:44   ` John Baldwin
@ 2017-04-05 12:59     ` Pedro Alves
  0 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-05 12:59 UTC (permalink / raw)
  To: John Baldwin, gdb-patches

On 04/04/2017 07:22 PM, John Baldwin wrote:
> On Tuesday, April 04, 2017 06:25:50 PM Pedro Alves wrote:
>> This is the remainder boring constification that all looks more of less
>> borderline obvious IMO.
>>
>> gdb/ChangeLog:
>> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
>>
>> 	* fbsd-tdep.c (fbsd_core_pid_to_str): Constify.
> 
> Tiny nit: this isn't actually changed in this patchset (was going to quickly
> eyeball it).  

Whooops, sorry about that.  Fixed locally.

> Perhaps the changelog is stale from you breaking the
> pid_to_str target method out into its own patch?

That's exactly what happened.

Thanks for taking a look!

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals
  2017-04-05  8:49   ` Philipp Rudo
@ 2017-04-05 13:03     ` Pedro Alves
  0 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-05 13:03 UTC (permalink / raw)
  To: Philipp Rudo; +Cc: gdb-patches

On 04/05/2017 09:49 AM, Philipp Rudo wrote:
> Hi Pedro
> 
> I found a typo ...

Thanks Philipp.  I fixed it in the version of the patch I sent in
reply to Sergio.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 15/18] -Wwrite-strings: execute_command calls with string literals
  2017-04-05  7:13   ` Metzger, Markus T
@ 2017-04-05 13:10     ` Pedro Alves
  0 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-05 13:10 UTC (permalink / raw)
  To: Metzger, Markus T, gdb-patches

On 04/05/2017 08:13 AM, Metzger, Markus T wrote:

> The patch looks good to me.  But I'm wondering if we should instead change
> execute_command to take a const char *.

That's not that simple, because some commands do want to modify the
input string.

For example, cli/cli-cmds.c:list_command does:

  /* If this command is repeated with RET,
     turn it into the no-arg variant.  */

  if (from_tty)
    *arg = 0;


and also, it'd require a lot of cascading constification
inside many commands, because lots of command args processing
passes "&args" to some routine that expects a "char **".

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 07/18] -Wwrite-strings: Constify work break character arrays
  2017-04-05  8:46   ` Philipp Rudo
@ 2017-04-05 13:17     ` Pedro Alves
  0 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-05 13:17 UTC (permalink / raw)
  To: Philipp Rudo; +Cc: gdb-patches

On 04/05/2017 09:46 AM, Philipp Rudo wrote:
> Hi Pedro
> 
> great series. Just one minor thing I noticed here.

Thanks!

>>  /* FIXME: brobecker/2003-09-17: No longer a const because it is
>>     returned by a function that does not return a const char *.  */
>> -static char *ada_completer_word_break_characters =
>> +static const char ada_completer_word_break_characters[] =
>>  #ifdef VMS
>>    " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
>>  #else
> 
> The comment above doesn't make sense, especially after your
> change. I think it should be removed. 

Indeed, nice catch.  I removed the comment.

And also fixed the typo in the commit's subject: "work" -> "word"...

Here's what I currently have.  (Nothing else changed.)

From 9171fb380f5267d2346dd3e6b3c5c80192911dfb Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Wed, 5 Apr 2017 12:58:19 +0100
Subject: [PATCH] -Wwrite-strings: Constify word break character arrays

-Wwrite-strings flags several cases of missing casts around
initializations like:

   static char *gdb_completer_command_word_break_characters =
    " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";

Obviously these could/should be const.  However, while at it, there's
no need for these variables to be pointers instead of arrays.  They
are never changed to point to anything else.

Unfortunately, readline's rl_completer_word_break_characters is "char
*", not "const char *".  So we always need a cast somewhere.  The
approach taken here is to add a new
set_rl_completer_word_break_characters function that becomes the only
place that writes to rl_completer_word_break_characters, and thus the
single place that needs the cast.

gdb/ChangeLog:
yyyy-mm-dd Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_completer_word_break_characters): Now a const
	array.
	(ada_get_gdb_completer_word_break_characters): Constify.
	* completer.c (gdb_completer_command_word_break_characters)
	(gdb_completer_file_name_break_characters)
	(gdb_completer_quote_characters): Now const arrays.
	(get_gdb_completer_quote_characters): Constify.
	(set_rl_completer_word_break_characters): New function.
	(set_gdb_completion_word_break_characters)
	(complete_line_internal): Use it.
	* completer.h (get_gdb_completer_quote_characters): Constify.
	(set_rl_completer_word_break_characters): Declare.
	* f-lang.c (f_word_break_characters): Constify.
	* language.c (default_word_break_characters): Constify.
	* language.h (language_defn::la_word_break_characters): Constify.
	(default_word_break_characters): Constify.
	* top.c (init_main): Use set_rl_completer_word_break_characters.
---
 gdb/ada-lang.c  |  6 ++----
 gdb/completer.c | 59 ++++++++++++++++++++++++++++++++++-----------------------
 gdb/completer.h |  8 +++++++-
 gdb/f-lang.c    |  2 +-
 gdb/language.c  |  2 +-
 gdb/language.h  |  4 ++--
 gdb/top.c       |  2 +-
 7 files changed, 49 insertions(+), 34 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 9b91e0c..7be135e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -315,9 +315,7 @@ static void ada_free_symbol_cache (struct ada_symbol_cache *sym_cache);
 /* Maximum-sized dynamic type.  */
 static unsigned int varsize_limit;
 
-/* FIXME: brobecker/2003-09-17: No longer a const because it is
-   returned by a function that does not return a const char *.  */
-static char *ada_completer_word_break_characters =
+static const char ada_completer_word_break_characters[] =
 #ifdef VMS
   " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
 #else
@@ -558,7 +556,7 @@ add_angle_brackets (const char *str)
   return result;
 }
 
-static char *
+static const char *
 ada_get_gdb_completer_word_break_characters (void)
 {
   return ada_completer_word_break_characters;
diff --git a/gdb/completer.c b/gdb/completer.c
index 45adc62..9183e2a 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -84,29 +84,30 @@ char *line_completion_function (const char *text, int matches,
    readline library sees one in any of the current completion strings,
    it thinks that the string needs to be quoted and automatically
    supplies a leading quote.  */
-static char *gdb_completer_command_word_break_characters =
+static const char gdb_completer_command_word_break_characters[] =
 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
 
 /* When completing on file names, we remove from the list of word
    break characters any characters that are commonly used in file
    names, such as '-', '+', '~', etc.  Otherwise, readline displays
    incorrect completion candidates.  */
-#ifdef HAVE_DOS_BASED_FILE_SYSTEM
 /* MS-DOS and MS-Windows use colon as part of the drive spec, and most
    programs support @foo style response files.  */
-static char *gdb_completer_file_name_break_characters = " \t\n*|\"';?><@";
+static const char gdb_completer_file_name_break_characters[] =
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  " \t\n*|\"';?><@";
 #else
-static char *gdb_completer_file_name_break_characters = " \t\n*|\"';:?><";
+  " \t\n*|\"';:?><";
 #endif
 
 /* Characters that can be used to quote completion strings.  Note that
    we can't include '"' because the gdb C parser treats such quoted
    sequences as strings.  */
-static char *gdb_completer_quote_characters = "'";
+static const char gdb_completer_quote_characters[] = "'";
 \f
 /* Accessor for some completer data that may interest other files.  */
 
-char *
+const char *
 get_gdb_completer_quote_characters (void)
 {
   return gdb_completer_quote_characters;
@@ -652,16 +653,26 @@ expression_completer (struct cmd_list_element *ignore,
 /* See definition in completer.h.  */
 
 void
+set_rl_completer_word_break_characters (const char *break_chars)
+{
+  rl_completer_word_break_characters = (char *) break_chars;
+}
+
+/* See definition in completer.h.  */
+
+void
 set_gdb_completion_word_break_characters (completer_ftype *fn)
 {
+  const char *break_chars;
+
   /* So far we are only interested in differentiating filename
      completers from everything else.  */
   if (fn == filename_completer)
-    rl_completer_word_break_characters
-      = gdb_completer_file_name_break_characters;
+    break_chars = gdb_completer_file_name_break_characters;
   else
-    rl_completer_word_break_characters
-      = gdb_completer_command_word_break_characters;
+    break_chars = gdb_completer_command_word_break_characters;
+
+  set_rl_completer_word_break_characters (break_chars);
 }
 
 /* Here are some useful test cases for completion.  FIXME: These
@@ -743,8 +754,8 @@ complete_line_internal (const char *text,
      then we will switch to the special word break set for command
      strings, which leaves out the '-' character used in some
      commands.  */
-  rl_completer_word_break_characters =
-    current_language->la_word_break_characters();
+  set_rl_completer_word_break_characters
+    (current_language->la_word_break_characters());
 
   /* Decide whether to complete on a list of gdb commands or on
      symbols.  */
@@ -821,8 +832,8 @@ complete_line_internal (const char *text,
 	    }
 	  /* Ensure that readline does the right thing with respect to
 	     inserting quotes.  */
-	  rl_completer_word_break_characters =
-	    gdb_completer_command_word_break_characters;
+	  set_rl_completer_word_break_characters
+	    (gdb_completer_command_word_break_characters);
 	}
     }
   else
@@ -848,8 +859,8 @@ complete_line_internal (const char *text,
 
 		  /* Ensure that readline does the right thing
 		     with respect to inserting quotes.  */
-		  rl_completer_word_break_characters =
-		    gdb_completer_command_word_break_characters;
+		  set_rl_completer_word_break_characters
+		    (gdb_completer_command_word_break_characters);
 		}
 	      else if (reason == handle_help)
 		list = NULL;
@@ -857,8 +868,8 @@ complete_line_internal (const char *text,
 		{
 		  if (reason != handle_brkchars)
 		    list = complete_on_enum (c->enums, p, word);
-		  rl_completer_word_break_characters =
-		    gdb_completer_command_word_break_characters;
+		  set_rl_completer_word_break_characters
+		    (gdb_completer_command_word_break_characters);
 		}
 	      else
 		{
@@ -879,8 +890,8 @@ complete_line_internal (const char *text,
 			     && strchr (gdb_completer_file_name_break_characters, p[-1]) == NULL;
 			   p--)
 			;
-		      rl_completer_word_break_characters =
-			gdb_completer_file_name_break_characters;
+		      set_rl_completer_word_break_characters
+			(gdb_completer_file_name_break_characters);
 		    }
 		  if (reason == handle_brkchars
 		      && c->completer_handle_brkchars != NULL)
@@ -913,8 +924,8 @@ complete_line_internal (const char *text,
 
 	      /* Ensure that readline does the right thing
 		 with respect to inserting quotes.  */
-	      rl_completer_word_break_characters =
-		gdb_completer_command_word_break_characters;
+	      set_rl_completer_word_break_characters
+		(gdb_completer_command_word_break_characters);
 	    }
 	}
       else if (reason == handle_help)
@@ -947,8 +958,8 @@ complete_line_internal (const char *text,
 				    p[-1]) == NULL;
 		       p--)
 		    ;
-		  rl_completer_word_break_characters =
-		    gdb_completer_file_name_break_characters;
+		  set_rl_completer_word_break_characters
+		    (gdb_completer_file_name_break_characters);
 		}
 	      if (reason == handle_brkchars
 		  && c->completer_handle_brkchars != NULL)
diff --git a/gdb/completer.h b/gdb/completer.h
index 416b313..2aa1987 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -99,10 +99,16 @@ extern VEC (char_ptr) *reg_or_group_completer (struct cmd_list_element *,
 extern VEC (char_ptr) *reggroup_completer (struct cmd_list_element *,
 					   const char *, const char *);
 
-extern char *get_gdb_completer_quote_characters (void);
+extern const char *get_gdb_completer_quote_characters (void);
 
 extern char *gdb_completion_word_break_characters (void);
 
+/* Set the word break characters array to BREAK_CHARS.  This function
+   is useful as const-correct alternative to direct assignment to
+   rl_completer_word_break_characters, which is "char *",
+   not "const char *".  */
+extern void set_rl_completer_word_break_characters (const char *break_chars);
+
 /* Set the word break characters array to the corresponding set of
    chars, based on FN.  This function is useful for cases when the
    completer doesn't know the type of the completion until some
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 8aba5ef..3c30d75 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -203,7 +203,7 @@ f_language_arch_info (struct gdbarch *gdbarch,
 
 /* Remove the modules separator :: from the default break list.  */
 
-static char *
+static const char *
 f_word_break_characters (void)
 {
   static char *retval;
diff --git a/gdb/language.c b/gdb/language.c
index 119c07e..f1fc220 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -698,7 +698,7 @@ default_pass_by_reference (struct type *type)
    delimiting words.  This is a reasonable default value that
    most languages should be able to use.  */
 
-char *
+const char *
 default_word_break_characters (void)
 {
   return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
diff --git a/gdb/language.h b/gdb/language.h
index 3d21e4e..96080ac 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -321,7 +321,7 @@ struct language_defn
     char string_lower_bound;
 
     /* The list of characters forming word boundaries.  */
-    char *(*la_word_break_characters) (void);
+    const char *(*la_word_break_characters) (void);
 
     /* Should return a vector of all symbols which are possible
        completions for TEXT.  WORD is the entire command on which the
@@ -583,7 +583,7 @@ extern char *language_class_name_from_physname (const struct language_defn *,
 					        const char *physname);
 
 /* Splitting strings into words.  */
-extern char *default_word_break_characters (void);
+extern const char *default_word_break_characters (void);
 
 /* Print the index of an array element using the C99 syntax.  */
 extern void default_print_array_index (struct value *index_value,
diff --git a/gdb/top.c b/gdb/top.c
index 295b680..4a22be1 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2022,7 +2022,7 @@ init_main (void)
   /* Setup important stuff for command line editing.  */
   rl_completion_word_break_hook = gdb_completion_word_break_characters;
   rl_completion_entry_function = readline_line_completion_function;
-  rl_completer_word_break_characters = default_word_break_characters ();
+  set_rl_completer_word_break_characters (default_word_break_characters ());
   rl_completer_quote_characters = get_gdb_completer_quote_characters ();
   rl_completion_display_matches_hook = cli_display_match_list;
   rl_readline_name = "gdb";
-- 
2.5.5


^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals
  2017-04-05 12:35     ` Pedro Alves
@ 2017-04-05 15:48       ` Sergio Durigan Junior
  0 siblings, 0 replies; 39+ messages in thread
From: Sergio Durigan Junior @ 2017-04-05 15:48 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Wednesday, April 05 2017, Pedro Alves wrote:

> On 04/04/2017 07:39 PM, Sergio Durigan Junior wrote:
>
>> I liked the approach.  As with the other Python patch, I'm more inclined
>> to use an explicit "gdb_PyGetSetDef" everywhere, just to be clear that
>> we are using our own version of it.  This can save time when debugging.
>
> OK, here's what that looks like.  Commit log updated to reflect the
> change too.  WDYT?

LGTM.  Thanks!

> From 566fd938f2919985db6a955d769ba619534964e8 Mon Sep 17 00:00:00 2001
> From: Pedro Alves <palves@redhat.com>
> Date: Wed, 5 Apr 2017 13:22:25 +0100
> Subject: [PATCH] -Wwrite-strings: Wrap PyGetSetDef for construction with
>  string literals
>
> Unfortunately, PyGetSetDef's 'name' and 'doc' members are 'char *'
> instead of 'const char *', meaning that in order to list-initialize
> PyGetSetDef arrays using string literals requires writing explicit
> 'char *' casts.  For example:
>
>     static PyGetSetDef value_object_getset[] = {
>    -  { "address", valpy_get_address, NULL, "The address of the value.",
>    +  { (char *) "address", valpy_get_address, NULL,
>    +    (char *) "The address of the value.",
> 	NULL },
>    -  { "is_optimized_out", valpy_get_is_optimized_out, NULL,
>    -    "Boolean telling whether the value is optimized "
>    +  { (char *) "is_optimized_out", valpy_get_is_optimized_out, NULL,
>    +    (char *) "Boolean telling whether the value is optimized "
> 	"out (i.e., not available).",
> 	NULL },
>    -  { "type", valpy_get_type, NULL, "Type of the value.", NULL },
>    -  { "dynamic_type", valpy_get_dynamic_type, NULL,
>    -    "Dynamic type of the value.", NULL },
>    -  { "is_lazy", valpy_get_is_lazy, NULL,
>    -    "Boolean telling whether the value is lazy (not fetched yet\n\
>    +  { (char *) "type", valpy_get_type, NULL,
>    +    (char *) "Type of the value.", NULL },
>    +  { (char *) "dynamic_type", valpy_get_dynamic_type, NULL,
>    +    (char *) "Dynamic type of the value.", NULL },
>    +  { (char *) "is_lazy", valpy_get_is_lazy, NULL,
>    +    (char *) "Boolean telling whether the value is lazy (not fetched yet\n\
>     from the inferior).  A lazy value is fetched when needed, or when\n\
>     the \"fetch_lazy()\" method is called.", NULL },
>       {NULL}  /* Sentinel */
>
> We have ~20 such arrays, and I first wrote a patch that fixed all of
> them like that...  It's not pretty...
>
> One way to make these a bit less ugly would be add a new macro that
> hides the casts, like:
>
>   #define GDBPY_GSDEF(NAME, GET, SET, DOC, CLOSURE) \
>      { (char *) NAME, GET, SET, (char *) DOC, CLOSURE }
>
> and then use it like:
>
>     static PyGetSetDef value_object_getset[] = {
>        GDBPY_GSDEF ("address", valpy_get_address, NULL,
>        		    "The address of the value.", NULL),
>        GDBPY_GSDEF ("is_optimized_out", valpy_get_is_optimized_out, NULL,
>        		    "Boolean telling whether the value is optimized ", NULL),
>       {NULL}  /* Sentinel */
>     };
>
> But since we have C++11, which gives us constexpr and list
> initialization, I thought of a way that requires no changes where the
> arrays are initialized:
>
> We add a new type that extends PyGetSetDef (called gdb_PyGetSetDef),
> and add constexpr constructors that accept const 'name' and 'doc', and
> then list/aggregate initialization simply "calls" these matching
> constructors instead.
>
> I put "calls" in quotes, because given "constexpr", it's all done at
> compile time, and there's no overhead either in binary size or at run
> time.  In fact, we get identical binaries, before/after this change.
>
> Unlike the fixes that fix some old Python API to match the API of more
> recent Python, this switches to using explicit "gdb_PyGetSetDef"
> everywhere, just to be clear that we are using our own version of it.
>
> gdb/ChangeLog:
> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
>
> 	* python/python-internal.h (gdb_PyGetSetDef): New type.
> 	* python/py-block.c (block_object_getset)
> 	(breakpoint_object_getset): Now a gdb_PyGetSetDef array.
> 	* python/py-event.c (event_object_getset)
> 	(finish_breakpoint_object_getset): Likewise.
> 	* python/py-inferior.c (inferior_object_getset): Likewise.
> 	* python/py-infthread.c (thread_object_getset): Likewise.
> 	* python/py-lazy-string.c (lazy_string_object_getset): Likewise.
> 	* python/py-linetable.c (linetable_entry_object_getset): Likewise.
> 	* python/py-objfile.c (objfile_getset): Likewise.
> 	* python/py-progspace.c (pspace_getset): Likewise.
> 	* python/py-record-btrace.c (btpy_insn_getset, btpy_call_getset):
> 	Likewise.
> 	* python/py-record.c (recpy_record_getset): Likewise.
> 	* python/py-symbol.c (symbol_object_getset): Likewise.
> 	* python/py-symtab.c (symtab_object_getset, sal_object_getset):
> 	Likewise.
> 	* python/py-type.c (type_object_getset, field_object_getset):
> 	Likewise.
> 	* python/py-value.c (value_object_getset): Likewise.
> ---
>  gdb/python/py-block.c            |  2 +-
>  gdb/python/py-breakpoint.c       |  2 +-
>  gdb/python/py-event.c            |  2 +-
>  gdb/python/py-finishbreakpoint.c |  2 +-
>  gdb/python/py-inferior.c         |  2 +-
>  gdb/python/py-infthread.c        |  2 +-
>  gdb/python/py-lazy-string.c      |  2 +-
>  gdb/python/py-linetable.c        |  2 +-
>  gdb/python/py-objfile.c          |  2 +-
>  gdb/python/py-progspace.c        |  2 +-
>  gdb/python/py-record-btrace.c    |  4 ++--
>  gdb/python/py-record.c           |  2 +-
>  gdb/python/py-symbol.c           |  2 +-
>  gdb/python/py-symtab.c           |  4 ++--
>  gdb/python/py-type.c             |  4 ++--
>  gdb/python/py-value.c            |  2 +-
>  gdb/python/python-internal.h     | 30 ++++++++++++++++++++++++++++++
>  17 files changed, 49 insertions(+), 19 deletions(-)
>
> diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
> index f477d4a..840c842 100644
> --- a/gdb/python/py-block.c
> +++ b/gdb/python/py-block.c
> @@ -461,7 +461,7 @@ Return true if this block is valid, false if not." },
>    {NULL}  /* Sentinel */
>  };
>  
> -static PyGetSetDef block_object_getset[] = {
> +static gdb_PyGetSetDef block_object_getset[] = {
>    { "start", blpy_get_start, NULL, "Start address of the block.", NULL },
>    { "end", blpy_get_end, NULL, "End address of the block.", NULL },
>    { "function", blpy_get_function, NULL,
> diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
> index 724a7ed..34f46fb 100644
> --- a/gdb/python/py-breakpoint.c
> +++ b/gdb/python/py-breakpoint.c
> @@ -1048,7 +1048,7 @@ local_setattro (PyObject *self, PyObject *name, PyObject *v)
>    return PyObject_GenericSetAttr ((PyObject *)self, name, v);
>  }
>  
> -static PyGetSetDef breakpoint_object_getset[] = {
> +static gdb_PyGetSetDef breakpoint_object_getset[] = {
>    { "enabled", bppy_get_enabled, bppy_set_enabled,
>      "Boolean telling whether the breakpoint is enabled.", NULL },
>    { "silent", bppy_get_silent, bppy_set_silent,
> diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c
> index 127dcc7..dc1d73e 100644
> --- a/gdb/python/py-event.c
> +++ b/gdb/python/py-event.c
> @@ -114,7 +114,7 @@ evpy_emit_event (PyObject *event,
>    return 0;
>  }
>  
> -static PyGetSetDef event_object_getset[] =
> +static gdb_PyGetSetDef event_object_getset[] =
>  {
>    { "__dict__", gdb_py_generic_dict, NULL,
>      "The __dict__ for this event.", &event_object_type },
> diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
> index 106fe34..76189b8 100644
> --- a/gdb/python/py-finishbreakpoint.c
> +++ b/gdb/python/py-finishbreakpoint.c
> @@ -426,7 +426,7 @@ gdbpy_initialize_finishbreakpoints (void)
>    return 0;
>  }
>  
> -static PyGetSetDef finish_breakpoint_object_getset[] = {
> +static gdb_PyGetSetDef finish_breakpoint_object_getset[] = {
>    { "return_value", bpfinishpy_get_returnvalue, NULL,
>    "gdb.Value object representing the return value, if any. \
>  None otherwise.", NULL },
> diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
> index 46a0aad..77fc543 100644
> --- a/gdb/python/py-inferior.c
> +++ b/gdb/python/py-inferior.c
> @@ -827,7 +827,7 @@ gdbpy_initialize_inferior (void)
>  				 &membuf_object_type);
>  }
>  
> -static PyGetSetDef inferior_object_getset[] =
> +static gdb_PyGetSetDef inferior_object_getset[] =
>  {
>    { "num", infpy_get_num, NULL, "ID of inferior, as assigned by GDB.", NULL },
>    { "pid", infpy_get_pid, NULL, "PID of inferior, as assigned by the OS.",
> diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
> index 5482bf9..626c15c 100644
> --- a/gdb/python/py-infthread.c
> +++ b/gdb/python/py-infthread.c
> @@ -304,7 +304,7 @@ gdbpy_initialize_thread (void)
>  				 (PyObject *) &thread_object_type);
>  }
>  
> -static PyGetSetDef thread_object_getset[] =
> +static gdb_PyGetSetDef thread_object_getset[] =
>  {
>    { "name", thpy_get_name, thpy_set_name,
>      "The name of the thread, as set by the user or the OS.", NULL },
> diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
> index ab3f411..1999033 100644
> --- a/gdb/python/py-lazy-string.c
> +++ b/gdb/python/py-lazy-string.c
> @@ -300,7 +300,7 @@ static PyMethodDef lazy_string_object_methods[] = {
>  };
>  
>  
> -static PyGetSetDef lazy_string_object_getset[] = {
> +static gdb_PyGetSetDef lazy_string_object_getset[] = {
>    { "address", stpy_get_address, NULL, "Address of the string.", NULL },
>    { "encoding", stpy_get_encoding, NULL, "Encoding of the string.", NULL },
>    { "length", stpy_get_length, NULL, "Length of the string.", NULL },
> diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
> index a5e57b0..8d17aab 100644
> --- a/gdb/python/py-linetable.c
> +++ b/gdb/python/py-linetable.c
> @@ -550,7 +550,7 @@ PyTypeObject ltpy_iterator_object_type = {
>  };
>  
>  
> -static PyGetSetDef linetable_entry_object_getset[] = {
> +static gdb_PyGetSetDef linetable_entry_object_getset[] = {
>    { "line", ltpy_entry_get_line, NULL,
>      "The line number in the source file.", NULL },
>    { "pc", ltpy_entry_get_pc, NULL,
> diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
> index 105d88a..6a47c17 100644
> --- a/gdb/python/py-objfile.c
> +++ b/gdb/python/py-objfile.c
> @@ -670,7 +670,7 @@ Add FILE_NAME to the list of files containing debug info for the objfile." },
>    { NULL }
>  };
>  
> -static PyGetSetDef objfile_getset[] =
> +static gdb_PyGetSetDef objfile_getset[] =
>  {
>    { "__dict__", gdb_py_generic_dict, NULL,
>      "The __dict__ for this objfile.", &objfile_object_type },
> diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
> index 1e06a75..edabba4 100644
> --- a/gdb/python/py-progspace.c
> +++ b/gdb/python/py-progspace.c
> @@ -378,7 +378,7 @@ gdbpy_initialize_pspace (void)
>  
>  \f
>  
> -static PyGetSetDef pspace_getset[] =
> +static gdb_PyGetSetDef pspace_getset[] =
>  {
>    { "__dict__", gdb_py_generic_dict, NULL,
>      "The __dict__ for this progspace.", &pspace_object_type },
> diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
> index c816332..6d08121 100644
> --- a/gdb/python/py-record-btrace.c
> +++ b/gdb/python/py-record-btrace.c
> @@ -903,7 +903,7 @@ recpy_bt_goto (PyObject *self, PyObject *args)
>  
>  /* BtraceInstruction members.  */
>  
> -struct PyGetSetDef btpy_insn_getset[] =
> +struct gdb_PyGetSetDef btpy_insn_getset[] =
>  {
>    { "number", btpy_number, NULL, "instruction number", NULL},
>    { "error", btpy_insn_error, NULL, "error number for gaps", NULL},
> @@ -920,7 +920,7 @@ executed speculatively", NULL},
>  
>  /* BtraceFunctionCall members.  */
>  
> -static PyGetSetDef btpy_call_getset[] =
> +static gdb_PyGetSetDef btpy_call_getset[] =
>  {
>    { "number", btpy_number, NULL, "function call number", NULL},
>    { "level", btpy_call_level, NULL, "call stack level", NULL},
> diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
> index 72922a4..60c0a7c 100644
> --- a/gdb/python/py-record.c
> +++ b/gdb/python/py-record.c
> @@ -175,7 +175,7 @@ Rewind to given location."},
>  
>  /* Record member list.  */
>  
> -static PyGetSetDef recpy_record_getset[] = {
> +static gdb_PyGetSetDef recpy_record_getset[] = {
>    { "ptid", recpy_ptid, NULL, "Current thread.", NULL },
>    { "method", recpy_method, NULL, "Current recording method.", NULL },
>    { "format", recpy_format, NULL, "Current recording format.", NULL },
> diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
> index b71cfb4..05b002f 100644
> --- a/gdb/python/py-symbol.c
> +++ b/gdb/python/py-symbol.c
> @@ -560,7 +560,7 @@ gdbpy_initialize_symbols (void)
>  
>  \f
>  
> -static PyGetSetDef symbol_object_getset[] = {
> +static gdb_PyGetSetDef symbol_object_getset[] = {
>    { "type", sympy_get_type, NULL,
>      "Type of the symbol.", NULL },
>    { "symtab", sympy_get_symtab, NULL,
> diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
> index 09cab22..53b160e 100644
> --- a/gdb/python/py-symtab.c
> +++ b/gdb/python/py-symtab.c
> @@ -544,7 +544,7 @@ gdbpy_initialize_symtabs (void)
>  
>  \f
>  
> -static PyGetSetDef symtab_object_getset[] = {
> +static gdb_PyGetSetDef symtab_object_getset[] = {
>    { "filename", stpy_get_filename, NULL,
>      "The symbol table's source filename.", NULL },
>    { "objfile", stpy_get_objfile, NULL, "The symtab's objfile.",
> @@ -606,7 +606,7 @@ PyTypeObject symtab_object_type = {
>    symtab_object_getset		  /*tp_getset */
>  };
>  
> -static PyGetSetDef sal_object_getset[] = {
> +static gdb_PyGetSetDef sal_object_getset[] = {
>    { "symtab", salpy_get_symtab, NULL, "Symtab object.", NULL },
>    { "pc", salpy_get_pc, NULL, "Return the symtab_and_line's pc.", NULL },
>    { "last", salpy_get_last, NULL,
> diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
> index f071006..12b6310 100644
> --- a/gdb/python/py-type.c
> +++ b/gdb/python/py-type.c
> @@ -1413,7 +1413,7 @@ gdbpy_initialize_types (void)
>  
>  \f
>  
> -static PyGetSetDef type_object_getset[] =
> +static gdb_PyGetSetDef type_object_getset[] =
>  {
>    { "code", typy_get_code, NULL,
>      "The code for this type.", NULL },
> @@ -1587,7 +1587,7 @@ PyTypeObject type_object_type =
>    0,				  /* tp_new */
>  };
>  
> -static PyGetSetDef field_object_getset[] =
> +static gdb_PyGetSetDef field_object_getset[] =
>  {
>    { "__dict__", gdb_py_generic_dict, NULL,
>      "The __dict__ for this field.", &field_object_type },
> diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
> index bb42e8b..9c0470f 100644
> --- a/gdb/python/py-value.c
> +++ b/gdb/python/py-value.c
> @@ -1767,7 +1767,7 @@ gdbpy_initialize_values (void)
>  
>  \f
>  
> -static PyGetSetDef value_object_getset[] = {
> +static gdb_PyGetSetDef value_object_getset[] = {
>    { "address", valpy_get_address, NULL, "The address of the value.",
>      NULL },
>    { "is_optimized_out", valpy_get_is_optimized_out, NULL,
> diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
> index 55efd75..d4ed170 100644
> --- a/gdb/python/python-internal.h
> +++ b/gdb/python/python-internal.h
> @@ -286,6 +286,36 @@ gdb_PySys_SetPath (const GDB_PYSYS_SETPATH_CHAR *path)
>  
>  #define PySys_SetPath gdb_PySys_SetPath
>  
> +/* Wrap PyGetSetDef to allow convenient construction with string
> +   literals.  Unfortunately, PyGetSetDef's 'name' and 'doc' members
> +   are 'char *' instead of 'const char *', meaning that in order to
> +   list-initialize PyGetSetDef arrays with string literals (and
> +   without the wrapping below) would require writing explicit 'char *'
> +   casts.  Instead, we extend PyGetSetDef and add constexpr
> +   constructors that accept const 'name' and 'doc', hiding the ugly
> +   casts here in a single place.  */
> +
> +struct gdb_PyGetSetDef : PyGetSetDef
> +{
> +  constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter set_,
> +			     const char *doc_, void *closure_)
> +    : PyGetSetDef {const_cast<char *> (name_), get_, set_,
> +		   const_cast<char *> (doc_), closure_}
> +  {}
> +
> +  /* Alternative constructor that allows omitting the closure in list
> +     initialization.  */
> +  constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter set_,
> +			     const char *doc_)
> +    : gdb_PyGetSetDef {name_, get_, set_, doc_, NULL}
> +  {}
> +
> +  /* Constructor for the sentinel entries.  */
> +  constexpr gdb_PyGetSetDef (std::nullptr_t)
> +    : gdb_PyGetSetDef { NULL, NULL, NULL, NULL, NULL }
> +  {}
> +};
> +
>  /* In order to be able to parse symtab_and_line_to_sal_object function
>     a real symtab_and_line structure is needed.  */
>  #include "symtab.h"
> -- 
> 2.5.5

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 14/18] -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overload
  2017-04-05 12:58     ` Pedro Alves
@ 2017-04-05 15:49       ` Sergio Durigan Junior
  0 siblings, 0 replies; 39+ messages in thread
From: Sergio Durigan Junior @ 2017-04-05 15:49 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Wednesday, April 05 2017, Pedro Alves wrote:

> On 04/04/2017 07:37 PM, Sergio Durigan Junior wrote:
>> On Tuesday, April 04 2017, Pedro Alves wrote:
>
>>> However, to avoid having all callers add the 'const_cast<char **>'
>>> themselves, this commit define a PyArg_ParseTupleAndKeywords overload
>>> here with a corresponding 'keywords' parameter type that does the cast
>>> in a single place.
>>>
>>> As in the PyGetSetDef patch, I'd be fine with naming this
>>> gdb_PyArg_ParseTupleAndKeywords instead, if people would find having
>>> our own overload confusing.
>> 
>> As much as I like the overloading approach in general, I prefer to see
>> our own overloads marked with the "gdb_", just to make things clearer.
>
> OK, updated patch below.  WDYT?

LGTM.  Thanks!

>> 
>>> BTW, this API issue was discussed years ago in the python-dev list:
>>>
>>>  https://mail.python.org/pipermail/python-dev/2006-February/060689.html
>>>
>>> ... and an overload for C++ was suggested in there somewhere.
>>> Unfortunately, it was never added.
>> 
>> Interesting.  I wonder if there's an actual bug/issue opened on their
>> bugzilla about this.
>> 
>> Hm, after a quick search I didn't find anything.  Maybe it's worth
>> creating one.
>
> I had found that thread via this bug: https://bugs.python.org/issue1772673

Oh, I see.  I was searching for the function name only.  Thanks.

> From 2ea02b3a4f5e7e0a1ecfb206d8a5f04b37876bd2 Mon Sep 17 00:00:00 2001
> From: Pedro Alves <palves@redhat.com>
> Date: Wed, 5 Apr 2017 13:45:55 +0100
> Subject: [PATCH] -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const
>  char *" overload
>
> -Wwrite-strings flags code like:
>
>    static char *keywords[] = {"command", "from_tty", "to_string", NULL };
>
> as needing "(char *)" casts, because string literals are "const char []".
>
> We can get rid of the casts by changing the array type like this:
>
>  -  static char *keywords[] = {"command", "from_tty", "to_string", NULL };
>  +  static const char *keywords[] = {"command", "from_tty", "to_string", NULL };
>
> However, passing the such array to PyArg_ParseTupleAndKeywords no longer
> works OOTB, because PyArg_ParseTupleAndKeywords expects a "char **":
>
>   PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw,
>                               const char *format,
> 			      char *keywords[], ...);
>
> and "const char **" is not implicitly convertible to "char **".  C++
> is more tolerant that C here WRT aliasing, and a const_cast<char **>
> is fine.  However, to avoid having all callers do the cast themselves,
> this commit defines a gdb_PyArg_ParseTupleAndKeywords function here
> with a corresponding 'keywords' parameter type that does the cast in a
> single place.
>
> gdb/ChangeLog:
> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
>
> 	* python/python-internal.h (gdb_PyArg_ParseTupleAndKeywords): New
> 	static inline function.
> 	* python/py-arch.c (archpy_disassemble): Constify 'keywords'
> 	array and use gdb_PyArg_ParseTupleAndKeywords.
> 	* python/py-cmd.c (cmdpy_init): Likewise.
> 	* python/py-finishbreakpoint.c (bpfinishpy_init): Likewise.
> 	* python/py-inferior.c (infpy_read_memory, infpy_write_memory)
> 	(infpy_search_memory): Likewise.
> 	* python/py-objfile.c (objfpy_add_separate_debug_file)
> 	(gdbpy_lookup_objfile): Likewise.
> 	* python/py-symbol.c (gdbpy_lookup_symbol)
> 	(gdbpy_lookup_global_symbol): Likewise.
> 	* python/py-type.c (gdbpy_lookup_type): Likewise.
> 	* python/py-value.c (valpy_lazy_string, valpy_string): Likewise.
> 	* python/python.c (execute_gdb_command, gdbpy_write, gdbpy_flush):
> 	Likewise.
> ---
>  gdb/python/py-arch.c             |  7 ++++---
>  gdb/python/py-breakpoint.c       | 10 +++++-----
>  gdb/python/py-cmd.c              | 10 +++++-----
>  gdb/python/py-finishbreakpoint.c |  6 +++---
>  gdb/python/py-inferior.c         | 21 ++++++++++-----------
>  gdb/python/py-objfile.c          | 10 +++++-----
>  gdb/python/py-symbol.c           | 13 +++++++------
>  gdb/python/py-type.c             |  6 +++---
>  gdb/python/py-value.c            | 12 ++++++------
>  gdb/python/python-internal.h     | 28 ++++++++++++++++++++++++++++
>  gdb/python/python.c              | 20 ++++++++++----------
>  11 files changed, 86 insertions(+), 57 deletions(-)
>
> diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
> index 71d2989..cfadb47 100644
> --- a/gdb/python/py-arch.c
> +++ b/gdb/python/py-arch.c
> @@ -116,7 +116,7 @@ archpy_name (PyObject *self, PyObject *args)
>  static PyObject *
>  archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
>  {
> -  static char *keywords[] = { "start_pc", "end_pc", "count", NULL };
> +  static const char *keywords[] = { "start_pc", "end_pc", "count", NULL };
>    CORE_ADDR start, end = 0;
>    CORE_ADDR pc;
>    gdb_py_ulongest start_temp;
> @@ -126,8 +126,9 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
>  
>    ARCHPY_REQUIRE_VALID (self, gdbarch);
>  
> -  if (!PyArg_ParseTupleAndKeywords (args, kw, GDB_PY_LLU_ARG "|OO", keywords,
> -                                    &start_temp, &end_obj, &count_obj))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, GDB_PY_LLU_ARG "|OO",
> +					keywords, &start_temp, &end_obj,
> +					&count_obj))
>      return NULL;
>  
>    start = start_temp;
> diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
> index 34f46fb..a08501e 100644
> --- a/gdb/python/py-breakpoint.c
> +++ b/gdb/python/py-breakpoint.c
> @@ -637,8 +637,8 @@ bppy_get_ignore_count (PyObject *self, void *closure)
>  static int
>  bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
>  {
> -  static char *keywords[] = { "spec", "type", "wp_class", "internal",
> -			      "temporary", NULL };
> +  static const char *keywords[] = { "spec", "type", "wp_class", "internal",
> +				    "temporary", NULL };
>    const char *spec;
>    int type = bp_breakpoint;
>    int access_type = hw_write;
> @@ -647,9 +647,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
>    int internal_bp = 0;
>    int temporary_bp = 0;
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
> -				     &spec, &type, &access_type,
> -				     &internal, &temporary))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
> +					&spec, &type, &access_type,
> +					&internal, &temporary))
>      return -1;
>  
>    if (internal)
> diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
> index 3aaf7f9..3e60673 100644
> --- a/gdb/python/py-cmd.c
> +++ b/gdb/python/py-cmd.c
> @@ -490,8 +490,8 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
>    char *docstring = NULL;
>    struct cmd_list_element **cmd_list;
>    char *cmd_name, *pfx_name;
> -  static char *keywords[] = { "name", "command_class", "completer_class",
> -			      "prefix", NULL };
> +  static const char *keywords[] = { "name", "command_class", "completer_class",
> +				    "prefix", NULL };
>    PyObject *is_prefix = NULL;
>    int cmp;
>  
> @@ -504,9 +504,9 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
>        return -1;
>      }
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kw, "si|iO",
> -				     keywords, &name, &cmdtype,
> -			  &completetype, &is_prefix))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "si|iO",
> +					keywords, &name, &cmdtype,
> +					&completetype, &is_prefix))
>      return -1;
>  
>    if (cmdtype != no_class && cmdtype != class_run
> diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
> index 76189b8..06f6ff9 100644
> --- a/gdb/python/py-finishbreakpoint.c
> +++ b/gdb/python/py-finishbreakpoint.c
> @@ -156,7 +156,7 @@ bpfinishpy_post_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
>  static int
>  bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
>  {
> -  static char *keywords[] = { "frame", "internal", NULL };
> +  static const char *keywords[] = { "frame", "internal", NULL };
>    struct finish_breakpoint_object *self_bpfinish =
>        (struct finish_breakpoint_object *) self;
>    PyObject *frame_obj = NULL;
> @@ -169,8 +169,8 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
>    CORE_ADDR pc;
>    struct symbol *function;
>  
> -  if (!PyArg_ParseTupleAndKeywords (args, kwargs, "|OO", keywords,
> -                                    &frame_obj, &internal))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|OO", keywords,
> +					&frame_obj, &internal))
>      return -1;
>  
>    TRY
> diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
> index 77fc543..41bedb5 100644
> --- a/gdb/python/py-inferior.c
> +++ b/gdb/python/py-inferior.c
> @@ -435,10 +435,10 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
>    CORE_ADDR addr, length;
>    gdb_byte *buffer = NULL;
>    PyObject *addr_obj, *length_obj, *result;
> -  static char *keywords[] = { "address", "length", NULL };
> +  static const char *keywords[] = { "address", "length", NULL };
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords,
> -				     &addr_obj, &length_obj))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords,
> +					&addr_obj, &length_obj))
>      return NULL;
>  
>    if (get_addr_from_python (addr_obj, &addr) < 0
> @@ -494,13 +494,12 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
>    const gdb_byte *buffer;
>    CORE_ADDR addr, length;
>    PyObject *addr_obj, *length_obj = NULL;
> -  static char *keywords[] = { "address", "buffer", "length", NULL };
> +  static const char *keywords[] = { "address", "buffer", "length", NULL };
>  #ifdef IS_PY3K
>    Py_buffer pybuf;
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kw, "Os*|O", keywords,
> -				     &addr_obj, &pybuf,
> -				     &length_obj))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "Os*|O", keywords,
> +					&addr_obj, &pybuf, &length_obj))
>      return NULL;
>  
>    buffer = (const gdb_byte *) pybuf.buf;
> @@ -643,7 +642,7 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
>  {
>    struct gdb_exception except = exception_none;
>    CORE_ADDR start_addr, length;
> -  static char *keywords[] = { "address", "length", "pattern", NULL };
> +  static const char *keywords[] = { "address", "length", "pattern", NULL };
>    PyObject *start_addr_obj, *length_obj;
>    Py_ssize_t pattern_size;
>    const gdb_byte *buffer;
> @@ -652,9 +651,9 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
>  #ifdef IS_PY3K
>    Py_buffer pybuf;
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kw, "OOs*", keywords,
> -				     &start_addr_obj, &length_obj,
> -				     &pybuf))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "OOs*", keywords,
> +					&start_addr_obj, &length_obj,
> +					&pybuf))
>      return NULL;
>  
>    buffer = (const gdb_byte *) pybuf.buf;
> diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
> index 6a47c17..52f2e1f 100644
> --- a/gdb/python/py-objfile.c
> +++ b/gdb/python/py-objfile.c
> @@ -432,13 +432,13 @@ objfpy_is_valid (PyObject *self, PyObject *args)
>  static PyObject *
>  objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
>  {
> -  static char *keywords[] = { "file_name", NULL };
> +  static const char *keywords[] = { "file_name", NULL };
>    objfile_object *obj = (objfile_object *) self;
>    const char *file_name;
>  
>    OBJFPY_REQUIRE_VALID (obj);
>  
> -  if (!PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
>      return NULL;
>  
>    TRY
> @@ -559,14 +559,14 @@ objfpy_lookup_objfile_by_build_id (const char *build_id)
>  PyObject *
>  gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
>  {
> -  static char *keywords[] = { "name", "by_build_id", NULL };
> +  static const char *keywords[] = { "name", "by_build_id", NULL };
>    const char *name;
>    PyObject *by_build_id_obj = NULL;
>    int by_build_id;
>    struct objfile *objfile;
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords,
> -				     &name, &PyBool_Type, &by_build_id_obj))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!", keywords,
> +					&name, &PyBool_Type, &by_build_id_obj))
>      return NULL;
>  
>    by_build_id = 0;
> diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
> index 05b002f..c9f83a3 100644
> --- a/gdb/python/py-symbol.c
> +++ b/gdb/python/py-symbol.c
> @@ -373,13 +373,14 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
>    int domain = VAR_DOMAIN;
>    struct field_of_this_result is_a_field_of_this;
>    const char *name;
> -  static char *keywords[] = { "name", "block", "domain", NULL };
> +  static const char *keywords[] = { "name", "block", "domain", NULL };
>    struct symbol *symbol = NULL;
>    PyObject *block_obj = NULL, *sym_obj, *bool_obj;
>    const struct block *block = NULL;
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
> -				     &block_object_type, &block_obj, &domain))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
> +					&block_object_type, &block_obj,
> +					&domain))
>      return NULL;
>  
>    if (block_obj)
> @@ -443,12 +444,12 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
>  {
>    int domain = VAR_DOMAIN;
>    const char *name;
> -  static char *keywords[] = { "name", "domain", NULL };
> +  static const char *keywords[] = { "name", "domain", NULL };
>    struct symbol *symbol = NULL;
>    PyObject *sym_obj;
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name,
> -				     &domain))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name,
> +					&domain))
>      return NULL;
>  
>    TRY
> diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
> index 12b6310..aa20d4c 100644
> --- a/gdb/python/py-type.c
> +++ b/gdb/python/py-type.c
> @@ -1347,14 +1347,14 @@ type_object_to_type (PyObject *obj)
>  PyObject *
>  gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
>  {
> -  static char *keywords[] = { "name", "block", NULL };
> +  static const char *keywords[] = { "name", "block", NULL };
>    const char *type_name = NULL;
>    struct type *type = NULL;
>    PyObject *block_obj = NULL;
>    const struct block *block = NULL;
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
> -				     &type_name, &block_obj))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
> +					&type_name, &block_obj))
>      return NULL;
>  
>    if (block_obj)
> diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
> index 9c0470f..b5a0ef8 100644
> --- a/gdb/python/py-value.c
> +++ b/gdb/python/py-value.c
> @@ -431,11 +431,11 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
>    gdb_py_longest length = -1;
>    struct value *value = ((value_object *) self)->value;
>    const char *user_encoding = NULL;
> -  static char *keywords[] = { "encoding", "length", NULL };
> +  static const char *keywords[] = { "encoding", "length", NULL };
>    PyObject *str_obj = NULL;
>  
> -  if (!PyArg_ParseTupleAndKeywords (args, kw, "|s" GDB_PY_LL_ARG, keywords,
> -				    &user_encoding, &length))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "|s" GDB_PY_LL_ARG,
> +					keywords, &user_encoding, &length))
>      return NULL;
>  
>    if (length < -1)
> @@ -526,10 +526,10 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw)
>    const char *user_encoding = NULL;
>    const char *la_encoding = NULL;
>    struct type *char_type;
> -  static char *keywords[] = { "encoding", "errors", "length", NULL };
> +  static const char *keywords[] = { "encoding", "errors", "length", NULL };
>  
> -  if (!PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
> -				    &user_encoding, &errors, &length))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
> +					&user_encoding, &errors, &length))
>      return NULL;
>  
>    TRY
> diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
> index d4ed170..db75002 100644
> --- a/gdb/python/python-internal.h
> +++ b/gdb/python/python-internal.h
> @@ -316,6 +316,34 @@ struct gdb_PyGetSetDef : PyGetSetDef
>    {}
>  };
>  
> +/* The 'keywords' parameter of PyArg_ParseTupleAndKeywords has type
> +   'char **'.  However, string literals are const in C++, and so to
> +   avoid casting at every keyword array definition, we'll need to make
> +   the keywords array an array of 'const char *'.  To avoid having all
> +   callers add a 'const_cast<char **>' themselves when passing such an
> +   array through 'char **', we define our own version of
> +   PyArg_ParseTupleAndKeywords here with a corresponding 'keywords'
> +   parameter type that does the cast in a single place.  (This is not
> +   an overload of PyArg_ParseTupleAndKeywords in order to make it
> +   clearer that we're calling our own function instead of a function
> +   that exists in some newer Python version.)  */
> +
> +static inline int
> +gdb_PyArg_ParseTupleAndKeywords (PyObject *args, PyObject *kw,
> +				 const char *format, const char **keywords, ...)
> +{
> +  va_list ap;
> +  int res;
> +
> +  va_start (ap, keywords);
> +  res = PyArg_VaParseTupleAndKeywords (args, kw, format,
> +				       const_cast<char **> (keywords),
> +				       ap);
> +  va_end (ap);
> +
> +  return res;
> +}
> +
>  /* In order to be able to parse symtab_and_line_to_sal_object function
>     a real symtab_and_line structure is needed.  */
>  #include "symtab.h"
> diff --git a/gdb/python/python.c b/gdb/python/python.c
> index a7aff53..25f475f 100644
> --- a/gdb/python/python.c
> +++ b/gdb/python/python.c
> @@ -572,11 +572,11 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
>    const char *arg;
>    PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
>    int from_tty, to_string;
> -  static char *keywords[] = {"command", "from_tty", "to_string", NULL };
> +  static const char *keywords[] = { "command", "from_tty", "to_string", NULL };
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
> -				     &PyBool_Type, &from_tty_obj,
> -				     &PyBool_Type, &to_string_obj))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
> +					&PyBool_Type, &from_tty_obj,
> +					&PyBool_Type, &to_string_obj))
>      return NULL;
>  
>    from_tty = 0;
> @@ -1047,11 +1047,11 @@ static PyObject *
>  gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
>  {
>    const char *arg;
> -  static char *keywords[] = {"text", "stream", NULL };
> +  static const char *keywords[] = { "text", "stream", NULL };
>    int stream_type = 0;
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &arg,
> -				     &stream_type))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &arg,
> +					&stream_type))
>      return NULL;
>  
>    TRY
> @@ -1088,11 +1088,11 @@ gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
>  static PyObject *
>  gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
>  {
> -  static char *keywords[] = {"stream", NULL };
> +  static const char *keywords[] = { "stream", NULL };
>    int stream_type = 0;
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kw, "|i", keywords,
> -				     &stream_type))
> +  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "|i", keywords,
> +					&stream_type))
>      return NULL;
>  
>    switch (stream_type)
> -- 
> 2.5.5

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings)
  2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
                   ` (19 preceding siblings ...)
  2017-04-04 19:37 ` Simon Marchi
@ 2017-04-05 18:05 ` Pedro Alves
  20 siblings, 0 replies; 39+ messages in thread
From: Pedro Alves @ 2017-04-05 18:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Binutils

Since the series has had a few pairs of eyes run over it
already (thanks everyone!), I'm going ahead and push it all in.

I'll push/post two new small patches that were the result of
trying the series on Solaris 11 today.

I'll push those before the final patch that enables the warning
to (try to) avoid breaking buildbots and bisects (... much).

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 18/18] -Wwrite-strings: Remove -Wno-write-strings
  2017-04-04 17:32 ` [PATCH 18/18] -Wwrite-strings: Remove -Wno-write-strings Pedro Alves
@ 2019-02-14 16:17   ` Thomas Schwinge
  0 siblings, 0 replies; 39+ messages in thread
From: Thomas Schwinge @ 2019-02-14 16:17 UTC (permalink / raw)
  To: gdb-patches; +Cc: Pedro Alves

[-- Attachment #1: Type: text/plain, Size: 589 bytes --]

Hi!

On Tue,  4 Apr 2017 18:25:51 +0100, Pedro Alves <palves@redhat.com> wrote:
> AFAIK GDB is now free from -Wwrite-strings warnings.  A few warnings may
> be left behind in some host-specific code

Hey, GNU Hurd was the lucky one!  ;-)

> but those should be few and
> easy to fix.

Right.

> 	* warning.m4 (build_warnings): Remove -Wno-write-strings.

Pushed to master the attached commit
924514e11c21ac5a5805e7a14824b6f3182b2198 '[gdb, hurd] Address "ISO C++
forbids converting a string constant to 'char*' [-Wwrite-strings]"
diagnostics'.


Grüße
 Thomas



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gdb-hurd-Address-ISO-C-forbids-converting-a-string-c.patch --]
[-- Type: text/x-diff, Size: 2416 bytes --]

From 924514e11c21ac5a5805e7a14824b6f3182b2198 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Thu, 14 Feb 2019 10:22:28 +0100
Subject: [PATCH] [gdb, hurd] Address "ISO C++ forbids converting a string
 constant to 'char*' [-Wwrite-strings]" diagnostics

... that appeared with 9bf2a700667c53003ece783c05e8b355801105f2
"-Wwrite-strings: Remove -Wno-write-strings".

	gdb/
	* gnu-nat.c (gnu_write_inferior, parse_int_arg, _parse_bool_arg)
	(check_empty): Use "const char *".
---
 gdb/ChangeLog | 3 +++
 gdb/gnu-nat.c | 9 +++++----
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 71c61bc909..e427dda8a3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,8 @@
 2019-02-14  Thomas Schwinge  <thomas@codesourcery.com>
 
+	* gnu-nat.c (gnu_write_inferior, parse_int_arg, _parse_bool_arg)
+	(check_empty): Use "const char *".
+
 	* gnu-nat.c (gnu_nat_target::detach): Instead of
 	'detach_inferior (pid)' call
 	'detach_inferior (find_inferior_pid (pid))'.
diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index 67cc95c68d..395b456ad7 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -2361,7 +2361,7 @@ gnu_write_inferior (task_t task, CORE_ADDR addr,
   mach_msg_type_number_t copy_count;
   int deallocate = 0;
 
-  char *errstr = "Bug in gnu_write_inferior";
+  const char *errstr = "Bug in gnu_write_inferior";
 
   struct vm_region_list *region_element;
   struct vm_region_list *region_head = NULL;
@@ -2778,7 +2778,7 @@ show_thread_default_cmd (const char *args, int from_tty)
 }
 
 static int
-parse_int_arg (const char *args, char *cmd_prefix)
+parse_int_arg (const char *args, const char *cmd_prefix)
 {
   if (args)
     {
@@ -2793,7 +2793,8 @@ parse_int_arg (const char *args, char *cmd_prefix)
 }
 
 static int
-_parse_bool_arg (const char *args, char *t_val, char *f_val, char *cmd_prefix)
+_parse_bool_arg (const char *args, const char *t_val, const char *f_val,
+		 const char *cmd_prefix)
 {
   if (!args || strcmp (args, t_val) == 0)
     return 1;
@@ -2809,7 +2810,7 @@ _parse_bool_arg (const char *args, char *t_val, char *f_val, char *cmd_prefix)
   _parse_bool_arg (args, "on", "off", cmd_prefix)
 
 static void
-check_empty (const char *args, char *cmd_prefix)
+check_empty (const char *args, const char *cmd_prefix)
 {
   if (args)
     error (_("Garbage after \"%s\" command: `%s'"), cmd_prefix, args);
-- 
2.19.2


^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2019-02-14 16:17 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
2017-04-04 17:26 ` [PATCH 08/18] -Wwrite-strings: Constify mi_cmd_argv_ftype's 'command' parameter Pedro Alves
2017-04-04 17:26 ` [PATCH 01/18] -Wwrite-strings: Constify struct disassemble_info's disassembler_options field Pedro Alves
2017-04-05  7:22   ` Nick Clifton
2017-04-04 17:26 ` [PATCH 14/18] -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overload Pedro Alves
2017-04-04 18:37   ` Sergio Durigan Junior
2017-04-05 12:58     ` Pedro Alves
2017-04-05 15:49       ` Sergio Durigan Junior
2017-04-04 17:26 ` [PATCH 02/18] -Wwrite-strings: Constify macroexp.c:init_shared_buffer Pedro Alves
2017-04-04 17:26 ` [PATCH 05/18] -Wwrite-strings: Constify warning_pre_print Pedro Alves
2017-04-04 17:26 ` [PATCH 04/18] -Wwrite-strings: Constify shell_escape and plug make_command leak Pedro Alves
2017-04-04 17:26 ` [PATCH 03/18] -Wwrite-strings: Don't initialize string command variables to empty string Pedro Alves
2017-04-04 17:26 ` [PATCH 06/18] -Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info Pedro Alves
2017-04-04 18:44   ` John Baldwin
2017-04-04 17:26 ` [PATCH 09/18] -Wwrite-strings: MI -info-os Pedro Alves
2017-04-04 17:26 ` [PATCH 07/18] -Wwrite-strings: Constify work break character arrays Pedro Alves
2017-04-05  8:46   ` Philipp Rudo
2017-04-05 13:17     ` Pedro Alves
2017-04-04 17:26 ` [PATCH 15/18] -Wwrite-strings: execute_command calls with string literals Pedro Alves
2017-04-05  7:13   ` Metzger, Markus T
2017-04-05 13:10     ` Pedro Alves
2017-04-04 17:26 ` [PATCH 16/18] -Wwrite-strings: Some constification in gdb/breakpoint.c Pedro Alves
2017-04-04 17:31 ` [PATCH 10/18] -Wwrite-strings: gdbserver's 'port' parsing Pedro Alves
2017-04-04 17:32 ` [PATCH 18/18] -Wwrite-strings: Remove -Wno-write-strings Pedro Alves
2019-02-14 16:17   ` Thomas Schwinge
2017-04-04 17:32 ` [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals Pedro Alves
2017-04-04 18:40   ` Sergio Durigan Junior
2017-04-05 12:35     ` Pedro Alves
2017-04-05 15:48       ` Sergio Durigan Junior
2017-04-05  8:49   ` Philipp Rudo
2017-04-05 13:03     ` Pedro Alves
2017-04-04 17:32 ` [PATCH 11/18] -Wwrite-strings: gdbserver/win32-low.c and TARGET_WAITKIND_EXECD Pedro Alves
2017-04-04 17:33 ` [PATCH 12/18] -Wwrite-strings: More fix-old-Python-API wrappers Pedro Alves
2017-04-04 17:36 ` [PATCH 17/18] -Wwrite-strings: The Rest Pedro Alves
2017-04-04 18:44   ` John Baldwin
2017-04-05 12:59     ` Pedro Alves
2017-04-04 18:42 ` [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Sergio Durigan Junior
2017-04-04 19:37 ` Simon Marchi
2017-04-05 18:05 ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).