+2018-05-02 Pedro Alves <palves@redhat.com>
+
+ * aarch64-fbsd-nat.c (_initialize_aarch64_fbsd_nat): Use
+ add_inf_child_target.
+ * aarch64-linux-nat.c (_initialize_aarch64_linux_nat): Use
+ add_inf_child_target.
+ * aix-thread.c (aix_thread_target_info): New.
+ (aix_thread_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ * alpha-bsd-nat.c (_initialize_alphabsd_nat): Use
+ add_inf_child_target.
+ * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use
+ add_inf_child_target.
+ * amd64-fbsd-nat.c (_initialize_amd64fbsd_nat): Use
+ add_inf_child_target.
+ * amd64-linux-nat.c (_initialize_amd64_linux_nat): Use
+ add_inf_child_target.
+ * amd64-nbsd-nat.c (_initialize_amd64nbsd_nat): Use
+ add_inf_child_target.
+ * amd64-obsd-nat.c (_initialize_amd64obsd_nat): Use
+ add_inf_child_target.
+ * arm-fbsd-nat.c (_initialize_arm_fbsd_nat): Use
+ add_inf_child_target.
+ * arm-linux-nat.c (_initialize_arm_linux_nat): Use
+ add_inf_child_target.
+ * arm-nbsd-nat.c (_initialize_arm_netbsd_nat): Use
+ add_inf_child_target.
+ * bfd-target.c (target_bfd_target_info): New.
+ (target_bfd) <shortname, longname, doc>: Delete.
+ <info>: New.
+ * bsd-kvm.c (bsd_kvm_target_info): New.
+ (bsd_kvm_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ (bsd_kvm_target::open): Rename to ...
+ (bsd_kvm_target_open): ... this. Adjust.
+ * bsd-uthread.c (bsd_uthread_target_info): New.
+ (bsd_uthread_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ * corefile.c (core_file_command): Adjust.
+ * corelow.c (core_target_info): New.
+ (core_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ (core_target::open): Rename to ...
+ (core_target_open): ... this. Adjust.
+ * ctf.c (ctf_target_info): New.
+ (ctf_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ (ctf_target::open): Rename to ...
+ (ctf_target_open): ... this.
+ (_initialize_ctf): Adjust.
+ * exec.c (exec_target_info): New.
+ (exec_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ (exec_target::open): Rename to ...
+ (exec_target_open): ... this.
+ * gdbcore.h (core_target_open): Declare.
+ * go32-nat.c (_initialize_go32_nat): Use add_inf_child_target.
+ * hppa-linux-nat.c (_initialize_hppa_linux_nat): Use
+ add_inf_child_target.
+ * hppa-nbsd-nat.c (_initialize_hppanbsd_nat): Use
+ add_inf_child_target.
+ * hppa-obsd-nat.c (_initialize_hppaobsd_nat): Use
+ add_inf_child_target.
+ * i386-darwin-nat.c (_initialize_i386_darwin_nat): Use
+ add_inf_child_target.
+ * i386-fbsd-nat.c (_initialize_i386fbsd_nat): Use
+ add_inf_child_target.
+ * i386-gnu-nat.c (_initialize_i386gnu_nat): Use
+ add_inf_child_target.
+ * i386-linux-nat.c (_initialize_i386_linux_nat): Use
+ add_inf_child_target.
+ * i386-nbsd-nat.c (_initialize_i386nbsd_nat): Use
+ add_inf_child_target.
+ * i386-obsd-nat.c (_initialize_i386obsd_nat): Use
+ add_inf_child_target.
+ * ia64-linux-nat.c (_initialize_ia64_linux_nat): Use
+ add_inf_child_target.
+ * inf-child.c (inf_child_target_info): New.
+ (inf_child_target::info): New.
+ (inf_child_open_target): Remove 'target' parameter. Use
+ get_native_target instead.
+ (inf_child_target::open): Delete.
+ (add_inf_child_target): New.
+ * inf-child.h (inf_child_target) <shortname, longname, doc, open>:
+ Delete.
+ <info>: New.
+ (add_inf_child_target): Declare.
+ (inf_child_open_target): Declare.
+ * linux-thread-db.c (thread_db_target_info): New.
+ (thread_db_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ * m32r-linux-nat.c (_initialize_m32r_linux_nat): Use
+ add_inf_child_target.
+ * m68k-bsd-nat.c (_initialize_m68kbsd_nat): Use
+ add_inf_child_target.
+ * m68k-linux-nat.c (_initialize_m68k_linux_nat): Use
+ add_inf_child_target.
+ * m88k-bsd-nat.c (_initialize_m88kbsd_nat): Use
+ add_inf_child_target.
+ * make-target-delegates (print_class): Adjust.
+ * mips-fbsd-nat.c (_initialize_mips_fbsd_nat): Use
+ add_inf_child_target.
+ * mips-linux-nat.c (_initialize_mips_linux_nat): Use
+ add_inf_child_target.
+ * mips-nbsd-nat.c (_initialize_mipsnbsd_nat): Use
+ add_inf_child_target.
+ * mips64-obsd-nat.c (_initialize_mips64obsd_nat): Use
+ add_inf_child_target.
+ * nto-procfs.c (nto_native_target_info): New.
+ (nto_procfs_target_native) <shortname, longname, doc>:
+ Delete.
+ <info>: New.
+ (nto_procfs_target_info): New.
+ (nto_procfs_target_procfs) <shortname, longname, doc>:
+ Delete.
+ <info>: New.
+ (init_procfs_targets): Adjust.
+ * ppc-fbsd-nat.c (_initialize_ppcfbsd_nat): Use
+ add_inf_child_target.
+ * ppc-linux-nat.c (_initialize_ppc_linux_nat): Use
+ add_inf_child_target.
+ * ppc-nbsd-nat.c (_initialize_ppcnbsd_nat): Use
+ add_inf_child_target.
+ * ppc-obsd-nat.c (_initialize_ppcobsd_nat): Use
+ add_inf_child_target.
+ * ravenscar-thread.c (ravenscar_target_info): New.
+ (ravenscar_thread_target) <shortname, longname, doc>:
+ Delete.
+ <info>: New.
+ * record-btrace.c (record_btrace_target_info):
+ (record_btrace_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ (record_btrace_target::open): Rename to ...
+ (record_btrace_target_open): ... this. Adjust.
+ * record-full.c (record_longname, record_doc): New.
+ (record_full_base_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ (record_full_target_info): New.
+ (record_full_target): <shortname>: Delete.
+ <info>: New.
+ (record_full_core_open_1, record_full_open_1): Update comments.
+ (record_full_base_target::open): Rename to ...
+ (record_full_open): ... this.
+ (cmd_record_full_restore): Update.
+ (_initialize_record_full): Update.
+ * remote-sim.c (remote_sim_target_info): New.
+ (gdbsim_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ (gdbsim_target::open): Rename to ...
+ (gdbsim_target_open): ... this.
+ (_initialize_remote_sim): Adjust.
+ * remote.c (remote_doc): New.
+ (remote_target_info): New.
+ (remote_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ (extended_remote_target_info): New.
+ (extended_remote_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ (remote_target::open_1): Make static. Adjust.
+ * rs6000-nat.c (_initialize_rs6000_nat): Use add_inf_child_target.
+ * s390-linux-nat.c (_initialize_s390_nat): Use
+ add_inf_child_target.
+ * sh-nbsd-nat.c (_initialize_shnbsd_nat): Use
+ add_inf_child_target.
+ * sol-thread.c (thread_db_target_info): New.
+ (sol_thread_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ * sparc-linux-nat.c (_initialize_sparc_linux_nat): Use
+ add_inf_child_target.
+ * sparc-nbsd-nat.c (_initialize_sparcnbsd_nat): Use
+ add_inf_child_target.
+ * sparc64-fbsd-nat.c (_initialize_sparc64fbsd_nat): Use
+ add_inf_child_target.
+ * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use
+ add_inf_child_target.
+ * sparc64-nbsd-nat.c (_initialize_sparc64nbsd_nat): Use
+ add_inf_child_target.
+ * sparc64-obsd-nat.c (_initialize_sparc64obsd_nat): Use
+ add_inf_child_target.
+ * spu-linux-nat.c (_initialize_spu_nat): Use
+ add_inf_child_target.
+ * spu-multiarch.c (spu_multiarch_target_info): New.
+ (spu_multiarch_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ * target-delegates.c: Regenerate.
+ * target.c: Include <unordered_map>.
+ (target_ops_p): Delete.
+ (DEF_VEC_P(target_ops_p)): Delete.
+ (target_factories): New.
+ (test_target_info): New.
+ (test_target_ops::info): New.
+ (open_target): Adjust to use target_factories.
+ (add_target_with_completer): Rename to ...
+ (add_target): ... this. Change prototype. Register target_info
+ and open callback in target_factories. Register target_info in
+ command context instead of target_ops.
+ (add_target): Delete old implementation.
+ (add_deprecated_target_alias): Change prototype. Adjust.
+ (the_native_target): New.
+ (set_native_target, get_native_target): New.
+ (find_default_run_target): Use the_native_target.
+ (find_attach_target, find_run_target): Simplify.
+ (target_ops::open): Delete.
+ (dummy_target_info): New.
+ (dummy_target::shortname, dummy_target::longname)
+ (dummy_target::doc): Delete.
+ (dummy_target::info): New.
+ (debug_target::shortname, debug_target::longname)
+ (debug_target::doc): Delete.
+ (debug_target::info): New.
+ * target.h (struct target_info): New.
+ (target_ops::~target_ops): Add comment.
+ (target_ops::info): New.
+ (target_ops::shortname, target_ops::longname, target_ops::doc): No
+ longer virtual. Implement in terms of target_info.
+ (set_native_target, get_native_target): Declare.
+ (target_open_ftype): New.
+ (add_target, add_target_with_completer)
+ (add_deprecated_target_alias): Change prototype.
+ (test_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ * tilegx-linux-nat.c (_initialize_tile_linux_nat): Use
+ add_inf_child_target.
+ * tracefile-tfile.c (tfile_target_info): New.
+ (tfile_target) <shortname, longname, doc>: Delete.
+ <info>: New.
+ (tfile_target::open): Rename to ...
+ (tfile_target_open): ... this.
+ (_initialize_tracefile_tfile): Adjust.
+ * vax-bsd-nat.c (_initialize_vaxbsd_nat): Use
+ add_inf_child_target.
+ * windows-nat.c (_initialize_windows_nat): Use
+ add_inf_child_target.
+ * xtensa-linux-nat.c (_initialize_xtensa_linux_nat): Use
+ add_inf_child_target.
+
2018-05-02 Pedro Alves <palves@redhat.com>
* linux-nat.h (linux_nat_target) <low_new_thread,
void
_initialize_aarch64_fbsd_nat (void)
{
- add_target (&the_aarch64_fbsd_nat_target);
+ add_inf_child_target (&the_aarch64_fbsd_nat_target);
}
void
_initialize_aarch64_linux_nat (void)
{
- struct target_ops *t = &the_aarch64_linux_nat_target;
-
add_show_debug_regs_command ();
/* Register the target. */
linux_target = &the_aarch64_linux_nat_target;
- add_target (t);
+ add_inf_child_target (&the_aarch64_linux_nat_target);
}
/* This module's target-specific operations, active while pd_able is true. */
+static const target_info aix_thread_target_info = {
+ "aix-threads",
+ N_("AIX pthread support"),
+ N_("AIX pthread support")
+};
+
class aix_thread_target final : public target_ops
{
public:
aix_thread_target ()
{ to_stratum = thread_stratum; }
- const char *shortname () override
- { return "aix-threads"; }
- const char *longname () override
- { return _("AIX pthread support"); }
- const char *doc () override
- { return _("AIX pthread support"); }
+ const target_info &info () const override
+ { return aix_thread_target_info; }
void detach (inferior *, int) override;
void resume (ptid_t, int, enum gdb_signal) override;
void
_initialize_alphabsd_nat (void)
{
- add_target (&the_alpha_bsd_nat_target);
+ add_inf_child_target (&the_alpha_bsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (alphabsd_supply_pcb);
_initialize_alpha_linux_nat (void)
{
linux_target = &the_alpha_linux_nat_target;
- add_target (&the_alpha_linux_nat_target);
+ add_inf_child_target (&the_alpha_linux_nat_target);
}
amd64_native_gregset32_reg_offset = amd64fbsd32_r_reg_offset;
amd64_native_gregset64_reg_offset = amd64fbsd64_r_reg_offset;
- add_target (&the_amd64_fbsd_nat_target);
+ add_inf_child_target (&the_amd64_fbsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (amd64fbsd_supply_pcb);
linux_target = &the_amd64_linux_nat_target;
/* Add the target. */
- add_target (linux_target);
+ add_inf_child_target (linux_target);
}
amd64_native_gregset32_num_regs = ARRAY_SIZE (amd64nbsd32_r_reg_offset);
amd64_native_gregset64_reg_offset = amd64nbsd_r_reg_offset;
- add_target (&the_amd64_nbsd_nat_target);
+ add_inf_child_target (&the_amd64_nbsd_nat_target);
}
amd64_native_gregset32_num_regs = ARRAY_SIZE (amd64obsd32_r_reg_offset);
amd64_native_gregset64_reg_offset = amd64obsd_r_reg_offset;
- add_target (&the_amd64_obsd_nat_target);
+ add_inf_child_target (&the_amd64_obsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (amd64obsd_supply_pcb);
void
_initialize_arm_fbsd_nat (void)
{
- add_target (&the_arm_fbsd_nat_target);
+ add_inf_child_target (&the_arm_fbsd_nat_target);
}
void
_initialize_arm_linux_nat (void)
{
- target_ops *t = &the_arm_linux_nat_target;
-
/* Register the target. */
linux_target = &the_arm_linux_nat_target;
- add_target (t);
+ add_inf_child_target (&the_arm_linux_nat_target);
}
void
_initialize_arm_netbsd_nat (void)
{
- add_target (&the_arm_netbsd_nat_target);
+ add_inf_child_target (&the_arm_netbsd_nat_target);
deprecated_add_core_fns (&arm_netbsd_elfcore_fns);
}
#include "gdb_bfd.h"
/* A target that wraps a BFD. */
+
+static const target_info target_bfd_target_info = {
+ "bfd",
+ N_("BFD backed target"),
+ N_("You should never see this")
+};
+
class target_bfd : public target_ops
{
public:
explicit target_bfd (struct bfd *bfd);
~target_bfd () override;
- const char *shortname () override
- { return "bfd"; }
-
- const char *longname () override
- { return _("BFD backed target"); }
-
- const char *doc () override
- { return _("You should never see this"); }
+ const target_info &info () const override
+ { return target_bfd_target_info; }
void close () override;
/* The libkvm target. */
+static const target_info bsd_kvm_target_info = {
+ "kvm",
+ N_("Kernel memory interface"),
+ N_("Use a kernel virtual memory image as a target.\n\
+Optionally specify the filename of a core dump.")
+};
+
class bsd_kvm_target final : public target_ops
{
public:
bsd_kvm_target ()
{ this->to_stratum = process_stratum; }
- const char *shortname () override
- { return "kvm"; }
-
- const char *longname () override
- { return _("Kernel memory interface"); }
-
- const char *doc () override
- {
- return _("Use a kernel virtual memory image as a target.\n\
-Optionally specify the filename of a core dump.");
- }
+ const target_info &info () const override
+ { return bsd_kvm_target_info; }
- void open (const char *, int) override;
void close () override;
void fetch_registers (struct regcache *, int) override;
static bsd_kvm_target bsd_kvm_ops;
static void
-bsd_kvm_target::open (const char *arg, int from_tty)
+bsd_kvm_target_open (const char *arg, int from_tty)
{
char errbuf[_POSIX2_LINE_MAX];
char *execfile = NULL;
gdb_assert (bsd_kvm_supply_pcb == NULL);
bsd_kvm_supply_pcb = supply_pcb;
- add_target (&bsd_kvm_ops);
+ add_target (bsd_kvm_target_info, bsd_kvm_target_open);
add_prefix_cmd ("kvm", class_obscure, bsd_kvm_cmd, _("\
Generic command for manipulating the kernel memory interface."),
#include "bsd-uthread.h"
+static const target_info bsd_uthread_target_info = {
+ "bsd-uthreads",
+ N_("BSD user-level threads"),
+ N_("BSD user-level threads")
+};
+
struct bsd_uthread_target final : public target_ops
{
bsd_uthread_target ()
{ to_stratum = thread_stratum; }
- const char *shortname () override
- { return "bsd-uthreads"; }
-
- const char *longname () override
- { return _("BSD user-level threads"); }
-
- const char *doc () override
- { return _("BSD user-level threads"); }
+ const target_info &info () const override
+ { return bsd_uthread_target_info; }
void close () override;
{
dont_repeat (); /* Either way, seems bogus. */
- gdb_assert (the_core_target != NULL);
-
if (!filename)
- the_core_target->detach (current_inferior (), from_tty);
+ {
+ gdb_assert (the_core_target != NULL);
+
+ the_core_target->detach (current_inferior (), from_tty);
+ }
else
- the_core_target->open (filename, from_tty);
+ core_target_open (filename, from_tty);
}
\f
/* The core file target. */
+static const target_info core_target_info = {
+ "core",
+ N_("Local core dump file"),
+ N_("Use a core file as a target. Specify the filename of the core file.")
+};
+
class core_target final : public target_ops
{
public:
core_target ()
{ to_stratum = process_stratum; }
- const char *shortname () override
- { return "core"; }
-
- const char *longname () override
- { return _("Local core dump file"); }
+ const target_info &info () const override
+ { return core_target_info; }
- const char *doc () override
- {
- return _("\
-Use a core file as a target. Specify the filename of the core file.");
- }
-
- void open (const char *, int) override;
void close () override;
void detach (inferior *, int) override;
void fetch_registers (struct regcache *, int) override;
inferior_ptid = ptid; /* Yes, make it current. */
}
-/* This routine opens and sets up the core file bfd. */
+/* See gdbcore.h. */
void
-core_target::open (const char *arg, int from_tty)
+core_target_open (const char *arg, int from_tty)
{
const char *p;
int siggy;
the_core_target->longname ());
the_core_target = &core_ops;
- add_target_with_completer (&core_ops, filename_completer);
+ add_target (core_target_info, core_target_open, filename_completer);
}
/* The CTF target. */
+static const target_info ctf_target_info = {
+ "ctf",
+ N_("CTF file"),
+ N_("(Use a CTF directory as a target.\n\
+Specify the filename of the CTF directory.")
+};
+
class ctf_target final : public tracefile_target
{
public:
- const char *shortname () override
- { return "ctf"; }
-
- const char *longname () override
- { return _("CTF file"); }
+ const target_info &info () const override
+ { return ctf_target_info; }
- const char *doc () override
- {
- return _("\
-Use a CTF directory as a target.\n\
-Specify the filename of the CTF directory.");
- }
-
- void open (const char *, int) override;
void close () override;
void fetch_registers (struct regcache *, int) override;
enum target_xfer_status xfer_partial (enum target_object object,
definitions from the first packet. Set the start position at the
second packet which contains events on trace blocks. */
-void
-ctf_target::open (const char *dirname, int from_tty)
+static void
+ctf_target_open (const char *dirname, int from_tty)
{
struct bt_ctf_event *event;
uint32_t event_id;
_initialize_ctf (void)
{
#if HAVE_LIBBABELTRACE
- add_target_with_completer (&ctf_ops, filename_completer);
+ add_target (ctf_target_info, ctf_target_open, filename_completer);
#endif
}
void (*deprecated_file_changed_hook) (const char *);
+static const target_info exec_target_info = {
+ "exec",
+ N_("Local exec file"),
+ N_("Use an executable file as a target.\n\
+Specify the filename of the executable file.")
+};
+
/* The target vector for executable files. */
struct exec_target final : public target_ops
exec_target ()
{ to_stratum = file_stratum; }
- const char *shortname () override
- { return "exec"; }
-
- const char *longname () override
- { return _("Local exec file"); }
+ const target_info &info () const override
+ { return exec_target_info; }
- const char *doc () override
- {
- return _("\
-Use an executable file as a target.\n\
-Specify the filename of the executable file.");
- }
-
- void open (const char *, int) override;
void close () override;
enum target_xfer_status xfer_partial (enum target_object object,
const char *annex,
}
-void
-exec_target::open (const char *args, int from_tty)
+static void
+exec_target_open (const char *args, int from_tty)
{
target_preopen (from_tty);
exec_file_attach (args, from_tty);
show_write_files,
&setlist, &showlist);
- add_target_with_completer (&exec_ops, filename_completer);
+ add_target (exec_target_info, exec_target_open, filename_completer);
}
extern int write_files;
+/* Open and set up the core file bfd. */
+
+extern void core_target_open (const char *arg, int from_tty);
+
extern void core_file_command (const char *filename, int from_tty);
extern void exec_file_attach (const char *filename, int from_tty);
x86_dr_low.get_addr = go32_get_dr;
x86_set_debug_register_length (4);
- add_target (&the_go32_nat_target);
+ add_inf_child_target (&the_go32_nat_target);
/* Initialize child's cwd as empty to be initialized when starting
the child. */
{
/* Register the target. */
linux_target = &the_hppa_linux_nat_target;
- add_target (&the_hppa_linux_nat_target);
+ add_inf_child_target (&the_hppa_linux_nat_target);
}
void
_initialize_hppanbsd_nat (void)
{
- add_target (&the_hppa_nbsd_nat_target);
+ add_inf_child_target (&the_hppa_nbsd_nat_target);
}
void
_initialize_hppaobsd_nat (void)
{
- add_target (&the_hppa_obsd_nat_target);
+ add_inf_child_target (&the_hppa_obsd_nat_target);
}
x86_set_debug_register_length (4);
#endif
- add_target (&darwin_target);
+ add_inf_child_target (&darwin_target);
}
void
_initialize_i386fbsd_nat (void)
{
- add_target (&the_i386_fbsd_nat_target);
+ add_inf_child_target (&the_i386_fbsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (i386fbsd_supply_pcb);
#endif /* i386_DEBUG_STATE */
/* Register the target. */
- add_target (&the_i386_gnu_nat_target);
+ add_inf_child_target (&the_i386_gnu_nat_target);
}
linux_target = &the_i386_linux_nat_target;
/* Add the target. */
- add_target (linux_target);
+ add_inf_child_target (linux_target);
}
void
_initialize_i386nbsd_nat (void)
{
- add_target (&the_i386_nbsd_nat_target);
+ add_inf_child_target (&the_i386_nbsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (i386nbsd_supply_pcb);
void
_initialize_i386obsd_nat (void)
{
- add_target (&i386_obsd_nat_target);
+ add_inf_child_target (&i386_obsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (i386obsd_supply_pcb);
void
_initialize_ia64_linux_nat (void)
{
- struct target_ops *t = &the_ia64_linux_nat_target;
-
/* Register the target. */
linux_target = &the_ia64_linux_nat_target;
- add_target (t);
+ add_inf_child_target (&the_ia64_linux_nat_target);
}
#include <fcntl.h>
#include <unistd.h>
+static const target_info inf_child_target_info = {
+ "native",
+ N_("Native process"),
+ N_("Native process (started by the \"run\" command).")
+};
+
+const target_info &
+inf_child_target::info () const
+{
+ return inf_child_target_info;
+}
+
/* Helper function for child_wait and the derivatives of child_wait.
HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
translation of that in OURSTATUS. */
/* See inf-child.h. */
void
-inf_child_open_target (struct target_ops *target, const char *arg,
- int from_tty)
+inf_child_open_target (const char *arg, int from_tty)
{
+ target_ops *target = get_native_target ();
+
+ /* There's always only ever one native target, and if we get here,
+ it better be an inf-child target. */
+ gdb_assert (dynamic_cast<inf_child_target *> (target) != NULL);
+
target_preopen (from_tty);
push_target (target);
inf_child_explicitly_opened = 1;
printf_filtered ("Done. Use the \"run\" command to start a process.\n");
}
-void
-inf_child_target::open (const char *arg, int from_tty)
-{
- inf_child_open_target (this, arg, from_tty);
-}
-
/* Implement the to_disconnect target_ops method. */
void
{
this->to_stratum = process_stratum;
}
+
+/* See inf-child.h. */
+
+void
+add_inf_child_target (inf_child_target *target)
+{
+ set_native_target (target);
+ add_target (inf_child_target_info, inf_child_open_target);
+}
inf_child_target ();
~inf_child_target () override = 0;
- const char *shortname () override
- { return "native"; }
+ const target_info &info () const override;
- const char *longname () override
- { return _("Native process"); }
-
- const char *doc () override
- { return _("Native process (started by the \"run\" command)."); }
-
- void open (const char *arg, int from_tty) override;
void close () override;
void disconnect (const char *, int) override;
/* This is for native targets which use a unix/POSIX-style waitstatus. */
extern void store_waitstatus (struct target_waitstatus *, int);
+/* Register TARGET as native target and set it up to respond to the
+ "target native" command. */
+extern void add_inf_child_target (inf_child_target *target);
+
+/* target_open_ftype callback for inf-child targets. Used by targets
+ that want to register an alternative target_info object. Most
+ targets use add_inf_child_target instead. */
+extern void inf_child_open_target (const char *arg, int from_tty);
+
#endif
of the ptid_t prevents thread IDs changing when libpthread is
loaded or unloaded. */
+static const target_info thread_db_target_info = {
+ "multi-thread",
+ N_("multi-threaded child process."),
+ N_("Threads and pthreads support.")
+};
+
class thread_db_target final : public target_ops
{
public:
thread_db_target ();
- const char *shortname () override
- { return "multi-thread"; }
- const char *longname () override
- { return _("multi-threaded child process."); }
- const char *doc () override
- { return _("Threads and pthreads support."); }
+ const target_info &info () const override
+ { return thread_db_target_info; }
void detach (inferior *, int) override;
ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
{
/* Register the target. */
linux_target = &the_m32r_linux_nat_target;
- add_target (&the_m32r_linux_nat_target);
+ add_inf_child_target (&the_m32r_linux_nat_target);
}
void
_initialize_m68kbsd_nat (void)
{
- add_target (&the_m68k_bsd_nat_target);
+ add_inf_child_target (&the_m68k_bsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (m68kbsd_supply_pcb);
{
/* Register the target. */
linux_target = &the_m68k_linux_nat_target;
- add_target (&the_m68k_linux_nat_target);
+ add_inf_child_target (&the_m68k_linux_nat_target);
}
print "{\n";
print " $name ();\n";
print "\n";
- print " const char *shortname () override;\n";
- print " const char *longname () override;\n";
- print " const char *doc () override;\n";
+ print " const target_info &info () const override;\n";
print "\n";
for $name (@delegators) {
void
_initialize_mips_fbsd_nat (void)
{
- add_target (&the_mips_fbsd_nat_target);
+ add_inf_child_target (&the_mips_fbsd_nat_target);
}
&maintenance_show_cmdlist);
linux_target = &the_mips_linux_nat_target;
- add_target (&the_mips_linux_nat_target);
+ add_inf_child_target (&the_mips_linux_nat_target);
}
void
_initialize_mipsnbsd_nat (void)
{
- add_target (&the_mips_nbsd_nat_target);
+ add_inf_child_target (&the_mips_nbsd_nat_target);
}
void
_initialize_mips64obsd_nat (void)
{
- add_target (&the_mips64_obsd_nat_target);
+ add_inf_child_target (&the_mips64_obsd_nat_target);
}
};
/* For "target native". */
-struct nto_procfs_target_native final : public nto_procfs_target
-{
- /* Leave shortname as "native". */
- const char *longname () override
- { return _("QNX Neutrino local process"); }
+static const target_info nto_native_target_info = {
+ "native",
+ N_("QNX Neutrino local process"),
+ N_("QNX Neutrino local process (started by the \"run\" command).")
+};
- const char *doc () override
- { return _("QNX Neutrino local process (started by the \"run\" command)."); }
+class nto_procfs_target_native final : public nto_procfs_target
+{
+ const target_info &info () const override
+ { return nto_native_target_info; }
};
/* For "target procfs <node>". */
-struct nto_procfs_target_procfs final : public nto_procfs_target
-{
- const char *shortname () override
- { return "procfs"; }
- const char *longname () override
- { return _("QNX Neutrino local or remote process"); }
+static const target_info nto_procfs_target_info = {
+ "procfs",
+ N_("QNX Neutrino local or remote process"),
+ N_("QNX Neutrino process. target procfs <node>")
+};
- const char *doc () override
- { return _("QNX Neutrino process. target procfs <node>"); }
+struct nto_procfs_target_procfs final : public nto_procfs_target
+{
+ const target_info &info () const override
+ { return nto_procfs_target_info; }
};
static ptid_t do_attach (ptid_t ptid);
init_procfs_targets (void)
{
/* Register "target native". This is the default run target. */
- add_target (&nto_native_ops);
+ add_target (nto_native_target_info, inf_child_open_target);
+ set_native_target (&nto_native_ops);
/* Register "target procfs <node>". */
- add_target (&nto_procfs_ops);
+ add_target (nto_procfs_target_info, inf_child_open_target);
}
#define OSTYPE_NTO 1
void
_initialize_ppcfbsd_nat (void)
{
- add_target (&the_ppc_fbsd_nat_target);
+ add_inf_child_target (&the_ppc_fbsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (ppcfbsd_supply_pcb);
gdb::observers::thread_exit.attach (ppc_linux_thread_exit);
/* Register the target. */
- add_target (linux_target);
+ add_inf_child_target (linux_target);
}
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (ppcnbsd_supply_pcb);
- add_target (&the_ppc_nbsd_nat_target);
+ add_inf_child_target (&the_ppc_nbsd_nat_target);
}
void
_initialize_ppcobsd_nat (void)
{
- add_target (&the_ppc_obsd_nat_target);
+ add_inf_child_target (&the_ppc_obsd_nat_target);
/* General-purpose registers. */
ppcobsd_reg_offsets.r0_offset = offsetof (struct reg, gpr);
static const char ravenscar_runtime_initializer[] =
"system__bb__threads__initialize";
+static const target_info ravenscar_target_info = {
+ "ravenscar",
+ N_("Ravenscar tasks."),
+ N_("Ravenscar tasks support.")
+};
+
struct ravenscar_thread_target final : public target_ops
{
ravenscar_thread_target ()
{ to_stratum = thread_stratum; }
- const char *shortname () override
- { return "ravenscar"; }
-
- const char *longname () override
- { return _("Ravenscar tasks."); }
-
- const char *doc () override
- { return _("Ravenscar tasks support."); }
+ const target_info &info () const override
+ { return ravenscar_target_info; }
ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
void resume (ptid_t, int, enum gdb_signal) override;
#include "vec.h"
#include <algorithm>
+static const target_info record_btrace_target_info = {
+ "record-btrace",
+ N_("Branch tracing target"),
+ N_("Collect control-flow trace and provide the execution history.")
+};
+
/* The target_ops of record-btrace. */
class record_btrace_target final : public target_ops
record_btrace_target ()
{ to_stratum = record_stratum; }
- const char *shortname () override
- { return "record-btrace"; }
-
- const char *longname () override
- { return _("Branch tracing target"); }
+ const target_info &info () const override
+ { return record_btrace_target_info; }
- const char *doc () override
- { return _("Collect control-flow trace and provide the execution history."); }
-
- void open (const char *, int) override;
void close () override;
void async (int) override;
std::forward_list<thread_info *> m_threads;
};
-/* The open method of target record-btrace. */
+/* Open target record-btrace. */
-void
-record_btrace_target::open (const char *args, int from_tty)
+static void
+record_btrace_target_open (const char *args, int from_tty)
{
/* If we fail to enable btrace for one thread, disable it for the threads for
which it was successfully enabled. */
&set_record_btrace_pt_cmdlist,
&show_record_btrace_pt_cmdlist);
- add_target (&record_btrace_ops);
+ add_target (record_btrace_target_info, record_btrace_target_open);
bfcache = htab_create_alloc (50, bfcache_hash, bfcache_eq, NULL,
xcalloc, xfree);
than count of insns presently in execution log). */
static ULONGEST record_full_insn_count;
+static const char record_longname[]
+ = N_("Process record and replay target");
+static const char record_doc[]
+ = N_("Log program while executing and replay execution from log.");
+
/* Base class implementing functionality common to both the
"record-full" and "record-core" targets. */
record_full_base_target ()
{ to_stratum = record_stratum; }
- const char *shortname () override = 0;
-
- const char *longname () override
- { return _("Process record and replay target"); }
-
- const char *doc () override
- { return _("Log program while executing and replay execution from log."); }
+ const target_info &info () const override = 0;
- void open (const char *, int) override;
void close () override;
void async (int) override;
ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
/* The "record-full" target. */
+static const target_info record_full_target_info = {
+ "record-full",
+ record_longname,
+ record_doc,
+};
+
class record_full_target final : public record_full_base_target
{
public:
- const char *shortname () override
- { return "record-full"; }
+ const target_info &info () const override
+ { return record_full_target_info; }
void commit_resume () override;
void resume (ptid_t, int, enum gdb_signal) override;
/* The "record-core" target. */
+static const target_info record_full_core_target_info = {
+ "record-core",
+ record_longname,
+ record_doc,
+};
+
class record_full_core_target final : public record_full_base_target
{
public:
- const char *shortname () override
- { return "record-core"; }
+ const target_info &info () const override
+ { return record_full_core_target_info; }
void resume (ptid_t, int, enum gdb_signal) override;
void disconnect (const char *, int) override;
inferior_event_handler (INF_REG_EVENT, NULL);
}
-/* Open the process record target. */
+/* Open the process record target for 'core' files. */
static void
record_full_core_open_1 (const char *name, int from_tty)
record_full_restore ();
}
-/* "open" target method for 'live' processes. */
+/* Open the process record target for 'live' processes. */
static void
record_full_open_1 (const char *name, int from_tty)
static void record_full_init_record_breakpoints (void);
-/* "open" target method. Open the process record target. */
+/* Open the process record target. */
-void
-record_full_base_target::open (const char *name, int from_tty)
+static void
+record_full_open (const char *name, int from_tty)
{
if (record_debug)
fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
cmd_record_full_restore (const char *args, int from_tty)
{
core_file_command (args, from_tty);
- record_full_ops.open (args, from_tty);
+ record_full_open (args, from_tty);
}
/* Save the execution log to a file. We use a modified elf corefile
record_full_first.next = NULL;
record_full_first.type = record_full_end;
- add_target (&record_full_ops);
- add_deprecated_target_alias (&record_full_ops, "record");
- add_target (&record_full_core_ops);
+ add_target (record_full_target_info, record_full_open);
+ add_deprecated_target_alias (record_full_target_info, "record");
+ add_target (record_full_core_target_info, record_full_open);
add_prefix_cmd ("full", class_obscure, cmd_record_full_start,
_("Start full execution recording."), &record_full_cmdlist,
sim_* are the interface to the simulator (see remote-sim.h).
gdbsim_* are stuff which is internal to gdb. */
+static const target_info gdbsim_target_info = {
+ "sim",
+ N_("simulator"),
+ N_("Use the compiled-in simulator.")
+};
+
struct gdbsim_target final
: public memory_breakpoint_target<target_ops>
{
gdbsim_target ()
{ to_stratum = process_stratum; }
- const char *shortname () override
- { return "sim"; }
-
- const char *longname () override
- { return _("simulator"); }
+ const target_info &info () const override
+ { return gdbsim_target_info; }
- const char *doc () override
- { return _("Use the compiled-in simulator."); }
-
- void open (const char *, int) override;
void close () override;
void detach (inferior *inf, int) override;
Targets should supply this routine, if only to provide an error message. */
/* Called when selecting the simulator. E.g. (gdb) target sim name. */
-void
-gdbsim_target::open (const char *args, int from_tty)
+static void
+gdbsim_target_open (const char *args, int from_tty)
{
int len;
char *arg_buf;
{
struct cmd_list_element *c;
- add_target (&gdbsim_ops);
+ add_target (gdbsim_target_info, gdbsim_target_open);
c = add_com ("sim", class_obscure, simulator_command,
_("Send a command to the simulator."));
/* The remote target. */
+static const char remote_doc[] = N_("\
+Use a remote computer via a serial line, using a gdb-specific protocol.\n\
+Specify the serial device it is connected to\n\
+(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
+
+static const target_info remote_target_info = {
+ "remote",
+ N_("Remote serial target in gdb-specific protocol"),
+ remote_doc
+};
+
class remote_target : public target_ops
{
public:
to_stratum = process_stratum;
}
- const char *shortname () override
- { return "remote"; }
-
- const char *longname () override
- { return _("Remote serial target in gdb-specific protocol"); }
-
- const char *doc () override
- {
- return _("\
-Use a remote computer via a serial line, using a gdb-specific protocol.\n\
-Specify the serial device it is connected to\n\
-(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
- }
+ const target_info &info () const override
+ { return remote_target_info; }
thread_control_capabilities get_thread_control_capabilities () override
{ return tc_schedlock; }
- void open (const char *, int) override;
+ /* Open a remote connection. */
+ static void open (const char *, int);
+
void close () override;
void detach (inferior *, int) override;
enum exec_direction_kind execution_direction () override;
protected:
- void open_1 (const char *name, int from_tty, int extended_p);
+ static void open_1 (const char *name, int from_tty, int extended_p);
void start_remote (int from_tty, int extended_p);
};
+static const target_info extended_remote_target_info = {
+ "extended-remote",
+ N_("Extended remote serial target in gdb-specific protocol"),
+ remote_doc
+};
+
/* Set up the extended remote target by extending the standard remote
target and adding to it. */
class extended_remote_target final : public remote_target
{
public:
- const char *shortname () override
- { return "extended-remote"; }
+ const target_info &info () const override
+ { return extended_remote_target_info; }
- const char *longname () override
- { return _("Extended remote serial target in gdb-specific protocol"); }
-
- void open (const char *, int) override;
+ /* Open an extended-remote connection. */
+ static void open (const char *, int);
bool can_create_inferior () override { return true; }
void create_inferior (const char *, const std::string &,
puts_filtered (name);
puts_filtered ("\n");
}
- push_target (this); /* Switch to using remote target now. */
+
+ remote_target *target
+ = extended_p ? &extended_remote_ops : &remote_ops;
+ push_target (target); /* Switch to using remote target now. */
/* Register extra event sources in the event loop. */
remote_async_inferior_event_token
TRY
{
- start_remote (from_tty, extended_p);
+ target->start_remote (from_tty, extended_p);
}
CATCH (ex, RETURN_MASK_ALL)
{
time. */
remote_state = new_remote_state ();
- add_target (&remote_ops);
- add_target (&extended_remote_ops);
+ add_target (remote_target_info, remote_target::open);
+ add_target (extended_remote_target_info, extended_remote_target::open);
/* Hook into new objfile notification. */
gdb::observers::new_objfile.attach (remote_new_objfile);
void
_initialize_rs6000_nat (void)
{
- add_target (&the_rs6000_nat_target);
+ add_inf_child_target (&the_rs6000_nat_target);
}
void
_initialize_s390_nat (void)
{
- struct target_ops *t = &the_s390_linux_nat_target;
-
/* Register the target. */
linux_target = &the_s390_linux_nat_target;
- add_target (t);
+ add_inf_child_target (&the_s390_linux_nat_target);
/* A maintenance command to enable showing the PER state. */
add_setshow_boolean_cmd ("show-debug-regs", class_maintenance,
void
_initialize_shnbsd_nat (void)
{
- add_target (&the_sh_nbsd_nat_target);
+ add_inf_child_target (&the_sh_nbsd_nat_target);
}
#include "minsyms.h"
#include "objfiles.h"
+static const target_info thread_db_target_info = {
+ "solaris-threads",
+ N_("Solaris threads and pthread."),
+ N_("Solaris threads and pthread support.")
+};
+
class sol_thread_target final : public target_ops
{
public:
sol_thread_target ()
{ this->to_stratum = thread_stratum; }
- const char *shortname () override
- { return "solaris-threads"; }
- const char *longname () override
- { return _("Solaris threads and pthread."); }
- const char *doc () override
- { return _("Solaris threads and pthread support."); }
+ const target_info &info () const override
+ { return thread_db_target_info; }
void detach (inferior *, int) override;
ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
/* Register the target. */
linux_target = &the_sparc_linux_nat_target;
- add_target (&the_sparc_linux_nat_target);
+ add_inf_child_target (&the_sparc_linux_nat_target);
}
sparc_gregmap = &sparc32nbsd_gregmap;
sparc_fpregmap = &sparc32_bsd_fpregmap;
- add_target (&sparc_nbsd_nat_target);
+ add_inf_child_target (&sparc_nbsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (sparc32nbsd_supply_pcb);
void
_initialize_sparc64fbsd_nat (void)
{
- struct target_ops *t;
-
- add_target (&the_sparc64_fbsd_nat_target);
+ add_inf_child_target (&the_sparc64_fbsd_nat_target);
sparc_gregmap = &sparc64fbsd_gregmap;
void
_initialize_sparc64_linux_nat (void)
{
- target_ops *t = &the_sparc64_linux_nat_target;
-
sparc_fpregmap = &sparc64_bsd_fpregmap;
/* Register the target. */
linux_target = &the_sparc64_linux_nat_target;
- add_target (t);
+ add_inf_child_target (&the_sparc64_linux_nat_target);
sparc_gregmap = &sparc64_linux_ptrace_gregmap;
}
sparc_gregset_supplies_p = sparc64nbsd_gregset_supplies_p;
sparc_fpregset_supplies_p = sparc64nbsd_fpregset_supplies_p;
- add_target (&the_sparc64_nbsd_nat_target);
+ add_inf_child_target (&the_sparc64_nbsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (sparc64nbsd_supply_pcb);
sparc_fpregmap = &sparc64_bsd_fpregmap;
/* Add some extra features to the generic SPARC target. */
- add_target (&the_sparc64_obsd_nat_target);
+ add_inf_child_target (&the_sparc64_obsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (sparc64obsd_supply_pcb);
void
_initialize_spu_nat (void)
{
- add_target (&the_spu_linux_nat_target);
+ add_inf_child_target (&the_spu_linux_nat_target);
}
/* The SPU multi-architecture support target. */
+static const target_info spu_multiarch_target_info = {
+ "spu",
+ N_("SPU multi-architecture support."),
+ N_("SPU multi-architecture support.")
+};
+
struct spu_multiarch_target final : public target_ops
{
spu_multiarch_target ()
{ to_stratum = arch_stratum; };
- const char *shortname () override
- { return "spu"; }
-
- const char *longname () override
- { return _("SPU multi-architecture support."); }
-
- const char *doc () override
- { return _("SPU multi-architecture support."); }
+ const target_info &info () const override
+ { return spu_multiarch_target_info; }
void mourn_inferior () override;
{
dummy_target ();
- const char *shortname () override;
- const char *longname () override;
- const char *doc () override;
+ const target_info &info () const override;
void post_attach (int arg0) override;
void detach (inferior *arg0, int arg1) override;
{
debug_target ();
- const char *shortname () override;
- const char *longname () override;
- const char *doc () override;
+ const target_info &info () const override;
void post_attach (int arg0) override;
void detach (inferior *arg0, int arg1) override;
#include "byte-vector.h"
#include "terminal.h"
#include <algorithm>
+#include <unordered_map>
static void generic_tls_error (void) ATTRIBUTE_NORETURN;
static enum exec_direction_kind default_execution_direction
(struct target_ops *self);
-/* Vector of existing target structures. */
-typedef struct target_ops *target_ops_p;
-DEF_VEC_P (target_ops_p);
-static VEC (target_ops_p) *target_structs;
+/* Mapping between target_info objects (which have address identity)
+ and corresponding open/factory function/callback. Each add_target
+ call adds one entry to this map, and registers a "target
+ TARGET_NAME" command that when invoked calls the factory registered
+ here. The target_info object is associated with the command via
+ the command's context. */
+static std::unordered_map<const target_info *, target_open_ftype *>
+ target_factories;
/* The initial current target, so that there is always a semi-valid
current target. */
gdb_stdout);
}
+#if GDB_SELF_TEST
+namespace selftests {
+
+/* A mock process_stratum target_ops that doesn't read/write registers
+ anywhere. */
+
+static const target_info test_target_info = {
+ "test",
+ N_("unit tests target"),
+ N_("You should never see this"),
+};
+
+const target_info &
+test_target_ops::info () const
+{
+ return test_target_info;
+}
+
+} /* namespace selftests */
+#endif /* GDB_SELF_TEST */
+
/* Default target_has_* methods for process_stratum targets. */
int
static void
open_target (const char *args, int from_tty, struct cmd_list_element *command)
{
- struct target_ops *ops = (struct target_ops *) get_cmd_context (command);
+ auto *ti = static_cast<target_info *> (get_cmd_context (command));
+ target_open_ftype *func = target_factories[ti];
if (targetdebug)
- fprintf_unfiltered (gdb_stdlog, "-> %s->to_open (...)\n",
- ops->shortname ());
+ fprintf_unfiltered (gdb_stdlog, "-> %s->open (...)\n",
+ ti->shortname);
- ops->open (args, from_tty);
+ func (args, from_tty);
if (targetdebug)
- fprintf_unfiltered (gdb_stdlog, "<- %s->to_open (%s, %d)\n",
- ops->shortname (), args, from_tty);
+ fprintf_unfiltered (gdb_stdlog, "<- %s->open (%s, %d)\n",
+ ti->shortname, args, from_tty);
}
-/* Add possible target architecture T to the list and add a new
- command 'target T->shortname ()'. Set COMPLETER as the command's
- completer if not NULL. */
+/* See target.h. */
void
-add_target_with_completer (struct target_ops *t,
- completer_ftype *completer)
+add_target (const target_info &t, target_open_ftype *func,
+ completer_ftype *completer)
{
struct cmd_list_element *c;
- VEC_safe_push (target_ops_p, target_structs, t);
+ auto &func_slot = target_factories[&t];
+ if (func_slot != nullptr)
+ internal_error (__FILE__, __LINE__,
+ _("target already added (\"%s\")."), t.shortname);
+ func_slot = func;
if (targetlist == NULL)
add_prefix_cmd ("target", class_run, target_command, _("\
information on the arguments for a particular protocol, type\n\
`help target ' followed by the protocol name."),
&targetlist, "target ", 0, &cmdlist);
- c = add_cmd (t->shortname (), no_class, t->doc (), &targetlist);
+ c = add_cmd (t.shortname, no_class, t.doc, &targetlist);
+ set_cmd_context (c, (void *) &t);
set_cmd_sfunc (c, open_target);
- set_cmd_context (c, t);
if (completer != NULL)
set_cmd_completer (c, completer);
}
-/* Add a possible target architecture to the list. */
-
-void
-add_target (struct target_ops *t)
-{
- add_target_with_completer (t, NULL);
-}
-
/* See target.h. */
void
-add_deprecated_target_alias (struct target_ops *t, const char *alias)
+add_deprecated_target_alias (const target_info &tinfo, const char *alias)
{
struct cmd_list_element *c;
char *alt;
/* If we use add_alias_cmd, here, we do not get the deprecated warning,
see PR cli/15104. */
- c = add_cmd (alias, no_class, t->doc (), &targetlist);
+ c = add_cmd (alias, no_class, tinfo.doc, &targetlist);
set_cmd_sfunc (c, open_target);
- set_cmd_context (c, t);
- alt = xstrprintf ("target %s", t->shortname ());
+ set_cmd_context (c, (void *) &tinfo);
+ alt = xstrprintf ("target %s", tinfo.shortname);
deprecate_cmd (c, alt);
}
value);
}
+/* A pointer to the target that can respond to "run" or "attach".
+ Native targets are always singletons and instantiated early at GDB
+ startup. */
+static target_ops *the_native_target;
+
+/* See target.h. */
+
+void
+set_native_target (target_ops *target)
+{
+ if (the_native_target != NULL)
+ internal_error (__FILE__, __LINE__,
+ _("native target already set (\"%s\")."),
+ the_native_target->longname ());
+
+ the_native_target = target;
+}
+
+/* See target.h. */
+
+target_ops *
+get_native_target ()
+{
+ return the_native_target;
+}
+
/* Look through the list of possible targets for a target that can
execute a run or attach command without any other data. This is
used to locate the default process stratum.
static struct target_ops *
find_default_run_target (const char *do_mesg)
{
- struct target_ops *runable = NULL;
-
- if (auto_connect_native_target)
- {
- struct target_ops *t;
- int count = 0;
- int i;
-
- for (i = 0; VEC_iterate (target_ops_p, target_structs, i, t); ++i)
- {
- if (t->can_run ())
- {
- runable = t;
- ++count;
- }
- }
-
- if (count != 1)
- runable = NULL;
- }
+ if (auto_connect_native_target && the_native_target != NULL)
+ return the_native_target;
- if (runable == NULL)
- {
- if (do_mesg)
- error (_("Don't know how to %s. Try \"help target\"."), do_mesg);
- else
- return NULL;
- }
-
- return runable;
+ if (do_mesg != NULL)
+ error (_("Don't know how to %s. Try \"help target\"."), do_mesg);
+ return NULL;
}
/* See target.h. */
struct target_ops *
find_attach_target (void)
{
- struct target_ops *t;
-
/* If a target on the current stack can attach, use it. */
- for (t = target_stack; t != NULL; t = t->beneath)
+ for (target_ops *t = target_stack; t != NULL; t = t->beneath)
{
if (t->can_attach ())
- break;
+ return t;
}
/* Otherwise, use the default run target for attaching. */
- if (t == NULL)
- t = find_default_run_target ("attach");
-
- return t;
+ return find_default_run_target ("attach");
}
/* See target.h. */
struct target_ops *
find_run_target (void)
{
- struct target_ops *t;
-
/* If a target on the current stack can run, use it. */
- for (t = target_stack; t != NULL; t = t->beneath)
+ for (target_ops *t = target_stack; t != NULL; t = t->beneath)
{
if (t->can_create_inferior ())
- break;
+ return t;
}
/* Otherwise, use the default run target. */
- if (t == NULL)
- t = find_default_run_target ("run");
-
- return t;
+ return find_default_run_target ("run");
}
bool
return aspace;
}
-void
-target_ops::open (const char *, int)
-{
- gdb_assert_not_reached ("target_ops::open called");
-}
-
void
target_ops::close ()
{
#include "target-delegates.c"
+static const target_info dummy_target_info = {
+ "None",
+ N_("None"),
+ ""
+};
+
dummy_target::dummy_target ()
{
to_stratum = dummy_stratum;
}
-const char *
-dummy_target::shortname ()
-{
- return "None";
-}
-
-const char *
-dummy_target::longname ()
-{
- return _("None");
-}
-
-const char *
-dummy_target::doc ()
-{
- return "";
-}
-
debug_target::debug_target ()
{
to_stratum = debug_stratum;
}
-const char *
-debug_target::shortname ()
+const target_info &
+dummy_target::info () const
{
- return beneath->shortname ();
+ return dummy_target_info;
}
-const char *
-debug_target::longname ()
-{
- return beneath->longname ();
-}
-
-const char *
-debug_target::doc ()
+const target_info &
+debug_target::info () const
{
- return beneath->doc ();
+ return beneath->info ();
}
\f
#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
{
struct target_ops *beneath; /* To the target under this one. */
+ /* 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 this target type. */
- virtual const char *shortname () = 0;
-
- /* 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 ()
+ { 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 ()
+ { return info ().longname; }
/* Close the target. This is where the target can handle
teardown. Heap-allocated targets should delete themselves
TARGET_DEFAULT_IGNORE ();
};
+/* 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 ();
+
/* The ops structure for our "current" target process. This should
never be NULL. If there is no target, it points to the dummy_target. */
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 *);
to_stratum = process_stratum;
}
- const char *shortname () override
- {
- return NULL;
- }
-
- const char *longname () override
- {
- return NULL;
- }
-
- const char *doc () override
- {
- return NULL;
- }
+ const target_info &info () const override;
bool has_registers () override
{
_initialize_tile_linux_nat (void)
{
linux_target = &the_tilegx_linux_nat_target;
- add_target (&the_tilegx_linux_nat_target);
+ add_inf_child_target (&the_tilegx_linux_nat_target);
}
/* The tfile target. */
+static const target_info tfile_target_info = {
+ "tfile",
+ N_("Local trace dump file"),
+ N_("Use a trace file as a target. Specify the filename of the trace file.")
+};
+
class tfile_target final : public tracefile_target
{
public:
- const char *shortname () override
- { return "tfile"; }
-
- const char *longname () override
- { return _("Local trace dump file"); }
-
- const char *doc () override
- {
- return _("\
-Use a trace file as a target. Specify the filename of the trace file.");
- }
+ const target_info &info () const override
+ { return tfile_target_info; }
- void open (const char *, int) override;
void close () override;
void fetch_registers (struct regcache *, int) override;
enum target_xfer_status xfer_partial (enum target_object object,
error (_("Premature end of file while reading trace file"));
}
-void
-tfile_target::open (const char *arg, int from_tty)
+/* Open the tfile target. */
+
+static void
+tfile_target_open (const char *arg, int from_tty)
{
int flags;
int scratch_chan;
void
_initialize_tracefile_tfile (void)
{
- add_target_with_completer (&tfile_ops, filename_completer);
+ add_target (tfile_target_info, tfile_target_open, filename_completer);
}
void
_initialize_vaxbsd_nat (void)
{
- add_target (&the_vax_bsd_nat_target);
+ add_inf_child_target (&the_vax_bsd_nat_target);
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (vaxbsd_supply_pcb);
calling x86_set_debug_register_length function
in processor windows specific native file. */
- add_target (&the_windows_nat_target);
+ add_inf_child_target (&the_windows_nat_target);
#ifdef __CYGWIN__
cygwin_internal (CW_SET_DOS_FILE_WARNING, 0);
}
linux_target = &the_xtensa_linux_nat_target;
- add_target (&the_xtensa_linux_nat_target);
+ add_inf_child_target (&the_xtensa_linux_nat_target);
}