platform/upstream/binutils.git
7 years ago * config.sub: Sync with master version in config project.
Andrew Jenner [Thu, 13 Apr 2017 09:34:19 +0000 (02:34 -0700)]
* config.sub: Sync with master version in config project.

7 years agoAdd ChangeLog entries
Iain Buclaw [Thu, 13 Apr 2017 08:39:13 +0000 (10:39 +0200)]
Add ChangeLog entries

ChangeLog entries were left unstaged in my previous commit on March 30th.

7 years agoWrap long lines
Alan Modra [Thu, 13 Apr 2017 03:54:18 +0000 (13:24 +0930)]
Wrap long lines

Not a comprehensive change, just some split out from fixes made for
the %A and %B changes.

* coffcode.h: Wrap some overly long _bfd_error_handler args.
* elf.c: Likewise.
* elf32-arm.c: Likewise.
* elf32-i386.c: Likewise.
* elf32-mep.c: Likewise.
* elf64-ia64-vms.c: Likewise.
* elf64-x86-64.c: Likewise.
* elflink.c: Likewise.
* elfnn-ia64.c: Likewise.
* elfxx-mips.c: Likewise.

7 years agoUse %A and %B in more error messages
Alan Modra [Thu, 13 Apr 2017 03:50:15 +0000 (13:20 +0930)]
Use %A and %B in more error messages

* aoutx.h: Use %B and %A in error messages throughout file.
* aout-cris.c: Likewise.
* archive.c: Likewise.
* binary.c: Likewise.
* coff-rs6000.c: Likewise.
* coff-tic4x.c: Likewise.
* coffcode.h: Likewise.
* coffgen.c: Likewise.
* cofflink.c: Likewise.
* coffswap.h: Likewise.
* cpu-arm.c: Likewise.
* elf-eh-frame.c: Likewise.
* elf-m10300.c: Likewise.
* elf.c: Likewise.
* elf32-arc.c: Likewise.
* elf32-arm.c: Likewise.
* elf32-bfin.c: Likewise.
* elf32-frv.c: Likewise.
* elf32-iq2000.c: Likewise.
* elf32-m32c.c: Likewise.
* elf32-microblaze.c: Likewise.
* elf32-nds32.c: Likewise.
* elf32-rl78.c: Likewise.
* elf32-rx.c: Likewise.
* elf32-score.c: Likewise.
* elf32-score7.c: Likewise.
* elf32-sh64.c: Likewise.
* elf32-v850.c: Likewise.
* elf32-vax.c: Likewise.
* elf32-visium.c: Likewise.
* elf64-ia64-vms.c: Likewise.
* elf64-mmix.c: Likewise.
* elf64-sh64.c: Likewise.
* elfcode.h: Likewise.
* elfnn-aarch64.c: Likewise.
* elfnn-ia64.c: Likewise.
* elfxx-mips.c: Likewise.
* hpux-core.c: Likewise.
* ieee.c: Likewise.
* ihex.c: Likewise.
* linker.c: Likewise.
* merge.c: Likewise.
* mmo.c: Likewise.
* oasys.c: Likewise.
* pdp11.c: Likewise.
* peXXigen.c: Likewise.
* rs6000-core.c: Likewise.
* vms-alpha.c: Likewise.
* xcofflink.c: Likewise.

7 years agoRewrite bfd error handler
Alan Modra [Thu, 13 Apr 2017 01:28:40 +0000 (10:58 +0930)]
Rewrite bfd error handler

This steals _doprnt from libiberty, extended to handle %A and %B.
Which lets us do away with the current horrible %A and %B handling
that requires all %A and %B arguments to be passed first, rather than
in the natural order.

* bfd.c (PRINT_TYPE): Define.
(_doprnt): New function.
(error_handler_internal): Use _doprnt.
* coff-arm.c: Put %A and %B arguments to _bfd_error_handler
calls in their natural order, throughout file.
* coff-mcore.c: Likewise.
* coff-ppc.c: Likewise.
* coff-tic80.c: Likewise.
* cofflink.c: Likewise.
* elf-s390-common.c: Likewise.
* elf.c: Likewise.
* elf32-arm.c: Likewise.
* elf32-i386.c: Likewise.
* elf32-m32r.c: Likewise.
* elf32-msp430.c: Likewise.
* elf32-spu.c: Likewise.
* elf64-ia64-vms.c: Likewise.
* elf64-sparc.c: Likewise.
* elf64-x86-64.c: Likewise.
* elflink.c: Likewise.
* elfnn-aarch64.c: Likewise.
* elfnn-ia64.c: Likewise.
* elfxx-mips.c: Likewise.

7 years agoMissing _bfd_error_handler args
Alan Modra [Thu, 13 Apr 2017 01:14:20 +0000 (10:44 +0930)]
Missing _bfd_error_handler args

* elf32-arm.c (arm_type_of_stub): Supply missing args to "long
branch veneers" error.  Fix double space and format message.
* elf32-avr.c (avr_add_stub): Do not pass NULL as %B arg.
* elf64-ppc.c (tocsave_find): Supply missing %B arg.

7 years agoRegen bfd-in2.h
Alan Modra [Thu, 13 Apr 2017 01:03:11 +0000 (10:33 +0930)]
Regen bfd-in2.h

* bfd-in2.h: Regenerate.

7 years agoFix a typo in rx_fpsw_type
Yao Qi [Thu, 13 Apr 2017 07:29:44 +0000 (08:29 +0100)]
Fix a typo in rx_fpsw_type

gdb:

2017-04-13  Yao Qi  <yao.qi@linaro.org>

* rx-tdep.c (rx_fpsw_type): Check tdep->rx_fpsw_type instead of
tdep->rx_psw_type.

7 years agoXCNEW gdbarch_tdep in rl78 and rx
Yao Qi [Thu, 13 Apr 2017 07:29:43 +0000 (08:29 +0100)]
XCNEW gdbarch_tdep in rl78 and rx

