public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] gdb: move all "current target" wrapper implementations to target.c
@ 2021-03-23 18:41 Simon Marchi
  2021-03-23 18:41 ` [PATCH 2/2] gdb: remove current_top_target function Simon Marchi
  2021-03-24  9:29 ` [PATCH 1/2] gdb: move all "current target" wrapper implementations to target.c Andrew Burgess
  0 siblings, 2 replies; 6+ messages in thread
From: Simon Marchi @ 2021-03-23 18:41 UTC (permalink / raw)
  To: gdb-patches

From: Simon Marchi <simon.marchi@polymtl.ca>

The following patch removes the current_top_target function, replacing
uses with `current_inferior ()->top_target ()`.  This is a problem for
uses in target.h, because they don't have access to the current_inferior
function and the inferior structure: target.h can't include inferior.h,
otherwise that would make a cyclic inclusion.

Avoid this by moving all implementations of the wrappers that call
target methods with the current target to target.c.  Many of them are
changed from a macro to a function, which is an improvement for
readability and debuggability, IMO.

target_shortname and target_longname were not function-like macros, so a
few adjustments are needed.

gdb/ChangeLog:

	* target.h (target_shortname): Change to function declaration.
	(target_longname): Likewise.
	(target_attach_no_wait): Likewise.
	(target_post_attach): Likewise.
	(target_prepare_to_store): Likewise.
	(target_supports_enable_disable_tracepoint): Likewise.
	(target_supports_string_tracing): Likewise.
	(target_supports_evaluation_of_breakpoint_conditions): Likewise.
	(target_supports_dumpcore): Likewise.
	(target_dumpcore): Likewise.
	(target_can_run_breakpoint_commands): Likewise.
	(target_files_info): Likewise.
	(target_post_startup_inferior): Likewise.
	(target_insert_fork_catchpoint): Likewise.
	(target_remove_fork_catchpoint): Likewise.
	(target_insert_vfork_catchpoint): Likewise.
	(target_remove_vfork_catchpoint): Likewise.
	(target_insert_exec_catchpoint): Likewise.
	(target_remove_exec_catchpoint): Likewise.
	(target_set_syscall_catchpoint): Likewise.
	(target_rcmd): Likewise.
	(target_can_lock_scheduler): Likewise.
	(target_can_async_p): Likewise.
	(target_is_async_p): Likewise.
	(target_execution_direction): Likewise.
	(target_extra_thread_info): Likewise.
	(target_pid_to_exec_file): Likewise.
	(target_thread_architecture): Likewise.
	(target_find_memory_regions): Likewise.
	(target_make_corefile_notes): Likewise.
	(target_get_bookmark): Likewise.
	(target_goto_bookmark): Likewise.
	(target_stopped_by_watchpoint): Likewise.
	(target_stopped_by_sw_breakpoint): Likewise.
	(target_supports_stopped_by_sw_breakpoint): Likewise.
	(target_stopped_by_hw_breakpoint): Likewise.
	(target_supports_stopped_by_hw_breakpoint): Likewise.
	(target_have_steppable_watchpoint): Likewise.
	(target_can_use_hardware_watchpoint): Likewise.
	(target_region_ok_for_hw_watchpoint): Likewise.
	(target_can_do_single_step): Likewise.
	(target_insert_watchpoint): Likewise.
	(target_remove_watchpoint): Likewise.
	(target_insert_hw_breakpoint): Likewise.
	(target_remove_hw_breakpoint): Likewise.
	(target_can_accel_watchpoint_condition): Likewise.
	(target_can_execute_reverse): Likewise.
	(target_get_ada_task_ptid): Likewise.
	(target_filesystem_is_local): Likewise.
	(target_trace_init): Likewise.
	(target_download_tracepoint): Likewise.
	(target_can_download_tracepoint): Likewise.
	(target_download_trace_state_variable): Likewise.
	(target_enable_tracepoint): Likewise.
	(target_disable_tracepoint): Likewise.
	(target_trace_start): Likewise.
	(target_trace_set_readonly_regions): Likewise.
	(target_get_trace_status): Likewise.
	(target_get_tracepoint_status): Likewise.
	(target_trace_stop): Likewise.
	(target_trace_find): Likewise.
	(target_get_trace_state_variable_value): Likewise.
	(target_save_trace_data): Likewise.
	(target_upload_tracepoints): Likewise.
	(target_upload_trace_state_variables): Likewise.
	(target_get_raw_trace_data): Likewise.
	(target_get_min_fast_tracepoint_insn_len): Likewise.
	(target_set_disconnected_tracing): Likewise.
	(target_set_circular_trace_buffer): Likewise.
	(target_set_trace_buffer_size): Likewise.
	(target_set_trace_notes): Likewise.
	(target_get_tib_address): Likewise.
	(target_set_permissions): Likewise.
	(target_static_tracepoint_marker_at): Likewise.
	(target_static_tracepoint_markers_by_strid): Likewise.
	(target_traceframe_info): Likewise.
	(target_use_agent): Likewise.
	(target_can_use_agent): Likewise.
	(target_augmented_libraries_svr4_read): Likewise.
	(target_log_command): Likewise.
	* target.c (target_shortname): New.
	(target_longname): New.
	(target_attach_no_wait): New.
	(target_post_attach): New.
	(target_prepare_to_store): New.
	(target_supports_enable_disable_tracepoint): New.
	(target_supports_string_tracing): New.
	(target_supports_evaluation_of_breakpoint_conditions): New.
	(target_supports_dumpcore): New.
	(target_dumpcore): New.
	(target_can_run_breakpoint_commands): New.
	(target_files_info): New.
	(target_post_startup_inferior): New.
	(target_insert_fork_catchpoint): New.
	(target_remove_fork_catchpoint): New.
	(target_insert_vfork_catchpoint): New.
	(target_remove_vfork_catchpoint): New.
	(target_insert_exec_catchpoint): New.
	(target_remove_exec_catchpoint): New.
	(target_set_syscall_catchpoint): New.
	(target_rcmd): New.
	(target_can_lock_scheduler): New.
	(target_can_async_p): New.
	(target_is_async_p): New.
	(target_execution_direction): New.
	(target_extra_thread_info): New.
	(target_pid_to_exec_file): New.
	(target_thread_architecture): New.
	(target_find_memory_regions): New.
	(target_make_corefile_notes): New.
	(target_get_bookmark): New.
	(target_goto_bookmark): New.
	(target_stopped_by_watchpoint): New.
	(target_stopped_by_sw_breakpoint): New.
	(target_supports_stopped_by_sw_breakpoint): New.
	(target_stopped_by_hw_breakpoint): New.
	(target_supports_stopped_by_hw_breakpoint): New.
	(target_have_steppable_watchpoint): New.
	(target_can_use_hardware_watchpoint): New.
	(target_region_ok_for_hw_watchpoint): New.
	(target_can_do_single_step): New.
	(target_insert_watchpoint): New.
	(target_remove_watchpoint): New.
	(target_insert_hw_breakpoint): New.
	(target_remove_hw_breakpoint): New.
	(target_can_accel_watchpoint_condition): New.
	(target_can_execute_reverse): New.
	(target_get_ada_task_ptid): New.
	(target_filesystem_is_local): New.
	(target_trace_init): New.
	(target_download_tracepoint): New.
	(target_can_download_tracepoint): New.
	(target_download_trace_state_variable): New.
	(target_enable_tracepoint): New.
	(target_disable_tracepoint): New.
	(target_trace_start): New.
	(target_trace_set_readonly_regions): New.
	(target_get_trace_status): New.
	(target_get_tracepoint_status): New.
	(target_trace_stop): New.
	(target_trace_find): New.
	(target_get_trace_state_variable_value): New.
	(target_save_trace_data): New.
	(target_upload_tracepoints): New.
	(target_upload_trace_state_variables): New.
	(target_get_raw_trace_data): New.
	(target_get_min_fast_tracepoint_insn_len): New.
	(target_set_disconnected_tracing): New.
	(target_set_circular_trace_buffer): New.
	(target_set_trace_buffer_size): New.
	(target_set_trace_notes): New.
	(target_get_tib_address): New.
	(target_set_permissions): New.
	(target_static_tracepoint_marker_at): New.
	(target_static_tracepoint_markers_by_strid): New.
	(target_traceframe_info): New.
	(target_use_agent): New.
	(target_can_use_agent): New.
	(target_augmented_libraries_svr4_read): New.
	(target_log_command): New.
	* bfin-tdep.c (bfin_sw_breakpoint_from_kind): Adjust.
	* infrun.c (set_schedlock_func): Adjust.
	* mi/mi-main.c (exec_reverse_continue): Adjust.
	* reverse.c (exec_reverse_once): Adjust.
	* sh-tdep.c (sh_sw_breakpoint_from_kind): Adjust.
	* tui/tui-stack.c (tui_locator_window::make_status_line): Adjust.
	* remote-sim.c (gdbsim_target::detach): Adjust.
	(gdbsim_target::files_info): Adjust.

Change-Id: I72ef56e9a25adeb0b91f1ad05e34c89f77ebeaa8
---
 gdb/bfin-tdep.c     |   2 +-
 gdb/infrun.c        |   3 +-
 gdb/mi/mi-main.c    |   2 +-
 gdb/remote-sim.c    |   4 +-
 gdb/reverse.c       |   2 +-
 gdb/sh-tdep.c       |   2 +-
 gdb/target.c        | 558 ++++++++++++++++++++++++++++++++++++++++++++
 gdb/target.h        | 287 +++++++++--------------
 gdb/tui/tui-stack.c |   4 +-
 9 files changed, 674 insertions(+), 190 deletions(-)

diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index 963b0485a48..e3d6eee8832 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -597,7 +597,7 @@ bfin_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 
   *size = kind;
 
-  if (strcmp (target_shortname, "sim") == 0)
+  if (strcmp (target_shortname (), "sim") == 0)
     return bfin_sim_breakpoint;
   else
     return bfin_breakpoint;
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 50340e6edad..b6f399d5478 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -2030,7 +2030,8 @@ set_schedlock_func (const char *args, int from_tty, struct cmd_list_element *c)
   if (!target_can_lock_scheduler ())
     {
       scheduler_mode = schedlock_off;
-      error (_("Target '%s' cannot support this command."), target_shortname);
+      error (_("Target '%s' cannot support this command."),
+	     target_shortname ());
     }
 }
 
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 9a14d78e1e2..d5ce08e95ed 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -322,7 +322,7 @@ exec_reverse_continue (char **argv, int argc)
     error (_("Already in reverse mode."));
 
   if (!target_can_execute_reverse ())
-    error (_("Target %s does not support this command."), target_shortname);
+    error (_("Target %s does not support this command."), target_shortname ());
 
   scoped_restore save_exec_dir = make_scoped_restore (&execution_direction,
 						      EXEC_REVERSE);
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 1746b626fa1..f2cf8dbd711 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -836,7 +836,7 @@ gdbsim_target::detach (inferior *inf, int from_tty)
 
   inf->unpush_target (this);		/* calls gdbsim_close to do the real work */
   if (from_tty)
-    printf_filtered ("Ending simulator %s debugging\n", target_shortname);
+    printf_filtered ("Ending simulator %s debugging\n", target_shortname ());
 }
 
 /* Resume execution of the target process.  STEP says whether to single-step
@@ -1119,7 +1119,7 @@ gdbsim_target::files_info ()
   if (current_program_space->exec_bfd ())
     {
       fprintf_unfiltered (gdb_stdlog, "\tAttached to %s running program %s\n",
-			  target_shortname, file);
+			  target_shortname (), file);
       sim_info (sim_data->gdbsim_desc, 0);
     }
 }
diff --git a/gdb/reverse.c b/gdb/reverse.c
index 4c618a00173..e51defb27a3 100644
--- a/gdb/reverse.c
+++ b/gdb/reverse.c
@@ -45,7 +45,7 @@ exec_reverse_once (const char *cmd, const char *args, int from_tty)
 	   cmd);
 
   if (!target_can_execute_reverse ())
-    error (_("Target %s does not support this command."), target_shortname);
+    error (_("Target %s does not support this command."), target_shortname ());
 
   std::string reverse_command = string_printf ("%s %s", cmd, args ? args : "");
   scoped_restore restore_exec_dir
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index ecd73c17217..5a71d3ac689 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -432,7 +432,7 @@ sh_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
   *size = kind;
 
   /* For remote stub targets, trapa #20 is used.  */
-  if (strcmp (target_shortname, "remote") == 0)
+  if (strcmp (target_shortname (), "remote") == 0)
     {
       static unsigned char big_remote_breakpoint[] = { 0xc3, 0x20 };
       static unsigned char little_remote_breakpoint[] = { 0x20, 0xc3 };
diff --git a/gdb/target.c b/gdb/target.c
index afc4b2cbbb6..e7af5e8a9b0 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -215,6 +215,564 @@ target_has_execution (inferior *inf)
   return false;
 }
 
+const char *
+target_shortname ()
+{
+  return current_top_target ()->shortname ();
+}
+
+/* See target.h.  */
+
+bool
+target_attach_no_wait ()
+{
+  return current_top_target ()->attach_no_wait ();
+}
+
+/* See target.h.  */
+
+void
+target_post_attach (int pid)
+{
+  return current_top_target ()->post_attach (pid);
+}
+
+/* See target.h.  */
+
+void
+target_prepare_to_store (regcache *regcache)
+{
+  return current_top_target ()->prepare_to_store (regcache);
+}
+
+/* See target.h.  */
+
+bool
+target_supports_enable_disable_tracepoint ()
+{
+  return current_top_target ()->supports_enable_disable_tracepoint ();
+}
+
+bool
+target_supports_string_tracing ()
+{
+  return current_top_target ()->supports_string_tracing ();
+}
+
+/* See target.h.  */
+
+bool
+target_supports_evaluation_of_breakpoint_conditions ()
+{
+  return current_top_target ()->supports_evaluation_of_breakpoint_conditions ();
+}
+
+/* See target.h.  */
+
+bool
+target_supports_dumpcore ()
+{
+  return current_top_target ()->supports_dumpcore ();
+}
+
+/* See target.h.  */
+
+void
+target_dumpcore (const char *filename)
+{
+  return current_top_target ()->dumpcore (filename);
+}
+
+/* See target.h.  */
+
+bool
+target_can_run_breakpoint_commands ()
+{
+  return current_top_target ()->can_run_breakpoint_commands ();
+}
+
+/* See target.h.  */
+
+void
+target_files_info ()
+{
+  return current_top_target ()->files_info ();
+}
+
+/* See target.h.  */
+
+void
+target_post_startup_inferior (ptid_t ptid)
+{
+  return current_top_target ()->post_startup_inferior (ptid);
+}
+
+/* See target.h.  */
+
+int
+target_insert_fork_catchpoint (int pid)
+{
+  return current_top_target ()->insert_fork_catchpoint (pid);
+}
+
+/* See target.h.  */
+
+int
+target_remove_fork_catchpoint (int pid)
+{
+  return current_top_target ()->remove_fork_catchpoint (pid);
+}
+
+/* See target.h.  */
+
+int
+target_insert_vfork_catchpoint (int pid)
+{
+  return current_top_target ()->insert_vfork_catchpoint (pid);
+}
+
+/* See target.h.  */
+
+int
+target_remove_vfork_catchpoint (int pid)
+{
+  return current_top_target ()->remove_vfork_catchpoint (pid);
+}
+
+/* See target.h.  */
+
+int
+target_insert_exec_catchpoint (int pid)
+{
+  return current_top_target ()->insert_exec_catchpoint (pid);
+}
+
+/* See target.h.  */
+
+int
+target_remove_exec_catchpoint (int pid)
+{
+  return current_top_target ()->remove_exec_catchpoint (pid);
+}
+
+/* See target.h.  */
+
+int
+target_set_syscall_catchpoint (int pid, bool needed, int any_count,
+			       gdb::array_view<const int> syscall_counts)
+{
+  return current_top_target ()->set_syscall_catchpoint (pid, needed, any_count,
+							syscall_counts);
+}
+
+/* See target.h.  */
+
+void
+target_rcmd (const char *command, struct ui_file *outbuf)
+{
+  return current_top_target ()->rcmd (command, outbuf);
+}
+
+/* See target.h.  */
+
+bool
+target_can_lock_scheduler ()
+{
+  return (current_top_target ()->get_thread_control_capabilities ()
+	  & tc_schedlock) != 0;
+}
+
+/* See target.h.  */
+
+bool
+target_can_async_p ()
+{
+  return current_top_target ()->can_async_p ();
+}
+
+/* See target.h.  */
+
+bool
+target_is_async_p ()
+{
+  return current_top_target ()->is_async_p ();
+}
+
+exec_direction_kind
+target_execution_direction ()
+{
+  return current_top_target ()->execution_direction ();
+}
+
+/* See target.h.  */
+
+const char *
+target_extra_thread_info (thread_info *tp)
+{
+  return current_top_target ()->extra_thread_info (tp);
+}
+
+/* See target.h.  */
+
+char *
+target_pid_to_exec_file (int pid)
+{
+  return current_top_target ()->pid_to_exec_file (pid);
+}
+
+/* See target.h.  */
+
+gdbarch *
+target_thread_architecture (ptid_t ptid)
+{
+  return current_top_target ()->thread_architecture (ptid);
+}
+
+/* See target.h.  */
+
+int
+target_find_memory_regions (find_memory_region_ftype func, void *data)
+{
+  return current_top_target ()->find_memory_regions (func, data);
+}
+
+/* See target.h.  */
+
+gdb::unique_xmalloc_ptr<char>
+target_make_corefile_notes (bfd *bfd, int *size_p)
+{
+  return current_top_target ()->make_corefile_notes (bfd, size_p);
+}
+
+gdb_byte *
+target_get_bookmark (const char *args, int from_tty)
+{
+  return current_top_target ()->get_bookmark (args, from_tty);
+}
+
+void
+target_goto_bookmark (const gdb_byte *arg, int from_tty)
+{
+  return current_top_target ()->goto_bookmark (arg, from_tty);
+}
+
+/* See target.h.  */
+
+bool
+target_stopped_by_watchpoint ()
+{
+  return current_top_target ()->stopped_by_watchpoint ();
+}
+
+/* See target.h.  */
+
+bool
+target_stopped_by_sw_breakpoint ()
+{
+  return current_top_target ()->stopped_by_sw_breakpoint ();
+}
+
+bool
+target_supports_stopped_by_sw_breakpoint ()
+{
+  return current_top_target ()->supports_stopped_by_sw_breakpoint ();
+}
+
+bool
+target_stopped_by_hw_breakpoint ()
+{
+  return current_top_target ()->stopped_by_hw_breakpoint ();
+}
+
+bool
+target_supports_stopped_by_hw_breakpoint ()
+{
+  return current_top_target ()->supports_stopped_by_hw_breakpoint ();
+}
+
+/* See target.h.  */
+
+bool
+target_have_steppable_watchpoint ()
+{
+  return current_top_target ()->have_steppable_watchpoint ();
+}
+
+/* See target.h.  */
+
+int
+target_can_use_hardware_watchpoint (bptype type, int cnt, int othertype)
+{
+  return current_top_target ()->can_use_hw_breakpoint (type, cnt, othertype);
+}
+
+/* See target.h.  */
+
+int
+target_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
+{
+  return current_top_target ()->region_ok_for_hw_watchpoint (addr, len);
+}
+
+
+int
+target_can_do_single_step ()
+{
+  return current_top_target ()->can_do_single_step ();
+}
+
+/* See target.h.  */
+
+int
+target_insert_watchpoint (CORE_ADDR addr, int len, target_hw_bp_type type,
+			  expression *cond)
+{
+  return current_top_target ()->insert_watchpoint (addr, len, type, cond);
+}
+
+/* See target.h.  */
+
+int
+target_remove_watchpoint (CORE_ADDR addr, int len, target_hw_bp_type type,
+			  expression *cond)
+{
+  return current_top_target ()->remove_watchpoint (addr, len, type, cond);
+}
+
+/* See target.h.  */
+
+int
+target_insert_hw_breakpoint (gdbarch *gdbarch, bp_target_info *bp_tgt)
+{
+  return current_top_target ()->insert_hw_breakpoint (gdbarch, bp_tgt);
+}
+
+/* See target.h.  */
+
+int
+target_remove_hw_breakpoint (gdbarch *gdbarch, bp_target_info *bp_tgt)
+{
+  return current_top_target ()->remove_hw_breakpoint (gdbarch, bp_tgt);
+}
+
+/* See target.h.  */
+
+bool
+target_can_accel_watchpoint_condition (CORE_ADDR addr, int len, int type,
+				       expression *cond)
+{
+  return current_top_target ()->can_accel_watchpoint_condition (addr, len, type, cond);
+}
+
+/* See target.h.  */
+
+bool
+target_can_execute_reverse ()
+{
+  return current_top_target ()->can_execute_reverse ();
+}
+
+ptid_t
+target_get_ada_task_ptid (long lwp, long tid)
+{
+  return current_top_target ()->get_ada_task_ptid (lwp, tid);
+}
+
+bool
+target_filesystem_is_local ()
+{
+  return current_top_target ()->filesystem_is_local ();
+}
+
+void
+target_trace_init ()
+{
+  return current_top_target ()->trace_init ();
+}
+
+void
+target_download_tracepoint (bp_location *location)
+{
+  return current_top_target ()->download_tracepoint (location);
+}
+
+bool
+target_can_download_tracepoint ()
+{
+  return current_top_target ()->can_download_tracepoint ();
+}
+
+void
+target_download_trace_state_variable (const trace_state_variable &tsv)
+{
+  return current_top_target ()->download_trace_state_variable (tsv);
+}
+
+void
+target_enable_tracepoint (bp_location *loc)
+{
+  return current_top_target ()->enable_tracepoint (loc);
+}
+
+void
+target_disable_tracepoint (bp_location *loc)
+{
+  return current_top_target ()->disable_tracepoint (loc);
+}
+
+void
+target_trace_start ()
+{
+  return current_top_target ()->trace_start ();
+}
+
+void
+target_trace_set_readonly_regions ()
+{
+  current_top_target ()->trace_set_readonly_regions ();
+}
+
+int
+target_get_trace_status (trace_status *ts)
+{
+  return current_top_target ()->get_trace_status (ts);
+}
+
+void
+target_get_tracepoint_status (breakpoint *tp, uploaded_tp *utp)
+{
+  return current_top_target ()->get_tracepoint_status (tp, utp);
+}
+
+void
+target_trace_stop ()
+{
+  return current_top_target ()->trace_stop ();
+}
+
+int
+target_trace_find (trace_find_type type, int num,
+		   CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
+{
+  return current_top_target ()->trace_find (type, num, addr1, addr2, tpp);
+}
+
+bool
+target_get_trace_state_variable_value (int tsv, LONGEST *val)
+{
+  return current_top_target ()->get_trace_state_variable_value (tsv, val);
+}
+
+int
+target_save_trace_data (const char *filename)
+{
+  return current_top_target ()->save_trace_data (filename);
+}
+
+int
+target_upload_tracepoints (uploaded_tp **utpp)
+{
+  return current_top_target ()->upload_tracepoints (utpp);
+}
+
+int
+target_upload_trace_state_variables (uploaded_tsv **utsvp)
+{
+  return current_top_target ()->upload_trace_state_variables (utsvp);
+}
+
+LONGEST
+target_get_raw_trace_data (gdb_byte *buf, ULONGEST offset, LONGEST len)
+{
+  return current_top_target ()->get_raw_trace_data (buf, offset, len);
+}
+
+int
+target_get_min_fast_tracepoint_insn_len ()
+{
+  return current_top_target ()->get_min_fast_tracepoint_insn_len ();
+}
+
+void
+target_set_disconnected_tracing (int val)
+{
+  return current_top_target ()->set_disconnected_tracing (val);
+}
+
+void
+target_set_circular_trace_buffer (int val)
+{
+  return current_top_target ()->set_circular_trace_buffer (val);
+}
+
+void
+target_set_trace_buffer_size (LONGEST val)
+{
+  return current_top_target ()->set_trace_buffer_size (val);
+}
+
+bool
+target_set_trace_notes (const char *user, const char *notes,
+			const char *stopnotes)
+{
+  return current_top_target ()->set_trace_notes (user, notes, stopnotes);
+}
+
+bool
+target_get_tib_address (ptid_t ptid, CORE_ADDR *addr)
+{
+  return current_top_target ()->get_tib_address (ptid, addr);
+}
+
+void
+target_set_permissions ()
+{
+  return current_top_target ()->set_permissions ();
+}
+
+bool
+target_static_tracepoint_marker_at (CORE_ADDR addr,
+				    static_tracepoint_marker *marker)
+{
+  return current_top_target ()->static_tracepoint_marker_at (addr, marker);
+}
+
+std::vector<static_tracepoint_marker>
+target_static_tracepoint_markers_by_strid (const char *marker_id)
+{
+  return current_top_target ()->static_tracepoint_markers_by_strid (marker_id);
+}
+
+traceframe_info_up
+target_traceframe_info ()
+{
+  return current_top_target ()->traceframe_info ();
+}
+
+bool
+target_use_agent (bool use)
+{
+  return current_top_target ()->use_agent (use);
+}
+
+bool
+target_can_use_agent ()
+{
+  return current_top_target ()->can_use_agent ();
+}
+
+bool
+target_augmented_libraries_svr4_read ()
+{
+  return current_top_target ()->augmented_libraries_svr4_read ();
+}
+
+void
+target_log_command (const char *p)
+{
+  return current_top_target ()->log_command (p);
+}
+
 /* This is used to implement the various target commands.  */
 
 static void
diff --git a/gdb/target.h b/gdb/target.h
index 8c11fb76d4c..8b223c0283f 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -917,8 +917,8 @@ struct target_ops
 
     /* Target file operations.  */
 
-    /* Return nonzero if the filesystem seen by the current inferior
-       is the local filesystem, zero otherwise.  */
+    /* Return true if the filesystem seen by the current inferior
+       is the local filesystem, false otherwise.  */
     virtual bool filesystem_is_local ()
       TARGET_DEFAULT_RETURN (true);
 
@@ -1069,8 +1069,8 @@ struct target_ops
     virtual void set_trace_buffer_size (LONGEST val)
       TARGET_DEFAULT_IGNORE ();
 
-    /* Add/change textual notes about the trace run, returning 1 if
-       successful, 0 otherwise.  */
+    /* Add/change textual notes about the trace run, returning true if
+       successful, false otherwise.  */
     virtual bool set_trace_notes (const char *user, const char *notes,
 				  const char *stopnotes)
       TARGET_DEFAULT_RETURN (false);
@@ -1363,7 +1363,7 @@ extern target_ops *get_dummy_target ();
 
 /* Define easy words for doing these operations on our current target.  */
 
-#define	target_shortname	(current_top_target ()->shortname ())
+extern const char *target_shortname ();
 
 /* Does whatever cleanup is required for a target that we are no
    longer going to be calling.  This routine is automatically always
@@ -1390,16 +1390,15 @@ extern struct target_ops *find_run_target (void);
    or their target_attach implementation takes care of the waiting.
    These targets must set to_attach_no_wait.  */
 
-#define target_attach_no_wait() \
-  (current_top_target ()->attach_no_wait ())
+extern bool target_attach_no_wait ();
 
 /* The target_attach operation places a process under debugger control,
    and stops the process.
 
    This operation provides a target-specific hook that allows the
    necessary bookkeeping to be performed after an attach completes.  */
-#define target_post_attach(pid) \
-     (current_top_target ()->post_attach) (pid)
+
+extern void target_post_attach (int pid);
 
 /* Display a message indicating we're about to detach from the current
    inferior process.  */
@@ -1480,8 +1479,7 @@ extern void target_store_registers (struct regcache *regcache, int regs);
    that REGISTERS contains all the registers from the program being
    debugged.  */
 
-#define	target_prepare_to_store(regcache)	\
-     (current_top_target ()->prepare_to_store) (regcache)
+extern void target_prepare_to_store (regcache *regcache);
 
 /* Determine current address space of thread PTID.  */
 
@@ -1501,33 +1499,27 @@ int target_supports_disable_randomization (void);
 /* Returns true if this target can enable and disable tracepoints
    while a trace experiment is running.  */
 
-#define target_supports_enable_disable_tracepoint() \
-  (current_top_target ()->supports_enable_disable_tracepoint) ()
+extern bool target_supports_enable_disable_tracepoint ();
 
-#define target_supports_string_tracing() \
-  (current_top_target ()->supports_string_tracing) ()
+extern bool target_supports_string_tracing ();
 
 /* Returns true if this target can handle breakpoint conditions
    on its end.  */
 
-#define target_supports_evaluation_of_breakpoint_conditions() \
-  (current_top_target ()->supports_evaluation_of_breakpoint_conditions) ()
+extern bool target_supports_evaluation_of_breakpoint_conditions ();
 
 /* Does this target support dumpcore API?  */
 
-#define target_supports_dumpcore() \
-  (current_top_target ()->supports_dumpcore) ()
+extern bool target_supports_dumpcore ();
 
 /* Generate the core file with target API.  */
 
-#define target_dumpcore(x) \
-  (current_top_target ()->dumpcore (x))
+extern void target_dumpcore (const char *filename);
 
 /* Returns true if this target can handle breakpoint commands
    on its end.  */
 
-#define target_can_run_breakpoint_commands() \
-  (current_top_target ()->can_run_breakpoint_commands) ()
+extern bool target_can_run_breakpoint_commands ();
 
 /* Read a string from target memory at address MEMADDR.  The string
    will be at most LEN bytes long (note that excess bytes may be read
@@ -1614,8 +1606,7 @@ int target_write_memory_blocks
 
 /* Print a line about the current target.  */
 
-#define	target_files_info()	\
-     (current_top_target ()->files_info) ()
+extern void target_files_info ();
 
 /* Insert a breakpoint at address BP_TGT->placed_address in
    the target machine.  Returns 0 for success, and returns non-zero or
@@ -1664,25 +1655,20 @@ extern void target_load (const char *arg, int from_tty);
 
    Such targets will supply an appropriate definition for this function.  */
 
-#define target_post_startup_inferior(ptid) \
-     (current_top_target ()->post_startup_inferior) (ptid)
+extern void target_post_startup_inferior (ptid_t ptid);
 
 /* On some targets, we can catch an inferior fork or vfork event when
    it occurs.  These functions insert/remove an already-created
    catchpoint for such events.  They return  0 for success, 1 if the
    catchpoint type is not supported and -1 for failure.  */
 
-#define target_insert_fork_catchpoint(pid) \
-     (current_top_target ()->insert_fork_catchpoint) (pid)
+extern int target_insert_fork_catchpoint (int pid);
 
-#define target_remove_fork_catchpoint(pid) \
-     (current_top_target ()->remove_fork_catchpoint) (pid)
+extern int target_remove_fork_catchpoint (int pid);
 
-#define target_insert_vfork_catchpoint(pid) \
-     (current_top_target ()->insert_vfork_catchpoint) (pid)
+extern int target_insert_vfork_catchpoint (int pid);
 
-#define target_remove_vfork_catchpoint(pid) \
-     (current_top_target ()->remove_vfork_catchpoint) (pid)
+extern int target_remove_vfork_catchpoint (int pid);
 
 /* If the inferior forks or vforks, this function will be called at
    the next resume in order to perform any bookkeeping and fiddling
@@ -1704,11 +1690,9 @@ void target_follow_exec (struct inferior *inf, const char *execd_pathname);
    catchpoint for such events.  They return  0 for success, 1 if the
    catchpoint type is not supported and -1 for failure.  */
 
-#define target_insert_exec_catchpoint(pid) \
-     (current_top_target ()->insert_exec_catchpoint) (pid)
+extern int target_insert_exec_catchpoint (int pid);
 
-#define target_remove_exec_catchpoint(pid) \
-     (current_top_target ()->remove_exec_catchpoint) (pid)
+extern int target_remove_exec_catchpoint (int pid);
 
 /* Syscall catch.
 
@@ -1726,9 +1710,9 @@ void target_follow_exec (struct inferior *inf, const char *execd_pathname);
    Return 0 for success, 1 if syscall catchpoints are not supported or -1
    for failure.  */
 
-#define target_set_syscall_catchpoint(pid, needed, any_count, syscall_counts) \
-     (current_top_target ()->set_syscall_catchpoint) (pid, needed, any_count, \
-					     syscall_counts)
+extern int target_set_syscall_catchpoint
+  (int pid, bool needed, int any_count,
+   gdb::array_view<const int> syscall_counts);
 
 /* The debugger has completed a blocking wait() call.  There is now
    some process event that must be processed.  This function should
@@ -1812,9 +1796,7 @@ extern void default_target_pass_ctrlc (struct target_ops *ops);
    (shell,interpreter) for execution.  The result of the query is
    placed in OUTBUF.  */
 
-#define target_rcmd(command, outbuf) \
-     (current_top_target ()->rcmd) (command, outbuf)
-
+extern void target_rcmd (const char *command, struct ui_file *outbuf);
 
 /* Does the target include memory?  (Dummy targets don't.)  */
 
@@ -1843,21 +1825,16 @@ extern bool target_has_execution (inferior *inf = nullptr);
 /* Can the target support the debugger control of thread execution?
    Can it lock the thread scheduler?  */
 
-static inline bool
-target_can_lock_scheduler ()
-{
-  return (current_top_target ()->get_thread_control_capabilities ()
-	  & tc_schedlock) != 0;
-}
+extern bool target_can_lock_scheduler ();
 
 /* Controls whether async mode is permitted.  */
 extern bool target_async_permitted;
 
 /* Can the target support asynchronous execution?  */
-#define target_can_async_p() (current_top_target ()->can_async_p ())
+extern bool target_can_async_p ();
 
 /* Is the target in asynchronous execution mode?  */
-#define target_is_async_p() (current_top_target ()->is_async_p ())
+extern bool target_is_async_p ();
 
 /* Enables/disabled async target events.  */
 extern void target_async (int enable);
@@ -1877,8 +1854,7 @@ extern bool target_is_non_stop_p ();
 /* Return true if at least one inferior has a non-stop target.  */
 extern bool exists_non_stop_target ();
 
-#define target_execution_direction() \
-  (current_top_target ()->execution_direction ())
+extern exec_direction_kind target_execution_direction ();
 
 /* Converts a process id to a string.  Usually, the string just contains
    `process xyz', but on some systems it may contain
@@ -1892,8 +1868,7 @@ extern std::string normal_pid_to_str (ptid_t ptid);
    e.g. "sleeping", "runnable", "running on LWP 3".  Null return value
    is okay.  */
 
-#define target_extra_thread_info(TP) \
-     (current_top_target ()->extra_thread_info (TP))
+extern const char *target_extra_thread_info (thread_info *tp);
 
 /* Return the thread's name, or NULL if the target is unable to determine it.
    The returned value must not be freed by the caller.  */
@@ -1924,13 +1899,11 @@ extern gdb::byte_vector target_thread_info_to_thread_handle
    the client if the string will not be immediately used, or if
    it must persist.  */
 
-#define target_pid_to_exec_file(pid) \
-     (current_top_target ()->pid_to_exec_file) (pid)
+extern char *target_pid_to_exec_file (int pid);
 
 /* See the to_thread_architecture description in struct target_ops.  */
 
-#define target_thread_architecture(ptid) \
-     (current_top_target ()->thread_architecture (ptid))
+extern gdbarch *target_thread_architecture (ptid_t ptid);
 
 /*
  * Iterator function for target memory regions.
@@ -1939,22 +1912,20 @@ extern gdb::byte_vector target_thread_info_to_thread_handle
  * as a function macro so that it can be tested for nullity.
  */
 
-#define target_find_memory_regions(FUNC, DATA) \
-     (current_top_target ()->find_memory_regions) (FUNC, DATA)
+extern int target_find_memory_regions (find_memory_region_ftype func,
+				       void *data);
 
 /*
  * Compose corefile .note section.
  */
 
-#define target_make_corefile_notes(BFD, SIZE_P) \
-     (current_top_target ()->make_corefile_notes) (BFD, SIZE_P)
+extern gdb::unique_xmalloc_ptr<char> target_make_corefile_notes (bfd *bfd,
+								 int *size_p);
 
 /* Bookmark interfaces.  */
-#define target_get_bookmark(ARGS, FROM_TTY) \
-     (current_top_target ()->get_bookmark) (ARGS, FROM_TTY)
+extern gdb_byte *target_get_bookmark (const char *args, int from_tty);
 
-#define target_goto_bookmark(ARG, FROM_TTY) \
-     (current_top_target ()->goto_bookmark) (ARG, FROM_TTY)
+extern void target_goto_bookmark (const gdb_byte *arg, int from_tty);
 
 /* Hardware watchpoint interfaces.  */
 
@@ -1992,34 +1963,25 @@ extern gdb::byte_vector target_thread_info_to_thread_handle
    gdbarch_have_nonsteppable_watchpoint, GDB assumes continuable
    watchpoints.  */
 
-/* Returns non-zero if we were stopped by a hardware watchpoint (memory read or
+/* Returns true if we were stopped by a hardware watchpoint (memory read or
    write).  Only the INFERIOR_PTID task is being queried.  */
 
-#define target_stopped_by_watchpoint()		\
-  ((current_top_target ()->stopped_by_watchpoint) ())
+extern bool target_stopped_by_watchpoint ();
 
-/* Returns non-zero if the target stopped because it executed a
+/* Returns true if the target stopped because it executed a
    software breakpoint instruction.  */
 
-#define target_stopped_by_sw_breakpoint()		\
-  ((current_top_target ()->stopped_by_sw_breakpoint) ())
+extern bool target_stopped_by_sw_breakpoint ();
 
-#define target_supports_stopped_by_sw_breakpoint() \
-  ((current_top_target ()->supports_stopped_by_sw_breakpoint) ())
+extern bool target_supports_stopped_by_sw_breakpoint ();
 
-#define target_stopped_by_hw_breakpoint()				\
-  ((current_top_target ()->stopped_by_hw_breakpoint) ())
+extern bool target_stopped_by_hw_breakpoint ();
 
-#define target_supports_stopped_by_hw_breakpoint() \
-  ((current_top_target ()->supports_stopped_by_hw_breakpoint) ())
+extern bool target_supports_stopped_by_hw_breakpoint ();
 
-/* Non-zero if we have steppable watchpoints  */
+/* True if we have steppable watchpoints  */
 
-static inline bool
-target_have_steppable_watchpoint ()
-{
-  return current_top_target ()->have_steppable_watchpoint ();
-}
+extern bool target_have_steppable_watchpoint ();
 
 /* Provide defaults for hardware watchpoint functions.  */
 
@@ -2035,19 +1997,15 @@ target_have_steppable_watchpoint ()
    one.  OTHERTYPE is the number of watchpoints of other types than
    this one used so far.  */
 
-#define target_can_use_hardware_watchpoint(TYPE,CNT,OTHERTYPE) \
- (current_top_target ()->can_use_hw_breakpoint) ( \
-					     TYPE, CNT, OTHERTYPE)
+extern int target_can_use_hardware_watchpoint (bptype type, int cnt,
+					       int othertype);
 
 /* Returns the number of debug registers needed to watch the given
    memory region, or zero if not supported.  */
 
-#define target_region_ok_for_hw_watchpoint(addr, len) \
-    (current_top_target ()->region_ok_for_hw_watchpoint) (addr, len)
-
+extern int target_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len);
 
