Commit Graph

1120 Commits

Author SHA1 Message Date
Simon Marchi a933405894 remote: Return NULL extra_info/name if they are empty
Commit

  remote: C++ify thread_item and threads_listing_context
  21fe1c752e

broke the test gdb.threads/names.exp.  The problem is that since we now
use an std::string to hold the extra_info, an empty string is returned
by target_extra_thread_info to print_thread_info_1 when the remote stub
didn't send any extra info, instead of NULL before.  Because of that,
print_thread_info_1 prints the extra info between parentheses, which
results in some spurious empty parentheses.

  Expected: * 1    Thread 22752.22752 "main" all_threads_ready () at ...
  Actual  : * 1    Thread 22752.22752 "main" () all_threads_ready () a ...

Since the bug was introduced by a behavior change in the remote target,
I chose to fix it on the remote target side by making it return NULL
when the extra string is empty.  This will avoid possibly changing the
behavior of the common code and affecting other targets.

The name field has the same problem.  If a remote stub returns no thread
names, remote_thread_name will return an empty string instead of NULL,
so print_thread_info_1 will show empty quotes ("") instead of nothing.

gdb/ChangeLog:

	PR gdb/22556
	* remote.c (remote_thread_name): Return NULL if name is empty.
	(remote_threads_extra_info): Return NULL if extra info is empty.
2017-12-11 21:05:30 -05:00
Pedro Alves 649a140ccf target_set_syscall_catchpoint, use gdb::array_view and bool
I noticed that we're passing down a data/size pair to
target_ops::to_set_syscall_catchpoint.  This commit makes use of
gdb::array_view instead.  While at it, use bool where appropriate as
well.

gdb/ChangeLog:

	* break-catch-syscall.c (insert_catch_syscall)
	(remove_catch_syscall): Adjust to pass reference to
	inf_data->syscalls_counts directly via gdb::array_view.
	* fbsd-nat.c (fbsd_set_syscall_catchpoint): Adjust to use bool
	and gdb::array_view.
	* linux-nat.c (linux_child_set_syscall_catchpoint): Likewise.
	* remote.c (remote_set_syscall_catchpoint): Likewise.
	* target-debug.h (target_debug_print_bool): New.
	(define target_debug_print_gdb_array_view_const_int): New.
	* target-delegates.c: Regenerate.
	* target.h (target_ops) <to_set_syscall_catchpoint>: Use
	gdb::array_view and bool.
	(target_set_syscall_catchpoint): Likewise.
2017-12-06 17:49:37 -05:00
Pedro Alves 7cc244debb remote: Make qXfer packets respect corresponding "set remote foo-packet"
I've noticed that "set remote target-features-packet off" before
connecting has no effect -- GDB still fetches a target description
anyway.

The problem is that while most "set remote foo-packet" commands were
fixed by:

  From 4082afcc3d Mon Sep 17 00:00:00 2001
  From: Pedro Alves <palves@redhat.com>
  Date: Fri, 25 Apr 2014 18:07:02 +0100
  Subject: [PATCH] Fix several "set remote foo-packet on/off" commands.
  <https://sourceware.org/ml/gdb-patches/2014-04/msg00006.html>

the "qXfer" packets where missed.  This commit fixes that.

I've changed remote_search_memory too for consistency (seems like
those are the last direct references to packet->support), though the
difference is not observable because the qSearch:memory packet is auto
probed.  Note gdb.base/find-unmapped.exp already exercises explicit
"set remote search-memory-packet off".

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

	* remote.c (remote_query_supported): Don't send "xmlRegisters=" if
	"qXfer:features:read"" is disabled.
	(remote_write_qxfer, remote_read_qxfer, remote_search_memory):
	Check packet_config_support instead of packet->support directly.

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

	* gdb.arch/i386-avx.exp: If testing with a RSP target, check
	force-disabling XML descriptions.
--

 gdb/remote.c                        |   16 +++++++++-------
 gdb/testsuite/gdb.arch/i386-avx.exp |   25 +++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 7 deletions(-)
2017-12-06 11:28:47 +00:00
Simon Marchi 798a7429f9 Remove some unused variables
This patch removes some unused variables, found with -Wunused.  I have
not removed everything reported by -Wunused, because some expressions
such as

  struct type *arg_type = check_typedef (value_type);

in bfin-tdep.c could have an unexpected but important side-effect.  I
removed others that I considered more low-risk, such as:

  struct gdbarch *gdbarch = get_objfile_arch (objfile);

I tested building with Python 2/Python 3/no Python, with/without expat,
with/without libipt and with/without babeltrace.

gdb/ChangeLog:

	* ada-lang.c (ada_collect_symbol_completion_matches): Remove
	unused variables.
	(ada_is_redundant_range_encoding): Likewise.
	* ada-varobj.c (ada_varobj_get_value_of_array_variable):
	Likewise.
	* alpha-tdep.c (alpha_software_single_step): Likewise.
	* arm-tdep.c (_initialize_arm_tdep): Likewise.
	* auto-load.c (info_auto_load_cmd): Likewise.
	* break-catch-syscall.c (insert_catch_syscall): Likewise.
	(remove_catch_syscall): Likewise.
	* breakpoint.c (condition_completer): Likewise.
	(clear_command): Likewise.
	(update_breakpoint_locations): Likewise.
	* btrace.c (btrace_disable): Likewise.
	(btrace_teardown): Likewise.
	(btrace_maint_update_pt_packets): Likewise.
	(maint_btrace_clear_cmd): Likewise.
	* cli/cli-decode.c (lookup_cmd_1): Likewise.
	(lookup_cmd_composition): Likewise.
	* cli/cli-dump.c (scan_filename): Likewise.
	(restore_command): Likewise.
	* compile/compile-loc2c.c (compute_stack_depth): Likewise.
	* compile/compile-object-load.c (compile_object_load): Likewise.
	* compile/compile-object-run.c (compile_object_run): Likewise.
	* compile/compile.c (compile_to_object): Likewise.
	* completer.c (filename_completer): Likewise.
	(complete_files_symbols): Likewise.
	(complete_expression): Likewise.
	* corelow.c (core_open): Likewise.
	* ctf.c (ctf_start): Likewise.
	(ctf_write_status): Likewise.
	(ctf_write_uploaded_tsv): Likewise.
	(ctf_write_definition_end): Likewise.
	(ctf_open_dir): Likewise.
	(ctf_xfer_partial): Likewise.
	(ctf_trace_find): Likewise.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
	Likewise.
	* dwarf2loc.c (allocate_piece_closure): Likewise.
	(indirect_pieced_value): Likewise.
	(dwarf2_evaluate_loc_desc_full): Likewise.
	* dwarf2read.c (dw2_expand_marked_cus): Likewise.
	(dw2_expand_symtabs_matching): Likewise.
	(dw2_map_symbol_filenames): Likewise.
	(read_and_check_comp_unit_head): Likewise.
	(read_cutu_die_from_dwo): Likewise.
	(lookup_dwo_unit): Likewise.
	(read_comp_units_from_section): Likewise.
	(dwarf2_compute_name): Likewise.
	(handle_DW_AT_stmt_list): Likewise.
	(create_cus_hash_table): Likewise.
	(create_dwp_v2_section): Likewise.
	(dwarf2_rnglists_process): Likewise.
	(dwarf2_ranges_process): Likewise.
	(dwarf2_record_block_ranges): Likewise.
	(is_vtable_name): Likewise.
	(read_formatted_entries): Likewise.
	(skip_form_bytes): Likewise.
	* elfread.c (elf_symtab_read): Likewise.
	* exec.c (exec_file_command): Likewise.
	* f-valprint.c (f_val_print): Likewise.
	(info_common_command_for_block): Likewise.
	* guile/guile.c (initialize_scheme_side): Likewise.
	* guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Likewise.
	* guile/scm-cmd.c (cmdscm_completer): Likewise.
	(gdbscm_register_command_x): Likewise.
	* guile/scm-frame.c (gdbscm_frame_read_var): Likewise.
	* guile/scm-param.c (gdbscm_parameter_value): Likewise.
	* guile/scm-ports.c (file_port_magic): Likewise.
	* guile/scm-pretty-print.c (ppscm_search_pp_list): Likewise.
	(ppscm_pretty_print_one_value): Likewise.
	(ppscm_print_children): Likewise.
	* guile/scm-string.c (gdbscm_string_to_argv): Likewise.
	* guile/scm-symtab.c (gdbscm_sal_symtab): Likewise.
	* guile/scm-type.c (gdbscm_type_next_field_x): Likewise.
	* guile/scm-utils.c (gdbscm_parse_function_args): Likewise.
	* i386-tdep.c (i386_register_reggroup_p): Likewise.
	* infcmd.c (run_command_1): Likewise.
	(until_next_fsm_clean_up): Likewise.
	* linespec.c (linespec_complete): Likewise.
	(find_label_symbols): Likewise.
	* m2-valprint.c (m2_val_print): Likewise.
	* memattr.c (require_user_regions): Likewise.
	(lookup_mem_region): Likewise.
	(disable_mem_command): Likewise.
	(mem_delete): Likewise.
	* mep-tdep.c (mep_register_name): Likewise.
	(mep_analyze_prologue): Likewise.
	* mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Likewise.
	* mi/mi-interp.c (mi_on_sync_execution_done): Likewise.
	* mi/mi-main.c (mi_cmd_trace_frame_collected): Likewise.
	* microblaze-linux-tdep.c (microblaze_linux_init_abi): Likewise.
	* minidebug.c (lzma_open): Likewise.
	* minsyms.c (lookup_minimal_symbol): Likewise.
	* mips-linux-tdep.c (mips64_fill_fpregset): Likewise.
	* mips-tdep.c (mips_stub_frame_sniffer): Likewise.
	(mips_o64_return_value): Likewise.
	(mips_single_step_through_delay): Likewise.
	(_initialize_mips_tdep): Likewise.
	* nios2-tdep.c (nios2_push_dummy_call): Likewise.
	(nios2_software_single_step): Likewise.
	* parse.c (find_minsym_type_and_address): Likewise.
	* psymtab.c (psym_relocate): Likewise.
	* python/py-breakpoint.c (bppy_get_commands): Likewise.
	(gdbpy_breakpoint_modified): Likewise.
	* python/py-infevents.c (create_inferior_call_event_object):
	Likewise.
	* python/py-record-btrace.c (btpy_list_item): Likewise.
	* python/py-type.c (typy_str): Likewise.
	* python/py-value.c (valpy_call): Likewise.
	* python/python.c (do_start_initialization): Likewise.
	* record-btrace.c (record_btrace_insn_history_range): Likewise.
	(record_btrace_call_history_range): Likewise.
	(record_btrace_record_method): Likewise.
	(record_btrace_xfer_partial): Likewise.
	(btrace_get_frame_function): Likewise.
	* record-full.c (record_full_open): Likewise.
	* record.c (get_context_size): Likewise.
	* registry.h (DEFINE_REGISTRY): Likewise.
	* remote-fileio.c (remote_fileio_request): Likewise.
	* remote.c (remote_update_thread_list): Likewise.
	(remote_check_symbols): Likewise.
	(remote_commit_resume): Likewise.
	(remote_interrupt): Likewise.
	(remote_insert_breakpoint): Likewise.
	(compare_sections_command): Likewise.
	* rust-exp.y (super_name): Likewise.
	(lex_string): Likewise.
	(convert_ast_to_type): Likewise.
	(convert_ast_to_expression): Likewise.
	* rust-lang.c (rust_print_struct_def): Likewise.
	(rust_print_type): Likewise.
	(rust_evaluate_subexp): Likewise.
	* rx-tdep.c (rx_register_type): Likewise.
	* ser-event.c (serial_event_clear): Likewise.
	* serial.c (serial_open): Likewise.
	* spu-tdep.c (spu_overlay_new_objfile): Likewise.
	* symfile.c (section_is_overlay): Likewise.
	(overlay_unmapped_address): Likewise.
	(overlay_mapped_address): Likewise.
	(simple_overlay_update_1): Likewise.
	(simple_overlay_update): Likewise.
	* symtab.c (symbol_find_demangled_name): Likewise.
	(search_symbols): Likewise.
	* target-descriptions.c (tdesc_predefined_type): Likewise.
	* target.c (target_commit_resume): Likewise.
	* thread.c (print_selected_thread_frame): Likewise.
	* top.c (new_ui_command): Likewise.
	(gdb_readline_no_editing): Likewise.
	* tracefile-tfile.c (tfile_open): Likewise.
	* tracepoint.c (create_tsv_from_upload): Likewise.
	* utils.c (quit): Likewise.
	(defaulted_query): Likewise.
	* valarith.c (value_concat): Likewise.
	* xml-syscall.c (xml_list_syscalls_by_group): Likewise.
	* xml-tdesc.c (target_fetch_description_xml): Likewise.
	* xtensa-tdep.c (xtensa_pseudo_register_read): Likewise.
	(xtensa_pseudo_register_write): Likewise.

gdb/gdbserver/ChangeLog:

	* regcache.c (registers_to_string): Remove unused variable.
2017-12-05 16:05:50 -05:00
Simon Marchi 7aabaf9d4a Create private_thread_info hierarchy
There are multiple definitions of the private_thread_info structure
compiled in the same GDB build.  Because of the one definition rule, we
need to change this if we want to be able to make them non-POD (e.g. use
std::vector fields).  This patch creates a class hierarchy, with
private_thread_info being an abstract base class, and all the specific
implementations inheriting from it.

In order to poison XNEW/xfree for non-POD types, it is also needed to
get rid of the xfree in thread_info::~thread_info, which operates on an
opaque type.  This is replaced by thread_info::priv now being a
unique_ptr, which calls the destructor of the private_thread_info
subclass when the thread is being destroyed.

Including gdbthread.h from darwin-nat.h gave these errors:

/Users/simark/src/binutils-gdb/gdb/gdbthread.h:609:3: error: must use 'class' tag to refer to type 'thread_info' in this scope
  thread_info *m_thread;
  ^
  class
/usr/include/mach/thread_act.h:240:15: note: class 'thread_info' is hidden by a non-type declaration of 'thread_info' here
kern_return_t thread_info
              ^

It turns out that there is a thread_info function in the Darwin/XNU/mach API:

  http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/thread_info.html

Therefore, I had to add the class keyword at a couple of places in gdbthread.h,
I don't really see a way around it.

gdb/ChangeLog:

	* gdbthread.h (private_thread_info): Define structure type, add
	virtual pure destructor.
	(thread_info) <priv>: Change type to unique_ptr.
	<private_dtor>: Remove.
	* thread.c (add_thread_with_info): Adjust to use of unique_ptr.
	(private_thread_info::~private_thread_info): Provide default
	implementation.
	(thread_info::~thread_info): Don't call private_dtor nor
	manually free priv.
	* aix-thread.c (private_thread_info): Rename to ...
	(aix_thread_info): ... this.
	(get_aix_thread_info): New.
	(sync_threadlists): Adjust.
	(iter_tid): Adjust.
	(aix_thread_resume): Adjust.
	(aix_thread_fetch_registers): Adjust.
	(aix_thread_store_registers): Adjust.
	(aix_thread_extra_thread_info): Adjust.
	* darwin-nat.h (private_thread_info): Rename to ...
	(darwin_thread_info): ... this.
	(get_darwin_thread_info): New.
	* darwin-nat.c (darwin_init_thread_list): Adjust.
	(darwin_check_new_threads): Adjust.
	(thread_info_from_private_thread_info): Adjust.
	* linux-thread-db.c (private_thread_info): Rename to ...
	(thread_db_thread_info): ... this, initialize fields.
	(get_thread_db_thread_info): New.
	<dying>: Change type to bool.
	(update_thread_state): Adjust to type rename.
	(record_thread): Adjust to type rename an use of unique_ptr.
	(thread_db_pid_to_str): Likewise.
	(thread_db_extra_thread_info): Likewise.
	(thread_db_thread_handle_to_thread_info): Likewise.
	(thread_db_get_thread_local_address): Likewise.
	* nto-tdep.h (private_thread_info): Rename to ...
	(nto_thread_info): ... this, initialize fields.
	(get_nto_thread_info): New.
	<name>: Change type to std::string.
	* nto-tdep.c (nto_extra_thread_info): Adjust to type rename and
	use of unique_ptr.
	* nto-procfs.c (update_thread_private_data_name): Adjust to
	std::string change, allocate nto_private_thread_info with new.
	(update_thread_private_data): Adjust to unique_ptr.
	* remote.c (private_thread_info): Rename to ...
	(remote_thread_info): ... this, initialize data members with
	default values.
	<extra, name>: Change type to std::string.
	<thread_handle>: Change type to non-pointer.
	(free_private_thread_info): Remove.
	(get_private_info_thread): Rename to...
	(get_remote_thread_info): ... this, change return type, adjust to
	use of unique_ptr, use remote_thread_info constructor.
	(remote_add_thread): Adjust.
	(get_private_info_ptid): Rename to...
	(get_remote_thread_info): ...this, change return type.
	(remote_thread_name): Use get_remote_thread_info, adjust to
	change to std::string.
	(struct thread_item) <~thread_item>: Remove.
	<thread_handle>: Make non pointer.
	(start_thread): Adjust to thread_item::thread_handle type
	change.
	(remote_update_thread_list): Adjust to type name change, move
	strings from temporary to long-lived object instead of
	duplicating.
	(remote_threads_extra_info): Use get_remote_thread_info.
	(process_initial_stop_replies): Likewise.
	(resume_clear_thread_private_info): Likewise.
	(remote_resume): Adjust to type name change.
	(remote_commit_resume): Use get_remote_thread_info.
	(process_stop_reply): Adjust to type name change.
	(remote_stopped_by_sw_breakpoint): Use get_remote_thread_info.
	(remote_stopped_by_hw_breakpoint): Likewise.
	(remote_stopped_by_watchpoint): Likewise.
	(remote_stopped_data_address): Likewise.
	(remote_core_of_thread): Likewise.
	(remote_thread_handle_to_thread_info): Use
	get_private_info_thread, adjust to thread_handle field type
	change.
2017-11-24 10:40:31 -05:00
Simon Marchi 21fe1c752e remote: C++ify thread_item and threads_listing_context
This patch C++ifies the thread_item and threads_listing_context
structures in remote.c.  thread_item::{extra,name} are changed to
std::string.  As a result, there's a bit of awkwardness in
remote_update_thread_list, where we have to xstrdup those strings when
filling the private_thread_info structure.  This is removed in the
following patch, where private_thread_info is also C++ified and its
corresponding fields made std::string too.  The xstrdup then becomes an
std::move.

Other than that there's nothing really special, it's a usual day-to-day
VEC -> vector and char* -> std::string change.  It allows removing a
cleanup in remote_update_thread_list.

Note that an overload of hex2bin that returns a gdb::byte_vector is
added, with corresponding selftests.

gdb/ChangeLog:

	* remote.c (struct thread_item): Add constructor, disable copy
	construction and copy assignment, define default move
	construction and move assignment.
	<extra, name>: Change type to std::string.
	<core>: Initialize.
	<thread_handle>: Make non-pointer.
	(thread_item_t): Remove typedef.
	(DEF_VEC_O(thread_item_t)): Remove.
	(threads_listing_context) <contains_thread>: New method.
	<remove_thread>: New method.
	<items>: Change type to std::vector.
	(clear_threads_listing_context): Remove.
	(threads_listing_context_remove): Remove.
	(remote_newthread_step): Use thread_item constructor, adjust to
	change to std::vector.
	(start_thread): Use thread_item constructor, adjust to change to
	std::vector.
	(end_thread): Adjust to change to std::vector and std::string.
	(remote_get_threads_with_qthreadinfo): Use thread_item
	constructor, adjust to std::vector.
	(remote_update_thread_list): Adjust to change to std::vector and
	std::string, use threads_listing_context methods.
	(remove_child_of_pending_fork): Adjust.
	(remove_new_fork_children): Adjust.
	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add rsp-low-selftests.c.
	(SUBDIR_UNITTESTS_OBS): Add rsp-low-selftests.o.
	* unittests/rsp-low-selftests.c: New file.
	* common/rsp-low.h: Include common/byte-vector.h.
	(hex2bin): New overload.
	* common/rsp-low.c (hex2bin): New overload.
2017-11-24 10:40:15 -05:00
Simon Marchi 089354bb06 Create private_inferior class hierarchy
There are currently multiple definitions of private_inferior, defined in
remote.c and darwin-nat.h.  The patch that poisons XNEW and friends for
non-POD types trips on that, because private_inferior is freed in
~inferior(), where it is an opaque type.  Since the compiler can't tell
whether the type is POD, it gives an error.  Also, we can't start using
C++ features in these structures (make them non-POD) as long as there
are multiple definitions with the same name.  For these reasons, this
patch makes a class hierarchy, with private_inferior being the abstract
base class, and darwin_inferior & remote_inferior inheriting from it.
Destruction is done through the virtual destructor.

I stumbled on some suspicious code in the darwin implementation though.
darwin_check_new_threads does an XCNEW(darwin_thread_t) when it finds a
new thread, allocating a new structure for it (darwin_thread_t is a
typedef for private_thread_info).  It then VEC_safe_pushes it in a
vector defined as DEF_VEC_O (a vector of objects).  This means that the
structure content gets copied in the vector.  The thread_info object is
created with the XCNEW'ed structure as the private thread info, while
the rest of the code works with the instance in the vector.  We have
therefore two distinct instances of darwin_thread_t/private_thread_info
for each thread.  This is not really a problem in practice, because
thread_info::priv is not used in the darwin code.  I still find it weird
and far from ideal, so I tried to fix it by changing the vector to be a
vector of pointers.  There should now be a single instance of the
structure for each thread.  The deallocation of the
darwin_thread_t/private_thread_info structure is done by the thread_info
destructor.

I am able to build on macOS, but not really test, since the port seems a
bit broken.  I am not able to debug reliably on the machine I have
access to, which runs macOS 10.12.6.

gdb/ChangeLog:

	* inferior.h (private_inferior): Define structure type, add
	virtual pure destructor.
	(inferior) <priv>: Change type to unique_ptr.
	* inferior.c (private_inferior::~private_inferior): Provide
	default implementation.
	(inferior::~inferior): Don't free priv field.
	(exit_inferior_1): Likewise.
	* darwin-nat.h (struct darwin_exception_info): Initialize fields.
	(darwin_exception_info): Remove typedef.
	(DEF_VEC_O (darwin_thread_t)); Remove.
	(private_inferior): Rename to ...
	(darwin_private_inferior): ... this, extend private_inferior.
	(get_darwin_inferior): New.
	<threads>: Change type to std::vector of darwin_thread_t pointers.
	* darwin-nat.c (darwin_check_new_threads): Adjust.
	(find_inferior_task_it): Adjust.
	(darwin_find_thread); Adjust.
	(darwin_suspend_inferior): Adjust.
	(darwin_resume_inferior): Adjust.
	(darwin_find_new_inferior): Adjust.
	(darwin_decode_notify_message): Adjust.
	(darwin_send_reply): Adjust.
	(darwin_resume_inferior_threads): Adjust.
	(darwin_suspend_inferior_threads): Adjust.
	(darwin_decode_message): Adjust.
	(darwin_wait): Adjust.
	(darwin_interrupt): Adjust.
	(darwin_deallocate_threads): Adjust.
	(darwin_mourn_inferior): Adjust, don't free private data.
	(darwin_reply_to_all_pending_messages): Adjust.
	(darwin_stop_inferior): Adjust.
	(darwin_setup_exceptions): Adjust.
	(darwin_kill_inferior): Adjust.
	(darwin_setup_request_notification): Adjust.
	(darwin_attach_pid): Adjust.
	(darwin_init_thread_list): Adjust.
	(darwin_setup_fake_stop_event): Adjust.
	(darwin_attach): Adjust.
	(darwin_detach): Adjust.
	(darwin_xfer_partial): Adjust.
	(set_enable_mach_exceptions): Adjust.
	(darwin_pid_to_exec_file): Adjust.
	(darwin_get_ada_task_ptid): Adjust.
	* darwin-nat-info.c (get_task_from_args): Adjust.
	(info_mach_ports_command): Adjust.
	(info_mach_region_command): Adjust.
	(info_mach_exceptions_command): Adjust.
	* remote.c (private_inferior): Rename to ...
	(remote_private_inferior): ... this, initialize fields.
	(get_remote_inferior); New.
	(remote_commit_resume): Use get_remote_inferior.
	(check_pending_event_prevents_wildcard_vcont_callback): Likewise.
2017-11-24 10:39:31 -05:00
Paul Carroll 92ffd47519 Fix 'xfered>0' assertion in target.c for remote connection
We have a customer who is using a Corelis gdb server to connect to gdb.
Occasionally, the gdb server will send a 0-byte block of memory for a
read.  When this happens, gdb gives an assertion from target.c:

internal-error: target_xfer_partial: Assertion `*xfered_len > 0' failed.

This problem is almost identical to that fixed in
https://sourceware.org/ml/gdb-patches/2014-02/msg00636.html

In this case, remote.c needs to be modified to return TARGET_XFER_EOF
instead of TARGET_XFER_OK or TARGET_XFER_UNAVAILABLE when 0 bytes are
transferred.

gdb/ChangeLog:

	PR gdb/22388
	* remote.c (remote_write_bytes_aux, remote_read_bytes_1,
	remote_read_bytes, remote_write_qxfer, remote_xfer_partial):
	Return TARGET_XFER_EOF if size of returned data is 0.
2017-11-14 17:39:24 -05:00
Simon Marchi b44ec61915 Make encode_actions_rsp use std::vector
Currently, encode_actions_rsp returns two malloc'ed arrays of malloc'ed
strings (char *) by pointer.  Change this to use
std::vector<std::string>.  This eliminates some cleanups in remote.c.

Regtested on the buildbot.

gdb/ChangeLog:

	* tracepoint.h (class collection_list) <stringify>: Return
	std::vector<std::string>.
	(encode_actions_rsp): Change parameters to
	std::vector<std::string> *.
	* tracepoint.c (collection_list::stringify): Return
	std::vector<std::string> and adjust accordingly.
	(encode_actions_rsp): Changee parameters to
	std::vector<std::string> and adjust accordingly.
	* remote.c (free_actions_list),
	free_actions_list_cleanup_wrapper): Remove.
	(remote_download_tracepoint): Adjust to std::vector.
2017-11-08 19:42:08 -05:00
Tom Tromey eb4c3f4aaa Constify add_setshow_*
This constifies the add_setshow_* family of functions, and then fixes
up the fallout.  The bulk of this patch was written by script.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (catch_ada_exception_command): Constify.
	(catch_assert_command): Constify.
	* break-catch-throw.c (catch_catch_command, catch_throw_command)
	(catch_rethrow_command): Constify.
	(catch_exception_command_1): Constify.
	* breakpoint.h (add_catch_command): Constify.
	* break-catch-syscall.c (catch_syscall_command_1): Constify.
	(catch_syscall_split_args): Constify.
	* break-catch-sig.c (catch_signal_command): Constify.
	(catch_signal_split_args): Constify.
	* cli/cli-decode.h (struct cmd_list_element) <function>: Use
	cmd_const_sfunc_ftype.
	* cli/cli-decode.c (add_setshow_cmd_full): Constify.
	(add_setshow_enum_cmd, add_setshow_auto_boolean_cmd)
	(add_setshow_boolean_cmd, add_setshow_filename_cmd)
	(add_setshow_string_cmd, struct cmd_list_element)
	(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
	(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
	(add_setshow_zuinteger_unlimited_cmd, add_setshow_zuinteger_cmd):
	Constify.
	(set_cmd_sfunc): Constify.
	(empty_sfunc): Constify.
	* command.h (add_setshow_enum_cmd, add_setshow_auto_boolean_cmd)
	(add_setshow_boolean_cmd, add_setshow_filename_cmd)
	(add_setshow_string_cmd, add_setshow_string_noescape_cmd)
	(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
	(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
	(add_setshow_zuinteger_cmd, add_setshow_zuinteger_unlimited_cmd):
	Constify.
	(set_cmd_sfunc): Constify.
	(cmd_sfunc_ftype): Remove.
	* compile/compile.c (set_compile_args): Constify.
	* infrun.c (set_disable_randomization): Constify.
	* infcmd.c (set_args_command, set_cwd_command): Constify.
	* breakpoint.c (set_condition_evaluation_mode): Constify.
	(add_catch_command): Constify.
	(catch_fork_command_1, catch_exec_command_1)
	(catch_load_command_1, catch_unload_command_1): Constify.
	(catch_load_or_unload): Constify.
	* guile/scm-param.c (pascm_set_func): Constify.
	(add_setshow_generic): Constify.
	* python/py-param.c (get_set_value): Constify.
	* top.h (set_verbose): Constify.
	* tui/tui-win.c (tui_set_var_cmd): Constify.
	* mi/mi-main.c (set_mi_async_command): Constify.
	* cli/cli-logging.c (set_logging_overwrite)
	(set_logging_redirect): Constify.
	* value.c (set_max_value_size): Constify.
	* valprint.c (set_input_radix, set_output_radix): Constify.
	* utils.c (set_width_command, set_height_command): Constify.
	* typeprint.c (set_print_type_methods, set_print_type_typedefs): Constify.
	* tracepoint.c (set_disconnected_tracing)
	(set_circular_trace_buffer, set_trace_buffer_size)
	(set_trace_user, set_trace_notes, set_trace_stop_notes): Constify.
	* top.c (set_history_size_command, set_verbose, set_editing)
	(set_gdb_datadir, set_history_filename): Constify.
	* target.c (set_targetdebug, maint_set_target_async_command)
	(maint_set_target_non_stop_command, set_target_permissions)
	(set_write_memory_permission): Constify.
	(open_target): Constify.
	* target-descriptions.c (set_tdesc_filename_cmd): Constify.
	* target-dcache.c (set_stack_cache, set_code_cache): Constify.
	* symtab.c (set_symbol_cache_size_handler): Constify.
	* symfile.c (set_ext_lang_command): Constify.
	* symfile-debug.c (set_debug_symfile): Constify.
	* source.c (set_directories_command): Constify.
	* solib.c (reload_shared_libraries, gdb_sysroot_changed): Constify.
	* serial.c (set_parity): Constify.
	* rs6000-tdep.c (powerpc_set_soft_float, powerpc_set_vector_abi): Constify.
	* remote.c (set_remote_exec_file, set_remotebreak)
	(set_remote_protocol_Z_packet_cmd, set_range_stepping): Constify.
	* record.c (set_record_insn_history_size)
	(set_record_call_history_size): Constify.
	* record-full.c (set_record_full_insn_max_num): Constify.
	* proc-api.c (set_procfs_trace_cmd, set_procfs_file_cmd): Constify.
	* osabi.c (set_osabi): Constify.
	* mips-tdep.c (set_mips64_transfers_32bit_regs)
	(reinit_frame_cache_sfunc, mips_abi_update): Constify.
	* maint.c (maintenance_set_profile_cmd): Constify.
	* linux-thread-db.c (set_libthread_db_search_path): Constify.
	* language.c (set_language_command, set_range_command)
	(set_case_command): Constify.
	* infrun.c (set_non_stop, set_observer_mode)
	(set_stop_on_solib_events, set_schedlock_func)
	(set_exec_direction_func): Constify.
	* infcmd.c (set_inferior_tty_command): Constify.
	* disasm.c (set_disassembler_options_sfunc): Constify.
	* demangle.c (set_demangling_command): Constify.
	* dcache.c (set_dcache_size, set_dcache_line_size): Constify.
	* cris-tdep.c (set_cris_version, set_cris_mode)
	(set_cris_dwarf2_cfi): Constify.
	* corefile.c (set_gnutarget_command): Constify.
	* charset.c (set_host_charset_sfunc, set_target_charset_sfunc)
	(set_target_wide_charset_sfunc): Constify.
	* breakpoint.c (update_dprintf_commands): Constify.
	* auto-load.c (set_auto_load_dir, set_auto_load_safe_path): Constify.
	* arm-tdep.c (set_fp_model_sfunc, arm_set_abi)
	(set_disassembly_style_sfunc): Constify.
	* arch-utils.c (set_endian, set_architecture): Constify.
	* alpha-tdep.c (reinit_frame_cache_sfunc): Constify.
	* agent.c (set_can_use_agent): Constify.
2017-11-07 13:59:09 -07:00
Tom Tromey 0b39b52e6e Constify add_com
This changes add_com to take a cmd_const_cfunc_ftype, and then fixes
up all the command implementations.

In most cases this is trivial.

In a couple of places I had to again introduce a temporary non-const
overload.  These overloads will be removed when add_info is
constified.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* solib.h (no_shared_libraries): Constify.
	* frame.h (return_command): Constify.
	* cli/cli-cmds.h (quit_command): Constify.
	* top.h (quit_command, execute_command): Constify.
	* target.h (flash_erase_command): Constify.
	* inferior.h (set_inferior_args, attach_command): Constify.
	* tracepoint.h (start_tracing, stop_tracing): Constify.
	* breakpoint.h (break_command, tbreak_command)
	(hbreak_command_wrapper, thbreak_command_wrapper)
	(rbreak_command_wrapper, watch_command_wrapper)
	(awatch_command_wrapper, rwatch_command_wrapper)
	(get_tracepoint_by_number): Constify.
	* symtab.c (info_variables_command, rbreak_command)
	(symtab_symbol_info): Constify.
	(info_variables_command): Add non-const overload.
	* top.c (dont_repeat_command): Constify.
	* breakpoint.c (ignore_command, commands_command)
	(condition_command, tbreak_command, hbreak_command)
	(thbreak_command, clear_command, break_command)
	(info_breakpoints_command, watch_command, rwatch_command)
	(awatch_command, trace_command, ftrace_command, strace_command)
	(trace_pass_command, break_range_command, dprintf_command)
	(agent_printf_command, get_tracepoint_by_number)
	(watch_maybe_just_location, trace_pass_command): Constify.
	(info_breakpoints_command): Add non-const overload.
	* tracefile.c (tsave_command): Constify.
	* infcmd.c (attach_command, disconnect_command, signal_command)
	(queue_signal_command, stepi_command, nexti_command)
	(finish_command, next_command, step_command, until_command)
	(advance_command, jump_command, continue_command, run_command)
	(start_command, starti_command, interrupt_command)
	(run_command_1, set_inferior_args, step_1): Constify.
	* inferior.c (add_inferior_command, remove_inferior_command)
	(clone_inferior_command): Constify.
	* linux-fork.c (checkpoint_command, restart_command): Constify.
	* windows-nat.c (signal_event_command): Constify.
	* guile/guile.c (guile_repl_command, guile_command): Constify.
	* printcmd.c (x_command, display_command, printf_command)
	(output_command, set_command, call_command, print_command)
	(eval_command): Constify.
	(non_const_set_command): Remove.
	(_initialize_printcmd): Update.
	* source.c (forward_search_command, reverse_search_command):
	Constify.
	* jit.c (jit_reader_load_command, jit_reader_unload_command):
	Constify.
	* infrun.c (handle_command): Constify.
	* memattr.c (mem_command): Constify.
	* stack.c (return_command, up_command, up_silently_command)
	(down_command, down_silently_command, frame_command)
	(backtrace_command, func_command, backtrace_command_1): Constify.
	(backtrace_command): Add non-const overload.
	* remote-sim.c (simulator_command): Constify.
	* exec.c (set_section_command): Constify.
	* tracepoint.c (tdump_command, trace_variable_command)
	(tstatus_command, tstop_command, tstart_command)
	(end_actions_pseudocommand, while_stepping_pseudocommand)
	(collect_pseudocommand, teval_pseudocommand, actions_command)
	(start_tracing, stop_tracing): Constify.
	* value.c (init_if_undefined_command): Constify.
	* tui/tui-stack.c (tui_update_command): Constify.
	* tui/tui-win.c (tui_refresh_all_command)
	(tui_set_tab_width_command, tui_set_win_height_command)
	(tui_set_focus_command, tui_scroll_forward_command)
	(tui_scroll_backward_command, tui_scroll_left_command)
	(tui_scroll_right_command, parse_scrolling_args, tui_set_focus)
	(tui_set_win_height): Constify.
	* tui/tui-layout.c (tui_layout_command): Constify.
	* procfs.c (proc_trace_syscalls, proc_trace_sysentry_cmd)
	(proc_trace_sysexit_cmd, proc_untrace_sysentry_cmd)
	(proc_untrace_sysexit_cmd): Constify.
	* remote.c (threadlist_test_cmd, threadinfo_test_cmd)
	(threadset_test_cmd, threadlist_update_test_cmd)
	(threadalive_test): Constify.
	* objc-lang.c (print_object_command): Constify.
	* command.h (add_com): Constify.
	* cli/cli-dump.c (restore_command): Constify.
	* cli/cli-cmds.c (pwd_command, echo_command, quit_command)
	(help_command, complete_command, shell_command, edit_command)
	(list_command, disassemble_command, make_command)
	(apropos_command, alias_command): Constify.
	* cli/cli-script.c (document_command, define_command)
	(while_command, if_command, validate_comname): Constify.
	* cli/cli-decode.c (struct cmd_list_element): Change type of
	"fun".
	* target.c (do_monitor_command, flash_erase_command): Constify.
	* regcache.c (reg_flush_command): Constify.
	* reverse.c (reverse_step, reverse_next, reverse_stepi)
	(reverse_nexti, reverse_continue, reverse_finish)
	(save_bookmark_command, goto_bookmark_command)
	(exec_reverse_once): Constify.
	* python/python.c (python_interactive_command, python_command):
	Constify.
	* typeprint.c (ptype_command, whatis_command, whatis_exp):
	Constify.
	* solib.c (sharedlibrary_command, no_shared_libraries): Constify.
	* gcore.c (gcore_command): Constify.
2017-11-07 13:59:09 -07:00
Pedro Alves 1b81856f5b remote.c, QCatchSyscalls: Build std::string instead of unique_xmalloc_ptr
Simplify the code a little bit using std::string + string_appendf.

gdb/ChangeLog:
2017-10-30  Pedro Alves  <palves@redhat.com>
	    Simon Marchi <simon.marchi@ericsson.com>

	* remote.c (remote_set_syscall_catchpoint): Build a std::string
	instead of a gdb::unique_xmalloc_ptr, using string_appendf.
2017-10-30 11:41:34 +00:00
Pedro Alves 23cc4e1b28 Garbage collect remote.c:remote_async_terminal_ours_p
remote.c:remote_async_terminal_ours_p stopped being useful after
048094accc ("target remote: Don't rely on immediate_quit (introduce
quit handlers)") and commit 41fd2b0f5d ("Make input_fd be per UI"),
which turned remote's terminal_inferior/ours methods into nops.

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

	* remote.c (remote_async_terminal_ours_p): Delete.
	(remote_open_1, remote_terminal_inferior, remote_terminal_ours):
	Remove references to 'remote_async_terminal_ours_p'.
2017-10-26 19:53:03 +01:00
Yao Qi ac7936dfd0 s/get_regcache_arch (regcache)/regcache->arch ()/g
This patches removes get_regcache_arch, and use regache->arch () instead.
The motivation of this change is that I am going to move some basic stuff
into a base class of regcache.  I don't need to update "client" code
regcache->arch ().  On the other hand, this patch shortens the code a
little bit.

gdb:

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

	* aarch32-linux-nat.c (aarch32_gp_regcache_supply): Use
	regcache->arch () instead get_regcache_arch.
	* aarch64-fbsd-nat.c (aarch64_fbsd_fetch_inferior_registers):
	Likewise.
	(aarch64_fbsd_store_inferior_registers): Likewise.
	* aarch64-linux-nat.c (fetch_gregs_from_thread): Likewise.
	(store_gregs_to_thread): Likewise.
	(fetch_fpregs_from_thread): Likewise.
	(store_fpregs_to_thread): Likewise.
	* aarch64-tdep.c (aarch64_extract_return_value): Likewise.
	(aarch64_store_return_value): Likewise.
	(aarch64_software_single_step): Likewise.
	* aix-thread.c (aix_thread_wait): Likewise.
	(supply_reg32): Likewise.
	(supply_sprs64): Likewise.
	(supply_sprs32): Likewise.
	(fill_gprs64): Likewise.
	(fill_gprs32): Likewise.
	(fill_sprs64): Likewise.
	(fill_sprs32): Likewise.
	(store_regs_user_thread): Likewise.
	(store_regs_kernel_thread): Likewise.
	* alpha-bsd-nat.c (alphabsd_fetch_inferior_registers): Likewise.
	(alphabsd_store_inferior_registers): Likewise.
	* alpha-tdep.c (alpha_extract_return_value): Likewise.
	(alpha_store_return_value): Likewise.
	(alpha_deal_with_atomic_sequence): Likewise.
	(alpha_next_pc): Likewise.
	(alpha_software_single_step): Likewise.
	* amd64-bsd-nat.c (amd64bsd_fetch_inferior_registers): Likewise.
	(amd64bsd_store_inferior_registers): Likewise.
	* amd64-linux-nat.c (amd64_linux_fetch_inferior_registers):
	Likewise.
	(amd64_linux_store_inferior_registers): Likewise.
	* amd64-nat.c (amd64_supply_native_gregset): Likewise.
	(amd64_collect_native_gregset): Likewise.
	* amd64-obsd-tdep.c (amd64obsd_supply_uthread): Likewise.
	(amd64obsd_collect_uthread): Likewise.
	* amd64-tdep.c (amd64_supply_fpregset): Likewise.
	(amd64_collect_fpregset): Likewise.
	(amd64_supply_fxsave): Likewise.
	(amd64_supply_xsave): Likewise.
	(amd64_collect_fxsave): Likewise.
	(amd64_collect_xsave): Likewise.
	* arc-tdep.c (arc_write_pc): Likewise.
	* arch-utils.c (default_skip_permanent_breakpoint): Likewise.
	* arm-fbsd-nat.c (arm_fbsd_fetch_inferior_registers): Likewise.
	(arm_fbsd_store_inferior_registers): Likewise.
	* arm-linux-nat.c (fetch_vfp_regs): Likewise.
	(store_vfp_regs): Likewise.
	(arm_linux_fetch_inferior_registers): Likewise.
	(arm_linux_store_inferior_registers): Likewise.
	* arm-linux-tdep.c (arm_linux_supply_gregset): Likewise.
	(arm_linux_sigreturn_next_pc): Likewise.
	(arm_linux_get_next_pcs_syscall_next_pc): Likewise.
	* arm-nbsd-nat.c (arm_supply_gregset): Likewise.
	(fetch_register): Likewise.
	(store_register): Likewise.
	* arm-tdep.c (arm_is_thumb): Likewise.
	(displaced_in_arm_mode): Likewise.
	(bx_write_pc): Likewise.
	(arm_get_next_pcs_addr_bits_remove): Likewise.
	(arm_software_single_step): Likewise.
	(arm_extract_return_value): Likewise.
	(arm_store_return_value): Likewise.
	(arm_write_pc): Likewise.
	* bfin-tdep.c (bfin_extract_return_value): Likewise.
	* bsd-uthread.c (bsd_uthread_fetch_registers): Likewise.
	(bsd_uthread_store_registers): Likewise.
	* core-regset.c (fetch_core_registers): Likewise.
	* corelow.c (get_core_registers): Likewise.
	* cris-tdep.c (cris_store_return_value): Likewise.
	(cris_extract_return_value): Likewise.
	(find_step_target): Likewise.
	(find_step_target): Likewise.
	(cris_software_single_step): Likewise.
	* ctf.c (ctf_fetch_registers): Likewise.
	* darwin-nat.c (cancel_breakpoint): Likewise.
	* fbsd-tdep.c (fbsd_collect_thread_registers): Likewise.
	* frv-tdep.c (frv_extract_return_value): Likewise.
	* ft32-tdep.c (ft32_store_return_value): Likewise.
	(ft32_extract_return_value): Likewise.
	* go32-nat.c (fetch_register): Likewise.
	(go32_fetch_registers): Likewise.
	(go32_store_registers): Likewise.
	(store_register): Likewise.
	* h8300-tdep.c (h8300_extract_return_value): Likewise.
	(h8300_store_return_value): Likewise.
	* hppa-linux-nat.c (fetch_register): Likewise.
	(store_register): Likewise.
	(hppa_linux_fetch_inferior_registers): Likewise.
	(hppa_linux_store_inferior_registers): Likewise.
	* i386-darwin-nat.c (i386_darwin_fetch_inferior_registers): Likewise.
	(i386_darwin_store_inferior_registers): Likewise.
	* i386-gnu-nat.c (gnu_fetch_registers): Likewise.
	(gnu_store_registers): Likewise.
	* i386-linux-nat.c (fetch_register): Likewise.
	(store_register): Likewise.
	(supply_gregset): Likewise.
	(fill_gregset): Likewise.
	(i386_linux_fetch_inferior_registers): Likewise.
	(i386_linux_store_inferior_registers): Likewise.
	(i386_linux_resume): Likewise.
	* i386-linux-tdep.c (i386_linux_get_syscall_number_from_regcache):
	Likewise.
	* i386-nto-tdep.c (i386nto_supply_gregset): Likewise.
	* i386-obsd-nat.c (i386obsd_supply_pcb): Likewise.
	* i386-obsd-tdep.c (i386obsd_supply_uthread): Likewise.
	(i386obsd_collect_uthread): Likewise.
	* i386-tdep.c (i386_mmx_regnum_to_fp_regnum): Likewise.
	(i386_supply_gregset): Likewise.
	(i386_collect_gregset): Likewise.
	(i386_supply_fpregset): Likewise.
	(i386_collect_fpregset): Likewise.
	(i386_mpx_bd_base): Likewise.
	* i386-v4-nat.c	(supply_fpregset): Likewise.
	(fill_fpregset): Likewise.
	* i387-tdep.c (i387_supply_fsave): Likewise.
	(i387_collect_fsave): Likewise.
	(i387_supply_fxsave): Likewise.
	(i387_collect_fxsave): Likewise.
	(i387_supply_xsave): Likewise.
	(i387_collect_xsave): Likewise.
	* ia64-linux-nat.c (ia64_linux_fetch_registers): Likewise.
	(ia64_linux_store_registers): Likewise.
	* ia64-tdep.c (ia64_access_rse_reg): Likewise.
	(ia64_extract_return_value): Likewise.
	(ia64_store_return_value): Likewise.
	(find_func_descr): Likewise.
	* inf-child.c (inf_child_fetch_inferior_registers): Likewise.
	* inf-ptrace.c (inf_ptrace_fetch_registers): Likewise.
	(inf_ptrace_store_registers): Likewise.
	* infrun.c (use_displaced_stepping): Likewise.
	(displaced_step_prepare_throw): Likewise.
	(resume): Likewise.
	(proceed): Likewise.
	(do_target_wait): Likewise.
	(adjust_pc_after_break): Likewise.
	(handle_inferior_event_1): Likewise.
	(handle_signal_stop): Likewise.
	(save_infcall_suspend_state): Likewise.
	(restore_infcall_suspend_state): Likewise.
	* iq2000-tdep.c (iq2000_extract_return_value): Likewise.
	* jit.c (jit_frame_prev_register): Likewise.
	* linux-nat.c (save_stop_reason): Likewise.
	(linux_nat_wait_1): Likewise.
	(resume_stopped_resumed_lwps): Likewise.
	* linux-record.c (record_linux_sockaddr): Likewise.
	(record_linux_msghdr): Likewise.
	(record_linux_system_call): Likewise.
	* linux-tdep.c (linux_collect_thread_registers): Likewise.
	* lm32-tdep.c (lm32_extract_return_value): Likewise.
	(lm32_store_return_value): Likewise.
	* m32c-tdep.c (m32c_read_flg): Likewise.
	(m32c_pseudo_register_read): Likewise.
	(m32c_pseudo_register_write): Likewise.
	* m32r-linux-tdep.c (m32r_linux_supply_gregset): Likewise.
	(m32r_linux_collect_gregset): Likewise.
	* m32r-tdep.c (m32r_store_return_value): Likewise.
	(m32r_extract_return_value): Likewise.
	* m68k-bsd-nat.c (m68kbsd_supply_fpregset): Likewise.
	(m68kbsd_collect_fpregset): Likewise.
	* m68k-bsd-tdep.c (m68kbsd_supply_fpregset): Likewise.
	* m68k-linux-nat.c (fetch_register): Likewise.
	(old_fetch_inferior_registers): Likewise.
	(old_store_inferior_registers): Likewise.
	(store_regs): Likewise.
	* m68k-tdep.c (m68k_svr4_extract_return_value): Likewise.
	(m68k_svr4_store_return_value): Likewise.
	* m88k-tdep.c (m88k_store_arguments): Likewise.
	* mi/mi-main.c (mi_cmd_data_list_changed_registers): Likewise.
	(mi_cmd_data_write_register_values): Likewise.
	* mips-fbsd-nat.c (mips_fbsd_fetch_inferior_registers): Likewise.
	(mips_fbsd_store_inferior_registers): Likewise.
	* mips-fbsd-tdep.c (mips_fbsd_supply_fpregs): Likewise.
	(mips_fbsd_supply_gregs): Likewise.
	(mips_fbsd_collect_fpregs): Likewise.
	(mips_fbsd_collect_gregs): Likewise.
	(mips_fbsd_supply_fpregset): Likewise.
	(mips_fbsd_collect_fpregset): Likewise.
	(mips_fbsd_supply_gregset): Likewise.
	(mips_fbsd_collect_gregset): Likewise.
	* mips-linux-nat.c (supply_gregset): Likewise.
	(fill_gregset): Likewise.
	(supply_fpregset): Likewise.
	(fill_fpregset): Likewise.
	* mips-linux-tdep.c (mips_supply_gregset): Likewise.
	(mips_fill_gregset): Likewise.
	(mips_supply_fpregset): Likewise.
	(mips_fill_fpregset): Likewise.
	(mips64_supply_gregset): Likewise.
	(micromips_linux_sigframe_validate): Likewise.
	* mips-nbsd-nat.c (mipsnbsd_fetch_inferior_registers): Likewise.
	(mipsnbsd_fetch_inferior_registers): Likewise.
	(mipsnbsd_store_inferior_registers): Likewise.
	* mips-nbsd-tdep.c (mipsnbsd_supply_fpregset): Likewise.
	(mipsnbsd_supply_gregset): Likewise.
	(mipsnbsd_iterate_over_regset_sections): Likewise.
	(mipsnbsd_supply_reg): Likewise.
	(mipsnbsd_supply_fpreg): Likewise.
	* mips-tdep.c (mips_in_frame_stub): Likewise.
	(mips_dummy_id): Likewise.
	(is_octeon_bbit_op): Likewise.
	(micromips_bc1_pc): Likewise.
	(extended_mips16_next_pc): Likewise.
	(mips16_next_pc): Likewise.
	(deal_with_atomic_sequence): Likewise.
	* moxie-tdep.c (moxie_process_readu): Likewise.
	* nios2-tdep.c (nios2_get_next_pc): Likewise.
	* nto-procfs.c (procfs_store_registers): Likewise.
	* ppc-fbsd-nat.c (ppcfbsd_fetch_inferior_registers): Likewise.
	(ppcfbsd_store_inferior_registers): Likewise.
	* ppc-linux-nat.c (fetch_vsx_register): Likewise.
	(fetch_altivec_register): Likewise.
	(get_spe_registers): Likewise.
	(fetch_spe_register): Likewise.
	(fetch_altivec_registers): Likewise.
	(fetch_all_gp_regs): Likewise.
	(fetch_all_fp_regs): Likewise.
	(store_vsx_register): Likewise.
	(store_altivec_register): Likewise.
	(set_spe_registers): Likewise.
	(store_spe_register): Likewise.
	(store_altivec_registers): Likewise.
	(store_all_gp_regs): Likewise.
	(store_all_fp_regs): Likewise.
	* ppc-linux-tdep.c (ppc_linux_supply_gregset): Likewise.
	(ppc_linux_collect_gregset): Likewise.
	(ppc_canonicalize_syscall): Likewise.
	(ppc_linux_record_signal): Likewise.
	(ppu2spu_prev_register): Likewise.
	* ppc-nbsd-nat.c (ppcnbsd_supply_pcb): Likewise.
	* ppc-obsd-nat.c (ppcobsd_fetch_registers): Likewise.
	(ppcobsd_store_registers): Likewise.
	* ppc-ravenscar-thread.c (ppc_ravenscar_generic_fetch_registers):
	Likewise.
	(ppc_ravenscar_generic_store_registers): Likewise.
	* procfs.c (procfs_fetch_registers): Likewise.
	(procfs_store_registers): Likewise.
	* ravenscar-thread.c (ravenscar_fetch_registers): Likewise.
	(ravenscar_store_registers): Likewise.
	(ravenscar_prepare_to_store): Likewise.
	* record-btrace.c (record_btrace_fetch_registers): Likewise.
	* record-full.c (record_full_wait_1): Likewise.
	(record_full_registers_change): Likewise.
	(record_full_store_registers): Likewise.
	(record_full_core_fetch_registers): Likewise.
	(record_full_save): Likewise.
	(record_full_goto_insn): Likewise.
	* regcache.c (regcache_register_size): Likewise.
	(get_regcache_arch): Remove.
	(regcache_read_pc): Likewise.
	* regcache.h (get_regcache_arch): Remove.
	* remote-sim.c (gdbsim_fetch_register): Likewise.
	(gdbsim_store_register): Likewise.
	* remote.c (fetch_register_using_p): Likewise.
	(send_g_packet): Likewise.
	(remote_prepare_to_store): Likewise.
	(store_registers_using_G): Likewise.
	* reverse.c (save_bookmark_command): Likewise.
	(goto_bookmark_command): Likewise.
	* rs6000-aix-tdep.c (branch_dest): Likewise.
	* rs6000-nat.c (rs6000_ptrace64): Likewise.
	(fetch_register): Likewise.
	* rs6000-tdep.c (ppc_supply_reg): Likewise.
	(ppc_collect_reg): Likewise.
	(ppc_collect_gregset): Likewise.
	(ppc_collect_fpregset): Likewise.
	(ppc_collect_vsxregset): Likewise.
	(ppc_collect_vrregset): Likewise.
	(ppc_displaced_step_hw_singlestep): Likewise.
	(rs6000_pseudo_register_read): Likewise.
	(rs6000_pseudo_register_write): Likewise.
	* s390-linux-nat.c (supply_gregset): Likewise.
	(fill_gregset): Likewise.
	(s390_linux_fetch_inferior_registers): Likewise.
	* s390-linux-tdep.c (s390_write_pc): Likewise.
	(s390_software_single_step): Likewise.
	(s390_all_but_pc_registers_record): Likewise.
	(s390_linux_syscall_record): Likewise.
	* sentinel-frame.c (sentinel_frame_prev_arch): Likewise.
	* sh-nbsd-nat.c (shnbsd_fetch_inferior_registers): Likewise.
	(shnbsd_store_inferior_registers): Likewise.
	* sh-tdep.c (sh_extract_return_value_nofpu): Likewise.
	(sh_extract_return_value_fpu): Likewise.
	(sh_store_return_value_nofpu): Likewise.
	(sh_corefile_supply_regset): Likewise.
	(sh_corefile_collect_regset): Likewise.
	* sh64-tdep.c (sh64_extract_return_value): Likewise.
	(sh64_store_return_value): Likewise.
	* sparc-linux-tdep.c (sparc32_linux_collect_core_fpregset): Likewise.
	* sparc-nat.c (sparc_fetch_inferior_registers): Likewise.
	(sparc_store_inferior_registers): Likewise.
	* sparc-ravenscar-thread.c (register_in_thread_descriptor_p): Likewise.
	(sparc_ravenscar_prepare_to_store): Likewise.
	* sparc-tdep.c (sparc32_store_arguments): Likewise.
	(sparc_analyze_control_transfer): Likewise.
	(sparc_step_trap): Likewise.
	(sparc_software_single_step): Likewise.
	(sparc32_gdbarch_init): Likewise.
	(sparc_supply_rwindow): Likewise.
	(sparc_collect_rwindow): Likewise.
	* sparc64-linux-tdep.c (sparc64_linux_collect_core_fpregset): Likewise.
	* sparc64-nbsd-nat.c (sparc64nbsd_supply_gregset): Likewise.
	(sparc64nbsd_collect_gregset): Likewise.
	(sparc64nbsd_supply_fpregset): Likewise.
	(sparc64nbsd_collect_fpregset): Likewise.
	* sparc64-tdep.c (sparc64_store_arguments): Likewise.
	(sparc64_supply_gregset): Likewise.
	(sparc64_collect_gregset): Likewise.
	(sparc64_supply_fpregset): Likewise.
	(sparc64_collect_fpregset): Likewise.
	* spu-linux-nat.c (spu_fetch_inferior_registers): Likewise.
	* spu-tdep.c (spu_unwind_sp): Likewise.
	(spu2ppu_prev_register): Likewise.
	(spu_memory_remove_breakpoint): Likewise.
	* stack.c (return_command): Likewise.
	* tic6x-tdep.c (tic6x_extract_signed_field): Likewise.
	* tracefile-tfile.c (tfile_fetch_registers): Likewise.
	* tracefile.c (trace_save_ctf): Likewise.
	* windows-nat.c (do_windows_fetch_inferior_registers): Likewise.
	(do_windows_store_inferior_registers): Likewise.
	(windows_resume): Likewise.
	* xtensa-linux-nat.c (fill_gregset): Likewise.
	(supply_gregset_reg): Likewise.
	* xtensa-tdep.c (xtensa_register_write_masked): Likewise.
	(xtensa_register_read_masked): Likewise.
	(xtensa_supply_gregset): Likewise.
	(xtensa_extract_return_value): Likewise.
	(xtensa_store_return_value): Likewise.
2017-10-25 16:37:03 +01:00
Simon Marchi a664f67e50 Get rid of VEC (mem_region)
This patch removes VEC (mem_region).  Doing so requires touching a lot
of little things here and there.

The fields in mem_attrib are now initialized during construction.  The
values match those that were in default_mem_attrib (now removed).
unknown_mem_attrib is also removed, and replaced with a static method
(mem_attrib::unknown) that returns the equivalent.

mem_region is initialized in a way similar to mem_region_init (now
removed) did.

I found the organization of mem_region_list and target_mem_region_list a
bit confusing.  Sometimes mem_region_list points to the same vector as
target_mem_region_list (and therefore does not own it), and sometimes
(when the user manually edits the mem regions) points to another vector,
and in this case owns it.  To avoid this ambiguity, I think it is
simpler to have two vectors, one for target-defined regions and one for
user-defined regions, and have mem_region_list point to one or the
other.  There are now no vector objects dynamically allocated, both are
static.

The make-target-delegates script does not generate valid code when a
target method returns a type with a parameter list.  For this reason, I
created a typedef (mem_region_vector) that's only used in the target_ops
structure.  If you speak perl, you are welcome to improve the script!

Regtested on the buildbot.

gdb/ChangeLog:

	* memattr.h: Don't include vec.h.
	(struct mem_attrib): Initialize fields.
	<unknown>: New static method.
	(struct mem_region): Add constructors, operator<, initialize
	fields.
	* memattr.c: Include algorithm.
	(default_mem_attrib, unknown_mem_attrib): Remove.
	(user_mem_region_list): New global.
	(target_mem_region_list, mem_region_list): Change type to
	std::vector<mem_region>.
	(mem_use_target): Now a function.
	(target_mem_regions_valid): Change type to bool.
	(mem_region_lessthan, mem_region_cmp, mem_region_init): Remove.
	(require_user_regions): Adjust.
	(require_target_regions): Adjust.
	(create_mem_region): Adjust.
	(lookup_mem_region): Adjust.
	(invalidate_target_mem_regions): Adjust.
	(mem_clear): Rename to...
	(user_mem_clear): ... this, and adjust.
	(mem_command): Adjust.
	(info_mem_command): Adjust.
	(mem_enable, enable_mem_command, mem_disable,
	disable_mem_command): Adjust.
	(mem_delete): Adjust.
	(delete_mem_command): Adjust.
	* memory-map.h (parse_memory_map): Return an std::vector.
	* memory-map.c (parse_memory_map): Likewise.
	(struct memory_map_parsing_data): Add constructor.
	<memory_map>: Point to std::vector.
	(memory_map_start_memory): Adjust.
	(memory_map_end_memory): Adjust.
	(memory_map_end_property): Adjust.
	(clear_result): Remove.
	* remote.c (remote_memory_map): Return an std::vector.
	* target-debug.h (target_debug_print_VEC_mem_region_s__p):
	Remove.
	(target_debug_print_mem_region_vector): New.
	* target-delegates.c: Regenerate.
	* target.h (mem_region_vector): New typedef.
	(to_memory_map): Return mem_region_vector.
	(target_memory_map): Return an std::vector.
	* target.c (target_memory_map): Return an std::vector.
	(flash_erase_command): Adjust.
2017-10-21 12:15:42 -04:00
Tom Tromey b7b030adc4 Return unique_xmalloc_ptr from target_read_stralloc
This changes target_read_stralloc to return a unique_xmalloc_ptr, and
then fixes all the callers.  unique_xmalloc_ptr is used, rather than
std::string, because target_read_stralloc gives a special meaning to a
NULL return.

ChangeLog
2017-10-16  Tom Tromey  <tom@tromey.com>

	* xml-syscall.c (xml_init_syscalls_info): Update.
	* xml-support.c (xinclude_start_include): Update.
	(xml_fetch_content_from_file): Return unique_xmalloc_ptr.
	* xml-support.h (xml_fetch_another): Return unique_xmalloc_ptr.
	(xml_fetch_content_from_file): Likewise.
	* osdata.c (get_osdata): Update.
	* target.h (target_read_stralloc, target_get_osdata): Return
	unique_xmalloc_ptr.
	* solib-aix.c (solib_aix_get_library_list): Update.
	* solib-target.c (solib_target_current_sos): Update.
	* solib-svr4.c (svr4_current_sos_via_xfer_libraries): Update.
	* xml-tdesc.c (fetch_available_features_from_target): Update.
	(target_fetch_description_xml): Update.
	(file_read_description_xml): Update.
	* remote.c (remote_get_threads_with_qxfer, remote_memory_map)
	(remote_traceframe_info, btrace_read_config, remote_read_btrace)
	(remote_pid_to_exec_file): Update.
	* target.c (target_read_stralloc): Return unique_xmalloc_ptr.
	(target_get_osdata): Likewise.
2017-10-16 16:10:21 -06:00
Tom Tromey b80406accc Simple cleanup removals in remote.c
This removes a few cleanups in remote.c using the usual techniques:
std::vector, unique_xmalloc_ptr, and gdb::def_vector.

ChangeLog
2017-10-16  Tom Tromey  <tom@tromey.com>

	* remote.c (remote_register_number_and_offset): Use std::vector.
	(remote_set_syscall_catchpoint): Use gdb::unique_xmalloc_ptr.
	(putpkt_binary): Use gdb::def_vector.
	(compare_sections_command): Use gdb::byte_vector.
2017-10-16 16:10:20 -06:00
Simon Marchi a79b1bc6f6 Get rid of VEC(mem_range_s)
This patch replaces the last usages of VEC(mem_range_s) with
std::vector<mem_range>.  This allows getting rid of a few cleanups and
of the DEF_VEC_O(mem_range_s).

I added a test for normalize_mem_ranges to make sure I didn't break
anything there.

Regtested on the buildbot.

gdb/ChangeLog:

	* memrange.h (struct mem_range): Define operator< and operator==.
	(mem_range_s): Remove.
	(DEF_VEC_O (mem_range_s)): Remove.
	(normalize_mem_ranges): Change parameter type to std::vector.
	* memrange.c (compare_mem_ranges): Remove.
	(normalize_mem_ranges): Change parameter type to std::vector,
	adjust to vector change.
	* exec.c (section_table_available_memory): Return vector, remove
	parameter.
	(section_table_read_available_memory): Adjust to std::vector
	change.
	* remote.c (remote_read_bytes): Adjust to std::vector
	change.
	* tracepoint.h (traceframe_available_memory): Change parameter
	type to std::vector.
	* tracepoint.c (traceframe_available_memory): Change parameter
	type to std::vector, adjust.
	* gdb/mi/mi-main.c (mi_cmd_trace_frame_collected): Adjust to
	std::vector change.
	* gdb/Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	unittests/memrange-selftests.c.
	(SUBDIR_UNITTESTS_OBS): Add memrange-selftests.o.
	* gdb/unittests/memrange-selftests.c: New file.
2017-10-16 11:07:18 -04:00
Simon Marchi 2098b39391 Make to_traceframe_info return a unique_ptr
Since this target method returns an allocated object, return a
unique_ptr.  It allows getting rid a some cleanups here and there.

I had to shuffle the includes around.  First, target.h now needs to
include tracepoint.h, to get the definition of traceframe_info_up.
However, the definition of enum trace_find_type was later in target, so
I had to move it to tracepoint.h, so that the declaration of tfind_1
could know about it.  I then had to remove the include of target.h from
tracepoint.h, which caused a circular dependency (it was probably
included to get enum trace_find_type in the first place anyway).

Regression tested on the buildbot.

gdb/ChangeLog:

	* target.h: Include tracepoint.h.
	(enum trace_find_type): Move to tracepoint.h.
	(struct target_ops) <to_traceframe_info>: Return a unique ptr.
	* tracepoint.h: Don't include target.h
	(enum trace_find_type): Move from target.h.
	(parse_traceframe_info): Return a unique ptr.
	* tracepoint.c (current_traceframe_info): Change type to unique
	ptr.
	(free_traceframe_info): Remove.
	(clear_traceframe_info): Don't manually free
	current_traceframe_info.
	(free_result): Remove.
	(parse_traceframe_info): Return a unique ptr.
	(get_traceframe_info): Adjust to unique ptr.
	* ctf.c (ctf_traceframe_info): Return a unique ptr.
	* remote.c (remote_traceframe_info): Return a unique ptr.
	* tracefile-tfile.c (tfile_traceframe_info): Return a unique
	ptr.
	* target-debug.h (target_debug_print_traceframe_info_up): New
	macro.
	* target-delegates.c: Regenerate.
2017-10-14 08:47:44 -04:00
Tom Tromey 981a3fb359 Constify add_prefix_cmd
This changes add_prefix_cmd to accept a const-taking function as an
argument; then fixes up all the callers.

In a couple of spots I had to add a non-const overload of a function,
because the function is passed to two different command-adding
"constructors".  These overloads are temporary; once constification is
complete they can be removed.

This patch also fixes a typo I happened to notice while constifying.

Note that this touches a couple of files (gnu-nat.c and go32-nat.c)
that I can't build.  So, while I made a best-effort there, I am not
certain they will still compile.

Tested by rebuilding.

gdb/ChangeLog
2017-10-11  Tom Tromey  <tom@tromey.com>

	* gdbthread.h (thread_command): Constify.
	* inferior.h (detach_command): Constify.
	* top.h (set_history, show_history): Constify.
	* arm-tdep.c (set_arm_command, show_arm_command): Constify.
	* serial.c (serial_set_cmd, serial_show_cmd): Constify.
	* bsd-kvm.c (bsd_kvm_cmd): Constify.
	* printcmd.c (set_command): Constify.
	(non_const_set_command): New function.
	* dcache.c (set_dcache_command, show_dcache_command): Constify.
	* breakpoint.c (enable_command, disable_command, delete_command)
	(catch_command, tcatch_command, set_breakpoint_cmd)
	(show_breakpoint_cmd): Constify.
	* macrocmd.c (macro_command): Constify.
	* infcmd.c (unset_command, kill_command, detach_command)
	(info_proc_cmd): Constify.
	* i386-tdep.c (set_mpx_cmd, show_mpx_cmd): Constify.
	* auto-load.c (show_auto_load_cmd, set_auto_load_cmd)
	(info_auto_load_cmd): Constify.
	* target-descriptions.c (set_tdesc_cmd, show_tdesc_cmd)
	(unset_tdesc_cmd): Constify.
	* ada-lang.c (set_ada_command, show_ada_command)
	(maint_set_ada_cmd, maint_show_ada_cmd): Constify.
	* guile/guile.c (set_guile_command, show_guile_command)
	(info_guile_command): Constify.
	* tui/tui-win.c (tui_command, set_tui_cmd, show_tui_cmd):
	Constify.
	* skip.c (skip_command): Constify.
	* compile/compile.c (_initialize_compile): Constify.
	* dwarf2read.c (set_dwarf_cmd, show_dwarf_cmd): Constify.
	* btrace.c (maint_btrace_cmd, maint_btrace_set_cmd)
	(maint_btrace_show_cmd, maint_btrace_pt_set_cmd)
	(maint_btrace_pt_show_cmd): Constify.
	* remote.c (set_remote_cmd, show_remote_cmd, remote_command):
	Constify.
	* python/python.c (user_show_python, user_set_python): Constify.
	* mips-tdep.c (set_mips_command, show_mips_command)
	(set_mipsfpu_command): Constify.
	* record-btrace.c (cmd_record_btrace_start)
	(cmd_set_record_btrace, cmd_show_record_btrace)
	(cmd_set_record_btrace_bts, cmd_show_record_btrace_bts)
	(cmd_set_record_btrace_pt, cmd_show_record_btrace_pt): Constify.
	* rs6000-tdep.c (set_powerpc_command, show_powerpc_command):
	Constify.
	* symfile.c (overlay_command): Constify.
	* spu-tdep.c (set_spu_command, show_spu_command): Constify.
	* cli/cli-logging.c (set_logging_command, show_logging_command):
	Constify.
	* cli/cli-dump.c (dump_command, append_command)
	(srec_dump_command, ihex_dump_command, verilog_dump_command)
	(tekhex_dump_command, binary_dump_command)
	(binary_append_command): Constify.
	* cli/cli-decode.c (struct cmd_list_element): Change type of
	"fun".
	* cli/cli-cmds.c (info_command, show_command, set_debug)
	(show_debug): Constify.
	(show_command): Add non-const overload.
	* top.c (set_history, show_history): Constify.
	* sh-tdep.c (set_sh_command, show_sh_command): Constify.
	* command.h (add_prefix_cmd): Accept a cmd_const_cfunc_ftype.
	* target.c (target_command): Constify.
	* sparc64-tdep.c (info_adi_command): Constify.
	* record-full.c (cmd_record_full_start): Constify.
	(set_record_full_command): Constify.  Fix typo.
	(show_record_full_command): Constify.
	* thread.c (thread_command, thread_apply_command): Constify.
	* memattr.c (dummy_cmd): Constify.
	* value.c (function_command): Constify.
	* frame.c (set_backtrace_cmd, show_backtrace_cmd): Constify.
	* probe.c (info_probes_command): Constify.
	* ser-tcp.c (set_tcp_cmd, show_tcp_cmd): Constify.
	* gnu-nat.c (set_task_cmd, show_task_cmd, set_thread_cmd)
	(show_thread_cmd, set_thread_default_cmd)
	(show_thread_default_cmd): Constify.
	(check_empty): Constify.
	* tracepoint.c (tfind_command): Constify.
	* cp-support.c (maint_cplus_command): Constify.
	* windows-tdep.c (info_w32_command): Constify.
	* record.c (cmd_record_start, set_record_command)
	(show_record_command, info_record_command, cmd_record_goto):
	Constify.
	* ravenscar-thread.c (set_ravenscar_command)
	(show_ravenscar_command): Constify.
	* utils.c (set_internal_problem_cmd, show_internal_problem_cmd):
	Constify.
	(add_internal_problem_command): Remove casts.
	* arc-tdep.c (maintenance_print_arc_command): Constify.
	* valprint.c (set_print, show_print, set_print_raw)
	(show_print_raw): Constify.
	* maint.c (maintenance_command, maintenance_info_command)
	(maintenance_print_command, maintenance_set_cmd)
	(maintenance_show_cmd, set_per_command_cmd)
	(show_per_command_cmd, maintenance_check_command): Constify.
	* language.c (set_check, show_check): Constify.
	* typeprint.c (show_print_type, set_print_type): Constify.
	* go32-nat.c (go32_info_dos_command): Constify.
2017-10-11 16:21:02 -06:00
Pedro Alves 5cd63fda03 Fix "Remote 'g' packet reply is too long" problems with multiple inferiors
When debugging two inferiors (or more) against gdbserver, and the
inferiors have different architectures, such as e.g., on x86_64
GNU/Linux and one inferior is 64-bit while the other is 32-bit, then
GDB can get confused with the different architectures in a couple
spots.

In both cases I ran into, GDB incorrectly ended up using the
architecture of whatever happens to be the selected inferior instead
of the architecture of some other given inferior:

#1 - When parsing the expedited registers in stop replies.

#2 - In the default implementation of the target_thread_architecture
     target method.

These resulted in instances of the infamous "Remote 'g' packet reply
is too long" error.  For example, with the test added in this commit,
we get:

~~~
  Continuing.
  Remote 'g' packet reply is too long (expected 440 bytes, got 816 bytes): ad064000000000000[snip]
  (gdb) FAIL: gdb.multi/multi-arch.exp: inf1 event with inf2 selected: continue to hello_loop

  c
  Continuing.
  Truncated register 50 in remote 'g' packet
  (gdb) PASS: gdb.multi/multi-arch.exp: inf2 event with inf1 selected: c
~~~

This commit fixes that.

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

	* remote.c (get_remote_arch_state): New 'gdbarch' parameter.  Use
	it instead of target_gdbarch.
	(get_remote_state, get_remote_packet_size): Adjust
	get_remote_arch_state calls, passing down target_gdbarch
	explicitly.
	(packet_reg_from_regnum, packet_reg_from_pnum): New parameter
	'gdbarch' and use it instead of target_gdbarch.
	(get_memory_packet_size): Adjust get_remote_arch_state calls,
	passing down target_gdbarch explicitly.
	(struct stop_reply) <arch>: New field.
	(remote_parse_stop_reply): Use the stopped thread's architecture,
	not the current inferior's.  Save the architecture in the
	stop_reply.
	(process_stop_reply): Use the stop reply's architecture.
	(process_g_packet, remote_fetch_registers)
	(remote_prepare_to_store, store_registers_using_G)
	(remote_store_registers): Adjust get_remote_arch_state calls,
	using the regcache's architecture.
	(remote_get_trace_status): Adjust get_remote_arch_state calls,
	passing down target_gdbarch explicitly.
	* spu-multiarch.c (spu_thread_architecture): Defer to the target
	beneath instead of calling target_gdbarch.
	* target.c (default_thread_architecture): Use the specified
	inferior's architecture, instead of the current inferior's
	architecture (via target_gdbarch).

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

	* gdb.multi/hangout.c: Include <unistd.h>.
	(hangout_loop): New function.
	(main): Call alarm.  Call hangout_loop in a loop.
	* gdb.multi/hello.c: Include <unistd.h>.
	(hello_loop): New function.
	(main): Call alarm.  Call hangout_loop in a loop.
	* gdb.multi/multi-arch.exp: Test running to a breakpoint one
	inferior with the other selected.
2017-10-04 18:23:22 +01:00
Sergio Durigan Junior bc3b087de2 Extend "set cwd" to work on gdbserver
This is the "natural" extension necessary for the "set cwd" command
(and the whole "set the inferior's cwd" logic) to work on gdbserver.

The idea here is to have a new remote packet, QSetWorkingDir (name
adopted from LLDB's extension to the RSP, as can be seen at
<https://raw.githubusercontent.com/llvm-mirror/lldb/master/docs/lldb-gdb-remote.txt>),
which sends an hex-encoded string representing the working directory
that the remote inferior will use.  There is a slight difference from
the packet proposed by LLDB: GDB's version will accept empty
arguments, meaning that the user wants to clear the previously set
working directory for the inferior (i.e., "set cwd" without arguments
on GDB).

For UNIX-like targets this feature is already implemented on
nat/fork-inferior.c, and all gdbserver has to do is to basically
implement "set_inferior_cwd" and call it whenever such packet arrives.
For other targets, like Windows, it is possible to use the existing
"get_inferior_cwd" function and do the necessary steps to make sure
that the inferior will use the specified working directory.

Aside from that, the patch consists basically of updates to the
testcase (making it available on remote targets) and the
documentation.

No regressions found.

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

	* NEWS (Changes since GDB 8.0): Add entry about new
	'set-cwd-on-gdbserver' feature.
	(New remote packets): Add entry for QSetWorkingDir.
	* common/common-inferior.h (set_inferior_cwd): New prototype.
	* infcmd.c (set_inferior_cwd): Remove "static".
	(show_cwd_command): Expand text to include remote debugging.
	* remote.c: Add PACKET_QSetWorkingDir.
	(remote_protocol_features) <QSetWorkingDir>: New entry for
	PACKET_QSetWorkingDir.
	(extended_remote_set_inferior_cwd): New function.
	(extended_remote_create_inferior): Call
	"extended_remote_set_inferior_cwd".
	(_initialize_remote): Call "add_packet_config_cmd" for
	QSetWorkingDir.

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

	* inferiors.c (set_inferior_cwd): New function.
	* server.c (handle_general_set): Handle QSetWorkingDir packet.
	(handle_query): Inform that QSetWorkingDir is supported.
	* win32-low.c (create_process): Pass the inferior's cwd to
	CreateProcess.

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

	* gdb.base/set-cwd.exp: Make it available on
	native-extended-gdbserver.

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

	* gdb.texinfo (Starting your Program) <The working directory.>:
	Mention remote debugging.
	(Working Directory) <Your Program's Working Directory>:
	Likewise.
	(Connecting) <Remote Packet>: Add "set-working-dir"
	and "QSetWorkingDir" to the table.
	(Remote Protocol) <QSetWorkingDir>: New item, explaining the
	packet.
2017-10-04 02:01:45 -04:00
Pedro Alves 256642e857 Constify unpack_varlen_hex & fix fallout
I ran into non-const unpack_varlen_hex while working on something
else, and decided to just fix it first.  Ends up constifying a good
deal of remote packet parsing.

gdb/ChangeLog:
2017-09-29  Pedro Alves  <palves@redhat.com>

	* common/rsp-low.c (unpack_varlen_hex): Constify.
	* common/rsp-low.h (unpack_varlen_hex): Constify.
	* linux-nat.c (linux_child_static_tracepoint_markers_by_strid):
	Constify.
	* remote.c (remote_set_permissions, read_ptid)
	(remote_current_thread, remote_get_threads_with_qthreadinfo)
	(remote_static_tracepoint_marker_at)
	(remote_static_tracepoint_markers_by_strid)
	(stop_reply_extract_thread, remote_parse_stop_reply): Constify.
	* tracepoint.c (parse_trace_status, parse_tracepoint_status)
	(parse_tracepoint_definition, parse_tsv_definition)
	(parse_static_tracepoint_marker_definition): Constify.
	* tracepoint.h (parse_static_tracepoint_marker_definition)
	(parse_trace_status, parse_tracepoint_status)
	(parse_tracepoint_definition, parse_tsv_definition): Constify.

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

	* ax.c (gdb_parse_agent_expr): Constify.
	* ax.h (gdb_parse_agent_expr): Constify.
	* mem-break.c (add_breakpoint_condition, add_breakpoint_commands):
	Constify.
	* mem-break.h (add_breakpoint_condition, add_breakpoint_commands): Constify.
	* remote-utils.c (hex_or_minus_one, read_ptid): Constify.
	* remote-utils.h (read_ptid): Constify.
	* server.c (handle_qxfer_exec_file, handle_query, handle_v_cont)
	(process_point_options, process_serial_event): Constify.
	* tracepoint.c (add_tracepoint_action, cmd_qtdp, cmd_qtdpsrc)
	(cmd_qtdv, cmd_qtenable_disable, cmd_qtro, cmd_qtframe, cmd_qtp)
	(cmd_qtbuffer): Constify.
2017-09-29 17:15:36 +01:00
Pedro Alves b6bb34680b gdb/remote.c: Eliminate target_buf/target_buf_size hack
This finally eliminates an old hack left in place when tracepoint RSP
support was migrated from tracepoint.c to remote.c, back in
35b1e5cca0 ("Make tracepoint operations go through target vector.")
over 7 years ago.

Tested on x86_64 GNU/Linux.

gdb/ChangeLog:
2017-09-29  Pedro Alves  <palves@redhat.com>

	* remote.c (target_buf, target_buf_size): Delete.
	(remote_get_noisy_reply): Remove buf_p and sizeof_buf parameters.
	Use the connection's packet buffer instead.
	All callers adjusted.
	(_initialize_remote): Remove references to target_buf and
	target_buf_size.
2017-09-29 17:09:05 +01:00
Tom Tromey ac88e2de83 Constify some commands in remote.c
gdb/ChangeLog
2017-09-27  Tom Tromey  <tom@tromey.com>

	* remote.c (set_memory_packet_size)
	(set_memory_write_packet_size, show_memory_write_packet_size)
	(set_memory_read_packet_size, show_memory_read_packet_size)
	(compare_sections_command, packet_command, remote_put_command)
	(remote_get_command, remote_delete_command): Constify.
2017-09-27 08:44:53 -06:00
Kevin Buettner f6327dcbf0 Add thread_handle_to_thread_info support for remote targets
This patch adds support to remote targets for converting a thread
handle to a thread_info struct pointer.

A thread handle is fetched via a "handle" attribute which has been
added to the qXfer:threads:read query packet.  An implementation is
provided in gdbserver for targets using the Linux kernel.

gdb/gdbserver/ChangeLog:

	* linux-low.h (struct lwp_info): Add new field, thread_handle.
	(thread_db_thread_handle): Declare.
	* linux-low.c (linux_target_ops): Initialize thread_handle.
	* server.c (handle_qxfer_threads_worker): Add support for
	"handle" attribute.
	* target.h (struct target_ops): Add new function pointer,
	thread_handle.
	(target_thread_handle): Define.
	* thread-db.c (find_one_thread, attach_thread): Set thread_handle
	field in lwp.
	(thread_db_thread_handle): New function.

gdb/ChangeLog:

	* remote.c (vector): Include.
	(struct private_thread_info): Add field, thread_handle.
	(free_private_thread_info): Deallocate storage associated with
	thread handle.
	(get_private_info_thread): Initialize `thread_handle' field.
	(struct thread_item): Add field, thread_handle.
	(clear_threads_listing_context): Deallocate storage associated
	with thread handle.
	(start_thread): Add support for "handle" attribute.
	(thread_attributes): Add "handle".
	(remote_get_threads_with_qthreadinfo): Initialize thread_handle
	field.
	(remote_update_thread_list): Update thread_handle.
	(remote_thread_handle_to_thread_info): New function.
	(init_remote_ops): Initialize to_thread_handle_to_thread_info.
2017-09-21 11:49:47 -07:00
Tom Tromey 223ffa714c Remove make_cleanup_restore_target_terminal
This removes make_cleanup_restore_target_terminal and generally
C++-ifies target terminal handling.  It changes all target_terminal_*
functions to be static members of a new target_terminal class and
changes the cleanup to be a scoped_* class.
make_cleanup_override_quit_handler is also removed in favor of simply
using scoped_restore.

Note that there are some files in this patch that I could not compile.
Considering that some of the rewrites were automated, and that none of
these files involed cleanups, I feel that this is relatively safe.

Regression tested by the buildbot.

gdb/ChangeLog
2017-09-20  Tom Tromey  <tom@tromey.com>

	* windows-nat.c (get_windows_debug_event, windows_wait)
	(do_initial_windows_stuff, windows_attach): Update.
	* utils.c (vwarning, internal_vproblem): Update.
	(ui_unregister_input_event_handler_cleanup)
	(prepare_to_handle_input): Remove.
	(class scoped_input_handler): New.
	(defaulted_query, prompt_for_continue): Update.
	* tui/tui-hooks.c (tui_refresh_frame_and_register_information):
	Update.
	* top.c (undo_terminal_modifications_before_exit): Update.
	* target/target.h (target_terminal_init, target_terminal_inferior)
	(target_terminal_ours): Don't declare.
	(class target_terminal): New.
	* target.h (target_terminal_is_inferior, target_terminal_is_ours)
	(target_terminal_ours_for_output)
	(make_cleanup_restore_target_terminal): Don't declare.
	(target_terminal_info): Remove.
	* target.c (enum terminal_state, terminal_state): Remove.
	(target_terminal::terminal_state): Define.
	(target_terminal::init): Rename from target_terminal_init.
	(target_terminal::inferior): Rename from
	target_terminal_inferior.
	(target_terminal::ours): Rename from target_terminal_ours.
	(target_terminal::ours_for_output): Rename from
	target_terminal_ours_for_output.
	(target_terminal::info): New method.
	(cleanup_restore_target_terminal)
	(make_cleanup_restore_target_terminal): Remove.
	* solib.c (handle_solib_event): Update.
	* remote.c (remote_serial_quit_handler): Update.
	(remote_terminal_inferior, remote_wait_as): Update.
	* record-full.c (record_full_wait_1): Update.
	* nto-procfs.c (procfs_create_inferior): Update.
	* nat/fork-inferior.c (startup_inferior): Update.
	* mi/mi-interp.c (mi_new_thread, mi_thread_exit)
	(mi_record_changed, mi_inferior_added, mi_inferior_appeared)
	(mi_inferior_exit, mi_inferior_removed, mi_traceframe_changed)
	(mi_tsv_created, mi_tsv_deleted, mi_tsv_modified)
	(mi_breakpoint_created, mi_breakpoint_deleted)
	(mi_breakpoint_modified, mi_on_resume, mi_solib_loaded)
	(mi_solib_unloaded, mi_command_param_changed, mi_memory_changed)
	(mi_user_selected_context_changed, report_initial_inferior):
	Update.
	* linux-nat.c (linux_nat_attach, linux_nat_terminal_ours)
	(linux_nat_terminal_inferior): Update.
	* infrun.c (follow_fork_inferior)
	(handle_vfork_child_exec_or_exit, do_target_resume)
	(check_curr_ui_sync_execution_done, handle_inferior_event_1)
	(handle_signal_stop, maybe_remove_breakpoints, normal_stop):
	Update.
	* inflow.c (child_terminal_init, info_terminal_command): Update.
	* infcmd.c (post_create_inferior, continue_1, prepare_one_step)
	(attach_command): Update.
	* infcall.c (call_thread_fsm_should_stop): Update.
	* gnu-nat.c (gnu_attach): Update.
	* extension.c (struct active_ext_lang_state)
	(restore_active_ext_lang): Update.
	* exceptions.c (print_flush): Update.
	* event-top.c (async_enable_stdin, default_quit_handler): Update.
	(struct quit_handler_cleanup_data, restore_quit_handler)
	(restore_quit_handler_dtor, make_cleanup_override_quit_handler):
	Remove.
	* cp-support.c (gdb_demangle): Update.
	* breakpoint.c (update_inserted_breakpoint_locations)
	(insert_breakpoint_locations, handle_jit_event)
	(disable_breakpoints_in_unloaded_shlib): Update.
	* annotate.c (annotate_breakpoints_invalid)
	(annotate_frames_invalid): Update.

gdb/gdbserver/ChangeLog
2017-09-20  Tom Tromey  <tom@tromey.com>

	* target.c (target_terminal::terminal_state): Define.
	(target_terminal::init): Rename from target_terminal_init.
	(target_terminal::inferior): Rename from
	target_terminal_inferior.
	(target_terminal::ours): Rename from target_terminal_ours.
	(target_terminal::ours_for_output, target_terminal::info): New.
2017-09-20 16:09:50 -06:00
John Baldwin 481695ed5f Remove unnecessary function prototypes.
These prototypes were required when compiling GDB as C but are not
required for C++.

gdb/ChangeLog:

	* aarch64-linux-nat.c: Remove _initialize_aarch64_linux_nat
	prototype.
	* aarch64-linux-tdep.c: Remove _initialize_aarch64_linux_tdep
	prototype.
	* aarch64-newlib-tdep.c: Remove _initialize_aarch64_newlib_tdep
	prototype.
	* aarch64-tdep.c: Remove _initialize_aarch64_tdep prototype.
	* ada-exp.y: Remove _initialize_ada_exp prototype.
	* ada-lang.c: Remove _initialize_ada_language prototype.
	* ada-tasks.c: Remove _initialize_tasks prototype.
	* addrmap.c: Remove _initialize_addrmap prototype.
	* agent.c: Remove _initialize_agent prototype.
	* aix-thread.c: Remove _initialize_aix_thread prototype.
	* alpha-bsd-nat.c: Remove _initialize_alphabsd_nat prototype.
	* alpha-linux-nat.c: Remove _initialize_alpha_linux_nat prototype.
	* alpha-linux-tdep.c: Remove _initialize_alpha_linux_tdep
	prototype.
	* alpha-nbsd-tdep.c: Remove _initialize_alphanbsd_tdep prototype.
	* alpha-obsd-tdep.c: Remove _initialize_alphaobsd_tdep prototype.
	* alpha-tdep.c: Remove _initialize_alpha_tdep prototype.
	* amd64-darwin-tdep.c: Remove _initialize_amd64_darwin_tdep
	prototype.
	* amd64-dicos-tdep.c: Remove _initialize_amd64_dicos_tdep
	prototype.
	* amd64-fbsd-nat.c: Remove _initialize_amd64fbsd_nat prototype.
	* amd64-fbsd-tdep.c: Remove _initialize_amd64fbsd_tdep prototype.
	* amd64-linux-nat.c: Remove _initialize_amd64_linux_nat prototype.
	* amd64-linux-tdep.c: Remove _initialize_amd64_linux_tdep
	prototype.
	* amd64-nbsd-nat.c: Remove _initialize_amd64nbsd_nat prototype.
	* amd64-nbsd-tdep.c: Remove _initialize_amd64nbsd_tdep prototype.
	* amd64-obsd-nat.c: Remove _initialize_amd64obsd_nat prototype.
	* amd64-obsd-tdep.c: Remove _initialize_amd64obsd_tdep prototype.
	* amd64-sol2-tdep.c: Remove _initialize_amd64_sol2_tdep prototype.
	* amd64-tdep.c: Remove _initialize_amd64_tdep prototype.
	* amd64-windows-nat.c: Remove _initialize_amd64_windows_nat
	prototype.
	* amd64-windows-tdep.c: Remove _initialize_amd64_windows_tdep
	prototype.
	* annotate.c: Remove _initialize_annotate prototype.
	* arc-newlib-tdep.c: Remove _initialize_arc_newlib_tdep prototype.
	* arc-tdep.c: Remove _initialize_arc_tdep prototype.
	* arch-utils.c: Remove _initialize_gdbarch_utils prototype.
	* arm-linux-nat.c: Remove _initialize_arm_linux_nat prototype.
	* arm-linux-tdep.c: Remove _initialize_arm_linux_tdep prototype.
	* arm-nbsd-tdep.c: Remove _initialize_arm_netbsd_tdep prototype.
	* arm-obsd-tdep.c: Remove _initialize_armobsd_tdep prototype.
	* arm-symbian-tdep.c: Remove _initialize_arm_symbian_tdep
	prototype.
	* arm-tdep.c: Remove _initialize_arm_tdep prototype.
	* arm-wince-tdep.c: Remove _initialize_arm_wince_tdep prototype.
	* auto-load.c: Remove _initialize_auto_load prototype.
	* auxv.c: Remove _initialize_auxv prototype.
	* avr-tdep.c: Remove _initialize_avr_tdep prototype.
	* ax-gdb.c: Remove _initialize_ax_gdb prototype.
	* bfin-linux-tdep.c: Remove _initialize_bfin_linux_tdep prototype.
	* bfin-tdep.c: Remove _initialize_bfin_tdep prototype.
	* break-catch-sig.c: Remove _initialize_break_catch_sig prototype.
	* break-catch-syscall.c: Remove _initialize_break_catch_syscall
	prototype.
	* break-catch-throw.c: Remove _initialize_break_catch_throw
	prototype.
	* breakpoint.c: Remove _initialize_breakpoint prototype.
	* bsd-uthread.c: Remove _initialize_bsd_uthread prototype.
	* btrace.c: Remove _initialize_btrace prototype.
	* charset.c: Remove _initialize_charset prototype.
	* cli/cli-cmds.c: Remove _initialize_cli_cmds prototype.
	* cli/cli-dump.c: Remove _initialize_cli_dump prototype.
	* cli/cli-interp.c: Remove _initialize_cli_interp prototype.
	* cli/cli-logging.c: Remove _initialize_cli_logging prototype.
	* cli/cli-script.c: Remove _initialize_cli_script prototype.
	* coff-pe-read.c: Remove _initialize_coff_pe_read prototype.
	* coffread.c: Remove _initialize_coffread prototype.
	* compile/compile.c: Remove _initialize_compile prototype.
	* complaints.c: Remove _initialize_complaints prototype.
	* completer.c: Remove _initialize_completer prototype.
	* copying.awk: Remove _initialize_copying prototype.
	* copying.c: Regenerate.
	* core-regset.c: Remove _initialize_core_regset prototype.
	* corefile.c: Remove _initialize_core prototype.
	* corelow.c: Remove _initialize_corelow prototype.
	* cp-abi.c: Remove _initialize_cp_abi prototype.
	* cp-namespace.c: Remove _initialize_cp_namespace prototype.
	* cp-support.c: Remove _initialize_cp_support prototype.
	* cp-valprint.c: Remove _initialize_cp_valprint prototype.
	* cris-linux-tdep.c: Remove _initialize_cris_linux_tdep prototype.
	* cris-tdep.c: Remove _initialize_cris_tdep prototype.
	* ctf.c: Remove _initialize_ctf prototype.
	* d-lang.c: Remove _initialize_d_language prototype.
	* darwin-nat-info.c: Remove _initialize_darwin_info_commands
	prototype.
	* darwin-nat.c: Remove _initialize_darwin_inferior prototype.
	* dbxread.c: Remove _initialize_dbxread prototype.
	* dcache.c: Remove _initialize_dcache prototype.
	* demangle.c: Remove _initialize_demangler prototype.
	* disasm-selftests.c: Remove _initialize_disasm_selftests
	prototype.
	* disasm.c: Remove _initialize_disasm prototype.
	* dtrace-probe.c: Remove _initialize_dtrace_probe prototype.
	* dummy-frame.c: Remove _initialize_dummy_frame prototype.
	* dwarf2-frame-tailcall.c: Remove _initialize_tailcall_frame
	prototype.
	* dwarf2-frame.c: Remove _initialize_dwarf2_frame prototype.
	* dwarf2expr.c: Remove _initialize_dwarf2expr prototype.
	* dwarf2loc.c: Remove _initialize_dwarf2loc prototype.
	* dwarf2read.c: Remove _initialize_dwarf2_read prototype.
	* elfread.c: Remove _initialize_elfread prototype.
	* exec.c: Remove _initialize_exec prototype.
	* extension.c: Remove _initialize_extension prototype.
	* f-lang.c: Remove _initialize_f_language prototype.
	* f-valprint.c: Remove _initialize_f_valprint prototype.
	* fbsd-nat.c: Remove _initialize_fbsd_nat prototype.
	* fbsd-tdep.c: Remove _initialize_fbsd_tdep prototype.
	* filesystem.c: Remove _initialize_filesystem prototype.
	* findcmd.c: Remove _initialize_mem_search prototype.
	* fork-child.c: Remove _initialize_fork_child prototype.
	* frame-base.c: Remove _initialize_frame_base prototype.
	* frame-unwind.c: Remove _initialize_frame_unwind prototype.
	* frame.c: Remove _initialize_frame prototype.
	* frv-linux-tdep.c: Remove _initialize_frv_linux_tdep prototype.
	* frv-tdep.c: Remove _initialize_frv_tdep prototype.
	* ft32-tdep.c: Remove _initialize_ft32_tdep prototype.
	* gcore.c: Remove _initialize_gcore prototype.
	* gdb_bfd.c: Remove _initialize_gdb_bfd prototype.
	* gdbarch.c: Regenerate.
	* gdbarch.sh: Remove _initialize_gdbarch prototype.
	* gdbtypes.c: Remove _initialize_gdbtypes prototype.
	* gnu-nat.c: Remove _initialize_gnu_nat prototype.
	* gnu-v2-abi.c: Remove _initialize_gnu_v2_abi prototype.
	* gnu-v3-abi.c: Remove _initialize_gnu_v3_abi prototype.
	* go-lang.c: Remove _initialize_go_language prototype.
	* go32-nat.c: Remove _initialize_go32_nat prototype.
	* guile/guile.c: Remove _initialize_guile prototype.
	* h8300-tdep.c: Remove _initialize_h8300_tdep prototype.
	* hppa-linux-nat.c: Remove _initialize_hppa_linux_nat prototype.
	* hppa-linux-tdep.c: Remove _initialize_hppa_linux_tdep prototype.
	* hppa-nbsd-nat.c: Remove _initialize_hppanbsd_nat prototype.
	* hppa-nbsd-tdep.c: Remove _initialize_hppanbsd_tdep prototype.
	* hppa-obsd-nat.c: Remove _initialize_hppaobsd_nat prototype.
	* hppa-obsd-tdep.c: Remove _initialize_hppaobsd_tdep prototype.
	* hppa-tdep.c: Remove _initialize_hppa_tdep prototype.
	* i386-bsd-nat.c: Remove _initialize_i386bsd_nat prototype.
	* i386-cygwin-tdep.c: Remove _initialize_i386_cygwin_tdep
	prototype.
	* i386-darwin-tdep.c: Remove _initialize_i386_darwin_tdep
	prototype.
	* i386-dicos-tdep.c: Remove _initialize_i386_dicos_tdep prototype.
	* i386-fbsd-nat.c: Remove _initialize_i386fbsd_nat prototype.
	* i386-fbsd-tdep.c: Remove _initialize_i386fbsd_tdep prototype.
	* i386-gnu-nat.c: Remove _initialize_i386gnu_nat prototype.
	* i386-gnu-tdep.c: Remove _initialize_i386gnu_tdep prototype.
	* i386-linux-nat.c: Remove _initialize_i386_linux_nat prototype.
	* i386-linux-tdep.c: Remove _initialize_i386_linux_tdep prototype.
	* i386-nbsd-nat.c: Remove _initialize_i386nbsd_nat prototype.
	* i386-nbsd-tdep.c: Remove _initialize_i386nbsd_tdep prototype.
	* i386-nto-tdep.c: Remove _initialize_i386nto_tdep prototype.
	* i386-obsd-nat.c: Remove _initialize_i386obsd_nat prototype.
	* i386-obsd-tdep.c: Remove _initialize_i386obsd_tdep prototype.
	* i386-sol2-nat.c: Remove _initialize_amd64_sol2_nat prototype.
	* i386-sol2-tdep.c: Remove _initialize_amd64_sol2_tdep prototype.
	* i386-tdep.c: Remove _initialize_i386_tdep prototype.
	* i386-windows-nat.c: Remove _initialize_i386_windows_nat
	prototype.
	* ia64-libunwind-tdep.c: Remove _initialize_libunwind_frame
	prototype.
	* ia64-linux-nat.c: Remove _initialize_ia64_linux_nat prototype.
	* ia64-linux-tdep.c: Remove _initialize_ia64_linux_tdep prototype.
	* ia64-tdep.c: Remove _initialize_ia64_tdep prototype.
	* ia64-vms-tdep.c: Remove _initialize_ia64_vms_tdep prototype.
	* infcall.c: Remove _initialize_infcall prototype.
	* infcmd.c: Remove _initialize_infcmd prototype.
	* inferior.c: Remove _initialize_inferiors prototype.
	* inflow.c: Remove _initialize_inflow prototype.
	* infrun.c: Remove _initialize_infrun prototype.
	* interps.c: Remove _initialize_interpreter prototype.
	* iq2000-tdep.c: Remove _initialize_iq2000_tdep prototype.
	* jit.c: Remove _initialize_jit prototype.
	* language.c: Remove _initialize_language prototype.
	* linux-fork.c: Remove _initialize_linux_fork prototype.
	* linux-nat.c: Remove _initialize_linux_nat prototype.
	* linux-tdep.c: Remove _initialize_linux_tdep prototype.
	* linux-thread-db.c: Remove _initialize_thread_db prototype.
	* lm32-tdep.c: Remove _initialize_lm32_tdep prototype.
	* m2-lang.c: Remove _initialize_m2_language prototype.
	* m32c-tdep.c: Remove _initialize_m32c_tdep prototype.
	* m32r-linux-nat.c: Remove _initialize_m32r_linux_nat prototype.
	* m32r-linux-tdep.c: Remove _initialize_m32r_linux_tdep prototype.
	* m32r-tdep.c: Remove _initialize_m32r_tdep prototype.
	* m68hc11-tdep.c: Remove _initialize_m68hc11_tdep prototype.
	* m68k-bsd-nat.c: Remove _initialize_m68kbsd_nat prototype.
	* m68k-bsd-tdep.c: Remove _initialize_m68kbsd_tdep prototype.
	* m68k-linux-nat.c: Remove _initialize_m68k_linux_tdep prototype.
	* m68k-linux-tdep.c: Remove _initialize_m68k_linux_tdep prototype.
	* m68k-tdep.c: Remove _initialize_m68k_tdep prototype.
	* m88k-bsd-nat.c: Remove _initialize_m68kbsd_nat prototype.
	* m88k-tdep.c: Remove _initialize_m68kbsd_tdep prototype.
	* machoread.c: Remove _initialize_machoread prototype.
	* macrocmd.c: Remove _initialize_macrocmd prototype.
	* macroscope.c: Remove _initialize_macroscope prototype.
	* maint.c: Remove _initialize_maint_cmds prototype.
	* mdebugread.c: Remove _initialize_mdebugread prototype.
	* memattr.c: Remove _initialize_mem prototype.
	* mep-tdep.c: Remove _initialize_mep_tdep prototype.
	* mi/mi-cmd-env.c: Remove _initialize_mi_cmd_env prototype.
	* mi/mi-cmds.c: Remove _initialize_mi_cmds prototype.
	* mi/mi-interp.c: Remove _initialize_mi_interp prototype.
	* mi/mi-main.c: Remove _initialize_mi_main prototype.
	* microblaze-linux-tdep.c: Remove
	_initialize_microblaze_linux_tdep prototype.
	* microblaze-tdep.c: Remove _initialize_microblaze_tdep prototype.
	* mips-fbsd-nat.c: Remove _initialize_mips_fbsd_nat prototype.
	* mips-fbsd-tdep.c: Remove _initialize_mips_fbsd_tdep prototype.
	* mips-linux-nat.c: Remove _initialize_mips_linux_nat prototype.
	* mips-linux-tdep.c: Remove _initialize_mips_linux_tdep prototype.
	* mips-nbsd-nat.c: Remove _initialize_mipsnbsd_nat prototype.
	* mips-nbsd-tdep.c: Remove _initialize_mipsnbsd_tdep prototype.
	* mips-sde-tdep.c: Remove _initialize_mips_sde_tdep prototype.
	* mips-tdep.c: Remove _initialize_mips_tdep prototype.
	* mips64-obsd-nat.c: Remove _initialize_mips64obsd_nat prototype.
	* mips64-obsd-tdep.c: Remove _initialize_mips64obsd_tdep
	prototype.
	* mipsread.c: Remove _initialize_mipsread prototype.
	* mn10300-linux-tdep.c: Remove _initialize_mn10300_linux_tdep
	prototype.
	* mn10300-tdep.c: Remove _initialize_mn10300_tdep prototype.
	* moxie-tdep.c: Remove _initialize_moxie_tdep prototype.
	* msp430-tdep.c: Remove _initialize_msp430_tdep prototype.
	* mt-tdep.c: Remove _initialize_mt_tdep prototype.
	* nds32-tdep.c: Remove _initialize_nds32_tdep prototype.
	* nios2-linux-tdep.c: Remove _initialize_nios2_linux_tdep
	prototype.
	* nios2-tdep.c: Remove _initialize_nios2_tdep prototype.
	* nto-procfs.c: Remove _initialize_procfs prototype.
	* nto-tdep.c: Remove _initialize_nto_tdep prototype.
	* objc-lang.c: Remove _initialize_objc_language prototype.
	* objfiles.c: Remove _initialize_objfiles prototype.
	* observer.c: Remove observer_test_first_notification_function,
	observer_test_second_notification_function,
	observer_test_third_notification_function, and
	_initialize_observer prototypes.
	* opencl-lang.c: Remove _initialize_opencl_language prototypes.
	* osabi.c: Remove _initialize_gdb_osabi prototype.
	* osdata.c: Remove _initialize_osdata prototype.
	* p-valprint.c: Remove _initialize_pascal_valprint prototype.
	* parse.c: Remove _initialize_parse prototype.
	* ppc-fbsd-nat.c: Remove _initialize_ppcfbsd_nat prototype.
	* ppc-fbsd-tdep.c: Remove _initialize_ppcfbsd_tdep prototype.
	* ppc-linux-nat.c: Remove _initialize_ppc_linux_nat prototype.
	* ppc-linux-tdep.c: Remove _initialize_ppc_linux_tdep prototype.
	* ppc-nbsd-nat.c: Remove _initialize_ppcnbsd_nat prototype.
	* ppc-nbsd-tdep.c: Remove _initialize_ppcnbsd_tdep prototype.
	* ppc-obsd-nat.c: Remove _initialize_ppcobsd_nat prototype.
	* ppc-obsd-tdep.c: Remove _initialize_ppcobsd_tdep prototype.
	* printcmd.c: Remove _initialize_printcmd prototype.
	* probe.c: Remove _initialize_probe prototype.
	* proc-api.c: Remove _initialize_proc_api prototype.
	* proc-events.c: Remove _initialize_proc_events prototype.
	* proc-service.c: Remove _initialize_proc_service prototype.
	* procfs.c: Remove _initialize_procfs prototype.
	* psymtab.c: Remove _initialize_psymtab prototype.
	* python/python.c: Remove _initialize_python prototype.
	* ravenscar-thread.c: Remove _initialize_ravenscar prototype.
	* record-btrace.c: Remove _initialize_record_btrace prototype.
	* record-full.c: Remove _initialize_record_full prototype.
	* record.c: Remove _initialize_record prototype.
	* regcache.c: Remove _initialize_regcache prototype.
	* reggroups.c: Remove _initialize_reggroup prototype.
	* remote-notif.c: Remove _initialize_notif prototype.
	* remote-sim.c: Remove _initialize_remote_sim prototype.
	* remote.c: Remove _initialize_remote prototype.
	* reverse.c: Remove _initialize_reverse prototype.
	* rl78-tdep.c: Remove _initialize_rl78_tdep prototype.
	* rs6000-aix-tdep.c: Remove _initialize_rs6000_aix_tdep prototype.
	* rs6000-lynx178-tdep.c: Remove _initialize_rs6000_lynx178_tdep
	prototype.
	* rs6000-nat.c: Remove _initialize_rs6000_nat prototype.
	* rs6000-tdep.c: Remove _initialize_rs6000_tdep prototype.
	* rust-exp.y: Remove _initialize_rust_exp prototype.
	* rx-tdep.c: Remove _initialize_rx_tdep prototype.
	* s390-linux-nat.c: Remove _initialize_s390_nat prototype.
	* s390-linux-tdep.c: Remove _initialize_s390_tdep prototype.
	* score-tdep.c: Remove _initialize_score_tdep prototype.
	* selftest-arch.c: Remove _initialize_selftests_foreach_arch
	prototype.
	* ser-go32.c: Remove _initialize_ser_dos prototype.
	* ser-mingw.c: Remove _initialize_ser_windows prototype.
	* ser-pipe.c: Remove _initialize_ser_pipe prototype.
	* ser-tcp.c: Remove _initialize_ser_tcp prototype.
	* ser-unix.c: Remove _initialize_ser_hardwire prototype.
	* serial.c: Remove _initialize_serial prototype.
	* sh-linux-tdep.c: Remove _initialize_sh_linux_tdep prototype.
	* sh-nbsd-nat.c: Remove _initialize_shnbsd_nat prototype.
	* sh-nbsd-tdep.c: Remove _initialize_shnbsd_tdep prototype.
	* sh-tdep.c: Remove _initialize_sh_tdep prototype.
	* skip.c: Remove _initialize_step_skip prototype.
	* sol-thread.c: Remove _initialize_sol_thread prototype.
	* solib-aix.c: Remove _initialize_solib_aix prototype.
	* solib-darwin.c: Remove _initialize_darwin_solib prototype.
	* solib-dsbt.c: Remove _initialize_dsbt_solib prototype.
	* solib-frv.c: Remove _initialize_frv_solib prototype.
	* solib-spu.c: Remove _initialize_spu_solib prototype.
	* solib-svr4.c: Remove _initialize_svr4_solib prototype.
	* solib-target.c: Remove _initialize_solib_target prototype.
	* solib.c: Remove _initialize_solib prototype.
	* source.c: Remove _initialize_source prototype.
	* sparc-linux-nat.c: Remove _initialize_sparc_linux_nat prototype.
	* sparc-linux-tdep.c: Remove _initialize_sparc_linux_tdep
	prototype.
	* sparc-nat.c: Remove _initialize_sparc_nat prototype.
	* sparc-nbsd-nat.c: Remove _initialize_sparcnbsd_nat prototype.
	* sparc-nbsd-tdep.c: Remove _initialize_sparcnbsd_tdep prototype.
	* sparc-obsd-tdep.c: Remove _initialize_sparc32obsd_tdep
	prototype.
	* sparc-sol2-nat.c: Remove _initialize_sparc_sol2_nat prototype.
	* sparc-sol2-tdep.c: Remove _initialize_sparc_sol2_tdep prototype.
	* sparc-tdep.c: Remove _initialize_sparc_tdep prototype.
	* sparc64-fbsd-nat.c: Remove _initialize_sparc64fbsd_nat
	prototype.
	* sparc64-fbsd-tdep.c: Remove _initialize_sparc64fbsd_tdep
	prototype.
	* sparc64-linux-nat.c: Remove _initialize_sparc64_linux_nat
	prototype.
	* sparc64-linux-tdep.c: Remove _initialize_sparc64_linux_tdep
	prototype.
	* sparc64-nat.c: Remove _initialize_sparc64_nat prototype.
	* sparc64-nbsd-nat.c: Remove _initialize_sparc64nbsd_nat
	prototype.
	* sparc64-nbsd-tdep.c: Remove _initialize_sparc64nbsd_tdep
	prototype.
	* sparc64-obsd-nat.c: Remove _initialize_sparc64obsd_nat
	prototype.
	* sparc64-obsd-tdep.c: Remove _initialize_sparc64obsd_tdep
	prototype.
	* sparc64-sol2-tdep.c: Remove _initialize_sparc64_sol2_tdep
	prototype.
	* spu-linux-nat.c: Remove _initialize_spu_nat prototype.
	* spu-multiarch.c: Remove _initialize_spu_multiarch prototype.
	* spu-tdep.c: Remove _initialize_spu_tdep prototype.
	* stabsread.c: Remove _initialize_stabsread prototype.
	* stack.c: Remove _initialize_stack prototype.
	* stap-probe.c: Remove _initialize_stap_probe prototype.
	* std-regs.c: Remove _initialize_frame_reg prototype.
	* symfile-debug.c: Remove _initialize_symfile_debug prototype.
	* symfile-mem.c: Remove _initialize_symfile_mem prototype.
	* symfile.c: Remove _initialize_symfile prototype.
	* symmisc.c: Remove _initialize_symmisc prototype.
	* symtab.c: Remove _initialize_symtab prototype.
	* target-dcache.c: Remove _initialize_target_dcache prototype.
	* target-descriptions.c: Remove _initialize_target_descriptions
	prototype.
	* thread.c: Remove _initialize_thread prototype.
	* tic6x-linux-tdep.c: Remove _initialize_tic6x_linux_tdep
	prototype.
	* tic6x-tdep.c: Remove _initialize_tic6x_tdep prototype.
	* tilegx-linux-nat.c: Remove _initialize_tile_linux_nat prototype.
	* tilegx-linux-tdep.c: Remove _initialize_tilegx_linux_tdep
	prototype.
	* tilegx-tdep.c: Remove _initialize_tilegx_tdep prototype.
	* tracefile-tfile.c: Remove _initialize_tracefile_tfile prototype.
	* tracefile.c: Remove _initialize_tracefile prototype.
	* tracepoint.c: Remove _initialize_tracepoint prototype.
	* tui/tui-hooks.c: Remove _initialize_tui_hooks prototype.
	* tui/tui-interp.c: Remove _initialize_tui_interp prototype.
	* tui/tui-layout.c: Remove _initialize_tui_layout prototype.
	* tui/tui-regs.c: Remove _initialize_tui_regs prototype.
	* tui/tui-stack.c: Remove _initialize_tui_stack prototype.
	* tui/tui-win.c: Remove _initialize_tui_win prototype.
	* tui/tui.c: Remove _initialize_tui prototype.
	* typeprint.c: Remove _initialize_typeprint prototype.
	* user-regs.c: Remove _initialize_user_regs prototype.
	* utils.c: Remove _initialize_utils prototype.
	* v850-tdep.c: Remove _initialize_v850_tdep prototype.
	* valarith.c: Remove _initialize_valarith prototype.
	* valops.c: Remove _initialize_valops prototype.
	* valprint.c: Remove _initialize_valprint prototype.
	* value.c: Remove _initialize_values prototype.
	* varobj.c: Remove _initialize_varobj prototype.
	* vax-bsd-nat.c: Remove _initialize_vaxbsd_nat prototype.
	* vax-nbsd-tdep.c: Remove _initialize_vaxnbsd_tdep prototype.
	* vax-tdep.c: Remove _initialize_vax_tdep prototype.
	* windows-nat.c: Remove _initialize_windows_nat,
	_initialize_check_for_gdb_ini, and _initialize_loadable
	prototypes.
	* windows-tdep.c: Remove _initialize_windows_tdep prototype.
	* xcoffread.c: Remove _initialize_xcoffread prototype.
	* xml-support.c: Remove _initialize_xml_support prototype.
	* xstormy16-tdep.c: Remove _initialize_xstormy16_tdep prototype.
	* xtensa-linux-nat.c: Remove _initialize_xtensa_linux_nat
	prototype.
	* xtensa-linux-tdep.c: Remove _initialize_xtensa_linux_tdep
	prototype.
	* xtensa-tdep.c: Remove _initialize_xtensa_tdep prototype.
2017-09-09 11:02:37 -07:00
Simon Marchi fc80982757 Improve "'g' reply is is to long" error message
... by adding the expected size, and the received size.  I found this
useful when debugging gdbarch/remote issues, since it gives a hint of
what gdb expects and what the remote sent.

gdb/ChangeLog:

	* remote.c (process_g_packet): Update error message.
2017-09-05 17:41:03 +02:00
Sergio Durigan Junior 0a2dde4a32 Implement the ability to set/unset environment variables to GDBserver when starting the inferior
This patch implements the ability to set/unset environment variables
on the remote target, mimicking what GDB already offers to the user.
There are two features present here: user-set and user-unset
environment variables.

User-set environment variables are only the variables that are
explicitly set by the user, using the 'set environment' command.  This
means that variables that were already present in the environment when
starting GDB/GDBserver are not transmitted/considered by this feature.

User-unset environment variables are variables that are explicitly
unset by the user, using the 'unset environment' command.

The idea behind this patch is to store user-set and user-unset
environment variables in two separate sets, both part of gdb_environ.
Then, when extended_remote_create_inferior is preparing to start the
inferior, it will iterate over the two sets and set/unset variables
accordingly.  Three new packets are introduced:

- QEnvironmentHexEncoded, which is used to set environment variables,
  and contains an hex-encoded string in the format "VAR=VALUE" (VALUE
  can be empty if the user set a variable with a null value, by doing
  'set environment VAR=').

- QEnvironmentUnset, which is used to unset environment variables, and
  contains an hex-encoded string in the format "VAR".

- QEnvironmentReset, which is always the first packet to be
  transmitted, and is used to reset the environment, i.e., discard any
  changes made by the user on previous runs.

The QEnvironmentHexEncoded packet is inspired on LLDB's extensions to
the RSP.  Details about it can be seen here:

  <https://raw.githubusercontent.com/llvm-mirror/lldb/master/docs/lldb-gdb-remote.txt>

I decided not to implement the QEnvironment packet because it is
considered deprecated by LLDB.  This packet, on LLDB, serves the same
purpose of QEnvironmentHexEncoded, but sends the information using a
plain text, non-hex-encoded string.

The other two packets are new.

This patch also includes updates to the documentation, testsuite, and
unit tests, without introducing regressions.

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

	* NEWS (Changes since GDB 8.0): Add entry mentioning new support
	for setting/unsetting environment variables on the remote target.
	(New remote packets): Add entries for QEnvironmentHexEncoded,
	QEnvironmentUnset and QEnvironmentReset.
	* common/environ.c (gdb_environ::operator=): Extend method to
	handle m_user_set_env_list and m_user_unset_env_list.
	(gdb_environ::clear): Likewise.
	(match_var_in_string): Change type of first parameter from 'char
	*' to 'const char *'.
	(gdb_environ::set): Extend method to handle
	m_user_set_env_list and m_user_unset_env_list.
	(gdb_environ::unset): Likewise.
	(gdb_environ::clear_user_set_env): New method.
	(gdb_environ::user_set_envp): Likewise.
	(gdb_environ::user_unset_envp): Likewise.
	* common/environ.h (gdb_environ): Handle m_user_set_env_list and
	m_user_unset_env_list on move constructor/assignment.
	(unset): Add new default parameter 'update_unset_list = true'.
	(clear_user_set_env): New method.
	(user_set_envp): Likewise.
	(user_unset_envp): Likewise.
	(m_user_set_env_list): New std::set.
	(m_user_unset_env_list): Likewise.
	* common/rsp-low.c (hex2str): New function.
	(bin2hex): New overload for bin2hex function.
	* common/rsp-low.c (hex2str): New prototype.
	(str2hex): New overload prototype.
	* remote.c: Include "environ.h". Add QEnvironmentHexEncoded,
	QEnvironmentUnset and QEnvironmentReset.
	(remote_protocol_features): Add QEnvironmentHexEncoded,
	QEnvironmentUnset and QEnvironmentReset packets.
	(send_environment_packet): New function.
	(extended_remote_environment_support): Likewise.
	(extended_remote_create_inferior): Call
	extended_remote_environment_support.
	(_initialize_remote): Add QEnvironmentHexEncoded,
	QEnvironmentUnset and QEnvironmentReset packet configs.
	* unittests/environ-selftests.c (gdb_selftest_env_var):
	New variable.
	(test_vector_initialization): New function.
	(test_init_from_host_environ): Likewise.
	(test_reinit_from_host_environ): Likewise.
	(test_set_A_unset_B_unset_A_cannot_find_A_can_find_B):
	Likewise.
	(test_unset_set_empty_vector): Likewise.
	(test_vector_clear): Likewise.
	(test_std_move): Likewise.
	(test_move_constructor):
	(test_self_move): Likewise.
	(test_set_unset_reset): Likewise.
	(run_tests): Rewrite in terms of the functions above.

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

	* server.c (handle_general_set): Handle QEnvironmentHexEncoded,
	QEnvironmentUnset and QEnvironmentReset packets.
	(handle_query): Inform remote that QEnvironmentHexEncoded,
	QEnvironmentUnset and QEnvironmentReset are supported.

gdb/doc/ChangeLog:
2017-08-31  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (set environment): Add @anchor.  Explain that
	environment variables set by the user are sent to GDBserver.
	(unset environment): Likewise, but for unsetting variables.
	(Connecting) <Remote Packet>: Add "environment-hex-encoded",
	"QEnvironmentHexEncoded", "environment-unset", "QEnvironmentUnset",
	"environment-reset" and "QEnvironmentReset" to the table.
	(Remote Protocol) <QEnvironmentHexEncoded, QEnvironmentUnset,
	QEnvironmentReset>: New item, explaining the packet.

gdb/testsuite/ChangeLog:
2017-08-31  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.base/share-env-with-gdbserver.c: New file.
	* gdb.base/share-env-with-gdbserver.exp: Likewise.
2017-08-31 17:22:10 -04:00
Sergio Durigan Junior 87215ad165 Fix PR remote/21852: Remote run without specifying a local binary crashes GDB
There is an assertion that is triggering when we start GDB and
instruct it to debug a remote inferior, but don't provide a local
binary, like:

  ./gdb -nx -q --data-directory=data-directory -ex "tar ext :1234" \
    -ex "set remote exec-file /bin/ls" -ex r

In this case, when calling exec_file_locate_attach to locate the
inferior, GDB is incorrectly resetting the breakpoints without a
thread/inferior even running, which causes an assertion to be
triggered:

  binutils-gdb/gdb/thread.c:1609: internal-error: scoped_restore_current_thread::scoped_restore_current_thread(): Assertion `tp != NULL' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n)

This happens because add_current_inferior_and_thread (on remote.c) is
breaking an invariant: making inferior_ptid point to a non-existing
thread and then calling common code, which in this case is
breakpoint_re_set.  The fix is to make sure that inferior_ptid points
to null_ptid if there is no thread present.

A testcase is provided.  Regtested on buildbot.

gdb/ChangeLog:
2017-08-23  Pedro Alves  <palves@redhat.com>

	PR remote/21852
	* remote.c (add_current_inferior_and_thread): Set inferior_ptid
	to null_ptid and switch to thread without reading the registers
	after adding the inferior.

gdb/testsuite/ChangeLog:
2017-08-23  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR remote/21852
	* gdb.server/normal.c: New file, copied from gdb.base.
	* gdb.server/run-without-local-binary.exp: New file.
2017-08-23 17:28:02 -04:00
Tom Tromey 773a1edcd1 Introduce gdb_argv, a class wrapper for buildargv
This introduces gdb_argv, a class wrapping an "argv" pointer; that is,
a pointer to a NULL-terminated array of char*, where both the array
and each non-NULL element in the array are xmalloc'd.

This patch then changes most users of gdb_buildargv to use gdb_argv
instead.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* utils.h (struct gdb_argv_deleter): New.
	(gdb_argv): New class.
	* utils.c (gdb_argv::reset): New method.
	* tracepoint.c (delete_trace_variable_command): Use gdb_argv.
	* tracefile.c (tsave_command): Use gdb_argv.
	* top.c (new_ui_command): Use gdb_argv.
	* symmisc.c (maintenance_print_symbols)
	(maintenance_print_msymbols, maintenance_expand_symtabs): Use gdb_argv.
	* symfile.c (symbol_file_command, generic_load)
	(remove_symbol_file_command): Use gdb_argv.
	* stack.c (backtrace_command): Use gdb_argv.
	* source.c (add_path, show_substitute_path_command)
	(unset_substitute_path_command, set_substitute_path_command):
	Use gdb_argv.
	* skip.c (skip_command): Use gdb_argv.  Use gdb_buildargv.
	* ser-mingw.c (pipe_windows_open): Use gdb_argv.
	* remote.c (extended_remote_run, remote_put_command)
	(remote_get_command, remote_delete_command): Use gdb_argv.
	* remote-sim.c (gdbsim_load, gdbsim_create_inferior)
	(gdbsim_open): Use gdb_argv.
	* python/py-cmd.c (gdbpy_string_to_argv): Use gdb_argv.
	* psymtab.c (maintenance_print_psymbols): Use gdb_argv.
	* procfs.c (procfs_info_proc): Use gdb_argv.
	* interps.c (interpreter_exec_cmd): Use gdb_argv.
	* infrun.c (handle_command): Use gdb_argv.
	* inferior.c (add_inferior_command, clone_inferior_command):
	Use gdb_argv.
	* guile/scm-string.c (gdbscm_string_to_argv): Use gdb_argv.
	* exec.c (exec_file_command): Use gdb_argv.
	* cli/cli-cmds.c (alias_command): Use gdb_argv.
	* compile/compile.c (build_argc_argv): Use gdb_argv.
2017-08-03 07:59:08 -06:00
Tom Tromey 2ec845e758 More uses of scoped_restore
There were a few more places in gdb that could easily use
scoped_restore, replacing some cleanups.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* reverse.c (exec_direction_default): Remove.
	(exec_reverse_once): Use scoped_restore.
	* remote.c (restore_remote_timeout): Remove.
	(remote_flash_erase, remote_flash_write, remote_flash_done)
	(readchar, remote_serial_write): Use scoped_restore.
	* cli/cli-script.c (struct source_cleanup_lines_args)
	(source_cleanup_lines): Remove.
	(script_from_file): Use scoped_restore.
	* cli/cli-cmds.c (source_verbose_cleanup): Remove.
	(source_command): Use scoped_restore.
2017-08-03 07:59:00 -06:00
Tom Tromey d419f42dd3 Introduce and use gdb_file_up
This introduces gdb_file_up, a unique pointer holding a FILE*, and
then changes some code in gdb to use it.  In particular
gdb_fopen_cloexec now returns a gdb_file_up.  This allow removing some
cleanups.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* xml-support.c (xml_fetch_content_from_file): Update.
	* ui-file.c (stdio_file::open): Update.
	* tracefile-tfile.c (tfile_start): Update.
	* remote.c (remote_file_put, remote_file_get): Update.
	* nat/linux-procfs.c (linux_proc_get_int)
	(linux_proc_pid_get_state, linux_proc_tid_get_name): Update.
	* nat/linux-osdata.c (linux_common_core_of_thread): Update.
	(command_from_pid, commandline_from_pid, linux_xfer_osdata_cpus)
	(print_sockets, linux_xfer_osdata_shm, linux_xfer_osdata_sem)
	(linux_xfer_osdata_msg, linux_xfer_osdata_modules): Update.
	* nat/linux-btrace.c (linux_determine_kernel_start): Update.
	* linux-nat.c (linux_proc_pending_signals): Update.
	* dwarf2read.c (write_psymtabs_to_index): Use gdb_file_up.
	(file_closer): Remove.
	* compile/compile.c (compile_to_object): Update.
	* common/filestuff.h (struct gdb_file_deleter): New.
	(gdb_file_up): New typedef.
	(gdb_fopen_cloexec): Change return type.
	* common/filestuff.c (gdb_fopen_cloexec): Return gdb_file_up.
	* cli/cli-dump.c (fopen_with_cleanup): Remove.
	(dump_binary_file, restore_binary_file): Update.
	* auto-load.c (auto_load_objfile_script_1): Update.
2017-08-03 07:58:52 -06:00
Yao Qi 27841e762c Remove one line comment
This patch is going to remove a line comment, which was added in this
commit,

commit 55fea07
Author: Jim Kingdon <jkingdon@engr.sgi.com>
Date:   Tue Sep 14 01:08:22 1993 +0000

        * remote.c: Define remote_debug to 0 and #if 0 baud_rate.  Temporary
        hack so this file compiles again.

        * remote-utils.c (gr_multi_scan): Cast return value from alloca.
        (gr_multi_scan): #if 0 never-reached return(-1).

and at that moment, remote_prepare_to_store does updates some global
state,

static void
remote_prepare_to_store ()
{
  /* Make sure the entire registers array is valid.  */
  read_register_bytes (0, (char *)NULL, REGISTER_BYTES);
}

However, now, remote_prepare_to_store doesn't do that at all, and
rsa->sizeof_g_packet is updated in init_remote_state, so the line of
comment is out of date, and this patch removes it.

gdb:

2017-07-18  Yao Qi  <yao.qi@linaro.org>

	* remote.c (store_registers_using_G): Remove one line comment.
2017-07-18 12:57:19 +01:00
Alan Hayward 4fa847d78e Remove MAX_REGISTER_SIZE from py-unwind.c
gdb/
	* remote.c (cached_reg): Move from here...
	* regcache.h (cached_reg): ...to here.
	* python/py-unwind.c (struct reg_info): Remove.
	(cached_frame_info): Use cached_reg_t.
	(pyuw_prev_register): Likewise.
	(pyuw_sniffer): Use cached_reg_t and allocate registers.
	(pyuw_dealloc_cache): Free all registers.
2017-06-22 14:10:34 +01:00
Sergio Durigan Junior aefd8b33d9 Implement proper "startup-with-shell" support on gdbserver
This patch implements the proper support for the "startup-with-shell"
feature on gdbserver.  A new packet is added, QStartupWithShell, and
it is sent on initialization.  If the host sends a
"QStartupWithShell:1", it means the inferior shall be started using a
shell.  If the host sends a "QStartupWithShell:0", it means the
inferior shall be started without using a shell.  Any other value is
considered an error.

There is no way to remotely set the shell that will be used by the
target to start the inferior.  In order to do that, the user must
start gdbserver while providing a shell via the $SHELL environment
variable.  The same is true for the host side.

The "set startup-with-shell" setting from the host side is used to
decide whether to start the remote inferior using a shell.  This same
setting is also used to decide whether to use a shell to start the
host inferior; this means that it is not really possible to start the
inferior using different mechanisms on target and host.

A documentation patch is included, along with a new testcase for the
feature.

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

	* NEWS (Changes since GDB 8.0): Announce that GDBserver is now
	able to start inferiors	using a shell.
	(New remote packets): Announce new packet "QStartupWithShell".
	* remote.c: Add PACKET_QStartupWithShell.
	(extended_remote_create_inferior): Handle new
	PACKET_QStartupWithShell.
	(remote_protocol_features) <QStartupWithShell>: New entry for
	PACKET_QStartupWithShell.
	(_initialize_remote): Call "add_packet_config_cmd" for
	QStartupShell.

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

	* server.c (handle_general_set): Handle new packet
	"QStartupWithShell".
	(handle_query): Add "QStartupWithShell" to the list of supported
	packets.
	(gdbserver_usage): Add help text explaining the
	new "--startup-with-shell" and "--no-startup-with-shell" CLI
	options.
	(captured_main): Recognize and act upon the presence of the new
	CLI options.

gdb/testsuite/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.base/startup-with-shell.c: New file.
	* gdb.base/startup-with-shell.exp: Likewise.

gdb/doc/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (Starting) <startup-with-shell>: Add @anchor.
	(Connecting) <Remote Packet>: Add "startup-with-shell"
	and "QStartupWithShell" to the table.
	(Remote Protocol) <QStartupWithShell>: New item, explaining the
	packet.
2017-06-07 19:56:09 -04:00
Simon Marchi c1fc265720 C++ify breakpoint class hierarchy (destructors only)
Breakpoints are currently in a limbo state between C and C++.  There is
a pseudo class hierarchy implemented using struct fields.  Taking
watchpoint as an example:

  struct watchpoint
  {
    /* The base class.  */
    struct breakpoint base;

    ...
  }

and it is instantianted with "new watchpoint ()".  When destroyed, a
destructor is first invoked through the breakpoint_ops, and then the
memory is freed by calling delete through a pointer to breakpoint.
Address sanitizer complains about this, for example, because we new and
delete the same memory using different types.

This patch takes the logical step of making breakpoint subclasses extend
the breakpoint class for real, and converts their destructors to actual
C++ destructors.

Regtested on the buildbot.

gdb/ChangeLog:

	* breakpoint.h (struct breakpoint_ops) <dtor>: Remove.
	(struct breakpoint) <~breakpoint>: New.
	(struct watchpoint): Inherit from breakpoint.
	<~watchpoint>: New.
	<base>: Remove.
	(struct tracepoint): Inherit from breakpoint.
	<base>: Remove.
	* breakpoint.c (longjmp_breakpoint_ops): Remove.
	(struct longjmp_breakpoint): Inherit from breakpoint.
	<~longjmp_breakpoint>: New.
	<base>: Remove.
	(new_breakpoint_from_type): Remove casts.
	(watchpoint_in_thread_scope): Remove reference to base field.
	(watchpoint_del_at_next_stop): Likewise.
	(update_watchpoint): Likewise.
	(watchpoint_check): Likewise.
	(bpstat_check_watchpoint): Likewise.
	(set_longjmp_breakpoint): Likewise.
	(struct fork_catchpoint): Inherit from breakpoint.
	<base>: Remove.
	(struct solib_catchpoint): Inherit from breakpoint.
	<~solib_catchpoint>: New.
	<base>: Remove.
	(dtor_catch_solib): Change to ...
	(solib_catchpoint::~solib_catchpoint): ... this.
	(breakpoint_hit_catch_solib): Remove reference to base field.
	(add_solib_catchpoint): Likewise.
	(create_fork_vfork_event_catchpoint): Likewise.
	(struct exec_catchpoint): Inherit from breakpoint.
	<~exec_catchpoint>: New.
	<base>: Remove.
	(dtor_catch_exec): Change to ...
	(exec_catchpoint::~exec_catchpoint): ... this.
	(dtor_watchpoint): Change to ...
	(watchpoint::~watchpoint): ... this.
	(watch_command_1): Remove reference to base field.
	(catch_exec_command_1): Likewise.
	(base_breakpoint_dtor): Change to ...
	(breakpoint::~breakpoint): ... this.
	(base_breakpoint_ops): Remove dtor field value.
	(longjmp_bkpt_dtor): Change to ...
	(longjmp_breakpoint::~longjmp_breakpoint): ... this.
	(strace_marker_create_breakpoints_sal): Remove reference to base
	field.
	(delete_breakpoint): Don't manually call breakpoint destructor.
	(create_tracepoint_from_upload): Remove reference to base field.
	(trace_pass_set_count): Likewise.
	(initialize_breakpoint_ops): Don't initialize
	momentary_breakpoint_ops, don't set dtors.
	* ada-lang.c (struct ada_catchpoint): Inherit from breakpoint.
	<~ada_catchpoint>: New.
	<base>: Remove.
	(create_excep_cond_exprs): Remove reference to base field.
	(dtor_exception): Change to ...
	(ada_catchpoint::~ada_catchpoint): ... this.
	(dtor_catch_exception): Remove.
	(dtor_catch_exception_unhandled): Remove.
	(dtor_catch_assert): Remove.
	(create_ada_exception_catchpoint): Remove reference to base
	field.
	(initialize_ada_catchpoint_ops): Don't set dtors.
	* break-catch-sig.c (struct signal_catchpoint): Inherit from
	breakpoint.
	<~signal_catchpoint>: New.
	<base>: Remove.
	(signal_catchpoint_dtor): Change to ...
	(signal_catchpoint::~signal_catchpoint): ... this.
	(create_signal_catchpoint): Remove reference to base field.
	(initialize_signal_catchpoint_ops): Don't set dtor.
	* break-catch-syscall.c (struct syscall_catchpoint): Inherit
	from breakpoint.
	<~syscall_catchpoint>: New.
	<base>: Remove.
	(dtor_catch_syscall): Change to ...
	(syscall_catchpoint::~syscall_catchpoint): ... this.
	(create_syscall_event_catchpoint): Remove reference to base
	field.
	(initialize_syscall_catchpoint_ops): Don't set dtor.
	* break-catch-throw.c (struct exception_catchpoint): Inherit
	from breakpoint.
	<~exception_catchpoint>: New.
	<base>: Remove.
	(dtor_exception_catchpoint): Change to ...
	(exception_catchpoint::~exception_catchpoint): ... this.
	(handle_gnu_v3_exceptions): Remove reference to base field.
	(initialize_throw_catchpoint_ops): Don't set dtor.
	* ctf.c (ctf_get_traceframe_address): Remove reference to base
	field.
	* remote.c (remote_get_tracepoint_status): Likewise.
	* tracefile-tfile.c (tfile_get_traceframe_address): Likewise.
	* tracefile.c (tracefile_fetch_registers): Likewise.
	* tracepoint.c (actions_command): Likewise.
	(validate_actionline): Likewise.
	(tfind_1): Likewise.
	(get_traceframe_location): Likewise.
	(find_matching_tracepoint_location): Likewise.
	(parse_tracepoint_status): Likewise.
	* mi/mi-cmd-break.c (mi_cmd_break_passcount): Likewise.
2017-06-02 23:16:21 +02:00
Pedro Alves 5ed8105e02 RAII-fy make_cleanup_restore_current_thread & friends
After all the make_cleanup_restore_current_thread fixing, I thought
I'd convert that and its relatives (which are all cleanups) to RAII
classes.

scoped_restore_current_pspace_and_thread was put in a separate file to
avoid a circular dependency.

Tested on x86-64 Fedora 23, native and gdbserver.

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

	* Makefile.in (SFILES): Add progspace-and-thread.c.
	(HFILES_NO_SRCDIR): Add progspace-and-thread.h.
	(COMMON_OBS): Add progspace-and-thread.o.
	* breakpoint.c: Include "progspace-and-thread.h".
	(update_inserted_breakpoint_locations)
	(insert_breakpoint_locations, create_longjmp_master_breakpoint):
	Use scoped_restore_current_pspace_and_thread.
	(create_std_terminate_master_breakpoint): Use
	scoped_restore_current_program_space.
	(remove_breakpoint): Use scoped_restore_current_pspace_and_thread.
	(print_breakpoint_location): Use
	scoped_restore_current_program_space.
	(bp_loc_is_permanent): Use
	scoped_restore_current_pspace_and_thread.
	(resolve_sal_pc): Use scoped_restore_current_pspace_and_thread.
	(download_tracepoint_locations): Use
	scoped_restore_current_pspace_and_thread.
	(breakpoint_re_set): Use scoped_restore_current_pspace_and_thread.
	* exec.c (exec_close_1): Use scoped_restore_current_program_space.
	(enum step_over_calls_kind): Moved from inferior.h.
	(class scoped_restore_current_thread): New class.
	* gdbthread.h (make_cleanup_restore_current_thread): Delete
	declaration.
	(scoped_restore_current_thread): New class.
	* infcmd.c: Include "common/gdb_optional.h".
	(continue_1, proceed_after_attach): Use
	scoped_restore_current_thread.
	(notice_new_inferior): Use scoped_restore_current_thread.
	* inferior.c: Include "progspace-and-thread.h".
	(restore_inferior, save_current_inferior): Delete.
	(add_inferior_command, clone_inferior_command): Use
	scoped_restore_current_pspace_and_thread.
	* inferior.h (scoped_restore_current_inferior): New class.
	* infrun.c: Include "progspace-and-thread.h" and
	"common/gdb_optional.h".
	(follow_fork_inferior): Use
	scoped_restore_current_pspace_and_thread.
	(scoped_restore_exited_inferior): New class.
	(handle_vfork_child_exec_or_exit): Use
	scoped_restore_exited_inferior,
	scoped_restore_current_pspace_and_thread,
	scoped_restore_current_thread and scoped_restore.
	(fetch_inferior_event): Use scoped_restore_current_thread.
	* linespec.c (decode_line_full, decode_line_1): Use
	scoped_restore_current_program_space.
	* mi/mi-main.c: Include "progspace-and-thread.h".
	(exec_continue): Use scoped_restore_current_thread.
	(mi_cmd_exec_run): Use scoped_restore_current_pspace_and_thread.
	(mi_cmd_trace_frame_collected): Use scoped_restore_current_thread.
	* proc-service.c (ps_pglobal_lookup): Use
	scoped_restore_current_program_space.
	* progspace-and-thread.c: New file.
	* progspace-and-thread.h: New file.
	* progspace.c (release_program_space, clone_program_space): Use
	scoped_restore_current_program_space.
	(restore_program_space, save_current_program_space)
	(save_current_space_and_thread): Delete.
	(switch_to_program_space_and_thread): Moved to
	progspace-and-thread.c.
	* progspace.h (save_current_program_space)
	(save_current_space_and_thread): Delete declarations.
	(scoped_restore_current_program_space): New class.
	* remote.c (remote_btrace_maybe_reopen): Use
	scoped_restore_current_thread.
	* symtab.c: Include "progspace-and-thread.h".
	(skip_prologue_sal): Use scoped_restore_current_pspace_and_thread.
	* thread.c (print_thread_info_1): Use
	scoped_restore_current_thread.
	(struct current_thread_cleanup): Delete.
	(do_restore_current_thread_cleanup)
	(restore_current_thread_cleanup_dtor): Rename/convert both to ...
	(scoped_restore_current_thread::~scoped_restore_current_thread):
	... this new dtor.
	(make_cleanup_restore_current_thread): Rename/convert to ...
	(scoped_restore_current_thread::scoped_restore_current_thread):
	... this new ctor.
	(thread_apply_all_command): Use scoped_restore_current_thread.
	(thread_apply_command): Use scoped_restore_current_thread.
	* tracepoint.c (tdump_command): Use scoped_restore_current_thread.
	* varobj.c (value_of_root_1): Use scoped_restore_current_thread.
2017-05-04 15:18:44 +01:00
Tom Tromey 2e78302469 Use ui_out_emit_tuple
This patch changes various places to use ui_out_emit_tuple,
eliminating a number of cleanups.  This patch only tackles "easy"
cases, which are ones where the cleanups in question were
block-structured and did not involve any changes other than the
obvious replacement.

ChangeLog
2017-04-22  Tom Tromey  <tom@tromey.com>

	* record-btrace.c (record_btrace_insn_history)
	(record_btrace_insn_history_range, record_btrace_call_history)
	(record_btrace_call_history_range): Use ui_out_emit_tuple.
	* thread.c (do_captured_list_thread_ids, print_thread_info_1): Use
	ui_out_emit_tuple.
	* stack.c (print_frame_info): Use ui_out_emit_tuple.
	* solib.c (info_sharedlibrary_command): Use ui_out_emit_tuple.
	* skip.c (skip_info): Use ui_out_emit_tuple.
	* remote.c (show_remote_cmd): Use ui_out_emit_tuple.
	* progspace.c (print_program_space): Use ui_out_emit_tuple.
	* probe.c (info_probes_for_ops): Use ui_out_emit_tuple.
	* osdata.c (info_osdata): Use ui_out_emit_tuple.
	* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Use
	ui_out_emit_tuple.
	* mi/mi-main.c (print_one_inferior, list_available_thread_groups)
	(output_register, mi_cmd_data_read_memory)
	(mi_cmd_data_read_memory_bytes, mi_load_progress)
	(mi_cmd_trace_frame_collected): Use ui_out_emit_tuple.
	* mi/mi-cmd-var.c (mi_cmd_var_list_children, varobj_update_one):
	Use ui_out_emit_tuple.
	* mi/mi-cmd-stack.c (mi_cmd_stack_list_args): Use
	ui_out_emit_tuple.
	* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions)
	(mi_cmd_info_gdb_mi_command): Use ui_out_emit_tuple.
	* linux-thread-db.c (info_auto_load_libthread_db): Use
	ui_out_emit_tuple.
	* inferior.c (print_inferior): Use ui_out_emit_tuple.
	* gdb_bfd.c (print_one_bfd): Use ui_out_emit_tuple.
	* disasm.c (do_mixed_source_and_assembly_deprecated)
	(do_mixed_source_and_assembly): Use ui_out_emit_tuple.
	* cp-abi.c (list_cp_abis): Use ui_out_emit_tuple.
	* cli/cli-setshow.c (cmd_show_list): Use ui_out_emit_tuple.
	* breakpoint.c (print_one_breakpoint_location)
	(print_one_breakpoint): Use ui_out_emit_tuple.
	* auto-load.c (print_script, info_auto_load_cmd): Use
	ui_out_emit_tuple.
	* ada-tasks.c (print_ada_task_info): Use ui_out_emit_tuple.
2017-04-22 09:46:58 -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
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 a121b7c1ac -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.
2017-04-05 19:21:37 +01:00
Pedro Alves 7a1149643d -Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info
-Wwrite-strings flagged a missing cast for example here:

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

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

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

	* aix-thread.c (aix_thread_pid_to_str)
	(aix_thread_extra_thread_info): Constify.
	* bsd-kvm.c (bsd_kvm_pid_to_str): Constify.
	* bsd-uthread.c (bsd_uthread_extra_thread_info)
	(bsd_uthread_pid_to_str): Constify.
	* corelow.c (core_pid_to_str): Constify.
	* darwin-nat.c (darwin_pid_to_str): Constify.
	* fbsd-nat.c (fbsd_pid_to_str): Constify.
	* fbsd-tdep.c (fbsd_core_pid_to_str, gdbarch_core_pid_to_str):
	Constify.
	* gnu-nat.c (gnu_pid_to_str): Constify.
	* go32-nat.c (go32_pid_to_str): Constify.
	* i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Constify.
	* inf-ptrace.c (inf_ptrace_pid_to_str): Constify.
	* inferior.c (inferior_pid_to_str): Constify.
	* linux-nat.c (linux_nat_pid_to_str): Constify.
	* linux-tdep.c (linux_core_pid_to_str): Constify.
	* linux-thread-db.c (thread_db_pid_to_str)
	(thread_db_extra_thread_info): Constify.
	* nto-tdep.c (nto_extra_thread_info): Constify.
	* nto-tdep.h (nto_extra_thread_info): Constify.
	* obsd-nat.c (obsd_pid_to_str): Constify.
	* procfs.c (procfs_pid_to_str): Constify.
	* ravenscar-thread.c (ravenscar_extra_thread_info)
	(ravenscar_pid_to_str): Constify.
	* remote-sim.c (gdbsim_pid_to_str): Constify.
	* remote.c (remote_threads_extra_info, remote_pid_to_str):
	Constify.
	* sol-thread.c (solaris_pid_to_str): Constify.
	* sol2-tdep.c (sol2_core_pid_to_str): Constify.
	* sol2-tdep.h (sol2_core_pid_to_str): Constify.
	* target.c (default_pid_to_str, target_pid_to_str)
	(normal_pid_to_str, default_pid_to_str): Constify.
	* target.h (target_ops::to_pid_to_str)
	(target_ops::to_extra_thread_info): Constify.
	(target_pid_to_str, normal_pid_to_str): Constify.
	* windows-nat.c (windows_pid_to_str): Constify.
	* gdbarch.sh (core_pid_to_str): Constify.
	* target-delegates.c: Regenerate.
	* gdbarch.h, gdbarch.c: Regenerate.
2017-04-05 19:21:34 +01:00
Simon Marchi d62a8ae2dd remote.c: Use ptid_t instead of struct ptid
It's the only place in the codebase that uses "struct ptid", so change
it to ptid_t for consistency.

gdb/ChangeLog:

	* remote.c (set_general_thread, set_continue_thread): Use ptid_t
	instead of struct ptid.
2017-04-04 10:31:50 -04:00
Simon Marchi bcc0c096d5 Use ptid from regcache in almost all remaining nat files
This patch contains almost all of the remaining changes needed to make
to_fetch_registers/to_store_registers/to_prepare_to_store independent of
inferior_ptid.  It contains only some "trivial" changes, the more
complicated ones are in separate patches.

gdb/ChangeLog:

	* i386-linux-nat.c (fetch_register, store_register,
	i386_linux_fetch_inferior_registers,
	i386_linux_store_inferior_registers): Use ptid from regcache.
	* ia64-linux-nat.c (ia64_linux_fetch_register,
	ia64_linux_store_register): Likewise.
	* inf-ptrace.c (inf_ptrace_fetch_register,
	inf_ptrace_store_register): Likewise.
	* m32r-linux-nat.c (m32r_linux_fetch_inferior_registers,
	m32r_linux_store_inferior_registers): Likewise.
	* m68k-bsd-nat.c (m68kbsd_fetch_inferior_registers,
	m68kbsd_store_inferior_registers): Likewise.
	* m68k-linux-nat.c (fetch_register, store_register,
	m68k_linux_fetch_inferior_registers,
	m68k_linux_store_inferior_registers): Likewise.
	* m88k-bsd-nat.c (m88kbsd_fetch_inferior_registers,
	m88kbsd_store_inferior_registers): Likewise.
	* mips-fbsd-nat.c (mips_fbsd_fetch_inferior_registers,
	mips_fbsd_store_inferior_registers): Likewise.
	* mips-linux-nat.c (mips64_linux_regsets_fetch_registers,
	mips64_linux_regsets_store_registers): Likewise.
	* mips-nbsd-nat.c (mipsnbsd_fetch_inferior_registers,
	mipsnbsd_store_inferior_registers): Likewise.
	* mips-obsd-nat.c (mips64obsd_fetch_inferior_registers,
	mips64obsd_store_inferior_registers): Likewise.
	* nto-procfs.c (procfs_fetch_registers, procfs_store_registers):
	Likewise.
	* ppc-fbsd-nat.c (ppcfbsd_fetch_inferior_registers,
	ppcfbsd_store_inferior_registers): Likewise.
	* ppc-linux-nat.c (ppc_linux_fetch_inferior_registers,
	ppc_linux_store_inferior_registers): Likewise.
	* ppc-nbsd-nat.c (ppcnbsd_fetch_inferior_registers,
	ppcnbsd_store_inferior_registers): Likewise.
	* ppc-obsd-nat.c (ppcobsd_fetch_registers,
	ppcobsd_store_registers): Likewise.
	* procfs.c (procfs_fetch_registers, procfs_store_registers):
	Likewise.
	* ravenscar-thread.c (ravenscar_fetch_registers,
	ravenscar_store_registers, ravenscar_prepare_to_store):
	Likewise.
	* record-btrace.c (record_btrace_fetch_registers,
	record_btrace_store_registers, record_btrace_prepare_to_store):
	Likewise.
	* remote-sim.c (gdbsim_fetch_register, gdbsim_store_register):
	Lookup inferior using ptid from regcache, instead of
	current_inferior.
	* remote.c (remote_fetch_registers, remote_store_registers): Use
	ptid from regcache.
	* rs6000-nat.c (fetch_register, store_register): Likewise.
	* s390-linux-nat.c (s390_linux_fetch_inferior_registers,
	s390_linux_store_inferior_registers): Likewise.
	* sh-nbsd-nat.c (shnbsd_fetch_inferior_registers,
	shnbsd_store_inferior_registers): Likewise.
	* sol-thread.c (sol_thread_fetch_registers,
	sol_thread_store_registers): Likewise.
	* sparc-nat.c (sparc_fetch_inferior_registers,
	sparc_store_inferior_registers): Likewise.
	* tilegx-linux-nat.c (fetch_inferior_registers,
	store_inferior_registers): Likewise.
	* vax-bsd-nat.c (vaxbsd_fetch_inferior_registers,
	vaxbsd_store_inferior_registers): Likewise.
	* xtensa-linux-nat.c (fetch_gregs, store_gregs, fetch_xtregs,
	store_xtregs): Likewise.
2017-03-20 17:37:36 -04:00
Marc-Andre Laperle e696b3ad34 Remove unused parameter in solib_add and update_solib_list
The target parameter in both solib_add and update_solib_list
functions is not used anymore and as not been used for a while. This
change removes the parameter to clean up the code a little bit.

gdb/ChangeLog:

	* infcmd.c (post_create_inferior): Remove unused argument in
	call to solib_add.
	* remote.c (remote_start_remote): Likewise.
	* solib-frv.c (frv_fetch_objfile_link_map): Likewise.
	* solib-svr4.c: (svr4_fetch_objfile_link_map): Likewise.
	(enable_break): Likewise.
	* solib.c (update_solib_list): Remove unused target argument
	and its documentation.
	(solib_add): Remove unused target argument.  Remove unused
	argument in call to update_solib_list.
	(info_sharedlibrary_command): Remove unused argument in call
	to update_solib_list.
	(sharedlibrary_command): Remove unused argument in call to
	solib_add.
	(handle_solib_event): Likewise.
	(reload_shared_libraries): Likewise.
	* solib.h (solib_add): Remove unused target argument.

Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
2017-03-20 14:57:32 -04:00
Simon Marchi df97be551f Use range-based for loop in remote_add_target_side_commands
gdb/ChangeLog:

	* remote.c (remote_add_target_side_commands): Use range-based
	for loop.
2017-03-03 12:58:24 -05:00
Simon Marchi d538e36dec Remove struct keyword from range-based for loop
The previous patch introduced this error with recent-ish GCCs:

../../binutils-gdb/gdb/remote.c: In function ‘int remote_add_target_side_condition(gdbarch*, bp_target_info*, char*, char*)’:
../../binutils-gdb/gdb/remote.c:9668:8: error: types may not be defined in a for-range-declaration [-Werror]
   for (struct agent_expr *aexpr : bp_tgt->conditions)
        ^~~~~~

Removing the struct keyword fixes the error.

gdb/ChangeLog:

	* remote.c (remote_add_target_side_condition): Remove "struct"
	keyword from range-based for loop.
2017-02-27 14:09:34 -05:00
Simon Marchi 8362122330 Use range-based for loop in remote_add_target_side_condition
Using a range based for loop makes this code a bit more clean and
readable.

The comment above is clearly erroneous, so I've updated it.

gdb/ChangeLog:

	* remote.c (remote_add_target_side_condition): Use range-based
	for loop.  Update comment.
2017-02-27 13:54:53 -05:00
Alan Hayward 8e3681243c Remove MAX_REGISTER_SIZE from remote.c
gdb/
	* regcache.c (regcache_raw_update): New function.
	(regcache_raw_read): Move code to regcache_raw_update.
	* regcache.h (regcache_raw_update): New declaration.
	* remote.c (remote_prepare_to_store): Call regcache_raw_update.
2017-02-27 09:58:35 +00:00
Pedro Alves d7e747318f Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy
This patch starts from the desire to eliminate
make_cleanup_ui_file_delete, but then goes beyond.  It makes ui_file &
friends a real C++ class hierarchy, and switches temporary
ui_file-like objects to stack-based allocation.

- mem_fileopen -> string_file

mem_fileopen is replaced with a new string_file class that is treated
as a value class created on the stack.  This alone eliminates most
make_cleanup_ui_file_delete calls, and, simplifies code a whole lot
(diffstat shows around 1k loc dropped.)

string_file's internal buffer is a std::string, thus the "string" in
the name.  This simplifies the implementation much, compared to
mem_fileopen, which managed growing its internal buffer manually.

- ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone

The new string_file class has a string() method that provides direct
writable access to the internal std::string buffer.  This replaced
ui_file_as_string, which forced a copy of the same data the stream had
inside.  With direct access via a writable reference, we can instead
move the string out of the string_stream, avoiding deep string
copying.

Related, ui_file_xstrdup calls are replaced with xstrdup'ping the
stream's string, and ui_file_obsavestring is replaced by
obstack_copy0.

With all those out of the way, getting rid of the weird ui_file_put
mechanism was possible.

- New ui_file::printf, ui_file::puts, etc. methods

These simplify / clarify client code.  I considered splitting
client-code changes, like these, e.g.:

  -  stb = mem_fileopen ();
  -  fprintf_unfiltered (stb, "%s%s%s",
  -		      _("The valid values are:\n"),
  -		      regdesc,
  -		      _("The default is \"std\"."));
  +  string_file stb;
  +  stb.printf ("%s%s%s",
  +	      _("The valid values are:\n"),
  +	      regdesc,
  +	      _("The default is \"std\"."));

In two steps, with the first step leaving fprintf_unfiltered (etc.)
calls in place, and only afterwards do a pass to change all those to
call stb.printf etc..  I didn't do that split, because (when I tried),
it turned out to be pointless make-work: the first pass would have to
touch the fprintf_unfiltered line anyway, to replace "stb" with
"&stb".

- gdb_fopen replaced with stack-based objects

This avoids the need for cleanups or unique_ptr's.  I.e., this:

      struct ui_file *file = gdb_fopen (filename, "w");
      if (filename == NULL)
 	perror_with_name (filename);
      cleanups = make_cleanup_ui_file_delete (file);
      // use file.
      do_cleanups (cleanups);

is replaced with this:

      stdio_file file;
      if (!file.open (filename, "w"))
 	perror_with_name (filename);
      // use file.

- odd contorsions in null_file_write / null_file_fputs around when to
  call to_fputs / to_write eliminated.

- Global null_stream object

A few places that were allocating a ui_file in order to print to
"nowhere" are adjusted to instead refer to a new 'null_stream' global
stream.

- TUI's tui_sfileopen eliminated.  TUI's ui_file much simplified

The TUI's ui_file was serving a dual purpose.  It supported being used
as string buffer, and supported being backed by a stdio FILE.  The
string buffer part is gone, replaced by using of string_file.  The
'FILE *' support is now much simplified, by making the TUI's ui_file
inherit from stdio_file.

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

	* ada-lang.c (type_as_string): Use string_file.
	* ada-valprint.c (ada_print_floating): Use string_file.
	* ada-varobj.c (ada_varobj_scalar_image)
	(ada_varobj_get_value_image): Use string_file.
	* aix-thread.c (aix_thread_extra_thread_info): Use string_file.
	* arm-tdep.c (_initialize_arm_tdep): Use string_printf.
	* breakpoint.c (update_inserted_breakpoint_locations)
	(insert_breakpoint_locations, reattach_breakpoints)
	(print_breakpoint_location, print_one_detail_ranged_breakpoint)
	(print_it_watchpoint): Use string_file.
	(save_breakpoints): Use stdio_file.
	* c-exp.y (oper): Use string_file.
	* cli/cli-logging.c (set_logging_redirect): Use ui_file_up and
	tee_file.
	(pop_output_files): Use delete.
	(handle_redirections): Use stdio_file and tee_file.
	* cli/cli-setshow.c (do_show_command): Use string_file.
	* compile/compile-c-support.c (c_compute_program): Use
	string_file.
	* compile/compile-c-symbols.c (generate_vla_size): Take a
	'string_file &' instead of a 'ui_file *'.
	(generate_c_for_for_one_variable): Take a 'string_file &' instead
	of a 'ui_file *'.  Use string_file.
	(generate_c_for_variable_locations): Take a 'string_file &'
	instead of a 'ui_file *'.
	* compile/compile-internal.h (generate_c_for_for_one_variable):
	Take a 'string_file &' instead of a 'ui_file *'.
	* compile/compile-loc2c.c (push, pushf, unary, binary)
	(print_label, pushf_register_address, pushf_register)
	(do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a
	'ui_file *'.  Adjust.
	* compile/compile.c (compile_to_object): Use string_file.
	* compile/compile.h (compile_dwarf_expr_to_c)
	(compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a
	'ui_file *'.
	* cp-support.c (inspect_type): Use string_file and obstack_copy0.
	(replace_typedefs_qualified_name): Use string_file and
	obstack_copy0.
	* disasm.c (gdb_pretty_print_insn): Use string_file.
	(gdb_disassembly): Adjust reference the null_stream global.
	(do_ui_file_delete): Delete.
	(gdb_insn_length): Use null_stream.
	* dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file.
	* dwarf2loc.c (dwarf2_compile_property_to_c)
	(locexpr_generate_c_location, loclist_generate_c_location): Take a
	'string_file &' instead of a 'ui_file *'.
	* dwarf2loc.h (dwarf2_compile_property_to_c): Likewise.
	* dwarf2read.c (do_ui_file_peek_last): Delete.
	(dwarf2_compute_name): Use string_file.
	* event-top.c (gdb_setup_readline): Use stdio_file.
	* gdbarch.sh (verify_gdbarch): Use string_file.
	* gdbtypes.c (safe_parse_type): Use null_stream.
	* guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use
	string_file.
	* guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a
	'string_file *' instead of a 'ui_file *'.
	(gdbscm_arch_disassemble): Use string_file.
	* guile/scm-frame.c (frscm_print_frame_smob): Use string_file.
	* guile/scm-ports.c (class ioscm_file_port): Now a class that
	inherits from ui_file.
	(ioscm_file_port_delete, ioscm_file_port_rewind)
	(ioscm_file_port_put): Delete.
	(ioscm_file_port_write): Rename to ...
	(ioscm_file_port::write): ... this.  Remove file_port_magic
	checks.
	(ioscm_file_port_new): Delete.
	(ioscm_with_output_to_port_worker): Use ioscm_file_port and
	ui_file_up.
	* guile/scm-type.c (tyscm_type_name): Use string_file.
	* guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print):
	Use string_file.
	* infcmd.c (print_return_value_1): Use string_file.
	* infrun.c (print_target_wait_results): Use string_file.
	* language.c (add_language): Use string_file.
	* location.c (explicit_to_string_internal): Use string_file.
	* main.c (captured_main_1): Use null_file.
	* maint.c (maintenance_print_architecture): Use stdio_file.
	* mi/mi-cmd-stack.c (list_arg_or_local): Use string_file.
	* mi/mi-common.h (struct mi_interp) <out, err, log, targ,
	event_channel>: Change type to mi_console_file pointer.
	* mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush)
	(mi_console_file_delete): Delete.
	(struct mi_console_file): Delete.
	(mi_console_file_magic): Delete.
	(mi_console_file_new): Delete.
	(mi_console_file::mi_console_file): New.
	(mi_console_file_delete): Delete.
	(mi_console_file_fputs): Delete.
	(mi_console_file::write): New.
	(mi_console_raw_packet): Delete.
	(mi_console_file::flush): New.
	(mi_console_file_flush): Delete.
	(mi_console_set_raw): Rename to ...
	(mi_console_file::set_raw): ... this.
	* mi/mi-console.h (class mi_console_file): New class.
	(mi_console_file_new, mi_console_set_raw): Delete.
	* mi/mi-interp.c (mi_interpreter_init): Use mi_console_file.
	(mi_set_logging): Use delete and tee_file.  Adjust.
	* mi/mi-main.c (output_register): Use string_file.
	(mi_cmd_data_evaluate_expression): Use string_file.
	(mi_cmd_data_read_memory): Use string_file.
	(mi_cmd_execute, print_variable_or_computed): Use string_file.
	* mi/mi-out.c (mi_ui_out::main_stream): New.
	(mi_ui_out::rewind): Use main_stream and
	string_file.
	(mi_ui_out::put): Use main_stream and string_file.
	(mi_ui_out::mi_ui_out): Remove 'stream' parameter.
	Allocate a 'string_file' instead.
	(mi_out_new): Don't allocate a mem_fileopen stream here.
	* mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter.
	(mi_ui_out::main_stream): Declare method.
	* printcmd.c (eval_command): Use string_file.
	* psymtab.c (maintenance_print_psymbols): Use stdio_file.
	* python/py-arch.c (archpy_disassemble): Use string_file.
	* python/py-breakpoint.c (bppy_get_commands): Use string_file.
	* python/py-frame.c (frapy_str): Use string_file.
	* python/py-framefilter.c (py_print_type, py_print_single_arg):
	Use string_file.
	* python/py-type.c (typy_str): Use string_file.
	* python/py-unwind.c (unwind_infopy_str): Use string_file.
	* python/py-value.c (valpy_str): Use string_file.
	* record-btrace.c (btrace_insn_history): Use string_file.
	* regcache.c (regcache_print): Use stdio_file.
	* reggroups.c (maintenance_print_reggroups): Use stdio_file.
	* remote.c (escape_buffer): Use string_file.
	* rust-lang.c (rust_get_disr_info): Use string_file.
	* serial.c (serial_open_ops_1): Use stdio_file.
	(do_serial_close): Use delete.
	* stack.c (print_frame_arg): Use string_file.
	(print_frame_args): Remove local mem_fileopen stream, not used.
	(print_frame): Use string_file.
	* symmisc.c (maintenance_print_symbols): Use stdio_file.
	* symtab.h (struct symbol_computed_ops) <generate_c_location>:
	Take a 'string_file *' instead of a 'ui_file *'.
	* top.c (new_ui): Use stdio_file and stderr_file.
	(free_ui): Use delete.
	(execute_command_to_string): Use string_file.
	(quit_confirm): Use string_file.
	* tracepoint.c (collection_list::append_exp): Use string_file.
	* tui/tui-disasm.c (tui_disassemble): Use string_file.
	* tui/tui-file.c: Don't include "ui-file.h".
	(enum streamtype, struct tui_stream): Delete.
	(tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen)
	(tui_file_isatty, tui_file_rewind, tui_file_put): Delete.
	(tui_file::tui_file): New method.
	(tui_file_fputs): Delete.
	(tui_file_get_strbuf): Delete.
	(tui_file::puts): New method.
	(tui_file_adjust_strbuf): Delete.
	(tui_file_flush): Delete.
	(tui_file::flush): New method.
	* tui/tui-file.h: Tweak intro comment.
	Include ui-file.h.
	(tui_fileopen, tui_sfileopen, tui_file_get_strbuf)
	(tui_file_adjust_strbuf): Delete declarations.
	(class tui_file): New class.
	* tui/tui-io.c (tui_initialize_io): Use tui_file.
	* tui/tui-regs.c (tui_restore_gdbout): Use delete.
	(tui_register_format): Use string_stream.
	* tui/tui-stack.c (tui_make_status_line): Use string_file.
	(tui_get_function_from_frame): Use string_file.
	* typeprint.c (type_to_string): Use string_file.
	* ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete.
	(null_stream): New global.
	(ui_file_delete): Delete.
	(ui_file::ui_file): New.
	(null_file_isatty): Delete.
	(ui_file::~ui_file): New.
	(null_file_rewind): Delete.
	(ui_file::printf): New.
	(null_file_put): Delete.
	(null_file_flush): Delete.
	(ui_file::putstr): New.
	(null_file_write): Delete.
	(ui_file::putstrn): New.
	(null_file_read): Delete.
	(ui_file::putc): New.
	(null_file_fputs): Delete.
	(null_file_write_async_safe): Delete.
	(ui_file::vprintf): New.
	(null_file_delete): Delete.
	(null_file::write): New.
	(null_file_fseek): Delete.
	(null_file::puts): New.
	(ui_file_data): Delete.
	(null_file::write_async_safe): New.
	(gdb_flush, ui_file_isatty): Adjust.
	(ui_file_put, ui_file_rewind): Delete.
	(ui_file_write): Adjust.
	(ui_file_write_for_put): Delete.
	(ui_file_write_async_safe, ui_file_read): Adjust.
	(ui_file_fseek): Delete.
	(fputs_unfiltered): Adjust.
	(set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind)
	(set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe)
	(set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek)
	(set_ui_file_data): Delete.
	(string_file::~string_file, string_file::write)
	(struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup)
	(do_ui_file_as_string, ui_file_as_string): Delete.
	(do_ui_file_obsavestring, ui_file_obsavestring): Delete.
	(struct mem_file): Delete.
	(mem_file_new): Delete.
	(stdio_file::stdio_file): New.
	(mem_file_delete): Delete.
	(stdio_file::stdio_file): New.
	(mem_fileopen): Delete.
	(stdio_file::~stdio_file): New.
	(mem_file_rewind): Delete.
	(stdio_file::set_stream): New.
	(mem_file_put): Delete.
	(stdio_file::open): New.
	(mem_file_write): Delete.
	(stdio_file_magic, struct stdio_file): Delete.
	(stdio_file_new, stdio_file_delete, stdio_file_flush): Delete.
	(stdio_file::flush): New.
	(stdio_file_read): Rename to ...
	(stdio_file::read): ... this.  Adjust.
	(stdio_file_write): Rename to ...
	(stdio_file::write): ... this.  Adjust.
	(stdio_file_write_async_safe): Rename to ...
	(stdio_file::write_async_safe) ... this.  Adjust.
	(stdio_file_fputs): Rename to ...
	(stdio_file::puts) ... this.  Adjust.
	(stdio_file_isatty): Delete.
	(stdio_file_fseek): Delete.
	(stdio_file::isatty): New.
	(stderr_file_write): Rename to ...
	(stderr_file::write) ... this.  Adjust.
	(stderr_file_fputs): Rename to ...
	(stderr_file::puts) ... this.  Adjust.
	(stderr_fileopen, stdio_fileopen, gdb_fopen): Delete.
	(stderr_file::stderr_file): New.
	(tee_file_magic): Delete.
	(struct tee_file): Delete.
	(tee_file::tee_file): New.
	(tee_file_new): Delete.
	(tee_file::~tee_file): New.
	(tee_file_delete): Delete.
	(tee_file_flush): Rename to ...
	(tee_file::flush): ... this.  Adjust.
	(tee_file_write): Rename to ...
	(tee_file::write): ... this.  Adjust.
	(tee_file::write_async_safe): New.
	(tee_file_fputs): Rename to ...
	(tee_file::puts): ... this.  Adjust.
	(tee_file_isatty): Rename to ...
	(tee_file::isatty): ... this.  Adjust.
	* ui-file.h (struct obstack, struct ui_file): Don't
	forward-declare.
	(ui_file_new, ui_file_flush_ftype, set_ui_file_flush)
	(ui_file_write_ftype)
	(set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs)
	(ui_file_write_async_safe_ftype, set_ui_file_write_async_safe)
	(ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype)
	(set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind)
	(ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put)
	(ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype)
	(set_ui_file_fseek): Delete.
	(ui_file_data, ui_file_delete, ui_file_rewind)
	(struct ui_file): New.
	(ui_file_up): New.
	(class null_file): New.
	(null_stream): Declare.
	(ui_file_write_for_put, ui_file_put): Delete.
	(ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring):
	Delete.
	(ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen)
	(gdb_fopen, tee_file_new): Delete.
	(struct string_file): New.
	(struct stdio_file): New.
	(stdio_file_up): New.
	(struct stderr_file): New.
	(class tee_file): New.
	* ui-out.c (ui_out::field_stream): Take a 'string_file &' instead
	of a 'ui_file *'.  Adjust.
	* ui-out.h (class ui_out) <field_stream>: Likewise.
	* utils.c (do_ui_file_delete, make_cleanup_ui_file_delete)
	(null_stream): Delete.
	(error_stream): Take a 'string_file &' instead of a 'ui_file *'.
	Adjust.
	* utils.h (struct ui_file): Delete forward declaration..
	(make_cleanup_ui_file_delete, null_stream): Delete declarations.
	(error_stream): Take a 'string_file &' instead of a
	'ui_file *'.
	* varobj.c (varobj_value_get_print_value): Use string_file.
	* xtensa-tdep.c (xtensa_verify_config): Use string_file.
	* gdbarch.c: Regenerate.
2017-02-02 11:11:47 +00:00
Alan Hayward d1dff2266d Allocate data in cached_reg_t
2017-01-18  Alan Hayward  <alan.hayward@arm.com>

	* remote.c (struct cached_reg): Change data into a pointer.
	* (stop_reply_dtr): Free data pointers before deleting vector.
	(process_stop_reply): Likewise.
	(remote_parse_stop_reply): Allocate space for data
2017-01-18 15:17:55 +00:00
Alan Hayward 9890e4338d Use register_size () instead of MAX_REGISTER_SIZE
2017-01-18  Alan Hayward  <alan.hayward@arm.com>

	* amd64-tdep.c (amd64_pseudo_register_read_value): remove
	MAX_REGISTER_SIZE.
	(amd64_pseudo_register_read_value): Likewise.
	* remote.c (fetch_register_using_p): Remove MAX_REGISTER_SIZE.
	(store_register_using_P): Likewise.
	* regcache.c (regcache_xfer_part): Likewise.
2017-01-18 15:17:55 +00:00
Yao Qi 6f8976bfd6 Don't print too much if remote_debug is on
If we turn "remote debug" on and GDB does some vFile operations,
a lot of things will be printed in the screen, which makes
"remote debug" useless.

This patch changes the code that we only print 512 chars in max in
debugging messages, like this,

Sending packet: $qXfer:features:read:target.xml:0,fff#7d...Packet received: l<?xml version="1.0"?>\n<!-- Copyright (C) 2010-2016 Free Software Foundation, Inc.\n\n     Copying and distribution of this file, with or without modification,\n     are permitted in any medium without royalty provided the copyright\n     notice and this notice are preserved.  -->\n\n<!-- AMD64 with AVX - Includes Linux-only special "register".  -->\n\n<!DOCTYPE target SYSTEM "gdb-target.dtd">\n<target>\n  <architecture>i386:x86-64</architecture>\n  <osabi>GNU/Linux</osabi>\n  <xi:include href="64bit-core.xml"/>\n  <xi:[14 bytes omitted]

Sending packet: $qXfer:auxv:read::0,1000#6b...Packet received: l!\000\000\000\000\000\000\000\000d\000\000\000\000\000\000\000\003\000\000\000\000\000\000\000@\000@\000\000\000\000\000\004\000\000\000\000\000\000\0008\000\000\000\000\000\000\000\005\000\000\000\000\000\000\000\t\000\000\000\000\000\000\000\a\000\000\000\000\000\000\000\177\000\000\b\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\t\000\000\000\000\000\000\000\000\004@\000\000\000\000\000\013\000\000\000\000\000\000\003\000\000\000\000\000\000\f\000\000\000\000\000\000\003\000\000\000\000\000\000\r\000\000\000\000\000\000\003\000\000\000\000\000\000\016\000\000\000\000\000\000\003\000\000\000\000\000\000\027\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\031\000\000\000\000\000\000\177\000\000\037\000\000\000\000\000\000\000\000\017\000\000\000\000\000\000\00\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000[582 bytes omitted]

gdb:

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

	* remote.c (REMOTE_DEBUG_MAX_CHAR): New macro.
	(putpkt_binary): Print only REMOTE_DEBUG_MAX_CHAR chars in debug
	output.
	(getpkt_or_notif_sane_1): Likewise.
2017-01-13 15:45:33 +00:00
Simon Marchi 3015c06465 Update comment in remote_can_async_p
I find this comment counter intuitive, and it probably predates the
always-target-async change.  AFAIK, remote will always be async, unless
the user explicitly prevents it with "maint set target-async off".

gdb/ChangeLog:

	* remote.c (remote_can_async_p): Update comment.
2017-01-12 11:15:02 -05:00
Joel Brobecker 61baf725ec update copyright year range in GDB files
This applies the second part of GDB's End of Year Procedure, which
updates the copyright year range in all of GDB's files.

gdb/ChangeLog:

        Update copyright year range in all GDB files.
2017-01-01 10:52:34 +04:00
Simon Marchi 112e8700a6 Class-ify ui_out
This patch finalizes the C++ conversion of the ui-out subsystem, by
turning the ui_out and ui_out_impl structures into a single class
hierarchy.  ui_out functions are turned into virtual methods of that new
class, so as a result there are a lot of call sites to update.

In the previous version of the patchset, there were separate ui_out and
ui_out_impl classes, but it wasn't really useful and added boilerplate.
In this version there is simply an ui_out base class that is
extended for CLI, TUI and MI.

It's a bit hard to maintain a ChangeLog for such a big patch, I did my
best but I'm sure there are some missing or outdated info in there...

gdb/ChangeLog:

    * ui-out.h (ui_out_begin, ui_out_end, ui_out_table_header,
    ui_out_table_body,  ui_out_field_int, ui_out_field_fmt_int,
    ui_out_field_core_addr, ui_out_field_string, ui_out_field_stream,
    ui_out_field_fmt, ui_out_field_skip, ui_out_spaces, ui_out_text,
    ui_out_message, ui_out_wrap_hint, ui_out_flush, ui_out_test_flags,
    ui_out_query_field, ui_out_is_mi_like_p, ui_out_redirect):
    Remove, replace with a method in class ui_out.
    (table_begin_ftype): Remove, replace with pure virtual method in
    class ui_out.
    (table_body_ftype): Likewise.
    (table_end_ftype): Likewise.
    (table_header_ftype): Likewise.
    (ui_out_begin_ftype): Likewise.
    (ui_out_end_ftype): Likewise.
    (field_int_ftype): Likewise.
    (field_skip_ftype): Likewise.
    (field_string_ftype): Likewise.
    (field_fmt_ftype): Likewise.
    (spaces_ftype): Likewise.
    (text_ftype): Likewise.
    (message_ftype): Likewise.
    (wrap_hint_ftype): Likewise.
    (flush_ftype): Likewise.
    (redirect_ftype): Likewise.
    (data_destroy_ftype): Likewise.
    (struct ui_out_impl): Remove, replace with class ui_out.
    (ui_out_new): Remove.
    (class ui_out): New class.
    * ui-out.c (struct ui_out): Remove, replaced with class ui_out.
    (current_level): Remove, replace with ui_out method.
    (push_level): Likewise.
    (pop_level): Likewise.
    (uo_table_begin, uo_table_body, uo_table_end, uo_table_header,
    uo_begin, uo_end, uo_field_int, uo_field_skip, uo_field_fmt,
    uo_spaces, uo_text, uo_message, uo_wrap_hint, uo_flush,
    uo_redirect, uo_field_string): Remove.
    (ui_out_table_begin): Replace with ...
    (ui_out::table_begin): ... this.
    (ui_out_table_body): Replace with ...
    (ui_out::table_body): ... this.
    (ui_out_table_end): Replace with ...
    (ui_out::table_end): ... this.
    (ui_out_table_header): Replace with ...
    (ui_out::table_header): ... this.
    (ui_out_begin): Replace with ...
    (ui_out::begin): ... this.
    (ui_out_end): Replace with ...
    (ui_out::end): ... this.
    (ui_out_field_int): Replace with ...
    (ui_out::field_int): ... this.
    (ui_out_field_fmt_int): Replace with ...
    (ui_out::field_fmt_int): ... this.
    (ui_out_field_core_addr): Replace with ...
    (ui_out::field_core_addr): ... this.
    (ui_out_field_stream): Replace with ...
    (ui_out::field_stream): ... this.
    (ui_out_field_skip): Replace with ...
    (ui_out::field_skip): ... this.
    (ui_out_field_string): Replace with ...
    (ui_out::field_string): ... this.
    (ui_out_field_fmt): Replace with ...
    (ui_out::field_fmt): ... this.
    (ui_out_spaces): Replace with ...
    (ui_out::spaces): ... this.
    (ui_out_text): Replace with ...
    (ui_out::text): ... this.
    (ui_out_message): Replace with ...
    (ui_out::message): ... this.
    (ui_out_wrap_hint): Replace with ...
    (ui_out::wrap_hint): ... this.
    (ui_out_flush): Replace with ...
    (ui_out::flush): ... this.
    (ui_out_redirect): Replace with ...
    (ui_out::redirect): ... this.
    (ui_out_test_flags): Replace with ...
    (ui_out::test_flags): ... this.
    (ui_out_is_mi_like_p): Replace with ...
    (ui_out::is_mi_like_p): ... this.
    (verify_field): Replace with ...
    (ui_out::verify_field): ... this.
    (ui_out_query_field): Replace with ...
    (ui_out::query_table_field): ... this.
    (ui_out_data): Remove.
    (ui_out_new): Remove, replace with ...
    (ui_out::ui_out): ... this constructor.
    (do_cleanup_table_end, make_cleanup_ui_out_tuple_begin_end,
    do_cleanup_end, make_cleanup_ui_out_tuple_begin_end,
    make_cleanup_ui_out_list_begin_end): Update fallouts of struct
    ui_out -> class ui_out change.
    * cli-out.c (cli_out_data): Remove.
    (cli_uiout_dtor): Remove.
    (cli_table_begin): Replace with ...
    (cli_ui_out::do_table_begin): ... this new method.
    (cli_table_body): Replace with ...
    (cli_ui_out::do_table_body): ... this new method.
    (cli_table_end): Replace with ...
    (cli_ui_out::do_table_end): ... this new method.
    (cli_table_header): Replace with ...
    (cli_ui_out::do_table_header): ... this new method.
    (cli_begin): Replace with ...
    (cli_ui_out::do_begin): ... this new method.
    (cli_end): Replace with ...
    (cli_ui_out::do_end): ... this new method.
    (cli_field_int): Replace with ...
    (cli_ui_out::do_field_int): ... this new method.
    (cli_field_skip): Replace with ...
    (cli_ui_out::do_field_skip): ... this new method.
    (cli_field_string): Replace with ...
    (cli_ui_out::do_field_string): ... this new method.
    (cli_field_fmt): Replace with ...
    (cli_ui_out::do_field_fmt): ... this new method.
    (cli_spaces): Replace with ...
    (cli_ui_out::do_spaces): ... this new method.
    (cli_text): Replace with ...
    (cli_ui_out::do_text): ... this new method.
    (cli_message): Replace with ...
    (cli_ui_out::do_message): ... this new method.
    (cli_wrap_hint): Replace with ...
    (cli_ui_out::do_wrap_hint): ... this new method.
    (cli_flush): Replace with ...
    (cli_ui_out::do_flush): ... this new method.
    (cli_redirect): Replace with ...
    (cli_ui_out::do_redirect): ... this new method.
    (out_field_fmt): Replace with ...
    (cli_ui_out::out_field_fmt): ... this new method.
    (field_separator): Replace with ...
    (cli_ui_out::field_separator): ... this new method.
    (cli_out_set_stream): Replace with ...
    (cli_ui_out::set_stream): ... this new method.
    (cli_ui_out_impl): Remove.
    (cli_out_data_ctor): Remove.
    (cli_ui_out_impl::cli_ui_out_impl): New constructor.
    (cli_ui_out_impl::~cli_ui_out_impl): New destructor.
    (cli_out_new): Change return type to cli_ui_out *, instantiate a
    cli_ui_out.
    * cli-out.h (cli_ui_out_data): Remove, replace with class
    cli_ui_out.
    (class cli_ui_out): New class.
    (cli_ui_out_impl): Remove.
    (cli_out_data_ctor): Remove.
    (cli_out_new): Change return type to cli_ui_out*.
    (cli_out_set_stream): Remove.
    * cli/cli-interp.c (struct cli_interp) <cli_uiout>: Change type
    to cli_ui_out*.
    (cli_interpreter_resume): Adapt.
    (cli_interpreter_exec): Adapt.
    * mi/mi-out.c (mi_ui_out_data, mi_out_data): Remove.
    (mi_ui_out_impl): Remove.
    (mi_table_begin): Replace with ...
    (mi_ui_out::do_table_begin): ... this.
    (mi_table_body): Replace with ...
    (mi_ui_out::do_table_body): ... this.
    (mi_table_end): Replace with ...
    (mi_ui_out::do_table_end): ... this.
    (mi_table_header): Replace with ...
    (mi_ui_out::do_table_header): ... this.
    (mi_begin): Replace with ...
    (mi_ui_out::do_begin): ... this.
    (mi_end): Replace with ...
    (mi_ui_out::do_end): ... this.
    (mi_field_int): Replace with ...
    (mi_ui_out::do_field_int): ... this.
    (mi_field_skip): Replace with ...
    (mi_ui_out::do_field_skip): ... this.
    (mi_field_string): Replace with ...
    (mi_ui_out::do_field_string): ... this.
    (mi_field_fmt): Replace with ...
    (mi_ui_out::do_field_fmt): ... this.
    (mi_spaces): Replace with ...
    (mi_ui_out::do_spaces): ... this.
    (mi_text): Replace with ...
    (mi_ui_out::do_text): ... this.
    (mi_message): Replace with ...
    (mi_ui_out::do_message): ... this.
    (mi_wrap_hint): Replace with ...
    (mi_ui_out::do_wrap_hint): ... this.
    (mi_flush): Replace with ...
    (mi_ui_out::do_flush): ... this.
    (mi_redirect): Replace with ...
    (mi_ui_out::do_redirect):
    (field_separator): Replace with ...
    (mi_ui_out::field_separator):
    (mi_open): Replace with ...
    (mi_ui_out::open): ... this.
    (mi_close): Replace with ...
    (mi_ui_out::close): ... this.
    (mi_out_rewind): Replace with ...
    (mi_ui_out::rewind): ... this.
    (mi_out_put): Replace with ...
    (mi_ui_out::put): ... this.
    (mi_version): Replace with ...
    (mi_ui_out::version): ... this.
    (mi_out_data_ctor): Replace with ...
    (mi_ui_out::mi_ui_out): ... this.
    (mi_out_data_dtor): Replace with ...
    (mi_ui_out::~mi_ui_out): ... this.
    (mi_out_new): Change return type to mi_ui_out*, instantiate
    an mi_ui_out object.
    (as_mi_ui_out): New function.
    (mi_version): Update fallouts of struct ui_out to class ui_out
    transition.
    (mi_out_put): Likewise.
    (mi_out_rewind): Likewise.
    * mi/mi-out.h (mi_out_new): Change return type to mi_ui_out*.
    * tui/tui-out.c (tui_ui_out_data, tui_out_data, tui_ui_out_impl):
    Remove.
    (tui_field_int): Replace with ...
    (tui_ui_out::do_field_int): ... this.
    (tui_field_string): Replace with ...
    (tui_ui_out::do_field_string): ... this.
    (tui_field_fmt): Replace with ...
    (tui_ui_out::do_field_fmt): ... this.
    (tui_text): Replace with ...
    (tui_ui_out::do_text): ... this.
    (tui_out_new): Change return type to tui_ui_out*, instantiate
    tui_ui_out object.
    (tui_ui_out::tui_ui_out): New.
    * tui/tui-out.h: New file.
    * tui/tui.h (tui_out_new): Move declaration to tui/tui-out.h.
    * tui/tui-io.c: Include tui/tui-out.h.
    (tui_old_uiout): Change type to cli_ui_out*.
    (tui_setup_io): Use dynamic_cast.
    * tui/tui-io.h (tui_old_uiout): Change type to cli_ui_out*.
    * tui/tui-interp.c (tui_resume): Adapt.
    * ada-lang.c (print_it_exception): Update fallouts of struct
    ui_out to class ui_out transition.
    (print_one_exception): Likewise.
    (print_mention_exception): Likewise.
    * ada-tasks.c (print_ada_task_info): Likewise.
    (info_task): Likewise.
    (task_command): Likewise.
    * auto-load.c (print_script): Likewise.
    (auto_load_info_scripts): Likewise.
    (info_auto_load_cmd): Likewise.
    * break-catch-sig.c (signal_catchpoint_print_one): Likewise.
    * break-catch-syscall.c (print_it_catch_syscall): Likewise.
    (print_one_catch_syscall): Likewise.
    * break-catch-throw.c (print_it_exception_catchpoint): Likewise.
    (print_one_exception_catchpoint): Likewise.
    (print_one_detail_exception_catchpoint): Likewise.
    (print_mention_exception_catchpoint): Likewise.
    * breakpoint.c (maybe_print_thread_hit_breakpoint): Likewise.
    (print_solib_event): Likewise.
    (watchpoint_check): Likewise.
    (wrap_indent_at_field): Likewise.
    (print_breakpoint_location): Likewise.
    (output_thread_groups): Likewise.
    (print_one_breakpoint_location): Likewise.
    (breakpoint_1): Likewise.
    (default_collect_info): Likewise.
    (watchpoints_info): Likewise.
    (print_it_catch_fork): Likewise.
    (print_one_catch_fork): Likewise.
    (print_it_catch_vfork): Likewise.
    (print_one_catch_vfork): Likewise.
    (print_it_catch_solib): Likewise.
    (print_one_catch_solib): Likewise.
    (print_it_catch_exec): Likewise.
    (print_one_catch_exec): Likewise.
    (mention): Likewise.
    (print_it_ranged_breakpoint): Likewise.
    (print_one_ranged_breakpoint): Likewise.
    (print_one_detail_ranged_breakpoint): Likewise.
    (print_mention_ranged_breakpoint): Likewise.
    (print_it_watchpoint): Likewise.
    (print_mention_watchpoint): Likewise.
    (print_it_masked_watchpoint): Likewise.
    (print_one_detail_masked_watchpoint): Likewise.
    (print_mention_masked_watchpoint): Likewise.
    (bkpt_print_it): Likewise.
    (tracepoint_print_one_detail): Likewise.
    (tracepoint_print_mention): Likewise.
    (update_static_tracepoint): Likewise.
    (tracepoints_info): Likewise.
    (save_breakpoints): Likewise.
    * cli/cli-cmds.c (complete_command): Likewise.
    * cli/cli-logging.c (set_logging_redirect): Likewise.
    (pop_output_files): Likewise.
    (handle_redirections): Likewise.
    * cli/cli-script.c (print_command_lines): Likewise.
    * cli/cli-setshow.c (do_show_command): Likewise.
    (cmd_show_list): Likewise.
    * cp-abi.c (list_cp_abis): Likewise.
    (show_cp_abi_cmd): Likewise.
    * darwin-nat-info.c (darwin_debug_regions_recurse): Likewise.
    * disasm.c (gdb_pretty_print_insn): Likewise.
    (do_mixed_source_and_assembly_deprecated): Likewise.
    (do_mixed_source_and_assembly): Likewise.
    * gdb_bfd.c (print_one_bfd): Likewise.
    (maintenance_info_bfds): Likewise.
    * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Likewise.
    * guile/scm-ports.c (ioscm_with_output_to_port_worker): Likewise.
    * i386-linux-tdep.c (i386_linux_handle_segmentation_fault): Likewise.
    * i386-tdep.c (i386_mpx_print_bounds): Likewise.
    * infcmd.c (run_command_1): Likewise.
    (print_return_value_1): Likewise.
    * inferior.c (print_selected_inferior): Likewise.
    (print_inferior): Likewise.
    * infrun.c (print_end_stepping_range_reason): Likewise.
    (print_signal_exited_reason): Likewise.
    (print_exited_reason): Likewise.
    (print_signal_received_reason): Likewise.
    (print_no_history_reason): Likewise.
    * interps.c (interp_set): Likewise.
    * linespec.c (decode_line_full): Likewise.
    * linux-thread-db.c (info_auto_load_libthread_db): Likewise.
    * mi/mi-cmd-env.c (mi_cmd_env_pwd): Likewise.
    (mi_cmd_env_path): Likewise.
    (mi_cmd_env_dir): Likewise.
    (mi_cmd_inferior_tty_show): Likewise.
    * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_file): Likewise.
    (print_partial_file_name): Likewise.
    (mi_cmd_file_list_exec_source_files): Likewise.
    * mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions): Likewise.
    (mi_cmd_info_gdb_mi_command): Likewise.
    * mi/mi-cmd-stack.c (mi_cmd_stack_info_depth): Likewise.
    (mi_cmd_stack_list_args): Likewise.
    (list_arg_or_local): Likewise.
    * mi/mi-cmd-var.c (print_varobj): Likewise.
    (mi_cmd_var_create): Likewise.
    (mi_cmd_var_delete): Likewise.
    (mi_cmd_var_set_format): Likewise.
    (mi_cmd_var_show_format): Likewise.
    (mi_cmd_var_info_num_children): Likewise.
    (mi_cmd_var_list_children): Likewise.
    (mi_cmd_var_info_type): Likewise.
    (mi_cmd_var_info_path_expression): Likewise.
    (mi_cmd_var_info_expression): Likewise.
    (mi_cmd_var_show_attributes): Likewise.
    (mi_cmd_var_evaluate_expression): Likewise.
    (mi_cmd_var_assign): Likewise.
    (varobj_update_one): Likewise.
    * mi/mi-interp.c (as_mi_interp): Likewise.
    (mi_on_normal_stop_1): Likewise.
    (mi_tsv_modified): Likewise.
    (mi_breakpoint_created): Likewise.
    (mi_breakpoint_modified): Likewise.
    (mi_solib_loaded): Likewise.
    (mi_solib_unloaded): Likewise.
    (mi_command_param_changed): Likewise.
    (mi_memory_changed): Likewise.
    (mi_user_selected_context_changed): Likewise.
    * mi/mi-main.c (print_one_inferior): Likewise.
    (output_cores): Likewise.
    (list_available_thread_groups): Likewise.
    (mi_cmd_data_list_register_names): Likewise.
    (mi_cmd_data_list_changed_registers): Likewise.
    (output_register): Likewise.
    (mi_cmd_data_evaluate_expression): Likewise.
    (mi_cmd_data_read_memory): Likewise.
    (mi_cmd_data_read_memory_bytes): Likewise.
    (mi_cmd_list_features): Likewise.
    (mi_cmd_list_target_features): Likewise.
    (mi_cmd_add_inferior): Likewise.
    (mi_execute_command): Likewise.
    (mi_load_progress): Likewise.
    (print_variable_or_computed): Likewise.
    (mi_cmd_trace_frame_collected): Likewise.
    * mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Likewise.
    * osdata.c (info_osdata_command): Likewise.
    * probe.c (gen_ui_out_table_header_info): Likewise.
    (print_ui_out_not_applicables): Likewise.
    (print_ui_out_info): Likewise.
    (info_probes_for_ops): Likewise.
    (enable_probes_command): Likewise.
    (disable_probes_command): Likewise.
    * progspace.c (print_program_space): Likewise.
    * python/py-breakpoint.c (bppy_get_commands): Likewise.
    * python/py-framefilter.c (py_print_type): Likewise.
    (py_print_value): Likewise.
    (py_print_single_arg): Likewise.
    (enumerate_args): Likewise.
    (enumerate_locals): Likewise.
    (py_print_args): Likewise.
    (py_print_frame): Likewise.
    * record-btrace.c (btrace_ui_out_decode_error): Likewise.
    (btrace_call_history_insn_range): Likewise.
    (btrace_call_history_src_line): Likewise.
    (btrace_call_history): Likewise.
    * remote.c (show_remote_cmd): Likewise.
    * skip.c (skip_info): Likewise.
    * solib.c (info_sharedlibrary_command): Likewise.
    * source.c (print_source_lines_base): Likewise.
    * spu-tdep.c (info_spu_event_command): Likewise.
    (info_spu_signal_command): Likewise.
    (info_spu_mailbox_list): Likewise.
    (info_spu_dma_cmdlist): Likewise.
    (info_spu_dma_command): Likewise.
    (info_spu_proxydma_command): Likewise.
    * stack.c (print_stack_frame): Likewise.
    (print_frame_arg): Likewise.
    (read_frame_arg): Likewise.
    (print_frame_args): Likewise.
    (print_frame_info): Likewise.
    (print_frame): Likewise.
    * symfile.c (load_progress): Likewise.
    (generic_load): Likewise.
    (print_transfer_performance): Likewise.
    * thread.c (do_captured_list_thread_ids): Likewise.
    (print_thread_info_1): Likewise.
    (restore_selected_frame): Likewise.
    (do_captured_thread_select): Likewise.
    (print_selected_thread_frame): Likewise.
    * top.c (execute_command_to_string): Likewise.
    * tracepoint.c (tvariables_info_1): Likewise.
    (trace_status_mi): Likewise.
    (tfind_1): Likewise.
    (print_one_static_tracepoint_marker): Likewise.
    (info_static_tracepoint_markers_command): Likewise.
    * utils.c (do_ui_out_redirect_pop): Likewise.
    (fputs_maybe_filtered): Likewise.
2016-12-22 16:19:42 -05:00
Pedro Alves 3cde5c42d1 Eliminate agent_expr_p; VEC -> std::vector in struct bp_target_info
After the previous patch, we end up with these two types with quite
similar, and potentially confusing names:

  typedef gdb::unique_ptr<agent_expr> agent_expr_up;

  /* Pointer to an agent_expr structure.  */
  typedef struct agent_expr *agent_expr_p;

The latter is only necessary to put agent_expr pointers in VECs.  So
just eliminate it and use std::vector instead.

gdb/ChangeLog:
2016-11-08  Pedro Alves  <palves@redhat.com>

	* ax.h (agent_expr_p): Delete.
	(DEF_VEC_P (agent_expr_p)): Delete.
	* breakpoint.c (build_target_condition_list)
	(build_target_command_list): Adjust to use of std::vector.
	(bp_location_dtor): Remove now unnecessary VEC_free calls.
	* breakpoint.h: Include <vector>.
	(struct bp_target_info) <conditions, tcommands>: Now
	std::vector's.
	* remote.c (remote_add_target_side_condition): bp_tgt->conditions
	is now a std::vector; adjust.
	(remote_add_target_side_commands, remote_insert_breakpoint):
	bp_tgt->tcommands is now a std::vector; adjust.
2016-11-08 15:26:47 +00:00
Pedro Alves 833177a4a5 'struct agent_expr *' -> unique_ptr<agent_expr>
This patch makes the gen_* functions return a unique_ptr instead of
raw pointer:

  typedef gdb::unique_ptr<agent_expr> agent_expr_up;

and then adjusts the codebase throughout to stop using
make_cleanup_free_agent_expr.

The cond_bytecode and cmd_bytecode fields of struct bp_location are
owning pointers, so they're changed to be unique_ptr's instead of raw
pointers.

gdb/ChangeLog:
2016-11-08  Pedro Alves  <palves@redhat.com>

	* ax-gdb.c (is_nontrivial_conversion): Use agent_expr_up.
	(gen_trace_for_var, gen_trace_for_expr, gen_eval_for_expr)
	(gen_trace_for_return_address, gen_printf): Use and return an
	agent_expr_up.  Don't use make_cleanup_free_agent_expr.
	(agent_eval_command_one, maint_agent_printf_command): Use
	agent_expr_up.  Don't use make_cleanup_free_agent_expr.
	* ax-gdb.h (gen_trace_for_expr, gen_trace_for_var)
	(gen_trace_for_return_address, gen_eval_for_expr, gen_printf): Use
	agent_expr_up.
	* ax-general.c (new_agent_expr): Rename to ...
	(agent_expr::agent_expr): ... this, and now a constructor.
	(free_agent_expr): Rename to ...
	(agent_expr::~agent_exp): ... this, and now a destructor.
	(do_free_agent_expr_cleanup, make_cleanup_free_agent_expr):
	Delete.
	* ax.h (struct agent_expr): Add ctor/dtor.
	(agent_expr_up): New typedef.
	(new_agent_expr, free_agent_expr, make_cleanup_free_agent_expr):
	Delete declarations.
	* breakpoint.c (parse_cond_to_aexpr): Use and return an
	agent_expr_up.  Don't use make_cleanup_free_agent_expr.
	(build_target_condition_list): Adjust to use agent_expr_up.
	(parse_cmd_to_aexpr): Use and return an agent_expr_up.  Don't use
	make_cleanup_free_agent_expr.
	(build_target_command_list): Adjust to use agent_expr_up.
	(force_breakpoint_reinsertion): Adjust to use agent_expr_up.
	(bp_location_dtor): Remove unnecessary free_agent_expr and xfree
	calls.
	* breakpoint.h (struct bp_target_info) <cond_bytecode,
	cmd_bytecode>: Now agent_expr_up's.
	* remote.c (remote_download_tracepoint): Adjust to use
	agent_expr_up and remove use of make_cleanup_free_agent_expr.
	* tracepoint.c (validate_actionline, collect_symbol): Adjust to
	use agent_expr_up and remove uses of make_cleanup_free_agent_expr.
	(collection_list::~collection_list): Call delete instead of
	free_agent_expr.
	(encode_actions_1): Adjust to use agent_expr_up and remove uses of
	make_cleanup_free_agent_expr.
	(add_aexpr): Change parameter type to agent_expr_up; Return a raw
	agent_expr pointer.
2016-11-08 15:26:47 +00:00
Pedro Alves b3ced9bad2 Use ui_file_as_string in gdb/remote.c
gdb/ChangeLog:
2016-11-08  Pedro Alves  <palves@redhat.com>

	* remote.c (escape_buffer): Use ui_file_as_string and return
	std::string.
	(putpkt_binary, read_frame): Adjust to use std::string.
2016-11-08 15:26:45 +00:00
Pedro Alves 4d01a485d2 'struct expression *' -> gdb::unique_xmalloc_ptr<expression>
This patch makes parse_expression and friends return a unique_ptr
instead of raw pointer [1]:

  typedef gdb::unique_malloc_ptr<expression> expression_up;

and then adjusts the codebase throughout to stop using cleanups to
manage lifetime of expression pointers.

Whenever I found a structure owning an expression pointer, I made it
store a unique_ptr instead of a raw pointer, which then requires using
new/delete of the holding structure, instead of XNEW/xfree.

[1] - I'd like to set the rule that types named with an "_up" suffix
      are unique_ptr typedefs.

Note I used gdb::unique_xmalloc_ptr instead of gdb::unique_ptr, simply
because we still use xmalloc instead of new to allocate expression
objects.  Once that's changed, all we need to do is change the
expression_up typedef and the smart pointer will then call delete
instead of xfree.

gdb/ChangeLog:
2016-11-08  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_read_renaming_var_value): Use expression_up.
	(struct ada_catchpoint_location) <excep_cond_expr>: Now an
	expression_up.
	(ada_catchpoint_location_dtor): Reset excep_cond_expr instead of
	using xfree.
	(create_excep_cond_exprs): Use expression_up and gdb::move.
	(allocate_location_exception): Use new instead of XNEW.
	(should_stop_exception): Likewise.  Adjust to use expression_up.
	(create_ada_exception_catchpoint): Use new instead of XNEW.
	* ax-gdb.c (agent_eval_command_one): Use expression_up instead of
	cleanups.
	(maint_agent_printf_command): Use expression_up.
	* break-catch-sig.c (create_signal_catchpoint): Use new instead of
	XNEW.
	* break-catch-syscall.c (create_syscall_event_catchpoint):
	Likewise.
	* break-catch-throw.c (handle_gnu_v3_exceptions): Use new instead
	of XCNEW.  Use gdb::unique_ptr instead of cleanups.
	* breakpoint.c (set_breakpoint_condition, update_watchpoint)
	(parse_cmd_to_aexpr, watchpoint_check)
	(bpstat_check_breakpoint_conditions, watchpoint_locations_match):
	Adjust to use expression_up.
	(init_bp_location): Adjust.
	(free_bp_location): Use delete instead of xfree.
	(set_raw_breakpoint_without_location, set_raw_breakpoint)
	(add_solib_catchpoint, create_fork_vfork_event_catchpoint)
	(new_single_step_breakpoint, create_breakpoint_sal): Use new
	instead of XNEW.
	(find_condition_and_thread): Adjust to use expression_up.
	(create_breakpoint): Use new instead of XNEW.
	(dtor_watchpoint): Don't xfree expression pointers, they're
	unique_ptr's now.
	(insert_watchpoint, remove_watchpoint): Adjust.
	(watch_command_1): Use expression_up.  Use new instead of XCNEW.
	(catch_exec_command_1): Use new instead of XNEW.
	(bp_location_dtor): Don't xfree expression pointers, they're
	unique_ptr's now.
	(base_breakpoint_allocate_location)
	(strace_marker_create_breakpoints_sal): Use new instead of XNEW.
	(delete_breakpoint): Use delete instead of xfree.
	* breakpoint.h (struct bp_location) <cond>: Now an
	unique_ptr<expression> instead of a raw pointer.
	(struct watchpoint) <exp, cond_exp>: Likewise.
	* cli/cli-script.c (execute_control_command): Use expression_up
	instead of cleanups.
	* dtrace-probe.c (dtrace_process_dof_probe): Use expression_up.
	* eval.c (parse_and_eval_address, parse_and_eval_long)
	(parse_and_eval, parse_to_comma_and_eval, parse_and_eval_type):
	Use expression_up instead of cleanups.
	* expression.h (expression_up): New typedef.
	(parse_expression, parse_expression_with_language, parse_exp_1):
	Change return type to expression_up.
	* mi/mi-main.c (mi_cmd_data_evaluate_expression)
	(print_variable_or_computed): Use expression_up.
	* objc-lang.c (print_object_command): Use expression_up instead of
	cleanups.
	* parse.c (parse_exp_1, parse_exp_in_context)
	(parse_exp_in_context_1, parse_expression)
	(parse_expression_with_language): Return an expression_up instead
	of a raw pointer.
	(parse_expression_for_completion): Use expression_up.
	* printcmd.c (struct display) <exp>: Now an expression_up instead
	of a raw pointer.
	(print_command_1, output_command_const, set_command, x_command):
	Use expression_up instead of cleanups.
	(display_command): Likewise.  Use new instead of XNEW.
	(free_display): Use delete instead of xfree.
	(do_one_display): Adjust to use expression_up.
	* remote.c (remote_download_tracepoint): Likewise.
	* stack.c (return_command): Likewise.
	* tracepoint.c (validate_actionline, encode_actions_1): Use
	expression_up instead of cleanups.
	* typeprint.c (whatis_exp, maintenance_print_type): Likewise.
	* value.c (init_if_undefined_command): Likewise.
	* varobj.c (struct varobj_root) <exp>: Now an expression_up
	instead of a raw pointer.
	(varobj_create): Adjust.
	(varobj_set_value): Use an expression_up instead of cleanups.
	(new_root_variable): Use new instead of XNEW.
	(free_variable): Use delete instead of xfree.
	(value_of_root_1): Use std::swap.
2016-11-08 15:26:43 +00:00
Lionel Flandrin 9dc193c3be Check for truncated registers in process_g_packet
While investigating an unrelated issue in remote.c I noticed that the
bound checking for 'g' packets was bogus:

The previous code would only check that the first byte of the register
was within bounds before passing the buffer to regcache_raw_supply.
If it turned out that the register in the 'g' packet was incomplete
then regcache_raw_supply would proceed to memcpy out-of-bounds.

Since the buffer is allocated with alloca it's relatively unlikely to
crash (you just end up dumping gdb's stack into the cache) but it's
still a bit messy.

I changed this logic to check for truncated registers and raise an
error if one is encountered.  Hopefully it should make debugging
remote stubs a bit easier.

gdb/ChangeLog:
2016-11-08  Lionel Flandrin  <lionel@svkt.org>

	* remote.c (process_g_packet): Detect truncated registers in 'g'
	packets and raise an error.
2016-11-08 10:27:36 +00:00
Yao Qi 579c6ad983 Rename placed_size to kind
This patch renames placed_size to kind.

gdb:

2016-11-03  Yao Qi  <yao.qi@linaro.org>

	* breakpoint.h (struct bp_target_info) <placed_size>: Remove.
	<kind>: New field.
	Update all users.
2016-11-03 14:35:13 +00:00
Yao Qi cd6c3b4ffc New gdbarch methods breakpoint_kind_from_pc and sw_breakpoint_from_kind
This patch adds two gdbarch methods breakpoint_kind_from_pc and
sw_breakpoint_from_kind, and uses target_info.placed_size as "kind"
of the breakpoint.  This patch updates the usages of
target_info.placed_size.

The "kind" of a breakpoint is determined by gdbarch rather than
target, so we have gdbarch method breakpoint_kind_from_pc, and we
should set target_info.placed_size out of each implementation of
target to_insert_breakpoint.  In this way, each target doesn't have
to set target_info.placed_size any more.

This patch also sets target_info.placed_address before
target_insert_breakpoint too, so that target to_insert_breakpoint
can use it, see record_full_insert_breakpoint.

Before we call target_insert_breakpoint, we set
target_info.placed_address and target_info.placed_size like this,

      CORE_ADDR addr = bl->target_info.reqstd_address;

      bl->target_info.placed_size = gdbarch_breakpoint_kind_from_pc (bl->gdbarch, &addr);
      bl->target_info.placed_address = addr;

      return target_insert_breakpoint (bl->gdbarch, &bl->target_info);

target_insert_breakpoint may fail, but it doesn't matter to the "kind"
and "placed_address" of a breakpoint.  They should be determined by
gdbarch.

gdb:

2016-11-03  Yao Qi  <yao.qi@linaro.org>

	* arch-utils.h (GDBARCH_BREAKPOINT_MANIPULATION): Define
	breakpoint_kind_from_pc and sw_breakpoint_from_kind.
	(GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN): Likewise.
	(SET_GDBARCH_BREAKPOINT_MANIPULATION): Call
	set_gdbarch_breakpoint_kind_from_pc and
	set_gdbarch_sw_breakpoint_from_kind.
	* arm-tdep.c: Add comments.
	* bfin-tdep.c: Likewise.
	* breakpoint.c (breakpoint_kind): New function.
	(insert_bp_location): Set target_info.placed_size and
	target_info.placed_address.
	(bkpt_insert_location): Likewise.
	* cris-tdep.c: Add comments.
	* gdbarch.sh (breakpoint_kind_from_pc): New.
	(sw_breakpoint_from_kind): New.
	* gdbarch.c, gdbarch.h: Regenerated.
	* ia64-tdep.c (ia64_memory_insert_breakpoint): Don't set
	bp_tgt->placed_size.
	(ia64_memory_remove_breakpoint): Don't assert
	bp_tgt->placed_size.
	(ia64_breakpoint_kind_from_pc): New function.
	(ia64_gdbarch_init): Install ia64_breakpoint_kind_from_pc.
	* m32r-tdep.c (m32r_memory_insert_breakpoint): Don't set
	bp_tgt->placed_size.
	* mem-break.c (default_memory_insert_breakpoint): Don't set
	bp_tgt->placed_size.  Call gdbarch_sw_breakpoint_from_kind.
	(default_memory_remove_breakpoint): Call
	gdbarch_sw_breakpoint_from_kind.
	(memory_validate_breakpoint): Don't check bp_tgt->placed_size.
	* mips-tdep.c: Add comments.
	* mt-tdep.c: Likewise.
	* nios2-tdep.c: Likewise.
	* record-full.c (record_full_insert_breakpoint): Don't call
	gdbarch_breakpoint_from_pc.  Don't set bp_tgt->placed_address
	and bp_tgt->placed_size.
	* remote.c (remote_insert_breakpoint): Don't call
	gdbarch_remote_breakpoint_from_pc.  Use bp_tgt->placed_size.
	Don't set bp_tgt->placed_address and bp_tgt->placed_size.
	(remote_insert_hw_breakpoint): Likewise.
	* score-tdep.c: Likewise.
	* sh-tdep.c: Likewise.
	* tic6x-tdep.c: Likewise.
	* v850-tdep.c: Likewise.
	* xtensa-tdep.c: Likewise.
2016-11-03 14:35:13 +00:00
Pedro Alves 85ad3aaf40 gdb: Coalesce/aggregate (async) vCont packets/actions
Currently, with "maint set target-non-stop on", that is, when gdb
connects with the non-stop/asynchronous variant of the remote
protocol, even with "set non-stop off", GDB always sends one vCont
packet per thread resumed.  This patch makes GDB aggregate and
coalesce vCont packets, so we send vCont packets like "vCont;s:p1.1;c"
in non-stop mode too.

Basically, this is done by:

  - Adding a new target method target_commit_resume that is called
    after calling target_resume one or more times.  When resuming a
    batch of threads, we'll only call target_commit_resume once after
    calling target_resume for all threads.

  - Making the remote target defer sending the actual vCont packet to
    target_commit_resume.

Special care must be taken to avoid sending a vCont action with a
"wildcard" thread-id (all threads of process / all threads) when that
would resume threads/processes that should not be resumed.  See
remote_commit_resume comments for details.

Unlike all-stop's remote_resume implementation, this handles the case
of too many actions resulting in a too-big vCont packet, by flushing
the vCont packet and starting a new one.

E.g., imagining that the "c" action in:

  vCont;s:1;c

overflows the packet buffer, we split the actions like:

  vCont;s:1
  vCont;c

Tested on x86_64 Fedora 20, with and without "maint set
target-non-stop on".

Also tested with a hack that makes remote_commit_resume flush the vCont
packet after every action appended (which caught a few bugs).

gdb/ChangeLog:
2016-10-26  Pedro Alves  <palves@redhat.com>

	* inferior.h (ALL_NON_EXITED_INFERIORS): New macro.
	* infrun.c (do_target_resume): Call target_commit_resume.
	(proceed): Defer target_commit_resume while looping over threads,
	resuming them.  Call target_commit_resume at the end.
	* record-btrace.c (record_btrace_commit_resume): New function.
	(init_record_btrace_ops): Install it as to_commit_resume method.
	* record-full.c (record_full_commit_resume): New function.
	(record_full_wait_1): Call the beneath target's to_commit_resume
	method.
	(init_record_full_ops): Install record_full_commit_resume as
	to_commit_resume method.
	* remote.c (struct private_thread_info) <last_resume_step,
	last_resume_sig, vcont_resumed>: New fields.
	(remote_add_thread): Set the new thread's vcont_resumed flag.
	(demand_private_info): Delete.
	(get_private_info_thread, get_private_info_ptid): New functions.
	(remote_update_thread_list): Adjust.
	(process_initial_stop_replies): Clear the thread's vcont_resumed
	flag.
	(remote_resume): If connected in non-stop mode, record the resume
	request and return early.
	(struct private_inferior): New.
	(struct vcont_builder): New.
	(vcont_builder_restart, vcont_builder_flush)
	(vcont_builder_push_action): New functions.
	(MAX_ACTION_SIZE): New macro.
	(remote_commit_resume): New function.
	(thread_pending_fork_status, is_pending_fork_parent_thread): New
	functions.
	(check_pending_event_prevents_wildcard_vcont_callback)
	(check_pending_events_prevent_wildcard_vcont): New functions.
	(process_stop_reply): Adjust.  Clear the thread's vcont_resumed
	flag.
	(init_remote_ops): Install remote_commit_resume.
	* target-delegates.c: Regenerate.
	* target.c (defer_target_commit_resume): New global.
	(target_commit_resume, make_cleanup_defer_target_commit_resume):
	New functions.
	* target.h (struct target_ops) <to_commit_resume>: New field.
	(target_resume): Update comments.
	(target_commit_resume): New declaration.
2016-10-26 16:22:50 +01:00
Pedro Alves 7b68ffbb32 gdb: Clean up remote.c:remote_resume
Just some refactoring / TLC.  Mainly split the old c/s/C/S packet
handling to a separate function.

gdb/ChangeLog:
2016-10-26  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_resume_with_hc): New function, factored out
	from ...
	(remote_resume): ... this.  Always try vCont first.
	(remote_vcont_resume): Rename to ...
	(remote_resume_with_vcont): ... this.  Bail out if execution
	direction is reverse.
2016-10-26 16:15:28 +01:00
Jan Kratochvil bb805577d2 PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regression
Regression: gdb --pid $(pidof qemu-system-x86_64) stopped working with gdb 7.11.1
https://sourceware.org/bugzilla/show_bug.cgi?id=20609

It was reported for qemu-system-x86_64 but it happens for any multithreaded
inferior with a JIT debugging hook.

136613ef0c6850427317e57be1b644080ff6decb is the first bad commit
Author: Pedro Alves <palves@redhat.com>
    Fix PR gdb/19828: gdb -p <process from a container>: internal error
Message-ID: <cbdf2e04-4fa8-872a-2a23-08c9c1b26e00@redhat.com>
https://sourceware.org/ml/gdb-patches/2016-05/msg00450.html

jit_breakpoint_re_set() is specific by trying to insert a breakpoint into the
main executable, not into a shared library.  During attachment GDB thinks it
needs to use 'breakpoint always-inserted' from
breakpoints_should_be_inserted_now() as a newly attached thread is
'thread_info->executing' due to 'lwp_info->must_set_ptrace_flags' enabled and
the task not yet stopped.  This did not happen before the 'bad commit' above
which adds tracking of such thread.

GDB then fails to insert the breakpoints to invalid address as PIE executable
gets properly relocated during later phase of attachment.  One can see in the
backtraces below:
 -> jit_breakpoint_re_set_internal()
later:
 -> svr4_exec_displacement()

One can suppress the initial breakpoint_re_set() call as there will be another
breakpoint_re_set() done from the final post_create_inferior() call in
setup_inferior().

BTW additionally 'threads_executing' cache bool is somehow stale (somewhere is
missing update_threads_executing()).  I was trying to deal with that in my
first/second attempt below but in my final third attempt (attached) I have
left it as it is.

First attempt trying not to falsely require 'breakpoint always-inserted':
  https://people.redhat.com/jkratoch/rhbz1375553-fix1.patch
Reduced first attempt:
  https://people.redhat.com/jkratoch/rhbz1375553-fix2.patch

The third attempt suppresses breakpoint insertion until PIE executable gets
relocated by svr4_exec_displacement().  Applied.

gdb/ChangeLog
2016-09-29  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regression
	* exec.c (exec_file_locate_attach): Add parameter defer_bp_reset.
	Use it.
	* gdbcore.h (exec_file_locate_attach): Add parameter defer_bp_reset.
	* infcmd.c (setup_inferior): Update caller.
	* remote.c (remote_add_inferior): Likewise.

gdb/testsuite/ChangeLog
2016-09-29  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regression
	* gdb.base/jit-attach-pie.c: New file.
	* gdb.base/jit-attach-pie.exp: New file.
2016-09-29 17:39:39 +02:00
Sergio Durigan Junior bc1e6c81d5 Consolidate target_mourn_inferior between GDB and gdbserver
This patch consolidates the API of target_mourn_inferior between GDB
and gdbserver, in my continuing efforts to make sharing the
fork_inferior function possible between both.

GDB's version of the function did not care about the inferior's ptid
being mourned, but gdbserver's needed to know this information.  Since
it actually makes sense to pass the ptid as an argument, instead of
depending on a global value directly (which GDB's version did), I
decided to make the generic API to accept it.  I then went on and
extended all calls being made on GDB to include a ptid argument (which
ended up being inferior_ptid most of the times, anyway), and now we
have a more sane interface.

On GDB's side, after talking to Pedro a bit about it, we decided that
just an assertion to make sure that the ptid being passed is equal to
inferior_ptid would be enough for now, on the GDB side.  We can remove
the assertion and perform more operations later if we ever pass
anything different than inferior_ptid.

Regression tested on our BuildBot, everything OK.

I'd appreciate a special look at gdb/windows-nat.c's modification
because I wasn't really sure what to do there.  It seemed to me that
maybe I should build a ptid out of the process information there, but
then I am almost sure the assertion on GDB's side would trigger.

gdb/ChangeLog:
2016-09-19  Sergio Durigan Junior  <sergiodj@redhat.com>

	* darwin-nat.c (darwin_kill_inferior): Adjusting call to
	target_mourn_inferior to include ptid_t argument.
	* fork-child.c (startup_inferior): Likewise.
	* gnu-nat.c (gnu_kill_inferior): Likewise.
	* inf-ptrace.c (inf_ptrace_kill): Likewise.
	* infrun.c (handle_inferior_event_1): Likewise.
	* linux-nat.c (linux_nat_attach): Likewise.
	(linux_nat_kill): Likewise.
	* nto-procfs.c (interrupt_query): Likewise.
	(procfs_interrupt): Likewise.
	(procfs_kill_inferior): Likewise.
	* procfs.c (procfs_kill_inferior): Likewise.
	* record.c (record_mourn_inferior): Likewise.
	* remote-sim.c (gdbsim_kill): Likewise.
	* remote.c (remote_detach_1): Likewise.
	(remote_kill): Likewise.
	* target.c (target_mourn_inferior): Change declaration to accept
	new ptid_t argument; use gdb_assert on it.
	* target.h (target_mourn_inferior): Move function prototype from
	here...
	* target/target.h (target_mourn_inferior): ... to here.  Adjust it
	to accept new ptid_t argument.
	* windows-nat.c (get_windows_debug_event): Adjusting call to
	target_mourn_inferior to include ptid_t argument.

gdb/gdbserver/ChangeLog:
2016-09-19  Sergio Durigan Junior  <sergiodj@redhat.com>

	* server.c (start_inferior): Call target_mourn_inferior instead of
	mourn_inferior; pass ptid_t argument to it.
	(resume): Likewise.
	(handle_target_event): Likewise.
	* target.c (target_mourn_inferior): New function.
	* target.h (mourn_inferior): Delete macro.
2016-09-19 00:17:29 -04:00
Pedro Alves 768adc05c4 gdb: Fix std::{min, max}-related build breakage on 32-bit hosts
Building on a 32-bit host fails currently with errors like:

  .../src/gdb/exec.c: In function ‘target_xfer_status section_table_read_available_memory(gdb_byte*, ULONGEST, ULONGEST, ULONGEST*)’:
  .../src/gdb/exec.c:801:54: error: no matching function for call to ‘min(ULONGEST, long unsigned int)’
      end = std::min (offset + len, r->start + r->length);
							^
  In file included from /usr/include/c++/5.3.1/algorithm:61:0,
		   from .../src/gdb/exec.c:46:
  /usr/include/c++/5.3.1/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)
       min(const _Tp& __a, const _Tp& __b)
       ^
  /usr/include/c++/5.3.1/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
  .../src/gdb/exec.c:801:54: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long long unsigned int’ and ‘long unsigned int’)
      end = std::min (offset + len, r->start + r->length);
							^
  In file included from /usr/include/c++/5.3.1/algorithm:61:0,
		   from .../src/gdb/exec.c:46:
  /usr/include/c++/5.3.1/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
       min(const _Tp& __a, const _Tp& __b, _Compare __comp)
       ^

The problem is that the std::min/std::max function templates use the
same type for both parameters.  When the argument types are different,
the compiler can't automatically deduce which template specialization
to pick from the arguments' types.

Fix that by specifying the specialization we want explicitly.

gdb/ChangeLog:
2016-09-18  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (hardware_watchpoint_inserted_in_range): Explicitly
	specify the std:min/std::max specialization.
	* exec.c (section_table_read_available_memory): Likewise.
	* remote.c (remote_read_qxfer): Likewise.
	* target.c (simple_verify_memory): Likewise.
2016-09-18 23:56:01 +01:00
Pedro Alves 325fac504a gdb: Use std::min and std::max throughout
Otherwise including <string> or some other C++ header is broken.
E.g.:

  In file included from /opt/gcc/include/c++/7.0.0/bits/char_traits.h:39:0,
		   from /opt/gcc/include/c++/7.0.0/string:40,
		   from /home/pedro/gdb/mygit/cxx-convertion/src/gdb/infrun.c:68:
  /opt/gcc/include/c++/7.0.0/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
       min(const _Tp& __a, const _Tp& __b, _Compare __comp)
							  ^
  /opt/gcc/include/c++/7.0.0/bits/stl_algobase.h:265:56: error: macro "max" passed 3 arguments, but takes just 2
       max(const _Tp& __a, const _Tp& __b, _Compare __comp)
							  ^
  In file included from .../src/gdb/infrun.c:21:0:

To the best of my grepping abilities, I believe I adjusted all min/max
calls.

gdb/ChangeLog:
2016-09-16  Pedro Alves  <palves@redhat.com>

	* defs.h (min, max): Delete.
	* aarch64-tdep.c: Include <algorithm> and use std::min and
	std::max throughout.
	* aarch64-tdep.c: Likewise.
	* alpha-tdep.c: Likewise.
	* amd64-tdep.c: Likewise.
	* amd64-windows-tdep.c: Likewise.
	* arm-tdep.c: Likewise.
	* avr-tdep.c: Likewise.
	* breakpoint.c: Likewise.
	* btrace.c: Likewise.
	* ctf.c: Likewise.
	* disasm.c: Likewise.
	* doublest.c: Likewise.
	* dwarf2loc.c: Likewise.
	* dwarf2read.c: Likewise.
	* environ.c: Likewise.
	* exec.c: Likewise.
	* f-exp.y: Likewise.
	* findcmd.c: Likewise.
	* ft32-tdep.c: Likewise.
	* gcore.c: Likewise.
	* hppa-tdep.c: Likewise.
	* i386-darwin-tdep.c: Likewise.
	* i386-tdep.c: Likewise.
	* linux-thread-db.c: Likewise.
	* lm32-tdep.c: Likewise.
	* m32r-tdep.c: Likewise.
	* m88k-tdep.c: Likewise.
	* memrange.c: Likewise.
	* minidebug.c: Likewise.
	* mips-tdep.c: Likewise.
	* moxie-tdep.c: Likewise.
	* nds32-tdep.c: Likewise.
	* nios2-tdep.c: Likewise.
	* nto-procfs.c: Likewise.
	* parse.c: Likewise.
	* ppc-sysv-tdep.c: Likewise.
	* probe.c: Likewise.
	* record-btrace.c: Likewise.
	* remote.c: Likewise.
	* rs6000-tdep.c: Likewise.
	* rx-tdep.c: Likewise.
	* s390-linux-nat.c: Likewise.
	* s390-linux-tdep.c: Likewise.
	* ser-tcp.c: Likewise.
	* sh-tdep.c: Likewise.
	* sh64-tdep.c: Likewise.
	* source.c: Likewise.
	* sparc-tdep.c: Likewise.
	* symfile.c: Likewise.
	* target-memory.c: Likewise.
	* target.c: Likewise.
	* tic6x-tdep.c: Likewise.
	* tilegx-tdep.c: Likewise.
	* tracefile-tfile.c: Likewise.
	* tracepoint.c: Likewise.
	* valprint.c: Likewise.
	* value.c: Likewise.
	* xtensa-tdep.c: Likewise.
	* cli/cli-cmds.c: Likewise.
	* compile/compile-object-load.c: Likewise.
2016-09-16 19:55:17 +01:00
Tom Tromey f5c4fcd971 Remove some unneeded casts from remote.c
I happened to notice a few unneeded casts in remote.c.  In some cases
these are no-ops, and in others these cast away const, but in a context
where this is not needed.

I'm checking this in under the obvious rule.
Tested by rebuilding on x86-64 Fedora 24.

2016-09-08  Tom Tromey  <tom@tromey.com>

	* remote.c (remote_notif_stop_ack, remote_wait_as)
	(show_remote_cmd): Remove unneeded casts.
2016-09-08 09:50:28 -06:00
Pedro Alves 7397181903 Plumb enum remove_bp_reason all the way to target_remove_breakpoint
So the target knows whether we're detaching breakpoints.
Nothing uses the parameter in this patch yet.

gdb/ChangeLog:
2016-08-10  Pedro Alves  <palves@redhat.com>

	PR gdb/19187
	* break-catch-sig.c (signal_catchpoint_remove_location): Adjust
	interface.
	* break-catch-syscall.c (remove_catch_syscall):
	* breakpoint.c (enum remove_bp_reason): Moved to breakpoint.h.
	(remove_breakpoint_1): Pass 'reason' down.
	(remove_catch_fork, remove_catch_vfork, remove_catch_solib)
	(remove_catch_exec, remove_watchpoint, remove_masked_watchpoint)
	(base_breakpoint_remove_location, bkpt_remove_location)
	(bkpt_probe_remove_location, bkpt_probe_remove_location): Adjust
	interface.
	* breakpoint.h (enum remove_bp_reason): Moved here from
	breakpoint.c.
	(struct breakpoint_ops) <remove_location>: Add 'reason' parameter.
	* corelow.c (core_remove_breakpoint): New function.
	(init_core_ops): Install it as to_remove_breakpoint method.
	* exec.c (exec_remove_breakpoint): New function.
	(init_exec_ops): Install it as to_remove_breakpoint method.
	* mem-break.c (memory_remove_breakpoint): Adjust interface.
	* record-btrace.c (record_btrace_remove_breakpoint): Adjust
	interface.
	* record-full.c (record_full_remove_breakpoint)
	(record_full_core_remove_breakpoint): Adjust interface.
	* remote.c (remote_remove_breakpoint): Adjust interface.
	* target-debug.h (target_debug_print_enum_remove_bp_reason): New
	macro.
	* target-delegates.c: Regenerate.
	* target.c (target_remove_breakpoint): Add 'reason' parameter.
	* target.h (struct target_ops) <to_remove_breakpoint>: Add
	'reason' parameter.
	(target_remove_breakpoint, memory_remove_breakpoint): Add 'reason'
	parameter.
2016-08-10 23:03:29 +01:00
Tim Wiederhake c0272db585 btrace: Resume recording after disconnect.
This patch allows gdbserver to continue recording after disconnect.  On
reconnect, the recorded data is accessible to gdb as if no disconnect happened.

A possible application for this feature is remotely examine bugs that occur
at irregular intervals, where maintaining a gdb connection is inconvenient.

This also fixes the issue mentioned here:
https://sourceware.org/ml/gdb-patches/2015-11/msg00424.html

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>

gdb/ChangeLog:
	* NEWS: Resume btrace on reconnect.
	* record-btrace.c: Added record-btrace.h include.
	(record_btrace_open): Split into this and ...
	(record_btrace_push_target): ... this.
	(record_btrace_disconnect): New function.
	(init_record_btrace_ops): Use record_btrace_disconnect.
	* record-btrace.h: New file.
	* remote.c: Added record-btrace.h include.
	(remote_start_remote): Check recording status.
	(remote_btrace_maybe_reopen): New function.

gdb/doc/ChangeLog:
	* gdb.texinfo: Resume btrace on reconnect.

gdb/testsuite/ChangeLog:

	* gdb.btrace/reconnect.c: New file.
	* gdb.btrace/reconnect.exp: New file.

Change-Id: I95e8b0ab8a89e58591aba0e63818cee82fd211bc
2016-07-25 11:03:43 +02:00
Don Breazeal 09c98b448f Optimize memory_xfer_partial for remote
Some analysis we did here showed that increasing the cap on the
transfer size in target.c:memory_xfer_partial could give 20% or more
improvement in remote load across JTAG.  Transfer sizes were capped
to 4K bytes because of performance problems encountered with the
restore command, documented here:

https://sourceware.org/ml/gdb-patches/2013-07/msg00611.html

and in commit 67c059c29e ("Improve performance of large restore
commands").

The 4K cap was introduced because in a case where the restore command
requested a 100MB transfer, memory_xfer_partial would repeatedy
allocate and copy an entire 100MB buffer in order to properly handle
breakpoint shadow instructions, even though memory_xfer_partial would
actually only write a small portion of the buffer contents.

A couple of alternative solutions were suggested:
* change the algorithm for handling the breakpoint shadow instructions
* throttle the transfer size up or down based on the previous actual
  transfer size

I tried implementing the throttling approach, and my implementation
reduced the performance in some cases.

This patch implements a new target function that returns that target's
limit on memory transfer size.  It defaults to ULONGEST_MAX bytes,
because for native targets there is no marshaling and thus no limit is
needed.  For remote targets it uses get_memory_write_packet_size.

gdb/ChangeLog:

	* remote.c (remote_get_memory_xfer_limit): New function.
	* target-delegates.c: Regenerate.
	* target.c (memory_xfer_partial): Call
	target_ops.to_get_memory_xfer_limit.
	* target.h (struct target_ops)
	<to_get_memory_xfer_limit>: New member.
2016-07-01 11:13:48 -07:00
Pedro Alves 0f48b75707 Factor out "Detaching from program" message printing
Several targets have a copy of the same code that prints

 "Detaching from program ..."

in their target_detach implementation.  Factor that out to a common
function.

(For now, I left the couple targets that print this a bit differently
alone.  Maybe this could be further pulled out into infcmd.c.  If we
did that, and those targets want to continue printing differently,
this new function could be converted to a target method.)

gdb/ChangeLog:
2016-07-01  Pedro Alves  <palves@redhat.com>

	* darwin-nat.c (darwin_detach): Use target_announce_detach.
	* inf-ptrace.c (inf_ptrace_detach): Likewise.
	* nto-procfs.c (procfs_detach): Likewise.
	* remote.c (remote_detach_1): Likewise.
	* target.c (target_announce_detach): New function.
	* target.h (target_announce_detach): New declaration.
2016-07-01 11:25:50 +01:00
Pedro Alves 41fd2b0f5d Make input_fd be per UI
And with that, we can switch the current UI to the UI whose input
descriptor woke up the event loop.  IOW, if the user types in UI 2,
the event loop wakes up, switches to UI 2, and processes the input.
Next the user types in UI 3, the event loop wakes up and switches to
UI 3, etc.

gdb/ChangeLog:
2016-06-21  Pedro Alves  <palves@redhat.com>

	* event-top.c (input_fd): Delete.
	(stdin_event_handler): Switch to the UI whose input descriptor got
	the event.  Adjust to per-UI input_fd.
	(gdb_setup_readline): Don't set the input_fd global.  Adjust to
	per-UI input_fd.
	(gdb_disable_readline): Adjust to per-UI input_fd.
	* event-top.h (input_fd): Delete declaration.
	* linux-nat.c (linux_nat_terminal_inferior): Don't remove input_fd
	from the event-loop here.
	(linux_nat_terminal_ours): Don't register input_fd in the
	event-loop here.
	* main.c (captured_main): Adjust to per-UI input_fd.
	* remote.c (remote_terminal_inferior): Don't remove input_fd from
	the event-loop here.
	(remote_terminal_ours): Don't register input_fd in the event-loop
	here.
	* target.c: Include top.h and event-top.h.
	(target_terminal_inferior): Remove input_fd from the event-loop
	here.
	(target_terminal_ours): Register input_fd in the event-loop.
	* top.h (struct ui) <input_fd>: New field.
2016-06-21 01:11:47 +01:00
Jan Kratochvil 57809e5e5a Workaround gdbserver<7.7 for setfs
With current FSF GDB HEAD and old FSF gdbserver I expected I could do:
	gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234'
(supplying that unsupported qXfer:exec-file:read by "file")
But that does not work because:
	Sending packet: $vFile:setfs:0#bf...Packet received: OK
	Packet vFile:setfs (hostio-setfs) is supported
	...
	Sending packet: $vFile:setfs:104#24...Packet received: OK
	"target:/root/redhat/threadit": could not open as an executable file: Invalid argument

GDB documentation says:
	The valid responses to Host I/O packets are:
	An empty response indicates that this operation is not recognized.

This "empty response" vs. "OK" was a bug in gdbserver < 7.7.  It was fixed by:
	commit e7f0d979dd
	Author: Yao Qi <yao@codesourcery.com>
	Date:   Tue Dec 10 21:59:20 2013 +0800
	    Fix a bug in matching notifications.
	Message-ID: <1386684626-11415-1-git-send-email-yao@codesourcery.com>
	https://sourceware.org/ml/gdb-patches/2013-12/msg00373.html
	2013-12-10  Yao Qi  <yao@codesourcery.com>
		* notif.c (handle_notif_ack): Return 0 if no notification
		matches.

with unpatched old FSF gdbserver and patched FSF GDB HEAD:
	gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234'
	Sending packet: $vFile:setfs:0#bf...Packet received: OK
	Packet vFile:setfs (hostio-setfs) is NOT supported
	...
	(gdb) info sharedlibrary
	From                To                  Syms Read   Shared Object Library
	0x00007ffff7ddbae0  0x00007ffff7df627a  Yes (*)     target:/lib64/ld-linux-x86-64.so.2
	0x00007ffff7bc48a0  0x00007ffff7bcf514  Yes (*)     target:/lib64/libpthread.so.0

gdb/ChangeLog
2016-04-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* remote.c (remote_start_remote): Detect PACKET_vFile_setfs.support.
2016-04-27 21:27:40 +02:00
Pedro Alves 3a00c80277 Fix PR remote/19840: gdb crashes on reverse-stepi
Reverse debugging against a remote target that does reverse debugging
itself (with the bs/bc packets) always trips on:

 (gdb) target remote localhost:...
 (gdb) reverse-stepi
 ../../gdb/target.c:602: internal-error: default_execution_direction: to_execution_direction must be implemented for reverse async

I missed adding a to_execution_direction method to remote.c in commit
3223143295 (Adds target_execution_direction to make record targets
support async mode), GDB 7.4 time.  Later, GDB 7.8 switched to
target-async on by default, making the regression user-visible by
default too.

Fix is simply to add the missing to_execution_direction implementation
to target remote.

Tested by Andi Kleen against Simics.

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

	PR remote/19840
	* remote.c (struct remote_state) <last_resume_exec_dir>: New
	field.
	(new_remote_state): Default last_resume_exec_dir to EXEC_FORWARD.
	(remote_open_1): Reset last_resume_exec_dir to EXEC_FORWARD.
	(remote_resume): Store the last execution direction.
	(remote_execution_direction): New function.
	(init_remote_ops): Install it as to_execution_direction target_ops
	method.
2016-04-13 14:34:00 +01:00
Pedro Alves 048094accc target remote: Don't rely on immediate_quit (introduce quit handlers)
remote.c is the last user of immediate_quit.  It's relied on to
immediately break the initial remote connection sync up, if the user
does Ctrl-C, assuming that was because the target isn't responding.
At that stage, since the connection isn't synced yet, disconnecting is
the only safe thing to do.  This commit reworks that, to not rely on
throwing from the SIGINT signal handler.

So, this commit:

- Introduces the concept of a "quit handler".  This is used to
  override what does the QUIT macro do when the quit flag is set.

- Makes the "struct serial" reachar / write code call QUIT in the
  partial read/write loops, so the current quit handler is invoked
  whenever a serial->read_prim / serial->write_prim returns EINTR.

- Makes the "struct serial" reachar / write code call
  interruptible_select instead of gdb_select, so that QUITs are
  detected in a race-free manner.

- Stops remote.c from setting immediate_quit during the initial
  connection.

- Instead, we install a custom quit handler whenever we're calling
  into the serial code.  This custom quit handler knows to immediately
  throw a quit when we're in the initial connection setup, and
  otherwise defer handling the quit/Ctrl-C request to later, when
  we're safely out of a packet command/response sequence.  This also
  is what is now responsible for handling "double Ctrl-C because
  target connection is stuck/wedged."

- remote.c no longer installs a specialized SIGINT handlers, and
  instead re-uses the quit flag.  Since we want to rely on the QUIT
  macro, the SIGINT handler must also set the quit.  And the easiest
  is just to not install custom SIGINT handler in remote.c.  Let the
  standard SIGINT handler do its job of setting the quit flag.
  Centralizing SIGINT handlers seems like a good thing to me, anyway.

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

	* defs.h (quit_handler_ftype, quit_handler)
	(make_cleanup_override_quit_handler, default_quit_handler): New.
	(QUIT): Adjust comments.
	* event-top.c (default_quit_handler): New function.
	(quit_handler): New global.
	(struct quit_handler_cleanup_data): New.
	(restore_quit_handler, restore_quit_handler_dtor)
	(make_cleanup_override_quit_handler): New.
	(async_request_quit): Call QUIT.
	* remote.c (struct remote_state) <got_ctrlc_during_io>: New field.
	(async_sigint_remote_twice_token, async_sigint_remote_token):
	Delete.
	(remote_close): Update comments.
	(remote_start_remote): Don't set immediate_quit.  Set starting_up
	earlier.
	(remote_serial_quit_handler, remote_unpush_and_throw): New
	functions.
	(remote_open_1): Clear got_ctrlc_during_io.  Set
	remote_async_terminal_ours_p unconditionally.
	(async_initialize_sigint_signal_handler)
	(async_handle_remote_sigint, async_handle_remote_sigint_twice)
	(remote_check_pending_interrupt, async_remote_interrupt)
	(async_remote_interrupt_twice)
	(async_cleanup_sigint_signal_handler, ofunc)
	(sync_remote_interrupt, sync_remote_interrupt_twice): Delete.
	(remote_terminal_inferior, remote_terminal_ours): Remove async
	checks.
	(remote_wait_as): Don't install a SIGINT handler in sync mode.
	(readchar, remote_serial_write): Override the quit handler with
	remote_serial_quit_handler.
	(getpkt_or_notif_sane_1): Don't call QUIT.
	(initialize_remote_ops): Don't install
	remote_check_pending_interrupt.
	(_initialize_remote): Don't create async_sigint_remote_token and
	async_sigint_remote_twice_token.
	* ser-base.c (ser_base_wait_for): Call QUIT and use
	interruptible_select.
	(ser_base_write): Call QUIT.
	* ser-go32.c (dos_readchar, dos_write): Call QUIT.
	* ser-unix.c (wait_for): Don't use VTIME.  Always take the
	gdb_select path, but call QUIT and interruptible_select.
	* utils.c (maybe_quit): Call the current quit handler.  Don't call
	target_check_pending_interrupt.
	(defaulted_query, prompt_for_continue): Override the quit handler
	with the default quit handler.
2016-04-12 17:01:18 +01:00
Pedro Alves 651ce16aa7 Do target_terminal_ours in query & friends instead of in all callers
Any time a caller calls query & friends / prompt_for_continue without
ensuring that gdb owns the terminal for input is a bug.  So do that in
defaulted_query / prompt_for_continue directly instead.

An example of a case where we currently miss calling
target_terminal_ours is internal_error.  Ever since defaulted_query
was made to use gdb_readline_callback, there's no way to answer the
internal error query if the internal error happens while the target is
has the terminal:

  (gdb) c
  Continuing.
  .../src/gdb/linux-nat.c:1676: internal-error: linux_nat_resume: Assertion `dummy_counter < 10' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n) _

Entering 'y' or 'n' does not work, GDB does not respond.

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

	PR gdb/19828
	* gnu-nat.c (inf_validate_task_sc): Don't call
	target_terminal_ours / target_terminal_inferior around query.
	* i386-tdep.c (i386_record_lea_modrm, i386_process_record): Don't
	call target_terminal_ours / target_terminal_inferior around
	yquery.
	* linux-record.c (record_linux_system_call): Don't call
	target_terminal_ours / target_terminal_inferior around yquery.
	* nto-procfs.c (interrupt_query): Don't call target_terminal_ours
	/ target_terminal_inferior around query.
	* record-full.c (record_full_check_insn_num): Remove
	'set_terminal' parameter.  Don't call target_terminal_ours /
	target_terminal_inferior around query.
	(record_full_message, record_full_registers_change)
	(record_full_xfer_partial): Adjust.
	* remote.c (interrupt_query): Don't call target_terminal_ours /
	target_terminal_inferior around query.
	* utils.c (defaulted_query): Install cleanup to restore target
	terminal.  Put target_terminal_ours_for_output in effect while
	defaulted producing, and target_terminal_ours in in effect while
	handling input.
	(prompt_for_continue): Install cleanup to restore target terminal.
	Put target_terminal_ours in in effect while handling input.
2016-04-12 17:00:01 +01:00
Pedro Alves 93692b589d Pass Ctrl-C to the target in target_terminal_inferior
If the user presses Ctrl-C immediately before target_terminal_inferior
is called and the target is resumed, instead of after, the Ctrl-C ends
up pending in the quit flag until the target next stops.

remote.c has this bit to handle this:

      if (!target_is_async_p ())
	{
	  ofunc = signal (SIGINT, sync_remote_interrupt);
	  /* If the user hit C-c before this packet, or between packets,
	     pretend that it was hit right here.  */
	  if (check_quit_flag ())
	    sync_remote_interrupt (SIGINT);
	}

But that's only reachable if async is off, while async is on by
default nowadays.  It's also obviously not reacheable on native
targets.

This patch generalizes that to all targets.

We can't remove that remote.c bit yet, until we get rid of the sync
SIGINT handler though.  That'll be done later in the series.

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

	* remote.c (remote_pass_ctrlc): New function.
	(init_remote_ops): Install it.
	* target.c (target_terminal_inferior): Pass pending Ctrl-C to the
	target.
	(target_pass_ctrlc, default_target_pass_ctrlc): New functions.
	* target.h (struct target_ops) <to_pass_ctrlc>: New method.
	(target_pass_ctrlc, default_target_pass_ctrlc): New declarations.
	* target-delegates.c: Regenerate.
2016-04-12 16:57:10 +01:00
Pedro Alves e42de8c7f8 Decouple target_interrupt from all-stop/non-stop modes
In non-stop mode, "interrupt" results in a "stop with no signal",
while in all-stop mode, it results in a remote interrupt request /
stop with SIGINT.  This is currently implemented in both the Linux and
remote target backends.  Move it to the core code instead, making
target_interrupt specifically always about "Interrupting as if with
Ctrl-C", just like it is documented.

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

	* infcmd.c (interrupt_target_1): Call target_stop is in non-stop
	mode.
	* linux-nat.c (linux_nat_interrupt): Delete.
	(linux_nat_add_target): Don't install linux_nat_interrupt.
	* remote.c (remote_interrupt_ns): Change return type to void.
	Throw error if interrupting the target is not supported.
	(remote_interrupt): Don't call the remote_stop_ns/remote_stop_as.
2016-04-12 16:56:39 +01:00
Pedro Alves abf009ef94 Don't call clear_quit_flag after check_quit_flag
Obviously not necessary since check_quit_flag clears the flag as side
effect.

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

	* remote-sim.c (gdb_os_poll_quit): Don't call clear_quit_flag.
	* remote.c (remote_wait_as): Don't call clear_quit_flag.
2016-04-12 16:54:49 +01:00
Jan Kratochvil 147316171d Revert the previous commit adding unknown_v_replies_ok.
It broke the compatibility with gdbserver-7.6 due to:
	warning: remote target does not support file transfer, attempting to access files from local filesystem.

gdb/ChangeLog
2016-04-06  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Revert the previous commit adding unknown_v_replies_ok.
2016-04-06 21:05:16 +02:00
Jan Kratochvil 319cb5d0cf Workaround gdbserver<7.7 for setfs
With current FSF GDB HEAD and old FSF gdbserver I expected I could do:
	gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234'
(supplying that unsupported qXfer:exec-file:read by "file")
But that does not work because:
	Sending packet: $vFile:setfs:0#bf...Packet received: OK
	Packet vFile:setfs (hostio-setfs) is supported
	...
	Sending packet: $vFile:setfs:104#24...Packet received: OK
	"target:/root/redhat/threadit": could not open as an executable file: Invalid argument

GDB documentation says:
	The valid responses to Host I/O packets are:
	An empty response indicates that this operation is not recognized.

This "empty response" vs. "OK" was a bug in gdbserver < 7.7.  It was fixed by:
	commit e7f0d979dd
	Author: Yao Qi <yao@codesourcery.com>
	Date:   Tue Dec 10 21:59:20 2013 +0800
	    Fix a bug in matching notifications.
	Message-ID: <1386684626-11415-1-git-send-email-yao@codesourcery.com>
	https://sourceware.org/ml/gdb-patches/2013-12/msg00373.html
	2013-12-10  Yao Qi  <yao@codesourcery.com>
		* notif.c (handle_notif_ack): Return 0 if no notification
		matches.

with unpatched old FSF gdbserver and patched FSF GDB HEAD:
	gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234'
	Sending packet: $vFile:setfs:0#bf...Packet received: OK
	Packet vFile:setfs (hostio-setfs) is NOT supported
	...
	(gdb) info sharedlibrary
	From                To                  Syms Read   Shared Object Library
	0x00007ffff7ddbae0  0x00007ffff7df627a  Yes (*)     target:/lib64/ld-linux-x86-64.so.2
	0x00007ffff7bc48a0  0x00007ffff7bcf514  Yes (*)     target:/lib64/libpthread.so.0

gdb/ChangeLog
2016-04-06  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* remote.c (struct remote_state): New field unknown_v_replies_ok.
	(packet_config_support): Read it.
	(remote_start_remote): Set it.
2016-04-06 17:18:21 +02:00
Jan Kratochvil 052d2eb254 Revert check-in by a mistake in the previous commit.
gdb/ChangeLog
2016-04-06  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* remote.c: Revert check-in by a mistake in the previous commit.
2016-04-06 16:48:27 +02:00
Jan Kratochvil fef3cb9f3a Print the "file" command suggestion in exec_file_locate_attach
currently:
	$ gdbserver-7.9 :1234 true &
	$ gdb -q -ex 'target remote :1234' # that -q is not relevant here
	Remote debugging using :1234
	warning: Could not load vsyscall page because no executable was specified
	try using the "file" command first.
	0x00007ffff7ddcc80 in ?? ()
	(gdb) b main
	No symbol table is loaded.  Use the "file" command.
	Make breakpoint pending on future shared library load? (y or [n]) _

Provide more suggestive message to use the "file" command.

gdb/ChangeLog
2016-04-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* exec.c (exec_file_locate_attach): Print warning for unsupported
	target_pid_to_exec_file.
	* symfile-mem.c (add_vsyscall_page): Remove the "file" command
	message part.
2016-04-06 15:57:08 +02:00
Marcin Kościelnicki 28170b88cc gdbserver: Handle 'v' packet while processing qSymbol.
On powerpc64, qSymbol query may require gdb to read a function
descriptor, sending a vFile packet to gdbserver.  Thus, we need
to handle 'v' packet in look_up_one_symbol.

vFile replies may be quite long, and require reallocating own_buf.
Since handle_v_requests assumes the buffer is the static global own_buf
from server.c and reallocates it, we need to make own_buf global and
use it from look_up_one_symbol instead of using our own auto variable.
I've also done the same change in relocate_instruction, just in case.

On gdb side, in remote_check_symbols, rs->buf may be clobbered by vFile
handling, yet we need its contents for the reply (the symbol name is
stored there).  Allocate a new buffer instead.

This broke fast tracepoints on powerpc64, due to errors in reading IPA
symbols.

gdb/ChangeLog:

	* remote.c (remote_check_symbols): Allocate own buffer for reply.

gdbserver/ChangeLog:

	* remote-utils.c (look_up_one_symbol): Remove own_buf, handle 'v'
	packets.
	(relocate_instruction): Remove own_buf.
	* server.c (own_buf): Make global.
	(handle_v_requests): Make global.
	* server.h (own_buf): New declaration.
	(handle_v_requests): New prototype.
2016-03-30 01:51:06 +02:00
Pedro Alves 0d5b594f86 PR remote/19496, timeout in forking-threads-plus-bkpt
This patch addresses a failure in
gdb.threads/forking-threads-plus-breakpoint.exp:

FAIL: gdb.threads/forking-threads-plus-breakpoint.exp: cond_bp_target=1:
detach_on_fork=on: inferior 1 exited (timeout)

Cause:

A fork event was reported to GDB before GDB knew about the parent
thread, followed immediately by a breakpoint event in a different
thread.  The parent thread was subsequently added via
remote_notice_new_inferior in process_stop_reply, but when the thread
was added the thread_info.state was set to THREAD_STOPPED.  The fork
event was then handled correctly, but when the fork parent was resumed
via a call to keep_going, the state was unchanged.

The breakpoint event was then handled, which caused all the
non-breakpoint threads to be stopped.  When the breakpoint thread was
resumed, all the non-breakpoint threads were resumed via
infrun.c:restart_threads.  Our old fork parent wasn't restarted,
because it still had thread_info.state set to THREAD_STOPPED.
Ultimately the program under debug hung waiting for a pthread_join
while the old fork parent was stopped forever by GDB.

Fix:

Since this is non-stop, then the bug is that the thread should have
been added in THREAD_RUNNING state.  Consider that infrun may be
pulling target events out of the target_ops backend into its own event
queue, but, not process them immediately.  E.g., infrun may be
stopping all threads temporarily for a step-over-breakpoint operation
for thread A (stop_all_threads).  The waitstatus of all threads is
thus left pending in the thread structure (save_status), including the
fork event of thread B.  Right at this point, if the user does "info
threads", that should show thread B (the fork parent) running, not
stopped, even if internally, gdb is holding it paused for a little
bit.

Thus if in non-stop mode, always add new threads in the external
user-visible THREAD_RUNNING state.  Change remote_notice_new_inferior
to accept the internal executing state of the thread instead, with
EXECUTING set to 1 when we discover a thread that is running on the
target (such as through remote_update_thread_list), and 0 when the
thread is really paused (such as when we see a stop reply).

Tested on x86_64 Linux and Nios II Linux target with x86 Linux host.

gdb/ChangeLog:
2016-03-17  Pedro Alves  <palves@redhat.com>
	    Don Breazeal  <donb@codesourcery.com>

	PR remote/19496
	* infcmd.c (notice_new_inferior): Use the 'leave_running' argument
	instead of checking the 'non_stop' global.
	* remote.c (remote_add_thread): New parameter 'executing'.  Use it
	to set the new thread's executing state.
	(remote_notice_new_inferior): Rename parameter 'running' to
	'executing'.  Always set the thread state to THREAD_RUNNING in
	non-stop mode, and to THREAD_STOPPED in all-stop mode.  Pass
	EXECUTING to remote_add_thread and notice_new_inferior.
	(remote_update_thread_list): Update to pass executing state, not
	running state.
2016-03-17 10:21:37 +00:00
Don Breazeal 4041ed7780 PR remote/19496, internal err forking-threads-plus-bkpt
This patch fixes an internal error that occurs in
gdb.threads/forking-threads-plus-breakpoint.exp:

/blah/binutils-gdb/gdb/target.c:2723: internal-error: Can't determine the
current address space of thread Thread 3170.3170

In default_thread_address_space, find_inferior_ptid couldn't find 3170.3170
because it had been overwritten in inferior_appeared, called as follows:

inferior_appeared
  remote_add_inferior
    remote_notice_new_inferior
      remote_update_thread_list

The cause of the problem was the following sequence of events:

* GDB knows only about the main thread

* the first fork event is reported to GDB, saved as pending_event

* qXfer:threads:read gets the threads from the remote.
  remove_new_fork_children id's the fork child from the pending event
  and removes it from the list reported to GDB.  All the rest of the
  threads, including the fork parent, are added to the GDB thread list.

* GDB stops all the threads.  All the stop events are pushed onto the
  stop reply queue behind the pending fork event.  The fork waitstatus
  is saved in the fork parent thread's pending status field
  thread_info.suspend.

* remote_wait_ns calls queued_stop_reply and process_stop_reply to
  remove the fork event from the front of the stop reply queue and save
  event information in the thread_info structure for the fork parent
  thread.  Unfortunately, none of the information saved in this way is
  the fork-specific information.

* A subsequent qXfer:threads:read packet gets the thread list including
  the fork parent and fork child.  remove_new_fork_children checks the
  thread list to see if there is a fork parent, doesn't find one, checks
  the stop reply queue for a pending fork event, doesn't find one, and
  allows the fork child thread to be reported to GDB before the fork
  event has been handled.  remote_update_thread_list calls
  remote_notice_new_thread and overwrites the current (main) thread in
  inferior_appeared.

So the fork event has been reported out of target_wait but it was left
pending on the infrun side (infrun.c:save_waitstatus).  IOW, the fork
event hasn't been processed by handle_inferior_event yet, so it hasn't
made it to tp->pending_follow yet.

The fix is to check thread_info.suspend along with the
thread_info.pending_follow in remote.c:remove_new_fork_children, to
prevent premature reporting of the fork child thread creation.

gdb/ChangeLog:

	PR remote/19496
	* remote.c (remove_new_fork_children): Check for pending
	fork status in thread_info.suspend.

gdb/testsuite/ChangeLog:

	PR remote/19496
	* gdb.threads/forking-threads-plus-breakpoint.exp (do_test):
	Remove kfail for PR remote/19496.
2016-02-16 08:56:06 -08:00
Simon Marchi 5488790363 remote.c: Cleanup unused variables
I built remote.c with -Wunused, to check a function I was working on,
turns out there is a bunch of unused variables.

gdb/ChangeLog:

	* remote.c (remote_register_number_and_offset): Remove unused
	variable(s).
	(remote_thread_always_alive): Likewise.
	(remote_update_thread_list): Likewise.
	(process_initial_stop_replies): Likewise.
	(remote_start_remote): Likewise.
	(remote_check_symbols): Likewise.
	(discard_pending_stop_replies): Likewise.
	(process_stop_reply): Likewise.
	(putpkt_binary): Likewise.
	(getpkt): Likewise.
	(remote_add_target_side_condition): Likewise.
	(remote_insert_breakpoint): Likewise.
	(remote_supports_stopped_by_sw_breakpoint): Likewise.
	(remote_supports_stopped_by_hw_breakpoint): Likewise.
	(remote_xfer_partial): Likewise.
	(remote_read_btrace): Likewise.
	(remote_async_serial_handler): Likewise.
	(remote_thread_events): Likewise.
	(_initialize_remote): Likewise.
2016-02-08 12:57:08 -05:00
Yao Qi e42e5352d1 waiting_for_stop_reply around remote_fileio_request
Hi,
I see this error when GDB connects with qemu,

(gdb) n
....
Sending packet: $vCont;c#a8...Ack
Packet received: Ffstat,00000001,f6fff038
Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.

looks we don't set rs->waiting_for_stop_reply to zero
before handle fileio request,

 #10 0x00000000005edb64 in target_write (len=64, offset=4143968312, buf=0x7fffffffd570 "\375\377\377\377", annex=0x0, object=TARGET_OBJECT_MEMORY,
    ops=<optimised out>) at /home/yao/SourceCode/gnu/gdb/git/gdb/target.c:1922
 #11 target_write_memory (memaddr=memaddr@entry=4143968312, myaddr=myaddr@entry=0x7fffffffd6a0 "", len=len@entry=64)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/target.c:1500
 #12 0x00000000004b2b41 in remote_fileio_func_fstat (buf=0x127b258 "") at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:1037
 #13 0x00000000004b1878 in do_remote_fileio_request (uiout=<optimised out>, buf_arg=buf_arg@entry=0x127b240)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:1204
 #14 0x00000000005b8c7c in catch_exceptions_with_msg (func_uiout=<optimised out>, func=func@entry=0x4b1800 <do_remote_fileio_request>,
    func_args=func_args@entry=0x127b240, gdberrmsg=gdberrmsg@entry=0x0, mask=mask@entry=RETURN_MASK_ALL)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/exceptions.c:187
 #15 0x00000000005b8dea in catch_exceptions (uiout=<optimised out>, func=func@entry=0x4b1800 <do_remote_fileio_request>, func_args=func_args@entry=0x127b240,
    mask=mask@entry=RETURN_MASK_ALL) at /home/yao/SourceCode/gnu/gdb/git/gdb/exceptions.c:167
 #16 0x00000000004b2fff in remote_fileio_request (buf=0x127b240 "Xf6fff038,0:", ctrlc_pending_p=0) at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:1255
 #17 0x0000000000496f12 in remote_wait_as (ptid=..., status=0x7fffffffdb20, options=1) at /home/yao/SourceCode/gnu/gdb/git/gdb/remote.c:6997

however, we did set rs->waiting_for_stop_reply to zero before Luis's
patch https://sourceware.org/ml/gdb-patches/2015-10/msg00336.html

In fact, Luis's patch v1
https://sourceware.org/ml/gdb-patches/2015-08/msg00809.html is about
setting rs->waiting_for_stop_reply back to one after
remote_fileio_request, which is correct.  However during the review, the
patch is changed and ends up with "not setting rs->waiting_for_stop_reply
to zero".

I manually test GDB, but I don't have a way to run regression tests.

gdb:

2016-02-04  Yao Qi  <yao.qi@linaro.org>

	* remote.c (remote_wait_as): Set rs->waiting_for_stop_reply to
	0 before handling 'F' and set it back afterwards.
2016-02-04 15:09:09 +00:00
Simon Marchi 8424cc978c Import strchrnul from gnulib and use it
For a forthcoming patch, I need a "skip_to_colon" function.  I noticed
there are two skip_to_semicolon (one in gdb and one in gdbserver). I
thought we could put it in common/, and generalize it for any character.
It turns out that the strchrnul function does exactly that.  I imported
the corresponding module from gnulib, for those systems that do not have
it.

There are probably more places where this function can be used instead
of doing the work by hand (I am looking at
remote-utils.c::look_up_one_symbol).

gdb/ChangeLog:

	* remote.c (skip_to_semicolon): Remove.
	(remote_parse_stop_reply): Use strchrnul instead of
	skip_to_semicolon.
	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add
	strchrnul.
	* gnulib/aclocal.m4: Regenerate.
	* gnulib/config.in: Regenerate.
	* gnulib/configure: Regenerate.
	* gnulib/import/Makefile.am: Regenerate.
	* gnulib/import/Makefile.in: Regenerate.
	* gnulib/import/m4/gnulib-cache.m4: Regenerate.
	* gnulib/import/m4/gnulib-comp.m4: Regenerate.
	* gnulib/import/m4/rawmemchr.m4: New file.
	* gnulib/import/m4/strchrnul.m4: New file.
	* gnulib/import/rawmemchr.c: New file.
	* gnulib/import/rawmemchr.valgrind: New file.
	* gnulib/import/strchrnul.c: New file.
	* gnulib/import/strchrnul.valgrind: New file.

gdb/gdbserver/ChangeLog:

	* server.c (skip_to_semicolon):  Remove.
	(process_point_options): Use strchrnul instead of
	skip_to_semicolon.
2016-01-28 10:28:56 -05:00
Yao Qi c0518081f0 Fix C++ build error by casting void *
Two recent patches breaks GDB C++ mode build,

  https://sourceware.org/ml/gdb-patches/2016-01/msg00150.html
  https://sourceware.org/ml/gdb-patches/2016-01/msg00086.html

gdb/remote.c: In function 'int remote_set_syscall_catchpoint(target_ops*, int, int, int, int, int*)':
gdb/remote.c:2036:39: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
       catch_packet = xmalloc (maxpktsz);
                                       ^

gdb/thread.c: In function 'int do_captured_thread_select(ui_out*, void*)':
gdb/git/gdb/thread.c:1999:24: error: invalid conversion from 'void*' to 'const char*' [-fpermissive]
   const char *tidstr = tidstr_v;
                        ^

this patch fixes them by casting void * to the right type.

gdb:

2016-01-14  Yao Qi  <yao.qi@linaro.org>

	* remote.c (remote_set_syscall_catchpoint): Cast to char *.
	* thread.c (do_captured_thread_select): Cast to const char *.
2016-01-14 12:28:02 +00:00
Pedro Alves 5d5658a1d3 Per-inferior/Inferior-qualified thread IDs
This commit changes GDB to track thread numbers per-inferior.  Then,
if you're debugging multiple inferiors, GDB displays
"inferior-num.thread-num" instead of just "thread-num" whenever it
needs to display a thread:

 (gdb) info inferiors
   Num  Description       Executable
   1    process 6022     /home/pedro/gdb/tests/threads
 * 2    process 6037     /home/pedro/gdb/tests/threads
 (gdb) info threads
   Id   Target Id         Frame
   1.1  Thread 0x7ffff7fc2740 (LWP 6022) "threads" (running)
   1.2  Thread 0x7ffff77c0700 (LWP 6028) "threads" (running)
   1.3  Thread 0x7ffff7fc2740 (LWP 6032) "threads" (running)
   2.1  Thread 0x7ffff7fc1700 (LWP 6037) "threads" (running)
   2.2  Thread 0x7ffff77c0700 (LWP 6038) "threads" (running)
 * 2.3  Thread 0x7ffff7fc2740 (LWP 6039) "threads" (running)
 (gdb)
...
 (gdb) thread 1.1
 [Switching to thread 1.1 (Thread 0x7ffff7fc2740 (LWP 8155))]
 (gdb)
...

etc.

You can still use "thread NUM", in which case GDB infers you're
referring to thread NUM of the current inferior.

The $_thread convenience var and Python's InferiorThread.num attribute
are remapped to the new per-inferior thread number.  It's a backward
compatibility break, but since it only matters when debugging multiple
inferiors, I think it's worth doing.

Because MI thread IDs need to be a single integer, we keep giving
threads a global identifier, _in addition_ to the per-inferior number,
and make MI always refer to the global thread IDs.  IOW, nothing
changes from a MI frontend's perspective.

Similarly, since Python's Breakpoint.thread and Guile's
breakpoint-thread/set-breakpoint-thread breakpoint methods need to
work with integers, those are adjusted to work with global thread IDs
too.  Follow up patches will provide convenient means to access
threads' global IDs.

To avoid potencially confusing users (which also avoids updating much
of the testsuite), if there's only one inferior and its ID is "1",
IOW, the user hasn't done anything multi-process/inferior related,
then the "INF." part of thread IDs is not shown.  E.g,.:

 (gdb) info inferiors
   Num  Description       Executable
 * 1    process 15275     /home/pedro/gdb/tests/threads
 (gdb) info threads
   Id   Target Id         Frame
 * 1    Thread 0x7ffff7fc1740 (LWP 15275) "threads" main () at threads.c:40
 (gdb) add-inferior
 Added inferior 2
 (gdb) info threads
   Id   Target Id         Frame
 * 1.1  Thread 0x7ffff7fc1740 (LWP 15275) "threads" main () at threads.c:40
 (gdb)

No regressions on x86_64 Fedora 20.

gdb/ChangeLog:
2016-01-13  Pedro Alves  <palves@redhat.com>

	* NEWS: Mention that thread IDs are now per inferior and global
	thread IDs.
	* Makefile.in (SFILES): Add tid-parse.c.
	(COMMON_OBS): Add tid-parse.o.
	(HFILES_NO_SRCDIR): Add tid-parse.h.
	* ada-tasks.c: Adjust to use ptid_to_global_thread_id.
	* breakpoint.c (insert_breakpoint_locations)
	(remove_threaded_breakpoints, bpstat_check_breakpoint_conditions)
	(print_one_breakpoint_location, set_longjmp_breakpoint)
	(check_longjmp_breakpoint_for_call_dummy)
	(set_momentary_breakpoint): Adjust to use global IDs.
	(find_condition_and_thread, watch_command_1): Use parse_thread_id.
	(until_break_command, longjmp_bkpt_dtor)
	(breakpoint_re_set_thread, insert_single_step_breakpoint): Adjust
	to use global IDs.
	* dummy-frame.c (pop_dummy_frame_bpt): Adjust to use
	ptid_to_global_thread_id.
	* elfread.c (elf_gnu_ifunc_resolver_stop): Likewise.
	* gdbthread.h (struct thread_info): Rename field 'num' to
	'global_num.  Add new fields 'per_inf_num' and 'inf'.
	(thread_id_to_pid): Rename thread_id_to_pid to
	global_thread_id_to_ptid.
	(pid_to_thread_id): Rename to ...
	(ptid_to_global_thread_id): ... this.
	(valid_thread_id): Rename to ...
	(valid_global_thread_id): ... this.
	(find_thread_id): Rename to ...
	(find_thread_global_id): ... this.
	(ALL_THREADS, ALL_THREADS_BY_INFERIOR): Declare.
	(print_thread_info): Add comment.
	* tid-parse.h: New file.
	* tid-parse.c: New file.
	* infcmd.c (step_command_fsm_prepare)
	(step_command_fsm_should_stop): Adjust to use the global thread
	ID.
	(until_next_command, until_next_command)
	(finish_command_fsm_should_stop): Adjust to use the global thread
	ID.
	(attach_post_wait): Adjust to check the inferior number too.
	* inferior.h (struct inferior) <highest_thread_num>: New field.
	* infrun.c (handle_signal_stop)
	(insert_exception_resume_breakpoint)
	(insert_exception_resume_from_probe): Adjust to use the global
	thread ID.
	* record-btrace.c (record_btrace_open): Use global thread IDs.
	* remote.c (process_initial_stop_replies): Also consider the
	inferior number.
	* target.c (target_pre_inferior): Clear the inferior's highest
	thread num.
	* thread.c (clear_thread_inferior_resources): Adjust to use the
	global thread ID.
	(new_thread): New inferior parameter.  Adjust to use it.  Set both
	the thread's global ID and the thread's per-inferior ID.
	(add_thread_silent): Adjust.
	(find_thread_global_id): New.
	(find_thread_id): Make static.  Adjust to rename.
	(valid_thread_id): Rename to ...
	(valid_global_thread_id): ... this.
	(pid_to_thread_id): Rename to ...
	(ptid_to_global_thread_id): ... this.
	(thread_id_to_pid): Rename to ...
	(global_thread_id_to_ptid): ... this.  Adjust.
	(first_thread_of_process): Adjust.
	(do_captured_list_thread_ids): Adjust to use global thread IDs.
	(should_print_thread): New function.
	(print_thread_info): Rename to ...
	(print_thread_info_1): ... this, and add new show_global_ids
	parameter.  Handle it.  Iterate over inferiors.
	(print_thread_info): Reimplement as wrapper around
	print_thread_info_1.
	(show_inferior_qualified_tids): New function.
	(print_thread_id): Use it.
	(tp_array_compar): Compare inferior numbers too.
	(thread_apply_command): Use tid_range_parser.
	(do_captured_thread_select): Use parse_thread_id.
	(thread_id_make_value): Adjust.
	(_initialize_thread): Adjust "info threads" help string.
	* varobj.c (struct varobj_root): Update comment.
	(varobj_create): Adjust to use global thread IDs.
	(value_of_root_1): Adjust to use global_thread_id_to_ptid.
	* windows-tdep.c (display_tib): No longer accept an argument.
	* cli/cli-utils.c (get_number_trailer): Make extern.
	* cli/cli-utils.h (get_number_trailer): Declare.
	(get_number_const): Adjust documentation.
	* mi/mi-cmd-var.c (mi_cmd_var_update_iter): Adjust to use global
	thread IDs.
	* mi/mi-interp.c (mi_new_thread, mi_thread_exit)
	(mi_on_normal_stop, mi_output_running_pid, mi_on_resume):
	* mi/mi-main.c (mi_execute_command, mi_cmd_execute): Likewise.
	* guile/scm-breakpoint.c (gdbscm_set_breakpoint_thread_x):
	Likewise.
	* python/py-breakpoint.c (bppy_set_thread): Likewise.
	* python/py-finishbreakpoint.c (bpfinishpy_init): Likewise.
	* python/py-infthread.c (thpy_get_num): Add comment and return the
	per-inferior thread ID.
	(thread_object_getset): Update comment of "num".

gdb/testsuite/ChangeLog:
2016-01-07  Pedro Alves  <palves@redhat.com>

	* gdb.base/break.exp: Adjust to output changes.
	* gdb.base/hbreak2.exp: Likewise.
	* gdb.base/sepdebug.exp: Likewise.
	* gdb.base/watch_thread_num.exp: Likewise.
	* gdb.linespec/keywords.exp: Likewise.
	* gdb.multi/info-threads.exp: Likewise.
	* gdb.threads/thread-find.exp: Likewise.
	* gdb.multi/tids.c: New file.
	* gdb.multi/tids.exp: New file.

gdb/doc/ChangeLog:
2016-01-07  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Threads): Document per-inferior thread IDs,
	qualified thread IDs, global thread IDs and thread ID lists.
	(Set Watchpoints, Thread-Specific Breakpoints): Adjust to refer to
	thread IDs.
	(Convenience Vars): Document the $_thread convenience variable.
	(Ada Tasks): Adjust to refer to thread IDs.
	(GDB/MI Async Records, GDB/MI Thread Commands, GDB/MI Ada Tasking
	Commands, GDB/MI Variable Objects): Update to mention global
	thread IDs.
	* guile.texi (Breakpoints In Guile)
	<breakpoint-thread/set-breakpoint-thread breakpoint>: Mention
	global thread IDs instead of thread IDs.
	* python.texi (Threads In Python): Adjust documentation of
	InferiorThread.num.
	(Breakpoint.thread): Mention global thread IDs instead of thread
	IDs.
2016-01-13 10:59:43 +00:00
Josh Stone 82075af2c1 Implement 'catch syscall' for gdbserver
This adds a new QCatchSyscalls packet to enable 'catch syscall', and new
stop reasons "syscall_entry" and "syscall_return" for those events.  It
is currently only supported on Linux x86 and x86_64.

gdb/ChangeLog:

2016-01-12  Josh Stone  <jistone@redhat.com>
	    Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS (Changes since GDB 7.10): Mention QCatchSyscalls and the
	syscall_entry and syscall_return stop reasons.  Mention GDB
	support for remote catch syscall.
	* remote.c (PACKET_QCatchSyscalls): New enum.
	(remote_set_syscall_catchpoint): New function.
	(remote_protocol_features): New element for QCatchSyscalls.
	(remote_parse_stop_reply): Parse syscall_entry/return stops.
	(init_remote_ops): Install remote_set_syscall_catchpoint.
	(_initialize_remote): Config QCatchSyscalls.
	* linux-nat.h (struct lwp_info) <syscall_state>: Comment typo.

gdb/doc/ChangeLog:

2016-01-12  Josh Stone  <jistone@redhat.com>
	    Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Remote Configuration): List the QCatchSyscalls packet.
	(Stop Reply Packets): List the syscall entry and return stop reasons.
	(General Query Packets): Describe QCatchSyscalls, and add it to the
	table and the detailed list of stub features.

gdb/gdbserver/ChangeLog:

2016-01-12  Josh Stone  <jistone@redhat.com>
	    Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* inferiors.h: Include "gdb_vecs.h".
	(struct process_info): Add syscalls_to_catch.
	* inferiors.c (remove_process): Free syscalls_to_catch.
	* remote-utils.c (prepare_resume_reply): Report syscall_entry and
	syscall_return stops.
	* server.h (UNKNOWN_SYSCALL, ANY_SYSCALL): Define.
	* server.c (handle_general_set): Handle QCatchSyscalls.
	(handle_query): Report support for QCatchSyscalls.
	* target.h (struct target_ops): Add supports_catch_syscall.
	(target_supports_catch_syscall): New macro.
	* linux-low.h (struct linux_target_ops): Add get_syscall_trapinfo.
	(struct lwp_info): Add syscall_state.
	* linux-low.c (handle_extended_wait): Mark syscall_state as an entry.
	Maintain syscall_state and syscalls_to_catch across exec.
	(get_syscall_trapinfo): New function, proxy to the_low_target.
	(linux_low_ptrace_options): Enable PTRACE_O_TRACESYSGOOD.
	(linux_low_filter_event): Toggle syscall_state entry/return for
	syscall traps, and set it ignored for all others.
	(gdb_catching_syscalls_p): New function.
	(gdb_catch_this_syscall_p): New function.
	(linux_wait_1): Handle SYSCALL_SIGTRAP.
	(linux_resume_one_lwp_throw): Add PTRACE_SYSCALL possibility.
	(linux_supports_catch_syscall): New function.
	(linux_target_ops): Install it.
	* linux-x86-low.c (x86_get_syscall_trapinfo): New function.
	(the_low_target): Install it.

gdb/testsuite/ChangeLog:

2016-01-12  Josh Stone  <jistone@redhat.com>
	    Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/catch-syscall.c (do_execve): New variable.
	(main): Conditionally trigger an execve.
	* gdb.base/catch-syscall.exp: Enable testing for remote targets.
	(test_catch_syscall_execve): New, check entry/return across execve.
	(do_syscall_tests): Call test_catch_syscall_execve.
2016-01-12 12:27:27 -08:00
Joel Brobecker 618f726fcb GDB copyright headers update after running GDB's copyright.py script.
gdb/ChangeLog:

        Update year range in copyright notice of all files.
2016-01-01 08:43:22 +04:00
Don Breazeal 8020350c52 Target remote mode fork and exec event support
This patch implements support for fork and exec events with target remote
mode Linux targets.  For such targets with Linux kernels 2.5.46 and later,
this enables follow-fork-mode, detach-on-fork and fork and exec
catchpoints.

The changes required to implement this included:

 * Don't exit from gdbserver if there are still active inferiors.

 * Allow changing the active process in remote mode.

 * Enable fork and exec events in remote mode.

 * Print "Ending remote debugging" only when disconnecting.

 * Combine remote_kill and extended_remote_kill into a single function
   that can handle the multiple inferior case for target remote.  Also,
   the same thing for remote_mourn and extended_remote_mourn.

 * Enable process-style ptids in target remote.

 * Remove restriction on multiprocess mode in target remote.

gdb/gdbserver/ChangeLog:

	* server.c (process_serial_event): Don't exit from gdbserver
	in remote mode if there are still active inferiors.

gdb/ChangeLog:

	* inferior.c (number_of_live_inferiors): New function.
	(have_live_inferiors): Use number_of_live_inferiors in place
	of duplicate code.
	* inferior.h (number_of_live_inferiors): Declare new function.
	* remote.c (set_general_process): Remove restriction on target
	remote mode.
	(remote_query_supported): Likewise.
	(remote_detach_1): Exit in target remote mode only when there
	is just one live inferior left.
	(remote_disconnect): Unpush the target directly instead of
	calling remote_mourn.
	(remote_kill): Rewrite function to handle both target remote
	and extended-remote.  Call remote_kill_k.
	(remote_kill_k): New function.
	(extended_remote_kill): Delete function.
	(remote_mourn, extended_remote_mourn): Combine functions into
	one, remote_mourn, and enable extended functionality for target
	remote.
	(remote_pid_to_str): Enable "process" style ptid string for
	target remote.
	(remote_supports_multi_process): Remove restriction on target
	remote mode.
2015-12-14 11:18:05 -08:00
Ulrich Weigand 974eac9d76 Avoid "operation may be undefined" warning in remote.c
GCC 4.1 gives the following warning:
gdb/remote.c: In function 'remote_parse_stop_reply':
gdb/remote.c:6549: warning: operation on 'p' may be undefined
on this line of code:

	event->ptid = read_ptid (++p, &p);

Since p actually isn't used afterwards anyway, simply use NULL.

gdb/
	* remote.c (remote_parse_stop_reply): Avoid GCC 4.1 "operation
	may be undefined" warning.
2015-12-01 18:04:39 +01:00
Ulrich Weigand 2e3b657e3a Fix uninitialized variable warnings in remote.c
Fix a couple of places where a struct thread_item was added to a
vector while the item.name field was uninitialized.

gdb/
	* remote.c (remote_newthread_step): Initialize item.name.
	(remote_get_threads_with_qthreadinfo): Likewise.
2015-12-01 17:49:27 +01:00
Pedro Alves f2faf941ae Implement TARGET_WAITKIND_NO_RESUMED in the remote protocol
Testing with "maint set target-non-stop on" causes regressions in
tests that rely on TARGET_WAITKIND_NO_RESUMED, which isn't modelled on
the RSP.  In real all-stop, gdbserver detects the situation and
reporst error to GDB, and so the tests (e.g.,
gdb.threads/no-unwaited-for-left.exp) at fail quickly.  But with
"maint set target-non-stop on", GDB instead hangs forever waiting for
a stop reply that never comes, and so the tests take longer to time
out.

This adds a new "N" stop reply packet that maps 1-1 to
TARGET_WAITKIND_NO_RESUMED.

gdb/ChangeLog:
2015-11-30  Pedro Alves  <palves@redhat.com>

	PR 14618
	* NEWS (New remote packets): Mention the N stop reply.
	* remote.c (remote_protocol_features): Add "no-resumed" entry.
	(remote_query_supported): Report no-resumed+ support.
	(remote_parse_stop_reply): Handle 'N'.
	(process_stop_reply): Handle TARGET_WAITKIND_NO_RESUMED.
	(remote_wait_as): Handle 'N' / TARGET_WAITKIND_NO_RESUMED.
	(_initialize_remote): Register "set/show remote
	no-resumed-stop-reply" commands.

gdb/doc/ChangeLog:
2015-11-30  Pedro Alves  <palves@redhat.com>

	PR 14618
	* gdb.texinfo (Stop Reply Packets): Document the N stop reply.
	(Remote Configuration): Add the "set/show remote
	no-resumed-stop-reply" to the available settings table.
	(General Query Packets): Document the "no-resumed" qSupported
	feature.

gdb/gdbserver/ChangeLog:
2015-11-30  Pedro Alves  <palves@redhat.com>

	PR 14618
	* linux-low.c (linux_wait_1): If the last resumed thread is gone,
	report TARGET_WAITKIND_NO_RESUMED.
	* remote-utils.c (prepare_resume_reply): Handle
	TARGET_WAITKIND_NO_RESUMED.
	* server.c (report_no_resumed): New global.
	(handle_query) <qSupported>: Handle "no-resumed+".  Report
	"no-resumed+" support.
	(resume): When the target reports TARGET_WAITKIND_NO_RESUMED, only
	return error if the client doesn't support no-resumed events.
	(push_stop_notification): New function.
	(handle_target_event): Use it.  Report TARGET_WAITKIND_NO_RESUMED
	events if the client supports them.

gdb/testsuite/ChangeLog:
2015-11-30  Pedro Alves  <palves@redhat.com>

	* gdb.threads/no-unwaited-for-left.exp: Remove setup_kfail calls.
2015-11-30 18:43:24 +00:00
Pedro Alves 65706a29ba Remote thread create/exit events
When testing with "maint set target-non-stop on", a few
threading-related tests expose an issue that requires new RSP packets.

Say there are 3 threads running, 1-3.  If GDB tries to stop thread 1,
2 and 3, and then waits for their stops, but meanwhile say, thread 2
exits, GDB hangs forever waiting for a stop for thread 2 that won't
ever happen.

This patch fixes the issue by adding support for thread exit events to
the protocol.  However, we don't want these always enabled, as they're
useless most of the time, and would slow down remote debugging.  So I
made it so that GDB can enable/disable them, and then made gdb do that
around the cases that need it, which currently is only
infrun.c:stop_all_threads.

In turn, if we have thread exit events, then the extra "thread x
exited" traffic slows down attach-many-short-lived-threads.exp enough
that gdb has trouble keeping up with new threads that are spawned
while gdb tries to stop existing ones.  To fix that I added support
for the counterpart thread created events too.  Enabling those when we
try to stop threads ensures that new threads never get a chance to
themselves start new threads, killing the race.

gdb/doc/ChangeLog:
2015-11-30  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Remote Configuration): List "set/show remote
	thread-events" command in configuration table.
	(Stop Reply Packets): Document "T05 create" stop
	reason and 'w' stop reply.
	(General Query Packets): Document QThreadEvents packet.  Document
	QThreadEvents qSupported feature.

gdb/gdbserver/ChangeLog:
2015-11-30  Pedro Alves  <palves@redhat.com>

	* linux-low.c (handle_extended_wait): Assert that the LWP's
	waitstatus is TARGET_WAITKIND_IGNORE.  If GDB wants to hear about
	thread create events, leave the new child's status pending.
	(linux_low_filter_event): If GDB wants to hear about thread exit
	events, leave the LWP marked dead and don't delete it.
	(linux_wait_for_event_filtered): Don't check for thread exit.
	(filter_exit_event): New function.
	(linux_wait_1): Use it, when returning an exit event.
	(linux_resume_one_lwp_throw): Assert that the LWP's
	waitstatus is TARGET_WAITKIND_IGNORE.
	* remote-utils.c (prepare_resume_reply): Handle
	TARGET_WAITKIND_THREAD_CREATED and TARGET_WAITKIND_THREAD_EXITED.
	* server.c (report_thread_events): New global.
	(handle_general_set): Handle QThreadEvents.
	(handle_query) <qSupported>: Handle and report QThreadEvents+;
	(handle_target_event): Handle TARGET_WAITKIND_THREAD_CREATED and
	TARGET_WAITKIND_THREAD_EXITED.
	* server.h (report_thread_events): Declare.

gdb/ChangeLog:
2015-11-30  Pedro Alves  <palves@redhat.com>

	* NEWS (New commands): Mention "set/show remote thread-events"
	commands.
	(New remote packets): Mention thread created/exited stop reasons
	and QThreadEvents packet.
	* infrun.c (disable_thread_events): New function.
	(stop_all_threads): Disable/enable thread create/exit events.
	Handle TARGET_WAITKIND_THREAD_EXITED.
	(handle_inferior_event_1): Handle TARGET_WAITKIND_THREAD_CREATED
	and TARGET_WAITKIND_THREAD_EXITED.
	* remote.c (remove_child_of_pending_fork): Also remove threads of
	threads that have TARGET_WAITKIND_THREAD_EXITED events.
	(remote_parse_stop_reply): Handle "create" magic register.  Handle
	'w' stop reply.
	(initialize_remote): Install remote_thread_events as
	to_thread_events target hook.
	(remote_thread_events): New function.
	* target-delegates.c: Regenerate.
	* target.c (target_thread_events): New function.
	* target.h (struct target_ops) <to_thread_events>: New field.
	(target_thread_events): Declare.
	* target/waitstatus.c (target_waitstatus_to_string): Handle
	TARGET_WAITKIND_THREAD_CREATED and TARGET_WAITKIND_THREAD_EXITED.
	* target/waitstatus.h (enum target_waitkind)
	<TARGET_WAITKIND_THREAD_CREATED, TARGET_WAITKIND_THREAD_EXITED):
	New values.
2015-11-30 18:40:30 +00:00
Pedro Alves de979965d3 New vCtrlC packet, non-stop mode equivalent of \003
There's currently no non-stop equivalent of the all-stop ^C (\003)
"packet" that GDB sends when a ctrl-c is pressed while a foreground
command is active.  There's vCont;t, but that's defined to cause a
"signal 0" stop.

This fixes many tests that type ^C, when testing with extended-remote
with "maint set target-non-stop on".  E.g.:

 Continuing.
 talk to me baby
 PASS: gdb.base/interrupt.exp: process is alive
 a
 a
 PASS: gdb.base/interrupt.exp: child process ate our char
 ^C
 [Thread 22730.22730] #1 stopped.
 0x0000003615ee6650 in __read_nocancel () at ../sysdeps/unix/syscall-template.S:81
 81      T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
 (gdb) FAIL: gdb.base/interrupt.exp: send_gdb control C
 p func1 ()

gdb/
2015-11-30  Pedro Alves  <palves@redhat.com>

	* NEWS (New remote packets): Mention vCtrlC.
	* remote.c (PACKET_vCtrlC): New enum value.
	(async_remote_interrupt): Call target_interrupt instead of
	target_stop.
	(remote_interrupt_as): Remove 'ptid' parameter.
	(remote_interrupt_ns): New function.
	(remote_stop): Adjust.
	(remote_interrupt): If the target is in non-stop mode, try
	interrupting with vCtrlC.
	(initialize_remote): Install set remote ctrl-c packet.

gdb/doc/
2015-11-30  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Bootstrapping): Add "interrupting remote targets"
	anchor.
	(Packets): Document vCtrlC.

gdb/gdbserver/
2015-11-30  Pedro Alves  <palves@redhat.com>

	* server.c (handle_v_requests): Handle vCtrlC.
2015-11-30 18:37:55 +00:00
Pedro Alves 799a2abe61 remote: stop reason and watchpoint data address per thread
Running local-watch-wrong-thread.exp with "maint set target-non-stop
on" exposes that gdb/remote.c only records whether the target stopped
for a breakpoint/watchpoint plus the watchpoint data address *for the
last reported remote event*.  But in non-stop mode, we need to keep
that info per-thread, as each thread can end up with its own
last-status pending.

gdb/ChangeLog:
2015-11-30  Pedro Alves  <palves@redhat.com>

	* remote.c (struct remote_state) <remote_watch_data_address,
	stop_reason>: Delete fields.
	(struct private_thread_info) <stop_reason, watch_data_address>:
	New fields.
	(resume_clear_thread_private_info): New function.
	(append_pending_thread_resumptions): Call it.
	(remote_resume): Clear all threads' private info.
	(process_stop_reply): Adjust.
	(remote_wait_as): Don't reference remote_state's stop_reason
	field.
	(remote_stopped_by_sw_breakpoint)
	(remote_stopped_by_hw_breakpoint, remote_stopped_by_watchpoint)
	(remote_stopped_data_address): Adjust to refer get data from the
	current thread.
2015-11-30 18:37:31 +00:00
Pedro Alves 6efcd9a8b3 Remote all-stop-on-top-of-non-stop
This is the first pass at implementing support for all-stop mode
running against the remote target using the non-stop variant of the
protocol.

The trickiest part here is the initial connection setup/synching.  We
need to fetch all inferiors' target descriptions etc. before stopping
threads, because stop_all_threads needs to read the threads' registers
(to record each thread's stop_pc).  But OTOH, the initial inferior
setup (target_post_attach, post_create_inferior, etc.), only works
correctly if the inferior is stopped...  So I've split that initial
setup part from attach_command_post_wait to a separate function, and
added a "still needs setup" flag to the inferior structure.  This is
similar to gdbserver/linux-low.c's handling of discovering the
process's target description).  Then if on connection all threads of
the remote inferior are running, when we go about stopping them, as
soon as they stop we call setup_inferior, from within
stop_all_threads.

Also, in all-stop, we need to process all the initial stop replies to
learn about all the pending signal the threads may already be stopped
for, and pick the one to report as current.  This is exposed by
gdb.threads/reconnect-signal.exp.

gdb/
2015-11-30  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (switch_to_thread_no_regs): Declare.
	* infcmd.c (setup_inferior): New function, factored out from ...
	(attach_command_post_wait): ... this.  Rename to ...
	(attach_post_wait): ... this.  Replace parameter async_exec with
	attach_post_wait_mode parameter.  Adjust.
	(enum attach_post_wait_mode): New enum.
	(struct attach_command_continuation_args): Replace 'async_exec'
	field with 'mode' field.
	(attach_command_continuation): Adjust.
	(attach_command): Add comment.  Mark the inferior as needing
	setup.  Adjust to use enum attach_post_wait_mode.
	(notice_new_inferior): Use switch_to_thread_no_regs.  Adjust to
	use enum attach_post_wait_mode.
	* inferior.h (setup_inferior): Declare.
	(struct inferior) <needs_setup>: New field.
	* infrun.c (set_last_target_status): Make extern.
	(stop_all_threads): Make extern.  Setup inferior, if necessary.
	* infrun.h (set_last_target_status, stop_all_threads): Declare.
	* remote-notif.c (remote_async_get_pending_events_handler)
	(handle_notification): Replace non_stop checks with
	target_is_non_stop_p() checks.
	* remote.c (remote_notice_new_inferior): Remove non_stop check.
	(remote_update_thread_list): Replace non_stop check with
	target_is_non_stop_p() check.
	(print_one_stopped_thread): New function.
	(process_initial_stop_replies): New 'from_tty' parameter.
	"Notice" all new live inferiors after storing initial stops as
	pending status in each corresponding thread.  If all-stop, stop
	all threads, try picking a signalled thread as current, and print
	the status of that one thread.  Record the last target status.
	(remote_start_remote): Replace non_stop checks with
	target_is_non_stop_p() checks.  Don't query for the remote current
	thread of use qOffsets here.  Pass from_tty to
	process_initial_stop_replies.
	(extended_remote_attach): Replace non_stop checks with
	target_is_non_stop_p() checks.
	(extended_remote_post_attach): Send qOffsets here.
	(remote_vcont_resume, remote_resume, remote_stop)
	(remote_interrupt, remote_parse_stop_reply, remote_wait): Replace
	non_stop checks with target_is_non_stop_p() checks.
	(remote_async): If target is non-stop, mark/clear the pending
	events token.
	* thread.c (switch_to_thread_no_regs): New function.
2015-11-30 18:36:37 +00:00
Simon Marchi e19616610d remote.c: Add missing cast
Fixes in C++:

/home/emaisin/src/binutils-gdb/gdb/remote.c: In function ‘void start_thread(gdb_xml_parser*, const gdb_xml_element*, void*, VEC_gdb_xml_value_s*)’:
/home/emaisin/src/binutils-gdb/gdb/remote.c:2975:59: error: invalid conversion from ‘void*’ to ‘const char*’ [-fpermissive]
   item.name = attr != NULL ? (char *) xstrdup (attr->value) : NULL;
                                                           ^
In file included from /home/emaisin/src/binutils-gdb/gdb/common/common-defs.h:64:0,
                 from /home/emaisin/src/binutils-gdb/gdb/defs.h:28,
                 from /home/emaisin/src/binutils-gdb/gdb/remote.c:22:
/home/emaisin/src/binutils-gdb/gdb/../include/libiberty.h:323:14: error:   initializing argument 1 of ‘char* xstrdup(const char*)’ [-fpermissive]
 extern char *xstrdup (const char *) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
              ^
make[2]: *** [remote.o] Error 1

gdb/ChangeLog:

	* remote.c (start_thread): Add cast.
2015-11-27 10:14:42 -05:00
Simon Marchi 79efa585c5 Display names of remote threads
This patch adds support for thread names in the remote protocol, and
updates gdb/gdbserver to use it.  The information is added to the XML
description sent in response to the qXfer:threads:read packet.

gdb/ChangeLog:

	* linux-nat.c (linux_nat_thread_name): Replace implementation by call
	to linux_proc_tid_get_name.
	* nat/linux-procfs.c (linux_proc_tid_get_name): New function,
	implementation inspired by linux_nat_thread_name.
	* nat/linux-procfs.h (linux_proc_tid_get_name): New declaration.
	* remote.c (struct private_thread_info) <name>: New field.
	(free_private_thread_info): Free name field.
	(remote_thread_name): New function.
	(thread_item_t) <name>: New field.
	(clear_threads_listing_context): Free name field.
	(start_thread): Get name xml attribute.
	(thread_attributes): Add "name" attribute.
	(remote_update_thread_list): Copy name field.
	(init_remote_ops): Assign remote_thread_name callback.
	* target.h (target_thread_name): Update comment.
	* NEWS: Mention remote thread name support.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_target_ops): Use linux_proc_tid_get_name.
	* server.c (handle_qxfer_threads_worker): Refactor to include thread
	name in reply.
	* target.h (struct target_ops) <thread_name>: New field.
	(target_thread_name): New macro.

gdb/doc/ChangeLog:

	* gdb.texinfo (Thread List Format): Mention thread names.
2015-11-26 10:50:08 -05:00
Pedro Alves b35d5edb03 gdb: Workaround bad gdbserver qSupported:xmlRegisters=i386;UnknwnFeat+ handling
gdbserver's target_process_qsupported is called for each feature that
the gdbserver common code does not recognize.  The only current
implementation, for x86 Linux, does this:

  static void
  x86_linux_process_qsupported (const char *query)
  {
    /* Return if gdb doesn't support XML.  If gdb sends "xmlRegisters="
       with "i386" in qSupported query, it supports x86 XML target
       descriptions.  */
    use_xml = 0;
    if (query != NULL && startswith (query, "xmlRegisters="))
      {
	char *copy = xstrdup (query + 13);
	char *p;

	for (p = strtok (copy, ","); p != NULL; p = strtok (NULL, ","))
	  {
	    if (strcmp (p, "i386") == 0)
	      {
		use_xml = 1;
		break;
	      }
	  }

	free (copy);
      }

    x86_linux_update_xmltarget ();
  }

Notice that this clears use_xml and calls x86_linux_update_xmltarget
each time target_process_qsupported is called.  So if gdb sends in any
unknown feature after "xmlRegisters=i386", like e.g.,
"xmlRegisters=i386;UnknownFeature+" gdbserver ends up not reporting a
XML description...

Work around this by having GDB send the "xmlRegisters=" feature last.

gdb/ChangeLog:
2015-11-19  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_query_supported): Send the "xmlRegisters="
	feature last.
2015-11-19 18:31:49 +00:00
Pedro Alves 915ef8b18e [C++] remote.c: Avoid enum arithmetic
Fixes:

  src/gdb/remote.c: In function ‘void remote_unpush_target()’:
  src/gdb/remote.c:4610:45: error: invalid conversion from ‘int’ to ‘strata’ [-fpermissive]
     pop_all_targets_above (process_stratum - 1);
					       ^
  In file included from src/gdb/inferior.h:38:0,
		   from src/gdb/remote.c:25:
  src/gdb/target.h:2299:13: error:   initializing argument 1 of ‘void pop_all_targets_above(strata)’ [-fpermissive]
   extern void pop_all_targets_above (enum strata above_stratum);
	       ^

I used to carry a patch in the C++ branch that just did:

 -  pop_all_targets_above (process_stratum - 1);
 +  pop_all_targets_above ((enum strata) (process_stratum - 1));

But then thought that maybe adding a routine that does exactly what we
need results in clearer code.  This is the result.

gdb/ChangeLog:
2015-11-19  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_unpush_target): Use
	pop_all_targets_at_and_above instead of pop_all_targets_above.
	* target.c (unpush_target_and_assert): New function, factored out
	from ...
	(pop_all_targets_above): ... here.
	(pop_all_targets_at_and_above): New function.
	* target.h (pop_all_targets_at_and_above): Declare.
2015-11-19 14:32:53 +00:00
Luis Machado 29090fb629 Make GDB wait for events after handling target File-I/O
_ftext () at arm-vector.S:25
25              ldr pc, [pc, #24] @ reset
(gdb) load
Loading section .text, size 0xc01c lma 0x0
Loading section .eh_frame, size 0x48 lma 0xc01c
Loading section .ARM.exidx, size 0x8 lma 0xc064
Loading section .rodata, size 0x398 lma 0xc070
Loading section .data, size 0x8e0 lma 0xc408
Start address 0x40, load size 52452
Transfer rate: 17074 KB/sec, 1748 bytes/write.
(gdb) c
Continuing.
infrun: clear_proceed_status_thread (Thread 1)
infrun: proceed (addr=0xffffffff, signal=GDB_SIGNAL_DEFAULT)
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 1] at 0x40
Sending packet: $vCont?#49...Ack
Packet received:
Packet vCont (verbose-resume) is NOT supported
Sending packet: $Hc0#db...Ack
Packet received: OK
Sending packet: $c#63...Ack
infrun: infrun_async(1)
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [Thread 0],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
Packet received: Ffstat,00000001,07fffdb0
Sending packet: $M7fffdb0,40:000000000000000000002080000000010000c336000001180000000000000000000000000000000000000200000000000000000055dfb11b55dfb11b55dfb11b#5a...Ack
Packet received: OK
Sending packet: $F0#76...Ack
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [Thread 0],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [Thread 0],
infrun:   status->kind = no-resumed
infrun: TARGET_WAITKIND_NO_RESUMED
infrun: stop_waiting
infrun: clear_step_over_info
Sending packet: $qfThreadInfo#bb...Ack
Packet received: m1
Sending packet: $qsThreadInfo#c8...Ack
Packet received: l
No unwaited-for children left.
infrun: infrun_async(0)
(gdb) c
Continuing.
Cannot execute this command while the selected thread is running.
(gdb)
Continuing.
Cannot execute this command while the selected thread is running.

This behavior shows up whenever GDB is in all-stop mode and is handling
target-initiated File-I/O requests, in the middle of, say, a continue
request.

When GDB is done handling the File-I/O request, it doesn't set
rs->waiting_for_stop_reply back to 1, meaning GDB should wait for
further target events.

This seems to be a latent bug, because in the past this didn't really
cause any issues. But it seems to have been uncovered by commit
567420d108, which explicitly checks
for rs->waiting_for_stop_reply == 0, triggering the failures above.

The following patch fixes this by reorganizing the setting of
rs->waiting_for_stop_reply.

infrun: prepare_to_wait
Packet received: Ffstat,00000001,07fffdb0
Sending packet: $M7fffdb0,40:000000000000000000002080000000010000c336000001180000000000000000000000000000000000000200000000000000000055dfb19e55dfb19e55dfb19e#7b...Ack
Packet received: OK
Sending packet: $F0#76...Ack
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [Thread 0],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
Packet received: Fisatty,00000001
Sending packet: $F1#77...Ack
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [Thread 0],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
Packet received: Fwrite,00000001,0000d098,00000004
Sending packet: $md098,4#d2...Ack
Packet received: 3732300a
720
Sending packet: $F4#7a...Ack
infrun: target_wait (-1.0.0, status) =
infrun:   -1.0.0 [Thread 0],
infrun:   status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
Packet received: Fwrite,00000001,07ffffac,00000011
Sending packet: $m7ffffac,11#8e...Ack
Packet received: 0a2a2a2a204558495420636f646520300a

*** EXIT code 0

Regression-tested on Ubuntu x86-64 and qemu-system-based debugging
for arm eabi.

gdb/ChangeLog:

2015-10-16  Luis Machado  <lgustavo@codesourcery.com>

	* remote.c (remote_wait_as): Set rs->waiting_for_stop_reply to 0
	when handling 'E', 'T', 'S', 'X' and 'W' packets.
	Do not set rs->waiting_for_stop_reply back to 1.
2015-10-19 11:36:01 -02:00
Don Breazeal 6ab24463cb Call strprefix instead of strncmp in event parsing
This fixes a typo that used strncmp instead of strprefix when
checking for an exec event in a stop reply packet.

gdb/ChangeLog:

	* remote.c (remote_parse_stop_reply): Call strprefix instead
	of strncmp.
2015-09-30 10:14:45 -07:00
Simon Marchi 19ba03f495 Add some more casts (2/2)
See previous patch's description.

gdb/ChangeLog:

	* macrocmd.c (print_macro_callback): Add cast(s).
	* macrotab.c (macro_bcache_str): Likewise.
	(new_macro_definition): Likewise.
	* main.c (captured_main): Likewise.
	* maint.c (print_bfd_section_info): Likewise.
	* mdebugread.c (mdebug_build_psymtabs): Likewise.
	(basic_type): Likewise.
	* memattr.c (mem_region_cmp): Likewise.
	* memory-map.c (memory_map_start_memory): Likewise.
	(memory_map_end_memory): Likewise.
	(memory_map_start_property): Likewise.
	(memory_map_end_property): Likewise.
	(clear_result): Likewise.
	* memrange.c (compare_mem_ranges): Likewise.
	* mep-tdep.c (mep_analyze_frame_prologue): Likewise.
	* mi/mi-cmd-var.c (mi_cmd_var_update_iter): Likewise.
	* mi/mi-console.c (mi_console_file_delete): Likewise.
	(mi_console_file_fputs): Likewise.
	(mi_console_raw_packet): Likewise.
	(mi_console_file_flush): Likewise.
	(mi_console_set_raw): Likewise.
	* mi/mi-interp.c (mi_interpreter_resume): Likewise.
	(mi_new_thread): Likewise.
	(mi_thread_exit): Likewise.
	(mi_record_changed): Likewise.
	(mi_inferior_added): Likewise.
	(mi_inferior_appeared): Likewise.
	(mi_inferior_exit): Likewise.
	(mi_inferior_removed): Likewise.
	(mi_interp_data): Likewise.
	(mi_on_normal_stop): Likewise.
	(mi_traceframe_changed): Likewise.
	(mi_tsv_created): Likewise.
	(mi_tsv_deleted): Likewise.
	(mi_tsv_modified): Likewise.
	(mi_breakpoint_created): Likewise.
	(mi_breakpoint_deleted): Likewise.
	(mi_breakpoint_modified): Likewise.
	(mi_output_running_pid): Likewise.
	(mi_inferior_count): Likewise.
	(mi_solib_loaded): Likewise.
	(mi_solib_unloaded): Likewise.
	(mi_command_param_changed): Likewise.
	(mi_memory_changed): Likewise.
	(report_initial_inferior): Likewise.
	(mi_ui_out): Likewise.
	(mi_set_logging): Likewise.
	* mi/mi-main.c (collect_cores): Likewise.
	(print_one_inferior): Likewise.
	(free_vector_of_ints): Likewise.
	(free_splay_tree): Likewise.
	(mi_execute_command): Likewise.
	* mi/mi-out.c (mi_table_body): Likewise.
	(mi_table_end): Likewise.
	(mi_table_header): Likewise.
	(mi_begin): Likewise.
	(mi_end): Likewise.
	(mi_field_int): Likewise.
	(mi_field_string): Likewise.
	(mi_field_fmt): Likewise.
	(mi_flush): Likewise.
	(mi_redirect): Likewise.
	(field_separator): Likewise.
	(mi_open): Likewise.
	(mi_close): Likewise.
	(mi_out_buffered): Likewise.
	(mi_out_rewind): Likewise.
	(mi_out_put): Likewise.
	(mi_version): Likewise.
	(mi_out_data_dtor): Likewise.
	* mi/mi-parse.c (mi_parse_cleanup): Likewise.
	* microblaze-tdep.c (microblaze_frame_cache): Likewise.
	* minidebug.c (lzma_open): Likewise.
	(lzma_pread): Likewise.
	(lzma_close): Likewise.
	(lzma_stat): Likewise.
	* mips-linux-tdep.c (mips_linux_init_abi): Likewise.
	* mips-sde-tdep.c (mips_sde_frame_cache): Likewise.
	(mips_sde_elf_osabi_sniff_abi_tag_sections): Likewise.
	* mips-tdep.c (mips_insn16_frame_cache): Likewise.
	(mips_micro_frame_cache): Likewise.
	(mips_insn32_frame_cache): Likewise.
	(mips_stub_frame_cache): Likewise.
	(gdb_print_insn_mips): Likewise.
	(value_of_mips_user_reg): Likewise.
	(mips_gdbarch_init): Likewise.
	* mips64obsd-tdep.c (mips64obsd_supply_gregset): Likewise.
	* mipsnbsd-tdep.c (mipsnbsd_supply_fpregset): Likewise.
	(mipsnbsd_supply_gregset): Likewise.
	* mn10300-linux-tdep.c (am33_supply_fpregset_method): Likewise.
	(am33_collect_gregset_method): Likewise.
	(am33_collect_fpregset_method): Likewise.
	* mn10300-tdep.c (mn10300_analyze_frame_prologue): Likewise.
	* moxie-tdep.c (moxie_frame_cache): Likewise.
	* msp430-tdep.c (msp430_get_opcode_byte): Likewise.
	(msp430_analyze_frame_prologue): Likewise.
	* mt-tdep.c (mt_frame_unwind_cache): Likewise.
	* nios2-linux-tdep.c (nios2_supply_gregset): Likewise.
	(nios2_collect_gregset): Likewise.
	* nios2-tdep.c (nios2_frame_unwind_cache): Likewise.
	(nios2_stub_frame_cache): Likewise.
	* objc-lang.c (find_methods): Likewise.
	* objfiles.c (objfiles_pspace_data_cleanup): Likewise.
	(get_objfile_pspace_data): Likewise.
	(get_objfile_bfd_data): Likewise.
	(objfile_bfd_data_free): Likewise.
	(add_to_objfile_sections): Likewise.
	(do_free_objfile_cleanup): Likewise.
	(resume_section_map_updates_cleanup): Likewise.
	* opencl-lang.c (builtin_opencl_type): Likewise.
	* osabi.c (generic_elf_osabi_sniff_abi_tag_sections): Likewise.
	* osdata.c (osdata_start_osdata): Likewise.
	(osdata_start_item): Likewise.
	(osdata_start_column): Likewise.
	(osdata_end_column): Likewise.
	(clear_parsing_data): Likewise.
	(osdata_free_cleanup): Likewise.
	* parse.c (type_stack_cleanup): Likewise.
	(exp_uses_objfile_iter): Likewise.
	* ppc-linux-tdep.c (ppc_linux_supply_gregset): Likewise.
	(ppc_linux_collect_gregset): Likewise.
	(ppu2spu_prev_arch): Likewise.
	(ppu2spu_this_id): Likewise.
	(ppu2spu_prev_register): Likewise.
	(ppu2spu_unwind_register): Likewise.
	(ppu2spu_sniffer): Likewise.
	(ppu2spu_dealloc_cache): Likewise.
	(ppc_linux_init_abi): Likewise.
	* ppcfbsd-tdep.c (ppcfbsd_sigtramp_frame_cache): Likewise.
	* ppcobsd-tdep.c (ppcobsd_sigtramp_frame_cache): Likewise.
	* progspace.c (restore_program_space): Likewise.
	* psymtab.c (find_pc_sect_psymtab): Likewise.
	(compare_psymbols): Likewise.
	(psymbol_bcache_full): Likewise.
	(allocate_psymtab): Likewise.
	(discard_psymtabs_upto): Likewise.
	* python/py-block.c (set_block): Likewise.
	(del_objfile_blocks): Likewise.
	* python/py-breakpoint.c (build_bp_list): Likewise.
	* python/py-inferior.c (inferior_to_inferior_object): Likewise.
	(build_inferior_list): Likewise.
	(py_free_inferior): Likewise.
	* python/py-objfile.c (py_free_objfile): Likewise.
	(objfile_to_objfile_object): Likewise.
	* python/py-prettyprint.c (py_restore_tstate): Likewise.
	* python/py-progspace.c (py_free_pspace): Likewise.
	(pspace_to_pspace_object): Likewise.
	* python/py-symbol.c (set_symbol): Likewise.
	(del_objfile_symbols): Likewise.
	* python/py-symtab.c (set_sal): Likewise.
	(set_symtab): Likewise.
	(del_objfile_symtab): Likewise.
	(del_objfile_sal): Likewise.
	* python/py-type.c (save_objfile_types): Likewise.
	(set_type): Likewise.
	* python/py-unwind.c (pyuw_prev_register): Likewise.
	(pyuw_on_new_gdbarch): Likewise.
	* python/py-utils.c (py_decref): Likewise.
	(py_xdecref): Likewise.
	(gdb_py_generic_dict): Likewise.
	* python/py-xmethods.c (gdbpy_free_xmethod_worker_data): Likewise.
	(gdbpy_clone_xmethod_worker_data): Likewise.
	(gdbpy_get_xmethod_arg_types): Likewise.
	(gdbpy_get_xmethod_result_type): Likewise.
	(gdbpy_invoke_xmethod): Likewise.
	* python/python.c (gdbpy_apply_type_printers): Likewise.
	(gdbpy_free_type_printers): Likewise.
	* record-btrace.c (record_btrace_disable_callback): Likewise.
	(bfcache_hash): Likewise.
	(bfcache_eq): Likewise.
	(btrace_get_frame_function): Likewise.
	(record_btrace_frame_unwind_stop_reason): Likewise.
	(record_btrace_frame_this_id): Likewise.
	(record_btrace_frame_prev_register): Likewise.
	(record_btrace_frame_dealloc_cache): Likewise.
	* record-full.c (record_full_message_wrapper): Likewise.
	(record_full_save_cleanups): Likewise.
	* regcache.c (regcache_descr): Likewise.
	(do_regcache_xfree): Likewise.
	(do_regcache_invalidate): Likewise.
	(do_cooked_read): Likewise.
	(regcache_transfer_regset): Likewise.
	* reggroups.c (reggroup_add): Likewise.
	(reggroup_next): Likewise.
	(reggroup_prev): Likewise.
	* remote-fileio.c (do_remote_fileio_request): Likewise.
	* remote-notif.c (remote_async_get_pending_events_handler): Likewise.
	(do_notif_event_xfree): Likewise.
	* remote.c (get_remote_arch_state): Likewise.
	(remote_pspace_data_cleanup): Likewise.
	(get_remote_exec_file): Likewise.
	(set_pspace_remote_exec_file): Likewise.
	(compare_pnums): Likewise.
	(clear_threads_listing_context): Likewise.
	(remote_newthread_step): Likewise.
	(start_thread): Likewise.
	(end_thread): Likewise.
	(remove_child_of_pending_fork): Likewise.
	(remove_stop_reply_for_inferior): Likewise.
	(remove_stop_reply_of_remote_state): Likewise.
	(remote_notif_remove_once_on_match): Likewise.
	(stop_reply_match_ptid_and_ws): Likewise.
	(kill_child_of_pending_fork): Likewise.
	(register_remote_g_packet_guess): Likewise.
	(remote_read_description_p): Likewise.
	(remote_read_description): Likewise.
	(free_actions_list_cleanup_wrapper): Likewise.
	(remote_async_serial_handler): Likewise.
	* rl78-tdep.c (rl78_get_opcode_byte): Likewise.
	(rl78_analyze_frame_prologue): Likewise.
	* rs6000-tdep.c (ppc_supply_gregset): Likewise.
	(ppc_supply_fpregset): Likewise.
	(ppc_supply_vsxregset): Likewise.
	(ppc_supply_vrregset): Likewise.
	(ppc_collect_gregset): Likewise.
	(ppc_collect_fpregset): Likewise.
	(ppc_collect_vsxregset): Likewise.
	(ppc_collect_vrregset): Likewise.
	(e500_move_ev_register): Likewise.
	(do_regcache_raw_write): Likewise.
	(rs6000_frame_cache): Likewise.
	(rs6000_epilogue_frame_cache): Likewise.
	(rs6000_gdbarch_init): Likewise.
	* rx-tdep.c (rx_get_opcode_byte): Likewise.
	(rx_analyze_frame_prologue): Likewise.
	(rx_frame_type): Likewise.
	(rx_frame_sniffer_common): Likewise.
	* s390-linux-tdep.c (s390_check_for_saved): Likewise.
	(s390_frame_unwind_cache): Likewise.
	(s390_stub_frame_unwind_cache): Likewise.
	(s390_sigtramp_frame_unwind_cache): Likewise.
	* score-tdep.c (score_make_prologue_cache): Likewise.
	* sentinel-frame.c (sentinel_frame_prev_register): Likewise.
	(sentinel_frame_prev_arch): Likewise.
	* ser-base.c (fd_event): Likewise.
	(push_event): Likewise.
	(ser_base_write): Likewise.
	* ser-pipe.c (pipe_close): Likewise.
	* serial.c (serial_write): Likewise.
	* sh-tdep.c (sh_frame_cache): Likewise.
	(sh_stub_this_id): Likewise.
	* sh64-tdep.c (sh64_frame_cache): Likewise.
	* solib-aix.c (get_solib_aix_inferior_data): Likewise.
	(library_list_start_library): Likewise.
	(library_list_start_list): Likewise.
	(solib_aix_free_library_list): Likewise.
	* solib-darwin.c (get_darwin_info): Likewise.
	* solib-dsbt.c (get_dsbt_info): Likewise.
	* solib-spu.c (append_ocl_sos): Likewise.
	* solib-svr4.c (svr4_pspace_data_cleanup): Likewise.
	(get_svr4_info): Likewise.
	(library_list_start_library): Likewise.
	(svr4_library_list_start_list): Likewise.
	(hash_probe_and_action): Likewise.
	(equal_probe_and_action): Likewise.
	(svr4_update_solib_event_breakpoint): Likewise.
	(set_solib_svr4_fetch_link_map_offsets): Likewise.
	(svr4_fetch_link_map_offsets): Likewise.
	(svr4_have_link_map_offsets): Likewise.
	* solib-target.c (library_list_start_segment): Likewise.
	(library_list_start_section): Likewise.
	(library_list_start_library): Likewise.
	(library_list_end_library): Likewise.
	(library_list_start_list): Likewise.
	(solib_target_free_library_list): Likewise.
	* solib.c (solib_ops): Likewise.
	(set_solib_ops): Likewise.
	* sparc-sol2-tdep.c (sparc32_sol2_sigtramp_frame_cache): Likewise.
	* sparc-tdep.c (sparc_frame_cache): Likewise.
	(sparc32_frame_cache): Likewise.
	(sparc32_supply_gregset): Likewise.
	(sparc32_collect_gregset): Likewise.
	(sparc32_supply_fpregset): Likewise.
	(sparc32_collect_fpregset): Likewise.
	* sparc64-sol2-tdep.c (sparc64_sol2_sigtramp_frame_cache): Likewise.
	* sparc64-tdep.c (sparc64_supply_gregset): Likewise.
	(sparc64_collect_gregset): Likewise.
	(sparc64_supply_fpregset): Likewise.
	(sparc64_collect_fpregset): Likewise.
	* sparc64fbsd-tdep.c (sparc64fbsd_sigtramp_frame_cache): Likewise.
	* sparc64nbsd-tdep.c (sparc64nbsd_sigcontext_frame_cache): Likewise.
	* sparc64obsd-tdep.c (sparc64obsd_frame_cache): Likewise.
	(sparc64obsd_trapframe_cache): Likewise.
	* sparcnbsd-tdep.c (sparc32nbsd_sigcontext_frame_cache): Likewise.
	* sparcobsd-tdep.c (sparc32obsd_sigtramp_frame_cache): Likewise.
	* spu-multiarch.c (spu_gdbarch): Likewise.
	* spu-tdep.c (spu_frame_unwind_cache): Likewise.
	(spu2ppu_prev_arch): Likewise.
	(spu2ppu_this_id): Likewise.
	(spu2ppu_prev_register): Likewise.
	(spu2ppu_dealloc_cache): Likewise.
	(spu_dis_asm_print_address): Likewise.
	(gdb_print_insn_spu): Likewise.
	(spu_get_overlay_table): Likewise.
	* stabsread.c (rs6000_builtin_type): Likewise.
	* stack.c (do_print_variable_and_value): Likewise.
	* stap-probe.c (get_stap_base_address_1): Likewise.
	* symfile-debug.c (debug_qf_has_symbols): Likewise.
	(debug_qf_find_last_source_symtab): Likewise.
	(debug_qf_forget_cached_source_info): Likewise.
	(debug_qf_map_symtabs_matching_filename): Likewise.
	(debug_qf_lookup_symbol): Likewise.
	(debug_qf_print_stats): Likewise.
	(debug_qf_dump): Likewise.
	(debug_qf_relocate): Likewise.
	(debug_qf_expand_symtabs_for_function): Likewise.
	(debug_qf_expand_all_symtabs): Likewise.
	(debug_qf_expand_symtabs_with_fullname): Likewise.
	(debug_qf_map_matching_symbols): Likewise.
	(debug_qf_expand_symtabs_matching): Likewise.
	(debug_qf_find_pc_sect_compunit_symtab): Likewise.
	(debug_qf_map_symbol_filenames): Likewise.
	(debug_sym_get_probes): Likewise.
	(debug_sym_new_init): Likewise.
	(debug_sym_init): Likewise.
	(debug_sym_read): Likewise.
	(debug_sym_read_psymbols): Likewise.
	(debug_sym_finish): Likewise.
	(debug_sym_offsets): Likewise.
	(debug_sym_read_linetable): Likewise.
	(debug_sym_relocate): Likewise.
	(uninstall_symfile_debug_logging): Likewise.
	* symfile-mem.c (symbol_file_add_from_memory_wrapper): Likewise.
	* symfile.c (place_section): Likewise.
	(add_section_size_callback): Likewise.
	(load_progress): Likewise.
	(load_section_callback): Likewise.
	(clear_memory_write_data): Likewise.
	(allocate_symtab): Likewise.
	* symmisc.c (maintenance_expand_file_matcher): Likewise.
	* symtab.c (lookup_symtab_callback): Likewise.
	(hash_demangled_name_entry): Likewise.
	(eq_demangled_name_entry): Likewise.
	(get_symbol_cache): Likewise.
	(symbol_cache_cleanup): Likewise.
	(set_symbol_cache_size): Likewise.
	(symbol_cache_flush): Likewise.
	(maintenance_print_symbol_cache): Likewise.
	(maintenance_print_symbol_cache_statistics): Likewise.
	(delete_filename_seen_cache): Likewise.
	(output_partial_symbol_filename): Likewise.
	(search_symbols_file_matches): Likewise.
	(search_symbols_name_matches): Likewise.
	(do_free_completion_list): Likewise.
	(maybe_add_partial_symtab_filename): Likewise.
	(get_main_info): Likewise.
	(main_info_cleanup): Likewise.
	* target-dcache.c (target_dcache_cleanup): Likewise.
	(target_dcache_init_p): Likewise.
	(target_dcache_invalidate): Likewise.
	(target_dcache_get): Likewise.
	(target_dcache_get_or_init): Likewise.
	* target-descriptions.c (target_find_description): Likewise.
	(tdesc_find_type): Likewise.
	(tdesc_data_cleanup): Likewise.
	(tdesc_find_arch_register): Likewise.
	(tdesc_register_name): Likewise.
	(tdesc_register_type): Likewise.
	(tdesc_register_reggroup_p): Likewise.
	(set_tdesc_pseudo_register_name): Likewise.
	(set_tdesc_pseudo_register_type): Likewise.
	(set_tdesc_pseudo_register_reggroup_p): Likewise.
	(tdesc_use_registers): Likewise.
	(free_target_description): Likewise.
	* target-memory.c (compare_block_starting_address): Likewise.
	(cleanup_request_data): Likewise.
	(cleanup_write_requests_vector): Likewise.
	* target.c (open_target): Likewise.
	(cleanup_restore_target_terminal): Likewise.
	(free_memory_read_result_vector): Likewise.
	* thread.c (disable_thread_stack_temporaries): Likewise.
	(finish_thread_state_cleanup): Likewise.
	(do_restore_current_thread_cleanup): Likewise.
	(restore_current_thread_cleanup_dtor): Likewise.
	(set_thread_refcount): Likewise.
	(tp_array_compar): Likewise.
	(do_captured_thread_select): Likewise.
	* tic6x-tdep.c (tic6x_frame_unwind_cache): Likewise.
	(tic6x_stub_this_id): Likewise.
	* tilegx-tdep.c (tilegx_frame_cache): Likewise.
	* top.c (do_restore_instream_cleanup): Likewise.
	(gdb_readline_wrapper_cleanup): Likewise.
	(kill_or_detach): Likewise.
	(print_inferior_quit_action): Likewise.
	* tracefile-tfile.c (match_blocktype): Likewise.
	(build_traceframe_info): Likewise.
	* tracefile.c (trace_file_writer_xfree): Likewise.
	* tracepoint.c (memrange_cmp): Likewise.
	(do_collect_symbol): Likewise.
	(do_clear_collection_list): Likewise.
	(do_restore_current_traceframe_cleanup): Likewise.
	(restore_current_traceframe_cleanup_dtor): Likewise.
	(free_current_marker): Likewise.
	(traceframe_info_start_memory): Likewise.
	(traceframe_info_start_tvar): Likewise.
	(free_result): Likewise.
	* tramp-frame.c (tramp_frame_cache): Likewise.
	* tui/tui-file.c (tui_file_delete): Likewise.
	(tui_fileopen): Likewise.
	(tui_sfileopen): Likewise.
	(tui_file_isatty): Likewise.
	(tui_file_rewind): Likewise.
	(tui_file_put): Likewise.
	(tui_file_fputs): Likewise.
	(tui_file_get_strbuf): Likewise.
	(tui_file_adjust_strbuf): Likewise.
	(tui_file_flush): Likewise.
	* tui/tui-layout.c (make_command_window): Likewise.
	(make_data_window): Likewise.
	(show_source_disasm_command): Likewise.
	(show_data): Likewise.
	(make_source_or_disasm_window): Likewise.
	(show_source_or_disasm_and_command): Likewise.
	* tui/tui-out.c (tui_field_int): Likewise.
	(tui_field_string): Likewise.
	(tui_field_fmt): Likewise.
	(tui_text): Likewise.
	* typeprint.c (hash_typedef_field): Likewise.
	(eq_typedef_field): Likewise.
	(do_free_typedef_hash): Likewise.
	(copy_typedef_hash_element): Likewise.
	(do_free_global_table): Likewise.
	(find_global_typedef): Likewise.
	(find_typedef_in_hash): Likewise.
	* ui-file.c (ui_file_write_for_put): Likewise.
	(do_ui_file_xstrdup): Likewise.
	(mem_file_delete): Likewise.
	(mem_file_rewind): Likewise.
	(mem_file_put): Likewise.
	(mem_file_write): Likewise.
	(stdio_file_delete): Likewise.
	(stdio_file_flush): Likewise.
	(stdio_file_read): Likewise.
	(stdio_file_write): Likewise.
	(stdio_file_write_async_safe): Likewise.
	(stdio_file_fputs): Likewise.
	(stdio_file_isatty): Likewise.
	(stdio_file_fseek): Likewise.
	(tee_file_delete): Likewise.
	(tee_file_flush): Likewise.
	(tee_file_write): Likewise.
	(tee_file_fputs): Likewise.
	(tee_file_isatty): Likewise.
	* ui-out.c (do_cleanup_table_end): Likewise.
	(do_cleanup_end): Likewise.
	* user-regs.c (user_reg_add): Likewise.
	(user_reg_map_name_to_regnum): Likewise.
	(usernum_to_user_reg): Likewise.
	(maintenance_print_user_registers): Likewise.
	* utils.c (do_bfd_close_cleanup): Likewise.
	(do_fclose_cleanup): Likewise.
	(do_obstack_free): Likewise.
	(do_ui_file_delete): Likewise.
	(do_ui_out_redirect_pop): Likewise.
	(do_free_section_addr_info): Likewise.
	(restore_integer): Likewise.
	(do_unpush_target): Likewise.
	(do_htab_delete_cleanup): Likewise.
	(do_restore_ui_file): Likewise.
	(do_value_free): Likewise.
	(do_free_so): Likewise.
	(free_current_contents): Likewise.
	(do_regfree_cleanup): Likewise.
	(core_addr_hash): Likewise.
	(core_addr_eq): Likewise.
	(do_free_char_ptr_vec): Likewise.
	* v850-tdep.c (v850_frame_cache): Likewise.
	* varobj.c (do_free_variable_cleanup): Likewise.
	* vax-tdep.c (vax_supply_gregset): Likewise.
	(vax_frame_cache): Likewise.
	* vaxobsd-tdep.c (vaxobsd_sigtramp_frame_cache): Likewise.
	* xml-support.c (gdb_xml_body_text): Likewise.
	(gdb_xml_values_cleanup): Likewise.
	(gdb_xml_start_element): Likewise.
	(gdb_xml_start_element_wrapper): Likewise.
	(gdb_xml_end_element): Likewise.
	(gdb_xml_end_element_wrapper): Likewise.
	(gdb_xml_cleanup): Likewise.
	(gdb_xml_fetch_external_entity): Likewise.
	(gdb_xml_parse_attr_enum): Likewise.
	(xinclude_start_include): Likewise.
	(xinclude_end_include): Likewise.
	(xml_xinclude_default): Likewise.
	(xml_xinclude_start_doctype): Likewise.
	(xml_xinclude_end_doctype): Likewise.
	(xml_xinclude_cleanup): Likewise.
	(xml_fetch_content_from_file): Likewise.
	* xml-syscall.c (free_syscalls_info): Likewise.
	(syscall_start_syscall): Likewise.
	* xml-tdesc.c (tdesc_end_arch): Likewise.
	(tdesc_end_osabi): Likewise.
	(tdesc_end_compatible): Likewise.
	(tdesc_start_target): Likewise.
	(tdesc_start_feature): Likewise.
	(tdesc_start_reg): Likewise.
	(tdesc_start_union): Likewise.
	(tdesc_start_struct): Likewise.
	(tdesc_start_flags): Likewise.
	(tdesc_start_field): Likewise.
	(tdesc_start_vector): Likewise.
	(fetch_available_features_from_target): Likewise.
	* xstormy16-tdep.c (xstormy16_frame_cache): Likewise.
	* xtensa-tdep.c (xtensa_supply_gregset): Likewise.
	(xtensa_frame_cache): Likewise.
	(xtensa_frame_prev_register): Likewise.
	(xtensa_extract_return_value): Likewise.
2015-09-25 14:08:07 -04:00
Simon Marchi 224c3ddb89 Add casts to memory allocation related calls
Most allocation functions (if not all) return a void* pointing to the
allocated memory.  In C++, we need to add an explicit cast when
assigning the result to a pointer to another type (which is the case
more often than not).

The content of this patch is taken from Pedro's branch, from commit
"(mostly) auto-generated patch to insert casts needed for C++".  I
validated that the changes make sense and manually reflowed the code to
make it respect the coding style.  I also found multiple places where I
could use XNEW/XNEWVEC/XRESIZEVEC/etc.

Thanks a lot to whoever did that automated script to insert casts, doing
it completely by hand would have taken a ridiculous amount of time.

Only files built on x86 with --enable-targets=all are modified.  This
means that all other -nat.c files are untouched and will have to be
dealt with later by using appropiate compilers.  Or maybe we can try to
build them with a regular g++ just to know where to add casts, I don't
know.

I built-tested this with --enable-targets=all and reg-tested.

Here's the changelog entry, which was not too bad to make despite the
size, thanks to David Malcom's script.  I fixed some bits by hand, but
there might be some wrong parts left (hopefully not).

gdb/ChangeLog:

	* aarch64-linux-tdep.c (aarch64_stap_parse_special_token): Add cast
	to allocation result assignment.
	* ada-exp.y (write_object_renaming): Likewise.
	(write_ambiguous_var): Likewise.
	(ada_nget_field_index): Likewise.
	(write_var_or_type): Likewise.
	* ada-lang.c (ada_decode_symbol): Likewise.
	(ada_value_assign): Likewise.
	(value_pointer): Likewise.
	(cache_symbol): Likewise.
	(add_nonlocal_symbols): Likewise.
	(ada_name_for_lookup): Likewise.
	(symbol_completion_add): Likewise.
	(ada_to_fixed_type_1): Likewise.
	(ada_get_next_arg): Likewise.
	(defns_collected): Likewise.
	* ada-lex.l (processId): Likewise.
	(processString): Likewise.
	* ada-tasks.c (read_known_tasks_array): Likewise.
	(read_known_tasks_list): Likewise.
	* ada-typeprint.c (decoded_type_name): Likewise.
	* addrmap.c (addrmap_mutable_create_fixed): Likewise.
	* amd64-tdep.c (amd64_push_arguments): Likewise.
	(amd64_displaced_step_copy_insn): Likewise.
	(amd64_classify_insn_at): Likewise.
	(amd64_relocate_instruction): Likewise.
	* amd64obsd-tdep.c (amd64obsd_sigtramp_p): Likewise.
	* arch-utils.c (simple_displaced_step_copy_insn): Likewise.
	(initialize_current_architecture): Likewise.
	* arm-linux-tdep.c (arm_stap_parse_special_token): Likewise.
	* arm-symbian-tdep.c (arm_symbian_osabi_sniffer): Likewise.
	* arm-tdep.c (arm_exidx_new_objfile): Likewise.
	(arm_push_dummy_call): Likewise.
	(extend_buffer_earlier): Likewise.
	(arm_adjust_breakpoint_address): Likewise.
	(arm_skip_stub): Likewise.
	* auto-load.c (filename_is_in_pattern): Likewise.
	(maybe_add_script_file): Likewise.
	(maybe_add_script_text): Likewise.
	(auto_load_objfile_script_1): Likewise.
	* auxv.c (ld_so_xfer_auxv): Likewise.
	* ax-general.c (new_agent_expr): Likewise.
	(grow_expr): Likewise.
	(ax_reg_mask): Likewise.
	* bcache.c (bcache_full): Likewise.
	* breakpoint.c (program_breakpoint_here_p): Likewise.
	* btrace.c (parse_xml_raw): Likewise.
	* build-id.c (build_id_to_debug_bfd): Likewise.
	* buildsym.c (end_symtab_with_blockvector): Likewise.
	* c-exp.y (string_exp): Likewise.
	(qualified_name): Likewise.
	(write_destructor_name): Likewise.
	(operator_stoken): Likewise.
	(parse_number): Likewise.
	(scan_macro_expansion): Likewise.
	(yylex): Likewise.
	(c_print_token): Likewise.
	* c-lang.c (c_get_string): Likewise.
	(emit_numeric_character): Likewise.
	* charset.c (wchar_iterate): Likewise.
	* cli/cli-cmds.c (complete_command): Likewise.
	(make_command): Likewise.
	* cli/cli-dump.c (restore_section_callback): Likewise.
	(restore_binary_file): Likewise.
	* cli/cli-interp.c (cli_interpreter_exec): Likewise.
	* cli/cli-script.c (execute_control_command): Likewise.
	* cli/cli-setshow.c (do_set_command): Likewise.
	* coff-pe-read.c (add_pe_forwarded_sym): Likewise.
	(read_pe_exported_syms): Likewise.
	* coffread.c (coff_read_struct_type): Likewise.
	(coff_read_enum_type): Likewise.
	* common/btrace-common.c (btrace_data_append): Likewise.
	* common/buffer.c (buffer_grow): Likewise.
	* common/filestuff.c (gdb_fopen_cloexec): Likewise.
	* common/format.c (parse_format_string): Likewise.
	* common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): Likewise.
	* common/xml-utils.c (xml_escape_text): Likewise.
	* compile/compile-object-load.c (copy_sections): Likewise.
	(compile_object_load): Likewise.
	* compile/compile-object-run.c (compile_object_run): Likewise.
	* completer.c (filename_completer): Likewise.
	* corefile.c (read_memory_typed_address): Likewise.
	(write_memory_unsigned_integer): Likewise.
	(write_memory_signed_integer): Likewise.
	(complete_set_gnutarget): Likewise.
	* corelow.c (get_core_register_section): Likewise.
	* cp-name-parser.y (d_grab): Likewise.
	(allocate_info): Likewise.
	(cp_new_demangle_parse_info): Likewise.
	* cp-namespace.c (cp_scan_for_anonymous_namespaces): Likewise.
	(cp_lookup_symbol_in_namespace): Likewise.
	(lookup_namespace_scope): Likewise.
	(find_symbol_in_baseclass): Likewise.
	(cp_lookup_nested_symbol): Likewise.
	(cp_lookup_transparent_type_loop): Likewise.
	* cp-support.c (copy_string_to_obstack): Likewise.
	(make_symbol_overload_list): Likewise.
	(make_symbol_overload_list_namespace): Likewise.
	(make_symbol_overload_list_adl_namespace): Likewise.
	(first_component_command): Likewise.
	* cp-valprint.c (cp_print_value): Likewise.
	* ctf.c (ctf_xfer_partial): Likewise.
	* d-exp.y (StringExp): Likewise.
	* d-namespace.c (d_lookup_symbol_in_module): Likewise.
	(lookup_module_scope): Likewise.
	(find_symbol_in_baseclass): Likewise.
	(d_lookup_nested_symbol): Likewise.
	* dbxread.c (find_stab_function_addr): Likewise.
	(read_dbx_symtab): Likewise.
	(dbx_end_psymtab): Likewise.
	(cp_set_block_scope): Likewise.
	* dcache.c (dcache_alloc): Likewise.
	* demangle.c (_initialize_demangler): Likewise.
	* dicos-tdep.c (dicos_load_module_p): Likewise.
	* dictionary.c (dict_create_hashed_expandable): Likewise.
	(dict_create_linear_expandable): Likewise.
	(expand_hashtable): Likewise.
	(add_symbol_linear_expandable): Likewise.
	* dwarf2-frame.c (add_cie): Likewise.
	(add_fde): Likewise.
	(dwarf2_build_frame_info): Likewise.
	* dwarf2expr.c (dwarf_expr_grow_stack): Likewise.
	(dwarf_expr_fetch_address): Likewise.
	(add_piece): Likewise.
	(execute_stack_op): Likewise.
	* dwarf2loc.c (chain_candidate): Likewise.
	(dwarf_entry_parameter_to_value): Likewise.
	(read_pieced_value): Likewise.
	(write_pieced_value): Likewise.
	* dwarf2read.c (dwarf2_read_section): Likewise.
	(add_type_unit): Likewise.
	(read_comp_units_from_section): Likewise.
	(fixup_go_packaging): Likewise.
	(dwarf2_compute_name): Likewise.
	(dwarf2_physname): Likewise.
	(create_dwo_unit_in_dwp_v1): Likewise.
	(create_dwo_unit_in_dwp_v2): Likewise.
	(read_func_scope): Likewise.
	(read_call_site_scope): Likewise.
	(dwarf2_attach_fields_to_type): Likewise.
	(process_structure_scope): Likewise.
	(mark_common_block_symbol_computed): Likewise.
	(read_common_block): Likewise.
	(abbrev_table_read_table): Likewise.
	(guess_partial_die_structure_name): Likewise.
	(fixup_partial_die): Likewise.
	(add_file_name): Likewise.
	(dwarf2_const_value_data): Likewise.
	(dwarf2_const_value_attr): Likewise.
	(build_error_marker_type): Likewise.
	(guess_full_die_structure_name): Likewise.
	(anonymous_struct_prefix): Likewise.
	(typename_concat): Likewise.
	(dwarf2_canonicalize_name): Likewise.
	(dwarf2_name): Likewise.
	(write_constant_as_bytes): Likewise.
	(dwarf2_fetch_constant_bytes): Likewise.
	(copy_string): Likewise.
	(parse_macro_definition): Likewise.
	* elfread.c (elf_symfile_segments): Likewise.
	(elf_rel_plt_read): Likewise.
	(elf_gnu_ifunc_resolve_by_cache): Likewise.
	(elf_gnu_ifunc_resolve_by_got): Likewise.
	(elf_read_minimal_symbols): Likewise.
	(elf_gnu_ifunc_record_cache): Likewise.
	* event-top.c (top_level_prompt): Likewise.
	(command_line_handler): Likewise.
	* exec.c (resize_section_table): Likewise.
	* expprint.c (print_subexp_standard): Likewise.
	* fbsd-tdep.c (fbsd_collect_regset_section_cb): Likewise.
	* findcmd.c (parse_find_args): Likewise.
	* findvar.c (address_from_register): Likewise.
	* frame.c (get_prev_frame_always): Likewise.
	* gdb_bfd.c (gdb_bfd_ref): Likewise.
	(get_section_descriptor): Likewise.
	* gdb_obstack.c (obconcat): Likewise.
	(obstack_strdup): Likewise.
	* gdbtypes.c (lookup_function_type_with_arguments): Likewise.
	(create_set_type): Likewise.
	(lookup_unsigned_typename): Likewise.
	(lookup_signed_typename): Likewise.
	(resolve_dynamic_union): Likewise.
	(resolve_dynamic_struct): Likewise.
	(add_dyn_prop): Likewise.
	(copy_dynamic_prop_list): Likewise.
	(arch_flags_type): Likewise.
	(append_composite_type_field_raw): Likewise.
	* gdbtypes.h (INIT_FUNC_SPECIFIC): Likewise.
	* gnu-v3-abi.c (gnuv3_rtti_type): Likewise.
	* go-exp.y (string_exp): Likewise.
	* go-lang.c (go_demangle): Likewise.
	* guile/guile.c (compute_scheme_string): Likewise.
	* guile/scm-cmd.c (gdbscm_parse_command_name): Likewise.
	(gdbscm_canonicalize_command_name): Likewise.
	* guile/scm-ports.c (ioscm_init_stdio_buffers): Likewise.
	(ioscm_init_memory_port): Likewise.
	(ioscm_reinit_memory_port): Likewise.
	* guile/scm-utils.c (gdbscm_gc_xstrdup): Likewise.
	(gdbscm_gc_dup_argv): Likewise.
	* h8300-tdep.c (h8300_push_dummy_call): Likewise.
	* hppa-tdep.c (internalize_unwinds): Likewise.
	(read_unwind_info): Likewise.
	* i386-cygwin-tdep.c (core_process_module_section): Likewise.
	(windows_core_xfer_shared_libraries): Likewise.
	* i386-tdep.c (i386_displaced_step_copy_insn): Likewise.
	(i386_stap_parse_special_token_triplet): Likewise.
	(i386_stap_parse_special_token_three_arg_disp): Likewise.
	* i386obsd-tdep.c (i386obsd_sigtramp_p): Likewise.
	* inf-child.c (inf_child_fileio_readlink): Likewise.
	* inf-ptrace.c (inf_ptrace_fetch_register): Likewise.
	(inf_ptrace_store_register): Likewise.
	* infrun.c (follow_exec): Likewise.
	(displaced_step_prepare_throw): Likewise.
	(save_stop_context): Likewise.
	(save_infcall_suspend_state): Likewise.
	* jit.c (jit_read_descriptor): Likewise.
	(jit_read_code_entry): Likewise.
	(jit_symtab_line_mapping_add_impl): Likewise.
	(finalize_symtab): Likewise.
	(jit_unwind_reg_get_impl): Likewise.
	* jv-exp.y (QualifiedName): Likewise.
	* jv-lang.c (get_java_utf8_name): Likewise.
	(type_from_class): Likewise.
	(java_demangle_type_signature): Likewise.
	(java_class_name_from_physname): Likewise.
	* jv-typeprint.c (java_type_print_base): Likewise.
	* jv-valprint.c (java_value_print): Likewise.
	* language.c (add_language): Likewise.
	* linespec.c (add_sal_to_sals_basic): Likewise.
	(add_sal_to_sals): Likewise.
	(decode_objc): Likewise.
	(find_linespec_symbols): Likewise.
	* linux-fork.c (fork_save_infrun_state): Likewise.
	* linux-nat.c (linux_nat_detach): Likewise.
	(linux_nat_fileio_readlink): Likewise.
	* linux-record.c (record_linux_sockaddr): Likewise.
	(record_linux_msghdr): Likewise.
	(Do): Likewise.
	* linux-tdep.c (linux_core_info_proc_mappings): Likewise.
	(linux_collect_regset_section_cb): Likewise.
	(linux_get_siginfo_data): Likewise.
	* linux-thread-db.c (try_thread_db_load_from_pdir_1): Likewise.
	(try_thread_db_load_from_dir): Likewise.
	(thread_db_load_search): Likewise.
	(info_auto_load_libthread_db): Likewise.
	* m32c-tdep.c (m32c_m16c_address_to_pointer): Likewise.
	(m32c_m16c_pointer_to_address): Likewise.
	* m68hc11-tdep.c (m68hc11_pseudo_register_write): Likewise.
	* m68k-tdep.c (m68k_get_longjmp_target): Likewise.
	* machoread.c (macho_check_dsym): Likewise.
	* macroexp.c (resize_buffer): Likewise.
	(gather_arguments): Likewise.
	(maybe_expand): Likewise.
	* macrotab.c (new_macro_key): Likewise.
	(new_source_file): Likewise.
	(new_macro_definition): Likewise.
	* mdebugread.c (parse_symbol): Likewise.
	(parse_type): Likewise.
	(parse_partial_symbols): Likewise.
	(psymtab_to_symtab_1): Likewise.
	* mem-break.c (default_memory_insert_breakpoint): Likewise.
	* mi/mi-cmd-break.c (mi_argv_to_format): Likewise.
	* mi/mi-main.c (mi_cmd_data_read_memory): Likewise.
	(mi_cmd_data_read_memory_bytes): Likewise.
	(mi_cmd_data_write_memory_bytes): Likewise.
	(mi_cmd_trace_frame_collected): Likewise.
	* mi/mi-parse.c (mi_parse_argv): Likewise.
	(mi_parse): Likewise.
	* minidebug.c (lzma_open): Likewise.
	(lzma_pread): Likewise.
	* mips-tdep.c (mips_read_fp_register_single): Likewise.
	(mips_print_fp_register): Likewise.
	* mipsnbsd-tdep.c (mipsnbsd_get_longjmp_target): Likewise.
	* mipsread.c (read_alphacoff_dynamic_symtab): Likewise.
	* mt-tdep.c (mt_register_name): Likewise.
	(mt_registers_info): Likewise.
	(mt_push_dummy_call): Likewise.
	* namespace.c (add_using_directive): Likewise.
	* nat/linux-btrace.c (perf_event_read): Likewise.
	(linux_enable_bts): Likewise.
	* nat/linux-osdata.c (linux_common_core_of_thread): Likewise.
	* nat/linux-ptrace.c (linux_ptrace_test_ret_to_nx): Likewise.
	* nto-tdep.c (nto_find_and_open_solib): Likewise.
	(nto_parse_redirection): Likewise.
	* objc-lang.c (objc_demangle): Likewise.
	(find_methods): Likewise.
	* objfiles.c (get_objfile_bfd_data): Likewise.
	(set_objfile_main_name): Likewise.
	(allocate_objfile): Likewise.
	(objfile_relocate): Likewise.
	(update_section_map): Likewise.
	* osabi.c (generic_elf_osabi_sniff_abi_tag_sections): Likewise.
	* p-exp.y (exp): Likewise.
	(yylex): Likewise.
	* p-valprint.c (pascal_object_print_value): Likewise.
	* parse.c (initialize_expout): Likewise.
	(mark_completion_tag): Likewise.
	(copy_name): Likewise.
	(parse_float): Likewise.
	(type_stack_reserve): Likewise.
	* ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise.
	(ppu2spu_prev_register): Likewise.
	* ppc-ravenscar-thread.c (supply_register_at_address): Likewise.
	* printcmd.c (printf_wide_c_string): Likewise.
	(printf_pointer): Likewise.
	* probe.c (parse_probes): Likewise.
	* python/py-cmd.c (gdbpy_parse_command_name): Likewise.
	(cmdpy_init): Likewise.
	* python/py-gdb-readline.c (gdbpy_readline_wrapper): Likewise.
	* python/py-symtab.c (set_sal): Likewise.
	* python/py-unwind.c (pyuw_sniffer): Likewise.
	* python/python.c (python_interactive_command): Likewise.
	(compute_python_string): Likewise.
	* ravenscar-thread.c (get_running_thread_id): Likewise.
	* record-full.c (record_full_exec_insn): Likewise.
	(record_full_core_open_1): Likewise.
	* regcache.c (regcache_raw_read_signed): Likewise.
	(regcache_raw_read_unsigned): Likewise.
	(regcache_cooked_read_signed): Likewise.
	(regcache_cooked_read_unsigned): Likewise.
	* remote-fileio.c (remote_fileio_func_open): Likewise.
	(remote_fileio_func_rename): Likewise.
	(remote_fileio_func_unlink): Likewise.
	(remote_fileio_func_stat): Likewise.
	(remote_fileio_func_system): Likewise.
	* remote-mips.c (mips_xfer_memory): Likewise.
	(mips_load_srec): Likewise.
	(pmon_end_download): Likewise.
	* remote.c (new_remote_state): Likewise.
	(map_regcache_remote_table): Likewise.
	(remote_register_number_and_offset): Likewise.
	(init_remote_state): Likewise.
	(get_memory_packet_size): Likewise.
	(remote_pass_signals): Likewise.
	(remote_program_signals): Likewise.
	(remote_start_remote): Likewise.
	(remote_check_symbols): Likewise.
	(remote_query_supported): Likewise.
	(extended_remote_attach): Likewise.
	(process_g_packet): Likewise.
	(store_registers_using_G): Likewise.
	(putpkt_binary): Likewise.
	(read_frame): Likewise.
	(compare_sections_command): Likewise.
	(remote_hostio_pread): Likewise.
	(remote_hostio_readlink): Likewise.
	(remote_file_put): Likewise.
	(remote_file_get): Likewise.
	(remote_pid_to_exec_file): Likewise.
	(_initialize_remote): Likewise.
	* rs6000-aix-tdep.c (rs6000_aix_ld_info_to_xml): Likewise.
	(rs6000_aix_core_xfer_shared_libraries_aix): Likewise.
	* rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise.
	(bfd_uses_spe_extensions): Likewise.
	* s390-linux-tdep.c (s390_displaced_step_copy_insn): Likewise.
	* score-tdep.c (score7_malloc_and_get_memblock): Likewise.
	* solib-dsbt.c (decode_loadmap): Likewise.
	(fetch_loadmap): Likewise.
	(scan_dyntag): Likewise.
	(enable_break): Likewise.
	(dsbt_relocate_main_executable): Likewise.
	* solib-frv.c (fetch_loadmap): Likewise.
	(enable_break2): Likewise.
	(frv_relocate_main_executable): Likewise.
	* solib-spu.c (spu_relocate_main_executable): Likewise.
	(spu_bfd_open): Likewise.
	* solib-svr4.c (lm_info_read): Likewise.
	(read_program_header): Likewise.
	(find_program_interpreter): Likewise.
	(scan_dyntag): Likewise.
	(elf_locate_base): Likewise.
	(open_symbol_file_object): Likewise.
	(read_program_headers_from_bfd): Likewise.
	(svr4_relocate_main_executable): Likewise.
	* solib-target.c (solib_target_relocate_section_addresses): Likewise.
	* solib.c (solib_find_1): Likewise.
	(exec_file_find): Likewise.
	(solib_find): Likewise.
	* source.c (openp): Likewise.
	(print_source_lines_base): Likewise.
	(forward_search_command): Likewise.
	* sparc-ravenscar-thread.c (supply_register_at_address): Likewise.
	* spu-tdep.c (spu2ppu_prev_register): Likewise.
	(spu_get_overlay_table): Likewise.
	* stabsread.c (patch_block_stabs): Likewise.
	(define_symbol): Likewise.
	(again:): Likewise.
	(read_member_functions): Likewise.
	(read_one_struct_field): Likewise.
	(read_enum_type): Likewise.
	(common_block_start): Likewise.
	* stack.c (read_frame_arg): Likewise.
	(backtrace_command): Likewise.
	* stap-probe.c (stap_parse_register_operand): Likewise.
	* symfile.c (syms_from_objfile_1): Likewise.
	(find_separate_debug_file): Likewise.
	(load_command): Likewise.
	(load_progress): Likewise.
	(load_section_callback): Likewise.
	(reread_symbols): Likewise.
	(add_filename_language): Likewise.
	(allocate_compunit_symtab): Likewise.
	(read_target_long_array): Likewise.
	(simple_read_overlay_table): Likewise.
	* symtab.c (symbol_set_names): Likewise.
	(resize_symbol_cache): Likewise.
	(rbreak_command): Likewise.
	(completion_list_add_name): Likewise.
	(completion_list_objc_symbol): Likewise.
	(add_filename_to_list): Likewise.
	* target-descriptions.c (maint_print_c_tdesc_cmd): Likewise.
	* target-memory.c (target_write_memory_blocks): Likewise.
	* target.c (target_read_string): Likewise.
	(read_whatever_is_readable): Likewise.
	(target_read_alloc_1): Likewise.
	(simple_search_memory): Likewise.
	(target_fileio_read_alloc_1): Likewise.
	* tilegx-tdep.c (tilegx_push_dummy_call): Likewise.
	* top.c (command_line_input): Likewise.
	* tracefile-tfile.c (tfile_fetch_registers): Likewise.
	* tracefile.c (tracefile_fetch_registers): Likewise.
	* tracepoint.c (add_memrange): Likewise.
	(init_collection_list): Likewise.
	(add_aexpr): Likewise.
	(trace_dump_actions): Likewise.
	(parse_trace_status): Likewise.
	(parse_tracepoint_definition): Likewise.
	(parse_tsv_definition): Likewise.
	(parse_static_tracepoint_marker_definition): Likewise.
	* tui/tui-file.c (tui_sfileopen): Likewise.
	(tui_file_adjust_strbuf): Likewise.
	* tui/tui-io.c (tui_expand_tabs): Likewise.
	* tui/tui-source.c (tui_set_source_content): Likewise.
	* typeprint.c (find_global_typedef): Likewise.
	* ui-file.c (do_ui_file_xstrdup): Likewise.
	(ui_file_obsavestring): Likewise.
	(mem_file_write): Likewise.
	* utils.c (make_hex_string): Likewise.
	(get_regcomp_error): Likewise.
	(puts_filtered_tabular): Likewise.
	(gdb_realpath_keepfile): Likewise.
	(ldirname): Likewise.
	(gdb_bfd_errmsg): Likewise.
	(substitute_path_component): Likewise.
	* valops.c (search_struct_method): Likewise.
	(find_oload_champ_namespace_loop): Likewise.
	* valprint.c (print_decimal_chars): Likewise.
	(read_string): Likewise.
	(generic_emit_char): Likewise.
	* varobj.c (varobj_delete): Likewise.
	(varobj_value_get_print_value): Likewise.
	* vaxobsd-tdep.c (vaxobsd_sigtramp_sniffer): Likewise.
	* windows-tdep.c (display_one_tib): Likewise.
	* xcoffread.c (read_xcoff_symtab): Likewise.
	(process_xcoff_symbol): Likewise.
	(swap_sym): Likewise.
	(scan_xcoff_symtab): Likewise.
	(xcoff_initial_scan): Likewise.
	* xml-support.c (gdb_xml_end_element): Likewise.
	(xml_process_xincludes): Likewise.
	(xml_fetch_content_from_file): Likewise.
	* xml-syscall.c (xml_list_of_syscalls): Likewise.
	* xstormy16-tdep.c (xstormy16_push_dummy_call): Likewise.

gdb/gdbserver/ChangeLog:

	* ax.c (gdb_parse_agent_expr): Add cast to allocation result
	assignment.
	(gdb_unparse_agent_expr): Likewise.
	* hostio.c (require_data): Likewise.
	(handle_pread): Likewise.
	* linux-low.c (disable_regset): Likewise.
	(fetch_register): Likewise.
	(store_register): Likewise.
	(get_dynamic): Likewise.
	(linux_qxfer_libraries_svr4): Likewise.
	* mem-break.c (delete_fast_tracepoint_jump): Likewise.
	(set_fast_tracepoint_jump): Likewise.
	(uninsert_fast_tracepoint_jumps_at): Likewise.
	(reinsert_fast_tracepoint_jumps_at): Likewise.
	(validate_inserted_breakpoint): Likewise.
	(clone_agent_expr): Likewise.
	* regcache.c (init_register_cache): Likewise.
	* remote-utils.c (putpkt_binary_1): Likewise.
	(decode_M_packet): Likewise.
	(decode_X_packet): Likewise.
	(look_up_one_symbol): Likewise.
	(relocate_instruction): Likewise.
	(monitor_output): Likewise.
	* server.c (handle_search_memory): Likewise.
	(handle_qxfer_exec_file): Likewise.
	(handle_qxfer_libraries): Likewise.
	(handle_qxfer): Likewise.
	(handle_query): Likewise.
	(handle_v_cont): Likewise.
	(handle_v_run): Likewise.
	(captured_main): Likewise.
	* target.c (write_inferior_memory): Likewise.
	* thread-db.c (try_thread_db_load_from_dir): Likewise.
	* tracepoint.c (init_trace_buffer): Likewise.
	(add_tracepoint_action): Likewise.
	(add_traceframe): Likewise.
	(add_traceframe_block): Likewise.
	(cmd_qtdpsrc): Likewise.
	(cmd_qtdv): Likewise.
	(cmd_qtstatus): Likewise.
	(response_source): Likewise.
	(response_tsv): Likewise.
	(cmd_qtnotes): Likewise.
	(gdb_collect): Likewise.
	(initialize_tracepoint): Likewise.
2015-09-25 14:08:06 -04:00
Yao Qi 750ce8d1ca Support single step by arch or target
Nowadays, GDB only knows whether architecture supports hardware single
step or software single step (through gdbarch hook software_single_step),
and for a given instruction or instruction sequence, GDB knows how to
do single step (hardware or software).  However, GDB doesn't know whether
the target supports hardware single step.  It is possible that the
architecture doesn't support hardware single step, such as arm, but
the target supports, such as simulator.  This was discussed in this
thread https://www.sourceware.org/ml/gdb/2009-12/msg00033.html before.

I encounter this problem for aarch64 multi-arch support.  When aarch64
debugs arm program, gdbarch is arm, so software single step is still
used.  However, the underneath linux kernel does support hardware
single step, so IWBN to use it.

This patch is to add a new target_ops hook to_can_do_single_step, and
only use it in arm_linux_software_single_step to decide whether or not
to use hardware single step.  On the native aarch64 linux target, 1 is
returned.  On other targets, -1 is returned.  On the remote target, if
the target supports s and S actions in the vCont? reply, then target
can do single step.  However,  old GDBserver will send s and S in the
reply to vCont?, which will confuse new GDB.  For example, old GDBserver
on arm-linux will send s and S in the reply to vCont?, but it doesn't
support hardware single step.  On the other hand, new GDBserver, on
arm-linux for example, will not send s and S in the reply to vCont?,
but old GDB thinks it doesn't support vCont packet at all.  In order
to address this problem, I add a new qSupported feature vContSupported,
which indicates GDB wants to know the supported actions in the reply
to vCont?, and qSupported response contains vContSupported if the
stub is able tell supported vCont actions in the reply of vCont?.

If the patched GDB talks with patched GDBserver on x86, the RSP traffic
is like this:

 -> $qSupported:...+;vContSupported+
 <- ...+;vContSupported+
 ...
 -> $vCont?
 <- vCont;c;C;t;s;S;r

then, GDB knows the stub can do single step, and may stop using software
single step even the architecture doesn't support hardware single step.

If the patched GDB talks with patched GDBserver on arm, the last vCont?
reply will become:

 <- vCont;c;C;t

GDB thinks the target doesn't support single step, so it will use software
single step.

If the patched GDB talks with unpatched GDBserver, the RSP traffic is like
this:

 -> $qSupported:...+;vContSupported+
 <- ...+
 ...
 -> $vCont?
 <- vCont;c;C;t;s;S;r

although GDBserver returns s and S, GDB still thinks GDBserver may not
support single step because it doesn't support vContSupported.

If the unpatched GDB talks with patched GDBserver on x86, the RSP traffic
is like:

 -> $qSupported:...+;
 <- ...+;vContSupported+
 ...
 -> $vCont?
 <- vCont;c;C;t;s;S;r

Since GDB doesn't sent vContSupported in the qSupported feature, GDBserver
sends s and S regardless of the support of hardware single step.

gdb:

2015-09-15  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (aarch64_linux_can_do_single_step): New
	function.
	(_initialize_aarch64_linux_nat): Install it to to_can_do_single_step.
	* arm-linux-tdep.c (arm_linux_software_single_step): Return 0
	if target_can_do_single_step returns 1.
	* remote.c (struct vCont_action_support) <s, S>: New fields.
	(PACKET_vContSupported): New enum.
	(remote_protocol_features): New element for vContSupported.
	(remote_query_supported): Append "vContSupported+".
	(remote_vcont_probe): Remove support_s and support_S, use
	rs->supports_vCont.s and rs->supports_vCont.S instead.  Disable
	vCont packet if c and C actions are not supported.
	(remote_can_do_single_step): New function.
	(init_remote_ops): Install it to to_can_do_single_step.
	(_initialize_remote): Call add_packet_config_cmd.
	* target.h (struct target_ops) <to_can_do_single_step>: New field.
	(target_can_do_single_step): New macro.
	* target-delegates.c: Re-generated.

gdb/gdbserver:

2015-09-15  Yao Qi  <yao.qi@linaro.org>

	* server.c (vCont_supported): New global variable.
	(handle_query): Set vCont_supported to 1 if "vContSupported+"
	matches.  Append ";vContSupported+" to own_buf.
	(handle_v_requests): Append ";s;S" to own_buf if target supports
	hardware single step or vCont_supported is false.
	(capture_main): Set vCont_supported to zero.

gdb/doc:

2015-09-15  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (General Query Packets): Add vContSupported to
	tables of 'gdbfeatures' and 'stub features' supported in the
	qSupported packet, as well as to the list containing stub
	feature details.
2015-09-15 14:09:18 +01:00
Don Breazeal d46addbb52 Extended-remote catch exec
This patch implements exec catchpoints for extended-remote Linux
targets.  The implementation follows the same approach used for
fork catchpoints, implementing extended-remote target routines for
inserting and removing the catchpoints by just checking if exec events
are supported.  Existing host-side code and previous support for
extended-remote exec events takes care of the rest.

gdb/ChangeLog:

	* remote.c (remote_exec_event_p): New function.
	(remote_insert_exec_catchpoint): New function.
	(remote_remove_exec_catchpoint): New function.
	(init_extended_remote_ops): Initialize extended_remote_ops
	members to_insert_exec_catchpoint and
	to_remove_exec_catchpoint.
2015-09-11 11:12:46 -07:00
Don Breazeal 94585166df Extended-remote follow-exec
This patch implements support for exec events on extended-remote Linux
targets.  Follow-exec-mode and rerun behave as expected.  Catchpoints and
test updates are implemented in subsequent patches.

This patch was derived from a patch posted last October:
https://sourceware.org/ml/gdb-patches/2014-10/msg00877.html.
It was originally based on some work done by Luis Machado in 2013.

IMPLEMENTATION
----------------
Exec events are enabled via ptrace options.

When an exec event is detected by gdbserver, the existing process
data, along with all its associated lwp and thread data, is deleted
and replaced by data for a new single-threaded process.  The new
process data is initialized with the appropriate parts of the state
of the execing process.  This approach takes care of several potential
pitfalls, including:

 * deleting the data for an execing non-leader thread before any
   wait/sigsuspend occurs
 * correctly initializing the architecture of the execed process

We then report the exec event using a new RSP stop reason, "exec".

When GDB receives an "exec" event, it saves the status in the event
structure's target_waitstatus field, like what is done for remote fork
events.  Because the original and execed programs may have different
architectures, we skip parsing the section of the stop reply packet
that contains register data.  The register data will be retrieved
later after the inferior's architecture has been set up by
infrun.c:follow_exec.

At that point the exec event is handled by the existing event handling
in GDB.  However, a few changes were necessary so that
infrun.c:follow_exec could accommodate the remote target.

 * Where follow-exec-mode "new" is handled, we now call
   add_inferior_with_spaces instead of add_inferior with separate calls
   to set up the program and address spaces.  The motivation for this
   is that add_inferior_with_spaces also sets up the initial architecture
   for the inferior, which is needed later by target_find_description
   when it calls target_gdbarch.

 * We call a new target function, target_follow_exec.  This function
   allows us to store the execd_pathname in the inferior, instead of
   using the static string remote_exec_file from remote.c.  The static
   string didn't work for follow-exec-mode "new", since once you switched
   to the execed program, the original remote exec-file was lost.  The
   execd_pathname is now stored in the inferior's program space as a
   REGISTRY field.  All of the requisite mechanisms for this are
   defined in remote.c.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_mourn): Static declaration.
	(linux_arch_setup): Move in front of
	handle_extended_wait.
	(linux_arch_setup_thread): New function.
	(handle_extended_wait): Handle exec events.  Call
	linux_arch_setup_thread.  Make event_lwp argument a
	pointer-to-a-pointer.
	(check_zombie_leaders): Do not check stopped threads.
	(linux_low_ptrace_options): Add PTRACE_O_TRACEEXEC.
	(linux_low_filter_event): Add lwp and thread for exec'ing
	non-leader thread if leader thread has been deleted.
	Refactor code into linux_arch_setup_thread and call it.
	Pass child lwp pointer by reference to handle_extended_wait.
	(linux_wait_for_event_filtered): Update comment.
	(linux_wait_1): Prevent clobbering exec event status.
	(linux_supports_exec_events): New function.
	(linux_target_ops) <supports_exec_events>: Initialize new member.
	* lynx-low.c (lynx_target_ops) <supports_exec_events>: Initialize
	new member.
	* remote-utils.c (prepare_resume_reply): New stop reason 'exec'.
	* server.c (report_exec_events): New global variable.
	(handle_query): Handle qSupported query for exec-events feature.
	(captured_main): Initialize report_exec_events.
	* server.h (report_exec_events): Declare new global variable.
	* target.h (struct target_ops) <supports_exec_events>: New
	member.
	(target_supports_exec_events): New macro.
	* win32-low.c (win32_target_ops) <supports_exec_events>:
	Initialize new member.

gdb/ChangeLog:

	* infrun.c (follow_exec): Use process-style ptid for
	exec message.  Call add_inferior_with_spaces and
	target_follow_exec.
	* nat/linux-ptrace.c (linux_supports_traceexec): New function.
	* nat/linux-ptrace.h (linux_supports_traceexec): Declare.
	* remote.c (remote_pspace_data): New static variable.
	(remote_pspace_data_cleanup): New function.
	(get_remote_exec_file): New function.
	(set_remote_exec_file_1): New function.
	(set_remote_exec_file): New function.
	(show_remote_exec_file): New function.
	(remote_exec_file): Delete static variable.
	(anonymous enum) <PACKET_exec_event_feature> New
	enumeration constant.
	(remote_protocol_features): Add entry for exec-events feature.
	(remote_query_supported): Add client side of qSupported query
	for exec-events feature.
	(remote_follow_exec): New function.
	(remote_parse_stop_reply): Handle 'exec' stop reason.
	(extended_remote_run, extended_remote_create_inferior): Call
	get_remote_exec_file and set_remote_exec_file_1.
	(init_extended_remote_ops) <to_follow_exec>: Initialize new
	member.
	(_initialize_remote): Call
	register_program_space_data_with_cleanup.  Call
	add_packet_config_cmd for remote exec-events feature.
	Modify call to add_setshow_string_noescape_cmd for exec-file
	to use new functions set_remote_exec_file and
	show_remote_exec_file.
	* target-debug.h, target-delegates.c: Regenerated.
	* target.c (target_follow_exec): New function.
	* target.h (struct target_ops) <to_follow_exec>: New member.
	(target_follow_exec): Declare new function.
2015-09-11 11:12:46 -07:00
Pedro Alves 243a925328 Replace "struct continuation" mechanism by something more extensible
This adds an object oriented replacement for the "struct continuation"
mechanism, and converts the stepping commands (step, next, stepi,
nexti) and the "finish" commands to use it.

It adds a new thread "class" (struct thread_fsm) that contains the
necessary info and callbacks to manage the state machine of a thread's
execution command.

This allows getting rid of some hacks.  E.g., in fetch_inferior_event
and normal_stop we no longer need to know whether a thread is doing a
multi-step (e.g., step N).  This effectively makes the
intermediate_continuations unused -- they'll be garbage collected in a
separate patch.  (They were never a proper abstraction, IMO.  See how
fetch_inferior_event needs to check step_multi before knowing whether
to call INF_EXEC_CONTINUE or INF_EXEC_COMPLETE.)

The target async vs !async uiout hacks in mi_on_normal_stop go away
too.

print_stop_event is no longer called from normal_stop.  Instead it is
now called from within each interpreter's normal_stop observer.  This
clears the path to make each interpreter print a stop event the way it
sees fit.  Currently we have some hacks in common code to
differenciate CLI vs TUI vs MI around this area.

The "finish" command's FSM class stores the return value plus that
value's position in the value history, so that those can be printed to
both MI and CLI's streams.  This fixes the CLI "finish" command when
run from MI -- it now also includes the function's return value in the
CLI stream:

  (gdb)
  ~"callee3 (strarg=0x400730 \"A string argument.\") at src/gdb/testsuite/gdb.mi/basics.c:35\n"
  ~"35\t}\n"
 +~"Value returned is $1 = 0\n"
  *stopped,reason="function-finished",frame=...,gdb-result-var="$1",return-value="0",thread-id="1",stopped-threads="all",core="0"
 -FAIL: gdb.mi/mi-cli.exp: CLI finish: check CLI output
 +PASS: gdb.mi/mi-cli.exp: CLI finish: check CLI output

gdb/ChangeLog:
2015-09-09  Pedro Alves  <palves@redhat.com>

	* Makefile.in (COMMON_OBS): Add thread-fsm.o.
	* breakpoint.c (handle_jit_event): Print debug output.
	(bpstat_what): Split event callback handling to ...
	(bpstat_run_callbacks): ... this new function.
	(momentary_bkpt_print_it): No longer handle bp_finish here.
	* breakpoint.h (bpstat_run_callbacks): Declare.
	* gdbthread.h (struct thread_info) <step_multi>: Delete field.
	<thread_fsm>: New field.
	(thread_cancel_execution_command): Declare.
	* infcmd.c: Include thread-fsm.h.
	(struct step_command_fsm): New.
	(step_command_fsm_ops): New global.
	(new_step_command_fsm, step_command_fsm_prepare): New functions.
	(step_1): Adjust to use step_command_fsm_prepare and
	prepare_one_step.
	(struct step_1_continuation_args): Delete.
	(step_1_continuation): Delete.
	(step_command_fsm_should_stop): New function.
	(step_once): Delete.
	(step_command_fsm_clean_up, step_command_fsm_async_reply_reason)
	(prepare_one_step): New function, based on step_once.
	(until_next_command): Remove step_multi reference.
	(struct return_value_info): New.
	(print_return_value): Rename to ...
	(print_return_value_1): ... this.  New struct return_value_info
	parameter.  Adjust.
	(print_return_value): Reimplement as wrapper around
	print_return_value_1.
	(struct finish_command_fsm): New.
	(finish_command_continuation): Delete.
	(finish_command_fsm_ops): New global.
	(new_finish_command_fsm, finish_command_fsm_should_stop): New
	functions.
	(finish_command_fsm_clean_up, finish_command_fsm_return_value):
	New.
	(finish_command_continuation_free_arg): Delete.
	(finish_command_fsm_async_reply_reason): New.
	(finish_backward, finish_forward): Change symbol parameter to a
	finish_command_fsm.  Adjust.
	(finish_command): Create a finish_command_fsm.  Adjust.
	* infrun.c: Include "thread-fsm.h".
	(clear_proceed_status_thread): Delete the thread's FSM.
	(infrun_thread_stop_requested_callback): Cancel the thread's
	execution command.
	(clean_up_just_stopped_threads_fsms): New function.
	(fetch_inferior_event): Handle the event_thread's should_stop
	method saying the command isn't done yet.
	(process_event_stop_test): Run breakpoint callbacks here.
	(print_stop_event): Rename to ...
	(print_stop_location): ... this.
	(restore_current_uiout_cleanup): New function.
	(print_stop_event): Reimplement.
	(normal_stop): No longer notify the end_stepping_range observers
	here handle "step N" nor "finish" here.  No longer call
	print_stop_event here.
	* infrun.h (struct return_value_info): Forward declare.
	(print_return_value): Declare.
	(print_stop_event): Change prototype.
	* thread-fsm.c: New file.
	* thread-fsm.h: New file.
	* thread.c: Include "thread-fsm.h".
	(thread_cancel_execution_command): New function.
	(clear_thread_inferior_resources): Call it.
	* cli/cli-interp.c (cli_on_normal_stop): New function.
	(cli_interpreter_init): Install cli_on_normal_stop as normal_stop
	observer.
	* mi/mi-interp.c: Include "thread-fsm.h".
	(restore_current_uiout_cleanup): Delete.
	(mi_on_normal_stop): If the thread has an FSM associated, and it
	finished, ask it for the async-reply-reason to print.  Always call
	print_stop_event here, regardless of the top-level interpreter.
	Check bpstat_what to tell whether an asynchronous breakpoint hit
	triggered.
	* tui/tui-interp.c (tui_on_normal_stop): New function.
	(tui_init): Install tui_on_normal_stop as normal_stop observer.

gdb/testsuite/ChangeLog:
2015-09-09  Pedro Alves  <palves@redhat.com>

	* gdb.mi/mi-cli.exp: Add CLI finish tests.
2015-09-09 18:24:00 +01:00
Pedro Alves a5c0808e22 gdb: remove packet size limit
The remote packet buffer size is currently capped to 16384 mostly for
historical reasons, related to use of alloca.  Stop using alloca and
remove the limitation.

Tested on x86_64 Fedora 20.

gdb/ChangeLog:
2015-08-27  Pedro Alves  <palves@redhat.com>

	* remote.c (DEFAULT_MAX_MEMORY_PACKET_SIZE)
	(MIN_MEMORY_PACKET_SIZE): New.
	(MAX_REMOTE_PACKET_SIZE, MIN_REMOTE_PACKET_SIZE): Delete.
	(get_memory_packet_size): Adjust.  No longer limit the max packet
	size.
	(set_memory_packet_size): Adjust, and remove dead code.
	(remote_check_symbols): Use xmalloc and a cleanup instead of
	alloca.
	(remote_packet_size): No longer cap the packet size.
	(putpkt_binary): Use xmalloc and a cleanup instead of alloca.
2015-08-27 13:03:15 +01:00
Simon Marchi 8d7493201c Replace some xmalloc-family functions with XNEW-family ones
This patch is part of the make-gdb-buildable-in-C++ effort.  The idea is
to change some calls to the xmalloc family of functions to calls to the
equivalents in the XNEW family.  This avoids adding an explicit cast, so
it keeps the code a bit more readable.  Some of them also map relatively
well to a C++ equivalent (XNEW (struct foo) -> new foo), so it will be
possible to do scripted replacements if needed.

I only changed calls that were obviously allocating memory for one or
multiple "objects".  Allocation of variable sizes (such as strings or
buffer handling) will be for later (and won't use XNEW).

  - xmalloc (sizeof (struct foo)) -> XNEW (struct foo)
  - xmalloc (num * sizeof (struct foo)) -> XNEWVEC (struct foo, num)
  - xcalloc (1, sizeof (struct foo)) -> XCNEW (struct foo)
  - xcalloc (num, sizeof (struct foo)) -> XCNEWVEC (struct foo, num)
  - xrealloc (p, num * sizeof (struct foo) -> XRESIZEVEC (struct foo, p, num)
  - obstack_alloc (ob, sizeof (struct foo)) -> XOBNEW (ob, struct foo)
  - obstack_alloc (ob, num * sizeof (struct foo)) -> XOBNEWVEC (ob, struct foo, num)
  - alloca (sizeof (struct foo)) -> XALLOCA (struct foo)
  - alloca (num * sizeof (struct foo)) -> XALLOCAVEC (struct foo, num)

Some instances of xmalloc followed by memset to zero the buffer were
replaced by XCNEW or XCNEWVEC.

I regtested on x86-64, Ubuntu 14.04, but the patch touches many
architecture-specific files.  For those I'll have to rely on the
buildbot or people complaining that I broke their gdb.

gdb/ChangeLog:

	* aarch64-linux-nat.c (aarch64_add_process): Likewise.
	* aarch64-tdep.c (aarch64_gdbarch_init): Likewise.
	* ada-exp.y (write_ambiguous_var): Likewise.
	* ada-lang.c (resolve_subexp): Likewise.
	(user_select_syms): Likewise.
	(assign_aggregate): Likewise.
	(ada_evaluate_subexp): Likewise.
	(cache_symbol): Likewise.
	* addrmap.c (allocate_key): Likewise.
	(addrmap_create_mutable): Likewise.
	* aix-thread.c (sync_threadlists): Likewise.
	* alpha-tdep.c (alpha_push_dummy_call): Likewise.
	(alpha_gdbarch_init): Likewise.
	* amd64-windows-tdep.c (amd64_windows_push_arguments): Likewise.
	* arm-linux-nat.c (arm_linux_add_process): Likewise.
	* arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise.
	* arm-tdep.c (push_stack_item): Likewise.
	(arm_displaced_step_copy_insn): Likewise.
	(arm_gdbarch_init): Likewise.
	(_initialize_arm_tdep): Likewise.
	* avr-tdep.c (push_stack_item): Likewise.
	* ax-general.c (new_agent_expr): Likewise.
	* block.c (block_initialize_namespace): Likewise.
	* breakpoint.c (alloc_counted_command_line): Likewise.
	(update_dprintf_command_list): Likewise.
	(parse_breakpoint_sals): Likewise.
	(decode_static_tracepoint_spec): Likewise.
	(until_break_command): Likewise.
	(clear_command): Likewise.
	(update_global_location_list): Likewise.
	(get_breakpoint_objfile_data) Likewise.
	* btrace.c (ftrace_new_function): Likewise.
	(btrace_set_insn_history): Likewise.
	(btrace_set_call_history): Likewise.
	* buildsym.c (add_symbol_to_list): Likewise.
	(record_pending_block): Likewise.
	(start_subfile): Likewise.
	(start_buildsym_compunit): Likewise.
	(push_subfile): Likewise.
	(end_symtab_get_static_block): Likewise.
	(buildsym_init): Likewise.
	* cli/cli-cmds.c (source_command): Likewise.
	* cli/cli-decode.c (add_cmd): Likewise.
	* cli/cli-script.c (build_command_line): Likewise.
	(setup_user_args): Likewise.
	(realloc_body_list): Likewise.
	(process_next_line): Likewise.
	(copy_command_lines): Likewise.
	* cli/cli-setshow.c (do_set_command): Likewise.
	* coff-pe-read.c (read_pe_exported_syms): Likewise.
	* coffread.c (coff_locate_sections): Likewise.
	(coff_symtab_read): Likewise.
	(coff_read_struct_type): Likewise.
	* common/cleanups.c (make_my_cleanup2): Likewise.
	* common/common-exceptions.c (throw_it): Likewise.
	* common/filestuff.c (make_cleanup_close): Likewise.
	* common/format.c (parse_format_string): Likewise.
	* common/queue.h (DEFINE_QUEUE_P): Likewise.
	* compile/compile-object-load.c (munmap_list_add): Likewise.
	(compile_object_load): Likewise.
	* compile/compile-object-run.c (compile_object_run): Likewise.
	* compile/compile.c (append_args): Likewise.
	* corefile.c (specify_exec_file_hook): Likewise.
	* cp-support.c (make_symbol_overload_list): Likewise.
	* cris-tdep.c (push_stack_item): Likewise.
	(cris_gdbarch_init): Likewise.
	* ctf.c (ctf_trace_file_writer_new): Likewise.
	* dbxread.c (init_header_files): Likewise.
	(add_new_header_file): Likewise.
	(init_bincl_list): Likewise.
	(dbx_end_psymtab): Likewise.
	(start_psymtab): Likewise.
	(dbx_end_psymtab): Likewise.
	* dcache.c (dcache_init): Likewise.
	* dictionary.c (dict_create_hashed): Likewise.
	(dict_create_hashed_expandable): Likewise.
	(dict_create_linear): Likewise.
	(dict_create_linear_expandable): Likewise.
	* dtrace-probe.c (dtrace_process_dof_probe): Likewise.
	* dummy-frame.c (register_dummy_frame_dtor): Likewise.
	* dwarf2-frame-tailcall.c (cache_new_ref1): Likewise.
	* dwarf2-frame.c (dwarf2_build_frame_info): Likewise.
	(decode_frame_entry_1): Likewise.
	* dwarf2expr.c (new_dwarf_expr_context): Likewise.
	* dwarf2loc.c (dwarf2_compile_expr_to_ax): Likewise.
	* dwarf2read.c (dwarf2_has_info): Likewise.
	(create_signatured_type_table_from_index): Likewise.
	(dwarf2_read_index): Likewise.
	(dw2_get_file_names_reader): Likewise.
	(create_all_type_units): Likewise.
	(read_cutu_die_from_dwo): Likewise.
	(init_tu_and_read_dwo_dies): Likewise.
	(init_cutu_and_read_dies): Likewise.
	(create_all_comp_units): Likewise.
	(queue_comp_unit): Likewise.
	(inherit_abstract_dies): Likewise.
	(read_call_site_scope): Likewise.
	(dwarf2_add_field): Likewise.
	(dwarf2_add_typedef): Likewise.
	(dwarf2_add_member_fn): Likewise.
	(attr_to_dynamic_prop): Likewise.
	(abbrev_table_alloc_abbrev): Likewise.
	(abbrev_table_read_table): Likewise.
	(add_include_dir): Likewise.
	(add_file_name): Likewise.
	(dwarf_decode_line_header): Likewise.
	(dwarf2_const_value_attr): Likewise.
	(dwarf_alloc_block): Likewise.
	(parse_macro_definition): Likewise.
	(set_die_type): Likewise.
	(write_psymtabs_to_index): Likewise.
	(create_cus_from_index): Likewise.
	(dwarf2_create_include_psymtab): Likewise.
	(process_psymtab_comp_unit_reader): Likewise.
	(build_type_psymtab_dependencies): Likewise.
	(read_comp_units_from_section): Likewise.
	(compute_compunit_symtab_includes): Likewise.
	(create_dwo_unit_in_dwp_v1): Likewise.
	(create_dwo_unit_in_dwp_v2): Likewise.
	(read_func_scope): Likewise.
	(process_structure_scope): Likewise.
	(mark_common_block_symbol_computed): Likewise.
	(load_partial_dies): Likewise.
	(dwarf2_symbol_mark_computed): Likewise.
	* elfread.c (elf_symfile_segments): Likewise.
	(elf_read_minimal_symbols): Likewise.
	* environ.c (make_environ): Likewise.
	* eval.c (evaluate_subexp_standard): Likewise.
	* event-loop.c (create_file_handler): Likewise.
	(create_async_signal_handler): Likewise.
	(create_async_event_handler): Likewise.
	(create_timer): Likewise.
	* exec.c (build_section_table): Likewise.
	* fbsd-nat.c (fbsd_remember_child): Likewise.
	* fork-child.c (fork_inferior): Likewise.
	* frv-tdep.c (new_variant): Likewise.
	* gdbarch.sh (gdbarch_alloc): Likewise.
	(append_name): Likewise.
	* gdbtypes.c (rank_function): Likewise.
	(copy_type_recursive): Likewise.
	(add_dyn_prop): Likewise.
	* gnu-nat.c (make_proc): Likewise.
	(make_inf): Likewise.
	(gnu_write_inferior): Likewise.
	* gnu-v3-abi.c (build_gdb_vtable_type): Likewise.
	(build_std_type_info_type): Likewise.
	* guile/scm-param.c (compute_enum_list): Likewise.
	* guile/scm-utils.c (gdbscm_parse_function_args): Likewise.
	* guile/scm-value.c (gdbscm_value_call): Likewise.
	* h8300-tdep.c (h8300_gdbarch_init): Likewise.
	* hppa-tdep.c (hppa_init_objfile_priv_data): Likewise.
	(read_unwind_info): Likewise.
	* ia64-tdep.c (ia64_gdbarch_init): Likewise.
	* infcall.c (dummy_frame_context_saver_setup): Likewise.
	(call_function_by_hand_dummy): Likewise.
	* infcmd.c (step_once): Likewise.
	(finish_forward): Likewise.
	(attach_command): Likewise.
	(notice_new_inferior): Likewise.
	* inferior.c (add_inferior_silent): Likewise.
	* infrun.c (add_displaced_stepping_state): Likewise.
	(save_infcall_control_state): Likewise.
	(save_inferior_ptid): Likewise.
	(_initialize_infrun): Likewise.
	* jit.c (bfd_open_from_target_memory): Likewise.
	(jit_gdbarch_data_init): Likewise.
	* language.c (add_language): Likewise.
	* linespec.c (decode_line_2): Likewise.
	* linux-nat.c (add_to_pid_list): Likewise.
	(add_initial_lwp): Likewise.
	* linux-thread-db.c (add_thread_db_info): Likewise.
	(record_thread): Likewise.
	(info_auto_load_libthread_db): Likewise.
	* m32c-tdep.c (m32c_gdbarch_init): Likewise.
	* m68hc11-tdep.c (m68hc11_gdbarch_init): Likewise.
	* m68k-tdep.c (m68k_gdbarch_init): Likewise.
	* m88k-tdep.c (m88k_analyze_prologue): Likewise.
	* macrocmd.c (macro_define_command): Likewise.
	* macroexp.c (gather_arguments): Likewise.
	* macroscope.c (sal_macro_scope): Likewise.
	* macrotab.c (new_macro_table): Likewise.
	* mdebugread.c (push_parse_stack): Likewise.
	(parse_partial_symbols): Likewise.
	(parse_symbol): Likewise.
	(psymtab_to_symtab_1): Likewise.
	(new_block): Likewise.
	(new_psymtab): Likewise.
	(mdebug_build_psymtabs): Likewise.
	(add_pending): Likewise.
	(elfmdebug_build_psymtabs): Likewise.
	* mep-tdep.c (mep_gdbarch_init): Likewise.
	* mi/mi-main.c (mi_execute_command): Likewise.
	* mi/mi-parse.c (mi_parse_argv): Likewise.
	* minidebug.c (lzma_open): Likewise.
	* minsyms.c (terminate_minimal_symbol_table): Likewise.
	* mips-linux-nat.c (mips_linux_insert_watchpoint): Likewise.
	* mips-tdep.c (mips_gdbarch_init): Likewise.
	* mn10300-tdep.c (mn10300_gdbarch_init): Likewise.
	* msp430-tdep.c (msp430_gdbarch_init): Likewise.
	* mt-tdep.c (mt_registers_info): Likewise.
	* nat/aarch64-linux.c (aarch64_linux_new_thread): Likewise.
	* nat/linux-btrace.c (linux_enable_bts): Likewise.
	(linux_enable_pt): Likewise.
	* nat/linux-osdata.c (linux_xfer_osdata_processes): Likewise.
	(linux_xfer_osdata_processgroups): Likewise.
	* nios2-tdep.c (nios2_gdbarch_init): Likewise.
	* nto-procfs.c (procfs_meminfo): Likewise.
	* objc-lang.c (start_msglist): Likewise.
	(selectors_info): Likewise.
	(classes_info): Likewise.
	(find_methods): Likewise.
	* objfiles.c (allocate_objfile): Likewise.
	(update_section_map): Likewise.
	* osabi.c (gdbarch_register_osabi): Likewise.
	(gdbarch_register_osabi_sniffer): Likewise.
	* parse.c (start_arglist): Likewise.
	* ppc-linux-nat.c (hwdebug_find_thread_points_by_tid): Likewise.
	(hwdebug_insert_point): Likewise.
	* printcmd.c (display_command): Likewise.
	(ui_printf): Likewise.
	* procfs.c (create_procinfo): Likewise.
	(load_syscalls): Likewise.
	(proc_get_LDT_entry): Likewise.
	(proc_update_threads): Likewise.
	* prologue-value.c (make_pv_area): Likewise.
	(pv_area_store): Likewise.
	* psymtab.c (extend_psymbol_list): Likewise.
	(init_psymbol_list): Likewise.
	(allocate_psymtab): Likewise.
	* python/py-inferior.c (add_thread_object): Likewise.
	* python/py-param.c (compute_enum_values): Likewise.
	* python/py-value.c (valpy_call): Likewise.
	* python/py-varobj.c (py_varobj_iter_next): Likewise.
	* python/python.c (ensure_python_env): Likewise.
	* record-btrace.c (record_btrace_start_replaying): Likewise.
	* record-full.c (record_full_reg_alloc): Likewise.
	(record_full_mem_alloc): Likewise.
	(record_full_end_alloc): Likewise.
	(record_full_core_xfer_partial): Likewise.
	* regcache.c (get_thread_arch_aspace_regcache): Likewise.
	* remote-fileio.c (remote_fileio_init_fd_map): Likewise.
	* remote-notif.c (remote_notif_state_allocate): Likewise.
	* remote.c (demand_private_info): Likewise.
	(remote_notif_stop_alloc_reply): Likewise.
	(remote_enable_btrace): Likewise.
	* reverse.c (save_bookmark_command): Likewise.
	* rl78-tdep.c (rl78_gdbarch_init): Likewise.
	* rx-tdep.c (rx_gdbarch_init): Likewise.
	* s390-linux-nat.c (s390_insert_watchpoint): Likewise.
	* ser-go32.c (dos_get_tty_state): Likewise.
	(dos_copy_tty_state): Likewise.
	* ser-mingw.c (ser_windows_open): Likewise.
	(ser_console_wait_handle): Likewise.
	(ser_console_get_tty_state): Likewise.
	(make_pipe_state): Likewise.
	(net_windows_open): Likewise.
	* ser-unix.c (hardwire_get_tty_state): Likewise.
	(hardwire_copy_tty_state): Likewise.
	* solib-aix.c (solib_aix_new_lm_info): Likewise.
	* solib-dsbt.c (dsbt_current_sos): Likewise.
	(dsbt_relocate_main_executable): Likewise.
	* solib-frv.c (frv_current_sos): Likewise.
	(frv_relocate_main_executable): Likewise.
	* solib-spu.c (spu_bfd_fopen): Likewise.
	* solib-svr4.c (lm_info_read): Likewise.
	(svr4_copy_library_list): Likewise.
	(svr4_default_sos): Likewise.
	* source.c (find_source_lines): Likewise.
	(line_info): Likewise.
	(add_substitute_path_rule): Likewise.
	* spu-linux-nat.c (spu_bfd_open): Likewise.
	* spu-tdep.c (info_spu_dma_cmdlist): Likewise.
	* stabsread.c (dbx_lookup_type): Likewise.
	(read_type): Likewise.
	(read_member_functions): Likewise.
	(read_struct_fields): Likewise.
	(read_baseclasses): Likewise.
	(read_args): Likewise.
	(_initialize_stabsread): Likewise.
	* stack.c (func_command): Likewise.
	* stap-probe.c (handle_stap_probe): Likewise.
	* symfile.c (addrs_section_sort): Likewise.
	(addr_info_make_relative): Likewise.
	(load_section_callback): Likewise.
	(add_symbol_file_command): Likewise.
	(init_filename_language_table): Likewise.
	* symtab.c (create_filename_seen_cache): Likewise.
	(sort_search_symbols_remove_dups): Likewise.
	(search_symbols): Likewise.
	* target.c (make_cleanup_restore_target_terminal): Likewise.
	* thread.c (new_thread): Likewise.
	(enable_thread_stack_temporaries): Likewise.
	(make_cleanup_restore_current_thread): Likewise.
	(thread_apply_all_command): Likewise.
	* tic6x-tdep.c (tic6x_gdbarch_init): Likewise.
	* top.c (gdb_readline_wrapper): Likewise.
	* tracefile-tfile.c (tfile_trace_file_writer_new): Likewise.
	* tracepoint.c (trace_find_line_command): Likewise.
	(all_tracepoint_actions_and_cleanup): Likewise.
	(make_cleanup_restore_current_traceframe): Likewise.
	(get_uploaded_tp): Likewise.
	(get_uploaded_tsv): Likewise.
	* tui/tui-data.c (tui_alloc_generic_win_info): Likewise.
	(tui_alloc_win_info): Likewise.
	(tui_alloc_content): Likewise.
	(tui_add_content_elements): Likewise.
	* tui/tui-disasm.c (tui_find_disassembly_address): Likewise.
	(tui_set_disassem_content): Likewise.
	* ui-file.c (ui_file_new): Likewise.
	(stdio_file_new): Likewise.
	(tee_file_new): Likewise.
	* utils.c (make_cleanup_restore_integer): Likewise.
	(add_internal_problem_command): Likewise.
	* v850-tdep.c (v850_gdbarch_init): Likewise.
	* valops.c (find_oload_champ): Likewise.
	* value.c (allocate_value_lazy): Likewise.
	(record_latest_value): Likewise.
	(create_internalvar): Likewise.
	* varobj.c (install_variable): Likewise.
	(new_variable): Likewise.
	(new_root_variable): Likewise.
	(cppush): Likewise.
	(_initialize_varobj): Likewise.
	* windows-nat.c (windows_make_so): Likewise.
	* x86-nat.c (x86_add_process): Likewise.
	* xcoffread.c (arrange_linetable): Likewise.
	(allocate_include_entry): Likewise.
	(process_linenos): Likewise.
	(SYMBOL_DUP): Likewise.
	(xcoff_start_psymtab): Likewise.
	(xcoff_end_psymtab): Likewise.
	* xml-support.c (gdb_xml_parse_attr_ulongest): Likewise.
	* xtensa-tdep.c (xtensa_register_type): Likewise.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.

gdb/gdbserver/ChangeLog:

	* ax.c (gdb_parse_agent_expr): Likewise.
	(compile_bytecodes): Likewise.
	* dll.c (loaded_dll): Likewise.
	* event-loop.c (append_callback_event): Likewise.
	(create_file_handler): Likewise.
	(create_file_event): Likewise.
	* hostio.c (handle_open): Likewise.
	* inferiors.c (add_thread): Likewise.
	(add_process): Likewise.
	* linux-aarch64-low.c (aarch64_linux_new_process): Likewise.
	* linux-arm-low.c (arm_new_process): Likewise.
	(arm_new_thread): Likewise.
	* linux-low.c (add_to_pid_list): Likewise.
	(linux_add_process): Likewise.
	(handle_extended_wait): Likewise.
	(add_lwp): Likewise.
	(enqueue_one_deferred_signal): Likewise.
	(enqueue_pending_signal): Likewise.
	(linux_resume_one_lwp_throw): Likewise.
	(linux_resume_one_thread): Likewise.
	(linux_read_memory): Likewise.
	(linux_write_memory): Likewise.
	* linux-mips-low.c (mips_linux_new_process): Likewise.
	(mips_linux_new_thread): Likewise.
	(mips_add_watchpoint): Likewise.
	* linux-x86-low.c (initialize_low_arch): Likewise.
	* lynx-low.c (lynx_add_process): Likewise.
	* mem-break.c (set_raw_breakpoint_at): Likewise.
	(set_breakpoint): Likewise.
	(add_condition_to_breakpoint): Likewise.
	(add_commands_to_breakpoint): Likewise.
	(clone_agent_expr): Likewise.
	(clone_one_breakpoint): Likewise.
	* regcache.c (new_register_cache): Likewise.
	* remote-utils.c (look_up_one_symbol): Likewise.
	* server.c (queue_stop_reply): Likewise.
	(start_inferior): Likewise.
	(queue_stop_reply_callback): Likewise.
	(handle_target_event): Likewise.
	* spu-low.c (fetch_ppc_memory): Likewise.
	(store_ppc_memory): Likewise.
	* target.c (set_target_ops): Likewise.
	* thread-db.c (thread_db_load_search): Likewise.
	(try_thread_db_load_1): Likewise.
	* tracepoint.c (add_tracepoint): Likewise.
	(add_tracepoint_action): Likewise.
	(create_trace_state_variable): Likewise.
	(cmd_qtdpsrc): Likewise.
	(cmd_qtro): Likewise.
	(add_while_stepping_state): Likewise.
	* win32-low.c (child_add_thread): Likewise.
	(get_image_name): Likewise.
2015-08-26 17:18:12 -04:00
Don Breazeal 17d8546e60 Fix native follow-exec-mode "new"
This patch fixes a segmentation fault in native GDB when
handling an exec event with follow-exec-mode set to "new".

The stack trace from the segfault was this:

 0  0x0000000000669594 in gdbarch_data (gdbarch=0x0, data=0x20da7a0)
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/gdbarch.c:4847
 1  0x00000000004d430e in get_remote_arch_state ()
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/remote.c:603
 2  0x00000000004d431e in get_remote_state ()
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/remote.c:616
 3  0x00000000004dda8b in discard_pending_stop_replies (inf=0x217c710)
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/remote.c:5775
 4  0x00000000006a5928 in observer_inferior_exit_notification_stub (
    data=0x4dda7a <discard_pending_stop_replies>, args_data=0x7fff12c258f0)
    at ./observer.inc:1137
 5  0x00000000006a419a in generic_observer_notify (subject=0x21dfbe0,
    args=0x7fff12c258f0)
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/observer.c:167
 6  0x00000000006a59ba in observer_notify_inferior_exit (inf=0x217c710)
    at ./observer.inc:1162
 7  0x00000000007981d5 in exit_inferior_1 (inftoex=0x217c710, silent=1)
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/inferior.c:244
 8  0x00000000007982f2 in exit_inferior_num_silent (num=1)
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/inferior.c:286
 9  0x000000000062f93d in follow_exec (ptid=...,
    execd_pathname=0x7fff12c259a0 "/scratch/dbreazea/sandbox/exec-nat/build/gdb/testsuite/gdb.base/execd-prog")
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/infrun.c:1195

In follow_exec we were creating a new inferior for the execd program,
as required by the exec mode, but we were doing it before calling
exit_inferior_num_silent on the original inferior.  So on entry to
exit_inferior_num_silent we had two inferiors with the same ptid.

In the calls made by exit_inferior_num_silent, the current inferior
is temporarily saved and replaced in order to make use of functions
that only operate on the current inferior (for example, in
do_all_continuations, called while deleting the threads of the original
inferior).  When we restored the original inferior, we just took the
first inferior that matched the ptid of the original and got the new
(wrong) one.  It hadn't been initialized yet and had no gdbarch
pointer, and GDB segfaulted.

The fix for that is to call exit_inferior_num_silent before adding the new
inferior, so that we never have two inferiors with the same ptid.  Then
exit_inferior_num_silent uses the original inferior as the current inferior
throughout, and can find a valid gdbarch pointer.

Once we have finished with the exit of the old inferior and added the
new one, we need to create a new thread for the new inferior.  In the
function that called follow_exec, handle_inferior_event_1,
ecs->event_thread now points to the thread that was deleted with the
exit of the original inferior.  To remedy this we create the new thread,
and once we return from follow_exec we reset ecs->event_thread.

Note that we are guaranteed that we can reset ecs->event_thread
safely using inferior_thread because we have set the current
inferior in follow_exec, and inferior_ptid was set by the call
to context_switch at the beginning of exec event handling.

gdb/ChangeLog:

	* infrun.c (follow_exec): Re-order operations for
	handling follow-exec-mode "new".
	(handle_inferior_event_1): Assign ecs->event_thread
	to the current thread.
	* remote.c (get_remote_arch_state): Add an assertion.
2015-08-26 14:07:25 -07:00
Pedro Alves abc56d60aa remote: allow aborting long operations (e.g., file transfers)
Currently, when remote debugging, if you type Ctrl-C just while the
target stopped for an internal event, and GDB is busy doing something
that takes a while (e.g., fetching chunks of a shared library off of
the target, with vFile, to process ELF headers and debug info), the
Ctrl-C is lost.

The patch hooks up the QUIT macro to a new target method that lets the
target react to the double-Ctrl-C before the event loop is reached,
which allows reacting to a double-Ctrl-C even when GDB is busy doing
some long operation and not waiting for a stop reply.  That end result
is:

 (gdb) c
 Continuing.
 ^C
 ^C
 Interrupted while waiting for the program.
 Give up waiting? (y or n) y
 Quit
 (gdb) info threads
   Id   Target Id         Frame
 * 1    Thread 11673      0x00007ffff7deb240 in _dl_debug_state () from target:/lib64/ld-linux-x86-64.so.2
 (gdb)

If, however, GDB is waiting for a stop reply (because the target has
been resumed, with e.g., vCont;c), but the target isn't responding, we
now get:

 (gdb) c
 Continuing.
 ^C
 ^C
 The target is not responding to interrupt requests.
 Stop debugging it? (y or n) y
 Disconnected from target.
 (gdb) info threads
 No threads.

This offers to disconnect, because when we're waiting for a stop
reply, there's nothing else we can send the target other than an
interrupt request.  And if that doesn't work, there's nothing else we
can do.

The Ctrl-C is presently lost because until we get to a user-visible
stop, the SIGINT handler that is installed is the one that forwards
the interrupt to the remote side, with the \003 "packet" [1].  But,
gdbserver ignores an interrupt request if the program is stopped.
Still, even if it didn't, the server can only report back a
stop-because-of-SIGINT when the program is next resumed.  And it may
take a while to actually re-resume the target.

[1] - In the old sync days, the remote target would react to a
double-Ctrl-C by asking users whether they wanted to give up waiting
and disconnect.  The code is still there, but it it isn't reacheable
on most hosts, which support serial connections in async mode
(probably only DJGPP doesn't).  Even then, in sync mode, remote.c's
SIGINT handler is only installed while the target is resumed, and is
removed as soon as the target sends back a stop reply.  That means
that a Ctrl-C just while GDB is processing an internal event can end
up with an odd "Quit" at the prompt instead of "Program stopped by
SIGINT".  In contrast, in async mode, remote.c's SIGINT handler is set
up as long as target_terminal_inferior or
target_terminal_ours_for_output are in effect (IOW, until we get a
user-visible stop and call target_terminal_ours), so the user
shouldn't get back a spurious Quit.  However, it's still desirable to
be able to interrupt a long-running GDB operation, if GDB takes a
while to re-resume the target or get back to the event loop.

Tested on x86_64 Fedora 20.

gdb/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* defs.h (maybe_quit): Declare.
	(QUIT): Now calls maybe_quit.
	* event-loop.c (clear_async_signal_handler)
	(async_signal_handler_is_marked): New functions.
	* event-loop.h (async_signal_handler_is_marked)
	(clear_async_signal_handler): New declarations.
	* remote.c (remote_check_pending_interrupt): New function.
	(interrupt_query): Use make_cleanup_restore_target_terminal.  No
	longer check whether the target is async.  If waiting for a stop
	reply, and a Ctrl-C as been sent to the target, offer to
	disconnect, and throw TARGET_CLOSE_ERROR instead of a quit.
	Otherwise do not disconnect and throw a quit.
	(_initialize_remote): Install remote_check_pending_interrupt as
	to_check_pending_interrupt.
	* target.c (target_check_pending_interrupt): New function.
	* target.h (struct target_ops) <to_check_pending_interrupt>: New
	field.
	(target_check_pending_interrupt): New declaration.
	* utils.c (maybe_quit): New function.
	* target-delegates.c: Regenerate.
2015-08-25 16:12:11 +01:00
Pedro Alves 73b8c1fda9 Add "set remote multiprocess-extensions-packet" command
Being able to force-disable the RSP multiprocess extensions is useful
for testing.

gdb/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* NEWS (New commands): Mention set/show remote
	multiprocess-extensions-packet.
	* remote.c (remote_query_supported): Only tell the server to use
	the multiprocess extensions if the user hasn't force-disabled them
	with "set remote multiprocess-extensions-packet off".

gdb/doc/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Remote Configuration): Document the "set/show
	remote multiprocess-extensions-packet" commands.
2015-08-24 19:58:31 +01:00
Pedro Alves 438e1e427e Prepare for gnulib update
After the last gnulib import (Dec 2012), gnulib upstream started
replacing mingw's 'struct timeval' with a version with 64-bit time_t,
for POSIX compliance:

 commit f8e84098084b3b53bc6943a5542af1f607ffd477
 Author: Bruno Haible <bruno@clisp.org>
 Date:   Sat Jan 28 18:12:10 2012 +0100
     sys_time: Override 'struct timeval' on some native Windows platforms.

See:

 https://lists.gnu.org/archive/html/bug-gnulib/2012-01/msg00372.html

However, that results in conflicts with native Winsock2's 'select':

select()'s argument
	http://sourceforge.net/p/mingw-w64/mailman/message/29610438/

... and libiberty's timeval-utils.h timeval_add/timeval_sub, at the
least.

We don't really need the POSIX compliance, so this patch prepares us
to simply not use gnulib's 'struct timeval' replacement once a more
recent gnulib is imported, thus preserving the current behavior, by
adding a sys/time.h wrapper header that undefs gnulib's replacements,
and including that everywhere instead.

The SIZE -> OSIZE change is necessary because newer gnulib's
sys/time.h also includes windows.h/winsock2.h, which defines a
conflicting SIZE symbol.

Cross build-tested mingw-w64 32-bit and 64-bit.
Regtested on x86_64 Fedora 20.

gdb/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* Makefile.in (HFILES_NO_SRCDIR): Add common/gdb_sys_time.h.
	* common/gdb_sys_time.h: New file.
	* event-loop.c: Include gdb_sys_time.h instead of sys/time.h.
	* gdb_select.h: Likewise.
	* gdb_usleep.c: Likewise.
	* maint.c: Likewise.
	* mi/mi-main.c: Likewise.
	* mi/mi-parse.h: Likewise.
	* remote-fileio.c: Likewise.
	* remote-m32r-sdi.c: Likewise.
	* remote.c: Likewise.
	* ser-base.c: Likewise.
	* ser-pipe.c: Likewise.
	* ser-tcp.c: Likewise.
	* ser-unix.c: Likewise.
	* symfile.c: Likewise.
	* symfile.c: Likewise.  Rename OSIZE to SIZE throughout.
	* target-memory.c: Include gdb_sys_time.h instead of sys/time.h.
	* utils.c: Likewise.

gdb/gdbserver/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* debug.c: Include gdb_sys_time.h instead of sys/time.h.
	* event-loop.c: Likewise.
	* remote-utils.c: Likewise.
	* tracepoint.c: Likewise.
2015-08-24 18:50:55 +01:00
Gary Benson 4313b8c0ed Warn when accessing binaries from remote targets
GDB provides no indicator of progress during file operations, and can
appear to have locked up during slow remote transfers.  This commit
updates GDB to print a warning each time a file is accessed over RSP.
An additional message detailing how to avoid remote transfers is
printed for the first transfer only.

gdb/ChangeLog:

	* target.h (struct target_ops) <to_fileio_open>: New argument
	warn_if_slow.  Update comment.  All implementations updated.
	(target_fileio_open_warn_if_slow): New declaration.
	* target.c (target_fileio_open): Renamed as...
	(target_fileio_open_1): ...this.  New argument warn_if_slow.
	Pass warn_if_slow to implementation.  Update debug printing.
	(target_fileio_open): New function.
	(target_fileio_open_warn_if_slow): Likewise.
	* gdb_bfd.c (gdb_bfd_iovec_fileio_open): Use new function
	target_fileio_open_warn_if_slow.

gdb/testsuite/ChangeLog:

	* gdb.trace/pending.exp: Cope with remote transfer warnings.
2015-08-21 17:11:36 +01:00
Pedro Alves 80152258b9 Add readahead cache to gdb's vFile:pread
This patch almost halves the time it takes to "target remote + run to
main" on a higher-latency connection.

E.g., I've got a ping time of ~85ms to an x86-64 machine on the gcc
compile farm (almost 2000km away from me), and I'm behind a ~16Mbit
ADSL.  When I connect to a gdbserver debugging itself on that machine
and run to main, it takes almost 55 seconds:

 [palves@gcc76] $ ./gdbserver :9999 ./gdbserver
 [palves@home] $ ssh -L 9999:localhost:9999 gcc76.fsffrance.org
 [palves@home] $ time ./gdb -data-directory=data-directory -ex "tar rem :9999" -ex "b main" -ex "c" -ex "set confirm off" -ex "quit"

 Pristine gdb 7.10.50.20150820-cvs gets us:
 ...
 Remote debugging using :9999
 Reading symbols from target:/home/palves/gdb/build/gdb/gdbserver/gdbserver...done.
 Reading symbols from target:/lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
 0x00007ffff7ddd190 in ?? () from target:/lib64/ld-linux-x86-64.so.2
 Breakpoint 1 at 0x41200c: file ../../../src/gdb/gdbserver/server.c, line 3635.
 Continuing.

 Breakpoint 1, main (argc=1, argv=0x7fffffffe3d8) at ../../../src/gdb/gdbserver/server.c:3635
 3635    ../../../src/gdb/gdbserver/server.c: No such file or directory.
 /home/palves/gdb/build/gdb/gdbserver/gdbserver: No such file or directory.

 real    0m54.803s
 user    0m0.329s
 sys     0m0.064s

While with the readahead cache added by this patch, it drops to:

 real    0m29.462s
 user    0m0.454s
 sys     0m0.054s

I added a few counters to show cache hit/miss, and got:

 readahead cache miss 142
 readahead cache hit 310

Tested on x86_64 Fedora 20.

gdb/ChangeLog:
2015-08-21  Pedro Alves  <palves@redhat.com>

	* remote.c (struct readahead_cache): New.
	(struct remote_state) <readahead_cache>: New field.
	(remote_open_1): Invalidate the cache.
	(readahead_cache_invalidate, readahead_cache_invalidate_fd): New
	functions.
	(remote_hostio_pwrite): Invalidate the readahead cache.
	(remote_hostio_pread): Rename to ...
	(remote_hostio_pread_vFile): ... this.
	(remote_hostio_pread_from_cache): New function.
	(remote_hostio_pread): Reimplement.
	(remote_hostio_close): Invalidate the readahead cache.
2015-08-21 10:13:27 +01:00
Pedro Alves 221e1a37cd remote non-stop: Process initially stopped threads before other commands
The main motivation for this is making non-stop / all-stop behave
similarly on initial connection, in order to move in the direction of
reimplementing all-stop mode with the remote target always running in
non-stop mode.

When we connect to a remote target in non-stop mode, we may find
threads either running or already stopped.  The act of connecting
itself does not force threads to stop.  To handle that, the remote
non-stop connection is currently roughly like this:

 #1 - Fetch list of remote threads (qXfer:threads:read, qfThreadInfo,
    etc).  All threads are assumed to be running until the target
    reports an asynchronous stop reply for them.

 #2 - Fetch the initial set of threads that were already stopped, with
    the '?'  packet.  (In non-stop, this is coupled with the vStopped
    mechanism to be able to retrieve the status of more than one
    thread.)

The stop replies fetched in #2 are placed in the pending stop reply
queue, and left for the regular event loop to process.  That is,
"target remote" finishes and returns _before_ those stops are
processed.

That means that it's possible to have GDB process further commands
before the initial set of stopped threads is reported to the user.

E.g., before the patch, note how the prompt is printed before the
frame:

 Remote debugging using :9999
 (gdb)
 [Thread 15296] #1 stopped.
 0x0000003615a011f0 in ?? ()

Even though thread #1 was not running, for a moment, the user can see
it as such:

 $ gdb a.out -ex "set non-stop 1" -ex "tar rem :9999"  -ex "info threads" -ex "info registers"
 Remote debugging using :9999
   Id   Target Id         Frame
 * 1    Thread 4772       (running)
 Target is executing.                 <<<<<<< info registers
 (gdb)
 [Thread 4772] #1 stopped.
 0x0000003615a011f0 in ?? ()

To fix that, this commit makes gdb process all threads found already
stopped at connection time, before giving the prompt to the user.

The fix takes a cue from fork-child.c:startup_inferior [1], and
processes the events locally in remote.c, avoiding the whole
wait_for_inferior/handle_inferior_event path.  I decided to try this
approach after noticing that:

 - several cases in handle_inferior_event miss checking stop_soon.
 - we don't want to fetch the thread list in normal_stop.

and trying to fix them was resulting in sprinkling stop_soon checks in
many places, and uglifying normal_stop even more.

While with this patch, I'm avoiding changing GDB's output other than
when the prompt is printed, I think this approach is more flexible if
we do want to change it.  And also, it's likely easier to get rid of
the MI *running event that is still sent for threads that are
initially found stopped, if we want to.

This happens to fix the testsuite too.  All non-stop tests are racy
against "target remote" / gdbserver testing currently.  That is,
sometimes the tests run, but other times they're just skipped without
any indication of PASS/FAIL.  When that happens, the logs show:

 target remote localhost:2346
 Remote debugging using localhost:2346
 (gdb)
 [Thread 25418] #1 stopped.
 0x0000003615a011f0 in ?? ()
 ^CQuit
 (gdb) Remote debugging from host 127.0.0.1
 Killing process(es): 25418
 monitor exit
 (gdb) Remote connection closed
 (gdb) testcase /home/pedro/gdb/mygit/build/../src/gdb/testsuite/gdb.threads/multi-create-ns-info-thr.exp completed in 61 seconds

The trouble here is that there's output after the prompt, and the
regex in question doesn't expect that:

   -re "Remote debugging using .*$serialport_re.*$gdb_prompt $" {
	verbose "Set target to $targetname"
	return 0
    }

[1] - before startup_inferior was added, we'd go through
wait_for_inferior/handle_inferior_event while going through the shell,
and that turned out problematic.

Tested on x86_64 Fedora 20, gdbserver.

gdb/ChangeLog:
2015-08-20  Pedro Alves  <palves@redhat.com>

	* infrun.c (print_target_wait_results): Make extern.
	* infrun.h (print_target_wait_results): Declare.
	* remote.c (set_stop_requested_callback): Delete.
	(process_initial_stop_replies): New function.
	(remote_start_remote): Use it.
	(stop_reply_queue_length): New function.

gdb/testsuite/ChangeLog:
2015-08-20  Pedro Alves  <palves@redhat.com>

	* gdb.server/connect-stopped-target.c: New file.
	* gdb.server/connect-stopped-target.exp: New file.
2015-08-20 18:27:55 +01:00
Sandra Loosemore 26d56a939e Fix mis-parsing of hex register numbers in 'T' stop replies.
2015-08-18  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/
	* remote.c (strprefix): New.
	(remote_parse_stop_reply): Use strprefix instead of strncmp
	to ensure exact match of keyword.
2015-08-18 10:29:54 -07:00
Keith Seitz f00aae0f7b Explicit locations: use new location API
This patch converts the code base to use the new struct event_location
API being introduced. This patch preserves the current functionality and
adds no new features.

The "big picture" API usage introduced by this patch may be illustrated
with a simple exmaple. Where previously developers would write:

void
my_command (char *arg, int from_tty)
{
   create_breakpoint (..., arg, ...);
   ...
}

one now uses:

void
my_command (char *arg, int from_tty)
{
   struct event_locaiton *location;
   struct cleanup *back_to;

   location = string_to_event_locaiton (&arg, ...);
   back_to = make_cleanup_delete_event_location (location);
   create_breakpoint (..., location, ...);
   do_cleanups (back_to);
}

Linespec-decoding functions (now called location-decoding) such as
decode_line_full no longer skip argument pointers over processed input.
That functionality has been moved into string_to_event_location as
demonstrated above.

gdb/ChangeLog

	* ax-gdb.c: Include location.h.
	(agent_command_1) Use linespec location instead of address
	string.
	* break-catch-throw.c: Include location.h.
	(re_set_exception_catchpoint): Use linespec locations instead
	of address strings.
	* breakpoint.c: Include location.h.
	(create_overlay_event_breakpoint, create_longjmp_master_breakpoint)
	(create_std_terminate_master_breakpoint)
	(create_exception_master_breakpoint, update_breakpoints_after_exec):
	Use linespec location instead of address string.
	(print_breakpoint_location):  Use locations and
	event_location_to_string.
	Print extra_string for pending locations for non-MI streams.
	(print_one_breakpoint_location): Use locations and
	event_location_to_string.
	(init_raw_breakpoint_without_location): Initialize b->location.
	(create_thread_event_breakpoint): Use linespec location instead of
	address string.
	(init_breakpoint_sal): Likewise.
	Only save extra_string if it is non-NULL and not the empty string.
	Use event_location_to_string instead of `addr_string'.
	Constify `p' and `endp'.
	Use skip_spaces_const/skip_space_const instead of non-const versions.
	Copy the location into the breakpoint.
	If LOCATION is NULL, save the breakpoint address as a linespec location
	instead of an address string.
	(create_breakpoint_sal): Change `addr_string' parameter to a struct
	event_location. All uses updated.
	(create_breakpoints_sal): Likewise for local variable `addr_string'.
	(parse_breakpoint_sals): Use locations instead of address strings.
	Remove check for empty linespec with conditional.
	Refactor.
	(decode_static_tracepoint_spec): Make argument const and update
	function.
	(create_breakpoint): Change `arg' to a struct event_location and
	rename.
	Remove `copy_arg' and `addr_start'.
	If EXTRA_STRING is empty, set it to NULL.
	Don't populate `canonical' for pending breakpoints.
	Pass `extra_string' to find_condition_and_thread.
	Clear `extra_string' if `rest' was NULL.
	Do not error with "garbage after location" if setting a dprintf
	breakpoint.
	Copy the location into the breakpoint instead of an address string.
	(break_command_1): Use string_to_event_location and pass this to
	create_breakpoint instead of an address string.
	Check against `arg_cp' for a probe linespec.
	(dprintf_command): Use string_to_event_location and pass this to
	create_breakpoint instead of an address string.
	Throw an exception if no format string was specified.
	(print_recreate_ranged_breakpoint): Use event_location_to_string
	instead of address strings.
	(break_range_command, until_break_command)
	(init_ada_exception_breakpoint): Use locations instead
	of address strings.
	(say_where): Print out extra_string for pending locations.
	(base_breakpoint_dtor): Delete `location' and `location_range_end' of
	the breakpoint.
	(base_breakpoint_create_sals_from_location): Use struct event_location
	instead of address string.
	Remove `addr_start' and `copy_arg' parameters.
	(base_breakpoint_decode_location): Use struct event_location instead of
	address string.
	(bkpt_re_set): Use locations instead of address strings.
	Use event_location_empty_p to check for unset location.
	(bkpt_print_recreate): Use event_location_to_string instead of
	an address string.
	Print out extra_string for pending locations.
	(bkpt_create_sals_from_location, bkpt_decode_location)
 	(bkpt_probe_create_sals_from_location): Use struct event_location
	instead of address string.
	(bkpt_probe_decode_location): Use struct event_location instead of
	address string.
	(tracepoint_print_recreate): Use event_location_to_string to
	recreate the tracepoint.
	(tracepoint_create_sals_from_location, tracepoint_decode_location)
	(tracepoint_probe_create_sals_from_location)
	(tracepoint_probe_decode_location): Use struct event_location
	instead of address string.
	(dprintf_print_recreate): Use event_location_to_string to recreate
	the dprintf.
	(dprintf_re_set): Remove check for valid/missing format string.
	(strace_marker_create_sals_from_location)
	(strace_marker_create_breakpoints_sal, strace_marker_decode_location)
	(update_static_tracepoint): Use struct event_location instead of
	address string.
	(location_to_sals): Likewise.
	Pass `extra_string' to find_condition_and_thread.
	For newly resolved pending breakpoint locations, clear the location's
	string representation.
	Assert that the breakpoint's condition string is NULL when
	condition_not_parsed.
	(breakpoint_re_set_default, create_sals_from_location_default)
	(decode_location_default, trace_command, ftrace_command)
	(strace_command, create_tracepoint_from_upload): Use locations
	instead of address strings.
	* breakpoint.h (struct breakpoint_ops) <create_sals_from_location>:
	Use struct event_location instead of address string.
	Update all uses.
	<decode_location>: Likewise.
	(struct breakpoint) <addr_string>: Change to struct event_location
	and rename `location'.
	<addr_string_range_end>: Change to struct event_location and rename
	`location_range_end'.
	(create_breakpoint): Use struct event_location instead of address
	string.
	* cli/cli-cmds.c: Include location.h.
	(edit_command, list_command): Use locations instead of address strings.
	* elfread.c: Include location.h.
	(elf_gnu_ifunc_resolver_return_stop): Use event_location_to_string.
	* guile/scm-breakpoint.c: Include location.h.
	(bpscm_print_breakpoint_smob): Use event_location_to_string.
	(gdbscm_register_breakpoint): Use locations instead of address
	strings.
	* linespec.c: Include location.h.
	(struct ls_parser) <stream>: Change to const char *.
	(PARSER_STREAM): Update.
	(lionespec_lexer_lex_keyword): According to find_condition_and_thread,
	keywords must be followed by whitespace.
	(canonicalize_linespec): Save a linespec location into `canonical'.
	Save a canonical linespec into `canonical'.
	(parse_linespec): Change `argptr' to const char * and rename `arg'.
	All uses updated.
	Update function description.
	(linespec_parser_new): Initialize `parser'.
	Update initialization of  parsing stream.
	(event_location_to_sals): New function.
	(decode_line_full): Change `argptr' to a struct event_location and
	rename it `location'.
	Use locations instead of address strings.
	Call event_location_to_sals instead of parse_linespec.
	(decode_line_1): Likewise.
	(decode_line_with_current_source, decode_line_with_last_displayed)
	Use locations instead of address strings.
	(decode_objc): Likewise.
	Change `argptr' to const char * and rename `arg'.
	(destroy_linespec_result): Delete the linespec result's location
	instead of freeing the address string.
	* linespec.h (struct linespec_result) <addr_string>: Change to
	struct event_location and rename to ...
	<location>: ... this.
	(decode_line_1, decode_line_full): Change `argptr' to struct
	event_location.  All callers updated.
	* mi/mi-cmd-break.c: Include language.h, location.h, and linespec.h.
	(mi_cmd_break_insert_1): Use locations instead of address strings.
	Throw an error if there was "garbage" at the end of the specified
	linespec.
	* probe.c: Include location.h.
	(parse_probes): Change `argptr' to struct event_location.
	Use event locations instead of address strings.
	* probe.h (parse_probes): Change `argptr' to struct event_location.
	* python/py-breakpoint.c: Include location.h.
	(bppy_get_location): Constify local variable `str'.
	Use event_location_to_string.
	(bppy_init): Use locations instead of address strings.
	* python/py-finishbreakpoint.c: Include location.h.
	(bpfinishpy_init): Remove local variable `addr_str'.
	Use locations instead of address strings.
	* python/python.c: Include location.h.
	(gdbpy_decode_line): Use locations instead of address strings.
	* remote.c: Include location.h.
	(remote_download_tracepoint): Use locations instead of address
	strings.
	* spu-tdep.c: Include location.h.
	(spu_catch_start): Remove local variable `buf'.
	Use locations instead of address strings.
	* tracepoint.c: Include location.h.
	(scope_info): Use locations instead of address strings.
	(encode_source_string): Constify parameter `src'.
	* tracepoint.h (encode_source_string): Likewise.

gdb/testsuite/ChangeLog

	* gdb.base/dprintf-pending.exp: Update dprintf "without format"
	test.
	Add tests for missing ",FMT" and ",".
2015-08-11 17:09:35 -07:00
Pedro Alves bfedc46af3 Fix interrupt-noterm.exp on targets always in non-stop
With "maint set target-non-stop on" we get:

 @@ -66,13 +66,16 @@ Continuing.
  interrupt
  (gdb) PASS: gdb.base/interrupt-noterm.exp: interrupt

 -Program received signal SIGINT, Interrupt.
 -PASS: gdb.base/interrupt-noterm.exp: inferior received SIGINT
 -testcase src/gdb/testsuite/gdb.base/interrupt-noterm.exp completed in 0 seconds
 +[process 12119] #1 stopped.
 +0x0000003615ebc6d0 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81
 +81     T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
 +FAIL: gdb.base/interrupt-noterm.exp: inferior received SIGINT (timeout)
 +testcase src/gdb/testsuite/gdb.base/interrupt-noterm.exp completed in 10 seconds

That is, we get "[$thread] #1 stopped" instead of SIGINT.

The issue is that we don't currently distinguish send
"interrupt/ctrl-c" to target terminal vs "stop/pause" thread well;
both cases go through "target_stop".

And then, the native Linux backend (linux-nat.c) implements
target_stop with SIGSTOP in non-stop mode, and SIGINT in all-stop
mode.  Since "maint set target-non-stop on" forces the backend to be
always running in non-stop mode, even though the user-visible behavior
is "set non-stop" is "off", "interrupt" causes a SIGSTOP instead of
the SIGINT the test expects.

Fix this by introducing a target_interrupt method to use in the
"interrupt/ctrl-c" case, so "set non-stop off" can always work the
same irrespective of "maint set target-non-stop on/off".  I'm
explictly considering changing the "set non-stop on" behavior as out
of scope here.

Most of the patch is an across-the-board rename of to_stop hook
implementations to to_interrupt.  The only targets where something
more than a rename is being done are linux-nat.c and remote.c, which
are the only targets that support async, and thus are the only ones
the core side calls target_stop on.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* darwin-nat.c (darwin_stop): Rename to ...
	(darwin_interrupt): ... this.
	(_initialize_darwin_inferior): Adjust.
	* gnu-nat.c (gnu_stop): Delete.
	(gnu_target): Don't install gnu_stop.
	* inf-ptrace.c (inf_ptrace_stop): Rename to ...
	(inf_ptrace_interrupt): ... this.
	(inf_ptrace_target): Adjust.
	* infcmd.c (interrupt_target_1): Use target_interrupt instead of
	target_stop.
	* linux-nat (linux_nat_stop): Rename to ...
	(linux_nat_interrupt): ... this.
	(linux_nat_stop): Reimplement.
	(linux_nat_add_target): Install linux_nat_interrupt.
	* nto-procfs.c (nto_interrupt_twice): Rename to ...
	(nto_handle_sigint_twice): ... this.
	(nto_interrupt): Rename to ...
	(nto_handle_sigint): ... this.  Call target_interrupt instead of
	target_stop.
	(procfs_wait): Adjust.
	(procfs_stop): Rename to ...
	(procfs_interrupt): ... this.
	(init_procfs_targets): Adjust.
	* procfs.c (procfs_stop): Rename to ...
	(procfs_interrupt): ... this.
	(procfs_target): Adjust.
	* remote-m32r-sdi.c (m32r_stop): Rename to ...
	(m32r_interrupt): ... this.
	(init_m32r_ops): Adjust.
	* remote-sim.c (gdbsim_stop_inferior): Rename to ...
	(gdbsim_interrupt_inferior): ... this.
	(gdbsim_stop): Rename to ...
	(gdbsim_interrupt): ... this.
	(gdbsim_cntrl_c): Adjust.
	(init_gdbsim_ops): Adjust.
	* remote.c (sync_remote_interrupt): Adjust comments.
	(remote_stop_as): Rename to ...
	(remote_interrupt_as): ... this.
	(remote_stop): Adjust comment.
	(remote_interrupt): New function.
	(init_remote_ops): Install remote_interrupt.
	* target.c (target_interrupt): New function.
	* target.h (struct target_ops) <to_interrupt>: New field.
	(target_interrupt): New declaration.
	* windows-nat.c (windows_stop): Rename to ...
	(windows_interrupt): ... this.
	* target-delegates.c: Regenerate.
2015-08-07 17:26:20 +01:00
Pedro Alves 567420d108 remote.c/all-stop: Implement TARGET_WAITKIND_NO_RESUMED and TARGET_WNOHANG
Even though "target remote" supports target-async, the all-stop
target_wait implementation ignores TARGET_WNOHANG.  If the core
happens to poll for events and we've already read the stop reply out
of the serial/socket, remote_wait_as hangs forever instead of
returning an indication that there are no events to process.  This
can't happen currently, but later changes will trigger this.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_wait_as): If not waiting for a stop reply,
	return TARGET_WAITKIND_NO_RESUMED.  If TARGET_WNOHANG is
	requested, don't block waiting forever.
2015-08-07 17:23:56 +01:00
Simon Marchi f486487f55 Mostly trivial enum fixes
This is a patch I extracted from Pedro's C++ branch.  It contains the
most trivial enum fixes, where an integer type/value was used instead
of the appropriate enum type/value.  It fixes many C++ errors, since
in C++ you can't mix integers and enums implicitely.

Regardless of the C++ conversion, I think this is a good cleanup to make
use of the appropriate enum types.

Regression-tested on native x86_64.

gdb/ChangeLog:

	* aarch64-linux-nat.c (aarch64_linux_can_use_hw_breakpoint): Use enum
	type or value instead of integer.
	(aarch64_linux_insert_watchpoint): Likewise.
	(aarch64_linux_remove_watchpoint): Likewise.
	* ada-lang.c (ada_op_print_tab): Likewise.
	* amd64-linux-tdep.c (amd64_canonicalize_syscall): Likewise.
	(amd64_linux_syscall_record_common): Likewise.
	* arch-utils.c (target_byte_order_user): Likewise.
	(default_byte_order): Likewise.
	* arm-linux-nat.c (arm_linux_can_use_hw_breakpoint): Likewise.
	(arm_linux_get_hwbp_type): Likewise.
	(arm_linux_hw_watchpoint_initialize): Likewise.
	(arm_linux_insert_watchpoint): Likewise.
	* arm-linux-tdep.c (arm_canonicalize_syscall): Likewise.
	(arm_linux_syscall_record): Likewise.
	* breakpoint.c (update_watchpoint): Likewise.
	(breakpoint_here_p): Likewise.
	(bpstat_print): Likewise.
	(enable_breakpoint_disp): Likewise.
	* c-lang.c (c_op_print_tab): Likewise.
	* cli/cli-decode.c (add_info_alias): Likewise.
	* d-lang.c (d_op_print_tab): Likewise.
	* eval.c (evaluate_subexp_standard): Likewise.
	* f-exp.y (dot_ops): Likewise.
	(f77_keywords): Likewise.
	* f-lang.c (f_op_print_tab): Likewise.
	* go-lang.c (go_op_print_tab): Likewise.
	* guile/scm-breakpoint.c (gdbscm_make_breakpoint): Likewise.
	* guile/scm-cmd.c (gdbscm_make_command): Likewise.
	* guile/scm-param.c (gdbscm_make_parameter): Likewise.
	* guile/scm-pretty-print.c (gdbscm_apply_val_pretty_printer): Likewise.
	* guile/scm-string.c (struct scm_to_stringn_data): Likewise.
	(struct scm_from_stringn_data): Likewise.
	* i386-linux-tdep.c (i386_canonicalize_syscall): Likewise.
	* ia64-linux-nat.c (ia64_linux_insert_watchpoint): Likewise.
	(ia64_linux_remove_watchpoint): Likewise.
	(ia64_linux_can_use_hw_breakpoint): Likewise.
	* infrun.c (print_stop_event): Likewise.
	* jv-lang.c (java_op_print_tab): Likewise.
	* linux-nat.c (linux_proc_xfer_partial): Likewise.
	* linux-nat.h (struct lwp_info): Likewise.
	* linux-thread-db.c (enable_thread_event): Likewise.
	* m2-lang.c (m2_op_print_tab): Likewise.
	* mi/mi-cmd-stack.c (mi_cmd_stack_list_locals): Likewise.
	(mi_cmd_stack_list_variables): Likewise.
	* mi/mi-main.c (mi_cmd_trace_frame_collected): Likewise.
	* mi/mi-out.c (mi_table_begin): Likewise.
	(mi_table_header): Likewise.
	* mips-linux-nat.c (mips_linux_can_use_hw_breakpoint): Likewise.
	(mips_linux_insert_watchpoint): Likewise.
	(mips_linux_remove_watchpoint): Likewise.
	* nat/mips-linux-watch.c (mips_linux_watch_type_to_irw): Likewise.
	* nat/mips-linux-watch.h (struct mips_watchpoint): Likewise.
	(mips_linux_watch_type_to_irw): Likewise.
	* nto-procfs.c (procfs_can_use_hw_breakpoint): Likewise.
	(procfs_insert_hw_watchpoint): Likewise.
	(procfs_remove_hw_watchpoint): Likewise.
	(procfs_hw_watchpoint): Likewise.
	(procfs_can_use_hw_breakpoint): Likewise.
	(procfs_remove_hw_watchpoint): Likewise.
	(procfs_insert_hw_watchpoint): Likewise.
	* p-lang.c (pascal_op_print_tab): Likewise.
	* ppc-linux-nat.c (ppc_linux_can_use_hw_breakpoint): Likewise.
	* ppc-linux-tdep.c (ppu2spu_unwind_register): Likewise.
	* ppc-sysv-tdep.c (get_decimal_float_return_value): Likewise.
	* procfs.c (procfs_can_use_hw_breakpoint): Likewise.
	(procfs_insert_watchpoint): Likewise.
	(procfs_remove_watchpoint): Likewise.
	* psymtab.c (recursively_search_psymtabs): Likewise.
	* remote-m32r-sdi.c (m32r_can_use_hw_watchpoint): Likewise.
	(m32r_insert_watchpoint): Likewise.
	* remote-mips.c (mips_can_use_watchpoint): Likewise.
	(mips_insert_watchpoint): Likewise.
	(mips_remove_watchpoint): Likewise.
	* remote.c (watchpoint_to_Z_packet): Likewise.
	(remote_insert_watchpoint): Likewise.
	(remote_remove_watchpoint): Likewise.
	(remote_check_watch_resources): Likewise.
	* s390-linux-nat.c (s390_insert_watchpoint): Likewise.
	(s390_remove_watchpoint): Likewise.
	(s390_can_use_hw_breakpoint): Likewise.
	* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
	* spu-linux-nat.c (spu_can_use_hw_breakpoint): Likewise.
	* target.h (struct target_ops): Likewise.
	* tilegx-tdep.c (tilegx_analyze_prologue): Likewise.
	* ui-out.c (struct ui_out_hdr): Likewise.
	(append_header_to_list): Likewise.
	(get_next_header): Likewise.
	(verify_field): Likewise.
	(ui_out_begin): Likewise.
	(ui_out_field_int): Likewise.
	(ui_out_field_fmt_int): Likewise.
	(ui_out_field_skip): Likewise.
	(ui_out_field_string): Likewise.
	(ui_out_field_fmt): Likewise.
	* varobj.c (new_variable): Likewise.
	* x86-nat.c (x86_insert_watchpoint): Likewise.
	(x86_remove_watchpoint): Likewise.
	(x86_can_use_hw_breakpoint): Likewise.
	* xtensa-tdep.h (struct gdbarch_tdep): Likewise.
	* inflow.c (enum gdb_has_a_terminal_flag_enum): Add name to
	previously anonymous enumeration type..
	* linux-record.h (enum gdb_syscall): Add gdb_sys_no_syscall
	value.
	* target-debug.h (target_debug_print_enum_target_hw_bp_type): New.
	(target_debug_print_enum_bptype): New.
	* target-delegates.c: Regenerate.
2015-07-31 13:19:53 -04:00
Pierre Langlois 6b940e6a06 Remove isize output argument from fast_tracepoint_valid_at
This patch removes the isize output argument from the
fast_tracepoint_valid_at gdbarch hook.  It was used to return the size
of the instruction that needs to be replaced when installing a fast
tracepoint.  Instead of getting this value from the
fast_tracepoint_valid_at hook, we can call the gdb_insn_length function.

If we do not do this, then architectures which do not have a restriction
on where to install the fast tracepoint will send uninitialized memory
off to GDBserver.  See remote_download_tracepoint:

~~~
int isize;

if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
				      tpaddr, &isize, NULL))
  xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":F%x",
	     isize);
~~~

The default implementation of fast_tracepoint_valid_at will not set
isize resulting in uninitialized memory being sent.  Later on, GDBserver
could use this information to compute a jump offset.

gdb/ChangeLog:

	* arch-utils.c (default_fast_tracepoint_valid_at): Remove unused
	isize argument.
	* arch-utils.h (default_fast_tracepoint_valid_at): Likewise.
	* breakpoint.c (check_fast_tracepoint_sals): Adjust call to
	gdbarch_fast_tracepoint_valid_at.
	* gdbarch.sh (fast_tracepoint_valid_at): Remove isize argument.
	* gdbarch.h: Regenerate.
	* gdbarch.c: Regenerate.
	* i386-tdep.c (i386_fast_tracepoint_valid_at): Remove isize
	argument.  Do not set it.
	* remote.c (remote_download_tracepoint): Adjust call to
	gdbarch_fast_tracepoint_valid_at.  Call gdb_insn_length to get
	the instruction length.
2015-07-30 18:05:00 +01:00
Kevin Buettner c9f35b348e remote.c: Make read_ptid return a null value when no thread id is found.
When using GDB to debug an RX target using the GDB remote protocol,
using a Renesas supplied debug agent, I encountered the following
assertion error:

thread.c:85: internal-error: inferior_thread: Assertion `tp' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n
Command aborted.

This assertion error occurs due to the fact that the value associated
with inferior_ptid is not on the thread list.

The remote debug output (obtained with "set debug remote 1") is fairly
short, so I will include it up to the point where things go wrong -
which is somewhat before the assertion failure:

    (gdb) target remote coyote.lan:61234
    Remote debugging using coyote.lan:61234
    Sending packet: $qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+#c9...Ack
    Packet received: PacketSize=c00;qXfer:memory-map:read-;qXfer:features:read-;QStartNoAckMode+;multiprocess+;QNonStop+
    Packet qSupported (supported-packets) is supported
    Sending packet: $QStartNoAckMode#b0...Ack
    Packet received: OK
    Sending packet: $Hgp0.0#ad...Packet received: OK
    Sending packet: $QNonStop:0#8c...Packet received: OK
    Sending packet: $qTStatus#49...Packet received:
    Packet qTStatus (trace-status) is NOT supported
    Sending packet: $?#3f...Packet received: S02
    Sending packet: $qfThreadInfo#bb...Packet received: m1
    Sending packet: $qsThreadInfo#c8...Packet received: l
    Sending packet: $qAttached:a410#bf...Packet received: 0
    Packet qAttached (query-attached) is supported
    Sending packet: $Hc-1#09...Packet received: OK
    Sending packet: $qC#b4...Packet received: QC not supported

Above is the trace starting from the invocation of "target remote"
through the call of get_current_thread() in remote_start_remote().
Below, I've pasted this line of code along with additional lines of
context.  The test following the call is especially important to
understanding both the problem and my patch.

          /* We have thread information; select the thread the target
             says should be current.  If we're reconnecting to a
             multi-threaded program, this will ideally be the thread
             that last reported an event before GDB disconnected.  */
          inferior_ptid = get_current_thread (wait_status);
          if (ptid_equal (inferior_ptid, null_ptid))
            {
              /* Odd... The target was able to list threads, but not
                 tell us which thread was current (no "thread"
                 register in T stop reply?).  Just pick the first
                 thread in the thread list then.  */
              inferior_ptid = thread_list->ptid;
            }
        }

Prior to getting to the code pasted above, remote_start_remote()
made a call to target_update_thread_list().  This corresponds to the
following lines from the above trace:

    Sending packet: $qfThreadInfo#bb...Packet received: m1
    Sending packet: $qsThreadInfo#c8...Packet received: l
    Sending packet: $qAttached:a410#bf...Packet received: 0
    Packet qAttached (query-attached) is supported

Once target_update_thread_list has completed, the thread list
contains a single entry: {pid = 42000, lwp = 1, tid = 0}.

remote_start_remote() then makes a call to set_continue_thread(),
accounting for this line of the trace:

    Sending packet: $Hc-1#09...Packet received: OK

Finally, the call to get_current_thread() is responsible for the last
line of the trace that I provided above:

    Sending packet: $qC#b4...Packet received: QC not supported

get_current_thread() calls stop_reply_extract_thread() with the wait
status. This returns null_ptid.

get_current_thread() then calls remote_current_thread with a null
inferior_ptid.  After the calls to putpkt() and getpkt(), rs->buf[0]
is 'Q', so read_ptid() is called and its result is returned.

The buffer passed to read_ptid() is " not supported".  read_ptid ultimately
returns a ptid of {pid = 4200, lwp = 0, tid = 0}.

However, this thread is not on the thread list.  As noted earlier, the
call to target_update_thread_list() had placed {pid = 42000, lwp = 1,
tid = 0} on the list.  This is the only thread in the list.

When these calls ultimately return to remote_start_remote(),
inferior_ptid gets set to {pid = 4200, lwp = 0, tid = 0}, which
(again) is not on the thread list.

It appears to me that the string " not supported" is coming from the
debug agent.  If so, it should be fixed, but I don't see a reason to
not consult the thread list in order to place a valid thread id in
inferior_ptid.

This (consultation of the thread list) is what is done when
inferior_ptid is null_ptid:

	  if (ptid_equal (inferior_ptid, null_ptid))
	    {
	      /* Odd... The target was able to list threads, but not
		 tell us which thread was current (no "thread"
		 register in T stop reply?).  Just pick the first
		 thread in the thread list then.  */
	      inferior_ptid = thread_list->ptid;
	    }

My patch causes a null inferior_ptid to be returned by read_ptid when
no thread id is found in the response from the debug agent.  This
return value ends up being returned by remote_current_thread() and
then by get_current_thread.  The assignment then places this null
value into inferior_ptid.  That, in turn, allows the ptid_equal test
(noted above) to fetch a valid thread from the thread list.  I no
longer see the assertion failure due a good value (which is on the
thread list) being placed in inferior_ptid.

This patch also adds two log warnings that may be output when "set
debug remote 1" is used.  When running against the Renesas debug agent
mentioned earlier, this is the relevant portion of the log output:

Sending packet: $qC#b4...Packet received: QC not supported
warning: garbage in qC reply
warning: couldn't determine remote current thread; picking first in list.

gdb/ChangeLog:

	* remote.c (read_ptid): Return null_ptid when no thread id
	is found.
	(remote_current_thread): Add log warning for malformed
	qC reply.
	(remote_start_remote): Add log warning when current thread
	not found.
2015-07-25 22:02:27 -07:00
Yao Qi 6a49a997b4 Fix using uninitialised values
We did a code refacotr here
https://sourceware.org/ml/gdb-patches/2013-11/msg00063.html

>	(get_current_thread): New function, factored out from ...
>	(add_current_inferior_and_thread): ... this.  Adjust.
>
>@@ -3332,18 +3371,8 @@ add_current_inferior_and_thread (char *wait_status)
>
>   inferior_ptid = null_ptid;
>
>-  /* Now, if we have thread information, update inferior_ptid.  First
>-     if we have a stop reply handy, maybe it's a T stop reply with a
>-     "thread" register we can extract the current thread from.  If
>-     not, ask the remote which is the current thread, with qC.  The
>-     former method avoids a roundtrip.  Note we don't use
>-     remote_parse_stop_reply as that makes use of the target
>-     architecture, which we haven't yet fully determined at this
>-     point.  */
>-  if (wait_status != NULL)
>-    ptid = stop_reply_extract_thread (wait_status);
>-  if (ptid_equal (ptid, null_ptid))
>-    ptid = remote_current_thread (inferior_ptid);
>+  /* Now, if we have thread information, update inferior_ptid.  */
>+  ptid = get_current_thread (wait_status);

but after the refactor, local variable ptid is used without
initialisation.  However, before this change, ptid is initialised to
null_ptid.  This error can be found by valgrind too...

==3298==    at 0x6B99BA: ptid_equal (ptid.c:80)
==3298==    by 0x4C67FF: get_current_thread (remote.c:3484)
==3298==    by 0x4C6951: add_current_inferior_and_thread (remote.c:3511)
==3298==    by 0x4C762C: extended_remote_create_inferior (remote.c:8506)
==3298==    by 0x5A5312: run_command_1 (infcmd.c:606)
==3298==    by 0x68B4FB: execute_command (top.c:463)
==3298==    by 0x5C7214: command_handler (event-top.c:494)
==3298==    by 0x5C78A3: command_line_handler (event-top.c:692)
==3298==    by 0x6DEB57: rl_callback_read_char (callback.c:220)
==3298==    by 0x5C7278: rl_callback_read_char_wrapper (event-top.c:171)
==3298==    by 0x5C72C2: stdin_event_handler (event-top.c:432)
==3298==    by 0x5C6194: gdb_wait_for_event (event-loop.c:834)

This patch initialises local variable ptid to null in get_current_thread.
We don't need to initialise ptid in add_current_inferior_and_thread,
so this patch also removes the ptid initialisation.

gdb:

2015-07-17  Yao Qi  <yao.qi@linaro.org>

	* remote.c (get_current_thread): Initialise ptid to null_ptid.
	(add_current_inferior_and_thread): Don't initialise ptid.
2015-07-17 12:14:59 +01:00
Markus Metzger b20a652466 btrace: support Intel(R) Processor Trace
Adds a new command "record btrace pt" to configure the kernel to use
Intel(R) Processor Trace instead of Branch Trace Strore.

The "record btrace" command chooses the tracing format automatically.

Intel(R) Processor Trace support requires Linux 4.1 and libipt.

gdb/
	* NEWS: Announce new commands "record btrace pt" and "record pt".
	Announce new options "set|show record btrace pt buffer-size".
	* btrace.c: Include "rsp-low.h".
	Include "inttypes.h".
	(btrace_add_pc): Add forward declaration.
	(pt_reclassify_insn, ftrace_add_pt, btrace_pt_readmem_callback)
	(pt_translate_cpu_vendor, btrace_finalize_ftrace_pt)
	(btrace_compute_ftrace_pt): New.
	(btrace_compute_ftrace): Support BTRACE_FORMAT_PT.
	(check_xml_btrace_version): Update version check.
	(parse_xml_raw, parse_xml_btrace_pt_config_cpu)
	(parse_xml_btrace_pt_raw, parse_xml_btrace_pt)
	(btrace_pt_config_cpu_attributes, btrace_pt_config_children)
	(btrace_pt_children): New.
	(btrace_children): Add support for "pt".
	(parse_xml_btrace_conf_pt, btrace_conf_pt_attributes): New.
	(btrace_conf_children): Add support for "pt".
	* btrace.h: Include "intel-pt.h".
	(btrace_pt_error): New.
	* common/btrace-common.c (btrace_format_string, btrace_data_fini)
	(btrace_data_empty): Support BTRACE_FORMAT_PT.
	* common/btrace-common.h (btrace_format): Add BTRACE_FORMAT_PT.
	(struct btrace_config_pt): New.
	(struct btrace_config)<pt>: New.
	(struct btrace_data_pt_config, struct btrace_data_pt): New.
	(struct btrace_data)<pt>: New.
	* features/btrace-conf.dtd (btrace-conf)<pt>: New.
	(pt): New.
	* features/btrace.dtd (btrace)<pt>: New.
	(pt, pt-config, cpu): New.
	* nat/linux-btrace.c (perf_event_read, perf_event_read_all)
	(perf_event_pt_event_type, kernel_supports_pt)
	(linux_supports_pt): New.
	(linux_supports_btrace): Support BTRACE_FORMAT_PT.
	(linux_enable_bts): Free tinfo on error.
	(linux_enable_pt): New.
	(linux_enable_btrace): Support BTRACE_FORMAT_PT.
	(linux_disable_pt): New.
	(linux_disable_btrace): Support BTRACE_FORMAT_PT.
	(linux_fill_btrace_pt_config, linux_read_pt): New.
	(linux_read_btrace): Support BTRACE_FORMAT_PT.
	* nat/linux-btrace.h (struct btrace_tinfo_pt): New.
	(struct btrace_target_info)<pt>: New.
	* record-btrace.c (set_record_btrace_pt_cmdlist)
	(show_record_btrace_pt_cmdlist): New.
	(record_btrace_print_pt_conf): New.
	(record_btrace_print_conf): Support BTRACE_FORMAT_PT.
	(btrace_ui_out_decode_error): Support BTRACE_FORMAT_PT.
	(cmd_record_btrace_pt_start): New.
	(cmd_record_btrace_start): Support BTRACE_FORMAT_PT.
	(cmd_set_record_btrace_pt, cmd_show_record_btrace_pt): New.
	(_initialize_record_btrace): Add new commands.
	* remote.c (PACKET_Qbtrace_pt, PACKET_Qbtrace_conf_pt_size): New.
	(remote_protocol_features): Add "Qbtrace:pt".
	Add "Qbtrace-conf:pt:size".
	(remote_supports_btrace): Support BTRACE_FORMAT_PT.
	(btrace_sync_conf): Support PACKET_Qbtrace_conf_pt_size.
	(remote_enable_btrace): Support BTRACE_FORMAT_PT.
	(_initialize_remote): Add new commands.

gdbserver/
	* linux-low.c: Include "rsp-low.h"
	(linux_low_encode_pt_config, linux_low_encode_raw): New.
	(linux_low_read_btrace): Support BTRACE_FORMAT_PT.
	(linux_low_btrace_conf): Support BTRACE_FORMAT_PT.
	(handle_btrace_enable_pt): New.
	(handle_btrace_general_set): Support "pt".
	(handle_btrace_conf_general_set): Support "pt:size".

doc/
	* gdb.texinfo (Process Record and Replay): Spell out that variables
	and registers are not available during btrace replay.
	Describe the new "record btrace pt" command.
	Describe the new "set|show record btrace pt buffer-size" options.
	(General Query Packets): Describe the new Qbtrace:pt and
	Qbtrace-conf:pt:size packets.
	Expand "bts" to "Branch Trace Store".
	Update the branch trace DTD.
2015-07-02 12:49:32 +02:00
Gary Benson a3be80c3c5 Remove gdb_sysroot NULL checks
Since fed040c6a5 gdb_sysroot is
never NULL.  This commit removes all gdb_sysroot NULL checks.

gdb/ChangeLog:

	* exec.c (exec_file_locate_attach): Remove gdb_sysroot NULL check.
	* infrun.c (follow_exec): Likewise.
	* remote.c (remote_filesystem_is_local): Likewise.
	* solib.c (solib_find_1): Likewise.
2015-06-25 09:31:07 +01:00
Simon Marchi 124e13d9e7 remote: consider addressable unit size when reading/writing memory
Adapt code in remote.c to take into account addressable unit size when
reading/writing memory.

A few variables are renamed and suffixed with _bytes or _units. This
way, it's more obvious if there is any place where we add or compare
values of different kinds (which would be a mistake).

gdb/ChangeLog:

	* common/rsp-low.c (needs_escaping): New.
	(remote_escape_output): Add unit_size parameter. Refactor to
	support multi-byte addressable units.  Rename parameters.
	* common/rsp-low.h (remote_escape_output): Add unit_size
	parameter and rename others. Update doc.
	* remote.c (align_for_efficient_write): New.
	(remote_write_bytes_aux): Add unit_size parameter and use it.
	Rename some variables.  Update doc.
	(remote_xfer_partial): Get unit size and use it.
	(remote_read_bytes_1): Add unit_size parameter and use it.
	Rename some variables. Update doc.
	(remote_write_bytes): Same.
	(remote_xfer_live_readonly_partial): Same.
	(remote_read_bytes): Same.
	(remote_flash_write): Update call to remote_write_bytes_aux.
	(remote_write_qxfer): Update call to remote_escape_output.
	(remote_search_memory): Same.
	(remote_hostio_pwrite): Same.

gdb/gdbserver/ChangeLog:

	* server.c (write_qxfer_response): Update call to
	remote_escape_output.
2015-06-18 13:12:39 -04:00
Gary Benson 15a201c844 Implement multiple-filesystem support for remote targets
This commit allows GDB to access executables and shared libraries
on remote targets where the remote stub does not share a common
filesystem with the inferior(s).  A new packet "vFile:setfs" is
added to the remote protocol and the three remote hostio functions
with filename arguments are modified to send "vFile:setfs" packets
as necessary.

gdb/ChangeLog:

	* remote.c (struct remote_state) <fs_pid>: New field.
	(new_remote_state): Initialize the above.
	(PACKET_vFile_setfs): New enum value.
	(remote_hostio_set_filesystem): New function.
	(remote_hostio_open): Call the above.
	(remote_hostio_unlink): Likewise.
	(remote_hostio_readlink): Likewise.
	(_initialize_remote): Register new "set/show remote
	hostio-setfs-packet" command.
	* NEWS: Announce new vFile:setfs packet.

gdb/doc/ChangeLog:

	* gdb.texinfo (Remote Configuration): Document the
	"set/show remote hostio-setfs-packet" command.
	(Host I/O Packets): Document the vFile:setfs packet.
2015-06-10 14:28:44 +01:00
Gary Benson 07c138c8ae Add "inferior" argument to some target_fileio functions
This commit adds a new argument to all target_fileio functions with
filename arguments to allow the desired inferior to be specified.
This allows GDB to support systems where processes do not necessarily
share a common filesystem.

gdb/ChangeLog:

	* target.h (struct inferior): New forward declaration.
	(struct target_ops) <to_filesystem_is_local>: Update comment.
	(struct target_ops) <to_fileio_open>: New argument inf.
	Update comment.  All implementations updated.
	(struct target_ops) <to_fileio_unlink>: Likewise.
	(struct target_ops) <to_fileio_readlink>: Likewise.
	(target_filesystem_is_local): Update comment.
	(target_fileio_open): New argument inf.  Update comment.
	(target_fileio_unlink): Likewise.
	(target_fileio_readlink): Likewise.
	(target_fileio_read_alloc): Likewise.
	(target_fileio_read_stralloc): Likewise.
	* target.c (target_fileio_open): New argument inf.
	Pass inf to implementation.  Update debug printing.
	(target_fileio_unlink): Likewise.
	(target_fileio_readlink): Likewise.
	(target_fileio_read_alloc_1): New argument inf. Pass inf
	to target_fileio_open.
	(target_fileio_read_alloc): New argument inf. Pass inf to
	target_fileio_read_alloc_1.
	(target_fileio_read_stralloc): Likewise.
	* gdb_bfd.c (inferior.h): New include.
	(gdb_bfd_iovec_fileio_open): Replace unused "open_closure"
	argument with new argument "inferior".  Pass inferior to
	target_fileio_open.
	(gdb_bfd_open): Supply inferior argument to
	gdb_bfd_iovec_fileio_open.
	* linux-tdep.c (linux_info_proc): Supply inf argument to
	relevant target_fileio calls.
	(linux_find_memory_regions_full): Likewise.
	(linux_fill_prpsinfo): Likewise.
	* remote.c (remote_filesystem_is_local): Supply inf
	argument to remote_hostio_open.
	(remote_file_put): Likewise.
	(remote_file_get): Likewise.
	(remote_file_delete): Supply inf argument to
	remote_hostio_unlink.
2015-06-10 14:28:43 +01:00
Gary Benson 12e2a5fdcc Comment and whitespace changes
Comments on the various implementations of target fileio functions
duplicate information documented in target.h.  This commit replaces
the duplicated documentation with breadcrumbs, and inserts blank
lines to separate comments from the functions they describe where
necessary.

gdb/ChangeLog:

	* inf-child.c (inf_child_fileio_open): Replace comment.
	(inf_child_fileio_pwrite): Likewise.
	(inf_child_fileio_pread): Likewise.
	(inf_child_fileio_fstat): Insert blank line before comment.
	(inf_child_fileio_close): Replace comment.
	(inf_child_fileio_unlink): Likewise.
	(inf_child_fileio_readlink): Likewise.
	* remote.c (remote_hostio_open): Likewise.
	(remote_hostio_pread): Likewise.
	(remote_hostio_pwrite): Likewise.
	(remote_hostio_close): Likewise.
	(remote_hostio_unlink): Likewise.
	(remote_hostio_readlink): Likewise.
	(remote_hostio_fstat): Likewise.
	(remote_filesystem_is_local): Likewise.
	* target.c (target_fileio_open): Likewise.
	(target_fileio_pwrite): Likewise.
	(target_fileio_pread): Likewise.
	(target_fileio_fstat): Insert blank line before comment.
	(target_fileio_close): Replace comment.
	(target_fileio_unlink): Likewise.
	(target_fileio_readlink): Likewise.
	(target_fileio_read_alloc): Likewise.
	(target_fileio_read_stralloc): Likewise.
2015-06-10 14:28:43 +01:00
Gary Benson e3dd7556ad Move vgdb special case into remote_filesystem_is_local
Valgrind GDB (vgdb) presents itself as a remote target but works on
the local filesystem.  gdb_bfd_open contained a special case to make
vgdb work with "target:" sysroots, but the implementation meant that
GDB would fall back to the local filesystem if *any* to_fileio_open
method failed with ENOSYS for *any* reason.  This commit moves the
vgdb special case to remote_filesystem_is_local to allow the fallback
to be restricted only to the specific case that remote file transfer
is unsupported.  This commit also adds a warning which is displayed
the first time the fallback is used.

gdb/ChangeLog:

	* gdb_bfd.c (gdb_bfd_open): Move vgdb special case to...
	* remote.c (remote_filesystem_is_local): ...here.
2015-06-05 16:08:05 +01:00
Don Breazeal cbb8991cab Extended-remote fork catch
This patch implements catchpoints for fork events on extended-remote
Linux targets.

Implementation appeared to be straightforward, requiring four new functions
in remote.c to implement insert/remove of fork/vfork catchpoints.  These
functions are essentially stubs that just return 0 ('success') if the
required features are enabled.  If the fork events are being reported, then
catchpoints are set and hit.

However, there are some extra issues that arise with catchpoints.

1) Thread creation reporting -- fork catchpoints are hit before the
   follow_fork has been completed.  When stopped at a fork catchpoint
   in the native implementation, the new process is not 'reported'
   until after the follow is done.  It doesn't show up in the inferiors
   list or the threads list.  However, in the gdbserver case, an
   'info threads' while stopped at a fork catchpoint will retrieve the
   new thread info from the target and add it to GDB's data structures,
   prior to the follow operations.  Because of this premature report,
   things on the GDB side eventually get very confused.

   So in remote.c:remote_update_thread_list, we check to see if there
   are any pending fork parent threads.  If there are we remove the
   related fork child thread from the thread list sent by the target.

2) Kill process before fork is followed -- on the native side in
   linux-nat.c:linux_nat_kill, there is some code to handle the case where
   a fork has occurred but follow_fork hasn't been called yet.  It does
   this by using the last status to determine if a follow is pending, and
   if it is, to kill the child task.  The use of last_status is fragile
   in situations like non-stop mode where other events may have occurred
   after the fork event.  This patch identifies a fork parent
   in remote.c:extended_remote_kill in a way similar to that used in
   thread creation reporting above.  If one is found, it kills the new
   child as well.

Tested on x64 Ubuntu Lucid, native, remote, extended-remote.  Tested the
case of killing the forking process before the fork has been followed
manually.

gdb/ChangeLog:
        * remote.c (remote_insert_fork_catchpoint): New function.
        (remote_remove_fork_catchpoint): New function.
        (remote_insert_vfork_catchpoint): New function.
        (remote_remove_vfork_catchpoint): New function.
        (pending_fork_parent_callback): New function.
        (remove_new_fork_child): New function.
        (remote_update_thread_list): Call remote_notif_get_pending_events
        and remove_new_fork_child.
        (extended_remote_kill): Kill fork child when killing the
        parent before follow_fork completes.
        (init_extended_remote_ops): Initialize target vector with
        new fork catchpoint functions.
2015-05-12 09:52:46 -07:00
Don Breazeal c269dbdb60 Extended-remote follow vfork
This patch implements follow-fork for vfork on extended-remote Linux targets.

The implementation follows the native implementation as much as possible.
Most of the work is done on the GDB side in the existing code now in
infrun.c.  GDBserver just has to report the events and do a little
bookkeeping.

Implementation includes:

 * enabling VFORK events by adding ptrace options for VFORK and VFORK_DONE
   to linux-low.c:linux_low_ptrace_options.

 * handling VFORK and VFORK_DONE events in linux-low.c:handle_extended_wait
   and reporting them to GDB.

 * including VFORK and VFORK_DONE events in the predicate
   linux-low.c:extended_event_reported.

 * adding support for VFORK and VFORK_DONE events in RSP by adding stop
   reasons "vfork" and "vforkdone" to the 'T' Stop Reply Packet in both
   gdbserver/remote-utils.c and gdb/remote.c.

Tested on x64 Ubuntu Lucid, native, remote, extended-remote.

gdb/gdbserver/ChangeLog:

        * linux-low.c (handle_extended_wait): Handle PTRACE_EVENT_FORK and
        PTRACE_EVENT_VFORK_DONE.
        (linux_low_ptrace_options, extended_event_reported): Add vfork
        events.
        * remote-utils.c (prepare_resume_reply): New stop reasons "vfork"
        and "vforkdone" for RSP 'T' Stop Reply Packet.
        * server.h (report_vfork_events): Declare
        global variable.

gdb/ChangeLog:

        * remote.c (remove_vfork_event_p): New function.
        (remote_follow_fork): Add vfork event type to event checking.
        (remote_parse_stop_reply): New stop reasons "vfork" and
        "vforkdone" for RSP 'T' Stop Reply Packet.
2015-05-12 09:52:45 -07:00
Don Breazeal de0d863ec3 Extended-remote Linux follow fork
This patch implements basic support for follow-fork and detach-on-fork on
extended-remote Linux targets.  Only 'fork' is supported in this patch;
'vfork' support is added n a subsequent patch.  This patch depends on
the previous patches in the patch series.

Sufficient extended-remote functionality has been implemented here to pass
gdb.base/multi-forks.exp, as well as gdb.base/foll-fork.exp with the
catchpoint tests commented out.  Some other fork tests fail with this
patch because it doesn't provide the architecture support needed for
watchpoint inheritance or fork catchpoints.

The implementation follows the same general structure as for the native
implementation as much as possible.

This implementation includes:
 * enabling fork events in linux-low.c in initialize_low and
   linux_enable_extended_features

 * handling fork events in gdbserver/linux-low.c:handle_extended_wait

   - when a fork event occurs in gdbserver, we must do the full creation
     of the new process, thread, lwp, and breakpoint lists.  This is
     required whether or not the new child is destined to be
     detached-on-fork, because GDB will make target calls that require all
     the structures.  In particular we need the breakpoint lists in order
     to remove the breakpoints from a detaching child.  If we are not
     detaching the child we will need all these structures anyway.

   - as part of this event handling we store the target_waitstatus in a new
     member of the parent lwp_info structure, 'waitstatus'.  This
     is used to store extended event information for reporting to GDB.

   - handle_extended_wait is given a return value, denoting whether the
     handled event should be reported to GDB.  Previously it had only
     handled clone events, which were never reported.

 * using a new predicate in gdbserver to control handling of the fork event
   (and eventually all extended events) in linux_wait_1.  The predicate,
   extended_event_reported, checks a target_waitstatus.kind for an
   extended ptrace event.

 * implementing a new RSP 'T' Stop Reply Packet stop reason: "fork", in
   gdbserver/remote-utils.c and remote.c.

 * implementing new target and RSP support for target_follow_fork with
   target extended-remote.  (The RSP components were actually defined in
   patch 1, but they see their first use here).

   - remote target routine remote_follow_fork, which just sends the 'D;pid'
     detach packet to detach the new fork child cleanly.  We can't just
     call target_detach because the data structures for the forked child
     have not been allocated on the host side.

Tested on x64 Ubuntu Lucid, native, remote, extended-remote.

gdb/gdbserver/ChangeLog:

        * linux-low.c (handle_extended_wait): Implement return value,
        rename argument 'event_child' to 'event_lwp', handle
        PTRACE_EVENT_FORK, call internal_error for unrecognized event.
        (linux_low_ptrace_options): New function.
        (linux_low_filter_event): Call linux_low_ptrace_options,
        use different argument fo linux_enable_event_reporting,
        use return value from handle_extended_wait.
        (extended_event_reported): New function.
        (linux_wait_1): Call extended_event_reported and set
        status to report fork events.
        (linux_write_memory): Add pid to debug message.
        (reset_lwp_ptrace_options_callback): New function.
        (linux_handle_new_gdb_connection): New function.
        (linux_target_ops): Initialize new structure member.
        * linux-low.h (struct lwp_info) <waitstatus>: New member.
        * lynx-low.c: Initialize new structure member.
        * remote-utils.c (prepare_resume_reply): Implement stop reason
        "fork" for "T" stop message.
        * server.c (handle_query): Call handle_new_gdb_connection.
        * server.h (report_fork_events): Declare global flag.
        * target.h (struct target_ops) <handle_new_gdb_connection>:
        New member.
        (target_handle_new_gdb_connection): New macro.
        * win32-low.c: Initialize new structure member.

gdb/ChangeLog:

        * linux-nat.c (linux_nat_ptrace_options): New function.
        (linux_init_ptrace, wait_lwp, linux_nat_filter_event):
        Call linux_nat_ptrace_options and use different argument to
        linux_enable_event_reporting.
        (_initialize_linux_nat): Delete call to
        linux_ptrace_set_additional_flags.
        * nat/linux-ptrace.c (current_ptrace_options): Rename to
        supported_ptrace_options.
        (additional_flags): Delete variable.
        (linux_check_ptrace_features): Use supported_ptrace_options.
        (linux_test_for_tracesysgood, linux_test_for_tracefork):
        Likewise, and remove additional_flags check.
        (linux_enable_event_reporting): Change 'attached' argument to
        'options'.  Use supported_ptrace_options.
        (ptrace_supports_feature): Change comment.  Use
        supported_ptrace_options.
        (linux_ptrace_set_additional_flags): Delete function.
        * nat/linux-ptrace.h (linux_ptrace_set_additional_flags):
        Delete function prototype.
        * remote.c (remote_fork_event_p): New function.
        (remote_detach_pid): New function.
        (remote_detach_1): Call remote_detach_pid, don't mourn inferior
        if doing detach-on-fork.
        (remote_follow_fork): New function.
        (remote_parse_stop_reply): Handle new "T" stop reason "fork".
        (remote_pid_to_str): Print "process" strings for pid/0/0 ptids.
        (init_extended_remote_ops): Initialize to_follow_fork.
2015-05-12 09:52:43 -07:00
Don Breazeal 89245bc056 Identify remote fork event support
This patch implements a mechanism for GDB to determine whether fork
events are supported in gdbserver.  This is a preparatory patch for
remote fork and exec event support.

Two new RSP packets are defined to represent fork and vfork event
support.  These packets are used just like PACKET_multiprocess_feature
to denote whether the corresponding event is supported.  GDB sends
fork-events+ and vfork-events+ to gdbserver to inquire about fork
event support.  If the response enables these packets, then GDB
knows that gdbserver supports the corresponding events and will
enable them.

Target functions used to query for support are included along with
each new packet.

In order for gdbserver to know whether the events are supported at the
point where the qSupported packet arrives, the code in nat/linux-ptrace.c
had to be reorganized.  Previously it would test for fork/exec event
support, then enable the events using the pid of the inferior.  When the
qSupported packet arrives there may not be an inferior.  So the mechanism
was split into two parts: a function that checks whether the events are
supported, called when gdbserver starts up, and another that enables the
events when the inferior stops for the first time.

Another gdbserver change was to add some global variables similar to
multi_process, one per new packet.  These are used to control whether
the corresponding fork events are enabled.  If GDB does not inquire
about the event support in the qSupported packet, then gdbserver will
not set these "report the event" flags.  If the flags are not set, the
events are ignored like they were in the past.  Thus, gdbserver will
never send fork event notification to an older GDB that doesn't
recognize fork events.

Tested on Ubuntu x64, native/remote/extended-remote, and as part of
subsequent patches in the series.

gdb/gdbserver/ChangeLog:

        * linux-low.c (linux_supports_fork_events): New function.
        (linux_supports_vfork_events): New function.
        (linux_target_ops): Initialize new structure members.
        (initialize_low): Call linux_check_ptrace_features.
        * lynx-low.c (lynx_target_ops): Initialize new structure
        members.
        * server.c (report_fork_events, report_vfork_events):
        New global flags.
        (handle_query): Add new features to qSupported packet and
        response.
        (captured_main): Initialize new global variables.
        * target.h (struct target_ops) <supports_fork_events>:
        New member.
        <supports_vfork_events>: New member.
        (target_supports_fork_events): New macro.
        (target_supports_vfork_events): New macro.
        * win32-low.c (win32_target_ops): Initialize new structure
        members.

gdb/ChangeLog:

        * nat/linux-ptrace.c (linux_check_ptrace_features): Change
        from static to extern.
        * nat/linux-ptrace.h (linux_check_ptrace_features): Declare.
        * remote.c (anonymous enum): <PACKET_fork_event_feature,
        * PACKET_vfork_event_feature>: New enumeration constants.
        (remote_protocol_features): Add table entries for new packets.
        (remote_query_supported): Add new feature queries to qSupported
        packet.
        (_initialize_remote): Exempt new packets from the requirement
        to have 'set remote' commands.
2015-05-12 09:52:41 -07:00
Gary Benson 835205d078 Locate executables on remote stubs without multiprocess extensions
This commit allows GDB to determine filenames of main executables
when debugging using remote stubs without multiprocess extensions.
The qXfer:exec-file:read packet is extended to allow an empty
annex, with the meaning that the remote stub should supply the
filename of whatever it thinks is the current process.

gdb/ChangeLog:

	* remote.c (remote_add_inferior): Call exec_file_locate_attach
	for fake PIDs as well as real ones.
	(remote_pid_to_exec_file): Send empty annex if PID is fake.

gdb/doc/ChangeLog:

	* gdb.texinfo (General Query Packets): Document
	qXfer:exec-file:read with empty annex.

gdb/gdbserver/ChangeLog:

	* server.c (handle_qxfer_exec_file): Use current process
	if annex is empty.
2015-05-12 11:57:52 +01:00
Gary Benson 1b6e6f5c7f Access executable from remote system when first inferior appears
This commit modifies remote_add_inferior to take an extra argument
try_open_exec.  If this is nonzero, remote_add_inferior will attempt
to open this inferior's executable as the main executable if no main
executable is open already.  Callers are updated appropriately.

With this commit, remote debugging can now be initiated using only a
"target remote" or "target extended-remote" command; no "set sysroot"
or "file" commands are required, e.g.

  bash$ gdb -q
  (gdb) target remote | gdbserver - /bin/sh
  Remote debugging using | gdbserver - /bin/sh
  Process /bin/sh created; pid = 32166
  stdin/stdout redirected
  Remote debugging using stdio
  Reading symbols from target:/bin/bash...

One testcase required updating as a result of this commit.  The test
checked that GDB's "info files" command does not crash if no main
executable is open, and relied on GDB's inability to access the main
executable over the remote protocol.  The test was updated to inhibit
this new behavior.

gdb/ChangeLog:

	* remote.c (remote_add_inferior): New argument try_open_exec.
	If nonzero, attempt to open the inferior's executable file as
	the main executable if no main executable is open already.
	All callers updated.
	* NEWS: Mention that GDB now supports automatic location and
	retrieval of executable + files from remote targets.

gdb/doc/ChangeLog:

	* gdb.texinfo (Connecting to a Remote Target): Mention that
	GDB can access program files from remote targets that support
	qXfer:exec-file:read and Host I/O packets.

gdb/testsuite/ChangeLog:

	* gdb.server/server-exec-info.exp: Inhibit GDB from accessing
	the main executable over the remote protocol.
2015-04-17 09:47:30 +01:00
Gary Benson c78fa86a21 Implement remote_pid_to_exec_file using qXfer:exec-file:read
This commit adds a new packet "qXfer:exec-file:read" to the remote
protocol that can be used to obtain the pathname of the file that
was executed to create a process on the remote system.  Support for
this packet is added to GDB and remote_ops.to_pid_to_exec_file is
implemented using it.

gdb/ChangeLog:

	* target.h (TARGET_OBJECT_EXEC_FILE): New enum value.
	* remote.c (PACKET_qXfer_exec_file): Likewise.
	(remote_protocol_features): Register the
	"qXfer:exec-file:read" feature.
	(remote_xfer_partial): Handle TARGET_OBJECT_EXEC_FILE.
	(remote_pid_to_exec_file): New function.
	(init_remote_ops): Initialize to_pid_to_exec_file.
	(_initialize_remote): Register new "set/show remote
	pid-to-exec-file-packet" command.
	* NEWS: Announce new qXfer:exec-file:read packet.

gdb/doc/ChangeLog:

	* gdb.texinfo (Remote Configuration): Document the "set/show
	remote pid-to-exec-file-packet" command.
	(General Query Packets): Document the qXfer:exec-file:read
	qSupported features.  Document the qXfer:exec-file:read packet.
2015-04-17 09:47:30 +01:00
Pedro Alves 8a06aea71e update thread list, delete exited threads
On GNU/Linux, if the running kernel supports clone events, then
linux-thread-db.c defers thread listing to the target beneath:

static void
thread_db_update_thread_list (struct target_ops *ops)
{
...
  if (target_has_execution && !thread_db_use_events ())
    ops->beneath->to_update_thread_list (ops->beneath);
  else
    thread_db_update_thread_list_td_ta_thr_iter (ops);
...
}

However, when live debugging, the target beneath, linux-nat.c, does
not implement the to_update_thread_list method.  The result is that if
a thread is marked exited (because it can't be deleted right now,
e.g., it was the selected thread), then it won't ever be deleted,
until the process exits or is killed/detached.

A similar thing happens with the remote.c target.  Because its
target_update_thread_list implementation skips exited threads when it
walks the current thread list looking for threads that no longer exits
on the target side, using ALL_NON_EXITED_THREADS_SAFE, stale exited
threads are never deleted.

This is not a big deal -- I can't think of any way this might be user
visible, other than gdb's memory growing a tiny bit whenever a thread
gets stuck in exited state.  Still, might as well clean things up
properly.

All other targets use prune_threads, so are unaffected.

The fix adds a ALL_THREADS_SAFE macro, that like
ALL_NON_EXITED_THREADS_SAFE, walks the thread list and allows deleting
the iterated thread, and uses that in places that are walking the
thread list in order to delete threads.  Actually, after converting
linux-nat.c and remote.c to use this, we find the only other user of
ALL_NON_EXITED_THREADS_SAFE is also walking the list to delete
threads.  So we convert that too, and end up deleting
ALL_NON_EXITED_THREADS_SAFE.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/ChangeLog
2015-04-07  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (ALL_NON_EXITED_THREADS_SAFE): Rename to ...
	(ALL_THREADS_SAFE): ... this, and don't skip exited threads.
	(delete_exited_threads): New declaration.
	* infrun.c (follow_exec): Use ALL_THREADS_SAFE.
	* linux-nat.c (linux_nat_update_thread_list): New function.
	(linux_nat_add_target): Install it.
	* remote.c (remote_update_thread_list): Use ALL_THREADS_SAFE.
	* thread.c (prune_threads): Use ALL_THREADS_SAFE.
	(delete_exited_threads): New function.
2015-04-07 15:47:22 +01:00