gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / target.h
index f78eb459dc1178ec91ee2db64f2e4226b73f215f..f2bb55e4bdd28675e76973c4863960ece269dd54 100644 (file)
@@ -1,6 +1,6 @@
 /* Interface between GDB and target environments, including files and processes
 
-   Copyright (C) 1990-2018 Free Software Foundation, Inc.
+   Copyright (C) 1990-2020 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.  Written by John Gilmore.
 
@@ -42,7 +42,8 @@ struct inferior;
 
 #include "infrun.h" /* For enum exec_direction_kind.  */
 #include "breakpoint.h" /* For enum bptype.  */
-#include "common/scoped_restore.h"
+#include "gdbsupport/scoped_restore.h"
+#include "gdbsupport/refcounted-object.h"
 
 /* This include file defines the interface between the main part
    of the debugger, and the part which is target-specific, or
@@ -61,7 +62,11 @@ struct inferior;
    of variables any more (the file target is handling them and they
    never get to the process target).  So when you push a file target,
    it goes into the file stratum, which is always below the process
-   stratum.  */
+   stratum.
+
+   Note that rather than allow an empty stack, we always have the
+   dummy target at the bottom stratum, so we can call the target
+   methods without checking them.  */
 
 #include "target/target.h"
 #include "target/resume.h"
@@ -70,15 +75,15 @@ struct inferior;
 #include "bfd.h"
 #include "symtab.h"
 #include "memattr.h"
-#include "vec.h"
-#include "gdb_signals.h"
+#include "gdbsupport/gdb_signals.h"
 #include "btrace.h"
 #include "record.h"
 #include "command.h"
 #include "disasm.h"
 #include "tracepoint.h"
+#include "displaced-stepping.h"
 
-#include "break-common.h" /* For enum target_hw_bp_type.  */
+#include "gdbsupport/break-common.h" /* For enum target_hw_bp_type.  */
 
 enum strata
   {
@@ -112,9 +117,8 @@ struct syscall
     const char *name;
   };
 
-/* Return a pretty printed form of TARGET_OPTIONS.
-   Space for the result is malloc'd, caller must free.  */
-extern char *target_options_to_string (int target_options);
+/* Return a pretty printed form of TARGET_OPTIONS.  */
+extern std::string target_options_to_string (int target_options);
 
 /* Possible types of events that the inferior handler will have to
    deal with.  */
@@ -134,8 +138,6 @@ enum target_object
 {
   /* AVR target specific transfer.  See "avr-tdep.c" and "remote.c".  */
   TARGET_OBJECT_AVR,
-  /* SPU target specific transfer.  See "spu-tdep.c".  */
-  TARGET_OBJECT_SPU,
   /* Transfer up-to LEN bytes of memory starting at OFFSET.  */
   TARGET_OBJECT_MEMORY,
   /* Memory, avoiding GDB's data cache and trusting the executable.
@@ -199,6 +201,10 @@ enum target_object
      of the process ID of the process in question, in hexadecimal
      format.  */
   TARGET_OBJECT_EXEC_FILE,
+  /* FreeBSD virtual memory mappings.  */
+  TARGET_OBJECT_FREEBSD_VMMAP,
+  /* FreeBSD process strings.  */
+  TARGET_OBJECT_FREEBSD_PS_STRINGS,
   /* Possible future objects: TARGET_OBJECT_FILE, ...  */
 };
 
@@ -404,27 +410,49 @@ typedef void async_callback_ftype (enum inferior_event_type event_type,
 #define TARGET_DEFAULT_RETURN(ARG)
 #define TARGET_DEFAULT_FUNC(ARG)
 
+/* Each target that can be activated with "target TARGET_NAME" passes
+   the address of one of these objects to add_target, which uses the
+   object's address as unique identifier, and registers the "target
+   TARGET_NAME" command using SHORTNAME as target name.  */
+
+struct target_info
+{
+  /* Name of this target.  */
+  const char *shortname;
+
+  /* Name for printing.  */
+  const char *longname;
+
+  /* Documentation.  Does not include trailing newline, and starts
+     with a one-line description (probably similar to longname).  */
+  const char *doc;
+};
+
 struct target_ops
+  : public refcounted_object
   {
-    struct target_ops *beneath;        /* To the target under this one.  */
+    /* Return this target's stratum.  */
+    virtual strata stratum () const = 0;
 
-    virtual ~target_ops () {}
+    /* To the target under this one.  */
+    target_ops *beneath () const;
 
-    /* Name this target type.  */
-    virtual const char *shortname () = 0;
+    /* Free resources associated with the target.  Note that singleton
+       targets, like e.g., native targets, are global objects, not
+       heap allocated, and are thus only deleted on GDB exit.  The
+       main teardown entry point is the "close" method, below.  */
+    virtual ~target_ops () {}
 
-    /* Name for printing.  */
-    virtual const char *longname () = 0;
+    /* Return a reference to this target's unique target_info
+       object.  */
+    virtual const target_info &info () const = 0;
 
-    /* Documentation.  Does not include trailing newline, and starts
-       ith a one-line description (probably similar to longname).  */
-    virtual const char *doc () = 0;
+    /* Name this target type.  */
+    const char *shortname () const
+    { return info ().shortname; }
 
-    /* The open routine takes the rest of the parameters from the
-       command, and (if successful) pushes a new target onto the
-       stack.  Targets should supply this routine, if only to provide
-       an error message.  */
-    virtual void open (const char *, int);
+    const char *longname () const
+    { return info ().longname; }
 
     /* Close the target.  This is where the target can handle
        teardown.  Heap-allocated targets should delete themselves
@@ -453,6 +481,13 @@ struct target_ops
       TARGET_DEFAULT_NORETURN (noprocess ());
     virtual void commit_resume ()
       TARGET_DEFAULT_IGNORE ();
+    /* See target_wait's description.  Note that implementations of
+       this method must not assume that inferior_ptid on entry is
+       pointing at the thread or inferior that ends up reporting an
+       event.  The reported event could be for some other thread in
+       the current inferior or even for a different process of the
+       current target.  inferior_ptid may also be null_ptid on
+       entry.  */
     virtual ptid_t wait (ptid_t, struct target_waitstatus *,
                         int TARGET_DEBUG_PRINTER (target_debug_print_options))
       TARGET_DEFAULT_FUNC (default_target_wait);
@@ -482,11 +517,11 @@ struct target_ops
        done from the target, so GDB needs to be able to tell whether
        it should ignore the event and whether it should adjust the PC.
        See adjust_pc_after_break.  */
-    virtual int stopped_by_sw_breakpoint ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool stopped_by_sw_breakpoint ()
+      TARGET_DEFAULT_RETURN (false);
     /* Returns true if the above method is supported.  */
-    virtual int supports_stopped_by_sw_breakpoint ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool supports_stopped_by_sw_breakpoint ()
+      TARGET_DEFAULT_RETURN (false);
 
     /* Returns true if the target stopped for a hardware breakpoint.
        Likewise, if the target supports hardware breakpoints, this
@@ -495,11 +530,11 @@ struct target_ops
        require PC adjustment, GDB needs to be able to tell whether the
        hardware breakpoint event is a delayed event for a breakpoint
        that is already gone and should thus be ignored.  */
-    virtual int stopped_by_hw_breakpoint ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool stopped_by_hw_breakpoint ()
+      TARGET_DEFAULT_RETURN (false);
     /* Returns true if the above method is supported.  */
-    virtual int supports_stopped_by_hw_breakpoint ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool supports_stopped_by_hw_breakpoint ()
+      TARGET_DEFAULT_RETURN (false);
 
     virtual int can_use_hw_breakpoint (enum bptype, int, int)
       TARGET_DEFAULT_RETURN (0);
@@ -527,15 +562,13 @@ struct target_ops
     virtual int remove_mask_watchpoint (CORE_ADDR, CORE_ADDR,
                                        enum target_hw_bp_type)
       TARGET_DEFAULT_RETURN (1);
-    virtual int stopped_by_watchpoint ()
-      TARGET_DEFAULT_RETURN (0);
-    virtual int have_steppable_watchpoint ()
-      TARGET_DEFAULT_RETURN (0);
-    virtual bool have_continuable_watchpoint ()
-      TARGET_DEFAULT_RETURN (0);
-    virtual int stopped_data_address (CORE_ADDR *)
-      TARGET_DEFAULT_RETURN (0);
-    virtual int watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int)
+    virtual bool stopped_by_watchpoint ()
+      TARGET_DEFAULT_RETURN (false);
+    virtual bool have_steppable_watchpoint ()
+      TARGET_DEFAULT_RETURN (false);
+    virtual bool stopped_data_address (CORE_ADDR *)
+      TARGET_DEFAULT_RETURN (false);
+    virtual bool watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int)
       TARGET_DEFAULT_FUNC (default_watchpoint_addr_within_range);
 
     /* Documentation of this routine is provided with the corresponding
@@ -543,9 +576,9 @@ struct target_ops
     virtual int region_ok_for_hw_watchpoint (CORE_ADDR, int)
       TARGET_DEFAULT_FUNC (default_region_ok_for_hw_watchpoint);
 
-    virtual int can_accel_watchpoint_condition (CORE_ADDR, int, int,
-                                               struct expression *)
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool can_accel_watchpoint_condition (CORE_ADDR, int, int,
+                                                struct expression *)
+      TARGET_DEFAULT_RETURN (false);
     virtual int masked_watch_num_registers (CORE_ADDR, CORE_ADDR)
       TARGET_DEFAULT_RETURN (-1);
 
@@ -555,7 +588,7 @@ struct target_ops
       TARGET_DEFAULT_RETURN (-1);
 
     virtual bool supports_terminal_ours ()
-      TARGET_DEFAULT_RETURN (0);
+      TARGET_DEFAULT_RETURN (false);
     virtual void terminal_init ()
       TARGET_DEFAULT_IGNORE ();
     virtual void terminal_inferior ()
@@ -590,13 +623,13 @@ struct target_ops
       TARGET_DEFAULT_RETURN (1);
     virtual int remove_vfork_catchpoint (int)
       TARGET_DEFAULT_RETURN (1);
-    virtual int follow_fork (int, int)
+    virtual bool follow_fork (bool, bool)
       TARGET_DEFAULT_FUNC (default_follow_fork);
     virtual int insert_exec_catchpoint (int)
       TARGET_DEFAULT_RETURN (1);
     virtual int remove_exec_catchpoint (int)
       TARGET_DEFAULT_RETURN (1);
-    virtual void follow_exec (struct inferior *, char *)
+    virtual void follow_exec (struct inferior *, const char *)
       TARGET_DEFAULT_IGNORE ();
     virtual int set_syscall_catchpoint (int, bool, int,
                                        gdb::array_view<const int>)
@@ -607,25 +640,23 @@ struct target_ops
     /* Note that can_run is special and can be invoked on an unpushed
        target.  Targets defining this method must also define
        to_can_async_p and to_supports_non_stop.  */
