Commit Graph

39041 Commits

Author SHA1 Message Date
Sergio Durigan Junior 096c92ddb3 Fix build breakage on Cygwin (PR gdb/21385)
On gdb/windows-nat.c:windows_create_inferior, ALLARGS needs to be
declared independently of the host that we're building for.  This
fixes a build breakage on Cygwin.

2017-04-13  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR gdb/21385
	* windows-nat.c (windows_create_inferior): Declare 'allargs'
	independently of the host, and fix build breakage on Cygwin.
2017-04-13 21:01:53 -04:00
Pedro Alves 0550c95595 Make inferior a class with cdtors, and use new/delete
struct inferior became a non-POD when enum_flags was made a non-POD,
so we should be allocating/destroying inferiors with new/delete, etc.
That's what this commit does.

Note: this commit makes all boolean fields of inferior be "bool",
except the "detaching" field.  That'll require more work, so I split
it to a separate patch.

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

	* inferior.c (free_inferior): Convert to ...
	(inferior::~inferior): ... this dtor.
	(inferior::inferior): New ctor, factored out from ...
	(add_inferior_silent): ... here.  Allocate the inferior with a new
	expression.
	(delete_inferior): Call delete instead of free_inferior.
	* inferior.h (gdb_environ, continuation): Forward declare.
	(inferior): Now a class.  Add in-class initialization to all
	members.  Make boolean fields bool, except 'detaching'.
	(inferior::inferior): New explicit ctor.
	(inferior::~inferior): New.
2017-04-13 16:18:16 +01:00
Pedro Alves e3d60dfc00 GC inferior.c:init_inferior_list
Not used anywhere.  This was actually never used.  It came in because
I originally created inferior.c by copying thread.c, and doing
s/thread/inferior/g, and missed that nothing needs this.  :-)

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

	* inferior.c (init_inferior_list): Delete.
	* inferior.h (init_inferior_list): Delete.
2017-04-13 16:18:16 +01:00
Pedro Alves 5fd69d0ab2 Improve coverage of the PR threads/13217 regression test
- Make sure we end up with no thread selected after the detach.

- Test both "thread apply all" and "thread apply $some_threads", for
  completeness.

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

	PR threads/13217
	* gdb.threads/threadapply.exp (thr_apply_detach): New procedure.
	(top level): Call it twice, with different thread sets.
2017-04-13 16:18:16 +01:00
Pedro Alves c6609450b3 C++fy thread_apply_all_command
This eliminates a couple cleanups.

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

	* thread.c: Include <algorithm>.
	(thread_array_cleanup): Delete.
	(scoped_inc_dec_ref): New class.
	(live_threads_count): New function.
	(set_thread_refcount): Delete.
	(tp_array_compar_ascending): Now a bool.
	(tp_array_compar): Convert to a std::sort comparison function.
	(thread_apply_all_command): Use std::vector and scoped_inc_dec_ref
	and live_threads_count.
2017-04-13 16:18:16 +01:00
Pedro Alves 2a00d7ce26 Fix follow-fork latent bug
A later patch in the series adds an assertion to switch_to_thread that
the resulting inferior_ptid always matches the "current_inferior()"
inferior.  This exposed a latent bug in the follow-fork code, where
we're building the fork child inferior.  We're switching
inferior_ptid, but not the current inferior object...

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

	* infrun.c (follow_fork_inferior): Also switch the current
	inferior.
2017-04-13 16:18:16 +01:00
Pedro Alves 441d7c9378 watch_command_1: Fix dangling frame access
While working on some changes to switch_to_thread, I inadvertently
make switch_to_thread call reinit_frame_cache more frequently, even
when the thread didn't change.  This exposed a latent bug in
watch_command_1, where we're referencing a frame after
creating/inserting breakpoints, which potentially calls
reinit_frame_cache if it needs to install breakpoints with a different
thread selected.

Handle this similarly to how it's already handled in other similar
cases.  I.e., save any frame-related information we might need before
creating a breakpoint.

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

	* breakpoint.c (watch_command_1): Save watchpoint-frame info
	before calling create_internal_breakpoint.
2017-04-13 16:15:34 +01:00
Pedro Alves 808480f667 fork-child.c: Avoid unnecessary heap-allocation / string copying
The previous change to fork-child.c converted the argv building from
an alloca-allocated array of non-owning arg pointers, to a std::vector
of owning pointers, which results in N string dups, with N being the
number of arguments in the vector, and then requires manually
releasing the pointers owned by the vector.

This patch makes the vector hold non-owning pointers, and avoids the
string dups, by doing one single string copy of the arguments upfront,
and replacing separators with NULL terminators in place, like we used
to.  All the logic to do that is encapsulated in a new class.

With this, there's no need to remember to manually release the argv
elements with free_vector_argv either.

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

	* fork-child.c (execv_argv): New class.
	(breakup_args): Refactored as ...
	(execv_argv::init_for_no_shell): .. this method of execv_argv.
	Copy arguments to storage and replace separators with NULL
	terminators in place.
	(escape_bang_in_quoted_argument): Adjust to return bool.
	(execv_argv::execv_argv): New ctor.
	(execv_argv::init_for_shell): New method, factored out from
	fork_inferior.  Don't strdup strings into the vector.
	(fork_inferior): Eliminate "shell" local and use execv_argv.  Use
	Remove free_vector_argv call.
