Commit Graph

1605 Commits

Author SHA1 Message Date
Yao Qi 605fd3c659 Fix GDBserver build failure when $development is false
When we set bfd/development.sh:$development to false, GDBserver failed to
build,

selftest.o: In function `selftests::run_tests(char const*)':
binutils-gdb/gdb/gdbserver/../common/selftest.c:97:undefined reference to `selftests::reset()'
collect2: error: ld returned 1 exit status

selftest.o shouldn't be compiled and linked when $development is false.
With this patch, in release mode, GDBserver doesn't nothing with option
--selftest,

$ ./gdbserver --selftest=foo
Selftests are not available in a non-development build.
$ ./gdbserver --selftest
Selftests are not available in a non-development build.

gdb/gdbserver:

2018-01-08  Yao Qi  <yao.qi@linaro.org>
	    Simon Marchi  <simon.marchi@ericsson.com>

	* Makefile.in (OBS): Remove selftest.o.
	* configure.ac: Set srv_selftest_objs if $development is true.
	(GDBSERVER_DEPFILES): Append $srv_selftest_objs.
	* configure: Re-generated.
	* server.c (captured_main): Wrap variable selftest_filter with
	GDB_SELF_TEST.

gdb/testsuite:

2018-01-08  Simon Marchi  <simon.marchi@ericsson.com>

	* gdb.server/unittest.exp: Match the output in non-development
	mode.
2018-01-08 10:09:33 +00:00
Simon Marchi 2cc050302c Make parse_debug_format_options return an std::string
This avoid having to manually free the return value.

gdb/gdbserver/ChangeLog:

	* server.c (parse_debug_format_options): Return std::string.
	(handle_monitor_command, captured_main): Adjust.