-    virtual int can_run ();
+    virtual bool can_run ();
 
     /* Documentation of this routine is provided with the corresponding
        target_* macro.  */
-    virtual void pass_signals (int,
-                              unsigned char * TARGET_DEBUG_PRINTER (target_debug_print_signals))
+    virtual void pass_signals (gdb::array_view<const unsigned char> TARGET_DEBUG_PRINTER (target_debug_print_signals))
       TARGET_DEFAULT_IGNORE ();
 
     /* Documentation of this routine is provided with the
        corresponding target_* function.  */
-    virtual void program_signals (int,
-                                 unsigned char * TARGET_DEBUG_PRINTER (target_debug_print_signals))
+    virtual void program_signals (gdb::array_view<const unsigned char> TARGET_DEBUG_PRINTER (target_debug_print_signals))
       TARGET_DEFAULT_IGNORE ();
 
-    virtual int thread_alive (ptid_t ptid)
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool thread_alive (ptid_t ptid)
+      TARGET_DEFAULT_RETURN (false);
     virtual void update_thread_list ()
       TARGET_DEFAULT_IGNORE ();
-    virtual const char *pid_to_str (ptid_t)
+    virtual std::string pid_to_str (ptid_t)
       TARGET_DEFAULT_FUNC (default_pid_to_str);
     virtual const char *extra_thread_info (thread_info *)
       TARGET_DEFAULT_RETURN (NULL);
@@ -635,6 +666,9 @@ struct target_ops
                                                       int,
                                                       inferior *inf)
       TARGET_DEFAULT_RETURN (NULL);
+    /* See target_thread_info_to_thread_handle.  */
+    virtual gdb::byte_vector thread_info_to_thread_handle (struct thread_info *)
+      TARGET_DEFAULT_RETURN (gdb::byte_vector ());
     virtual void stop (ptid_t)
       TARGET_DEFAULT_IGNORE ();
     virtual void interrupt ()
@@ -649,14 +683,13 @@ struct target_ops
       TARGET_DEFAULT_IGNORE ();
     virtual struct target_section_table *get_section_table ()
       TARGET_DEFAULT_RETURN (NULL);
-    enum strata to_stratum;
 
     /* Provide default values for all "must have" methods.  */
-    virtual int has_all_memory () { return 0; }
-    virtual int has_memory () { return 0; }
-    virtual int has_stack () { return 0; }
-    virtual int has_registers () { return 0; }
-    virtual int has_execution (ptid_t) { return 0; }
+    virtual bool has_all_memory () { return false; }
+    virtual bool has_memory () { return false; }
+    virtual bool has_stack () { return false; }
+    virtual bool has_registers () { return false; }
+    virtual bool has_execution (inferior *inf) { return false; }
 
     /* Control thread execution.  */
     virtual thread_control_capabilities get_thread_control_capabilities ()
@@ -665,22 +698,24 @@ struct target_ops
       TARGET_DEFAULT_RETURN (0);
     /* This method must be implemented in some situations.  See the
        comment on 'can_run'.  */
-    virtual int can_async_p ()
-      TARGET_DEFAULT_RETURN (0);
-    virtual int is_async_p ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool can_async_p ()
+      TARGET_DEFAULT_RETURN (false);
+    virtual bool is_async_p ()
+      TARGET_DEFAULT_RETURN (false);
     virtual void async (int)
       TARGET_DEFAULT_NORETURN (tcomplain ());
+    virtual int async_wait_fd ()
+      TARGET_DEFAULT_NORETURN (noprocess ());
     virtual void thread_events (int)
       TARGET_DEFAULT_IGNORE ();
     /* This method must be implemented in some situations.  See the
        comment on 'can_run'.  */