"struct gdbarch_tdep" is XNEW'ed in rl78 and rx, so the memory is not
cleared.  As the result, tdep->rl78_psw_type is never initialized
properly.

  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  if (tdep->rl78_psw_type == NULL)
    {
      tdep->rl78_psw_type = arch_flags_type (gdbarch,
     "builtin_type_rl78_psw", 1);

The bug is found by my unit test in the following patch.

gdb:

2017-04-13  Yao Qi  <yao.qi@linaro.org>

* rl78-tdep.c (rl78_gdbarch_init): Use XCNEW instead of XNEW.
* rx-tdep.c (rx_gdbarch_init): Likewise.

7 years agostruct breakpoint: Fix indentation
Pedro Alves [Thu, 13 Apr 2017 02:07:21 +0000 (03:07 +0100)]
struct breakpoint: Fix indentation

I'm going to need to touch all these fields to add in-class
initialization anyway, might as well take the opportunity to finally
fix this...

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

* breakpoint.h (struct breakpoint): Reindent.

7 years agobreakpoint.c: bp_location (the array) shadows bp_location (the type)
Pedro Alves [Thu, 13 Apr 2017 01:12:53 +0000 (02:12 +0100)]
breakpoint.c: bp_location (the array) shadows bp_location (the type)

The bp_location array has the same name as the "struct bp_location",
type preventing refering to the structure without the "struct" inside
breakpoint.c.  I.e., we must write:

 "new struct bp_location;"

instead of:

 "new bp_location"

Rename the array and the associated variables/functions to avoid the
shadowing.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

* breakpoint.c (bp_location): Rename to ...
(bp_locations): ... this.  All references updated.
(bp_location_count): Rename to ...
(bp_locations_count): ... this.  All references updated.
(bp_location_placed_address_before_address_max): Rename to ...
(bp_locations_placed_address_before_address_max): ... this.  All
references updated.
(bp_location_shadow_len_after_address_max): Rename to ...
(bp_locations_shadow_len_after_address_max): ... this.  All
references updated.
(bp_location_compare_addrs): Rename to ...
(bp_locations_compare_addrs): ... this.  All references updated.
(bp_location_compare):Rename to ...
(bp_locations_compare): ... this.  All references updated.
(bp_location_target_extensions_update): Rename to ...
(bp_locations_target_extensions_update): ... this.  All references
updated.

7 years agoAutomatic date update in version.in
GDB Administrator [Thu, 13 Apr 2017 00:00:38 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoCreate gdb_termios.h (and cleanup gdb/{,gdbserver/}terminal.h)
Sergio Durigan Junior [Wed, 12 Apr 2017 01:05:12 +0000 (21:05 -0400)]
Create gdb_termios.h (and cleanup gdb/{,gdbserver/}terminal.h)

As requested, I'm sending this as a separate patch because it is ready
to be included as-is.

The idea here is that both gdb/terminal.h and gdb/gdbserver/terminal.h
share the same code, which is responsible for setting a bunch of
defines on based on the presence of termios.h and a few other headers.
This simple patch just moves this common code to common/gdb_termios.h
and makes the necessary adjustments on both GDB and gdbserver so that
they can use this new header.  It also implements the some header
checks on common/common.m4.

As a bonus, gdb/gdbserver/terminal.h can be removed because it's now
empty.

Built on x86_64, no regressions found.

gdb/ChangeLog:
2017-04-12  Sergio Durigan Junior  <sergiodj@redhat.com>

* Makefile.in (HFILES_NO_SRCDIR): Add "common/gdb_termios.h".
* common/common.m4: Check headers 'termios.h', 'termio.h' and
'sgtty.h'.
* common/gdb_termios.h: New file, with parts of "terminal.h".
* inflow.c: Include "gdb_termios.h".
* ser-unix.c: Include "gdb_termios.h".
* terminal.h: Move terminal-related defines to
"common/gdb_termios.h".

gdb/gdbserver/ChangeLog:
2017-04-12  Sergio Durigan Junior  <sergiodj@redhat.com>

* remote-utils.c: Include "gdb_termios.h" instead of
"terminal.h".
* terminal.h: Delete file.

7 years agoChange linespec_result::location to be an event_location_up
Tom Tromey [Mon, 10 Apr 2017 21:53:22 +0000 (15:53 -0600)]
Change linespec_result::location to be an event_location_up

This is a follow-up to another patch.  It changes
linespec_result::location to be an event_location_up.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* probe.c (parse_probes): Update.
* location.h (delete_event_location): Don't declare.
(event_location_deleter::operator()): Update.
* location.c (event_location_deleter::operator()): Rename from
delete_event_location.
* linespec.h (linespec_result) <location>: Change type to
event_location_up.
* linespec.c (canonicalize_linespec, event_location_to_sals)
(decode_objc): Update.
(linespec_result): Don't call delete_event_location.
* breakpoint.c (create_breakpoints_sal)
(bkpt_probe_create_sals_from_location)
(strace_marker_create_sals_from_location): Update.

7 years agoAdd a constructor and destructor to linespec_result
Tom Tromey [Mon, 10 Apr 2017 21:47:21 +0000 (15:47 -0600)]
Add a constructor and destructor to linespec_result

linespec_result is only ever allocated on the stack, so it's
relatively easy to convert to having a constructor and a destructor.
This patch makes this change.  This removes some cleanups.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* linespec.h (struct linespec_result): Add constructor and
destructor.
(init_linespec_result, destroy_linespec_result)
(make_cleanup_destroy_linespec_result): Don't declare.
* linespec.c (init_linespec_result): Remove.
(linespec_result::~linespec_result): Rename from
destroy_linespec_result.  Update.
(cleanup_linespec_result, make_cleanup_destroy_linespec_result):
Remove.
* breakpoint.c (create_breakpoint, break_range_command)
(decode_location_default): Update.
* ax-gdb.c (agent_command_1): Update.

7 years agoChange breakpoint event locations to event_location_up
Tom Tromey [Mon, 10 Apr 2017 21:41:25 +0000 (15:41 -0600)]
Change breakpoint event locations to event_location_up

This is a follow-up to an earlier patch.  It changes breakpoint's
location and location_range_end members to be of type
event_location_up, then fixes up the users.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* remote.c (remote_download_tracepoint): Update.
* python/py-breakpoint.c (bppy_get_location): Update.
* guile/scm-breakpoint.c (bpscm_print_breakpoint_smob)
(gdbscm_breakpoint_location): Update.
* elfread.c (elf_gnu_ifunc_resolver_return_stop): Update.
* breakpoint.h (struct breakpoint) <location, location_range_end>:
Change type to event_location_up.
* breakpoint.c (create_overlay_event_breakpoint)
(create_longjmp_master_breakpoint)
(create_std_terminate_master_breakpoint)
(create_exception_master_breakpoint)
(breakpoint_event_location_empty_p, print_breakpoint_location)
(print_one_breakpoint_location, create_thread_event_breakpoint)
(init_breakpoint_sal, create_breakpoint)
(print_recreate_ranged_breakpoint, break_range_command)
(init_ada_exception_breakpoint, say_where): Update.
(base_breakpoint_dtor): Don't call delete_event_location.
(bkpt_print_recreate, tracepoint_print_recreate)
(dprintf_print_recreate, update_static_tracepoint)
(breakpoint_re_set_default): Update.

7 years agoUse std::vector in compile-loc2c.c
Tom Tromey [Fri, 7 Apr 2017 22:05:42 +0000 (16:05 -0600)]
Use std::vector in compile-loc2c.c

This changes compile-loc2c.c to use std::vector in place of a VEC,
allowing the removal of a cleanup.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* compile/compile-loc2c.c (compute_stack_depth_worker): Change
type of "to_do".  Update.
(compute_stack_depth): Use std::vector.

7 years agoUse std::vector in find_instruction_backward
Tom Tromey [Fri, 7 Apr 2017 22:01:10 +0000 (16:01 -0600)]
Use std::vector in find_instruction_backward

This changes find_instruction_backward to use std::vector, removing a
cleanup.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* printcmd.c (find_instruction_backward): Use std::vector.

7 years agoUse std::vector in reread_symbols
Tom Tromey [Fri, 7 Apr 2017 21:58:25 +0000 (15:58 -0600)]
Use std::vector in reread_symbols

This changes reread_symbols to use std::vector, removing a cleanup.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* symfile.c (objfilep): Remove typedef.
(reread_symbols): Use a std::vector.

7 years agoUse scoped_restore in more places
Tom Tromey [Fri, 7 Apr 2017 21:37:25 +0000 (15:37 -0600)]
Use scoped_restore in more places

This changes a few more places to use scoped_restore, allowing some
cleanup removals.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* mi/mi-main.c (exec_direction_forward): Remove.
(exec_reverse_continue, mi_execute_command): Use scoped_restore.
* guile/scm-ports.c (ioscm_with_output_to_port_worker): Use
scoped_restore.
* guile/guile.c (guile_repl_command, guile_command)
(gdbscm_execute_gdb_command): Use scoped_restore.
* go-exp.y (go_parse): Use scoped_restore.
* d-exp.y (d_parse): Use scoped_restore.
* cli/cli-decode.c (cmd_func): Use scoped_restore.
* c-exp.y (c_parse): Use scoped_restore.

7 years agoC++ify mi_parse
Tom Tromey [Fri, 7 Apr 2017 21:34:02 +0000 (15:34 -0600)]
C++ify mi_parse

This changes mi_parse to return a unique_ptr, and to use "new"; then
fixes up the users.  This allows removing one cleanup.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* mi/mi-parse.h (struct mi_parse): Add constructor, destructor.
(mi_parse): Update return type.
(mi_parse_free): Remove.
* mi/mi-parse.c (mi_parse::mi_parse): New constructor.
(mi_parse::~mi_parse): Rename from mi_parse_free.
(mi_parse_cleanup): Remove.
(mi_parse): Return a unique_ptr.  Use new.
* mi/mi-main.c (mi_execute_command): Update.

7 years agoRemove some cleanups from location.c
Tom Tromey [Fri, 7 Apr 2017 05:26:14 +0000 (23:26 -0600)]
Remove some cleanups from location.c

This removes some more cleanups from location.c by using
unique_xmalloc_ptr.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* location.c (explicit_location_lex_one): Return a
unique_xmalloc_ptr.
(string_to_explicit_location): Update.  Remove cleanups.

7 years agoRemove some cleanups from gnu-v3-abi.c
Tom Tromey [Fri, 7 Apr 2017 04:48:27 +0000 (22:48 -0600)]
Remove some cleanups from gnu-v3-abi.c

This removes some cleanups from gnu-v3-abi.c, by using std::vector
rather than VEC.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* gnu-v3-abi.c (value_and_voffset_p): Remove typedef.
(compare_value_and_voffset): Change type.  Update.
(compute_vtable_size): Change type of "offset_vec".
(gnuv3_print_vtable): Use std::vector.  Remove cleanups.
(gnuv3_get_typeid): Remove extraneous declaration.

7 years agoFix up wchar_iterator comment
Tom Tromey [Fri, 7 Apr 2017 03:07:00 +0000 (21:07 -0600)]
Fix up wchar_iterator comment

This fixes up a comment in charset.h that has been obsolete for a
while.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* charset.h (wchar_iterator): Fix comment.

7 years agoRemove cleanup_iconv
Tom Tromey [Fri, 7 Apr 2017 02:50:38 +0000 (20:50 -0600)]
Remove cleanup_iconv

This introduces a new "iconv_wrapper" class, to be used in
convert_between_encodings.  This allows the removal of cleanup_iconv.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* charset.c (iconv_wrapper): New class.
(cleanup_iconv): Remove.
(convert_between_encodings): Use it.

7 years agoChange increment_reading_symtab to return a scoped_restore
Tom Tromey [Fri, 7 Apr 2017 02:27:10 +0000 (20:27 -0600)]
Change increment_reading_symtab to return a scoped_restore

This changes increment_reading_symtab to return a scoped_restore, then
fixes up the users.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* symfile.h (increment_reading_symtab): Update type.
* symfile.c (decrement_reading_symtab): Remove.
(increment_reading_symtab): Return a scoped_restore_tmpl<int>.
* psymtab.c (psymtab_to_symtab): Update.
* dwarf2read.c (dw2_instantiate_symtab): Update.

7 years agoIntroduce gdb_dlhandle_up
Tom Tromey [Fri, 7 Apr 2017 02:09:42 +0000 (20:09 -0600)]
Introduce gdb_dlhandle_up

This introduces gdb_dlhandle_up, a unique_ptr that can close a
dlopen'd library.  All the functions working with dlopen handles are
updated to use this new type.

I did not try to build this on Windows.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* jit.c (struct jit_reader): Declare separately.  Add constructor
and destructor.  Change type of "handle".
(loaded_jit_reader): Define separately.
(jit_reader_load): Update.  New "new".
(jit_reader_unload_command): Use "delete".
* gdb-dlfcn.h (struct dlclose_deleter): New.
(gdb_dlhandle_up): New typedef.
(gdb_dlopen, gdb_dlsym): Update types.
(gdb_dlclose): Remove.
* gdb-dlfcn.c (gdb_dlopen): Return a gdb_dlhandle_up.
(gdb_dlsym): Change type of "handle".
(make_cleanup_dlclose): Remove.
(dlclose_deleter::operator()): Rename from gdb_dlclose.
* compile/compile-c-support.c (load_libcc): Update.

7 years agoChange find_pcs_for_symtab_line to return a std::vector
Tom Tromey [Thu, 6 Apr 2017 22:38:56 +0000 (16:38 -0600)]
Change find_pcs_for_symtab_line to return a std::vector

This changes find_pcs_for_symtab_line to return a std::vector.  This
allows the removal of some cleanups.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* symtab.h (find_pcs_for_symtab_line): Change return type.
* symtab.c (find_pcs_for_symtab_line): Change return type.
* python/py-linetable.c (build_line_table_tuple_from_pcs): Change
type of "vec".  Update.
(ltpy_get_pcs_for_line): Update.
* linespec.c (decode_digits_ordinary): Update.

7 years agoIntroduce command_line_up
Tom Tromey [Thu, 6 Apr 2017 03:14:09 +0000 (21:14 -0600)]
Introduce command_line_up

This introduces command_line_up, a unique_ptr for command_line
objects, and changes many places to use it.  This removes a number of
cleanups.

Command lines are funny in that sometimes they are reference counted.
Once there is more C++-ification of some of the users, perhaps all of
these can be changed to use shared_ptr instead.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* tracepoint.c (actions_command): Update.
* python/python.c (python_command, python_interactive_command):
Update.
* mi/mi-cmd-break.c (mi_cmd_break_commands): Update.
* guile/guile.c (guile_command): Update.
* defs.h (read_command_lines, read_command_lines_1): Return
command_line_up.
(command_lines_deleter): New struct.
(command_line_up): New typedef.
* compile/compile.c (compile_code_command)
(compile_print_command): Update.
* cli/cli-script.h (get_command_line, copy_command_lines): Return
command_line_up.
(make_cleanup_free_command_lines): Remove.
* cli/cli-script.c (get_command_line, read_command_lines_1)
(copy_command_lines): Return command_line_up.
(while_command, if_command, read_command_lines, define_command)
(document_command): Update.
(do_free_command_lines_cleanup, make_cleanup_free_command_lines):
Remove.
* breakpoint.h (breakpoint_set_commands): Change type of
"commands".
* breakpoint.c (breakpoint_set_commands): Change type of
"commands".  Update.
(do_map_commands_command, update_dprintf_command_list)
(create_tracepoint_from_upload): Update.

7 years agoIntroduce event_location_up
Tom Tromey [Thu, 6 Apr 2017 02:44:01 +0000 (20:44 -0600)]
Introduce event_location_up

This removes make_cleanup_delete_event_location and instead changes
the various location functions to return an event_location_up, a new
unique_ptr typedef.

This is largely straightforward, but be sure to examine the
init_breakpoint_sal change.  I believe the code I deleted there is
dead, because "location != NULL" can never be true in that branch; but
you should double-check.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

* tracepoint.c (scope_info): Update.
* spu-tdep.c (spu_catch_start): Update.
* python/python.c (gdbpy_decode_line): Update.
* python/py-finishbreakpoint.c (bpfinishpy_init): Update.
* python/py-breakpoint.c (bppy_init): Update.
* probe.c (parse_probes): Update.
* mi/mi-cmd-break.c (mi_cmd_break_insert_1): Update.
* location.h (event_location_deleter): New struct.
(event_location_up): New typedef.
(new_linespec_location, new_address_location, new_probe_location)
(new_explicit_location, copy_event_location)
(string_to_event_location, string_to_event_location_basic)
(string_to_explicit_location): Update return type.
(make_cleanup_delete_event_location): Remove.
* location.c (new_linespec_location, new_address_location)
(new_probe_location, new_explicit_location, copy_event_location):
Return event_location_up.
(delete_event_location_cleanup)
(make_cleanup_delete_event_location): Remove.
(string_to_explicit_location, string_to_event_location_basic)
(string_to_event_location): Return event_location_up.
* linespec.c (canonicalize_linespec, event_location_to_sals)
(decode_line_with_current_source)
(decode_line_with_last_displayed, decode_objc): Update.
* guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Update.
* completer.c (location_completer): Update.
* cli/cli-cmds.c (edit_command, list_command): Update.
* breakpoint.c (create_overlay_event_breakpoint)
(create_longjmp_master_breakpoint)
(create_std_terminate_master_breakpoint)
(create_exception_master_breakpoint)
(create_thread_event_breakpoint): Update.
(init_breakpoint_sal): Update.  Remove some dead code.
(create_breakpoint_sal): Change type of "location".  Update.
(create_breakpoints_sal, create_breakpoint, break_command_1)
(dprintf_command, break_range_command, until_break_command)
(init_ada_exception_breakpoint)
(strace_marker_create_sals_from_location)
(update_static_tracepoint, trace_command, ftrace_command)
(strace_command, create_tracepoint_from_upload): Update.
* break-catch-throw.c (re_set_exception_catchpoint): Update.
* ax-gdb.c (agent_command_1): Update.

7 years agogdb: Move DJGPP/go32 bits to their own tdep file
Pedro Alves [Wed, 12 Apr 2017 15:00:04 +0000 (16:00 +0100)]
gdb: Move DJGPP/go32 bits to their own tdep file

I posit that this makes them easier to find.

The other day while working on the wchar_t patch, I had a bit of
trouble finding the DJGPP/go32 tdep bits.  My initial reaction was
looking for a go32-specific tdep file, but there's none.

Confirmed that a --host=i586-pc-msdosdjgpp GDB still builds
successfully and includes the  i386-go32-tdep.o object.

Confirmed that an --enable-targets=all build of GDB on x86-64
GNU/Linux includes the DJGPP/go32 bits too.

gdb/ChangeLog:
2017-04-12  Pedro Alves  <palves@redhat.com>

* Makefile.in (ALL_TARGET_OBS): Add i386-go32-tdep.o.
* configure.tgt: Handle i[34567]86-*-go32* and
i[34567]86-*-msdosdjgpp*.
* i386-tdep.c (i386_svr4_reg_to_regnum):
Make extern.
(i386_go32_init_abi, i386_coff_osabi_sniffer): Moved to
i386-go32-tdep.c.
(_initialize_i386_tdep): DJGPP bits moved to i386-go32-tdep.c.
* i386-go32-tdep.c: New file.
* i386-tdep.h (tdesc_i386_mmx, i386_svr4_reg_to_regnum): New
declarations.

7 years agoFix build error in aix-thread.c
Simon Marchi [Wed, 12 Apr 2017 14:46:13 +0000 (10:46 -0400)]
Fix build error in aix-thread.c

Obvious fix for:

aix-thread.c: In function 'char* pd_status2str(int)':
aix-thread.c:163:33: error: deprecated conversion from string constant to 'char*' [-Werror=write-strings]
     case PTHDB_SUCCESS:  return "SUCCESS";
                                 ^
gdb/ChangeLog:

* aix-thread.c (pd_status2str): Change return type to const char *.

7 years agoRemove unnecessary set_gdbarch_gnu_triplet_regexp calls
Pedro Alves [Fri, 31 Mar 2017 12:41:45 +0000 (13:41 +0100)]
Remove unnecessary set_gdbarch_gnu_triplet_regexp calls

i386_gdbarch_init already does this unconditionally for all x86 ports.

Tested on x86-64 Fedora 23.

gdb/ChangeLog:
2017-04-12  Pedro Alves  <palves@redhat.com>

* i386-tdep.c (i386_elf_init_abi, i386_go32_init_abi): Remove
calls to set_gdbarch_gnu_triplet_regexp.

7 years agoTeach GDB that wchar_t is a built-in type in C++ mode
Pedro Alves [Wed, 12 Apr 2017 13:00:49 +0000 (14:00 +0100)]
Teach GDB that wchar_t is a built-in type in C++ mode

GDB is currently not aware that wchar_t is a built-in type in C++
mode.  This is usually not a problem because the debug info describes
the type, so when you have a program loaded, you don't notice this.
However, if you try expressions involving wchar_t before a program is
loaded, gdb errors out:

 (gdb) p (wchar_t)-1
 No symbol table is loaded.  Use the "file" command.
 (gdb) p L"hello"
 No type named wchar_t.
 (gdb) ptype L"hello"
 No type named wchar_t.

This commit teaches gdb about the type.  After:

 (gdb) p (wchar_t)-1
 $1 = -1 L'\xffffffff'
 (gdb) p L"hello"
 $2 = L"hello"
 (gdb) ptype L"hello"
 type = wchar_t [6]

Unlike char16_t/char32_t, unfortunately, the underlying type of
wchar_t is implementation dependent, both size and signness.  So this
requires adding a couple new gdbarch hooks.

I grepped the GCC code base for WCHAR_TYPE and WCHAR_TYPE_SIZE, and it
seems to me that the majority of the ABIs have a 4-byte signed
wchar_t, so that's what I made the default for GDB too.  And then I
looked for which ports have a 16-bit and/or unsigned wchar_t, and made
GDB follow suit.

gdb/ChangeLog:
2017-04-12  Pedro Alves  <palves@redhat.com>

PR gdb/21323
* c-lang.c (cplus_primitive_types) <cplus_primitive_type_wchar_t>:
New enum value.
(cplus_language_arch_info): Register cplus_primitive_type_wchar_t.
* gdbtypes.h (struct builtin_type) <builtin_wchar>: New field.
* gdbtypes.c (gdbtypes_post_init): Create the "wchar_t" type.
* gdbarch.sh (wchar_bit, wchar_signed): New per-arch values.
* gdbarch.h, gdbarch.c: Regenerate.
* aarch64-tdep.c (aarch64_gdbarch_init): Override
gdbarch_wchar_bit and gdbarch_wchar_signed.
* alpha-tdep.c (alpha_gdbarch_init): Likewise.
* arm-tdep.c (arm_gdbarch_init): Likewise.
* avr-tdep.c (avr_gdbarch_init): Likewise.
* h8300-tdep.c (h8300_gdbarch_init): Likewise.
* i386-nto-tdep.c (i386nto_init_abi): Likewise.
* i386-tdep.c (i386_go32_init_abi): Likewise.
* m32r-tdep.c (m32r_gdbarch_init): Likewise.
* moxie-tdep.c (moxie_gdbarch_init): Likewise.
* nds32-tdep.c (nds32_gdbarch_init): Likewise.
* rs6000-aix-tdep.c (rs6000_aix_init_osabi): Likewise.
* sh-tdep.c (sh_gdbarch_init): Likewise.
* sparc-tdep.c (sparc32_gdbarch_init): Likewise.
* sparc64-tdep.c (sparc64_init_abi): Likewise.
* windows-tdep.c (windows_init_abi): Likewise.
* xstormy16-tdep.c (xstormy16_gdbarch_init): Likewise.

gdb/testsuite/ChangeLog:
2017-04-12  Pedro Alves  <palves@redhat.com>

PR gdb/21323
* gdb.cp/wide_char_types.c: Include <wchar.h>.
(wchar): New global.
* gdb.cp/wide_char_types.exp (wide_char_types_program)
(do_test_wide_char, wide_char_types_no_program, top level): Add
wchar_t testing.

7 years agoFix PR c++/21323: GDB thinks char16_t and char32_t are signed in C++
Pedro Alves [Wed, 12 Apr 2017 13:00:49 +0000 (14:00 +0100)]
Fix PR c++/21323: GDB thinks char16_t and char32_t are signed in C++

While the C++ standard says that char16_t and char32_t are unsigned types:

 Types char16_t and char32_t denote distinct types with the same size,
 signedness, and alignment as uint_least16_t and uint_least32_t,
 respectively, in <cstdint>, called the underlying types.

... gdb treats them as signed currently:

 (gdb) p (char16_t)-1
 $1 = -1 u'\xffff'

There are actually two places in gdb that hardcode these types:

- gdbtypes.c:gdbtypes_post_init, when creating the built-in types,
  seemingly used by the "x /s" command (judging from commit 9a22f0d0).

- dwarf2read.c, when reading base types with DW_ATE_UTF encoding
  (which is what is used for these types, when compiling for C++11 and
  up).  Despite the comment, the type created does end up used.

Both places need fixing.  But since I couldn't tell why dwarf2read.c
needs to create a new type, I've made it use the per-arch built-in
types instead, so that the types are only created once per arch
instead of once per objfile.  That seems to work fine.

While writting the test, I noticed that the C++ language parser isn't
actually aware of these built-in types, so if you try to use them
without a program that uses them, you get:

 (gdb) set language c++
 (gdb) ptype char16_t
 No symbol table is loaded.  Use the "file" command.
 (gdb) ptype u"hello"
 No type named char16_t.
 (gdb) p u"hello"
 No type named char16_t.

That's fixed by simply adding a couple entries to C++'s built-in types
array in c-lang.c.  With that, we get the expected:

 (gdb) ptype char16_t
 type = char16_t
 (gdb) ptype u"hello"
 type = char16_t [6]
 (gdb) p u"hello"
 $1 = u"hello"

gdb/ChangeLog:
2017-04-12  Pedro Alves  <palves@redhat.com>

PR c++/21323
* c-lang.c (cplus_primitive_types) <cplus_primitive_type_char16_t,
cplus_primitive_type_char32_t>: New enum values.
(cplus_language_arch_info): Register cplus_primitive_type_char16_t
and cplus_primitive_type_char32_t.
* dwarf2read.c (read_base_type) <DW_ATE_UTF>: If bit size is 16 or
32, use the archtecture's built-in type for char16_t and char32_t,
respectively.  Otherwise, fallback to init_integer_type as before,
but make the type unsigned, and issue a complaint.
* gdbtypes.c (gdbtypes_post_init): Make char16_t and char32_t unsigned.

gdb/testsuite/ChangeLog:
2017-04-12  Pedro Alves  <palves@redhat.com>

PR c++/21323
* gdb.cp/wide_char_types.c: New file.
* gdb.cp/wide_char_types.exp: New file.

7 years agoFix Changelog for ab0538b875c054468aa205d8d36550d1223a3bfd
Alan Hayward [Wed, 12 Apr 2017 08:51:04 +0000 (09:51 +0100)]
Fix Changelog for ab0538b875c054468aa205d8d36550d1223a3bfd

7 years agoAdd M32R_ARG_REGISTER_SIZE
Alan Hayward [Wed, 12 Apr 2017 08:19:55 +0000 (09:19 +0100)]
Add M32R_ARG_REGISTER_SIZE

gdb/
* m32r-tdep.c M32R_ARG_REGISTER_SIZE: Added.
(m32r_push_dummy_call): Use M32R_ARG_REGISTER_SIZE.

7 years agoFix build breakage from last commit (window-nat.c:windows_create_inferior)
Sergio Durigan Junior [Wed, 12 Apr 2017 05:16:50 +0000 (01:16 -0400)]
Fix build breakage from last commit (window-nat.c:windows_create_inferior)

Forgot to declare the variable 'toexec' (from
window-nat.c:windows_create_inferior) as 'const char *', which caused
a build breakage.

gdb/ChangeLog:
2017-04-12  Sergio Durigan Junior  <sergiodj@redhat.com>

* windows-nat.c (windows_create_inferior): Declare 'toexec' as
'const char *'.

7 years agoC++-fy and prepare for sharing fork_inferior
Sergio Durigan Junior [Thu, 23 Mar 2017 01:54:49 +0000 (21:54 -0400)]
C++-fy and prepare for sharing fork_inferior

As a preparation for the next patch, which will move fork_inferior
from GDB to common/ (and therefore share it with gdbserver), it is
interesting to convert a few functions to C++.

This patch touches functions related to parsing command-line arguments
to the inferior (see gdb/fork-child.c:breakup_args), the way the
arguments are stored on fork_inferior (using std::vector instead of
char **), and the code responsible for dealing with argv also on
gdbserver.

I've taken this opportunity and decided to constify a few arguments to
fork_inferior/create_inferior as well, in order to make the code
cleaner.  And now, on gdbserver, we're using xstrdup everywhere and
aren't checking for memory allocation failures anymore, as requested
by Pedro:

  <https://sourceware.org/ml/gdb-patches/2017-03/msg00191.html>
  Message-Id: <025ebdb9-90d9-d54a-c055-57ed2406b812@redhat.com>

  Pedro Alves wrote:

  > On the "== NULL" check: IIUC, the old NULL check was there to
  > handle strdup returning NULL due to out-of-memory.
  > See NULL checks and comments further above in this function.
  > Now that you're using a std::vector, that doesn't work or make
  > sense any longer, since if push_back fails to allocate space for
  > its internal buffer (with operator new), our operator new replacement
  > (common/new-op.c) calls malloc_failure, which aborts gdbserver.
  >
  > Not sure it makes sense to handle out-of-memory specially in
  > the gdb/rsp-facing functions nowadays (maybe git blame/log/patch
  > submission for that code shows some guidelines).  Maybe (or, probably)
  > it's OK to stop caring about it, but then we should consistently remove
  > left over code, by using xstrdup instead and remove the NULL checks.

IMO this refactoring was very good to increase the readability of the
code as well, because some parts of the argument handling were
unnecessarily confusing before.

gdb/ChangeLog:
2017-04-12  Sergio Durigan Junior  <sergiodj@redhat.com>

* common/common-utils.c (free_vector_argv): New function.
* common/common-utils.h: Include <vector>.
(free_vector_argv): New prototype.
* darwin-nat.c (darwin_create_inferior): Rewrite function
prototype in order to constify "exec_file" and accept a
"std::string" for "allargs".
* fork-child.c: Include <vector>.
(breakup_args): Rewrite function, using C++.
(fork_inferior): Rewrite function header, constify "exec_file_arg"
and accept "std::string" for "allargs".  Update the code to
calculate "argv" based on "allargs".  Update calls to "exec_fun"
and "execvp".
* gnu-nat.c (gnu_create_inferior): Rewrite function prototype in
order to constify "exec_file" and accept a "std::string" for
"allargs".
* go32-nat.c (go32_create_inferior): Likewise.
* inf-ptrace.c (inf_ptrace_create_inferior): Likewise.
* infcmd.c (run_command_1): Constify "exec_file".  Use
"std::string" for inferior arguments.
* inferior.h (fork_inferior): Update prototype.
* linux-nat.c (linux_nat_create_inferior): Rewrite function
prototype in order to constify "exec_file" and accept a
"std::string" for "allargs".
* nto-procfs.c (procfs_create_inferior): Likewise.
* procfs.c (procfs_create_inferior): Likewise.
* remote-sim.c (gdbsim_create_inferior): Likewise.
* remote.c (extended_remote_run): Update code to accept
"std::string" as argument.
(extended_remote_create_inferior): Rewrite function prototype in
order to constify "exec_file" and accept a "std::string" for
"allargs".
* rs6000-nat.c (super_create_inferior): Likewise.
(rs6000_create_inferior): Likewise.
* target.h (struct target_ops) <to_create_inferior>: Likewise.
* windows-nat.c (windows_create_inferior): Likewise.

gdb/gdbserver/ChangeLog:
2017-04-12  Sergio Durigan Junior  <sergiodj@redhat.com>

* server.c: Include <vector>.
<program_argv, wrapper_argv>: Convert to std::vector.
(start_inferior): Rewrite function to use C++.
(handle_v_run): Likewise.  Update code that calculates the argv
based on the vRun packet; use C++.
(captured_main): Likewise.

7 years agoAutomatic date update in version.in
GDB Administrator [Wed, 12 Apr 2017 00:00:43 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoRemove the extra `\n' in warning/error messages
H.J. Lu [Tue, 11 Apr 2017 22:41:00 +0000 (15:41 -0700)]
Remove the extra `\n' in warning/error messages

* elf-properties.c (_bfd_elf_parse_gnu_properties): Remove the
extra `\n' in warning/error messages.
* elf32-i386.c (elf_i386_parse_gnu_properties): Likewise.
* elf64-x86-64.c (elf_x86_64_parse_gnu_properties): Likewise.

7 years agoIgnore processor-specific GNU program properties
H.J. Lu [Tue, 11 Apr 2017 22:07:41 +0000 (15:07 -0700)]
Ignore processor-specific GNU program properties

Skip processor-specific GNU program properties with generic ELF target
vector.  They should be handled by the matching ELF target vector.

* elf-properties.c (_bfd_elf_parse_gnu_properties): Ignore
processor-specific properties with generic ELF target vector.

7 years agogdb/thread.c: Fix whitespace throughout
Pedro Alves [Tue, 11 Apr 2017 12:57:52 +0000 (13:57 +0100)]
gdb/thread.c: Fix whitespace throughout

gdb/ChangeLog:
2017-04-11  Pedro Alves  <palves@redhat.com>

* thread.c: Fix whitespace throughout.

7 years agoFix read after xfree in linux-nat.c:linux_nat_detach
Philipp Rudo [Tue, 11 Apr 2017 13:28:51 +0000 (14:28 +0100)]
Fix read after xfree in linux-nat.c:linux_nat_detach

At the end of linux_nat_detach the main_lwp is deleted (delete_lwp).
This is problematic as during detach (detach_one_lwp and
linux_fork_detach) main_lwp already gets freed.  Thus calling
delete_lwp causes a read after free.  Fix it by removing the
unnecessary delete_lwp.

gdb/ChangeLog:
2017-04-11  Philipp Rudo  <prudo@linux.vnet.ibm.com>

* linux-nat.c (linux_nat_detach): Remove delete_lwp call.

7 years agoRemove MAX_REGISTER_SIZE from arm-tdep.c
Alan Hayward [Tue, 11 Apr 2017 12:51:58 +0000 (13:51 +0100)]
Remove MAX_REGISTER_SIZE from arm-tdep.c

gdb/
* arm-tdep.c (arm_store_return_value): Use FP_REGISTER_SIZE

7 years agoPR 21274, ld segfaults linking PE DLL
Alan Modra [Tue, 11 Apr 2017 10:07:51 +0000 (19:37 +0930)]
PR 21274, ld segfaults linking PE DLL

Don't use fixed size buffers for symbol names.

PR 21274
PR 18466
* emultempl/pe.em (pe_find_data_imports): Don't use fixed size
symbol buffer.  Instead, xmalloc max size needed with space for
prefix.  Wrap overlong lines.  Formatting.  Pass symbol buffer
copy of name to pe_walk_relocs_of_symbol.
(make_inport_fixup): Add "name" param, pass to pe_create_import_fixup.
* emultempl/pe.em (pep_find_data_imports): As for pe_find_data_imports.
(make_import_fixup): Add "name" param, pass to pep_create_import_fixup.
Use bfd_get_signed_* and remove unnecessary casts.  Formatting.
* pe-dll.c (pe_walk_relocs_of_symbol): Add "name" param.  Pass to
callback.
(make_import_fixup_mark): Add "name" param.  Make use of prefix
space rather than xmalloc here.
(pe_create_import_fixup): Likewise.
* pe-dll.h (pe_walk_relocs_of_symbol): Update prototype.
(pe_create_import_fixup): Likewise.
* pep-dll.h (pep_walk_relocs_of_symbol): Likewise.
(pep_create_import_fixup): Likewise.

7 years agoAutomatic date update in version.in
GDB Administrator [Tue, 11 Apr 2017 00:00:28 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoReorder PPC_OPCODE_* and set PPC_OPCODE_TMR for e6500
Alan Modra [Mon, 10 Apr 2017 22:13:21 +0000 (07:43 +0930)]
Reorder PPC_OPCODE_* and set PPC_OPCODE_TMR for e6500

PPC_OPCODE_* renumbered to fill the gaps left by previous patches,
and reordered chronologically just because.  I kept PPC_OPCODE_TMR
because presumably it might be used in future APUinfo for e6500.

include/
* opcode/ppc.h (PPC_OPCODE_*): Renumber and order chronologically.
(PPC_OPCODE_SPE): Comment on this and other bits used for APUinfo.
opcodes/
* ppc-dis.c (ppc_opts): Formatting.  Set PPC_OPCODE_TMR for e6500.
* ppc-opc.c (powerpc_opcodes <mftmr, mttmr>): Remove now
unnecessary E6500.

7 years agoBye bye PPC_OPCODE_HTM and -mhtm
Alan Modra [Mon, 10 Apr 2017 22:10:24 +0000 (07:40 +0930)]
Bye bye PPC_OPCODE_HTM and -mhtm

The -mhtm option is fairly useless too.

include/
* opcode/ppc.h (PPC_OPCODE_HTM): Delete.
gas/
* config/tc-ppc.c (md_show_usage): Delete mention of -mhtm.
* testsuite/gas/ppc/htm.d: Pass -mpower8 and -Mpower8.
opcodes/
* ppc-dis.c (ppc_opts): Remove PPC_OPCODE_HTM and "htm".
* ppc-opc.c (PPCHTM): Define as PPC_OPCODE_POWER8.

7 years agoBye Bye PPC_OPCODE_VSX3
Alan Modra [Mon, 10 Apr 2017 22:06:43 +0000 (07:36 +0930)]
Bye Bye PPC_OPCODE_VSX3

This bit is also useless as it can be replaced with PPC_OPCODE_POWER9.
Defining the VSX2 and VSX3 selection based on cpu bits also lets the
assembler/disassembler distinguish between the power7 VSX opcodes and
the power8 ones.  Note that this change means -mvsx now reverts back
to just adding the power7 VSX insns.

include/
* opcode/ppc.h (PPC_OPCODE_VSX3): Delete.
opcodes/
* ppc-dis.c (ppc_opts): Remove PPC_OPCODE_VSX3.
* ppc-opc.c (PPCVSX2): Define as PPC_OPCODE_POWER8.
(PPCVSX3): Define as PPC_OPCODE_POWER9.

7 years agoBye bye PPC_OPCODE_ALTIVEC2
Alan Modra [Mon, 10 Apr 2017 22:03:50 +0000 (07:33 +0930)]
Bye bye PPC_OPCODE_ALTIVEC2

This bit is worse than useless.  Using it prevents the assembler and
disassembler distinguishing between opcodes added for power8 and those
added for power9.

include/
* opcode/ppc.h (PPC_OPCODE_ALTIVEC2): Delete.
opcodes/
* ppc-dis.c (ppc_opts): Remove PPC_OPCODE_ALTIVEC2.
* ppc-opc.c (PPCVEC2): Define as PPC_OPCODE_POWER8|PPC_OPCODE_E6500.
(PPCVEC3): Define as PPC_OPCODE_POWER9.

7 years agoFix PR gdb/21364: Dead code due to an unreachable condition in osdata.c
Sergio Durigan Junior [Mon, 10 Apr 2017 16:43:44 +0000 (12:43 -0400)]
Fix PR gdb/21364: Dead code due to an unreachable condition in osdata.c

Pedro's recent commits enabling -Wwrite-strings has changed a bit the
logic of info_osdata.  Now, 'type' is always non-NULL, so we have to
check if it's an empty string instead of NULL.  One of the checks was
fixed, but there is another that was left behind.  This commit fixes
it.

gdb/ChangeLog:
2017-04-10  Sergio Durigan Junior  <sergiodj@redhat.com>

PR gdb/21364
* osdata.c (info_osdata): Check if 'type' is an empty string
instead of NULL.

7 years agoPrevent a bigus warning from readelf about a gdb-index table being too big.
John Delsignor [Mon, 10 Apr 2017 15:27:05 +0000 (16:27 +0100)]
Prevent a bigus warning from readelf about a gdb-index table being too big.

PR binutils/21319
* dwarf.c (display_gdb_index): Correct test for a corrupt address
table size.

7 years agoDocument undocumented linker command line options.
Nick Clifton [Mon, 10 Apr 2017 14:56:55 +0000 (15:56 +0100)]
Document undocumented linker command line options.

ld  * ld.texinfo (--strip-discarded): Document.
(--embedded-relocs): Document.
(--spare-dynamic-tags): Document.
(--task-link): Document.

7 years agothread.c: ptid_equal -> operator==
Pedro Alves [Mon, 10 Apr 2017 14:54:57 +0000 (15:54 +0100)]
thread.c: ptid_equal -> operator==

gdb/ChangeLog:
2017-04-10  Pedro Alves  <palves@redhat.com>

* thread.c (add_thread_silent, delete_thread_1, find_thread_ptid)
(ptid_to_global_thread_id, in_thread_list)
(do_captured_list_thread_ids, set_resumed, set_running)
(set_executing, set_stop_requested, finish_thread_state)
(validate_registers_access, can_access_registers_ptid)
(print_thread_info_1, switch_to_thread)
(do_restore_current_thread_cleanup)
(make_cleanup_restore_current_thread, thread_command)
(thread_name_command): Use operator== instead of ptid_equal.

7 years agoGC gdb/thread.c:current_thread_cleanup_chain
Pedro Alves [Mon, 10 Apr 2017 14:18:49 +0000 (15:18 +0100)]
GC gdb/thread.c:current_thread_cleanup_chain

Commit 803bdfe43083475c7df3db38dc96f4e20d05457d ("Don't delete
thread_info if refcount isn't zero") eliminated
restore_current_thread_ptid_changed, so current_thread_cleanup_chain
is no longer necessary either.

gdb/ChangeLog:
2017-04-10  Pedro Alves  <palves@redhat.com>

* thread.c (struct current_thread_cleanup) <next>: Delete field.
(current_thread_cleanup_chain): Delete.
(restore_current_thread_cleanup_dtor)
(make_cleanup_restore_current_thread): Remove references to
current_thread_cleanup_chain.

7 years agomsp430: Don't use REG_UNKNOWN
Alan Hayward [Mon, 10 Apr 2017 14:01:53 +0000 (15:01 +0100)]
msp430: Don't use REG_UNKNOWN

gdb/
* msp430-tdep.c (msp430_pseudo_register_read): Never return
REG_UNKNOWN.

7 years agoDon't delete thread_info if refcount isn't zero
Yao Qi [Mon, 10 Apr 2017 13:39:41 +0000 (14:39 +0100)]
Don't delete thread_info if refcount isn't zero

I build GDB with asan, and run test case hook-stop.exp, and threadapply.exp,
I got the following asan error,

=================================================================^M
^[[1m^[[31m==2291==ERROR: AddressSanitizer: heap-use-after-free on address 0x6160000999c4 at pc 0x000000826022 bp 0x7ffd28a8ff70 sp 0x7ffd28a8ff60^M
^[[1m^[[0m^[[1m^[[34mREAD of size 4 at 0x6160000999c4 thread T0^[[1m^[[0m^M
    #0 0x826021 in release_stop_context_cleanup ../../binutils-gdb/gdb/infrun.c:8203^M
    #1 0x72798a in do_my_cleanups ../../binutils-gdb/gdb/common/cleanups.c:154^M
    #2 0x727a32 in do_cleanups(cleanup*) ../../binutils-gdb/gdb/common/cleanups.c:176^M
    #3 0x826895 in normal_stop() ../../binutils-gdb/gdb/infrun.c:8381^M
    #4 0x815208 in fetch_inferior_event(void*) ../../binutils-gdb/gdb/infrun.c:4011^M
    #5 0x868aca in inferior_event_handler(inferior_event_type, void*) ../../binutils-gdb/gdb/inf-loop.c:44^M
....
^[[1m^[[32m0x6160000999c4 is located 68 bytes inside of 568-byte region [0x616000099980,0x616000099bb8)^M
^[[1m^[[0m^[[1m^[[35mfreed by thread T0 here:^[[1m^[[0m^M
    #0 0x7fb0bc1312ca in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x982ca)^M
    #1 0xb8c62f in xfree(void*) ../../binutils-gdb/gdb/common/common-utils.c:100^M
    #2 0x83df67 in free_thread ../../binutils-gdb/gdb/thread.c:207^M
    #3 0x83dfd2 in init_thread_list() ../../binutils-gdb/gdb/thread.c:223^M
    #4 0x805494 in kill_command ../../binutils-gdb/gdb/infcmd.c:2595^M
....

Detaching from program: /home/yao.qi/SourceCode/gnu/build-with-asan/gdb/testsuite/outputs/gdb.threads/threadapply/threadapply, process 2399^M
=================================================================^M
^[[1m^[[31m==2387==ERROR: AddressSanitizer: heap-use-after-free on address 0x6160000a98c0 at pc 0x00000083fd28 bp 0x7ffd401c3110 sp 0x7ffd401c3100^M
^[[1m^[[0m^[[1m^[[34mREAD of size 4 at 0x6160000a98c0 thread T0^[[1m^[[0m^M
    #0 0x83fd27 in thread_alive ../../binutils-gdb/gdb/thread.c:741^M
    #1 0x844277 in thread_apply_all_command ../../binutils-gdb/gdb/thread.c:1804^M
....
^M
^[[1m^[[32m0x6160000a98c0 is located 64 bytes inside of 568-byte region [0x6160000a9880,0x6160000a9ab8)^M
^[[1m^[[0m^[[1m^[[35mfreed by thread T0 here:^[[1m^[[0m^M
    #0 0x7f59a7e322ca in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x982ca)^M
    #1 0xb8c62f in xfree(void*) ../../binutils-gdb/gdb/common/common-utils.c:100^M
    #2 0x83df67 in free_thread ../../binutils-gdb/gdb/thread.c:207^M
    #3 0x83dfd2 in init_thread_list() ../../binutils-gdb/gdb/thread.c:223^M

This patch fixes the issue by deleting thread_info object if it is
deletable, otherwise, mark it as exited (by set_thread_exited).
Function set_thread_exited is shared from delete_thread_1.  This patch
also moves field "refcount" to private and methods incref and
decref.  Additionally, we stop using "ptid_t" in
"struct current_thread_cleanup" to reference threads, instead we use
"thread_info" directly.  Due to this change, we don't need
restore_current_thread_ptid_changed anymore.

gdb:

2017-04-10  Yao Qi  <yao.qi@linaro.org>

PR gdb/19942
* gdbthread.h (thread_info::deletable): New method.
(thread_info::incref): New method.
(thread_info::decref): New method.
(thread_info::refcount): Move it to private.
* infrun.c (save_stop_context): Call inc_refcount.
(release_stop_context_cleanup): Likewise.
* thread.c (set_thread_exited): New function.
(init_thread_list): Delete "tp" only it is deletable, otherwise
call set_thread_exited.
(delete_thread_1): Call set_thread_exited.
(current_thread_cleanup) <inferior_pid>: Remove.
<thread>: New field.
(restore_current_thread_ptid_changed): Removed.
(do_restore_current_thread_cleanup): Adjust.
(restore_current_thread_cleanup_dtor): Don't call
find_thread_ptid.
(set_thread_refcount): Use dec_refcount.
(make_cleanup_restore_current_thread): Adjust.
(thread_apply_all_command): Call inc_refcount.
(_initialize_thread): Don't call
observer_attach_thread_ptid_changed.

7 years agoHoist code on marking thread as exited
Yao Qi [Mon, 10 Apr 2017 13:39:41 +0000 (14:39 +0100)]
Hoist code on marking thread as exited

This patch hoists code on marking thread as exited, so more code is shared
for two different paths (thread_info is deleted or is not deleted).

gdb:

2017-04-10  Yao Qi  <yao.qi@linaro.org>

* thread.c (delete_thread_1): Hoist code on marking thread as
exited.

7 years agogas: xtensa: fix incorrect code generated with auto litpools
Max Filippov [Mon, 10 Apr 2017 12:12:52 +0000 (13:12 +0100)]
gas: xtensa: fix incorrect code generated with auto litpools

* config/tc-xtensa.c (xtensa_maybe_create_literal_pool_frag):
Initialize lps->frag_count with auto_litpool_limit.
(xg_promote_candidate_litpool): New function.
(xtensa_move_literals): Extract candidate litpool promotion code
into separate function. Call it for all possible found
candidates.
(xtensa_switch_to_literal_fragment): Drop 'recursive' flag and
call to xtensa_mark_literal_pool_location that it guards.
Replace it with call to xtensa_maybe_create_literal_pool_frag.
Initialize pool_location with created literal pool candidate.
* testsuite/gas/xtensa/all.exp: Add new tests.
* testsuite/gas/xtensa/auto-litpools-first1.d: New test results.
* testsuite/gas/xtensa/auto-litpools-first1.s: New test.
* testsuite/gas/xtensa/auto-litpools-first2.d: New test results.
* testsuite/gas/xtensa/auto-litpools-first2.s: New test.
* testsuite/gas/xtensa/auto-litpools.d: Fix offsets changed due
to additional jump instruction.

7 years agoPort the bug fix for PR 19704 (Missing dynamic relocation against undefined weak...
Qing Zhao [Mon, 10 Apr 2017 11:46:30 +0000 (12:46 +0100)]
Port the bug fix for PR 19704 (Missing dynamic relocation against undefined weak symbol) to the SPARC architecture.

       * elf32-sparc.c (elf_backend_fixup_symbol): New.
        * elf64-sparc.c (elf_backend_fixup_symbol): New.
        * elfxx-sparc.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): New.
        (_bfd_sparc_elf_link_hash_entry): Add has_got_reloc and
        has_non_got_reloc.
        (link_hash_newfunc): Initialize has_got_reloc and
has_non_got_reloc.
        (_bfd_sparc_elf_size_dynamic_sections): Set interp to .interp
        section.
        (_bfd_sparc_elf_copy_indirect_symbol): Copy has_got_reloc and
        has_non_got_reloc.
        (_bfd_sparc_elf_check_relocs): Set has_got_reloc and
        has_non_got_reloc.
        (_bfd_sparc_elf_fixup_symbol): New function.
        (allocate_dynrelocs): Don't allocate space for dynamic
        relocations and discard relocations against resolved undefined
        weak symbols in executable.  Don't make resolved undefined weak
        symbols in executable dynamic.  Keep dynamic non-GOT/non-PLT
        relocation against undefined weak symbols in PIE.
        (_bfd_sparc_elf_relocate_section): Don't generate dynamic
        relocations against resolved undefined weak symbols in PIE
        (_bfd_sparc_elf_finish_dynamic_symbol): Keep PLT/GOT entries
        without ynamic PLT/GOT relocations for resolved undefined weak
        symbols.
        Don't generate dynamic relocation against resolved undefined
        weak symbol in executable.
        (pie_finish_undefweak_symbol): New function.
        (_bfd_sparc_elf_finish_dynamic_sections): Call
        pie_finish_undefweak_symbol on all symbols in PIE.
        * elfxx-sparc.h (_bfd_sparc_elf_link_hash_table): Add interp.
        (_bfd_sparc_elf_fixup_symbol): New function.

7 years agoRemove the ns32k target from the obsolete list.
Nick Clifton [Mon, 10 Apr 2017 10:38:21 +0000 (11:38 +0100)]
Remove the ns32k target from the obsolete list.

* config.bfd: Remove ns32k from obsolete list.

7 years agoTidy ppc476 opcodes
Alan Modra [Mon, 10 Apr 2017 06:05:11 +0000 (15:35 +0930)]
Tidy ppc476 opcodes

PPC_OPCODE_440 being set for ppc476 meant that many opcodes needed to
be deprecated for ppc476.  There are far fewer to add specially for
ppc476 if PPC_OPCODE_440 is not set for ppc476.

* ppc-dis.c (ppc_opts <476>): Remove PPC_OPCODE_440.
* ppc-opc.c (MULHW): Add PPC_OPCODE_476.
(powerpc_opcodes): Adjust PPC440, PPC464 and PPC476 insns to suit
removal of PPC_OPCODE_440 from ppc476 cpu selection bits.

7 years agoPR21287, Inconsistent section type for .init_array and .init_array.42
Alan Modra [Mon, 10 Apr 2017 05:41:35 +0000 (15:11 +0930)]
PR21287, Inconsistent section type for .init_array and .init_array.42

PR21287 notes that .init_array is correctly given a type of
SHT_INIT_ARRAY while .init_array.nnn gets SHT_PROGBITS.  This patch
fixes that problem, and properly drops warnings from the compiler that
would cause the testsuite to fail.  My a44d0bd78 change to check
ld_compile status, necessary to pick up compile errors, also meant
warnings were not ignored.

bfd/
PR 21287
* elf.c (special_sections_f): Match .fini_array and .fini_array.*.
(special_sections_i): Likewise for .init_array.
(special_sections_p): Likewise for .preinit_array.
ld/
PR 21287
* testsuite/ld-elf/init-fini-arrays.d: Match INIT_ARRAY and FINI_ARRAY.
* testsuite/ld-elf/init-fini-arrays.s: Use %init_array and %fini_array
section types.
* testsuite/lib/ld-lib.exp (default_ld_compile): Trim assembler
warnings about "ignoring incorrect section type".
(run_ld_link_exec_tests, run_cc_link_tests): Delete old comment.

7 years agoClean elfvsb files left over from previous runs
Alan Modra [Mon, 10 Apr 2017 05:40:58 +0000 (15:10 +0930)]
Clean elfvsb files left over from previous runs

My mips-linux and mips64-linux testsuite runs have been failing a
bunch of visibility tests, seemingly randomly.  It turns out the
problem occurs when object files are left over in ld/tmpdir from a
previous run.

* testsuite/ld-elfvsb/elfvsb.exp (visibility_run): Delete
sh1p.o, sh2p.o, sh1np.o and sh2np.o before compiling.  Use
remote_file host exists rather than file exists.

7 years agoWebAssembly disassembler support
Pip Cet [Mon, 10 Apr 2017 00:10:28 +0000 (00:10 +0000)]
WebAssembly disassembler support

* wasm32-dis.c (print_insn_wasm32): Avoid DECIMAL_DIG, specify
appropriate floating-point precision directly.

7 years agowindows-nat.c: Fix bad initialization of ptid
Simon Marchi [Mon, 10 Apr 2017 03:14:36 +0000 (23:14 -0400)]
windows-nat.c: Fix bad initialization of ptid

When trying to build for x86_64-w64-mingw32:

/home/simark/src/binutils-gdb/gdb/windows-nat.c: In function â€˜void windows_detach(target_ops*, const char*, int)’:
/home/simark/src/binutils-gdb/gdb/windows-nat.c:1915:20: error: converting to â€˜ptid_t’ from initializer list would use explicit constructor â€˜constexpr ptid_t::ptid_t(int, long int, long int)’
   ptid_t ptid = {-1};
                    ^
Fixed by initializing ptid with the minus_one_ptid variable.

gdb/ChangeLog:

* windows-nat.c (windows_detach): Initialize ptid with
minus_one_ptid.

7 years agoAutomatic date update in version.in
GDB Administrator [Mon, 10 Apr 2017 00:00:37 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAutomatic date update in version.in
GDB Administrator [Sun, 9 Apr 2017 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAdd support for fcvtl and fcvtl2.
Jim Wilson [Sat, 8 Apr 2017 19:06:31 +0000 (12:06 -0700)]
Add support for fcvtl and fcvtl2.

sim/aarch64/
* simulator.c (do_vec_FCVTL): New.
(do_vec_op1): Call do_vec_FCVTL.

sim/testsuite/sim/aarch64/
* fcvtl.s: New.

7 years agoSupport the fcmXX zero instructions.
Jim Wilson [Sat, 8 Apr 2017 14:10:38 +0000 (07:10 -0700)]
Support the fcmXX zero instructions.

sim/aarch64/
* simulator.c (do_scalar_FCMGE_zero): New.
(do_scalar_FCMLE_zero, do_scalar_FCMGT_zero, do_scalar_FCMEQ_zero)
(do_scalar_FCMLT_zero): Likewise.
(do_scalar_vec): Add calls to new functions.

sim/testsuite/sim/aarch64/
* fcmXX.s: New.

7 years agoAutomatic date update in version.in
GDB Administrator [Sat, 8 Apr 2017 00:00:33 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoUse NOPIE_CFLAGS and NOPIE_LDFLAGS to disable PIE
H.J. Lu [Fri, 7 Apr 2017 15:53:43 +0000 (08:53 -0700)]
Use NOPIE_CFLAGS and NOPIE_LDFLAGS to disable PIE

Since not all compilers support -no-pie, NOPIE_CFLAGS and NOPIE_LDFLAGS
should be used to disable PIE.

PR ld/21090
* testsuite/ld-x86-64/x86-64.exp (undefined_weak): Use
NOPIE_CFLAGS and NOPIE_LDFLAGS to disable PIE for the non-pie
version of the test.

7 years agoELF: Check ELF_COMMON_DEF_P for common symbols
H.J. Lu [Fri, 7 Apr 2017 14:40:14 +0000 (07:40 -0700)]
ELF: Check ELF_COMMON_DEF_P for common symbols

Since common symbols that are turned into definitions don't have the
DEF_REGULAR flag set, we need to check ELF_COMMON_DEF_P for common
symbols.

bfd/

PR ld/19579
PR ld/21306
* elf32-s390.c (elf_s390_finish_dynamic_symbol): Check
ELF_COMMON_DEF_P for common symbols.
* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
* elflink.c (_bfd_elf_merge_symbol): Revert commits
202ac193bbbecc96a4978d1ac3d17148253f9b01 and
07492f668d2173da7a2bda3707ff0985e0f460b6.

ld/

PR ld/19579
PR ld/21306
* testsuite/ld-elf/pr19579a.c (main): Updated.

7 years agoptid-selftests: Fix erroneous assert messages
Simon Marchi [Fri, 7 Apr 2017 14:27:48 +0000 (10:27 -0400)]
ptid-selftests: Fix erroneous assert messages

gdb/ChangeLog:

* unittests/ptid-selftests.c: Fix erroneous assert messages.

7 years agoFix building the BFD library for Win64 by reqorking the find_separate_debug_file...
Pedro Alves [Fri, 7 Apr 2017 13:51:42 +0000 (14:51 +0100)]
Fix building the BFD library for Win64 by reqorking the find_separate_debug_file interface.

* opncls.c (bfd_get_debug_link_info): Rename to...
(bfd_get_debug_link_info_1): ... this.  Change type of second
parameter to void pointer.  Adjust.
(bfd_get_debug_link_info): Reimplement on top of
bfd_get_debug_link_info_1.
(separate_debug_file_exists, separate_alt_debug_file_exists):
Change type of second parameter to void pointer.  Adjust.
(get_func_type, check_func_type): Change type of second parameter
to void pointer.
(find_separate_debug_file): Add 'func_data' parameter.  Pass it to
the callback functions instead of passing the address of a local.
(bfd_follow_gnu_debuglink): Pass address of unsigned long local to
find_separate_debug_file.
(get_alt_debug_link_info_shim): Change type of second parameter to
void pointer.  Adjust.
(bfd_follow_gnu_debugaltlink): Adjust to pass NULL to
find_separate_debug_file.
(get_build_id_name, bfd_boolean check_build_id_file): Change type
of second parameter to void pointer.  Adjust.
(bfd_follow_build_id_debuglink): Pass address of bfd_build_id
pointer local to find_separate_debug_file.

7 years agoFix failure in x86_64 linker tests when compiling with a PIE enabled compiler.
Nick Clifton [Fri, 7 Apr 2017 10:48:08 +0000 (11:48 +0100)]
Fix failure in x86_64 linker tests when compiling with a PIE enabled compiler.

PR 21090
* testsuite/ld-x86-64/x86-64.exp (undefined_weak): Explicitly
disable PIE for the non-pie version of the test.

7 years agoRemove E6500 insns from PPC_OPCODE_ALTIVEC2
Alan Modra [Fri, 7 Apr 2017 08:33:46 +0000 (18:03 +0930)]
Remove E6500 insns from PPC_OPCODE_ALTIVEC2

This isn't losing anything from the testsuite.  All of these insns
appear in testsuite/gas/ppc/e6500.s

opcodes/
* ppc-opc.c (powerpc_opcodes <mviwsplt, mvidsplt, lvexbx, lvepxl,
lvexhx, lvepx, lvexwx, stvexbx, stvexhx, stvexwx, lvtrx, lvtlx,
lvswx, stvfrx, stvflx, stvswx, lvsm, stvepxl, lvtrxl, stvepx,
lvtlxl, lvswxl, stvfrxl, stvflxl, stvswxl>): Enable E6500 only
vector instructions with E6500 not PPCVEC2.
gas/
* testsuite/gas/ppc/altivec2.s: Delete E6500 vector insns.
* testsuite/gas/ppc/altivec2.d: Adjust to suit.

7 years agoTweak MBIND ld test for ARM.
Alan Modra [Fri, 7 Apr 2017 08:31:43 +0000 (18:01 +0930)]
Tweak MBIND ld test for ARM.

* testsuite/ld-elf/mbind2a.s: Don't use @, the ARM comment char.

7 years agoMBIND gas test tweak
Alan Modra [Fri, 7 Apr 2017 08:28:37 +0000 (17:58 +0930)]
MBIND gas test tweak

score-elf aligns text sections.

* testsuite/gas/elf/section12a.d: Don't expect alignment of 1
for .mbind.text.

7 years agoAdd BFIN_MAX_REGISTER_SIZE
Alan Hayward [Fri, 7 Apr 2017 08:31:37 +0000 (09:31 +0100)]
Add BFIN_MAX_REGISTER_SIZE

gdb/
* bfin-tdep.c (BFIN_MAX_REGISTER_SIZE): Add.
(bfin_pseudo_register_read): Use BFIN_MAX_REGISTER_SIZE.
(bfin_pseudo_register_write): Likewise

7 years agope/coff: handle weak defined symbol for gc-sections.
Tristan Gingold [Fri, 31 Mar 2017 13:25:18 +0000 (15:25 +0200)]
pe/coff: handle weak defined symbol for gc-sections.

bfd/
* coffgen.c (_bfd_coff_gc_mark_hook): Handle PE weak
external symbols with a definition.
(_bfd_coff_gc_mark_extra_sections): Fix typo.

ld/
* testsuite/ld-pe/pe.exp: New test.
* testsuite/ld-pe/weakdef-1.s: New test source.
* testsuite/ld-pe/weakdef-1.d: New test.

7 years agoClass-ify ptid_t
Simon Marchi [Fri, 7 Apr 2017 03:29:53 +0000 (23:29 -0400)]
Class-ify ptid_t

I grew a bit tired of using ptid_get_{lwp,pid,tid} and friends, so I decided to
make it a bit easier to use by making it a proper class.  The fields are now
private, so it's not possible to change a ptid_t field by mistake.

The new methods of ptid_t map to existing functions/practice like this:

  ptid_t (pid, lwp, tid) -> ptid_build (pid, lwp, tid)
  ptid_t (pid) -> pid_to_ptid (pid)
  ptid.is_pid () -> ptid_is_pid (ptid)
  ptid == other -> ptid_equal (ptid, other)
  ptid != other -> !ptid_equal (ptid, other)
  ptid.pid () -> ptid_get_pid (ptid)
  ptid.lwp_p () -> ptid_lwp_p (ptid)
  ptid.lwp () -> ptid_get_lwp (ptid)
  ptid.tid_p () -> ptid_tid_p (ptid)
  ptid.tid () -> ptid_get_tid (ptid)
  ptid.matches (filter) -> ptid_match (ptid, filter)

I've replaced the implementation of the existing functions with calls to
the new methods.  People are encouraged to gradually switch to using the
ptid_t methods instead of the functions (or we can change them all in
one pass eventually).

Also, I'm not sure if it's worth it (because of ptid_t's relatively
small size), but I have made the functions and methods take ptid_t
arguments by const reference instead of by value.

gdb/ChangeLog:

* common/ptid.h (struct ptid): Change to...
(class ptid_t): ... this.
<ptid_t>: New constructors.
<pid, lwp_p, lwp, tid_p, tid, is_pid, operator==, operator!=,
matches>: New methods.
<make_null, make_minus_one>: New static methods.
<pid>: Rename to...
<m_pid>: ...this.
<lwp>: Rename to...
<m_lwp>: ...this.
<tid>: Rename to...
<m_tid>: ...this.
(ptid_build, ptid_get_pid, ptid_get_lwp, ptid_get_tid, ptid_equal,
ptid_is_pid, ptid_lwp_p, ptid_tid_p, ptid_match): Take ptid arguments
as references, move comment to class ptid_t.
* common/ptid.c (null_ptid, minus_one_ptid): Initialize with
ptid_t static methods.
(ptid_build, pid_to_ptid, ptid_get_pid, ptid_get_tid,
ptid_equal, ptid_is_pid, ptid_lwp_p, ptid_tid_p, ptid_match):
Take ptid arguments as references, implement using ptid_t methods.
* unittests/ptid-selftests.c: New file.
* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
unittests/ptid-selftests.c.
(SUBDIR_UNITTESTS_OBS): Add unittests/ptid-selftests.o.

gdb/gdbserver/ChangeLog:

* server.c (handle_v_cont): Initialize thread_resume::thread
with null_ptid.

7 years agoAutomatic date update in version.in
GDB Administrator [Fri, 7 Apr 2017 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAdd support for disassembling WebAssembly opcodes.
Pip Cet [Thu, 6 Apr 2017 16:17:15 +0000 (17:17 +0100)]
Add support for disassembling WebAssembly opcodes.

include * dis-asm.h: Add prototypes for wasm32 disassembler.

opcodes * Makefile.am: Add wasm32-dis.c.
* configure.ac: Add wasm32-dis.c to wasm32 target.
* disassemble.c: Add wasm32 disassembler code.
* wasm32-dis.c: New file.
* Makefile.in: Regenerate.
* configure: Regenerate.
* po/POTFILES.in: Regenerate.
* po/opcodes.pot: Regenerate.

gas * testsuite/gas/wasm32/allinsn.d: Adjust test for disassembler
changes.
* testsuite/gas/wasm32/disass.d: New test.
* testsuite/gas/wasm32/disass.s: New test.
* testsuite/gas/wasm32/disass-2.d: New test.
* testsuite/gas/wasm32/disass-2.s: New test.
* testsuite/gas/wasm32/reloc.d: Adjust test for changed reloc
names.
* testsuite/gas/wasm32/reloc.s: Update test for changed assembler
syntax.
* testsuite/gas/wasm32/wasm32.exp: Run new tests.  Expect allinsn
test to succeed.

7 years agoFix Windows gdb build failure with Python 2 support
Thomas Preud'homme [Thu, 6 Apr 2017 16:17:23 +0000 (17:17 +0100)]
Fix Windows gdb build failure with Python 2 support

GDB fails to build for Windows host with Python 2 support enabled due
to PyFile_FromString's second argument being of type char * and being
passed a (const) string literal. This parameter is input only so this
commit fixes the issue by casting to char *.

2017-04-06  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gdb/
* python/python.c (python_run_simple_file): Cast mode literal to
non-const char pointer as expected by PyFile_FromString.

7 years agombind tests: don't check PT_LOAD headers
Alan Modra [Thu, 6 Apr 2017 14:48:33 +0000 (00:18 +0930)]
mbind tests: don't check PT_LOAD headers

On powerpc-linux, the second PT_LOAD header is RWE.  On hppa64-linux,
only one PT_LOAD header is present.  Since the tests are really about
the new GNU_MBIND headers, ignore PT_LOAD and its section mapping.

* testsuite/ld-elf/mbind1a.d: Remove matches for PT_LOAD segments.
* testsuite/ld-elf/mbind1b.d: Likewise.
* testsuite/ld-elf/mbind1c.d: Likewise.

7 years agoRegen SRC-POTFILES.in
Alan Modra [Thu, 6 Apr 2017 14:47:09 +0000 (00:17 +0930)]
Regen SRC-POTFILES.in

Missed when elf-properties.c was added.

* po/SRC-POTFILES.in: Regenerate.

7 years ago[objcopy] Fix quadratic-time when handling --redefine-syms
Jiong Wang [Wed, 5 Apr 2017 16:22:47 +0000 (17:22 +0100)]
[objcopy] Fix quadratic-time when handling --redefine-syms

objcopy/
* objcopy.c (struct redefine_node): Delete the field "next".
(redefine_sym_list): Deleted.
(redefine_specific_htab): New hash table.
(redefine_specific_reverse_htab): Likewise.
(eq_string_redefnode): New function.
(htab_hash_redefnode): Likewise.
(create_symbol2redef_htab): Likewise.
(add_specific_symbol_node): Likewise.
(create_symbol_htabs): Create redefine_specific_htab and
redefine_specific_reverse_htab.
(lookup_sym_redefinition): Use hash table instead of list.
(redefine_list_append): Likewise, and rename to add_redefine_and_check.
(copy_main): Use redefine_specific_htab instead of redefine_sym_list.
Update comments.

7 years agoAutomatic date update in version.in
GDB Administrator [Thu, 6 Apr 2017 00:00:21 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoPR ld/21233: change xfails to kfails, fix the indentation issue
Hans-Peter Nilsson [Wed, 5 Apr 2017 21:12:16 +0000 (23:12 +0200)]
PR ld/21233: change xfails to kfails, fix the indentation issue

7 years agoptid_{lwp,tid}_p: Remove unnecessary checks
Simon Marchi [Wed, 5 Apr 2017 19:15:59 +0000 (15:15 -0400)]
ptid_{lwp,tid}_p: Remove unnecessary checks

The calls to ptid_equal in ptid_lwp_p and ptid_tid_p that compare the
argument to minus_one_ptid and null_ptid are not necessary.  The calls
in question are:

   if (ptid_equal (minus_one_ptid, ptid)
       || ptid_equal (null_ptid, ptid))
     return 0;

minus_one_ptid is { .pid = -1, .lwp = 0, .tid = 0 }
null_ptid is { .pid = 0, .lwp = 0, .tid = 0 }

If the ptid argument is either of them, the statements

  return (ptid_get_lwp (ptid) != 0);

and

  return (ptid_get_tid (ptid) != 0);

will yield the same result (0/false).

gdb/ChangeLog:

* common/ptid.c (ptid_lwp_p, ptid_tid_p): Remove comparison with
minus_one_ptid and null_ptid.

7 years ago-Wwrite-strings: Remove -Wno-write-strings
Pedro Alves [Wed, 5 Apr 2017 18:21:37 +0000 (19:21 +0100)]
-Wwrite-strings: Remove -Wno-write-strings

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:
2017-04-05  Pedro Alves  <palves@redhat.com>

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

gdb/gdbserver/ChangeLog:
2017-04-05  Pedro Alves  <palves@redhat.com>

* configure: Regenerate.

7 years ago-Wwrite-strings: The Rest
Pedro Alves [Wed, 5 Apr 2017 18:21:37 +0000 (19:21 +0100)]
-Wwrite-strings: The Rest

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

gdb/ChangeLog:
2017-04-05  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.
* 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.
* 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-thread-db.c (thread_db_err_str): 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_write_bytes)
(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:
2017-04-05  Pedro Alves  <palves@redhat.com>

* gdbreplay.c (sync_error): Constify.
* linux-x86-low.c (push_opcode): Constify.

7 years ago-Wwrite-strings: More Solaris
Pedro Alves [Wed, 5 Apr 2017 18:21:37 +0000 (19:21 +0100)]
-Wwrite-strings: More Solaris

Some obvious constifications found by attempting to build 64-bit GDB
on Solaris 11.

gdb/ChangeLog:
2017-04-05  Pedro Alves  <palves@redhat.com>

* proc-api.c (struct trans): Constify.
(procfs_note): Constify.
* proc-events.c (struct trans, syscall_table):
* proc-flags.c (struct trans): Constify.
* proc-utils.h (procfs_note): Constify.
* proc-why.c (struct trans): Constify.
* procfs.c (dead_procinfo, find_syscall, proc_warn, proc_error)
(procfs_detach): Constify.
* sol-thread.c (struct string_map): Constify.
(td_err_string, td_state_string): Constify.

7 years ago-Wwrite-strings: Fix Solaris "set procfs-file"
Pedro Alves [Wed, 5 Apr 2017 18:21:36 +0000 (19:21 +0100)]
-Wwrite-strings: Fix Solaris "set procfs-file"

Compiling GDB with -Wwrite-strings flags this code in gdb/proc-api.c:

  static char *procfs_filename = "procfs_trace";

as needing a cast.  However, this variable is a command variable, and
as such it's incorrect to initialize it to a literal, since when you
use the corresponding set command, gdb frees the old string...

I didn't manage to fully build Solaris gdb (fails for other reasons),
but I confirmed that the system GDB on Solaris 11 crashes when running
this command:

 (gdb) set procfs-file foo
 Segmentation Fault (core dumped)

So I don't think this commit can make it worse than the status quo.

gdb/ChangeLog:
2017-04-05  Pedro Alves  <palves@redhat.com>

* proc-api.c (procfs_filename): Don't initialize
        procfs_filename.
(prepare_to_trace): Assume procfs_filename is non-NULL.
(_initialize_proc_api): Give procfs_filename a default value here.

7 years ago-Wwrite-strings: Some constification in gdb/breakpoint.c
Pedro Alves [Wed, 5 Apr 2017 18:21:36 +0000 (19:21 +0100)]
-Wwrite-strings: Some constification in gdb/breakpoint.c

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
spiraling out of control, so instead I settled for keeping const and
non-const overloads.

gdb/ChangeLog:
2017-04-05  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.

7 years ago-Wwrite-strings: execute_command calls with string literals
Pedro Alves [Wed, 5 Apr 2017 18:21:36 +0000 (19:21 +0100)]
-Wwrite-strings: execute_command calls with string literals

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:
2017-04-05  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.

7 years ago-Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overload
Pedro Alves [Wed, 5 Apr 2017 18:21:36 +0000 (19:21 +0100)]
-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:
2017-04-05  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.

7 years ago-Wwrite-strings: Wrap PyGetSetDef for construction with string literals
Pedro Alves [Wed, 5 Apr 2017 18:21:36 +0000 (19:21 +0100)]
-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:
2017-04-05  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.