2018-01-07 10:50:48 -05:00
Pedro Alves e379cee61f Fix regression: cannot start with LD_PRELOAD=libSegFault.so (PR gdb/18653#c7)
At https://sourceware.org/bugzilla/show_bug.cgi?id=18653#c7, Andrew
reports that the fix for PR gdb/18653 made GDB useless if you preload
libSegFault.so, because GDB internal-errors on startup:

 $ LD_PRELOAD=libSegFault.so gdb
 src/gdb/common/signals-state-save-restore.c:64: internal-error: unexpected signal handler
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Aborted (core dumped)
 $

The internal error comes from the code saving the signal dispositions
inherited from gdb's parent:

 (top-gdb) bt
 #0  0x000000000056b001 in internal_error(char const*, int, char const*, ...) (file=0xaf5f38 "src/gdb/common/signals-state-save-restore.c", line=64, fmt=0xaf5f18 "unexpected signal handler") at src/gdb/common/errors.c:54
 #1  0x00000000005752c9 in save_original_signals_state() () at src/gdb/common/signals-state-save-restore.c:64
 #2  0x00000000007425de in captured_main_1(captured_main_args*) (context=0x7fffffffd860)
     at src/gdb/main.c:509
 #3  0x0000000000743622 in captured_main(void*) (data=0x7fffffffd860) at src/gdb/main.c:1145
 During symbol reading, cannot get low and high bounds for subprogram DIE at 24065.
 #4  0x00000000007436f9 in gdb_main(captured_main_args*) (args=0x7fffffffd860) at src/gdb/main.c:1171
 #5  0x0000000000413acd in main(int, char**) (argc=1, argv=0x7fffffffd968) at src/gdb/gdb.c:32

This commit downgrades the internal error to a warning.  You'll get
instead:

~~~
 $ LD_PRELOAD=libSegFault.so gdb
 warning: Found custom handler for signal 11 (Segmentation fault) preinstalled.
 Some signal dispositions inherited from the environment (SIG_DFL/SIG_IGN)
 won't be propagated to spawned programs.
 GNU gdb (GDB) 8.0.50.20171213-git
 Copyright (C) 2017 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
 and "show warranty" for details.
 This GDB was configured as "x86_64-pc-linux-gnu".
 Type "show configuration" for configuration details.
 For bug reporting instructions, please see:
 <http://www.gnu.org/software/gdb/bugs/>.
 Find the GDB manual and other documentation resources online at:
 <http://www.gnu.org/software/gdb/documentation/>.
 For help, type "help".
 Type "apropos word" to search for commands related to "word"...
 (gdb)
~~~

This also moves the location where save_original_signals_state is
called a bit further below (to after option processing), so that "-q"
disables the warning:

~~~
 $ LD_PRELOAD=libSegFault.so gdb -q
 (gdb)
~~~

New testcase included.

gdb/ChangeLog:
2018-01-05  Pedro Alves  <palves@redhat.com>

	PR gdb/18653
	* common/signals-state-save-restore.c
	(save_original_signals_state): New parameter 'quiet'.  Warn if we
	find a custom handler preinstalled, instead of internal erroring.
	But only warn if !quiet.
	* common/signals-state-save-restore.h
	(save_original_signals_state): New parameter 'quiet'.
	* main.c (captured_main_1): Move save_original_signals_state call
	after option handling, and pass QUIET.

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

	PR gdb/18653
	* server.c (captured_main): Pass quiet=false to
	save_original_signals_state.

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

	PR gdb/18653
	* gdb.base/libsegfault.exp: New.
2018-01-05 18:26:18 +00:00
Joel Brobecker 82e1e79a42 Update copyright year in version message of GDB, GDBserver and GDBreplay
gdb/ChangeLog:

	* top.c (print_gdb_version): Update Copyright year in version
	message.

gdb/gdbserver/ChangeLog:

	* gdbreplay.c (gdbreplay_version): Update copyright year in
	version message.
	* server.c (gdbserver_version): Likewise.
2018-01-02 07:38:05 +04:00
Tom Tromey 8e481c3ba8 C++-ify parse_format_string
This replaces parse_format_string with a class, removing some
constructors along the way.  While doing this, I found that one
argument to gen_printf is unused, so I removed it.

Also, I am not completely sure, but the use of `release' in
maint_agent_printf_command and parse_cmd_to_aexpr seems like it may
leak expressions.

Regression tested by the buildbot.

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

	* printcmd.c (ui_printf): Update.  Use std::vector.
	* common/format.h (struct format_piece): Add constructor.
	<string>: Now const.
	(class format_pieces): New class.
	(parse_format_string, free_format_pieces)
	(free_format_pieces_cleanup): Remove.
	* common/format.c (format_pieces::format_pieces): Rename from
	parse_format_string.  Update.
	(free_format_pieces, free_format_pieces_cleanup): Remove.
	* breakpoint.c (parse_cmd_to_aexpr): Update.  Use std::vector.
	* ax-gdb.h (gen_printf): Remove argument.
	* ax-gdb.c (gen_printf): Remove "frags" argument.
	(maint_agent_printf_command): Update.  Use std::vector.

gdbserver/ChangeLog
2017-12-08  Tom Tromey  <tom@tromey.com>

	* ax.c (ax_printf): Update.
2017-12-08 10:23:43 -07:00
Yao Qi a880623024 Initialize target description early in IPA
Target descriptions are allocated lazily, that is fine in GDBserver,
but it is not safe to call malloc in gdb_collect in IPA, because we
can set a fast tracepoint in malloc, and when the tracepoint is hit,
gdb_collect/malloc is called, deadlock or memory corruption may be
triggered.

 #0  0xf7cfc200 in malloc ()
 #1  0xf7efdc07 in operator new(unsigned int) ()
 #2  0xf7ef7636 in allocate_target_description() ()
 #3  0xf7efcbe1 in i386_create_target_description(unsigned long long, bool) ()
 #4  0xf7efb474 in i386_linux_read_description(unsigned long long) ()
 #5  0xf7efb190 in get_ipa_tdesc(int) ()
 #6  0xf7ef9baa in gdb_collect ()

The fix is to initialize all target descriptions earlier, when the
IPA is loaded.  In order to guarantee malloc is not called in IPA
in gdb_collect, I change the test to set a breakpoint on malloc, if
IPA gdb_collect calls malloc, program will hit the breakpoint, and
test fail.

continue
Continuing.

Thread 1 "" hit Breakpoint 5, 0xf7cfc200 in malloc ()
(gdb) FAIL: gdb.trace/ftrace.exp: advance through tracing

gdb/gdbserver:

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

	* linux-aarch64-ipa.c (initialize_low_tracepoint): Call
	aarch64_linux_read_description.
	* linux-amd64-ipa.c (idx2mask): New array.
	(get_ipa_tdesc): Move idx2mask out.
	(initialize_low_tracepoint): Initialize target descriptions.
	* linux-i386-ipa.c (idx2mask): New array.
	(get_ipa_tdesc): Move idx2mask out.
	(initialize_low_tracepoint): Initialize target descriptions.

gdb/testsuite:

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

	* gdb.trace/ftrace.exp (run_trace_experiment): Set breakpoint on
	malloc and catch syscall.
2017-12-07 17:07:01 +00:00
Simon Marchi d4a0e8b57d Split tdesc_type into multiple classes
This patch makes tdesc_type an abstract base class and creates three
subclasses:

- tdesc_type_builtin, for builtin types
- tdesc_type_vector, for vector types
- tdesc_type_with_fields, for struct, union, flag and enum types

This allows getting rid of the union in tdesc_type and to not allow the
std::vector separately.  I tried to go further and create separate
classes for struct, union, flag and enum, but it proved too difficult.
One problem is that from the point of the of the target description
code, the types tdesc_type_* are opaque (only forward-declared).
Therefore, it doesn't know about inheritance relationship between those
classes.  This makes it impossible to make functions that accept a
pointer to a base class and pass a pointer to a derived class, for
example.  I think this patch here is a good compromise, and if somebody
wants to improve things further, the door is open.

A make_gdb_type virtual pure method is added to tdesc_type, which
replaces the current tdesc_gdb_type function.  Calling this method on a
tdesc_type returns the corresponding built gdb type.

gdb/ChangeLog:

	* target-descriptions.c (struct tdesc_type): Use default
	destructor.
	<u>: Remove.
	<accept>: Remove.
	(struct tdesc_type_builtin): New.
	(struct tdesc_type_vector): New.
	(struct tdesc_type_with_fields): New.
	(tdesc_predefined_types): Change type to tdesc_type_builtin[].
	(tdesc_gdb_type): Remove.
	(tdesc_register_type): Adjust.
	(tdesc_create_vector): Create tdesc_type_vector.
	(tdesc_create_struct): Create tdesc_type_with_fields.
	(tdesc_set_struct_size): Change parameter type.
	(tdesc_create_union): Create tdesc_type_with_fields.
	(tdesc_create_flags): Likewise.
	(tdesc_create_enum): Likewise.
	(tdesc_add_field): Change parameter type.
	(tdesc_add_typed_bitfield): Likewise.
	(tdesc_add_bitfield): Likewise.
	(tdesc_add_flag): Likewise.
	(tdesc_add_enum_value): Likewise.
	(print_c_tdesc) <visit>: Remove overload with tdesc_type
	parameter, add overloads for tdesc_type_builtin,
	tdesc_type_with_fields and tdesc_type_vector.
	<m_printed_type>: Remove.
	<m_printed_element_type, m_printed_type_with_fields>: Add.
	* target-descriptions.h (tdesc_create_enum): Change return type.
	(tdesc_add_typed_bitfield): Change parameter type.
	(tdesc_add_enum_value): Change parameter type.
	* xml-tdesc.c (struct tdesc_parsing_data) <current_type>: Change
	type to tdesc_type_with_fields.
	(tdesc_start_struct): Adjust.
	(tdesc_start_flags): Adjust.
	(tdesc_start_enum): Adjust.
	(tdesc_start_field): Adjust.
	* arch/tdesc.h (struct tdesc_type_builtin): Forward-declare.
	(struct tdesc_type_vector): Forward-declare.
	(struct tdesc_type_with_fields): Forward-declare.
	(tdesc_create_struct): Change return type.
	(tdesc_create_union): Likewise.
	(tdesc_create_flags): Likewise.
	(tdesc_add_field): Change parameter type.
	(tdesc_set_struct_size): Likewise.
	(tdesc_add_bitfield): Likewise.
	(tdesc_add_flag): Likewise.
	* features: Re-generate C files.

gdb/gdbserver/ChangeLog:

	* tdesc.c (struct tdesc_type): Change return type.
	(tdesc_add_flag): Change parameter type.
	(tdesc_add_bitfield): Likewise.
	(tdesc_add_field): Likewise.
	(tdesc_set_struct_size): Likewise.
2017-12-05 16:30:28 -05: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 c0e15c9bfd Remove for_each_inferior_with_data
Remove for_each_inferior_with_data, replacing its sole usage with
for_each_thread.

gdb/gdbserver/ChangeLog:

	* inferiors.c (for_each_inferior_with_data): Remove.
	* inferiors.h (for_each_inferior_with_data): Remove.
	* server.c (handle_qxfer_threads_worker): Change parameter type.
	(handle_qxfer_threads_proper): Use for_each_thread.
2017-12-02 20:38:37 -05:00
Simon Marchi f004534791 Remove for_each_inferior
This patch removes for_each_inferior, replacing all its usages with
for_each_thread.

gdb/gdbserver/ChangeLog:

	* inferiors.c (for_each_inferior): Remove.
	(clear_inferiors): Use for_each_thread.
	* inferiors.h (for_each_inferior): Remove.
	* linux-low.c (linux_wait_for_event_filtered): Use
	for_each_thread.
	(linux_stabilize_threads): Likewise.
	* regcache.c (regcache_release): Likewise.
	* server.c (gdb_wants_all_threads_stopped): Likewise.
	(clear_pending_status_callback): Remove.
	(handle_status): Use for_each_thread.
	(captured_main): Likewise.
	* win32-low.c (child_init_thread_list): Likewise.
	(win32_clear_inferiors): Likewise.
	(fake_breakpoint_event): Likewise.
2017-12-02 20:37:53 -05:00
Simon Marchi 9521758bf9 Remove find_inferior
All the usages of find_inferior were removed, so the function itself can
be removed.

gdb/gdbserver/ChangeLog:

	* inferiors.h (find_inferior): Remove.
	* inferiors.c (find_inferior): Remove.
2017-12-02 20:36:45 -05:00
Simon Marchi 8f86d7aa85 Update comments
These functions were modified in the previous patch series, but I forgot
to update some comments.

gdb/gdbserver/ChangeLog:

	* linux-low.c (resume_status_pending_p): Update comment.
	(need_step_over_p): Update comment.
2017-12-02 20:36:44 -05:00
Simon Marchi e2b4407579 Remove usages of find_inferior that call proceed_one_lwp
Replace with for_each_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (proceed_one_lwp): Return void, change parameter
	type.
	(unsuspend_and_proceed_one_lwp): Likewise.
	(proceed_all_lwps): Use for_each_thread.
	(unstop_all_lwps): Likewise.
2017-12-02 20:36:43 -05:00
Simon Marchi c80825ff32 Remove usage of find_inferior in linux_resume
Replace with for_each_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_resume_one_thread): Return void, take
	parameter directly.
	(linux_resume): Use for_each_thread.
2017-12-02 20:36:42 -05:00
Simon Marchi df3e4dbe66 Remove usages of find_inferior in stop_all_lwps
Replace with for_each_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (send_sigstop_callback): Return void, change
	parameter type.  Rename to...
	(send_sigstop): ... this.
	(suspend_and_send_sigstop_callback): Return void, change parameter
	type.  Rename to...
	(suspend_and_send_sigstop): ... this.
	(stop_all_lwps): Use for_each_thread.
2017-12-02 20:36:42 -05:00
Simon Marchi 5a6b0a41df Remove usage of find_inferior in linux_stabilize_threads
Replace with find_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (lwp_running): Return bool, remove unused
	argument.
	(linux_stabilize_threads): Use find_thread.
2017-12-02 20:36:41 -05:00
Simon Marchi 39a64da5fc Remove usages of find_inferior in select_event_lwp
Replace with find_thread/for_each_thread.  I inlined the callbacks,
because they are relatively simple.

gdb/gdbserver/ChangeLog:

	* linux-low.c (select_singlestep_lwp_callback): Remove.
	(count_events_callback): Remove.
	(select_event_lwp_callback): Remove.
	(select_event_lwp): Use find_thread/for_each_thread.
2017-12-02 20:36:40 -05:00
Simon Marchi a1385b7b88 Remove usages of find_inferior calling not_stopped_callback
Replace with find_thread.  Writing a lambda inline in directly in the if
conditions would be a bit messy, so I chose to assign them to variables
instead.

gdb/gdbserver/ChangeLog:

	* linux-low.c (not_stopped_callback): Return bool, take filter
	argument directly.
	(linux_wait_for_event_filtered): Use find_thread.
	(linux_wait_1): Likewise.
2017-12-02 20:36:39 -05:00
Simon Marchi 454296a2c1 Remove usage of find_inferior in find_lwp_pid
Replace with find_thread.  We could almost use find_thread_ptid, except
that find_lwp_pid uses the pid of the input ptid of the lwp is 0, so the
behavior is not quite the same.

gdb/gdbserver/ChangeLog:

	* linux-low.c (same_lwp): Remove.
	(find_lwp_pid): Use find_thread.
2017-12-02 20:36:38 -05:00
Simon Marchi 6b2a85daf5 Remove usage of find_inferior in linux_mourn
Replace with for_each_thread with pid filtering.  The callback becomes
trivial enough that it's better to inline it.

gdb/gdbserver/ChangeLog:

	* linux-low.c (delete_lwp_callback): Remove.
	(linux_mourn): Use for_each_thread.
2017-12-02 20:36:37 -05:00
Simon Marchi 798a38e8de Remove usage of find_inferior in linux_detach
Replace with for_each_thread with pid filtering.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_detach_lwp_callback): Return void, remove
	args parameter, don't check for pid.
	(linux_detach): Use for_each_thread.
2017-12-02 20:36:36 -05:00
Simon Marchi e4eb0dec0b Remove usage of find_inferior in last_thread_of_process_p
Replace it with find_thread.  I also modified the code a bit to use a
lambda and a boolean.

gdb/gdbserver/ChangeLog:

	* linux-low.c (struct counter): Remove.
	(second_thread_of_pid_p): Remove.
	(last_thread_of_process_p): Use find_thread.
2017-12-02 20:36:36 -05:00
Simon Marchi 83e1b6c13a Remove find_inferior_in_random
Replace with find_thread_in_random.

gdb/gdbserver/ChangeLog:

	* inferiors.c (find_inferior_in_random): Remove.
	* inferiors.h (find_inferior_in_random): Remove.
	* linux-low.c (status_pending_p_callback): Return bool, accept
	parameter ptid directly.
	(linux_wait_for_event_filtered): Use find_thread_in_random.
	(linux_wait_1): Likewise.
2017-12-02 20:36:35 -05:00
Simon Marchi 8dc7b443a6 Remove find_inferior_id
Remove find_inferior_id, replacing its usages with find_thread_ptid.
find_thread_ptid was implemented using find_inferior_id, so move the
implementation there instead.

gdb/gdbserver/ChangeLog:

	* inferiors.c (find_inferior_id): Remove.
	(find_thread_ptid): Move implemention from find_inferior_id to
	here.
	* inferiors.h (find_inferior_id): Remove.
	* server.c (handle_status): Use find_thread_ptid.
	(process_serial_event): Likewise.
	* thread-db.c (find_one_thread): Likewise.
	(thread_db_thread_handle): Likewise.
	* win32-low.c (thread_rec): Likewise.
	(child_delete_thread): Likewise.
	(win32_thread_alive): Likewise.
	(get_child_debug_event): Likewise.
2017-12-02 20:36:34 -05:00
Simon Marchi da25033cd9 Remove usages of find_inferior in linux-mips-low.c
Replace with for_each_thread with pid filtering.  This allows
simplifying the callback a little bit.

gdb/gdbserver/ChangeLog:

	* linux-mips-low.c (update_watch_registers_callback): Return
	void, remove pid_p parameter, don't check for pid.
	(mips_insert_point, mips_remove_point): Use for_each_thread.
2017-12-02 20:36:33 -05:00
Simon Marchi c91bb56b06 Remove usage of find_inferior in lynx_mourn
Replace it with for_each_thread with pid filtering.  We can remove
lynx_delete_thread_callback and pass remove_thread directly.

I can't build/test this change, but it should be obvious enough.

gdb/gdbserver/ChangeLog:

	* lynx.low (lynx_delete_thread_callback): Remove.
	(lynx_mourn): Use for_each_thread.
2017-12-02 20:36:32 -05:00
Simon Marchi 634a3254c8 Remove usage of find_inferior in regcache_invalidate_pid
Replace with for_each_thread with pid filtering.
regcache_invalidate_one is not longer needed, as it was only used to
filter the pid.  We can call regcache_invalidate_thread directly.

gdb/gdbserver/ChangeLog:

	* regcache.c (regcache_invalidate_one): Remove.
	(regcache_invalidate_pid): use for_each_thread.
2017-12-02 20:36:32 -05:00
Tom Tromey 41272101db Change maybe_disable_address_space_randomization to a class
This changes maybe_disable_address_space_randomization to be an RAII
class, rather than having it return a cleanup.

Regression tested by the buildbot.

ChangeLog
2017-11-26  Tom Tromey  <tom@tromey.com>

	* nat/linux-personality.h (class
	maybe_disable_address_space_randomization): New class.
	(maybe_disable_address_space_randomization): Don't declare
	function.
	* nat/linux-personality.c (restore_personality)
	(make_disable_asr_cleanup): Remove.
	(maybe_disable_address_space_randomization): Now a constructor.
	(~maybe_disable_address_space_randomization): New destructor.
	* linux-nat.c (linux_nat_create_inferior): Update.

gdbserver/ChangeLog
2017-11-26  Tom Tromey  <tom@tromey.com>

	* linux-low.c (linux_create_inferior): Update.
2017-11-26 10:42:15 -07:00
Ulrich Weigand f5291a6f32 [spu] Fix spu-linux gdbserver build
Fix a typo in a newly added argument name.

gdb/ChangeLog:
2017-11-24  Ulrich Weigand  <uweigand@de.ibm.com>

	* spu-low.c (spu_create_inferior): Fix typo in argument name.
2017-11-24 22:04:41 +01:00
Alan Hayward 6654d750c7 Add xml selftests for aarch64 target description.
gdb/
	* aarch64-tdep.c (_initialize_aarch64_tdep): Add target desc
	selftest.

gdbserver/
	* configure.srv: Add linux-aarch64-tdesc-selftest.o.
	* linux-aarch64-low.c (initialize_low_arch): Call init func.
	* linux-aarch64-tdesc-selftest.c: New file.
	* linux-aarch64-tdesc.h (initialize_low_tdesc): New declaration.
2017-11-24 11:18:19 +00:00
Alan Hayward 49bdb7ee48 Use flexible target descriptors for aarch64
gdb/
	* aarch64-tdep.c (_initialize_aarch64_tdep): Remove init.
	* arch/aarch64.c (aarch64_create_target_description): Create
	new target description.
	* features/Makefile: Add new files.
	* features/aarch64.c: Remove file.
	* features/aarch64-core.c: New autogenerated file.
	* features/aarch64-fpu.c: New autogenerated file.
	* target-descriptions.c (maint_print_c_tdesc_cmd): Check for aarch64.

gdbserver/
	* linux-aarch64-ipa.c (initialize_low_tracepoint): Remove init.
	* linux-aarch64-low.c (initialize_low_arch): Remove init.
	* linux-aarch64-tdesc.c (aarch64_linux_read_description): Add init.
2017-11-24 11:18:19 +00:00
Alan Hayward d6d7ce5623 gdbserver: add aarch64_create_target_description
gdbserver/
	* configure.srv: Add new files.
	* linux-aarch64-ipa.c (get_ipa_tdesc): Call
	aarch64_linux_read_description.
	* linux-aarch64-low.c (aarch64_linux_read_description):
	Merge with aarch64_arch_setup.
	(aarch64_arch_setup): Call aarch64_linux_read_description.
	* linux-aarch64-tdesc.c: New file.
	* linux-aarch64-tdesc.h: New file.
2017-11-24 11:18:19 +00:00
Yao Qi 506fe5f499 Change tic6x target descriptions
This patch changes tic6x target descriptions to be more flexible.  Rebuild
tic6x-uclinux GDBserver with my x86 g++, and the unit test passes.

gdb:

2017-11-24  Yao Qi  <yao.qi@linaro.org>

	* arch/tic6x.c: New file.
	* arch/tic6x.h: New file.
	* features/Makefile (FEATURE_XMLFILES): Add tic6x-c6xp.xml,
	tic6x-core.xml and tic6x-gp.xml.
	* features/tic6x-c6xp.c: Generated.
	* features/tic6x-core.c: Generated.
	* features/tic6x-gp.c: Generated.
	* target-descriptions.c (maint_print_c_tdesc_cmd): Match
	"tic6x-".

gdb/gdbserver:

2017-11-24  Yao Qi  <yao.qi@linaro.org>

	* configure.srv: Set $srv_regobj for tic6x-linux.
	* linux-tic6x-low.c: Include "arch/tic6x.h" and "tdesc.h".
	(tic6x_read_description): Move some code to tic6x_arch_setup.
	(tic6x_tdesc_test): New function.
	(initialize_low_arch): Call selftests::register_test.
2017-11-24 09:29:43 +00:00
Yao Qi 29f9a56737 Fix build with GCC 8: strncpy -> memcpy
Recent gcc 8 trunk emits the warning below,

../../../binutils-gdb/gdb/gdbserver/remote-utils.c:1204:14: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 6 bytes from a string of the same length [-Werror=stringop-truncation]
      strncpy (buf, "watch:", 6);
      ~~~~~~~~^~~~~~~~~~~~~~~~~~

../../binutils-gdb/gdb/cli/cli-decode.c:1118:15: error: ‘char* strncpy(char*, const char*, size_t)’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
       strncpy (cmdtype1 + 1, cmdtype, len - 1);
       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../binutils-gdb/gdb/cli/cli-decode.c:1110:16: note: length computed here
   len = strlen (cmdtype);
         ~~~~~~~^~~~~~~~~
../../binutils-gdb/gdb/cli/cli-decode.c:1120:15: error: ‘char* strncpy(char*, const char*, size_t)’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
       strncpy (cmdtype2, cmdtype, len - 1);
       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../binutils-gdb/gdb/cli/cli-decode.c:1110:16: note: length computed here
   len = strlen (cmdtype);
         ~~~~~~~^~~~~~~~~

../../binutils-gdb/gdb/cp-namespace.c:1071:11: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 2 bytes from a string of the same length [-Werror=stringop-truncation]
   strncpy (full_name + scope_length, "::", 2);
   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This patch fixes it by using memcpy instead of strncpy.

gdb:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

	* cli/cli-decode.c (help_list): Use memcpy instead of strncpy.
	* cp-namespace.c (cp_lookup_transparent_type_loop): Likewise.

gdb/gdbserver:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

	* remote-utils.c (prepare_resume_reply): Use memcpy.
2017-11-22 12:22:11 +00:00
Simon Marchi 578290ecaf Remove usage of find_inferior when calling kill_one_lwp_callback
Replace with for_each_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (kill_one_lwp_callback): Return void, take
	argument directly, don't filter on pid.
	(linux_kill): Use for_each_thread.
2017-11-19 22:23:28 -05:00
Simon Marchi eca55aec1d Remove usages of find_thread when calling need_step_over_p
Replace with find_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (need_step_over_p): Return bool, remove dummy
	argument.
	(linux_resume, proceed_all_lwps): Use find_thread.
2017-11-19 22:23:27 -05:00
Simon Marchi 25c28b4d15 Remove usage of find_thread when calling resume_status_pending_p
Replace with find_thread.  Instead of setting the flag in the callback,
make the callback return true/false, and check the result against NULL
in the caller.

gdb/gdbserver/ChangeLog:

	* linux-low.c (resume_status_pending_p): Return bool, remove
	flag_p argument.
	(linux_resume): Use find_thread.
2017-11-19 22:23:27 -05:00
Simon Marchi 5fdda39248 Remove usage of find_inferior when calling linux_set_resume_request
Replace it with for_each_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (struct thread_resume_array): Remove.
	(linux_set_resume_request): Return void, take arguments
	directly.
	(linux_resume): Use for_each_thread.
2017-11-19 22:23:26 -05:00
Simon Marchi fcb056a58d Remove usage of find_inferior in linux_stabilize_threads
Simply replace with find_thread.

gdb/gdbserver/ChangeLog:

	* linux-low.c (stuck_in_jump_pad_callback): Change prototype,
	return bool, remove data argument.
	(linux_stabilize_threads): Use find_thread.
2017-11-19 22:23:25 -05:00
Simon Marchi 139720c5b3 Remove usage of find_inferior in unsuspend_all_lwps
Replace with for_each_thread.  I inlined unsuspend_one_lwp in
unsuspend_all_lwps, since it is very simple.

gdb/gdbserver/ChangeLog:

	* linux-low.c (unsuspend_one_lwp): Remove.
	(unsuspend_all_lwps): Use for_each_thread, inline code from
	unsuspend_one_lwp.
2017-11-19 22:23:24 -05:00
Simon Marchi 6d1e5673fe Remove usage of find_inferior in iterate_over_lwps
Replace find_inferior with find_thread.  Since it may be useful in the
future, I added another overload to find_thread which filters based on a
ptid (using ptid_t::matches), so now iterate_over_lwps doesn't have to
do the filtering itself.  iterate_over_lwps_filter is removed and
inlined into iterate_over_lwps.

gdb/gdbserver/ChangeLog:

	* gdbthread.h (find_thread): Add overload with ptid_t filter.
	* linux-low.c (struct iterate_over_lwps_args): Remove.
	(iterate_over_lwps_filter): Remove.
	(iterate_over_lwps): Use find_thread.
2017-11-19 22:23:23 -05:00
Simon Marchi bbf550d50e Remove usage of find_inferior in reset_lwp_ptrace_options_callback
Replace with for_each_thread, and inline code from
reset_lwp_ptrace_options_callback.

gdb/gdbserver/ChangeLog:

	* linux-low.c (reset_lwp_ptrace_options_callback): Remove.
	(linux_handle_new_gdb_connection): Use for_each_thread, inline
	code from reset_lwp_ptrace_options_callback.
2017-11-19 22:23:23 -05:00
Simon Marchi 00192f7717 Remove usages of find_inferior in linux-arm-low.c
Replace two usages with the overload of for_each_thread that filters on
pid.  It allows to simplify the callback a little bit.

gdb/gdbserver/ChangeLog:

	* linux-arm-low.c (struct update_registers_data): Remove.
	(update_registers_callback): Return void, take arguments
	directly, don't check thread's pid.
	(arm_insert_point, arm_remove_point): Use for_each_thread.
2017-11-19 22:23:22 -05:00
Simon Marchi 2bee2b6ca4 Remove usage of find_inferior in win32-low.c
Replace with for_each_thread.

gdb/gdbserver/ChangeLog:

	* win32-low.c (continue_one_thread): Return void, take argument
	directly.
	(child_continue): Use for_each_thread.
2017-11-19 22:23:21 -05:00
Simon Marchi 0b360f1926 Remove usage of find_inferior in win32-i386-low.c
Straightforward replacement of find_inferior with the overload of
for_each_thread that filters on pid.  I am able to build-test this
patch, but not run it.

gdb/gdbserver/ChangeLog:

	* win32-i386-low.c (update_debug_registers_callback): Rename
	to ...
	(update_debug_registers): ... this, return void, remove pid_p arg.
	(x86_dr_low_set_addr, x86_dr_low_set_control): Use for_each_thread.
2017-11-19 22:23:20 -05:00
Simon Marchi f27866ba9c Make process_info::syscalls_to_catch an std::vector
This patch makes the syscalls_to_catch field of process_info an
std::vector<int>.  The process_info structure must now be
newed/deleted.

In handle_extended_wait, the code that handles exec events destroys the
existing process_info and creates a new one.  It moves the content of
syscalls_to_catch from the old to the new vector.  I used std::move for
that (through an intermediary variable), which should have the same
behavior as the old code.

gdb/gdbserver/ChangeLog:

	* inferiors.h (struct process_info): Add constructor, initialize
	fields..
	<syscalls_to_catch>: Change type to std::vector<int>.
	* inferiors.c (add_process): Allocate process_info with new.
	(remove_process): Free process_info with delete.
	* linux-low.c (handle_extended_wait): Adjust.
	(gdb_catching_syscalls_p, gdb_catch_this_syscall_p): Adjust.
	* server.c (handle_general_set): Adjust.
2017-11-17 13:03:34 -05:00
Pedro Alves e849ea896b GDBserver: Fix ignored Ctrl-C after reconnection
This fixes the issue reported by Dmitry Antipov <dantipov@nvidia.com>
here:
  https://sourceware.org/ml/gdb/2017-10/msg00048.html

The problem is that GDBserver stops listening to Ctrl-C/interrupt
requests if you disconnect and reconnect back.

Dmitry wrote:

~~~
Currently gdbserver installs SIGIO handler just once, in
initialize_async_io() called from captured_main(), and this handler is
removed when remote_desc is closed in remote_close().  Next, when a
new instance of remote_desc is fetched from accept() and has '\003'
arrived, input_interrupt() is never called because it is not
registered as SIGIO handler.
~~~

The fix here is not remove the SIGIO handler in the first place, thus
going back to the original before-first-connection state.

(I haven't gone back to try it, but I think this was a regression
caused by commit 8b20733984 ("[GDBserver] Block and unblock SIGIO"),
which was what made remote_close remove the signal handler.)

New test included.

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

	* remote-utils.c (remote_close): Block SIGIO signals instead of
	uninstalling the SIGIO handler.

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

	* gdb.server/reconnect-ctrl-c.c: New file.
	* gdb.server/reconnect-ctrl-c.exp: New file.
2017-11-16 14:58:51 +00:00
Alan Hayward 1d0aa65c24 Allow osabi to be optional in target descriptions
gdbserver/
	* tdesc.c (tdesc_get_features_xml): Allow null osabi.
2017-11-16 10:09:17 +00:00
Yao Qi 3491a34c4f Fix tic6x-uclinux GDBserver build failure
I can't find a c6x-uclinux c++ compiler, so I use my host g++ to build
tic6x-uclinux GDBserver, and find the following build failures.  They are
not target specific, so I believe they are real errors.  This patch fixes
them.

../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c:313:34: error: invalid
conversion from 'void*' to 'tic6x_register*' [-fpermissive]
   union tic6x_register *regset = buf;
                                  ^
../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c: In function 'void tic6x_store_gregset(regcache*, const void*)':
../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c:324:40: error: invalid
conversion from 'const void*' to 'const tic6x_register*' [-fpermissive]
   const union tic6x_register *regset = buf;
                                        ^

../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c: At global scope:
../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c:359:28: error: redefinition of 'usrregs_info tic6x_usrregs_info'
 static struct usrregs_info tic6x_usrregs_info =
                            ^
../binutils-gdb/gdb/gdbserver/linux-tic6x-low.c:186:28: note: 'usrregs_info tic6x_usrregs_info' previously declared here
 static struct usrregs_info tic6x_usrregs_info;
                            ^

gdb/gdbserver:

2017-11-16  Yao Qi  <yao.qi@linaro.org>

	* linux-tic6x-low.c (tic6x_fill_gregset): Cast buf.
	(tic6x_store_gregset): Likewise.
	(tic6x_usrregs_info): Move it up.
2017-11-16 10:05:27 +00:00
Alan Hayward a602f924c8 Better make rule for arch/ files built for IPA
gdbserver/
	* Makefile.in: Update arch rules.
	* configure.srv: Explicitly mark arch/ files.
2017-11-15 09:59:12 +00:00
Andreas Schwab 5616b6c32f Enable hardware single step for m68k in GDBServer
* linux-m68k-low.c (m68k_supports_hardware_single_step): New
function.
(struct linux_target_ops) <supports_hardware_single_step>: Initialize.
2017-11-13 16:03:36 +01:00
Pedro Alves d1928160a3 Don't check termio.h and sgtty.h in common/common.m4 either
common/common.m4 still had checks for termio.h/sgtty.h that are stale
now.  Remove them.

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

	* common/common.m4 (GDB_AC_COMMON): No longer check termio.h nor
	sgtty.h.
	* config.in, configure: Regenerate.

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

	* config.in, configure: Regenerate.
2017-11-06 16:19:12 +00:00
Simon Marchi bac608e7e1 Remove find_inferior usage for thread_search
Replace it with for_each_thread.  While at it, we can inline the
callback code.  One little change is that I am using the
prev_general_thread variable instead of current_gen_ptid, since they
should have the same value.

gdb/gdbserver/ChangeLog:

	* target.c (struct thread_search): Remove.
	(thread_search_callback): Remove.
	(prepare_to_access_memory): Use for_each_thread instead of
	find_inferior.  Inline code from thread_search_callback.
2017-10-27 23:44:12 -04:00
Simon Marchi eaddb42592 Remove usage of find_inferior in resume
Change find_inferior with find_thread.  Since we can now pass arguments
directly instead of through a void pointer, we don't need the
visit_actioned_threads_data structure anymore.

gdb/gdbserver/ChangeLog:

	* server.c (struct visit_actioned_threads_data): Remove.
	(visit_actioned_threads): Change prototype to take arguments
	directly.
	(resume): Use find_thread instead of find_inferior.
2017-10-27 23:43:11 -04:00
Simon Marchi 99078d344d Remove usages of find_inferior in handle_status
Replace one with find_thread, the other with for_each_thread.

gdb/gdbserver/ChangeLog:

	* server.c (queue_stop_reply_callback): Change prototype, return
	void.
	(find_status_pending_thread_callback): Remove.
	(handle_status): Replace find_inferior with find_thread and
	for_each_thread.
2017-10-27 23:41:49 -04:00
Alan Hayward cc628f3dbb Add common AARCH64 REGNUM defines
gdb/
	* aarch64-tdep.h (enum aarch64_regnum): Remove.
	* arch/aarch64.h: New file.

gdbserver/
	* linux-aarch64-low.c (aarch64_fill_gregset): Replace defines
	with REGNO.
	(aarch64_store_gregset): Likewise.
	(aarch64_fill_fpregset): Likewise.
	(aarch64_store_fpregset): Likewise.
2017-10-25 09:06:41 +01:00
Simon Marchi 4d3bb80e5d Add overloads of for_each_thread/find_thread that filter on pid
It happens often that we want to iterate or find threads restricted to a
given pid.  I think it's worth having an overload to help with this.
Right now there is a single user of each of the find_thread and
for_each_thread overload, but as we replace the usages of find_inferior
with for_each_thread/find_thread, more usages will pop up.

gdb/gdbserver/ChangeLog:

	* gdbthread.h (find_thread, for_each_thread): New functions.
	* inferiors.c (thread_of_pid): Remove.
	(find_any_thread_of_pid): Use find_thread.
	* linux-low.c (num_lwps): Use for_each_thread.
2017-10-21 12:20:21 -04:00
Yao Qi 7a7cdfa04b [GDBserver] Move aarch64-insn.o to arch/ and remove one Makefile rule
gdb/gdbserver:

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

	* Makefile.in: Remove one rule.
	* configure.srv: Rename aarch64-insn.o with arch/aarch64-insn.o.
2017-10-17 12:12:04 +01:00
Yao Qi e675d1703f [GDBserver] Move arm-linux.o and arm-get-next-pcs.o to arch/
gdb/gdbserver:

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

	* configure.srv: Rename arm-linux.o with arch/arm-linux.o.
	Rename arm-get-next-pcs.o with arch/arm-get-next-pcs.o.
2017-10-17 12:12:04 +01:00
Yao Qi 7eb4e0f956 [GDBserver] Move arm.o to arch/arm.o
gdb/gdbserver:

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

	* configure.srv: Rename arm.o with arch/arm.o.
2017-10-17 12:12:04 +01:00
Yao Qi 60d6cfc99e [GDBserver] Replicate src dir in build dir
Similar to f38307f5 (Replicate src dir in build dir), this patch change
configure and Makefile to generate object files in arch/ directory.

gdb/gdbserver:

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

	* Makefile.in (CONFIG_SRC_SUBDIR): New variable.
	(clean): Remove .o files in CONFIG_SRC_SUBDIR.
	(distclean): Remove DEPDIR in CONFIG_SRC_SUBDIR.
	(arch-i386.o, arch-amd64.o): Remove rules.
	(arch/%.o): New rule.
	Update POSTCOMPILE and COMPILE.pre.
	* configure.ac: Invoke AC_CONFIG_COMMANDS.
	* configure: Re-generated.
	* configure.srv: Replace arch-i386.o with arch/i386.o.
	Replace arch-amd64.o with arch/amd64.o.
2017-10-17 12:12:04 +01:00
Yao Qi 5bfda25568 Regenerate gdbserver/configure
4fa7574 (Fix gdb 8.1 Solaris compilation) changes warning.m4 and updates
configure, but gdbserver/configure is not updated.

gdb/gdbserver:

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

	* configure: Regenerated.
2017-10-16 11:26:38 +01:00
Simon Marchi 9c80ecd646 gdbserver: use std::list for all_threads
Remove the usage of inferior_list for the all_threads list in
gdbserver.  The entry field in thread_info is removed, and replaced by a
simple ptid field.

I added some functions to iterate (for_each_thread) and find threads
(find_thread).  However, changing all the users of find_inferior & co to
use these new functions would have made the patch way too big.  So I
opted instead to make find_inferior & co some shims, so that the
existing code only needs to be updated minimally.  We can then update
the existing code to use the new functions incrementally (I've started
to do the work, but I'll post it afterwards, see [1] if you want a peek).

This patch has been built-tested on all relevant platforms, except
lynx.  I also regtested using the native-gdbserver and
native-extended-gdbserver boards on x86.

[1] https://github.com/simark/binutils-gdb/commits/kill-inferior-list-entry

gdb/gdbserver/ChangeLog:

	* inferiors.h: (struct inferior_list): Remove.
	(struct inferior_list_entry); Remove.
	(add_inferior_to_list, clear_inferior_list, one_inferior_p,
	A_I_NEXT, ALL_INFERIORS_TYPE, ALL_INFERIORS, remove_inferior,
	get_first_inferior): Remove.
	(for_each_inferior, for_each_inferior_with_data, find_inferior,
	find_inferior_id, find_inferior_in_random): Change signature.
	* inferiors.c (all_threads): Change type to
	std::list<thread_info *>.
	(get_thread): Remove macro.
	(find_inferior, find_inferior_id): Change signature, implement
	using find_thread.
	(find_inferior_in_random): Change signature, implement using
	find_thread_in_random.
	(for_each_inferior, for_each_inferior_with_data): Change
	signature, implement using for_each_thread.
	(add_inferior_to_list, remove_inferior): Remove.
	(add_thread, get_first_thread, thread_of_pid,
	find_any_thread_of_pid, free_one_thread, remove_thread): Update.
	(get_first_inferior, one_inferior_p, clear_inferior_list):
	Remove.
	(clear_inferiors, get_thread_process): Update.
	* gdbthread.h: Include <list>.
	(struct thread_info) <entry>: Remove field.
	<id>: New field.
	(all_threads): Change type to std::list<thread_info *>.
	(get_first_inferior): Add doc.
	(find_thread, for_each_thread, find_thread_in_random): New
	functions.
	(current_ptid, pid_of, ptid_of, lwpid_of): Update.
	* linux-arm-low.c (update_registers_callback): Update.
	* linux-low.c (second_thread_of_pid_p): Update.
	(kill_one_lwp_callback, linux_detach_lwp_callback,
	delete_lwp_callback, status_pending_p_callback, same_lwp,
	find_lwp_pid, num_lwps, iterate_over_lwps_filter,
	iterate_over_lwps, not_stopped_callback,
	resume_stopped_resumed_lwps, count_events_callback,
	select_singlestep_lwp_callback, select_event_lwp_callback,
	unsuspend_one_lwp, linux_wait_1, send_sigstop_callback,
	suspend_and_send_sigstop_callback, wait_for_sigstop,
	stuck_in_jump_pad_callback, move_out_of_jump_pad_callback,
	lwp_running, linux_set_resume_request, resume_status_pending_p,
	need_step_over_p, start_step_over, linux_resume_one_thread,
	proceed_one_lwp, unsuspend_and_proceed_one_lwp,
	reset_lwp_ptrace_options_callback): Update.
	* linux-mips-low.c (update_watch_registers_callback): Update.
	* regcache.c (regcache_invalidate_one, regcache_invalidate):
	Update.
	(free_register_cache_thread_one): Remove.
	(regcache_release): Update.
	* server.c (handle_btrace_enable_bts, handle_btrace_enable_pt,
	handle_qxfer_threads_worker): Update.
	(handle_query): Update, use list iterator.
	(visit_actioned_threads, handle_pending_status,
	queue_stop_reply_callback, gdb_wants_all_threads_stopped,
	clear_pending_status_callback, set_pending_status_callback,
	find_status_pending_thread_callback, handle_status,
	process_serial_event): Update.
	* target.c (thread_search_callback): Update.
	* thread-db.c (thread_db_get_tls_address): Update.
	* tracepoint.c (tracepoint_finished_step, tracepoint_was_hit):
	Update.
	* win32-i386-low.c (update_debug_registers_callback): Update.
	* win32-low.c (delete_thread_info, child_delete_thread,
	continue_one_thread, suspend_one_thread,
	get_child_debug_event): Adjust.
2017-10-14 09:11:12 -04:00
Simon Marchi 9179355e65 gdbserver: Use std::list for all_processes
Remove the usage of inferior_list for the all_processes list in
gdbserver, replace it with an std::list. The entry field in process_info
is removed, and replaced by a simple pid field.

The pid_of macro, used for both processes and threads, is replaced with
separate functions.  For completeness, I changed ptid_of and lwpid_of to
functions as well.

gdb/gdbserver/ChangeLog:

	* gdbthread.h (ptid_of, pid_of, lwpid_of): New functions.
	* inferiors.h: Include <list>.
	(struct process_info) <entry>: Remove field.
	<pid>: New field.
	(pid_of): Change macro to function.
	(ptid_of, lwpid_of): Remove macro.
	(all_processes): Change type to std::list<process_info *>.
	(ALL_PROCESSES): Remove macro.
	(for_each_process, find_process): New function.
	* inferiors.c (all_processes): Change type to
	std::list<process_info *>.
	(find_thread_process): Adjust.
	(add_process): Likewise.
	(remove_process): Likewise.
	(find_process_pid): Likewise.
	(get_first_process): Likewise.
	(started_inferior_callback): Remove.
	(have_started_inferiors_p): Adjust.
	(attached_inferior_callback): Remove.
	(have_attached_inferiors_p): Adjust.
	* linux-low.c (check_zombie_leaders): Likewise.
	* linux-x86-low.c (x86_arch_setup_process_callback): Remove.
	(x86_linux_update_xmltarget): Adjust.
	* server.c (handle_query): Likewise.
	(gdb_reattached_process): Remove.
	(handle_status): Adjust.
	(kill_inferior_callback): Likewise.
	(detach_or_kill_inferior): Remove.
	(print_started_pid): Likewise.
	(print_attached_pid): Likewise.
	(detach_or_kill_for_exit): Update.
	(process_serial_event): Likewise.
	* linux-arm-low.c (arm_new_fork): Likewise.
2017-10-14 09:10:42 -04:00
Simon Marchi c9cb8905b4 gdbserver: Use std::list for all_dlls
As a small step towards removing inferior_list/inferior_list_entry, this
patch replaces the usage of inferior_list for the list of dlls by an
std::list.  The dll_info type now uses an std::string for name and has a
simple constructor.

I am able to build gdbserver with mingw on Linux, but I am not able to
test this on a Windows machine (the only platform that uses this code).

gdb/gdbserver/ChangeLog:

	* dll.h: Include <list>.
	(struct dll_info): Add constructor.
	<entry>: Remove field.
	(all_dlls): Change type to std::list<dll_info>.
	* dll.c: Include <algorithm>.
	(get_dll): Remove macro.
	(all_dlls): Change type to std::list<dll_info *>.
	(free_one_dll): Remove.
	(match_dll): Likewise.
	(loaded_dll): Adjust.
	(unloaded_dll): Adjust to all_dlls type change, use
	std::find_if.  Inline code from match_dll.
	(clear_dlls): Adjust to all_dlls type change.
	* server.c (emit_dll_description): Remove.
	(handle_qxfer_libraries): Adjust to all_dlls type change,
	integrate emit_dll_description's functionality.
2017-10-14 09:09:22 -04:00
Simon Marchi 04ec7890fc linux low: Make the arch code free arch_process_info
For the same reason as the previous patch, we need to make the
arch-specific code free the arch_process_info structure it allocates.

gdb/gdbserver/ChangeLog:

	* linux-low.h (struct linux_target_ops) <delete_process>: New
	field.
	* linux-low.c (linux_mourn): Call the_low_target.delete_process.
	* linux-aarch64-low.c (aarch64_linux_delete_process): New.
	(struct linux_target_ops): Add delete_process callback.
	* linux-arm-low.c (arm_delete_process): New.
	(struct linux_target_ops): Add delete_process callback.
	* linux-bfin-low.c (struct linux_target_ops): Likewise.
	* linux-crisv32-low.c (struct linux_target_ops): Likewise.
	* linux-m32r-low.c (struct linux_target_ops): Likewise.
	* linux-mips-low.c (mips_linux_delete_process): New.
	(struct linux_target_ops): Add delete_process callback.
	* linux-ppc-low.c (struct linux_target_ops): Likewise.
	* linux-s390-low.c (struct linux_target_ops): Likewise.
	* linux-sh-low.c (struct linux_target_ops): Likewise.
	* linux-tic6x-low.c (struct linux_target_ops): Likewise.
	* linux-tile-low.c (struct linux_target_ops): Likewise.
	* linux-x86-low.c (x86_linux_delete_process): New.
	(struct linux_target_ops): Add delete_process callback.
	* linux-xtensa-low.c (struct linux_target_ops): Likewise.
2017-10-12 16:49:27 -04:00
Simon Marchi 466eeceef4 lwp_info: Make the arch code free arch_lwp_info
I have the goal of "poisoning" the XNEW/xfree-family of functions, so
that we catch their usages with non-POD types.  A few things need to be
fixed in the mean time, this is one.

The common lwp code in linux-nat.c and gdbserver/linux-low.c xfrees the
private lwp data of type arch_lwp_info.  However, that type is opaque
from its point of view, as its defined differently in each arch-specific
implementation.  This trips on the std::is_pod<T> check, since the
compiler can't tell whether the type is POD or not if it doesn't know
about it.

My initial patch [1] made a class hierarchy with a virtual destructor.
However, as Pedro pointed out, we only have one native architecture at
the time built in gdb and gdbserver, so that's overkill.  Instead, we
can move the responsibility of free'ing arch_lwp_info to the arch code
(which is also the one that allocated it in the first place).  This is
what this patch does.

Also, I had the concern that if we wanted to use C++ features in these
structures, we would have a problem with the one-definition rule.
However, since a build will only have one version of arch_lwp_info,
that's not a problem.

There are changes in arch-specific files, I was only able to built-test
this patch with the following cross-compilers:

  aarch64-linux-gnu
  alpha-linux-gnu
  arm-linux-gnueabihf
  hppa-linux-gnu
  m68k-linux-gnu
  mips64el-linux-gnuabi64
  powerpc64-linux-gnu
  s390x-linux-gnu
  sh4-linux-gnu
  sparc64-linux-gnu
  x86_64-linux-gnu
  x86_64-w64-mingw32

A buildbot run didn't find any regression.

[1] https://sourceware.org/ml/gdb-patches/2017-08/msg00255.html

gdb/ChangeLog:

	* linux-nat.h (linux_nat_set_delete_thread): New declaration.
	* linux-nat.c (linux_nat_delete_thread): New variable.
	(lwp_free): Invoke linux_nat_delete_thread if set.
	(linux_nat_set_delete_thread): New function.
	* aarch64-linux-nat.c (_initialize_aarch64_linux_nat): Assign
	thread delete callback.
	* arm-linux-nat.c (arm_linux_delete_thread): New function.
	(_initialize_arm_linux_nat): Assign thread delete callback.
	* s390-linux-nat.c (s390_delete_thread): New function.
	(_initialize_s390_nat): Assign thread delete callback.
	* x86-linux-nat.c (x86_linux_add_target): Likewise.
	* nat/aarch64-linux.c (aarch64_linux_delete_thread): New
	function.
	* nat/aarch64-linux.h (aarch64_linux_delete_thread): New
	declaration.
	* nat/x86-linux.c (x86_linux_delete_thread): New function.
	* nat/x86-linux.h (x86_linux_delete_thread): New declaration.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-low.c (the_low_target): Add thread delete
	callback.
	* linux-arm-low.c (arm_delete_thread): New function.
	(the_low_target): Add thread delete callback.
	* linux-bfin-low.c (the_low_target): Likewise.
	* linux-crisv32-low.c (the_low_target): Likewise.
	* linux-low.c (delete_lwp): Invoke delete_thread callback if
	set.
	* linux-low.h (struct linux_target_ops) <delete_thread>: New
	field.
	* linux-m32r-low.c (the_low_target): Add thread delete callback.
	* linux-mips-low.c (mips_linux_delete_thread): New function.
	(the_low_target): Add thread delete callback.
	* linux-ppc-low.c (the_low_target): Likewise.
	* linux-s390-low.c (the_low_target): Likewise.
	* linux-sh-low.c (the_low_target): Likewise.
	* linux-tic6x-low.c (the_low_target): Likewise.
	* linux-tile-low.c (the_low_target): Likewise.
	* linux-x86-low.c (the_low_target): Likewise.
	* linux-xtensa-low.c (the_low_target): Likewise.
2017-10-12 16:48:22 -04:00
Yuanhui Zhang b79f7801a2 Fix GDB build under msys+mingw gcc 32bit
I see a build error when building GDB under msys+mingw gcc 32bit:

 g++ -x c++ -std=gnu++11 -g -O2    -I. -I../../../binutils-gdb/gdb/gdbserver -I../../../binutils-gdb/gdb/gdbserver/../common -I../../../binutils-gdb/gdb/gdbserver/../regformats -I../../../binutils-gdb/gdb/gdbserver/.. -I../../../binutils-gdb/gdb/gdbserver/../../include -I../../../binutils-gdb/gdb/gdbserver/../gnulib/import -Ibuild-gnulib-gdbserver/import  -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-narrowing -Wno-error=maybe-uninitialized -Wno-format -Werror -DGDBSERVER -c -o win32-low.o -MT win32-low.o -MMD -MP -MF .deps/win32-low.Tpo ../../../binutils-gdb/gdb/gdbserver/win32-low.c
 ../../../binutils-gdb/gdb/gdbserver/win32-low.c: In function 'BOOL create_process(const char*, char*, DWORD, PROCESS_INFORMATION*)':
 ../../../binutils-gdb/gdb/gdbserver/win32-low.c:566:48: error: 'get_inferior_cwd' was not declared in this scope
    const char *inferior_cwd = get_inferior_cwd ();
						 ^
 make[4]: *** [win32-low.o] Error 1

It can be fixed by simply including the right header file.

gdb/gdbserver/ChangeLog:
2017-10-06  Yuanhui Zhang  <asmwarrior@gmail.com>

	* win32-low.c: Include "common-inferior.h".
2017-10-06 11:44:54 +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
Sergio Durigan Junior d092c5a246 Implement "set cwd" command on GDB
This commit adds new "set/show cwd" commands, which are used to
set/show the current working directory of the inferior that will be
started.

The idea here is that "set cwd" will become the de facto way of
setting the inferior's cwd.  Currently, the user can use "cd" for
that, but there are side effects: with "cd", GDB also switches to
another directory, and that can impact the loading of scripts and
other files.  With "set cwd", we separate the logic into a new
command.

To maintain backward compatibility, if the user issues a "cd" command
but doesn't use "set cwd", then the inferior's cwd will still be
changed according to what the user specified.  However, "set cwd" has
precedence over "cd", so it can always be used to override it.

"set cwd" works in the following way:

- If the user sets the inferior's cwd by using "set cwd", then this
  directory is saved into current_inferior ()->cwd and is used when
  the inferior is started (see below).

- If the user doesn't set the inferior's cwd by using "set cwd", but
  rather use the "cd" command as before, then this directory is
  inherited by the inferior because GDB will have chdir'd into it.

On Unix-like hosts, the way the directory is changed before the
inferior execution is by expanding the user set directory before the
fork, and then "chdir" after the call to fork/vfork on
"fork_inferior", but before the actual execution.  On Windows, the
inferior cwd set by the user is passed directly to the CreateProcess
call, which takes care of the actual chdir for us.

This way, we'll make sure that GDB's cwd is not affected by the user
set cwd.

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

	* NEWS (New commands): Mention "set/show cwd".
	* cli/cli-cmds.c (_initialize_cli_cmds): Mention "set cwd" on
	"cd" command's help text.
	* common/common-inferior.h (get_inferior_cwd): New prototype.
	* infcmd.c (inferior_cwd_scratch): New global variable.
	(set_inferior_cwd): New function.
	(get_inferior_cwd): Likewise.
	(set_cwd_command): Likewise.
	(show_cwd_command): Likewise.
	(_initialize_infcmd): Add "set/show cwd" commands.
	* inferior.h (class inferior) <cwd>: New field.
	* nat/fork-inferior.c: Include "gdb_tilde_expand.h".
	(fork_inferior): Change inferior's cwd before its execution.
	* windows-nat.c (windows_create_inferior): Pass inferior's cwd
	to CreateProcess.

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

	* inferiors.c (current_inferior_cwd): New global variable.
	(get_inferior_cwd): New function.
	* inferiors.h (struct process_info) <cwd>: New field.

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

	* gdb.texinfo (Starting your Program) <The working directory.>:
	Mention new "set cwd" command.
	(Working Directory) <Your Program's Working Directory>:
	Rephrase to explain that "set cwd" exists and is the default
	way to change the inferior's cwd.

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

	* gdb.base/set-cwd.c: New file.
	* gdb.base/set-cwd.exp: Likewise.
2017-10-04 01:59:30 -04:00
Sergio Durigan Junior 7da0a88674 Introduce gdb_tilde_expand
Currently, whenever we want to handle paths provided by the user and
perform tilde expansion on GDB, we rely on "tilde_expand", which comes
from readline.  This was enough for our use cases so far, but the
situation will change when we start dealing with paths on gdbserver as
well, which is what the next patches implement.

Unfortunately it is not possible to use "tilde_expand" in this case
because gdbserver doesn't use readline.  For that reason I decided to
implement a new "gdb_tilde_expand" function, which is basically a
wrapper for "glob" and its GNU extension, GLOB_TILDE_CHECK.  With the
import of the "glob" module from gnulib, we're sure that "glob" always
supports this extension.

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

	* Makefile.in (SFILES): Add gdb_tilde_expand.c.
	(HFILES_NO_SRCDIR): Add gdb_tilde_expand.h.
	(COMMON_OBS): Add gdb_tilde_expand.o.
	* common/gdb_tilde_expand.c: New file.
	* common/gdb_tilde_expand.h: Likewise.

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

	* Makefile.in (SFILES): Add $(srcdir)/common/gdb_tilde_expand.c.
	(OBS): Add gdb_tilde_expand.o.
2017-10-04 01:57:29 -04:00
Simon Marchi 289a6840c1 nto & lynx x86: call init_target_desc
In gdbserver, target descriptions need to be initialized by calling
init_target_desc.  Because i386_create_target_description is shared with
GDB, it doesn't do that, the callers must take care of it.  These two
platforms currently don't.

I am not able to build them, so I couldn't test.

gdb/gdbserver/ChangeLog:

	* lynx-i386-low.c (lynx_i386_arch_setup): Call init_target_desc.
	* nto-x86-low.c (nto_x86_arch_setup): Likewise.
2017-10-02 11:00:30 +02: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 5b9ca4d43b gdbserver/libthread_db: Don't ignore memory reading failures
If we had this in place before, then the regression fixed by the
previous commit would have been been visible is all test runs.  E.g.:

  Running src/gdb/testsuite/gdb.threads/multi-create-ns-info-thr.exp ...
  FAIL: gdb.threads/multi-create-ns-info-thr.exp: continue to breakpoint 6

Debugging manually we'd see this:
  gdbserver: Cannot get thread handle for LWP 1467: generic error

Instead of:
  gdbserver: PID mismatch!  Expected 27472, got 27471

which is misleading - gdbserver didn't 27471, that was stale stack
data from previous function invocations.

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

	* proc-service.c (ps_pdread): Return PS_ERR if reading memory
	fails.
2017-09-29 13:10:39 +01:00
Pedro Alves 94c207e097 Fix gdbserver regression exposed by gdb.threads/multi-create-ns-info-thr.exp
Commit 8629910955 ("Add thread_db_notice_clone to gdbserver")
introduced calls into libthread_db without making sure that the
current thread is pointing to a know-stopped thread.  This resulted in
sometimes thread_db_notice_clone failing->find_one_thread failing like
this, as seen when running gdb.threads/multi-create-ns-info-thr.exp:

~~~
  Thread <6> executing
  Thread <7> executing
  gdbserver: PID mismatch!  Expected 27472, got 27471
  gdbserver: Cannot find thread after clone.

  Thread <1000> executing
  Thread <1001> executing
~~~

Things go south from here and sometimes that ends up resulting in
gdbserver crashing and the test failing.

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

	* linux-low.c (handle_extended_wait): Pass parent thread instead
	of process to thread_db_notice_clone.
	* linux-low.h (thread_db_notice_clone): Replace parent process
	parameter with parent thread parameter.
	* thread-db.c (find_one_thread): Add comment.
	(thread_db_notice_clone): Replace parent process parameter with
	parent thread parameter.  Temporarily switch to the parent thread.
2017-09-29 13:06:34 +01:00
Sergio Durigan Junior 75352e283f Use "switch_to_thread" more thoroughly on gdbserver
This is a technical debt that I left when I ported "switch_to_thread"
to gdbserver.  It's a simple patch that converts occurences of:

  current_thread = find_thread_ptid (ptid);

to:

  switch_to_thread (ptid);

This patch also converts a simple "if" to a "gdb_assert" on
gdbserver's version of "switch_to_thread":

  gdb_assert (ptid != minus_one_ptid);

This change makes the code more similar to what GDB already does.

Regtested on BuildBot.

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

	* gdbthread.h: Include "common-gdbthread.h".
	* inferiors.c (switch_to_thread): Use "gdb_assert" instead of
	"if" when validating the ptid.
	* remote-utils.c: Include "gdbthread.h".
	(prepare_resume_reply): Use "switch_to_thread".
	* target.c (done_accessing_memory): Likewise.
2017-09-26 12:50:25 -04:00
Andreas Arnez ad3396348e S390: Add guarded-storage register support to gdbserver
Enable gdbserver to deal with the new guarded-storage register sets.

gdb/gdbserver/ChangeLog:

	* configure.srv (s390*-*-linux*): Add s390-gs-linux64.o and
	s390x-gs-linux64.o to srv_regobj.  Add s390-gs-linux64.xml,
	s390x-gs-linux64.xml, s390-gs.xml, and s390-gsbc.xml to
	srv_xmlfiles.  Add s390-gs-linux64-ipa.o and
	s390x-gs-linux64-ipa.o to ipa_obj.
	* linux-s390-low.c (HWCAP_S390_GS): New define.
	(s390_fill_gs, s390_store_gs, s390_fill_gsbc, s390_store_gsbc):
	New functions.
	(s390_regsets): Add regsets for NT_S390_GS_CB and NT_S390_GS_BC.
	(s390_arch_setup): Check for guarded-storage support and choose
	appropriate tdesc.
	(initialize_low_arch): Invoke init_registers_s390_gs_linux64 and
	init_registers_s390x_gs_linux64.
	* linux-s390-tdesc.h (enum s390_linux_tdesc) <S390_TDESC_GS>: New
	enum value.
	(init_registers_s390x_gs_linux64, tdesc_s390x_gs_linux64)
	(init_registers_s390_gs_linux64, tdesc_s390_gs_linux64): Declare.
2017-09-25 16:02:23 +02:00
Simon Marchi cc4d742f4c gdbserver x86 on win32: call init_target_desc
When trying to run gdbserver compiled for x86 win32 under wine, I get:

  $ wine ./gdbserver/gdbserver.exe --once :1234 ./test
  /home/emaisin/src/binutils-gdb/gdb/gdbserver/regcache.c:177: A problem internal to GDBserver has been detected.
  regcache* new_register_cache(const target_desc*): Assertion `tdesc->registers_size != 0' failed.

It seems like on that platform, init_target_desc is never called, so
registers_size is never computed.

My first thought was to call init_target_desc somewhere in win32-low.c,
but it turns out that when using win32 on arm, the target description is
already initialized by the generated code.  My second thought was to
call it in {i386,amd64}_create_target_description, but those functions
are shared with GDB, and init_target_desc is gdbserver-specific.  So I
ended up with the simplest fix, calling it in i386_arch_setup.

Now I hit some other problem:

  $ wine ./gdbserver/gdbserver.exe --once :1234 ./test
  Killing process(es): 39
  No program to debug
  Exiting

but still, I think fixing the tdesc issue this is a step forward.

gdb/gdbserver/ChangeLog:

	* win32-i386-low.c (i386_arch_setup): Call init_target_desc.
2017-09-22 16:51:55 +02: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
Kevin Buettner 8629910955 Add thread_db_notice_clone to gdbserver
While working on a patch for fetching a thread handle in gdbserver, I
ran into a circumstance in which tests in gdb.mi/mi-nsmoribund.exp
would occasionally fail.  Over a large enough number of runs, it would
fail roughly 2% of the time.

That thread handle patch caused find_one_thread() to be called on
every stop.  find_one_thread() calls td_ta_map_lwp2thr() which, in
turn, can cause ps_get_thread_area() to be called.
ps_get_thread_area() makes a call to ptrace() for getting the thread
area address.  If this should happen when the thread is not stopped,
the call to ptrace will return error which in turn propogates back to
find_one_thread().  find_one_thread() calls error() in this instance
which causes the program to die.

This patch causes find_one_thread() to be called upon reciept of a
clone event.  Since the clone is stopped, the circumstances described
above cannot occur.

gdb/gdbserver/ChangeLog:

	* linux-low.c (handle_extended_wait): Call thread_db_notice_clone().
	* linux-low.h (thread_db_notice_clone): Declare.
	* thread-db.c (thread_db_notice_clone): New function.
2017-09-21 11:49:47 -07:00
Pedro Alves f557a88ab1 gdbserver: Remove traces of ancient Hc handling
Back in commit f0db101d98 ("gdbserver: don't pick a random thread if
the current thread dies"), a couple years ago, the last references to
set_desired_thread(0) [select the Hc thread] were removed, and all the
remaining calls to set_desired_thread pass '1', meaning general
thread.  This means we can simplify set_desired_thread.

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

	* server.c (gdb_read_memory, handle_status, process_serial_event)
	(handle_serial_event, handle_target_event): Adjust to
	set_desired_thread prototype change.
	* target.c (set_desired_thread): Remove 'use_general' parameter
	and adjust.
	* target.h (set_desired_thread): Remove 'use_general' parameter.
2017-09-21 16:52:33 +01: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
Simon Marchi 04fd3ba9b6 Refactor handle_qxfer_libraries and friends to use std::string
Using std::string in handle_qxfer_libraries and friends allow to
simplify the code.  We don't have to manually free the buffer, and we
don't have to pre-compute the required space.

gdb/gdbserver/ChangeLog:

	* server.c (accumulate_file_name_length): Remove.
	(emit_dll_description): Adjust to std::string change.
	(handle_qxfer_libraries): Use std::string to hold document.
2017-09-16 14:22:11 +02:00
Simon Marchi 5e1875543d Make xml_escape_text return an std::string
This is a simple replacement, it allows removing some manual free'ing in
the callers.

gdb/ChangeLog:

	* common/buffer.c (buffer_xml_printf): Adjust.
	* common/xml-utils.c (xml_escape_text): Change return type to
	std::string, update code accordingly.
	* common/xml-utils.h (xml_escape_text): Change return type to
	std::string.
	* rs6000-aix-tdep.c (rs6000_aix_shared_library_to_xml): Adjust.
	* windows-tdep.c (windows_xfer_shared_library): Adjust.
	* unittests/xml-utils-selftests.c (test_xml_escape_text):
	Adjust.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_qxfer_libraries_svr4): Adjust to change of
	return type of xml_escape_text.
	* server.c (emit_dll_description): Likewise.
2017-09-16 14:19:31 +02:00
Simon Marchi 1526853e34 Add selftests run filtering
With the growing number of selftests, I think it would be useful to be
able to run only a subset of the tests.  This patch associates a name to
each registered selftest.  It then allows doing something like:

  (gdb) maintenance selftest aarch64
  Running self-tests.
  Running selftest aarch64-analyze-prologue.
  Running selftest aarch64-process-record.
  Ran 2 unit tests, 0 failed

or with gdbserver:

  ./gdbserver --selftest=aarch64

In both cases, only the tests that contain "aarch64" in their name are
ran.  To help validate that the tests you want to run were actually ran,
it also prints a message with the test name before running each test.

Right now, all the arch-dependent tests are registered as a single test
of the selftests.  To be able to filter those too, I made them
"first-class citizen" selftests.  The selftest type is an interface,
with different implementations for "simple selftests" and "arch
selftests".  The run_tests function simply iterates on that an invokes
operator() on each test.

I changed the tests data structure from a vector to a map, because

  - it allows iterating in a stable (alphabetical) order
  - it allows to easily verify if a test with a given name has been
    registered, to avoid duplicates

There's also a new command "maintenance info selftests" that lists the
registered selftests.

gdb/ChangeLog:

	* common/selftest.h (selftest): New struct/interface.
	(register_test): Add name parameter, add new overload.
	(run_tests): Add filter parameter.
	(for_each_selftest_ftype): New typedef.
	(for_each_selftest): New declaration.
	* common/selftest.c (tests): Change type to
	map<string, unique_ptr<selftest>>.
	(simple_selftest): New struct.
	(register_test): New function.
	(register_test): Add name parameter and use it.
	(run_tests): Add filter parameter and use it.  Add prints.
	Adjust to vector -> map change.
	* aarch64-tdep.c (_initialize_aarch64_tdep): Add names when
	registering selftests.
	* arm-tdep.c (_initialize_arm_tdep): Likewise.
	* disasm-selftests.c (_initialize_disasm_selftests): Likewise.
	* dwarf2-frame.c (_initialize_dwarf2_frame): Likewise.
	* dwarf2loc.c (_initialize_dwarf2loc): Likewise.
	* findvar.c (_initialize_findvar): Likewise.
	* gdbarch-selftests.c (_initialize_gdbarch_selftests): Likewise.
	* maint.c (maintenance_selftest): Update call to run_tests.
	(maintenance_info_selftests): New function.
	(_initialize_maint_cmds): Register "maintenance info selftests"
	command.  Update "maintenance selftest" doc.
	* regcache.c (_initialize_regcache): Add names when registering
	selftests.
	* rust-exp.y (_initialize_rust_exp): Likewise.
	* selftest-arch.c (gdbarch_selftest): New struct.
	(gdbarch_tests): Remove.
	(register_test_foreach_arch): Add name parameter.  Call
	register_test.
	(tests_with_arch): Remove, move most content to
	gdbarch_selftest::operator().
	(_initialize_selftests_foreach_arch): Remove.
	* selftest-arch.h (register_test_foreach_arch): Add name
	parameter.
	(run_tests_with_arch): New declaration.
	* utils-selftests.c (_initialize_utils_selftests): Add names
	when registering selftests.
	* utils.c (_initialize_utils): Likewise.
	* unittests/array-view-selftests.c
	(_initialize_array_view_selftests): Likewise.
	* unittests/environ-selftests.c (_initialize_environ_selftests):
	Likewise.
	* unittests/function-view-selftests.c
	(_initialize_function_view_selftests): Likewise.
	* unittests/offset-type-selftests.c
	(_initialize_offset_type_selftests): Likewise.
	* unittests/optional-selftests.c
	(_initialize_optional_selftests): Likewise.
	* unittests/scoped_restore-selftests.c
	(_initialize_scoped_restore_selftests): Likewise.
	* NEWS: Document "maintenance selftest" and "maint info
	selftests".

gdb/gdbserver/ChangeLog:

	* server.c (captured_main): Accept argument for --selftest.
	Update run_tests call.
	* linux-x86-tdesc-selftest.c (initialize_low_tdesc): Add names
	when registering selftests.

gdb/doc/ChangeLog:

	* gdb.texinfo (Maintenance Commands): Document filter parameter
	of "maint selftest".  Document "maint info selftests" command.
2017-09-16 14:06:03 +02:00
Sergio Durigan Junior c4dfafabc5 Use std::vector on tdesc->reg_defs (gdbserver/tdesc.h)
This is a followup patch to the build breakage fix on AArch64.  While
doing the fix, I found it better to convert tdesc->reg_defs (on
gdbserver/tdesc.h) from using VEC to using std::vector.  This makes
the code easier to read and maintain, and also is one more step
towards the C++fication.

Regtested on BuildBot.

2017-09-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* regcache.c (get_thread_regcache): Update code to use "std::vector"
	instead of "VEC" for "target_desc.reg_defs".
	(regcache_cpy): Likewise.
	(registers_to_string): Likewise.
	(registers_from_string): Likewise.
	(find_regno): Likewise.
	(supply_regblock): Likewise.
	(regcache_raw_read_unsigned): Likewise.
	* tdesc.c (init_target_desc): Likewise.
	(tdesc_create_reg): Likewise.
	* tdesc.h: Remove declaration of "tdesc_reg_p".  Include <vector>.
	(struct target_desc) <reg_defs>: Convert to "std::vector".
	(target_desc): Do not initialize "reg_defs".
	(~target_desc): Update code to use "std::vector" instead of "VEC"
	for "target_desc.reg_defs".
	(operator==): Likewise.
2017-09-15 23:51:33 -04:00
Simon Marchi 124aceb46d gdbserver: Remove thread_to_gdb_id
As explained in the previous patch, the gdb_id concept is no longer
relevant.  The function thread_to_gdb_id is trivial, it returns the
thread's ptid.  Remove it and replace its usage with ptid_of.

The changes in nto-low.c and lynx-low.c are fairly straightforward, but
I was not able to build test them.

gdb/gdbserver/ChangeLog:

	* inferiors.h (thread_to_gdb_id): Remove.
	* inferiors.c (thread_to_gdb_id): Remove.
	* server.c (handle_qxfer_threads_worker, handle_query): Adjust.
	* lynx-low.c (lynx_resume, lynx_wait_1, lynx_fetch_registers,
	lynx_store_registers, lynx_read_memory, lynx_write_memory):
	Likewise.
	* nto-low.c (nto_fetch_registers, nto_store_registers,
	nto_stopped_by_watchpoint, nto_stopped_data_address): Likewise.
2017-09-15 18:02:51 +02:00
Simon Marchi 96cde54f0a gdbserver: Remove gdb_id_to_thread_id
From what I understand, this function is not doing anything useful as of
today.

Here's the result of my archeological research:

- The field thread_info::gdb_id was added in

  a06660f7  Use LWP IDs for thread IDs in gdbserver

  There was problem when using a 32-bits gdb with a 64-bits gdbserver.
  For some reason that I don't fully understand, the thread ids
  exchanged between gdb and gdbserver could overflow a 32 bits data
  type.  My guess is that they were the thread address (e.g. the
  0x7ffff7f20b40 in "Thread 0x7ffff7f20b40 (LWP 1058)" today).  This
  patch changed that so gdb/gdbserver would talk in terms of the OS
  assigned numerical id (as shown in ps).  It therefore added a way to
  convert between this gdb_id (the numerical id) and the thread id (the
  address).

- 95954743cb  Implement the multiprocess extensions, and add linux
              multiprocess supportNon-stop mode support.

  This patch made gdbserver deal with threads using their numerical ids
  and not the address-like id.  Starting from there, the gdb_id <->
  thread id conversion was not needed anymore, since the remote protocol
  and gdbserver were using the same kind of ids again.  The gdb_id field
  in the thread_info structure was also unused starting there.

- d50171e4  Teach linux gdbserver to step-over-breakpoints.

  This patch moved the thread_info structure around, and got rid of the
  gdb_id field (which was unused).

Looking at the implementation of gdb_id_to_thread_id, it is not doing
anything useful.  It is looking up a thread by ptid using
find_thread_ptid, which basically loops over all threads looking at
their entry.id field.  If a thread with that ptid is found, it returns
its entry.id field.  So it will always return the same thing as it input
(with the exception of if no thread exist with that ptid, then it will
return null_ptid).

gdb/gdbserver/ChangeLog:

	* inferiors.h (gdb_id_to_thread_id): Remove.
	* inferiors.c (gdb_id_to_thread_id): Remove.
	* server.c (process_serial_event): Adjust to gdb_id_to_thread_id
	removal.  Move pid declaration closer to where it's used.
2017-09-15 18:02:51 +02:00
Simon Marchi e8ca139ed0 gdbserver: Move detach code to its own function
The code required to handle the 'D' packet is non trivial, so move it
out to its own function.

The moved out code is identical, except for the call to strtol and some
breaks that became returns.

Tested manually, and by running gdb.base/*detach*.exp with
native-gdbserver and native-extended-gdbserver.

gdb/gdbserver/ChangeLog:

	* server.c (handle_detach): New function.
	(process_serial_event): Move code out, call handle_detach.
2017-09-15 17:59:37 +02:00
Simon Marchi f8a4e11920 Deduplicate require_running macros and move them up
I find it very confusing to define the require_running in the middle of
the file, and re-define it to something else later in the middle of the
same file.  I think it would be better if those macros had different
names so that we know exactly what they do.

gdb/gdbserver/ChangeLog:

	* server.c (require_running): Rename to ...
	(require_running_or_return): ... this ...
	(require_running_or_break): ... and this.
	(handle_query, process_serial_event): Adjust.
2017-09-15 17:59:36 +02:00
Simon Marchi 0eb0a40713 linux-low: Remove unused variables
gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_set_resume_request): Remove unused
	variables.
2017-09-15 16:41:35 +02:00
Simon Marchi 785922a559 gdbserver: Remove duplicate functions to find any thread of process
We have about 6 functions/callbacks to find_inferior meant to find a
thread that belongs to a given pid.  Remove all but
find_any_thread_of_pid and replace their uses with
find_any_thread_of_pid.

gdb/gdbserver/ChangeLog:

	* server.c (first_thread_of): Remove.
	(process_serial_event): Replace usage of first_thread_of with
	find_any_thread_of_pid.
	* tracepoint.c (same_process_p): Remove.
	(gdb_agent_about_to_close): Replace usage of same_process_p with
	find_any_thread_of_pid.
	* linux-x86-low.c (same_process_callback): Remove.
	(x86_arch_setup_process_callback): Replace usage of
	same_process_callback with find_any_thread_of_pid.
	* thread-db.c (any_thread_of): Remove.
	(switch_to_process): Replace usage of any_thread_of with
	find_any_thread_of_pid.
	* inferiors.c (thread_pid_matches_callback): Remove.
	(find_thread_process): Adjust to use find_any_thread_of_pid.
2017-09-15 14:53:20 +02:00
Sergio Durigan Junior a059f00c85 Fix build breakage on GNU/Linux AArch64, take 2
The last commit unfortunately was not enough to fix the build breakage
on AArch64.  I made a mistake and did not test it alone on BuildBot,
but along with another patch that was responsible for fixing the
breakage.

The failure is:

  In file included from /usr/include/string.h:640:0,
		   from build-gnulib-gdbserver/import/string.h:41,
		   from ../../../binutils-gdb/gdb/gdbserver/../common/common-defs.h:56,
		   from ../../../binutils-gdb/gdb/gdbserver/server.h:22,
		   from ../../../binutils-gdb/gdb/gdbserver/regcache.c:19:
  In function ‘void* memset(void*, int, size_t)’,
      inlined from ‘regcache* init_register_cache(regcache*, const target_desc*, unsigned char*)’ at ../../../binutils-gdb/gdb/gdbserver/regcache.c:150:50:
  /usr/include/aarch64-linux-gnu/bits/string3.h:81:32: error: call to ‘__warn_memset_zero_len’ declared with attribute warning: memset used with constant zero length parameter; this could be due to transposed parameters [-Werror]
	 __warn_memset_zero_len ();
				  ^
  In function ‘void* memset(void*, int, size_t)’,
      inlined from ‘regcache* get_thread_regcache(thread_info*, int)’ at ../../../binutils-gdb/gdb/gdbserver/regcache.c:57:60:
  /usr/include/aarch64-linux-gnu/bits/string3.h:81:32: error: call to ‘__warn_memset_zero_len’ declared with attribute warning: memset used with constant zero length parameter; this could be due to transposed parameters [-Werror]
	 __warn_memset_zero_len ();

This is likely due to a GCC bug, because for some reason the compiler
assumes that the third argument to the memset:

  memset (regcache->register_status, REG_UNAVAILABLE,
	  VEC_length (tdesc_reg_p, regcache->tdesc->reg_defs));

is always zero, which is not always true.

Anyway, the simple fix for this is to guard the memset calls with:

  if (!VEC_empty (tdesc_reg_p, regcache->tdesc->reg_defs))

This time, I made sure to regtest only this patch on BuildBot, and it
finally solved the breakage.

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

	* regcache.c (get_thread_regcache): Guard calls to "memset"
          with "!VEC_empty".
2017-09-10 18:12:14 -04:00
Sergio Durigan Junior cc397f3a23 Fix build breakage on GNU/Linux AArch64
This patch fixes the build breakage that has been happening on AArch64
since September 5th.  The breakage was introduced by the following
commit:

  author        Yao Qi <yao.qi@linaro.org>
          Tue, 5 Sep 2017 04:54:52 -0400 (09:54 +0100)
  committer     Yao Qi <yao.qi@linaro.org>
          Tue, 5 Sep 2017 04:54:52 -0400 (09:54 +0100)
  commit        f7000548a2

  Use VEC for target_desc.reg_defs

The build log for this commit can be seen here:

  <https://gdb-build.sergiodj.net/builders/Ubuntu-AArch64-native-gdbserver-m64/builds/2696/steps/compile%20gdb/logs/stdio>

And the underlying problem is that the code is not calling the new
function "allocate_target_description" to allocate the "struct
target_desc" using "new" instead of XNEW, which end up not properly
initializing the fields of the structure.

Regtested on BuildBot.

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

	* linux-low.c (handle_extended_wait): Use
	"allocate_target_description" instead of "XNEW".
	* linux-x86-low.c (initialize_low_arch): Likewise.
2017-09-10 12:33:28 -04:00
Yao Qi 22916b0786 Convert the rest x86 target descriptions
This patch changes the rest of x86 target descriptions in GDB and
GDBserver.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* amd64-tdep.c (amd64_target_description): Create target
	descriptions.
	(_initialize_amd64_tdep): Don't call functions
	initialize_tdesc_amd64_*.  Add self tests.
	* arch/amd64.c (amd64_create_target_description): Add parameter
	is_linux.  Call set_tdesc_osabi if is_linux is true.
	* arch/amd64.h (amd64_create_target_description): Update the
	declaration.
	* arch/i386.c (i386_create_target_description): Add parameter
	is_linux.  Call set_tdesc_osabi if is_linux is true.
	* arch/i386.h (i386_create_target_description): Update
	declaration.
	* configure.tgt: Add i386.o to gdb_target_obs.
	* features/Makefile (XMLTOC): Remove i386/*.xml.
	* features/i386/amd64-avx-avx512.c: Remove.
	* features/i386/amd64-avx-mpx-avx512-pku.c: Remove.
	* features/i386/amd64-avx-mpx.c: Remove.
	* features/i386/amd64-avx.c: Remove.
	* features/i386/amd64-mpx.c: Remove.
	* features/i386/amd64.c: Remove.
	* features/i386/i386-avx-avx512.c: Remove.
	* features/i386/i386-avx-mpx-avx512-pku.c: Remove.
	* features/i386/i386-avx-mpx.c: Remove.
	* features/i386/i386-avx.c: Remove.
	* features/i386/i386-mmx.c: Remove.
	* features/i386/i386-mpx.c: Remove.
	* features/i386/i386.c: Remove.
	* i386-tdep.c: Don't include features/i386/i386*.c., include
	target-descriptions.h and arch/i386.h.
	(i386_target_description): Create target descriptions.
	(i386_gdbarch_init): Don't call initialize_tdesc_i386_*
	functions.  Do self tests.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_i386_regobj): Remove.
	(srv_amd64_regobj): Remove.
	(srv_regobj): Set it to "" for x86 non-linux targets.
	* linux-x86-tdesc.c (i386_linux_read_description):
	* lynx-i386-low.c: Include x86-xstate.h and arch/i386.h.
	(init_registers_i386): Remove the declaration.
	(tdesc_i386): Remove the declaration.
	(lynx_i386_arch_setup): Call i386_create_target_description.
	* nto-x86-low.c: Likewise.
	* win32-i386-low.c [__x86_64__]: include arch/amd64.h.
	[!__x86_64__]: include arch/i386.h.
	(i386_arch_setup) [__x86_64__]: Call amd64_create_target_description.
2017-09-05 09:54:54 +01:00
Yao Qi 38602d55e0 [GDBserver] Shorten srv_amd64_linux_xmlfiles
GDBserver now is able to generate target descriptions from features, so
don't need to remember these target description files.

Note that it should be i386/amd64-avx-avx512-linux.xml instead of
i386/amd64-avx-avx512.xml in $srv_amd64_linux_xmlfiles.  This patch
removes it anyway.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_amd64_linux_xmlfiles): Remove
	i386/amd64-XXX-linux from it.
2017-09-05 09:54:54 +01:00
Yao Qi 44b886ff15 [GDBserver] Use pre-generated amd64-linux tdesc as test
Now, all these amd64-linux pre-generated tdesc can be used as test, so
don't need to build them if $development is false.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* configure.srv: Empty srv_amd64_linux_regobj if $development is
	false.
	(ipa_amd64_linux_regobj): Remove.
	(ipa_x32_linux_regobj): Remove.
2017-09-05 09:54:54 +01:00
Yao Qi b4570e4b30 Convert amd64-linux target descriptions
This patch changes amd64-linux target descriptions so that they can be
dynamically generated in both GDB and GDBserver.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* Makefile.in (arch-amd64.o): New rule.
	* configure.srv: Append arch-amd64.o.
	* linux-amd64-ipa.c: Include common/x86-xstate.h.
	(get_ipa_tdesc): Call amd64_linux_read_description.
	(initialize_low_tracepoint): Don't call init_registers_x32_XXX
	and init_registers_amd64_XXX.
	* linux-x86-low.c (x86_linux_read_description): Call
	amd64_linux_read_description.
	(x86_get_ipa_tdesc_idx): Call amd64_get_ipa_tdesc_idx.
	(initialize_low_arch): Don't call init_registers_x32_XXX and
	init_registers_amd64_XXX.
	* linux-x86-tdesc-selftest.c: Declare init_registers_amd64_XXX
	and tdesc_amd64_XXX.
	[__x86_64__] (amd64_tdesc_test): New function.
	(initialize_low_tdesc) [__x86_64__]: Call init_registers_x32_XXX
	and init_registers_amd64_XXX.
	* linux-x86-tdesc.c: Include arch/amd64.h.
	(xcr0_to_tdesc_idx): New function.
	(i386_linux_read_description): New function.
	(amd64_get_ipa_tdesc_idx): New function.
	* linux-x86-tdesc.h (amd64_get_ipa_tdesc_idx): Declare.
	(amd64_get_ipa_tdesc): Declare.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* amd64-linux-tdep.c: Include arch/amd64.h.  Don't include
	features/i386/*.c.
	(amd64_linux_read_description): Call
	amd64_create_target_description.
	* arch/amd64.c: New file.
	* arch/amd64.h: New file.
	* configure.tgt (x86_64-*-linux*): Append amd64.o.
	* Makefile.in (ALL_64_TARGET_OBS): Append amd64.o.
2017-09-05 09:54:54 +01:00
Yao Qi d1f28ea24a [GDBserver] Shorten srv_i386_linux_xmlfiles
GDBserver now is able to generate target descriptions from features, so
don't need to remember these target description files.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_i386_linux_xmlfiles): Remove
	i386/i386-XXX-linux.xml from it.
2017-09-05 09:54:53 +01:00
Yao Qi 25a93583f3 [GDBserver] Use pre-generated tdesc as test
Now, these *-generate.c files are only used in GDBserver for unit test.
If $development is false (in release), these *-generate.c files won't be
used at all.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* configure.srv: Set srv_i386_linux_regobj empty if $development
	is false.
	* linux-i386-ipa.c (initialize_low_tracepoint): Don't call
	initialize_low_tdesc.
	* linux-x86-low.c (initialize_low_arch): Wrap initialize_low_tdesc
	with #if initialize_low_tdesc.
	* linux-x86-tdesc-selftest.c: New file.
	* linux-x86-tdesc.c: Move code to linux-x86-tdesc-selftest.c.
2017-09-05 09:54:53 +01:00
Yao Qi 5f035c0716 Share i386-linux target description between GDB and GDBserver
The code on creating i386-linux target descriptions are quite similar
between GDB and GDBserver, so this patch moves them into a shared file
arch/i386.c.  I didn't name it as i386-linux.c, because I want to reuse it
to create other i386 non-linux target descriptions later.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* Makefile.in (ALL_TARGET_OBS): Add i386.o.
	(SFILES): Add arch/i386.c.
	(HFILES_NO_SRCDIR): Add arch/i386.h.
	* arch/i386.c: New file.
	* arch/i386.h: New file.
	* arch/tdesc.h (allocate_target_description): Declare.
	(set_tdesc_architecture): Declare.
	(set_tdesc_osabi): Declare.
	* configure.tgt (i[34567]86-*-linux*): Add i386.o.
	* i386-linux-tdep.c: Don't include ../features/i386/32bit-XXX.c.
	include arch/i386.h.
	(i386_linux_read_description): Remove code and call
	i386_create_target_description.
	(set_tdesc_architecture): New function.
	(set_tdesc_osabi): New function.
	* target-descriptions.h (allocate_target_description): Remove.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* Makefile.in (arch-i386.o): New rule.
	* configure.srv (i[34567]86-*-linux*): Add arch-i386.o.
	(x86_64-*-linux*): Likewise.
	* linux-x86-tdesc.c: Don't include ../features/i386/32bit-XXX.c,
	include arch/i386.h.
	(i386_linux_read_description): Remove code and call
	i386_create_target_description.
	* tdesc.c (allocate_target_description): New function.
	* tdesc.h (set_tdesc_architecture): Remove declaration.
	(set_tdesc_osabi): Likewise.
2017-09-05 09:54:53 +01:00
Yao Qi 0abe8a8992 Dynamically composite xml in reply to GDB
GDBserver still uses pre-generated target descriptions in order to
reply to GDB's query on target description (see xml-builtin-generated.c
in GDBserver build directory).  This patch teaches GDBserver to
create XML contents according to the target descriptions rather than
using pre-generated ones.

First, change target feature c files to pass the feature xml file
name to tdesc_create_feature, so that target description in GDBserver
can record them, and create XML contents from these features in
buffer, like

  ...
  <xi:include href="$FEATURE1_XML_NAME"/>
  <xi:include href="$FEATURE2_XML_NAME"/>
  ...

and send this buffer back to GDB.

Note that this patch reuses target_desc.xmltarget a little bit, which is
to hold the XML contents dynamically generated in tdesc_get_features_xml.
However, it is not xfree'ed in ~target_desc, because we can't tell it is
from xstrdup or a literal string.  Since we don't delete target_desc,
there is no memory leak yet.  After we change all target descriptions to
the new style, target_desc.xmltarget is from xstrdup, then, we can safely
xfree it in ~target_desc.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* arch/tdesc.h (tdesc_create_feature): Add an argument xml.
	* target-descriptions.c (tdesc_create_feature): Likewise, and
	adjust code.
	* features/i386/32bit-avx.c: Re-generated.
	* features/i386/32bit-avx512.c: Re-generated.
	* features/i386/32bit-core.c: Re-generated.
	* features/i386/32bit-linux.c: Re-generated.
	* features/i386/32bit-mpx.c: Re-generated.
	* features/i386/32bit-pkeys.c: Re-generated.
	* features/i386/32bit-sse.c: Re-generated.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* linux-x86-tdesc.c: Don't include <inttypes.h>.
	(i386_linux_read_description) [!IN_PROCESS_AGENT]: Call
	set_tdesc_architecture and set_tdesc_osabi.  Remove code setting
	.xmltarget.
	* server.c (get_features_xml): Call tdesc_get_features_xml.
	* tdesc.c (set_tdesc_architecture): New function.
	(set_tdesc_osabi): New function.
	(tdesc_get_features_xml): New function.
	(tdesc_create_feature): Add an argument.
	* tdesc.h (struct target_desc) <features>: New field.
	<arch, osabi>: New field.
	(~target_desc): xfree features, arch, and osabi.
	(target_desc::oerator==): Don't compare .xmltarget.
	[!IN_PROCESS_AGENT] (set_tdesc_architecture): Declare.
	(set_tdesc_osabi): Likewise.
	(tdesc_get_features_xml): Likewise.
2017-09-05 09:54:53 +01:00
Yao Qi 0a188386c0 [GDBserver] unit test to i386_tdesc
This patch adds a unit test in GDBserver to test dynamically created
target descriptions equal these pre-generated ones.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* linux-x86-tdesc.c: Include selftest.h.
	(i386_tdesc_test): New function.
	(initialize_low_tdesc): Call selftests::register_test.
	* tdesc.h: Include regdef.h.
	(target_desc): Override operator == and !=.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* regformats/regdef.h (struct reg): Override operator == and !=.
2017-09-05 09:54:53 +01:00
Yao Qi f49ff00066 [GDBserver] Centralize tdesc for i386-linux
tdesc_i386_XXX_linux is used in many places in linux-x86-low.c and this
patch adds a new function i386_linux_read_description to return the right
tdesc according to xcr0.  i386_linux_read_description is quite similar to
the counterpart in GDB, and the following patch will share the duplicated
code, so this patch adds arch/tdesc.h includes the declarations of various
tdesc apis which are used by the shared code.  The generated c feature
files can include arch/tdesc.h only.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_tgtobj): Append linux-x86-tdesc.o.
	(ipa_obj): Likewise.
	* linux-i386-ipa.c: Include common/x86-xstate.h
	(get_ipa_tdesc): Call i386_linux_read_description.
	(initialize_low_tracepoint): Don't call  init_registers_XXX
	functions, call initialize_low_tdesc instead.
	* linux-x86-low.c (x86_linux_read_description): Call
	i386_linux_read_description.
	(initialize_low_arch): Don't call init_registers_i386_XXX
	functions, call initialize_low_tdesc.
	* linux-x86-tdesc.c: New file.
	* linux-x86-tdesc.h (x86_linux_tdesc): New X86_TDESC_LAST.
	(i386_get_ipa_tdesc_idx): Declare.
	(i386_get_ipa_tdesc): Declare.
	(initialize_low_tdesc): Declare.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* arch/tdesc.h: New file.
	* regformats/regdat.sh: Generate code using tdesc_create_reg.
	* target-descriptions.c: Update comments.
	* target-descriptions.h: Include "arch/tdesc.h".  Remove the
	declarations.
	* features/i386/32bit-avx.c: Re-generated.
	* features/i386/32bit-avx512.c: Re-generated.
	* features/i386/32bit-core.c: Re-generated.
	* features/i386/32bit-linux.c: Re-generated.
	* features/i386/32bit-mpx.c: Re-generated.
	* features/i386/32bit-pkeys.c: Re-generated.
	* features/i386/32bit-sse.c: Re-generated.
2017-09-05 09:54:53 +01:00
Yao Qi 2b68ef2f11 Return X86_TDESC_MMX in x86_get_ipa_tdesc_idx
gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* linux-x86-low.c (x86_get_ipa_tdesc_idx): Use X86_TDESC_MMX
	instead of 0.
2017-09-05 09:54:52 +01:00
Yao Qi f7000548a2 Use VEC for target_desc.reg_defs
Nowadays, target_desc.reg_defs is a pointer points to a pre-generated
array, which is not flexible.  This patch changes it from an array
to a VEC so that GDBserver can create target descriptions dynamically
later.  Instead of using pre-generated array, the -generated.c calls
VEC_safe_push to add each register to vector.

Since target_desc.reg_defs is used in IPA, we need to build common/vec.c
for IPA too.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* Makefile.in (IPA_OBJS): Add vec-ipa.o
	* regcache.c (get_thread_regcache): Use VEC_length.
	(init_register_cache): Likewise.
	(regcache_cpy): Likewise.
	(registers_to_string): Iterate reg_defs via VEC_iterate.
	(find_regno): Likewise.
	(find_register_by_number): Use VEC_index.
	(register_size): Call find_register_by_number.
	(register_data): Call find_register_by_number.
	(supply_regblock): Use VEC_length.
	(regcache_raw_read_unsigned): Likewise.
	* tdesc.c (init_target_desc): Iterate reg_defs via
	VEC_iterate.
	(default_description): Update initializer.
	(copy_target_description): Don't update field num_registers.
	* tdesc.h (struct target_desc) <reg_defs>: Change it to VEC.
	<num_registers>: Remove.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

	* regformats/regdat.sh: Update generated code.
2017-09-05 09:54:52 +01:00
Simon Marchi 50a421ac3a gdbserver Makefile: don't delete intermediary files
If you "make" from scratch in gdbserver/, you'll notice that make
deletes the files it considers as intermediary at the end:

  $ make clean && make
  ...
  rm i386-mmx-linux-generated.c x32-avx-avx512-linux-generated.c ...

Then, if you type make again, make will rebuild these files and rebuild
gdbserver.  To avoid this, we can add the .SECONDARY special target.  If
it has no pre-requisites, all intermediary files will be kept.

gdb/gdbserver/ChangeLog:

	* Makefile.in (.SECONDARY): Define target.
2017-09-04 19:02:56 +02:00
Simon Marchi 23fdd69e42 Make target_waitstatus_to_string return an std::string
A quite straightforward change.  It does "fix" leaks in record-btrace.c,
although since this is only used in debug printing code, it has no real
world impact.

gdb/ChangeLog:

	* target/waitstatus.h (target_waitstatus_to_string): Change
	return type to std::string.
	* target/waitstatus.c (target_waitstatus_to_string): Return
	std::string.
	* target.h (target_waitstatus_to_string): Remove declaration.
	* infrun.c (resume, clear_proceed_status_thread,
	print_target_wait_results, do_target_wait, save_waitstatus,
	stop_all_threads): Adjust.
	* record-btrace.c (record_btrace_wait): Adjust.
	* target-debug.h
	(target_debug_print_struct_target_waitstatus_p): Adjust.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_wait_1): Adjust.
	* server.c (queue_stop_reply_callback): Adjust.
2017-09-03 10:23:31 +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
Simon Marchi 6afd337d1a gdbserver: Rename some functions, thread -> inferior
These functions apply to thread, and not inferiors (in the gdbserver
sense, the abstraction for threads and processes, as in
inferior_list).  Therefore, it would make more sense if these functions
were named with "thread" rather than "inferior".

gdb/gdbserver/ChangeLog:

	* inferiors.h (inferior_target_data): Rename to ...
	(thread_target_data): ... this.
	(inferior_regcache_data): Rename to ...
	(thread_regcache_data): ... this.
	(set_inferior_regcache_data): Rename to ...
	(set_thread_regcache_data): ... this.
	* inferiors.c (inferior_target_data): Rename to ...
	(thread_target_data): ... this.
	(inferior_regcache_data): Rename to ...
	(thread_regcache_data): ... this.
	(set_inferior_regcache_data): Rename to ...
	(set_thread_regcache_data): ... this.
	(free_one_thread): Update.
	* linux-low.h (get_thread_lwp): Update.
	* regcache.c (get_thread_regcache): Update.
	(regcache_invalidate_thread): Update.
	(free_register_cache_thread): Update.
	* win32-i386-low.c (update_debug_registers_callback): Update.
	(win32_get_current_dr): Update.
	* win32-low.c (thread_rec): Update.
	(delete_thread_info): Update.
	(continue_one_thread): Update.
	(suspend_one_thread): Update.
2017-08-25 10:45:33 +02:00
Simon Marchi a160cc4628 Remove unused function set_inferior_target_data
The inferior (thread) target data is always set through add_thread.

gdb/gdbserver/ChangeLog:

	* inferiors.c (set_inferior_target_data): Remove.
	* inferiors.h (set_inferior_target_data): Remove.
2017-08-24 23:34:43 +02:00
Yao Qi 6d580b635f GDBserver self tests
This patch uses GDB self test in GDBserver.  The self tests are run if
GDBserver is started with option --selftest.

gdb:

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

	* NEWS: Mention GDBserver's new option "--selftest".
	* Makefile.in (SFILES): Remove selftest.c, add common/selftest.c.
	* selftest.c: Move it to common/selftest.c.
	* selftest.h: Move it to common/selftest.h.
	* selftest-arch.c (reset): New function.
	(tests_with_arch): Call reset.

gdb/gdbserver:

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

	* Makefile.in (OBS): Add selftest.o.
	* configure.ac: AC_DEFINE GDB_SELF_TEST if $development.
	* configure, config.in: Re-generated.
	* server.c: Include common/sefltest.h.
	(captured_main): Handle option --selftest.

gdb/testsuite:

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

	* gdb.server/unittest.exp: New.

gdb/doc:

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

	* gdb.texinfo (Server): Document "--selftest".
2017-08-18 09:20:43 +01:00
Yao Qi f5a29eb0a6 Clean up x86 non-linux GDBserver target descriptions
In GDBserver, only tdesc_i386 and tdesc_amd64 are used.  There is no point
of generating these *.dat files (which are used to generate *.c files during
GDBserver build.).

gdb:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* features/Makefile (WHICH): Remove i386/ non-linux stuff.
	* regformats/i386/amd64-avx-avx512.dat: Remove.
	* regformats/i386/amd64-avx-mpx-avx512-pku.dat: Remove.
	* regformats/i386/amd64-avx-mpx.dat:Remove.
	* regformats/i386/amd64-avx.dat: Remove.
	* regformats/i386/amd64-mpx.dat: Remove.
	* regformats/i386/i386-avx-avx512.dat: Remove.
	* regformats/i386/i386-avx-mpx-avx512-pku.dat: Remove.
	* regformats/i386/i386-avx-mpx.dat: Remove.
	* regformats/i386/i386-mmx.dat: Remove.
	* regformats/i386/i386-mpx.dat: Remove.

gdb/gdbserver:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_i386_regobj): Remove i386-avx.o,
	i386-avx-avx512.o, i386-avx-mpx-avx512-pku.o, i386-mpx.o,
	i386-avx-mpx.o and i386-mmx.o.
	(srv_amd64_regobj): Remove amd64-avx.o, amd64-avx-avx512.o,
	amd64-avx-mpx-avx512-pku.o, amd64-mpx.o and amd64-avx-mpx.o.
	(srv_i386_xmlfiles): Remove i386/i386-avx.xml,
	i386/i386-avx-avx512.xml, i386/i386-avx-mpx-avx512-pku.xml,
	i386/i386-mpx.xml, i386/i386-avx-mpx.xml and i386/i386-mmx.xml.
	(srv_amd64_xmlfile):i386/amd64-avx.xml, i386/amd64-avx-avx512.xml,
	i386/amd64-avx-mpx-avx512-pku.xml, i386/amd64-mpx.xml,
	i386/amd64-avx-mpx.xml.
2017-08-09 12:29:21 +01:00
Yao Qi 57757c2f09 Remove x32 non-linux target descriptions
x32 non-linux target descriptions are not used in GDB or GDBserver.  This
patch removes them.

gdb:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* amd64-tdep.h (tdesc_x32): Remove the declaration.
	* amd64-tdep.c: Don't include features/i386/x32*.c.
	(_initialize_amd64_tdep): Don't call initialize_tdesc_x32*
	functions.
	* features/Makefile (WHICH): Remove i386/x32, i386/x32-avx,
	and i386/x32-avx-avx512.
	(XMLTOC): Remove i386/x32-avx.xml, i386/x32-avx-avx512.xml,
	and i386/x32.xml.
	* features/i386/x32-avx-avx512.c: Removed.
	* features/i386/x32-avx-avx512.xml: Removed.
	* features/i386/x32-avx.c: Removed.
	* features/i386/x32-avx.xml: Removed.
	* features/i386/x32.c: Removed.
	* features/i386/x32.xml: Removed.
	* regformats/i386/x32-avx-avx512.dat: Removed.
	* regformats/i386/x32-avx.dat: Removed.
	* regformats/i386/x32.dat: Removed.

gdb/gdbserver:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_amd64_regobj): Remove x32.o, x32-avx.o
	and x32-avx-avx512.o.
	(srv_amd64_xmlfiles): Remove i386/x32.xml, i386/x32-avx.xml
	i386/x32-avx-avx512.xml.
2017-08-09 12:28:59 +01:00
Simon Marchi 229d26fc9e Add enum for result of fast_tracepoint_collecting
I got confused by the result value of fast_tracepoint_collecting, while
it sounds like it would return true/false (whether the thread is
collecting or not), it actually returns:

  0: not collecting
  1: in the jump pad, before the relocated instruction
  2: in the jump pad, at or after the relocated instruction

To avoid confusion, I think it would be nice to make it return an enum.
If you can help find a shorter but still relavant name, it would be
awesome.  Otherwise, we'll go with that, fast_tpoint_collect_result,
which is at least consistent with the existing
fast_tpoint_collect_status.

gdb/gdbserver/ChangeLog:

	* tracepoint.h (enum class fast_tpoint_collect_result): New
	enumeration.
	(fast_tracepoint_collecting): Change return type to
	fast_tpoint_collect_result.
	* tracepoint.c (fast_tracepoint_collecting): Likewise.
	* linux-low.h: Include tracepoint.h.
	(struct lwp_info) <collecting_fast_tracepoint>: Change type to
	fast_tpoint_collect_result.
	* linux-low.c (handle_tracepoints): Adjust.
	(linux_fast_tracepoint_collecting): Change return type to
	fast_tpoint_collect_result.
	(maybe_move_out_of_jump_pad, linux_wait_for_event_filtered,
	linux_wait_1, stuck_in_jump_pad_callback,
	lwp_signal_can_be_delivered, linux_resume_one_lwp_throw,
	proceed_one_lwp): Adjust to type change.
2017-07-26 10:57:07 +02:00
Yao Qi 2e1e43e140 Re-indent the code
gdb/gdbserver:

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

	* linux-x86-low.c (x86_linux_read_description): Re-indent the code.
2017-07-10 11:53:44 +01:00
Yao Qi adc764e7d2 Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT
struct target_desc is used by both GDBserver and IPA, but fields
expedite_regs and xmltarget are only used in GDBserver, so this patch wraps
these two fields by ifndef IN_PROCESS_AGENT.  This patch also changes
regformats/regdat.sh to generate .c files in this way too.

gdb/gdbserver:

2017-06-29  Yao Qi  <yao.qi@linaro.org>

	* tdesc.h (struct target_desc) [IN_PROCESS_AGENT] <expedite_regs>:
	Remove.
	[IN_PROCESS_AGENT] <xmltarget>: Likewise.

gdb:

2017-06-29  Yao Qi  <yao.qi@linaro.org>

	* regformats/regdat.sh: Generate code with
	"ifndef IN_PROCESS_AGENT".
2017-06-29 12:41:50 +01:00
Simon Marchi a206891ad1 gdbserver/Makefile.in: Sort IPA_OBJS
gdb/gdbserver/ChangeLog:

	* Makefile.in (IPA_OBJS): Sort and format one item per line.
2017-06-20 16:59:03 +02:00
Sergio Durigan Junior 9a6c7d9c02 C++ify gdb/common/environ.c
As part of the preparation necessary for my upcoming task, I'd like to
propose that we turn gdb_environ into a class.  The approach taken
here is simple: the class gdb_environ contains everything that is
needed to manipulate the environment variables.  These variables are
stored in an std::vector<char *>, which can be converted to a 'char
**' and passed as argument to functions that need it.

The usage has not changed much.  As per Pedro's suggestion, this class
uses a static factory method initialization.  This means that when an
instance is created, it is initially empty.  When needed, it has to be
initialized using the static method 'from_host_environ'.

As mentioned before, this is a preparation for an upcoming work that I
will be posting in the next few weeks or so.  For that work, I'll
probably create another data structure that will contain all the
environment variables that were set by the user using the 'set
environment' command, because I'll need access to them.  This will be
much easier with the class-ification of gdb_environ.

As noted, this has been regression-tested with the new version of
environ.exp and no regressions were found.

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

	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	'unittests/environ-selftests.c'.
	(SUBDIR_UNITTESTS_OBS): Add 'environ-selftests.o'.
	* charset.c (find_charset_names): Declare object 'iconv_env'.
	Update code to use 'iconv_env' object.  Remove call to
	'free_environ'.
	* common/environ.c: Include <utility>.
	(make_environ): Delete function.
	(free_environ): Delete function.
	(gdb_environ::clear): New function.
	(gdb_environ::operator=): New function.
	(gdb_environ::get): Likewise.
	(environ_vector): Delete function.
	(set_in_environ): Delete function.
	(gdb_environ::set): New function.
	(unset_in_environ): Delete function.
	(gdb_environ::unset): New function.
	(gdb_environ::envp): Likewise.
	* common/environ.h: Include <vector>.
	(struct gdb_environ): Delete; transform into...
	(class gdb_environ): ... this class.
	(free_environ): Delete prototype.
	(init_environ, get_in_environ, set_in_environ, unset_in_environ,
	environ_vector): Likewise.
	* infcmd.c (run_command_1): Update code to call
	'envp' from 'gdb_environ' class.
	(environment_info): Update code to call methods from 'gdb_environ'
	class.
	(unset_environment_command): Likewise.
	(path_info): Likewise.
	(path_command): Likewise.
	* inferior.c (inferior::~inferior): Delete call to 'free_environ'.
	(inferior::inferior): Initialize 'environment' using the host's
	information.
	* inferior.h: Remove forward declaration of 'struct gdb_environ'.
	Include "environ.h".
	(class inferior) <environment>: Change type from 'struct
	gdb_environ' to 'gdb_environ'.
	* mi/mi-cmd-env.c (mi_cmd_env_path): Update code to call
	methods from 'gdb_environ' class.
	* solib.c (solib_find_1): Likewise
	* unittests/environ-selftests.c: New file.

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

	* linux-low.c (linux_create_inferior): Adjust code to access the
	environment information via 'gdb_environ' class.
	* lynx-low.c (lynx_create_inferior): Likewise.
	* server.c (our_environ): Make it an instance of 'gdb_environ'.
	(get_environ): Return a pointer to 'our_environ'.
	(captured_main): Initialize 'our_environ'.
	* server.h (get_environ): Adjust prototype.
	* spu-low.c (spu_create_inferior): Adjust code to access the
	environment information via 'gdb_environ' class.
2017-06-20 08:59:27 -04:00
Simon Marchi ae3e2ccfe7 linux-low: Remove usage of "register" keyword
AFAIK, the register keyword is not relevant today, and clang complains
about it:

/home/emaisin/src/binutils-gdb/gdb/gdbserver/linux-low.c:5873:3: error: 'register' storage class specifier is deprecated and incompatible with C++1z
      [-Werror,-Wdeprecated-register]
  register PTRACE_XFER_TYPE *buffer;
  ^~~~~~~~~

I think we can safely remove it.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_read_memory, linux_write_memory): Remove
	usage of "register" keyword.
2017-06-17 23:19:09 +02:00
Simon Marchi 8465943af6 gdb: Add -Wno-mismatched-tags
clang complains that for some types, we use both the class and struct
keywords in different places.  It's not really a problem, so I think we
can safely turn this warning off.

gdb/ChangeLog:

	* configure: Re-generate.
	* warning.m4 (build_warnings): Add -Wno-mismatched-tags.

gdb/gdbserver/ChangeLog:

	* configure: Re-generate.
2017-06-17 23:18:49 +02:00
Simon Marchi 3e019bdc20 gdb: Use -Werror when checking for (un)supported warning flags
In warning.m4, we pass all the warning flags one by one to the compiler
to test if they are supported by this particular compiler.  If the
compiler exits with an error, we conclude that this warning flag is not
supported and exclude it.  This allows us to use warning flags without
having to worry about which versions of which compilers support each
flag.

clang, by default, only emits a warning if an unknown flag is passed:

  warning: unknown warning option '-Wfoo' [-Wunknown-warning-option]

The result is that we think that all the warning flags we use are
supported by clang (they are not), and the compilation fails later when
building with -Werror, since the aforementioned warning becomes an
error.  The fix is to also pass -Werror when probing for supported
flags, then we'll correctly get an error when using an unknown warning,
and we'll exclude it:

  error: unknown warning option '-Wfoo' [-Werror,-Wunknown-warning-option]

I am not sure why there is a change in a random comment in
gdbserver/configure, but I suppose it's a leftfover from a previous
patch, so I included it.

gdb/ChangeLog:

	* configure: Re-generate.
	* warning.m4: Pass -Werror to compiler when checking for
	supported warning flags.

gdb/gdbserver/ChangeLog:

	* configure: Re-generate.
2017-06-17 23:18:20 +02:00
Simon Marchi cf0dd6f02c gdb: Pass -x c++ to the compiler
Because we are compiling .c files containing C++ code, clang++ complains
with:

  clang: error: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated

If renaming all the source files to .cpp is out of the question, an
alternative is to pass "-x c++" to convince the compiler that we are
really compiling C++.  It works fine with GCC too.

gdb/ChangeLog:

	* Makefile.in (COMPILE.pre): Add "-x c++".

gdb/gdbserver/ChangeLog:

	* Makefile.in (COMPILE.pre): Add "-x c++".
2017-06-17 23:17:00 +02:00
Sergio Durigan Junior 9845682bda Include <signal.h> on gdbserver/fork-child.c (and fix regressions)
Hi,

This is another obvious patch that fixes a thinko from my previous
startup-with-shell series.  We should conditionally include <signal.h>
on gdb/gdbserver/fork-child.c because gdbserver will be putting the
inferior's terminal on the correct mode after the call to
fork_inferior, and for that it needs to ignore SIGTTOU.

This patch fixes a bunch of regressions happening on AArch64 that were
reported by Yao.

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

	* fork-child.c: Conditionally include <signal.h>.
2017-06-09 18:16:19 -04: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
Sergio Durigan Junior 2090129c36 Share fork_inferior et al with gdbserver
This is the most important (and the biggest, sorry) patch of the
series.  It moves fork_inferior from gdb/fork-child.c to
nat/fork-inferior.c and makes all the necessary adjustments to both
GDB and gdbserver to make sure everything works OK.

There is no "most important change" with this patch; all changes are
made in a progressive way, making sure that gdbserver had the
necessary features while not breaking GDB at the same time.

I decided to go ahead and implement a partial support for starting the
inferior with a shell on gdbserver, although the full feature comes in
the next patch.  The user won't have the option to disable the
startup-with-shell, and also won't be able to change which shell
gdbserver will use (other than setting the $SHELL environment
variable, that is).

Everything is working as expected, and no regressions were present
during the tests.

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

	* Makefile.in (HFILES_NO_SRCDIR): Add "common/common-inferior.h"
	and "nat/fork-inferior.h".
	* common/common-inferior.h: New file, with contents from
	"gdb/inferior.h".
	* commom/common-utils.c: Include "common-utils.h".
	(stringify_argv): New function.
	* common/common-utils.h (stringify_argv): New prototype.
	* configure.nat: Add "fork-inferior.o" as a dependency for
	"*linux*", "fbsd*" and "nbsd*" hosts.
	* corefile.c (get_exec_file): Update comment.
	* darwin-nat.c (darwin_ptrace_him): Call "gdb_startup_inferior"
	instead of "startup_inferior".
	(darwin_create_inferior): Call "add_thread_silent" after
	"fork_inferior".
	* fork-child.c: Cleanup unnecessary includes.
	(SHELL_FILE): Move to "common/common-fork-child.c".
	(environ): Likewise.
	(exec_wrapper): Initialize.
	(get_exec_wrapper): New function.
	(breakup_args): Move to "common/common-fork-child.c"; rename to
	"breakup_args_for_exec".
	(escape_bang_in_quoted_argument): Move to
	"common/common-fork-child.c".
	(saved_ui): New variable.
	(prefork_hook): New function.
	(postfork_hook): Likewise.
	(postfork_child_hook): Likewise.
	(gdb_startup_inferior): Likewise.
	(fork_inferior): Move to "common/common-fork-child.c".  Update
	function to support gdbserver.
	(startup_inferior): Likewise.
	* gdbcore.h (get_exec_file): Remove declaration.
	* gnu-nat.c (gnu_create_inferior): Call "gdb_startup_inferior"
	instead of "startup_inferior".  Call "add_thread_silent" after
	"fork_inferior".
	* inf-ptrace.c: Include "nat/fork-inferior.h" and "utils.h".
	(inf_ptrace_create_inferior): Call "gdb_startup_inferior"
	instead of "startup_inferior".  Call "add_thread_silent" after
	"fork_inferior".
	* inferior.h: Include "common-inferior.h".
	(trace_start_error): Move to "common/common-utils.h".
	(trace_start_error_with_name): Likewise.
	(fork_inferior): Move prototype to "nat/fork-inferior.h".
	(startup_inferior): Likewise.
	(gdb_startup_inferior): New prototype.
	* nat/fork-inferior.c: New file, with contents from "fork-child.c".
	* nat/fork-inferior.h: New file.
	* procfs.c (procfs_init_inferior): Call "gdb_startup_inferior"
	instead of "startup_inferior".  Call "add_thread_silent" after
	"fork_inferior".
	* target.h (target_terminal_init): Move prototype to
	"target/target.h".
	(target_terminal_inferior): Likewise.
	(target_terminal_ours): Likewise.
	* target/target.h (target_terminal_init): New prototype, moved
	from "target.h".
	(target_terminal_inferior): Likewise.
	(target_terminal_ours): Likewise.
	* utils.c (gdb_flush_out_err): New function.

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

	* Makefile.in (SFILES): Add "nat/fork-inferior.o".
	* configure: Regenerate.
	* configure.srv (srv_linux_obj): Add "fork-child.o" and
	"fork-inferior.o".
	(i[34567]86-*-lynxos*): Likewise.
	(spu*-*-*): Likewise.
	* fork-child.c: New file.
	* linux-low.c: Include "common-inferior.h", "nat/fork-inferior.h"
	and "environ.h".
	(linux_ptrace_fun): New function.
	(linux_create_inferior): Adjust function prototype to reflect
	change on "target.h".  Adjust function code to use
	"fork_inferior".
	(linux_request_interrupt): Delete "signal_pid".
	* lynx-low.c: Include "common-inferior.h" and "nat/fork-inferior.h".
	(lynx_ptrace_fun): New function.
	(lynx_create_inferior): Adjust function prototype to reflect
	change on "target.h".  Adjust function code to use
	"fork_inferior".
	* nto-low.c (nto_create_inferior): Adjust function prototype and
	code to reflect change on "target.h".  Update comments.
	* server.c: Include "common-inferior.h", "nat/fork-inferior.h",
	"common-terminal.h" and "environ.h".
	(terminal_fd): Moved to fork-child.c.
	(old_foreground_pgrp): Likewise.
	(restore_old_foreground_pgrp): Likewise.
	(last_status): Make it global.
	(last_ptid): Likewise.
	(our_environ): New variable.
	(startup_with_shell): Likewise.
	(program_name): Likewise.
	(program_argv): Rename to...
	(program_args): ...this.
	(wrapper_argv): New variable.
	(start_inferior): Delete function.
	(get_exec_wrapper): New function.
	(get_exec_file): Likewise.
	(get_environ): Likewise.
	(prefork_hook): Likewise.
	(post_fork_inferior): Likewise.
	(postfork_hook): Likewise.
	(postfork_child_hook): Likewise.
	(handle_v_run): Update code to deal with arguments coming from the
	remote host.  Update calls from "start_inferior" to
	"create_inferior".
	(captured_main): Likewise.  Initialize environment variable.  Call
	"have_job_control".
	* server.h (post_fork_inferior): New prototype.
	(get_environ): Likewise.
	(last_status): Declare.
	(last_ptid): Likewise.
	(signal_pid): Likewise.
	* spu-low.c: Include "common-inferior.h" and "nat/fork-inferior.h".
	(spu_ptrace_fun): New function.
	(spu_create_inferior): Adjust function prototype to reflect change
	on "target.h".  Adjust function code to use "fork_inferior".
	* target.c (target_terminal_init): New function.
	(target_terminal_inferior): Likewise.
	(target_terminal_ours): Likewise.
	* target.h: Include <vector>.
	(struct target_ops) <create_inferior>: Update prototype.
	(create_inferior): Update macro.
	* utils.c (gdb_flush_out_err): New function.
	* win32-low.c (win32_create_inferior): Adjust function prototype
	and code to reflect change on "target.h".

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

	* gdb.server/non-existing-program.exp: Update regex in order to
	reflect the fact that gdbserver is now using fork_inferior (with a
	shell) to startup the inferior.
2017-06-07 19:56:09 -04:00
Sergio Durigan Junior 043a49349c Share parts of gdb/gdbthread.h with gdbserver
GDB and gdbserver now share 'switch_to_thread' because of
fork_inferior.  To make things clear, I created a new file name
common/common-gdbthread.h, and left the implementation specific to
each part.

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

	* Makefile.in (HFILES_NO_SRCDIR): Add "common/common-gdbthread.h".
	* common/common-gdbthread.h: New file, with parts from
	"gdb/gdbthread.h".
	* gdbthread.h: Include "common-gdbthread.h".
	(switch_to_thread): Moved to "common/common-gdbthread.h".

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

	* inferiors.c (switch_to_thread): New function.
2017-06-07 19:56:01 -04:00
Sergio Durigan Junior 156525114c Move parts of inferior job control to common/
This commit moves a few bits responsible for dealing with inferior job
control from GDB to common/, which makes them available to gdbserver.
This is necessary for the upcoming patches that will share
fork_inferior et al between GDB and gdbserver.

We move some parts of gdb/terminal.h to gdb/common/common-terminal.h,
especifically the code that checks terminal features and that are used
to set job_control accordingly.

After sharing parts of gdb/terminal.h, we also to share the two
functions on gdb/inflow.c that are going to be needed by the
fork_inferior rework.  They are 'gdb_setpgid' and the new
'have_job_control'.  I've also taken the opportunity to give a more
meaningful name to "inflow.c" on common/.  Now it is called
"job-control.c" (thanks Pedro for the suggestion).

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

	* Makefile.in (SFILES): Add "common/job-control.c".
	(HFILES_NO_SRCDIR): Add "common/job-control.h".
	(COMMON_OBS): Add "job-control.o".
	* common/job-control.c: New file, with contents from
	"gdb/inflow.c".
	* common/job-control.h: New file, with contents from "terminal.h".
	* fork-child.c: Include "job-control.h".
	* inflow.c: Include "job-control.h".
	(gdb_setpgid): Move to "common/common-inflow.c".
	(_initialize_inflow): Move setting of "job_control" to
	"handle_job_control".
	* terminal.h (job_control): Moved to "common/common-terminal.h".
	(gdb_setpgid): Likewise.
	* top.c: Include "job_control.h".
	* utils.c: Likewise.
	(job_control): Moved to "job-control.c".

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

	* Makefile.in (SFILE): Add "common/job-control.c".
	(OBS): Add "job-control.o".
2017-06-07 19:52:56 -04:00
Sergio Durigan Junior 21ea5acdd1 Introduce "gdb/configure.nat" (and delete "gdb/config/*/*.mh" files)
Due to my ongoing work to make it possible for gdbserver to start the
inferior using the shell, I had to share the fork_inferior function
under the "nat/" directory.  In order to do that, I created a new file
and put the function there; however, this meant that I now had to
update some of the *.mh files (under "gdb/config") and add the new
file as a dependency to be built natively.  Bleh...

After talking a bit to Pedro about this, the idea came up to write a
new "gdb/configure.nat" file, a la "gdb/configure.tgt", which would
concentrate all of the native settings for each host/system.  I
decided to tackle this issue.

The patch is simple.  All of the previous Makefile variables that were
being declared inside the *.mh files are now inside "gdb/Makefile.in",
and "gdb/configure" is responsible for AC_SUBST'ing them.  The
definitions of these variables were put inside "gdb/configure.nat", so
now they're shell variables.  For excerpts of Makefile code, one must
create a file under "gdb/config/${gdb_cpu_host}" and reference it on
the "nat_extra_makefile_frag" variable.

It should now be easier to update the native dependencies of hosts in
this single file.

This has been tested on x86_64 without regressions.

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

	* Makefile.in: Remove "@host_makefile_frag@".  Add variables
	NAT_FILE, NATDEPFILES, NAT_CDEPS, LOADLIBES, MH_CFLAGS, XM_CLIBS,
	NAT_GENERATED_FILES, HAVE_NATIVE_GCORE_HOST.  Add
	"@nat_extra_makefile_frag@".
	(Makefile): Remove dependency on "@frags@".
	($(GNULIB_BUILDDIR)/Makefile): Likewise.
	(data-directory/Makefile): Likewise.
	* config/aarch64/linux.mh: Deleted; moved contents to
	"gdb/configure.nat".
	* config/alpha/alpha-linux.mh: Likewise.
	* config/alpha/nbsd.mh: Likewise.
	* config/arm/linux.mh: Likewise.
	* config/arm/nbsdelf.mh: Likewise.
	* config/i386/cygwin.mh: Likewise.
	* config/i386/cygwin64.mh: Likewise.
	* config/i386/darwin.mh: Likewise.
	* config/i386/fbsd.mh: Likewise.
	* config/i386/fbsd64.mh: Likewise.
	* config/i386/go32.mh: Likewise.
	* config/i386/i386gnu.mh: Likewise.
	* config/i386/i386sol2.mh: Likewise.
	* config/i386/linux.mh: Likewise.
	* config/i386/linux64.mh: Likewise.
	* config/i386/mingw.mh: Likewise.
	* config/i386/mingw64.mh: Likewise.
	* config/i386/nbsd64.mh: Likewise.
	* config/i386/nbsdelf.mh: Likewise.
	* config/i386/nto.mh: Likewise.
	* config/i386/obsd.mh: Likewise.
	* config/i386/obsd64.mh: Likewise.
	* config/i386/sol2-64.mh: Likewise.
	* config/ia64/linux.mh: Likewise.
	* config/m32r/linux.mh: Likewise.
	* config/m68k/linux.mh: Likewise.
	* config/m68k/nbsdelf.mh: Likewise.
	* config/m68k/obsd.mh: Likewise.
	* config/m88k/obsd.mh: Likewise.
	* config/mips/fbsd.mh: Likewise.
	* config/mips/linux.mh: Likewise.
	* config/mips/nbsd.mh: Likewise.
	* config/mips/obsd64.mh: Likewise.
	* config/pa/linux.mh: Likewise.
	* config/pa/nbsd.mh: Likewise.
	* config/pa/obsd.mh: Likewise.
	* config/powerpc/aix.mh: Likewise.
	* config/powerpc/fbsd.mh: Likewise.
	* config/powerpc/linux.mh: Likewise.
	* config/powerpc/nbsd.mh: Likewise.
	* config/powerpc/obsd.mh: Likewise.
	* config/powerpc/ppc64-linux.mh: Likewise.
	* config/powerpc/spu-linux.mh: Likewise.
	* config/s390/linux.mh: Likewise.
	* config/sh/nbsd.mh: Likewise.
	* config/sparc/fbsd.mh: Likewise.
	* config/sparc/linux.mh: Likewise.
	* config/sparc/linux64.mh: Likewise.
	* config/sparc/nbsd64.mh: Likewise.
	* config/sparc/nbsdelf.mh: Likewise.
	* config/sparc/obsd64.mh: Likewise.
	* config/sparc/sol2.mh: Likewise.
	* config/tilegx/linux.mh: Likewise.
	* config/vax/nbsdelf.mh: Likewise.
	* config/vax/obsd.mh: Likewise.
	* config/xtensa/linux.mh: Likewise.
	* config/i386/i386gnu.mn: New file, with excerpts from
	"config/i386/i386gnu.mh".
	* configure: Regenerate.
	* configure.ac: Rewrite code to use "gdb/configure.nat" instead of
	*.mh files under "gdb/config".
	* configure.nat: New file, with contents from the
	"gdb/config/*/*.mh" files.

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

	* Makefile: Remove "@host_makefile_frag@".
2017-05-06 10:09:35 -04:00
Pedro Alves e13cb306f0 gdb: Disable -Werror for -Wmaybe-uninitialized
Newer GCCs are triggering false-positive -Wmaybe-uninitialized
warnings around code that uses gdb::optional:
  https://sourceware.org/ml/gdb-patches/2017-05/msg00118.html

Using std::optional wouldn't help, it triggers the same warnings:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635

Initializing the variables to quiet the warning would defeat the
purpose of gdb::optional.  Making the optional ctor memset its storage
would be a pessimization.  Wrapping gdb::optional's internals with
"#pragma GCC diagnostic push/ignored/pop" doesn't work, we'd have to
wrap uses of gdb::optional instead, which I think would get unwieldy
and ugly as we start using gdb::optional more and more.

The -Wmaybe-uninitialized warning is documented as producing false
positives (unlike -Wuninialized), so until we find a better
workaround, disable -Werror for this warning.  You'll still see the
warning when building gdb, but it won't cause a build failure.

Tested by building with gcc 4.8.5, 5.3.1, and gcc trunk (20170428).

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

	* warning.m4 (build_warnings): Add -Wno-error=maybe-uninitialized.
	* configure: Regenerate.

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

	* configure: Regenerate.
2017-05-05 01:03:28 +01:00
Sergio Durigan Junior c94fee56f5 Regenerate gdb/{,gdbserver/}configure (for commit be628ab814)
On commit be628ab814, both
common/common.m4 was modified in order to check for the presence of
'termios.h', 'termio.h' and 'sgtty.h'.  However, I forgot to
regenerate both gdb/configure and gdb/gdbserver/configure.  This
commit does that.

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

	* configure: Regenerate.

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

	* configure: Regenerate.
2017-05-03 09:17:12 -04:00
Simon Marchi a0ff9e1ad2 Change return type of gdbarch_software_single_step to vector<CORE_ADDR>
This is a relatively straightforward patch that changes
gdbarch_software_single_step so it returns an std::vector<CORE_ADDR>
instead of a VEC (CORE_ADDR).

gdb/ChangeLog:

	* gdbarch.sh (software_single_step): Change return type to
	std::vector<CORE_ADDR>.
	* gdbarch.c, gdbarch.h: Re-generate.
	* arch/arm-get-next-pcs.c (thumb_deal_with_atomic_sequence_raw):
	Adjust.
	(arm_deal_with_atomic_sequence_raw): Adjust.
	(thumb_get_next_pcs_raw): Adjust.
	(arm_get_next_pcs_raw): Adjust.
	(arm_get_next_pcs): Adjust.
	* arch/arm-get-next-pcs.h (arm_get_next_pcs): Adjust.
	* aarch64-tdep.c (aarch64_software_single_step): Adjust.
	* alpha-tdep.c (alpha_deal_with_atomic_sequence): Adjust.
	(alpha_software_single_step): Adjust.
	* alpha-tdep.h (alpha_software_single_step): Adjust.
	* arm-linux-tdep.c (arm_linux_software_single_step): Adjust.
	* arm-tdep.c (arm_software_single_step): Adjust.
	(arm_breakpoint_kind_from_current_state): Adjust.
	* arm-tdep.h (arm_software_single_step): Adjust.
	* breakpoint.c (insert_single_step_breakpoint): Adjust.
	* cris-tdep.c (cris_software_single_step): Adjust.
	* mips-tdep.c (mips_deal_with_atomic_sequence): Adjust.
	(micromips_deal_with_atomic_sequence): Adjust.
	(deal_with_atomic_sequence): Adjust.
	(mips_software_single_step): Adjust.
	* mips-tdep.h (mips_software_single_step): Adjust.
	* moxie-tdep.c (moxie_software_single_step): Adjust.
	* nios2-tdep.c (nios2_software_single_step): Adjust.
	* ppc-tdep.h (ppc_deal_with_atomic_sequence): Adjust.
	* rs6000-aix-tdep.c (rs6000_software_single_step): Adjust.
	* rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust.
	* s390-linux-tdep.c (s390_software_single_step): Adjust.
	* sparc-tdep.c (sparc_software_single_step): Adjust.
	* spu-tdep.c (spu_software_single_step): Adjust.
	* tic6x-tdep.c (tic6x_software_single_step): Adjust.

gdb/gdbserver/ChangeLog:

	* linux-arm-low.c (arm_gdbserver_get_next_pcs): Adjust to
	software_single_step change of return type to
	std::vector<CORE_ADDR>.
	* linux-low.c (install_software_single_step_breakpoints):
	Likewise.
	* linux-low.h (install_software_single_step_breakpoints):
	Likewise.
2017-05-02 13:30:07 -04:00
Sergio Durigan Junior be628ab814 Create gdb_termios.h (and cleanup gdb/{,gdbserver/}terminal.h)
As requested, I'm sending this as a separate patch because it is ready
to be included as-is.

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

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

Built on x86_64, no regressions found.

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

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

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

	* remote-utils.c: Include "gdb_termios.h" instead of
	"terminal.h".
	* terminal.h: Delete file.
2017-04-12 17:59:45 -04:00
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
Simon Marchi 436252de3e Class-ify ptid_t
I grew a bit tired of using ptid_get_{lwp,pid,tid} and friends, so I decided to
make it a bit easier to use by making it a proper class.  The fields are now
private, so it's not possible to change a ptid_t field by mistake.

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

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

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

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

gdb/ChangeLog:

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

gdb/gdbserver/ChangeLog:

	* server.c (handle_v_cont): Initialize thread_resume::thread
	with null_ptid.
2017-04-06 23:29:53 -04:00
Pedro Alves 9bf2a70066 -Wwrite-strings: Remove -Wno-write-strings
AFAIK GDB is now free from -Wwrite-strings warnings.  A few warnings may
be left behind in some host-specific code, but those should be few and
easy to fix.

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

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

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

	* configure: Regenerate.
2017-04-05 19:21:37 +01: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 21c8a587ab -Wwrite-strings: gdbserver/win32-low.c and TARGET_WAITKIND_EXECD
src/gdb/gdbserver/win32-low.c:1499:39: error: ISO C++ forbids converting a string constant to 'char*' [-Werror=write-strings]
	ourstatus->value.execd_pathname = "Main executable";
					^

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

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

	* win32-low.c (get_child_debug_event)
	<CREATE_PROCESS_DEBUG_EVENT>: Don't report TARGET_WAITKIND_EXECD.
	Report TARGET_WAITKIND_SPURIOUS instead.
2017-04-05 19:21:35 +01:00
Pedro Alves fb32b4f700 -Wwrite-strings: gdbserver's 'port' parsing
-Wwrite-strings flags this assignment as requiring a cast:

		  port = STDIO_CONNECTION_NAME;

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

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

        * remote-utils.c (remote_prepare, remote_open): Constify.
        * remote-utils.h (remote_prepare, remote_open): Constify.
        * server.c (captured_main): Constify 'port' handling.
2017-04-05 19:21:35 +01:00
Simon Marchi 65dd1e590e gdbserver: Clear .deps on clean
In some situations, the dependency tracking files in .deps can refer to
source files that were removed or renamed, leading to errors like:

  make: *** No rule to make target `version.c', needed by `version.o'. Stop.

This patch makes the clean target clear the .deps directory, which gives
the user a chance to recover from the error wihtout knowing about the
internals of the build system.

It is already done for GDB.  See here for more details:

  https://sourceware.org/ml/gdb-patches/2009-03/msg00000.html

gdb/gdbserver/ChangeLog:

	* Makefile.in (clean): Clear .deps.
2017-04-04 10:50:01 -04:00
Simon Marchi 8fa5b77748 gdbserver: Suffix generated C files with -generated
I noticed that there were some missing files in gdbserver's gitignore
(some generated register format .c files).  Of course the easy fix would
be to add those files to .gitignore, but I think we can do a better job,
so that we don't have to worry about adding generated files to
.gitignore or the clean Makefile target.

I suggest naming all generated source files -generated.c.  This way, we
can use a single rule in .gitignore and do a "rm -f *-generated.c" to
clean them up.

New in v2:

  - Don't rename version.o and xml-builtin.o

gdb/gdbserver/ChangeLog:

	* .gitignore: Remove generated files, replace with wildcard.
	* (clean): Replace removal of generated files with wildcard.
	(version.c): Replace with...
	(version-generated.c): ...this.
	(xml-builtin.c): Replace with...
	(xml-builtin-generated.c): ...this.
	(%-ipa.o: %-generated.c, %.o: %-generated.c): New rules.
	(%.c: *regformats*): Replace with...
	(%-generated.c: *regformats*): ...this.
2017-03-31 11:19:44 -04:00
Max Filippov a12e714b77 gdbserver: xtensa: support THREADPTR register
Provide aceess to the THREADPTR register to remote gdb.

gdb/gdbserver/
2017-03-27  Max Filippov  <jcmvbkbc@gmail.com>

	* linux-xtensa-low.c (regnum::R_THREADPTR): New enum member.
	(xtensa_fill_gregset): Call collect_register_by_name for
	threadptr register.
	(xtensa_store_gregset): Call supply_register_by_name for
	threadptr register.
2017-03-27 13:03:13 -07:00
Max Filippov 1a09b50a46 gdbserver: xtensa: add call0 support
Correctly handle a0- registers on requests from remote gdb. This fixes

  'Register 1 is not available'

and subsequent assertion in the remote gdb connecting to the gdbserver:

  'findvar.c:291: internal-error: value_of_register_lazy:
    Assertion `frame_id_p(get_frame_id (frame))' failed.'

The register structure is the same for windowed and call0 ABIs because
currently linux kernel internally requires windowed registers, so they
are always present.

gdb/gdbserver/
2017-03-27  Max Filippov  <jcmvbkbc@gmail.com>

	* linux-xtensa-low.c (xtensa_fill_gregset): Call collect_register
	for all registers in a0_regnum..a0_regnum + C0_NREGS range.
	(xtensa_store_gregset): Call supply_register for all registers in
	a0_regnum..a0_regnum + C0_NREGS range.
2017-03-27 13:00:04 -07:00
Simon Marchi 1a01e7c6b0 gdbserver: Use pattern rule for the remaining %-ipa.o objects
gdb/gdbserver/ChangeLog:

	* Makefile.in (%-ipa.o: %-ipa.c): New rule.
	(ax-ipa.o: ax.c): Remove.
	(linux-i386-ipa.o: linux-i386-ipa.c): Remove.
	(linux-amd64-ipa.o: linux-amd64-ipa.c): Remove.
	(linux-aarch64-ipa.o: linux-aarch64-ipa.c): Remove.
	(linux-s390-ipa.o: linux-s390-ipa.c): Remove.
	(linux-ppc-ipa.o: linux-ppc-ipa.c): Remove.
2017-03-13 18:44:05 -04:00
Simon Marchi 36bc18a810 gdbserver: Use pattern rule for IPA objects from common/
gdb/gdbserver/ChangeLog:

	* Makefile.in (%-ipa.o: ../common/%.c): New rule.
	(print-utils-ipa.o: ../common/print-utils.c): Remove.
	(rsp-low-ipa.o: ../common/rsp-low.c): Remove.
	(errors-ipa.o: ../common/errors.c): Remove.
	(format-ipa.o: ../common/format.c): Remove.
	(common-utils-ipa.o: ../common/common-utils.c): Remove.
2017-03-13 18:44:05 -04:00
Simon Marchi a8ebe3d5f1 gdbserver: Use pattern rule for IPA objects from gdbserver/
gdb/gdbserver/ChangeLog:

	* Makefile.in (%-ipa.o: %.c): New rule.
	(tracepoint-ipa.o: tracepoint.c): Remove.
	(utils-ipa.o: utils.c): Remove.
	(remote-utils-ipa.o: remote-utils.c): Remove.
	(regcache-ipa.o: regcache.c): Remove.
	(i386-linux-ipa.o: i386-linux.c): Remove.
	(i386-mmx-linux-ipa.o: i386-mmx-linux.c): Remove.
	(i386-avx-linux-ipa.o: i386-avx-linux.c): Remove.
	(i386-mpx-linux-ipa.o: i386-mpx-linux.c): Remove.
	(i386-avx-mpx-linux-ipa.o: i386-avx-mpx-linux.c): Remove.
	(i386-avx-avx512-linux-ipa.o: i386-avx-avx512-linux.c): Remove.
	(i386-avx-mpx-avx512-pku-linux-ipa.o: i386-avx-mpx-avx512-pku-linux.c): Remove.
	(amd64-linux-ipa.o: amd64-linux.c): Remove.
	(amd64-avx-linux-ipa.o: amd64-avx-linux.c): Remove.
	(amd64-mpx-linux-ipa.o: amd64-mpx-linux.c): Remove.
	(amd64-avx-mpx-linux-ipa.o: amd64-avx-mpx-linux.c): Remove.
	(amd64-avx-avx512-linux-ipa.o: amd64-avx-avx512-linux.c): Remove.
	(amd64-avx-mpx-avx512-pku-linux-ipa.o: amd64-avx-mpx-avx512-pku-linux.c): Remove.
	(aarch64-ipa.o: aarch64.c): Remove.
	(s390-linux32-ipa.o: s390-linux32.c): Remove.
	(s390-linux32v1-ipa.o: s390-linux32v1.c): Remove.
	(s390-linux32v2-ipa.o: s390-linux32v2.c): Remove.
	(s390-linux64-ipa.o: s390-linux64.c): Remove.
	(s390-linux64v1-ipa.o: s390-linux64v1.c): Remove.
	(s390-linux64v2-ipa.o: s390-linux64v2.c): Remove.
	(s390-te-linux64-ipa.o: s390-te-linux64.c): Remove.
	(s390-vx-linux64-ipa.o: s390-vx-linux64.c): Remove.
	(s390-tevx-linux64-ipa.o: s390-tevx-linux64.c): Remove.
	(s390x-linux64-ipa.o: s390x-linux64.c): Remove.
	(s390x-linux64v1-ipa.o: s390x-linux64v1.c): Remove.
	(s390x-linux64v2-ipa.o: s390x-linux64v2.c): Remove.
	(s390x-te-linux64-ipa.o: s390x-te-linux64.c): Remove.
	(s390x-vx-linux64-ipa.o: s390x-vx-linux64.c): Remove.
	(s390x-tevx-linux64-ipa.o: s390x-tevx-linux64.c): Remove.
	(powerpc-32l-ipa.o: powerpc-32l.c): Remove.
	(powerpc-altivec32l-ipa.o: powerpc-altivec32l.c): Remove.
	(powerpc-cell32l-ipa.o: powerpc-cell32l.c): Remove.
	(powerpc-vsx32l-ipa.o: powerpc-vsx32l.c): Remove.
	(powerpc-isa205-32l-ipa.o: powerpc-isa205-32l.c): Remove.
	(powerpc-isa205-altivec32l-ipa.o: powerpc-isa205-altivec32l.c): Remove.
	(powerpc-isa205-vsx32l-ipa.o: powerpc-isa205-vsx32l.c): Remove.
	(powerpc-e500l-ipa.o: powerpc-e500l.c): Remove.
	(powerpc-64l-ipa.o: powerpc-64l.c): Remove.
	(powerpc-altivec64l-ipa.o: powerpc-altivec64l.c): Remove.
	(powerpc-cell64l-ipa.o: powerpc-cell64l.c): Remove.
	(powerpc-vsx64l-ipa.o: powerpc-vsx64l.c): Remove.
	(powerpc-isa205-64l-ipa.o: powerpc-isa205-64l.c): Remove.
	(powerpc-isa205-altivec64l-ipa.o: powerpc-isa205-altivec64l.c): Remove.
	(powerpc-isa205-vsx64l-ipa.o: powerpc-isa205-vsx64l.c): Remove.
	(tdesc-ipa.o: tdesc.c): Remove.
	(x32-linux-ipa.o: x32-linux.c): Remove.
	(x32-avx-linux-ipa.o: x32-avx-linux.c): Remove.
	(x32-avx512-linux-ipa.o: x32-avx512-linux.c): Remove.
2017-03-13 18:44:04 -04:00
Simon Marchi 50cfacb78f gdbserver: Use pattern rule for objects from arch/
gdb/gdbserver/ChangeLog:

	* Makefile.in (%.o: ../arch/%.c): New rule.
	(arm.o: ../arch/arm.c): Remove.
	(arm-linux.o: ../arch/arm-linux.c): Remove.
	(arm-get-next-pcs.o: ../arch/arm-get-next-pcs.c): Remove.
	(aarch64-insn.o: ../arch/aarch64-insn.c): Remove.
2017-03-13 18:44:03 -04:00
Simon Marchi c5a22423d0 gdbserver: Use pattern rule for objects from nat/
gdb/gdbserver/ChangeLog:

	* Makefile.in (%.o: ../nat/%.c): New rule.
	(x86-dregs.o: ../nat/x86-dregs.c): Remove.
	(amd64-linux-siginfo.o: ../nat/amd64-linux-siginfo.c): Remove.
	(linux-btrace.o: ../nat/linux-btrace.c): Remove.
	(linux-osdata.o: ../nat/linux-osdata.c): Remove.
	(linux-procfs.o: ../nat/linux-procfs.c): Remove.
	(linux-ptrace.o: ../nat/linux-ptrace.c): Remove.
	(linux-waitpid.o: ../nat/linux-waitpid.c): Remove.
	(mips-linux-watch.o: ../nat/mips-linux-watch.c): Remove.
	(ppc-linux.o: ../nat/ppc-linux.c): Remove.
	(linux-personality.o: ../nat/linux-personality.c): Remove.
	(aarch64-linux-hw-point.o: ../nat/aarch64-linux-hw-point.c): Remove.
	(aarch64-linux.o: ../nat/aarch64-linux.c): Remove.
	(x86-linux.o: ../nat/x86-linux.c): Remove.
	(x86-linux-dregs.o: ../nat/x86-linux-dregs.c): Remove.
	(linux-namespaces.o: ../nat/linux-namespaces.c): Remove.
2017-03-13 18:44:03 -04:00
Simon Marchi 6bda016bec gdbserver: Use pattern rule for objects from common/
gdb/gdbserver/ChangeLog:

	* Makefile.in (%.o: ../common/%.c): New rule.
	(signals.o: ../common/signals.c): Remove.
	(print-utils.o: ../common/print-utils.c): Remove.
	(rsp-low.o: ../common/rsp-low.c): Remove.
	(common-utils.o: ../common/common-utils.c): Remove.
	(posix-strerror.o: ../common/posix-strerror.c): Remove.
	(mingw-strerror.o: ../common/mingw-strerror.c): Remove.
	(vec.o: ../common/vec.c): Remove.
	(gdb_vecs.o: ../common/gdb_vecs.c): Remove.
	(xml-utils.o: ../common/xml-utils.c): Remove.
	(ptid.o: ../common/ptid.c): Remove.
	(buffer.o: ../common/buffer.c): Remove.
	(format.o: ../common/format.c): Remove.
	(filestuff.o: ../common/filestuff.c): Remove.
	(agent.o: ../common/agent.c): Remove.
	(errors.o: ../common/errors.c): Remove.
	(environ.o: ../common/environ.c): Remove.
	(common-debug.o: ../common/common-debug.c): Remove.
	(cleanups.o: ../common/cleanups.c): Remove.
	(common-exceptions.o: ../common/common-exceptions.c): Remove.
	(fileio.o: ../common/fileio.c): Remove.
	(common-regcache.o: ../common/common-regcache.c): Remove.
	(signals-state-save-restore.o: ../common/signals-state-save-restore.c): Remove.
	(new-op.o: ../common/new-op.c): Remove.
	(btrace-common.o: ../common/btrace-common.c): Remove.
2017-03-13 18:44:02 -04:00
Simon Marchi 21122961ec gdbserver: Use pattern rule for objects from target/
gdb/gdbserver/ChangeLog:

	* Makefile.in (%.o: ../target/%.c): New rule.
	(waitstatus.o: ../target/waitstatus.c): Remove.
2017-03-13 18:44:02 -04:00