/* Interface between GDB and target environments, including files and processes
- Copyright (C) 1990-2020 Free Software Foundation, Inc.
+ Copyright (C) 1990-2021 Free Software Foundation, Inc.
Contributed by Cygnus Support. Written by John Gilmore.
struct bp_location;
struct bp_target_info;
struct regcache;
-struct target_section_table;
struct trace_state_variable;
struct trace_status;
struct uploaded_tsv;
#include "breakpoint.h" /* For enum bptype. */
#include "gdbsupport/scoped_restore.h"
#include "gdbsupport/refcounted-object.h"
+#include "target-section.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. */
virtual void attach (const char *, int);
virtual void post_attach (int)
TARGET_DEFAULT_IGNORE ();
+
+ /* Detaches from the inferior. Note that on targets that support
+ async execution (i.e., targets where it is possible to detach
+ from programs with threads running), the target is responsible
+ for removing breakpoints from the program before the actual
+ detach, otherwise the program dies when it hits one. */
virtual void detach (inferior *, int)
TARGET_DEFAULT_IGNORE ();
+
virtual void disconnect (const char *, int)
TARGET_DEFAULT_NORETURN (tcomplain ());
virtual void resume (ptid_t,
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 (NULL);
virtual void log_command (const char *)
TARGET_DEFAULT_IGNORE ();
- virtual struct target_section_table *get_section_table ()
- TARGET_DEFAULT_RETURN (NULL);
+ virtual const target_section_table *get_section_table ()
+ TARGET_DEFAULT_RETURN (default_get_section_table ());
/* Provide default values for all "must have" methods. */
virtual bool has_all_memory () { return false; }
virtual int find_memory_regions (find_memory_region_ftype func, void *data)
TARGET_DEFAULT_FUNC (dummy_find_memory_regions);
/* make_corefile_notes support method for gcore */
- virtual char *make_corefile_notes (bfd *, int *)
+ virtual gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *)
TARGET_DEFAULT_FUNC (dummy_make_corefile_notes);
/* get_bookmark support method for bookmarks */
virtual gdb_byte *get_bookmark (const char *, int)
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 ()
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. */
(current_top_target ()->rcmd) (command, outbuf)
-/* Does the target include all of memory, or only part of it? This
- determines whether we look up the target chain for other parts of
- memory if this target can't satisfy a request. */
-
-extern int target_has_all_memory_1 (void);
-#define target_has_all_memory target_has_all_memory_1 ()
-
/* Does the target include memory? (Dummy targets don't.) */
-extern int target_has_memory_1 (void);
-#define target_has_memory target_has_memory_1 ()
+extern int target_has_memory ();
/* Does the target have a stack? (Exec files don't, VxWorks doesn't, until
we start a process.) */
-extern int target_has_stack_1 (void);
-#define target_has_stack target_has_stack_1 ()
+extern int target_has_stack ();
/* Does the target have registers? (Exec files don't.) */
-extern int target_has_registers_1 (void);
-#define target_has_registers target_has_registers_1 ()
+extern int target_has_registers ();
/* Does the target have execution? Can we make it jump (through
hoops), or pop its stack a few times? This means that the current
whether or not the target is capable of execution, but there are
also targets which can be current while not executing. In that
case this will become true after to_create_inferior or
- to_attach. */
-
-extern bool target_has_execution_1 (inferior *inf);
-
-/* Like target_has_execution_1, but always passes
- current_inferior(). */
-
-extern int target_has_execution_current (void);
+ to_attach. INF is the inferior to use; nullptr means to use the
+ current inferior. */
-#define target_has_execution target_has_execution_current ()
+extern bool target_has_execution (inferior *inf = nullptr);
/* Can the target support the debugger control of thread execution?
Can it lock the thread scheduler? */
-#define target_can_lock_scheduler \
- (current_top_target ()->get_thread_control_capabilities () & tc_schedlock)
+static inline bool
+target_can_lock_scheduler ()
+{
+ return (current_top_target ()->get_thread_control_capabilities ()
+ & tc_schedlock) != 0;
+}
/* Controls whether async mode is permitted. */
extern bool target_async_permitted;
/* Is the target in non-stop mode? Some targets control the inferior
in non-stop mode even with "set non-stop off". Always true if "set
non-stop" is on. */
-extern int target_is_non_stop_p (void);
+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 ();
/* Non-zero if we have steppable watchpoints */
-#define target_have_steppable_watchpoint \
- (current_top_target ()->have_steppable_watchpoint ())
+static inline bool
+target_have_steppable_watchpoint ()
+{
+ return current_top_target ()->have_steppable_watchpoint ();
+}
/* Provide defaults for hardware watchpoint functions. */
extern int target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask);
/* Target can execute in reverse? */
-#define target_can_execute_reverse \
- current_top_target ()->can_execute_reverse ()
+static inline bool
+target_can_execute_reverse ()
+{
+ return 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) \
(current_top_target ()->get_ada_task_ptid) (lwp,tid)
-/* Utility implementation of searching memory. */
-extern int simple_search_memory (struct target_ops* ops,
- CORE_ADDR start_addr,
- ULONGEST search_space_len,
- const gdb_byte *pattern,
- ULONGEST pattern_len,
- CORE_ADDR *found_addrp);
-
/* Main entry point for searching memory. */
extern int target_search_memory (CORE_ADDR start_addr,
- ULONGEST search_space_len,
- const gdb_byte *pattern,
- ULONGEST pattern_len,
- CORE_ADDR *found_addrp);
+ ULONGEST search_space_len,
+ const gdb_byte *pattern,
+ ULONGEST pattern_len,
+ CORE_ADDR *found_addrp);
/* Target file operations. */
extern int unpush_target (struct target_ops *);
+/* A unique_ptr helper to unpush a target. */
+
+struct target_unpusher
+{
+ void operator() (struct target_ops *ops) const
+ {
+ unpush_target (ops);
+ }
+};
+
+/* A unique_ptr that unpushes a target on destruction. */
+
+typedef std::unique_ptr<struct target_ops, target_unpusher> target_unpush_up;
+
extern void target_pre_inferior (int);
extern void target_preopen (int);
extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
CORE_ADDR offset);
-/* Struct target_section maps address ranges to file sections. It is
- mostly used with BFD files, but can be used without (e.g. for handling
- raw disks, or files not in formats handled by BFD). */
-
-struct target_section
- {
- CORE_ADDR addr; /* Lowest address in section */
- CORE_ADDR endaddr; /* 1+highest address in section */
-
- struct bfd_section *the_bfd_section;
-
- /* The "owner" of the section.
- It can be any unique value. It is set by add_target_sections
- and used by remove_target_sections.
- For example, for executables it is a pointer to exec_bfd and
- for shlibs it is the so_list pointer. */
- void *owner;
- };
-
-/* Holds an array of target sections. Defined by [SECTIONS..SECTIONS_END[. */
-
-struct target_section_table
-{
- struct target_section *sections;
- struct target_section *sections_end;
-};
-
/* Return the "section" containing the specified address. */
-struct target_section *target_section_by_addr (struct target_ops *target,
- CORE_ADDR addr);
+const struct target_section *target_section_by_addr (struct target_ops *target,
+ CORE_ADDR addr);
/* Return the target section table this target (or the targets
beneath) currently manipulate. */
-extern struct target_section_table *target_get_section_table
+extern const target_section_table *target_get_section_table
(struct target_ops *target);
+/* Default implementation of get_section_table for dummy_target. */
+
+extern const target_section_table *default_get_section_table ();
+
/* From mem-break.c */
extern int memory_remove_breakpoint (struct target_ops *,
/* Stuff that should be shared among the various remote targets. */
-/* Debugging level. 0 is off, and non-zero values mean to print some debug
- information (higher values, more information). */
-extern int remote_debug;
-
-/* Speed in bits per second, or -1 which means don't mess with the speed. */
-extern int baud_rate;
-
-/* Parity for serial port */
-extern int serial_parity;
/* Timeout limit for response from target. */
extern int remote_timeout;