2017-04-13 11:46:07 +01:00
Iain Buclaw b1b45502bd Add ChangeLog entries
ChangeLog entries were left unstaged in my previous commit on March 30th.
2017-04-13 10:39:13 +02:00
Yao Qi ad3d022a77 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.
2017-04-13 08:29:44 +01:00
Yao Qi e6ddc3bfed 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.
2017-04-13 08:29:43 +01:00
Pedro Alves bfb8cf9091 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.
2017-04-13 03:07:21 +01:00
Pedro Alves f5336ca55c 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.
2017-04-13 02:12:53 +01:00
Sergio Durigan Junior be628ab814 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.
2017-04-12 17:59:45 -04:00
Tom Tromey 8e9e35b180 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.
2017-04-12 11:16:19 -06:00
Tom Tromey 16e802b9c0 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.
2017-04-12 11:16:19 -06:00
Tom Tromey d28cd78ad8 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.
2017-04-12 11:16:19 -06:00
Tom Tromey 711799d513 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.
2017-04-12 11:16:19 -06:00
Tom Tromey 52d214d3e1 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.
2017-04-12 11:16:19 -06:00
Tom Tromey 4c404b8be6 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.
2017-04-12 11:16:19 -06:00
Tom Tromey 156d9eab86 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.
2017-04-12 11:16:19 -06:00
Tom Tromey 4d89769a7b 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.
2017-04-12 11:16:18 -06:00
Tom Tromey 4b217cc72b 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.
2017-04-12 11:16:18 -06:00
Tom Tromey 59d3651be7 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.
2017-04-12 11:16:18 -06:00
Tom Tromey b24b0d6c3b 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.
2017-04-12 11:16:18 -06:00
Tom Tromey 80a3b8c578 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.
2017-04-12 11:16:18 -06:00
Tom Tromey c83dd86726 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.
2017-04-12 11:16:17 -06:00
Tom Tromey 0e8621a0be 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.
2017-04-12 11:16:17 -06:00
Tom Tromey 67d8990150 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.
2017-04-12 11:16:17 -06:00
Tom Tromey 93921405a4 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.
2017-04-12 11:16:17 -06:00
Tom Tromey ffc2605c41 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.
2017-04-12 11:16:17 -06:00
Pedro Alves 8f10c93233 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.
2017-04-12 16:00:04 +01:00
Simon Marchi 0a31ccfbd8 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 *.
2017-04-12 10:46:48 -04:00
Pedro Alves e9bb3fbbe8 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.
2017-04-12 14:14:56 +01:00
Pedro Alves 53375380e9 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.
2017-04-12 14:06:40 +01:00
Pedro Alves 53e710acd2 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.
2017-04-12 14:00:49 +01:00
Alan Hayward 5e0e042213 Fix Changelog for ab0538b875 2017-04-12 09:51:28 +01:00
Alan Hayward ab0538b875 Add M32R_ARG_REGISTER_SIZE
gdb/
	* m32r-tdep.c M32R_ARG_REGISTER_SIZE: Added.
	(m32r_push_dummy_call): Use M32R_ARG_REGISTER_SIZE.
2017-04-12 09:19:55 +01:00
Sergio Durigan Junior 5430098f18 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 *'.
2017-04-12 01:16:50 -04:00
Sergio Durigan Junior 7c5ded6a00 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.
2017-04-12 01:02:03 -04:00
Pedro Alves ae0eee4282 gdb/thread.c: Fix whitespace throughout
gdb/ChangeLog:
2017-04-11  Pedro Alves  <palves@redhat.com>

	* thread.c: Fix whitespace throughout.
2017-04-11 14:31:34 +01:00
Philipp Rudo a6acac0611 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.
2017-04-11 14:28:51 +01:00
Alan Hayward 64403bd183 Remove MAX_REGISTER_SIZE from arm-tdep.c
gdb/
	* arm-tdep.c (arm_store_return_value): Use FP_REGISTER_SIZE
2017-04-11 13:51:58 +01:00
Sergio Durigan Junior a5bef50fdb 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.
2017-04-10 12:43:44 -04:00
Pedro Alves 9295a5a95d 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.
2017-04-10 15:54:57 +01:00
Pedro Alves 996812e3d4 GC gdb/thread.c:current_thread_cleanup_chain
Commit 803bdfe430 ("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.
2017-04-10 15:18:49 +01:00
Alan Hayward 845b344fd5 msp430: Don't use REG_UNKNOWN
gdb/
	* msp430-tdep.c (msp430_pseudo_register_read): Never return
	REG_UNKNOWN.
2017-04-10 15:01:53 +01:00
Yao Qi 803bdfe430 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.
2017-04-10 14:39:41 +01:00
Yao Qi 8c25b49760 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.
2017-04-10 14:39:41 +01:00
Simon Marchi 8473b4472d 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.
2017-04-09 23:14:57 -04:00