-#define target_can_do_single_step() \
-  (current_top_target ()->can_do_single_step) ()
+extern int target_can_do_single_step ();
 
 /* Set/clear a hardware watchpoint starting at ADDR, for LEN bytes.
    TYPE is 0 for write, 1 for read, and 2 for read/write accesses.
@@ -2055,11 +2013,11 @@ target_have_steppable_watchpoint ()
    Returns 0 for success, 1 if the watchpoint type is not supported,
    -1 for failure.  */
 
-#define	target_insert_watchpoint(addr, len, type, cond) \
-     (current_top_target ()->insert_watchpoint) (addr, len, type, cond)
+extern int target_insert_watchpoint (CORE_ADDR addr, int len,
+				     target_hw_bp_type type, expression *cond);
 
-#define	target_remove_watchpoint(addr, len, type, cond) \
-     (current_top_target ()->remove_watchpoint) (addr, len, type, cond)
+extern int target_remove_watchpoint (CORE_ADDR addr, int len,
+				     target_hw_bp_type type, expression *cond);
 
 /* Insert a new masked watchpoint at ADDR using the mask MASK.
    RW may be hw_read for a read watchpoint, hw_write for a write watchpoint
@@ -2082,11 +2040,11 @@ extern int target_remove_mask_watchpoint (CORE_ADDR, CORE_ADDR,
    throws an error (with a detailed failure reason error code and
    message) otherwise.  */
 
-#define target_insert_hw_breakpoint(gdbarch, bp_tgt) \
-     (current_top_target ()->insert_hw_breakpoint) (gdbarch, bp_tgt)
+extern int target_insert_hw_breakpoint (gdbarch *gdbarch,
+					bp_target_info *bp_tgt);
 
-#define target_remove_hw_breakpoint(gdbarch, bp_tgt) \
-     (current_top_target ()->remove_hw_breakpoint) (gdbarch, bp_tgt)
+extern int target_remove_hw_breakpoint (gdbarch *gdbarch,
+					bp_target_info *bp_tgt);
 
 /* Return number of debug registers needed for a ranged breakpoint,
    or -1 if ranged breakpoints are not supported.  */
@@ -2114,8 +2072,9 @@ extern int target_ranged_break_num_registers (void);
    expression is false, but may report some false positives as well.
    For this reason, GDB will still evaluate the condition expression when
    the watchpoint triggers.  */
-#define target_can_accel_watchpoint_condition(addr, len, type, cond) \
-  (current_top_target ()->can_accel_watchpoint_condition) (addr, len, type, cond)
+
+extern bool target_can_accel_watchpoint_condition (CORE_ADDR addr, int len,
+						   int type, expression *cond);
 
 /* Return number of debug registers needed for a masked watchpoint,
    -1 if masked watchpoints are not supported or -2 if the given address
@@ -2124,16 +2083,12 @@ extern int target_ranged_break_num_registers (void);
 extern int target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask);
 
 /* Target can execute in reverse?  */
-static inline bool
-target_can_execute_reverse ()
-{
-  return current_top_target ()->can_execute_reverse ();
-}
+
+extern bool target_can_execute_reverse ();
 
 extern const struct target_desc *target_read_description (struct target_ops *);
 
-#define target_get_ada_task_ptid(lwp, tid) \
-     (current_top_target ()->get_ada_task_ptid) (lwp,tid)
+extern ptid_t target_get_ada_task_ptid (long lwp, long tid);
 
 /* Main entry point for searching memory.  */
 extern int target_search_memory (CORE_ADDR start_addr,
@@ -2144,10 +2099,10 @@ extern int target_search_memory (CORE_ADDR start_addr,
 
 /* Target file operations.  */
 
-/* Return nonzero if the filesystem seen by the current inferior
+/* Return true if the filesystem seen by the current inferior
    is the local filesystem, zero otherwise.  */
-#define target_filesystem_is_local() \
-  current_top_target ()->filesystem_is_local ()
+
+extern bool target_filesystem_is_local ();
 
 /* Open FILENAME on the target, in the filesystem as seen by INF,
    using FLAGS and MODE.  If INF is NULL, use the filesystem seen by
@@ -2227,102 +2182,72 @@ extern gdb::unique_xmalloc_ptr<char> target_fileio_read_stralloc
 
 /* Tracepoint-related operations.  */
 
-#define target_trace_init() \
-  (current_top_target ()->trace_init) ()
-
-#define target_download_tracepoint(t) \
-  (current_top_target ()->download_tracepoint) (t)
-
-#define target_can_download_tracepoint() \
-  (current_top_target ()->can_download_tracepoint) ()
+extern void target_trace_init ();
 
-#define target_download_trace_state_variable(tsv) \
-  (current_top_target ()->download_trace_state_variable) (tsv)
+extern void target_download_tracepoint (bp_location *location);
 
-#define target_enable_tracepoint(loc) \
-  (current_top_target ()->enable_tracepoint) (loc)
+extern bool target_can_download_tracepoint ();
 
-#define target_disable_tracepoint(loc) \
-  (current_top_target ()->disable_tracepoint) (loc)
+extern void target_download_trace_state_variable (const trace_state_variable &tsv);
 
-#define target_trace_start() \
-  (current_top_target ()->trace_start) ()
+extern void target_enable_tracepoint (bp_location *loc);
 
-#define target_trace_set_readonly_regions() \
-  (current_top_target ()->trace_set_readonly_regions) ()
+extern void target_disable_tracepoint (bp_location *loc);
 
-#define target_get_trace_status(ts) \
-  (current_top_target ()->get_trace_status) (ts)
+extern void target_trace_start ();
 
-#define target_get_tracepoint_status(tp,utp)		\
-  (current_top_target ()->get_tracepoint_status) (tp, utp)
+extern void target_trace_set_readonly_regions ();
 
-#define target_trace_stop() \
-  (current_top_target ()->trace_stop) ()
+extern int target_get_trace_status (trace_status *ts);
 
-#define target_trace_find(type,num,addr1,addr2,tpp) \
-  (current_top_target ()->trace_find) (\
-				   (type), (num), (addr1), (addr2), (tpp))
+extern void target_get_tracepoint_status (breakpoint *tp, uploaded_tp *utp);
 
-#define target_get_trace_state_variable_value(tsv,val) \
-  (current_top_target ()->get_trace_state_variable_value) ((tsv), (val))
+extern void target_trace_stop ();
 
-#define target_save_trace_data(filename) \
-  (current_top_target ()->save_trace_data) (filename)
+extern int target_trace_find (trace_find_type type, int num, CORE_ADDR addr1,
+			      CORE_ADDR addr2, int *tpp);
 
-#define target_upload_tracepoints(utpp) \
-  (current_top_target ()->upload_tracepoints) (utpp)
+extern bool target_get_trace_state_variable_value (int tsv, LONGEST *val);
 
-#define target_upload_trace_state_variables(utsvp) \
-  (current_top_target ()->upload_trace_state_variables) (utsvp)
+extern int target_save_trace_data (const char *filename);
 
-#define target_get_raw_trace_data(buf,offset,len) \
-  (current_top_target ()->get_raw_trace_data) ((buf), (offset), (len))
+extern int target_upload_tracepoints (uploaded_tp **utpp);
 
-#define target_get_min_fast_tracepoint_insn_len() \
-  (current_top_target ()->get_min_fast_tracepoint_insn_len) ()
+extern int target_upload_trace_state_variables (uploaded_tsv **utsvp);
 
-#define target_set_disconnected_tracing(val) \
-  (current_top_target ()->set_disconnected_tracing) (val)
+extern LONGEST target_get_raw_trace_data (gdb_byte *buf, ULONGEST offset,
+					  LONGEST len);
 
-#define	target_set_circular_trace_buffer(val)	\
-  (current_top_target ()->set_circular_trace_buffer) (val)
+extern int target_get_min_fast_tracepoint_insn_len ();
 
-#define	target_set_trace_buffer_size(val)	\
-  (current_top_target ()->set_trace_buffer_size) (val)
+extern void target_set_disconnected_tracing (int val);
 
-#define	target_set_trace_notes(user,notes,stopnotes)		\
-  (current_top_target ()->set_trace_notes) ((user), (notes), (stopnotes))
+extern void target_set_circular_trace_buffer (int val);
 
-#define target_get_tib_address(ptid, addr) \
-  (current_top_target ()->get_tib_address) ((ptid), (addr))
+extern void target_set_trace_buffer_size (LONGEST val);
 
-#define target_set_permissions() \
-  (current_top_target ()->set_permissions) ()
+extern bool target_set_trace_notes (const char *user, const char *notes,
+				    const char *stopnotes);
 
-#define target_static_tracepoint_marker_at(addr, marker) \
-  (current_top_target ()->static_tracepoint_marker_at) (addr, marker)
+extern bool target_get_tib_address (ptid_t ptid, CORE_ADDR *addr);
 
-#define target_static_tracepoint_markers_by_strid(marker_id) \
-  (current_top_target ()->static_tracepoint_markers_by_strid) (marker_id)
+extern void target_set_permissions ();
 
-#define target_traceframe_info() \
-  (current_top_target ()->traceframe_info) ()
+extern bool target_static_tracepoint_marker_at
+  (CORE_ADDR addr, static_tracepoint_marker *marker);
 
-#define target_use_agent(use) \
-  (current_top_target ()->use_agent) (use)
+extern std::vector<static_tracepoint_marker>
+  target_static_tracepoint_markers_by_strid (const char *marker_id);
 
-#define target_can_use_agent() \
-  (current_top_target ()->can_use_agent) ()
+extern traceframe_info_up target_traceframe_info ();
 
-#define target_augmented_libraries_svr4_read() \
-  (current_top_target ()->augmented_libraries_svr4_read) ()
+extern bool target_use_agent (bool use);
 
-/* Command logging facility.  */
+extern bool target_can_use_agent ();
 
-#define target_log_command(p)					\
-  (current_top_target ()->log_command) (p)
+extern bool target_augmented_libraries_svr4_read ();
 
+extern void target_log_command (const char *p);
 
 extern int target_core_of_thread (ptid_t ptid);
 
diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index b5daa61b4e2..0200a111c92 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -77,7 +77,7 @@ tui_locator_window::make_status_line () const
       pid_name = pid_name_holder.c_str ();
     }
 
-  target_width = strlen (target_shortname);
+  target_width = strlen (target_shortname ());
   if (target_width > MAX_TARGET_WIDTH)
     target_width = MAX_TARGET_WIDTH;
 
@@ -149,7 +149,7 @@ tui_locator_window::make_status_line () const
   string_file string;
 
   if (target_width > 0)
-    string.printf ("%*.*s ", -target_width, target_width, target_shortname);
+    string.printf ("%*.*s ", -target_width, target_width, target_shortname ());
   if (pid_width > 0)
     string.printf ("%*.*s ", -pid_width, pid_width, pid_name);
 
-- 
2.30.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] gdb: remove current_top_target function
  2021-03-23 18:41 [PATCH 1/2] gdb: move all "current target" wrapper implementations to target.c Simon Marchi
