Commit Graph

197 Commits

Author SHA1 Message Date
Simon Marchi 5ab2fbf185 gdb: bool-ify follow_fork
Change parameters and return value of the various follow_fork
functions/methods from int to bool.

gdb/ChangeLog:

	* fbsd-nat.c (fbsd_nat_target::follow_fork): Change bool to int.
	* fbsd-nat.h (class fbsd_nat_target) <follow_fork>: Likewise.
	* inf-ptrace.c (inf_ptrace_target::follow_fork): Likewise.
	* inf-ptrace.h (struct inf_ptrace_target) <follow_fork>: Likewise.
	* infrun.c (follow_fork): Likewise.
	(follow_fork_inferior): Likewise.
	* linux-nat.c (linux_nat_target::follow_fork): Likewise.
	* linux-nat.h (class linux_nat_target): Likewise.
	* remote.c (class remote_target) <follow_fork>: Likewise.
	(remote_target::follow_fork): Likewise.
	* target-delegates.c: Re-generate.
	* target.c (default_follow_fork): Likewise.
	(target_follow_fork): Likewise.
	* target.h (struct target_ops) <follow_fork>: Likewise.
	(target_follow_fork): Likewise.
2020-03-24 13:45:21 -04:00
Pedro Alves 5b6d1e4fa4 Multi-target support
This commit adds multi-target support to GDB.  What this means is that
with this commit, GDB can now be connected to different targets at the
same time.  E.g., you can debug a live native process and a core dump
at the same time, connect to multiple gdbservers, etc.

Actually, the word "target" is overloaded in gdb.  We already have a
target stack, with pushes several target_ops instances on top of one
another.  We also have "info target" already, which means something
completely different to what this patch does.

So from here on, I'll be using the "target connections" term, to mean
an open process_stratum target, pushed on a target stack.  This patch
makes gdb have multiple target stacks, and multiple process_stratum
targets open simultaneously.  The user-visible changes / commands will
also use this terminology, but of course it's all open to debate.

User-interface-wise, not that much changes.  The main difference is
that each inferior may have its own target connection.

A target connection (e.g., a target extended-remote connection) may
support debugging multiple processes, just as before.

Say you're debugging against gdbserver in extended-remote mode, and
you do "add-inferior" to prepare to spawn a new process, like:

 (gdb) target extended-remote :9999
 ...
 (gdb) start
 ...
 (gdb) add-inferior
 Added inferior 2
 (gdb) inferior 2
 [Switching to inferior 2 [<null>] (<noexec>)]
 (gdb) file a.out
 ...
 (gdb) start
 ...

At this point, you have two inferiors connected to the same gdbserver.

With this commit, GDB will maintain a target stack per inferior,
instead of a global target stack.

To preserve the behavior above, by default, "add-inferior" makes the
new inferior inherit a copy of the target stack of the current
inferior.  Same across a fork - the child inherits a copy of the
target stack of the parent.  While the target stacks are copied, the
targets themselves are not.  Instead, target_ops is made a
refcounted_object, which means that target_ops instances are
refcounted, which each inferior counting for a reference.

What if you want to create an inferior and connect it to some _other_
target?  For that, this commit introduces a new "add-inferior
-no-connection" option that makes the new inferior not share the
current inferior's target.  So you could do:

 (gdb) target extended-remote :9999
 Remote debugging using :9999
 ...
 (gdb) add-inferior -no-connection
 [New inferior 2]
 Added inferior 2
 (gdb) inferior 2
 [Switching to inferior 2 [<null>] (<noexec>)]
 (gdb) info inferiors
   Num  Description       Executable
   1    process 18401     target:/home/pedro/tmp/main
 * 2    <null>
 (gdb) tar extended-remote :10000
 Remote debugging using :10000
 ...
 (gdb) info inferiors
   Num  Description       Executable
   1    process 18401     target:/home/pedro/tmp/main
 * 2    process 18450     target:/home/pedro/tmp/main
 (gdb)

A following patch will extended "info inferiors" to include a column
indicating which connection an inferior is bound to, along with a
couple other UI tweaks.

Other than that, debugging is the same as before.  Users interact with
inferiors and threads as before.  The only difference is that
inferiors may be bound to processes running in different machines.

That's pretty much all there is to it in terms of noticeable UI
changes.

On to implementation.

Since we can be connected to different systems at the same time, a
ptid_t is no longer a unique identifier.  Instead a thread can be
identified by a pair of ptid_t and 'process_stratum_target *', the
later being the instance of the process_stratum target that owns the
process/thread.  Note that process_stratum_target inherits from
target_ops, and all process_stratum targets inherit from
process_stratum_target.  In earlier patches, many places in gdb were
converted to refer to threads by thread_info pointer instead of
ptid_t, but there are still places in gdb where we start with a
pid/tid and need to find the corresponding inferior or thread_info
objects.  So you'll see in the patch many places adding a
process_stratum_target parameter to functions that used to take only a
ptid_t.

Since each inferior has its own target stack now, we can always find
the process_stratum target for an inferior.  That is done via a
inf->process_target() convenience method.

Since each inferior has its own target stack, we need to handle the
"beneath" calls when servicing target calls.  The solution I settled
with is just to make sure to switch the current inferior to the
inferior you want before making a target call.  Not relying on global
context is just not feasible in current GDB.  Fortunately, there
aren't that many places that need to do that, because generally most
code that calls target methods already has the current context
pointing to the right inferior/thread.  Note, to emphasize -- there's
no method to "switch to this target stack".  Instead, you switch the
current inferior, and that implicitly switches the target stack.

In some spots, we need to iterate over all inferiors so that we reach
all target stacks.

Native targets are still singletons.  There's always only a single
instance of such targets.

Remote targets however, we'll have one instance per remote connection.

The exec target is still a singleton.  There's only one instance.  I
did not see the point of instanciating more than one exec_target
object.

After vfork, we need to make sure to push the exec target on the new
inferior.  See exec_on_vfork.

For type safety, functions that need a {target, ptid} pair to identify
a thread, take a process_stratum_target pointer for target parameter
instead of target_ops *.  Some shared code in gdb/nat/ also need to
gain a target pointer parameter.  This poses an issue, since gdbserver
doesn't have process_stratum_target, only target_ops.  To fix this,
this commit renames gdbserver's target_ops to process_stratum_target.
I think this makes sense.  There's no concept of target stack in
gdbserver, and gdbserver's target_ops really implements a
process_stratum-like target.

The thread and inferior iterator functions also gain
process_stratum_target parameters.  These are used to be able to
iterate over threads and inferiors of a given target.  Following usual
conventions, if the target pointer is null, then we iterate over
threads and inferiors of all targets.

I tried converting "add-inferior" to the gdb::option framework, as a
preparatory patch, but that stumbled on the fact that gdb::option does
not support file options yet, for "add-inferior -exec".  I have a WIP
patchset that adds that, but it's not a trivial patch, mainly due to
need to integrate readline's filename completion, so I deferred that
to some other time.

In infrun.c/infcmd.c, the main change is that we need to poll events
out of all targets.  See do_target_wait.  Right after collecting an
event, we switch the current inferior to an inferior bound to the
target that reported the event, so that target methods can be used
while handling the event.  This makes most of the code transparent to
multi-targets.  See fetch_inferior_event.

infrun.c:stop_all_threads is interesting -- in this function we need
to stop all threads of all targets.  What the function does is send an
asynchronous stop request to all threads, and then synchronously waits
for events, with target_wait, rinse repeat, until all it finds are
stopped threads.  Now that we have multiple targets, it's not
efficient to synchronously block in target_wait waiting for events out
of one target.  Instead, we implement a mini event loop, with
interruptible_select, select'ing on one file descriptor per target.
For this to work, we need to be able to ask the target for a waitable
file descriptor.  Such file descriptors already exist, they are the
descriptors registered in the main event loop with add_file_handler,
inside the target_async implementations.  This commit adds a new
target_async_wait_fd target method that just returns the file
descriptor in question.  See wait_one / stop_all_threads in infrun.c.

The 'threads_executing' global is made a per-target variable.  Since
it is only relevant to process_stratum_target targets, this is where
it is put, instead of in target_ops.

You'll notice that remote.c includes some FIXME notes.  These refer to
the fact that the global arrays that hold data for the remote packets
supported are still globals.  For example, if we connect to two
different servers/stubs, then each might support different remote
protocol features.  They might even be different architectures, like
e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a
host/controller scenario as a single program.  That isn't going to
work correctly today, because of said globals.  I'm leaving fixing
that for another pass, since it does not appear to be trivial, and I'd
rather land the base work first.  It's already useful to be able to
debug multiple instances of the same server (e.g., a distributed
cluster, where you have full control over the servers installed), so I
think as is it's already reasonable incremental progress.

Current limitations:

 - You can only resume more that one target at the same time if all
   targets support asynchronous debugging, and support non-stop mode.
   It should be possible to support mixed all-stop + non-stop
   backends, but that is left for another time.  This means that
   currently in order to do multi-target with gdbserver you need to
   issue "maint set target-non-stop on".  I would like to make that
   mode be the default, but we're not there yet.  Note that I'm
   talking about how the target backend works, only.  User-visible
   all-stop mode works just fine.

 - As explained above, connecting to different remote servers at the
   same time is likely to produce bad results if they don't support the
   exact set of RSP features.

FreeBSD updates courtesy of John Baldwin.