-    virtual int supports_non_stop ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool supports_non_stop ()
+      TARGET_DEFAULT_RETURN (false);
     /* Return true if the target operates in non-stop mode even with
        "set non-stop off".  */
-    virtual int always_non_stop_p ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool always_non_stop_p ()
+      TARGET_DEFAULT_RETURN (false);
     /* find_memory_regions support method for gcore */
     virtual int find_memory_regions (find_memory_region_ftype func, void *data)
       TARGET_DEFAULT_FUNC (dummy_find_memory_regions);
@@ -695,9 +730,9 @@ struct target_ops
       TARGET_DEFAULT_NORETURN (tcomplain ());
     /* Return the thread-local address at OFFSET in the
        thread-local storage for the thread PTID and the shared library
-       or executable file given by OBJFILE.  If that block of
+       or executable file given by LOAD_MODULE_ADDR.  If that block of
        thread-local storage hasn't been allocated yet, this function
-       may return an error.  LOAD_MODULE_ADDR may be zero for statically
+       may throw an error.  LOAD_MODULE_ADDR may be zero for statically
        linked multithreaded inferiors.  */
     virtual CORE_ADDR get_thread_local_address (ptid_t ptid,
                                                CORE_ADDR load_module_addr,
@@ -815,8 +850,8 @@ struct target_ops
       TARGET_DEFAULT_FUNC (default_search_memory);
 
     /* Can target execute in reverse?  */
-    virtual int can_execute_reverse ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool can_execute_reverse ()
+      TARGET_DEFAULT_RETURN (false);
 
     /* The direction the target is currently executing.  Must be
        implemented on targets that support reverse execution and async
@@ -826,58 +861,52 @@ struct target_ops
 
     /* Does this target support debugging multiple processes
        simultaneously?  */
-    virtual int supports_multi_process ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool supports_multi_process ()
+      TARGET_DEFAULT_RETURN (false);
 
     /* Does this target support enabling and disabling tracepoints while a trace
        experiment is running?  */
-    virtual int supports_enable_disable_tracepoint ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool supports_enable_disable_tracepoint ()
+      TARGET_DEFAULT_RETURN (false);
 
     /* Does this target support disabling address space randomization?  */
-    virtual int supports_disable_randomization ()
+    virtual bool supports_disable_randomization ()
       TARGET_DEFAULT_FUNC (find_default_supports_disable_randomization);
 
     /* Does this target support the tracenz bytecode for string collection?  */
-    virtual int supports_string_tracing ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool supports_string_tracing ()
+      TARGET_DEFAULT_RETURN (false);
 
     /* Does this target support evaluation of breakpoint conditions on its
        end?  */
-    virtual int supports_evaluation_of_breakpoint_conditions ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool supports_evaluation_of_breakpoint_conditions ()
+      TARGET_DEFAULT_RETURN (false);
 
     /* Does this target support evaluation of breakpoint commands on its
        end?  */
-    virtual int can_run_breakpoint_commands ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool can_run_breakpoint_commands ()
+      TARGET_DEFAULT_RETURN (false);
 
     /* Determine current architecture of thread PTID.
 
        The target is supposed to determine the architecture of the code where
-       the target is currently stopped at (on Cell, if a target is in spu_run,
-       to_thread_architecture would return SPU, otherwise PPC32 or PPC64).
-       This is architecture used to perform decr_pc_after_break adjustment,
-       and also determines the frame architecture of the innermost frame.
-       ptrace operations need to operate according to target_gdbarch ().
-
-       The default implementation always returns target_gdbarch ().  */
+       the target is currently stopped at.  The architecture information is
+       used to perform decr_pc_after_break adjustment, and also to determine
+       the frame architecture of the innermost frame.  ptrace operations need to
+       operate according to target_gdbarch ().  */
     virtual struct gdbarch *thread_architecture (ptid_t)
-      TARGET_DEFAULT_FUNC (default_thread_architecture);
-
-    /* Determine current address space of thread PTID.
+      TARGET_DEFAULT_RETURN (NULL);
 
-       The default implementation always returns the inferior's
-       address space.  */
+    /* Determine current address space of thread PTID.  */
     virtual struct address_space *thread_address_space (ptid_t)
-      TARGET_DEFAULT_FUNC (default_thread_address_space);
+      TARGET_DEFAULT_RETURN (NULL);
 
     /* Target file operations.  */
 
     /* Return nonzero if the filesystem seen by the current inferior
        is the local filesystem, zero otherwise.  */
-    virtual int filesystem_is_local ()
-      TARGET_DEFAULT_RETURN (1);
+    virtual bool filesystem_is_local ()
+      TARGET_DEFAULT_RETURN (true);
 
     /* Open FILENAME on the target, in the filesystem as seen by INF,
        using FLAGS and MODE.  If INF is NULL, use the filesystem seen
@@ -944,8 +973,8 @@ struct target_ops
 
     /* Is the target able to download tracepoint locations in current
        state?  */
-    virtual int can_download_tracepoint ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool can_download_tracepoint ()
+      TARGET_DEFAULT_RETURN (false);
 
     /* Send full details of a trace state variable to the target.  */
     virtual void download_trace_state_variable (const trace_state_variable &tsv)
@@ -993,8 +1022,8 @@ struct target_ops
     /* Get the value of the trace state variable number TSV, returning
        1 if the value is known and writing the value itself into the
        location pointed to by VAL, else returning 0.  */
-    virtual int get_trace_state_variable_value (int tsv, LONGEST *val)
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool get_trace_state_variable_value (int tsv, LONGEST *val)
+      TARGET_DEFAULT_RETURN (false);
 
     virtual int save_trace_data (const char *filename)
       TARGET_DEFAULT_NORETURN (tcomplain ());
@@ -1028,9 +1057,9 @@ struct target_ops
 
     /* Add/change textual notes about the trace run, returning 1 if
        successful, 0 otherwise.  */
-    virtual int set_trace_notes (const char *user, const char *notes,
-                                const char *stopnotes)
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool set_trace_notes (const char *user, const char *notes,
+                                 const char *stopnotes)
+      TARGET_DEFAULT_RETURN (false);
 
     /* Return the processor core that thread PTID was last seen on.
        This information is updated only when:
@@ -1052,7 +1081,7 @@ struct target_ops
 
     /* Return the address of the start of the Thread Information Block
        a Windows OS specific feature.  */
-    virtual int get_tib_address (ptid_t ptid, CORE_ADDR *addr)
+    virtual bool get_tib_address (ptid_t ptid, CORE_ADDR *addr)
       TARGET_DEFAULT_NORETURN (tcomplain ());
 
     /* Send the new settings of write permission variables.  */
@@ -1078,14 +1107,14 @@ struct target_ops
     virtual traceframe_info_up traceframe_info ()
       TARGET_DEFAULT_NORETURN (tcomplain ());
 
-    /* Ask the target to use or not to use agent according to USE.  Return 1
-       successful, 0 otherwise.  */
-    virtual int use_agent (int use)
+    /* Ask the target to use or not to use agent according to USE.
+       Return true if successful, false otherwise.  */
+    virtual bool use_agent (bool use)
       TARGET_DEFAULT_NORETURN (tcomplain ());
 
     /* Is the target able to use agent in current state?  */
-    virtual int can_use_agent ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool can_use_agent ()
+      TARGET_DEFAULT_RETURN (false);
 
     /* Enable branch tracing for PTID using CONF configuration.
        Return a branch trace target information struct for reading and for
@@ -1140,13 +1169,13 @@ struct target_ops
       TARGET_DEFAULT_NORETURN (tcomplain ());
 
     /* Query if the record target is currently replaying PTID.  */
-    virtual int record_is_replaying (ptid_t ptid)
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool record_is_replaying (ptid_t ptid)
+      TARGET_DEFAULT_RETURN (false);
 
     /* Query if the record target will replay PTID if it were resumed in
        execution direction DIR.  */
-    virtual int record_will_replay (ptid_t ptid, int dir)
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool record_will_replay (ptid_t ptid, int dir)
+      TARGET_DEFAULT_RETURN (false);
 
     /* Stop replaying.  */
     virtual void record_stop_replaying ()
@@ -1203,10 +1232,10 @@ struct target_ops
     virtual void call_history_range (ULONGEST begin, ULONGEST end, record_print_flags flags)
       TARGET_DEFAULT_NORETURN (tcomplain ());
 
-    /* Nonzero if TARGET_OBJECT_LIBRARIES_SVR4 may be read with a
+    /* True if TARGET_OBJECT_LIBRARIES_SVR4 may be read with a
        non-empty annex.  */
-    virtual int augmented_libraries_svr4_read ()
-      TARGET_DEFAULT_RETURN (0);
+    virtual bool augmented_libraries_svr4_read ()
+      TARGET_DEFAULT_RETURN (false);
 
     /* Those unwinders are tried before any other arch unwinders.  If
        SELF doesn't have unwinders, it should delegate to the
@@ -1224,17 +1253,113 @@ struct target_ops
     /* Cleanup after generating a core file.  */
     virtual void done_generating_core ()
       TARGET_DEFAULT_IGNORE ();
+
+    virtual bool supports_displaced_step (thread_info *thread)
+      TARGET_DEFAULT_FUNC (default_supports_displaced_step);
+
+    virtual displaced_step_prepare_status displaced_step_prepare (thread_info *thread)
+      TARGET_DEFAULT_FUNC (default_displaced_step_prepare);
+
+    virtual displaced_step_finish_status displaced_step_finish (thread_info *thread, gdb_signal sig)
+      TARGET_DEFAULT_FUNC (default_displaced_step_finish);
   };
 