@ 2021-03-23 18:41 ` Simon Marchi
  2021-03-24 11:02   ` Andrew Burgess
  2021-03-24  9:29 ` [PATCH 1/2] gdb: move all "current target" wrapper implementations to target.c Andrew Burgess
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2021-03-23 18:41 UTC (permalink / raw)
  To: gdb-patches

From: Simon Marchi <simon.marchi@polymtl.ca>

The current_top_target function is a hidden dependency on the current
inferior.  Since I'd like to slowly move towards reducing our dependency
on the global current state, remove this function and make callers use

  current_inferior ()->top_target ()

There is no expected change in behavior, but this one step towards
making those callers use the inferior from their context, rather than
refer to the global current inferior.

gdb/ChangeLog:

	* target.h (current_top_target): Remove, make callers use the
	current inferior instead.
	* target.c (current_top_target): Remove.

Change-Id: Iccd457036f84466cdaa3865aa3f9339a24ea001d
---
 gdb/auxv.c                |   6 +-
 gdb/avr-tdep.c            |   6 +-
 gdb/breakpoint.c          |  12 +-
 gdb/corefile.c            |   4 +-
 gdb/elfread.c             |  14 +-
 gdb/eval.c                |   5 +-
 gdb/exec.c                |   2 +-
 gdb/fbsd-tdep.c           |   2 +-
 gdb/frame.c               |   5 +-
 gdb/gnu-v3-abi.c          |   5 +-
 gdb/ia64-tdep.c           |   4 +-
 gdb/ia64-vms-tdep.c       |   3 +-
 gdb/infcall.c             |   9 +-
 gdb/infcmd.c              |  14 +-
 gdb/inferior.c            |   2 +-
 gdb/infrun.c              |  16 +-
 gdb/linespec.c            |   3 +-
 gdb/linux-tdep.c          |  21 +-
 gdb/maint.c               |   3 +-
 gdb/mi/mi-main.c          |   7 +-
 gdb/minsyms.c             |   6 +-
 gdb/ppc-linux-nat.c       |  19 +-
 gdb/procfs.c              |   3 +-
 gdb/regcache.c            |   2 +-
 gdb/remote.c              |  19 +-
 gdb/rs6000-tdep.c         |   3 +-
 gdb/s390-linux-nat.c      |   2 +-
 gdb/s390-tdep.c           |   3 +-
 gdb/solib-aix.c           |   3 +-
 gdb/solib-darwin.c        |   3 +-
 gdb/solib-dsbt.c          |   6 +-
 gdb/solib-svr4.c          |  34 +--
 gdb/solib-target.c        |   5 +-
 gdb/sparc-tdep.c          |   2 +-
 gdb/sparc64-tdep.c        |   6 +-
 gdb/symfile.c             |   6 +-
 gdb/symtab.c              |   6 +-
 gdb/target-descriptions.c |   6 +-
 gdb/target-memory.c       |   5 +-
 gdb/target.c              | 462 ++++++++++++++++++++++----------------
 gdb/target.h              |   5 -
 gdb/tracefile-tfile.c     |   2 +-
 gdb/tracepoint.c          |   3 +-
 gdb/valops.c              |   5 +-
 gdb/valprint.c            |   6 +-
 gdb/value.c               |   4 +-
 gdb/windows-tdep.c        |   2 +-
 47 files changed, 445 insertions(+), 326 deletions(-)

diff --git a/gdb/auxv.c b/gdb/auxv.c
index f13f90b153f..6507df192e5 100644
--- a/gdb/auxv.c
+++ b/gdb/auxv.c
@@ -320,7 +320,8 @@ target_auxv_parse (gdb_byte **readptr,
   if (gdbarch_auxv_parse_p (gdbarch))
     return gdbarch_auxv_parse (gdbarch, readptr, endptr, typep, valp);
 
-  return current_top_target ()->auxv_parse (readptr, endptr, typep, valp);
+  return current_inferior ()->top_target ()->auxv_parse (readptr, endptr,
+							 typep, valp);
 }
 
 
@@ -580,7 +581,8 @@ info_auxv_command (const char *cmd, int from_tty)
     error (_("The program has no auxiliary information now."));
   else
     {
-      int ents = fprint_target_auxv (gdb_stdout, current_top_target ());
+      int ents = fprint_target_auxv (gdb_stdout,
+				     current_inferior ()->top_target ());
 
       if (ents < 0)
 	error (_("No auxiliary vector found, or failed reading it."));
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 815c6d45143..018b18f3dfd 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -1561,7 +1561,8 @@ avr_io_reg_read_command (const char *args, int from_tty)
 
   /* Find out how many io registers the target has.  */
   gdb::optional<gdb::byte_vector> buf
-    = target_read_alloc (current_top_target (), TARGET_OBJECT_AVR, "avr.io_reg");
+    = target_read_alloc (current_inferior ()->top_target (),
+			 TARGET_OBJECT_AVR, "avr.io_reg");
 
   if (!buf)
     {
@@ -1595,7 +1596,8 @@ avr_io_reg_read_command (const char *args, int from_tty)
 	j = nreg - i;           /* last block is less than 8 registers */
 
       snprintf (query, sizeof (query) - 1, "avr.io_reg:%x,%x", i, j);
-      buf = target_read_alloc (current_top_target (), TARGET_OBJECT_AVR, query);
+      buf = target_read_alloc (current_inferior ()->top_target (),
+			       TARGET_OBJECT_AVR, query);
 
       if (!buf)
 	{
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index de1e79ba5d0..16cf7977b62 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3598,8 +3598,8 @@ create_exception_master_breakpoint_hook (objfile *objfile)
     }
 
   addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
-  addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
-					     current_top_target ());
+  addr = gdbarch_convert_from_func_ptr_addr
+    (gdbarch, addr, current_inferior ()->top_target ());
   b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
 				  &internal_breakpoint_ops);
   initialize_explicit_location (&explicit_loc);
@@ -4869,7 +4869,7 @@ watchpoints_triggered (struct target_waitstatus *ws)
       return 0;
     }
 
-  if (!target_stopped_data_address (current_top_target (), &addr))
+  if (!target_stopped_data_address (current_inferior ()->top_target (), &addr))
     {
       /* We were stopped by a watchpoint, but we don't know where.
 	 Mark all watchpoints as unknown.  */
@@ -4909,9 +4909,9 @@ watchpoints_triggered (struct target_waitstatus *ws)
 		  }
 	      }
 	    /* Exact match not required.  Within range is sufficient.  */
-	    else if (target_watchpoint_addr_within_range (current_top_target (),
-							 addr, loc->address,
-							 loc->length))
+	    else if (target_watchpoint_addr_within_range
+		       (current_inferior ()->top_target (), addr, loc->address,
+			loc->length))
 	      {
 		w->watchpoint_triggered = watch_triggered_yes;
 		break;
diff --git a/gdb/corefile.c b/gdb/corefile.c
index 4ddcc06ec96..30960c129fd 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -218,8 +218,8 @@ read_memory_object (enum target_object object, CORE_ADDR memaddr,
       enum target_xfer_status status;
       ULONGEST xfered_len;
 
-      status = target_xfer_partial (current_top_target (), object, NULL,
-				    myaddr + xfered, NULL,
+      status = target_xfer_partial (current_inferior ()->top_target (), object,
+				    NULL, myaddr + xfered, NULL,
 				    memaddr + xfered, len - xfered,
 				    &xfered_len);
 
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 85100875347..49bbbec663e 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -863,8 +863,8 @@ elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
       if (target_read_memory (pointer_address, buf, ptr_size) != 0)
 	continue;
       addr = extract_typed_address (buf, ptr_type);
-      addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
-						 current_top_target ());
+      addr = gdbarch_convert_from_func_ptr_addr
+	(gdbarch, addr, current_inferior ()->top_target ());
       addr = gdbarch_addr_bits_remove (gdbarch, addr);
 
       if (elf_gnu_ifunc_record_cache (name, addr))
@@ -931,12 +931,13 @@ elf_gnu_ifunc_resolve_addr (struct gdbarch *gdbarch, CORE_ADDR pc)
      parameter.  FUNCTION is the function entry address.  ADDRESS may be a
      function descriptor.  */
 
-  target_auxv_search (current_top_target (), AT_HWCAP, &hwcap);
+  target_auxv_search (current_inferior ()->top_target (), AT_HWCAP, &hwcap);
   hwcap_val = value_from_longest (builtin_type (gdbarch)
 				  ->builtin_unsigned_long, hwcap);
   address_val = call_function_by_hand (function, NULL, hwcap_val);
   address = value_as_address (address_val);
-  address = gdbarch_convert_from_func_ptr_addr (gdbarch, address, current_top_target ());
+  address = gdbarch_convert_from_func_ptr_addr
+    (gdbarch, address, current_inferior ()->top_target ());
   address = gdbarch_addr_bits_remove (gdbarch, address);
 
   if (name_at_pc)
@@ -1042,9 +1043,8 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
   gdbarch_return_value (gdbarch, func_func, value_type, regcache,
 			value_contents_raw (value), NULL);
   resolved_address = value_as_address (value);
-  resolved_pc = gdbarch_convert_from_func_ptr_addr (gdbarch,
-						    resolved_address,
-						    current_top_target ());
+  resolved_pc = gdbarch_convert_from_func_ptr_addr
+    (gdbarch, resolved_address, current_inferior ()->top_target ());
   resolved_pc = gdbarch_addr_bits_remove (gdbarch, resolved_pc);
 
   gdb_assert (current_program_space == b->pspace || b->pspace == NULL);
diff --git a/gdb/eval.c b/gdb/eval.c
index 530ff152134..363ab4fa4af 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -42,6 +42,7 @@
 #include <ctype.h>
 #include "expop.h"
 #include "c-exp.h"
+#include "inferior.h"
 
 \f
 /* Parse the string EXP as a C expression, evaluate it,
@@ -1964,8 +1965,8 @@ eval_op_objc_msgcall (struct type *expect_type, struct expression *exp,
 
       /* The address might point to a function descriptor;
 	 resolve it to the actual code address instead.  */
-      addr = gdbarch_convert_from_func_ptr_addr (exp->gdbarch, addr,
-						 current_top_target ());
+      addr = gdbarch_convert_from_func_ptr_addr
+	(exp->gdbarch, addr, current_inferior ()->top_target ());
 
       /* Is it a high_level symbol?  */
       sym = find_pc_function (addr);
diff --git a/gdb/exec.c b/gdb/exec.c
index b737bcf6e0f..ff0db82a69b 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -775,7 +775,7 @@ section_table_read_available_memory (gdb_byte *readbuf, ULONGEST offset,
 				     ULONGEST len, ULONGEST *xfered_len)
 {
   const target_section_table *table
-    = target_get_section_table (current_top_target ());
+    = target_get_section_table (current_inferior ()->top_target ());
   std::vector<mem_range> available_memory
     = section_table_available_memory (offset, len, *table);
 
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index 170e8f5e84e..6cab31dde82 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -593,7 +593,7 @@ static gdb::optional<gdb::byte_vector>
 fbsd_make_note_desc (enum target_object object, uint32_t structsize)
 {
   gdb::optional<gdb::byte_vector> buf =
-    target_read_alloc (current_top_target (), object, NULL);
+    target_read_alloc (current_inferior ()->top_target (), object, NULL);
   if (!buf || buf->empty ())
     return {};
 
diff --git a/gdb/frame.c b/gdb/frame.c
index 4578b1acab3..dc9fdd41646 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2478,9 +2478,8 @@ inside_main_func (frame_info *this_frame)
 
   /* Convert any function descriptor addresses into the actual function
      code address.  */
-  sym_addr
-    = gdbarch_convert_from_func_ptr_addr (get_frame_arch (this_frame),
-					  sym_addr, current_top_target ());
+  sym_addr = gdbarch_convert_from_func_ptr_addr
+    (get_frame_arch (this_frame), sym_addr, current_inferior ()->top_target ());
 
   return sym_addr == get_frame_func (this_frame);
 }
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 8461535c6ec..45e57c210cb 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -31,6 +31,7 @@
 #include <algorithm>
 #include "cli/cli-style.h"
 #include "dwarf2/loc.h"
+#include "inferior.h"
 
 static struct cp_abi_ops gnu_v3_abi_ops;
 
@@ -1243,8 +1244,8 @@ gnuv3_skip_trampoline (struct frame_info *frame, CORE_ADDR stop_pc)
      (powerpc 64 for example).  Make sure to retrieve the address
      of the real function from the function descriptor before passing on
      the address to other layers of GDB.  */
-  func_addr = gdbarch_convert_from_func_ptr_addr (gdbarch, method_stop_pc,
-						  current_top_target ());
+  func_addr = gdbarch_convert_from_func_ptr_addr
+    (gdbarch, method_stop_pc, current_inferior ()->top_target ());
   if (func_addr != 0)
     method_stop_pc = func_addr;
 
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index 35eeffe8434..1c4fc4cca47 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -2653,8 +2653,8 @@ getunwind_table ()
      we should find a way to override the corefile layer's
      xfer_partial method.  */
 
-  return target_read_alloc (current_top_target (), TARGET_OBJECT_UNWIND_TABLE,
-			    NULL);
+  return target_read_alloc (current_inferior ()->top_target (),
+			    TARGET_OBJECT_UNWIND_TABLE, NULL);
 }
 
 /* Get the kernel unwind table.  */				 
diff --git a/gdb/ia64-vms-tdep.c b/gdb/ia64-vms-tdep.c
index 0481f00c2fa..cc8e1914274 100644
--- a/gdb/ia64-vms-tdep.c
+++ b/gdb/ia64-vms-tdep.c
@@ -41,7 +41,8 @@ ia64_vms_find_proc_info_x (unw_addr_space_t as, unw_word_t ip,
   CORE_ADDR table_addr;
   unsigned int info_len;
 
-  res = target_read (current_top_target (), TARGET_OBJECT_OPENVMS_UIB,
+  res = target_read (current_inferior ()->top_target (),
+		     TARGET_OBJECT_OPENVMS_UIB,
 		     annex + 2, buf, 0, sizeof (buf));
 
   if (res != sizeof (buf))
diff --git a/gdb/infcall.c b/gdb/infcall.c
index 2332f293a1e..ca3347fbb9d 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -269,8 +269,8 @@ find_function_addr (struct value *function,
       ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
       if (ftype->code () == TYPE_CODE_FUNC
 	  || ftype->code () == TYPE_CODE_METHOD)
-	funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
-						      current_top_target ());
+	funaddr = gdbarch_convert_from_func_ptr_addr
+	  (gdbarch, funaddr, current_inferior ()->top_target());
     }
   if (ftype->code () == TYPE_CODE_FUNC
       || ftype->code () == TYPE_CODE_METHOD)
@@ -321,9 +321,8 @@ find_function_addr (struct value *function,
 
 	      funaddr = value_as_address (value_addr (function));
 	      nfunaddr = funaddr;
-	      funaddr
-		= gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
-						      current_top_target ());
+	      funaddr = gdbarch_convert_from_func_ptr_addr
+		(gdbarch, funaddr, current_inferior ()->top_target ());
 	      if (funaddr != nfunaddr)
 		found_descriptor = 1;
 	    }
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 80e6ad3048f..a6e9572fc7f 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -759,7 +759,7 @@ continue_command (const char *args, int from_tty)
       ensure_not_running ();
     }
 
-  prepare_execution_command (current_top_target (), async_exec);
+  prepare_execution_command (current_inferior ()->top_target (), async_exec);
 
   if (from_tty)
     printf_filtered (_("Continuing.\n"));
@@ -877,7 +877,7 @@ step_1 (int skip_subroutines, int single_inst, const char *count_string)
     = strip_bg_char (count_string, &async_exec);
   count_string = stripped.get ();
 
-  prepare_execution_command (current_top_target (), async_exec);
+  prepare_execution_command (current_inferior ()->top_target (), async_exec);
 
   count = count_string ? parse_and_eval_long (count_string) : 1;
 
@@ -1075,7 +1075,7 @@ jump_command (const char *arg, int from_tty)
   gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
   arg = stripped.get ();
 
-  prepare_execution_command (current_top_target (), async_exec);
+  prepare_execution_command (current_inferior ()->top_target (), async_exec);
 
   if (!arg)
     error_no_arg (_("starting address"));
@@ -1155,7 +1155,7 @@ signal_command (const char *signum_exp, int from_tty)
     = strip_bg_char (signum_exp, &async_exec);
   signum_exp = stripped.get ();
 
-  prepare_execution_command (current_top_target (), async_exec);
+  prepare_execution_command (current_inferior ()->top_target (), async_exec);
 
   if (!signum_exp)
     error_no_arg (_("signal number"));
@@ -1400,7 +1400,7 @@ until_command (const char *arg, int from_tty)
   gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
   arg = stripped.get ();
 
-  prepare_execution_command (current_top_target (), async_exec);
+  prepare_execution_command (current_inferior ()->top_target (), async_exec);
 
   if (arg)
     until_break_command (arg, from_tty, 0);
@@ -1425,7 +1425,7 @@ advance_command (const char *arg, int from_tty)
   gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
   arg = stripped.get ();
 
-  prepare_execution_command (current_top_target (), async_exec);
+  prepare_execution_command (current_inferior ()->top_target (), async_exec);
 
   until_break_command (arg, from_tty, 1);
 }
@@ -1772,7 +1772,7 @@ finish_command (const char *arg, int from_tty)
   gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
   arg = stripped.get ();
 
-  prepare_execution_command (current_top_target (), async_exec);
+  prepare_execution_command (current_inferior ()->top_target (), async_exec);
 
   if (arg)
     error (_("The \"finish\" command does not take any arguments."));
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 69baee34ce9..9188f72e35d 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -507,7 +507,7 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
 
       uiout->field_signed ("number", inf->num);
 
-      /* Because target_pid_to_str uses current_top_target,
+      /* Because target_pid_to_str uses the current inferior,
 	 switch the inferior.  */
       switch_to_inferior_no_thread (inf);
 
diff --git a/gdb/infrun.c b/gdb/infrun.c
index b6f399d5478..20035a0f5e8 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1777,7 +1777,7 @@ displaced_step_finish (thread_info *event_thread, enum gdb_signal signal)
   /* Fixup may need to read memory/registers.  Switch to the thread
      that we're fixing up.  Also, target_stopped_by_watchpoint checks
      the current thread, and displaced_step_restore performs ptid-dependent
-     memory accesses using current_inferior() and current_top_target().  */
+     memory accesses using current_inferior().  */
   switch_to_thread (event_thread);
 
   displaced_step_reset_cleanup cleanup (displaced);
@@ -5813,7 +5813,8 @@ handle_signal_stop (struct execution_control_state *ecs)
 
 	  infrun_debug_printf ("stopped by watchpoint");
 
-	  if (target_stopped_data_address (current_top_target (), &addr))
+	  if (target_stopped_data_address (current_inferior ()->top_target (),
+					   &addr))
 	    infrun_debug_printf ("stopped data address=%s",
 				 paddress (reg_gdbarch, addr));
 	  else
@@ -8835,7 +8836,8 @@ siginfo_value_read (struct value *v)
   validate_registers_access ();
 
   transferred =
-    target_read (current_top_target (), TARGET_OBJECT_SIGNAL_INFO,
+    target_read (current_inferior ()->top_target (),
+		 TARGET_OBJECT_SIGNAL_INFO,
 		 NULL,
 		 value_contents_all_raw (v),
 		 value_offset (v),
@@ -8857,7 +8859,7 @@ siginfo_value_write (struct value *v, struct value *fromval)
      vice versa.  */
   validate_registers_access ();
 
-  transferred = target_write (current_top_target (),
+  transferred = target_write (current_inferior ()->top_target (),
 			      TARGET_OBJECT_SIGNAL_INFO,
 			      NULL,
 			      value_contents_all_raw (fromval),
@@ -8921,7 +8923,8 @@ class infcall_suspend_state
 
 	siginfo_data.reset ((gdb_byte *) xmalloc (len));
 
-	if (target_read (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL,
+	if (target_read (current_inferior ()->top_target (),
+			 TARGET_OBJECT_SIGNAL_INFO, NULL,
 			 siginfo_data.get (), 0, len) != len)
 	  {
 	    /* Errors ignored.  */
@@ -8956,7 +8959,8 @@ class infcall_suspend_state
 	struct type *type = gdbarch_get_siginfo_type (gdbarch);
 
 	/* Errors ignored.  */
-	target_write (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL,
+	target_write (current_inferior ()->top_target (),
+		      TARGET_OBJECT_SIGNAL_INFO, NULL,
 		      m_siginfo_data.get (), 0, TYPE_LENGTH (type));
       }
 
diff --git a/gdb/linespec.c b/gdb/linespec.c
index c7dbd3eeae2..4034bbab8a0 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -47,6 +47,7 @@
 #include "gdbsupport/function-view.h"
 #include "gdbsupport/def-vector.h"
 #include <algorithm>
+#include "inferior.h"
 
 /* An enumeration of the various things a user might attempt to
    complete for a linespec location.  */
@@ -2314,7 +2315,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
 				= (gdbarch_convert_from_func_ptr_addr
 				   (gdbarch,
 				    msym_addr,
-				    current_top_target ()));
+				    current_inferior ()->top_target ()));
 			    }
 
 			  if (msym_addr == addr)
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index ab3402a41c2..68cf7265a96 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -385,9 +385,10 @@ int
 linux_is_uclinux (void)
 {
   CORE_ADDR dummy;
+  target_ops *target = current_inferior ()->top_target ();
 
-  return (target_auxv_search (current_top_target (), AT_NULL, &dummy) > 0
-	  && target_auxv_search (current_top_target (), AT_PAGESZ, &dummy) == 0);
+  return (target_auxv_search (target, AT_NULL, &dummy) > 0
+	  && target_auxv_search (target, AT_PAGESZ, &dummy) == 0);
 }
 
 static int
@@ -1619,7 +1620,8 @@ linux_get_siginfo_data (thread_info *thread, struct gdbarch *gdbarch)
 
   gdb::byte_vector buf (TYPE_LENGTH (siginfo_type));
 
-  bytes_read = target_read (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL,
+  bytes_read = target_read (current_inferior ()->top_target (),
+			    TARGET_OBJECT_SIGNAL_INFO, NULL,
 			    buf.data (), 0, TYPE_LENGTH (siginfo_type));
   if (bytes_read != TYPE_LENGTH (siginfo_type))
     buf.clear ();
@@ -1921,7 +1923,8 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
 
   /* Auxillary vector.  */
   gdb::optional<gdb::byte_vector> auxv =
-    target_read_alloc (current_top_target (), TARGET_OBJECT_AUXV, NULL);
+    target_read_alloc (current_inferior ()->top_target (),
+		       TARGET_OBJECT_AUXV, NULL);
   if (auxv && !auxv->empty ())
     {
       note_data.reset (elfcore_write_note (obfd, note_data.release (),
@@ -2201,7 +2204,8 @@ linux_vsyscall_range_raw (struct gdbarch *gdbarch, struct mem_range *range)
   char filename[100];
   long pid;
 
-  if (target_auxv_search (current_top_target (), AT_SYSINFO_EHDR, &range->start) <= 0)
+  if (target_auxv_search (current_inferior ()->top_target (),
+			  AT_SYSINFO_EHDR, &range->start) <= 0)
     return 0;
 
   /* It doesn't make sense to access the host's /proc when debugging a
@@ -2391,14 +2395,15 @@ linux_displaced_step_location (struct gdbarch *gdbarch)
      local-store address and is thus not usable as displaced stepping
      location.  The auxiliary vector gets us the PowerPC-side entry
      point address instead.  */
-  if (target_auxv_search (current_top_target (), AT_ENTRY, &addr) <= 0)
+  if (target_auxv_search (current_inferior ()->top_target (),
+			  AT_ENTRY, &addr) <= 0)
     throw_error (NOT_SUPPORTED_ERROR,
 		 _("Cannot find AT_ENTRY auxiliary vector entry."));
 
   /* Make certain that the address points at real code, and not a
      function descriptor.  */
-  addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
-					     current_top_target ());
+  addr = gdbarch_convert_from_func_ptr_addr
+    (gdbarch, addr, current_inferior ()->top_target ());
 
   /* Inferior calls also use the entry point as a breakpoint location.
      We don't want displaced stepping to interfere with those
diff --git a/gdb/maint.c b/gdb/maint.c
index 5254cd6ed26..7f505d07a69 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -40,6 +40,7 @@
 #include "top.h"
 #include "maint.h"
 #include "gdbsupport/selftest.h"
+#include "inferior.h"
 
 #include "cli/cli-decode.h"
 #include "cli/cli-utils.h"
@@ -472,7 +473,7 @@ maintenance_info_target_sections (const char *arg, int from_tty)
   bfd *abfd = nullptr;
   int digits = 0;
   const target_section_table *table
-    = target_get_section_table (current_top_target ());
+    = target_get_section_table (current_inferior ()->top_target ());
   if (table == nullptr)
     return;
 
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index d5ce08e95ed..c6f1ab4e3f0 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -264,7 +264,7 @@ proceed_thread_callback (struct thread_info *thread, void *arg)
 static void
 exec_continue (char **argv, int argc)
 {
-  prepare_execution_command (current_top_target (), mi_async_p ());
+  prepare_execution_command (current_inferior ()->top_target (), mi_async_p ());
 
   if (non_stop)
     {
@@ -1328,7 +1328,8 @@ mi_cmd_data_read_memory (const char *command, char **argv, int argc)
 
   gdb::byte_vector mbuf (total_bytes);
 
-  nr_bytes = target_read (current_top_target (), TARGET_OBJECT_MEMORY, NULL,
+  nr_bytes = target_read (current_inferior ()->top_target (),
+			  TARGET_OBJECT_MEMORY, NULL,
 			  mbuf.data (), addr, total_bytes);
   if (nr_bytes <= 0)
     error (_("Unable to read memory."));
@@ -1448,7 +1449,7 @@ mi_cmd_data_read_memory_bytes (const char *command, char **argv, int argc)
   length = atol (argv[1]);
 
   std::vector<memory_read_result> result
-    = read_memory_robust (current_top_target (), addr, length);
+    = read_memory_robust (current_inferior ()->top_target (), addr, length);
 
   if (result.size () == 0)
     error (_("Unable to read memory."));
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 3cf849f48bf..8ffd9076124 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -54,6 +54,7 @@
 #include <algorithm>
 #include "safe-ctype.h"
 #include "gdbsupport/parallel-for.h"
+#include "inferior.h"
 
 #if CXX_STD_THREAD
 #include <mutex>
@@ -78,9 +79,8 @@ msymbol_is_function (struct objfile *objfile, minimal_symbol *minsym,
     case mst_data_gnu_ifunc:
       {
 	struct gdbarch *gdbarch = objfile->arch ();
-	CORE_ADDR pc
-	  = gdbarch_convert_from_func_ptr_addr (gdbarch, msym_addr,
-						current_top_target ());
+	CORE_ADDR pc = gdbarch_convert_from_func_ptr_addr
+	  (gdbarch, msym_addr, current_inferior ()->top_target ());
 	if (pc != msym_addr)
 	  {
 	    if (func_address_p != NULL)
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index f1ba165d540..171f5b386fa 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -1967,8 +1967,8 @@ ppc_linux_nat_target::read_description ()
 
   features.wordsize = ppc_linux_target_wordsize (tid);
 
-  CORE_ADDR hwcap = linux_get_hwcap (current_top_target ());
-  CORE_ADDR hwcap2 = linux_get_hwcap2 (current_top_target ());
+  CORE_ADDR hwcap = linux_get_hwcap (current_inferior ()->top_target ());
+  CORE_ADDR hwcap2 = linux_get_hwcap2 (current_inferior ()->top_target ());
 
   if (have_ptrace_getsetvsxregs
       && (hwcap & PPC_FEATURE_HAS_VSX))
@@ -2125,7 +2125,8 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
 	 takes two hardware watchpoints though.  */
       if (len > 1
 	  && hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_RANGE
-	  && linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
+	  && (linux_get_hwcap (current_inferior ()->top_target ())
+	      & PPC_FEATURE_BOOKE))
 	return 2;
       /* Check if the processor provides DAWR interface.  */
       if (hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_DAWR)
@@ -2153,7 +2154,8 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
     {
       gdb_assert (m_dreg_interface.debugreg_p ());
 
-      if (((linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
+      if (((linux_get_hwcap (current_inferior ()->top_target ())
+	    & PPC_FEATURE_BOOKE)
 	   && (addr + len) > (addr & ~3) + 4)
 	  || (addr + len) > (addr & ~7) + 8)
 	return 0;
@@ -2640,7 +2642,8 @@ ppc_linux_nat_target::insert_watchpoint (CORE_ADDR addr, int len,
       long wp_value;
       long read_mode, write_mode;
 
-      if (linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
+      if (linux_get_hwcap (current_inferior ()->top_target ())
+	  & PPC_FEATURE_BOOKE)
 	{
 	  /* PowerPC 440 requires only the read/write flags to be passed
 	     to the kernel.  */
@@ -3013,9 +3016,11 @@ ppc_linux_nat_target::watchpoint_addr_within_range (CORE_ADDR addr,
   int mask;
 
   if (m_dreg_interface.hwdebug_p ()
-      && linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
+      && (linux_get_hwcap (current_inferior ()->top_target ())
+	  & PPC_FEATURE_BOOKE))
     return start <= addr && start + length >= addr;
-  else if (linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
+  else if (linux_get_hwcap (current_inferior ()->top_target ())
+	   & PPC_FEATURE_BOOKE)
     mask = 3;
   else
     mask = 7;
diff --git a/gdb/procfs.c b/gdb/procfs.c
index 91d2039e3f9..eb703cf43b7 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -3643,7 +3643,8 @@ procfs_target::make_corefile_notes (bfd *obfd, int *note_size)
 			     &thread_args);
 
   gdb::optional<gdb::byte_vector> auxv =
-    target_read_alloc (current_top_target (), TARGET_OBJECT_AUXV, NULL);
+    target_read_alloc (current_inferior ()->top_target (),
+		       TARGET_OBJECT_AUXV, NULL);
   if (auxv && !auxv->empty ())
     note_data.reset (elfcore_write_note (obfd, note_data.release (), note_size,
 					 "CORE", NT_AUXV, auxv->data (),
diff --git a/gdb/regcache.c b/gdb/regcache.c
index a419a21f30a..bf3c6f43e6a 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -1916,7 +1916,7 @@ cooked_write_test (struct gdbarch *gdbarch)
 {
   /* Error out if debugging something, because we're going to push the
      test target, which would pop any existing target.  */
-  if (current_top_target ()->stratum () >= process_stratum)
+  if (current_inferior ()->top_target ()->stratum () >= process_stratum)
     error (_("target already pushed"));
 
   /* Create a mock environment.  A process_stratum target pushed.  */
diff --git a/gdb/remote.c b/gdb/remote.c
index a7f35396045..e36f03aec46 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -5058,9 +5058,8 @@ remote_target::remote_check_symbols ()
 
 	  /* If this is a function address, return the start of code
 	     instead of any data function descriptor.  */
-	  sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
-							 sym_addr,
-							 current_top_target ());
+	  sym_addr = gdbarch_convert_from_func_ptr_addr
+	    (target_gdbarch (), sym_addr, current_inferior ()->top_target ());
 
 	  xsnprintf (msg.data (), get_remote_packet_size (), "qSymbol:%s:%s",
 		     phex_nz (sym_addr, addr_size), &reply[8]);
@@ -11436,7 +11435,8 @@ remote_target::memory_map ()
 {
   std::vector<mem_region> result;
   gdb::optional<gdb::char_vector> text
-    = target_read_stralloc (current_top_target (), TARGET_OBJECT_MEMORY_MAP, NULL);
+    = target_read_stralloc (current_inferior ()->top_target (),
+			    TARGET_OBJECT_MEMORY_MAP, NULL);
 
   if (text)
     result = parse_memory_map (text->data ());
@@ -13667,7 +13667,8 @@ traceframe_info_up
 remote_target::traceframe_info ()
 {
   gdb::optional<gdb::char_vector> text
-    = target_read_stralloc (current_top_target (), TARGET_OBJECT_TRACEFRAME_INFO,
+    = target_read_stralloc (current_inferior ()->top_target (),
+			    TARGET_OBJECT_TRACEFRAME_INFO,
 			    NULL);
   if (text)
     return parse_traceframe_info (text->data ());
@@ -13896,7 +13897,8 @@ static void
 btrace_read_config (struct btrace_config *conf)
 {
   gdb::optional<gdb::char_vector> xml
-    = target_read_stralloc (current_top_target (), TARGET_OBJECT_BTRACE_CONF, "");
+    = target_read_stralloc (current_inferior ()->top_target (),
+			    TARGET_OBJECT_BTRACE_CONF, "");
   if (xml)
     parse_xml_btrace_conf (conf, xml->data ());
 }
@@ -14097,7 +14099,8 @@ remote_target::read_btrace (struct btrace_data *btrace,
     }
 
   gdb::optional<gdb::char_vector> xml
-    = target_read_stralloc (current_top_target (), TARGET_OBJECT_BTRACE, annex);
+    = target_read_stralloc (current_inferior ()->top_target (),
+			    TARGET_OBJECT_BTRACE, annex);
   if (!xml)
     return BTRACE_ERR_UNKNOWN;
 
@@ -14153,7 +14156,7 @@ remote_target::pid_to_exec_file (int pid)
       xsnprintf (annex, annex_size, "%x", pid);
     }
 
-  filename = target_read_stralloc (current_top_target (),
+  filename = target_read_stralloc (current_inferior ()->top_target (),
 				   TARGET_OBJECT_EXEC_FILE, annex);
 
   return filename ? filename->data () : nullptr;
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index b09f63137dc..cb06cd952a7 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -5077,7 +5077,8 @@ ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
       return 0;
 
     case 1014:		/* Data Cache Block set to Zero */
-      if (target_auxv_search (current_top_target (), AT_DCACHEBSIZE, &at_dcsz) <= 0
+      if (target_auxv_search (current_inferior ()->top_target (),
+			      AT_DCACHEBSIZE, &at_dcsz) <= 0
 	  || at_dcsz == 0)
 	at_dcsz = 128; /* Assume 128-byte cache line size (POWER8)  */
 
diff --git a/gdb/s390-linux-nat.c b/gdb/s390-linux-nat.c
index d493843410a..41b50ce4800 100644
--- a/gdb/s390-linux-nat.c
+++ b/gdb/s390-linux-nat.c
@@ -1002,7 +1002,7 @@ s390_linux_nat_target::read_description ()
      that mode, report s390 architecture with 64-bit GPRs.  */
 #ifdef __s390x__
   {
-    CORE_ADDR hwcap = linux_get_hwcap (current_top_target ());
+    CORE_ADDR hwcap = linux_get_hwcap (current_inferior ()->top_target ());
 
     have_regset_tdb = (hwcap & HWCAP_S390_TE)
       && check_regset (tid, NT_S390_TDB, s390_sizeof_tdbregset);
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 39c8ee0450a..1bd770a3cc3 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -39,6 +39,7 @@
 #include "target-descriptions.h"
 #include "trad-frame.h"
 #include "value.h"
+#include "inferior.h"
 
 #include "features/s390-linux32.c"
 #include "features/s390x-linux64.c"
@@ -685,7 +686,7 @@ s390_load (struct s390_prologue_data *data,
   if (pv_is_constant (addr))
     {
       const struct target_section *secp
-	= target_section_by_addr (current_top_target (), addr.k);
+	= target_section_by_addr (current_inferior ()->top_target (), addr.k);
       if (secp != NULL
 	  && (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY))
 	return pv_constant (read_memory_integer (addr.k, size,
diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
index a0dbdde4d49..faccf299899 100644
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -246,7 +246,8 @@ solib_aix_get_library_list (struct inferior *inf, const char *warning_msg)
     return data->library_list;
 
   gdb::optional<gdb::char_vector> library_document
-    = target_read_stralloc (current_top_target (), TARGET_OBJECT_LIBRARIES_AIX,
+    = target_read_stralloc (current_inferior ()->top_target (),
+			    TARGET_OBJECT_LIBRARIES_AIX,
 			    NULL);
   if (!library_document && warning_msg != NULL)
     {
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index 628ef02a653..152afc21b9d 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -488,7 +488,8 @@ darwin_solib_read_all_image_info_addr (struct darwin_info *info)
   if (TYPE_LENGTH (ptr_type) > sizeof (buf))
     return;
 
-  len = target_read (current_top_target (), TARGET_OBJECT_DARWIN_DYLD_INFO,
+  len = target_read (current_inferior ()->top_target (),
+		     TARGET_OBJECT_DARWIN_DYLD_INFO,
 		     NULL, buf, 0, TYPE_LENGTH (ptr_type));
   if (len <= 0)
     return;
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 4b1b7560e16..c279435c89a 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -280,7 +280,8 @@ dsbt_get_initial_loadmaps (void)
 {
   struct dsbt_info *info = get_dsbt_info ();
   gdb::optional<gdb::byte_vector> buf
-    = target_read_alloc (current_top_target (), TARGET_OBJECT_FDPIC, "exec");
+    = target_read_alloc (current_inferior ()->top_target (),
+			 TARGET_OBJECT_FDPIC, "exec");
 
   if (!buf || buf->empty ())
     {
@@ -291,7 +292,8 @@ dsbt_get_initial_loadmaps (void)
   if (solib_dsbt_debug)
     dsbt_print_loadmap (info->exec_loadmap);
 
-  buf = target_read_alloc (current_top_target (), TARGET_OBJECT_FDPIC, "exec");
+  buf = target_read_alloc (current_inferior ()->top_target (),
+			   TARGET_OBJECT_FDPIC, "exec");
   if (!buf || buf->empty ())
     {
       info->interp_loadmap = NULL;
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index c7b3157191f..531469484e5 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -428,11 +428,14 @@ read_program_header (int type, int *p_arch_size, CORE_ADDR *base_addr)
   int pt_phdr_p = 0;
 
   /* Get required auxv elements from target.  */
-  if (target_auxv_search (current_top_target (), AT_PHDR, &at_phdr) <= 0)
+  if (target_auxv_search (current_inferior ()->top_target (),
+			  AT_PHDR, &at_phdr) <= 0)
     return {};
-  if (target_auxv_search (current_top_target (), AT_PHENT, &at_phent) <= 0)
+  if (target_auxv_search (current_inferior ()->top_target (),
+			  AT_PHENT, &at_phent) <= 0)
     return {};
-  if (target_auxv_search (current_top_target (), AT_PHNUM, &at_phnum) <= 0)
+  if (target_auxv_search (current_inferior ()->top_target (),
+			  AT_PHNUM, &at_phnum) <= 0)
     return {};
   if (!at_phdr || !at_phnum)
     return {};
@@ -1239,7 +1242,8 @@ svr4_current_sos_via_xfer_libraries (struct svr4_library_list *list,
 
   /* Fetch the list of shared libraries.  */
   gdb::optional<gdb::char_vector> svr4_library_document
-    = target_read_stralloc (current_top_target (), TARGET_OBJECT_LIBRARIES_SVR4,
+    = target_read_stralloc (current_inferior ()->top_target (),
+			    TARGET_OBJECT_LIBRARIES_SVR4,
 			    annex);
   if (!svr4_library_document)
     return 0;
@@ -2242,9 +2246,8 @@ enable_break (struct svr4_info *info, int from_tty)
 
       sym_addr = gdbarch_addr_bits_remove
 	(target_gdbarch (),
-	 gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
-					     sym_addr,
-					     current_top_target ()));
+	 gdbarch_convert_from_func_ptr_addr
+	   (target_gdbarch (), sym_addr, current_inferior ()->top_target ()));
 
       /* On at least some versions of Solaris there's a dynamic relocation
 	 on _r_debug.r_brk and SYM_ADDR may not be relocated yet, e.g., if
@@ -2353,7 +2356,8 @@ enable_break (struct svr4_info *info, int from_tty)
       /* If we were not able to find the base address of the loader
 	 from our so_list, then try using the AT_BASE auxilliary entry.  */
       if (!load_addr_found)
-	if (target_auxv_search (current_top_target (), AT_BASE, &load_addr) > 0)
+	if (target_auxv_search (current_inferior ()->top_target (),
+				AT_BASE, &load_addr) > 0)
 	  {
 	    int addr_bit = gdbarch_addr_bit (target_gdbarch ());
 
@@ -2474,9 +2478,8 @@ enable_break (struct svr4_info *info, int from_tty)
 	  && (BMSYMBOL_VALUE_ADDRESS (msymbol) != 0))
 	{
 	  sym_addr = BMSYMBOL_VALUE_ADDRESS (msymbol);
-	  sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
-							 sym_addr,
-							 current_top_target ());
+	  sym_addr = gdbarch_convert_from_func_ptr_addr
+	    (target_gdbarch (), sym_addr, current_inferior ()->top_target ());
 	  svr4_create_solib_event_breakpoints (info, target_gdbarch (),
 					       sym_addr);
 	  return 1;
@@ -2492,9 +2495,9 @@ enable_break (struct svr4_info *info, int from_tty)
 	      && (BMSYMBOL_VALUE_ADDRESS (msymbol) != 0))
 	    {
 	      sym_addr = BMSYMBOL_VALUE_ADDRESS (msymbol);
-	      sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
-							     sym_addr,
-							     current_top_target ());
+	      sym_addr = gdbarch_convert_from_func_ptr_addr
+		(target_gdbarch (), sym_addr,
+		 current_inferior ()->top_target ());
 	      svr4_create_solib_event_breakpoints (info, target_gdbarch (),
 						   sym_addr);
 	      return 1;
@@ -2582,7 +2585,8 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
   if ((bfd_get_file_flags (current_program_space->exec_bfd ()) & DYNAMIC) == 0)
     return 0;
 
-  if (target_auxv_search (current_top_target (), AT_ENTRY, &entry_point) <= 0)
+  if (target_auxv_search (current_inferior ()->top_target (),
+			  AT_ENTRY, &entry_point) <= 0)
     return 0;
 
   exec_displacement
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index d8e33c3b027..1e010c52221 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -25,6 +25,7 @@
 #include "target.h"
 #include "solib-target.h"
 #include <vector>
+#include "inferior.h"
 
 /* Private data for each loaded library.  */
 struct lm_info_target : public lm_info_base
@@ -233,8 +234,8 @@ solib_target_current_sos (void)
 
   /* Fetch the list of shared libraries.  */
   gdb::optional<gdb::char_vector> library_document
-    = target_read_stralloc (current_top_target (), TARGET_OBJECT_LIBRARIES,
-			    NULL);
+    = target_read_stralloc (current_inferior ()->top_target (),
+			    TARGET_OBJECT_LIBRARIES, NULL);
   if (!library_document)
     return NULL;
 
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index 34f22879737..a6df0fcb58b 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -189,7 +189,7 @@ ULONGEST
 sparc_fetch_wcookie (struct gdbarch *gdbarch)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  struct target_ops *ops = current_top_target ();
+  struct target_ops *ops = current_inferior ()->top_target ();
   gdb_byte buf[8];
   int len;
 
diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
index c4d5ab21b2f..3609794419a 100644
--- a/gdb/sparc64-tdep.c
+++ b/gdb/sparc64-tdep.c
@@ -214,10 +214,12 @@ adi_available (void)
     return proc->stat.is_avail;
 
   proc->stat.checked_avail = true;
-  if (target_auxv_search (current_top_target (), AT_ADI_BLKSZ, &value) <= 0)
+  if (target_auxv_search (current_inferior ()->top_target (),
+			  AT_ADI_BLKSZ, &value) <= 0)
     return false;
   proc->stat.blksize = value;
-  target_auxv_search (current_top_target (), AT_ADI_NBITS, &value);
+  target_auxv_search (current_inferior ()->top_target (),
+		      AT_ADI_NBITS, &value);
   proc->stat.nbits = value;
   proc->stat.max_version = (1 << proc->stat.nbits) - 2;
   proc->stat.is_avail = true;
diff --git a/gdb/symfile.c b/gdb/symfile.c
index adcdc169306..e417878031d 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -838,10 +838,8 @@ init_entry_point_info (struct objfile *objfile)
 
       /* Make certain that the address points at real code, and not a
 	 function descriptor.  */
-      entry_point
-	= gdbarch_convert_from_func_ptr_addr (objfile->arch (),
-					      entry_point,
-					      current_top_target ());
+      entry_point = gdbarch_convert_from_func_ptr_addr
+	(objfile->arch (), entry_point, current_inferior ()->top_target ());
 
       /* Remove any ISA markers, so that this matches entries in the
 	 symbol table.  */
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 084e8ecc2e8..122fdf0b1d3 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5564,10 +5564,8 @@ find_gnu_ifunc (const symbol *sym)
 	  if (MSYMBOL_TYPE (minsym) == mst_data_gnu_ifunc)
 	    {
 	      struct gdbarch *gdbarch = objfile->arch ();
-	      msym_addr
-		= gdbarch_convert_from_func_ptr_addr (gdbarch,
-						      msym_addr,
-						      current_top_target ());
+	      msym_addr = gdbarch_convert_from_func_ptr_addr
+		(gdbarch, msym_addr, current_inferior ()->top_target ());
 	    }
 	  if (msym_addr == address)
 	    {
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 248edd51bd1..c0e798a3530 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -553,11 +553,13 @@ target_find_description (void)
   /* Next try to read the description from the current target using
      target objects.  */
   if (current_target_desc == NULL)
-    current_target_desc = target_read_description_xml (current_top_target ());
+    current_target_desc = target_read_description_xml
+      (current_inferior ()->top_target ());
 
   /* If that failed try a target-specific hook.  */
   if (current_target_desc == NULL)
-    current_target_desc = target_read_description (current_top_target ());
+    current_target_desc = target_read_description
+      (current_inferior ()->top_target ());
 
   /* If a non-NULL description was returned, then update the current
      architecture.  */
diff --git a/gdb/target-memory.c b/gdb/target-memory.c
index 060f9cc6642..877f6c3e946 100644
--- a/gdb/target-memory.c
+++ b/gdb/target-memory.c
@@ -21,6 +21,7 @@
 #include "defs.h"
 #include "target.h"
 #include "memory-map.h"
+#include "inferior.h"
 
 #include "gdbsupport/gdb_sys_time.h"
 #include <algorithm>
@@ -335,7 +336,7 @@ target_write_memory_blocks (const std::vector<memory_write_request> &requests,
     {
       LONGEST len;
 
-      len = target_write_with_progress (current_top_target (),
+      len = target_write_with_progress (current_inferior ()->top_target (),
 					TARGET_OBJECT_MEMORY, NULL,
 					iter.data, iter.begin,
 					iter.end - iter.begin,
@@ -358,7 +359,7 @@ target_write_memory_blocks (const std::vector<memory_write_request> &requests,
 	{
 	  LONGEST len;
 
-	  len = target_write_with_progress (current_top_target (),
+	  len = target_write_with_progress (current_inferior ()->top_target (),
 					    TARGET_OBJECT_FLASH, NULL,
 					    iter.data, iter.begin,
 					    iter.end - iter.begin,
diff --git a/gdb/target.c b/gdb/target.c
index e7af5e8a9b0..6956bc08e37 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -110,16 +110,6 @@ static std::unordered_map<const target_info *, target_open_ftype *>
 
 static struct target_ops *the_debug_target;
 
-/* Top of target stack.  */
-/* The target structure we are currently using to talk to a process
-   or file or whatever "inferior" we have.  */
-
-target_ops *
-current_top_target ()
-{
-  return current_inferior ()->top_target ();
-}
-
 /* Command list for target.  */
 
 static struct cmd_list_element *targetlist = NULL;
@@ -173,7 +163,9 @@ show_targetdebug (struct ui_file *file, int from_tty,
 int
 target_has_memory ()
 {
-  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
+  for (target_ops *t = current_inferior ()->top_target ();
+       t != NULL;
+       t = t->beneath ())
     if (t->has_memory ())
       return 1;
 
@@ -183,7 +175,9 @@ target_has_memory ()
 int
 target_has_stack ()
 {
-  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
+  for (target_ops *t = current_inferior ()->top_target ();
+       t != NULL;
+       t = t->beneath ())
     if (t->has_stack ())
       return 1;
 
@@ -193,7 +187,9 @@ target_has_stack ()
 int
 target_has_registers ()
 {
-  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
+  for (target_ops *t = current_inferior ()->top_target ();
+       t != NULL;
+       t = t->beneath ())
     if (t->has_registers ())
       return 1;
 
@@ -218,7 +214,7 @@ target_has_execution (inferior *inf)
 const char *
 target_shortname ()
 {
-  return current_top_target ()->shortname ();
+  return current_inferior ()->top_target ()->shortname ();
 }
 
 /* See target.h.  */
@@ -226,7 +222,7 @@ target_shortname ()
 bool
 target_attach_no_wait ()
 {
-  return current_top_target ()->attach_no_wait ();
+  return current_inferior ()->top_target ()->attach_no_wait ();
 }
 
 /* See target.h.  */
@@ -234,7 +230,7 @@ target_attach_no_wait ()
 void
 target_post_attach (int pid)
 {
-  return current_top_target ()->post_attach (pid);
+  return current_inferior ()->top_target ()->post_attach (pid);
 }
 
 /* See target.h.  */
@@ -242,7 +238,7 @@ target_post_attach (int pid)
 void
 target_prepare_to_store (regcache *regcache)
 {
-  return current_top_target ()->prepare_to_store (regcache);
+  return current_inferior ()->top_target ()->prepare_to_store (regcache);
 }
 
 /* See target.h.  */
@@ -250,13 +246,15 @@ target_prepare_to_store (regcache *regcache)
 bool
 target_supports_enable_disable_tracepoint ()
 {
-  return current_top_target ()->supports_enable_disable_tracepoint ();
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->supports_enable_disable_tracepoint ();
 }
 
 bool
 target_supports_string_tracing ()
 {
-  return current_top_target ()->supports_string_tracing ();
+  return current_inferior ()->top_target ()->supports_string_tracing ();
 }
 
 /* See target.h.  */
@@ -264,7 +262,9 @@ target_supports_string_tracing ()
 bool
 target_supports_evaluation_of_breakpoint_conditions ()
 {
-  return current_top_target ()->supports_evaluation_of_breakpoint_conditions ();
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->supports_evaluation_of_breakpoint_conditions ();
 }
 
 /* See target.h.  */
@@ -272,7 +272,7 @@ target_supports_evaluation_of_breakpoint_conditions ()
 bool
 target_supports_dumpcore ()
 {
-  return current_top_target ()->supports_dumpcore ();
+  return current_inferior ()->top_target ()->supports_dumpcore ();
 }
 
 /* See target.h.  */
@@ -280,7 +280,7 @@ target_supports_dumpcore ()
 void
 target_dumpcore (const char *filename)
 {
-  return current_top_target ()->dumpcore (filename);
+  return current_inferior ()->top_target ()->dumpcore (filename);
 }
 
 /* See target.h.  */
@@ -288,7 +288,7 @@ target_dumpcore (const char *filename)
 bool
 target_can_run_breakpoint_commands ()
 {
-  return current_top_target ()->can_run_breakpoint_commands ();
+  return current_inferior ()->top_target ()->can_run_breakpoint_commands ();
 }
 
 /* See target.h.  */
@@ -296,7 +296,7 @@ target_can_run_breakpoint_commands ()
 void
 target_files_info ()
 {
-  return current_top_target ()->files_info ();
+  return current_inferior ()->top_target ()->files_info ();
 }
 
 /* See target.h.  */
@@ -304,7 +304,7 @@ target_files_info ()
 void
 target_post_startup_inferior (ptid_t ptid)
 {
-  return current_top_target ()->post_startup_inferior (ptid);
+  return current_inferior ()->top_target ()->post_startup_inferior (ptid);
 }
 
 /* See target.h.  */
@@ -312,7 +312,7 @@ target_post_startup_inferior (ptid_t ptid)
 int
 target_insert_fork_catchpoint (int pid)
 {
-  return current_top_target ()->insert_fork_catchpoint (pid);
+  return current_inferior ()->top_target ()->insert_fork_catchpoint (pid);
 }
 
 /* See target.h.  */
@@ -320,7 +320,7 @@ target_insert_fork_catchpoint (int pid)
 int
 target_remove_fork_catchpoint (int pid)
 {
-  return current_top_target ()->remove_fork_catchpoint (pid);
+  return current_inferior ()->top_target ()->remove_fork_catchpoint (pid);
 }
 
 /* See target.h.  */
@@ -328,7 +328,7 @@ target_remove_fork_catchpoint (int pid)
 int
 target_insert_vfork_catchpoint (int pid)
 {
-  return current_top_target ()->insert_vfork_catchpoint (pid);
+  return current_inferior ()->top_target ()->insert_vfork_catchpoint (pid);
 }
 
 /* See target.h.  */
@@ -336,7 +336,7 @@ target_insert_vfork_catchpoint (int pid)
 int
 target_remove_vfork_catchpoint (int pid)
 {
-  return current_top_target ()->remove_vfork_catchpoint (pid);
+  return current_inferior ()->top_target ()->remove_vfork_catchpoint (pid);
 }
 
 /* See target.h.  */
@@ -344,7 +344,7 @@ target_remove_vfork_catchpoint (int pid)
 int
 target_insert_exec_catchpoint (int pid)
 {
-  return current_top_target ()->insert_exec_catchpoint (pid);
+  return current_inferior ()->top_target ()->insert_exec_catchpoint (pid);
 }
 
 /* See target.h.  */
@@ -352,7 +352,7 @@ target_insert_exec_catchpoint (int pid)
 int
 target_remove_exec_catchpoint (int pid)
 {
-  return current_top_target ()->remove_exec_catchpoint (pid);
+  return current_inferior ()->top_target ()->remove_exec_catchpoint (pid);
 }
 
 /* See target.h.  */
@@ -361,8 +361,10 @@ int
 target_set_syscall_catchpoint (int pid, bool needed, int any_count,
 			       gdb::array_view<const int> syscall_counts)
 {
-  return current_top_target ()->set_syscall_catchpoint (pid, needed, any_count,
-							syscall_counts);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->set_syscall_catchpoint (pid, needed, any_count,
+					 syscall_counts);
 }
 
 /* See target.h.  */
@@ -370,7 +372,7 @@ target_set_syscall_catchpoint (int pid, bool needed, int any_count,
 void
 target_rcmd (const char *command, struct ui_file *outbuf)
 {
-  return current_top_target ()->rcmd (command, outbuf);
+  return current_inferior ()->top_target ()->rcmd (command, outbuf);
 }
 
 /* See target.h.  */
@@ -378,8 +380,9 @@ target_rcmd (const char *command, struct ui_file *outbuf)
 bool
 target_can_lock_scheduler ()
 {
-  return (current_top_target ()->get_thread_control_capabilities ()
-	  & tc_schedlock) != 0;
+  target_ops *target = current_inferior ()->top_target ();
+
+  return (target->get_thread_control_capabilities ()& tc_schedlock) != 0;
 }
 
 /* See target.h.  */
@@ -387,7 +390,7 @@ target_can_lock_scheduler ()
 bool
 target_can_async_p ()
 {
-  return current_top_target ()->can_async_p ();
+  return current_inferior ()->top_target ()->can_async_p ();
 }
 
 /* See target.h.  */
@@ -395,13 +398,13 @@ target_can_async_p ()
 bool
 target_is_async_p ()
 {
-  return current_top_target ()->is_async_p ();
+  return current_inferior ()->top_target ()->is_async_p ();
 }
 
 exec_direction_kind
 target_execution_direction ()
 {
-  return current_top_target ()->execution_direction ();
+  return current_inferior ()->top_target ()->execution_direction ();
 }
 
 /* See target.h.  */
@@ -409,7 +412,7 @@ target_execution_direction ()
 const char *
 target_extra_thread_info (thread_info *tp)
 {
-  return current_top_target ()->extra_thread_info (tp);
+  return current_inferior ()->top_target ()->extra_thread_info (tp);
 }
 
 /* See target.h.  */
@@ -417,7 +420,7 @@ target_extra_thread_info (thread_info *tp)
 char *
 target_pid_to_exec_file (int pid)
 {
-  return current_top_target ()->pid_to_exec_file (pid);
+  return current_inferior ()->top_target ()->pid_to_exec_file (pid);
 }
 
 /* See target.h.  */
@@ -425,7 +428,7 @@ target_pid_to_exec_file (int pid)
 gdbarch *
 target_thread_architecture (ptid_t ptid)
 {
-  return current_top_target ()->thread_architecture (ptid);
+  return current_inferior ()->top_target ()->thread_architecture (ptid);
 }
 
 /* See target.h.  */
@@ -433,7 +436,7 @@ target_thread_architecture (ptid_t ptid)
 int
 target_find_memory_regions (find_memory_region_ftype func, void *data)
 {
-  return current_top_target ()->find_memory_regions (func, data);
+  return current_inferior ()->top_target ()->find_memory_regions (func, data);
 }
 
 /* See target.h.  */
@@ -441,19 +444,19 @@ target_find_memory_regions (find_memory_region_ftype func, void *data)
 gdb::unique_xmalloc_ptr<char>
 target_make_corefile_notes (bfd *bfd, int *size_p)
 {
-  return current_top_target ()->make_corefile_notes (bfd, size_p);
+  return current_inferior ()->top_target ()->make_corefile_notes (bfd, size_p);
 }
 
 gdb_byte *
 target_get_bookmark (const char *args, int from_tty)
 {
-  return current_top_target ()->get_bookmark (args, from_tty);
+  return current_inferior ()->top_target ()->get_bookmark (args, from_tty);
 }
 
 void
 target_goto_bookmark (const gdb_byte *arg, int from_tty)
 {
-  return current_top_target ()->goto_bookmark (arg, from_tty);
+  return current_inferior ()->top_target ()->goto_bookmark (arg, from_tty);
 }
 
 /* See target.h.  */
@@ -461,7 +464,7 @@ target_goto_bookmark (const gdb_byte *arg, int from_tty)
 bool
 target_stopped_by_watchpoint ()
 {
-  return current_top_target ()->stopped_by_watchpoint ();
+  return current_inferior ()->top_target ()->stopped_by_watchpoint ();
 }
 
 /* See target.h.  */
@@ -469,25 +472,29 @@ target_stopped_by_watchpoint ()
 bool
 target_stopped_by_sw_breakpoint ()
 {
-  return current_top_target ()->stopped_by_sw_breakpoint ();
+  return current_inferior ()->top_target ()->stopped_by_sw_breakpoint ();
 }
 
 bool
 target_supports_stopped_by_sw_breakpoint ()
 {
-  return current_top_target ()->supports_stopped_by_sw_breakpoint ();
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->supports_stopped_by_sw_breakpoint ();
 }
 
 bool
 target_stopped_by_hw_breakpoint ()
 {
-  return current_top_target ()->stopped_by_hw_breakpoint ();
+  return current_inferior ()->top_target ()->stopped_by_hw_breakpoint ();
 }
 
 bool
 target_supports_stopped_by_hw_breakpoint ()
 {
-  return current_top_target ()->supports_stopped_by_hw_breakpoint ();
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->supports_stopped_by_hw_breakpoint ();
 }
 
 /* See target.h.  */
@@ -495,7 +502,7 @@ target_supports_stopped_by_hw_breakpoint ()
 bool
 target_have_steppable_watchpoint ()
 {
-  return current_top_target ()->have_steppable_watchpoint ();
+  return current_inferior ()->top_target ()->have_steppable_watchpoint ();
 }
 
 /* See target.h.  */
@@ -503,7 +510,9 @@ target_have_steppable_watchpoint ()
 int
 target_can_use_hardware_watchpoint (bptype type, int cnt, int othertype)
 {
-  return current_top_target ()->can_use_hw_breakpoint (type, cnt, othertype);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->can_use_hw_breakpoint (type, cnt, othertype);
 }
 
 /* See target.h.  */
@@ -511,14 +520,16 @@ target_can_use_hardware_watchpoint (bptype type, int cnt, int othertype)
 int
 target_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
 {
-  return current_top_target ()->region_ok_for_hw_watchpoint (addr, len);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->region_ok_for_hw_watchpoint (addr, len);
 }
 
 
 int
 target_can_do_single_step ()
 {
-  return current_top_target ()->can_do_single_step ();
+  return current_inferior ()->top_target ()->can_do_single_step ();
 }
 
 /* See target.h.  */
@@ -527,7 +538,9 @@ int
 target_insert_watchpoint (CORE_ADDR addr, int len, target_hw_bp_type type,
 			  expression *cond)
 {
-  return current_top_target ()->insert_watchpoint (addr, len, type, cond);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->insert_watchpoint (addr, len, type, cond);
 }
 
 /* See target.h.  */
@@ -536,7 +549,9 @@ int
 target_remove_watchpoint (CORE_ADDR addr, int len, target_hw_bp_type type,
 			  expression *cond)
 {
-  return current_top_target ()->remove_watchpoint (addr, len, type, cond);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->remove_watchpoint (addr, len, type, cond);
 }
 
 /* See target.h.  */
@@ -544,7 +559,9 @@ target_remove_watchpoint (CORE_ADDR addr, int len, target_hw_bp_type type,
 int
 target_insert_hw_breakpoint (gdbarch *gdbarch, bp_target_info *bp_tgt)
 {
-  return current_top_target ()->insert_hw_breakpoint (gdbarch, bp_tgt);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->insert_hw_breakpoint (gdbarch, bp_tgt);
 }
 
 /* See target.h.  */
@@ -552,7 +569,9 @@ target_insert_hw_breakpoint (gdbarch *gdbarch, bp_target_info *bp_tgt)
 int
 target_remove_hw_breakpoint (gdbarch *gdbarch, bp_target_info *bp_tgt)
 {
-  return current_top_target ()->remove_hw_breakpoint (gdbarch, bp_tgt);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->remove_hw_breakpoint (gdbarch, bp_tgt);
 }
 
 /* See target.h.  */
@@ -561,7 +580,9 @@ bool
 target_can_accel_watchpoint_condition (CORE_ADDR addr, int len, int type,
 				       expression *cond)
 {
-  return current_top_target ()->can_accel_watchpoint_condition (addr, len, type, cond);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->can_accel_watchpoint_condition (addr, len, type, cond);
 }
 
 /* See target.h.  */
@@ -569,208 +590,226 @@ target_can_accel_watchpoint_condition (CORE_ADDR addr, int len, int type,
 bool
 target_can_execute_reverse ()
 {
-  return current_top_target ()->can_execute_reverse ();
+  return current_inferior ()->top_target ()->can_execute_reverse ();
 }
 
 ptid_t
 target_get_ada_task_ptid (long lwp, long tid)
 {
-  return current_top_target ()->get_ada_task_ptid (lwp, tid);
+  return current_inferior ()->top_target ()->get_ada_task_ptid (lwp, tid);
 }
 
 bool
 target_filesystem_is_local ()
 {
-  return current_top_target ()->filesystem_is_local ();
+  return current_inferior ()->top_target ()->filesystem_is_local ();
 }
 
 void
 target_trace_init ()
 {
-  return current_top_target ()->trace_init ();
+  return current_inferior ()->top_target ()->trace_init ();
 }
 
 void
 target_download_tracepoint (bp_location *location)
 {
-  return current_top_target ()->download_tracepoint (location);
+  return current_inferior ()->top_target ()->download_tracepoint (location);
 }
 
 bool
 target_can_download_tracepoint ()
 {
-  return current_top_target ()->can_download_tracepoint ();
+  return current_inferior ()->top_target ()->can_download_tracepoint ();
 }
 
 void
 target_download_trace_state_variable (const trace_state_variable &tsv)
 {
-  return current_top_target ()->download_trace_state_variable (tsv);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->download_trace_state_variable (tsv);
 }
 
 void
 target_enable_tracepoint (bp_location *loc)
 {
-  return current_top_target ()->enable_tracepoint (loc);
+  return current_inferior ()->top_target ()->enable_tracepoint (loc);
 }
 
 void
 target_disable_tracepoint (bp_location *loc)
 {
-  return current_top_target ()->disable_tracepoint (loc);
+  return current_inferior ()->top_target ()->disable_tracepoint (loc);
 }
 
 void
 target_trace_start ()
 {
-  return current_top_target ()->trace_start ();
+  return current_inferior ()->top_target ()->trace_start ();
 }
 
 void
 target_trace_set_readonly_regions ()
 {
-  current_top_target ()->trace_set_readonly_regions ();
+  return current_inferior ()->top_target ()->trace_set_readonly_regions ();
 }
 
 int
 target_get_trace_status (trace_status *ts)
 {
-  return current_top_target ()->get_trace_status (ts);
+  return current_inferior ()->top_target ()->get_trace_status (ts);
 }
 
 void
 target_get_tracepoint_status (breakpoint *tp, uploaded_tp *utp)
 {
-  return current_top_target ()->get_tracepoint_status (tp, utp);
+  return current_inferior ()->top_target ()->get_tracepoint_status (tp, utp);
 }
 
 void
 target_trace_stop ()
 {
-  return current_top_target ()->trace_stop ();
+  return current_inferior ()->top_target ()->trace_stop ();
 }
 
 int
 target_trace_find (trace_find_type type, int num,
 		   CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
 {
-  return current_top_target ()->trace_find (type, num, addr1, addr2, tpp);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->trace_find (type, num, addr1, addr2, tpp);
 }
 
 bool
 target_get_trace_state_variable_value (int tsv, LONGEST *val)
 {
-  return current_top_target ()->get_trace_state_variable_value (tsv, val);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->get_trace_state_variable_value (tsv, val);
 }
 
 int
 target_save_trace_data (const char *filename)
 {
-  return current_top_target ()->save_trace_data (filename);
+  return current_inferior ()->top_target ()->save_trace_data (filename);
 }
 
 int
 target_upload_tracepoints (uploaded_tp **utpp)
 {
-  return current_top_target ()->upload_tracepoints (utpp);
+  return current_inferior ()->top_target ()->upload_tracepoints (utpp);
 }
 
 int
 target_upload_trace_state_variables (uploaded_tsv **utsvp)
 {
-  return current_top_target ()->upload_trace_state_variables (utsvp);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->upload_trace_state_variables (utsvp);
 }
 
 LONGEST
 target_get_raw_trace_data (gdb_byte *buf, ULONGEST offset, LONGEST len)
 {
-  return current_top_target ()->get_raw_trace_data (buf, offset, len);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->get_raw_trace_data (buf, offset, len);
 }
 
 int
 target_get_min_fast_tracepoint_insn_len ()
 {
-  return current_top_target ()->get_min_fast_tracepoint_insn_len ();
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->get_min_fast_tracepoint_insn_len ();
 }
 
 void
 target_set_disconnected_tracing (int val)
 {
-  return current_top_target ()->set_disconnected_tracing (val);
+  return current_inferior ()->top_target ()->set_disconnected_tracing (val);
 }
 
 void
 target_set_circular_trace_buffer (int val)
 {
-  return current_top_target ()->set_circular_trace_buffer (val);
+  return current_inferior ()->top_target ()->set_circular_trace_buffer (val);
 }
 
 void
 target_set_trace_buffer_size (LONGEST val)
 {
-  return current_top_target ()->set_trace_buffer_size (val);
+  return current_inferior ()->top_target ()->set_trace_buffer_size (val);
 }
 
 bool
 target_set_trace_notes (const char *user, const char *notes,
 			const char *stopnotes)
 {
-  return current_top_target ()->set_trace_notes (user, notes, stopnotes);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->set_trace_notes (user, notes, stopnotes);
 }
 
 bool
 target_get_tib_address (ptid_t ptid, CORE_ADDR *addr)
 {
-  return current_top_target ()->get_tib_address (ptid, addr);
+  return current_inferior ()->top_target ()->get_tib_address (ptid, addr);
 }
 
 void
 target_set_permissions ()
 {
-  return current_top_target ()->set_permissions ();
+  return current_inferior ()->top_target ()->set_permissions ();
 }
 
 bool
 target_static_tracepoint_marker_at (CORE_ADDR addr,
 				    static_tracepoint_marker *marker)
 {
-  return current_top_target ()->static_tracepoint_marker_at (addr, marker);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->static_tracepoint_marker_at (addr, marker);
 }
 
 std::vector<static_tracepoint_marker>
 target_static_tracepoint_markers_by_strid (const char *marker_id)
 {
-  return current_top_target ()->static_tracepoint_markers_by_strid (marker_id);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->static_tracepoint_markers_by_strid (marker_id);
 }
 
 traceframe_info_up
 target_traceframe_info ()
 {
-  return current_top_target ()->traceframe_info ();
+  return current_inferior ()->top_target ()->traceframe_info ();
 }
 
 bool
 target_use_agent (bool use)
 {
-  return current_top_target ()->use_agent (use);
+  return current_inferior ()->top_target ()->use_agent (use);
 }
 
 bool
 target_can_use_agent ()
 {
-  return current_top_target ()->can_use_agent ();
+  return current_inferior ()->top_target ()->can_use_agent ();
 }
 
 bool
 target_augmented_libraries_svr4_read ()
 {
-  return current_top_target ()->augmented_libraries_svr4_read ();
+  return current_inferior ()->top_target ()->augmented_libraries_svr4_read ();
 }
 
 void
 target_log_command (const char *p)
 {
-  return current_top_target ()->log_command (p);
+  return current_inferior ()->top_target ()->log_command (p);
 }
 
 /* This is used to implement the various target commands.  */
@@ -843,14 +882,14 @@ add_deprecated_target_alias (const target_info &tinfo, const char *alias)
 void
 target_kill (void)
 {
-  current_top_target ()->kill ();
+  current_inferior ()->top_target ()->kill ();
 }
 
 void
 target_load (const char *arg, int from_tty)
 {
   target_dcache_invalidate ();
-  current_top_target ()->load (arg, from_tty);
+  current_inferior ()->top_target ()->load (arg, from_tty);
 }
 
 /* Define it.  */
@@ -863,7 +902,7 @@ target_terminal_state target_terminal::m_terminal_state
 void
 target_terminal::init (void)
 {
-  current_top_target ()->terminal_init ();
+  current_inferior ()->top_target ()->terminal_init ();
 
   m_terminal_state = target_terminal_state::is_ours;
 }
@@ -894,7 +933,7 @@ target_terminal::inferior (void)
 
   if (inf->terminal_state != target_terminal_state::is_inferior)
     {
-      current_top_target ()->terminal_inferior ();
+      current_inferior ()->top_target ()->terminal_inferior ();
       inf->terminal_state = target_terminal_state::is_inferior;
     }
 
@@ -929,7 +968,7 @@ target_terminal::restore_inferior (void)
 	if (inf->terminal_state == target_terminal_state::is_ours_for_output)
 	  {
 	    set_current_inferior (inf);
-	    current_top_target ()->terminal_inferior ();
+	    current_inferior ()->top_target ()->terminal_inferior ();
 	    inf->terminal_state = target_terminal_state::is_inferior;
 	  }
       }
@@ -961,7 +1000,7 @@ target_terminal_is_ours_kind (target_terminal_state desired_state)
       if (inf->terminal_state == target_terminal_state::is_inferior)
 	{
 	  set_current_inferior (inf);
-	  current_top_target ()->terminal_save_inferior ();
+	  current_inferior ()->top_target ()->terminal_save_inferior ();
 	}
     }
 
@@ -976,9 +1015,9 @@ target_terminal_is_ours_kind (target_terminal_state desired_state)
 	{
 	  set_current_inferior (inf);
 	  if (desired_state == target_terminal_state::is_ours)
-	    current_top_target ()->terminal_ours ();
+	    current_inferior ()->top_target ()->terminal_ours ();
 	  else if (desired_state == target_terminal_state::is_ours_for_output)
-	    current_top_target ()->terminal_ours_for_output ();
+	    current_inferior ()->top_target ()->terminal_ours_for_output ();
 	  else
 	    gdb_assert_not_reached ("unhandled desired state");
 	  inf->terminal_state = desired_state;
@@ -1027,7 +1066,7 @@ target_terminal::ours_for_output ()
 void
 target_terminal::info (const char *arg, int from_tty)
 {
-  current_top_target ()->terminal_info (arg, from_tty);
+  current_inferior ()->top_target ()->terminal_info (arg, from_tty);
 }
 
 /* See target.h.  */
@@ -1051,7 +1090,7 @@ static void
 tcomplain (void)
 {
   error (_("You can't do that when your target is `%s'"),