gdb/ChangeLog:
2020-01-10  Pedro Alves  <palves@redhat.com>
	    John Baldwin  <jhb@FreeBSD.org>

	* aarch64-linux-nat.c
	(aarch64_linux_nat_target::thread_architecture): Adjust.
	* ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call.
	(task_command_1): Likewise.
	* aix-thread.c (sync_threadlists, aix_thread_target::resume)
	(aix_thread_target::wait, aix_thread_target::fetch_registers)
	(aix_thread_target::store_registers)
	(aix_thread_target::thread_alive): Adjust.
	* amd64-fbsd-tdep.c: Include "inferior.h".
	(amd64fbsd_get_thread_local_address): Pass down target.
	* amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle
	thread's gdbarch instead of target_gdbarch.
	* break-catch-sig.c (signal_catchpoint_print_it): Adjust call to
	get_last_target_status.
	* break-catch-syscall.c (print_it_catch_syscall): Likewise.
	* breakpoint.c (breakpoints_should_be_inserted_now): Consider all
	inferiors.
	(update_inserted_breakpoint_locations): Skip if inferiors with no
	execution.
	(update_global_location_list): When handling moribund locations,
	find representative inferior for location's pspace, and use thread
	count of its process_stratum target.
	* bsd-kvm.c (bsd_kvm_target_open): Pass target down.
	* bsd-uthread.c (bsd_uthread_target::wait): Use
	as_process_stratum_target and adjust thread_change_ptid and
	add_thread calls.
	(bsd_uthread_target::update_thread_list): Use
	as_process_stratum_target and adjust find_thread_ptid,
	thread_change_ptid and add_thread calls.
	* btrace.c (maint_btrace_packet_history_cmd): Adjust
	find_thread_ptid call.
	* corelow.c (add_to_thread_list): Adjust add_thread call.
	(core_target_open): Adjust add_thread_silent and thread_count
	calls.
	(core_target::pid_to_str): Adjust find_inferior_ptid call.
	* ctf.c (ctf_target_open): Adjust add_thread_silent call.
	* event-top.c (async_disconnect): Pop targets from all inferiors.
	* exec.c (add_target_sections): Push exec target on all inferiors
	sharing the program space.
	(remove_target_sections): Remove the exec target from all
	inferiors sharing the program space.
	(exec_on_vfork): New.
	* exec.h (exec_on_vfork): Declare.
	* fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter.
	Pass it down.
	(fbsd_nat_target::update_thread_list): Adjust.
	(fbsd_nat_target::resume): Adjust.
	(fbsd_handle_debug_trap): Add fbsd_nat_target parameter.  Pass it
	down.
	(fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust.
	* fbsd-tdep.c (fbsd_corefile_thread): Adjust
	get_thread_arch_regcache call.
	* fork-child.c (gdb_startup_inferior): Pass target down to
	startup_inferior and set_executing.
	* gdbthread.h (struct process_stratum_target): Forward declare.
	(add_thread, add_thread_silent, add_thread_with_info)
	(in_thread_list): Add process_stratum_target parameter.
	(find_thread_ptid(inferior*, ptid_t)): New overload.
	(find_thread_ptid, thread_change_ptid): Add process_stratum_target
	parameter.
	(all_threads()): Delete overload.
	(all_threads, all_non_exited_threads): Add process_stratum_target
	parameter.
	(all_threads_safe): Use brace initialization.
	(thread_count): Add process_stratum_target parameter.
	(set_resumed, set_running, set_stop_requested, set_executing)
	(threads_are_executing, finish_thread_state): Add
	process_stratum_target parameter.
	(switch_to_thread): Use is_current_thread.
	* i386-fbsd-tdep.c: Include "inferior.h".
	(i386fbsd_get_thread_local_address): Pass down target.
	* i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust.
	* inf-child.c (inf_child_target::maybe_unpush_target): Remove
	have_inferiors check.
	* inf-ptrace.c (inf_ptrace_target::create_inferior)
	(inf_ptrace_target::attach): Adjust.
	* infcall.c (run_inferior_call): Adjust.
	* infcmd.c (run_command_1): Pass target to
	scoped_finish_thread_state.
	(proceed_thread_callback): Skip inferiors with no execution.
	(continue_command): Rename 'all_threads' local to avoid hiding
	'all_threads' function.  Adjust get_last_target_status call.
	(prepare_one_step): Adjust set_running call.
	(signal_command): Use user_visible_resume_target.  Compare thread
	pointers instead of inferior_ptid.
	(info_program_command): Adjust to pass down target.
	(attach_command): Mark target's 'thread_executing' flag.
	(stop_current_target_threads_ns): New, factored out from ...
	(interrupt_target_1): ... this.  Switch inferior before making
	target calls.
	* inferior-iter.h
	(struct all_inferiors_iterator, struct all_inferiors_range)
	(struct all_inferiors_safe_range)
	(struct all_non_exited_inferiors_range): Filter on
	process_stratum_target too.  Remove explicit.
	* inferior.c (inferior::inferior): Push dummy target on target
	stack.
	(find_inferior_pid, find_inferior_ptid, number_of_live_inferiors):
	Add process_stratum_target parameter, and pass it down.
	(have_live_inferiors): Adjust.
	(switch_to_inferior_and_push_target): New.
	(add_inferior_command, clone_inferior_command): Handle
	"-no-connection" parameter.  Use
	switch_to_inferior_and_push_target.
	(_initialize_inferior): Mention "-no-connection" option in
	the help of "add-inferior" and "clone-inferior" commands.
	* inferior.h: Include "process-stratum-target.h".
	(interrupt_target_1): Use bool.
	(struct inferior) <push_target, unpush_target, target_is_pushed,
	find_target_beneath, top_target, process_target, target_at,
	m_stack>: New.
	(discard_all_inferiors): Delete.
	(find_inferior_pid, find_inferior_ptid, number_of_live_inferiors)
	(all_inferiors, all_non_exited_inferiors): Add
	process_stratum_target parameter.
	* infrun.c: Include "gdb_select.h" and <unordered_map>.
	(target_last_proc_target): New global.
	(follow_fork_inferior): Push target on new inferior.  Pass target
	to add_thread_silent.  Call exec_on_vfork.  Handle target's
	reference count.
	(follow_fork): Adjust get_last_target_status call.  Also consider
	target.
	(follow_exec): Push target on new inferior.
	(struct execution_control_state) <target>: New field.
	(user_visible_resume_target): New.
	(do_target_resume): Call target_async.
	(resume_1): Set target's threads_executing flag.  Consider resume
	target.
	(commit_resume_all_targets): New.
	(proceed): Also consider resume target.  Skip threads of inferiors
	with no execution.  Commit resumtion in all targets.
	(start_remote): Pass current inferior to wait_for_inferior.
	(infrun_thread_stop_requested): Consider target as well.  Pass
	thread_info pointer to clear_inline_frame_state instead of ptid.
	(infrun_thread_thread_exit): Consider target as well.
	(random_pending_event_thread): New inferior parameter.  Use it.
	(do_target_wait): Rename to ...
	(do_target_wait_1): ... this.  Add inferior parameter, and pass it
	down.
	(threads_are_resumed_pending_p, do_target_wait): New.
	(prepare_for_detach): Adjust calls.
	(wait_for_inferior): New inferior parameter.  Handle it.  Use
	do_target_wait_1 instead of do_target_wait.
	(fetch_inferior_event): Adjust.  Switch to representative
	inferior.  Pass target down.
	(set_last_target_status): Add process_stratum_target parameter.
	Save target in global.
	(get_last_target_status): Add process_stratum_target parameter and
	handle it.
	(nullify_last_target_wait_ptid): Clear 'target_last_proc_target'.
	(context_switch): Check inferior_ptid == null_ptid before calling
	inferior_thread().
	(get_inferior_stop_soon): Pass down target.
	(wait_one): Rename to ...
	(poll_one_curr_target): ... this.
	(struct wait_one_event): New.
	(wait_one): New.
	(stop_all_threads): Adjust.
	(handle_no_resumed, handle_inferior_event): Adjust to consider the
	event's target.
	(switch_back_to_stepped_thread): Also consider target.
	(print_stop_event): Update.
	(normal_stop): Update.  Also consider the resume target.
	* infrun.h (wait_for_inferior): Remove declaration.
	(user_visible_resume_target): New declaration.
	(get_last_target_status, set_last_target_status): New
	process_stratum_target parameter.
	* inline-frame.c (clear_inline_frame_state(ptid_t)): Add
	process_stratum_target parameter, and use it.
	(clear_inline_frame_state (thread_info*)): New.
	* inline-frame.c (clear_inline_frame_state(ptid_t)): Add
	process_stratum_target parameter.
	(clear_inline_frame_state (thread_info*)): Declare.
	* linux-fork.c (delete_checkpoint_command): Pass target down to
	find_thread_ptid.
	(checkpoint_command): Adjust.
	* linux-nat.c (linux_nat_target::follow_fork): Switch to thread
	instead of just tweaking inferior_ptid.
	(linux_nat_switch_fork): Pass target down to thread_change_ptid.
	(exit_lwp): Pass target down to find_thread_ptid.
	(attach_proc_task_lwp_callback): Pass target down to
	add_thread/set_running/set_executing.
	(linux_nat_target::attach): Pass target down to
	thread_change_ptid.
	(get_detach_signal): Pass target down to find_thread_ptid.
	Consider last target status's target.
	(linux_resume_one_lwp_throw, resume_lwp)
	(linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp)
	(stop_wait_callback, save_stop_reason, linux_nat_filter_event)
	(linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down.
	(linux_nat_target::async_wait_fd): New.
	(linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass
	target down.
	* linux-nat.h (linux_nat_target::async_wait_fd): Declare.
	* linux-tdep.c (get_thread_arch_regcache): Pass target down.
	* linux-thread-db.c (struct thread_db_info::process_target): New
	field.
	(add_thread_db_info): Save target.
	(get_thread_db_info): New process_stratum_target parameter.  Also
	match target.
	(delete_thread_db_info): New process_stratum_target parameter.
	Also match target.
	(thread_from_lwp): Adjust to pass down target.
	(thread_db_notice_clone): Pass down target.
	(check_thread_db_callback): Pass down target.
	(try_thread_db_load_1): Always push the thread_db target.
	(try_thread_db_load, record_thread): Pass target down.
	(thread_db_target::detach): Pass target down.  Always unpush the
	thread_db target.
	(thread_db_target::wait, thread_db_target::mourn_inferior): Pass
	target down.  Always unpush the thread_db target.
	(find_new_threads_callback, thread_db_find_new_threads_2)
	(thread_db_target::update_thread_list): Pass target down.
	(thread_db_target::pid_to_str): Pass current inferior down.
	(thread_db_target::get_thread_local_address): Pass target down.
	(thread_db_target::resume, maintenance_check_libthread_db): Pass
	target down.
	* nto-procfs.c (nto_procfs_target::update_thread_list): Adjust.
	* procfs.c (procfs_target::procfs_init_inferior): Declare.
	(proc_set_current_signal, do_attach, procfs_target::wait): Adjust.
	(procfs_init_inferior): Rename to ...
	(procfs_target::procfs_init_inferior): ... this and adjust.
	(procfs_target::create_inferior, procfs_notice_thread)
	(procfs_do_thread_registers): Adjust.
	* ppc-fbsd-tdep.c: Include "inferior.h".
	(ppcfbsd_get_thread_local_address): Pass down target.
	* proc-service.c (ps_xfer_memory): Switch current inferior and
	program space as well.
	(get_ps_regcache): Pass target down.
	* process-stratum-target.c
	(process_stratum_target::thread_address_space)
	(process_stratum_target::thread_architecture): Pass target down.
	* process-stratum-target.h
	(process_stratum_target::threads_executing): New field.
	(as_process_stratum_target): New.
	* ravenscar-thread.c
	(ravenscar_thread_target::update_inferior_ptid): Pass target down.
	(ravenscar_thread_target::wait, ravenscar_add_thread): Pass target
	down.
	* record-btrace.c (record_btrace_target::info_record): Adjust.
	(record_btrace_target::record_method)
	(record_btrace_target::record_is_replaying)
	(record_btrace_target::fetch_registers)
	(get_thread_current_frame_id, record_btrace_target::resume)
	(record_btrace_target::wait, record_btrace_target::stop): Pass
	target down.
	* record-full.c (record_full_wait_1): Switch to event thread.
	Pass target down.
	* regcache.c (regcache::regcache)
	(get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add
	process_stratum_target parameter and handle it.
	(current_thread_target): New global.
	(get_thread_regcache): Add process_stratum_target parameter and
	handle it.  Switch inferior before calling target method.
	(get_thread_regcache): Pass target down.
	(get_thread_regcache_for_ptid): Pass target down.
	(registers_changed_ptid): Add process_stratum_target parameter and
	handle it.
	(registers_changed_thread, registers_changed): Pass target down.
	(test_get_thread_arch_aspace_regcache): New.
	(current_regcache_test): Define a couple local test_target_ops
	instances and use them for testing.
	(readwrite_regcache): Pass process_stratum_target parameter.
	(cooked_read_test, cooked_write_test): Pass mock_target down.
	* regcache.h (get_thread_regcache, get_thread_arch_regcache)
	(get_thread_arch_aspace_regcache): Add process_stratum_target
	parameter.
	(regcache::target): New method.
	(regcache::regcache, regcache::get_thread_arch_aspace_regcache)
	(regcache::registers_changed_ptid): Add process_stratum_target
	parameter.
	(regcache::m_target): New field.
	(registers_changed_ptid): Add process_stratum_target parameter.
	* remote.c (remote_state::supports_vCont_probed): New field.
	(remote_target::async_wait_fd): New method.
	(remote_unpush_and_throw): Add remote_target parameter.
	(get_current_remote_target): Adjust.
	(remote_target::remote_add_inferior): Push target.
	(remote_target::remote_add_thread)
	(remote_target::remote_notice_new_inferior)
	(get_remote_thread_info): Pass target down.
	(remote_target::update_thread_list): Skip threads of inferiors
	bound to other targets.  (remote_target::close): Don't discard
	inferiors.  (remote_target::add_current_inferior_and_thread)
	(remote_target::process_initial_stop_replies)
	(remote_target::start_remote)
	(remote_target::remote_serial_quit_handler): Pass down target.
	(remote_target::remote_unpush_target): New remote_target
	parameter.  Unpush the target from all inferiors.
	(remote_target::remote_unpush_and_throw): New remote_target
	parameter.  Pass it down.
	(remote_target::open_1): Check whether the current inferior has
	execution instead of checking whether any inferior is live.  Pass
	target down.
	(remote_target::remote_detach_1): Pass down target.  Use
	remote_unpush_target.
	(extended_remote_target::attach): Pass down target.
	(remote_target::remote_vcont_probe): Set supports_vCont_probed.
	(remote_target::append_resumption): Pass down target.
	(remote_target::append_pending_thread_resumptions)
	(remote_target::remote_resume_with_hc, remote_target::resume)
	(remote_target::commit_resume): Pass down target.
	(remote_target::remote_stop_ns): Check supports_vCont_probed.
	(remote_target::interrupt_query)
	(remote_target::remove_new_fork_children)
	(remote_target::check_pending_events_prevent_wildcard_vcont)
	(remote_target::remote_parse_stop_reply)
	(remote_target::process_stop_reply): Pass down target.
	(first_remote_resumed_thread): New remote_target parameter.  Pass
	it down.
	(remote_target::wait_as): Pass down target.
	(unpush_and_perror): New remote_target parameter.  Pass it down.
	(remote_target::readchar, remote_target::remote_serial_write)
	(remote_target::getpkt_or_notif_sane_1)
	(remote_target::kill_new_fork_children, remote_target::kill): Pass
	down target.
	(remote_target::mourn_inferior): Pass down target.  Use
	remote_unpush_target.
	(remote_target::core_of_thread)
	(remote_target::remote_btrace_maybe_reopen): Pass down target.
	(remote_target::pid_to_exec_file)
	(remote_target::thread_handle_to_thread_info): Pass down target.
	(remote_target::async_wait_fd): New.
	* riscv-fbsd-tdep.c: Include "inferior.h".
	(riscv_fbsd_get_thread_local_address): Pass down target.
	* sol2-tdep.c (sol2_core_pid_to_str): Pass down target.
	* sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs)
	(ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback):
	Adjust.
	* solib-spu.c (spu_skip_standalone_loader): Pass down target.
	* solib-svr4.c (enable_break): Pass down target.
	* spu-multiarch.c (parse_spufs_run): Pass down target.
	* spu-tdep.c (spu2ppu_sniffer): Pass down target.
	* target-delegates.c: Regenerate.
	* target.c (g_target_stack): Delete.
	(current_top_target): Return the current inferior's top target.
	(target_has_execution_1): Refer to the passed-in inferior's top
	target.
	(target_supports_terminal_ours): Check whether the initial
	inferior was already created.
	(decref_target): New.
	(target_stack::push): Incref/decref the target.
	(push_target, push_target, unpush_target): Adjust.
	(target_stack::unpush): Defref target.
	(target_is_pushed): Return bool.  Adjust to refer to the current
	inferior's target stack.
	(dispose_inferior): Delete, and inline parts ...
	(target_preopen): ... here.  Only dispose of the current inferior.
	(target_detach): Hold strong target reference while detaching.
	Pass target down.
	(target_thread_name): Add assertion.
	(target_resume): Pass down target.
	(target_ops::beneath, find_target_at): Adjust to refer to the
	current inferior's target stack.
	(get_dummy_target): New.
	(target_pass_ctrlc): Pass the Ctrl-C to the first inferior that
	has a thread running.
	(initialize_targets): Rename to ...
	(_initialize_target): ... this.
	* target.h: Include "gdbsupport/refcounted-object.h".
	(struct target_ops): Inherit refcounted_object.
	(target_ops::shortname, target_ops::longname): Make const.
	(target_ops::async_wait_fd): New method.
	(decref_target): Declare.
	(struct target_ops_ref_policy): New.
	(target_ops_ref): New typedef.
	(get_dummy_target): Declare function.
	(target_is_pushed): Return bool.
	* thread-iter.c (all_matching_threads_iterator::m_inf_matches)
	(all_matching_threads_iterator::all_matching_threads_iterator):
	Handle filter target.
	* thread-iter.h (struct all_matching_threads_iterator, struct
	all_matching_threads_range, class all_non_exited_threads_range):
	Filter by target too.  Remove explicit.
	* thread.c (threads_executing): Delete.
	(inferior_thread): Pass down current inferior.
	(clear_thread_inferior_resources): Pass down thread pointer
	instead of ptid_t.
	(add_thread_silent, add_thread_with_info, add_thread): Add
	process_stratum_target parameter.  Use it for thread and inferior
	searches.
	(is_current_thread): New.
	(thread_info::deletable): Use it.
	(find_thread_ptid, thread_count, in_thread_list)
	(thread_change_ptid, set_resumed, set_running): New
	process_stratum_target parameter.  Pass it down.
	(set_executing): New process_stratum_target parameter.  Pass it
	down.  Adjust reference to 'threads_executing'.
	(threads_are_executing): New process_stratum_target parameter.
	Adjust reference to 'threads_executing'.
	(set_stop_requested, finish_thread_state): New
	process_stratum_target parameter.  Pass it down.
	(switch_to_thread): Also match inferior.
	(switch_to_thread): New process_stratum_target parameter.  Pass it
	down.
	(update_threads_executing): Reimplement.
	* top.c (quit_force): Pop targets from all inferior.
	(gdb_init): Don't call initialize_targets.
	* windows-nat.c (windows_nat_target) <get_windows_debug_event>:
	Declare.
	(windows_add_thread, windows_delete_thread): Adjust.
	(get_windows_debug_event): Rename to ...
	(windows_nat_target::get_windows_debug_event): ... this.  Adjust.
	* tracefile-tfile.c (tfile_target_open): Pass down target.
	* gdbsupport/common-gdbthread.h (struct process_stratum_target):
	Forward declare.
	(switch_to_thread): Add process_stratum_target parameter.
	* mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target
	parameter.  Use it.
	(mi_on_resume): Pass target down.
	* nat/fork-inferior.c (startup_inferior): Add
	process_stratum_target parameter.  Pass it down.
	* nat/fork-inferior.h (startup_inferior): Add
	process_stratum_target parameter.
	* python/py-threadevent.c (py_get_event_thread): Pass target down.

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

	* fork-child.c (post_fork_inferior): Pass target down to
	startup_inferior.
	* inferiors.c (switch_to_thread): Add process_stratum_target
	parameter.
	* lynx-low.c (lynx_target_ops): Now a process_stratum_target.
	* nto-low.c (nto_target_ops): Now a process_stratum_target.
	* linux-low.c (linux_target_ops): Now a process_stratum_target.
	* remote-utils.c (prepare_resume_reply): Pass the target to
	switch_to_thread.
	* target.c (the_target): Now a process_stratum_target.
	(done_accessing_memory): Pass the target to switch_to_thread.
	(set_target_ops): Ajust to use process_stratum_target.
	* target.h (struct target_ops): Rename to ...
	(struct process_stratum_target): ... this.
	(the_target, set_target_ops): Adjust.
	(prepare_to_access_memory): Adjust comment.
	* win32-low.c (child_xfer_memory): Adjust to use
	process_stratum_target.
	(win32_target_ops): Now a process_stratum_target.
2020-01-10 20:06:08 +00:00
Tom Tromey 4ca51187d2 Constify target_ops::follow_exec
I noticed that target_ops::follow_exec took a "char *" parameter,
where "const char *" would be more correct.  This patch changes this
(and related functions) to be constified.

Tested by rebuilding.

gdb/ChangeLog
2019-05-22  Tom Tromey  <tromey@adacore.com>

	* target.c (target_follow_exec): Constify parameter.
	* target-delegates.c: Rebuild.
	* remote.c (remote_target::follow_exec): Constify parameter.
	* infrun.c (follow_exec): Constify parameter.
	* target.h (struct target_ops) <follow_exec>: Constify parameter.
	(target_follow_exec): Likewise.
2019-05-22 15:41:28 -04:00
Kevin Buettner 3d6c62048d Introduce target_ops method thread_info_to_thread_handle
This patch adds a thread_info_to_thread_handle method to the target_ops
struct.  It also implements this functionality for remote targets and
linux native threads.

gdb/ChangeLog:

	* gdbthread.h (thread_to_thread_handle): Declare.
	* thread.c (gdbtypes.h): Include.
	(thread_to_thread_handle): New function.

	* target.h (struct target_ops): Add thread_info_to_thread_handle.
	(target_thread_info_to_thread_handle): Declare.
	* target.c (target_thread_info_to_thread_handle): New function.
	* target-debug.h (target_debug_print_gdb_byte_vector): Define.
	* target-delegates.c: Regenerate.

	* linux-thread-db.c (class thread_db_target): Add method
	thread_info_to_thread_handle.
	(thread_db_target::thread_info_to_thread_handle): Define.
	* remote.c (class remote_target): Add new method
	thread_info_to_thread_handle.
	(remote_target::thread_info_to_thread_handle): Define.
2019-04-08 20:09:37 -07:00
Tom Tromey a068643d69 Change pid_to_str to return std::string
Currently the target pid_to_str method returns a const char *, so many
implementations have a static buffer that they update.  This patch
changes these methods to return a std::string instead.  I think this
is cleaner and avoids possible gotchas when calling pid_to_str on
different ptids in a single statement.  (Though no such calls exist
currently.)

This also updates various helper functions, and the gdbarch pid_to_str
methods.

I also made a best effort to fix all the callers, but I can't build
some of the *-nat.c files.

Tested by the buildbot.

gdb/ChangeLog
2019-03-13  Tom Tromey  <tromey@adacore.com>

	* i386-gnu-nat.c (i386_gnu_nat_target::fetch_registers)
	(i386_gnu_nat_target::store_registers): Update.
	* target-debug.h (target_debug_print_std_string): New macro.
	* x86-linux-nat.c (x86_linux_nat_target::enable_btrace): Update.
	* windows-tdep.c (display_one_tib): Update.
	* tui/tui-stack.c (tui_make_status_line): Update.
	* top.c (print_inferior_quit_action): Update.
	* thread.c (thr_try_catch_cmd): Update.
	(add_thread_with_info): Update.
	(thread_target_id_str): Update.
	(thr_try_catch_cmd): Update.
	(thread_command): Update.
	(thread_find_command): Update.
	* record-btrace.c (record_btrace_target::info_record)
	(record_btrace_resume_thread, record_btrace_target::resume)
	(record_btrace_cancel_resume, record_btrace_step_thread)
	(record_btrace_target::wait, record_btrace_target::wait)
	(record_btrace_target::wait, record_btrace_target::stop): Update.
	* progspace.c (print_program_space): Update.
	* process-stratum-target.c
	(process_stratum_target::thread_address_space): Update.
	* linux-fork.c (linux_fork_mourn_inferior)
	(detach_checkpoint_command, info_checkpoints_command)
	(linux_fork_context): Update.
	(linux_fork_detach): Update.
	(class scoped_switch_fork_info): Update.
	(delete_checkpoint_command): Update.
	* infrun.c (follow_fork_inferior): Update.
	(follow_fork_inferior): Update.
	(proceed_after_vfork_done): Update.
	(handle_vfork_child_exec_or_exit): Update.
	(follow_exec): Update.
	(displaced_step_prepare_throw): Update.
	(displaced_step_restore): Update.
	(start_step_over): Update.
	(resume_1): Update.
	(clear_proceed_status_thread): Update.
	(proceed): Update.
	(print_target_wait_results): Update.
	(do_target_wait): Update.
	(context_switch): Update.
	(stop_all_threads): Update.
	(restart_threads): Update.
	(finish_step_over): Update.
	(handle_signal_stop): Update.
	(switch_back_to_stepped_thread): Update.
	(keep_going_pass_signal): Update.
	(print_exited_reason): Update.
	(normal_stop): Update.
	* inferior.c (inferior_pid_to_str): Change return type.
	(print_selected_inferior): Update.
	(add_inferior): Update.
	(detach_inferior): Update.
	* dummy-frame.c (fprint_dummy_frames): Update.
	* dcache.c (dcache_info_1): Update.
	* btrace.c (btrace_enable, btrace_disable, btrace_teardown)
	(btrace_fetch, btrace_clear): Update.
	* linux-tdep.c (linux_core_pid_to_str): Change return type.
	* i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Change return
	type.
	* fbsd-tdep.c (fbsd_core_pid_to_str): Change return type.
	* sol2-tdep.h (sol2_core_pid_to_str): Change return type.
	* sol2-tdep.c (sol2_core_pid_to_str): Change return type.
	* gdbarch.c, gdbarch.h: Rebuild.
	* gdbarch.sh (core_pid_to_str): Change return type.
	* windows-nat.c (struct windows_nat_target) <pid_to_str>: Change
	return type.
	(windows_nat_target::pid_to_str): Change return type.
	(windows_delete_thread): Update.
	(windows_nat_target::attach): Update.
	(windows_nat_target::files_info): Update.
	* target-delegates.c: Rebuild.
	* sol-thread.c (class sol_thread_target) <pid_to_str>: Change
	return type.
	(sol_thread_target::pid_to_str): Change return type.
	* remote.c (class remote_target) <pid_to_str>: Change return
	type.
	(remote_target::pid_to_str): Change return type.
	(extended_remote_target::attach, remote_target::remote_stop_ns)
	(remote_target::remote_notif_remove_queued_reply)
	(remote_target::push_stop_reply, remote_target::disable_btrace):
	Update.
	(extended_remote_target::attach): Update.
	* remote-sim.c (struct gdbsim_target) <pid_to_str>: Change return
	type.
	(gdbsim_target::pid_to_str): Change return type.
	* ravenscar-thread.c (struct ravenscar_thread_target)
	<pid_to_str>: Change return type.
	(ravenscar_thread_target::pid_to_str): Change return type.
	* procfs.c (class procfs_target) <pid_to_str>: Change return
	type.
	(procfs_target::pid_to_str): Change return type.
	(procfs_target::attach): Update.
	(procfs_target::detach): Update.
	(procfs_target::fetch_registers): Update.
	(procfs_target::store_registers): Update.
	(procfs_target::wait): Update.
	(procfs_target::files_info): Update.
	* obsd-nat.c (obsd_nat_target::pid_to_str): Change return type.
	* nto-procfs.c (struct nto_procfs_target) <pid_to_str>: Change
	return type.
	(nto_procfs_target::pid_to_str): Change return type.
	(nto_procfs_target::files_info, nto_procfs_target::attach): Update.
	* linux-thread-db.c (class thread_db_target) <pid_to_str>: Change
	return type.
	* linux-nat.c (linux_nat_target::pid_to_str): Change return type.
	(exit_lwp): Update.
	(attach_proc_task_lwp_callback, get_detach_signal)
	(detach_one_lwp, resume_lwp, linux_nat_target::resume)
	(linux_nat_target::resume, wait_lwp, stop_callback)
	(maybe_clear_ignore_sigint, stop_wait_callback, status_callback)
	(save_stop_reason, select_event_lwp, linux_nat_filter_event)
	(linux_nat_wait_1, resume_stopped_resumed_lwps)
	(linux_nat_target::wait, linux_nat_stop_lwp): Update.
	* inf-ptrace.c (inf_ptrace_target::pid_to_str): Change return
	type.
	(inf_ptrace_target::attach): Update.
	(inf_ptrace_target::files_info): Update.
	* go32-nat.c (struct go32_nat_target) <pid_to_str>: Change return
	type.
	(go32_nat_target::pid_to_str): Change return type.
	* gnu-nat.c (gnu_nat_target::pid_to_str): Change return type.
	(gnu_nat_target::wait): Update.
	(gnu_nat_target::wait): Update.
	(gnu_nat_target::resume): Update.
	* fbsd-nat.c (fbsd_nat_target::pid_to_str): Change return type.
	(fbsd_nat_target::wait): Update.
	* darwin-nat.c (darwin_nat_target::pid_to_str): Change return
	type.
	(darwin_nat_target::attach): Update.
	* corelow.c (class core_target) <pid_to_str>: Change return type.
	(core_target::pid_to_str): Change return type.
	* target.c (normal_pid_to_str): Change return type.
	(default_pid_to_str): Likewise.
	(target_pid_to_str): Change return type.
	(target_translate_tls_address): Update.
	(target_announce_detach): Update.
	* bsd-uthread.c (struct bsd_uthread_target) <pid_to_str>: Change
	return type.
	(bsd_uthread_target::pid_to_str): Change return type.
	* bsd-kvm.c (class bsd_kvm_target) <pid_to_str>: Change return
	type.
	(bsd_kvm_target::pid_to_str): Change return type.
	* aix-thread.c (class aix_thread_target) <pid_to_str>: Change
	return type.
	(aix_thread_target::pid_to_str): Change return type.
	* target.h (struct target_ops) <pid_to_str>: Change return type.
	(target_pid_to_str, normal_pid_to_str): Likewise.
	* obsd-nat.h (class obsd_nat_target) <pid_to_str>: Change return
	type.
	* linux-nat.h (class linux_nat_target) <pid_to_str>: Change return
	type.
	* inf-ptrace.h (struct inf_ptrace_target) <pid_to_str>: Change
	return type.
	* gnu-nat.h (struct gnu_nat_target) <pid_to_str>: Change return
	type.
	* fbsd-nat.h (class fbsd_nat_target) <pid_to_str>: Change return
	type.
	* darwin-nat.h (class darwin_nat_target) <pid_to_str>: Change
	return type.
2019-03-13 13:50:13 -06:00
Pedro Alves adc6a863a9 target_pass_signals/target_program_signals: Use gdb::array_view
This replaces the pointer and length parameters of target_pass_signals
and target_program_signals with a gdb::array_view parameter, and fixes
the fallout.

In infrun.c, the signal_stop, signal_print, signal_program,
signal_catch, signal_pass globals are currently pointers to
heap-allocated memory.  I see no point in that, so I converted them to
arrays.  This allows simplifying the calls to
target_pass_signals/target_program_signals, since we can pass the
array directly, which can implicitly convert to gdb::array_view.

gdb/ChangeLog:
2019-01-24  Pedro Alves  <palves@redhat.com>

	* infrun.c (signal_stop, signal_print, signal_program)
	(signal_catch, signal_pass): Now arrays instead of pointers.
	(update_signals_program_target, do_target_resume)
	(signal_catch_update, handle_command, _initialize_infrun): Adjust.
	* linux-nat.c (linux_nat_target::pass_signals)
	(linux_nat_target::create_inferior, linux_nat_target::attach):
	Adjust.
	* linux-nat.h (linux_nat_target::pass_signals): Adjust.
	* nto-procfs.c (nto_procfs_target::pass_signals): Adjust.
	* procfs.c (procfs_target::pass_signals): Adjust.
	* record-full.c (record_full_target::resume): Adjust.
	* remote.c (remote_target::pass_signals)
	(remote_target::program_signals): Adjust.
	* target-debug.h (target_debug_print_signals): Now takes a
	gdb::array_view as parameter.  Adjust.
	* target.h (target_ops) <pass_signals, program_signals>: Replace
	pointer and length parameters with gdb::array_view.
	(target_pass_signals, target_program_signals): Likewise.
	* target-delegates.c: Regenerate.
2019-01-24 18:25:06 +00:00
Tom Tromey 491adecac4 Constify target_pass_signals and target_program_signals
This constifies the final parameter to target_pass_signals and
target_program_signals and updates the rest of gdb.

Note that I have no way to test the nto-procfs.c change.

gdb/ChangeLog
2019-01-14  Tom Tromey  <tom@tromey.com>

	* target-debug.h (target_debug_print_signals): Constify.
	* nto-procfs.c (nto_procfs_target::pass_signals): Update.
	* procfs.c (procfs_target::pass_signals): Update.
	* linux-nat.c (linux_nat_target::pass_signals): Update.
	* linux-nat.h (class linux_nat_target) <pass_signals>: Update.
	* target-delegates.c: Rebuild.
	* remote.c (remote_target::program_signals): Update.
	(remote_target::pass_signals): Update.
	* target.c (target_pass_signals): Constify argument.
	(target_program_signals): Likewise.
	* target.h (struct target_ops) <pass_signals, program_signals>:
	Constify argument.
	(target_pass_signals, target_program_signals): Constify argument.
2019-01-14 17:32:24 -07:00
Pedro Alves 66b4deae03 target_ops::to_stratum -> target_ops::stratum() virtual method
Given that a target's stratum is a property of the type, and not of an
instance of the type, get rid of to_stratum data field and replace it
with a virtual method.

I.e., when we have e.g., 10 target remote instances active, there's no
need for each of the instances to have their own to_stratum copy.

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

	* aix-thread.c (aix_thread_target) <aix_thread_target>: Delete.
	<stratum>: New override.
	* bfd-target.c (aix_thread_target) <aix_thread_target>: Delete.
	<stratum>: New override.
	* bsd-uthread.c (bsd_uthread_target) <bsd_uthread_target>: Delete.
	<stratum>: New override.
	* exec.c (exec_target) <exec_target>: Delete.
	<stratum>: New override.
	* gdbarch-selftests.c (register_to_value_test): Adjust to use the
	stratum method instead of the to_stratum field.
	* linux-thread-db.c (thread_db_target) <thread_db_target>: Delete.
	<stratum>: New override.
	(thread_db_target::thread_db_target): Delete.
	* make-target-delegates (print_class): Don't print a ctor
	declaration.  Print a stratum method override declaration.
	* process-stratum-target.h (process_stratum_target)
	<process_stratum_target>: Delete.
	<stratum>: New override.
	* ravenscar-thread.c (ravenscar_thread_target)
	<ravenscar_thread_target>: Delete.
	<stratum>: New override.
	* record-btrace.c (record_btrace_target)
	<record_btrace_target>: Delete.
	<stratum>: New override.
	* record-full.c (record_full_base_target)
	<record_full_base_target>: Delete.
	<stratum>: New override.
	* record.c (record_disconnect, record_detach)
	(record_mourn_inferior, record_kill): Adjust to use the stratum
	method instead of the to_stratum field.
	* regcache.c (cooked_read_test, cooked_write_test): Likewise.
	* sol-thread.c (sol_thread_target)
	<sol_thread_target>: Delete.
	<stratum>: New override.
	* spu-multiarch.c (spu_multiarch_target)
	<spu_multiarch_target>: Delete.
	<stratum>: New override.
	* target-delegates.c: Regenerate.
	* target.c (target_stack::push, target_stack::unpush)
	(pop_all_targets_above, pop_all_targets_at_and_above)
	(info_target_command, target_require_runnable)
	(target_stack::find_beneath): Adjust to use the stratum method
	instead of the to_stratum field.
	(dummy_target::dummy_target): Delete.
	(dummy_target::stratum): New.
	(debug_target::debug_target): Delete.
	(debug_target::stratum): New.
	(maintenance_print_target_stack): Adjust to use the stratum method
	instead of the to_stratum field.
	* target.h (struct target_ops) <stratum>: New method.
	<to_stratum>: Delete.
	<is_pushed>: Adjust to use the stratum method
	instead of the to_stratum field.
2018-11-30 17:49:49 +00:00
Pedro Alves 3b3dac9b3f Introduce process_stratum_target
This adds a base class that all process_stratum targets inherit from.

default_thread_address_space/default_thread_architecture only make
sense for process_stratum targets, so they are transformed to
process_stratum_target methods/overrides.

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

	* Makefile.in (COMMON_SFILES): Add process-stratum-target.c.
	* bsd-kvm.c: Include "process-stratum-target.h".
	(bsd_kvm_target): Now inherits from process_stratum_target.
	(bsd_kvm_target::bsd_kvm_target): Default it.
	* corelow.c: Include "process-stratum-target.h".
	(core_target): Now inherits from process_stratum_target.
	(core_target::core_target): Don't set to_stratum here.
	* inf-child.c (inf_child_target::inf_child_target): Delete.
	* inf-child.h: Include "process-stratum-target.h".
	(inf_child_target): Inherit from process_stratum_target.
	(inf_child_target) <inf_child_target>: Default it.
	<can_async_p, supports_non_stop, supports_disable_randomization>:
	Delete overrides.
	* process-stratum-target.c: New file.
	* process-stratum-target.h: New file.
	* remote-sim.c: Include "process-stratum-target.h".
	(gdbsim_target): Inherit from process_stratum_target.
	<gdbsim_target>: Default it.
	* remote.c: Include "process-stratum-target.h".
	(remote_target): Inherit from process_stratum_target.
	<remote_target>: Default it.
	* target.c (default_thread_address_space)
	(default_thread_architecture): Delete.
	* target.h (target_ops) <thread_architecture>: Now returns NULL by
	default.
	<thread_address_space>: Ditto.
	* test-target.h: Include "process-stratum-target.h" instead of
	"target.h".
	(test_target_ops): Inherit from process_stratum_target.
	<test_target_ops>: Default it.
	* tracefile.c (tracefile_target::tracefile_target): Delete.
	* tracefile.h: Include "process-stratum-target.h".
	(tracefile_target): Inherit from process_stratum_target.
	<tracefile_target>: Default it.
	* target-delegates.c: Regenerate.
2018-11-30 16:27:26 +00:00
Tom Tromey c2a6c5da37 Fix ia64-linux-nat.c
PR build/23814 points out that ia64-linux-nat.c will not compile any
more.  This patch fixes the problem.  Thanks to Andreas Schwab for
trying the patch.

gdb/ChangeLog
2018-11-18  Tom Tromey  <tom@tromey.com>

	PR build/23814:
	* target-delegates.c: Rebuild.
	* ia64-linux-nat.c (class ia64_linux_nat_target)
	<have_steppable_watchpoint>: Use override.  Return true, not 1.
	(ia64_linux_nat_target::can_use_hw_breakpoint): Rename.  Remove
	"self" argument.
	(ia64_linux_nat_target::low_new_thread): Rename.
	(class ia64_linux_nat_target) <read_description>: Don't declare.
	* target.h (struct target_ops) <have_steppable_watchpoint>: Return
	bool.
2018-11-18 09:30:55 -07:00
Pedro Alves 7eb65fafed Eliminate target_have_continuable_watchpoint
target_have_continuable_watchpoint isn't used anywhere so remove it.
The property isn't necessary because checking for "continuable" is the
same as checking for "!steppable && !non-steppable".

gdb/ChangeLog:
2018-08-31  Pedro Alves  <palves@redhat.com>

	* nto-procfs.c (nto_procfs_target::have_continuable_watchpoint):
	Delete.
	* s390-linux-nat.c
	(s390_linux_nat_target::have_continuable_watchpoint): Delete.
	* target.h (target_ops::have_continuable_watchpoint): Delete.
	(target_have_continuable_watchpoint): Delete.
	* x86-nat.h (x86_nat_target::have_continuable_watchpoint): Delete.
	* target-delegates.c: Regenerate.
2018-08-31 18:47:12 +01:00
Pedro Alves b6a8c27bb8 target_ops::beneath -> target_ops::beneath()
This changes target_ops::beneath from a pointer to a method, and
adjusts all references throughout.  The idea here is to make it easier
to change the target stack representation from an intrusive singly
linked list to something else without leaking implementation details
throughout.

The commit does not change the representation yet, that will be done
in a following patch.  That is why a new target_ops::m_beneath field
appears here.  That new field isn't really documented properly or made
private, simply because it will be removed shortly.

Note that target_ops::beneath() is essentially the same as the current
find_target_beneath routine.  The following patch will eliminate the
latter.

gdb/ChangeLog:
2018-06-07  Pedro Alves  <palves@redhat.com>

	* target.h (target_ops) <beneath>: Now a method.  All references
	updated.
	(target_ops) <m_beneath>: New.
	* target.c (target_ops::beneath): New.
	* corelow.c: Adjust all references to target_ops::beneath.
	* linux-thread-db.c: Likewise.
	* make-target-delegates: Likewise.
	* record-btrace.c: Likewise.
	* record-full.c: Likewise.
	* remote.c: Likewise.
	* target.c: Likewise.
	* target-delegates.c: Regenerate.
2018-06-07 18:57:06 +01:00
Pedro Alves d9f719f1ad target factories, target open and multiple instances of targets
Currently, to open a target, with "target TARGET_NAME", GDB finds the
target_ops instance with "TARGET_NAME" as short name, and then calls
its target_ops::open virtual method.  In reality, there's no actual
target/name lookup, a pointer to the target_ops object was associated
with the "target TARGET_NAME" command at add_target time (when GDB is
initialized), as the command's context.

This creates a chicken and egg situation.  Consider the case of
wanting to open multiple remote connections.  We want to be able to
have one remote target_ops instance per connection, but, if we're not
connected yet, so we don't yet have an instance to call target->open()
on...

This patch fixes this by separating out common info about a target_ops
to a separate structure (shortname, longname, doc), and changing the
add_target routine to take a reference to such an object instead of a
pointer to a target_ops, and a pointer to a factory function that is
responsible to open an instance of the corresponding target when the
user types "target TARGET_NAME".

 -extern void add_target (struct target_ops *);
 +extern void add_target (const target_info &info, target_open_ftype *func);

I.e. this factory function replaces the target_ops::open virtual
method.

For static/singleton targets, nothing changes, the target_open_ftype
function pushes the global target_ops instance on the target stack.
At target_close time, the connection is tor down, but the global
target_ops object remains live.

However, targets that support being open multiple times will make
their target_open_ftype routine allocate a new target_ops instance on
the heap [e.g., new remote_target()], and push that on the stack.  At
target_close time, the new object is destroyed (by the
target_ops::close virtual method).

Both the core target and the remote targets will support being open
multiple times (others could/should too, but those were my stopping
point), but not in this patch yet.  We need to get rid of more globals
first before that'd be useful.

Native targets are somewhat special, given find_default_run_target &
friends.  Those routines also expect to return a target_ops pointer,
even before we've open the target.  However, we'll never need more
than one instance of the native target, so we can assume/require that
native targets are global/simpletons, and have the backends register a
pointer to the native target_ops.  Since all native targets inherit
inf_child_target, we can centralize that registration.  See
add_inf_child_target, get_native_target/set_native_target and
find_default_run_target.

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

	* aarch64-fbsd-nat.c (_initialize_aarch64_fbsd_nat): Use
	add_inf_child_target.
	* aarch64-linux-nat.c (_initialize_aarch64_linux_nat): Use
	add_inf_child_target.
	* aix-thread.c (aix_thread_target_info): New.
	(aix_thread_target) <shortname, longname, doc>: Delete.
	<info>: New.
	* alpha-bsd-nat.c (_initialize_alphabsd_nat): Use
	add_inf_child_target.
	* alpha-linux-nat.c (_initialize_alpha_linux_nat): Use
	add_inf_child_target.
	* amd64-fbsd-nat.c (_initialize_amd64fbsd_nat): Use
	add_inf_child_target.
	* amd64-linux-nat.c (_initialize_amd64_linux_nat): Use
	add_inf_child_target.
	* amd64-nbsd-nat.c (_initialize_amd64nbsd_nat): Use
	add_inf_child_target.
	* amd64-obsd-nat.c (_initialize_amd64obsd_nat): Use
	add_inf_child_target.
	* arm-fbsd-nat.c (_initialize_arm_fbsd_nat): Use
	add_inf_child_target.
	* arm-linux-nat.c (_initialize_arm_linux_nat): Use
	add_inf_child_target.
	* arm-nbsd-nat.c (_initialize_arm_netbsd_nat): Use
	add_inf_child_target.
	* bfd-target.c (target_bfd_target_info): New.
	(target_bfd) <shortname, longname, doc>: Delete.
	<info>: New.
	* bsd-kvm.c (bsd_kvm_target_info): New.
	(bsd_kvm_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(bsd_kvm_target::open): Rename to ...
	(bsd_kvm_target_open): ... this.  Adjust.
	* bsd-uthread.c (bsd_uthread_target_info): New.
	(bsd_uthread_target) <shortname, longname, doc>: Delete.
	<info>:	New.
	* corefile.c (core_file_command): Adjust.
	* corelow.c (core_target_info): New.
	(core_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(core_target::open): Rename to ...
	(core_target_open): ... this.  Adjust.
	* ctf.c (ctf_target_info): New.
	(ctf_target) <shortname, longname, doc>: Delete.
	<info>:	New.
	(ctf_target::open): Rename to ...
	(ctf_target_open): ... this.
	(_initialize_ctf): Adjust.
	* exec.c (exec_target_info): New.
	(exec_target) <shortname, longname, doc>: Delete.
	<info>:	New.
	(exec_target::open): Rename to ...
	(exec_target_open): ... this.
	* gdbcore.h (core_target_open): Declare.
	* go32-nat.c (_initialize_go32_nat): Use add_inf_child_target.
	* hppa-linux-nat.c (_initialize_hppa_linux_nat): Use
	add_inf_child_target.
	* hppa-nbsd-nat.c (_initialize_hppanbsd_nat): Use
	add_inf_child_target.
	* hppa-obsd-nat.c (_initialize_hppaobsd_nat): Use
	add_inf_child_target.
	* i386-darwin-nat.c (_initialize_i386_darwin_nat): Use
	add_inf_child_target.
	* i386-fbsd-nat.c (_initialize_i386fbsd_nat): Use
	add_inf_child_target.
	* i386-gnu-nat.c (_initialize_i386gnu_nat): Use
	add_inf_child_target.
	* i386-linux-nat.c (_initialize_i386_linux_nat): Use
	add_inf_child_target.
	* i386-nbsd-nat.c (_initialize_i386nbsd_nat): Use
	add_inf_child_target.
	* i386-obsd-nat.c (_initialize_i386obsd_nat): Use
	add_inf_child_target.
	* ia64-linux-nat.c (_initialize_ia64_linux_nat): Use
	add_inf_child_target.
	* inf-child.c (inf_child_target_info): New.
	(inf_child_target::info): New.
	(inf_child_open_target): Remove 'target' parameter.  Use
	get_native_target instead.
	(inf_child_target::open): Delete.
	(add_inf_child_target): New.
	* inf-child.h (inf_child_target) <shortname, longname, doc, open>:
	Delete.
	<info>:	New.
	(add_inf_child_target): Declare.
	(inf_child_open_target): Declare.
	* linux-thread-db.c (thread_db_target_info): New.
	(thread_db_target) <shortname, longname, doc>: Delete.
	<info>:	New.
	* m32r-linux-nat.c (_initialize_m32r_linux_nat): Use
	add_inf_child_target.
	* m68k-bsd-nat.c (_initialize_m68kbsd_nat): Use
	add_inf_child_target.
	* m68k-linux-nat.c (_initialize_m68k_linux_nat): Use
	add_inf_child_target.
	* m88k-bsd-nat.c (_initialize_m88kbsd_nat): Use
	add_inf_child_target.
	* make-target-delegates (print_class): Adjust.
	* mips-fbsd-nat.c (_initialize_mips_fbsd_nat): Use
	add_inf_child_target.
	* mips-linux-nat.c (_initialize_mips_linux_nat): Use
	add_inf_child_target.
	* mips-nbsd-nat.c (_initialize_mipsnbsd_nat): Use
	add_inf_child_target.
	* mips64-obsd-nat.c (_initialize_mips64obsd_nat): Use
	add_inf_child_target.
	* nto-procfs.c (nto_native_target_info): New.
	(nto_procfs_target_native) <shortname, longname, doc>:
	Delete.
	<info>:	New.
	(nto_procfs_target_info): New.
	(nto_procfs_target_procfs) <shortname, longname, doc>:
	Delete.
	<info>:	New.
	(init_procfs_targets): Adjust.
	* ppc-fbsd-nat.c (_initialize_ppcfbsd_nat): Use
	add_inf_child_target.
	* ppc-linux-nat.c (_initialize_ppc_linux_nat): Use
	add_inf_child_target.
	* ppc-nbsd-nat.c (_initialize_ppcnbsd_nat): Use
	add_inf_child_target.
	* ppc-obsd-nat.c (_initialize_ppcobsd_nat): Use
	add_inf_child_target.
	* ravenscar-thread.c (ravenscar_target_info): New.
	(ravenscar_thread_target) <shortname, longname, doc>:
	Delete.
	<info>:	New.
	* record-btrace.c (record_btrace_target_info):
	(record_btrace_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(record_btrace_target::open): Rename to ...
	(record_btrace_target_open): ... this.  Adjust.
	* record-full.c (record_longname, record_doc): New.
	(record_full_base_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(record_full_target_info): New.
	(record_full_target): <shortname>: Delete.
	<info>: New.
	(record_full_core_open_1, record_full_open_1): Update comments.
	(record_full_base_target::open): Rename to ...
	(record_full_open): ... this.
	(cmd_record_full_restore): Update.
	(_initialize_record_full): Update.
	* remote-sim.c (remote_sim_target_info): New.
	(gdbsim_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(gdbsim_target::open): Rename to ...
	(gdbsim_target_open): ... this.
	(_initialize_remote_sim): Adjust.
	* remote.c (remote_doc): New.
	(remote_target_info): New.
	(remote_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(extended_remote_target_info): New.
	(extended_remote_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(remote_target::open_1): Make static.  Adjust.
	* rs6000-nat.c (_initialize_rs6000_nat): Use add_inf_child_target.
	* s390-linux-nat.c (_initialize_s390_nat): Use
	add_inf_child_target.
	* sh-nbsd-nat.c (_initialize_shnbsd_nat): Use
	add_inf_child_target.
	* sol-thread.c (thread_db_target_info): New.
	(sol_thread_target) <shortname, longname, doc>: Delete.
	<info>: New.
	* sparc-linux-nat.c (_initialize_sparc_linux_nat): Use
	add_inf_child_target.
	* sparc-nbsd-nat.c (_initialize_sparcnbsd_nat): Use
	add_inf_child_target.
	* sparc64-fbsd-nat.c (_initialize_sparc64fbsd_nat): Use
	add_inf_child_target.
	* sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use
	add_inf_child_target.
	* sparc64-nbsd-nat.c (_initialize_sparc64nbsd_nat): Use
	add_inf_child_target.
	* sparc64-obsd-nat.c (_initialize_sparc64obsd_nat): Use
	add_inf_child_target.
	* spu-linux-nat.c (_initialize_spu_nat): Use
	add_inf_child_target.
	* spu-multiarch.c (spu_multiarch_target_info): New.
	(spu_multiarch_target) <shortname, longname, doc>: Delete.
	<info>: New.
	* target-delegates.c: Regenerate.
	* target.c: Include <unordered_map>.
	(target_ops_p): Delete.
	(DEF_VEC_P(target_ops_p)): Delete.
	(target_factories): New.
	(test_target_info): New.
	(test_target_ops::info): New.
	(open_target): Adjust to use target_factories.
	(add_target_with_completer): Rename to ...
	(add_target): ... this.  Change prototype.  Register target_info
	and open callback in target_factories.  Register target_info in
	command context instead of target_ops.
	(add_target): Delete old implementation.
	(add_deprecated_target_alias): Change prototype.  Adjust.
	(the_native_target): New.
	(set_native_target, get_native_target): New.
	(find_default_run_target): Use the_native_target.
	(find_attach_target, find_run_target): Simplify.
	(target_ops::open): Delete.
	(dummy_target_info): New.
	(dummy_target::shortname, dummy_target::longname)
	(dummy_target::doc): Delete.
	(dummy_target::info): New.
	(debug_target::shortname, debug_target::longname)
	(debug_target::doc): Delete.
	(debug_target::info): New.
	* target.h (struct target_info): New.
	(target_ops::~target_ops): Add comment.
	(target_ops::info): New.
	(target_ops::shortname, target_ops::longname, target_ops::doc): No
	longer virtual.  Implement in terms of target_info.
	(set_native_target, get_native_target): Declare.
	(target_open_ftype): New.
	(add_target, add_target_with_completer)
	(add_deprecated_target_alias): Change prototype.
	(test_target) <shortname, longname, doc>: Delete.
	<info>: New.
	* tilegx-linux-nat.c (_initialize_tile_linux_nat): Use
	add_inf_child_target.
	* tracefile-tfile.c (tfile_target_info): New.
	(tfile_target) <shortname, longname, doc>: Delete.
	<info>: New.
	(tfile_target::open): Rename to ...
	(tfile_target_open): ... this.
	(_initialize_tracefile_tfile): Adjust.
	* vax-bsd-nat.c (_initialize_vaxbsd_nat): Use
	add_inf_child_target.
	* windows-nat.c (_initialize_windows_nat): Use
	add_inf_child_target.
	* xtensa-linux-nat.c (_initialize_xtensa_linux_nat): Use
	add_inf_child_target.
2018-05-03 00:53:12 +01:00
Pedro Alves 57810aa7e8 target_ops: Use bool throughout
After the previous target_ops/C++ patches are all squashed and merged,
this one can go in separately.

This patch adjusts all the target methods to return bool instead of int
when they're returning a boolean.

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

	* target.h (target_ops)
	<stopped_by_sw_breakpoint, supports_stopped_by_sw_breakpoint,
	stopped_by_hw_breakpoint, supports_stopped_by_hw_breakpoint,
	stopped_by_watchpoint, have_continuable_watchpoint,
	stopped_data_address, watchpoint_addr_within_range,
	can_accel_watchpoint_condition, can_run, thread_alive,
	has_all_memory, has_memory, has_stack, has_registers,
	has_execution, can_async_p, is_async_p, supports_non_stop,
	always_non_stop_p, can_execute_reverse, supports_multi_process,
	supports_enable_disable_tracepoint,
	supports_disable_randomization, supports_string_tracing,
	supports_evaluation_of_breakpoint_conditions,
	can_run_breakpoint_commands, filesystem_is_local,
	can_download_tracepoint, get_trace_state_variable_value,
	set_trace_notes, get_tib_address, use_agent, can_use_agent,
	record_is_replaying, record_will_replay,
	augmented_libraries_svr4_read>: Adjust to return bool.
	* aarch64-linux-nat.c: All implementations adjusted.
	* aix-thread.c: All implementations adjusted.
	* arm-linux-nat.c: All implementations adjusted.
	* breakpoint.c: All implementations adjusted.
	* bsd-kvm.c: All implementations adjusted.
	* bsd-uthread.c: All implementations adjusted.
	* corelow.c: All implementations adjusted.
	* ctf.c: All implementations adjusted.
	* darwin-nat.c: All implementations adjusted.
	* darwin-nat.h: All implementations adjusted.
	* exec.c: All implementations adjusted.
	* fbsd-nat.c: All implementations adjusted.
	* fbsd-nat.h: All implementations adjusted.
	* gnu-nat.c: All implementations adjusted.
	* gnu-nat.h: All implementations adjusted.
	* go32-nat.c: All implementations adjusted.
	* ia64-linux-nat.c: All implementations adjusted.
	* inf-child.c: All implementations adjusted.
	* inf-child.h: All implementations adjusted.
	* inf-ptrace.c: All implementations adjusted.
	* inf-ptrace.h: All implementations adjusted.
	* linux-nat.c: All implementations adjusted.
	* linux-nat.h: All implementations adjusted.
	* mips-linux-nat.c: All implementations adjusted.
	* nto-procfs.c: All implementations adjusted.
	* ppc-linux-nat.c: All implementations adjusted.
	* procfs.c: All implementations adjusted.
	* ravenscar-thread.c: All implementations adjusted.
	* record-btrace.c: All implementations adjusted.
	* record-full.c: All implementations adjusted.
	* remote-sim.c: All implementations adjusted.
	* remote.c: All implementations adjusted.
	* s390-linux-nat.c: All implementations adjusted.
	* sol-thread.c: All implementations adjusted.
	* spu-multiarch.c: All implementations adjusted.
	* target-delegates.c: All implementations adjusted.
	* target.c: All implementations adjusted.
	* target.h: All implementations adjusted.
	* tracefile-tfile.c: All implementations adjusted.
	* tracefile.c: All implementations adjusted.
	* tracefile.h: All implementations adjusted.
	* windows-nat.c: All implementations adjusted.
	* x86-linux-nat.h: All implementations adjusted.
	* x86-nat.h: All implementations adjusted.
2018-05-03 00:51:30 +01:00
Pedro Alves f6ac5f3d63 Convert struct target_ops to C++
I.e., use C++ virtual methods and inheritance instead of tables of
function pointers.

Unfortunately, there's no way to do a smooth transition.  ALL native
targets in the tree must be converted at the same time.  I've tested
all I could with cross compilers and with help from GCC compile farm,
but naturally I haven't been able to test many of the ports.  Still, I
made a best effort to port everything over, and while I expect some
build problems due to typos and such, which should be trivial to fix,
I don't expect any design problems.

* Implementation notes:

- The flattened current_target is gone.  References to current_target
  or current_target.beneath are replaced with references to
  target_stack (the top of the stack) directly.

- To keep "set debug target" working, this adds a new debug_stratum
  layer that sits on top of the stack, prints the debug, and delegates
  to the target beneath.

  In addition, this makes the shortname and longname properties of
  target_ops be virtual methods instead of data fields, and makes the
  debug target defer those to the target beneath.  This is so that
  debug code sprinkled around that does "if (debugtarget) ..."  can
  transparently print the name of the target beneath.

  A patch later in the series actually splits out the
  shortname/longname methods to a separate structure, but I preferred
  to keep that chance separate as it is associated with changing a bit
  the design of how targets are registered and open.

- Since you can't check whether a C++ virtual method is overridden,
  the old method of checking whether a target_ops implements a method
  by comparing the function pointer must be replaced with something
  else.

  Some cases are fixed by adding a parallel "can_do_foo" target_ops
  methods.  E.g.,:

    +  for (t = target_stack; t != NULL; t = t->beneath)
	 {
    -      if (t->to_create_inferior != NULL)
    +      if (t->can_create_inferior ())
	    break;
	 }

  Others are fixed by changing void return type to bool or int return
  type, and have the default implementation return false or -1, to
  indicate lack of support.

- make-target-delegates was adjusted to generate C++ classes and
  methods.

  It needed tweaks to grok "virtual" in front of the target method
  name, and for the fact that methods are no longer function pointers.
  (In particular, the current code parsing the return type was simple
  because it could simply parse up until the '(' in '(*to_foo)'.

  It now generates a couple C++ classes that inherit target_ops:
  dummy_target and debug_target.

  Since we need to generate the class declarations as well, i.e., we
  need to emit methods twice, we now generate the code in two passes.

- The core_target global is renamed to avoid conflict with the
  "core_target" class.

- ctf/tfile targets

  init_tracefile_ops is replaced by a base class that is inherited by
  both ctf and tfile.

- bsd-uthread

  The bsd_uthread_ops_hack hack is gone.  It's not needed because
  nothing was extending a target created by bsd_uthread_target.

- remote/extended-remote targets

  This is a first pass, just enough to C++ify target_ops.

  A later pass will convert more free functions to methods, and make
  remote_state be truly per remote instance, allowing multiple
  simultaneous instances of remote targets.

- inf-child/"native" is converted to an actual base class
  (inf_child_target), that is inherited by all native targets.

- GNU/Linux

  The old weird double-target linux_ops mechanism in linux-nat.c, is
  gone, replaced by adding a few virtual methods to linux-nat.h's
  target_ops, called low_XXX, that the concrete linux-nat
  implementations override.  Sort of like gdbserver's
  linux_target_ops, but simpler, for requiring only one
  target_ops-like hierarchy, which spares implementing the same method
  twice when we need to forward the method to a low implementation.
  The low target simply reimplements the target_ops method directly in
  that case.

  There are a few remaining linux-nat.c hooks that would be better
  converted to low_ methods like above too.  E.g.:

   linux_nat_set_new_thread (t, x86_linux_new_thread);
   linux_nat_set_new_fork (t, x86_linux_new_fork);
   linux_nat_set_forget_process

  That'll be done in a follow up patch.

- We can no longer use functions like x86_use_watchpoints to install
  custom methods on an arbitrary base target.

  The patch replaces instances of such a pattern with template mixins.
  For example memory_breakpoint_target defined in target.h, or
  x86_nat_target in x86-nat.h.

- linux_trad_target, MIPS and Alpha GNU/Linux

  The code in the new linux-nat-trad.h/c files which was split off of
  inf-ptrace.h/c recently, is converted to a C++ base class, and used
  by the MIPS and Alpha GNU/Linux ports.

- BSD targets

  The

    $architecture x NetBSD/OpenBSD/FreeBSD

  support matrix complicates things a bit.  There's common BSD target
  code, and there's common architecture-specific code shared between
  the different BSDs.  Currently, all that is stiched together to form
  a final target, via the i386bsd_target, x86bsd_target,
  fbsd_nat_add_target functions etc.

  This introduces new fbsd_nat_target, obsd_nat_target and
  nbsd_nat_target classes that serve as base/prototype target for the
  corresponding BSD variant.

  And introduces generic i386/AMD64 BSD targets, to be used as
  template mixin to build a final target.  Similarly, a generic SPARC
  target is added, used by both BSD and Linux ports.

- bsd_kvm_add_target, BSD libkvm target

  I considered making bsd_kvm_supply_pcb a virtual method, and then
  have each port inherit bsd_kvm_target and override that method, but
  that was resulting in lots of unjustified churn, so I left the
  function pointer mechanism alone.

gdb/ChangeLog:
2018-05-02  Pedro Alves  <palves@redhat.com>
	    John Baldwin  <jhb@freebsd.org>

	* target.h (enum strata) <debug_stratum>: New.
	(struct target_ops) <all delegation methods>: Replace by C++
	virtual methods, and drop "to_" prefix.  All references updated
	throughout.
	<to_shortname, to_longname, to_doc, to_data,
	to_have_steppable_watchpoint, to_have_continuable_watchpoint,
	to_has_thread_control, to_attach_no_wait>: Delete, replaced by
	virtual methods.  All references updated throughout.
	<can_attach, supports_terminal_ours, can_create_inferior,
	get_thread_control_capabilities, attach_no_wait>: New
	virtual methods.
	<insert_breakpoint, remove_breakpoint>: Now
	TARGET_DEFAULT_NORETURN methods.
	<info_proc>: Now returns bool.
	<to_magic>: Delete.
	(OPS_MAGIC): Delete.
	(current_target): Delete.  All references replaced by references
	to ...
	(target_stack): ... this.  New.
	(target_shortname, target_longname): Adjust.
	(target_can_run): Now a function declaration.
	(default_child_has_all_memory, default_child_has_memory)
	(default_child_has_stack, default_child_has_registers)
	(default_child_has_execution): Remove target_ops parameter.
	(complete_target_initialization): Delete.
	(memory_breakpoint_target): New template class.
	(test_target_ops): Refactor as a C++ class with virtual methods.
	* make-target-delegates (NAME_PART): Tighten.
	(POINTER_PART, CP_SYMBOL): New.
	(SIMPLE_RETURN_PART): Reimplement.
	(VEC_RETURN_PART): Expect less.
	(RETURN_PART, VIRTUAL_PART): New.
	(METHOD): Adjust to C++ virtual methods.
	(scan_target_h): Remove reference to C99.
	(dname): Output "target_ops::" prefix.
	(write_function_header): Adjust to output a C++ class method.
	(write_declaration): New.
	(write_delegator): Adjust to output a C++ class method.
	(tdname): Output "dummy_target::" prefix.
	(write_tdefault, write_debugmethod): Adjust to output a C++ class
	method.
	(tdefault_names, debug_names): Delete.
	(return_types, tdefaults, styles, argtypes_array): New.
	(top level): All methods are delegators.
	(print_class): New.
	(top level): Print dummy_target and debug_target classes.
	* target-delegates.c: Regenerate.
	* target-debug.h (target_debug_print_enum_info_proc_what)
	(target_debug_print_thread_control_capabilities)
	(target_debug_print_thread_info_p): New.
	* target.c (dummy_target): Delete.
	(the_dummy_target, the_debug_target): New.
	(target_stack): Now extern.
	(set_targetdebug): Push/unpush debug target.
	(default_child_has_all_memory, default_child_has_memory)
	(default_child_has_stack, default_child_has_registers)
	(default_child_has_execution): Remove target_ops parameter.
	(complete_target_initialization): Delete.
	(add_target_with_completer): No longer call
	complete_target_initialization.
	(target_supports_terminal_ours): Use regular delegation.
	(update_current_target): Delete.
	(push_target): No longer check magic number.  Don't call
	update_current_target.
	(unpush_target): Don't call update_current_target.
	(target_is_pushed): No longer check magic number.
	(target_require_runnable): Skip for all stratums over
	process_stratum.
	(target_ops::info_proc): New.
	(target_info_proc): Use find_target_at and
	find_default_run_target.
	(target_supports_disable_randomization): Use regular delegation.
	(target_get_osdata): Use find_target_at.
	(target_ops::open, target_ops::close, target_ops::can_attach)
	(target_ops::attach, target_ops::can_create_inferior)
	(target_ops::create_inferior, target_ops::can_run)
	(target_can_run): New.
	(default_fileio_target): Use regular delegation.
	(target_ops::fileio_open, target_ops::fileio_pwrite)
	(target_ops::fileio_pread, target_ops::fileio_fstat)
	(target_ops::fileio_close, target_ops::fileio_unlink)
	(target_ops::fileio_readlink): New.
	(target_fileio_open_1, target_fileio_unlink)
	(target_fileio_readlink): Always call the target method.  Handle
	FILEIO_ENOSYS.
	(return_zero, return_zero_has_execution): Delete.
	(init_dummy_target): Delete.
	(dummy_target::dummy_target, dummy_target::shortname)
	(dummy_target::longname, dummy_target::doc)
	(debug_target::debug_target, debug_target::shortname)
	(debug_target::longname, debug_target::doc): New.
	(target_supports_delete_record): Use regular delegation.
	(setup_target_debug): Delete.
	(maintenance_print_target_stack): Skip debug_stratum.
	(initialize_targets): Instantiate the_dummy_target and
	the_debug_target.
	* auxv.c (target_auxv_parse): Remove 'ops' parameter.  Adjust to
	use target_stack.
	(target_auxv_search, fprint_target_auxv): Adjust.
	(info_auxv_command): Adjust to use target_stack.
	* auxv.h (target_auxv_parse): Remove 'ops' parameter.
	* exceptions.c (print_flush): Handle a NULL target_stack.
	* regcache.c (target_ops_no_register): Refactor as class with
	virtual methods.

	* exec.c (exec_target): New class.
	(exec_ops): Now an exec_target.
	(exec_open, exec_close_1, exec_get_section_table)
	(exec_xfer_partial, exec_files_info, exec_has_memory)
	(exec_make_note_section): Refactor as exec_target methods.
	(exec_file_clear, ignore, exec_remove_breakpoint, init_exec_ops):
	Delete.
	(exec_target::find_memory_regions): New.
	(_initialize_exec): Don't call init_exec_ops.
	* gdbcore.h (exec_file_clear): Delete.

	* corefile.c (core_target): Delete.
	(core_file_command): Adjust.
	* corelow.c (core_target): New class.
	(the_core_target): New.
	(core_close): Remove target_ops parameter.
	(core_close_cleanup): Adjust.
	(core_target::close): New.
	(core_open, core_detach, get_core_registers, core_files_info)
	(core_xfer_partial, core_thread_alive, core_read_description)
	(core_pid_to_str, core_thread_name, core_has_memory)
	(core_has_stack, core_has_registers, core_info_proc): Rework as
	core_target methods.
	(ignore, core_remove_breakpoint, init_core_ops): Delete.
	(_initialize_corelow): Initialize the_core_target.
	* gdbcore.h (core_target): Delete.
	(the_core_target): New.

	* ctf.c: (ctf_target): New class.
	(ctf_ops): Now a ctf_target.
	(ctf_open, ctf_close, ctf_files_info, ctf_fetch_registers)
	(ctf_xfer_partial, ctf_get_trace_state_variable_value)
	(ctf_trace_find, ctf_traceframe_info): Refactor as ctf_target
	methods.
	(init_ctf_ops): Delete.
	(_initialize_ctf): Don't call it.
	* tracefile-tfile.c (tfile_target): New class.
	(tfile_ops): Now a tfile_target.
	(tfile_open, tfile_close, tfile_files_info)
	(tfile_get_tracepoint_status, tfile_trace_find)
	(tfile_fetch_registers, tfile_xfer_partial)
	(tfile_get_trace_state_variable_value, tfile_traceframe_info):
	Refactor as tfile_target methods.
	(tfile_xfer_partial_features): Remove target_ops parameter.
	(init_tfile_ops): Delete.
	(_initialize_tracefile_tfile): Don't call it.
	* tracefile.c (tracefile_has_all_memory, tracefile_has_memory)
	(tracefile_has_stack, tracefile_has_registers)
	(tracefile_thread_alive, tracefile_get_trace_status): Refactor as
	tracefile_target methods.
	(init_tracefile_ops): Delete.
	(tracefile_target::tracefile_target): New.
	* tracefile.h: Include "target.h".
	(tracefile_target): New class.
	(init_tracefile_ops): Delete.

	* spu-multiarch.c (spu_multiarch_target): New class.
	(spu_ops): Now a spu_multiarch_target.
	(spu_thread_architecture, spu_region_ok_for_hw_watchpoint)
	(spu_fetch_registers, spu_store_registers, spu_xfer_partial)
	(spu_search_memory, spu_mourn_inferior): Refactor as
	spu_multiarch_target methods.
	(init_spu_ops): Delete.
	(_initialize_spu_multiarch): Remove references to init_spu_ops,
	complete_target_initialization.

	* ravenscar-thread.c (ravenscar_thread_target): New class.
	(ravenscar_ops): Now a ravenscar_thread_target.
	(ravenscar_resume, ravenscar_wait, ravenscar_update_thread_list)
	(ravenscar_thread_alive, ravenscar_pid_to_str)
	(ravenscar_fetch_registers, ravenscar_store_registers)
	(ravenscar_prepare_to_store, ravenscar_stopped_by_sw_breakpoint)
	(ravenscar_stopped_by_hw_breakpoint)
	(ravenscar_stopped_by_watchpoint, ravenscar_stopped_data_address)
	(ravenscar_mourn_inferior, ravenscar_core_of_thread)
	(ravenscar_get_ada_task_ptid): Refactor as ravenscar_thread_target
	methods.
	(init_ravenscar_thread_ops): Delete.
	(_initialize_ravenscar): Remove references to
	init_ravenscar_thread_ops and complete_target_initialization.

	* bsd-uthread.c (bsd_uthread_ops_hack): Delete.
	(bsd_uthread_target): New class.
	(bsd_uthread_ops): Now a bsd_uthread_target.
	(bsd_uthread_activate): Adjust to refer to bsd_uthread_ops.
	(bsd_uthread_close, bsd_uthread_mourn_inferior)
	(bsd_uthread_fetch_registers, bsd_uthread_store_registers)
	(bsd_uthread_wait, bsd_uthread_resume, bsd_uthread_thread_alive)
	(bsd_uthread_update_thread_list, bsd_uthread_extra_thread_info)
	(bsd_uthread_pid_to_str): Refactor as bsd_uthread_target methods.
	(bsd_uthread_target): Delete function.
	(_initialize_bsd_uthread): Remove reference to
	complete_target_initialization.

	* bfd-target.c (target_bfd_data): Delete.  Fields folded into ...
	(target_bfd): ... this new class.
	(target_bfd_xfer_partial, target_bfd_get_section_table)
	(target_bfd_close): Refactor as target_bfd methods.
	(target_bfd::~target_bfd): New.
	(target_bfd_reopen): Adjust.
	(target_bfd::close): New.

	* record-btrace.c (record_btrace_target): New class.
	(record_btrace_ops): Now a record_btrace_target.
	(record_btrace_open, record_btrace_stop_recording)
	(record_btrace_disconnect, record_btrace_close)
	(record_btrace_async, record_btrace_info)
	(record_btrace_insn_history, record_btrace_insn_history_range)
	(record_btrace_insn_history_from, record_btrace_call_history)
	(record_btrace_call_history_range)
	(record_btrace_call_history_from, record_btrace_record_method)
	(record_btrace_is_replaying, record_btrace_will_replay)
	(record_btrace_xfer_partial, record_btrace_insert_breakpoint)
	(record_btrace_remove_breakpoint, record_btrace_fetch_registers)
	(record_btrace_store_registers, record_btrace_prepare_to_store)
	(record_btrace_to_get_unwinder)
	(record_btrace_to_get_tailcall_unwinder, record_btrace_resume)
	(record_btrace_commit_resume, record_btrace_wait)
	(record_btrace_stop, record_btrace_can_execute_reverse)
	(record_btrace_stopped_by_sw_breakpoint)
	(record_btrace_supports_stopped_by_sw_breakpoint)
	(record_btrace_stopped_by_hw_breakpoint)
	(record_btrace_supports_stopped_by_hw_breakpoint)
	(record_btrace_update_thread_list, record_btrace_thread_alive)
	(record_btrace_goto_begin, record_btrace_goto_end)
	(record_btrace_goto, record_btrace_stop_replaying_all)
	(record_btrace_execution_direction)
	(record_btrace_prepare_to_generate_core)
	(record_btrace_done_generating_core): Refactor as
	record_btrace_target methods.
	(init_record_btrace_ops): Delete.
	(_initialize_record_btrace): Remove reference to
	init_record_btrace_ops.
	* record-full.c (RECORD_FULL_IS_REPLAY): Adjust to always refer to
	the execution_direction global.
	(record_full_base_target, record_full_target)
	(record_full_core_target): New classes.
	(record_full_ops): Now a record_full_target.
	(record_full_core_ops): Now a record_full_core_target.
	(record_full_target::detach, record_full_target::disconnect)
	(record_full_core_target::disconnect)
	(record_full_target::mourn_inferior, record_full_target::kill):
	New.
	(record_full_open, record_full_close, record_full_async): Refactor
	as methods of the record_full_base_target class.
	(record_full_resume, record_full_commit_resume): Refactor
	as methods of the record_full_target class.
	(record_full_wait, record_full_stopped_by_watchpoint)
	(record_full_stopped_data_address)
	(record_full_stopped_by_sw_breakpoint)
	(record_full_supports_stopped_by_sw_breakpoint)
	(record_full_stopped_by_hw_breakpoint)
	(record_full_supports_stopped_by_hw_breakpoint): Refactor as
	methods of the record_full_base_target class.
	(record_full_store_registers, record_full_xfer_partial)
	(record_full_insert_breakpoint, record_full_remove_breakpoint):
	Refactor as methods of the record_full_target class.
	(record_full_can_execute_reverse, record_full_get_bookmark)
	(record_full_goto_bookmark, record_full_execution_direction)
	(record_full_record_method, record_full_info, record_full_delete)
	(record_full_is_replaying, record_full_will_replay)
	(record_full_goto_begin, record_full_goto_end, record_full_goto)
	(record_full_stop_replaying): Refactor as methods of the
	record_full_base_target class.
	(record_full_core_resume, record_full_core_kill)
	(record_full_core_fetch_registers)
	(record_full_core_prepare_to_store)
	(record_full_core_store_registers, record_full_core_xfer_partial)
	(record_full_core_insert_breakpoint)
	(record_full_core_remove_breakpoint)
	(record_full_core_has_execution): Refactor
	as methods of the record_full_core_target class.
	(record_full_base_target::supports_delete_record): New.
	(init_record_full_ops): Delete.
	(init_record_full_core_ops): Delete.
	(record_full_save): Refactor as method of the
	record_full_base_target class.
	(_initialize_record_full): Remove references to
	init_record_full_ops and init_record_full_core_ops.

	* remote.c (remote_target, extended_remote_target): New classes.
	(remote_ops): Now a remote_target.
	(extended_remote_ops): Now an extended_remote_target.
	(remote_insert_fork_catchpoint, remote_remove_fork_catchpoint)
	(remote_insert_vfork_catchpoint, remote_remove_vfork_catchpoint)
	(remote_insert_exec_catchpoint, remote_remove_exec_catchpoint)
	(remote_pass_signals, remote_set_syscall_catchpoint)
	(remote_program_signals, )
	(remote_thread_always_alive): Remove target_ops parameter.
	(remote_thread_alive, remote_thread_name)
	(remote_update_thread_list, remote_threads_extra_info)
	(remote_static_tracepoint_marker_at)
	(remote_static_tracepoint_markers_by_strid)
	(remote_get_ada_task_ptid, remote_close, remote_start_remote)
	(remote_open): Refactor as methods of remote_target.
	(extended_remote_open, extended_remote_detach)
	(extended_remote_attach, extended_remote_post_attach):
	(extended_remote_supports_disable_randomization)
	(extended_remote_create_inferior): : Refactor as method of
	extended_remote_target.
	(remote_set_permissions, remote_open_1, remote_detach)
	(remote_follow_fork, remote_follow_exec, remote_disconnect)
	(remote_resume, remote_commit_resume, remote_stop)
	(remote_interrupt, remote_pass_ctrlc, remote_terminal_inferior)
	(remote_terminal_ours, remote_wait, remote_fetch_registers)
	(remote_prepare_to_store, remote_store_registers)
	(remote_flash_erase, remote_flash_done, remote_files_info)
	(remote_kill, remote_mourn, remote_insert_breakpoint)
	(remote_remove_breakpoint, remote_insert_watchpoint)
	(remote_watchpoint_addr_within_range)
	(remote_remove_watchpoint, remote_region_ok_for_hw_watchpoint)
	(remote_check_watch_resources, remote_stopped_by_sw_breakpoint)
	(remote_supports_stopped_by_sw_breakpoint)
	(remote_stopped_by_hw_breakpoint)
	(remote_supports_stopped_by_hw_breakpoint)
	(remote_stopped_by_watchpoint, remote_stopped_data_address)
	(remote_insert_hw_breakpoint, remote_remove_hw_breakpoint)
	(remote_verify_memory): Refactor as methods of remote_target.
	(remote_write_qxfer, remote_read_qxfer): Remove target_ops
	parameter.
	(remote_xfer_partial, remote_get_memory_xfer_limit)
	(remote_search_memory, remote_rcmd, remote_memory_map)
	(remote_pid_to_str, remote_get_thread_local_address)
	(remote_get_tib_address, remote_read_description): Refactor as
	methods of remote_target.
	(remote_target::fileio_open, remote_target::fileio_pwrite)
	(remote_target::fileio_pread, remote_target::fileio_close): New.
	(remote_hostio_readlink, remote_hostio_fstat)
	(remote_filesystem_is_local, remote_can_execute_reverse)
	(remote_supports_non_stop, remote_supports_disable_randomization)
	(remote_supports_multi_process, remote_supports_cond_breakpoints)
	(remote_supports_enable_disable_tracepoint)
	(remote_supports_string_tracing)
	(remote_can_run_breakpoint_commands, remote_trace_init)
	(remote_download_tracepoint, remote_can_download_tracepoint)
	(remote_download_trace_state_variable, remote_enable_tracepoint)
	(remote_disable_tracepoint, remote_trace_set_readonly_regions)
	(remote_trace_start, remote_get_trace_status)
	(remote_get_tracepoint_status, remote_trace_stop)
	(remote_trace_find, remote_get_trace_state_variable_value)
	(remote_save_trace_data, remote_get_raw_trace_data)
	(remote_set_disconnected_tracing, remote_core_of_thread)
	(remote_set_circular_trace_buffer, remote_traceframe_info)
	(remote_get_min_fast_tracepoint_insn_len)
	(remote_set_trace_buffer_size, remote_set_trace_notes)
	(remote_use_agent, remote_can_use_agent, remote_enable_btrace)
	(remote_disable_btrace, remote_teardown_btrace)
	(remote_read_btrace, remote_btrace_conf)
	(remote_augmented_libraries_svr4_read, remote_load)
	(remote_pid_to_exec_file, remote_can_do_single_step)
	(remote_execution_direction, remote_thread_handle_to_thread_info):
	Refactor as methods of remote_target.
	(init_remote_ops, init_extended_remote_ops): Delete.
	(remote_can_async_p, remote_is_async_p, remote_async)
	(remote_thread_events, remote_upload_tracepoints)
	(remote_upload_trace_state_variables): Refactor as methods of
	remote_target.
	(_initialize_remote): Remove references to init_remote_ops and
	init_extended_remote_ops.

	* remote-sim.c (gdbsim_target): New class.
	(gdbsim_fetch_register, gdbsim_store_register, gdbsim_kill)
	(gdbsim_load, gdbsim_create_inferior, gdbsim_open, gdbsim_close)
	(gdbsim_detach, gdbsim_resume, gdbsim_interrupt)
	(gdbsim_wait, gdbsim_prepare_to_store, gdbsim_xfer_partial)
	(gdbsim_files_info, gdbsim_mourn_inferior, gdbsim_thread_alive)
	(gdbsim_pid_to_str, gdbsim_has_all_memory, gdbsim_has_memory):
	Refactor as methods of gdbsim_target.
	(gdbsim_ops): Now a gdbsim_target.
	(init_gdbsim_ops): Delete.
	(gdbsim_cntrl_c): Adjust.
	(_initialize_remote_sim): Remove reference to init_gdbsim_ops.

	* amd64-linux-nat.c (amd64_linux_nat_target): New class.
	(the_amd64_linux_nat_target): New.
	(amd64_linux_fetch_inferior_registers)
	(amd64_linux_store_inferior_registers): Refactor as methods of
	amd64_linux_nat_target.
	(_initialize_amd64_linux_nat): Adjust.  Set linux_target.
	* i386-linux-nat.c: Don't include "linux-nat.h".
	(i386_linux_nat_target): New class.
	(the_i386_linux_nat_target): New.
	(i386_linux_fetch_inferior_registers)
	(i386_linux_store_inferior_registers, i386_linux_resume): Refactor
	as methods of i386_linux_nat_target.
	(_initialize_i386_linux_nat): Adjust.  Set linux_target.
	* inf-child.c (inf_child_ops): Delete.
	(inf_child_fetch_inferior_registers)
	(inf_child_store_inferior_registers): Delete.
	(inf_child_post_attach, inf_child_prepare_to_store): Refactor as
	methods of inf_child_target.
	(inf_child_target::supports_terminal_ours)
	(inf_child_target::terminal_init)
	(inf_child_target::terminal_inferior)
	(inf_child_target::terminal_ours_for_output)
	(inf_child_target::terminal_ours, inf_child_target::interrupt)
	(inf_child_target::pass_ctrlc, inf_child_target::terminal_info):
	New.
	(inf_child_open, inf_child_disconnect, inf_child_close)
	(inf_child_mourn_inferior, inf_child_maybe_unpush_target)
	(inf_child_post_startup_inferior, inf_child_can_run)
	(inf_child_pid_to_exec_file): Refactor as methods of
	inf_child_target.
	(inf_child_follow_fork): Delete.
	(inf_child_target::can_create_inferior)
	(inf_child_target::can_attach): New.
	(inf_child_target::has_all_memory, inf_child_target::has_memory)
	(inf_child_target::has_stack, inf_child_target::has_registers)
	(inf_child_target::has_execution): New.
	(inf_child_fileio_open, inf_child_fileio_pwrite)
	(inf_child_fileio_pread, inf_child_fileio_fstat)
	(inf_child_fileio_close, inf_child_fileio_unlink)
	(inf_child_fileio_readlink, inf_child_use_agent)
	(inf_child_can_use_agent): Refactor as methods of
	inf_child_target.
	(return_zero, inf_child_target): Delete.
	(inf_child_target::inf_child_target): New.
	* inf-child.h: Include "target.h".
	(inf_child_target): Delete function prototype.
	(inf_child_target): New class.
	(inf_child_open_target, inf_child_mourn_inferior)
	(inf_child_maybe_unpush_target): Delete.
	* inf-ptrace.c (inf_ptrace_target::~inf_ptrace_target): New.
	(inf_ptrace_follow_fork, inf_ptrace_insert_fork_catchpoint)
	(inf_ptrace_remove_fork_catchpoint, inf_ptrace_create_inferior)
	(inf_ptrace_post_startup_inferior, inf_ptrace_mourn_inferior)
	(inf_ptrace_attach, inf_ptrace_post_attach, inf_ptrace_detach)
	(inf_ptrace_detach_success, inf_ptrace_kill, inf_ptrace_resume)
	(inf_ptrace_wait, inf_ptrace_xfer_partial)
	(inf_ptrace_thread_alive, inf_ptrace_files_info)
	(inf_ptrace_pid_to_str, inf_ptrace_auxv_parse): Refactor as
	methods of inf_ptrace_target.
	(inf_ptrace_target): Delete function.
	* inf-ptrace.h: Include "inf-child.h".
	(inf_ptrace_target): Delete function declaration.
	(inf_ptrace_target): New class.
	(inf_ptrace_trad_target, inf_ptrace_detach_success): Delete.
	* linux-nat.c (linux_target): New.
	(linux_ops, linux_ops_saved, super_xfer_partial): Delete.
	(linux_nat_target::~linux_nat_target): New.
	(linux_child_post_attach, linux_child_post_startup_inferior)
	(linux_child_follow_fork, linux_child_insert_fork_catchpoint)
	(linux_child_remove_fork_catchpoint)
	(linux_child_insert_vfork_catchpoint)
	(linux_child_remove_vfork_catchpoint)
	(linux_child_insert_exec_catchpoint)
	(linux_child_remove_exec_catchpoint)
	(linux_child_set_syscall_catchpoint, linux_nat_pass_signals)
	(linux_nat_create_inferior, linux_nat_attach, linux_nat_detach)
	(linux_nat_resume, linux_nat_stopped_by_watchpoint)
	(linux_nat_stopped_data_address)
	(linux_nat_stopped_by_sw_breakpoint)
	(linux_nat_supports_stopped_by_sw_breakpoint)
	(linux_nat_stopped_by_hw_breakpoint)
	(linux_nat_supports_stopped_by_hw_breakpoint, linux_nat_wait)
	(linux_nat_kill, linux_nat_mourn_inferior)
	(linux_nat_xfer_partial, linux_nat_thread_alive)
	(linux_nat_update_thread_list, linux_nat_pid_to_str)
	(linux_nat_thread_name, linux_child_pid_to_exec_file)
	(linux_child_static_tracepoint_markers_by_strid)
	(linux_nat_is_async_p, linux_nat_can_async_p)
	(linux_nat_supports_non_stop, linux_nat_always_non_stop_p)
	(linux_nat_supports_multi_process)
	(linux_nat_supports_disable_randomization, linux_nat_async)
	(linux_nat_stop, linux_nat_close, linux_nat_thread_address_space)
	(linux_nat_core_of_thread, linux_nat_filesystem_is_local)
	(linux_nat_fileio_open, linux_nat_fileio_readlink)
	(linux_nat_fileio_unlink, linux_nat_thread_events): Refactor as
	methods of linux_nat_target.
	(linux_nat_wait_1, linux_xfer_siginfo, linux_proc_xfer_partial)
	(linux_proc_xfer_spu, linux_nat_xfer_osdata): Remove target_ops
	parameter.
	(check_stopped_by_watchpoint): Adjust.
	(linux_xfer_partial): Delete.
	(linux_target_install_ops, linux_target, linux_nat_add_target):
	Delete.
	(linux_nat_target::linux_nat_target): New.
	* linux-nat.h: Include "inf-ptrace.h".
	(linux_nat_target): New.
	(linux_target, linux_target_install_ops, linux_nat_add_target):
	Delete function declarations.
	(linux_target): Declare global.
	* linux-thread-db.c (thread_db_target): New.
	(thread_db_target::thread_db_target): New.
	(thread_db_ops): Delete.
	(the_thread_db_target): New.
	(thread_db_detach, thread_db_wait, thread_db_mourn_inferior)
	(thread_db_update_thread_list, thread_db_pid_to_str)
	(thread_db_extra_thread_info)
	(thread_db_thread_handle_to_thread_info)
	(thread_db_get_thread_local_address, thread_db_get_ada_task_ptid)
	(thread_db_resume): Refactor as methods of thread_db_target.
	(init_thread_db_ops): Delete.
	(_initialize_thread_db): Remove reference to init_thread_db_ops.
	* x86-linux-nat.c: Don't include "linux-nat.h".
	(super_post_startup_inferior): Delete.
	(x86_linux_nat_target::~x86_linux_nat_target): New.
	(x86_linux_child_post_startup_inferior)
	(x86_linux_read_description, x86_linux_enable_btrace)
	(x86_linux_disable_btrace, x86_linux_teardown_btrace)
	(x86_linux_read_btrace, x86_linux_btrace_conf): Refactor as
	methods of x86_linux_nat_target.
	(x86_linux_create_target): Delete.  Bits folded ...
	(x86_linux_add_target): ... here.  Now takes a linux_nat_target
	pointer.
	* x86-linux-nat.h: Include "linux-nat.h" and "x86-nat.h".
	(x86_linux_nat_target): New class.
	(x86_linux_create_target): Delete.
	(x86_linux_add_target): Now takes a linux_nat_target pointer.
	* x86-nat.c (x86_insert_watchpoint, x86_remove_watchpoint)
	(x86_region_ok_for_watchpoint, x86_stopped_data_address)
	(x86_stopped_by_watchpoint, x86_insert_hw_breakpoint)
	(x86_remove_hw_breakpoint, x86_can_use_hw_breakpoint)
	(x86_stopped_by_hw_breakpoint): Remove target_ops parameter and
	make extern.
	(x86_use_watchpoints): Delete.
	* x86-nat.h: Include "breakpoint.h" and "target.h".
	(x86_use_watchpoints): Delete.
	(x86_can_use_hw_breakpoint, x86_region_ok_for_hw_watchpoint)
	(x86_stopped_by_watchpoint, x86_stopped_data_address)
	(x86_insert_watchpoint, x86_remove_watchpoint)
	(x86_insert_hw_breakpoint, x86_remove_hw_breakpoint)
	(x86_stopped_by_hw_breakpoint): New declarations.
	(x86_nat_target): New template class.

	* ppc-linux-nat.c (ppc_linux_nat_target): New class.
	(the_ppc_linux_nat_target): New.
	(ppc_linux_fetch_inferior_registers)
	(ppc_linux_can_use_hw_breakpoint)
	(ppc_linux_region_ok_for_hw_watchpoint)
	(ppc_linux_ranged_break_num_registers)
	(ppc_linux_insert_hw_breakpoint, ppc_linux_remove_hw_breakpoint)
	(ppc_linux_insert_mask_watchpoint)
	(ppc_linux_remove_mask_watchpoint)
	(ppc_linux_can_accel_watchpoint_condition)
	(ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint)
	(ppc_linux_stopped_data_address, ppc_linux_stopped_by_watchpoint)
	(ppc_linux_watchpoint_addr_within_range)
	(ppc_linux_masked_watch_num_registers)
	(ppc_linux_store_inferior_registers, ppc_linux_auxv_parse)
	(ppc_linux_read_description): Refactor as methods of
	ppc_linux_nat_target.
	(_initialize_ppc_linux_nat): Adjust.  Set linux_target.

	* procfs.c (procfs_xfer_partial): Delete forward declaration.
	(procfs_target): New class.
	(the_procfs_target): New.
	(procfs_target): Delete function.
	(procfs_auxv_parse, procfs_attach, procfs_detach)
	(procfs_fetch_registers, procfs_store_registers, procfs_wait)
	(procfs_xfer_partial, procfs_resume, procfs_pass_signals)
	(procfs_files_info, procfs_kill_inferior, procfs_mourn_inferior)
	(procfs_create_inferior, procfs_update_thread_list)
	(procfs_thread_alive, procfs_pid_to_str)
	(procfs_can_use_hw_breakpoint, procfs_stopped_by_watchpoint)
	(procfs_stopped_data_address, procfs_insert_watchpoint)
	(procfs_remove_watchpoint, procfs_region_ok_for_hw_watchpoint)
	(proc_find_memory_regions, procfs_info_proc)
	(procfs_make_note_section): Refactor as methods of procfs_target.
	(_initialize_procfs): Adjust.
	* sol-thread.c (sol_thread_target): New class.
	(sol_thread_ops): Now a sol_thread_target.
	(sol_thread_detach, sol_thread_resume, sol_thread_wait)
	(sol_thread_fetch_registers, sol_thread_store_registers)
	(sol_thread_xfer_partial, sol_thread_mourn_inferior)
	(sol_thread_alive, solaris_pid_to_str, sol_update_thread_list)
	(sol_get_ada_task_ptid): Refactor as methods of sol_thread_target.
	(init_sol_thread_ops): Delete.
	(_initialize_sol_thread): Adjust.  Remove references to
	init_sol_thread_ops and complete_target_initialization.

	* windows-nat.c (windows_nat_target): New class.
	(windows_fetch_inferior_registers)
	(windows_store_inferior_registers, windows_resume, windows_wait)
	(windows_attach, windows_detach, windows_pid_to_exec_file)
	(windows_files_info, windows_create_inferior)
	(windows_mourn_inferior, windows_interrupt, windows_kill_inferior)
	(windows_close, windows_pid_to_str, windows_xfer_partial)
	(windows_get_tib_address, windows_get_ada_task_ptid)
	(windows_thread_name, windows_thread_alive): Refactor as
	windows_nat_target methods.
	(do_initial_windows_stuff): Adjust.
	(windows_target): Delete function.
	(_initialize_windows_nat): Adjust.

	* darwin-nat.c (darwin_resume, darwin_wait_to, darwin_interrupt)
	(darwin_mourn_inferior, darwin_kill_inferior)
	(darwin_create_inferior, darwin_attach, darwin_detach)
	(darwin_pid_to_str, darwin_thread_alive, darwin_xfer_partial)
	(darwin_pid_to_exec_file, darwin_get_ada_task_ptid)
	(darwin_supports_multi_process): Refactor as darwin_nat_target
	methods.
	(darwin_resume_to, darwin_files_info): Delete.
	(_initialize_darwin_inferior): Rename to ...
	(_initialize_darwin_nat): ... this.  Adjust to C++ification.
	* darwin-nat.h: Include "inf-child.h".
	(darwin_nat_target): New class.
	(darwin_complete_target): Delete.
	* i386-darwin-nat.c (i386_darwin_nat_target): New class.
	(darwin_target): New.
	(i386_darwin_fetch_inferior_registers)
	(i386_darwin_store_inferior_registers): Refactor as methods of
	darwin_nat_target.
	(darwin_complete_target): Delete, with ...
	(_initialize_i386_darwin_nat): ... bits factored out here.

	* alpha-linux-nat.c (alpha_linux_nat_target): New class.
	(the_alpha_linux_nat_target): New.
	(alpha_linux_register_u_offset): Refactor as
	alpha_linux_nat_target method.
	(_initialize_alpha_linux_nat): Adjust.
	* linux-nat-trad.c (inf_ptrace_register_u_offset): Delete.
	(inf_ptrace_fetch_register, inf_ptrace_fetch_registers)
	(inf_ptrace_store_register, inf_ptrace_store_registers): Refact as
	methods of linux_nat_trad_target.
	(linux_trad_target): Delete.
	* linux-nat-trad.h (linux_trad_target): Delete function.
	(linux_nat_trad_target): New class.
	* mips-linux-nat.c (mips_linux_nat_target): New class.
	(super_fetch_registers, super_store_registers, super_close):
	Delete.
	(the_mips_linux_nat_target): New.
	(mips64_linux_regsets_fetch_registers)
	(mips64_linux_regsets_store_registers)
	(mips64_linux_fetch_registers, mips64_linux_store_registers)
	(mips_linux_register_u_offset, mips_linux_read_description)
	(mips_linux_can_use_hw_breakpoint)
	(mips_linux_stopped_by_watchpoint)
	(mips_linux_stopped_data_address)
	(mips_linux_region_ok_for_hw_watchpoint)
	(mips_linux_insert_watchpoint, mips_linux_remove_watchpoint)
	(mips_linux_close): Refactor as methods of mips_linux_nat.
	(_initialize_mips_linux_nat): Adjust to C++ification.

	* aix-thread.c (aix_thread_target): New class.
	(aix_thread_ops): Now an aix_thread_target.
	(aix_thread_detach, aix_thread_resume, aix_thread_wait)
	(aix_thread_fetch_registers, aix_thread_store_registers)
	(aix_thread_xfer_partial, aix_thread_mourn_inferior)
	(aix_thread_thread_alive, aix_thread_pid_to_str)
	(aix_thread_extra_thread_info, aix_thread_get_ada_task_ptid):
	Refactor as methods of aix_thread_target.
	(init_aix_thread_ops): Delete.
	(_initialize_aix_thread): Remove references to init_aix_thread_ops
	and complete_target_initialization.
	* rs6000-nat.c (rs6000_xfer_shared_libraries): Delete.
	(rs6000_nat_target): New class.
	(the_rs6000_nat_target): New.
	(rs6000_fetch_inferior_registers, rs6000_store_inferior_registers)
	(rs6000_xfer_partial, rs6000_wait, rs6000_create_inferior)
	(rs6000_xfer_shared_libraries): Refactor as rs6000_nat_target methods.
	(super_create_inferior): Delete.
	(_initialize_rs6000_nat): Adjust to C++ification.

	* arm-linux-nat.c (arm_linux_nat_target): New class.
	(the_arm_linux_nat_target): New.
	(arm_linux_fetch_inferior_registers)
	(arm_linux_store_inferior_registers, arm_linux_read_description)
	(arm_linux_can_use_hw_breakpoint, arm_linux_insert_hw_breakpoint)
	(arm_linux_remove_hw_breakpoint)
	(arm_linux_region_ok_for_hw_watchpoint)
	(arm_linux_insert_watchpoint, arm_linux_remove_watchpoint)
	(arm_linux_stopped_data_address, arm_linux_stopped_by_watchpoint)
	(arm_linux_watchpoint_addr_within_range): Refactor as methods of
	arm_linux_nat_target.
	(_initialize_arm_linux_nat): Adjust to C++ification.

	* aarch64-linux-nat.c (aarch64_linux_nat_target): New class.
	(the_aarch64_linux_nat_target): New.
	(aarch64_linux_fetch_inferior_registers)
	(aarch64_linux_store_inferior_registers)
	(aarch64_linux_child_post_startup_inferior)
	(aarch64_linux_read_description)
	(aarch64_linux_can_use_hw_breakpoint)
	(aarch64_linux_insert_hw_breakpoint)
	(aarch64_linux_remove_hw_breakpoint)
	(aarch64_linux_insert_watchpoint, aarch64_linux_remove_watchpoint)
	(aarch64_linux_region_ok_for_hw_watchpoint)
	(aarch64_linux_stopped_data_address)
	(aarch64_linux_stopped_by_watchpoint)
	(aarch64_linux_watchpoint_addr_within_range)
	(aarch64_linux_can_do_single_step): Refactor as methods of
	aarch64_linux_nat_target.
	(super_post_startup_inferior): Delete.
	(_initialize_aarch64_linux_nat): Adjust to C++ification.

	* hppa-linux-nat.c (hppa_linux_nat_target): New class.
	(the_hppa_linux_nat_target): New.
	(hppa_linux_fetch_inferior_registers)
	(hppa_linux_store_inferior_registers): Refactor as methods of
	hppa_linux_nat_target.
	(_initialize_hppa_linux_nat): Adjust to C++ification.

	* ia64-linux-nat.c (ia64_linux_nat_target): New class.
	(the_ia64_linux_nat_target): New.
	(ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint)
	(ia64_linux_stopped_data_address)
	(ia64_linux_stopped_by_watchpoint, ia64_linux_fetch_registers)
	(ia64_linux_store_registers, ia64_linux_xfer_partial): Refactor as
	ia64_linux_nat_target methods.
	(super_xfer_partial): Delete.
	(_initialize_ia64_linux_nat): Adjust to C++ification.

	* m32r-linux-nat.c (m32r_linux_nat_target): New class.
	(the_m32r_linux_nat_target): New.
	(m32r_linux_fetch_inferior_registers)
	(m32r_linux_store_inferior_registers): Refactor as
	m32r_linux_nat_target methods.
	(_initialize_m32r_linux_nat): Adjust to C++ification.

	* m68k-linux-nat.c (m68k_linux_nat_target): New class.
	(the_m68k_linux_nat_target): New.
	(m68k_linux_fetch_inferior_registers)
	(m68k_linux_store_inferior_registers): Refactor as
	m68k_linux_nat_target methods.
	(_initialize_m68k_linux_nat): Adjust to C++ification.

	* s390-linux-nat.c (s390_linux_nat_target): New class.
	(the_s390_linux_nat_target): New.
	(s390_linux_fetch_inferior_registers)
	(s390_linux_store_inferior_registers, s390_stopped_by_watchpoint)
	(s390_insert_watchpoint, s390_remove_watchpoint)
	(s390_can_use_hw_breakpoint, s390_insert_hw_breakpoint)
	(s390_remove_hw_breakpoint, s390_region_ok_for_hw_watchpoint)
	(s390_auxv_parse, s390_read_description): Refactor as methods of
	s390_linux_nat_target.
	(_initialize_s390_nat): Adjust to C++ification.

	* sparc-linux-nat.c (sparc_linux_nat_target): New class.
	(the_sparc_linux_nat_target): New.
	(_initialize_sparc_linux_nat): Adjust to C++ification.
	* sparc-nat.c (sparc_fetch_inferior_registers)
	(sparc_store_inferior_registers): Remove target_ops parameter.
	* sparc-nat.h (sparc_fetch_inferior_registers)
	(sparc_store_inferior_registers): Remove target_ops parameter.
	* sparc64-linux-nat.c (sparc64_linux_nat_target): New class.
	(the_sparc64_linux_nat_target): New.
	(_initialize_sparc64_linux_nat): Adjust to C++ification.

	* spu-linux-nat.c (spu_linux_nat_target): New class.
	(the_spu_linux_nat_target): New.
	(spu_child_post_startup_inferior, spu_child_post_attach)
	(spu_child_wait, spu_fetch_inferior_registers)
	(spu_store_inferior_registers, spu_xfer_partial)
	(spu_can_use_hw_breakpoint): Refactor as spu_linux_nat_target
	methods.
	(_initialize_spu_nat): Adjust to C++ification.

	* tilegx-linux-nat.c (tilegx_linux_nat_target): New class.
	(the_tilegx_linux_nat_target): New.
	(fetch_inferior_registers, store_inferior_registers):
	Refactor as methods.
	(_initialize_tile_linux_nat): Adjust to C++ification.

	* xtensa-linux-nat.c (xtensa_linux_nat_target): New class.
	(the_xtensa_linux_nat_target): New.
	(xtensa_linux_fetch_inferior_registers)
	(xtensa_linux_store_inferior_registers): Refactor as
	xtensa_linux_nat_target methods.
	(_initialize_xtensa_linux_nat): Adjust to C++ification.

	* fbsd-nat.c (USE_SIGTRAP_SIGINFO): Delete.
	(fbsd_pid_to_exec_file, fbsd_find_memory_regions)
	(fbsd_find_memory_regions, fbsd_info_proc, fbsd_xfer_partial)
	(fbsd_thread_alive, fbsd_pid_to_str, fbsd_thread_name)
	(fbsd_update_thread_list, fbsd_resume, fbsd_wait)
	(fbsd_stopped_by_sw_breakpoint)
	(fbsd_supports_stopped_by_sw_breakpoint, fbsd_follow_fork)
	(fbsd_insert_fork_catchpoint, fbsd_remove_fork_catchpoint)
	(fbsd_insert_vfork_catchpoint, fbsd_remove_vfork_catchpoint)
	(fbsd_post_startup_inferior, fbsd_post_attach)
	(fbsd_insert_exec_catchpoint, fbsd_remove_exec_catchpoint)
	(fbsd_set_syscall_catchpoint)
	(super_xfer_partial, super_resume, super_wait)
	(fbsd_supports_stopped_by_hw_breakpoint): Delete.
	(fbsd_handle_debug_trap): Remove target_ops parameter.
	(fbsd_nat_add_target): Delete.
	* fbsd-nat.h: Include "inf-ptrace.h".
	(fbsd_nat_add_target): Delete.
	(USE_SIGTRAP_SIGINFO): Define.
	(fbsd_nat_target): New class.

	* amd64-bsd-nat.c (amd64bsd_fetch_inferior_registers)
	(amd64bsd_store_inferior_registers): Remove target_ops parameter.
	(amd64bsd_target): Delete.
	* amd64-bsd-nat.h: New file.
	* amd64-fbsd-nat.c: Include "amd64-bsd-nat.h" instead of
	"x86-bsd-nat.h".
	(amd64_fbsd_nat_target): New class.
	(the_amd64_fbsd_nat_target): New.
	(amd64fbsd_read_description): Refactor as method of
	amd64_fbsd_nat_target.
	(amd64_fbsd_nat_target::supports_stopped_by_hw_breakpoint): New.
	(_initialize_amd64fbsd_nat): Adjust to C++ification.
	* amd64-nat.h (amd64bsd_target): Delete function declaration.
	* i386-bsd-nat.c (i386bsd_fetch_inferior_registers)
	(i386bsd_store_inferior_registers): Remove target_ops parameter.
	(i386bsd_target): Delete.
	* i386-bsd-nat.h (i386bsd_target): Delete function declaration.
	(i386bsd_fetch_inferior_registers)
	(i386bsd_store_inferior_registers): Declare.
	(i386_bsd_nat_target): New class.
	* i386-fbsd-nat.c (i386_fbsd_nat_target): New class.
	(the_i386_fbsd_nat_target): New.
	(i386fbsd_resume, i386fbsd_read_description): Refactor as
	i386_fbsd_nat_target methods.
	(i386_fbsd_nat_target::supports_stopped_by_hw_breakpoint): New.
	(_initialize_i386fbsd_nat): Adjust to C++ification.
	* x86-bsd-nat.c (super_mourn_inferior): Delete.
	(x86bsd_mourn_inferior, x86bsd_target): Delete.
	(_initialize_x86_bsd_nat): Adjust to C++ification.
	* x86-bsd-nat.h: Include "x86-nat.h".
	(x86bsd_target): Delete declaration.
	(x86bsd_nat_target): New class.

	* aarch64-fbsd-nat.c (aarch64_fbsd_nat_target): New class.
	(the_aarch64_fbsd_nat_target): New.
	(aarch64_fbsd_fetch_inferior_registers)
	(aarch64_fbsd_store_inferior_registers): Refactor as methods of
	aarch64_fbsd_nat_target.
	(_initialize_aarch64_fbsd_nat): Adjust to C++ification.
	* alpha-bsd-nat.c (alpha_bsd_nat_target): New class.
	(the_alpha_bsd_nat_target): New.
	(alphabsd_fetch_inferior_registers)
	(alphabsd_store_inferior_registers): Refactor as
	alpha_bsd_nat_target methods.
	(_initialize_alphabsd_nat): Refactor as methods of
	alpha_bsd_nat_target.
	* amd64-nbsd-nat.c: Include "amd64-bsd-nat.h".
	(the_amd64_nbsd_nat_target): New.
	(_initialize_amd64nbsd_nat): Adjust to C++ification.
	* amd64-obsd-nat.c: Include "amd64-bsd-nat.h".
	(the_amd64_obsd_nat_target): New.
	(_initialize_amd64obsd_nat): Adjust to C++ification.
	* arm-fbsd-nat.c (arm_fbsd_nat_target): New.
	(the_arm_fbsd_nat_target): New.
	(arm_fbsd_fetch_inferior_registers)
	(arm_fbsd_store_inferior_registers, arm_fbsd_read_description):
	(_initialize_arm_fbsd_nat): Refactor as methods of
	arm_fbsd_nat_target.
	(_initialize_arm_fbsd_nat): Adjust to C++ification.
	* arm-nbsd-nat.c (arm_netbsd_nat_target): New class.
	(the_arm_netbsd_nat_target): New.
	(armnbsd_fetch_registers, armnbsd_store_registers): Refactor as
	arm_netbsd_nat_target.
	(_initialize_arm_netbsd_nat): Adjust to C++ification.
	* hppa-nbsd-nat.c (hppa_nbsd_nat_target): New class.
	(the_hppa_nbsd_nat_target): New.
	(hppanbsd_fetch_registers, hppanbsd_store_registers): Refactor as
	hppa_nbsd_nat_target methods.
	(_initialize_hppanbsd_nat): Adjust to C++ification.
	* hppa-obsd-nat.c (hppa_obsd_nat_target): New class.
	(the_hppa_obsd_nat_target): New.
	(hppaobsd_fetch_registers, hppaobsd_store_registers): Refactor as
	methods of hppa_obsd_nat_target.
	(_initialize_hppaobsd_nat): Adjust to C++ification.  Use
	add_target.
	* i386-nbsd-nat.c (the_i386_nbsd_nat_target): New.
	(_initialize_i386nbsd_nat): Adjust to C++ification.  Use
	add_target.
	* i386-obsd-nat.c (the_i386_obsd_nat_target): New.
	(_initialize_i386obsd_nat): Use add_target.
	* m68k-bsd-nat.c (m68k_bsd_nat_target): New class.
	(the_m68k_bsd_nat_target): New.
	(m68kbsd_fetch_inferior_registers)
	(m68kbsd_store_inferior_registers): Refactor as methods of
	m68k_bsd_nat_target.
	(_initialize_m68kbsd_nat): Adjust to C++ification.
	* mips-fbsd-nat.c (mips_fbsd_nat_target): New class.
	(the_mips_fbsd_nat_target): New.
	(mips_fbsd_fetch_inferior_registers)
	(mips_fbsd_store_inferior_registers): Refactor as methods of
	mips_fbsd_nat_target.
	(_initialize_mips_fbsd_nat): Adjust to C++ification.  Use
	add_target.
	* mips-nbsd-nat.c (mips_nbsd_nat_target): New class.
	(the_mips_nbsd_nat_target): New.
	(mipsnbsd_fetch_inferior_registers)
	(mipsnbsd_store_inferior_registers): Refactor as methods of
	mips_nbsd_nat_target.
	(_initialize_mipsnbsd_nat): Adjust to C++ification.
	* mips64-obsd-nat.c (mips64_obsd_nat_target): New class.
	(the_mips64_obsd_nat_target): New.
	(mips64obsd_fetch_inferior_registers)
	(mips64obsd_store_inferior_registers): Refactor as methods of
	mips64_obsd_nat_target.
	(_initialize_mips64obsd_nat): Adjust to C++ification.  Use
	add_target.
	* nbsd-nat.c (nbsd_pid_to_exec_file): Refactor as method of
	nbsd_nat_target.
	* nbsd-nat.h: Include "inf-ptrace.h".
	(nbsd_nat_target): New class.
	* obsd-nat.c (obsd_pid_to_str, obsd_update_thread_list)
	(obsd_wait): Refactor as methods of obsd_nat_target.
	(obsd_add_target): Delete.
	* obsd-nat.h: Include "inf-ptrace.h".
	(obsd_nat_target): New class.
	* ppc-fbsd-nat.c (ppc_fbsd_nat_target): New class.
	(the_ppc_fbsd_nat_target): New.
	(ppcfbsd_fetch_inferior_registers)
	(ppcfbsd_store_inferior_registers): Refactor as methods of
	ppc_fbsd_nat_target.
	(_initialize_ppcfbsd_nat): Adjust to C++ification.  Use
	add_target.
	* ppc-nbsd-nat.c (ppc_nbsd_nat_target): New class.
	(the_ppc_nbsd_nat_target): New.
	(ppcnbsd_fetch_inferior_registers)
	(ppcnbsd_store_inferior_registers): Refactor as methods of
	ppc_nbsd_nat_target.
	(_initialize_ppcnbsd_nat): Adjust to C++ification.
	* ppc-obsd-nat.c (ppc_obsd_nat_target): New class.
	(the_ppc_obsd_nat_target): New.
	(ppcobsd_fetch_registers, ppcobsd_store_registers): Refactor as
	methods of ppc_obsd_nat_target.
	(_initialize_ppcobsd_nat): Adjust to C++ification.  Use
	add_target.
	* sh-nbsd-nat.c (sh_nbsd_nat_target): New class.
	(the_sh_nbsd_nat_target): New.
	(shnbsd_fetch_inferior_registers)
	(shnbsd_store_inferior_registers): Refactor as methods of
	sh_nbsd_nat_target.
	(_initialize_shnbsd_nat): Adjust to C++ification.
	* sparc-nat.c (sparc_xfer_wcookie): Make extern.
	(inf_ptrace_xfer_partial): Delete.
	(sparc_xfer_partial, sparc_target): Delete.
	* sparc-nat.h (sparc_fetch_inferior_registers)
	(sparc_store_inferior_registers, sparc_xfer_wcookie): Declare.
	(sparc_target): Delete function declaration.
	(sparc_target): New template class.
	* sparc-nbsd-nat.c (the_sparc_nbsd_nat_target): New.
	(_initialize_sparcnbsd_nat): Adjust to C++ification.
	* sparc64-fbsd-nat.c (the_sparc64_fbsd_nat_target): New.
	(_initialize_sparc64fbsd_nat): Adjust to C++ification.  Use
	add_target.
	* sparc64-nbsd-nat.c (the_sparc64_nbsd_nat_target): New.
	(_initialize_sparc64nbsd_nat): Adjust to C++ification.
	* sparc64-obsd-nat.c (the_sparc64_obsd_nat_target): New.
	(_initialize_sparc64obsd_nat): Adjust to C++ification.  Use
	add_target.
	* vax-bsd-nat.c (vax_bsd_nat_target): New class.
	(the_vax_bsd_nat_target): New.
	(vaxbsd_fetch_inferior_registers)
	(vaxbsd_store_inferior_registers): Refactor as vax_bsd_nat_target
	methods.
	(_initialize_vaxbsd_nat): Adjust to C++ification.

	* bsd-kvm.c (bsd_kvm_target): New class.
	(bsd_kvm_ops): Now a bsd_kvm_target.
	(bsd_kvm_open, bsd_kvm_close, bsd_kvm_xfer_partial)
	(bsd_kvm_files_info, bsd_kvm_fetch_registers)
	(bsd_kvm_thread_alive, bsd_kvm_pid_to_str): Refactor as methods of
	bsd_kvm_target.
	(bsd_kvm_return_one): Delete.
	(bsd_kvm_add_target): Adjust to C++ification.

	* nto-procfs.c (nto_procfs_target, nto_procfs_target_native)
	(nto_procfs_target_procfs): New classes.
	(procfs_open_1, procfs_thread_alive, procfs_update_thread_list)
	(procfs_files_info, procfs_pid_to_exec_file, procfs_attach)
	(procfs_post_attach, procfs_wait, procfs_fetch_registers)
	(procfs_xfer_partial, procfs_detach, procfs_insert_breakpoint)
	(procfs_remove_breakpoint, procfs_insert_hw_breakpoint)
	(procfs_remove_hw_breakpoint, procfs_resume)
	(procfs_mourn_inferior, procfs_create_inferior, procfs_interrupt)
	(procfs_kill_inferior, procfs_store_registers)
	(procfs_pass_signals, procfs_pid_to_str, procfs_can_run): Refactor
	as methods of nto_procfs_target.
	(nto_procfs_ops): Now an nto_procfs_target_procfs.
	(nto_native_ops): Delete.
	(procfs_open, procfs_native_open): Delete.
	(nto_native_ops): Now an nto_procfs_target_native.
	(init_procfs_targets): Adjust to C++ification.
	(procfs_can_use_hw_breakpoint, procfs_remove_hw_watchpoint)
	(procfs_insert_hw_watchpoint, procfs_stopped_by_watchpoint):
	Refactor as methods of nto_procfs_target.

	* go32-nat.c (go32_nat_target): New class.
	(the_go32_nat_target): New.
	(go32_attach, go32_resume, go32_wait, go32_fetch_registers)
	(go32_store_registers, go32_xfer_partial, go32_files_info)
	(go32_kill_inferior, go32_create_inferior, go32_mourn_inferior)
	(go32_terminal_init, go32_terminal_info, go32_terminal_inferior)
	(go32_terminal_ours, go32_pass_ctrlc, go32_thread_alive)
	(go32_pid_to_str): Refactor as methods of go32_nat_target.
	(go32_target): Delete.
	(_initialize_go32_nat): Adjust to C++ification.

	* gnu-nat.c (gnu_wait, gnu_resume, gnu_kill_inferior)
	(gnu_mourn_inferior, gnu_create_inferior, gnu_attach, gnu_detach)
	(gnu_stop, gnu_thread_alive, gnu_xfer_partial)
	(gnu_find_memory_regions, gnu_pid_to_str): Refactor as methods of
	gnu_nat_target.
	(gnu_target): Delete.
	* gnu-nat.h (gnu_target): Delete.
	(gnu_nat_target): New class.
	* i386-gnu-nat.c (gnu_base_target): New.
	(i386_gnu_nat_target): New class.
	(the_i386_gnu_nat_target): New.
	(_initialize_i386gnu_nat): Adjust to C++ification.

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

	* gdb.base/breakpoint-in-ro-region.exp: Adjust to to_resume and
	to_log_command renames.
	* gdb.base/sss-bp-on-user-bp-2.exp: Likewise.
2018-05-03 00:48:36 +01:00
Pedro Alves 436411b1c6 Eliminate target_has_exited
Nothing uses this.

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

	* target.h (target_ops::to_has_exited): Delete.
	(target_has_exited): Delete.
	* target-delegates.c: Regenerate.
2018-04-12 17:36:01 +01:00
Simon Marchi c252925ccc Remove VEC(tsv_s), use std::vector instead
This patch removes VEC(tsv_s), using an std::vector instead.  I C++ified
trace_state_variable a bit in the process, using std::string for the
name.  I also thought it would be nicer to pass a const reference to
target_download_trace_state_variable, since we know it will never be
NULL.  This highlighted that the make-target-delegates script didn't
handle references well, so I adjusted this as well.  It will surely be
useful in the future.

gdb/ChangeLog:

	* tracepoint.h (struct trace_state_variable): Add constructor.
	<name>: Change type to std::string.
	* tracepoint.c (tsv_s): Remove.
	(DEF_VEC_O(tsv_s)): Remove.
	(tvariables): Change to std::vector.
	(create_trace_state_variable): Adjust to std::vector.
	(find_trace_state_variable): Likewise.
	(find_trace_state_variable_by_number): Likewise.
	(delete_trace_state_variable): Likewise.
	(trace_variable_command): Adjust to std::string.
	(delete_trace_variable_command): Likewise.
	(tvariables_info_1): Adjust to std::vector.
	(save_trace_state_variables): Likewise.
	(start_tracing): Likewise.
	(merge_uploaded_trace_state_variables): Adjust to std::vector
	and std::string.
	* target.h (struct target_ops)
	<to_download_trace_state_variable>: Pass reference to
	trace_state_variable.
	* target-debug.h (target_debug_print_const_trace_state_variable_r): New.
	* target-delegates.c: Re-generate.
	* mi/mi-interp.c (mi_tsv_created): Adjust to std::string.
	(mi_tsv_deleted): Likewise.
	* mi/mi-main.c (mi_cmd_trace_frame_collected): Likewise.
	* remote.c (remote_download_trace_state_variable): Change
	pointer to reference and adjust.
	* make-target-delegates (parse_argtypes): Handle references.
	(write_function_header): Likewise.
	(munge_type): Likewise.
2018-04-09 15:16:19 -04:00
Simon Marchi 5d9310c4b8 Get rid of VEC(static_tracepoint_marker_p)
This patch replaces VEC(static_tracepoint_marker_p) with std::vector,
and does some c++ification around that.  I thought a new overload of
hex2str was useful, so I added it as well as corresponding unit tests.
I also added an overload of ui_out::field_string that takes an
std::string directly.

gdb/ChangeLog:

	* tracepoint.h (struct static_tracepoint_marker): Initialize
	fields, define default constructor, move constructor and move
	assignment, disable the rest.
	<str_id, extra>: Make std::string.
	(release_static_tracepoint_marker): Remove.
	(free_current_marker): Remove.
	* tracepoint.c (free_current_marker): Remove.
	(parse_static_tracepoint_marker_definition): Adjust to
	std::string, use new hex2str overload.
	(release_static_tracepoint_marker): Remove.
	(print_one_static_tracepoint_marker): Get marker by reference
	and adjust to std::string.
	(info_static_tracepoint_markers_command): Adjust to std::vector
	changes
	* target.h (static_tracepoint_marker_p): Remove typedef.
	(DEF_VEC_P(static_tracepoint_marker_p)): Remove.
	(struct target_ops) <to_static_tracepoint_marker_at>: Return
	bool.
	<to_static_tracepoint_markers_by_strid>: Return std::vector.
	* target-debug.h
	(target_debug_print_VEC_static_tracepoint_marker_p_p): Remove.
	(target_debug_print_std_vector_static_tracepoint_marker): New.
	(target_debug_print_struct_static_tracepoint_marker_p): Rename
	to...
	(target_debug_print_static_tracepoint_marker_p): ... this.
	* target-delegates.c: Re-generate.
	* breakpoint.h (struct tracepoint) <static_trace_marker_id>:
	Make std::string.
	* breakpoint.c (init_breakpoint_sal): Adjust to std::string.
	(decode_static_tracepoint_spec): Adjust to std::vector.
	(tracepoint_print_one_detail): Adjust to std::string.
	(strace_marker_decode_location): Adjust to std::string.
	(update_static_tracepoint): Adjust to std::string, remove call
	to release_static_tracepoint_marker.
	* linux-nat.c (linux_child_static_tracepoint_markers_by_strid):
	Adjust to std::vector.
	* remote.c (remote_static_tracepoint_marker_at): Return bool.
	(remote_static_tracepoint_markers_by_strid): Adjust to
	std::vector.
	* common/rsp-low.h (hex2str): New overload with explicit count
	of bytes.
	* common/rsp-low.c (hex2str): New overload with explicit count
	of bytes.
	* unittests/rsp-low-selftests.c (test_hex2str): New function.
	(_initialize_rsp_low_selftests): Add test_hex2str test.
	* unittests/tracepoint-selftests.c
	(test_parse_static_tracepoint_marker_definition): Adjust to
	std::string.
2018-03-22 00:27:19 -04:00
Simon Marchi 0cb7c7b0bb Propagate record_print_flags
These flags are returned as an int by get_call_history_modifiers, and
get cast back to record_print_flags in the btrace code.  Instead, we can
make the arguments of that type from start to end.

gdb/ChangeLog:

	* record.c (get_call_history_modifiers): Return a
	record_print_flags.
	(cmd_record_call_history): Adjust.
	* record-btrace.c (record_btrace_call_history): Adjust.
	(record_btrace_call_history_range): Adjust.
	(record_btrace_call_history_from): Adjust.
	* target-debug.h (target_debug_print_record_print_flags): New.
	* target-delegates.c: Re-generate.
	* target.c (target_call_history): Change flags type.
	(target_call_history_from): Likewise.
	(target_call_history_range): Likewise.
	* target.h (struct target_ops) <target_call_history>: Likewise.
	(target_call_history_from): Likewise.
	(target_call_history_range): Likewise.
2018-03-01 10:51:21 -05:00
Markus Metzger de6242d307 btrace, gdbserver: remove the to_supports_btrace target method
Remove the to_supports_btrace target method and instead rely on detecting errors
when trying to enable recording.  This will also provide a suitable error
message explaining why recording is not possible.

For remote debugging, gdbserver will now always advertise branch tracing related
packets.  When talking to an older GDB, this will cause GDB to try to enable
branch tracing and gdbserver to report a suitable error message every time.

An older gdbserver will not advertise branch tracing related packets if the
one-time check failed, so a newer GDB with this patch will fail to enable branch
tracing at remote_enable_btrace() rather than at btrace_enable().  The error
message is the same in both cases so there should be no user-visible change.

gdb/
	* btrace.c (btrace_enable): Remove target_supports_btrace call.
	* nat/linux-btrace.c (perf_event_pt_event_type): Move.
	(kernel_supports_bts, kernel_supports_pt, linux_supports_bts)
	(linux_supports_pt, linux_supports_btrace): Remove.
	(linux_enable_bts): Call cpu_supports_bts.
	* nat/linux-btrace.h (linux_supports_btrace): Remove.
	* remote.c (remote_supports_btrace): Remove.
	(init_remote_ops): Remove remote_supports_btrace.
	* target-delegates.c: Regenerated.
	* target.c (target_supports_btrace): Remove.
	* target.h (target_ops) <to_supports_btrace>: Remove
	(target_supports_btrace): Remove.
	* x86-linux-nat.c (x86_linux_create_target): Remove
	linux_supports_btrace.

gdbserver/
	* linux-low.c (linux_target_ops): Remove linux_supports_btrace.
	* nto-low.c (nto_target_ops): Remove NULL for supports_btrace.
	* spu-low.c (spu_target_ops): Likewise.
	* win32-low.c (win32_target_ops): Likewise.
	* server.c (supported_btrace_packets): Report packets unconditionally.
	* target.h (target_ops) <supports_btrace>: Remove.
	(target_supports_btrace): Remove.
2018-02-09 14:03:20 +01:00
Pedro Alves e671cd59d7 Per-inferior target_terminal state, fix PR gdb/13211, more
In my multi-target branch I ran into problems with GDB's terminal
handling that exist in master as well, with multi-inferior debugging.

This patch adds a testcase for said problems
(gdb.multi/multi-term-settings.exp), fixes the problems, fixes PR
gdb/13211 as well (and adds a testcase for that too,
gdb.base/interrupt-daemon.exp).

The basis of the problem I ran into is the following.  Consider a
scenario where you have:

 - inferior 1 - started with "attach", process is running on some
   other terminal.

 - inferior 2 - started with "run", process is sharing gdb's terminal.

In this scenario, when you stop/resume both inferiors, you want GDB to
save/restore the terminal settings of inferior 2, the one that is
sharing GDB's terminal.  I.e., you want inferior 2 to "own" the
terminal (in target_terminal::is_ours/target_terminal::is_inferior
sense).

Unfortunately, that's not what you get currently.  Because GDB doesn't
know whether an attached inferior is actually sharing GDB's terminal,
it tries to save/restore its settings anyway, ignoring errors.  In
this case, this is pointless, because inferior 1 is running on a
different terminal, but GDB doesn't know better.

And then, because it is only possible to have the terminal settings of
a single inferior be in effect at a time, or make one inferior/pgrp be
the terminal's foreground pgrp (aka, only one inferior can "own" the
terminal, ignoring fork children here), if GDB happens to try to
restore the terminal settings of inferior 1 first, then GDB never
restores the terminal settings of inferior 2.

This patch fixes that and a few things more along the way:

 - Moves enum target_terminal::terminal_state out of the
   target_terminal class (it's currently private) and makes it a
   scoped enum so that it can be easily used elsewhere.

 - Replaces the inflow.c:terminal_is_ours boolean with a
   target_terminal_state variable.  This allows distinguishing is_ours
   and is_ours_for_output states.  This allows finally making
   child_terminal_ours_1 do something with its "output_only"
   parameter.

 - Makes each inferior have its own copy of the
   is_ours/is_ours_for_output/is_inferior state.

 - Adds a way for GDB to tell whether the inferior is sharing GDB's
   terminal.  Works best on Linux and Solaris; the fallback works just
   as well as currently.

 - With that, we can remove the inf->attach_flag tests from
   child_terminal_inferior/child_terminal_ours.

 - Currently target_ops.to_ours is responsible for both saving the
   current inferior's terminal state, and restoring gdb's state.
   Because each inferior has its own terminal state (possibly handled
   by different targets in a multi-target world, even), we need to
   split the inferior-saving part from the gdb-restoring part.  The
   patch adds a new target_ops.to_save_inferior target method for
   that.

 - Adds a new target_terminal::save_inferior() function, so that
   sequences like:

     scoped_restore_terminal_state save_state;
     target_terminal::ours_for_output ();

   ... restore back inferiors that were
   target_terminal_state::is_inferior before back to is_inferior, and
   leaves inferiors that were is_ours alone.

 - Along the way, this adds a default implementation of
   target_pass_ctrlc to inflow.c (for inf-child.c), that handles
   passing the Ctrl-C to a process running on GDB's terminal or to
   some other process otherwise.

 - Similarly, adds a new target default implementation of
   target_interrupt, for the "interrupt" command.  The current
   implementation of this hook in inf-ptrace.c kills the whole process
   group, but that's incorrect/undesirable because we may not be
   attached to all processes in the process group.  And also, it's
   incorrect because inferior_process_group() doesn't really return
   the inferior's real process group id if the inferior is not a
   process group leader...  This is the cause of PR gdb/13211 [1],
   which this patch fixes.  While at it, that target method's "ptid"
   parameter is eliminated, because it's not really used.

 - A new test is included that exercises and fixes PR gdb/13211, and
   also fixes a GDB issue reported on stackoverflow that I ran into
   while working on this [2].  The problem is similar to PR gdb/13211,
   except that it also triggers with Ctrl-C.  When debugging a daemon
   (i.e., a process that disconnects from the controlling terminal and
   is not a process group leader, then Ctrl-C doesn't work, you just
   can't interrupt the inferior at all, resulting in a hung debug
   session.  The problem is that since the inferior is no longer
   associated with gdb's session / controlling terminal, then trying
   to put the inferior in the foreground fails.  And so Ctrl-C never
   reaches the inferior directly.  pass_signal is only used when the
   inferior is attached, but that is not the case here.  This is fixed
   by the new child_pass_ctrlc.  Without the fix, the new
   interrupt-daemon.exp testcase fails with timeout waiting for a
   SIGINT that never arrives.

[1] PR gdb/13211 - Async / Process group and interrupt not working
https://sourceware.org/bugzilla/show_bug.cgi?id=13211

[2] GDB not reacting Ctrl-C when after fork() and setsid()
https://stackoverflow.com/questions/46101292/gdb-not-reacting-ctrl-c-when-after-fork-and-setsid

Note this patch does _not_ fix:

 - PR gdb/14559 - The 'interrupt' command does not work if sigwait is in use
   https://sourceware.org/bugzilla/show_bug.cgi?id=14559

 - PR gdb/9425 - When using "sigwait" GDB doesn't trap SIGINT. Ctrl+C terminates program when should break gdb.
   https://sourceware.org/bugzilla/show_bug.cgi?id=9425

The only way to fix that that I know of (without changing the kernel)
is to make GDB put inferiors in a separate session (create a
pseudo-tty master/slave pair, make the inferior run with the slave as
its terminal, and have gdb pump output/input on the master end).

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

	PR gdb/13211
	* config.in, configure: Regenerate.
	* configure.ac: Check for getpgid.
	* go32-nat.c (go32_pass_ctrlc): New.
	(go32_target): Install it.
	* inf-child.c (inf_child_target): Install
	child_terminal_save_inferior, child_pass_ctrlc and
	child_interrupt.
	* inf-ptrace.c (inf_ptrace_interrupt): Delete.
	(inf_ptrace_target): No longer install it.
	* infcmd.c (interrupt_target_1): Adjust.
	* inferior.h (child_terminal_save_inferior, child_pass_ctrlc)
	(child_interrupt): Declare.
	(inferior::terminal_state): New.
	* inflow.c (struct terminal_info): Update comments.
	(inferior_process_group): Delete.
	(terminal_is_ours): Delete.
	(gdb_tty_state): New.
	(child_terminal_init): Adjust.
	(is_gdb_terminal, sharing_input_terminal_1)
	(sharing_input_terminal): New functions.
	(child_terminal_inferior): Adjust.  Use sharing_input_terminal.
	Set the process's actual process group in the foreground if
	possible.  Handle is_ours_for_output/is_ours distinction.  Don't
	mark terminal as the inferior's if not sharing GDB's terminal.
	Don't check attach_flag.
	(child_terminal_ours_for_output, child_terminal_ours): Adjust to
	pass down a target_terminal_state.
	(child_terminal_save_inferior): New, factored out from ...
	(child_terminal_ours_1): ... this.  Handle
	target_terminal_state::is_ours_for_output.
	(child_interrupt, child_pass_ctrlc): New.
	(inflow_inferior_exit): Clear the inferior's terminal_state.
	(copy_terminal_info): Copy the inferior's terminal state.
	(_initialize_inflow): Remove reference to terminal_is_ours.
	* inflow.h (inferior_process_group): Delete.
	* nto-procfs.c (nto_handle_sigint, procfs_interrupt): Adjust.
	* procfs.c (procfs_target): Don't install procfs_interrupt.
	(procfs_interrupt): Delete.
	* remote.c (remote_serial_quit_handler): Adjust.
	(remote_interrupt): Remove ptid parameter.  Adjust.
	* target-delegates.c: Regenerate.
	* target.c: Include "terminal.h".
	(target_terminal::terminal_state): Rename to ...
	(target_terminal::m_terminal_state): ... this.
	(target_terminal::init): Adjust.
	(target_terminal::inferior): Adjust to per-inferior
	terminal_state.
	(target_terminal::restore_inferior, target_terminal_is_ours_kind): New.
	(target_terminal::ours, target_terminal::ours_for_output): Use
	target_terminal_is_ours_kind.
	(target_interrupt): Remove ptid parameter.  Adjust.
	(default_target_pass_ctrlc): Adjust.
	* target.h (target_ops::to_terminal_save_inferior): New field.
	(target_ops::to_interrupt): Remove ptid_t parameter.
	(target_interrupt): Remove ptid_t parameter.  Update comment.
	(target_pass_ctrlc): Update comment.
	* target/target.h (target_terminal_state): New scoped enum,
	factored out of ...
	(target_terminal::terminal_state): ... here.
	(target_terminal::inferior): Update comments.
	(target_terminal::restore_inferior): New.
	(target_terminal::is_inferior, target_terminal::is_ours)
	(target_terminal::is_ours_for_output): Adjust.
	(target_terminal::scoped_restore_terminal_state): Adjust to
	rename, and call restore_inferior() instead of inferior().
	(target_terminal::scoped_restore_terminal_state::m_state): Change
	type.
	(target_terminal::terminal_state): Rename to ...
	(target_terminal::m_terminal_state): ... this and change type.

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

	PR gdb/13211
	* target.c (target_terminal::terminal_state): Rename to ...
	(target_terminal::m_terminal_state): ... this.

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

	PR gdb/13211
	* gdb.base/interrupt-daemon.c: New.
	* gdb.base/interrupt-daemon.exp: New.
	* gdb.multi/multi-term-settings.c: New.
	* gdb.multi/multi-term-settings.exp: New.
2018-01-30 14:55:18 +00:00
Simon Marchi 6e1e1966ba Pass inferior down to target_detach and to_detach
The to_detach target_ops method implementations are currently expected
to work on current_inferior/inferior_ptid.  In order to make things more
explicit, and remove some "shadow" parameter passing through globals,
this patch adds an "inferior" parameter to to_detach.  Implementations
will be expected to use this instead of relying on the global.  However,
to keep things simple, this patch only does the minimum that is
necessary to add the parameter.  The following patch gives an example of
how one such implementation would be adapted.  If the approach is deemed
good, we can then look into adapting more implementations.  Until then,
they'll continue to work as they do currently.

gdb/ChangeLog:

	* target.h (struct target_ops) <to_detach>: Add inferior
	parameter.
	(target_detach): Likewise.
	* target.c (dispose_inferior): Pass inferior down.
	(target_detach): Pass inferior down.  Assert that it is equal to
	the current inferior.
	* aix-thread.c (aix_thread_detach): Pass inferior down.
	* corefile.c (core_file_command): Pass current_inferior() down.
	* corelow.c (core_detach): Add inferior parameter.
	* darwin-nat.c (darwin_detach): Likewise.
	* gnu-nat.c (gnu_detach): Likewise.
	* inf-ptrace.c (inf_ptrace_detach): Likewise.
	* infcmd.c (detach_command): Pass current_inferior() down to
	target_detach.
	* infrun.c (follow_fork_inferior): Pass parent_inf to
	target_detach.
	(handle_vfork_child_exec_or_exit): Pass inf->vfork_parent to
	target_detach.
	* linux-nat.c (linux_nat_detach): Add inferior parameter.
	* linux-thread-db.c (thread_db_detach): Likewise.
	* nto-procfs.c (procfs_detach): Likewise.
	* procfs.c (procfs_detach): Likewise.
	* record.c (record_detach): Likewise.
	* record.h (struct inferior): Forward-declare.
	(record_detach): Add inferior parameter.
	* remote-sim.c (gdbsim_detach): Likewise.
	* remote.c (remote_detach_1): Likewise.
	(remote_detach): Likewise.
	(extended_remote_detach): Likewise.
	* sol-thread.c (sol_thread_detach): Likewise.
	* target-debug.h (target_debug_print_inferior_p): New macro.
	* target-delegates.c: Re-generate.
	* top.c (kill_or_detach): Pass inferior down to target_detach.
	* windows-nat.c (windows_detach): Add inferior parameter.
2018-01-19 11:47:57 -05:00
Simon Marchi 6bd6f3b656 Remove args from target detach
I was looking into adding a parameter to target_detach, and was
wondering what the args parameter was.  It seems like in the distant
past, it was possible to specify a signal number when detaching.  That
signal was injected in the process before it was detached.  There is an
example of code handling this in linux_nat_detach.  With today's GDB, I
can't get this to work.  Doing "detach 15" (15 == SIGTERM) doesn't work,
because detach is a prefix command and doesn't recognize the sub-command
15.  Doing "detach inferiors 15" doesn't work because it expects a list
of inferior id to detach.  Therefore, I don't think there's a way of
invoking detach_command with a non-NULL args.  I also didn't find any
documentation related to this feature.

I assume that this feature stopped working when detach was made a prefix
command, which is in f73adfeb8b (sorry,
there's no commit title) from 2006.  Given that this feature was broken
for such a long time and we haven't heard anything (AFAIK, I did not
find any related bug), I think it's safe to remove it, as well as the
args parameter to target_detach.  If someone wants to re-introduce it, I
would suggest rethinking the user interface, and in particular would
suggest using signal name instead of numbers.

I tried to fix all the impacted code, but I might have forgotten some
spots.  It shouldn't be hard to fix if that's the case.  I also couldn't
build-test everything I changed, especially the nto and solaris stuff.

gdb/ChangeLog:

	* target.h (struct target_ops) <to_detach>: Remove args
	parameter.
	(target_detach): Likewise.
	* target.c (dispose_inferior): Adjust.
	(target_detach): Remove args parameter, adjust.
	* aix-thread.c (aix_thread_detach): Adjust.
	* corefile.c (core_file_command): Adjust.
	* corelow.c (core_detach): Adjust.
	* darwin-nat.c (darwin_detach): Adjust.
	* gnu-nat.c (gnu_detach): Adjust.
	* inf-ptrace.c (inf_ptrace_detach): Adjust.
	* infcmd.c (detach_command): Adjust
	* infrun.c (follow_fork_inferior): Adjust.
	(handle_vfork_child_exec_or_exit): Adjust.
	* linux-fork.c (linux_fork_detach): Remove args parameter.
	* linux-fork.h (linux_fork_detach): Likewise.
	* linux-nat.c (linux_nat_detach): Likewise, and adjust.
	* linux-thread-db.c (thread_db_detach): Likewise.
	* nto-procfs.c (procfs_detach): Likewise.
	* procfs.c (procfs_detach): Likewise.
	(do_detach): Remove signo parameter.
	* record.c (record_detach): Remove args parameter.
	* record.h (record_detach): Likewise.
	* remote-sim.c (gdbsim_detach): Likewise.
	* remote.c (remote_detach_1): Likewise.
	(remote_detach): Likewise.
	(extended_remote_detach): Likewise.
	* sol-thread.c (sol_thread_detach): Likewise.
	* target-delegates.c: Re-generate.
	* top.c (struct qt_args) <args>: Remove field.
	(kill_or_detach): Don't pass args.
	(quit_force): Don't set args.
	* windows-nat.c (windows_detach): Remove args parameter.
2018-01-19 11:47:24 -05:00
Pedro Alves 649a140ccf target_set_syscall_catchpoint, use gdb::array_view and bool
I noticed that we're passing down a data/size pair to
target_ops::to_set_syscall_catchpoint.  This commit makes use of
gdb::array_view instead.  While at it, use bool where appropriate as
well.

gdb/ChangeLog:

	* break-catch-syscall.c (insert_catch_syscall)
	(remove_catch_syscall): Adjust to pass reference to
	inf_data->syscalls_counts directly via gdb::array_view.
	* fbsd-nat.c (fbsd_set_syscall_catchpoint): Adjust to use bool
	and gdb::array_view.
	* linux-nat.c (linux_child_set_syscall_catchpoint): Likewise.
	* remote.c (remote_set_syscall_catchpoint): Likewise.
	* target-debug.h (target_debug_print_bool): New.
	(define target_debug_print_gdb_array_view_const_int): New.
	* target-delegates.c: Regenerate.
	* target.h (target_ops) <to_set_syscall_catchpoint>: Use
	gdb::array_view and bool.
	(target_set_syscall_catchpoint): Likewise.
2017-12-06 17:49:37 -05:00
Simon Marchi 1e97a22796 Remove mem_region_vector typedef
Now that make-target-delegates understands namespaces and templates,
this typedef is no longer useful.

gdb/ChangeLog:

	* target.h (mem_region_vector): Remove.
	(struct target_ops) <to_memory_map>: Change return type to
	std::vector<mem_region>.
	* target-debug.h (target_debug_print_mem_region_vector): Rename
	to ...
	(target_debug_print_std_vector_mem_region): ... this.
	* target-delegates.c: Re-generate.
2017-12-03 13:06:14 -05:00
Pedro Alves 10f6417841 Make make-target-delegates grok namespace scope op and template params
The next patch will want to use gdb::array_view<int> as parameter type
of a target_ops method.  However, that runs into a
make-target-delegates limitation: target_debug_foo calls in
target-delegates.c for parameters/return types with namespace scope
operators ("::") or template parameters, end up looking like:

 @@ -1313,9 +1313,7 @@ debug_set_syscall_catchpoint (struct target_ops *self, int arg1, int arg2, int a
    fputs_unfiltered (", ", gdb_stdlog);
    target_debug_print_int (arg3);
    fputs_unfiltered (", ", gdb_stdlog);
 -  target_debug_print_int (arg4);
 -  fputs_unfiltered (", ", gdb_stdlog);
 -  target_debug_print_int_p (arg5);
 +  target_debug_print_gdb::array_view<const_int> (arg4);

which obviously isn't something that compiles.  The problem is that
make-target-delegates wasn't ever taught that '::', '<', and '>' can
appear in parameter/return types.  You could work around it by hidding
the unsupported characters behind a typedef in the target method
declaration, or by using an explicit TARGET_DEBUG_PRINTER, but it's
better to just remove the limitation.

While at it, also fix an "abuse" of reserved identifiers.

gdb/ChangeLog:

	* make-target-delegates (munge_type): Also munge '<', '>', and
	':'.  Avoid double underscores in identifiers, and trailing
	underscores.
	* target-debug.h
	(target_debug_print_VEC_static_tracepoint_marker_p__p): Rename to
	...
	(target_debug_print_VEC_static_tracepoint_marker_p_p): ... this.
	* target-delegates.c: Regenerate.
2017-12-03 12:50:43 -05:00
Simon Marchi a664f67e50 Get rid of VEC (mem_region)
This patch removes VEC (mem_region).  Doing so requires touching a lot
of little things here and there.

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

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

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

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

Regtested on the buildbot.

gdb/ChangeLog:

	* memattr.h: Don't include vec.h.
	(struct mem_attrib): Initialize fields.
	<unknown>: New static method.
	(struct mem_region): Add constructors, operator<, initialize
	fields.
	* memattr.c: Include algorithm.
	(default_mem_attrib, unknown_mem_attrib): Remove.
	(user_mem_region_list): New global.
	(target_mem_region_list, mem_region_list): Change type to
	std::vector<mem_region>.
	(mem_use_target): Now a function.
	(target_mem_regions_valid): Change type to bool.
	(mem_region_lessthan, mem_region_cmp, mem_region_init): Remove.
	(require_user_regions): Adjust.
	(require_target_regions): Adjust.
	(create_mem_region): Adjust.
	(lookup_mem_region): Adjust.
	(invalidate_target_mem_regions): Adjust.
	(mem_clear): Rename to...
	(user_mem_clear): ... this, and adjust.
	(mem_command): Adjust.
	(info_mem_command): Adjust.
	(mem_enable, enable_mem_command, mem_disable,
	disable_mem_command): Adjust.
	(mem_delete): Adjust.
	(delete_mem_command): Adjust.
	* memory-map.h (parse_memory_map): Return an std::vector.
	* memory-map.c (parse_memory_map): Likewise.
	(struct memory_map_parsing_data): Add constructor.
	<memory_map>: Point to std::vector.
	(memory_map_start_memory): Adjust.
	(memory_map_end_memory): Adjust.
	(memory_map_end_property): Adjust.
	(clear_result): Remove.
	* remote.c (remote_memory_map): Return an std::vector.
	* target-debug.h (target_debug_print_VEC_mem_region_s__p):
	Remove.
	(target_debug_print_mem_region_vector): New.
	* target-delegates.c: Regenerate.
	* target.h (mem_region_vector): New typedef.
	(to_memory_map): Return mem_region_vector.
	(target_memory_map): Return an std::vector.
	* target.c (target_memory_map): Return an std::vector.
	(flash_erase_command): Adjust.
2017-10-21 12:15:42 -04:00
Simon Marchi 2098b39391 Make to_traceframe_info return a unique_ptr
Since this target method returns an allocated object, return a
unique_ptr.  It allows getting rid a some cleanups here and there.

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

Regression tested on the buildbot.

gdb/ChangeLog:

	* target.h: Include tracepoint.h.
	(enum trace_find_type): Move to tracepoint.h.
	(struct target_ops) <to_traceframe_info>: Return a unique ptr.
	* tracepoint.h: Don't include target.h
	(enum trace_find_type): Move from target.h.
	(parse_traceframe_info): Return a unique ptr.
	* tracepoint.c (current_traceframe_info): Change type to unique
	ptr.
	(free_traceframe_info): Remove.
	(clear_traceframe_info): Don't manually free
	current_traceframe_info.
	(free_result): Remove.
	(parse_traceframe_info): Return a unique ptr.
	(get_traceframe_info): Adjust to unique ptr.
	* ctf.c (ctf_traceframe_info): Return a unique ptr.
	* remote.c (remote_traceframe_info): Return a unique ptr.
	* tracefile-tfile.c (tfile_traceframe_info): Return a unique
	ptr.
	* target-debug.h (target_debug_print_traceframe_info_up): New
	macro.
	* target-delegates.c: Regenerate.
2017-10-14 08:47:44 -04:00
Kevin Buettner e04ee09e24 Add target method for converting thread handle to thread_info struct pointer
This patch adds a target method named `to_thread_handle_to_thread_info'.
It is intended to map a thread library specific thread handle (such as
pthread_t for the pthread library) to the corresponding GDB internal
thread_info struct (pointer).

An implementation is provided for Linux pthreads; see linux-thread-db.c.

gdb/ChangeLog:

	* target.h (struct target_ops): Add to_thread_handle_to_thread_info.
	(target_thread_handle_to_thread_info): Declare.
	* target.c (target_thread_handle_to_thread_info): New function.
	* target-delegates.c: Regenerate.
	* gdbthread.h (find_thread_by_handle): Declare.
	* thread.c (find_thread_by_handle): New function.
	* linux-thread-db.c (thread_db_thread_handle_to_thread_info): New
	function.
	(init_thread_db_ops): Register thread_db_thread_handle_to_thread_info.
2017-09-21 11:19:10 -07:00
Pedro Alves 9a24775b97 Introduce gdb_disassembly_flags
For some reason I ended up staring at some of the "int flags" in
btrace-related code, and I got confused because I had no clue what the
flags where supposed to indicate.

Fix that by using enum_flags, so that:
  #1 - it's clear from the type what the flags are about, and
  #2 - the compiler can catch mismatching mistakes

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

	* cli/cli-cmds.c (print_disassembly, disassemble_current_function)
	(disassemble_command): Use gdb_disassembly_flags instead of bare
	int.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn)
	(dump_insns, do_mixed_source_and_assembly_deprecated)
	(do_mixed_source_and_assembly, do_assembly_only, gdb_disassembly):
	Use gdb_disassembly_flags instead of bare int.
	* disasm.h (DISASSEMBLY_SOURCE_DEPRECATED, DISASSEMBLY_RAW_INSN)
	(DISASSEMBLY_OMIT_FNAME, DISASSEMBLY_FILENAME)
	(DISASSEMBLY_OMIT_PC, DISASSEMBLY_SOURCE)
	(DISASSEMBLY_SPECULATIVE): No longer macros.  Instead they're...
	(enum gdb_disassembly_flag): ... values of this new enumeration.
	(gdb_disassembly_flags): Define.
	(gdb_disassembly)
	(gdb_pretty_print_disassembler::pretty_print_insn): Use it.
	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Use
	gdb_disassembly_flags instead of bare int.
	* record-btrace.c (btrace_insn_history)
	(record_btrace_insn_history, record_btrace_insn_history_range)
	(record_btrace_insn_history_from): Use gdb_disassembly_flags
	instead of bare int.
	* record.c (get_insn_history_modifiers, cmd_record_insn_history):
	Use gdb_disassembly_flags instead of bare int.
	* target-debug.h (target_debug_print_gdb_disassembly_flags):
	Define.
	* target-delegates.c: Regenerate.
	* target.c (target_insn_history, target_insn_history_from)
	(target_insn_history_range): Use gdb_disassembly_flags instead of
	bare int.
	* target.h: Include "disasm.h".
	(struct target_ops) <to_insn_history, to_insn_history_from,
	to_insn_history_range>: Use gdb_disassembly_flags instead of bare
	int.
	(target_insn_history, target_insn_history_from)
	(target_insn_history_range): Use gdb_disassembly_flags instead of
	bare int.
2017-09-04 18:23:22 +01:00
Pedro Alves 7a1149643d -Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info
-Wwrite-strings flagged a missing cast for example here:

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

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

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

	* aix-thread.c (aix_thread_pid_to_str)
	(aix_thread_extra_thread_info): Constify.
	* bsd-kvm.c (bsd_kvm_pid_to_str): Constify.
	* bsd-uthread.c (bsd_uthread_extra_thread_info)
	(bsd_uthread_pid_to_str): Constify.
	* corelow.c (core_pid_to_str): Constify.
	* darwin-nat.c (darwin_pid_to_str): Constify.
	* fbsd-nat.c (fbsd_pid_to_str): Constify.
	* fbsd-tdep.c (fbsd_core_pid_to_str, gdbarch_core_pid_to_str):
	Constify.
	* gnu-nat.c (gnu_pid_to_str): Constify.
	* go32-nat.c (go32_pid_to_str): Constify.
	* i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Constify.
	* inf-ptrace.c (inf_ptrace_pid_to_str): Constify.
	* inferior.c (inferior_pid_to_str): Constify.
	* linux-nat.c (linux_nat_pid_to_str): Constify.
	* linux-tdep.c (linux_core_pid_to_str): Constify.
	* linux-thread-db.c (thread_db_pid_to_str)
	(thread_db_extra_thread_info): Constify.
	* nto-tdep.c (nto_extra_thread_info): Constify.
	* nto-tdep.h (nto_extra_thread_info): Constify.
	* obsd-nat.c (obsd_pid_to_str): Constify.
	* procfs.c (procfs_pid_to_str): Constify.
	* ravenscar-thread.c (ravenscar_extra_thread_info)
	(ravenscar_pid_to_str): Constify.
	* remote-sim.c (gdbsim_pid_to_str): Constify.
	* remote.c (remote_threads_extra_info, remote_pid_to_str):
	Constify.
	* sol-thread.c (solaris_pid_to_str): Constify.
	* sol2-tdep.c (sol2_core_pid_to_str): Constify.
	* sol2-tdep.h (sol2_core_pid_to_str): Constify.
	* target.c (default_pid_to_str, target_pid_to_str)
	(normal_pid_to_str, default_pid_to_str): Constify.
	* target.h (target_ops::to_pid_to_str)
	(target_ops::to_extra_thread_info): Constify.
	(target_pid_to_str, normal_pid_to_str): Constify.
	* windows-nat.c (windows_pid_to_str): Constify.
	* gdbarch.sh (core_pid_to_str): Constify.
	* target-delegates.c: Regenerate.
	* gdbarch.h, gdbarch.c: Regenerate.
2017-04-05 19:21:34 +01:00
Tim Wiederhake b158a20f26 Add method to query current recording method to target_ops.
Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>

gdb/ChangeLog

	* record-btrace.c (record_btrace_record_method): New function.
	(init_record_btrace_ops): Initialize to_record_method.
	* record-full.c (record_full_record_method): New function.
	(init_record_full_ops, init_record_full_core_ops): Add
	record_full_record_method.
	* record.h (enum record_method): New enum.
	* target-debug.h (target_debug_print_enum_record_method: New define.
	* target-delegates.c: Regenerate.
	* target.c (target_record_method): New function.
	* target.h: Include record.h.
	(struct target_ops) <to_record_method>: New field.
	(target_record_method): New export.

Change-Id: I05daa70e4e08a19901e848c731bb7d60cd87cc5a
2017-02-14 10:57:56 +01:00
Pedro Alves 85ad3aaf40 gdb: Coalesce/aggregate (async) vCont packets/actions
Currently, with "maint set target-non-stop on", that is, when gdb
connects with the non-stop/asynchronous variant of the remote
protocol, even with "set non-stop off", GDB always sends one vCont
packet per thread resumed.  This patch makes GDB aggregate and
coalesce vCont packets, so we send vCont packets like "vCont;s:p1.1;c"
in non-stop mode too.

Basically, this is done by:

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

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

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

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

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

  vCont;s:1;c

overflows the packet buffer, we split the actions like:

  vCont;s:1
  vCont;c

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

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

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

	* inferior.h (ALL_NON_EXITED_INFERIORS): New macro.
	* infrun.c (do_target_resume): Call target_commit_resume.
	(proceed): Defer target_commit_resume while looping over threads,
	resuming them.  Call target_commit_resume at the end.
	* record-btrace.c (record_btrace_commit_resume): New function.
	(init_record_btrace_ops): Install it as to_commit_resume method.
	* record-full.c (record_full_commit_resume): New function.
	(record_full_wait_1): Call the beneath target's to_commit_resume
	method.
	(init_record_full_ops): Install record_full_commit_resume as
	to_commit_resume method.
	* remote.c (struct private_thread_info) <last_resume_step,
	last_resume_sig, vcont_resumed>: New fields.
	(remote_add_thread): Set the new thread's vcont_resumed flag.
	(demand_private_info): Delete.
	(get_private_info_thread, get_private_info_ptid): New functions.
	(remote_update_thread_list): Adjust.
	(process_initial_stop_replies): Clear the thread's vcont_resumed
	flag.
	(remote_resume): If connected in non-stop mode, record the resume
	request and return early.
	(struct private_inferior): New.
	(struct vcont_builder): New.
	(vcont_builder_restart, vcont_builder_flush)
	(vcont_builder_push_action): New functions.
	(MAX_ACTION_SIZE): New macro.
	(remote_commit_resume): New function.
	(thread_pending_fork_status, is_pending_fork_parent_thread): New
	functions.
	(check_pending_event_prevents_wildcard_vcont_callback)
	(check_pending_events_prevent_wildcard_vcont): New functions.
	(process_stop_reply): Adjust.  Clear the thread's vcont_resumed
	flag.
	(init_remote_ops): Install remote_commit_resume.
	* target-delegates.c: Regenerate.
	* target.c (defer_target_commit_resume): New global.
	(target_commit_resume, make_cleanup_defer_target_commit_resume):
	New functions.
	* target.h (struct target_ops) <to_commit_resume>: New field.
	(target_resume): Update comments.
	(target_commit_resume): New declaration.
2016-10-26 16:22:50 +01:00
Pedro Alves 7397181903 Plumb enum remove_bp_reason all the way to target_remove_breakpoint
So the target knows whether we're detaching breakpoints.
Nothing uses the parameter in this patch yet.

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

	PR gdb/19187
	* break-catch-sig.c (signal_catchpoint_remove_location): Adjust
	interface.
	* break-catch-syscall.c (remove_catch_syscall):
	* breakpoint.c (enum remove_bp_reason): Moved to breakpoint.h.
	(remove_breakpoint_1): Pass 'reason' down.
	(remove_catch_fork, remove_catch_vfork, remove_catch_solib)
	(remove_catch_exec, remove_watchpoint, remove_masked_watchpoint)
	(base_breakpoint_remove_location, bkpt_remove_location)
	(bkpt_probe_remove_location, bkpt_probe_remove_location): Adjust
	interface.
	* breakpoint.h (enum remove_bp_reason): Moved here from
	breakpoint.c.
	(struct breakpoint_ops) <remove_location>: Add 'reason' parameter.
	* corelow.c (core_remove_breakpoint): New function.
	(init_core_ops): Install it as to_remove_breakpoint method.
	* exec.c (exec_remove_breakpoint): New function.
	(init_exec_ops): Install it as to_remove_breakpoint method.
	* mem-break.c (memory_remove_breakpoint): Adjust interface.
	* record-btrace.c (record_btrace_remove_breakpoint): Adjust
	interface.
	* record-full.c (record_full_remove_breakpoint)
	(record_full_core_remove_breakpoint): Adjust interface.
	* remote.c (remote_remove_breakpoint): Adjust interface.
	* target-debug.h (target_debug_print_enum_remove_bp_reason): New
	macro.
	* target-delegates.c: Regenerate.
	* target.c (target_remove_breakpoint): Add 'reason' parameter.
	* target.h (struct target_ops) <to_remove_breakpoint>: Add
	'reason' parameter.
	(target_remove_breakpoint, memory_remove_breakpoint): Add 'reason'
	parameter.
2016-08-10 23:03:29 +01:00
Don Breazeal 09c98b448f Optimize memory_xfer_partial for remote
Some analysis we did here showed that increasing the cap on the
transfer size in target.c:memory_xfer_partial could give 20% or more
improvement in remote load across JTAG.  Transfer sizes were capped
to 4K bytes because of performance problems encountered with the
restore command, documented here:

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

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

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

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

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

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

gdb/ChangeLog:

	* remote.c (remote_get_memory_xfer_limit): New function.
	* target-delegates.c: Regenerate.
	* target.c (memory_xfer_partial): Call
	target_ops.to_get_memory_xfer_limit.
	* target.h (struct target_ops)
	<to_get_memory_xfer_limit>: New member.
2016-07-01 11:13:48 -07:00
Pedro Alves cfd0fbddb0 Eliminate target_check_pending_interrupt
This is no longer called anywhere.

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

	* target.c (target_check_pending_interrupt): Delete.
	* target.h (struct target_ops) <to_check_pending_interrupt>:
	Remove method.
	(target_check_pending_interrupt): Remove declaration.
	* target-delegates.c: Regenerate.
2016-04-12 17:02:06 +01:00
Pedro Alves 93692b589d Pass Ctrl-C to the target in target_terminal_inferior
If the user presses Ctrl-C immediately before target_terminal_inferior
is called and the target is resumed, instead of after, the Ctrl-C ends
up pending in the quit flag until the target next stops.

remote.c has this bit to handle this:

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

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

This patch generalizes that to all targets.

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

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

	* remote.c (remote_pass_ctrlc): New function.
	(init_remote_ops): Install it.
	* target.c (target_terminal_inferior): Pass pending Ctrl-C to the
	target.
	(target_pass_ctrlc, default_target_pass_ctrlc): New functions.
	* target.h (struct target_ops) <to_pass_ctrlc>: New method.
	(target_pass_ctrlc, default_target_pass_ctrlc): New declarations.
	* target-delegates.c: Regenerate.
2016-04-12 16:57:10 +01:00
Pedro Alves 65706a29ba Remote thread create/exit events
When testing with "maint set target-non-stop on", a few
threading-related tests expose an issue that requires new RSP packets.

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

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

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

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

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

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

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

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

	* NEWS (New commands): Mention "set/show remote thread-events"
	commands.
	(New remote packets): Mention thread created/exited stop reasons
	and QThreadEvents packet.
	* infrun.c (disable_thread_events): New function.
	(stop_all_threads): Disable/enable thread create/exit events.
	Handle TARGET_WAITKIND_THREAD_EXITED.
	(handle_inferior_event_1): Handle TARGET_WAITKIND_THREAD_CREATED
	and TARGET_WAITKIND_THREAD_EXITED.
	* remote.c (remove_child_of_pending_fork): Also remove threads of
	threads that have TARGET_WAITKIND_THREAD_EXITED events.
	(remote_parse_stop_reply): Handle "create" magic register.  Handle
	'w' stop reply.
	(initialize_remote): Install remote_thread_events as
	to_thread_events target hook.
	(remote_thread_events): New function.
	* target-delegates.c: Regenerate.
	* target.c (target_thread_events): New function.
	* target.h (struct target_ops) <to_thread_events>: New field.
	(target_thread_events): Declare.
	* target/waitstatus.c (target_waitstatus_to_string): Handle
	TARGET_WAITKIND_THREAD_CREATED and TARGET_WAITKIND_THREAD_EXITED.
	* target/waitstatus.h (enum target_waitkind)
	<TARGET_WAITKIND_THREAD_CREATED, TARGET_WAITKIND_THREAD_EXITED):
	New values.
2015-11-30 18:40:30 +00:00
Simon Marchi 73ede76585 Constify thread name return path
Since this code path returns a string owned by the target (we don't know how
it's allocated, could be a static read-only string), it's safer if we return
a constant string.  If, for some reasons, the caller wishes to modify the
string, it should make itself a copy.

gdb/ChangeLog:

	* linux-nat.c (linux_nat_thread_name): Constify return value.
	* target.h (struct target_ops) <to_thread_name>: Likewise.
	(target_thread_name): Likewise.
	* target.c (target_thread_name): Likewise.
	* target-delegates.c (debug_thread_name): Regenerate.
	* python/py-infthread.c (thpy_get_name): Constify local variables.
	* thread.c (print_thread_info): Likewise.
	(thread_find_command): Likewise.
2015-11-26 09:49:03 -05:00
Simon Marchi f4b0a6714a target_ops mask_watchpoint: change int to target_hw_bp_type
Fixes:

/home/simark/src/binutils-gdb/gdb/ppc-linux-nat.c: In function ‘int ppc_linux_insert_mask_watchpoint(target_ops*, CORE_ADDR, CORE_ADDR, int)’:
/home/simark/src/binutils-gdb/gdb/ppc-linux-nat.c:1730:40: error: invalid conversion from ‘int’ to ‘target_hw_bp_type’ [-fpermissive]
   p.trigger_type = get_trigger_type (rw);
                                        ^

gdb/ChangeLog:

	* ppc-linux-nat.c (ppc_linux_insert_mask_watchpoint): Change
	type of rw to enum target_hw_bp_type.
	(ppc_linux_remove_mask_watchpoint): Likewise.
	* target.c (target_insert_mask_watchpoint): Likewise.
	(target_remove_mask_watchpoint): Likewise.
	* target.h (target_insert_mask_watchpoint): Likewise.
	(target_remove_mask_watchpoint): Likewise.
	(struct target_ops) <to_insert_mask_watchpoint>: Likewise.
	(struct target_ops) <to_remove_mask_watchpoint>: Likewise.
	* target-delegates.c: Regenerate.
2015-11-03 13:33:12 -05:00
Markus Metzger 7ff27e9bab target: add to_record_will_replay target method
Add a new target method to_record_will_replay to query if there is a record
target that will replay at least one thread matching the argument PTID if it
were executed in the argument execution direction.

gdb/
	* record-btrace.c ((record_btrace_will_replay): New.
	(init_record_btrace_ops): Initialize to_record_will_replay.
	* record-full.c ((record_full_will_replay): New.
	(init_record_full_ops): Initialize to_record_will_replay.
	* target-delegates.c: Regenerated.
	* target.c (target_record_will_replay): New.
	* target.h (struct target_ops) <to_record_will_replay>: New.
	(target_record_will_replay): New.

Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
2015-09-18 14:30:49 +02:00
Markus Metzger 797094dddf target: add to_record_stop_replaying target method
Add a new target method to_record_stop_replaying to stop replaying.

gdb/
	* record-btrace.c (record_btrace_resume): Call
	target_record_stop_replaying.
	(record_btrace_stop_replaying_all): New.
	(init_record_btrace_ops): Initialize to_record_stop_replaying.
	* record-full.c (record_full_stop_replaying): New.
	(init_record_full_ops ): Initialize to_record_stop_replaying.
	* target-delegates.c: Regenerated.
	* target.c (target_record_stop_replaying): New.
	* target.h (struct target_ops) <to_record_stop_replaying>: New.
	(target_record_stop_replaying): New.
2015-09-18 14:30:12 +02:00
Markus Metzger a52eab4808 target, record: add PTID argument to to_record_is_replaying
The to_record_is_replaying target method is used to query record targets if
they are replaying.  This is currently interpreted as "is any thread being
replayed".

Add a PTID argument and change the interpretation to "is any thread matching
PTID being replayed".

Change all users to pass minus_one_ptid to preserve the old meaning.

The record full target does not really support multi-threading and ignores
the PTID argument.

gdb/
	* record-btrace.c (record_btrace_is_replaying): Add ptid argument.
	Update users to pass minus_one_ptid.
	* record-full.c (record_full_is_replaying): Add ptid argument (ignored).
	* record.c (cmd_record_delete): Pass inferior_ptid to
	target_record_is_replaying.
	* target-delegates.c: Regenerated.
	* target.c (target_record_is_replaying): Add ptid argument.
	* target.h (struct target_ops) <to_record_is_replaying>: Add ptid
	argument.
	(target_record_is_replaying): Add ptid argument.
2015-09-18 14:28:43 +02:00
Yao Qi 750ce8d1ca Support single step by arch or target
Nowadays, GDB only knows whether architecture supports hardware single
step or software single step (through gdbarch hook software_single_step),
and for a given instruction or instruction sequence, GDB knows how to
do single step (hardware or software).  However, GDB doesn't know whether
the target supports hardware single step.  It is possible that the
architecture doesn't support hardware single step, such as arm, but
the target supports, such as simulator.  This was discussed in this
thread https://www.sourceware.org/ml/gdb/2009-12/msg00033.html before.

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

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

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

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

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

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

 <- vCont;c;C;t

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

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

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

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

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

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

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

gdb:

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

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

gdb/gdbserver:

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

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

gdb/doc:

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

	* gdb.texinfo (General Query Packets): Add vContSupported to
	tables of 'gdbfeatures' and 'stub features' supported in the
	qSupported packet, as well as to the list containing stub
	feature details.
2015-09-15 14:09:18 +01:00
Don Breazeal 94585166df Extended-remote follow-exec
This patch implements support for exec events on extended-remote Linux
targets.  Follow-exec-mode and rerun behave as expected.  Catchpoints and
test updates are implemented in subsequent patches.

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

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

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

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

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

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

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

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

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

gdb/gdbserver/ChangeLog:

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

gdb/ChangeLog:

	* infrun.c (follow_exec): Use process-style ptid for
	exec message.  Call add_inferior_with_spaces and
	target_follow_exec.
	* nat/linux-ptrace.c (linux_supports_traceexec): New function.
	* nat/linux-ptrace.h (linux_supports_traceexec): Declare.
	* remote.c (remote_pspace_data): New static variable.
	(remote_pspace_data_cleanup): New function.
	(get_remote_exec_file): New function.
	(set_remote_exec_file_1): New function.
	(set_remote_exec_file): New function.
	(show_remote_exec_file): New function.
	(remote_exec_file): Delete static variable.
	(anonymous enum) <PACKET_exec_event_feature> New
	enumeration constant.
	(remote_protocol_features): Add entry for exec-events feature.
	(remote_query_supported): Add client side of qSupported query
	for exec-events feature.
	(remote_follow_exec): New function.
	(remote_parse_stop_reply): Handle 'exec' stop reason.
	(extended_remote_run, extended_remote_create_inferior): Call
	get_remote_exec_file and set_remote_exec_file_1.
	(init_extended_remote_ops) <to_follow_exec>: Initialize new
	member.
	(_initialize_remote): Call
	register_program_space_data_with_cleanup.  Call
	add_packet_config_cmd for remote exec-events feature.
	Modify call to add_setshow_string_noescape_cmd for exec-file
	to use new functions set_remote_exec_file and
	show_remote_exec_file.
	* target-debug.h, target-delegates.c: Regenerated.
	* target.c (target_follow_exec): New function.
	* target.h (struct target_ops) <to_follow_exec>: New member.
	(target_follow_exec): Declare new function.
2015-09-11 11:12:46 -07:00
Pedro Alves 0b333c5e7d Merge async and sync code paths some more
This patch makes the execution control code use largely the same
mechanisms in both sync- and async-capable targets.  This means using
continuations and use the event loop to react to target events on sync
targets as well.  The trick is to immediately mark infrun's event loop
source after resume instead of calling wait_for_inferior.  Then
fetch_inferior_event is adjusted to do a blocking wait on sync
targets.

Tested on x86_64 Fedora 20, native and gdbserver, with and without
"maint set target-async off".

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

	* breakpoint.c (bpstat_do_actions_1, until_break_command): Don't
	check whether the target can async.
	* inf-loop.c (inferior_event_handler): Only call target_async if
	the target can async.
	* infcall.c: Include top.h and interps.h.
	(run_inferior_call): For the interpreter to sync mode while
	running the infcall.  Call wait_sync_command_done instead of
	wait_for_inferior plus normal_stop.
	* infcmd.c (prepare_execution_command): Don't check whether the
	target can async when running in the foreground.
	(step_1): Delete synchronous case handling.
	(step_once): Always install a continuation, even in sync mode.
	(until_next_command, finish_forward): Don't check whether the
	target can async.
	(attach_command_post_wait, notice_new_inferior): Always install a
	continuation, even in sync mode.
	* infrun.c (mark_infrun_async_event_handler): New function.
	(proceed): In sync mode, mark infrun's event source instead of
	waiting for events here.
	(fetch_inferior_event): If the target can't async, do a blocking
	wait.
	(prepare_to_wait): In sync mode, mark infrun's event source.
	(infrun_async_inferior_event_handler): No longer bail out if the
	target can't async.
	* infrun.h (mark_infrun_async_event_handler): New declaration.
	* linux-nat.c (linux_nat_wait_1): Remove calls to
	set_sigint_trap/clear_sigint_trap.
	(linux_nat_terminal_inferior): No longer check whether the target
	can async.
	* mi/mi-interp.c (mi_on_sync_execution_done): Update and simplify
	comment.
	(mi_execute_command_input_handler): No longer check whether the
	target is async.  Update and simplify comment.
	* target.c (default_target_wait): New function.
	* target.h (struct target_ops) <to_wait>: Now defaults to
	default_target_wait.
	(default_target_wait): Declare.
	* top.c (wait_sync_command_done): New function, factored out from
	...
	(maybe_wait_sync_command_done): ... this.
	* top.h (wait_sync_command_done): Declare.
	* target-delegates.c: Regenerate.
2015-09-09 18:23:23 +01:00
Pedro Alves abc56d60aa remote: allow aborting long operations (e.g., file transfers)
Currently, when remote debugging, if you type Ctrl-C just while the
target stopped for an internal event, and GDB is busy doing something
that takes a while (e.g., fetching chunks of a shared library off of
the target, with vFile, to process ELF headers and debug info), the
Ctrl-C is lost.

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

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

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

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

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

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

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

Tested on x86_64 Fedora 20.

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

	* defs.h (maybe_quit): Declare.
	(QUIT): Now calls maybe_quit.
	* event-loop.c (clear_async_signal_handler)
	(async_signal_handler_is_marked): New functions.
	* event-loop.h (async_signal_handler_is_marked)
	(clear_async_signal_handler): New declarations.
	* remote.c (remote_check_pending_interrupt): New function.
	(interrupt_query): Use make_cleanup_restore_target_terminal.  No
	longer check whether the target is async.  If waiting for a stop
	reply, and a Ctrl-C as been sent to the target, offer to
	disconnect, and throw TARGET_CLOSE_ERROR instead of a quit.
	Otherwise do not disconnect and throw a quit.
	(_initialize_remote): Install remote_check_pending_interrupt as
	to_check_pending_interrupt.
	* target.c (target_check_pending_interrupt): New function.
	* target.h (struct target_ops) <to_check_pending_interrupt>: New
	field.
	(target_check_pending_interrupt): New declaration.
	* utils.c (maybe_quit): New function.
	* target-delegates.c: Regenerate.
2015-08-25 16:12:11 +01:00
Pedro Alves bfedc46af3 Fix interrupt-noterm.exp on targets always in non-stop
With "maint set target-non-stop on" we get:

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

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

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

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

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

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

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

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

	* darwin-nat.c (darwin_stop): Rename to ...
	(darwin_interrupt): ... this.
	(_initialize_darwin_inferior): Adjust.
	* gnu-nat.c (gnu_stop): Delete.
	(gnu_target): Don't install gnu_stop.
	* inf-ptrace.c (inf_ptrace_stop): Rename to ...
	(inf_ptrace_interrupt): ... this.
	(inf_ptrace_target): Adjust.
	* infcmd.c (interrupt_target_1): Use target_interrupt instead of
	target_stop.
	* linux-nat (linux_nat_stop): Rename to ...
	(linux_nat_interrupt): ... this.
	(linux_nat_stop): Reimplement.
	(linux_nat_add_target): Install linux_nat_interrupt.
	* nto-procfs.c (nto_interrupt_twice): Rename to ...
	(nto_handle_sigint_twice): ... this.
	(nto_interrupt): Rename to ...
	(nto_handle_sigint): ... this.  Call target_interrupt instead of
	target_stop.
	(procfs_wait): Adjust.
	(procfs_stop): Rename to ...
	(procfs_interrupt): ... this.
	(init_procfs_targets): Adjust.
	* procfs.c (procfs_stop): Rename to ...
	(procfs_interrupt): ... this.
	(procfs_target): Adjust.
	* remote-m32r-sdi.c (m32r_stop): Rename to ...
	(m32r_interrupt): ... this.
	(init_m32r_ops): Adjust.
	* remote-sim.c (gdbsim_stop_inferior): Rename to ...
	(gdbsim_interrupt_inferior): ... this.
	(gdbsim_stop): Rename to ...
	(gdbsim_interrupt): ... this.
	(gdbsim_cntrl_c): Adjust.
	(init_gdbsim_ops): Adjust.
	* remote.c (sync_remote_interrupt): Adjust comments.
	(remote_stop_as): Rename to ...
	(remote_interrupt_as): ... this.
	(remote_stop): Adjust comment.
	(remote_interrupt): New function.
	(init_remote_ops): Install remote_interrupt.
	* target.c (target_interrupt): New function.
	* target.h (struct target_ops) <to_interrupt>: New field.
	(target_interrupt): New declaration.
	* windows-nat.c (windows_stop): Rename to ...
	(windows_interrupt): ... this.
	* target-delegates.c: Regenerate.
2015-08-07 17:26:20 +01:00
Pedro Alves fbea99ea8a Implement all-stop on top of a target running non-stop mode
This finally implements user-visible all-stop mode running with the
target_ops backend always in non-stop mode.  This is a stepping stone
towards finer-grained control of threads, being able to do interesting
things like thread groups, associating groups with breakpoints, etc.
From the user's perspective, all-stop mode is really just a special
case of being able to stop and resume specific sets of threads, so it
makes sense to do this step first.

With this, even in all-stop, the target is no longer in charge of
stopping all threads before reporting an event to the core -- the core
takes care of it when it sees fit.  For example, when "next"- or
"step"-ing, we can avoid stopping and resuming all threads at each
internal single-step, and instead only stop all threads when we're
about to present the stop to the user.

The implementation is almost straight forward, as the heavy lifting
has been done already in previous patches.  Basically, we replace
checks for "set non-stop on/off" (the non_stop global), with calls to
a new target_is_non_stop_p function.  In a few places, if "set
non-stop off", we stop all threads explicitly, and in a few other
places we resume all threads explicitly, making use of existing
methods that were added for teaching non-stop to step over breakpoints
without displaced stepping.

This adds a new "maint set target-non-stop on/off/auto" knob that
allows both disabling the feature if we find problems, and
force-enable it for development (useful when teaching a target about
this.  The default is "auto", which means the feature is enabled if a
new target method says it should be enabled.  The patch implements the
method in linux-nat.c, just for illustration, because it still returns
false.  We'll need a few follow up fixes before turning it on by
default.  This is a separate target method from indicating regular
non-stop support, because e.g., while e.g., native linux-nat.c is
close to regression free with all-stop-non-stop (with following
patches will fixing the remaining regressions), remote.c+gdbserver
will still need more fixing, even though it supports "set non-stop
on".

Tested on x86_64 Fedora 20, native, with and without "set displaced
off", and with and without "maint set target-non-stop on"; and also
against gdbserver.

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

	* NEWS: Mention "maint set/show target-non-stop".
	* breakpoint.c (update_global_location_list): Check
	target_is_non_stop_p instead of non_stop.
	* infcmd.c (attach_command_post_wait, attach_command): Likewise.
	* infrun.c (show_can_use_displaced_stepping)
	(can_use_displaced_stepping_p, start_step_over_inferior):
	Likewise.
	(internal_resume_ptid): New function.
	(resume): Use it.
	(proceed): Check target_is_non_stop_p instead of non_stop.  If in
	all-stop mode but the target is always in non-stop mode, start all
	the other threads that are implicitly resumed too.
	(for_each_just_stopped_thread, fetch_inferior_event)
	(adjust_pc_after_break, stop_all_threads): Check
	target_is_non_stop_p instead of non_stop.
	(handle_inferior_event): Likewise.  Handle detach-fork in all-stop
	with the target always in non-stop mode.
	(handle_signal_stop) <random signal>: Check target_is_non_stop_p
	instead of non_stop.
	(switch_back_to_stepped_thread): Check target_is_non_stop_p
	instead of non_stop.
	(keep_going_stepped_thread): Use internal_resume_ptid.
	(stop_waiting): If in all-stop mode, and the target is in non-stop
	mode, stop all threads.
	(keep_going_pass): Likewise, when starting a new in-line step-over
	sequence.
	* linux-nat.c (get_pending_status, select_event_lwp)
	(linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check
	target_is_non_stop_p instead of non_stop.
	(linux_nat_always_non_stop_p): New function.
	(linux_nat_stop): Check target_is_non_stop_p instead of non_stop.
	(linux_nat_add_target): Install linux_nat_always_non_stop_p.
	* target-delegates.c: Regenerate.
	* target.c (target_is_non_stop_p): New function.
	(target_non_stop_enabled, target_non_stop_enabled_1): New globals.
	(maint_set_target_non_stop_command)
	(maint_show_target_non_stop_command): New functions.
	(_initilize_target): Install "maint set/show target-non-stop"
	commands.
	* target.h (struct target_ops) <to_always_non_stop_p>: New field.
	(target_non_stop_enabled): New declaration.
	(target_is_non_stop_p): New declaration.

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

	* gdb.texinfo (Maintenance Commands): Document "maint set/show
	target-non-stop".
2015-08-07 17:24:01 +01:00
Simon Marchi f486487f55 Mostly trivial enum fixes
This is a patch I extracted from Pedro's C++ branch.  It contains the
most trivial enum fixes, where an integer type/value was used instead
of the appropriate enum type/value.  It fixes many C++ errors, since
in C++ you can't mix integers and enums implicitely.

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

Regression-tested on native x86_64.

gdb/ChangeLog:

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