+/* Deleter for std::unique_ptr.  See comments in
+   target_ops::~target_ops and target_ops::close about heap-allocated
+   targets.  */
+struct target_ops_deleter
+{
+  void operator() (target_ops *target)
+  {
+    target->close ();
+  }
+};
+
+/* A unique pointer for target_ops.  */
+typedef std::unique_ptr<target_ops, target_ops_deleter> target_ops_up;
+
+/* Decref a target and close if, if there are no references left.  */
+extern void decref_target (target_ops *t);
+
+/* A policy class to interface gdb::ref_ptr with target_ops.  */
+
+struct target_ops_ref_policy
+{
+  static void incref (target_ops *t)
+  {
+    t->incref ();
+  }
+
+  static void decref (target_ops *t)
+  {
+    decref_target (t);
+  }
+};
+
+/* A gdb::ref_ptr pointer to a target_ops.  */
+typedef gdb::ref_ptr<target_ops, target_ops_ref_policy> target_ops_ref;
+
+/* Native target backends call this once at initialization time to
+   inform the core about which is the target that can respond to "run"
+   or "attach".  Note: native targets are always singletons.  */
+extern void set_native_target (target_ops *target);
+
+/* Get the registered native target, if there's one.  Otherwise return
+   NULL.  */
+extern target_ops *get_native_target ();
+
+/* Type that manages a target stack.  See description of target stacks
+   and strata at the top of the file.  */
+
+class target_stack
+{
+public:
+  target_stack () = default;
+  DISABLE_COPY_AND_ASSIGN (target_stack);
+
+  /* Push a new target into the stack of the existing target
+     accessors, possibly superseding some existing accessor.  */
+  void push (target_ops *t);
+
+  /* Remove a target from the stack, wherever it may be.  Return true
+     if it was removed, false otherwise.  */
+  bool unpush (target_ops *t);
+
+  /* Returns true if T is pushed on the target stack.  */
+  bool is_pushed (target_ops *t) const
+  { return at (t->stratum ()) == t; }
+
+  /* Return the target at STRATUM.  */
+  target_ops *at (strata stratum) const { return m_stack[stratum]; }
+
+  /* Return the target at the top of the stack.  */
+  target_ops *top () const { return at (m_top); }
+
+  /* Find the next target down the stack from the specified target.  */
+  target_ops *find_beneath (const target_ops *t) const;
+
+private:
+  /* The stratum of the top target.  */
+  enum strata m_top {};
+
+  /* The stack, represented as an array, with one slot per stratum.
+     If no target is pushed at some stratum, the corresponding slot is
+     null.  */
+  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 struct target_ops *target_stack;
+extern target_ops *current_top_target ();
+
+/* Return the dummy target.  */
+extern target_ops *get_dummy_target ();
 
 /* Define easy words for doing these operations on our current target.  */
 
-#define        target_shortname        (target_stack->shortname ())
-#define        target_longname         (target_stack->longname ())
+#define        target_shortname        (current_top_target ()->shortname ())
+#define        target_longname         (current_top_target ()->longname ())
 
 /* Does whatever cleanup is required for a target that we are no
    longer going to be calling.  This routine is automatically always
@@ -1262,7 +1387,7 @@ extern struct target_ops *find_run_target (void);
    These targets must set to_attach_no_wait.  */
 
 #define target_attach_no_wait() \
-  (target_stack->attach_no_wait ())
+  (current_top_target ()->attach_no_wait ())
 
 /* The target_attach operation places a process under debugger control,
    and stops the process.
@@ -1270,7 +1395,7 @@ extern struct target_ops *find_run_target (void);
    This operation provides a target-specific hook that allows the
    necessary bookkeeping to be performed after an attach completes.  */
 #define target_post_attach(pid) \
-     (target_stack->post_attach) (pid)
+     (current_top_target ()->post_attach) (pid)
 
 /* Display a message indicating we're about to detach from the current
    inferior process.  */
@@ -1352,7 +1477,7 @@ extern void target_store_registers (struct regcache *regcache, int regs);
    debugged.  */
 
 #define        target_prepare_to_store(regcache)       \
-     (target_stack->prepare_to_store) (regcache)
+     (current_top_target ()->prepare_to_store) (regcache)
 
 /* Determine current address space of thread PTID.  */
 
@@ -1373,22 +1498,22 @@ int target_supports_disable_randomization (void);
    while a trace experiment is running.  */
 
 #define target_supports_enable_disable_tracepoint() \
-  (target_stack->supports_enable_disable_tracepoint) ()
+  (current_top_target ()->supports_enable_disable_tracepoint) ()
 
 #define target_supports_string_tracing() \
-  (target_stack->supports_string_tracing) ()
+  (current_top_target ()->supports_string_tracing) ()
 
 /* Returns true if this target can handle breakpoint conditions
    on its end.  */
 
 #define target_supports_evaluation_of_breakpoint_conditions() \
-  (target_stack->supports_evaluation_of_breakpoint_conditions) ()
+  (current_top_target ()->supports_evaluation_of_breakpoint_conditions) ()
 
 /* Returns true if this target can handle breakpoint commands
    on its end.  */
 
 #define target_can_run_breakpoint_commands() \
-  (target_stack->can_run_breakpoint_commands) ()
+  (current_top_target ()->can_run_breakpoint_commands) ()
 
 extern int target_read_string (CORE_ADDR, gdb::unique_xmalloc_ptr<char> *,
                               int, int *);
@@ -1454,7 +1579,7 @@ enum flash_preserve_mode
    that supports writing to flash memory, and it should be used for
    all cases where access to flash memory is desirable.
 
-   REQUESTS is the vector (see vec.h) of memory_write_request.
+   REQUESTS is the vector of memory_write_request.
    PRESERVE_FLASH_P indicates what to do with blocks which must be
      erased, but not completely rewritten.
    PROGRESS_CB is a function that will be periodically called to provide
@@ -1471,7 +1596,7 @@ int target_write_memory_blocks
 /* Print a line about the current target.  */
 
 #define        target_files_info()     \
-     (target_stack->files_info) ()
+     (current_top_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
@@ -1491,7 +1616,7 @@ extern int target_remove_breakpoint (struct gdbarch *gdbarch,
 /* Return true if the target stack has a non-default
   "terminal_ours" method.  */
 
-extern int target_supports_terminal_ours (void);
+extern bool target_supports_terminal_ours (void);
 
 /* Kill the inferior process.   Make it go away.  */
 
@@ -1521,7 +1646,7 @@ 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) \
-     (target_stack->post_startup_inferior) (ptid)
+     (current_top_target ()->post_startup_inferior) (ptid)
 
 /* On some targets, we can catch an inferior fork or vfork event when
    it occurs.  These functions insert/remove an already-created
@@ -1529,31 +1654,31 @@ extern void target_load (const char *arg, int from_tty);
    catchpoint type is not supported and -1 for failure.  */
 
 #define target_insert_fork_catchpoint(pid) \
-     (target_stack->insert_fork_catchpoint) (pid)
+     (current_top_target ()->insert_fork_catchpoint) (pid)
 
 #define target_remove_fork_catchpoint(pid) \
-     (target_stack->remove_fork_catchpoint) (pid)
+     (current_top_target ()->remove_fork_catchpoint) (pid)
 
 #define target_insert_vfork_catchpoint(pid) \
-     (target_stack->insert_vfork_catchpoint) (pid)
+     (current_top_target ()->insert_vfork_catchpoint) (pid)
 
 #define target_remove_vfork_catchpoint(pid) \
-     (target_stack->remove_vfork_catchpoint) (pid)
+     (current_top_target ()->remove_vfork_catchpoint) (pid)
 
 /* If the inferior forks or vforks, this function will be called at
    the next resume in order to perform any bookkeeping and fiddling
    necessary to continue debugging either the parent or child, as
    requested, and releasing the other.  Information about the fork
    or vfork event is available via get_last_target_status ().
-   This function returns 1 if the inferior should not be resumed
+   This function returns true if the inferior should not be resumed
    (i.e. there is another event pending).  */
 
-int target_follow_fork (int follow_child, int detach_fork);
+bool target_follow_fork (bool follow_child, bool detach_fork);
 
 /* Handle the target-specific bookkeeping required when the inferior
    makes an exec call.  INF is the exec'd inferior.  */
 
-void target_follow_exec (struct inferior *inf, char *execd_pathname);
+void target_follow_exec (struct inferior *inf, const char *execd_pathname);
 
 /* On some targets, we can catch an inferior exec event when it
    occurs.  These functions insert/remove an already-created
@@ -1561,10 +1686,10 @@ void target_follow_exec (struct inferior *inf, char *execd_pathname);
    catchpoint type is not supported and -1 for failure.  */
 
 #define target_insert_exec_catchpoint(pid) \
-     (target_stack->insert_exec_catchpoint) (pid)
+     (current_top_target ()->insert_exec_catchpoint) (pid)
 
 #define target_remove_exec_catchpoint(pid) \
-     (target_stack->remove_exec_catchpoint) (pid)
+     (current_top_target ()->remove_exec_catchpoint) (pid)
 
 /* Syscall catch.
 
@@ -1583,7 +1708,7 @@ void target_follow_exec (struct inferior *inf, char *execd_pathname);
    for failure.  */
 
 #define target_set_syscall_catchpoint(pid, needed, any_count, syscall_counts) \
-     (target_stack->set_syscall_catchpoint) (pid, needed, any_count, \
+     (current_top_target ()->set_syscall_catchpoint) (pid, needed, any_count, \
                                             syscall_counts)
 
 /* The debugger has completed a blocking wait() call.  There is now
@@ -1599,7 +1724,7 @@ extern int target_can_run ();
 
 /* Set list of signals to be handled in the target.
 
-   PASS_SIGNALS is an array of size NSIG, indexed by target signal number
+   PASS_SIGNALS is an array indexed by target signal number
    (enum gdb_signal).  For every signal whose entry in this array is
    non-zero, the target is allowed -but not required- to skip reporting
    arrival of the signal to the GDB core by returning from target_wait,
@@ -1609,12 +1734,13 @@ extern int target_can_run ();
    about to receive a signal, it needs to be reported in any case, even
    if mentioned in a previous target_pass_signals call.   */
 
-extern void target_pass_signals (int nsig, unsigned char *pass_signals);
+extern void target_pass_signals
+  (gdb::array_view<const unsigned char> pass_signals);
 
 /* Set list of signals the target may pass to the inferior.  This
    directly maps to the "handle SIGNAL pass/nopass" setting.
 
-   PROGRAM_SIGNALS is an array of size NSIG, indexed by target signal
+   PROGRAM_SIGNALS is an array indexed by target signal
    number (enum gdb_signal).  For every signal whose entry in this
    array is non-zero, the target is allowed to pass the signal to the
    inferior.  Signals not present in the array shall be silently
@@ -1625,7 +1751,8 @@ extern void target_pass_signals (int nsig, unsigned char *pass_signals);
    example, when detaching (as threads may have been suspended with
    pending signals not reported to GDB).  */
 
-extern void target_program_signals (int nsig, unsigned char *program_signals);
+extern void target_program_signals
+  (gdb::array_view<const unsigned char> program_signals);
 
 /* Check to see if a thread is still alive.  */
 
@@ -1667,7 +1794,7 @@ extern void default_target_pass_ctrlc (struct target_ops *ops);
    placed in OUTBUF.  */
 
 #define target_rcmd(command, outbuf) \
-     (target_stack->rcmd) (command, outbuf)
+     (current_top_target ()->rcmd) (command, outbuf)
 
 
 /* Does the target include all of memory, or only part of it?  This
@@ -1701,37 +1828,29 @@ extern int target_has_registers_1 (void);
    case this will become true after to_create_inferior or
    to_attach.  */
 
-extern int target_has_execution_1 (ptid_t);
+extern bool target_has_execution_1 (inferior *inf);
 
-/* Like target_has_execution_1, but always passes inferior_ptid.  */
+/* Like target_has_execution_1, but always passes
+   current_inferior().  */
 
 extern int target_has_execution_current (void);
 
 #define target_has_execution target_has_execution_current ()
 
-/* Default implementations for process_stratum targets.  Return true
-   if there's a selected inferior, false otherwise.  */
-
-extern int default_child_has_all_memory ();
-extern int default_child_has_memory ();
-extern int default_child_has_stack ();
-extern int default_child_has_registers ();
-extern int default_child_has_execution (ptid_t the_ptid);
-
 /* Can the target support the debugger control of thread execution?
    Can it lock the thread scheduler?  */
 
 #define target_can_lock_scheduler \
-  (target_stack->get_thread_control_capabilities () & tc_schedlock)
+  (current_top_target ()->get_thread_control_capabilities () & tc_schedlock)
 
 /* Controls whether async mode is permitted.  */
-extern int target_async_permitted;
+extern bool target_async_permitted;
 
 /* Can the target support asynchronous execution?  */
-#define target_can_async_p() (target_stack->can_async_p ())
+#define target_can_async_p() (current_top_target ()->can_async_p ())
 
 /* Is the target in asynchronous execution mode?  */
-#define target_is_async_p() (target_stack->is_async_p ())
+#define target_is_async_p() (current_top_target ()->is_async_p ())
 
 /* Enables/disabled async target events.  */
 extern void target_async (int enable);
@@ -1748,23 +1867,26 @@ extern enum auto_boolean target_non_stop_enabled;
    non-stop" is on.  */
 extern int target_is_non_stop_p (void);
 
+/* Return true if at least one inferior has a non-stop target.  */
+extern bool exists_non_stop_target ();
+
 #define target_execution_direction() \
-  (target_stack->execution_direction ())
+  (current_top_target ()->execution_direction ())
 
 /* Converts a process id to a string.  Usually, the string just contains
    `process xyz', but on some systems it may contain
    `process xyz thread abc'.  */
 
-extern const char *target_pid_to_str (ptid_t ptid);
+extern std::string target_pid_to_str (ptid_t ptid);
 
-extern const char *normal_pid_to_str (ptid_t ptid);
+extern std::string normal_pid_to_str (ptid_t ptid);
 
 /* Return a short string describing extra information about PID,
    e.g. "sleeping", "runnable", "running on LWP 3".  Null return value
    is okay.  */
 
 #define target_extra_thread_info(TP) \
-     (target_stack->extra_thread_info (TP))
+     (current_top_target ()->extra_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.  */
@@ -1777,6 +1899,12 @@ extern const char *target_thread_name (struct thread_info *);
 extern struct thread_info *target_thread_handle_to_thread_info
   (const gdb_byte *thread_handle, int handle_len, struct inferior *inf);
 
+/* Given a thread, return the thread handle, a target-specific sequence of
+   bytes which serves as a thread identifier within the program being
+   debugged.  */
+extern gdb::byte_vector target_thread_info_to_thread_handle
+  (struct thread_info *);
+
 /* Attempts to find the pathname of the executable file
    that was run to create a specified process.
 
@@ -1790,12 +1918,12 @@ extern struct thread_info *target_thread_handle_to_thread_info
    it must persist.  */
 
 #define target_pid_to_exec_file(pid) \
-     (target_stack->pid_to_exec_file) (pid)
+     (current_top_target ()->pid_to_exec_file) (pid)
 
 /* See the to_thread_architecture description in struct target_ops.  */
 
 #define target_thread_architecture(ptid) \
-     (target_stack->thread_architecture (ptid))
+     (current_top_target ()->thread_architecture (ptid))
 
 /*
  * Iterator function for target memory regions.
@@ -1805,54 +1933,83 @@ extern struct thread_info *target_thread_handle_to_thread_info
  */
 
 #define target_find_memory_regions(FUNC, DATA) \
-     (target_stack->find_memory_regions) (FUNC, DATA)
+     (current_top_target ()->find_memory_regions) (FUNC, DATA)
 
 /*
  * Compose corefile .note section.
  */
 
 #define target_make_corefile_notes(BFD, SIZE_P) \
-     (target_stack->make_corefile_notes) (BFD, SIZE_P)
+     (current_top_target ()->make_corefile_notes) (BFD, SIZE_P)
 
 /* Bookmark interfaces.  */
 #define target_get_bookmark(ARGS, FROM_TTY) \
-     (target_stack->get_bookmark) (ARGS, FROM_TTY)
+     (current_top_target ()->get_bookmark) (ARGS, FROM_TTY)
 
 #define target_goto_bookmark(ARG, FROM_TTY) \
-     (target_stack->goto_bookmark) (ARG, FROM_TTY)
+     (current_top_target ()->goto_bookmark) (ARG, FROM_TTY)
 
 /* Hardware watchpoint interfaces.  */
 
+/* GDB's current model is that there are three "kinds" of watchpoints,
+   with respect to when they trigger and how you can move past them.
+
+   Those are: continuable, steppable, and non-steppable.
+
+   Continuable watchpoints are like x86's -- those trigger after the
+   memory access's side effects are fully committed to memory.  I.e.,
+   they trap with the PC pointing at the next instruction already.
+   Continuing past such a watchpoint is doable by just normally
+   continuing, hence the name.
+
+   Both steppable and non-steppable watchpoints trap before the memory
+   access.  I.e, the PC points at the instruction that is accessing
+   the memory.  So GDB needs to single-step once past the current
+   instruction in order to make the access effective and check whether
+   the instruction's side effects change the watched expression.
+
+   Now, in order to step past that instruction, depending on
+   architecture and target, you can have two situations:
+
+   - steppable watchpoints: you can single-step with the watchpoint
+     still armed, and the watchpoint won't trigger again.
+
+   - non-steppable watchpoints: if you try to single-step with the
+     watchpoint still armed, you'd trap the watchpoint again and the
+     thread wouldn't make any progress.  So GDB needs to temporarily
+     remove the watchpoint in order to step past it.
+
+   If your target/architecture does not signal that it has either
+   steppable or non-steppable watchpoints via either
+   target_have_steppable_watchpoint or
+   gdbarch_have_nonsteppable_watchpoint, GDB assumes continuable
+   watchpoints.  */
+
 /* Returns non-zero 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()         \
-  ((target_stack->stopped_by_watchpoint) ())
+  ((current_top_target ()->stopped_by_watchpoint) ())
 
 /* Returns non-zero if the target stopped because it executed a
    software breakpoint instruction.  */
 
 #define target_stopped_by_sw_breakpoint()              \
-  ((target_stack->stopped_by_sw_breakpoint) ())
+  ((current_top_target ()->stopped_by_sw_breakpoint) ())
 
 #define target_supports_stopped_by_sw_breakpoint() \
-  ((target_stack->supports_stopped_by_sw_breakpoint) ())
+  ((current_top_target ()->supports_stopped_by_sw_breakpoint) ())
 
 #define target_stopped_by_hw_breakpoint()                              \
-  ((target_stack->stopped_by_hw_breakpoint) ())
+  ((current_top_target ()->stopped_by_hw_breakpoint) ())
 
 #define target_supports_stopped_by_hw_breakpoint() \
-  ((target_stack->supports_stopped_by_hw_breakpoint) ())
+  ((current_top_target ()->supports_stopped_by_hw_breakpoint) ())
 
 /* Non-zero if we have steppable watchpoints  */
 
 #define target_have_steppable_watchpoint \
-  (target_stack->have_steppable_watchpoint ())
-
-/* Non-zero if we have continuable watchpoints  */
-
-#define target_have_continuable_watchpoint \
-  (target_stack->have_continuable_watchpoint ())
+  (current_top_target ()->have_steppable_watchpoint ())
 
 /* Provide defaults for hardware watchpoint functions.  */
 
@@ -1869,18 +2026,18 @@ extern struct thread_info *target_thread_handle_to_thread_info
    this one used so far.  */
 
 #define target_can_use_hardware_watchpoint(TYPE,CNT,OTHERTYPE) \
- (target_stack->can_use_hw_breakpoint) ( \
+ (current_top_target ()->can_use_hw_breakpoint) ( \
                                             TYPE, CNT, 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) \
-    (target_stack->region_ok_for_hw_watchpoint) (addr, len)
+    (current_top_target ()->region_ok_for_hw_watchpoint) (addr, len)
 
 
 #define target_can_do_single_step() \
-  (target_stack->can_do_single_step) ()
+  (current_top_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.
@@ -1889,10 +2046,10 @@ extern struct thread_info *target_thread_handle_to_thread_info
    -1 for failure.  */
 
 #define        target_insert_watchpoint(addr, len, type, cond) \
-     (target_stack->insert_watchpoint) (addr, len, type, cond)
+     (current_top_target ()->insert_watchpoint) (addr, len, type, cond)
 
 #define        target_remove_watchpoint(addr, len, type, cond) \
-     (target_stack->remove_watchpoint) (addr, len, type, cond)
+     (current_top_target ()->remove_watchpoint) (addr, len, type, 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
@@ -1916,10 +2073,10 @@ extern int target_remove_mask_watchpoint (CORE_ADDR, CORE_ADDR,
    message) otherwise.  */
 
 #define target_insert_hw_breakpoint(gdbarch, bp_tgt) \
-     (target_stack->insert_hw_breakpoint) (gdbarch, bp_tgt)
+     (current_top_target ()->insert_hw_breakpoint) (gdbarch, bp_tgt)
 
 #define target_remove_hw_breakpoint(gdbarch, bp_tgt) \
-     (target_stack->remove_hw_breakpoint) (gdbarch, bp_tgt)
+     (current_top_target ()->remove_hw_breakpoint) (gdbarch, bp_tgt)
 
 /* Return number of debug registers needed for a ranged breakpoint,
    or -1 if ranged breakpoints are not supported.  */
@@ -1948,7 +2105,7 @@ extern int target_ranged_break_num_registers (void);
    For this reason, GDB will still evaluate the condition expression when
    the watchpoint triggers.  */
 #define target_can_accel_watchpoint_condition(addr, len, type, cond) \
-  (target_stack->can_accel_watchpoint_condition) (addr, len, type, cond)
+  (current_top_target ()->can_accel_watchpoint_condition) (addr, len, type, cond)
 
 /* Return number of debug registers needed for a masked watchpoint,
    -1 if masked watchpoints are not supported or -2 if the given address
@@ -1958,12 +2115,12 @@ extern int target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask);
 
 /* Target can execute in reverse?  */
 #define target_can_execute_reverse \
-      target_stack->can_execute_reverse ()
+      current_top_target ()->can_execute_reverse ()
 
 extern const struct target_desc *target_read_description (struct target_ops *);
 
 #define target_get_ada_task_ptid(lwp, tid) \
-     (target_stack->get_ada_task_ptid) (lwp,tid)
+     (current_top_target ()->get_ada_task_ptid) (lwp,tid)
 
 /* Utility implementation of searching memory.  */
 extern int simple_search_memory (struct target_ops* ops,
@@ -1985,24 +2142,18 @@ extern int target_search_memory (CORE_ADDR start_addr,
 /* Return nonzero if the filesystem seen by the current inferior
    is the local filesystem, zero otherwise.  */
 #define target_filesystem_is_local() \
-  target_stack->filesystem_is_local ()
+  current_top_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 the debugger (GDB or, for remote targets, the remote stub).
-   Return a target file descriptor, or -1 if an error occurs (and
-   set *TARGET_ERRNO).  */
+   using FLAGS and MODE.  If INF is NULL, use the filesystem seen by
+   the debugger (GDB or, for remote targets, the remote stub).  Return
+   a target file descriptor, or -1 if an error occurs (and set
+   *TARGET_ERRNO).  If WARN_IF_SLOW is true, print a warning message
+   if the file is being accessed over a link that may be slow.  */
 extern int target_fileio_open (struct inferior *inf,
                               const char *filename, int flags,
-                              int mode, int *target_errno);
-
-/* Like target_fileio_open, but print a warning message if the
-   file is being accessed over a link that may be slow.  */
-extern int target_fileio_open_warn_if_slow (struct inferior *inf,
-                                           const char *filename,
-                                           int flags,
-                                           int mode,
-                                           int *target_errno);
+                              int mode, bool warn_if_slow,
+                              int *target_errno);
 
 /* Write up to LEN bytes from WRITE_BUF to FD on the target.
    Return the number of bytes written, or -1 if an error occurs
@@ -2072,100 +2223,100 @@ extern gdb::unique_xmalloc_ptr<char> target_fileio_read_stralloc
 /* Tracepoint-related operations.  */
 
 #define target_trace_init() \
-  (target_stack->trace_init) ()
+  (current_top_target ()->trace_init) ()
 
 #define target_download_tracepoint(t) \
-  (target_stack->download_tracepoint) (t)
+  (current_top_target ()->download_tracepoint) (t)
 
 #define target_can_download_tracepoint() \
-  (target_stack->can_download_tracepoint) ()
+  (current_top_target ()->can_download_tracepoint) ()
 
 #define target_download_trace_state_variable(tsv) \
-  (target_stack->download_trace_state_variable) (tsv)
+  (current_top_target ()->download_trace_state_variable) (tsv)
 
 #define target_enable_tracepoint(loc) \
-  (target_stack->enable_tracepoint) (loc)
+  (current_top_target ()->enable_tracepoint) (loc)
 
 #define target_disable_tracepoint(loc) \
-  (target_stack->disable_tracepoint) (loc)
+  (current_top_target ()->disable_tracepoint) (loc)
 
 #define target_trace_start() \
-  (target_stack->trace_start) ()
+  (current_top_target ()->trace_start) ()
 
 #define target_trace_set_readonly_regions() \
-  (target_stack->trace_set_readonly_regions) ()
+  (current_top_target ()->trace_set_readonly_regions) ()
 
 #define target_get_trace_status(ts) \
-  (target_stack->get_trace_status) (ts)
+  (current_top_target ()->get_trace_status) (ts)
 
 #define target_get_tracepoint_status(tp,utp)           \
-  (target_stack->get_tracepoint_status) (tp, utp)
+  (current_top_target ()->get_tracepoint_status) (tp, utp)
 
 #define target_trace_stop() \
-  (target_stack->trace_stop) ()
+  (current_top_target ()->trace_stop) ()
 
 #define target_trace_find(type,num,addr1,addr2,tpp) \
-  (target_stack->trace_find) (\
+  (current_top_target ()->trace_find) (\
                                   (type), (num), (addr1), (addr2), (tpp))
 
 #define target_get_trace_state_variable_value(tsv,val) \
-  (target_stack->get_trace_state_variable_value) ((tsv), (val))
+  (current_top_target ()->get_trace_state_variable_value) ((tsv), (val))
 
 #define target_save_trace_data(filename) \
-  (target_stack->save_trace_data) (filename)
+  (current_top_target ()->save_trace_data) (filename)
 
 #define target_upload_tracepoints(utpp) \
-  (target_stack->upload_tracepoints) (utpp)
+  (current_top_target ()->upload_tracepoints) (utpp)
 
 #define target_upload_trace_state_variables(utsvp) \
-  (target_stack->upload_trace_state_variables) (utsvp)
+  (current_top_target ()->upload_trace_state_variables) (utsvp)
 
 #define target_get_raw_trace_data(buf,offset,len) \
-  (target_stack->get_raw_trace_data) ((buf), (offset), (len))
+  (current_top_target ()->get_raw_trace_data) ((buf), (offset), (len))
 
 #define target_get_min_fast_tracepoint_insn_len() \
-  (target_stack->get_min_fast_tracepoint_insn_len) ()
+  (current_top_target ()->get_min_fast_tracepoint_insn_len) ()
 
 #define target_set_disconnected_tracing(val) \
-  (target_stack->set_disconnected_tracing) (val)
+  (current_top_target ()->set_disconnected_tracing) (val)
 
 #define        target_set_circular_trace_buffer(val)   \
-  (target_stack->set_circular_trace_buffer) (val)
+  (current_top_target ()->set_circular_trace_buffer) (val)
 
 #define        target_set_trace_buffer_size(val)       \
-  (target_stack->set_trace_buffer_size) (val)
+  (current_top_target ()->set_trace_buffer_size) (val)
 
 #define        target_set_trace_notes(user,notes,stopnotes)            \
-  (target_stack->set_trace_notes) ((user), (notes), (stopnotes))
+  (current_top_target ()->set_trace_notes) ((user), (notes), (stopnotes))
 
 #define target_get_tib_address(ptid, addr) \
-  (target_stack->get_tib_address) ((ptid), (addr))
+  (current_top_target ()->get_tib_address) ((ptid), (addr))
 
 #define target_set_permissions() \
-  (target_stack->set_permissions) ()
+  (current_top_target ()->set_permissions) ()
 
 #define target_static_tracepoint_marker_at(addr, marker) \
-  (target_stack->static_tracepoint_marker_at) (addr, marker)
+  (current_top_target ()->static_tracepoint_marker_at) (addr, marker)
 
 #define target_static_tracepoint_markers_by_strid(marker_id) \
-  (target_stack->static_tracepoint_markers_by_strid) (marker_id)
+  (current_top_target ()->static_tracepoint_markers_by_strid) (marker_id)
 
 #define target_traceframe_info() \
-  (target_stack->traceframe_info) ()
+  (current_top_target ()->traceframe_info) ()
 
 #define target_use_agent(use) \
-  (target_stack->use_agent) (use)
+  (current_top_target ()->use_agent) (use)
 
 #define target_can_use_agent() \
-  (target_stack->can_use_agent) ()
+  (current_top_target ()->can_use_agent) ()
 
 #define target_augmented_libraries_svr4_read() \
-  (target_stack->augmented_libraries_svr4_read) ()
+  (current_top_target ()->augmented_libraries_svr4_read) ()
 
 /* Command logging facility.  */
 
 #define target_log_command(p)                                  \
-  (target_stack->log_command) (p)
+  (current_top_target ()->log_command) (p)
 
 
 extern int target_core_of_thread (ptid_t ptid);
@@ -2207,19 +2358,32 @@ int target_verify_memory (const gdb_byte *data,
    no matter where it is on the list.  Returns 0 if no
    change, 1 if removed from stack.  */
 
-extern void add_target (struct target_ops *);
+/* Type of callback called when the user activates a target with
+   "target TARGET_NAME".  The callback routine takes the rest of the
+   parameters from the command, and (if successful) pushes a new
+   target onto the stack.  */
+typedef void target_open_ftype (const char *args, int from_tty);
+
+/* Add the target described by INFO to the list of possible targets
+   and add a new command 'target $(INFO->shortname)'.  Set COMPLETER
+   as the command's completer if not NULL.  */
 
-extern void add_target_with_completer (struct target_ops *t,
-                                      completer_ftype *completer);
+extern void add_target (const target_info &info,
+                       target_open_ftype *func,
+                       completer_ftype *completer = NULL);
 
-/* Adds a command ALIAS for target T and marks it deprecated.  This is useful
-   for maintaining backwards compatibility when renaming targets.  */
+/* Adds a command ALIAS for the target described by INFO and marks it
+   deprecated.  This is useful for maintaining backwards compatibility
+   when renaming targets.  */
 
-extern void add_deprecated_target_alias (struct target_ops *t,
+extern void add_deprecated_target_alias (const target_info &info,
                                         const char *alias);
 
 extern void push_target (struct target_ops *);
 
+/* An overload that deletes the target on failure.  */
+extern void push_target (target_ops_up &&);
+
 extern int unpush_target (struct target_ops *);
 
 extern void target_pre_inferior (int);
@@ -2237,7 +2401,7 @@ extern void pop_all_targets_at_and_above (enum strata stratum);
    strictly above ABOVE_STRATUM.  */
 extern void pop_all_targets_above (enum strata above_stratum);
 
-extern int target_is_pushed (struct target_ops *t);
+extern bool target_is_pushed (target_ops *t);
 
 extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
                                               CORE_ADDR offset);
@@ -2325,8 +2489,6 @@ extern void noprocess (void) ATTRIBUTE_NORETURN;
 
 extern void target_require_runnable (void);
 
-extern struct target_ops *find_target_beneath (struct target_ops *);
-
 /* Find the target at STRATUM.  If no target is at that stratum,
    return NULL.  */
 
@@ -2359,12 +2521,12 @@ extern int remote_timeout;
 extern scoped_restore_tmpl<int>
     make_scoped_restore_show_memory_breakpoints (int show);
 
-extern int may_write_registers;
-extern int may_write_memory;
-extern int may_insert_breakpoints;
-extern int may_insert_tracepoints;
-extern int may_insert_fast_tracepoints;
-extern int may_stop;
+extern bool may_write_registers;
+extern bool may_write_memory;
+extern bool may_insert_breakpoints;
+extern bool may_insert_tracepoints;
+extern bool may_insert_fast_tracepoints;
+extern bool may_stop;
 
 extern void update_target_permissions (void);
 
@@ -2451,62 +2613,4 @@ extern void target_prepare_to_generate_core (void);
 /* See to_done_generating_core.  */
 extern void target_done_generating_core (void);
 
-#if GDB_SELF_TEST
-namespace selftests {
-
-/* A mock process_stratum target_ops that doesn't read/write registers
-   anywhere.  */
-
-class test_target_ops : public target_ops
-{
-public:
-  test_target_ops ()
-    : target_ops {}
-  {
-    to_stratum = process_stratum;
-  }
-
-  const char *shortname () override
-  {
-    return NULL;
-  }
-
-  const char *longname () override
-  {
-    return NULL;
-  }
-
-  const char *doc () override
-  {
-    return NULL;
-  }
-
-  int has_registers () override
-  {
-    return 1;
-  }
-
-  int has_stack () override
-  {
-    return 1;
-  }
-
-  int has_memory () override
-  {
-    return 1;
-  }
-
-  void prepare_to_store (regcache *regs) override
-  {
-  }
-
-  void store_registers (regcache *regs, int regno) override
-  {
-  }
-};
-
-
-} // namespace selftests
-#endif /* GDB_SELF_TEST */
-
 #endif /* !defined (TARGET_H) */
This page took 0.049207 seconds and 4 git commands to generate.