/* Interface between GDB and target environments, including files and processes
- Copyright (C) 1990-2019 Free Software Foundation, Inc.
+ Copyright (C) 1990-2020 Free Software Foundation, Inc.
Contributed by Cygnus Support. Written by John Gilmore.
#include "infrun.h" /* For enum exec_direction_kind. */
#include "breakpoint.h" /* For enum bptype. */
#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
};
/* Return a pretty printed form of TARGET_OPTIONS. */
-extern std::string target_options_to_string (int target_options);
+extern std::string target_options_to_string (target_wait_flags target_options);
/* Possible types of events that the inferior handler will have to
deal with. */
};
struct target_ops
+ : public refcounted_object
{
/* Return this target's stratum. */
virtual strata stratum () const = 0;
virtual const target_info &info () const = 0;
/* Name this target type. */
- const char *shortname ()
+ const char *shortname () const
{ return info ().shortname; }
- const char *longname ()
+ const char *longname () const
{ return info ().longname; }
/* Close the target. This is where the target can handle
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_wait_flags options)
TARGET_DEFAULT_FUNC (default_target_wait);
virtual void fetch_registers (struct regcache *, int)
TARGET_DEFAULT_IGNORE ();
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 bool has_memory () { return false; }
virtual bool has_stack () { return false; }
virtual bool has_registers () { return false; }
- virtual bool has_execution (ptid_t) { return false; }
+ virtual bool has_execution (inferior *inf) { return false; }
/* Control thread execution. */
virtual thread_control_capabilities get_thread_control_capabilities ()
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
virtual bool supports_evaluation_of_breakpoint_conditions ()
TARGET_DEFAULT_RETURN (false);
+ /* Does this target support native dumpcore API? */
+ virtual bool supports_dumpcore ()
+ TARGET_DEFAULT_RETURN (false);
+
+ /* Generate the core file with native target API. */
+ virtual void dumpcore (const char *filename)
+ TARGET_DEFAULT_IGNORE ();
+
/* Does this target support evaluation of breakpoint commands on its
end? */
virtual bool can_run_breakpoint_commands ()
/* 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 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_RETURN (NULL);
/* 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 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 (current_top_target ()->shortname ())
extern ptid_t default_target_wait (struct target_ops *ops,
ptid_t ptid,
struct target_waitstatus *status,
- int options);
+ target_wait_flags options);
/* Fetch at least register REGNO, or all regs if regno == -1. No result. */
#define target_supports_evaluation_of_breakpoint_conditions() \
(current_top_target ()->supports_evaluation_of_breakpoint_conditions) ()
+/* Does this target support dumpcore API? */
+
+#define target_supports_dumpcore() \
+ (current_top_target ()->supports_dumpcore) ()
+
+/* Generate the core file with target API. */
+
+#define target_dumpcore(x) \
+ (current_top_target ()->dumpcore (x))
+
/* 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 int target_read_string (CORE_ADDR, gdb::unique_xmalloc_ptr<char> *,
- int, int *);
+/* 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
+ in some cases -- but these will not be returned). Returns nullptr
+ on error. */
+
+extern gdb::unique_xmalloc_ptr<char> target_read_string
+ (CORE_ADDR memaddr, int len, int *bytes_read = nullptr);
/* For target_read_memory see target/target.h. */
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. */
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);
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() \
(current_top_target ()->execution_direction ())
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
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);