-	 current_top_target ()->shortname ());
+	 current_inferior ()->top_target ()->shortname ());
 }
 
 void
@@ -1186,8 +1225,9 @@ unpush_target_and_assert (struct target_ops *target)
 void
 pop_all_targets_above (enum strata above_stratum)
 {
-  while ((int) (current_top_target ()->stratum ()) > (int) above_stratum)
-    unpush_target_and_assert (current_top_target ());
+  while ((int) (current_inferior ()->top_target ()->stratum ())
+	 > (int) above_stratum)
+    unpush_target_and_assert (current_inferior ()->top_target ());
 }
 
 /* See target.h.  */
@@ -1195,8 +1235,9 @@ pop_all_targets_above (enum strata above_stratum)
 void
 pop_all_targets_at_and_above (enum strata stratum)
 {
-  while ((int) (current_top_target ()->stratum ()) >= (int) stratum)
-    unpush_target_and_assert (current_top_target ());
+  while ((int) (current_inferior ()->top_target ()->stratum ())
+	 >= (int) stratum)
+    unpush_target_and_assert (current_inferior ()->top_target ());
 }
 
 void
@@ -1226,7 +1267,7 @@ CORE_ADDR
 target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
 {
   volatile CORE_ADDR addr = 0;
-  struct target_ops *target = current_top_target ();
+  struct target_ops *target = current_inferior ()->top_target ();
   struct gdbarch *gdbarch = target_gdbarch ();
 
   if (gdbarch_fetch_tls_load_module_address_p (gdbarch))
@@ -1745,7 +1786,8 @@ target_xfer_partial (struct target_ops *ops,
 int
 target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
 {
-  if (target_read (current_top_target (), TARGET_OBJECT_MEMORY, NULL,
+  if (target_read (current_inferior ()->top_target (),
+		   TARGET_OBJECT_MEMORY, NULL,
 		   myaddr, memaddr, len) == len)
     return 0;
   else
@@ -1775,7 +1817,8 @@ target_read_uint32 (CORE_ADDR memaddr, uint32_t *result)
 int
 target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
 {
-  if (target_read (current_top_target (), TARGET_OBJECT_RAW_MEMORY, NULL,
+  if (target_read (current_inferior ()->top_target (),
+		   TARGET_OBJECT_RAW_MEMORY, NULL,
 		   myaddr, memaddr, len) == len)
     return 0;
   else
@@ -1788,7 +1831,8 @@ target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
 int
 target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
 {
-  if (target_read (current_top_target (), TARGET_OBJECT_STACK_MEMORY, NULL,
+  if (target_read (current_inferior ()->top_target (),
+		   TARGET_OBJECT_STACK_MEMORY, NULL,
 		   myaddr, memaddr, len) == len)
     return 0;
   else
@@ -1801,7 +1845,8 @@ target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
 int
 target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
 {
-  if (target_read (current_top_target (), TARGET_OBJECT_CODE_MEMORY, NULL,
+  if (target_read (current_inferior ()->top_target (),
+		   TARGET_OBJECT_CODE_MEMORY, NULL,
 		   myaddr, memaddr, len) == len)
     return 0;
   else
@@ -1817,7 +1862,8 @@ target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
 int
 target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
 {
-  if (target_write (current_top_target (), TARGET_OBJECT_MEMORY, NULL,
+  if (target_write (current_inferior ()->top_target (),
+		    TARGET_OBJECT_MEMORY, NULL,
 		    myaddr, memaddr, len) == len)
     return 0;
   else
@@ -1833,7 +1879,8 @@ target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
 int
 target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
 {
-  if (target_write (current_top_target (), TARGET_OBJECT_RAW_MEMORY, NULL,
+  if (target_write (current_inferior ()->top_target (),
+		    TARGET_OBJECT_RAW_MEMORY, NULL,
 		    myaddr, memaddr, len) == len)
     return 0;
   else
@@ -1845,7 +1892,8 @@ target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
 std::vector<mem_region>
 target_memory_map (void)
 {
-  std::vector<mem_region> result = current_top_target ()->memory_map ();
+  target_ops *target = current_inferior ()->top_target ();
+  std::vector<mem_region> result = target->memory_map ();
   if (result.empty ())
     return result;
 
@@ -1875,13 +1923,13 @@ target_memory_map (void)
 void
 target_flash_erase (ULONGEST address, LONGEST length)
 {
-  current_top_target ()->flash_erase (address, length);
+  current_inferior ()->top_target ()->flash_erase (address, length);
 }
 
 void
 target_flash_done (void)
 {
-  current_top_target ()->flash_done ();
+  current_inferior ()->top_target ()->flash_done ();
 }
 
 static void
@@ -2336,7 +2384,9 @@ target_insert_breakpoint (struct gdbarch *gdbarch,
       return 1;
     }
 
-  return current_top_target ()->insert_breakpoint (gdbarch, bp_tgt);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->insert_breakpoint (gdbarch, bp_tgt);
 }
 
 /* See target.h.  */
@@ -2356,7 +2406,9 @@ target_remove_breakpoint (struct gdbarch *gdbarch,
       return 1;
     }
 
-  return current_top_target ()->remove_breakpoint (gdbarch, bp_tgt, reason);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->remove_breakpoint (gdbarch, bp_tgt, reason);
 }
 
 static void
@@ -2371,7 +2423,9 @@ info_target_command (const char *args, int from_tty)
 			 objfile_name (objf));
     }
 
-  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
+  for (target_ops *t = current_inferior ()->top_target ();
+       t != NULL;
+       t = t->beneath ())
     {
       if (!t->has_memory ())
 	continue;
@@ -2491,7 +2545,7 @@ target_detach (inferior *inf, int from_tty)
      target.  */
   auto proc_target_ref = target_ops_ref::new_reference (inf->process_target ());
 
-  current_top_target ()->detach (inf, from_tty);
+  current_inferior ()->top_target ()->detach (inf, from_tty);
 
   process_stratum_target *proc_target
     = as_process_stratum_target (proc_target_ref.get ());
@@ -2513,7 +2567,7 @@ target_disconnect (const char *args, int from_tty)
      disconnecting.  */
   remove_breakpoints ();
 
-  current_top_target ()->disconnect (args, from_tty);
+  current_inferior ()->top_target ()->disconnect (args, from_tty);
 }
 
 /* See target/target.h.  */
@@ -2522,7 +2576,7 @@ ptid_t
 target_wait (ptid_t ptid, struct target_waitstatus *status,
 	     target_wait_flags options)
 {
-  target_ops *target = current_top_target ();
+  target_ops *target = current_inferior ()->top_target ();
 
   if (!target->can_async_p ())
     gdb_assert ((options & TARGET_WNOHANG) == 0);
@@ -2544,7 +2598,7 @@ default_target_wait (struct target_ops *ops,
 std::string
 target_pid_to_str (ptid_t ptid)
 {
-  return current_top_target ()->pid_to_str (ptid);
+  return current_inferior ()->top_target ()->pid_to_str (ptid);
 }
 
 const char *
@@ -2552,7 +2606,7 @@ target_thread_name (struct thread_info *info)
 {
   gdb_assert (info->inf == current_inferior ());
 
-  return current_top_target ()->thread_name (info);
+  return current_inferior ()->top_target ()->thread_name (info);
 }
 
 struct thread_info *
@@ -2560,8 +2614,9 @@ target_thread_handle_to_thread_info (const gdb_byte *thread_handle,
 				     int handle_len,
 				     struct inferior *inf)
 {
-  return current_top_target ()->thread_handle_to_thread_info (thread_handle,
-						     handle_len, inf);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->thread_handle_to_thread_info (thread_handle, handle_len, inf);
 }
 
 /* See target.h.  */
@@ -2569,7 +2624,9 @@ target_thread_handle_to_thread_info (const gdb_byte *thread_handle,
 gdb::byte_vector
 target_thread_info_to_thread_handle (struct thread_info *tip)
 {
-  return current_top_target ()->thread_info_to_thread_handle (tip);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->thread_info_to_thread_handle (tip);
 }
 
 void
@@ -2579,7 +2636,7 @@ target_resume (ptid_t ptid, int step, enum gdb_signal signal)
 
   target_dcache_invalidate ();
 
-  current_top_target ()->resume (ptid, step, signal);
+  current_inferior ()->top_target ()->resume (ptid, step, signal);
 
   registers_changed_ptid (curr_target, ptid);
   /* We only set the internal executing state here.  The user/frontend
@@ -2600,7 +2657,7 @@ target_commit_resume (void)
   if (defer_target_commit_resume)
     return;
 
-  current_top_target ()->commit_resume ();
+  current_inferior ()->top_target ()->commit_resume ();
 }
 
 /* See target.h.  */
@@ -2614,13 +2671,13 @@ make_scoped_defer_target_commit_resume ()
 void
 target_pass_signals (gdb::array_view<const unsigned char> pass_signals)
 {
-  current_top_target ()->pass_signals (pass_signals);
+  current_inferior ()->top_target ()->pass_signals (pass_signals);
 }
 
 void
 target_program_signals (gdb::array_view<const unsigned char> program_signals)
 {
-  current_top_target ()->program_signals (program_signals);
+  current_inferior ()->top_target ()->program_signals (program_signals);
 }
 
 static bool
@@ -2638,7 +2695,9 @@ default_follow_fork (struct target_ops *self, bool follow_child,
 bool
 target_follow_fork (bool follow_child, bool detach_fork)
 {
-  return current_top_target ()->follow_fork (follow_child, detach_fork);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->follow_fork (follow_child, detach_fork);
 }
 
 /* Target wrapper for follow exec hook.  */
@@ -2646,7 +2705,7 @@ target_follow_fork (bool follow_child, bool detach_fork)
 void
 target_follow_exec (struct inferior *inf, const char *execd_pathname)
 {
-  current_top_target ()->follow_exec (inf, execd_pathname);
+  current_inferior ()->top_target ()->follow_exec (inf, execd_pathname);
 }
 
 static void
@@ -2660,7 +2719,7 @@ void
 target_mourn_inferior (ptid_t ptid)
 {
   gdb_assert (ptid.pid () == inferior_ptid.pid ());
-  current_top_target ()->mourn_inferior ();
+  current_inferior ()->top_target ()->mourn_inferior ();
 
   /* We no longer need to keep handles on any of the object files.
      Make sure to release them to avoid unnecessarily locking any
@@ -2688,7 +2747,8 @@ default_search_memory (struct target_ops *self,
 {
   auto read_memory = [=] (CORE_ADDR addr, gdb_byte *result, size_t len)
     {
-      return target_read (current_top_target (), TARGET_OBJECT_MEMORY, NULL,
+      return target_read (current_inferior ()->top_target (),
+			  TARGET_OBJECT_MEMORY, NULL,
 			  result, addr, len) == len;
     };
 
@@ -2709,8 +2769,10 @@ target_search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
 		      const gdb_byte *pattern, ULONGEST pattern_len,
 		      CORE_ADDR *found_addrp)
 {
-  return current_top_target ()->search_memory (start_addr, search_space_len,
-				      pattern, pattern_len, found_addrp);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->search_memory (start_addr, search_space_len, pattern,
+				pattern_len, found_addrp);
 }
 
 /* Look through the currently pushed targets.  If none of them will
@@ -2720,7 +2782,9 @@ target_search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
 void
 target_require_runnable (void)
 {
-  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
+  for (target_ops *t = current_inferior ()->top_target ();
+       t != NULL;
+       t = t->beneath ())
     {
       /* If this target knows how to create a new program, then
 	 assume we will still be able to after killing the current
@@ -2810,7 +2874,9 @@ struct target_ops *
 find_attach_target (void)
 {
   /* If a target on the current stack can attach, use it.  */
-  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
+  for (target_ops *t = current_inferior ()->top_target ();
+       t != NULL;
+       t = t->beneath ())
     {
       if (t->can_attach ())
 	return t;
@@ -2826,7 +2892,9 @@ struct target_ops *
 find_run_target (void)
 {
   /* If a target on the current stack can run, use it.  */
-  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
+  for (target_ops *t = current_inferior ()->top_target ();
+       t != NULL;
+       t = t->beneath ())
     {
       if (t->can_create_inferior ())
 	return t;
@@ -2885,7 +2953,7 @@ find_default_supports_disable_randomization (struct target_ops *self)
 int
 target_supports_disable_randomization (void)
 {
-  return current_top_target ()->supports_disable_randomization ();
+  return current_inferior ()->top_target ()->supports_disable_randomization ();
 }
 
 /* See target/target.h.  */
@@ -2893,7 +2961,7 @@ target_supports_disable_randomization (void)
 int
 target_supports_multi_process (void)
 {
-  return current_top_target ()->supports_multi_process ();
+  return current_inferior ()->top_target ()->supports_multi_process ();
 }
 
 /* See target.h.  */
@@ -2923,7 +2991,7 @@ target_thread_address_space (ptid_t ptid)
 {
   struct address_space *aspace;
 
-  aspace = current_top_target ()->thread_address_space (ptid);
+  aspace = current_inferior ()->top_target ()->thread_address_space (ptid);
   gdb_assert (aspace != NULL);
 
   return aspace;
@@ -2976,7 +3044,9 @@ target_ops::can_run ()
 int
 target_can_run ()
 {
-  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
+  for (target_ops *t = current_inferior ()->top_target ();
+       t != NULL;
+       t = t->beneath ())
     {
       if (t->can_run ())
 	return 1;
@@ -3659,13 +3729,13 @@ target_close (struct target_ops *targ)
 int
 target_thread_alive (ptid_t ptid)
 {
-  return current_top_target ()->thread_alive (ptid);
+  return current_inferior ()->top_target ()->thread_alive (ptid);
 }
 
 void
 target_update_thread_list (void)
 {
-  current_top_target ()->update_thread_list ();
+  current_inferior ()->top_target ()->update_thread_list ();
 }
 
 void
@@ -3677,7 +3747,7 @@ target_stop (ptid_t ptid)
       return;
     }
 
-  current_top_target ()->stop (ptid);
+  current_inferior ()->top_target ()->stop (ptid);
 }
 
 void
@@ -3689,7 +3759,7 @@ target_interrupt ()
       return;
     }
 
-  current_top_target ()->interrupt ();
+  current_inferior ()->top_target ()->interrupt ();
 }
 
 /* See target.h.  */
@@ -3719,7 +3789,7 @@ target_pass_ctrlc (void)
 		 through the target_stack.  */
 	      scoped_restore_current_inferior restore_inferior;
 	      set_current_inferior (inf);
-	      current_top_target ()->pass_ctrlc ();
+	      current_inferior ()->top_target ()->pass_ctrlc ();
 	      return;
 	    }
 	}
@@ -3814,7 +3884,7 @@ target_options_to_string (target_wait_flags target_options)
 void
 target_fetch_registers (struct regcache *regcache, int regno)
 {
-  current_top_target ()->fetch_registers (regcache, regno);
+  current_inferior ()->top_target ()->fetch_registers (regcache, regno);
   if (targetdebug)
     regcache->debug_print_register ("target_fetch_registers", regno);
 }
@@ -3825,7 +3895,7 @@ target_store_registers (struct regcache *regcache, int regno)
   if (!may_write_registers)
     error (_("Writing to registers is not allowed (regno %d)"), regno);
 
-  current_top_target ()->store_registers (regcache, regno);
+  current_inferior ()->top_target ()->store_registers (regcache, regno);
   if (targetdebug)
     {
       regcache->debug_print_register ("target_store_registers", regno);
@@ -3835,7 +3905,7 @@ target_store_registers (struct regcache *regcache, int regno)
 int
 target_core_of_thread (ptid_t ptid)
 {
-  return current_top_target ()->core_of_thread (ptid);
+  return current_inferior ()->top_target ()->core_of_thread (ptid);
 }
 
 int
@@ -3873,14 +3943,16 @@ default_verify_memory (struct target_ops *self,
 		       const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
 {
   /* Start over from the top of the target stack.  */
-  return simple_verify_memory (current_top_target (),
+  return simple_verify_memory (current_inferior ()->top_target (),
 			       data, memaddr, size);
 }
 
 int
 target_verify_memory (const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
 {
-  return current_top_target ()->verify_memory (data, memaddr, size);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->verify_memory (data, memaddr, size);
 }
 
 /* The documentation for this function is in its prototype declaration in
@@ -3890,7 +3962,9 @@ int
 target_insert_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask,
 			       enum target_hw_bp_type rw)
 {
-  return current_top_target ()->insert_mask_watchpoint (addr, mask, rw);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->insert_mask_watchpoint (addr, mask, rw);
 }
 
 /* The documentation for this function is in its prototype declaration in
@@ -3900,7 +3974,9 @@ int
 target_remove_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask,
 			       enum target_hw_bp_type rw)
 {
-  return current_top_target ()->remove_mask_watchpoint (addr, mask, rw);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->remove_mask_watchpoint (addr, mask, rw);
 }
 
 /* The documentation for this function is in its prototype declaration
@@ -3909,7 +3985,9 @@ target_remove_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask,
 int
 target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask)
 {
-  return current_top_target ()->masked_watch_num_registers (addr, mask);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->masked_watch_num_registers (addr, mask);
 }
 
 /* The documentation for this function is in its prototype declaration
@@ -3918,7 +3996,7 @@ target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask)
 int
 target_ranged_break_num_registers (void)
 {
-  return current_top_target ()->ranged_break_num_registers ();
+  return current_inferior ()->top_target ()->ranged_break_num_registers ();
 }
 
 /* See target.h.  */
@@ -3926,7 +4004,7 @@ target_ranged_break_num_registers (void)
 struct btrace_target_info *
 target_enable_btrace (ptid_t ptid, const struct btrace_config *conf)
 {
-  return current_top_target ()->enable_btrace (ptid, conf);
+  return current_inferior ()->top_target ()->enable_btrace (ptid, conf);
 }
 
 /* See target.h.  */
@@ -3934,7 +4012,7 @@ target_enable_btrace (ptid_t ptid, const struct btrace_config *conf)
 void
 target_disable_btrace (struct btrace_target_info *btinfo)
 {
-  current_top_target ()->disable_btrace (btinfo);
+  current_inferior ()->top_target ()->disable_btrace (btinfo);
 }
 
 /* See target.h.  */
@@ -3942,7 +4020,7 @@ target_disable_btrace (struct btrace_target_info *btinfo)
 void
 target_teardown_btrace (struct btrace_target_info *btinfo)
 {
-  current_top_target ()->teardown_btrace (btinfo);
+  current_inferior ()->top_target ()->teardown_btrace (btinfo);
 }
 
 /* See target.h.  */
@@ -3952,7 +4030,9 @@ target_read_btrace (struct btrace_data *btrace,
 		    struct btrace_target_info *btinfo,
 		    enum btrace_read_type type)
 {
-  return current_top_target ()->read_btrace (btrace, btinfo, type);
+  target_ops *target = current_inferior ()->top_target ();
+
+  return target->read_btrace (btrace, btinfo, type);
 }
 
 /* See target.h.  */
@@ -3960,7 +4040,7 @@ target_read_btrace (struct btrace_data *btrace,
 const struct btrace_config *
 target_btrace_conf (const struct btrace_target_info *btinfo)
 {
-  return current_top_target ()->btrace_conf (btinfo);
+  return current_inferior ()->top_target ()->btrace_conf (btinfo);
 }
 
 /* See target.h.  */
@@ -3968,7 +4048,7 @@ target_btrace_conf (const struct btrace_target_info *btinfo)
 void
 target_stop_recording (void)
 {
-  current_top_target ()->stop_recording ();
+  current_inferior ()->top_target ()->stop_recording ();
 }
 
 /* See target.h.  */
@@ -3976,7 +4056,7 @@ target_stop_recording (void)
 void
 target_save_record (const char *filename)
 {
-  current_top_target ()->save_record (filename);
+  current_inferior ()->top_target ()->save_record (filename);
 }
 
 /* See target.h.  */
@@ -3984,7 +4064,7 @@ target_save_record (const char *filename)
 int
 target_supports_delete_record ()
 {
-  return current_top_target ()->supports_delete_record ();
+  return current_inferior ()->top_target ()->supports_delete_record ();
 }
 
 /* See target.h.  */
@@ -3992,7 +4072,7 @@ target_supports_delete_record ()
 void
 target_delete_record (void)
 {
-  current_top_target ()->delete_record ();
+  current_inferior ()->top_target ()->delete_record ();
 }
 
 /* See target.h.  */
@@ -4000,7 +4080,7 @@ target_delete_record (void)
 enum record_method
 target_record_method (ptid_t ptid)
 {
-  return current_top_target ()->record_method (ptid);
+  return current_inferior ()->top_target ()->record_method (ptid);
 }
 
 /* See target.h.  */
@@ -4008,7 +4088,7 @@ target_record_method (ptid_t ptid)
 int
 target_record_is_replaying (ptid_t ptid)
 {
-  return current_top_target ()->record_is_replaying (ptid);
+  return current_inferior ()->top_target ()->record_is_replaying (ptid);
 }
 
 /* See target.h.  */
@@ -4016,7 +4096,7 @@ target_record_is_replaying (ptid_t ptid)
 int
 target_record_will_replay (ptid_t ptid, int dir)
 {
-  return current_top_target ()->record_will_replay (ptid, dir);
+  return current_inferior ()->top_target ()->record_will_replay (ptid, dir);
 }
 
 /* See target.h.  */
@@ -4024,7 +4104,7 @@ target_record_will_replay (ptid_t ptid, int dir)
 void
 target_record_stop_replaying (void)
 {
-  current_top_target ()->record_stop_replaying ();
+  current_inferior ()->top_target ()->record_stop_replaying ();
 }
 
 /* See target.h.  */
@@ -4032,7 +4112,7 @@ target_record_stop_replaying (void)
 void
 target_goto_record_begin (void)
 {
-  current_top_target ()->goto_record_begin ();
+  current_inferior ()->top_target ()->goto_record_begin ();
 }
 
 /* See target.h.  */
@@ -4040,7 +4120,7 @@ target_goto_record_begin (void)
 void
 target_goto_record_end (void)
 {
-  current_top_target ()->goto_record_end ();
+  current_inferior ()->top_target ()->goto_record_end ();
 }
 
 /* See target.h.  */
@@ -4048,7 +4128,7 @@ target_goto_record_end (void)
 void
 target_goto_record (ULONGEST insn)
 {
-  current_top_target ()->goto_record (insn);
+  current_inferior ()->top_target ()->goto_record (insn);
 }
 
 /* See target.h.  */
@@ -4056,7 +4136,7 @@ target_goto_record (ULONGEST insn)
 void
 target_insn_history (int size, gdb_disassembly_flags flags)
 {
-  current_top_target ()->insn_history (size, flags);
+  current_inferior ()->top_target ()->insn_history (size, flags);
 }
 
 /* See target.h.  */
@@ -4065,7 +4145,7 @@ void
 target_insn_history_from (ULONGEST from, int size,
 			  gdb_disassembly_flags flags)
 {
-  current_top_target ()->insn_history_from (from, size, flags);
+  current_inferior ()->top_target ()->insn_history_from (from, size, flags);
 }
 
 /* See target.h.  */
@@ -4074,7 +4154,7 @@ void
 target_insn_history_range (ULONGEST begin, ULONGEST end,
 			   gdb_disassembly_flags flags)
 {
-  current_top_target ()->insn_history_range (begin, end, flags);
+  current_inferior ()->top_target ()->insn_history_range (begin, end, flags);
 }
 
 /* See target.h.  */
@@ -4082,7 +4162,7 @@ target_insn_history_range (ULONGEST begin, ULONGEST end,
 void
 target_call_history (int size, record_print_flags flags)
 {
-  current_top_target ()->call_history (size, flags);
+  current_inferior ()->top_target ()->call_history (size, flags);
 }
 
 /* See target.h.  */
@@ -4090,7 +4170,7 @@ target_call_history (int size, record_print_flags flags)
 void
 target_call_history_from (ULONGEST begin, int size, record_print_flags flags)
 {
-  current_top_target ()->call_history_from (begin, size, flags);
+  current_inferior ()->top_target ()->call_history_from (begin, size, flags);
 }
 
 /* See target.h.  */
@@ -4098,7 +4178,7 @@ target_call_history_from (ULONGEST begin, int size, record_print_flags flags)
 void
 target_call_history_range (ULONGEST begin, ULONGEST end, record_print_flags flags)
 {
-  current_top_target ()->call_history_range (begin, end, flags);
+  current_inferior ()->top_target ()->call_history_range (begin, end, flags);
 }
 
 /* See target.h.  */
@@ -4106,7 +4186,7 @@ target_call_history_range (ULONGEST begin, ULONGEST end, record_print_flags flag
 const struct frame_unwind *
 target_get_unwinder (void)
 {
-  return current_top_target ()->get_unwinder ();
+  return current_inferior ()->top_target ()->get_unwinder ();
 }
 
 /* See target.h.  */
@@ -4114,7 +4194,7 @@ target_get_unwinder (void)
 const struct frame_unwind *
 target_get_tailcall_unwinder (void)
 {
-  return current_top_target ()->get_tailcall_unwinder ();
+  return current_inferior ()->top_target ()->get_tailcall_unwinder ();
 }
 
 /* See target.h.  */
@@ -4122,7 +4202,7 @@ target_get_tailcall_unwinder (void)
 void
 target_prepare_to_generate_core (void)
 {
-  current_top_target ()->prepare_to_generate_core ();
+  current_inferior ()->top_target ()->prepare_to_generate_core ();
 }
 
 /* See target.h.  */
@@ -4130,7 +4210,7 @@ target_prepare_to_generate_core (void)
 void
 target_done_generating_core (void)
 {
-  current_top_target ()->done_generating_core ();
+  current_inferior ()->top_target ()->done_generating_core ();
 }
 
 \f
@@ -4198,7 +4278,9 @@ maintenance_print_target_stack (const char *cmd, int from_tty)
 {
   printf_filtered (_("The current target stack is:\n"));
 
-  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
+  for (target_ops *t = current_inferior ()->top_target ();
+       t != NULL;
+       t = t->beneath ())
     {
       if (t->stratum () == debug_stratum)
 	continue;
@@ -4212,7 +4294,7 @@ void
 target_async (int enable)
 {
   infrun_async (enable);
-  current_top_target ()->async (enable);
+  current_inferior ()->top_target ()->async (enable);
 }
 
 /* See target.h.  */
@@ -4220,7 +4302,7 @@ target_async (int enable)
 void
 target_thread_events (int enable)
 {
-  current_top_target ()->thread_events (enable);
+  current_inferior ()->top_target ()->thread_events (enable);
 }
 
 /* Controls if targets can report that they can/are async.  This is
@@ -4260,7 +4342,7 @@ maint_show_target_async_command (struct ui_file *file, int from_tty,
 static int
 target_always_non_stop_p (void)
 {
-  return current_top_target ()->always_non_stop_p ();
+  return current_inferior ()->top_target ()->always_non_stop_p ();
 }
 
 /* See target.h.  */
diff --git a/gdb/target.h b/gdb/target.h
index 8b223c0283f..39dc10a7446 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1353,11 +1353,6 @@ class target_stack
   target_ops *m_stack[(int) debug_stratum + 1] {};
 };
 
-/* The ops structure for our "current" target process.  This should
-   never be NULL.  If there is no target, it points to the dummy_target.  */
-
-extern target_ops *current_top_target ();
-
 /* Return the dummy target.  */
 extern target_ops *get_dummy_target ();
 
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index d82cac8d9dd..33ce86bbe23 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -310,7 +310,7 @@ tfile_write_tdesc (struct trace_file_writer *self)
     = (struct tfile_trace_file_writer *) self;
 
   gdb::optional<std::string> tdesc
-    = target_fetch_description_xml (current_top_target ());
+    = target_fetch_description_xml (current_inferior ()->top_target ());
 
   if (!tdesc)
     return;
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index bf8a63c5966..48d72d6a1f2 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -3812,7 +3812,8 @@ sdata_make_value (struct gdbarch *gdbarch, struct internalvar *var,
 {
   /* We need to read the whole object before we know its size.  */
   gdb::optional<gdb::byte_vector> buf
-    = target_read_alloc (current_top_target (), TARGET_OBJECT_STATIC_TRACE_DATA,
+    = target_read_alloc (current_inferior ()->top_target (),
+			 TARGET_OBJECT_STATIC_TRACE_DATA,
 			 NULL);
   if (buf)
     {
diff --git a/gdb/valops.c b/gdb/valops.c
index fec821ad932..f86c9818058 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1040,7 +1040,7 @@ read_value_memory (struct value *val, LONGEST bit_offset,
       enum target_xfer_status status;
       ULONGEST xfered_partial;
 
-      status = target_xfer_partial (current_top_target (),
+      status = target_xfer_partial (current_inferior ()->top_target (),
 				    object, NULL,
 				    buffer + xfered_total * unit_size, NULL,
 				    memaddr + xfered_total,
@@ -1286,7 +1286,8 @@ value_assign (struct value *toval, struct value *fromval)
     case lval_register:
     case lval_computed:
 
-      gdb::observers::target_changed.notify (current_top_target ());
+      gdb::observers::target_changed.notify
+	(current_inferior ()->top_target ());
 
       /* Having destroyed the frame cache, restore the selected
 	 frame.  */
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 340a329f9d0..56a9306dcc1 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -42,6 +42,7 @@
 #include "count-one-bits.h"
 #include "c-lang.h"
 #include "cp-abi.h"
+#include "inferior.h"
 
 /* Maximum number of wchars returned from wchar_iterate.  */
 #define MAX_WCHARS 4
@@ -1836,9 +1837,8 @@ print_function_pointer_address (const struct value_print_options *options,
 				CORE_ADDR address,
 				struct ui_file *stream)
 {
-  CORE_ADDR func_addr
-    = gdbarch_convert_from_func_ptr_addr (gdbarch, address,
-					  current_top_target ());
+  CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr
+    (gdbarch, address, current_inferior ()->top_target ());
 
   /* If the function pointer is represented by a description, print
      the address of the description.  */
diff --git a/gdb/value.c b/gdb/value.c
index 9527186f57a..3bd81e76007 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -45,6 +45,7 @@
 #include "gdbsupport/array-view.h"
 #include "cli/cli-style.h"
 #include "expop.h"
+#include "inferior.h"
 
 /* Definition of a user function.  */
 struct internal_function
@@ -3159,7 +3160,8 @@ value_fn_field (struct value **arg1p, struct fn_field *f,
 
       set_value_address (v,
 	gdbarch_convert_from_func_ptr_addr
-	   (gdbarch, BMSYMBOL_VALUE_ADDRESS (msym), current_top_target ()));
+	   (gdbarch, BMSYMBOL_VALUE_ADDRESS (msym),
+	    current_inferior ()->top_target ()));
     }
 
   if (arg1p)
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index a06b44822d4..97aa3da6e77 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -487,7 +487,7 @@ display_one_tib (ptid_t ptid)
       return -1;
     }
 
-  if (target_read (current_top_target (), TARGET_OBJECT_MEMORY,
+  if (target_read (current_inferior ()->top_target (), TARGET_OBJECT_MEMORY,
 		   NULL, tib, thread_local_base, tib_size) != tib_size)
     {
       printf_filtered (_("Unable to read thread information "
-- 
2.30.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] gdb: move all "current target" wrapper implementations to target.c
  2021-03-23 18:41 [PATCH 1/2] gdb: move all "current target" wrapper implementations to target.c Simon Marchi
  2021-03-23 18:41 ` [PATCH 2/2] gdb: remove current_top_target function Simon Marchi
@ 2021-03-24  9:29 ` Andrew Burgess
  2021-03-24 14:04   ` Simon Marchi
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Burgess @ 2021-03-24  9:29 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

* Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2021-03-23 14:41:37 -0400]:

> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> The following patch removes the current_top_target function, replacing
> uses with `current_inferior ()->top_target ()`.  This is a problem for
> uses in target.h, because they don't have access to the current_inferior
> function and the inferior structure: target.h can't include inferior.h,
> otherwise that would make a cyclic inclusion.
> 
> Avoid this by moving all implementations of the wrappers that call
> target methods with the current target to target.c.  Many of them are
> changed from a macro to a function, which is an improvement for
> readability and debuggability, IMO.
> 
> target_shortname and target_longname were not function-like macros, so a
> few adjustments are needed.

This all makes sense and seems like an improvement.  I had just one
observation...

> 
> gdb/ChangeLog:
> 
> 	* target.h (target_shortname): Change to function declaration.
> 	(target_longname): Likewise.
> 	(target_attach_no_wait): Likewise.
> 	(target_post_attach): Likewise.
> 	(target_prepare_to_store): Likewise.
> 	(target_supports_enable_disable_tracepoint): Likewise.
> 	(target_supports_string_tracing): Likewise.
> 	(target_supports_evaluation_of_breakpoint_conditions): Likewise.
> 	(target_supports_dumpcore): Likewise.
> 	(target_dumpcore): Likewise.
> 	(target_can_run_breakpoint_commands): Likewise.
> 	(target_files_info): Likewise.
> 	(target_post_startup_inferior): Likewise.
> 	(target_insert_fork_catchpoint): Likewise.
> 	(target_remove_fork_catchpoint): Likewise.
> 	(target_insert_vfork_catchpoint): Likewise.
> 	(target_remove_vfork_catchpoint): Likewise.
> 	(target_insert_exec_catchpoint): Likewise.
> 	(target_remove_exec_catchpoint): Likewise.
> 	(target_set_syscall_catchpoint): Likewise.
> 	(target_rcmd): Likewise.
> 	(target_can_lock_scheduler): Likewise.
> 	(target_can_async_p): Likewise.
> 	(target_is_async_p): Likewise.
> 	(target_execution_direction): Likewise.
> 	(target_extra_thread_info): Likewise.
> 	(target_pid_to_exec_file): Likewise.
> 	(target_thread_architecture): Likewise.
> 	(target_find_memory_regions): Likewise.
> 	(target_make_corefile_notes): Likewise.
> 	(target_get_bookmark): Likewise.
> 	(target_goto_bookmark): Likewise.
> 	(target_stopped_by_watchpoint): Likewise.
> 	(target_stopped_by_sw_breakpoint): Likewise.
> 	(target_supports_stopped_by_sw_breakpoint): Likewise.
> 	(target_stopped_by_hw_breakpoint): Likewise.
> 	(target_supports_stopped_by_hw_breakpoint): Likewise.
> 	(target_have_steppable_watchpoint): Likewise.
> 	(target_can_use_hardware_watchpoint): Likewise.
> 	(target_region_ok_for_hw_watchpoint): Likewise.
> 	(target_can_do_single_step): Likewise.
> 	(target_insert_watchpoint): Likewise.
> 	(target_remove_watchpoint): Likewise.
> 	(target_insert_hw_breakpoint): Likewise.
> 	(target_remove_hw_breakpoint): Likewise.
> 	(target_can_accel_watchpoint_condition): Likewise.
> 	(target_can_execute_reverse): Likewise.
> 	(target_get_ada_task_ptid): Likewise.
> 	(target_filesystem_is_local): Likewise.
> 	(target_trace_init): Likewise.
> 	(target_download_tracepoint): Likewise.
> 	(target_can_download_tracepoint): Likewise.
> 	(target_download_trace_state_variable): Likewise.
> 	(target_enable_tracepoint): Likewise.
> 	(target_disable_tracepoint): Likewise.
> 	(target_trace_start): Likewise.
> 	(target_trace_set_readonly_regions): Likewise.
> 	(target_get_trace_status): Likewise.
> 	(target_get_tracepoint_status): Likewise.
> 	(target_trace_stop): Likewise.
> 	(target_trace_find): Likewise.
> 	(target_get_trace_state_variable_value): Likewise.
> 	(target_save_trace_data): Likewise.
> 	(target_upload_tracepoints): Likewise.
> 	(target_upload_trace_state_variables): Likewise.
> 	(target_get_raw_trace_data): Likewise.
> 	(target_get_min_fast_tracepoint_insn_len): Likewise.
> 	(target_set_disconnected_tracing): Likewise.
> 	(target_set_circular_trace_buffer): Likewise.
> 	(target_set_trace_buffer_size): Likewise.
> 	(target_set_trace_notes): Likewise.
> 	(target_get_tib_address): Likewise.
> 	(target_set_permissions): Likewise.
> 	(target_static_tracepoint_marker_at): Likewise.
> 	(target_static_tracepoint_markers_by_strid): Likewise.
> 	(target_traceframe_info): Likewise.
> 	(target_use_agent): Likewise.
> 	(target_can_use_agent): Likewise.
> 	(target_augmented_libraries_svr4_read): Likewise.
> 	(target_log_command): Likewise.
> 	* target.c (target_shortname): New.
> 	(target_longname): New.
> 	(target_attach_no_wait): New.
> 	(target_post_attach): New.
> 	(target_prepare_to_store): New.
> 	(target_supports_enable_disable_tracepoint): New.
> 	(target_supports_string_tracing): New.
> 	(target_supports_evaluation_of_breakpoint_conditions): New.
> 	(target_supports_dumpcore): New.
> 	(target_dumpcore): New.
> 	(target_can_run_breakpoint_commands): New.
> 	(target_files_info): New.
> 	(target_post_startup_inferior): New.
> 	(target_insert_fork_catchpoint): New.
> 	(target_remove_fork_catchpoint): New.
> 	(target_insert_vfork_catchpoint): New.
> 	(target_remove_vfork_catchpoint): New.
> 	(target_insert_exec_catchpoint): New.
> 	(target_remove_exec_catchpoint): New.
> 	(target_set_syscall_catchpoint): New.
> 	(target_rcmd): New.
> 	(target_can_lock_scheduler): New.
> 	(target_can_async_p): New.
> 	(target_is_async_p): New.
> 	(target_execution_direction): New.
> 	(target_extra_thread_info): New.
> 	(target_pid_to_exec_file): New.
> 	(target_thread_architecture): New.
> 	(target_find_memory_regions): New.
> 	(target_make_corefile_notes): New.
> 	(target_get_bookmark): New.
> 	(target_goto_bookmark): New.
> 	(target_stopped_by_watchpoint): New.
> 	(target_stopped_by_sw_breakpoint): New.
> 	(target_supports_stopped_by_sw_breakpoint): New.
> 	(target_stopped_by_hw_breakpoint): New.
> 	(target_supports_stopped_by_hw_breakpoint): New.
> 	(target_have_steppable_watchpoint): New.
> 	(target_can_use_hardware_watchpoint): New.
> 	(target_region_ok_for_hw_watchpoint): New.
> 	(target_can_do_single_step): New.
> 	(target_insert_watchpoint): New.
> 	(target_remove_watchpoint): New.
> 	(target_insert_hw_breakpoint): New.
> 	(target_remove_hw_breakpoint): New.
> 	(target_can_accel_watchpoint_condition): New.
> 	(target_can_execute_reverse): New.
> 	(target_get_ada_task_ptid): New.
> 	(target_filesystem_is_local): New.
> 	(target_trace_init): New.
> 	(target_download_tracepoint): New.
> 	(target_can_download_tracepoint): New.
> 	(target_download_trace_state_variable): New.
> 	(target_enable_tracepoint): New.
> 	(target_disable_tracepoint): New.
> 	(target_trace_start): New.
> 	(target_trace_set_readonly_regions): New.
> 	(target_get_trace_status): New.
> 	(target_get_tracepoint_status): New.
> 	(target_trace_stop): New.
> 	(target_trace_find): New.
> 	(target_get_trace_state_variable_value): New.
> 	(target_save_trace_data): New.
> 	(target_upload_tracepoints): New.
> 	(target_upload_trace_state_variables): New.
> 	(target_get_raw_trace_data): New.
> 	(target_get_min_fast_tracepoint_insn_len): New.
> 	(target_set_disconnected_tracing): New.
> 	(target_set_circular_trace_buffer): New.
> 	(target_set_trace_buffer_size): New.
> 	(target_set_trace_notes): New.
> 	(target_get_tib_address): New.
> 	(target_set_permissions): New.
> 	(target_static_tracepoint_marker_at): New.
> 	(target_static_tracepoint_markers_by_strid): New.
> 	(target_traceframe_info): New.
> 	(target_use_agent): New.
> 	(target_can_use_agent): New.
> 	(target_augmented_libraries_svr4_read): New.
> 	(target_log_command): New.
> 	* bfin-tdep.c (bfin_sw_breakpoint_from_kind): Adjust.
> 	* infrun.c (set_schedlock_func): Adjust.
> 	* mi/mi-main.c (exec_reverse_continue): Adjust.
> 	* reverse.c (exec_reverse_once): Adjust.
> 	* sh-tdep.c (sh_sw_breakpoint_from_kind): Adjust.
> 	* tui/tui-stack.c (tui_locator_window::make_status_line): Adjust.
> 	* remote-sim.c (gdbsim_target::detach): Adjust.
> 	(gdbsim_target::files_info): Adjust.
> 
> Change-Id: I72ef56e9a25adeb0b91f1ad05e34c89f77ebeaa8
> ---
>  gdb/bfin-tdep.c     |   2 +-
>  gdb/infrun.c        |   3 +-
>  gdb/mi/mi-main.c    |   2 +-
>  gdb/remote-sim.c    |   4 +-
>  gdb/reverse.c       |   2 +-
>  gdb/sh-tdep.c       |   2 +-
>  gdb/target.c        | 558 ++++++++++++++++++++++++++++++++++++++++++++
>  gdb/target.h        | 287 +++++++++--------------
>  gdb/tui/tui-stack.c |   4 +-
>  9 files changed, 674 insertions(+), 190 deletions(-)
> 
> diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
> index 963b0485a48..e3d6eee8832 100644
> --- a/gdb/bfin-tdep.c
> +++ b/gdb/bfin-tdep.c
> @@ -597,7 +597,7 @@ bfin_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
>  
>    *size = kind;
>  
> -  if (strcmp (target_shortname, "sim") == 0)
> +  if (strcmp (target_shortname (), "sim") == 0)
>      return bfin_sim_breakpoint;
>    else
>      return bfin_breakpoint;
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index 50340e6edad..b6f399d5478 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -2030,7 +2030,8 @@ set_schedlock_func (const char *args, int from_tty, struct cmd_list_element *c)
>    if (!target_can_lock_scheduler ())
>      {
>        scheduler_mode = schedlock_off;
> -      error (_("Target '%s' cannot support this command."), target_shortname);
> +      error (_("Target '%s' cannot support this command."),
> +	     target_shortname ());
>      }
>  }
>  
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index 9a14d78e1e2..d5ce08e95ed 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -322,7 +322,7 @@ exec_reverse_continue (char **argv, int argc)
>      error (_("Already in reverse mode."));
>  
>    if (!target_can_execute_reverse ())
> -    error (_("Target %s does not support this command."), target_shortname);
> +    error (_("Target %s does not support this command."), target_shortname ());
>  
>    scoped_restore save_exec_dir = make_scoped_restore (&execution_direction,
>  						      EXEC_REVERSE);
> diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
> index 1746b626fa1..f2cf8dbd711 100644
> --- a/gdb/remote-sim.c
> +++ b/gdb/remote-sim.c
> @@ -836,7 +836,7 @@ gdbsim_target::detach (inferior *inf, int from_tty)
>  
>    inf->unpush_target (this);		/* calls gdbsim_close to do the real work */
>    if (from_tty)
> -    printf_filtered ("Ending simulator %s debugging\n", target_shortname);
> +    printf_filtered ("Ending simulator %s debugging\n", target_shortname ());
>  }
>  
>  /* Resume execution of the target process.  STEP says whether to single-step
> @@ -1119,7 +1119,7 @@ gdbsim_target::files_info ()
>    if (current_program_space->exec_bfd ())
>      {
>        fprintf_unfiltered (gdb_stdlog, "\tAttached to %s running program %s\n",
> -			  target_shortname, file);
> +			  target_shortname (), file);
>        sim_info (sim_data->gdbsim_desc, 0);
>      }
>  }
> diff --git a/gdb/reverse.c b/gdb/reverse.c
> index 4c618a00173..e51defb27a3 100644
> --- a/gdb/reverse.c
> +++ b/gdb/reverse.c
> @@ -45,7 +45,7 @@ exec_reverse_once (const char *cmd, const char *args, int from_tty)
>  	   cmd);
>  
>    if (!target_can_execute_reverse ())
> -    error (_("Target %s does not support this command."), target_shortname);
> +    error (_("Target %s does not support this command."), target_shortname ());
>  
>    std::string reverse_command = string_printf ("%s %s", cmd, args ? args : "");
>    scoped_restore restore_exec_dir
> diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
> index ecd73c17217..5a71d3ac689 100644
> --- a/gdb/sh-tdep.c
> +++ b/gdb/sh-tdep.c
> @@ -432,7 +432,7 @@ sh_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
>    *size = kind;
>  
>    /* For remote stub targets, trapa #20 is used.  */
> -  if (strcmp (target_shortname, "remote") == 0)
> +  if (strcmp (target_shortname (), "remote") == 0)
>      {
>        static unsigned char big_remote_breakpoint[] = { 0xc3, 0x20 };
>        static unsigned char little_remote_breakpoint[] = { 0x20, 0xc3 };
> diff --git a/gdb/target.c b/gdb/target.c
> index afc4b2cbbb6..e7af5e8a9b0 100644
> --- a/gdb/target.c
> +++ b/gdb/target.c
> @@ -215,6 +215,564 @@ target_has_execution (inferior *inf)
>    return false;
>  }
>  
> +const char *
> +target_shortname ()

There are a few of the functions here missing a header comment.

Otherwise, this all looks fine.

Thanks,
Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] gdb: remove current_top_target function
  2021-03-23 18:41 ` [PATCH 2/2] gdb: remove current_top_target function Simon Marchi
@ 2021-03-24 11:02   ` Andrew Burgess
  2021-03-24 22:11     ` Simon Marchi
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Burgess @ 2021-03-24 11:02 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

* Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2021-03-23 14:41:38 -0400]:

> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> The current_top_target function is a hidden dependency on the current
> inferior.  Since I'd like to slowly move towards reducing our dependency
> on the global current state, remove this function and make callers use
> 
>   current_inferior ()->top_target ()
> 
> There is no expected change in behavior, but this one step towards
> making those callers use the inferior from their context, rather than
> refer to the global current inferior.

LGTM.

Thanks,
Andrew

> 
> gdb/ChangeLog:
> 
> 	* target.h (current_top_target): Remove, make callers use the
> 	current inferior instead.
> 	* target.c (current_top_target): Remove.
> 
> Change-Id: Iccd457036f84466cdaa3865aa3f9339a24ea001d
> ---
>  gdb/auxv.c                |   6 +-
>  gdb/avr-tdep.c            |   6 +-
>  gdb/breakpoint.c          |  12 +-
>  gdb/corefile.c            |   4 +-
>  gdb/elfread.c             |  14 +-
>  gdb/eval.c                |   5 +-
>  gdb/exec.c                |   2 +-
>  gdb/fbsd-tdep.c           |   2 +-
>  gdb/frame.c               |   5 +-
>  gdb/gnu-v3-abi.c          |   5 +-
>  gdb/ia64-tdep.c           |   4 +-
>  gdb/ia64-vms-tdep.c       |   3 +-
>  gdb/infcall.c             |   9 +-
>  gdb/infcmd.c              |  14 +-
>  gdb/inferior.c            |   2 +-
>  gdb/infrun.c              |  16 +-
>  gdb/linespec.c            |   3 +-
>  gdb/linux-tdep.c          |  21 +-
>  gdb/maint.c               |   3 +-
>  gdb/mi/mi-main.c          |   7 +-
>  gdb/minsyms.c             |   6 +-
>  gdb/ppc-linux-nat.c       |  19 +-
>  gdb/procfs.c              |   3 +-
>  gdb/regcache.c            |   2 +-
>  gdb/remote.c              |  19 +-
>  gdb/rs6000-tdep.c         |   3 +-
>  gdb/s390-linux-nat.c      |   2 +-
>  gdb/s390-tdep.c           |   3 +-
>  gdb/solib-aix.c           |   3 +-
>  gdb/solib-darwin.c        |   3 +-
>  gdb/solib-dsbt.c          |   6 +-
>  gdb/solib-svr4.c          |  34 +--
>  gdb/solib-target.c        |   5 +-
>  gdb/sparc-tdep.c          |   2 +-
>  gdb/sparc64-tdep.c        |   6 +-
>  gdb/symfile.c             |   6 +-
>  gdb/symtab.c              |   6 +-
>  gdb/target-descriptions.c |   6 +-
>  gdb/target-memory.c       |   5 +-
>  gdb/target.c              | 462 ++++++++++++++++++++++----------------
>  gdb/target.h              |   5 -
>  gdb/tracefile-tfile.c     |   2 +-
>  gdb/tracepoint.c          |   3 +-
>  gdb/valops.c              |   5 +-
>  gdb/valprint.c            |   6 +-
>  gdb/value.c               |   4 +-
>  gdb/windows-tdep.c        |   2 +-
>  47 files changed, 445 insertions(+), 326 deletions(-)
> 
> diff --git a/gdb/auxv.c b/gdb/auxv.c
> index f13f90b153f..6507df192e5 100644
> --- a/gdb/auxv.c
> +++ b/gdb/auxv.c
> @@ -320,7 +320,8 @@ target_auxv_parse (gdb_byte **readptr,
>    if (gdbarch_auxv_parse_p (gdbarch))
>      return gdbarch_auxv_parse (gdbarch, readptr, endptr, typep, valp);
>  
> -  return current_top_target ()->auxv_parse (readptr, endptr, typep, valp);
> +  return current_inferior ()->top_target ()->auxv_parse (readptr, endptr,
> +							 typep, valp);
>  }
>  
>  
> @@ -580,7 +581,8 @@ info_auxv_command (const char *cmd, int from_tty)
>      error (_("The program has no auxiliary information now."));
>    else
>      {
> -      int ents = fprint_target_auxv (gdb_stdout, current_top_target ());
> +      int ents = fprint_target_auxv (gdb_stdout,
> +				     current_inferior ()->top_target ());
>  
>        if (ents < 0)
>  	error (_("No auxiliary vector found, or failed reading it."));
> diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
> index 815c6d45143..018b18f3dfd 100644
> --- a/gdb/avr-tdep.c
> +++ b/gdb/avr-tdep.c
> @@ -1561,7 +1561,8 @@ avr_io_reg_read_command (const char *args, int from_tty)
>  
>    /* Find out how many io registers the target has.  */
>    gdb::optional<gdb::byte_vector> buf
> -    = target_read_alloc (current_top_target (), TARGET_OBJECT_AVR, "avr.io_reg");
> +    = target_read_alloc (current_inferior ()->top_target (),
> +			 TARGET_OBJECT_AVR, "avr.io_reg");
>  
>    if (!buf)
>      {
> @@ -1595,7 +1596,8 @@ avr_io_reg_read_command (const char *args, int from_tty)
>  	j = nreg - i;           /* last block is less than 8 registers */
>  
>        snprintf (query, sizeof (query) - 1, "avr.io_reg:%x,%x", i, j);
> -      buf = target_read_alloc (current_top_target (), TARGET_OBJECT_AVR, query);
> +      buf = target_read_alloc (current_inferior ()->top_target (),
> +			       TARGET_OBJECT_AVR, query);
>  
>        if (!buf)
>  	{
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index de1e79ba5d0..16cf7977b62 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -3598,8 +3598,8 @@ create_exception_master_breakpoint_hook (objfile *objfile)
>      }
>  
>    addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
> -  addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
> -					     current_top_target ());
> +  addr = gdbarch_convert_from_func_ptr_addr
> +    (gdbarch, addr, current_inferior ()->top_target ());
>    b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
>  				  &internal_breakpoint_ops);
>    initialize_explicit_location (&explicit_loc);
> @@ -4869,7 +4869,7 @@ watchpoints_triggered (struct target_waitstatus *ws)
>        return 0;
>      }
>  
> -  if (!target_stopped_data_address (current_top_target (), &addr))
> +  if (!target_stopped_data_address (current_inferior ()->top_target (), &addr))
>      {
>        /* We were stopped by a watchpoint, but we don't know where.
>  	 Mark all watchpoints as unknown.  */
> @@ -4909,9 +4909,9 @@ watchpoints_triggered (struct target_waitstatus *ws)
>  		  }
>  	      }
>  	    /* Exact match not required.  Within range is sufficient.  */
> -	    else if (target_watchpoint_addr_within_range (current_top_target (),
> -							 addr, loc->address,
> -							 loc->length))
> +	    else if (target_watchpoint_addr_within_range
> +		       (current_inferior ()->top_target (), addr, loc->address,
> +			loc->length))
>  	      {
>  		w->watchpoint_triggered = watch_triggered_yes;
>  		break;
> diff --git a/gdb/corefile.c b/gdb/corefile.c
> index 4ddcc06ec96..30960c129fd 100644
> --- a/gdb/corefile.c
> +++ b/gdb/corefile.c
> @@ -218,8 +218,8 @@ read_memory_object (enum target_object object, CORE_ADDR memaddr,
>        enum target_xfer_status status;
>        ULONGEST xfered_len;
>  
> -      status = target_xfer_partial (current_top_target (), object, NULL,
> -				    myaddr + xfered, NULL,
> +      status = target_xfer_partial (current_inferior ()->top_target (), object,
> +				    NULL, myaddr + xfered, NULL,
>  				    memaddr + xfered, len - xfered,
>  				    &xfered_len);
>  
> diff --git a/gdb/elfread.c b/gdb/elfread.c
> index 85100875347..49bbbec663e 100644
> --- a/gdb/elfread.c
> +++ b/gdb/elfread.c
> @@ -863,8 +863,8 @@ elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
>        if (target_read_memory (pointer_address, buf, ptr_size) != 0)
>  	continue;
>        addr = extract_typed_address (buf, ptr_type);
> -      addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
> -						 current_top_target ());
> +      addr = gdbarch_convert_from_func_ptr_addr
> +	(gdbarch, addr, current_inferior ()->top_target ());
>        addr = gdbarch_addr_bits_remove (gdbarch, addr);
>  
>        if (elf_gnu_ifunc_record_cache (name, addr))
> @@ -931,12 +931,13 @@ elf_gnu_ifunc_resolve_addr (struct gdbarch *gdbarch, CORE_ADDR pc)
>       parameter.  FUNCTION is the function entry address.  ADDRESS may be a
>       function descriptor.  */
>  
> -  target_auxv_search (current_top_target (), AT_HWCAP, &hwcap);
> +  target_auxv_search (current_inferior ()->top_target (), AT_HWCAP, &hwcap);
>    hwcap_val = value_from_longest (builtin_type (gdbarch)
>  				  ->builtin_unsigned_long, hwcap);
>    address_val = call_function_by_hand (function, NULL, hwcap_val);
>    address = value_as_address (address_val);
> -  address = gdbarch_convert_from_func_ptr_addr (gdbarch, address, current_top_target ());
> +  address = gdbarch_convert_from_func_ptr_addr
> +    (gdbarch, address, current_inferior ()->top_target ());
>    address = gdbarch_addr_bits_remove (gdbarch, address);
>  
>    if (name_at_pc)
> @@ -1042,9 +1043,8 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
>    gdbarch_return_value (gdbarch, func_func, value_type, regcache,
>  			value_contents_raw (value), NULL);
>    resolved_address = value_as_address (value);
> -  resolved_pc = gdbarch_convert_from_func_ptr_addr (gdbarch,
> -						    resolved_address,
> -						    current_top_target ());
> +  resolved_pc = gdbarch_convert_from_func_ptr_addr
> +    (gdbarch, resolved_address, current_inferior ()->top_target ());
>    resolved_pc = gdbarch_addr_bits_remove (gdbarch, resolved_pc);
>  
>    gdb_assert (current_program_space == b->pspace || b->pspace == NULL);
> diff --git a/gdb/eval.c b/gdb/eval.c
> index 530ff152134..363ab4fa4af 100644
> --- a/gdb/eval.c
> +++ b/gdb/eval.c
> @@ -42,6 +42,7 @@
>  #include <ctype.h>
>  #include "expop.h"
>  #include "c-exp.h"
> +#include "inferior.h"
>  
>  \f
>  /* Parse the string EXP as a C expression, evaluate it,
> @@ -1964,8 +1965,8 @@ eval_op_objc_msgcall (struct type *expect_type, struct expression *exp,
>  
>        /* The address might point to a function descriptor;
>  	 resolve it to the actual code address instead.  */
> -      addr = gdbarch_convert_from_func_ptr_addr (exp->gdbarch, addr,
> -						 current_top_target ());
> +      addr = gdbarch_convert_from_func_ptr_addr
> +	(exp->gdbarch, addr, current_inferior ()->top_target ());
>  
>        /* Is it a high_level symbol?  */
>        sym = find_pc_function (addr);
> diff --git a/gdb/exec.c b/gdb/exec.c
> index b737bcf6e0f..ff0db82a69b 100644
> --- a/gdb/exec.c
> +++ b/gdb/exec.c
> @@ -775,7 +775,7 @@ section_table_read_available_memory (gdb_byte *readbuf, ULONGEST offset,
>  				     ULONGEST len, ULONGEST *xfered_len)
>  {
>    const target_section_table *table
> -    = target_get_section_table (current_top_target ());
> +    = target_get_section_table (current_inferior ()->top_target ());
>    std::vector<mem_range> available_memory
>      = section_table_available_memory (offset, len, *table);
>  
> diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
> index 170e8f5e84e..6cab31dde82 100644
> --- a/gdb/fbsd-tdep.c
> +++ b/gdb/fbsd-tdep.c
> @@ -593,7 +593,7 @@ static gdb::optional<gdb::byte_vector>
>  fbsd_make_note_desc (enum target_object object, uint32_t structsize)
>  {
>    gdb::optional<gdb::byte_vector> buf =
> -    target_read_alloc (current_top_target (), object, NULL);
> +    target_read_alloc (current_inferior ()->top_target (), object, NULL);
>    if (!buf || buf->empty ())
>      return {};
>  
> diff --git a/gdb/frame.c b/gdb/frame.c
> index 4578b1acab3..dc9fdd41646 100644
> --- a/gdb/frame.c
> +++ b/gdb/frame.c
> @@ -2478,9 +2478,8 @@ inside_main_func (frame_info *this_frame)
>  
>    /* Convert any function descriptor addresses into the actual function
>       code address.  */
> -  sym_addr
> -    = gdbarch_convert_from_func_ptr_addr (get_frame_arch (this_frame),
> -					  sym_addr, current_top_target ());
> +  sym_addr = gdbarch_convert_from_func_ptr_addr
> +    (get_frame_arch (this_frame), sym_addr, current_inferior ()->top_target ());
>  
>    return sym_addr == get_frame_func (this_frame);
>  }
> diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
> index 8461535c6ec..45e57c210cb 100644
> --- a/gdb/gnu-v3-abi.c
> +++ b/gdb/gnu-v3-abi.c
> @@ -31,6 +31,7 @@
>  #include <algorithm>
>  #include "cli/cli-style.h"
>  #include "dwarf2/loc.h"
> +#include "inferior.h"
>  
>  static struct cp_abi_ops gnu_v3_abi_ops;
>  
> @@ -1243,8 +1244,8 @@ gnuv3_skip_trampoline (struct frame_info *frame, CORE_ADDR stop_pc)
>       (powerpc 64 for example).  Make sure to retrieve the address
>       of the real function from the function descriptor before passing on
>       the address to other layers of GDB.  */
> -  func_addr = gdbarch_convert_from_func_ptr_addr (gdbarch, method_stop_pc,
> -						  current_top_target ());
> +  func_addr = gdbarch_convert_from_func_ptr_addr
> +    (gdbarch, method_stop_pc, current_inferior ()->top_target ());
>    if (func_addr != 0)
>      method_stop_pc = func_addr;
>  
> diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
> index 35eeffe8434..1c4fc4cca47 100644
> --- a/gdb/ia64-tdep.c
> +++ b/gdb/ia64-tdep.c
> @@ -2653,8 +2653,8 @@ getunwind_table ()
>       we should find a way to override the corefile layer's
>       xfer_partial method.  */
>  
> -  return target_read_alloc (current_top_target (), TARGET_OBJECT_UNWIND_TABLE,
> -			    NULL);
> +  return target_read_alloc (current_inferior ()->top_target (),
> +			    TARGET_OBJECT_UNWIND_TABLE, NULL);
>  }
>  
>  /* Get the kernel unwind table.  */				 
> diff --git a/gdb/ia64-vms-tdep.c b/gdb/ia64-vms-tdep.c
> index 0481f00c2fa..cc8e1914274 100644
> --- a/gdb/ia64-vms-tdep.c
> +++ b/gdb/ia64-vms-tdep.c
> @@ -41,7 +41,8 @@ ia64_vms_find_proc_info_x (unw_addr_space_t as, unw_word_t ip,
>    CORE_ADDR table_addr;
>    unsigned int info_len;
>  
> -  res = target_read (current_top_target (), TARGET_OBJECT_OPENVMS_UIB,
> +  res = target_read (current_inferior ()->top_target (),
> +		     TARGET_OBJECT_OPENVMS_UIB,
>  		     annex + 2, buf, 0, sizeof (buf));
>  
>    if (res != sizeof (buf))
> diff --git a/gdb/infcall.c b/gdb/infcall.c
> index 2332f293a1e..ca3347fbb9d 100644
> --- a/gdb/infcall.c
> +++ b/gdb/infcall.c
> @@ -269,8 +269,8 @@ find_function_addr (struct value *function,
>        ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
>        if (ftype->code () == TYPE_CODE_FUNC
>  	  || ftype->code () == TYPE_CODE_METHOD)
> -	funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
> -						      current_top_target ());
> +	funaddr = gdbarch_convert_from_func_ptr_addr
> +	  (gdbarch, funaddr, current_inferior ()->top_target());
>      }
>    if (ftype->code () == TYPE_CODE_FUNC
>        || ftype->code () == TYPE_CODE_METHOD)
> @@ -321,9 +321,8 @@ find_function_addr (struct value *function,
>  
>  	      funaddr = value_as_address (value_addr (function));
>  	      nfunaddr = funaddr;
> -	      funaddr
> -		= gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
> -						      current_top_target ());
> +	      funaddr = gdbarch_convert_from_func_ptr_addr
> +		(gdbarch, funaddr, current_inferior ()->top_target ());
>  	      if (funaddr != nfunaddr)
>  		found_descriptor = 1;
>  	    }
> diff --git a/gdb/infcmd.c b/gdb/infcmd.c
> index 80e6ad3048f..a6e9572fc7f 100644
> --- a/gdb/infcmd.c
> +++ b/gdb/infcmd.c
> @@ -759,7 +759,7 @@ continue_command (const char *args, int from_tty)
>        ensure_not_running ();
>      }
>  
> -  prepare_execution_command (current_top_target (), async_exec);
> +  prepare_execution_command (current_inferior ()->top_target (), async_exec);
>  
>    if (from_tty)
>      printf_filtered (_("Continuing.\n"));
> @@ -877,7 +877,7 @@ step_1 (int skip_subroutines, int single_inst, const char *count_string)
>      = strip_bg_char (count_string, &async_exec);
>    count_string = stripped.get ();
>  
> -  prepare_execution_command (current_top_target (), async_exec);
> +  prepare_execution_command (current_inferior ()->top_target (), async_exec);
>  
>    count = count_string ? parse_and_eval_long (count_string) : 1;
>  
> @@ -1075,7 +1075,7 @@ jump_command (const char *arg, int from_tty)
>    gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
>    arg = stripped.get ();
>  
> -  prepare_execution_command (current_top_target (), async_exec);
> +  prepare_execution_command (current_inferior ()->top_target (), async_exec);
>  
>    if (!arg)
>      error_no_arg (_("starting address"));
> @@ -1155,7 +1155,7 @@ signal_command (const char *signum_exp, int from_tty)
>      = strip_bg_char (signum_exp, &async_exec);
>    signum_exp = stripped.get ();
>  
> -  prepare_execution_command (current_top_target (), async_exec);
> +  prepare_execution_command (current_inferior ()->top_target (), async_exec);
>  
>    if (!signum_exp)
>      error_no_arg (_("signal number"));
> @@ -1400,7 +1400,7 @@ until_command (const char *arg, int from_tty)
>    gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
>    arg = stripped.get ();
>  
> -  prepare_execution_command (current_top_target (), async_exec);
> +  prepare_execution_command (current_inferior ()->top_target (), async_exec);
>  
>    if (arg)
>      until_break_command (arg, from_tty, 0);
> @@ -1425,7 +1425,7 @@ advance_command (const char *arg, int from_tty)
>    gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
>    arg = stripped.get ();
>  
> -  prepare_execution_command (current_top_target (), async_exec);
> +  prepare_execution_command (current_inferior ()->top_target (), async_exec);
>  
>    until_break_command (arg, from_tty, 1);
>  }
> @@ -1772,7 +1772,7 @@ finish_command (const char *arg, int from_tty)
>    gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
>    arg = stripped.get ();
>  
> -  prepare_execution_command (current_top_target (), async_exec);
> +  prepare_execution_command (current_inferior ()->top_target (), async_exec);
>  
>    if (arg)
>      error (_("The \"finish\" command does not take any arguments."));
> diff --git a/gdb/inferior.c b/gdb/inferior.c
> index 69baee34ce9..9188f72e35d 100644
> --- a/gdb/inferior.c
> +++ b/gdb/inferior.c
> @@ -507,7 +507,7 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
>  
>        uiout->field_signed ("number", inf->num);
>  
> -      /* Because target_pid_to_str uses current_top_target,
> +      /* Because target_pid_to_str uses the current inferior,
>  	 switch the inferior.  */
>        switch_to_inferior_no_thread (inf);
>  
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index b6f399d5478..20035a0f5e8 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -1777,7 +1777,7 @@ displaced_step_finish (thread_info *event_thread, enum gdb_signal signal)
>    /* Fixup may need to read memory/registers.  Switch to the thread
>       that we're fixing up.  Also, target_stopped_by_watchpoint checks
>       the current thread, and displaced_step_restore performs ptid-dependent
> -     memory accesses using current_inferior() and current_top_target().  */
> +     memory accesses using current_inferior().  */
>    switch_to_thread (event_thread);
>  
>    displaced_step_reset_cleanup cleanup (displaced);
> @@ -5813,7 +5813,8 @@ handle_signal_stop (struct execution_control_state *ecs)
>  
>  	  infrun_debug_printf ("stopped by watchpoint");
>  
> -	  if (target_stopped_data_address (current_top_target (), &addr))
> +	  if (target_stopped_data_address (current_inferior ()->top_target (),
> +					   &addr))
>  	    infrun_debug_printf ("stopped data address=%s",
>  				 paddress (reg_gdbarch, addr));
>  	  else
> @@ -8835,7 +8836,8 @@ siginfo_value_read (struct value *v)
>    validate_registers_access ();
>  
>    transferred =
> -    target_read (current_top_target (), TARGET_OBJECT_SIGNAL_INFO,
> +    target_read (current_inferior ()->top_target (),
> +		 TARGET_OBJECT_SIGNAL_INFO,
>  		 NULL,
>  		 value_contents_all_raw (v),
>  		 value_offset (v),
> @@ -8857,7 +8859,7 @@ siginfo_value_write (struct value *v, struct value *fromval)
>       vice versa.  */
>    validate_registers_access ();
>  
> -  transferred = target_write (current_top_target (),
> +  transferred = target_write (current_inferior ()->top_target (),
>  			      TARGET_OBJECT_SIGNAL_INFO,
>  			      NULL,
>  			      value_contents_all_raw (fromval),
> @@ -8921,7 +8923,8 @@ class infcall_suspend_state
>  
>  	siginfo_data.reset ((gdb_byte *) xmalloc (len));
>  
> -	if (target_read (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL,
> +	if (target_read (current_inferior ()->top_target (),
> +			 TARGET_OBJECT_SIGNAL_INFO, NULL,
>  			 siginfo_data.get (), 0, len) != len)
>  	  {
>  	    /* Errors ignored.  */
> @@ -8956,7 +8959,8 @@ class infcall_suspend_state
>  	struct type *type = gdbarch_get_siginfo_type (gdbarch);
>  
>  	/* Errors ignored.  */
> -	target_write (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL,
> +	target_write (current_inferior ()->top_target (),
> +		      TARGET_OBJECT_SIGNAL_INFO, NULL,
>  		      m_siginfo_data.get (), 0, TYPE_LENGTH (type));
>        }
>  
> diff --git a/gdb/linespec.c b/gdb/linespec.c
> index c7dbd3eeae2..4034bbab8a0 100644
> --- a/gdb/linespec.c
> +++ b/gdb/linespec.c
> @@ -47,6 +47,7 @@
>  #include "gdbsupport/function-view.h"
>  #include "gdbsupport/def-vector.h"
>  #include <algorithm>
> +#include "inferior.h"
>  
>  /* An enumeration of the various things a user might attempt to
>     complete for a linespec location.  */
> @@ -2314,7 +2315,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
>  				= (gdbarch_convert_from_func_ptr_addr
>  				   (gdbarch,
>  				    msym_addr,
> -				    current_top_target ()));
> +				    current_inferior ()->top_target ()));
>  			    }
>  
>  			  if (msym_addr == addr)
> diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
> index ab3402a41c2..68cf7265a96 100644
> --- a/gdb/linux-tdep.c
> +++ b/gdb/linux-tdep.c
> @@ -385,9 +385,10 @@ int
>  linux_is_uclinux (void)
>  {
>    CORE_ADDR dummy;
> +  target_ops *target = current_inferior ()->top_target ();
>  
> -  return (target_auxv_search (current_top_target (), AT_NULL, &dummy) > 0
> -	  && target_auxv_search (current_top_target (), AT_PAGESZ, &dummy) == 0);
> +  return (target_auxv_search (target, AT_NULL, &dummy) > 0
> +	  && target_auxv_search (target, AT_PAGESZ, &dummy) == 0);
>  }
>  
>  static int
> @@ -1619,7 +1620,8 @@ linux_get_siginfo_data (thread_info *thread, struct gdbarch *gdbarch)
>  
>    gdb::byte_vector buf (TYPE_LENGTH (siginfo_type));
>  
> -  bytes_read = target_read (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL,
> +  bytes_read = target_read (current_inferior ()->top_target (),
> +			    TARGET_OBJECT_SIGNAL_INFO, NULL,
>  			    buf.data (), 0, TYPE_LENGTH (siginfo_type));
>    if (bytes_read != TYPE_LENGTH (siginfo_type))
>      buf.clear ();
> @@ -1921,7 +1923,8 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
>  
>    /* Auxillary vector.  */
>    gdb::optional<gdb::byte_vector> auxv =
> -    target_read_alloc (current_top_target (), TARGET_OBJECT_AUXV, NULL);
> +    target_read_alloc (current_inferior ()->top_target (),
> +		       TARGET_OBJECT_AUXV, NULL);
>    if (auxv && !auxv->empty ())
>      {
>        note_data.reset (elfcore_write_note (obfd, note_data.release (),
> @@ -2201,7 +2204,8 @@ linux_vsyscall_range_raw (struct gdbarch *gdbarch, struct mem_range *range)
>    char filename[100];
>    long pid;
>  
> -  if (target_auxv_search (current_top_target (), AT_SYSINFO_EHDR, &range->start) <= 0)
> +  if (target_auxv_search (current_inferior ()->top_target (),
> +			  AT_SYSINFO_EHDR, &range->start) <= 0)
>      return 0;
>  
>    /* It doesn't make sense to access the host's /proc when debugging a
> @@ -2391,14 +2395,15 @@ linux_displaced_step_location (struct gdbarch *gdbarch)
>       local-store address and is thus not usable as displaced stepping
>       location.  The auxiliary vector gets us the PowerPC-side entry
>       point address instead.  */
> -  if (target_auxv_search (current_top_target (), AT_ENTRY, &addr) <= 0)
> +  if (target_auxv_search (current_inferior ()->top_target (),
> +			  AT_ENTRY, &addr) <= 0)
>      throw_error (NOT_SUPPORTED_ERROR,
>  		 _("Cannot find AT_ENTRY auxiliary vector entry."));
>  
>    /* Make certain that the address points at real code, and not a
>       function descriptor.  */
> -  addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
> -					     current_top_target ());
> +  addr = gdbarch_convert_from_func_ptr_addr
> +    (gdbarch, addr, current_inferior ()->top_target ());
>  
>    /* Inferior calls also use the entry point as a breakpoint location.
>       We don't want displaced stepping to interfere with those
> diff --git a/gdb/maint.c b/gdb/maint.c
> index 5254cd6ed26..7f505d07a69 100644
> --- a/gdb/maint.c
> +++ b/gdb/maint.c
> @@ -40,6 +40,7 @@
>  #include "top.h"
>  #include "maint.h"
>  #include "gdbsupport/selftest.h"
> +#include "inferior.h"
>  
>  #include "cli/cli-decode.h"
>  #include "cli/cli-utils.h"
> @@ -472,7 +473,7 @@ maintenance_info_target_sections (const char *arg, int from_tty)
>    bfd *abfd = nullptr;
>    int digits = 0;
>    const target_section_table *table
> -    = target_get_section_table (current_top_target ());
> +    = target_get_section_table (current_inferior ()->top_target ());
>    if (table == nullptr)
>      return;
>  
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index d5ce08e95ed..c6f1ab4e3f0 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -264,7 +264,7 @@ proceed_thread_callback (struct thread_info *thread, void *arg)
>  static void
>  exec_continue (char **argv, int argc)
>  {
> -  prepare_execution_command (current_top_target (), mi_async_p ());
> +  prepare_execution_command (current_inferior ()->top_target (), mi_async_p ());
>  
>    if (non_stop)
>      {
> @@ -1328,7 +1328,8 @@ mi_cmd_data_read_memory (const char *command, char **argv, int argc)
>  
>    gdb::byte_vector mbuf (total_bytes);
>  
> -  nr_bytes = target_read (current_top_target (), TARGET_OBJECT_MEMORY, NULL,
> +  nr_bytes = target_read (current_inferior ()->top_target (),
> +			  TARGET_OBJECT_MEMORY, NULL,
>  			  mbuf.data (), addr, total_bytes);
>    if (nr_bytes <= 0)
>      error (_("Unable to read memory."));
> @@ -1448,7 +1449,7 @@ mi_cmd_data_read_memory_bytes (const char *command, char **argv, int argc)
>    length = atol (argv[1]);
>  
>    std::vector<memory_read_result> result
> -    = read_memory_robust (current_top_target (), addr, length);
> +    = read_memory_robust (current_inferior ()->top_target (), addr, length);
>  
>    if (result.size () == 0)
>      error (_("Unable to read memory."));
> diff --git a/gdb/minsyms.c b/gdb/minsyms.c
> index 3cf849f48bf..8ffd9076124 100644
> --- a/gdb/minsyms.c
> +++ b/gdb/minsyms.c
> @@ -54,6 +54,7 @@
>  #include <algorithm>
>  #include "safe-ctype.h"
>  #include "gdbsupport/parallel-for.h"
> +#include "inferior.h"
>  
>  #if CXX_STD_THREAD
>  #include <mutex>
> @@ -78,9 +79,8 @@ msymbol_is_function (struct objfile *objfile, minimal_symbol *minsym,
>      case mst_data_gnu_ifunc:
>        {
>  	struct gdbarch *gdbarch = objfile->arch ();
> -	CORE_ADDR pc
> -	  = gdbarch_convert_from_func_ptr_addr (gdbarch, msym_addr,
> -						current_top_target ());
> +	CORE_ADDR pc = gdbarch_convert_from_func_ptr_addr
> +	  (gdbarch, msym_addr, current_inferior ()->top_target ());
>  	if (pc != msym_addr)
>  	  {
>  	    if (func_address_p != NULL)
> diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
> index f1ba165d540..171f5b386fa 100644
> --- a/gdb/ppc-linux-nat.c
> +++ b/gdb/ppc-linux-nat.c
> @@ -1967,8 +1967,8 @@ ppc_linux_nat_target::read_description ()
>  
>    features.wordsize = ppc_linux_target_wordsize (tid);
>  
> -  CORE_ADDR hwcap = linux_get_hwcap (current_top_target ());
> -  CORE_ADDR hwcap2 = linux_get_hwcap2 (current_top_target ());
> +  CORE_ADDR hwcap = linux_get_hwcap (current_inferior ()->top_target ());
> +  CORE_ADDR hwcap2 = linux_get_hwcap2 (current_inferior ()->top_target ());
>  
>    if (have_ptrace_getsetvsxregs
>        && (hwcap & PPC_FEATURE_HAS_VSX))
> @@ -2125,7 +2125,8 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
>  	 takes two hardware watchpoints though.  */
>        if (len > 1
>  	  && hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_RANGE
> -	  && linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
> +	  && (linux_get_hwcap (current_inferior ()->top_target ())
> +	      & PPC_FEATURE_BOOKE))
>  	return 2;
>        /* Check if the processor provides DAWR interface.  */
>        if (hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_DAWR)
> @@ -2153,7 +2154,8 @@ ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
>      {
>        gdb_assert (m_dreg_interface.debugreg_p ());
>  
> -      if (((linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
> +      if (((linux_get_hwcap (current_inferior ()->top_target ())
> +	    & PPC_FEATURE_BOOKE)
>  	   && (addr + len) > (addr & ~3) + 4)
>  	  || (addr + len) > (addr & ~7) + 8)
>  	return 0;
> @@ -2640,7 +2642,8 @@ ppc_linux_nat_target::insert_watchpoint (CORE_ADDR addr, int len,
>        long wp_value;
>        long read_mode, write_mode;
>  
> -      if (linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
> +      if (linux_get_hwcap (current_inferior ()->top_target ())
> +	  & PPC_FEATURE_BOOKE)
>  	{
>  	  /* PowerPC 440 requires only the read/write flags to be passed
>  	     to the kernel.  */
> @@ -3013,9 +3016,11 @@ ppc_linux_nat_target::watchpoint_addr_within_range (CORE_ADDR addr,
>    int mask;
>  
>    if (m_dreg_interface.hwdebug_p ()
> -      && linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
> +      && (linux_get_hwcap (current_inferior ()->top_target ())
> +	  & PPC_FEATURE_BOOKE))
>      return start <= addr && start + length >= addr;
> -  else if (linux_get_hwcap (current_top_target ()) & PPC_FEATURE_BOOKE)
> +  else if (linux_get_hwcap (current_inferior ()->top_target ())
> +	   & PPC_FEATURE_BOOKE)
>      mask = 3;
>    else
>      mask = 7;
> diff --git a/gdb/procfs.c b/gdb/procfs.c
> index 91d2039e3f9..eb703cf43b7 100644
> --- a/gdb/procfs.c
> +++ b/gdb/procfs.c
> @@ -3643,7 +3643,8 @@ procfs_target::make_corefile_notes (bfd *obfd, int *note_size)
>  			     &thread_args);
>  
>    gdb::optional<gdb::byte_vector> auxv =
> -    target_read_alloc (current_top_target (), TARGET_OBJECT_AUXV, NULL);
> +    target_read_alloc (current_inferior ()->top_target (),
> +		       TARGET_OBJECT_AUXV, NULL);
>    if (auxv && !auxv->empty ())
>      note_data.reset (elfcore_write_note (obfd, note_data.release (), note_size,
>  					 "CORE", NT_AUXV, auxv->data (),
> diff --git a/gdb/regcache.c b/gdb/regcache.c
> index a419a21f30a..bf3c6f43e6a 100644
> --- a/gdb/regcache.c
> +++ b/gdb/regcache.c
> @@ -1916,7 +1916,7 @@ cooked_write_test (struct gdbarch *gdbarch)
>  {
>    /* Error out if debugging something, because we're going to push the
>       test target, which would pop any existing target.  */
> -  if (current_top_target ()->stratum () >= process_stratum)
> +  if (current_inferior ()->top_target ()->stratum () >= process_stratum)
>      error (_("target already pushed"));
>  
>    /* Create a mock environment.  A process_stratum target pushed.  */
> diff --git a/gdb/remote.c b/gdb/remote.c
> index a7f35396045..e36f03aec46 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -5058,9 +5058,8 @@ remote_target::remote_check_symbols ()
>  
>  	  /* If this is a function address, return the start of code
>  	     instead of any data function descriptor.  */
> -	  sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
> -							 sym_addr,
> -							 current_top_target ());
> +	  sym_addr = gdbarch_convert_from_func_ptr_addr
> +	    (target_gdbarch (), sym_addr, current_inferior ()->top_target ());
>  
>  	  xsnprintf (msg.data (), get_remote_packet_size (), "qSymbol:%s:%s",
>  		     phex_nz (sym_addr, addr_size), &reply[8]);
> @@ -11436,7 +11435,8 @@ remote_target::memory_map ()
>  {
>    std::vector<mem_region> result;
>    gdb::optional<gdb::char_vector> text
> -    = target_read_stralloc (current_top_target (), TARGET_OBJECT_MEMORY_MAP, NULL);
> +    = target_read_stralloc (current_inferior ()->top_target (),
> +			    TARGET_OBJECT_MEMORY_MAP, NULL);
>  
>    if (text)
>      result = parse_memory_map (text->data ());
> @@ -13667,7 +13667,8 @@ traceframe_info_up
>  remote_target::traceframe_info ()
>  {
>    gdb::optional<gdb::char_vector> text
> -    = target_read_stralloc (current_top_target (), TARGET_OBJECT_TRACEFRAME_INFO,
> +    = target_read_stralloc (current_inferior ()->top_target (),
> +			    TARGET_OBJECT_TRACEFRAME_INFO,
>  			    NULL);
>    if (text)
>      return parse_traceframe_info (text->data ());
> @@ -13896,7 +13897,8 @@ static void
>  btrace_read_config (struct btrace_config *conf)
>  {
>    gdb::optional<gdb::char_vector> xml
> -    = target_read_stralloc (current_top_target (), TARGET_OBJECT_BTRACE_CONF, "");
> +    = target_read_stralloc (current_inferior ()->top_target (),
> +			    TARGET_OBJECT_BTRACE_CONF, "");
>    if (xml)
>      parse_xml_btrace_conf (conf, xml->data ());
>  }
> @@ -14097,7 +14099,8 @@ remote_target::read_btrace (struct btrace_data *btrace,
>      }
>  
>    gdb::optional<gdb::char_vector> xml
> -    = target_read_stralloc (current_top_target (), TARGET_OBJECT_BTRACE, annex);
> +    = target_read_stralloc (current_inferior ()->top_target (),
> +			    TARGET_OBJECT_BTRACE, annex);
>    if (!xml)
>      return BTRACE_ERR_UNKNOWN;
>  
> @@ -14153,7 +14156,7 @@ remote_target::pid_to_exec_file (int pid)
>        xsnprintf (annex, annex_size, "%x", pid);
>      }
>  
> -  filename = target_read_stralloc (current_top_target (),
> +  filename = target_read_stralloc (current_inferior ()->top_target (),
>  				   TARGET_OBJECT_EXEC_FILE, annex);
>  
>    return filename ? filename->data () : nullptr;
> diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
> index b09f63137dc..cb06cd952a7 100644
> --- a/gdb/rs6000-tdep.c
> +++ b/gdb/rs6000-tdep.c
> @@ -5077,7 +5077,8 @@ ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
>        return 0;
>  
>      case 1014:		/* Data Cache Block set to Zero */
> -      if (target_auxv_search (current_top_target (), AT_DCACHEBSIZE, &at_dcsz) <= 0
> +      if (target_auxv_search (current_inferior ()->top_target (),
> +			      AT_DCACHEBSIZE, &at_dcsz) <= 0
>  	  || at_dcsz == 0)
>  	at_dcsz = 128; /* Assume 128-byte cache line size (POWER8)  */
>  
> diff --git a/gdb/s390-linux-nat.c b/gdb/s390-linux-nat.c
> index d493843410a..41b50ce4800 100644
> --- a/gdb/s390-linux-nat.c
> +++ b/gdb/s390-linux-nat.c
> @@ -1002,7 +1002,7 @@ s390_linux_nat_target::read_description ()
>       that mode, report s390 architecture with 64-bit GPRs.  */
>  #ifdef __s390x__
>    {
> -    CORE_ADDR hwcap = linux_get_hwcap (current_top_target ());
> +    CORE_ADDR hwcap = linux_get_hwcap (current_inferior ()->top_target ());
>  
>      have_regset_tdb = (hwcap & HWCAP_S390_TE)
>        && check_regset (tid, NT_S390_TDB, s390_sizeof_tdbregset);
> diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
> index 39c8ee0450a..1bd770a3cc3 100644
> --- a/gdb/s390-tdep.c
> +++ b/gdb/s390-tdep.c
> @@ -39,6 +39,7 @@
>  #include "target-descriptions.h"
>  #include "trad-frame.h"
>  #include "value.h"
> +#include "inferior.h"
>  
>  #include "features/s390-linux32.c"
>  #include "features/s390x-linux64.c"
> @@ -685,7 +686,7 @@ s390_load (struct s390_prologue_data *data,
>    if (pv_is_constant (addr))
>      {
>        const struct target_section *secp
> -	= target_section_by_addr (current_top_target (), addr.k);
> +	= target_section_by_addr (current_inferior ()->top_target (), addr.k);
>        if (secp != NULL
>  	  && (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY))
>  	return pv_constant (read_memory_integer (addr.k, size,
> diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
> index a0dbdde4d49..faccf299899 100644
> --- a/gdb/solib-aix.c
> +++ b/gdb/solib-aix.c
> @@ -246,7 +246,8 @@ solib_aix_get_library_list (struct inferior *inf, const char *warning_msg)
>      return data->library_list;
>  
>    gdb::optional<gdb::char_vector> library_document
> -    = target_read_stralloc (current_top_target (), TARGET_OBJECT_LIBRARIES_AIX,
> +    = target_read_stralloc (current_inferior ()->top_target (),
> +			    TARGET_OBJECT_LIBRARIES_AIX,
>  			    NULL);
>    if (!library_document && warning_msg != NULL)
>      {
> diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
> index 628ef02a653..152afc21b9d 100644
> --- a/gdb/solib-darwin.c
> +++ b/gdb/solib-darwin.c
> @@ -488,7 +488,8 @@ darwin_solib_read_all_image_info_addr (struct darwin_info *info)
>    if (TYPE_LENGTH (ptr_type) > sizeof (buf))
>      return;
>  
> -  len = target_read (current_top_target (), TARGET_OBJECT_DARWIN_DYLD_INFO,
> +  len = target_read (current_inferior ()->top_target (),
> +		     TARGET_OBJECT_DARWIN_DYLD_INFO,
>  		     NULL, buf, 0, TYPE_LENGTH (ptr_type));
>    if (len <= 0)
>      return;
> diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
> index 4b1b7560e16..c279435c89a 100644
> --- a/gdb/solib-dsbt.c
> +++ b/gdb/solib-dsbt.c
> @@ -280,7 +280,8 @@ dsbt_get_initial_loadmaps (void)
>  {
>    struct dsbt_info *info = get_dsbt_info ();
>    gdb::optional<gdb::byte_vector> buf
> -    = target_read_alloc (current_top_target (), TARGET_OBJECT_FDPIC, "exec");
> +    = target_read_alloc (current_inferior ()->top_target (),
> +			 TARGET_OBJECT_FDPIC, "exec");
>  
>    if (!buf || buf->empty ())
>      {
> @@ -291,7 +292,8 @@ dsbt_get_initial_loadmaps (void)
>    if (solib_dsbt_debug)
>      dsbt_print_loadmap (info->exec_loadmap);
>  
> -  buf = target_read_alloc (current_top_target (), TARGET_OBJECT_FDPIC, "exec");
> +  buf = target_read_alloc (current_inferior ()->top_target (),
> +			   TARGET_OBJECT_FDPIC, "exec");
>    if (!buf || buf->empty ())
>      {
>        info->interp_loadmap = NULL;
> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
> index c7b3157191f..531469484e5 100644
> --- a/gdb/solib-svr4.c
> +++ b/gdb/solib-svr4.c
> @@ -428,11 +428,14 @@ read_program_header (int type, int *p_arch_size, CORE_ADDR *base_addr)
>    int pt_phdr_p = 0;
>  
>    /* Get required auxv elements from target.  */
> -  if (target_auxv_search (current_top_target (), AT_PHDR, &at_phdr) <= 0)
> +  if (target_auxv_search (current_inferior ()->top_target (),
> +			  AT_PHDR, &at_phdr) <= 0)
>      return {};
> -  if (target_auxv_search (current_top_target (), AT_PHENT, &at_phent) <= 0)
> +  if (target_auxv_search (current_inferior ()->top_target (),
> +			  AT_PHENT, &at_phent) <= 0)
>      return {};
> -  if (target_auxv_search (current_top_target (), AT_PHNUM, &at_phnum) <= 0)
> +  if (target_auxv_search (current_inferior ()->top_target (),
> +			  AT_PHNUM, &at_phnum) <= 0)
>      return {};
>    if (!at_phdr || !at_phnum)
>      return {};
> @@ -1239,7 +1242,8 @@ svr4_current_sos_via_xfer_libraries (struct svr4_library_list *list,
>  
>    /* Fetch the list of shared libraries.  */
>    gdb::optional<gdb::char_vector> svr4_library_document
> -    = target_read_stralloc (current_top_target (), TARGET_OBJECT_LIBRARIES_SVR4,
> +    = target_read_stralloc (current_inferior ()->top_target (),
> +			    TARGET_OBJECT_LIBRARIES_SVR4,
>  			    annex);
>    if (!svr4_library_document)
>      return 0;
> @@ -2242,9 +2246,8 @@ enable_break (struct svr4_info *info, int from_tty)
>  
>        sym_addr = gdbarch_addr_bits_remove
>  	(target_gdbarch (),
> -	 gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
> -					     sym_addr,
> -					     current_top_target ()));
> +	 gdbarch_convert_from_func_ptr_addr
> +	   (target_gdbarch (), sym_addr, current_inferior ()->top_target ()));
>  
>        /* On at least some versions of Solaris there's a dynamic relocation
>  	 on _r_debug.r_brk and SYM_ADDR may not be relocated yet, e.g., if
> @@ -2353,7 +2356,8 @@ enable_break (struct svr4_info *info, int from_tty)
>        /* If we were not able to find the base address of the loader
>  	 from our so_list, then try using the AT_BASE auxilliary entry.  */
>        if (!load_addr_found)
> -	if (target_auxv_search (current_top_target (), AT_BASE, &load_addr) > 0)
> +	if (target_auxv_search (current_inferior ()->top_target (),
> +				AT_BASE, &load_addr) > 0)
>  	  {
>  	    int addr_bit = gdbarch_addr_bit (target_gdbarch ());
>  
> @@ -2474,9 +2478,8 @@ enable_break (struct svr4_info *info, int from_tty)
>  	  && (BMSYMBOL_VALUE_ADDRESS (msymbol) != 0))
>  	{
>  	  sym_addr = BMSYMBOL_VALUE_ADDRESS (msymbol);
> -	  sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
> -							 sym_addr,
> -							 current_top_target ());
> +	  sym_addr = gdbarch_convert_from_func_ptr_addr
> +	    (target_gdbarch (), sym_addr, current_inferior ()->top_target ());
>  	  svr4_create_solib_event_breakpoints (info, target_gdbarch (),
>  					       sym_addr);
>  	  return 1;
> @@ -2492,9 +2495,9 @@ enable_break (struct svr4_info *info, int from_tty)
>  	      && (BMSYMBOL_VALUE_ADDRESS (msymbol) != 0))
>  	    {
>  	      sym_addr = BMSYMBOL_VALUE_ADDRESS (msymbol);
> -	      sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
> -							     sym_addr,
> -							     current_top_target ());
> +	      sym_addr = gdbarch_convert_from_func_ptr_addr
> +		(target_gdbarch (), sym_addr,
> +		 current_inferior ()->top_target ());
>  	      svr4_create_solib_event_breakpoints (info, target_gdbarch (),
>  						   sym_addr);
>  	      return 1;
> @@ -2582,7 +2585,8 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
>    if ((bfd_get_file_flags (current_program_space->exec_bfd ()) & DYNAMIC) == 0)
>      return 0;
>  
> -  if (target_auxv_search (current_top_target (), AT_ENTRY, &entry_point) <= 0)
> +  if (target_auxv_search (current_inferior ()->top_target (),
> +			  AT_ENTRY, &entry_point) <= 0)
>      return 0;
>  
>    exec_displacement
> diff --git a/gdb/solib-target.c b/gdb/solib-target.c
> index d8e33c3b027..1e010c52221 100644
> --- a/gdb/solib-target.c
> +++ b/gdb/solib-target.c
> @@ -25,6 +25,7 @@
>  #include "target.h"
>  #include "solib-target.h"
>  #include <vector>
> +#include "inferior.h"
>  
>  /* Private data for each loaded library.  */
>  struct lm_info_target : public lm_info_base
> @@ -233,8 +234,8 @@ solib_target_current_sos (void)
>  
>    /* Fetch the list of shared libraries.  */
>    gdb::optional<gdb::char_vector> library_document
> -    = target_read_stralloc (current_top_target (), TARGET_OBJECT_LIBRARIES,
> -			    NULL);
> +    = target_read_stralloc (current_inferior ()->top_target (),
> +			    TARGET_OBJECT_LIBRARIES, NULL);
>    if (!library_document)
>      return NULL;
>  
> diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
> index 34f22879737..a6df0fcb58b 100644
> --- a/gdb/sparc-tdep.c
> +++ b/gdb/sparc-tdep.c
> @@ -189,7 +189,7 @@ ULONGEST
>  sparc_fetch_wcookie (struct gdbarch *gdbarch)
>  {
>    enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  struct target_ops *ops = current_top_target ();
> +  struct target_ops *ops = current_inferior ()->top_target ();
>    gdb_byte buf[8];
>    int len;
>  
> diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
> index c4d5ab21b2f..3609794419a 100644
> --- a/gdb/sparc64-tdep.c
> +++ b/gdb/sparc64-tdep.c
> @@ -214,10 +214,12 @@ adi_available (void)
>      return proc->stat.is_avail;
>  
>    proc->stat.checked_avail = true;
> -  if (target_auxv_search (current_top_target (), AT_ADI_BLKSZ, &value) <= 0)
> +  if (target_auxv_search (current_inferior ()->top_target (),
> +			  AT_ADI_BLKSZ, &value) <= 0)
>      return false;
>    proc->stat.blksize = value;
> -  target_auxv_search (current_top_target (), AT_ADI_NBITS, &value);
> +  target_auxv_search (current_inferior ()->top_target (),
> +		      AT_ADI_NBITS, &value);
>    proc->stat.nbits = value;
>    proc->stat.max_version = (1 << proc->stat.nbits) - 2;
>    proc->stat.is_avail = true;
> diff --git a/gdb/symfile.c b/gdb/symfile.c
> index adcdc169306..e417878031d 100644
> --- a/gdb/symfile.c
> +++ b/gdb/symfile.c
> @@ -838,10 +838,8 @@ init_entry_point_info (struct objfile *objfile)
>  
>        /* Make certain that the address points at real code, and not a
>  	 function descriptor.  */
> -      entry_point
> -	= gdbarch_convert_from_func_ptr_addr (objfile->arch (),
> -					      entry_point,
> -					      current_top_target ());
> +      entry_point = gdbarch_convert_from_func_ptr_addr
> +	(objfile->arch (), entry_point, current_inferior ()->top_target ());
>  
>        /* Remove any ISA markers, so that this matches entries in the
>  	 symbol table.  */
> diff --git a/gdb/symtab.c b/gdb/symtab.c
> index 084e8ecc2e8..122fdf0b1d3 100644
> --- a/gdb/symtab.c
> +++ b/gdb/symtab.c
> @@ -5564,10 +5564,8 @@ find_gnu_ifunc (const symbol *sym)
>  	  if (MSYMBOL_TYPE (minsym) == mst_data_gnu_ifunc)
>  	    {
>  	      struct gdbarch *gdbarch = objfile->arch ();
> -	      msym_addr
> -		= gdbarch_convert_from_func_ptr_addr (gdbarch,
> -						      msym_addr,
> -						      current_top_target ());
> +	      msym_addr = gdbarch_convert_from_func_ptr_addr
> +		(gdbarch, msym_addr, current_inferior ()->top_target ());
>  	    }
>  	  if (msym_addr == address)
>  	    {
> diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
> index 248edd51bd1..c0e798a3530 100644
> --- a/gdb/target-descriptions.c
> +++ b/gdb/target-descriptions.c
> @@ -553,11 +553,13 @@ target_find_description (void)
>    /* Next try to read the description from the current target using
>       target objects.  */
>    if (current_target_desc == NULL)
> -    current_target_desc = target_read_description_xml (current_top_target ());
> +    current_target_desc = target_read_description_xml
> +      (current_inferior ()->top_target ());
>  
>    /* If that failed try a target-specific hook.  */
>    if (current_target_desc == NULL)
> -    current_target_desc = target_read_description (current_top_target ());
> +    current_target_desc = target_read_description
> +      (current_inferior ()->top_target ());
>  
>    /* If a non-NULL description was returned, then update the current
>       architecture.  */
> diff --git a/gdb/target-memory.c b/gdb/target-memory.c
> index 060f9cc6642..877f6c3e946 100644
> --- a/gdb/target-memory.c
> +++ b/gdb/target-memory.c
> @@ -21,6 +21,7 @@
>  #include "defs.h"
>  #include "target.h"
>  #include "memory-map.h"
> +#include "inferior.h"
>  
>  #include "gdbsupport/gdb_sys_time.h"
>  #include <algorithm>
> @@ -335,7 +336,7 @@ target_write_memory_blocks (const std::vector<memory_write_request> &requests,
>      {
>        LONGEST len;
>  
> -      len = target_write_with_progress (current_top_target (),
> +      len = target_write_with_progress (current_inferior ()->top_target (),
>  					TARGET_OBJECT_MEMORY, NULL,
>  					iter.data, iter.begin,
>  					iter.end - iter.begin,
> @@ -358,7 +359,7 @@ target_write_memory_blocks (const std::vector<memory_write_request> &requests,
>  	{
>  	  LONGEST len;
>  
> -	  len = target_write_with_progress (current_top_target (),
> +	  len = target_write_with_progress (current_inferior ()->top_target (),
>  					    TARGET_OBJECT_FLASH, NULL,
>  					    iter.data, iter.begin,
>  					    iter.end - iter.begin,
> diff --git a/gdb/target.c b/gdb/target.c
> index e7af5e8a9b0..6956bc08e37 100644
> --- a/gdb/target.c
> +++ b/gdb/target.c
> @@ -110,16 +110,6 @@ static std::unordered_map<const target_info *, target_open_ftype *>
>  
>  static struct target_ops *the_debug_target;
>  
> -/* Top of target stack.  */
> -/* The target structure we are currently using to talk to a process
> -   or file or whatever "inferior" we have.  */
> -
> -target_ops *
> -current_top_target ()
> -{
> -  return current_inferior ()->top_target ();
> -}
> -
>  /* Command list for target.  */
>  
>  static struct cmd_list_element *targetlist = NULL;
> @@ -173,7 +163,9 @@ show_targetdebug (struct ui_file *file, int from_tty,
>  int
>  target_has_memory ()
>  {
> -  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
> +  for (target_ops *t = current_inferior ()->top_target ();
> +       t != NULL;
> +       t = t->beneath ())
>      if (t->has_memory ())
>        return 1;
>  
> @@ -183,7 +175,9 @@ target_has_memory ()
>  int
>  target_has_stack ()
>  {
> -  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
> +  for (target_ops *t = current_inferior ()->top_target ();
> +       t != NULL;
> +       t = t->beneath ())
>      if (t->has_stack ())
>        return 1;
>  
> @@ -193,7 +187,9 @@ target_has_stack ()
>  int
>  target_has_registers ()
>  {
> -  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
> +  for (target_ops *t = current_inferior ()->top_target ();
> +       t != NULL;
> +       t = t->beneath ())
>      if (t->has_registers ())
>        return 1;
>  
> @@ -218,7 +214,7 @@ target_has_execution (inferior *inf)
>  const char *
>  target_shortname ()
>  {
> -  return current_top_target ()->shortname ();
> +  return current_inferior ()->top_target ()->shortname ();
>  }
>  
>  /* See target.h.  */
> @@ -226,7 +222,7 @@ target_shortname ()
>  bool
>  target_attach_no_wait ()
>  {
> -  return current_top_target ()->attach_no_wait ();
> +  return current_inferior ()->top_target ()->attach_no_wait ();
>  }
>  
>  /* See target.h.  */
> @@ -234,7 +230,7 @@ target_attach_no_wait ()
>  void
>  target_post_attach (int pid)
>  {
> -  return current_top_target ()->post_attach (pid);
> +  return current_inferior ()->top_target ()->post_attach (pid);
>  }
>  
>  /* See target.h.  */
> @@ -242,7 +238,7 @@ target_post_attach (int pid)
>  void
>  target_prepare_to_store (regcache *regcache)
>  {
> -  return current_top_target ()->prepare_to_store (regcache);
> +  return current_inferior ()->top_target ()->prepare_to_store (regcache);
>  }
>  
>  /* See target.h.  */
> @@ -250,13 +246,15 @@ target_prepare_to_store (regcache *regcache)
>  bool
>  target_supports_enable_disable_tracepoint ()
>  {
> -  return current_top_target ()->supports_enable_disable_tracepoint ();
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->supports_enable_disable_tracepoint ();
>  }
>  
>  bool
>  target_supports_string_tracing ()
>  {
> -  return current_top_target ()->supports_string_tracing ();
> +  return current_inferior ()->top_target ()->supports_string_tracing ();
>  }
>  
>  /* See target.h.  */
> @@ -264,7 +262,9 @@ target_supports_string_tracing ()
>  bool
>  target_supports_evaluation_of_breakpoint_conditions ()
>  {
> -  return current_top_target ()->supports_evaluation_of_breakpoint_conditions ();
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->supports_evaluation_of_breakpoint_conditions ();
>  }
>  
>  /* See target.h.  */
> @@ -272,7 +272,7 @@ target_supports_evaluation_of_breakpoint_conditions ()
>  bool
>  target_supports_dumpcore ()
>  {
> -  return current_top_target ()->supports_dumpcore ();
> +  return current_inferior ()->top_target ()->supports_dumpcore ();
>  }
>  
>  /* See target.h.  */
> @@ -280,7 +280,7 @@ target_supports_dumpcore ()
>  void
>  target_dumpcore (const char *filename)
>  {
> -  return current_top_target ()->dumpcore (filename);
> +  return current_inferior ()->top_target ()->dumpcore (filename);
>  }
>  
>  /* See target.h.  */
> @@ -288,7 +288,7 @@ target_dumpcore (const char *filename)
>  bool
>  target_can_run_breakpoint_commands ()
>  {
> -  return current_top_target ()->can_run_breakpoint_commands ();
> +  return current_inferior ()->top_target ()->can_run_breakpoint_commands ();
>  }
>  
>  /* See target.h.  */
> @@ -296,7 +296,7 @@ target_can_run_breakpoint_commands ()
>  void
>  target_files_info ()
>  {
> -  return current_top_target ()->files_info ();
> +  return current_inferior ()->top_target ()->files_info ();
>  }
>  
>  /* See target.h.  */
> @@ -304,7 +304,7 @@ target_files_info ()
>  void
>  target_post_startup_inferior (ptid_t ptid)
>  {
> -  return current_top_target ()->post_startup_inferior (ptid);
> +  return current_inferior ()->top_target ()->post_startup_inferior (ptid);
>  }
>  
>  /* See target.h.  */
> @@ -312,7 +312,7 @@ target_post_startup_inferior (ptid_t ptid)
>  int
>  target_insert_fork_catchpoint (int pid)
>  {
> -  return current_top_target ()->insert_fork_catchpoint (pid);
> +  return current_inferior ()->top_target ()->insert_fork_catchpoint (pid);
>  }
>  
>  /* See target.h.  */
> @@ -320,7 +320,7 @@ target_insert_fork_catchpoint (int pid)
>  int
>  target_remove_fork_catchpoint (int pid)
>  {
> -  return current_top_target ()->remove_fork_catchpoint (pid);
> +  return current_inferior ()->top_target ()->remove_fork_catchpoint (pid);
>  }
>  
>  /* See target.h.  */
> @@ -328,7 +328,7 @@ target_remove_fork_catchpoint (int pid)
>  int
>  target_insert_vfork_catchpoint (int pid)
>  {
> -  return current_top_target ()->insert_vfork_catchpoint (pid);
> +  return current_inferior ()->top_target ()->insert_vfork_catchpoint (pid);
>  }
>  
>  /* See target.h.  */
> @@ -336,7 +336,7 @@ target_insert_vfork_catchpoint (int pid)
>  int
>  target_remove_vfork_catchpoint (int pid)
>  {
> -  return current_top_target ()->remove_vfork_catchpoint (pid);
> +  return current_inferior ()->top_target ()->remove_vfork_catchpoint (pid);
>  }
>  
>  /* See target.h.  */
> @@ -344,7 +344,7 @@ target_remove_vfork_catchpoint (int pid)
>  int
>  target_insert_exec_catchpoint (int pid)
>  {
> -  return current_top_target ()->insert_exec_catchpoint (pid);
> +  return current_inferior ()->top_target ()->insert_exec_catchpoint (pid);
>  }
>  
>  /* See target.h.  */
> @@ -352,7 +352,7 @@ target_insert_exec_catchpoint (int pid)
>  int
>  target_remove_exec_catchpoint (int pid)
>  {
> -  return current_top_target ()->remove_exec_catchpoint (pid);
> +  return current_inferior ()->top_target ()->remove_exec_catchpoint (pid);
>  }
>  
>  /* See target.h.  */
> @@ -361,8 +361,10 @@ int
>  target_set_syscall_catchpoint (int pid, bool needed, int any_count,
>  			       gdb::array_view<const int> syscall_counts)
>  {
> -  return current_top_target ()->set_syscall_catchpoint (pid, needed, any_count,
> -							syscall_counts);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->set_syscall_catchpoint (pid, needed, any_count,
> +					 syscall_counts);
>  }
>  
>  /* See target.h.  */
> @@ -370,7 +372,7 @@ target_set_syscall_catchpoint (int pid, bool needed, int any_count,
>  void
>  target_rcmd (const char *command, struct ui_file *outbuf)
>  {
> -  return current_top_target ()->rcmd (command, outbuf);
> +  return current_inferior ()->top_target ()->rcmd (command, outbuf);
>  }
>  
>  /* See target.h.  */
> @@ -378,8 +380,9 @@ target_rcmd (const char *command, struct ui_file *outbuf)
>  bool
>  target_can_lock_scheduler ()
>  {
> -  return (current_top_target ()->get_thread_control_capabilities ()
> -	  & tc_schedlock) != 0;
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return (target->get_thread_control_capabilities ()& tc_schedlock) != 0;
>  }
>  
>  /* See target.h.  */
> @@ -387,7 +390,7 @@ target_can_lock_scheduler ()
>  bool
>  target_can_async_p ()
>  {
> -  return current_top_target ()->can_async_p ();
> +  return current_inferior ()->top_target ()->can_async_p ();
>  }
>  
>  /* See target.h.  */
> @@ -395,13 +398,13 @@ target_can_async_p ()
>  bool
>  target_is_async_p ()
>  {
> -  return current_top_target ()->is_async_p ();
> +  return current_inferior ()->top_target ()->is_async_p ();
>  }
>  
>  exec_direction_kind
>  target_execution_direction ()
>  {
> -  return current_top_target ()->execution_direction ();
> +  return current_inferior ()->top_target ()->execution_direction ();
>  }
>  
>  /* See target.h.  */
> @@ -409,7 +412,7 @@ target_execution_direction ()
>  const char *
>  target_extra_thread_info (thread_info *tp)
>  {
> -  return current_top_target ()->extra_thread_info (tp);
> +  return current_inferior ()->top_target ()->extra_thread_info (tp);
>  }
>  
>  /* See target.h.  */
> @@ -417,7 +420,7 @@ target_extra_thread_info (thread_info *tp)
>  char *
>  target_pid_to_exec_file (int pid)
>  {
> -  return current_top_target ()->pid_to_exec_file (pid);
> +  return current_inferior ()->top_target ()->pid_to_exec_file (pid);
>  }
>  
>  /* See target.h.  */
> @@ -425,7 +428,7 @@ target_pid_to_exec_file (int pid)
>  gdbarch *
>  target_thread_architecture (ptid_t ptid)
>  {
> -  return current_top_target ()->thread_architecture (ptid);
> +  return current_inferior ()->top_target ()->thread_architecture (ptid);
>  }
>  
>  /* See target.h.  */
> @@ -433,7 +436,7 @@ target_thread_architecture (ptid_t ptid)
>  int
>  target_find_memory_regions (find_memory_region_ftype func, void *data)
>  {
> -  return current_top_target ()->find_memory_regions (func, data);
> +  return current_inferior ()->top_target ()->find_memory_regions (func, data);
>  }
>  
>  /* See target.h.  */
> @@ -441,19 +444,19 @@ target_find_memory_regions (find_memory_region_ftype func, void *data)
>  gdb::unique_xmalloc_ptr<char>
>  target_make_corefile_notes (bfd *bfd, int *size_p)
>  {
> -  return current_top_target ()->make_corefile_notes (bfd, size_p);
> +  return current_inferior ()->top_target ()->make_corefile_notes (bfd, size_p);
>  }
>  
>  gdb_byte *
>  target_get_bookmark (const char *args, int from_tty)
>  {
> -  return current_top_target ()->get_bookmark (args, from_tty);
> +  return current_inferior ()->top_target ()->get_bookmark (args, from_tty);
>  }
>  
>  void
>  target_goto_bookmark (const gdb_byte *arg, int from_tty)
>  {
> -  return current_top_target ()->goto_bookmark (arg, from_tty);
> +  return current_inferior ()->top_target ()->goto_bookmark (arg, from_tty);
>  }
>  
>  /* See target.h.  */
> @@ -461,7 +464,7 @@ target_goto_bookmark (const gdb_byte *arg, int from_tty)
>  bool
>  target_stopped_by_watchpoint ()
>  {
> -  return current_top_target ()->stopped_by_watchpoint ();
> +  return current_inferior ()->top_target ()->stopped_by_watchpoint ();
>  }
>  
>  /* See target.h.  */
> @@ -469,25 +472,29 @@ target_stopped_by_watchpoint ()
>  bool
>  target_stopped_by_sw_breakpoint ()
>  {
> -  return current_top_target ()->stopped_by_sw_breakpoint ();
> +  return current_inferior ()->top_target ()->stopped_by_sw_breakpoint ();
>  }
>  
>  bool
>  target_supports_stopped_by_sw_breakpoint ()
>  {
> -  return current_top_target ()->supports_stopped_by_sw_breakpoint ();
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->supports_stopped_by_sw_breakpoint ();
>  }
>  
>  bool
>  target_stopped_by_hw_breakpoint ()
>  {
> -  return current_top_target ()->stopped_by_hw_breakpoint ();
> +  return current_inferior ()->top_target ()->stopped_by_hw_breakpoint ();
>  }
>  
>  bool
>  target_supports_stopped_by_hw_breakpoint ()
>  {
> -  return current_top_target ()->supports_stopped_by_hw_breakpoint ();
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->supports_stopped_by_hw_breakpoint ();
>  }
>  
>  /* See target.h.  */
> @@ -495,7 +502,7 @@ target_supports_stopped_by_hw_breakpoint ()
>  bool
>  target_have_steppable_watchpoint ()
>  {
> -  return current_top_target ()->have_steppable_watchpoint ();
> +  return current_inferior ()->top_target ()->have_steppable_watchpoint ();
>  }
>  
>  /* See target.h.  */
> @@ -503,7 +510,9 @@ target_have_steppable_watchpoint ()
>  int
>  target_can_use_hardware_watchpoint (bptype type, int cnt, int othertype)
>  {
> -  return current_top_target ()->can_use_hw_breakpoint (type, cnt, othertype);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->can_use_hw_breakpoint (type, cnt, othertype);
>  }
>  
>  /* See target.h.  */
> @@ -511,14 +520,16 @@ target_can_use_hardware_watchpoint (bptype type, int cnt, int othertype)
>  int
>  target_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
>  {
> -  return current_top_target ()->region_ok_for_hw_watchpoint (addr, len);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->region_ok_for_hw_watchpoint (addr, len);
>  }
>  
>  
>  int
>  target_can_do_single_step ()
>  {
> -  return current_top_target ()->can_do_single_step ();
> +  return current_inferior ()->top_target ()->can_do_single_step ();
>  }
>  
>  /* See target.h.  */
> @@ -527,7 +538,9 @@ int
>  target_insert_watchpoint (CORE_ADDR addr, int len, target_hw_bp_type type,
>  			  expression *cond)
>  {
> -  return current_top_target ()->insert_watchpoint (addr, len, type, cond);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->insert_watchpoint (addr, len, type, cond);
>  }
>  
>  /* See target.h.  */
> @@ -536,7 +549,9 @@ int
>  target_remove_watchpoint (CORE_ADDR addr, int len, target_hw_bp_type type,
>  			  expression *cond)
>  {
> -  return current_top_target ()->remove_watchpoint (addr, len, type, cond);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->remove_watchpoint (addr, len, type, cond);
>  }
>  
>  /* See target.h.  */
> @@ -544,7 +559,9 @@ target_remove_watchpoint (CORE_ADDR addr, int len, target_hw_bp_type type,
>  int
>  target_insert_hw_breakpoint (gdbarch *gdbarch, bp_target_info *bp_tgt)
>  {
> -  return current_top_target ()->insert_hw_breakpoint (gdbarch, bp_tgt);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->insert_hw_breakpoint (gdbarch, bp_tgt);
>  }
>  
>  /* See target.h.  */
> @@ -552,7 +569,9 @@ target_insert_hw_breakpoint (gdbarch *gdbarch, bp_target_info *bp_tgt)
>  int
>  target_remove_hw_breakpoint (gdbarch *gdbarch, bp_target_info *bp_tgt)
>  {
> -  return current_top_target ()->remove_hw_breakpoint (gdbarch, bp_tgt);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->remove_hw_breakpoint (gdbarch, bp_tgt);
>  }
>  
>  /* See target.h.  */
> @@ -561,7 +580,9 @@ bool
>  target_can_accel_watchpoint_condition (CORE_ADDR addr, int len, int type,
>  				       expression *cond)
>  {
> -  return current_top_target ()->can_accel_watchpoint_condition (addr, len, type, cond);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->can_accel_watchpoint_condition (addr, len, type, cond);
>  }
>  
>  /* See target.h.  */
> @@ -569,208 +590,226 @@ target_can_accel_watchpoint_condition (CORE_ADDR addr, int len, int type,
>  bool
>  target_can_execute_reverse ()
>  {
> -  return current_top_target ()->can_execute_reverse ();
> +  return current_inferior ()->top_target ()->can_execute_reverse ();
>  }
>  
>  ptid_t
>  target_get_ada_task_ptid (long lwp, long tid)
>  {
> -  return current_top_target ()->get_ada_task_ptid (lwp, tid);
> +  return current_inferior ()->top_target ()->get_ada_task_ptid (lwp, tid);
>  }
>  
>  bool
>  target_filesystem_is_local ()
>  {
> -  return current_top_target ()->filesystem_is_local ();
> +  return current_inferior ()->top_target ()->filesystem_is_local ();
>  }
>  
>  void
>  target_trace_init ()
>  {
> -  return current_top_target ()->trace_init ();
> +  return current_inferior ()->top_target ()->trace_init ();
>  }
>  
>  void
>  target_download_tracepoint (bp_location *location)
>  {
> -  return current_top_target ()->download_tracepoint (location);
> +  return current_inferior ()->top_target ()->download_tracepoint (location);
>  }
>  
>  bool
>  target_can_download_tracepoint ()
>  {
> -  return current_top_target ()->can_download_tracepoint ();
> +  return current_inferior ()->top_target ()->can_download_tracepoint ();
>  }
>  
>  void
>  target_download_trace_state_variable (const trace_state_variable &tsv)
>  {
> -  return current_top_target ()->download_trace_state_variable (tsv);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->download_trace_state_variable (tsv);
>  }
>  
>  void
>  target_enable_tracepoint (bp_location *loc)
>  {
> -  return current_top_target ()->enable_tracepoint (loc);
> +  return current_inferior ()->top_target ()->enable_tracepoint (loc);
>  }
>  
>  void
>  target_disable_tracepoint (bp_location *loc)
>  {
> -  return current_top_target ()->disable_tracepoint (loc);
> +  return current_inferior ()->top_target ()->disable_tracepoint (loc);
>  }
>  
>  void
>  target_trace_start ()
>  {
> -  return current_top_target ()->trace_start ();
> +  return current_inferior ()->top_target ()->trace_start ();
>  }
>  
>  void
>  target_trace_set_readonly_regions ()
>  {
> -  current_top_target ()->trace_set_readonly_regions ();
> +  return current_inferior ()->top_target ()->trace_set_readonly_regions ();
>  }
>  
>  int
>  target_get_trace_status (trace_status *ts)
>  {
> -  return current_top_target ()->get_trace_status (ts);
> +  return current_inferior ()->top_target ()->get_trace_status (ts);
>  }
>  
>  void
>  target_get_tracepoint_status (breakpoint *tp, uploaded_tp *utp)
>  {
> -  return current_top_target ()->get_tracepoint_status (tp, utp);
> +  return current_inferior ()->top_target ()->get_tracepoint_status (tp, utp);
>  }
>  
>  void
>  target_trace_stop ()
>  {
> -  return current_top_target ()->trace_stop ();
> +  return current_inferior ()->top_target ()->trace_stop ();
>  }
>  
>  int
>  target_trace_find (trace_find_type type, int num,
>  		   CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
>  {
> -  return current_top_target ()->trace_find (type, num, addr1, addr2, tpp);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->trace_find (type, num, addr1, addr2, tpp);
>  }
>  
>  bool
>  target_get_trace_state_variable_value (int tsv, LONGEST *val)
>  {
> -  return current_top_target ()->get_trace_state_variable_value (tsv, val);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->get_trace_state_variable_value (tsv, val);
>  }
>  
>  int
>  target_save_trace_data (const char *filename)
>  {
> -  return current_top_target ()->save_trace_data (filename);
> +  return current_inferior ()->top_target ()->save_trace_data (filename);
>  }
>  
>  int
>  target_upload_tracepoints (uploaded_tp **utpp)
>  {
> -  return current_top_target ()->upload_tracepoints (utpp);
> +  return current_inferior ()->top_target ()->upload_tracepoints (utpp);
>  }
>  
>  int
>  target_upload_trace_state_variables (uploaded_tsv **utsvp)
>  {
> -  return current_top_target ()->upload_trace_state_variables (utsvp);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->upload_trace_state_variables (utsvp);
>  }
>  
>  LONGEST
>  target_get_raw_trace_data (gdb_byte *buf, ULONGEST offset, LONGEST len)
>  {
> -  return current_top_target ()->get_raw_trace_data (buf, offset, len);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->get_raw_trace_data (buf, offset, len);
>  }
>  
>  int
>  target_get_min_fast_tracepoint_insn_len ()
>  {
> -  return current_top_target ()->get_min_fast_tracepoint_insn_len ();
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->get_min_fast_tracepoint_insn_len ();
>  }
>  
>  void
>  target_set_disconnected_tracing (int val)
>  {
> -  return current_top_target ()->set_disconnected_tracing (val);
> +  return current_inferior ()->top_target ()->set_disconnected_tracing (val);
>  }
>  
>  void
>  target_set_circular_trace_buffer (int val)
>  {
> -  return current_top_target ()->set_circular_trace_buffer (val);
> +  return current_inferior ()->top_target ()->set_circular_trace_buffer (val);
>  }
>  
>  void
>  target_set_trace_buffer_size (LONGEST val)
>  {
> -  return current_top_target ()->set_trace_buffer_size (val);
> +  return current_inferior ()->top_target ()->set_trace_buffer_size (val);
>  }
>  
>  bool
>  target_set_trace_notes (const char *user, const char *notes,
>  			const char *stopnotes)
>  {
> -  return current_top_target ()->set_trace_notes (user, notes, stopnotes);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->set_trace_notes (user, notes, stopnotes);
>  }
>  
>  bool
>  target_get_tib_address (ptid_t ptid, CORE_ADDR *addr)
>  {
> -  return current_top_target ()->get_tib_address (ptid, addr);
> +  return current_inferior ()->top_target ()->get_tib_address (ptid, addr);
>  }
>  
>  void
>  target_set_permissions ()
>  {
> -  return current_top_target ()->set_permissions ();
> +  return current_inferior ()->top_target ()->set_permissions ();
>  }
>  
>  bool
>  target_static_tracepoint_marker_at (CORE_ADDR addr,
>  				    static_tracepoint_marker *marker)
>  {
> -  return current_top_target ()->static_tracepoint_marker_at (addr, marker);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->static_tracepoint_marker_at (addr, marker);
>  }
>  
>  std::vector<static_tracepoint_marker>
>  target_static_tracepoint_markers_by_strid (const char *marker_id)
>  {
> -  return current_top_target ()->static_tracepoint_markers_by_strid (marker_id);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->static_tracepoint_markers_by_strid (marker_id);
>  }
>  
>  traceframe_info_up
>  target_traceframe_info ()
>  {
> -  return current_top_target ()->traceframe_info ();
> +  return current_inferior ()->top_target ()->traceframe_info ();
>  }
>  
>  bool
>  target_use_agent (bool use)
>  {
> -  return current_top_target ()->use_agent (use);
> +  return current_inferior ()->top_target ()->use_agent (use);
>  }
>  
>  bool
>  target_can_use_agent ()
>  {
> -  return current_top_target ()->can_use_agent ();
> +  return current_inferior ()->top_target ()->can_use_agent ();
>  }
>  
>  bool
>  target_augmented_libraries_svr4_read ()
>  {
> -  return current_top_target ()->augmented_libraries_svr4_read ();
> +  return current_inferior ()->top_target ()->augmented_libraries_svr4_read ();
>  }
>  
>  void
>  target_log_command (const char *p)
>  {
> -  return current_top_target ()->log_command (p);
> +  return current_inferior ()->top_target ()->log_command (p);
>  }
>  
>  /* This is used to implement the various target commands.  */
> @@ -843,14 +882,14 @@ add_deprecated_target_alias (const target_info &tinfo, const char *alias)
>  void
>  target_kill (void)
>  {
> -  current_top_target ()->kill ();
> +  current_inferior ()->top_target ()->kill ();
>  }
>  
>  void
>  target_load (const char *arg, int from_tty)
>  {
>    target_dcache_invalidate ();
> -  current_top_target ()->load (arg, from_tty);
> +  current_inferior ()->top_target ()->load (arg, from_tty);
>  }
>  
>  /* Define it.  */
> @@ -863,7 +902,7 @@ target_terminal_state target_terminal::m_terminal_state
>  void
>  target_terminal::init (void)
>  {
> -  current_top_target ()->terminal_init ();
> +  current_inferior ()->top_target ()->terminal_init ();
>  
>    m_terminal_state = target_terminal_state::is_ours;
>  }
> @@ -894,7 +933,7 @@ target_terminal::inferior (void)
>  
>    if (inf->terminal_state != target_terminal_state::is_inferior)
>      {
> -      current_top_target ()->terminal_inferior ();
> +      current_inferior ()->top_target ()->terminal_inferior ();
>        inf->terminal_state = target_terminal_state::is_inferior;
>      }
>  
> @@ -929,7 +968,7 @@ target_terminal::restore_inferior (void)
>  	if (inf->terminal_state == target_terminal_state::is_ours_for_output)
>  	  {
>  	    set_current_inferior (inf);
> -	    current_top_target ()->terminal_inferior ();
> +	    current_inferior ()->top_target ()->terminal_inferior ();
>  	    inf->terminal_state = target_terminal_state::is_inferior;
>  	  }
>        }
> @@ -961,7 +1000,7 @@ target_terminal_is_ours_kind (target_terminal_state desired_state)
>        if (inf->terminal_state == target_terminal_state::is_inferior)
>  	{
>  	  set_current_inferior (inf);
> -	  current_top_target ()->terminal_save_inferior ();
> +	  current_inferior ()->top_target ()->terminal_save_inferior ();
>  	}
>      }
>  
> @@ -976,9 +1015,9 @@ target_terminal_is_ours_kind (target_terminal_state desired_state)
>  	{
>  	  set_current_inferior (inf);
>  	  if (desired_state == target_terminal_state::is_ours)
> -	    current_top_target ()->terminal_ours ();
> +	    current_inferior ()->top_target ()->terminal_ours ();
>  	  else if (desired_state == target_terminal_state::is_ours_for_output)
> -	    current_top_target ()->terminal_ours_for_output ();
> +	    current_inferior ()->top_target ()->terminal_ours_for_output ();
>  	  else
>  	    gdb_assert_not_reached ("unhandled desired state");
>  	  inf->terminal_state = desired_state;
> @@ -1027,7 +1066,7 @@ target_terminal::ours_for_output ()
>  void
>  target_terminal::info (const char *arg, int from_tty)
>  {
> -  current_top_target ()->terminal_info (arg, from_tty);
> +  current_inferior ()->top_target ()->terminal_info (arg, from_tty);
>  }
>  
>  /* See target.h.  */
> @@ -1051,7 +1090,7 @@ static void
>  tcomplain (void)
>  {
>    error (_("You can't do that when your target is `%s'"),
> -	 current_top_target ()->shortname ());
> +	 current_inferior ()->top_target ()->shortname ());
>  }
>  
>  void
> @@ -1186,8 +1225,9 @@ unpush_target_and_assert (struct target_ops *target)
>  void
>  pop_all_targets_above (enum strata above_stratum)
>  {
> -  while ((int) (current_top_target ()->stratum ()) > (int) above_stratum)
> -    unpush_target_and_assert (current_top_target ());
> +  while ((int) (current_inferior ()->top_target ()->stratum ())
> +	 > (int) above_stratum)
> +    unpush_target_and_assert (current_inferior ()->top_target ());
>  }
>  
>  /* See target.h.  */
> @@ -1195,8 +1235,9 @@ pop_all_targets_above (enum strata above_stratum)
>  void
>  pop_all_targets_at_and_above (enum strata stratum)
>  {
> -  while ((int) (current_top_target ()->stratum ()) >= (int) stratum)
> -    unpush_target_and_assert (current_top_target ());
> +  while ((int) (current_inferior ()->top_target ()->stratum ())
> +	 >= (int) stratum)
> +    unpush_target_and_assert (current_inferior ()->top_target ());
>  }
>  
>  void
> @@ -1226,7 +1267,7 @@ CORE_ADDR
>  target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
>  {
>    volatile CORE_ADDR addr = 0;
> -  struct target_ops *target = current_top_target ();
> +  struct target_ops *target = current_inferior ()->top_target ();
>    struct gdbarch *gdbarch = target_gdbarch ();
>  
>    if (gdbarch_fetch_tls_load_module_address_p (gdbarch))
> @@ -1745,7 +1786,8 @@ target_xfer_partial (struct target_ops *ops,
>  int
>  target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
>  {
> -  if (target_read (current_top_target (), TARGET_OBJECT_MEMORY, NULL,
> +  if (target_read (current_inferior ()->top_target (),
> +		   TARGET_OBJECT_MEMORY, NULL,
>  		   myaddr, memaddr, len) == len)
>      return 0;
>    else
> @@ -1775,7 +1817,8 @@ target_read_uint32 (CORE_ADDR memaddr, uint32_t *result)
>  int
>  target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
>  {
> -  if (target_read (current_top_target (), TARGET_OBJECT_RAW_MEMORY, NULL,
> +  if (target_read (current_inferior ()->top_target (),
> +		   TARGET_OBJECT_RAW_MEMORY, NULL,
>  		   myaddr, memaddr, len) == len)
>      return 0;
>    else
> @@ -1788,7 +1831,8 @@ target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
>  int
>  target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
>  {
> -  if (target_read (current_top_target (), TARGET_OBJECT_STACK_MEMORY, NULL,
> +  if (target_read (current_inferior ()->top_target (),
> +		   TARGET_OBJECT_STACK_MEMORY, NULL,
>  		   myaddr, memaddr, len) == len)
>      return 0;
>    else
> @@ -1801,7 +1845,8 @@ target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
>  int
>  target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
>  {
> -  if (target_read (current_top_target (), TARGET_OBJECT_CODE_MEMORY, NULL,
> +  if (target_read (current_inferior ()->top_target (),
> +		   TARGET_OBJECT_CODE_MEMORY, NULL,
>  		   myaddr, memaddr, len) == len)
>      return 0;
>    else
> @@ -1817,7 +1862,8 @@ target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
>  int
>  target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
>  {
> -  if (target_write (current_top_target (), TARGET_OBJECT_MEMORY, NULL,
> +  if (target_write (current_inferior ()->top_target (),
> +		    TARGET_OBJECT_MEMORY, NULL,
>  		    myaddr, memaddr, len) == len)
>      return 0;
>    else
> @@ -1833,7 +1879,8 @@ target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
>  int
>  target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
>  {
> -  if (target_write (current_top_target (), TARGET_OBJECT_RAW_MEMORY, NULL,
> +  if (target_write (current_inferior ()->top_target (),
> +		    TARGET_OBJECT_RAW_MEMORY, NULL,
>  		    myaddr, memaddr, len) == len)
>      return 0;
>    else
> @@ -1845,7 +1892,8 @@ target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
>  std::vector<mem_region>
>  target_memory_map (void)
>  {
> -  std::vector<mem_region> result = current_top_target ()->memory_map ();
> +  target_ops *target = current_inferior ()->top_target ();
> +  std::vector<mem_region> result = target->memory_map ();
>    if (result.empty ())
>      return result;
>  
> @@ -1875,13 +1923,13 @@ target_memory_map (void)
>  void
>  target_flash_erase (ULONGEST address, LONGEST length)
>  {
> -  current_top_target ()->flash_erase (address, length);
> +  current_inferior ()->top_target ()->flash_erase (address, length);
>  }
>  
>  void
>  target_flash_done (void)
>  {
> -  current_top_target ()->flash_done ();
> +  current_inferior ()->top_target ()->flash_done ();
>  }
>  
>  static void
> @@ -2336,7 +2384,9 @@ target_insert_breakpoint (struct gdbarch *gdbarch,
>        return 1;
>      }
>  
> -  return current_top_target ()->insert_breakpoint (gdbarch, bp_tgt);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->insert_breakpoint (gdbarch, bp_tgt);
>  }
>  
>  /* See target.h.  */
> @@ -2356,7 +2406,9 @@ target_remove_breakpoint (struct gdbarch *gdbarch,
>        return 1;
>      }
>  
> -  return current_top_target ()->remove_breakpoint (gdbarch, bp_tgt, reason);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->remove_breakpoint (gdbarch, bp_tgt, reason);
>  }
>  
>  static void
> @@ -2371,7 +2423,9 @@ info_target_command (const char *args, int from_tty)
>  			 objfile_name (objf));
>      }
>  
> -  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
> +  for (target_ops *t = current_inferior ()->top_target ();
> +       t != NULL;
> +       t = t->beneath ())
>      {
>        if (!t->has_memory ())
>  	continue;
> @@ -2491,7 +2545,7 @@ target_detach (inferior *inf, int from_tty)
>       target.  */
>    auto proc_target_ref = target_ops_ref::new_reference (inf->process_target ());
>  
> -  current_top_target ()->detach (inf, from_tty);
> +  current_inferior ()->top_target ()->detach (inf, from_tty);
>  
>    process_stratum_target *proc_target
>      = as_process_stratum_target (proc_target_ref.get ());
> @@ -2513,7 +2567,7 @@ target_disconnect (const char *args, int from_tty)
>       disconnecting.  */
>    remove_breakpoints ();
>  
> -  current_top_target ()->disconnect (args, from_tty);
> +  current_inferior ()->top_target ()->disconnect (args, from_tty);
>  }
>  
>  /* See target/target.h.  */
> @@ -2522,7 +2576,7 @@ ptid_t
>  target_wait (ptid_t ptid, struct target_waitstatus *status,
>  	     target_wait_flags options)
>  {
> -  target_ops *target = current_top_target ();
> +  target_ops *target = current_inferior ()->top_target ();
>  
>    if (!target->can_async_p ())
>      gdb_assert ((options & TARGET_WNOHANG) == 0);
> @@ -2544,7 +2598,7 @@ default_target_wait (struct target_ops *ops,
>  std::string
>  target_pid_to_str (ptid_t ptid)
>  {
> -  return current_top_target ()->pid_to_str (ptid);
> +  return current_inferior ()->top_target ()->pid_to_str (ptid);
>  }
>  
>  const char *
> @@ -2552,7 +2606,7 @@ target_thread_name (struct thread_info *info)
>  {
>    gdb_assert (info->inf == current_inferior ());
>  
> -  return current_top_target ()->thread_name (info);
> +  return current_inferior ()->top_target ()->thread_name (info);
>  }
>  
>  struct thread_info *
> @@ -2560,8 +2614,9 @@ target_thread_handle_to_thread_info (const gdb_byte *thread_handle,
>  				     int handle_len,
>  				     struct inferior *inf)
>  {
> -  return current_top_target ()->thread_handle_to_thread_info (thread_handle,
> -						     handle_len, inf);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->thread_handle_to_thread_info (thread_handle, handle_len, inf);
>  }
>  
>  /* See target.h.  */
> @@ -2569,7 +2624,9 @@ target_thread_handle_to_thread_info (const gdb_byte *thread_handle,
>  gdb::byte_vector
>  target_thread_info_to_thread_handle (struct thread_info *tip)
>  {
> -  return current_top_target ()->thread_info_to_thread_handle (tip);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->thread_info_to_thread_handle (tip);
>  }
>  
>  void
> @@ -2579,7 +2636,7 @@ target_resume (ptid_t ptid, int step, enum gdb_signal signal)
>  
>    target_dcache_invalidate ();
>  
> -  current_top_target ()->resume (ptid, step, signal);
> +  current_inferior ()->top_target ()->resume (ptid, step, signal);
>  
>    registers_changed_ptid (curr_target, ptid);
>    /* We only set the internal executing state here.  The user/frontend
> @@ -2600,7 +2657,7 @@ target_commit_resume (void)
>    if (defer_target_commit_resume)
>      return;
>  
> -  current_top_target ()->commit_resume ();
> +  current_inferior ()->top_target ()->commit_resume ();
>  }
>  
>  /* See target.h.  */
> @@ -2614,13 +2671,13 @@ make_scoped_defer_target_commit_resume ()
>  void
>  target_pass_signals (gdb::array_view<const unsigned char> pass_signals)
>  {
> -  current_top_target ()->pass_signals (pass_signals);
> +  current_inferior ()->top_target ()->pass_signals (pass_signals);
>  }
>  
>  void
>  target_program_signals (gdb::array_view<const unsigned char> program_signals)
>  {
> -  current_top_target ()->program_signals (program_signals);
> +  current_inferior ()->top_target ()->program_signals (program_signals);
>  }
>  
>  static bool
> @@ -2638,7 +2695,9 @@ default_follow_fork (struct target_ops *self, bool follow_child,
>  bool
>  target_follow_fork (bool follow_child, bool detach_fork)
>  {
> -  return current_top_target ()->follow_fork (follow_child, detach_fork);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->follow_fork (follow_child, detach_fork);
>  }
>  
>  /* Target wrapper for follow exec hook.  */
> @@ -2646,7 +2705,7 @@ target_follow_fork (bool follow_child, bool detach_fork)
>  void
>  target_follow_exec (struct inferior *inf, const char *execd_pathname)
>  {
> -  current_top_target ()->follow_exec (inf, execd_pathname);
> +  current_inferior ()->top_target ()->follow_exec (inf, execd_pathname);
>  }
>  
>  static void
> @@ -2660,7 +2719,7 @@ void
>  target_mourn_inferior (ptid_t ptid)
>  {
>    gdb_assert (ptid.pid () == inferior_ptid.pid ());
> -  current_top_target ()->mourn_inferior ();
> +  current_inferior ()->top_target ()->mourn_inferior ();
>  
>    /* We no longer need to keep handles on any of the object files.
>       Make sure to release them to avoid unnecessarily locking any
> @@ -2688,7 +2747,8 @@ default_search_memory (struct target_ops *self,
>  {
>    auto read_memory = [=] (CORE_ADDR addr, gdb_byte *result, size_t len)
>      {
> -      return target_read (current_top_target (), TARGET_OBJECT_MEMORY, NULL,
> +      return target_read (current_inferior ()->top_target (),
> +			  TARGET_OBJECT_MEMORY, NULL,
>  			  result, addr, len) == len;
>      };
>  
> @@ -2709,8 +2769,10 @@ target_search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
>  		      const gdb_byte *pattern, ULONGEST pattern_len,
>  		      CORE_ADDR *found_addrp)
>  {
> -  return current_top_target ()->search_memory (start_addr, search_space_len,
> -				      pattern, pattern_len, found_addrp);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->search_memory (start_addr, search_space_len, pattern,
> +				pattern_len, found_addrp);
>  }
>  
>  /* Look through the currently pushed targets.  If none of them will
> @@ -2720,7 +2782,9 @@ target_search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
>  void
>  target_require_runnable (void)
>  {
> -  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
> +  for (target_ops *t = current_inferior ()->top_target ();
> +       t != NULL;
> +       t = t->beneath ())
>      {
>        /* If this target knows how to create a new program, then
>  	 assume we will still be able to after killing the current
> @@ -2810,7 +2874,9 @@ struct target_ops *
>  find_attach_target (void)
>  {
>    /* If a target on the current stack can attach, use it.  */
> -  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
> +  for (target_ops *t = current_inferior ()->top_target ();
> +       t != NULL;
> +       t = t->beneath ())
>      {
>        if (t->can_attach ())
>  	return t;
> @@ -2826,7 +2892,9 @@ struct target_ops *
>  find_run_target (void)
>  {
>    /* If a target on the current stack can run, use it.  */
> -  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
> +  for (target_ops *t = current_inferior ()->top_target ();
> +       t != NULL;
> +       t = t->beneath ())
>      {
>        if (t->can_create_inferior ())
>  	return t;
> @@ -2885,7 +2953,7 @@ find_default_supports_disable_randomization (struct target_ops *self)
>  int
>  target_supports_disable_randomization (void)
>  {
> -  return current_top_target ()->supports_disable_randomization ();
> +  return current_inferior ()->top_target ()->supports_disable_randomization ();
>  }
>  
>  /* See target/target.h.  */
> @@ -2893,7 +2961,7 @@ target_supports_disable_randomization (void)
>  int
>  target_supports_multi_process (void)
>  {
> -  return current_top_target ()->supports_multi_process ();
> +  return current_inferior ()->top_target ()->supports_multi_process ();
>  }
>  
>  /* See target.h.  */
> @@ -2923,7 +2991,7 @@ target_thread_address_space (ptid_t ptid)
>  {
>    struct address_space *aspace;
>  
> -  aspace = current_top_target ()->thread_address_space (ptid);
> +  aspace = current_inferior ()->top_target ()->thread_address_space (ptid);
>    gdb_assert (aspace != NULL);
>  
>    return aspace;
> @@ -2976,7 +3044,9 @@ target_ops::can_run ()
>  int
>  target_can_run ()
>  {
> -  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
> +  for (target_ops *t = current_inferior ()->top_target ();
> +       t != NULL;
> +       t = t->beneath ())
>      {
>        if (t->can_run ())
>  	return 1;
> @@ -3659,13 +3729,13 @@ target_close (struct target_ops *targ)
>  int
>  target_thread_alive (ptid_t ptid)
>  {
> -  return current_top_target ()->thread_alive (ptid);
> +  return current_inferior ()->top_target ()->thread_alive (ptid);
>  }
>  
>  void
>  target_update_thread_list (void)
>  {
> -  current_top_target ()->update_thread_list ();
> +  current_inferior ()->top_target ()->update_thread_list ();
>  }
>  
>  void
> @@ -3677,7 +3747,7 @@ target_stop (ptid_t ptid)
>        return;
>      }
>  
> -  current_top_target ()->stop (ptid);
> +  current_inferior ()->top_target ()->stop (ptid);
>  }
>  
>  void
> @@ -3689,7 +3759,7 @@ target_interrupt ()
>        return;
>      }
>  
> -  current_top_target ()->interrupt ();
> +  current_inferior ()->top_target ()->interrupt ();
>  }
>  
>  /* See target.h.  */
> @@ -3719,7 +3789,7 @@ target_pass_ctrlc (void)
>  		 through the target_stack.  */
>  	      scoped_restore_current_inferior restore_inferior;
>  	      set_current_inferior (inf);
> -	      current_top_target ()->pass_ctrlc ();
> +	      current_inferior ()->top_target ()->pass_ctrlc ();
>  	      return;
>  	    }
>  	}
> @@ -3814,7 +3884,7 @@ target_options_to_string (target_wait_flags target_options)
>  void
>  target_fetch_registers (struct regcache *regcache, int regno)
>  {
> -  current_top_target ()->fetch_registers (regcache, regno);
> +  current_inferior ()->top_target ()->fetch_registers (regcache, regno);
>    if (targetdebug)
>      regcache->debug_print_register ("target_fetch_registers", regno);
>  }
> @@ -3825,7 +3895,7 @@ target_store_registers (struct regcache *regcache, int regno)
>    if (!may_write_registers)
>      error (_("Writing to registers is not allowed (regno %d)"), regno);
>  
> -  current_top_target ()->store_registers (regcache, regno);
> +  current_inferior ()->top_target ()->store_registers (regcache, regno);
>    if (targetdebug)
>      {
>        regcache->debug_print_register ("target_store_registers", regno);
> @@ -3835,7 +3905,7 @@ target_store_registers (struct regcache *regcache, int regno)
>  int
>  target_core_of_thread (ptid_t ptid)
>  {
> -  return current_top_target ()->core_of_thread (ptid);
> +  return current_inferior ()->top_target ()->core_of_thread (ptid);
>  }
>  
>  int
> @@ -3873,14 +3943,16 @@ default_verify_memory (struct target_ops *self,
>  		       const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
>  {
>    /* Start over from the top of the target stack.  */
> -  return simple_verify_memory (current_top_target (),
> +  return simple_verify_memory (current_inferior ()->top_target (),
>  			       data, memaddr, size);
>  }
>  
>  int
>  target_verify_memory (const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
>  {
> -  return current_top_target ()->verify_memory (data, memaddr, size);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->verify_memory (data, memaddr, size);
>  }
>  
>  /* The documentation for this function is in its prototype declaration in
> @@ -3890,7 +3962,9 @@ int
>  target_insert_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask,
>  			       enum target_hw_bp_type rw)
>  {
> -  return current_top_target ()->insert_mask_watchpoint (addr, mask, rw);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->insert_mask_watchpoint (addr, mask, rw);
>  }
>  
>  /* The documentation for this function is in its prototype declaration in
> @@ -3900,7 +3974,9 @@ int
>  target_remove_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask,
>  			       enum target_hw_bp_type rw)
>  {
> -  return current_top_target ()->remove_mask_watchpoint (addr, mask, rw);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->remove_mask_watchpoint (addr, mask, rw);
>  }
>  
>  /* The documentation for this function is in its prototype declaration
> @@ -3909,7 +3985,9 @@ target_remove_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask,
>  int
>  target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask)
>  {
> -  return current_top_target ()->masked_watch_num_registers (addr, mask);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->masked_watch_num_registers (addr, mask);
>  }
>  
>  /* The documentation for this function is in its prototype declaration
> @@ -3918,7 +3996,7 @@ target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask)
>  int
>  target_ranged_break_num_registers (void)
>  {
> -  return current_top_target ()->ranged_break_num_registers ();
> +  return current_inferior ()->top_target ()->ranged_break_num_registers ();
>  }
>  
>  /* See target.h.  */
> @@ -3926,7 +4004,7 @@ target_ranged_break_num_registers (void)
>  struct btrace_target_info *
>  target_enable_btrace (ptid_t ptid, const struct btrace_config *conf)
>  {
> -  return current_top_target ()->enable_btrace (ptid, conf);
> +  return current_inferior ()->top_target ()->enable_btrace (ptid, conf);
>  }
>  
>  /* See target.h.  */
> @@ -3934,7 +4012,7 @@ target_enable_btrace (ptid_t ptid, const struct btrace_config *conf)
>  void
>  target_disable_btrace (struct btrace_target_info *btinfo)
>  {
> -  current_top_target ()->disable_btrace (btinfo);
> +  current_inferior ()->top_target ()->disable_btrace (btinfo);
>  }
>  
>  /* See target.h.  */
> @@ -3942,7 +4020,7 @@ target_disable_btrace (struct btrace_target_info *btinfo)
>  void
>  target_teardown_btrace (struct btrace_target_info *btinfo)
>  {
> -  current_top_target ()->teardown_btrace (btinfo);
> +  current_inferior ()->top_target ()->teardown_btrace (btinfo);
>  }
>  
>  /* See target.h.  */
> @@ -3952,7 +4030,9 @@ target_read_btrace (struct btrace_data *btrace,
>  		    struct btrace_target_info *btinfo,
>  		    enum btrace_read_type type)
>  {
> -  return current_top_target ()->read_btrace (btrace, btinfo, type);
> +  target_ops *target = current_inferior ()->top_target ();
> +
> +  return target->read_btrace (btrace, btinfo, type);
>  }
>  
>  /* See target.h.  */
> @@ -3960,7 +4040,7 @@ target_read_btrace (struct btrace_data *btrace,
>  const struct btrace_config *
>  target_btrace_conf (const struct btrace_target_info *btinfo)
>  {
> -  return current_top_target ()->btrace_conf (btinfo);
> +  return current_inferior ()->top_target ()->btrace_conf (btinfo);
>  }
>  
>  /* See target.h.  */
> @@ -3968,7 +4048,7 @@ target_btrace_conf (const struct btrace_target_info *btinfo)
>  void
>  target_stop_recording (void)
>  {
> -  current_top_target ()->stop_recording ();
> +  current_inferior ()->top_target ()->stop_recording ();
>  }
>  
>  /* See target.h.  */
> @@ -3976,7 +4056,7 @@ target_stop_recording (void)
>  void
>  target_save_record (const char *filename)
>  {
> -  current_top_target ()->save_record (filename);
> +  current_inferior ()->top_target ()->save_record (filename);
>  }
>  
>  /* See target.h.  */
> @@ -3984,7 +4064,7 @@ target_save_record (const char *filename)
>  int
>  target_supports_delete_record ()
>  {
> -  return current_top_target ()->supports_delete_record ();
> +  return current_inferior ()->top_target ()->supports_delete_record ();
>  }
>  
>  /* See target.h.  */
> @@ -3992,7 +4072,7 @@ target_supports_delete_record ()
>  void
>  target_delete_record (void)
>  {
> -  current_top_target ()->delete_record ();
> +  current_inferior ()->top_target ()->delete_record ();
>  }
>  
>  /* See target.h.  */
> @@ -4000,7 +4080,7 @@ target_delete_record (void)
>  enum record_method
>  target_record_method (ptid_t ptid)
>  {
> -  return current_top_target ()->record_method (ptid);
> +  return current_inferior ()->top_target ()->record_method (ptid);
>  }
>  
>  /* See target.h.  */
> @@ -4008,7 +4088,7 @@ target_record_method (ptid_t ptid)
>  int
>  target_record_is_replaying (ptid_t ptid)
>  {
> -  return current_top_target ()->record_is_replaying (ptid);
> +  return current_inferior ()->top_target ()->record_is_replaying (ptid);
>  }
>  
>  /* See target.h.  */
> @@ -4016,7 +4096,7 @@ target_record_is_replaying (ptid_t ptid)
>  int
>  target_record_will_replay (ptid_t ptid, int dir)
>  {
> -  return current_top_target ()->record_will_replay (ptid, dir);
> +  return current_inferior ()->top_target ()->record_will_replay (ptid, dir);
>  }
>  
>  /* See target.h.  */
> @@ -4024,7 +4104,7 @@ target_record_will_replay (ptid_t ptid, int dir)
>  void
>  target_record_stop_replaying (void)
>  {
> -  current_top_target ()->record_stop_replaying ();
> +  current_inferior ()->top_target ()->record_stop_replaying ();
>  }
>  
>  /* See target.h.  */
> @@ -4032,7 +4112,7 @@ target_record_stop_replaying (void)
>  void
>  target_goto_record_begin (void)
>  {
> -  current_top_target ()->goto_record_begin ();
> +  current_inferior ()->top_target ()->goto_record_begin ();
>  }
>  
>  /* See target.h.  */
> @@ -4040,7 +4120,7 @@ target_goto_record_begin (void)
>  void
>  target_goto_record_end (void)
>  {
> -  current_top_target ()->goto_record_end ();
> +  current_inferior ()->top_target ()->goto_record_end ();
>  }
>  
>  /* See target.h.  */
> @@ -4048,7 +4128,7 @@ target_goto_record_end (void)
>  void
>  target_goto_record (ULONGEST insn)
>  {
> -  current_top_target ()->goto_record (insn);
> +  current_inferior ()->top_target ()->goto_record (insn);
>  }
>  
>  /* See target.h.  */
> @@ -4056,7 +4136,7 @@ target_goto_record (ULONGEST insn)
>  void
>  target_insn_history (int size, gdb_disassembly_flags flags)
>  {
> -  current_top_target ()->insn_history (size, flags);
> +  current_inferior ()->top_target ()->insn_history (size, flags);
>  }
>  
>  /* See target.h.  */
> @@ -4065,7 +4145,7 @@ void
>  target_insn_history_from (ULONGEST from, int size,
>  			  gdb_disassembly_flags flags)
>  {
> -  current_top_target ()->insn_history_from (from, size, flags);
> +  current_inferior ()->top_target ()->insn_history_from (from, size, flags);
>  }
>  
>  /* See target.h.  */
> @@ -4074,7 +4154,7 @@ void
>  target_insn_history_range (ULONGEST begin, ULONGEST end,
>  			   gdb_disassembly_flags flags)
>  {
> -  current_top_target ()->insn_history_range (begin, end, flags);
> +  current_inferior ()->top_target ()->insn_history_range (begin, end, flags);
>  }
>  
>  /* See target.h.  */
> @@ -4082,7 +4162,7 @@ target_insn_history_range (ULONGEST begin, ULONGEST end,
>  void
>  target_call_history (int size, record_print_flags flags)
>  {
> -  current_top_target ()->call_history (size, flags);
> +  current_inferior ()->top_target ()->call_history (size, flags);
>  }
>  
>  /* See target.h.  */
> @@ -4090,7 +4170,7 @@ target_call_history (int size, record_print_flags flags)
>  void
>  target_call_history_from (ULONGEST begin, int size, record_print_flags flags)
>  {
> -  current_top_target ()->call_history_from (begin, size, flags);
> +  current_inferior ()->top_target ()->call_history_from (begin, size, flags);
>  }
>  
>  /* See target.h.  */
> @@ -4098,7 +4178,7 @@ target_call_history_from (ULONGEST begin, int size, record_print_flags flags)
>  void
>  target_call_history_range (ULONGEST begin, ULONGEST end, record_print_flags flags)
>  {
> -  current_top_target ()->call_history_range (begin, end, flags);
> +  current_inferior ()->top_target ()->call_history_range (begin, end, flags);
>  }
>  
>  /* See target.h.  */
> @@ -4106,7 +4186,7 @@ target_call_history_range (ULONGEST begin, ULONGEST end, record_print_flags flag
>  const struct frame_unwind *
>  target_get_unwinder (void)
>  {
> -  return current_top_target ()->get_unwinder ();
> +  return current_inferior ()->top_target ()->get_unwinder ();
>  }
>  
>  /* See target.h.  */
> @@ -4114,7 +4194,7 @@ target_get_unwinder (void)
>  const struct frame_unwind *
>  target_get_tailcall_unwinder (void)
>  {
> -  return current_top_target ()->get_tailcall_unwinder ();
> +  return current_inferior ()->top_target ()->get_tailcall_unwinder ();
>  }
>  
>  /* See target.h.  */
> @@ -4122,7 +4202,7 @@ target_get_tailcall_unwinder (void)
>  void
>  target_prepare_to_generate_core (void)
>  {
> -  current_top_target ()->prepare_to_generate_core ();
> +  current_inferior ()->top_target ()->prepare_to_generate_core ();
>  }
>  
>  /* See target.h.  */
> @@ -4130,7 +4210,7 @@ target_prepare_to_generate_core (void)
>  void
>  target_done_generating_core (void)
>  {
> -  current_top_target ()->done_generating_core ();
> +  current_inferior ()->top_target ()->done_generating_core ();
>  }
>  
>  \f
> @@ -4198,7 +4278,9 @@ maintenance_print_target_stack (const char *cmd, int from_tty)
>  {
>    printf_filtered (_("The current target stack is:\n"));
>  
> -  for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ())
> +  for (target_ops *t = current_inferior ()->top_target ();
> +       t != NULL;
> +       t = t->beneath ())
>      {
>        if (t->stratum () == debug_stratum)
>  	continue;
> @@ -4212,7 +4294,7 @@ void
>  target_async (int enable)
>  {
>    infrun_async (enable);
> -  current_top_target ()->async (enable);
> +  current_inferior ()->top_target ()->async (enable);
>  }
>  
>  /* See target.h.  */
> @@ -4220,7 +4302,7 @@ target_async (int enable)
>  void
>  target_thread_events (int enable)
>  {
> -  current_top_target ()->thread_events (enable);
> +  current_inferior ()->top_target ()->thread_events (enable);
>  }
>  
>  /* Controls if targets can report that they can/are async.  This is
> @@ -4260,7 +4342,7 @@ maint_show_target_async_command (struct ui_file *file, int from_tty,
>  static int
>  target_always_non_stop_p (void)
>  {
> -  return current_top_target ()->always_non_stop_p ();
> +  return current_inferior ()->top_target ()->always_non_stop_p ();
>  }
>  
>  /* See target.h.  */
> diff --git a/gdb/target.h b/gdb/target.h
> index 8b223c0283f..39dc10a7446 100644
> --- a/gdb/target.h
> +++ b/gdb/target.h
> @@ -1353,11 +1353,6 @@ class target_stack
>    target_ops *m_stack[(int) debug_stratum + 1] {};
>  };
>  
> -/* The ops structure for our "current" target process.  This should
> -   never be NULL.  If there is no target, it points to the dummy_target.  */
> -
> -extern target_ops *current_top_target ();
> -
>  /* Return the dummy target.  */
>  extern target_ops *get_dummy_target ();
>  
> diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
> index d82cac8d9dd..33ce86bbe23 100644
> --- a/gdb/tracefile-tfile.c
> +++ b/gdb/tracefile-tfile.c
> @@ -310,7 +310,7 @@ tfile_write_tdesc (struct trace_file_writer *self)
>      = (struct tfile_trace_file_writer *) self;
>  
>    gdb::optional<std::string> tdesc
> -    = target_fetch_description_xml (current_top_target ());
> +    = target_fetch_description_xml (current_inferior ()->top_target ());
>  
>    if (!tdesc)
>      return;
> diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
> index bf8a63c5966..48d72d6a1f2 100644
> --- a/gdb/tracepoint.c
> +++ b/gdb/tracepoint.c
> @@ -3812,7 +3812,8 @@ sdata_make_value (struct gdbarch *gdbarch, struct internalvar *var,
>  {
>    /* We need to read the whole object before we know its size.  */
>    gdb::optional<gdb::byte_vector> buf
> -    = target_read_alloc (current_top_target (), TARGET_OBJECT_STATIC_TRACE_DATA,
> +    = target_read_alloc (current_inferior ()->top_target (),
> +			 TARGET_OBJECT_STATIC_TRACE_DATA,
>  			 NULL);
>    if (buf)
>      {
> diff --git a/gdb/valops.c b/gdb/valops.c
> index fec821ad932..f86c9818058 100644
> --- a/gdb/valops.c
> +++ b/gdb/valops.c
> @@ -1040,7 +1040,7 @@ read_value_memory (struct value *val, LONGEST bit_offset,
>        enum target_xfer_status status;
>        ULONGEST xfered_partial;
>  
> -      status = target_xfer_partial (current_top_target (),
> +      status = target_xfer_partial (current_inferior ()->top_target (),
>  				    object, NULL,
>  				    buffer + xfered_total * unit_size, NULL,
>  				    memaddr + xfered_total,
> @@ -1286,7 +1286,8 @@ value_assign (struct value *toval, struct value *fromval)
>      case lval_register:
>      case lval_computed:
>  
> -      gdb::observers::target_changed.notify (current_top_target ());
> +      gdb::observers::target_changed.notify
> +	(current_inferior ()->top_target ());
>  
>        /* Having destroyed the frame cache, restore the selected
>  	 frame.  */
> diff --git a/gdb/valprint.c b/gdb/valprint.c
> index 340a329f9d0..56a9306dcc1 100644
> --- a/gdb/valprint.c
> +++ b/gdb/valprint.c
> @@ -42,6 +42,7 @@
>  #include "count-one-bits.h"
>  #include "c-lang.h"
>  #include "cp-abi.h"
> +#include "inferior.h"
>  
>  /* Maximum number of wchars returned from wchar_iterate.  */
>  #define MAX_WCHARS 4
> @@ -1836,9 +1837,8 @@ print_function_pointer_address (const struct value_print_options *options,
>  				CORE_ADDR address,
>  				struct ui_file *stream)
>  {
> -  CORE_ADDR func_addr
> -    = gdbarch_convert_from_func_ptr_addr (gdbarch, address,
> -					  current_top_target ());
> +  CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr
> +    (gdbarch, address, current_inferior ()->top_target ());
>  
>    /* If the function pointer is represented by a description, print
>       the address of the description.  */
> diff --git a/gdb/value.c b/gdb/value.c
> index 9527186f57a..3bd81e76007 100644
> --- a/gdb/value.c
> +++ b/gdb/value.c
> @@ -45,6 +45,7 @@
>  #include "gdbsupport/array-view.h"
>  #include "cli/cli-style.h"
>  #include "expop.h"
> +#include "inferior.h"
>  
>  /* Definition of a user function.  */
>  struct internal_function
> @@ -3159,7 +3160,8 @@ value_fn_field (struct value **arg1p, struct fn_field *f,
>  
>        set_value_address (v,
>  	gdbarch_convert_from_func_ptr_addr
> -	   (gdbarch, BMSYMBOL_VALUE_ADDRESS (msym), current_top_target ()));
> +	   (gdbarch, BMSYMBOL_VALUE_ADDRESS (msym),
> +	    current_inferior ()->top_target ()));
>      }
>  
>    if (arg1p)
> diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
> index a06b44822d4..97aa3da6e77 100644
> --- a/gdb/windows-tdep.c
> +++ b/gdb/windows-tdep.c
> @@ -487,7 +487,7 @@ display_one_tib (ptid_t ptid)
>        return -1;
>      }
>  
> -  if (target_read (current_top_target (), TARGET_OBJECT_MEMORY,
> +  if (target_read (current_inferior ()->top_target (), TARGET_OBJECT_MEMORY,
>  		   NULL, tib, thread_local_base, tib_size) != tib_size)
>      {
>        printf_filtered (_("Unable to read thread information "
> -- 
> 2.30.0
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] gdb: move all "current target" wrapper implementations to target.c
  2021-03-24  9:29 ` [PATCH 1/2] gdb: move all "current target" wrapper implementations to target.c Andrew Burgess
@ 2021-03-24 14:04   ` Simon Marchi
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-03-24 14:04 UTC (permalink / raw)
  To: Andrew Burgess, Simon Marchi; +Cc: gdb-patches

>> diff --git a/gdb/target.c b/gdb/target.c
>> index afc4b2cbbb6..e7af5e8a9b0 100644
>> --- a/gdb/target.c
>> +++ b/gdb/target.c
>> @@ -215,6 +215,564 @@ target_has_execution (inferior *inf)
>>    return false;
>>  }
>>  
>> +const char *
>> +target_shortname ()
> 
> There are a few of the functions here missing a header comment.

As a general rule, I don't put the /* See header.h.  */ comment if the
declaration in header.h doesn't have a comment.  Otherwise, that's
meaningless.  Of course, all declarations should have a comment, but
it's not in the scope of this patch to add them.

target_shortname has a comment above it but... it doesn't really
describe what it does...

Simon

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] gdb: remove current_top_target function
  2021-03-24 11:02   ` Andrew Burgess
@ 2021-03-24 22:11     ` Simon Marchi
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-03-24 22:11 UTC (permalink / raw)
  To: Andrew Burgess, Simon Marchi; +Cc: gdb-patches

On 2021-03-24 7:02 a.m., Andrew Burgess wrote:
> * Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2021-03-23 14:41:38 -0400]:
> 
>> From: Simon Marchi <simon.marchi@polymtl.ca>
>>
>> The current_top_target function is a hidden dependency on the current
>> inferior.  Since I'd like to slowly move towards reducing our dependency
>> on the global current state, remove this function and make callers use
>>
>>   current_inferior ()->top_target ()
>>
>> There is no expected change in behavior, but this one step towards
>> making those callers use the inferior from their context, rather than
>> refer to the global current inferior.
> 
> LGTM.
> 
> Thanks,
> Andrew

Thanks, I pushed both patches.

Simon

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-24 22:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 18:41 [PATCH 1/2] gdb: move all "current target" wrapper implementations to target.c Simon Marchi
2021-03-23 18:41 ` [PATCH 2/2] gdb: remove current_top_target function Simon Marchi
2021-03-24 11:02   ` Andrew Burgess
2021-03-24 22:11     ` Simon Marchi
2021-03-24  9:29 ` [PATCH 1/2] gdb: move all "current target" wrapper implementations to target.c Andrew Burgess
2021-03-24 14:04   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).