[PATCH 00/40] C++ify target_ops, toward multi-target

classic Classic list List threaded Threaded
65 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

[PATCH 00/40] C++ify target_ops, toward multi-target

Pedro Alves-7
Here's another chunk from the multi-target branch.

This converts target_ops to a C++ class with virtual methods.

The reason this is part of the multi-target effort is that with
multi-target, we will want to be able to instantiate the remote, core,
etc. targets more than once at the same time.  In order to get there,
there are globals associated with these targets that will naturally
need to be made per-instance.  Perhaps naively, one of the first
things I did in the branch was to go ahead and convert target_ops to a
proper C++ class with virtual methods, thinking about how a C++ class
makes it easier to associate data with each instance, and also
thinking about how the current target_ops is really more the vtable
than the object, and it is preferable to avoid duplicating the whole
vtable in memory for each target instance...  In the end, I'm
convinced this paid off.

The hurdle is that doing this requires touching _every_ target in the
tree.  There's no partial transition possible.  I've worked on the
branch sitting on top of a version of this patch that only did a
partial transition, ignoring many native target_ops instances, but in
order to continue with upstreaming the multi-target work, I converted
all targets now, the best I could.  There are certainly many of native
targets here that I have no way to test.  My hope with posting this a
bit early (I'm missing some ChangeLogs) is that maybe someone will be
able to lend a hand with testing on their favorite port while I finish
that up and work through any review comments as they come.

There are actually three across-all-targets changes in this series.

  - target_ops function pointers -> virtual methods
  - target_ops use bool throughout
  - target_ops::open -> target factories (the last patch in the series)

I'm sending it all together thinking that that might save testing
rounds to those willing to lend a hand with testing.

And it goes without saying, but, testing help would be really
appreciated!

For testing and review convenience, I've pushed this to the
users/palves/target_ops-cxx branch, along with the few other related
patches that I posted this week that haven't been merged to master
yet.

The multi-target work will require at least one more round of touching
prototypes of some target methods, but I think that will be a smaller
patch (once I manage to split it cleanly from the rest of the branch).

After this, the main multi-target changes will be (in no particular
order):

 - per-inferior thread lists
 - a target stack per-inferior
 - use thread and inferior pointers more throughout instead of ptid_t
 - getting rid of more global state in the core and remote targets
 - actually instantiate multiple copies of core and remote targets
 - user interface, documentation, tests, etc.

Though that's still around 150 patches of fixes of fixes in the branch
to clean up, so it'll take a bit to get there.  Meanwhile, I'd
appreciate getting this chunk in, since it's a large burden to
maintain it off trunk.

Pedro Alves (40):
  Convert struct target_ops to C++
  make-target-delegates: line break between return type and function
    name
  target_ops/C++: exec target
  target_ops/C++: core target
  target_ops/C++: ctf/tfile targets
  target_ops/C++: spu-multiarch
  target_ops/C++: ravenscar-thread
  target_ops/C++: bsd-uthread
  target_ops/C++: bfd-target
  target_ops/C++: record targets
  target_ops/C++: remote/extended-remote targets
  target_ops/C++: target remote-sim
  target_ops/C++: GNU/Linux + x86/AMD64
  target_ops/C++: PPC/PPC64 GNU/Linux
  target_ops/C++: Solaris/procfs
  target_ops/C++: Windows targets
  target_ops/C++: macOS/Darwin target
  target_ops/C++: linux_trad_target, MIPS and Alpha GNU/Linux
  target_ops/C++: AIX target
  target_ops/C++: ARM GNU/Linux
  target_ops/C++: Aarch64 GNU/Linux
  target_ops/C++: HP-PA GNU/Linux
  target_ops/C++: IA-64 GNU/Linux
  target_ops/C++: m32r GNU/Linux
  target_ops/C++: m68k GNU/Linux
  target_ops/C++: s390 GNU/Linux
  target_ops/C++: SPARC GNU/Linux
  target_ops/C++: SPU/Linux
  target_ops/C++: Tile-Gx GNU/Linux
  target_ops/C++: Xtensa GNU/Linux
  target_ops/C++: Base FreeBSD target
  target_ops/C++: Generic i386/AMD64 BSD targets
  target_ops/C++: The rest of the BSD targets
  target_ops/C++: bsd_kvm_add_target, BSD libkvm target
  target_ops/C++: NTO/QNX, nto-procfs.c
  target_ops/C++: go32/DJGPP
  target_ops/C++: The Hurd
  target_ops: Use bool throughout
  linux_nat_target: More low methods
  target factories, target open and multiple instances of targets

 gdb/aarch64-fbsd-nat.c                             |   27 +-
 gdb/aarch64-linux-nat.c                            |  227 +-
 gdb/aix-thread.c                                   |  163 +-
 gdb/alpha-bsd-nat.c                                |   25 +-
 gdb/alpha-linux-nat.c                              |   17 +-
 gdb/amd64-bsd-nat.c                                |   24 +-
 gdb/amd64-bsd-nat.h                                |   44 +
 gdb/amd64-fbsd-nat.c                               |   26 +-
 gdb/amd64-linux-nat.c                              |   53 +-
 gdb/amd64-nat.h                                    |    5 -
 gdb/amd64-nbsd-nat.c                               |   10 +-
 gdb/amd64-obsd-nat.c                               |    6 +-
 gdb/arm-fbsd-nat.c                                 |   35 +-
 gdb/arm-linux-nat.c                                |  185 +-
 gdb/arm-nbsd-nat.c                                 |   27 +-
 gdb/auxv.c                                         |   13 +-
 gdb/auxv.h                                         |    3 +-
 gdb/avr-tdep.c                                     |    4 +-
 gdb/bfd-target.c                                   |  105 +-
 gdb/breakpoint.c                                   |    9 +-
 gdb/bsd-kvm.c                                      |  104 +-
 gdb/bsd-uthread.c                                  |  139 +-
 gdb/corefile.c                                     |   16 +-
 gdb/corelow.c                                      |  204 +-
 gdb/ctf.c                                          |  103 +-
 gdb/darwin-nat.c                                   |  146 +-
 gdb/darwin-nat.h                                   |   46 +-
 gdb/elfread.c                                      |   10 +-
 gdb/eval.c                                         |    2 +-
 gdb/exceptions.c                                   |    6 +-
 gdb/exec.c                                         |  131 +-
 gdb/fbsd-nat.c                                     |  218 +-
 gdb/fbsd-nat.h                                     |   70 +-
 gdb/frame.c                                        |    2 +-
 gdb/gdbarch-selftests.c                            |    4 +-
 gdb/gdbcore.h                                      |   10 +-
 gdb/gnu-nat.c                                      |  101 +-
 gdb/gnu-nat.h                                      |   34 +-
 gdb/gnu-v3-abi.c                                   |    2 +-
 gdb/go32-nat.c                                     |  181 +-
 gdb/hppa-linux-nat.c                               |   32 +-
 gdb/hppa-nbsd-nat.c                                |   30 +-
 gdb/hppa-obsd-nat.c                                |   25 +-
 gdb/i386-bsd-nat.c                                 |   24 +-
 gdb/i386-bsd-nat.h                                 |   22 +-
 gdb/i386-darwin-nat.c                              |   28 +-
 gdb/i386-fbsd-nat.c                                |   37 +-
 gdb/i386-gnu-nat.c                                 |   29 +-
 gdb/i386-linux-nat.c                               |   42 +-
 gdb/i386-nbsd-nat.c                                |    9 +-
 gdb/i386-obsd-nat.c                                |    5 +-
 gdb/ia64-linux-nat.c                               |  148 +-
 gdb/ia64-tdep.c                                    |    2 +-
 gdb/ia64-vms-tdep.c                                |    2 +-
 gdb/inf-child.c                                    |  327 +-
 gdb/inf-child.h                                    |  113 +-
 gdb/inf-ptrace.c                                   |  142 +-
 gdb/inf-ptrace.h                                   |   67 +-
 gdb/infcall.c                                      |    4 +-
 gdb/infcmd.c                                       |   36 +-
 gdb/infrun.c                                       |   12 +-
 gdb/linux-fork.c                                   |    2 +-
 gdb/linux-nat-trad.c                               |   54 +-
 gdb/linux-nat-trad.h                               |   24 +-
 gdb/linux-nat.c                                    |  636 +--
 gdb/linux-nat.h                                    |  217 +-
 gdb/linux-tdep.c                                   |   18 +-
 gdb/linux-thread-db.c                              |  157 +-
 gdb/m32r-linux-nat.c                               |   29 +-
 gdb/m68k-bsd-nat.c                                 |   25 +-
 gdb/m68k-linux-nat.c                               |   32 +-
 gdb/m88k-bsd-nat.c                                 |   25 +-
 gdb/make-target-delegates                          |  223 +-
 gdb/mi/mi-main.c                                   |   13 +-
 gdb/minsyms.c                                      |    4 +-
 gdb/mips-fbsd-nat.c                                |   25 +-
 gdb/mips-linux-nat.c                               |  192 +-
 gdb/mips-nbsd-nat.c                                |   25 +-
 gdb/mips64-obsd-nat.c                              |   23 +-
 gdb/nbsd-nat.c                                     |    2 +-
 gdb/nbsd-nat.h                                     |   10 +-
 gdb/nto-procfs.c                                   |  345 +-
 gdb/obsd-nat.c                                     |   32 +-
 gdb/obsd-nat.h                                     |   10 +-
 gdb/parse.c                                        |    2 +-
 gdb/ppc-fbsd-nat.c                                 |   26 +-
 gdb/ppc-linux-nat.c                                |  208 +-
 gdb/ppc-linux-tdep.c                               |   10 +-
 gdb/ppc-nbsd-nat.c                                 |   26 +-
 gdb/ppc-obsd-nat.c                                 |   26 +-
 gdb/procfs.c                                       |  316 +-
 gdb/ravenscar-thread.c                             |  240 +-
 gdb/record-btrace.c                                |  566 +--
 gdb/record-full.c                                  |  618 +--
 gdb/record.c                                       |   18 +-
 gdb/regcache.c                                     |   64 +-
 gdb/remote-sim.c                                   |  233 +-
 gdb/remote.c                                       | 1386 +++---
 gdb/rs6000-nat.c                                   |   95 +-
 gdb/rs6000-tdep.c                                  |    2 +-
 gdb/s390-linux-nat.c                               |  162 +-
 gdb/s390-tdep.c                                    |    2 +-
 gdb/sh-nbsd-nat.c                                  |   24 +-
 gdb/sol-thread.c                                   |  173 +-
 gdb/solib-aix.c                                    |    2 +-
 gdb/solib-darwin.c                                 |    2 +-
 gdb/solib-dsbt.c                                   |    4 +-
 gdb/solib-spu.c                                    |    6 +-
 gdb/solib-svr4.c                                   |   18 +-
 gdb/solib-target.c                                 |    2 +-
 gdb/sparc-linux-nat.c                              |   24 +-
 gdb/sparc-nat.c                                    |   39 +-
 gdb/sparc-nat.h                                    |   41 +-
 gdb/sparc-nbsd-nat.c                               |    5 +-
 gdb/sparc-tdep.c                                   |    2 +-
 gdb/sparc64-fbsd-nat.c                             |    9 +-
 gdb/sparc64-linux-nat.c                            |   33 +-
 gdb/sparc64-nbsd-nat.c                             |    6 +-
 gdb/sparc64-obsd-nat.c                             |    5 +-
 gdb/sparc64-tdep.c                                 |    4 +-
 gdb/spu-linux-nat.c                                |   78 +-
 gdb/spu-multiarch.c                                |  164 +-
 gdb/spu-tdep.c                                     |   30 +-
 gdb/symfile.c                                      |    2 +-
 gdb/target-debug.h                                 |    6 +
 gdb/target-delegates.c                             | 5194 +++++++++-----------
 gdb/target-descriptions.c                          |    4 +-
 gdb/target-memory.c                                |    4 +-
 gdb/target.c                                       |  954 ++--
 gdb/target.h                                       |  926 ++--
 gdb/testsuite/gdb.base/breakpoint-in-ro-region.exp |    4 +-
 gdb/testsuite/gdb.base/sss-bp-on-user-bp-2.exp     |    4 +-
 gdb/tilegx-linux-nat.c                             |   34 +-
 gdb/tracefile-tfile.c                              |  122 +-
 gdb/tracefile.c                                    |   38 +-
 gdb/tracefile.h                                    |   16 +-
 gdb/tracepoint.c                                   |    2 +-
 gdb/valops.c                                       |    4 +-
 gdb/valprint.c                                     |    2 +-
 gdb/value.c                                        |    2 +-
 gdb/vax-bsd-nat.c                                  |   25 +-
 gdb/windows-nat.c                                  |  223 +-
 gdb/windows-tdep.c                                 |    2 +-
 gdb/x86-bsd-nat.c                                  |   27 +-
 gdb/x86-bsd-nat.h                                  |   21 +-
 gdb/x86-linux-nat.c                                |   91 +-
 gdb/x86-linux-nat.h                                |   62 +-
 gdb/x86-nat.c                                      |   64 +-
 gdb/x86-nat.h                                      |   79 +-
 gdb/xtensa-linux-nat.c                             |   32 +-
 150 files changed, 9106 insertions(+), 9305 deletions(-)
 create mode 100644 gdb/amd64-bsd-nat.h

--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 02/40] make-target-delegates: line break between return type and function name

Pedro Alves-7
Before the target_ops C++ification, this wasn't necessary simply
because the methods were wrapped in ()'s, like
  '(*to_my_long_method_name) (target_ops *)',
so
  std::vector<long_type_name>(*to_my_long_method_name) ()TARGET_DEFAULT_IGNORE ()

still parsed correctly.  With the (*) gone, we need this.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <[hidden email]>

        * make-target-delegates (scan_target_h): Don't trim lines here.
        Replace sequences of tabs and/or whitespace with a single
        whitespace.
        (top level, parsing methods): Trim each line before processing it
        here.
---
 gdb/make-target-delegates | 20 +++++++++++++++++++-
 gdb/target.h              |  3 ++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/gdb/make-target-delegates b/gdb/make-target-delegates
index 10853e3e20..83a1afcadf 100755
--- a/gdb/make-target-delegates
+++ b/gdb/make-target-delegates
@@ -102,7 +102,6 @@ sub scan_target_h() {
 
  # Strip // comments.
  $_ =~ s,//.*$,,;
- $_ = trim ($_);
 
  $all_the_text .= $_;
     }
@@ -110,6 +109,21 @@ sub scan_target_h() {
     # Now strip out the C comments.
     $all_the_text =~ s,/\*(.*?)\*/,,g;
 
+    # Replace sequences of tabs and/or whitespace with a single
+    # whitespace character.  We need the whitespace because the method
+    # may have been split between multiple lines, like e.g.:
+    #
+    #  virtual std::vector<long_type_name>
+    #    my_long_method_name ()
+    #    TARGET_DEFAULT_IGNORE ();
+    #
+    # If we didn't preserve the whitespace, then we'd end up with:
+    #
+    #  virtual std::vector<long_type_name>my_long_method_name ()TARGET_DEFAULT_IGNORE ()
+    #
+    # ... which wouldn't later be parsed correctly.
+    $all_the_text =~ s/[\t\s]+/ /g;
+
     return split (/;/, $all_the_text);
 }
 
@@ -348,6 +362,10 @@ print "\n";
 @argtypes_array = ();
 
 foreach $current_line (@lines) {
+    # See comments in scan_target_h.  Here we strip away the leading
+    # and trailing whitespace.
+    $current_line = trim ($current_line);
+
     next unless $current_line =~ m/$METHOD/;
 
     my $name = $+{name};
diff --git a/gdb/target.h b/gdb/target.h
index b23b7625be..f78eb459dc 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1067,7 +1067,8 @@ struct target_ops
 
     /* Return a vector of all tracepoints markers string id ID, or all
        markers if ID is NULL.  */
-    virtual std::vector<static_tracepoint_marker> static_tracepoint_markers_by_strid (const char *id)
+    virtual std::vector<static_tracepoint_marker>
+      static_tracepoint_markers_by_strid (const char *id)
       TARGET_DEFAULT_NORETURN (tcomplain ());
 
     /* Return a traceframe info object describing the current
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 03/40] target_ops/C++: exec target

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.
---
 gdb/exec.c    | 139 ++++++++++++++++++++++++----------------------------------
 gdb/gdbcore.h |   2 -
 2 files changed, 58 insertions(+), 83 deletions(-)

diff --git a/gdb/exec.c b/gdb/exec.c
index f94c15f1f5..14d0668591 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -49,15 +49,43 @@
 
 void (*deprecated_file_changed_hook) (const char *);
 
-/* Prototypes for local functions */
-
-static void exec_files_info (struct target_ops *);
-
-static void init_exec_ops (void);
-
 /* The target vector for executable files.  */
 
-static struct target_ops exec_ops;
+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 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,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+  struct target_section_table *get_section_table () override;
+  void files_info () override;
+
+  int has_memory () override;
+  char *make_corefile_notes (bfd *, int *) override;
+  int find_memory_regions (find_memory_region_ftype func, void *data) override;
+};
+
+static exec_target exec_ops;
 
 /* Whether to open exec and core files read-only or read-write.  */
 
@@ -71,8 +99,8 @@ show_write_files (struct ui_file *file, int from_tty,
 }
 
 
-static void
-exec_open (const char *args, int from_tty)
+void
+exec_target::open (const char *args, int from_tty)
 {
   target_preopen (from_tty);
   exec_file_attach (args, from_tty);
@@ -105,8 +133,8 @@ exec_close (void)
 /* This is the target_close implementation.  Clears all target
    sections and closes all executable bfds from all program spaces.  */
 
-static void
-exec_close_1 (struct target_ops *self)
+void
+exec_target::close ()
 {
   struct program_space *ss;
   scoped_restore_current_program_space restore_pspace;
@@ -119,17 +147,7 @@ exec_close_1 (struct target_ops *self)
     }
 }
 
-void
-exec_file_clear (int from_tty)
-{
-  /* Remove exec file.  */
-  exec_close ();
-
-  if (from_tty)
-    printf_unfiltered (_("No executable file now.\n"));
-}
-
-/* See exec.h.  */
+/* See gdbcore.h.  */
 
 void
 try_open_exec_file (const char *exec_file_host, struct inferior *inf,
@@ -846,19 +864,19 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
   return TARGET_XFER_EOF; /* We can't help.  */
 }
 
-static struct target_section_table *
-exec_get_section_table (struct target_ops *ops)
+struct target_section_table *
+exec_target::get_section_table ()
 {
   return current_target_sections;
 }
 
-static enum target_xfer_status
-exec_xfer_partial (struct target_ops *ops, enum target_object object,
-   const char *annex, gdb_byte *readbuf,
-   const gdb_byte *writebuf,
-   ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+exec_target::xfer_partial (enum target_object object,
+   const char *annex, gdb_byte *readbuf,
+   const gdb_byte *writebuf,
+   ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
 {
-  struct target_section_table *table = target_get_section_table (ops);
+  struct target_section_table *table = get_section_table ();
 
   if (object == TARGET_OBJECT_MEMORY)
     return section_table_xfer_memory_partial (readbuf, writebuf,
@@ -940,8 +958,8 @@ print_section_info (struct target_section_table *t, bfd *abfd)
     }
 }
 
-static void
-exec_files_info (struct target_ops *t)
+void
+exec_target::files_info ()
 {
   if (exec_bfd)
     print_section_info (current_target_sections, exec_bfd);
@@ -981,7 +999,7 @@ set_section_command (const char *args, int from_tty)
   p->addr += offset;
   p->endaddr += offset;
   if (from_tty)
-    exec_files_info (&exec_ops);
+    exec_ops.files_info ();
   return;
  }
     }
@@ -1013,29 +1031,8 @@ exec_set_section_address (const char *filename, int index, CORE_ADDR address)
     }
 }
 
-/* If mourn is being called in all the right places, this could be say
-   `gdb internal error' (since generic_mourn calls
-   breakpoint_init_inferior).  */
-
-static int
-ignore (struct target_ops *ops, struct gdbarch *gdbarch,
- struct bp_target_info *bp_tgt)
-{
-  return 0;
-}
-
-/* Implement the to_remove_breakpoint method.  */
-
-static int
-exec_remove_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
- struct bp_target_info *bp_tgt,
- enum remove_bp_reason reason)
-{
-  return 0;
-}
-
-static int
-exec_has_memory (struct target_ops *ops)
+int
+exec_target::has_memory ()
 {
   /* We can provide memory if we have any file/target sections to read
      from.  */
@@ -1043,34 +1040,16 @@ exec_has_memory (struct target_ops *ops)
   != current_target_sections->sections_end);
 }
 
-static char *
-exec_make_note_section (struct target_ops *self, bfd *obfd, int *note_size)
+char *
+exec_target::make_corefile_notes (bfd *obfd, int *note_size)
 {
   error (_("Can't create a corefile"));
 }
 
-/* Fill in the exec file target vector.  Very few entries need to be
-   defined.  */
-
-static void
-init_exec_ops (void)
+int
+exec_target::find_memory_regions (find_memory_region_ftype func, void *data)
 {
-  exec_ops.to_shortname = "exec";
-  exec_ops.to_longname = "Local exec file";
-  exec_ops.to_doc = "Use an executable file as a target.\n\
-Specify the filename of the executable file.";
-  exec_ops.to_open = exec_open;
-  exec_ops.to_close = exec_close_1;
-  exec_ops.to_xfer_partial = exec_xfer_partial;
-  exec_ops.to_get_section_table = exec_get_section_table;
-  exec_ops.to_files_info = exec_files_info;
-  exec_ops.to_insert_breakpoint = ignore;
-  exec_ops.to_remove_breakpoint = exec_remove_breakpoint;
-  exec_ops.to_stratum = file_stratum;
-  exec_ops.to_has_memory = exec_has_memory;
-  exec_ops.to_make_corefile_notes = exec_make_note_section;
-  exec_ops.to_find_memory_regions = objfile_find_memory_regions;
-  exec_ops.to_magic = OPS_MAGIC;
+  return objfile_find_memory_regions (this, func, data);
 }
 
 void
@@ -1078,8 +1057,6 @@ _initialize_exec (void)
 {
   struct cmd_list_element *c;
 
-  init_exec_ops ();
-
   if (!dbx_commands)
     {
       c = add_cmd ("file", class_files, file_command, _("\
diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h
index fef7879e99..5264eef4ee 100644
--- a/gdb/gdbcore.h
+++ b/gdb/gdbcore.h
@@ -153,8 +153,6 @@ extern void exec_file_attach (const char *filename, int from_tty);
 
 extern void exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty);
 
-extern void exec_file_clear (int from_tty);
-
 extern void validate_files (void);
 
 /* The current default bfd target.  */
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 04/40] target_ops/C++: core target

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.

The core_target global is renamed to avoid conflict with the
"core_target" class.
---
 gdb/corefile.c |  12 ++--
 gdb/corelow.c  | 202 ++++++++++++++++++++++++++++-----------------------------
 gdb/gdbcore.h  |   4 +-
 3 files changed, 105 insertions(+), 113 deletions(-)

diff --git a/gdb/corefile.c b/gdb/corefile.c
index 5a735264ef..c849a10646 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -53,9 +53,6 @@ static int exec_file_hook_count = 0; /* Size of array.  */
 
 bfd *core_bfd = NULL;
 
-/* corelow.c target.  It is never NULL after GDB initialization.  */
-
-struct target_ops *core_target;
 
 
 /* Backward compatability with old way of specifying core files.  */
@@ -65,12 +62,12 @@ core_file_command (const char *filename, int from_tty)
 {
   dont_repeat (); /* Either way, seems bogus.  */
 
-  gdb_assert (core_target != NULL);
+  gdb_assert (the_core_target != NULL);
 
   if (!filename)
-    (core_target->to_detach) (core_target, current_inferior (), from_tty);
+    the_core_target->detach (current_inferior (), from_tty);
   else
-    (core_target->to_open) (filename, from_tty);
+    the_core_target->open (filename, from_tty);
 }
 
 
@@ -237,8 +234,7 @@ read_memory_object (enum target_object object, CORE_ADDR memaddr,
       enum target_xfer_status status;
       ULONGEST xfered_len;
 
-      status = target_xfer_partial (current_target.beneath,
-    object, NULL,
+      status = target_xfer_partial (target_stack, object, NULL,
     myaddr + xfered, NULL,
     memaddr + xfered, len - xfered,
     &xfered_len);
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 190f0162d9..f7202f75e3 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -50,6 +50,55 @@
 #define O_LARGEFILE 0
 #endif
 
+/* The core file target.  */
+
+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 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;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+  void files_info () override;
+
+  int thread_alive (ptid_t ptid) override;
+  const struct target_desc *read_description () override;
+
+  const char *pid_to_str (ptid_t) override;
+
+  const char *thread_name (struct thread_info *) override;
+
+  int has_memory () override;
+  int has_stack () override;
+  int has_registers () override;
+  bool info_proc (const char *, enum info_proc_what) override;
+};
+
+/* See gdbcore.h.  */
+struct target_ops *the_core_target;
+
 /* List of all available core_fns.  On gdb startup, each core file
    register reader calls deprecated_add_core_fns() to register
    information on each core format it is prepared to read.  */
@@ -74,21 +123,15 @@ static struct gdbarch *core_gdbarch = NULL;
    unix child targets.  */
 static struct target_section_table *core_data;
 
-static void core_files_info (struct target_ops *);
-
 static struct core_fns *sniff_core_bfd (bfd *);
 
 static int gdb_check_format (bfd *);
 
-static void core_close (struct target_ops *self);
-
 static void core_close_cleanup (void *ignore);
 
 static void add_to_thread_list (bfd *, asection *, void *);
 
-static void init_core_ops (void);
-
-static struct target_ops core_ops;
+static core_target core_ops;
 
 /* An arbitrary identifier for the core inferior.  */
 #define CORELOW_PID 1
@@ -185,7 +228,7 @@ gdb_check_format (bfd *abfd)
    stack spaces as empty.  */
 
 static void
-core_close (struct target_ops *self)
+core_close ()
 {
   if (core_bfd)
     {
@@ -216,7 +259,13 @@ core_close (struct target_ops *self)
 static void
 core_close_cleanup (void *ignore)
 {
-  core_close (NULL);
+  core_close ();
+}
+
+void
+core_target::close ()
+{
+  core_close ();
 }
 
 /* Look for sections whose names start with `.reg/' so that we can
@@ -266,8 +315,8 @@ add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg)
 
 /* This routine opens and sets up the core file bfd.  */
 
-static void
-core_open (const char *arg, int from_tty)
+void
+core_target::open (const char *arg, int from_tty)
 {
   const char *p;
   int siggy;
@@ -463,10 +512,10 @@ core_open (const char *arg, int from_tty)
     }
 }
 
-static void
-core_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+core_target::detach (inferior *inf, int from_tty)
 {
-  unpush_target (ops);
+  unpush_target (this);
   reinit_frame_cache ();
   if (from_tty)
     printf_filtered (_("No core file now.\n"));
@@ -585,9 +634,8 @@ get_core_registers_cb (const char *sect_name, int size,
 
 /* We just get all the registers, so we don't use regno.  */
 
-static void
-get_core_registers (struct target_ops *ops,
-    struct regcache *regcache, int regno)
+void
+core_target::fetch_registers (struct regcache *regcache, int regno)
 {
   int i;
   struct gdbarch *gdbarch;
@@ -619,8 +667,8 @@ get_core_registers (struct target_ops *ops,
       regcache_raw_supply (regcache, i, NULL);
 }
 
-static void
-core_files_info (struct target_ops *t)
+void
+core_target::files_info ()
 {
   print_section_info (core_data, core_bfd);
 }
@@ -655,11 +703,10 @@ add_to_spuid_list (bfd *abfd, asection *asect, void *list_p)
   list->pos += 4;
 }
 
-static enum target_xfer_status
-core_xfer_partial (struct target_ops *ops, enum target_object object,
-   const char *annex, gdb_byte *readbuf,
-   const gdb_byte *writebuf, ULONGEST offset,
-   ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+core_target::xfer_partial (enum target_object object, const char *annex,
+   gdb_byte *readbuf, const gdb_byte *writebuf,
+   ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
 {
   switch (object)
     {
@@ -861,35 +908,13 @@ core_xfer_partial (struct target_ops *ops, enum target_object object,
       return TARGET_XFER_E_IO;
 
     default:
-      return ops->beneath->to_xfer_partial (ops->beneath, object,
-    annex, readbuf,
-    writebuf, offset, len,
-    xfered_len);
+      return this->beneath->xfer_partial (object, annex, readbuf,
+  writebuf, offset, len,
+  xfered_len);
     }
 }
 
 
-/* If mourn is being called in all the right places, this could be say
-   `gdb internal error' (since generic_mourn calls
-   breakpoint_init_inferior).  */
-
-static int
-ignore (struct target_ops *ops, struct gdbarch *gdbarch,
- struct bp_target_info *bp_tgt)
-{
-  return 0;
-}
-
-/* Implement the to_remove_breakpoint method.  */
-
-static int
-core_remove_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
- struct bp_target_info *bp_tgt,
- enum remove_bp_reason reason)
-{
-  return 0;
-}
-
 
 /* Okay, let's be honest: threads gleaned from a core file aren't
    exactly lively, are they?  On the other hand, if we don't claim
@@ -897,8 +922,8 @@ core_remove_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
    to appear in an "info thread" command, which is quite a useful
    behaviour.
  */
-static int
-core_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+core_target::thread_alive (ptid_t ptid)
 {
   return 1;
 }
@@ -908,24 +933,23 @@ core_thread_alive (struct target_ops *ops, ptid_t ptid)
    wrapper could be avoided if targets got a chance to specialize
    core_ops.  */
 
-static const struct target_desc *
-core_read_description (struct target_ops *target)
+const struct target_desc *
+core_target::read_description ()
 {
   if (core_gdbarch && gdbarch_core_read_description_p (core_gdbarch))
     {
       const struct target_desc *result;
 
-      result = gdbarch_core_read_description (core_gdbarch,
-      target, core_bfd);
+      result = gdbarch_core_read_description (core_gdbarch, this, core_bfd);
       if (result != NULL)
  return result;
     }
 
-  return target->beneath->to_read_description (target->beneath);
+  return this->beneath->read_description ();
 }
 
-static const char *
-core_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+core_target::pid_to_str (ptid_t ptid)
 {
   static char buf[64];
   struct inferior *inf;
@@ -956,8 +980,8 @@ core_pid_to_str (struct target_ops *ops, ptid_t ptid)
   return buf;
 }
 
-static const char *
-core_thread_name (struct target_ops *self, struct thread_info *thr)
+const char *
+core_target::thread_name (struct thread_info *thr)
 {
   if (core_gdbarch
       && gdbarch_core_thread_name_p (core_gdbarch))
@@ -965,29 +989,28 @@ core_thread_name (struct target_ops *self, struct thread_info *thr)
   return NULL;
 }
 
-static int
-core_has_memory (struct target_ops *ops)
+int
+core_target::has_memory ()
 {
   return (core_bfd != NULL);
 }
 
-static int
-core_has_stack (struct target_ops *ops)
+int
+core_target::has_stack ()
 {
   return (core_bfd != NULL);
 }
 
-static int
-core_has_registers (struct target_ops *ops)
+int
+core_target::has_registers ()
 {
   return (core_bfd != NULL);
 }
 
 /* Implement the to_info_proc method.  */
 
-static void
-core_info_proc (struct target_ops *ops, const char *args,
- enum info_proc_what request)
+bool
+core_target::info_proc (const char *args, enum info_proc_what request)
 {
   struct gdbarch *gdbarch = get_current_arch ();
 
@@ -995,47 +1018,18 @@ core_info_proc (struct target_ops *ops, const char *args,
      method on gdbarch, not 'info_proc'.  */
   if (gdbarch_core_info_proc_p (gdbarch))
     gdbarch_core_info_proc (gdbarch, args, request);
-}
-
-/* Fill in core_ops with its defined operations and properties.  */
 
-static void
-init_core_ops (void)
-{
-  core_ops.to_shortname = "core";
-  core_ops.to_longname = "Local core dump file";
-  core_ops.to_doc =
-    "Use a core file as a target.  Specify the filename of the core file.";
-  core_ops.to_open = core_open;
-  core_ops.to_close = core_close;
-  core_ops.to_detach = core_detach;
-  core_ops.to_fetch_registers = get_core_registers;
-  core_ops.to_xfer_partial = core_xfer_partial;
-  core_ops.to_files_info = core_files_info;
-  core_ops.to_insert_breakpoint = ignore;
-  core_ops.to_remove_breakpoint = core_remove_breakpoint;
-  core_ops.to_thread_alive = core_thread_alive;
-  core_ops.to_read_description = core_read_description;
-  core_ops.to_pid_to_str = core_pid_to_str;
-  core_ops.to_thread_name = core_thread_name;
-  core_ops.to_stratum = process_stratum;
-  core_ops.to_has_memory = core_has_memory;
-  core_ops.to_has_stack = core_has_stack;
-  core_ops.to_has_registers = core_has_registers;
-  core_ops.to_info_proc = core_info_proc;
-  core_ops.to_magic = OPS_MAGIC;
-
-  if (core_target)
-    internal_error (__FILE__, __LINE__,
-    _("init_core_ops: core target already exists (\"%s\")."),
-    core_target->to_longname);
-  core_target = &core_ops;
+  return true;
 }
 
 void
 _initialize_corelow (void)
 {
-  init_core_ops ();
+  if (the_core_target != NULL)
+    internal_error (__FILE__, __LINE__,
+    _("core target already exists (\"%s\")."),
+    the_core_target->longname ());
+  the_core_target = &core_ops;
 
   add_target_with_completer (&core_ops, filename_completer);
 }
diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h
index 5264eef4ee..04a235dd90 100644
--- a/gdb/gdbcore.h
+++ b/gdb/gdbcore.h
@@ -135,7 +135,9 @@ extern void specify_exec_file_hook (void (*hook) (const char *filename));
 
 extern bfd *core_bfd;
 
-extern struct target_ops *core_target;
+/* corelow.c target.  It is never NULL after GDB initialization.  */
+
+extern struct target_ops *the_core_target;
 
 /* Whether to open exec and core files read-only or read-write.  */
 
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 05/40] target_ops/C++: ctf/tfile targets

Pedro Alves-7
In reply to this post by Pedro Alves-7
init_tracefile_ops is replaced by a base class that is inherited by
both ctf and tfile.
---
 gdb/ctf.c             | 103 +++++++++++++++++++++++--------------------
 gdb/tracefile-tfile.c | 120 +++++++++++++++++++++++++++-----------------------
 gdb/tracefile.c       |  38 ++++++----------
 gdb/tracefile.h       |  16 ++++++-
 4 files changed, 149 insertions(+), 128 deletions(-)

diff --git a/gdb/ctf.c b/gdb/ctf.c
index 07ae93b999..b09cebbf07 100644
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -32,6 +32,40 @@
 #include <ctype.h>
 #include <algorithm>
 
+/* The CTF target.  */
+
+class ctf_target final : public tracefile_target
+{
+public:
+  const char *shortname () override
+  { return "ctf"; }
+
+  const char *longname () override
+  { return _("CTF file"); }
+
+  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,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+  void files_info () override;
+  int trace_find (enum trace_find_type type, int num,
+  CORE_ADDR addr1, CORE_ADDR addr2, int *tpp) override;
+  int get_trace_state_variable_value (int tsv, LONGEST *val) override;
+  traceframe_info_up traceframe_info () override;
+};
+
 /* GDB saves trace buffers and other information (such as trace
    status) got from the remote target into Common Trace Format (CTF).
    The following types of information are expected to save in CTF:
@@ -826,7 +860,7 @@ static struct bt_iter_pos *start_pos;
 /* The name of CTF directory.  */
 static char *trace_dirname;
 
-static struct target_ops ctf_ops;
+static ctf_target ctf_ops;
 
 /* Destroy ctf iterator and context.  */
 
@@ -1074,8 +1108,8 @@ ctf_read_tp (struct uploaded_tp **uploaded_tps)
    definitions from the first packet.  Set the start position at the
    second packet which contains events on trace blocks.  */
 
-static void
-ctf_open (const char *dirname, int from_tty)
+void
+ctf_target::open (const char *dirname, int from_tty)
 {
   struct bt_ctf_event *event;
   uint32_t event_id;
@@ -1142,8 +1176,8 @@ ctf_open (const char *dirname, int from_tty)
 /* This is the implementation of target_ops method to_close.  Destroy
    CTF iterator and context.  */
 
-static void
-ctf_close (struct target_ops *self)
+void
+ctf_target::close ()
 {
   int pid;
 
@@ -1161,8 +1195,8 @@ ctf_close (struct target_ops *self)
 /* This is the implementation of target_ops method to_files_info.
    Print the directory name of CTF trace data.  */
 
-static void
-ctf_files_info (struct target_ops *t)
+void
+ctf_target::files_info ()
 {
   printf_filtered ("\t`%s'\n", trace_dirname);
 }
@@ -1172,9 +1206,8 @@ ctf_files_info (struct target_ops *t)
    extract contents from events, and set REGCACHE with the contents.
    If no matched events are found, mark registers unavailable.  */
 
-static void
-ctf_fetch_registers (struct target_ops *ops,
-     struct regcache *regcache, int regno)
+void
+ctf_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   struct bt_ctf_event *event = NULL;
@@ -1258,11 +1291,11 @@ ctf_fetch_registers (struct target_ops *ops,
    OFFSET is within the range, read the contents from events to
    READBUF.  */
 
-static enum target_xfer_status
-ctf_xfer_partial (struct target_ops *ops, enum target_object object,
-  const char *annex, gdb_byte *readbuf,
-  const gdb_byte *writebuf, ULONGEST offset,
-  ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+ctf_target::xfer_partial (enum target_object object,
+  const char *annex, gdb_byte *readbuf,
+  const gdb_byte *writebuf, ULONGEST offset,
+  ULONGEST len, ULONGEST *xfered_len)
 {
   /* We're only doing regular memory for now.  */
   if (object != TARGET_OBJECT_MEMORY)
@@ -1397,9 +1430,8 @@ ctf_xfer_partial (struct target_ops *ops, enum target_object object,
    trace variable is found, set the value of it to *VAL and return
    true, otherwise return false.  */
 
-static int
-ctf_get_trace_state_variable_value (struct target_ops *self,
-    int tsvnum, LONGEST *val)
+int
+ctf_target::get_trace_state_variable_value (int tsvnum, LONGEST *val)
 {
   struct bt_iter_pos *pos;
   int found = 0;
@@ -1515,9 +1547,9 @@ ctf_get_traceframe_address (void)
    Iterate the events whose name is "frame", extract the tracepoint
    number in it.  Return traceframe number when matched.  */
 
-static int
-ctf_trace_find (struct target_ops *self, enum trace_find_type type, int num,
- CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
+int
+ctf_target::trace_find (enum trace_find_type type, int num,
+ CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
 {
   int tfnum = 0;
   int found = 0;
@@ -1617,10 +1649,10 @@ ctf_trace_find (struct target_ops *self, enum trace_find_type type, int num,
    frame, extract memory range information, and return them in
    traceframe_info.  */
 
-static traceframe_info_up
-ctf_traceframe_info (struct target_ops *self)
+traceframe_info_up
+ctf_target::traceframe_info ()
 {
-  traceframe_info_up info (new traceframe_info);
+  traceframe_info_up info (new struct traceframe_info);
   const char *name;
   struct bt_iter_pos *pos;
 
@@ -1684,27 +1716,6 @@ ctf_traceframe_info (struct target_ops *self)
   return info;
 }
 
-static void
-init_ctf_ops (void)
-{
-  memset (&ctf_ops, 0, sizeof (ctf_ops));
-
-  init_tracefile_ops (&ctf_ops);
-  ctf_ops.to_shortname = "ctf";
-  ctf_ops.to_longname = "CTF file";
-  ctf_ops.to_doc = "Use a CTF directory as a target.\n\
-Specify the filename of the CTF directory.";
-  ctf_ops.to_open = ctf_open;
-  ctf_ops.to_close = ctf_close;
-  ctf_ops.to_fetch_registers = ctf_fetch_registers;
-  ctf_ops.to_xfer_partial = ctf_xfer_partial;
-  ctf_ops.to_files_info = ctf_files_info;
-  ctf_ops.to_trace_find = ctf_trace_find;
-  ctf_ops.to_get_trace_state_variable_value
-    = ctf_get_trace_state_variable_value;
-  ctf_ops.to_traceframe_info = ctf_traceframe_info;
-}
-
 #endif
 
 /* module initialization */
@@ -1713,8 +1724,6 @@ void
 _initialize_ctf (void)
 {
 #if HAVE_LIBBABELTRACE
-  init_ctf_ops ();
-
   add_target_with_completer (&ctf_ops, filename_completer);
 #endif
 }
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index d7e934770a..af8e3bd83b 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -38,6 +38,42 @@
 #define O_LARGEFILE 0
 #endif
 
+/* The tfile target.  */
+
+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.");
+  }
+
+  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,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+  void files_info () override;
+  int trace_find (enum trace_find_type type, int num,
+  CORE_ADDR addr1, CORE_ADDR addr2, int *tpp) override;
+  int get_trace_state_variable_value (int tsv, LONGEST *val) override;
+  traceframe_info_up traceframe_info () override;
+
+  void get_tracepoint_status (struct breakpoint *tp,
+      struct uploaded_tp *utp) override;
+};
+
 /* TFILE trace writer.  */
 
 struct tfile_trace_file_writer
@@ -275,7 +311,7 @@ tfile_write_tdesc (struct trace_file_writer *self)
     = (struct tfile_trace_file_writer *) self;
 
   gdb::optional<std::string> tdesc
-    = target_fetch_description_xml (&current_target);
+    = target_fetch_description_xml (target_stack);
 
   if (!tdesc)
     return;
@@ -378,9 +414,7 @@ tfile_trace_file_writer_new (void)
 
 /* target tfile command */
 
-static struct target_ops tfile_ops;
-
-/* Fill in tfile_ops with its defined operations and properties.  */
+static tfile_target tfile_ops;
 
 #define TRACE_HEADER_SIZE 8
 
@@ -417,8 +451,8 @@ tfile_read (gdb_byte *readbuf, int size)
     error (_("Premature end of file while reading trace file"));
 }
 
-static void
-tfile_open (const char *arg, int from_tty)
+void
+tfile_target::open (const char *arg, int from_tty)
 {
   int flags;
   int scratch_chan;
@@ -580,8 +614,8 @@ tfile_interp_line (char *line, struct uploaded_tp **utpp,
 
 /* Close the trace file and generally clean up.  */
 
-static void
-tfile_close (struct target_ops *self)
+void
+tfile_target::close ()
 {
   int pid;
 
@@ -592,7 +626,7 @@ tfile_close (struct target_ops *self)
   inferior_ptid = null_ptid; /* Avoid confusion from thread stuff.  */
   exit_inferior_silent (pid);
 
-  close (trace_fd);
+  ::close (trace_fd);
   trace_fd = -1;
   xfree (trace_filename);
   trace_filename = NULL;
@@ -601,15 +635,14 @@ tfile_close (struct target_ops *self)
   trace_reset_local_state ();
 }
 
-static void
-tfile_files_info (struct target_ops *t)
+void
+tfile_target::files_info ()
 {
   printf_filtered ("\t`%s'\n", trace_filename);
 }
 
-static void
-tfile_get_tracepoint_status (struct target_ops *self,
-     struct breakpoint *tp, struct uploaded_tp *utp)
+void
+tfile_target::get_tracepoint_status (struct breakpoint *tp, struct uploaded_tp *utp)
 {
   /* Other bits of trace status were collected as part of opening the
      trace files, so nothing to do here.  */
@@ -653,9 +686,9 @@ tfile_get_traceframe_address (off_t tframe_offset)
    both the traceframe and tracepoint number, otherwise -1 for
    each.  */
 
-static int
-tfile_trace_find (struct target_ops *self, enum trace_find_type type, int num,
-  CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
+int
+tfile_target::trace_find (enum trace_find_type type, int num,
+  CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
 {
   short tpnum;
   int tfnum = 0, found = 0;
@@ -836,9 +869,8 @@ traceframe_find_block_type (char type_wanted, int pos)
 /* Look for a block of saved registers in the traceframe, and get the
    requested register from it.  */
 
-static void
-tfile_fetch_registers (struct target_ops *ops,
-       struct regcache *regcache, int regno)
+void
+tfile_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   int offset, regn, regsize, dummy;
@@ -883,7 +915,7 @@ tfile_fetch_registers (struct target_ops *ops,
 }
 
 static enum target_xfer_status
-tfile_xfer_partial_features (struct target_ops *ops, const char *annex,
+tfile_xfer_partial_features (const char *annex,
      gdb_byte *readbuf, const gdb_byte *writebuf,
      ULONGEST offset, ULONGEST len,
      ULONGEST *xfered_len)
@@ -909,15 +941,15 @@ tfile_xfer_partial_features (struct target_ops *ops, const char *annex,
   return TARGET_XFER_OK;
 }
 
-static enum target_xfer_status
-tfile_xfer_partial (struct target_ops *ops, enum target_object object,
-    const char *annex, gdb_byte *readbuf,
-    const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
-    ULONGEST *xfered_len)
+enum target_xfer_status
+tfile_target::xfer_partial (enum target_object object,
+    const char *annex, gdb_byte *readbuf,
+    const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+    ULONGEST *xfered_len)
 {
   /* We're only doing regular memory and tdesc for now.  */
   if (object == TARGET_OBJECT_AVAILABLE_FEATURES)
-    return tfile_xfer_partial_features (ops, annex, readbuf, writebuf,
+    return tfile_xfer_partial_features (annex, readbuf, writebuf,
  offset, len, xfered_len);
   if (object != TARGET_OBJECT_MEMORY)
     return TARGET_XFER_E_IO;
@@ -1001,9 +1033,8 @@ tfile_xfer_partial (struct target_ops *ops, enum target_object object,
 /* Iterate through the blocks of a trace frame, looking for a 'V'
    block with a matching tsv number.  */
 
-static int
-tfile_get_trace_state_variable_value (struct target_ops *self,
-      int tsvnum, LONGEST *val)
+int
+tfile_target::get_trace_state_variable_value (int tsvnum, LONGEST *val)
 {
   int pos;
   int found = 0;
@@ -1085,10 +1116,10 @@ build_traceframe_info (char blocktype, void *data)
   return 0;
 }
 
-static traceframe_info_up
-tfile_traceframe_info (struct target_ops *self)
+traceframe_info_up
+tfile_target::traceframe_info ()
 {
-  traceframe_info_up info (new traceframe_info);
+  traceframe_info_up info (new struct traceframe_info);
 
   traceframe_walk_blocks (build_traceframe_info, 0, info.get ());
 
@@ -1105,31 +1136,8 @@ tfile_append_tdesc_line (const char *line)
   buffer_grow_str (&trace_tdesc, "\n");
 }
 
-static void
-init_tfile_ops (void)
-{
-  init_tracefile_ops (&tfile_ops);
-
-  tfile_ops.to_shortname = "tfile";
-  tfile_ops.to_longname = "Local trace dump file";
-  tfile_ops.to_doc
-    = "Use a trace file as a target.  Specify the filename of the trace file.";
-  tfile_ops.to_open = tfile_open;
-  tfile_ops.to_close = tfile_close;
-  tfile_ops.to_fetch_registers = tfile_fetch_registers;
-  tfile_ops.to_xfer_partial = tfile_xfer_partial;
-  tfile_ops.to_files_info = tfile_files_info;
-  tfile_ops.to_get_tracepoint_status = tfile_get_tracepoint_status;
-  tfile_ops.to_trace_find = tfile_trace_find;
-  tfile_ops.to_get_trace_state_variable_value
-    = tfile_get_trace_state_variable_value;
-  tfile_ops.to_traceframe_info = tfile_traceframe_info;
-}
-
 void
 _initialize_tracefile_tfile (void)
 {
-  init_tfile_ops ();
-
   add_target_with_completer (&tfile_ops, filename_completer);
 }
diff --git a/gdb/tracefile.c b/gdb/tracefile.c
index 58d620c3af..9c9c75398e 100644
--- a/gdb/tracefile.c
+++ b/gdb/tracefile.c
@@ -425,16 +425,16 @@ tracefile_fetch_registers (struct regcache *regcache, int regno)
 
 /* This is the implementation of target_ops method to_has_all_memory.  */
 
-static int
-tracefile_has_all_memory (struct target_ops *ops)
+int
+tracefile_target::has_all_memory ()
 {
   return 1;
 }
 
 /* This is the implementation of target_ops method to_has_memory.  */
 
-static int
-tracefile_has_memory (struct target_ops *ops)
+int
+tracefile_target::has_memory ()
 {
   return 1;
 }
@@ -443,8 +443,8 @@ tracefile_has_memory (struct target_ops *ops)
    The target has a stack when GDB has already selected one trace
    frame.  */
 
-static int
-tracefile_has_stack (struct target_ops *ops)
+int
+tracefile_target::has_stack ()
 {
   return get_traceframe_number () != -1;
 }
@@ -453,8 +453,8 @@ tracefile_has_stack (struct target_ops *ops)
    The target has registers when GDB has already selected one trace
    frame.  */
 
-static int
-tracefile_has_registers (struct target_ops *ops)
+int
+tracefile_target::has_registers ()
 {
   return get_traceframe_number () != -1;
 }
@@ -462,8 +462,8 @@ tracefile_has_registers (struct target_ops *ops)
 /* This is the implementation of target_ops method to_thread_alive.
    tracefile has one thread faked by GDB.  */
 
-static int
-tracefile_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+tracefile_target::thread_alive (ptid_t ptid)
 {
   return 1;
 }
@@ -471,8 +471,8 @@ tracefile_thread_alive (struct target_ops *ops, ptid_t ptid)
 /* This is the implementation of target_ops method to_get_trace_status.
    The trace status for a file is that tracing can never be run.  */
 
-static int
-tracefile_get_trace_status (struct target_ops *self, struct trace_status *ts)
+int
+tracefile_target::get_trace_status (struct trace_status *ts)
 {
   /* Other bits of trace status were collected as part of opening the
      trace files, so nothing to do here.  */
@@ -480,19 +480,9 @@ tracefile_get_trace_status (struct target_ops *self, struct trace_status *ts)
   return -1;
 }
 
-/* Initialize OPS for tracefile related targets.  */
-
-void
-init_tracefile_ops (struct target_ops *ops)
+tracefile_target::tracefile_target ()
 {
-  ops->to_stratum = process_stratum;
-  ops->to_get_trace_status = tracefile_get_trace_status;
-  ops->to_has_all_memory = tracefile_has_all_memory;
-  ops->to_has_memory = tracefile_has_memory;
-  ops->to_has_stack = tracefile_has_stack;
-  ops->to_has_registers = tracefile_has_registers;
-  ops->to_thread_alive = tracefile_thread_alive;
-  ops->to_magic = OPS_MAGIC;
+  this->to_stratum = process_stratum;
 }
 
 void
diff --git a/gdb/tracefile.h b/gdb/tracefile.h
index e6d4460d3e..accd038ebd 100644
--- a/gdb/tracefile.h
+++ b/gdb/tracefile.h
@@ -2,6 +2,7 @@
 #define TRACEFILE_H 1
 
 #include "tracepoint.h"
+#include "target.h"
 
 struct trace_file_writer;
 
@@ -113,7 +114,20 @@ struct trace_file_writer
 
 extern struct trace_file_writer *tfile_trace_file_writer_new (void);
 
-extern void init_tracefile_ops (struct target_ops *ops);
+/* Base class for tracefile related targets.  */
+
+class tracefile_target : public target_ops
+{
+public:
+  tracefile_target ();
+
+  int get_trace_status (trace_status *ts) override;
+  int has_all_memory () override;
+  int has_memory () override;
+  int has_stack () override;
+  int has_registers () override;
+  int thread_alive (ptid_t ptid) override;
+};
 
 extern void tracefile_fetch_registers (struct regcache *regcache, int regno);
 
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 06/40] target_ops/C++: spu-multiarch

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.
---
 gdb/spu-multiarch.c | 163 +++++++++++++++++++++++++++-------------------------
 1 file changed, 86 insertions(+), 77 deletions(-)

diff --git a/gdb/spu-multiarch.c b/gdb/spu-multiarch.c
index 86782abc8b..4e3397fdfe 100644
--- a/gdb/spu-multiarch.c
+++ b/gdb/spu-multiarch.c
@@ -34,8 +34,44 @@
 #include "ppc-linux-tdep.h"
 #include "spu-tdep.h"
 
-/* This module's target vector.  */
-static struct target_ops spu_ops;
+/* The SPU multi-architecture support target.  */
+
+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."); }
+
+  void mourn_inferior () override;
+
+    void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+  int search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
+     const gdb_byte *pattern, ULONGEST pattern_len,
+     CORE_ADDR *found_addrp) override;
+
+  int region_ok_for_hw_watchpoint (CORE_ADDR, int) override;
+
+  struct gdbarch *thread_architecture (ptid_t) override;
+};
+
+static spu_multiarch_target spu_ops;
 
 /* Number of SPE objects loaded into the current inferior.  */
 static int spu_nr_solib;
@@ -112,8 +148,8 @@ spu_gdbarch (int spufs_fd)
 }
 
 /* Override the to_thread_architecture routine.  */
-static struct gdbarch *
-spu_thread_architecture (struct target_ops *ops, ptid_t ptid)
+struct gdbarch *
+spu_multiarch_target::thread_architecture (ptid_t ptid)
 {
   int spufs_fd;
   CORE_ADDR spufs_addr;
@@ -121,32 +157,31 @@ spu_thread_architecture (struct target_ops *ops, ptid_t ptid)
   if (parse_spufs_run (ptid, &spufs_fd, &spufs_addr))
     return spu_gdbarch (spufs_fd);
 
-  target_ops *beneath = find_target_beneath (ops);
-  return beneath->to_thread_architecture (beneath, ptid);
+  target_ops *beneath = find_target_beneath (this);
+  return beneath->thread_architecture (ptid);
 }
 
 /* Override the to_region_ok_for_hw_watchpoint routine.  */
-static int
-spu_region_ok_for_hw_watchpoint (struct target_ops *self,
- CORE_ADDR addr, int len)
+int
+spu_multiarch_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
 {
-  struct target_ops *ops_beneath = find_target_beneath (self);
+  struct target_ops *ops_beneath = find_target_beneath (this);
 
   /* We cannot watch SPU local store.  */
   if (SPUADDR_SPU (addr) != -1)
     return 0;
 
-  return ops_beneath->to_region_ok_for_hw_watchpoint (ops_beneath, addr, len);
+  return ops_beneath->region_ok_for_hw_watchpoint (addr, len);
 }
 
 /* Override the to_fetch_registers routine.  */
-static void
-spu_fetch_registers (struct target_ops *ops,
-     struct regcache *regcache, int regno)
+
+void
+spu_multiarch_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  struct target_ops *ops_beneath = find_target_beneath (ops);
+  struct target_ops *ops_beneath = find_target_beneath (this);
   int spufs_fd;
   CORE_ADDR spufs_addr;
 
@@ -158,7 +193,7 @@ spu_fetch_registers (struct target_ops *ops,
   /* This version applies only if we're currently in spu_run.  */
   if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
     {
-      ops_beneath->to_fetch_registers (ops_beneath, regcache, regno);
+      ops_beneath->fetch_registers (regcache, regno);
       return;
     }
 
@@ -200,12 +235,12 @@ spu_fetch_registers (struct target_ops *ops,
 }
 
 /* Override the to_store_registers routine.  */
-static void
-spu_store_registers (struct target_ops *ops,
-     struct regcache *regcache, int regno)
+
+void
+spu_multiarch_target::store_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct target_ops *ops_beneath = find_target_beneath (ops);
+  struct target_ops *ops_beneath = find_target_beneath (this);
   int spufs_fd;
   CORE_ADDR spufs_addr;
 
@@ -217,7 +252,7 @@ spu_store_registers (struct target_ops *ops,
   /* This version applies only if we're currently in spu_run.  */
   if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
     {
-      ops_beneath->to_store_registers (ops_beneath, regcache, regno);
+      ops_beneath->store_registers (regcache, regno);
       return;
     }
 
@@ -252,13 +287,14 @@ spu_store_registers (struct target_ops *ops,
 }
 
 /* Override the to_xfer_partial routine.  */
-static enum target_xfer_status
-spu_xfer_partial (struct target_ops *ops, enum target_object object,
-  const char *annex, gdb_byte *readbuf,
-  const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
-  ULONGEST *xfered_len)
+
+enum target_xfer_status
+spu_multiarch_target::xfer_partial (enum target_object object,
+    const char *annex, gdb_byte *readbuf,
+    const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+    ULONGEST *xfered_len)
 {
-  struct target_ops *ops_beneath = find_target_beneath (ops);
+  struct target_ops *ops_beneath = find_target_beneath (this);
 
   /* Use the "mem" spufs file to access SPU local store.  */
   if (object == TARGET_OBJECT_MEMORY)
@@ -273,9 +309,9 @@ spu_xfer_partial (struct target_ops *ops, enum target_object object,
       if (fd >= 0)
  {
   xsnprintf (mem_annex, sizeof mem_annex, "%d/mem", fd);
-  ret = ops_beneath->to_xfer_partial (ops_beneath, TARGET_OBJECT_SPU,
-      mem_annex, readbuf, writebuf,
-      addr, len, xfered_len);
+  ret = ops_beneath->xfer_partial (TARGET_OBJECT_SPU,
+   mem_annex, readbuf, writebuf,
+   addr, len, xfered_len);
   if (ret == TARGET_XFER_OK)
     return ret;
 
@@ -285,41 +321,38 @@ spu_xfer_partial (struct target_ops *ops, enum target_object object,
      trying the original address first, and getting end-of-file.  */
   xsnprintf (lslr_annex, sizeof lslr_annex, "%d/lslr", fd);
   memset (buf, 0, sizeof buf);
-  if (ops_beneath->to_xfer_partial (ops_beneath, TARGET_OBJECT_SPU,
-    lslr_annex, buf, NULL,
-    0, sizeof buf, xfered_len)
+  if (ops_beneath->xfer_partial (TARGET_OBJECT_SPU,
+ lslr_annex, buf, NULL,
+ 0, sizeof buf, xfered_len)
       != TARGET_XFER_OK)
     return ret;
 
   lslr = strtoulst ((char *) buf, NULL, 16);
-  return ops_beneath->to_xfer_partial (ops_beneath, TARGET_OBJECT_SPU,
-       mem_annex, readbuf, writebuf,
-       addr & lslr, len, xfered_len);
+  return ops_beneath->xfer_partial (TARGET_OBJECT_SPU,
+    mem_annex, readbuf, writebuf,
+    addr & lslr, len, xfered_len);
  }
     }
 
-  return ops_beneath->to_xfer_partial (ops_beneath, object, annex,
-       readbuf, writebuf, offset, len, xfered_len);
+  return ops_beneath->xfer_partial (object, annex,
+    readbuf, writebuf, offset, len, xfered_len);
 }
 
 /* Override the to_search_memory routine.  */
-static int
-spu_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)
+int
+spu_multiarch_target::search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
+     const gdb_byte *pattern, ULONGEST pattern_len,
+     CORE_ADDR *found_addrp)
 {
-  struct target_ops *ops_beneath = find_target_beneath (ops);
+  struct target_ops *ops_beneath = find_target_beneath (this);
 
   /* For SPU local store, always fall back to the simple method.  */
   if (SPUADDR_SPU (start_addr) >= 0)
-    return simple_search_memory (ops,
- start_addr, search_space_len,
+    return simple_search_memory (this, start_addr, search_space_len,
  pattern, pattern_len, found_addrp);
 
-  return ops_beneath->to_search_memory (ops_beneath,
- start_addr, search_space_len,
- pattern, pattern_len, found_addrp);
+  return ops_beneath->search_memory (start_addr, search_space_len,
+     pattern, pattern_len, found_addrp);
 }
 
 
@@ -373,42 +406,18 @@ spu_multiarch_solib_unloaded (struct so_list *so)
  spu_multiarch_deactivate ();
 }
 
-static void
-spu_mourn_inferior (struct target_ops *ops)
+void
+spu_multiarch_target::mourn_inferior ()
 {
-  struct target_ops *ops_beneath = find_target_beneath (ops);
+  struct target_ops *ops_beneath = find_target_beneath (this);
 
-  ops_beneath->to_mourn_inferior (ops_beneath);
+  ops_beneath->mourn_inferior ();
   spu_multiarch_deactivate ();
 }
 
-
-/* Initialize the SPU multi-architecture support target.  */
-
-static void
-init_spu_ops (void)
-{
-  spu_ops.to_shortname = "spu";
-  spu_ops.to_longname = "SPU multi-architecture support.";
-  spu_ops.to_doc = "SPU multi-architecture support.";
-  spu_ops.to_mourn_inferior = spu_mourn_inferior;
-  spu_ops.to_fetch_registers = spu_fetch_registers;
-  spu_ops.to_store_registers = spu_store_registers;
-  spu_ops.to_xfer_partial = spu_xfer_partial;
-  spu_ops.to_search_memory = spu_search_memory;
-  spu_ops.to_region_ok_for_hw_watchpoint = spu_region_ok_for_hw_watchpoint;
-  spu_ops.to_thread_architecture = spu_thread_architecture;
-  spu_ops.to_stratum = arch_stratum;
-  spu_ops.to_magic = OPS_MAGIC;
-}
-
 void
 _initialize_spu_multiarch (void)
 {
-  /* Install ourselves on the target stack.  */
-  init_spu_ops ();
-  complete_target_initialization (&spu_ops);
-
   /* Install observers to watch for SPU objects.  */
   gdb::observers::inferior_created.attach (spu_multiarch_inferior_created);
   gdb::observers::solib_loaded.attach (spu_multiarch_solib_loaded);
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 07/40] target_ops/C++: ravenscar-thread

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.
---
 gdb/ravenscar-thread.c | 230 ++++++++++++++++++++++++-------------------------
 1 file changed, 115 insertions(+), 115 deletions(-)

diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c
index 46e454a6a8..e850ef7507 100644
--- a/gdb/ravenscar-thread.c
+++ b/gdb/ravenscar-thread.c
@@ -60,9 +60,6 @@
 /* If non-null, ravenscar task support is enabled.  */
 static int ravenscar_task_support = 1;
 
-/* This module's target-specific operations.  */
-static struct target_ops ravenscar_ops;
-
 /* PTID of the last thread that received an event.
    This can be useful to determine the associated task that received
    the event, to make it the current task.  */
@@ -76,20 +73,62 @@ static const char first_task_name[] = "system__tasking__debug__first_task";
 static const char ravenscar_runtime_initializer[] =
   "system__bb__threads__initialize";
 
-static void ravenscar_update_thread_list (struct target_ops *ops);
+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."); }
+
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+  void resume (ptid_t, int, enum gdb_signal) override;
+
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  void prepare_to_store (struct regcache *) override;
+
+  int stopped_by_sw_breakpoint () override;
+
+  int stopped_by_hw_breakpoint () override;
+
+  int stopped_by_watchpoint () override;
+
+  int stopped_data_address (CORE_ADDR *) override;
+
+  int thread_alive (ptid_t ptid) override;
+
+  int core_of_thread (ptid_t ptid) override;
+
+  void update_thread_list () override;
+
+  const char *extra_thread_info (struct thread_info *) override;
+
+  const char *pid_to_str (ptid_t) override;
+
+  ptid_t get_ada_task_ptid (long lwp, long thread) override;
+
+  void mourn_inferior () override;
+
+  int has_all_memory ()  override { return default_child_has_all_memory (); }
+  int has_memory ()  override { return default_child_has_memory (); }
+  int has_stack ()  override { return default_child_has_stack (); }
+  int has_registers ()  override { return default_child_has_registers (); }
+  int has_execution (ptid_t ptid) override
+  { return default_child_has_execution (ptid); }
+};
+
+/* This module's target-specific operations.  */
+static ravenscar_thread_target ravenscar_ops;
+
 static ptid_t ravenscar_active_task (int cpu);
-static const char *ravenscar_extra_thread_info (struct target_ops *self,
- struct thread_info *tp);
-static int ravenscar_thread_alive (struct target_ops *ops, ptid_t ptid);
-static void ravenscar_fetch_registers (struct target_ops *ops,
-                                       struct regcache *regcache, int regnum);
-static void ravenscar_store_registers (struct target_ops *ops,
-                                       struct regcache *regcache, int regnum);
-static void ravenscar_prepare_to_store (struct target_ops *self,
- struct regcache *regcache);
-static void ravenscar_resume (struct target_ops *ops, ptid_t ptid, int step,
-      enum gdb_signal siggnal);
-static void ravenscar_mourn_inferior (struct target_ops *ops);
 static void ravenscar_update_inferior_ptid (void);
 static int has_ravenscar_runtime (void);
 static int ravenscar_runtime_initialized (void);
@@ -281,26 +320,25 @@ get_running_thread_id (int cpu)
   return extract_typed_address (buf, builtin_type_void_data_ptr);
 }
 
-static void
-ravenscar_resume (struct target_ops *ops, ptid_t ptid, int step,
-  enum gdb_signal siggnal)
+void
+ravenscar_thread_target::resume (ptid_t ptid, int step, enum gdb_signal siggnal)
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   inferior_ptid = base_ptid;
-  beneath->to_resume (beneath, base_ptid, step, siggnal);
+  beneath->resume (base_ptid, step, siggnal);
 }
 
-static ptid_t
-ravenscar_wait (struct target_ops *ops, ptid_t ptid,
-                struct target_waitstatus *status,
-                int options)
+ptid_t
+ravenscar_thread_target::wait (ptid_t ptid,
+       struct target_waitstatus *status,
+       int options)
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   ptid_t event_ptid;
 
   inferior_ptid = base_ptid;
-  event_ptid = beneath->to_wait (beneath, base_ptid, status, 0);
+  event_ptid = beneath->wait (base_ptid, status, 0);
   /* Find any new threads that might have been created, and update
      inferior_ptid to the active thread.
 
@@ -312,7 +350,7 @@ ravenscar_wait (struct target_ops *ops, ptid_t ptid,
       && status->kind != TARGET_WAITKIND_SIGNALLED)
     {
       inferior_ptid = event_ptid;
-      ravenscar_update_thread_list (ops);
+      this->update_thread_list ();
       ravenscar_update_inferior_ptid ();
     }
   return inferior_ptid;
@@ -328,8 +366,8 @@ ravenscar_add_thread (struct ada_task_info *task)
     add_thread (task->ptid);
 }
 
-static void
-ravenscar_update_thread_list (struct target_ops *ops)
+void
+ravenscar_thread_target::update_thread_list ()
 {
   ada_build_task_list ();
 
@@ -352,21 +390,21 @@ ravenscar_active_task (int cpu)
     return ptid_build (ptid_get_pid (base_ptid), 0, tid);
 }
 
-static const char *
-ravenscar_extra_thread_info (struct target_ops *self, struct thread_info *tp)
+const char *
+ravenscar_thread_target::extra_thread_info (thread_info *tp)
 {
   return "Ravenscar task";
 }
 
-static int
-ravenscar_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+ravenscar_thread_target::thread_alive (ptid_t ptid)
 {
   /* Ravenscar tasks are non-terminating.  */
   return 1;
 }
 
-static const char *
-ravenscar_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+ravenscar_thread_target::pid_to_str (ptid_t ptid)
 {
   static char buf[30];
 
@@ -374,11 +412,10 @@ ravenscar_pid_to_str (struct target_ops *ops, ptid_t ptid)
   return buf;
 }
 
-static void
-ravenscar_fetch_registers (struct target_ops *ops,
-                           struct regcache *regcache, int regnum)
+void
+ravenscar_thread_target::fetch_registers (struct regcache *regcache, int regnum)
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   ptid_t ptid = regcache_get_ptid (regcache);
 
   if (ravenscar_runtime_initialized ()
@@ -392,14 +429,14 @@ ravenscar_fetch_registers (struct target_ops *ops,
       arch_ops->to_fetch_registers (regcache, regnum);
     }
   else
-    beneath->to_fetch_registers (beneath, regcache, regnum);
+    beneath->fetch_registers (regcache, regnum);
 }
 
-static void
-ravenscar_store_registers (struct target_ops *ops,
-                           struct regcache *regcache, int regnum)
+void
+ravenscar_thread_target::store_registers (struct regcache *regcache,
+  int regnum)
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  target_ops *beneath = find_target_beneath (this);
   ptid_t ptid = regcache_get_ptid (regcache);
 
   if (ravenscar_runtime_initialized ()
@@ -410,17 +447,16 @@ ravenscar_store_registers (struct target_ops *ops,
       struct ravenscar_arch_ops *arch_ops
  = gdbarch_ravenscar_ops (gdbarch);
 
-      arch_ops->to_store_registers (regcache, regnum);
+      beneath->store_registers (regcache, regnum);
     }
   else
-    beneath->to_store_registers (beneath, regcache, regnum);
+    beneath->store_registers (regcache, regnum);
 }
 
-static void
-ravenscar_prepare_to_store (struct target_ops *self,
-    struct regcache *regcache)
+void
+ravenscar_thread_target::prepare_to_store (struct regcache *regcache)
 {
-  struct target_ops *beneath = find_target_beneath (self);
+  target_ops *beneath = find_target_beneath (this);
   ptid_t ptid = regcache_get_ptid (regcache);
 
   if (ravenscar_runtime_initialized ()
@@ -431,93 +467,93 @@ ravenscar_prepare_to_store (struct target_ops *self,
       struct ravenscar_arch_ops *arch_ops
  = gdbarch_ravenscar_ops (gdbarch);
 
-      arch_ops->to_prepare_to_store (regcache);
+      beneath->prepare_to_store (regcache);
     }
   else
-    beneath->to_prepare_to_store (beneath, regcache);
+    beneath->prepare_to_store (regcache);
 }
 
 /* Implement the to_stopped_by_sw_breakpoint target_ops "method".  */
 
-static int
-ravenscar_stopped_by_sw_breakpoint (struct target_ops *ops)
+int
+ravenscar_thread_target::stopped_by_sw_breakpoint ()
 {
   ptid_t saved_ptid = inferior_ptid;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   int result;
 
   inferior_ptid = get_base_thread_from_ravenscar_task (saved_ptid);
-  result = beneath->to_stopped_by_sw_breakpoint (beneath);
+  result = beneath->stopped_by_sw_breakpoint ();
   inferior_ptid = saved_ptid;
   return result;
 }
 
 /* Implement the to_stopped_by_hw_breakpoint target_ops "method".  */
 
-static int
-ravenscar_stopped_by_hw_breakpoint (struct target_ops *ops)
+int
+ravenscar_thread_target::stopped_by_hw_breakpoint ()
 {
   ptid_t saved_ptid = inferior_ptid;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   int result;
 
   inferior_ptid = get_base_thread_from_ravenscar_task (saved_ptid);
-  result = beneath->to_stopped_by_hw_breakpoint (beneath);
+  result = beneath->stopped_by_hw_breakpoint ();
   inferior_ptid = saved_ptid;
   return result;
 }
 
 /* Implement the to_stopped_by_watchpoint target_ops "method".  */
 
-static int
-ravenscar_stopped_by_watchpoint (struct target_ops *ops)
+int
+ravenscar_thread_target::stopped_by_watchpoint ()
 {
   ptid_t saved_ptid = inferior_ptid;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   int result;
 
   inferior_ptid = get_base_thread_from_ravenscar_task (saved_ptid);
-  result = beneath->to_stopped_by_watchpoint (beneath);
+  result = beneath->stopped_by_watchpoint ();
   inferior_ptid = saved_ptid;
   return result;
 }
 
 /* Implement the to_stopped_data_address target_ops "method".  */
 
-static int
-ravenscar_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
+int
+ravenscar_thread_target::stopped_data_address (CORE_ADDR *addr_p)
 {
   ptid_t saved_ptid = inferior_ptid;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   int result;
 
   inferior_ptid = get_base_thread_from_ravenscar_task (saved_ptid);
-  result = beneath->to_stopped_data_address (beneath, addr_p);
+  result = beneath->stopped_data_address (addr_p);
   inferior_ptid = saved_ptid;
   return result;
 }
 
-static void
-ravenscar_mourn_inferior (struct target_ops *ops)
+void
+ravenscar_thread_target::mourn_inferior ()
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   base_ptid = null_ptid;
-  beneath->to_mourn_inferior (beneath);
+  beneath->mourn_inferior ();
   unpush_target (&ravenscar_ops);
 }
 
 /* Implement the to_core_of_thread target_ops "method".  */
 
-static int
-ravenscar_core_of_thread (struct target_ops *ops, ptid_t ptid)
+int
+ravenscar_thread_target::core_of_thread (ptid_t ptid)
 {
   ptid_t saved_ptid = inferior_ptid;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   int result;
 
   inferior_ptid = get_base_thread_from_ravenscar_task (saved_ptid);
-  result = beneath->to_core_of_thread (beneath, inferior_ptid);
+  result = beneath->core_of_thread (inferior_ptid);
   inferior_ptid = saved_ptid;
   return result;
 }
@@ -545,45 +581,12 @@ ravenscar_inferior_created (struct target_ops *target, int from_tty)
   push_target (&ravenscar_ops);
 }
 
-static ptid_t
-ravenscar_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
+ptid_t
+ravenscar_thread_target::get_ada_task_ptid (long lwp, long thread)
 {
   return ptid_build (ptid_get_pid (base_ptid), 0, thread);
 }
 
-static void
-init_ravenscar_thread_ops (void)
-{
-  ravenscar_ops.to_shortname = "ravenscar";
-  ravenscar_ops.to_longname = "Ravenscar tasks.";
-  ravenscar_ops.to_doc = "Ravenscar tasks support.";
-  ravenscar_ops.to_resume = ravenscar_resume;
-  ravenscar_ops.to_wait = ravenscar_wait;
-  ravenscar_ops.to_fetch_registers = ravenscar_fetch_registers;
-  ravenscar_ops.to_store_registers = ravenscar_store_registers;
-  ravenscar_ops.to_prepare_to_store = ravenscar_prepare_to_store;
-  ravenscar_ops.to_stopped_by_sw_breakpoint
-    = ravenscar_stopped_by_sw_breakpoint;
-  ravenscar_ops.to_stopped_by_hw_breakpoint
-    = ravenscar_stopped_by_hw_breakpoint;
-  ravenscar_ops.to_stopped_by_watchpoint = ravenscar_stopped_by_watchpoint;
-  ravenscar_ops.to_stopped_data_address = ravenscar_stopped_data_address;
-  ravenscar_ops.to_thread_alive = ravenscar_thread_alive;
-  ravenscar_ops.to_update_thread_list = ravenscar_update_thread_list;
-  ravenscar_ops.to_pid_to_str = ravenscar_pid_to_str;
-  ravenscar_ops.to_extra_thread_info = ravenscar_extra_thread_info;
-  ravenscar_ops.to_get_ada_task_ptid = ravenscar_get_ada_task_ptid;
-  ravenscar_ops.to_mourn_inferior = ravenscar_mourn_inferior;
-  ravenscar_ops.to_has_all_memory = default_child_has_all_memory;
-  ravenscar_ops.to_has_memory = default_child_has_memory;
-  ravenscar_ops.to_has_stack = default_child_has_stack;
-  ravenscar_ops.to_has_registers = default_child_has_registers;
-  ravenscar_ops.to_has_execution = default_child_has_execution;
-  ravenscar_ops.to_stratum = thread_stratum;
-  ravenscar_ops.to_core_of_thread = ravenscar_core_of_thread;
-  ravenscar_ops.to_magic = OPS_MAGIC;
-}
-
 /* Command-list for the "set/show ravenscar" prefix command.  */
 static struct cmd_list_element *set_ravenscar_list;
 static struct cmd_list_element *show_ravenscar_list;
@@ -627,15 +630,12 @@ Support for Ravenscar task/thread switching is disabled\n"));
 void
 _initialize_ravenscar (void)
 {
-  init_ravenscar_thread_ops ();
   base_ptid = null_ptid;
 
   /* Notice when the inferior is created in order to push the
      ravenscar ops if needed.  */
   gdb::observers::inferior_created.attach (ravenscar_inferior_created);
 
-  complete_target_initialization (&ravenscar_ops);
-
   add_prefix_cmd ("ravenscar", no_class, set_ravenscar_command,
                   _("Prefix command for changing Ravenscar-specific settings"),
                   &set_ravenscar_list, "set ravenscar ", 0, &setlist);
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 08/40] target_ops/C++: bsd-uthread

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.

The bsd_uthread_ops_hack hack is gone.  It's not needed because
nothing was extending a target created by bsd_uthread_target.
---
 gdb/bsd-uthread.c | 137 +++++++++++++++++++++++++++---------------------------
 1 file changed, 69 insertions(+), 68 deletions(-)

diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index 6c9e3af77f..19d49c76f9 100644
--- a/gdb/bsd-uthread.c
+++ b/gdb/bsd-uthread.c
@@ -33,8 +33,40 @@
 
 #include "bsd-uthread.h"
 
-/* HACK: Save the bsd_uthreads ops returned by bsd_uthread_target.  */
-static struct target_ops *bsd_uthread_ops_hack;
+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"); }
+
+  void close () override;
+
+  void mourn_inferior () override;
+
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+  void resume (ptid_t, int, enum gdb_signal) override;
+
+  int thread_alive (ptid_t ptid) override;
+
+  void update_thread_list () override;
+
+  const char *extra_thread_info (struct thread_info *) override;
+
+  const char *pid_to_str (ptid_t) override;
+};
+
+static bsd_uthread_target bsd_uthread_ops;
 
 
 /* Architecture-specific operations.  */
@@ -200,15 +232,15 @@ bsd_uthread_activate (struct objfile *objfile)
   bsd_uthread_thread_ctx_offset =
     bsd_uthread_lookup_offset ("_thread_ctx_offset", objfile);
 
-  push_target (bsd_uthread_ops_hack);
+  push_target (&bsd_uthread_ops);
   bsd_uthread_active = 1;
   return 1;
 }
 
 /* Cleanup due to deactivation.  */
 
-static void
-bsd_uthread_close (struct target_ops *self)
+void
+bsd_uthread_target::close ()
 {
   bsd_uthread_active = 0;
   bsd_uthread_thread_run_addr = 0;
@@ -228,7 +260,7 @@ bsd_uthread_deactivate (void)
   if (!bsd_uthread_active)
     return;
 
-  unpush_target (bsd_uthread_ops_hack);
+  unpush_target (&bsd_uthread_ops);
 }
 
 static void
@@ -275,24 +307,23 @@ bsd_uthread_solib_unloaded (struct so_list *so)
     bsd_uthread_deactivate ();
 }
 
-static void
-bsd_uthread_mourn_inferior (struct target_ops *ops)
+void
+bsd_uthread_target::mourn_inferior ()
 {
-  struct target_ops *beneath = find_target_beneath (ops);
-  beneath->to_mourn_inferior (beneath);
+  struct target_ops *beneath = find_target_beneath (this);
+  beneath->mourn_inferior ();
   bsd_uthread_deactivate ();
 }
 
-static void
-bsd_uthread_fetch_registers (struct target_ops *ops,
-     struct regcache *regcache, int regnum)
+void
+bsd_uthread_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   struct bsd_uthread_ops *uthread_ops
     = (struct bsd_uthread_ops *) gdbarch_data (gdbarch, bsd_uthread_data);
   ptid_t ptid = regcache_get_ptid (regcache);
   CORE_ADDR addr = ptid_get_tid (ptid);
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   CORE_ADDR active_addr;
   scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
 
@@ -301,7 +332,7 @@ bsd_uthread_fetch_registers (struct target_ops *ops,
   inferior_ptid = ptid;
 
   /* Always fetch the appropriate registers from the layer beneath.  */
-  beneath->to_fetch_registers (beneath, regcache, regnum);
+  beneath->fetch_registers (regcache, regnum);
 
   /* FIXME: That might have gotten us more than we asked for.  Make
      sure we overwrite all relevant registers with values from the
@@ -317,14 +348,13 @@ bsd_uthread_fetch_registers (struct target_ops *ops,
     }
 }
 
-static void
-bsd_uthread_store_registers (struct target_ops *ops,
-     struct regcache *regcache, int regnum)
+void
+bsd_uthread_target::store_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   struct bsd_uthread_ops *uthread_ops
     = (struct bsd_uthread_ops *) gdbarch_data (gdbarch, bsd_uthread_data);
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   ptid_t ptid = regcache_get_ptid (regcache);
   CORE_ADDR addr = ptid_get_tid (ptid);
   CORE_ADDR active_addr;
@@ -345,20 +375,20 @@ bsd_uthread_store_registers (struct target_ops *ops,
     {
       /* Updating the thread that is currently running; pass the
          request to the layer beneath.  */
-      beneath->to_store_registers (beneath, regcache, regnum);
+      beneath->store_registers (regcache, regnum);
     }
 }
 
-static ptid_t
-bsd_uthread_wait (struct target_ops *ops,
-  ptid_t ptid, struct target_waitstatus *status, int options)
+ptid_t
+bsd_uthread_target::wait (ptid_t ptid, struct target_waitstatus *status,
+  int options)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
   CORE_ADDR addr;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   /* Pass the request to the layer beneath.  */
-  ptid = beneath->to_wait (beneath, ptid, status, options);
+  ptid = beneath->wait (ptid, status, options);
 
   /* If the process is no longer alive, there's no point in figuring
      out the thread ID.  It will fail anyway.  */
@@ -399,20 +429,19 @@ bsd_uthread_wait (struct target_ops *ops,
   return ptid;
 }
 
-static void
-bsd_uthread_resume (struct target_ops *ops,
-    ptid_t ptid, int step, enum gdb_signal sig)
+void
+bsd_uthread_target::resume (ptid_t ptid, int step, enum gdb_signal sig)
 {
   /* Pass the request to the layer beneath.  */
-  struct target_ops *beneath = find_target_beneath (ops);
-  beneath->to_resume (beneath, ptid, step, sig);
+  struct target_ops *beneath = find_target_beneath (this);
+  beneath->resume (ptid, step, sig);
 }
 
-static int
-bsd_uthread_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+bsd_uthread_target::thread_alive (ptid_t ptid)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   CORE_ADDR addr = ptid_get_tid (ptid);
 
   if (addr != 0)
@@ -427,11 +456,11 @@ bsd_uthread_thread_alive (struct target_ops *ops, ptid_t ptid)
  return 0;
     }
 
-  return beneath->to_thread_alive (beneath, ptid);
+  return beneath->thread_alive (ptid);
 }
 
-static void
-bsd_uthread_update_thread_list (struct target_ops *ops)
+void
+bsd_uthread_target::update_thread_list ()
 {
   pid_t pid = ptid_get_pid (inferior_ptid);
   int offset = bsd_uthread_thread_next_offset;
@@ -487,9 +516,8 @@ static const char *bsd_uthread_state[] =
 /* Return a string describing th state of the thread specified by
    INFO.  */
 
-static const char *
-bsd_uthread_extra_thread_info (struct target_ops *self,
-       struct thread_info *info)
+const char *
+bsd_uthread_target::extra_thread_info (thread_info *info)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
   CORE_ADDR addr = ptid_get_tid (info->ptid);
@@ -507,8 +535,8 @@ bsd_uthread_extra_thread_info (struct target_ops *self,
   return NULL;
 }
 
-static const char *
-bsd_uthread_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+bsd_uthread_target::pid_to_str (ptid_t ptid)
 {
   if (ptid_get_tid (ptid) != 0)
     {
@@ -522,36 +550,9 @@ bsd_uthread_pid_to_str (struct target_ops *ops, ptid_t ptid)
   return normal_pid_to_str (ptid);
 }
 
-static struct target_ops *
-bsd_uthread_target (void)
-{
-  struct target_ops *t = XCNEW (struct target_ops);
-
-  t->to_shortname = "bsd-uthreads";
-  t->to_longname = "BSD user-level threads";
-  t->to_doc = "BSD user-level threads";
-  t->to_close = bsd_uthread_close;
-  t->to_mourn_inferior = bsd_uthread_mourn_inferior;
-  t->to_fetch_registers = bsd_uthread_fetch_registers;
-  t->to_store_registers = bsd_uthread_store_registers;
-  t->to_wait = bsd_uthread_wait;
-  t->to_resume = bsd_uthread_resume;
-  t->to_thread_alive = bsd_uthread_thread_alive;
-  t->to_update_thread_list = bsd_uthread_update_thread_list;
-  t->to_extra_thread_info = bsd_uthread_extra_thread_info;
-  t->to_pid_to_str = bsd_uthread_pid_to_str;
-  t->to_stratum = thread_stratum;
-  t->to_magic = OPS_MAGIC;
-  bsd_uthread_ops_hack = t;
-
-  return t;
-}
-
 void
 _initialize_bsd_uthread (void)
 {
-  complete_target_initialization (bsd_uthread_target ());
-
   bsd_uthread_data = gdbarch_data_register_pre_init (bsd_uthread_init);
 
   gdb::observers::inferior_created.attach (bsd_uthread_inferior_created);
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 09/40] target_ops/C++: bfd-target

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.
---
 gdb/bfd-target.c | 104 +++++++++++++++++++++++++++++++------------------------
 1 file changed, 59 insertions(+), 45 deletions(-)

diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
index 99b49aad13..7ac8bc3c61 100644
--- a/gdb/bfd-target.c
+++ b/gdb/bfd-target.c
@@ -23,36 +23,58 @@
 #include "exec.h"
 #include "gdb_bfd.h"
 
-/* The object that is stored in the target_ops->to_data field has this
-   type.  */
-struct target_bfd_data
+/* A target that wraps a BFD.  */
+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"); }
+
+  void close () override;
+
+  target_xfer_status
+    xfer_partial (target_object object,
+  const char *annex, gdb_byte *readbuf,
+  const gdb_byte *writebuf,
+  ULONGEST offset, ULONGEST len,
+  ULONGEST *xfered_len) override;
+
+  target_section_table *get_section_table () override;
+
+private:
   /* The BFD we're wrapping.  */
-  struct bfd *bfd;
+  struct bfd *m_bfd;
 
   /* The section table build from the ALLOC sections in BFD.  Note
      that we can't rely on extracting the BFD from a random section in
      the table, since the table can be legitimately empty.  */
-  struct target_section_table table;
+  struct target_section_table m_table;
 };
 
-static enum target_xfer_status
-target_bfd_xfer_partial (struct target_ops *ops,
- enum target_object object,
- const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf,
- ULONGEST offset, ULONGEST len,
- ULONGEST *xfered_len)
+target_xfer_status
+target_bfd::xfer_partial (target_object object,
+  const char *annex, gdb_byte *readbuf,
+  const gdb_byte *writebuf,
+  ULONGEST offset, ULONGEST len,
+  ULONGEST *xfered_len)
 {
   switch (object)
     {
     case TARGET_OBJECT_MEMORY:
       {
- struct target_bfd_data *data = (struct target_bfd_data *) ops->to_data;
  return section_table_xfer_memory_partial (readbuf, writebuf,
   offset, len, xfered_len,
-  data->table.sections,
-  data->table.sections_end,
+  m_table.sections,
+  m_table.sections_end,
   NULL);
       }
     default:
@@ -60,44 +82,36 @@ target_bfd_xfer_partial (struct target_ops *ops,
     }
 }
 
-static struct target_section_table *
-target_bfd_get_section_table (struct target_ops *ops)
+target_section_table *
+target_bfd::get_section_table ()
 {
-  struct target_bfd_data *data = (struct target_bfd_data *) ops->to_data;
-  return &data->table;
+  return &m_table;
 }
 
-static void
-target_bfd_close (struct target_ops *t)
+target_bfd::target_bfd (struct bfd *abfd)
 {
-  struct target_bfd_data *data = (struct target_bfd_data *) t->to_data;
+  this->to_stratum = file_stratum;
+  m_bfd = abfd;
+  gdb_bfd_ref (abfd);
+  m_table.sections = NULL;
+  m_table.sections_end = NULL;
+  build_section_table (abfd, &m_table.sections, &m_table.sections_end);
+}
 
-  gdb_bfd_unref (data->bfd);
-  xfree (data->table.sections);
-  xfree (data);
-  xfree (t);
+target_bfd::~target_bfd ()
+{
+  gdb_bfd_unref (m_bfd);
+  xfree (m_table.sections);
 }
 
-struct target_ops *
+target_ops *
 target_bfd_reopen (struct bfd *abfd)
 {
-  struct target_ops *t;
-  struct target_bfd_data *data;
+  return new target_bfd (abfd);
+}
 
-  data = XCNEW (struct target_bfd_data);
-  data->bfd = abfd;
-  gdb_bfd_ref (abfd);
-  build_section_table (abfd, &data->table.sections, &data->table.sections_end);
-
-  t = XCNEW (struct target_ops);
-  t->to_shortname = "bfd";
-  t->to_longname = _("BFD backed target");
-  t->to_doc = _("You should never see this");
-  t->to_get_section_table = target_bfd_get_section_table;
-  t->to_xfer_partial = target_bfd_xfer_partial;
-  t->to_close = target_bfd_close;
-  t->to_data = data;
-  t->to_magic = OPS_MAGIC;
-
-  return t;
+void
+target_bfd::close ()
+{
+  delete this;
 }
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 10/40] target_ops/C++: record targets

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.
---
 gdb/record-btrace.c | 557 ++++++++++++++++++++++++------------------------
 gdb/record-full.c   | 596 +++++++++++++++++++++++++++-------------------------
 gdb/record.c        |  18 +-
 3 files changed, 598 insertions(+), 573 deletions(-)

diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 7264b8ed2b..cce188e71a 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -42,7 +42,105 @@
 #include <algorithm>
 
 /* The target_ops of record-btrace.  */
-static struct target_ops record_btrace_ops;
+
+class record_btrace_target final : public target_ops
+{
+public:
+  record_btrace_target ()
+  { to_stratum = record_stratum; }
+
+  const char *shortname () override
+  { return "record-btrace"; }
+
+  const char *longname () override
+  { return _("Branch tracing target"); }
+
+  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;
+
+  void detach (inferior *inf, int from_tty) override
+  { record_detach (this, inf, from_tty); }
+
+  void disconnect (const char *, int) override;
+
+  void mourn_inferior () override
+  { record_mourn_inferior (this); }
+
+  void kill () override
+  { record_kill (this); }
+
+  enum record_method record_method (ptid_t ptid) override;
+
+  void stop_recording () override;
+  void info_record () override;
+
+  void insn_history (int size, gdb_disassembly_flags flags) override;
+  void insn_history_from (ULONGEST from, int size,
+  gdb_disassembly_flags flags) override;
+  void insn_history_range (ULONGEST begin, ULONGEST end,
+   gdb_disassembly_flags flags) override;
+  void call_history (int size, record_print_flags flags) override;
+  void call_history_from (ULONGEST begin, int size, record_print_flags flags)
+    override;
+  void call_history_range (ULONGEST begin, ULONGEST end, record_print_flags flags)
+    override;
+
+  int record_is_replaying (ptid_t ptid) override;
+  int record_will_replay (ptid_t ptid, int dir) override;
+  void record_stop_replaying () override;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+  int insert_breakpoint (struct gdbarch *,
+ struct bp_target_info *) override;
+  int remove_breakpoint (struct gdbarch *, struct bp_target_info *,
+ enum remove_bp_reason) override;
+
+  void fetch_registers (struct regcache *, int) override;
+
+  void store_registers (struct regcache *, int) override;
+  void prepare_to_store (struct regcache *) override;
+
+  const struct frame_unwind *get_unwinder () override;
+
+  const struct frame_unwind *get_tailcall_unwinder () override;
+
+  void commit_resume () override;
+  void resume (ptid_t, int, enum gdb_signal) override;
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+
+  void stop (ptid_t) override;
+  void update_thread_list () override;
+  int thread_alive (ptid_t ptid) override;
+  void goto_record_begin () override;
+  void goto_record_end () override;
+  void goto_record (ULONGEST insn) override;
+
+  int can_execute_reverse () override;
+
+  int stopped_by_sw_breakpoint () override;
+  int supports_stopped_by_sw_breakpoint () override;
+
+  int stopped_by_hw_breakpoint () override;
+  int supports_stopped_by_hw_breakpoint () override;
+
+  enum exec_direction_kind execution_direction () override;
+  void prepare_to_generate_core () override;
+  void done_generating_core () override;
+};
+
+static record_btrace_target record_btrace_ops;
+
+/* Initialize the record-btrace target ops.  */
 
 /* Token associated with a new-thread observer enabling branch tracing
    for the new thread.  */
@@ -237,10 +335,10 @@ private:
   std::forward_list<thread_info *> m_threads;
 };
 
-/* The to_open method of target record-btrace.  */
+/* The open method of target record-btrace.  */
 
-static void
-record_btrace_open (const char *args, int from_tty)
+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.  */
@@ -267,10 +365,10 @@ record_btrace_open (const char *args, int from_tty)
   btrace_disable.discard ();
 }
 
-/* The to_stop_recording method of target record-btrace.  */
+/* The stop_recording method of target record-btrace.  */
 
-static void
-record_btrace_stop_recording (struct target_ops *self)
+void
+record_btrace_target::stop_recording ()
 {
   struct thread_info *tp;
 
@@ -283,25 +381,25 @@ record_btrace_stop_recording (struct target_ops *self)
       btrace_disable (tp);
 }
 
-/* The to_disconnect method of target record-btrace.  */
+/* The disconnect method of target record-btrace.  */
 
-static void
-record_btrace_disconnect (struct target_ops *self, const char *args,
-  int from_tty)
+void
+record_btrace_target::disconnect (const char *args,
+  int from_tty)
 {
-  struct target_ops *beneath = self->beneath;
+  struct target_ops *beneath = this->beneath;
 
   /* Do not stop recording, just clean up GDB side.  */
-  unpush_target (self);
+  unpush_target (this);
 
   /* Forward disconnect.  */
-  beneath->to_disconnect (beneath, args, from_tty);
+  beneath->disconnect (args, from_tty);
 }
 
-/* The to_close method of target record-btrace.  */
+/* The close method of target record-btrace.  */
 
-static void
-record_btrace_close (struct target_ops *self)
+void
+record_btrace_target::close ()
 {
   struct thread_info *tp;
 
@@ -318,17 +416,17 @@ record_btrace_close (struct target_ops *self)
     btrace_teardown (tp);
 }
 
-/* The to_async method of target record-btrace.  */
+/* The async method of target record-btrace.  */
 
-static void
-record_btrace_async (struct target_ops *ops, int enable)
+void
+record_btrace_target::async (int enable)
 {
   if (enable)
     mark_async_event_handler (record_btrace_async_inferior_event_handler);
   else
     clear_async_event_handler (record_btrace_async_inferior_event_handler);
 
-  ops->beneath->to_async (ops->beneath, enable);
+  this->beneath->async (enable);
 }
 
 /* Adjusts the size and returns a human readable size suffix.  */
@@ -416,10 +514,10 @@ record_btrace_print_conf (const struct btrace_config *conf)
   internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
 }
 
-/* The to_info_record method of target record-btrace.  */
+/* The info_record method of target record-btrace.  */
 
-static void
-record_btrace_info (struct target_ops *self)
+void
+record_btrace_target::info_record ()
 {
   struct btrace_thread_info *btinfo;
   const struct btrace_config *conf;
@@ -436,7 +534,7 @@ record_btrace_info (struct target_ops *self)
 
   btinfo = &tp->btrace;
 
-  conf = btrace_conf (btinfo);
+  conf = ::btrace_conf (btinfo);
   if (conf != NULL)
     record_btrace_print_conf (conf);
 
@@ -725,11 +823,10 @@ btrace_insn_history (struct ui_out *uiout,
     }
 }
 
-/* The to_insn_history method of target record-btrace.  */
+/* The insn_history method of target record-btrace.  */
 
-static void
-record_btrace_insn_history (struct target_ops *self, int size,
-    gdb_disassembly_flags flags)
+void
+record_btrace_target::insn_history (int size, gdb_disassembly_flags flags)
 {
   struct btrace_thread_info *btinfo;
   struct btrace_insn_history *history;
@@ -809,12 +906,11 @@ record_btrace_insn_history (struct target_ops *self, int size,
   btrace_set_insn_history (btinfo, &begin, &end);
 }
 
-/* The to_insn_history_range method of target record-btrace.  */
+/* The insn_history_range method of target record-btrace.  */
 
-static void
-record_btrace_insn_history_range (struct target_ops *self,
-  ULONGEST from, ULONGEST to,
-  gdb_disassembly_flags flags)
+void
+record_btrace_target::insn_history_range (ULONGEST from, ULONGEST to,
+  gdb_disassembly_flags flags)
 {
   struct btrace_thread_info *btinfo;
   struct btrace_insn_iterator begin, end;
@@ -858,12 +954,11 @@ record_btrace_insn_history_range (struct target_ops *self,
   btrace_set_insn_history (btinfo, &begin, &end);
 }
 
-/* The to_insn_history_from method of target record-btrace.  */
+/* The insn_history_from method of target record-btrace.  */
 
-static void
-record_btrace_insn_history_from (struct target_ops *self,
- ULONGEST from, int size,
- gdb_disassembly_flags flags)
+void
+record_btrace_target::insn_history_from (ULONGEST from, int size,
+ gdb_disassembly_flags flags)
 {
   ULONGEST begin, end, context;
 
@@ -890,7 +985,7 @@ record_btrace_insn_history_from (struct target_ops *self,
  end = ULONGEST_MAX;
     }
 
-  record_btrace_insn_history_range (self, begin, end, flags);
+  insn_history_range (begin, end, flags);
 }
 
 /* Print the instruction number range for a function call history line.  */
@@ -1078,11 +1173,10 @@ btrace_call_history (struct ui_out *uiout,
     }
 }
 
-/* The to_call_history method of target record-btrace.  */
+/* The call_history method of target record-btrace.  */
 
-static void
-record_btrace_call_history (struct target_ops *self, int size,
-    record_print_flags flags)
+void
+record_btrace_target::call_history (int size, record_print_flags flags)
 {
   struct btrace_thread_info *btinfo;
   struct btrace_call_history *history;
@@ -1165,12 +1259,11 @@ record_btrace_call_history (struct target_ops *self, int size,
   btrace_set_call_history (btinfo, &begin, &end);
 }
 
-/* The to_call_history_range method of target record-btrace.  */
+/* The call_history_range method of target record-btrace.  */
 
-static void
-record_btrace_call_history_range (struct target_ops *self,
-  ULONGEST from, ULONGEST to,
-  record_print_flags flags)
+void
+record_btrace_target::call_history_range (ULONGEST from, ULONGEST to,
+  record_print_flags flags)
 {
   struct btrace_thread_info *btinfo;
   struct btrace_call_iterator begin, end;
@@ -1214,12 +1307,11 @@ record_btrace_call_history_range (struct target_ops *self,
   btrace_set_call_history (btinfo, &begin, &end);
 }
 
-/* The to_call_history_from method of target record-btrace.  */
+/* The call_history_from method of target record-btrace.  */
 
-static void
-record_btrace_call_history_from (struct target_ops *self,
- ULONGEST from, int size,
- record_print_flags flags)
+void
+record_btrace_target::call_history_from (ULONGEST from, int size,
+ record_print_flags flags)
 {
   ULONGEST begin, end, context;
 
@@ -1246,13 +1338,13 @@ record_btrace_call_history_from (struct target_ops *self,
  end = ULONGEST_MAX;
     }
 
-  record_btrace_call_history_range (self, begin, end, flags);
+  call_history_range ( begin, end, flags);
 }
 
-/* The to_record_method method of target record-btrace.  */
+/* The record_method method of target record-btrace.  */
 
-static enum record_method
-record_btrace_record_method (struct target_ops *self, ptid_t ptid)
+enum record_method
+record_btrace_target::record_method (ptid_t ptid)
 {
   struct thread_info * const tp = find_thread_ptid (ptid);
 
@@ -1265,10 +1357,10 @@ record_btrace_record_method (struct target_ops *self, ptid_t ptid)
   return RECORD_METHOD_BTRACE;
 }
 
-/* The to_record_is_replaying method of target record-btrace.  */
+/* The record_is_replaying method of target record-btrace.  */
 
-static int
-record_btrace_is_replaying (struct target_ops *self, ptid_t ptid)
+int
+record_btrace_target::record_is_replaying (ptid_t ptid)
 {
   struct thread_info *tp;
 
@@ -1279,26 +1371,26 @@ record_btrace_is_replaying (struct target_ops *self, ptid_t ptid)
   return 0;
 }
 
-/* The to_record_will_replay method of target record-btrace.  */
+/* The record_will_replay method of target record-btrace.  */
 
-static int
-record_btrace_will_replay (struct target_ops *self, ptid_t ptid, int dir)
+int
+record_btrace_target::record_will_replay (ptid_t ptid, int dir)
 {
-  return dir == EXEC_REVERSE || record_btrace_is_replaying (self, ptid);
+  return dir == EXEC_REVERSE || record_is_replaying (ptid);
 }
 
-/* The to_xfer_partial method of target record-btrace.  */
+/* The xfer_partial method of target record-btrace.  */
 
-static enum target_xfer_status
-record_btrace_xfer_partial (struct target_ops *ops, enum target_object object,
-    const char *annex, gdb_byte *readbuf,
-    const gdb_byte *writebuf, ULONGEST offset,
-    ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+record_btrace_target::xfer_partial (enum target_object object,
+    const char *annex, gdb_byte *readbuf,
+    const gdb_byte *writebuf, ULONGEST offset,
+    ULONGEST len, ULONGEST *xfered_len)
 {
   /* Filter out requests that don't make sense during replay.  */
   if (replay_memory_access == replay_memory_access_read_only
       && !record_btrace_generating_corefile
-      && record_btrace_is_replaying (ops, inferior_ptid))
+      && record_is_replaying (inferior_ptid))
     {
       switch (object)
  {
@@ -1314,7 +1406,7 @@ record_btrace_xfer_partial (struct target_ops *ops, enum target_object object,
       }
 
     /* We allow reading readonly memory.  */
-    section = target_section_by_addr (ops, offset);
+    section = target_section_by_addr (this, offset);
     if (section != NULL)
       {
  /* Check if the section we found is readonly.  */
@@ -1335,17 +1427,15 @@ record_btrace_xfer_partial (struct target_ops *ops, enum target_object object,
     }
 
   /* Forward the request.  */
-  ops = ops->beneath;
-  return ops->to_xfer_partial (ops, object, annex, readbuf, writebuf,
-       offset, len, xfered_len);
+  return this->beneath->xfer_partial (object, annex, readbuf, writebuf,
+      offset, len, xfered_len);
 }
 
-/* The to_insert_breakpoint method of target record-btrace.  */
+/* The insert_breakpoint method of target record-btrace.  */
 
-static int
-record_btrace_insert_breakpoint (struct target_ops *ops,
- struct gdbarch *gdbarch,
- struct bp_target_info *bp_tgt)
+int
+record_btrace_target::insert_breakpoint (struct gdbarch *gdbarch,
+ struct bp_target_info *bp_tgt)
 {
   const char *old;
   int ret;
@@ -1358,7 +1448,7 @@ record_btrace_insert_breakpoint (struct target_ops *ops,
   ret = 0;
   TRY
     {
-      ret = ops->beneath->to_insert_breakpoint (ops->beneath, gdbarch, bp_tgt);
+      ret = this->beneath->insert_breakpoint (gdbarch, bp_tgt);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -1371,13 +1461,12 @@ record_btrace_insert_breakpoint (struct target_ops *ops,
   return ret;
 }
 
-/* The to_remove_breakpoint method of target record-btrace.  */
+/* The remove_breakpoint method of target record-btrace.  */
 
-static int
-record_btrace_remove_breakpoint (struct target_ops *ops,
- struct gdbarch *gdbarch,
- struct bp_target_info *bp_tgt,
- enum remove_bp_reason reason)
+int
+record_btrace_target::remove_breakpoint (struct gdbarch *gdbarch,
+ struct bp_target_info *bp_tgt,
+ enum remove_bp_reason reason)
 {
   const char *old;
   int ret;
@@ -1390,8 +1479,7 @@ record_btrace_remove_breakpoint (struct target_ops *ops,
   ret = 0;
   TRY
     {
-      ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch, bp_tgt,
- reason);
+      ret = this->beneath->remove_breakpoint (gdbarch, bp_tgt, reason);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -1404,11 +1492,10 @@ record_btrace_remove_breakpoint (struct target_ops *ops,
   return ret;
 }
 
-/* The to_fetch_registers method of target record-btrace.  */
+/* The fetch_registers method of target record-btrace.  */
 
-static void
-record_btrace_fetch_registers (struct target_ops *ops,
-       struct regcache *regcache, int regno)
+void
+record_btrace_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct btrace_insn_iterator *replay;
   struct thread_info *tp;
@@ -1438,45 +1525,35 @@ record_btrace_fetch_registers (struct target_ops *ops,
       regcache_raw_supply (regcache, regno, &insn->pc);
     }
   else
-    {
-      struct target_ops *t = ops->beneath;
-
-      t->to_fetch_registers (t, regcache, regno);
-    }
+    this->beneath->fetch_registers (regcache, regno);
 }
 
-/* The to_store_registers method of target record-btrace.  */
+/* The store_registers method of target record-btrace.  */
 
-static void
-record_btrace_store_registers (struct target_ops *ops,
-       struct regcache *regcache, int regno)
+void
+record_btrace_target::store_registers (struct regcache *regcache, int regno)
 {
   struct target_ops *t;
 
   if (!record_btrace_generating_corefile
-      && record_btrace_is_replaying (ops, regcache_get_ptid (regcache)))
+      && record_is_replaying (regcache_get_ptid (regcache)))
     error (_("Cannot write registers while replaying."));
 
   gdb_assert (may_write_registers != 0);
 
-  t = ops->beneath;
-  t->to_store_registers (t, regcache, regno);
+  this->beneath->store_registers (regcache, regno);
 }
 
-/* The to_prepare_to_store method of target record-btrace.  */
+/* The prepare_to_store method of target record-btrace.  */
 
-static void
-record_btrace_prepare_to_store (struct target_ops *ops,
- struct regcache *regcache)
+void
+record_btrace_target::prepare_to_store (struct regcache *regcache)
 {
-  struct target_ops *t;
-
   if (!record_btrace_generating_corefile
-      && record_btrace_is_replaying (ops, regcache_get_ptid (regcache)))
+      && record_is_replaying (regcache_get_ptid (regcache)))
     return;
 
-  t = ops->beneath;
-  t->to_prepare_to_store (t, regcache);
+  this->beneath->prepare_to_store (regcache);
 }
 
 /* The branch trace frame cache.  */
@@ -1792,18 +1869,18 @@ const struct frame_unwind record_btrace_tailcall_frame_unwind =
   record_btrace_frame_dealloc_cache
 };
 
-/* Implement the to_get_unwinder method.  */
+/* Implement the get_unwinder method.  */
 
-static const struct frame_unwind *
-record_btrace_to_get_unwinder (struct target_ops *self)
+const struct frame_unwind *
+record_btrace_target::get_unwinder ()
 {
   return &record_btrace_frame_unwind;
 }
 
-/* Implement the to_get_tailcall_unwinder method.  */
+/* Implement the get_tailcall_unwinder method.  */
 
-static const struct frame_unwind *
-record_btrace_to_get_tailcall_unwinder (struct target_ops *self)
+const struct frame_unwind *
+record_btrace_target::get_tailcall_unwinder ()
 {
   return &record_btrace_tailcall_frame_unwind;
 }
@@ -1872,7 +1949,7 @@ get_thread_current_frame (struct thread_info *tp)
      We are not actually running, yet.  We just started a reverse execution
      command or a record goto command.
      For the latter, EXECUTING is false and this has no effect.
-     For the former, EXECUTING is true and we're in to_wait, about to
+     For the former, EXECUTING is true and we're in wait, about to
      move the thread.  Since we need to recompute the stack, we temporarily
      set EXECUTING to flase.  */
   executing = is_executing (inferior_ptid);
@@ -2022,40 +2099,38 @@ record_btrace_stop_replaying_at_end (struct thread_info *tp)
     record_btrace_stop_replaying (tp);
 }
 
-/* The to_resume method of target record-btrace.  */
+/* The resume method of target record-btrace.  */
 
-static void
-record_btrace_resume (struct target_ops *ops, ptid_t ptid, int step,
-      enum gdb_signal signal)
+void
+record_btrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
 {
   struct thread_info *tp;
   enum btrace_thread_flag flag, cflag;
 
   DEBUG ("resume %s: %s%s", target_pid_to_str (ptid),
- execution_direction == EXEC_REVERSE ? "reverse-" : "",
+ ::execution_direction == EXEC_REVERSE ? "reverse-" : "",
  step ? "step" : "cont");
 
   /* Store the execution direction of the last resume.
 
-     If there is more than one to_resume call, we have to rely on infrun
+     If there is more than one resume call, we have to rely on infrun
      to not change the execution direction in-between.  */
-  record_btrace_resume_exec_dir = execution_direction;
+  record_btrace_resume_exec_dir = ::execution_direction;
 
   /* As long as we're not replaying, just forward the request.
 
      For non-stop targets this means that no thread is replaying.  In order to
      make progress, we may need to explicitly move replaying threads to the end
      of their execution history.  */
-  if ((execution_direction != EXEC_REVERSE)
-      && !record_btrace_is_replaying (ops, minus_one_ptid))
+  if ((::execution_direction != EXEC_REVERSE)
+      && !record_is_replaying (minus_one_ptid))
     {
-      ops = ops->beneath;
-      ops->to_resume (ops, ptid, step, signal);
+      this->beneath->resume (ptid, step, signal);
       return;
     }
 
   /* Compute the btrace thread flag for the requested move.  */
-  if (execution_direction == EXEC_REVERSE)
+  if (::execution_direction == EXEC_REVERSE)
     {
       flag = step == 0 ? BTHR_RCONT : BTHR_RSTEP;
       cflag = BTHR_RCONT;
@@ -2098,14 +2173,14 @@ record_btrace_resume (struct target_ops *ops, ptid_t ptid, int step,
     }
 }
 
-/* The to_commit_resume method of target record-btrace.  */
+/* The commit_resume method of target record-btrace.  */
 
-static void
-record_btrace_commit_resume (struct target_ops *ops)
+void
+record_btrace_target::commit_resume ()
 {
-  if ((execution_direction != EXEC_REVERSE)
-      && !record_btrace_is_replaying (ops, minus_one_ptid))
-    ops->beneath->to_commit_resume (ops->beneath);
+  if ((::execution_direction != EXEC_REVERSE)
+      && !record_is_replaying (minus_one_ptid))
+    beneath->commit_resume ();
 }
 
 /* Cancel resuming TP.  */
@@ -2400,7 +2475,7 @@ record_btrace_step_thread (struct thread_info *tp)
       return btrace_step_again ();
     }
 
-  /* We keep threads moving at the end of their execution history.  The to_wait
+  /* We keep threads moving at the end of their execution history.  The wait
      method will stop the thread for whom the event is reported.  */
   if (status.kind == TARGET_WAITKIND_NO_HISTORY)
     btinfo->flags |= flags;
@@ -2435,11 +2510,11 @@ record_btrace_maybe_mark_async_event
   mark_async_event_handler (record_btrace_async_inferior_event_handler);
 }
 
-/* The to_wait method of target record-btrace.  */
+/* The wait method of target record-btrace.  */
 
-static ptid_t
-record_btrace_wait (struct target_ops *ops, ptid_t ptid,
-    struct target_waitstatus *status, int options)
+ptid_t
+record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status,
+    int options)
 {
   std::vector<thread_info *> moving;
   std::vector<thread_info *> no_history;
@@ -2447,11 +2522,10 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid,
   DEBUG ("wait %s (0x%x)", target_pid_to_str (ptid), options);
 
   /* As long as we're not replaying, just forward the request.  */
-  if ((execution_direction != EXEC_REVERSE)
-      && !record_btrace_is_replaying (ops, minus_one_ptid))
+  if ((::execution_direction != EXEC_REVERSE)
+      && !record_is_replaying (minus_one_ptid))
     {
-      ops = ops->beneath;
-      return ops->to_wait (ops, ptid, status, options);
+      return this->beneath->wait (ptid, status, options);
     }
 
   /* Keep a work list of moving threads.  */
@@ -2569,19 +2643,18 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid,
   return eventing->ptid;
 }
 
-/* The to_stop method of target record-btrace.  */
+/* The stop method of target record-btrace.  */
 
-static void
-record_btrace_stop (struct target_ops *ops, ptid_t ptid)
+void
+record_btrace_target::stop (ptid_t ptid)
 {
   DEBUG ("stop %s", target_pid_to_str (ptid));
 
   /* As long as we're not replaying, just forward the request.  */
-  if ((execution_direction != EXEC_REVERSE)
-      && !record_btrace_is_replaying (ops, minus_one_ptid))
+  if ((::execution_direction != EXEC_REVERSE)
+      && !record_is_replaying (minus_one_ptid))
     {
-      ops = ops->beneath;
-      ops->to_stop (ops, ptid);
+      this->beneath->stop (ptid);
     }
   else
     {
@@ -2596,94 +2669,92 @@ record_btrace_stop (struct target_ops *ops, ptid_t ptid)
     }
  }
 
-/* The to_can_execute_reverse method of target record-btrace.  */
+/* The can_execute_reverse method of target record-btrace.  */
 
-static int
-record_btrace_can_execute_reverse (struct target_ops *self)
+int
+record_btrace_target::can_execute_reverse ()
 {
   return 1;
 }
 
-/* The to_stopped_by_sw_breakpoint method of target record-btrace.  */
+/* The stopped_by_sw_breakpoint method of target record-btrace.  */
 
-static int
-record_btrace_stopped_by_sw_breakpoint (struct target_ops *ops)
+int
+record_btrace_target::stopped_by_sw_breakpoint ()
 {
-  if (record_btrace_is_replaying (ops, minus_one_ptid))
+  if (record_is_replaying (minus_one_ptid))
     {
       struct thread_info *tp = inferior_thread ();
 
       return tp->btrace.stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT;
     }
 
-  return ops->beneath->to_stopped_by_sw_breakpoint (ops->beneath);
+  return this->beneath->stopped_by_sw_breakpoint ();
 }
 
-/* The to_supports_stopped_by_sw_breakpoint method of target
+/* The supports_stopped_by_sw_breakpoint method of target
    record-btrace.  */
 
-static int
-record_btrace_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
+int
+record_btrace_target::supports_stopped_by_sw_breakpoint ()
 {
-  if (record_btrace_is_replaying (ops, minus_one_ptid))
+  if (record_is_replaying (minus_one_ptid))
     return 1;
 
-  return ops->beneath->to_supports_stopped_by_sw_breakpoint (ops->beneath);
+  return this->beneath->supports_stopped_by_sw_breakpoint ();
 }
 
-/* The to_stopped_by_sw_breakpoint method of target record-btrace.  */
+/* The stopped_by_sw_breakpoint method of target record-btrace.  */
 
-static int
-record_btrace_stopped_by_hw_breakpoint (struct target_ops *ops)
+int
+record_btrace_target::stopped_by_hw_breakpoint ()
 {
-  if (record_btrace_is_replaying (ops, minus_one_ptid))
+  if (record_is_replaying (minus_one_ptid))
     {
       struct thread_info *tp = inferior_thread ();
 
       return tp->btrace.stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT;
     }
 
-  return ops->beneath->to_stopped_by_hw_breakpoint (ops->beneath);
+  return this->beneath->stopped_by_hw_breakpoint ();
 }
 
-/* The to_supports_stopped_by_hw_breakpoint method of target
+/* The supports_stopped_by_hw_breakpoint method of target
    record-btrace.  */
 
-static int
-record_btrace_supports_stopped_by_hw_breakpoint (struct target_ops *ops)
+int
+record_btrace_target::supports_stopped_by_hw_breakpoint ()
 {
-  if (record_btrace_is_replaying (ops, minus_one_ptid))
+  if (record_is_replaying (minus_one_ptid))
     return 1;
 
-  return ops->beneath->to_supports_stopped_by_hw_breakpoint (ops->beneath);
+  return this->beneath->supports_stopped_by_hw_breakpoint ();
 }
 
-/* The to_update_thread_list method of target record-btrace.  */
+/* The update_thread_list method of target record-btrace.  */
 
-static void
-record_btrace_update_thread_list (struct target_ops *ops)
+void
+record_btrace_target::update_thread_list ()
 {
   /* We don't add or remove threads during replay.  */
-  if (record_btrace_is_replaying (ops, minus_one_ptid))
+  if (record_is_replaying (minus_one_ptid))
     return;
 
   /* Forward the request.  */
-  ops = ops->beneath;
-  ops->to_update_thread_list (ops);
+  this->beneath->update_thread_list ();
 }
 
-/* The to_thread_alive method of target record-btrace.  */
+/* The thread_alive method of target record-btrace.  */
 
-static int
-record_btrace_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+record_btrace_target::thread_alive (ptid_t ptid)
 {
   /* We don't add or remove threads during replay.  */
-  if (record_btrace_is_replaying (ops, minus_one_ptid))
+  if (record_is_replaying (minus_one_ptid))
     return find_thread_ptid (ptid) != NULL;
 
   /* Forward the request.  */
-  ops = ops->beneath;
-  return ops->to_thread_alive (ops, ptid);
+  return this->beneath->thread_alive (ptid);
 }
 
 /* Set the replay branch trace instruction iterator.  If IT is NULL, replay
@@ -2717,10 +2788,10 @@ record_btrace_set_replay (struct thread_info *tp,
   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
 }
 
-/* The to_goto_record_begin method of target record-btrace.  */
+/* The goto_record_begin method of target record-btrace.  */
 
-static void
-record_btrace_goto_begin (struct target_ops *self)
+void
+record_btrace_target::goto_record_begin ()
 {
   struct thread_info *tp;
   struct btrace_insn_iterator begin;
@@ -2742,10 +2813,10 @@ record_btrace_goto_begin (struct target_ops *self)
   record_btrace_set_replay (tp, &begin);
 }
 
-/* The to_goto_record_end method of target record-btrace.  */
+/* The goto_record_end method of target record-btrace.  */
 
-static void
-record_btrace_goto_end (struct target_ops *ops)
+void
+record_btrace_target::goto_record_end ()
 {
   struct thread_info *tp;
 
@@ -2754,10 +2825,10 @@ record_btrace_goto_end (struct target_ops *ops)
   record_btrace_set_replay (tp, NULL);
 }
 
-/* The to_goto_record method of target record-btrace.  */
+/* The goto_record method of target record-btrace.  */
 
-static void
-record_btrace_goto (struct target_ops *self, ULONGEST insn)
+void
+record_btrace_target::goto_record (ULONGEST insn)
 {
   struct thread_info *tp;
   struct btrace_insn_iterator it;
@@ -2781,10 +2852,10 @@ record_btrace_goto (struct target_ops *self, ULONGEST insn)
   record_btrace_set_replay (tp, &it);
 }
 
-/* The to_record_stop_replaying method of target record-btrace.  */
+/* The record_stop_replaying method of target record-btrace.  */
 
-static void
-record_btrace_stop_replaying_all (struct target_ops *self)
+void
+record_btrace_target::record_stop_replaying ()
 {
   struct thread_info *tp;
 
@@ -2792,91 +2863,30 @@ record_btrace_stop_replaying_all (struct target_ops *self)
     record_btrace_stop_replaying (tp);
 }
 
-/* The to_execution_direction target method.  */
+/* The execution_direction target method.  */
 
-static enum exec_direction_kind
-record_btrace_execution_direction (struct target_ops *self)
+enum exec_direction_kind
+record_btrace_target::execution_direction ()
 {
   return record_btrace_resume_exec_dir;
 }
 
-/* The to_prepare_to_generate_core target method.  */
+/* The prepare_to_generate_core target method.  */
 
-static void
-record_btrace_prepare_to_generate_core (struct target_ops *self)
+void
+record_btrace_target::prepare_to_generate_core ()
 {
   record_btrace_generating_corefile = 1;
 }
 
-/* The to_done_generating_core target method.  */
+/* The done_generating_core target method.  */
 
-static void
-record_btrace_done_generating_core (struct target_ops *self)
+void
+record_btrace_target::done_generating_core ()
 {
   record_btrace_generating_corefile = 0;
 }
 
-/* Initialize the record-btrace target ops.  */
-
-static void
-init_record_btrace_ops (void)
-{
-  struct target_ops *ops;
-
-  ops = &record_btrace_ops;
-  ops->to_shortname = "record-btrace";
-  ops->to_longname = "Branch tracing target";
-  ops->to_doc = "Collect control-flow trace and provide the execution history.";
-  ops->to_open = record_btrace_open;
-  ops->to_close = record_btrace_close;
-  ops->to_async = record_btrace_async;
-  ops->to_detach = record_detach;
-  ops->to_disconnect = record_btrace_disconnect;
-  ops->to_mourn_inferior = record_mourn_inferior;
-  ops->to_kill = record_kill;
-  ops->to_stop_recording = record_btrace_stop_recording;
-  ops->to_info_record = record_btrace_info;
-  ops->to_insn_history = record_btrace_insn_history;
-  ops->to_insn_history_from = record_btrace_insn_history_from;
-  ops->to_insn_history_range = record_btrace_insn_history_range;
-  ops->to_call_history = record_btrace_call_history;
-  ops->to_call_history_from = record_btrace_call_history_from;
-  ops->to_call_history_range = record_btrace_call_history_range;
-  ops->to_record_method = record_btrace_record_method;
-  ops->to_record_is_replaying = record_btrace_is_replaying;
-  ops->to_record_will_replay = record_btrace_will_replay;
-  ops->to_record_stop_replaying = record_btrace_stop_replaying_all;
-  ops->to_xfer_partial = record_btrace_xfer_partial;
-  ops->to_remove_breakpoint = record_btrace_remove_breakpoint;
-  ops->to_insert_breakpoint = record_btrace_insert_breakpoint;
-  ops->to_fetch_registers = record_btrace_fetch_registers;
-  ops->to_store_registers = record_btrace_store_registers;
-  ops->to_prepare_to_store = record_btrace_prepare_to_store;
-  ops->to_get_unwinder = &record_btrace_to_get_unwinder;
-  ops->to_get_tailcall_unwinder = &record_btrace_to_get_tailcall_unwinder;
-  ops->to_resume = record_btrace_resume;
-  ops->to_commit_resume = record_btrace_commit_resume;
-  ops->to_wait = record_btrace_wait;
-  ops->to_stop = record_btrace_stop;
-  ops->to_update_thread_list = record_btrace_update_thread_list;
-  ops->to_thread_alive = record_btrace_thread_alive;
-  ops->to_goto_record_begin = record_btrace_goto_begin;
-  ops->to_goto_record_end = record_btrace_goto_end;
-  ops->to_goto_record = record_btrace_goto;
-  ops->to_can_execute_reverse = record_btrace_can_execute_reverse;
-  ops->to_stopped_by_sw_breakpoint = record_btrace_stopped_by_sw_breakpoint;
-  ops->to_supports_stopped_by_sw_breakpoint
-    = record_btrace_supports_stopped_by_sw_breakpoint;
-  ops->to_stopped_by_hw_breakpoint = record_btrace_stopped_by_hw_breakpoint;
-  ops->to_supports_stopped_by_hw_breakpoint
-    = record_btrace_supports_stopped_by_hw_breakpoint;
-  ops->to_execution_direction = record_btrace_execution_direction;
-  ops->to_prepare_to_generate_core = record_btrace_prepare_to_generate_core;
-  ops->to_done_generating_core = record_btrace_done_generating_core;
-  ops->to_stratum = record_stratum;
-  ops->to_magic = OPS_MAGIC;
-}
-
 /* Start recording in BTS format.  */
 
 static void
@@ -3132,7 +3142,6 @@ to see the actual buffer size."), NULL, show_record_pt_buffer_size_value,
     &set_record_btrace_pt_cmdlist,
     &show_record_btrace_pt_cmdlist);
 
-  init_record_btrace_ops ();
   add_target (&record_btrace_ops);
 
   bfcache = htab_create_alloc (50, bfcache_hash, bfcache_eq, NULL,
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 4d8dd61bca..de96574baf 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -47,7 +47,7 @@
 
    Target record has two modes: recording, and replaying.
 
-   In record mode, we intercept the to_resume and to_wait methods.
+   In record mode, we intercept the resume and wait methods.
    Whenever gdb resumes the target, we run the target in single step
    mode, and we build up an execution log in which, for each executed
    instruction, we record all changes in memory and register state.
@@ -63,7 +63,7 @@
 #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
 
 #define RECORD_FULL_IS_REPLAY \
-     (record_full_list->next || execution_direction == EXEC_REVERSE)
+  (record_full_list->next || ::execution_direction == EXEC_REVERSE)
 
 #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
 
@@ -206,9 +206,144 @@ static unsigned int record_full_insn_num = 0;
    than count of insns presently in execution log).  */
 static ULONGEST record_full_insn_count;
 
-/* The target_ops of process record.  */
-static struct target_ops record_full_ops;
-static struct target_ops record_full_core_ops;
+/* Base class implementing functionality common to both the
+   "record-full" and "record-core" targets.  */
+
+class record_full_base_target : public target_ops
+{
+public:
+  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."); }
+
+  void open (const char *, int) override;
+  void close () override;
+  void async (int) override;
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+  int stopped_by_watchpoint () override;
+  int stopped_data_address (CORE_ADDR *) override;
+
+  int stopped_by_sw_breakpoint () override;
+  int supports_stopped_by_sw_breakpoint () override;
+
+  int stopped_by_hw_breakpoint () override;
+  int supports_stopped_by_hw_breakpoint () override;
+
+  int can_execute_reverse () override;
+
+  /* Add bookmark target methods.  */
+  gdb_byte *get_bookmark (const char *, int) override;
+  void goto_bookmark (const gdb_byte *, int) override;
+  enum exec_direction_kind execution_direction () override;
+  enum record_method record_method (ptid_t ptid) override;
+  void info_record () override;
+  void save_record (const char *filename) override;
+  bool supports_delete_record () override;
+  void delete_record () override;
+  int record_is_replaying (ptid_t ptid) override;
+  int record_will_replay (ptid_t ptid, int dir) override;
+  void record_stop_replaying () override;
+  void goto_record_begin () override;
+  void goto_record_end () override;
+  void goto_record (ULONGEST insn) override;
+};
+
+/* The "record-full" target.  */
+
+class record_full_target final : public record_full_base_target
+{
+public:
+  const char *shortname () override
+  { return "record-full"; }
+
+  void commit_resume () override;
+  void resume (ptid_t, int, enum gdb_signal) override;
+  void disconnect (const char *, int) override;
+  void detach (inferior *, int) override;
+  void mourn_inferior () override;
+  void kill () override;
+  void store_registers (struct regcache *, int) override;
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+  int insert_breakpoint (struct gdbarch *,
+ struct bp_target_info *) override;
+  int remove_breakpoint (struct gdbarch *,
+ struct bp_target_info *,
+ enum remove_bp_reason) override;
+};
+
+/* The "record-core" target.  */
+
+class record_full_core_target final : public record_full_base_target
+{
+public:
+  const char *shortname () override
+  { return "record-core"; }
+
+  void resume (ptid_t, int, enum gdb_signal) override;
+  void disconnect (const char *, int) override;
+  void kill () override;
+  void fetch_registers (struct regcache *regcache, int regno) override;
+  void prepare_to_store (struct regcache *regcache) override;
+  void store_registers (struct regcache *, int) override;
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+  int insert_breakpoint (struct gdbarch *,
+ struct bp_target_info *) override;
+  int remove_breakpoint (struct gdbarch *,
+ struct bp_target_info *,
+ enum remove_bp_reason) override;
+
+  int has_execution (ptid_t) override;
+};
+
+static record_full_target record_full_ops;
+static record_full_core_target record_full_core_ops;
+
+void
+record_full_target::detach (inferior *inf, int from_tty)
+{
+  record_detach (this, inf, from_tty);
+}
+
+void
+record_full_target::disconnect (const char *args, int from_tty)
+{
+  record_disconnect (this, args, from_tty);
+}
+
+void
+record_full_core_target::disconnect (const char *args, int from_tty)
+{
+  record_disconnect (this, args, from_tty);
+}
+
+void
+record_full_target::mourn_inferior ()
+{
+  record_mourn_inferior (this);
+}
+
+void
+record_full_target::kill ()
+{
+  record_kill (this);
+}
 
 /* See record-full.h.  */
 
@@ -232,8 +367,6 @@ static struct cmd_list_element *record_full_cmdlist;
 
 static void record_full_goto_insn (struct record_full_entry *entry,
    enum exec_direction_kind dir);
-static void record_full_save (struct target_ops *self,
-      const char *recfilename);
 
 /* Alloc and free functions for record_full_reg, record_full_mem, and
    record_full_end entries.  */
@@ -797,7 +930,7 @@ record_full_core_open_1 (const char *name, int from_tty)
   record_full_restore ();
 }
 
-/* "to_open" target method for 'live' processes.  */
+/* "open" target method for 'live' processes.  */
 
 static void
 record_full_open_1 (const char *name, int from_tty)
@@ -821,10 +954,10 @@ record_full_open_1 (const char *name, int from_tty)
 
 static void record_full_init_record_breakpoints (void);
 
-/* "to_open" target method.  Open the process record target.  */
+/* "open" target method.  Open the process record target.  */
 
-static void
-record_full_open (const char *name, int from_tty)
+void
+record_full_base_target::open (const char *name, int from_tty)
 {
   if (record_debug)
     fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
@@ -852,10 +985,10 @@ record_full_open (const char *name, int from_tty)
   gdb::observers::record_changed.notify (current_inferior (),  1, "full", NULL);
 }
 
-/* "to_close" target method.  Close the process record target.  */
+/* "close" target method.  Close the process record target.  */
 
-static void
-record_full_close (struct target_ops *self)
+void
+record_full_base_target::close ()
 {
   struct record_full_core_buf_entry *entry;
 
@@ -887,17 +1020,17 @@ record_full_close (struct target_ops *self)
     delete_async_event_handler (&record_full_async_inferior_event_token);
 }
 
-/* "to_async" target method.  */
+/* "async" target method.  */
 
-static void
-record_full_async (struct target_ops *ops, int enable)
+void
+record_full_base_target::async (int enable)
 {
   if (enable)
     mark_async_event_handler (record_full_async_inferior_event_token);
   else
     clear_async_event_handler (record_full_async_inferior_event_token);
 
-  ops->beneath->to_async (ops->beneath, enable);
+  beneath->async (enable);
 }
 
 static int record_full_resume_step = 0;
@@ -923,15 +1056,14 @@ static int record_full_resumed = 0;
 */
 static enum exec_direction_kind record_full_execution_dir = EXEC_FORWARD;
 
-/* "to_resume" target method.  Resume the process record target.  */
+/* "resume" target method.  Resume the process record target.  */
 
-static void
-record_full_resume (struct target_ops *ops, ptid_t ptid, int step,
-    enum gdb_signal signal)
+void
+record_full_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
 {
   record_full_resume_step = step;
   record_full_resumed = 1;
-  record_full_execution_dir = execution_direction;
+  record_full_execution_dir = ::execution_direction;
 
   if (!RECORD_FULL_IS_REPLAY)
     {
@@ -963,7 +1095,7 @@ record_full_resume (struct target_ops *ops, ptid_t ptid, int step,
       /* Make sure the target beneath reports all signals.  */
       target_pass_signals (0, NULL);
 
-      ops->beneath->to_resume (ops->beneath, ptid, step, signal);
+      this->beneath->resume (ptid, step, signal);
     }
 
   /* We are about to start executing the inferior (or simulate it),
@@ -972,18 +1104,18 @@ record_full_resume (struct target_ops *ops, ptid_t ptid, int step,
     target_async (1);
 }
 
-/* "to_commit_resume" method for process record target.  */
+/* "commit_resume" method for process record target.  */
 
-static void
-record_full_commit_resume (struct target_ops *ops)
+void
+record_full_target::commit_resume ()
 {
   if (!RECORD_FULL_IS_REPLAY)
-    ops->beneath->to_commit_resume (ops->beneath);
+    beneath->commit_resume ();
 }
 
 static int record_full_get_sig = 0;
 
-/* SIGINT signal handler, registered by "to_wait" method.  */
+/* SIGINT signal handler, registered by "wait" method.  */
 
 static void
 record_full_sig_handler (int signo)
@@ -1011,13 +1143,13 @@ record_full_wait_cleanups (void *ignore)
     record_full_list = record_full_list->prev;
 }
 
-/* "to_wait" target method for process record target.
+/* "wait" target method for process record target.
 
    In record mode, the target is always run in singlestep mode
-   (even when gdb says to continue).  The to_wait method intercepts
+   (even when gdb says to continue).  The wait method intercepts
    the stop events and determines which ones are to be passed on to
    gdb.  Most stop events are just singlestep events that gdb is not
-   to know about, so the to_wait method just records them and keeps
+   to know about, so the wait method just records them and keeps
    singlestepping.
 
    In replay mode, this function emulates the recorded execution log,
@@ -1060,7 +1192,7 @@ record_full_wait_1 (struct target_ops *ops,
       if (record_full_resume_step)
  {
   /* This is a single step.  */
-  return ops->beneath->to_wait (ops->beneath, ptid, status, options);
+  return ops->beneath->wait (ptid, status, options);
  }
       else
  {
@@ -1073,7 +1205,7 @@ record_full_wait_1 (struct target_ops *ops,
     {
       struct thread_info *tp;
 
-      ret = ops->beneath->to_wait (ops->beneath, ptid, status, options);
+      ret = ops->beneath->wait (ptid, status, options);
       if (status->kind == TARGET_WAITKIND_IGNORE)
  {
   if (record_debug)
@@ -1149,9 +1281,8 @@ record_full_wait_1 (struct target_ops *ops,
     "Process record: record_full_wait "
     "issuing one more step in the "
     "target beneath\n");
-      ops->beneath->to_resume (ops->beneath, ptid, step,
-       GDB_SIGNAL_0);
-      ops->beneath->to_commit_resume (ops->beneath);
+      ops->beneath->resume (ptid, step, GDB_SIGNAL_0);
+      ops->beneath->commit_resume ();
       continue;
     }
  }
@@ -1315,14 +1446,13 @@ replay_out:
   return inferior_ptid;
 }
 
-static ptid_t
-record_full_wait (struct target_ops *ops,
-  ptid_t ptid, struct target_waitstatus *status,
-  int options)
+ptid_t
+record_full_base_target::wait (ptid_t ptid, struct target_waitstatus *status,
+       int options)
 {
   ptid_t return_ptid;
 
-  return_ptid = record_full_wait_1 (ops, ptid, status, options);
+  return_ptid = record_full_wait_1 (this, ptid, status, options);
   if (status->kind != TARGET_WAITKIND_IGNORE)
     {
       /* We're reporting a stop.  Make sure any spurious
@@ -1333,54 +1463,54 @@ record_full_wait (struct target_ops *ops,
   return return_ptid;
 }
 
-static int
-record_full_stopped_by_watchpoint (struct target_ops *ops)
+int
+record_full_base_target::stopped_by_watchpoint ()
 {
   if (RECORD_FULL_IS_REPLAY)
     return record_full_stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
   else
-    return ops->beneath->to_stopped_by_watchpoint (ops->beneath);
+    return beneath->stopped_by_watchpoint ();
 }
 
-static int
-record_full_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
+int
+record_full_base_target::stopped_data_address (CORE_ADDR *addr_p)
 {
   if (RECORD_FULL_IS_REPLAY)
     return 0;
   else
-    return ops->beneath->to_stopped_data_address (ops->beneath, addr_p);
+    return this->beneath->stopped_data_address (addr_p);
 }
 
-/* The to_stopped_by_sw_breakpoint method of target record-full.  */
+/* The stopped_by_sw_breakpoint method of target record-full.  */
 
-static int
-record_full_stopped_by_sw_breakpoint (struct target_ops *ops)
+int
+record_full_base_target::stopped_by_sw_breakpoint ()
 {
   return record_full_stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT;
 }
 
-/* The to_supports_stopped_by_sw_breakpoint method of target
+/* The supports_stopped_by_sw_breakpoint method of target
    record-full.  */
 
-static int
-record_full_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
+int
+record_full_base_target::supports_stopped_by_sw_breakpoint ()
 {
   return 1;
 }
 
-/* The to_stopped_by_hw_breakpoint method of target record-full.  */
+/* The stopped_by_hw_breakpoint method of target record-full.  */
 
-static int
-record_full_stopped_by_hw_breakpoint (struct target_ops *ops)
+int
+record_full_base_target::stopped_by_hw_breakpoint ()
 {
   return record_full_stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT;
 }
 
-/* The to_supports_stopped_by_sw_breakpoint method of target
+/* The supports_stopped_by_sw_breakpoint method of target
    record-full.  */
 
-static int
-record_full_supports_stopped_by_hw_breakpoint (struct target_ops *ops)
+int
+record_full_base_target::supports_stopped_by_hw_breakpoint ()
 {
   return 1;
 }
@@ -1432,12 +1562,10 @@ record_full_registers_change (struct regcache *regcache, int regnum)
     record_full_insn_num++;
 }
 
-/* "to_store_registers" method for process record target.  */
+/* "store_registers" method for process record target.  */
 
-static void
-record_full_store_registers (struct target_ops *ops,
-     struct regcache *regcache,
-     int regno)
+void
+record_full_target::store_registers (struct regcache *regcache, int regno)
 {
   if (!record_full_gdb_operation_disable)
     {
@@ -1485,19 +1613,19 @@ record_full_store_registers (struct target_ops *ops,
 
       record_full_registers_change (regcache, regno);
     }
-  ops->beneath->to_store_registers (ops->beneath, regcache, regno);
+  this->beneath->store_registers (regcache, regno);
 }
 
-/* "to_xfer_partial" method.  Behavior is conditional on
+/* "xfer_partial" method.  Behavior is conditional on
    RECORD_FULL_IS_REPLAY.
    In replay mode, we cannot write memory unles we are willing to
    invalidate the record/replay log from this point forward.  */
 
-static enum target_xfer_status
-record_full_xfer_partial (struct target_ops *ops, enum target_object object,
-  const char *annex, gdb_byte *readbuf,
-  const gdb_byte *writebuf, ULONGEST offset,
-  ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+record_full_target::xfer_partial (enum target_object object,
+  const char *annex, gdb_byte *readbuf,
+  const gdb_byte *writebuf, ULONGEST offset,
+  ULONGEST len, ULONGEST *xfered_len)
 {
   if (!record_full_gdb_operation_disable
       && (object == TARGET_OBJECT_MEMORY
@@ -1550,9 +1678,8 @@ record_full_xfer_partial (struct target_ops *ops, enum target_object object,
  record_full_insn_num++;
     }
 
-  return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
- readbuf, writebuf, offset,
- len, xfered_len);
+  return this->beneath->xfer_partial (object, annex, readbuf, writebuf, offset,
+      len, xfered_len);
 }
 
 /* This structure represents a breakpoint inserted while the record
@@ -1614,10 +1741,9 @@ record_full_init_record_breakpoints (void)
    insert or remove breakpoints in the real target when replaying, nor
    when recording.  */
 
-static int
-record_full_insert_breakpoint (struct target_ops *ops,
-       struct gdbarch *gdbarch,
-       struct bp_target_info *bp_tgt)
+int
+record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
+       struct bp_target_info *bp_tgt)
 {
   struct record_full_breakpoint *bp;
   int in_target_beneath = 0;
@@ -1630,12 +1756,11 @@ record_full_insert_breakpoint (struct target_ops *ops,
  However, we do have to insert software single-step
  breakpoints, in case the target can't hardware step.  To keep
  things simple, we always insert.  */
-      int ret;
 
       scoped_restore restore_operation_disable
  = record_full_gdb_operation_disable_set ();
-      ret = ops->beneath->to_insert_breakpoint (ops->beneath, gdbarch, bp_tgt);
 
+      int ret = this->beneath->insert_breakpoint (gdbarch, bp_tgt);
       if (ret != 0)
  return ret;
 
@@ -1666,13 +1791,12 @@ record_full_insert_breakpoint (struct target_ops *ops,
   return 0;
 }
 
-/* "to_remove_breakpoint" method for process record target.  */
+/* "remove_breakpoint" method for process record target.  */
 
-static int
-record_full_remove_breakpoint (struct target_ops *ops,
-       struct gdbarch *gdbarch,
-       struct bp_target_info *bp_tgt,
-       enum remove_bp_reason reason)
+int
+record_full_target::remove_breakpoint (struct gdbarch *gdbarch,
+       struct bp_target_info *bp_tgt,
+       enum remove_bp_reason reason)
 {
   struct record_full_breakpoint *bp;
   int ix;
@@ -1687,12 +1811,11 @@ record_full_remove_breakpoint (struct target_ops *ops,
  {
   if (bp->in_target_beneath)
     {
-      int ret;
-
       scoped_restore restore_operation_disable
  = record_full_gdb_operation_disable_set ();
-      ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch,
- bp_tgt, reason);
+
+      int ret = this->beneath->remove_breakpoint (gdbarch, bp_tgt,
+  reason);
       if (ret != 0)
  return ret;
     }
@@ -1709,19 +1832,18 @@ record_full_remove_breakpoint (struct target_ops *ops,
   gdb_assert_not_reached ("removing unknown breakpoint");
 }
 
-/* "to_can_execute_reverse" method for process record target.  */
+/* "can_execute_reverse" method for process record target.  */
 
-static int
-record_full_can_execute_reverse (struct target_ops *self)
+int
+record_full_base_target::can_execute_reverse ()
 {
   return 1;
 }
 
-/* "to_get_bookmark" method for process record and prec over core.  */
+/* "get_bookmark" method for process record and prec over core.  */
 
-static gdb_byte *
-record_full_get_bookmark (struct target_ops *self, const char *args,
-  int from_tty)
+gdb_byte *
+record_full_base_target::get_bookmark (const char *args, int from_tty)
 {
   char *ret = NULL;
 
@@ -1741,11 +1863,11 @@ record_full_get_bookmark (struct target_ops *self, const char *args,
   return (gdb_byte *) ret;
 }
 
-/* "to_goto_bookmark" method for process record and prec over core.  */
+/* "goto_bookmark" method for process record and prec over core.  */
 
-static void
-record_full_goto_bookmark (struct target_ops *self,
-   const gdb_byte *raw_bookmark, int from_tty)
+void
+record_full_base_target::goto_bookmark (const gdb_byte *raw_bookmark,
+ int from_tty)
 {
   const char *bookmark = (const char *) raw_bookmark;
 
@@ -1766,22 +1888,22 @@ record_full_goto_bookmark (struct target_ops *self,
   record_goto (bookmark);
 }
 
-static enum exec_direction_kind
-record_full_execution_direction (struct target_ops *self)
+enum exec_direction_kind
+record_full_base_target::execution_direction ()
 {
   return record_full_execution_dir;
 }
 
-/* The to_record_method method of target record-full.  */
+/* The record_method method of target record-full.  */
 
 enum record_method
-record_full_record_method (struct target_ops *self, ptid_t ptid)
+record_full_base_target::record_method (ptid_t ptid)
 {
   return RECORD_METHOD_FULL;
 }
 
-static void
-record_full_info (struct target_ops *self)
+void
+record_full_base_target::info_record ()
 {
   struct record_full_entry *p;
 
@@ -1824,26 +1946,32 @@ record_full_info (struct target_ops *self)
    record_full_insn_max_num);
 }
 
-/* The "to_record_delete" target method.  */
+bool
+record_full_base_target::supports_delete_record ()
+{
+  return true;
+}
 
-static void
-record_full_delete (struct target_ops *self)
+/* The "delete_record" target method.  */
+
+void
+record_full_base_target::delete_record ()
 {
   record_full_list_release_following (record_full_list);
 }
 
-/* The "to_record_is_replaying" target method.  */
+/* The "record_is_replaying" target method.  */
 
-static int
-record_full_is_replaying (struct target_ops *self, ptid_t ptid)
+int
+record_full_base_target::record_is_replaying (ptid_t ptid)
 {
   return RECORD_FULL_IS_REPLAY;
 }
 
-/* The "to_record_will_replay" target method.  */
+/* The "record_will_replay" target method.  */
 
-static int
-record_full_will_replay (struct target_ops *self, ptid_t ptid, int dir)
+int
+record_full_base_target::record_will_replay (ptid_t ptid, int dir)
 {
   /* We can currently only record when executing forwards.  Should we be able
      to record when executing backwards on targets that support reverse
@@ -1880,10 +2008,10 @@ record_full_goto_entry (struct record_full_entry *p)
   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
 }
 
-/* The "to_goto_record_begin" target method.  */
+/* The "goto_record_begin" target method.  */
 
-static void
-record_full_goto_begin (struct target_ops *self)
+void
+record_full_base_target::goto_record_begin ()
 {
   struct record_full_entry *p = NULL;
 
@@ -1894,10 +2022,10 @@ record_full_goto_begin (struct target_ops *self)
   record_full_goto_entry (p);
 }
 
-/* The "to_goto_record_end" target method.  */
+/* The "goto_record_end" target method.  */
 
-static void
-record_full_goto_end (struct target_ops *self)
+void
+record_full_base_target::goto_record_end ()
 {
   struct record_full_entry *p = NULL;
 
@@ -1910,10 +2038,10 @@ record_full_goto_end (struct target_ops *self)
   record_full_goto_entry (p);
 }
 
-/* The "to_goto_record" target method.  */
+/* The "goto_record" target method.  */
 
-static void
-record_full_goto (struct target_ops *self, ULONGEST target_insn)
+void
+record_full_base_target::goto_record (ULONGEST target_insn)
 {
   struct record_full_entry *p = NULL;
 
@@ -1924,73 +2052,23 @@ record_full_goto (struct target_ops *self, ULONGEST target_insn)
   record_full_goto_entry (p);
 }
 
-/* The "to_record_stop_replaying" target method.  */
+/* The "record_stop_replaying" target method.  */
 
-static void
-record_full_stop_replaying (struct target_ops *self)
+void
+record_full_base_target::record_stop_replaying ()
 {
-  record_full_goto_end (self);
+  goto_record_end ();
 }
 
-static void
-init_record_full_ops (void)
-{
-  record_full_ops.to_shortname = "record-full";
-  record_full_ops.to_longname = "Process record and replay target";
-  record_full_ops.to_doc =
-    "Log program while executing and replay execution from log.";
-  record_full_ops.to_open = record_full_open;
-  record_full_ops.to_close = record_full_close;
-  record_full_ops.to_async = record_full_async;
-  record_full_ops.to_resume = record_full_resume;
-  record_full_ops.to_commit_resume = record_full_commit_resume;
-  record_full_ops.to_wait = record_full_wait;
-  record_full_ops.to_disconnect = record_disconnect;
-  record_full_ops.to_detach = record_detach;
-  record_full_ops.to_mourn_inferior = record_mourn_inferior;
-  record_full_ops.to_kill = record_kill;
-  record_full_ops.to_store_registers = record_full_store_registers;
-  record_full_ops.to_xfer_partial = record_full_xfer_partial;
-  record_full_ops.to_insert_breakpoint = record_full_insert_breakpoint;
-  record_full_ops.to_remove_breakpoint = record_full_remove_breakpoint;
-  record_full_ops.to_stopped_by_watchpoint = record_full_stopped_by_watchpoint;
-  record_full_ops.to_stopped_data_address = record_full_stopped_data_address;
-  record_full_ops.to_stopped_by_sw_breakpoint
-    = record_full_stopped_by_sw_breakpoint;
-  record_full_ops.to_supports_stopped_by_sw_breakpoint
-    = record_full_supports_stopped_by_sw_breakpoint;
-  record_full_ops.to_stopped_by_hw_breakpoint
-    = record_full_stopped_by_hw_breakpoint;
-  record_full_ops.to_supports_stopped_by_hw_breakpoint
-    = record_full_supports_stopped_by_hw_breakpoint;
-  record_full_ops.to_can_execute_reverse = record_full_can_execute_reverse;
-  record_full_ops.to_stratum = record_stratum;
-  /* Add bookmark target methods.  */
-  record_full_ops.to_get_bookmark = record_full_get_bookmark;
-  record_full_ops.to_goto_bookmark = record_full_goto_bookmark;
-  record_full_ops.to_execution_direction = record_full_execution_direction;
-  record_full_ops.to_record_method = record_full_record_method;
-  record_full_ops.to_info_record = record_full_info;
-  record_full_ops.to_save_record = record_full_save;
-  record_full_ops.to_delete_record = record_full_delete;
-  record_full_ops.to_record_is_replaying = record_full_is_replaying;
-  record_full_ops.to_record_will_replay = record_full_will_replay;
-  record_full_ops.to_record_stop_replaying = record_full_stop_replaying;
-  record_full_ops.to_goto_record_begin = record_full_goto_begin;
-  record_full_ops.to_goto_record_end = record_full_goto_end;
-  record_full_ops.to_goto_record = record_full_goto;
-  record_full_ops.to_magic = OPS_MAGIC;
-}
-
-/* "to_resume" method for prec over corefile.  */
+/* "resume" method for prec over corefile.  */
 
-static void
-record_full_core_resume (struct target_ops *ops, ptid_t ptid, int step,
- enum gdb_signal signal)
+void
+record_full_core_target::resume (ptid_t ptid, int step,
+ enum gdb_signal signal)
 {
   record_full_resume_step = step;
   record_full_resumed = 1;
-  record_full_execution_dir = execution_direction;
+  record_full_execution_dir = ::execution_direction;
 
   /* We are about to start executing the inferior (or simulate it),
      let's register it with the event loop.  */
@@ -1998,23 +2076,22 @@ record_full_core_resume (struct target_ops *ops, ptid_t ptid, int step,
     target_async (1);
 }
 
-/* "to_kill" method for prec over corefile.  */
+/* "kill" method for prec over corefile.  */
 
-static void
-record_full_core_kill (struct target_ops *ops)
+void
+record_full_core_target::kill ()
 {
   if (record_debug)
     fprintf_unfiltered (gdb_stdlog, "Process record: record_full_core_kill\n");
 
-  unpush_target (&record_full_core_ops);
+  unpush_target (this);
 }
 
-/* "to_fetch_registers" method for prec over corefile.  */
+/* "fetch_registers" method for prec over corefile.  */
 
-static void
-record_full_core_fetch_registers (struct target_ops *ops,
-  struct regcache *regcache,
-  int regno)
+void
+record_full_core_target::fetch_registers (struct regcache *regcache,
+  int regno)
 {
   if (regno < 0)
     {
@@ -2028,20 +2105,18 @@ record_full_core_fetch_registers (struct target_ops *ops,
     regcache->raw_supply (regno, *record_full_core_regbuf);
 }
 
-/* "to_prepare_to_store" method for prec over corefile.  */
+/* "prepare_to_store" method for prec over corefile.  */
 
-static void
-record_full_core_prepare_to_store (struct target_ops *self,
-   struct regcache *regcache)
+void
+record_full_core_target::prepare_to_store (struct regcache *regcache)
 {
 }
 
-/* "to_store_registers" method for prec over corefile.  */
+/* "store_registers" method for prec over corefile.  */
 
-static void
-record_full_core_store_registers (struct target_ops *ops,
-                             struct regcache *regcache,
-                             int regno)
+void
+record_full_core_target::store_registers (struct regcache *regcache,
+  int regno)
 {
   if (record_full_gdb_operation_disable)
     record_full_core_regbuf->raw_supply (regno, *regcache);
@@ -2049,14 +2124,13 @@ record_full_core_store_registers (struct target_ops *ops,
     error (_("You can't do that without a process to debug."));
 }
 
-/* "to_xfer_partial" method for prec over corefile.  */
+/* "xfer_partial" method for prec over corefile.  */
 
-static enum target_xfer_status
-record_full_core_xfer_partial (struct target_ops *ops,
-       enum target_object object,
-       const char *annex, gdb_byte *readbuf,
-       const gdb_byte *writebuf, ULONGEST offset,
-       ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+record_full_core_target::xfer_partial (enum target_object object,
+       const char *annex, gdb_byte *readbuf,
+       const gdb_byte *writebuf, ULONGEST offset,
+       ULONGEST len, ULONGEST *xfered_len)
 {
   if (object == TARGET_OBJECT_MEMORY)
     {
@@ -2120,11 +2194,10 @@ record_full_core_xfer_partial (struct target_ops *ops,
   else
     {
       if (!entry)
- return ops->beneath->to_xfer_partial (ops->beneath,
-      object, annex,
-      readbuf, writebuf,
-      offset, len,
-      xfered_len);
+ return this->beneath->xfer_partial (object, annex,
+    readbuf, writebuf,
+    offset, len,
+    xfered_len);
 
       memcpy (readbuf, entry->buf + sec_offset,
       (size_t) len);
@@ -2141,93 +2214,38 @@ record_full_core_xfer_partial (struct target_ops *ops,
  error (_("You can't do that without a process to debug."));
     }
 
-  return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
- readbuf, writebuf, offset, len,
- xfered_len);
+  return this->beneath->xfer_partial (object, annex,
+      readbuf, writebuf, offset, len,
+      xfered_len);
 }
 
-/* "to_insert_breakpoint" method for prec over corefile.  */
+/* "insert_breakpoint" method for prec over corefile.  */
 
-static int
-record_full_core_insert_breakpoint (struct target_ops *ops,
-    struct gdbarch *gdbarch,
-    struct bp_target_info *bp_tgt)
+int
+record_full_core_target::insert_breakpoint (struct gdbarch *gdbarch,
+    struct bp_target_info *bp_tgt)
 {
   return 0;
 }
 
-/* "to_remove_breakpoint" method for prec over corefile.  */
+/* "remove_breakpoint" method for prec over corefile.  */
 
-static int
-record_full_core_remove_breakpoint (struct target_ops *ops,
-    struct gdbarch *gdbarch,
-    struct bp_target_info *bp_tgt,
-    enum remove_bp_reason reason)
+int
+record_full_core_target::remove_breakpoint (struct gdbarch *gdbarch,
+    struct bp_target_info *bp_tgt,
+    enum remove_bp_reason reason)
 {
   return 0;
 }
 
-/* "to_has_execution" method for prec over corefile.  */
+/* "has_execution" method for prec over corefile.  */
 
-static int
-record_full_core_has_execution (struct target_ops *ops, ptid_t the_ptid)
+int
+record_full_core_target::has_execution (ptid_t the_ptid)
 {
   return 1;
 }
 
-static void
-init_record_full_core_ops (void)
-{
-  record_full_core_ops.to_shortname = "record-core";
-  record_full_core_ops.to_longname = "Process record and replay target";
-  record_full_core_ops.to_doc =
-    "Log program while executing and replay execution from log.";
-  record_full_core_ops.to_open = record_full_open;
-  record_full_core_ops.to_close = record_full_close;
-  record_full_core_ops.to_async = record_full_async;
-  record_full_core_ops.to_resume = record_full_core_resume;
-  record_full_core_ops.to_wait = record_full_wait;
-  record_full_core_ops.to_kill = record_full_core_kill;
-  record_full_core_ops.to_fetch_registers = record_full_core_fetch_registers;
-  record_full_core_ops.to_prepare_to_store = record_full_core_prepare_to_store;
-  record_full_core_ops.to_store_registers = record_full_core_store_registers;
-  record_full_core_ops.to_xfer_partial = record_full_core_xfer_partial;
-  record_full_core_ops.to_insert_breakpoint
-    = record_full_core_insert_breakpoint;
-  record_full_core_ops.to_remove_breakpoint
-    = record_full_core_remove_breakpoint;
-  record_full_core_ops.to_stopped_by_watchpoint
-    = record_full_stopped_by_watchpoint;
-  record_full_core_ops.to_stopped_data_address
-    = record_full_stopped_data_address;
-  record_full_core_ops.to_stopped_by_sw_breakpoint
-    = record_full_stopped_by_sw_breakpoint;
-  record_full_core_ops.to_supports_stopped_by_sw_breakpoint
-    = record_full_supports_stopped_by_sw_breakpoint;
-  record_full_core_ops.to_stopped_by_hw_breakpoint
-    = record_full_stopped_by_hw_breakpoint;
-  record_full_core_ops.to_supports_stopped_by_hw_breakpoint
-    = record_full_supports_stopped_by_hw_breakpoint;
-  record_full_core_ops.to_can_execute_reverse
-    = record_full_can_execute_reverse;
-  record_full_core_ops.to_has_execution = record_full_core_has_execution;
-  record_full_core_ops.to_stratum = record_stratum;
-  /* Add bookmark target methods.  */
-  record_full_core_ops.to_get_bookmark = record_full_get_bookmark;
-  record_full_core_ops.to_goto_bookmark = record_full_goto_bookmark;
-  record_full_core_ops.to_execution_direction
-    = record_full_execution_direction;
-  record_full_core_ops.to_record_method = record_full_record_method;
-  record_full_core_ops.to_info_record = record_full_info;
-  record_full_core_ops.to_delete_record = record_full_delete;
-  record_full_core_ops.to_record_is_replaying = record_full_is_replaying;
-  record_full_core_ops.to_record_will_replay = record_full_will_replay;
-  record_full_core_ops.to_goto_record_begin = record_full_goto_begin;
-  record_full_core_ops.to_goto_record_end = record_full_goto_end;
-  record_full_core_ops.to_goto_record = record_full_goto;
-  record_full_core_ops.to_magic = OPS_MAGIC;
-}
-
 /* Record log save-file format
    Version 1 (never released)
 
@@ -2501,14 +2519,14 @@ static void
 cmd_record_full_restore (const char *args, int from_tty)
 {
   core_file_command (args, from_tty);
-  record_full_open (args, from_tty);
+  record_full_ops.open (args, from_tty);
 }
 
 /* Save the execution log to a file.  We use a modified elf corefile
    format, with an extra section for our data.  */
 
-static void
-record_full_save (struct target_ops *self, const char *recfilename)
+void
+record_full_base_target::save_record (const char *recfilename)
 {
   struct record_full_entry *cur_record_full_list;
   uint32_t magic;
@@ -2790,10 +2808,8 @@ _initialize_record_full (void)
   record_full_first.next = NULL;
   record_full_first.type = record_full_end;
 
-  init_record_full_ops ();
   add_target (&record_full_ops);
   add_deprecated_target_alias (&record_full_ops, "record");
-  init_record_full_core_ops ();
   add_target (&record_full_core_ops);
 
   add_prefix_cmd ("full", class_obscure, cmd_record_full_start,
diff --git a/gdb/record.c b/gdb/record.c
index 7c35dc8989..492d516ea2 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -154,9 +154,9 @@ record_read_memory (struct gdbarch *gdbarch,
 static void
 record_stop (struct target_ops *t)
 {
-  DEBUG ("stop %s", t->to_shortname);
+  DEBUG ("stop %s", t->shortname ());
 
-  t->to_stop_recording (t);
+  t->stop_recording ();
 }
 
 /* Unpush the record target.  */
@@ -164,7 +164,7 @@ record_stop (struct target_ops *t)
 static void
 record_unpush (struct target_ops *t)
 {
-  DEBUG ("unpush %s", t->to_shortname);
+  DEBUG ("unpush %s", t->shortname ());
 
   unpush_target (t);
 }
@@ -176,7 +176,7 @@ record_disconnect (struct target_ops *t, const char *args, int from_tty)
 {
   gdb_assert (t->to_stratum == record_stratum);
 
-  DEBUG ("disconnect %s", t->to_shortname);
+  DEBUG ("disconnect %s", t->shortname ());
 
   record_stop (t);
   record_unpush (t);
@@ -191,7 +191,7 @@ record_detach (struct target_ops *t, inferior *inf, int from_tty)
 {
   gdb_assert (t->to_stratum == record_stratum);
 
-  DEBUG ("detach %s", t->to_shortname);
+  DEBUG ("detach %s", t->shortname ());
 
   record_stop (t);
   record_unpush (t);
@@ -206,7 +206,7 @@ record_mourn_inferior (struct target_ops *t)
 {
   gdb_assert (t->to_stratum == record_stratum);
 
-  DEBUG ("mourn inferior %s", t->to_shortname);
+  DEBUG ("mourn inferior %s", t->shortname ());
 
   /* It is safer to not stop recording.  Resources will be freed when
      threads are discarded.  */
@@ -222,7 +222,7 @@ record_kill (struct target_ops *t)
 {
   gdb_assert (t->to_stratum == record_stratum);
 
-  DEBUG ("kill %s", t->to_shortname);
+  DEBUG ("kill %s", t->shortname ());
 
   /* It is safer to not stop recording.  Resources will be freed when
      threads are discarded.  */
@@ -346,8 +346,8 @@ info_record_command (const char *args, int from_tty)
       return;
     }
 
-  printf_filtered (_("Active record target: %s\n"), t->to_shortname);
-  t->to_info_record (t);
+  printf_filtered (_("Active record target: %s\n"), t->shortname ());
+  t->info_record ();
 }
 
 /* The "record save" command.  */
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 11/40] target_ops/C++: remote/extended-remote targets

Pedro Alves-7
In reply to this post by Pedro Alves-7
This is a first pass, just enough to C++ify target_ops.

A later pass will convert more free functions to methods, and make the
remote_state be truly per remote instance, allowing multiple
simultaneous instances of remote targets.
---
 gdb/remote.c | 1319 +++++++++++++++++++++++++++++++---------------------------
 1 file changed, 712 insertions(+), 607 deletions(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index e6d07a620c..0b22b11c09 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -76,6 +76,337 @@
 #include "environ.h"
 #include "common/byte-vector.h"
 
+/* The remote target.  */
+
+class remote_target : public target_ops
+{
+public:
+  remote_target ()
+  {
+    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.).");
+  }
+
+  thread_control_capabilities get_thread_control_capabilities () override
+  { return tc_schedlock; }
+
+  void open (const char *, int) override;
+  void close () override;
+
+  void detach (inferior *, int) override;
+  void disconnect (const char *, int) override;
+
+  void commit_resume () override;
+  void resume (ptid_t, int, enum gdb_signal) override;
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+  void prepare_to_store (struct regcache *) override;
+
+  void files_info () override;
+
+  int insert_breakpoint (struct gdbarch *, struct bp_target_info *) override;
+
+  int remove_breakpoint (struct gdbarch *, struct bp_target_info *,
+ enum remove_bp_reason) override;
+
+
+  int stopped_by_sw_breakpoint () override;
+  int supports_stopped_by_sw_breakpoint () override;
+
+  int stopped_by_hw_breakpoint () override;
+
+  int supports_stopped_by_hw_breakpoint () override;
+
+  int stopped_by_watchpoint () override;
+
+  int stopped_data_address (CORE_ADDR *) override;
+
+  int watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int) override;
+
+  int can_use_hw_breakpoint (enum bptype, int, int) override;
+
+  int insert_hw_breakpoint (struct gdbarch *, struct bp_target_info *) override;
+
+  int remove_hw_breakpoint (struct gdbarch *, struct bp_target_info *) override;
+
+  int region_ok_for_hw_watchpoint (CORE_ADDR, int) override;
+
+  int insert_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
+ struct expression *) override;
+
+  int remove_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
+ struct expression *) override;
+
+  void kill () override;
+
+  void load (const char *, int) override;
+
+  void mourn_inferior () override;
+
+  void pass_signals (int, unsigned char *) override;
+
+  int set_syscall_catchpoint (int, bool, int,
+      gdb::array_view<const int>) override;
+
+  void program_signals (int, unsigned char *) override;
+
+  int thread_alive (ptid_t ptid) override;
+
+  const char *thread_name (struct thread_info *) override;
+
+  void update_thread_list () override;
+
+  const char *pid_to_str (ptid_t) override;
+
+  const char *extra_thread_info (struct thread_info *) override;
+
+  ptid_t get_ada_task_ptid (long lwp, long thread) override;
+
+  thread_info *thread_handle_to_thread_info (const gdb_byte *thread_handle,
+     int handle_len,
+     inferior *inf) override;
+
+  void stop (ptid_t) override;
+
+  void interrupt () override;
+
+  void pass_ctrlc () override;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+  ULONGEST get_memory_xfer_limit () override;
+
+  void rcmd (const char *command, struct ui_file *output) override;
+
+  char *pid_to_exec_file (int pid) override;
+
+  void log_command (const char *cmd) override
+  {
+    serial_log_command (this, cmd);
+  }
+
+  CORE_ADDR get_thread_local_address (ptid_t ptid,
+      CORE_ADDR load_module_addr,
+      CORE_ADDR offset) override;
+
+  int has_all_memory ()  override { return default_child_has_all_memory (); }
+  int has_memory ()  override { return default_child_has_memory (); }
+  int has_stack ()  override { return default_child_has_stack (); }
+  int has_registers ()  override { return default_child_has_registers (); }
+  int has_execution (ptid_t ptid)  override { return default_child_has_execution (ptid); }
+
+  int can_execute_reverse () override;
+
+  std::vector<mem_region> memory_map () override;
+
+  void flash_erase (ULONGEST address, LONGEST length) override;
+
+  void flash_done () override;
+
+  const struct target_desc *read_description () override;
+
+  int search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
+     const gdb_byte *pattern, ULONGEST pattern_len,
+     CORE_ADDR *found_addrp) override;
+
+  int can_async_p () override;
+
+  int is_async_p () override;
+
+  void async (int) override;
+
+  void thread_events (int) override;
+
+  int can_do_single_step () override;
+
+  void terminal_inferior () override;
+
+  void terminal_ours () override;
+
+  int supports_non_stop () override;
+
+  int supports_multi_process () override;
+
+  int supports_disable_randomization () override;
+
+  int filesystem_is_local () override;
+
+
+  int fileio_open (struct inferior *inf, const char *filename,
+   int flags, int mode, int warn_if_slow,
+   int *target_errno) override;
+
+  int fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
+     ULONGEST offset, int *target_errno) override;
+
+  int fileio_pread (int fd, gdb_byte *read_buf, int len,
+    ULONGEST offset, int *target_errno) override;
+
+  int fileio_fstat (int fd, struct stat *sb, int *target_errno) override;
+
+  int fileio_close (int fd, int *target_errno) override;
+
+  int fileio_unlink (struct inferior *inf,
+     const char *filename,
+     int *target_errno) override;
+
+  gdb::optional<std::string>
+    fileio_readlink (struct inferior *inf,
+     const char *filename,
+     int *target_errno) override;
+
+  int supports_enable_disable_tracepoint () override;
+
+  int supports_string_tracing () override;
+
+  int supports_evaluation_of_breakpoint_conditions () override;
+
+  int can_run_breakpoint_commands () override;
+
+  void trace_init () override;
+
+  void download_tracepoint (struct bp_location *location) override;
+
+  int can_download_tracepoint () override;
+
+  void download_trace_state_variable (const trace_state_variable &tsv) override;
+
+  void enable_tracepoint (struct bp_location *location) override;
+
+  void disable_tracepoint (struct bp_location *location) override;
+
+  void trace_set_readonly_regions () override;
+
+  void trace_start () override;
+
+  int get_trace_status (struct trace_status *ts) override;
+
+  void get_tracepoint_status (struct breakpoint *tp, struct uploaded_tp *utp)
+    override;
+
+  void trace_stop () override;
+
+  int trace_find (enum trace_find_type type, int num,
+  CORE_ADDR addr1, CORE_ADDR addr2, int *tpp) override;
+
+  int get_trace_state_variable_value (int tsv, LONGEST *val) override;
+
+  int save_trace_data (const char *filename) override;
+
+  int upload_tracepoints (struct uploaded_tp **utpp) override;
+
+  int upload_trace_state_variables (struct uploaded_tsv **utsvp) override;
+
+  LONGEST get_raw_trace_data (gdb_byte *buf, ULONGEST offset, LONGEST len) override;
+
+  int get_min_fast_tracepoint_insn_len () override;
+
+  void set_disconnected_tracing (int val) override;
+
+  void set_circular_trace_buffer (int val) override;
+
+  void set_trace_buffer_size (LONGEST val) override;
+
+  int set_trace_notes (const char *user, const char *notes,
+       const char *stopnotes) override;
+
+  int core_of_thread (ptid_t ptid) override;
+
+  int verify_memory (const gdb_byte *data,
+     CORE_ADDR memaddr, ULONGEST size) override;
+
+
+  int get_tib_address (ptid_t ptid, CORE_ADDR *addr) override;
+
+  void set_permissions () override;
+
+  bool static_tracepoint_marker_at (CORE_ADDR,
+    struct static_tracepoint_marker *marker)
+    override;
+
+  std::vector<static_tracepoint_marker>
+    static_tracepoint_markers_by_strid (const char *id) override;
+
+  traceframe_info_up traceframe_info () override;
+
+  int use_agent (int use) override;
+  int can_use_agent () override;
+
+  struct btrace_target_info *enable_btrace (ptid_t ptid,
+    const struct btrace_config *conf) override;
+
+  void disable_btrace (struct btrace_target_info *tinfo) override;
+
+  void teardown_btrace (struct btrace_target_info *tinfo) override;
+
+  enum btrace_error read_btrace (struct btrace_data *data,
+ struct btrace_target_info *btinfo,
+ enum btrace_read_type type) override;
+
+  const struct btrace_config *btrace_conf (const struct btrace_target_info *) override;
+  int augmented_libraries_svr4_read () override;
+  int follow_fork (int, int) override;
+  void follow_exec (struct inferior *, char *) override;
+  int insert_fork_catchpoint (int) override;
+  int remove_fork_catchpoint (int) override;
+  int insert_vfork_catchpoint (int) override;
+  int remove_vfork_catchpoint (int) override;
+  int insert_exec_catchpoint (int) override;
+  int remove_exec_catchpoint (int) override;
+  enum exec_direction_kind execution_direction () override;
+
+protected:
+  void open_1 (const char *name, int from_tty, int extended_p);
+  void start_remote (int from_tty, int extended_p);
+};
+
+/* Set up the extended remote target by extending the standard remote
+   target and adding to it.  */
+
+class extended_remote_target : public remote_target
+{
+public:
+  const char *shortname () override
+  { return "extended-remote"; }
+
+  const char *longname () override
+  { return _("Extended remote serial target in gdb-specific protocol"); }
+
+  void open (const char *, int) override;
+
+  bool can_create_inferior () override { return true; }
+  void create_inferior (const char *, const std::string &,
+ char **, int) override;
+
+  void detach (inferior *, int) override;
+
+  bool can_attach () override { return true; }
+  void attach (const char *, int) override;
+
+  void post_attach (int) override;
+  int supports_disable_randomization () override;
+};
+
 /* Per-program-space data key.  */
 static const struct program_space_data *remote_pspace_data;
 
@@ -102,42 +433,18 @@ static int getpkt_sane (char **buf, long *sizeof_buf, int forever);
 static int getpkt_or_notif_sane (char **buf, long *sizeof_buf,
  int forever, int *is_notif);
 
-static void remote_files_info (struct target_ops *ignore);
-
-static void remote_prepare_to_store (struct target_ops *self,
-     struct regcache *regcache);
-
-static void remote_open_1 (const char *, int, struct target_ops *,
-   int extended_p);
-
-static void remote_close (struct target_ops *self);
-
 struct remote_state;
 
 static int remote_vkill (int pid, struct remote_state *rs);
 
 static void remote_kill_k (void);
 
-static void remote_mourn (struct target_ops *ops);
-
-static void extended_remote_restart (void);
-
 static void remote_send (char **buf, long *sizeof_buf_p);
 
 static int readchar (int timeout);
 
 static void remote_serial_write (const char *str, int len);
 
-static void remote_kill (struct target_ops *ops);
-
-static int remote_can_async_p (struct target_ops *);
-
-static int remote_is_async_p (struct target_ops *);
-
-static void remote_async (struct target_ops *ops, int enable);
-
-static void remote_thread_events (struct target_ops *ops, int enable);
-
 static void interrupt_query (void);
 
 static void set_general_thread (ptid_t ptid);
@@ -151,12 +458,6 @@ static long read_frame (char **buf_p, long *sizeof_buf);
 
 static int hexnumlen (ULONGEST num);
 
-static void init_remote_ops (void);
-
-static void init_extended_remote_ops (void);
-
-static void remote_stop (struct target_ops *self, ptid_t);
-
 static int stubhex (int ch);
 
 static int hexnumstr (char *, ULONGEST);
@@ -187,17 +488,6 @@ static void show_remote_protocol_packet_cmd (struct ui_file *file,
 static char *write_ptid (char *buf, const char *endbuf, ptid_t ptid);
 static ptid_t read_ptid (const char *buf, const char **obuf);
 
-static void remote_set_permissions (struct target_ops *self);
-
-static int remote_get_trace_status (struct target_ops *self,
-    struct trace_status *ts);
-
-static int remote_upload_tracepoints (struct target_ops *self,
-      struct uploaded_tp **utpp);
-
-static int remote_upload_trace_state_variables (struct target_ops *self,
- struct uploaded_tsv **utsvp);
-  
 static void remote_query_supported (void);
 
 static void remote_check_symbols (void);
@@ -214,16 +504,10 @@ static void remove_new_fork_children (struct threads_listing_context *);
 
 static void remote_async_inferior_event_handler (gdb_client_data);
 
-static void remote_terminal_ours (struct target_ops *self);
-
 static int remote_read_description_p (struct target_ops *target);
 
 static void remote_console_output (char *msg);
 
-static int remote_supports_cond_breakpoints (struct target_ops *self);
-
-static int remote_can_run_breakpoint_commands (struct target_ops *self);
-
 static void remote_btrace_reset (void);
 
 static void remote_btrace_maybe_reopen (void);
@@ -902,9 +1186,9 @@ packet_reg_from_pnum (struct gdbarch *gdbarch, struct remote_arch_state *rsa,
   return NULL;
 }
 
-static struct target_ops remote_ops;
+static remote_target remote_ops;
 
-static struct target_ops extended_remote_ops;
+static extended_remote_target extended_remote_ops;
 
 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
    ``forever'' still use the normal timeout mechanism.  This is
@@ -1656,8 +1940,8 @@ remote_exec_event_p (struct remote_state *rs)
 /* Insert fork catchpoint target routine.  If fork events are enabled
    then return success, nothing more to do.  */
 
-static int
-remote_insert_fork_catchpoint (struct target_ops *ops, int pid)
+int
+remote_target::insert_fork_catchpoint (int pid)
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -1667,8 +1951,8 @@ remote_insert_fork_catchpoint (struct target_ops *ops, int pid)
 /* Remove fork catchpoint target routine.  Nothing to do, just
    return success.  */
 
-static int
-remote_remove_fork_catchpoint (struct target_ops *ops, int pid)
+int
+remote_target::remove_fork_catchpoint (int pid)
 {
   return 0;
 }
@@ -1676,8 +1960,8 @@ remote_remove_fork_catchpoint (struct target_ops *ops, int pid)
 /* Insert vfork catchpoint target routine.  If vfork events are enabled
    then return success, nothing more to do.  */
 
-static int
-remote_insert_vfork_catchpoint (struct target_ops *ops, int pid)
+int
+remote_target::insert_vfork_catchpoint (int pid)
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -1687,8 +1971,8 @@ remote_insert_vfork_catchpoint (struct target_ops *ops, int pid)
 /* Remove vfork catchpoint target routine.  Nothing to do, just
    return success.  */
 
-static int
-remote_remove_vfork_catchpoint (struct target_ops *ops, int pid)
+int
+remote_target::remove_vfork_catchpoint (int pid)
 {
   return 0;
 }
@@ -1696,8 +1980,8 @@ remote_remove_vfork_catchpoint (struct target_ops *ops, int pid)
 /* Insert exec catchpoint target routine.  If exec events are
    enabled, just return success.  */
 
-static int
-remote_insert_exec_catchpoint (struct target_ops *ops, int pid)
+int
+remote_target::insert_exec_catchpoint (int pid)
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -1707,8 +1991,8 @@ remote_insert_exec_catchpoint (struct target_ops *ops, int pid)
 /* Remove exec catchpoint target routine.  Nothing to do, just
    return success.  */
 
-static int
-remote_remove_exec_catchpoint (struct target_ops *ops, int pid)
+int
+remote_target::remove_exec_catchpoint (int pid)
 {
   return 0;
 }
@@ -1971,9 +2255,8 @@ record_currthread (struct remote_state *rs, ptid_t currthread)
 /* If 'QPassSignals' is supported, tell the remote stub what signals
    it can simply pass through to the inferior without reporting.  */
 
-static void
-remote_pass_signals (struct target_ops *self,
-     int numsigs, unsigned char *pass_signals)
+void
+remote_target::pass_signals (int numsigs, unsigned char *pass_signals)
 {
   if (packet_support (PACKET_QPassSignals) != PACKET_DISABLE)
     {
@@ -2022,10 +2305,9 @@ remote_pass_signals (struct target_ops *self,
 /* If 'QCatchSyscalls' is supported, tell the remote stub
    to report syscalls to GDB.  */
 
-static int
-remote_set_syscall_catchpoint (struct target_ops *self,
-       int pid, bool needed, int any_count,
-       gdb::array_view<const int> syscall_counts)
+int
+remote_target::set_syscall_catchpoint (int pid, bool needed, int any_count,
+       gdb::array_view<const int> syscall_counts)
 {
   const char *catch_packet;
   enum packet_result result;
@@ -2099,9 +2381,8 @@ remote_set_syscall_catchpoint (struct target_ops *self,
 /* If 'QProgramSignals' is supported, tell the remote stub what
    signals it should pass through to the inferior when detaching.  */
 
-static void
-remote_program_signals (struct target_ops *self,
- int numsigs, unsigned char *signals)
+void
+remote_target::program_signals (int numsigs, unsigned char *signals)
 {
   if (packet_support (PACKET_QProgramSignals) != PACKET_DISABLE)
     {
@@ -2221,7 +2502,7 @@ set_general_process (void)
    to model non-threaded targets as single-threaded.  */
 
 static int
-remote_thread_always_alive (struct target_ops *ops, ptid_t ptid)
+remote_thread_always_alive (ptid_t ptid)
 {
   if (ptid_equal (ptid, magic_null_ptid))
     /* The main thread is always alive.  */
@@ -2239,15 +2520,15 @@ remote_thread_always_alive (struct target_ops *ops, ptid_t ptid)
 /* Return nonzero if the thread PTID is still alive on the remote
    system.  */
 
-static int
-remote_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+remote_target::thread_alive (ptid_t ptid)
 {
   struct remote_state *rs = get_remote_state ();
   char *p, *endp;
 
   /* Check if this is a thread that we made up ourselves to model
      non-threaded targets as single-threaded.  */
-  if (remote_thread_always_alive (ops, ptid))
+  if (remote_thread_always_alive (ptid))
     return 1;
 
   p = rs->buf;
@@ -2264,8 +2545,8 @@ remote_thread_alive (struct target_ops *ops, ptid_t ptid)
 /* Return a pointer to a thread name if we know it and NULL otherwise.
    The thread_info object owns the memory for the name.  */
 
-static const char *
-remote_thread_name (struct target_ops *ops, struct thread_info *info)
+const char *
+remote_target::thread_name (struct thread_info *info)
 {
   if (info->priv != NULL)
     {
@@ -3211,8 +3492,8 @@ remote_get_threads_with_qthreadinfo (struct target_ops *ops,
 /* Implement the to_update_thread_list function for the remote
    targets.  */
 
-static void
-remote_update_thread_list (struct target_ops *ops)
+void
+remote_target::update_thread_list ()
 {
   struct threads_listing_context context;
   int got_list = 0;
@@ -3220,16 +3501,16 @@ remote_update_thread_list (struct target_ops *ops)
   /* We have a few different mechanisms to fetch the thread list.  Try
      them all, starting with the most preferred one first, falling
      back to older methods.  */
-  if (remote_get_threads_with_qxfer (ops, &context)
-      || remote_get_threads_with_qthreadinfo (ops, &context)
-      || remote_get_threads_with_ql (ops, &context))
+  if (remote_get_threads_with_qxfer (this, &context)
+      || remote_get_threads_with_qthreadinfo (this, &context)
+      || remote_get_threads_with_ql (this, &context))
     {
       struct thread_info *tp, *tmp;
 
       got_list = 1;
 
       if (context.items.empty ()
-  && remote_thread_always_alive (ops, inferior_ptid))
+  && remote_thread_always_alive (inferior_ptid))
  {
   /* Some targets don't really support threads, but still
      reply an (empty) thread list in response to the thread
@@ -3297,8 +3578,8 @@ remote_update_thread_list (struct target_ops *ops)
  * Optional: targets are not required to implement this function.
  */
 
-static const char *
-remote_threads_extra_info (struct target_ops *self, struct thread_info *tp)
+const char *
+remote_target::extra_thread_info (thread_info *tp)
 {
   struct remote_state *rs = get_remote_state ();
   int result;
@@ -3381,9 +3662,9 @@ remote_threads_extra_info (struct target_ops *self, struct thread_info *tp)
 }
 
 
-static bool
-remote_static_tracepoint_marker_at (struct target_ops *self, CORE_ADDR addr,
-    struct static_tracepoint_marker *marker)
+bool
+remote_target::static_tracepoint_marker_at (CORE_ADDR addr,
+    struct static_tracepoint_marker *marker)
 {
   struct remote_state *rs = get_remote_state ();
   char *p = rs->buf;
@@ -3407,9 +3688,8 @@ remote_static_tracepoint_marker_at (struct target_ops *self, CORE_ADDR addr,
   return false;
 }
 
-static std::vector<static_tracepoint_marker>
-remote_static_tracepoint_markers_by_strid (struct target_ops *self,
-   const char *strid)
+std::vector<static_tracepoint_marker>
+remote_target::static_tracepoint_markers_by_strid (const char *strid)
 {
   struct remote_state *rs = get_remote_state ();
   std::vector<static_tracepoint_marker> markers;
@@ -3446,8 +3726,8 @@ remote_static_tracepoint_markers_by_strid (struct target_ops *self,
 
 /* Implement the to_get_ada_task_ptid function for the remote targets.  */
 
-static ptid_t
-remote_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
+ptid_t
+remote_target::get_ada_task_ptid (long lwp, long thread)
 {
   return ptid_build (ptid_get_pid (inferior_ptid), lwp, 0);
 }
@@ -3470,8 +3750,8 @@ extended_remote_restart (void)
 
 /* Clean up connection to a remote debugger.  */
 
-static void
-remote_close (struct target_ops *self)
+void
+remote_target::close ()
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -3479,7 +3759,7 @@ remote_close (struct target_ops *self)
     return; /* already closed */
 
   /* Make sure we leave stdin registered in the event loop.  */
-  remote_terminal_ours (self);
+  terminal_ours ();
 
   serial_close (rs->remote_desc);
   rs->remote_desc = NULL;
@@ -3977,8 +4257,8 @@ process_initial_stop_replies (int from_tty)
 
 /* Start the remote connection and sync state.  */
 
-static void
-remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
+void
+remote_target::start_remote (int from_tty, int extended_p)
 {
   struct remote_state *rs = get_remote_state ();
   struct packet_config *noack_config;
@@ -4007,7 +4287,7 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
 
   /* If the stub wants to get a QAllow, compose one and send it.  */
   if (packet_support (PACKET_QAllow) != PACKET_DISABLE)
-    remote_set_permissions (target);
+    set_permissions ();
 
   /* gdbserver < 7.7 (before its fix from 2013-12-11) did reply to any
      unknown 'v' packet with string "OK".  "OK" gets interpreted by GDB
@@ -4090,7 +4370,7 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
  controlling.  We default to adding them in the running state.
  The '?' query below will then tell us about which threads are
  stopped.  */
-      remote_update_thread_list (target);
+      this->update_thread_list ();
     }
   else if (packet_support (PACKET_QNonStop) == PACKET_ENABLE)
     {
@@ -4106,11 +4386,11 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
   /* Upload TSVs regardless of whether the target is running or not.  The
      remote stub, such as GDBserver, may have some predefined or builtin
      TSVs, even if the target is not running.  */
-  if (remote_get_trace_status (target, current_trace_status ()) != -1)
+  if (get_trace_status (current_trace_status ()) != -1)
     {
       struct uploaded_tsv *uploaded_tsvs = NULL;
 
-      remote_upload_trace_state_variables (target, &uploaded_tsvs);
+      upload_trace_state_variables (&uploaded_tsvs);
       merge_uploaded_trace_state_variables (&uploaded_tsvs);
     }
 
@@ -4190,7 +4470,7 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
  how to do it some other way, try again.  This is not
  supported for non-stop; it could be, but it is tricky if
  there are no stopped threads when we connect.  */
-      if (remote_read_description_p (target)
+      if (remote_read_description_p (this)
   && gdbarch_target_desc (target_gdbarch ()) == NULL)
  {
   target_clear_description ();
@@ -4202,7 +4482,7 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
       strcpy (rs->buf, wait_status);
       rs->cached_wait_status = 1;
 
-      start_remote (from_tty); /* Initialize gdb process mechanisms.  */
+      ::start_remote (from_tty); /* Initialize gdb process mechanisms.  */
     }
   else
     {
@@ -4245,7 +4525,7 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
       gdb_assert (wait_status == NULL);
 
       /* Report all signals during attach/startup.  */
-      remote_pass_signals (target, 0, NULL);
+      pass_signals (0, NULL);
 
       /* If there are already stopped threads, mark them stopped and
  report their stops before giving the prompt to the user.  */
@@ -4264,14 +4544,14 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
 
   /* Possibly the target has been engaged in a trace run started
      previously; find out where things are at.  */
-  if (remote_get_trace_status (target, current_trace_status ()) != -1)
+  if (get_trace_status (current_trace_status ()) != -1)
     {
       struct uploaded_tp *uploaded_tps = NULL;
 
       if (current_trace_status ()->running)
  printf_filtered (_("Trace is already running on the target.\n"));
 
-      remote_upload_tracepoints (target, &uploaded_tps);
+      upload_tracepoints (&uploaded_tps);
 
       merge_uploaded_tracepoints (&uploaded_tps);
     }
@@ -4294,19 +4574,19 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
 /* Open a connection to a remote debugger.
    NAME is the filename used for communication.  */
 
-static void
-remote_open (const char *name, int from_tty)
+void
+remote_target::open (const char *name, int from_tty)
 {
-  remote_open_1 (name, from_tty, &remote_ops, 0);
+  open_1 (name, from_tty, 0);
 }
 
 /* Open a connection to a remote debugger using the extended
    remote gdb protocol.  NAME is the filename used for communication.  */
 
-static void
-extended_remote_open (const char *name, int from_tty)
+void
+extended_remote_target::open (const char *name, int from_tty)
 {
-  remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */);
+  open_1 (name, from_tty, 1 /*extended_p */);
 }
 
 /* Reset all packets back to "unknown support".  Called when opening a
@@ -4436,7 +4716,7 @@ remote_serial_open (const char *name)
    permissions.  */
 
 void
-remote_set_permissions (struct target_ops *self)
+remote_target::set_permissions ()
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -4919,9 +5199,8 @@ remote_unpush_and_throw (void)
   throw_error (TARGET_CLOSE_ERROR, _("Disconnected from target."));
 }
 
-static void
-remote_open_1 (const char *name, int from_tty,
-       struct target_ops *target, int extended_p)
+void
+remote_target::open_1 (const char *name, int from_tty, int extended_p)
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -4991,7 +5270,7 @@ remote_open_1 (const char *name, int from_tty,
       puts_filtered (name);
       puts_filtered ("\n");
     }
-  push_target (target); /* Switch to using remote target now.  */
+  push_target (this); /* Switch to using remote target now.  */
 
   /* Register extra event sources in the event loop.  */
   remote_async_inferior_event_token
@@ -5059,7 +5338,7 @@ remote_open_1 (const char *name, int from_tty,
 
     TRY
       {
- remote_start_remote (from_tty, target, extended_p);
+ start_remote (from_tty, extended_p);
       }
     CATCH (ex, RETURN_MASK_ALL)
       {
@@ -5145,14 +5424,14 @@ remote_detach_1 (int from_tty, inferior *inf)
     }
 }
 
-static void
-remote_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+remote_target::detach (inferior *inf, int from_tty)
 {
   remote_detach_1 (from_tty, inf);
 }
 
-static void
-extended_remote_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+extended_remote_target::detach (inferior *inf, int from_tty)
 {
   remote_detach_1 (from_tty, inf);
 }
@@ -5164,9 +5443,8 @@ extended_remote_detach (struct target_ops *ops, inferior *inf, int from_tty)
    it is named remote_follow_fork in anticipation of using it for the
    remote target as well.  */
 
-static int
-remote_follow_fork (struct target_ops *ops, int follow_child,
-    int detach_fork)
+int
+remote_target::follow_fork (int follow_child, int detach_fork)
 {
   struct remote_state *rs = get_remote_state ();
   enum target_waitkind kind = inferior_thread ()->pending_follow.kind;
@@ -5201,9 +5479,8 @@ remote_follow_fork (struct target_ops *ops, int follow_child,
    inferior, which may be the same as the exec'ing inferior unless
    follow-exec-mode is "new".  */
 
-static void
-remote_follow_exec (struct target_ops *ops,
-    struct inferior *inf, char *execd_pathname)
+void
+remote_target::follow_exec (struct inferior *inf, char *execd_pathname)
 {
   /* We know that this is a target file name, so if it has the "target:"
      prefix we strip it off before saving it in the program space.  */
@@ -5215,8 +5492,8 @@ remote_follow_exec (struct target_ops *ops,
 
 /* Same as remote_detach, but don't send the "D" packet; just disconnect.  */
 
-static void
-remote_disconnect (struct target_ops *target, const char *args, int from_tty)
+void
+remote_target::disconnect (const char *args, int from_tty)
 {
   if (args)
     error (_("Argument given to \"disconnect\" when remotely debugging."));
@@ -5224,7 +5501,7 @@ remote_disconnect (struct target_ops *target, const char *args, int from_tty)
   /* Make sure we unpush even the extended remote targets.  Calling
      target_mourn_inferior won't unpush, and remote_mourn won't
      unpush if there is more than one inferior left.  */
-  unpush_target (target);
+  unpush_target (this);
   generic_mourn_inferior ();
 
   if (from_tty)
@@ -5234,9 +5511,8 @@ remote_disconnect (struct target_ops *target, const char *args, int from_tty)
 /* Attach to the process specified by ARGS.  If FROM_TTY is non-zero,
    be chatty about it.  */
 
-static void
-extended_remote_attach (struct target_ops *target, const char *args,
- int from_tty)
+void
+extended_remote_target::attach (const char *args, int from_tty)
 {
   struct remote_state *rs = get_remote_state ();
   int pid;
@@ -5299,7 +5575,7 @@ extended_remote_attach (struct target_ops *target, const char *args,
       struct thread_info *thread;
 
       /* Get list of threads.  */
-      remote_update_thread_list (target);
+      update_thread_list ();
 
       thread = first_thread_of_process (pid);
       if (thread)
@@ -5350,8 +5626,8 @@ extended_remote_attach (struct target_ops *target, const char *args,
 
 /* Implementation of the to_post_attach method.  */
 
-static void
-extended_remote_post_attach (struct target_ops *ops, int pid)
+void
+extended_remote_target::post_attach (int pid)
 {
   /* Get text, data & bss offsets.  */
   get_offsets ();
@@ -5674,9 +5950,8 @@ remote_resume_with_vcont (ptid_t ptid, int step, enum gdb_signal siggnal)
 
 /* Tell the remote machine to resume.  */
 
-static void
-remote_resume (struct target_ops *ops,
-       ptid_t ptid, int step, enum gdb_signal siggnal)
+void
+remote_target::resume (ptid_t ptid, int step, enum gdb_signal siggnal)
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -5687,7 +5962,7 @@ remote_resume (struct target_ops *ops,
      request; the actual remote resumption will be done in
      target_commit_resume / remote_commit_resume, where we'll be able
      to do vCont action coalescing.  */
-  if (target_is_non_stop_p () && execution_direction != EXEC_REVERSE)
+  if (target_is_non_stop_p () && ::execution_direction != EXEC_REVERSE)
     {
       remote_thread_info *remote_thr;
 
@@ -5710,11 +5985,11 @@ remote_resume (struct target_ops *ops,
   if (!target_is_non_stop_p ())
     remote_notif_process (rs->notif_state, &notif_client_stop);
 
-  rs->last_resume_exec_dir = execution_direction;
+  rs->last_resume_exec_dir = ::execution_direction;
 
   /* Prefer vCont, and fallback to s/c/S/C, which use Hc.  */
   if (!remote_resume_with_vcont (ptid, step, siggnal))
-    remote_resume_with_hc (ops, ptid, step, siggnal);
+    remote_resume_with_hc (this, ptid, step, siggnal);
 
   /* We are about to start executing the inferior, let's register it
      with the event loop.  NOTE: this is the one place where all the
@@ -5850,8 +6125,8 @@ vcont_builder_push_action (struct vcont_builder *builder,
 
 /* to_commit_resume implementation.  */
 
-static void
-remote_commit_resume (struct target_ops *ops)
+void
+remote_target::commit_resume ()
 {
   struct inferior *inf;
   struct thread_info *tp;
@@ -5863,7 +6138,7 @@ remote_commit_resume (struct target_ops *ops)
      request directly from remote_resume.  Likewise if
      reverse-debugging, as there are no defined vCont actions for
      reverse execution.  */
-  if (!target_is_non_stop_p () || execution_direction == EXEC_REVERSE)
+  if (!target_is_non_stop_p () || ::execution_direction == EXEC_REVERSE)
     return;
 
   /* Try to send wildcard actions ("vCont;c" or "vCont;c:pPID.-1")
@@ -6129,8 +6404,8 @@ remote_interrupt_ns (void)
 
 /* Implement the to_stop function for the remote targets.  */
 
-static void
-remote_stop (struct target_ops *self, ptid_t ptid)
+void
+remote_target::stop (ptid_t ptid)
 {
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
@@ -6147,8 +6422,8 @@ remote_stop (struct target_ops *self, ptid_t ptid)
 
 /* Implement the to_interrupt function for the remote targets.  */
 
-static void
-remote_interrupt (struct target_ops *self)
+void
+remote_target::interrupt ()
 {
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
@@ -6161,8 +6436,8 @@ remote_interrupt (struct target_ops *self)
 
 /* Implement the to_pass_ctrlc function for the remote targets.  */
 
-static void
-remote_pass_ctrlc (struct target_ops *self)
+void
+remote_target::pass_ctrlc ()
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -6209,16 +6484,16 @@ interrupt_query (void)
    different in that explicit transfer of ownership to/from GDB/target
    is required.  */
 
-static void
-remote_terminal_inferior (struct target_ops *self)
+void
+remote_target::terminal_inferior ()
 {
   /* NOTE: At this point we could also register our selves as the
      recipient of all input.  Any characters typed could then be
      passed on down to the target.  */
 }
 
-static void
-remote_terminal_ours (struct target_ops *self)
+void
+remote_target::terminal_ours ()
 {
 }
 
@@ -7420,9 +7695,8 @@ remote_wait_as (ptid_t ptid, struct target_waitstatus *status, int options)
 /* Wait until the remote machine stops, then return, storing status in
    STATUS just as `wait' would.  */
 
-static ptid_t
-remote_wait (struct target_ops *ops,
-     ptid_t ptid, struct target_waitstatus *status, int options)
+ptid_t
+remote_target::wait (ptid_t ptid, struct target_waitstatus *status, int options)
 {
   ptid_t event_ptid;
 
@@ -7672,9 +7946,8 @@ set_remote_traceframe (void)
     warning (_("could not set remote traceframe"));
 }
 
-static void
-remote_fetch_registers (struct target_ops *ops,
- struct regcache *regcache, int regnum)
+void
+remote_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   remote_arch_state *rsa = get_remote_arch_state (gdbarch);
@@ -7724,8 +7997,8 @@ remote_fetch_registers (struct target_ops *ops,
    'G' request), we have to read out the ones we don't want to change
    first.  */
 
-static void
-remote_prepare_to_store (struct target_ops *self, struct regcache *regcache)
+void
+remote_target::prepare_to_store (struct regcache *regcache)
 {
   remote_arch_state *rsa = get_remote_arch_state (regcache->arch ());
   int i;
@@ -7828,9 +8101,8 @@ store_registers_using_G (const struct regcache *regcache)
 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
    of the register cache buffer.  FIXME: ignores errors.  */
 
-static void
-remote_store_registers (struct target_ops *ops,
- struct regcache *regcache, int regnum)
+void
+remote_target::store_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   remote_arch_state *rsa = get_remote_arch_state (gdbarch);
@@ -8440,9 +8712,8 @@ remote_send_printf (const char *format, ...)
    In future, we'll need to decide on a better approach.  */
 static const int remote_flash_timeout = 1000;
 
-static void
-remote_flash_erase (struct target_ops *ops,
-                    ULONGEST address, LONGEST length)
+void
+remote_target::flash_erase (ULONGEST address, LONGEST length)
 {
   int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
   enum packet_result ret;
@@ -8474,8 +8745,8 @@ remote_flash_write (struct target_ops *ops, ULONGEST address,
  xfered_len,'X', 0);
 }
 
-static void
-remote_flash_done (struct target_ops *ops)
+void
+remote_target::flash_done ()
 {
   int ret;
 
@@ -8495,8 +8766,8 @@ remote_flash_done (struct target_ops *ops)
     }
 }
 
-static void
-remote_files_info (struct target_ops *ignore)
+void
+remote_target::files_info ()
 {
   puts_filtered ("Debugging a target over a serial line.\n");
 }
@@ -9261,8 +9532,8 @@ kill_new_fork_children (int pid, struct remote_state *rs)
 
 /* Target hook to kill the current inferior.  */
 
-static void
-remote_kill (struct target_ops *ops)
+void
+remote_target::kill ()
 {
   int res = -1;
   int pid = ptid_get_pid (inferior_ptid);
@@ -9363,15 +9634,15 @@ remote_kill_k (void)
   END_CATCH
 }
 
-static void
-remote_mourn (struct target_ops *target)
+void
+remote_target::mourn_inferior ()
 {
   struct remote_state *rs = get_remote_state ();
 
   /* In 'target remote' mode with one inferior, we close the connection.  */
   if (!rs->extended && number_of_live_inferiors () <= 1)
     {
-      unpush_target (target);
+      unpush_target (this);
 
       /* remote_close takes care of doing most of the clean up.  */
       generic_mourn_inferior ();
@@ -9431,8 +9702,8 @@ remote_mourn (struct target_ops *target)
     }
 }
 
-static int
-extended_remote_supports_disable_randomization (struct target_ops *self)
+int
+extended_remote_target::supports_disable_randomization ()
 {
   return packet_support (PACKET_QDisableRandomization) == PACKET_ENABLE;
 }
@@ -9608,11 +9879,10 @@ directory: %s"),
    executable file and the command line arguments, but not the
    environment.  */
 
-static void
-extended_remote_create_inferior (struct target_ops *ops,
- const char *exec_file,
- const std::string &args,
- char **env, int from_tty)
+void
+extended_remote_target::create_inferior (const char *exec_file,
+ const std::string &args,
+ char **env, int from_tty)
 {
   int run_worked;
   char *stop_reply;
@@ -9625,7 +9895,7 @@ extended_remote_create_inferior (struct target_ops *ops,
     target_async (1);
 
   /* Disable address space randomization if requested (and supported).  */
-  if (extended_remote_supports_disable_randomization (ops))
+  if (supports_disable_randomization ())
     extended_remote_disable_randomization (disable_randomization);
 
   /* If startup-with-shell is on, we inform gdbserver to start the
@@ -9736,10 +10006,9 @@ remote_add_target_side_commands (struct gdbarch *gdbarch,
    support, we ask the remote target to do the work; on targets
    which don't, we insert a traditional memory breakpoint.  */
 
-static int
-remote_insert_breakpoint (struct target_ops *ops,
-  struct gdbarch *gdbarch,
-  struct bp_target_info *bp_tgt)
+int
+remote_target::insert_breakpoint (struct gdbarch *gdbarch,
+  struct bp_target_info *bp_tgt)
 {
   /* Try the "Z" s/w breakpoint packet if it is not already disabled.
      If it succeeds, then set the support to PACKET_ENABLE.  If it
@@ -9768,10 +10037,10 @@ remote_insert_breakpoint (struct target_ops *ops,
       p += hexnumstr (p, addr);
       xsnprintf (p, endbuf - p, ",%d", bp_tgt->kind);
 
-      if (remote_supports_cond_breakpoints (ops))
+      if (supports_evaluation_of_breakpoint_conditions ())
  remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
 
-      if (remote_can_run_breakpoint_commands (ops))
+      if (can_run_breakpoint_commands ())
  remote_add_target_side_commands (gdbarch, bp_tgt, p);
 
       putpkt (rs->buf);
@@ -9794,14 +10063,13 @@ remote_insert_breakpoint (struct target_ops *ops,
     throw_error (NOT_SUPPORTED_ERROR, _("\
 Target doesn't support breakpoints that have target side commands."));
 
-  return memory_insert_breakpoint (ops, gdbarch, bp_tgt);
+  return memory_insert_breakpoint (this, gdbarch, bp_tgt);
 }
 
-static int
-remote_remove_breakpoint (struct target_ops *ops,
-  struct gdbarch *gdbarch,
-  struct bp_target_info *bp_tgt,
-  enum remove_bp_reason reason)
+int
+remote_target::remove_breakpoint (struct gdbarch *gdbarch,
+  struct bp_target_info *bp_tgt,
+  enum remove_bp_reason reason)
 {
   CORE_ADDR addr = bp_tgt->placed_address;
   struct remote_state *rs = get_remote_state ();
@@ -9830,7 +10098,7 @@ remote_remove_breakpoint (struct target_ops *ops,
       return (rs->buf[0] == 'E');
     }
 
-  return memory_remove_breakpoint (ops, gdbarch, bp_tgt, reason);
+  return memory_remove_breakpoint (this, gdbarch, bp_tgt, reason);
 }
 
 static enum Z_packet_type
@@ -9853,9 +10121,9 @@ watchpoint_to_Z_packet (int type)
     }
 }
 
-static int
-remote_insert_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
-  enum target_hw_bp_type type, struct expression *cond)
+int
+remote_target::insert_watchpoint (CORE_ADDR addr, int len,
+  enum target_hw_bp_type type, struct expression *cond)
 {
   struct remote_state *rs = get_remote_state ();
   char *endbuf = rs->buf + get_remote_packet_size ();
@@ -9892,9 +10160,9 @@ remote_insert_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
   _("remote_insert_watchpoint: reached end of function"));
 }
 
-static int
-remote_watchpoint_addr_within_range (struct target_ops *target, CORE_ADDR addr,
-     CORE_ADDR start, int length)
+int
+remote_target::watchpoint_addr_within_range (CORE_ADDR addr,
+     CORE_ADDR start, int length)
 {
   CORE_ADDR diff = remote_address_masked (addr - start);
 
@@ -9902,9 +10170,9 @@ remote_watchpoint_addr_within_range (struct target_ops *target, CORE_ADDR addr,
 }
 
 
-static int
-remote_remove_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
-  enum target_hw_bp_type type, struct expression *cond)
+int
+remote_target::remove_watchpoint (CORE_ADDR addr, int len,
+  enum target_hw_bp_type type, struct expression *cond)
 {
   struct remote_state *rs = get_remote_state ();
   char *endbuf = rs->buf + get_remote_packet_size ();
@@ -9944,9 +10212,8 @@ int remote_hw_watchpoint_limit = -1;
 int remote_hw_watchpoint_length_limit = -1;
 int remote_hw_breakpoint_limit = -1;
 
-static int
-remote_region_ok_for_hw_watchpoint (struct target_ops *self,
-    CORE_ADDR addr, int len)
+int
+remote_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
 {
   if (remote_hw_watchpoint_length_limit == 0)
     return 0;
@@ -9958,9 +10225,8 @@ remote_region_ok_for_hw_watchpoint (struct target_ops *self,
     return 0;
 }
 
-static int
-remote_check_watch_resources (struct target_ops *self,
-      enum bptype type, int cnt, int ot)
+int
+remote_target::can_use_hw_breakpoint (enum bptype type, int cnt, int ot)
 {
   if (type == bp_hardware_breakpoint)
     {
@@ -9987,8 +10253,8 @@ remote_check_watch_resources (struct target_ops *self,
 
 /* The to_stopped_by_sw_breakpoint method of target remote.  */
 
-static int
-remote_stopped_by_sw_breakpoint (struct target_ops *ops)
+int
+remote_target::stopped_by_sw_breakpoint ()
 {
   struct thread_info *thread = inferior_thread ();
 
@@ -10000,16 +10266,16 @@ remote_stopped_by_sw_breakpoint (struct target_ops *ops)
 /* The to_supports_stopped_by_sw_breakpoint method of target
    remote.  */
 
-static int
-remote_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
+int
+remote_target::supports_stopped_by_sw_breakpoint ()
 {
   return (packet_support (PACKET_swbreak_feature) == PACKET_ENABLE);
 }
 
 /* The to_stopped_by_hw_breakpoint method of target remote.  */
 
-static int
-remote_stopped_by_hw_breakpoint (struct target_ops *ops)
+int
+remote_target::stopped_by_hw_breakpoint ()
 {
   struct thread_info *thread = inferior_thread ();
 
@@ -10021,14 +10287,14 @@ remote_stopped_by_hw_breakpoint (struct target_ops *ops)
 /* The to_supports_stopped_by_hw_breakpoint method of target
    remote.  */
 
-static int
-remote_supports_stopped_by_hw_breakpoint (struct target_ops *ops)
+int
+remote_target::supports_stopped_by_hw_breakpoint ()
 {
   return (packet_support (PACKET_hwbreak_feature) == PACKET_ENABLE);
 }
 
-static int
-remote_stopped_by_watchpoint (struct target_ops *ops)
+int
+remote_target::stopped_by_watchpoint ()
 {
   struct thread_info *thread = inferior_thread ();
 
@@ -10037,8 +10303,8 @@ remote_stopped_by_watchpoint (struct target_ops *ops)
       == TARGET_STOPPED_BY_WATCHPOINT));
 }
 
-static int
-remote_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
+int
+remote_target::stopped_data_address (CORE_ADDR *addr_p)
 {
   struct thread_info *thread = inferior_thread ();
 
@@ -10054,9 +10320,9 @@ remote_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
 }
 
 
-static int
-remote_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
-     struct bp_target_info *bp_tgt)
+int
+remote_target::insert_hw_breakpoint (struct gdbarch *gdbarch,
+     struct bp_target_info *bp_tgt)
 {
   CORE_ADDR addr = bp_tgt->reqstd_address;
   struct remote_state *rs;
@@ -10083,10 +10349,10 @@ remote_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
   p += hexnumstr (p, (ULONGEST) addr);
   xsnprintf (p, endbuf - p, ",%x", bp_tgt->kind);
 
-  if (remote_supports_cond_breakpoints (self))
+  if (supports_evaluation_of_breakpoint_conditions ())
     remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
 
-  if (remote_can_run_breakpoint_commands (self))
+  if (can_run_breakpoint_commands ())
     remote_add_target_side_commands (gdbarch, bp_tgt, p);
 
   putpkt (rs->buf);
@@ -10112,9 +10378,9 @@ remote_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
 }
 
 
-static int
-remote_remove_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
-     struct bp_target_info *bp_tgt)
+int
+remote_target::remove_hw_breakpoint (struct gdbarch *gdbarch,
+     struct bp_target_info *bp_tgt)
 {
   CORE_ADDR addr;
   struct remote_state *rs = get_remote_state ();
@@ -10154,9 +10420,8 @@ remote_remove_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
 
 /* Verify memory using the "qCRC:" request.  */
 
-static int
-remote_verify_memory (struct target_ops *ops,
-      const gdb_byte *data, CORE_ADDR lma, ULONGEST size)
+int
+remote_target::verify_memory (const gdb_byte *data, CORE_ADDR lma, ULONGEST size)
 {
   struct remote_state *rs = get_remote_state ();
   unsigned long host_crc, target_crc;
@@ -10195,7 +10460,7 @@ remote_verify_memory (struct target_ops *ops,
  }
     }
 
-  return simple_verify_memory (ops, data, lma, size);
+  return simple_verify_memory (this, data, lma, size);
 }
 
 /* compare-sections command
@@ -10280,7 +10545,7 @@ the loaded file\n"));
    target is returned, or -1 for error.  */
 
 static enum target_xfer_status
-remote_write_qxfer (struct target_ops *ops, const char *object_name,
+remote_write_qxfer (const char *object_name,
                     const char *annex, const gdb_byte *writebuf,
                     ULONGEST offset, LONGEST len, ULONGEST *xfered_len,
                     struct packet_config *packet)
@@ -10323,7 +10588,7 @@ remote_write_qxfer (struct target_ops *ops, const char *object_name,
    target supports this object.  */
 
 static enum target_xfer_status
-remote_read_qxfer (struct target_ops *ops, const char *object_name,
+remote_read_qxfer (const char *object_name,
    const char *annex,
    gdb_byte *readbuf, ULONGEST offset, LONGEST len,
    ULONGEST *xfered_len,
@@ -10403,11 +10668,11 @@ remote_read_qxfer (struct target_ops *ops, const char *object_name,
     }
 }
 
-static enum target_xfer_status
-remote_xfer_partial (struct target_ops *ops, enum target_object object,
-     const char *annex, gdb_byte *readbuf,
-     const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
-     ULONGEST *xfered_len)
+enum target_xfer_status
+remote_target::xfer_partial (enum target_object object,
+     const char *annex, gdb_byte *readbuf,
+     const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+     ULONGEST *xfered_len)
 {
   struct remote_state *rs;
   int i;
@@ -10433,7 +10698,7 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
  return remote_write_bytes (offset, writebuf, len, unit_size,
    xfered_len);
       else
- return remote_read_bytes (ops, offset, readbuf, len, unit_size,
+ return remote_read_bytes (this, offset, readbuf, len, unit_size,
   xfered_len);
     }
 
@@ -10441,11 +10706,11 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
   if (object == TARGET_OBJECT_SPU)
     {
       if (readbuf)
- return remote_read_qxfer (ops, "spu", annex, readbuf, offset, len,
+ return remote_read_qxfer ("spu", annex, readbuf, offset, len,
   xfered_len, &remote_protocol_packets
   [PACKET_qXfer_spu_read]);
       else
- return remote_write_qxfer (ops, "spu", annex, writebuf, offset, len,
+ return remote_write_qxfer ("spu", annex, writebuf, offset, len,
    xfered_len, &remote_protocol_packets
    [PACKET_qXfer_spu_write]);
     }
@@ -10454,11 +10719,11 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
   if (object == TARGET_OBJECT_SIGNAL_INFO)
     {
       if (readbuf)
- return remote_read_qxfer (ops, "siginfo", annex, readbuf, offset, len,
+ return remote_read_qxfer ("siginfo", annex, readbuf, offset, len,
   xfered_len, &remote_protocol_packets
   [PACKET_qXfer_siginfo_read]);
       else
- return remote_write_qxfer (ops, "siginfo", annex,
+ return remote_write_qxfer ("siginfo", annex,
    writebuf, offset, len, xfered_len,
    &remote_protocol_packets
    [PACKET_qXfer_siginfo_write]);
@@ -10467,7 +10732,7 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
   if (object == TARGET_OBJECT_STATIC_TRACE_DATA)
     {
       if (readbuf)
- return remote_read_qxfer (ops, "statictrace", annex,
+ return remote_read_qxfer ("statictrace", annex,
   readbuf, offset, len, xfered_len,
   &remote_protocol_packets
   [PACKET_qXfer_statictrace_read]);
@@ -10481,7 +10746,7 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
       switch (object)
  {
  case TARGET_OBJECT_FLASH:
-  return remote_flash_write (ops, offset, len, xfered_len,
+  return remote_flash_write (this, offset, len, xfered_len,
      writebuf);
 
  default:
@@ -10499,28 +10764,28 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
 
     case TARGET_OBJECT_AUXV:
       gdb_assert (annex == NULL);
-      return remote_read_qxfer (ops, "auxv", annex, readbuf, offset, len,
+      return remote_read_qxfer ("auxv", annex, readbuf, offset, len,
  xfered_len,
  &remote_protocol_packets[PACKET_qXfer_auxv]);
 
     case TARGET_OBJECT_AVAILABLE_FEATURES:
       return remote_read_qxfer
- (ops, "features", annex, readbuf, offset, len, xfered_len,
+ ("features", annex, readbuf, offset, len, xfered_len,
  &remote_protocol_packets[PACKET_qXfer_features]);
 
     case TARGET_OBJECT_LIBRARIES:
       return remote_read_qxfer
- (ops, "libraries", annex, readbuf, offset, len, xfered_len,
+ ("libraries", annex, readbuf, offset, len, xfered_len,
  &remote_protocol_packets[PACKET_qXfer_libraries]);
 
     case TARGET_OBJECT_LIBRARIES_SVR4:
       return remote_read_qxfer
- (ops, "libraries-svr4", annex, readbuf, offset, len, xfered_len,
+ ("libraries-svr4", annex, readbuf, offset, len, xfered_len,
  &remote_protocol_packets[PACKET_qXfer_libraries_svr4]);
 
     case TARGET_OBJECT_MEMORY_MAP:
       gdb_assert (annex == NULL);
-      return remote_read_qxfer (ops, "memory-map", annex, readbuf, offset, len,
+      return remote_read_qxfer ("memory-map", annex, readbuf, offset, len,
  xfered_len,
  &remote_protocol_packets[PACKET_qXfer_memory_map]);
 
@@ -10528,43 +10793,43 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
       /* Should only get here if we're connected.  */
       gdb_assert (rs->remote_desc);
       return remote_read_qxfer
- (ops, "osdata", annex, readbuf, offset, len, xfered_len,
+ ("osdata", annex, readbuf, offset, len, xfered_len,
         &remote_protocol_packets[PACKET_qXfer_osdata]);
 
     case TARGET_OBJECT_THREADS:
       gdb_assert (annex == NULL);
-      return remote_read_qxfer (ops, "threads", annex, readbuf, offset, len,
+      return remote_read_qxfer ("threads", annex, readbuf, offset, len,
  xfered_len,
  &remote_protocol_packets[PACKET_qXfer_threads]);
 
     case TARGET_OBJECT_TRACEFRAME_INFO:
       gdb_assert (annex == NULL);
       return remote_read_qxfer
- (ops, "traceframe-info", annex, readbuf, offset, len, xfered_len,
+ ("traceframe-info", annex, readbuf, offset, len, xfered_len,
  &remote_protocol_packets[PACKET_qXfer_traceframe_info]);
 
     case TARGET_OBJECT_FDPIC:
-      return remote_read_qxfer (ops, "fdpic", annex, readbuf, offset, len,
+      return remote_read_qxfer ("fdpic", annex, readbuf, offset, len,
  xfered_len,
  &remote_protocol_packets[PACKET_qXfer_fdpic]);
 
     case TARGET_OBJECT_OPENVMS_UIB:
-      return remote_read_qxfer (ops, "uib", annex, readbuf, offset, len,
+      return remote_read_qxfer ("uib", annex, readbuf, offset, len,
  xfered_len,
  &remote_protocol_packets[PACKET_qXfer_uib]);
 
     case TARGET_OBJECT_BTRACE:
-      return remote_read_qxfer (ops, "btrace", annex, readbuf, offset, len,
+      return remote_read_qxfer ("btrace", annex, readbuf, offset, len,
  xfered_len,
         &remote_protocol_packets[PACKET_qXfer_btrace]);
 
     case TARGET_OBJECT_BTRACE_CONF:
-      return remote_read_qxfer (ops, "btrace-conf", annex, readbuf, offset,
+      return remote_read_qxfer ("btrace-conf", annex, readbuf, offset,
  len, xfered_len,
  &remote_protocol_packets[PACKET_qXfer_btrace_conf]);
 
     case TARGET_OBJECT_EXEC_FILE:
-      return remote_read_qxfer (ops, "exec-file", annex, readbuf, offset,
+      return remote_read_qxfer ("exec-file", annex, readbuf, offset,
  len, xfered_len,
  &remote_protocol_packets[PACKET_qXfer_exec_file]);
 
@@ -10618,17 +10883,16 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
 
 /* Implementation of to_get_memory_xfer_limit.  */
 
-static ULONGEST
-remote_get_memory_xfer_limit (struct target_ops *ops)
+ULONGEST
+remote_target::get_memory_xfer_limit ()
 {
   return get_memory_write_packet_size ();
 }
 
-static int
-remote_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)
+int
+remote_target::search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
+      const gdb_byte *pattern, ULONGEST pattern_len,
+      CORE_ADDR *found_addrp)
 {
   int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
   struct remote_state *rs = get_remote_state ();
@@ -10663,7 +10927,7 @@ remote_search_memory (struct target_ops* ops,
     {
       /* Target doesn't provided special support, fall back and use the
  standard support (copy memory and do the search here).  */
-      return simple_search_memory (ops, start_addr, search_space_len,
+      return simple_search_memory (this, start_addr, search_space_len,
    pattern, pattern_len, found_addrp);
     }
 
@@ -10694,7 +10958,7 @@ remote_search_memory (struct target_ops* ops,
  supported.  If so, fall back to the simple way.  */
       if (packet_config_support (packet) == PACKET_DISABLE)
  {
-  return simple_search_memory (ops, start_addr, search_space_len,
+  return simple_search_memory (this, start_addr, search_space_len,
        pattern, pattern_len, found_addrp);
  }
       return -1;
@@ -10716,9 +10980,8 @@ remote_search_memory (struct target_ops* ops,
   return found;
 }
 
-static void
-remote_rcmd (struct target_ops *self, const char *command,
-     struct ui_file *outbuf)
+void
+remote_target::rcmd (const char *command, struct ui_file *outbuf)
 {
   struct remote_state *rs = get_remote_state ();
   char *p = rs->buf;
@@ -10786,8 +11049,8 @@ remote_rcmd (struct target_ops *self, const char *command,
     }
 }
 
-static std::vector<mem_region>
-remote_memory_map (struct target_ops *ops)
+std::vector<mem_region>
+remote_target::memory_map ()
 {
   std::vector<mem_region> result;
   gdb::optional<gdb::char_vector> text
@@ -10972,8 +11235,8 @@ init_remote_threadtests (void)
 /* Convert a thread ID to a string.  Returns the string in a static
    buffer.  */
 
-static const char *
-remote_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+remote_target::pid_to_str (ptid_t ptid)
 {
   static char buf[64];
   struct remote_state *rs = get_remote_state ();
@@ -11021,9 +11284,9 @@ remote_pid_to_str (struct target_ops *ops, ptid_t ptid)
 /* Get the address of the thread local variable in OBJFILE which is
    stored at OFFSET within the thread local storage for thread PTID.  */
 
-static CORE_ADDR
-remote_get_thread_local_address (struct target_ops *ops,
- ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset)
+CORE_ADDR
+remote_target::get_thread_local_address (ptid_t ptid, CORE_ADDR lm,
+ CORE_ADDR offset)
 {
   if (packet_support (PACKET_qGetTLSAddr) != PACKET_DISABLE)
     {
@@ -11069,8 +11332,8 @@ remote_get_thread_local_address (struct target_ops *ops,
 /* Provide thread local base, i.e. Thread Information Block address.
    Returns 1 if ptid is found and thread_local_base is non zero.  */
 
-static int
-remote_get_tib_address (struct target_ops *self, ptid_t ptid, CORE_ADDR *addr)
+int
+remote_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
 {
   if (packet_support (PACKET_qGetTIBAddr) != PACKET_DISABLE)
     {
@@ -11176,8 +11439,8 @@ remote_read_description_p (struct target_ops *target)
   return 0;
 }
 
-static const struct target_desc *
-remote_read_description (struct target_ops *target)
+const struct target_desc *
+remote_target::read_description ()
 {
   struct remote_g_packet_data *data
     = ((struct remote_g_packet_data *)
@@ -11186,7 +11449,7 @@ remote_read_description (struct target_ops *target)
   /* Do not try this during initial connection, when we do not know
      whether there is a running but stopped thread.  */
   if (!target_has_execution || ptid_equal (inferior_ptid, null_ptid))
-    return target->beneath->to_read_description (target->beneath);
+    return beneath->read_description ();
 
   if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
     {
@@ -11205,7 +11468,7 @@ remote_read_description (struct target_ops *target)
  an architecture, but it's too tricky to do safely.  */
     }
 
-  return target->beneath->to_read_description (target->beneath);
+  return beneath->read_description ();
 }
 
 /* Remote file transfer support.  This is host-initiated I/O, not
@@ -11509,6 +11772,15 @@ remote_hostio_open (struct target_ops *self,
      remote_errno, NULL, NULL);
 }
 
+int
+remote_target::fileio_open (struct inferior *inf, const char *filename,
+    int flags, int mode, int warn_if_slow,
+    int *remote_errno)
+{
+  return remote_hostio_open (this, inf, filename, flags, mode, warn_if_slow,
+     remote_errno);
+}
+
 /* Implementation of to_fileio_pwrite.  */
 
 static int
@@ -11538,6 +11810,13 @@ remote_hostio_pwrite (struct target_ops *self,
      remote_errno, NULL, NULL);
 }
 
+int
+remote_target::fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
+      ULONGEST offset, int *remote_errno)
+{
+  return remote_hostio_pwrite (this, fd, write_buf, len, offset, remote_errno);
+}
+
 /* Helper for the implementation of to_fileio_pread.  Read the file
    from the remote side with vFile:pread.  */
 
@@ -11648,6 +11927,13 @@ remote_hostio_pread (struct target_ops *self,
   return remote_hostio_pread_from_cache (rs, fd, read_buf, len, offset);
 }
 
+int
+remote_target::fileio_pread (int fd, gdb_byte *read_buf, int len,
+     ULONGEST offset, int *remote_errno)
+{
+  return remote_hostio_pread (this, fd, read_buf, len, offset, remote_errno);
+}
+
 /* Implementation of to_fileio_close.  */
 
 static int
@@ -11667,6 +11953,12 @@ remote_hostio_close (struct target_ops *self, int fd, int *remote_errno)
      remote_errno, NULL, NULL);
 }
 
+int
+remote_target::fileio_close (int fd, int *remote_errno)
+{
+  return remote_hostio_close (this, fd, remote_errno);
+}
+
 /* Implementation of to_fileio_unlink.  */
 
 static int
@@ -11690,12 +11982,18 @@ remote_hostio_unlink (struct target_ops *self,
      remote_errno, NULL, NULL);
 }
 
+int
+remote_target::fileio_unlink (struct inferior *inf, const char *filename,
+      int *remote_errno)
+{
+  return remote_hostio_unlink (this, inf, filename, remote_errno);
+}
+
 /* Implementation of to_fileio_readlink.  */
 
-static gdb::optional<std::string>
-remote_hostio_readlink (struct target_ops *self,
- struct inferior *inf, const char *filename,
- int *remote_errno)
+gdb::optional<std::string>
+remote_target::fileio_readlink (struct inferior *inf, const char *filename,
+ int *remote_errno)
 {
   struct remote_state *rs = get_remote_state ();
   char *p = rs->buf;
@@ -11731,10 +12029,8 @@ remote_hostio_readlink (struct target_ops *self,
 
 /* Implementation of to_fileio_fstat.  */
 
-static int
-remote_hostio_fstat (struct target_ops *self,
-     int fd, struct stat *st,
-     int *remote_errno)
+int
+remote_target::fileio_fstat (int fd, struct stat *st, int *remote_errno)
 {
   struct remote_state *rs = get_remote_state ();
   char *p = rs->buf;
@@ -11791,8 +12087,8 @@ remote_hostio_fstat (struct target_ops *self,
 
 /* Implementation of to_filesystem_is_local.  */
 
-static int
-remote_filesystem_is_local (struct target_ops *self)
+int
+remote_target::filesystem_is_local ()
 {
   /* Valgrind GDB presents itself as a remote target but works
      on the local filesystem: it does not implement remote get
@@ -11811,12 +12107,12 @@ remote_filesystem_is_local (struct target_ops *self)
   /* Try opening a file to probe support.  The supplied
      filename is irrelevant, we only care about whether
      the stub recognizes the packet or not.  */
-  fd = remote_hostio_open (self, NULL, "just probing",
+  fd = remote_hostio_open (this, NULL, "just probing",
    FILEIO_O_RDONLY, 0700, 0,
    &remote_errno);
 
   if (fd >= 0)
-    remote_hostio_close (self, fd, &remote_errno);
+    remote_hostio_close (this, fd, &remote_errno);
 
   ps = packet_support (PACKET_vFile_open);
  }
@@ -12122,8 +12418,8 @@ remote_command (const char *args, int from_tty)
   help_list (remote_cmdlist, "remote ", all_commands, gdb_stdout);
 }
 
-static int
-remote_can_execute_reverse (struct target_ops *self)
+int
+remote_target::can_execute_reverse ()
 {
   if (packet_support (PACKET_bs) == PACKET_ENABLE
       || packet_support (PACKET_bc) == PACKET_ENABLE)
@@ -12132,21 +12428,21 @@ remote_can_execute_reverse (struct target_ops *self)
     return 0;
 }
 
-static int
-remote_supports_non_stop (struct target_ops *self)
+int
+remote_target::supports_non_stop ()
 {
   return 1;
 }
 
-static int
-remote_supports_disable_randomization (struct target_ops *self)
+int
+remote_target::supports_disable_randomization ()
 {
   /* Only supported in extended mode.  */
   return 0;
 }
 
-static int
-remote_supports_multi_process (struct target_ops *self)
+int
+remote_target::supports_multi_process ()
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -12154,56 +12450,56 @@ remote_supports_multi_process (struct target_ops *self)
 }
 
 static int
-remote_supports_cond_tracepoints (void)
+remote_supports_cond_tracepoints ()
 {
   return packet_support (PACKET_ConditionalTracepoints) == PACKET_ENABLE;
 }
 
-static int
-remote_supports_cond_breakpoints (struct target_ops *self)
+int
+remote_target::supports_evaluation_of_breakpoint_conditions ()
 {
   return packet_support (PACKET_ConditionalBreakpoints) == PACKET_ENABLE;
 }
 
 static int
-remote_supports_fast_tracepoints (void)
+remote_supports_fast_tracepoints ()
 {
   return packet_support (PACKET_FastTracepoints) == PACKET_ENABLE;
 }
 
 static int
-remote_supports_static_tracepoints (void)
+remote_supports_static_tracepoints ()
 {
   return packet_support (PACKET_StaticTracepoints) == PACKET_ENABLE;
 }
 
 static int
-remote_supports_install_in_trace (void)
+remote_supports_install_in_trace ()
 {
   return packet_support (PACKET_InstallInTrace) == PACKET_ENABLE;
 }
 
-static int
-remote_supports_enable_disable_tracepoint (struct target_ops *self)
+int
+remote_target::supports_enable_disable_tracepoint ()
 {
   return (packet_support (PACKET_EnableDisableTracepoints_feature)
   == PACKET_ENABLE);
 }
 
-static int
-remote_supports_string_tracing (struct target_ops *self)
+int
+remote_target::supports_string_tracing ()
 {
   return packet_support (PACKET_tracenz_feature) == PACKET_ENABLE;
 }
 
-static int
-remote_can_run_breakpoint_commands (struct target_ops *self)
+int
+remote_target::can_run_breakpoint_commands ()
 {
   return packet_support (PACKET_BreakpointCommands) == PACKET_ENABLE;
 }
 
-static void
-remote_trace_init (struct target_ops *self)
+void
+remote_target::trace_init ()
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -12253,8 +12549,8 @@ remote_download_command_source (int num, ULONGEST addr,
     }
 }
 
-static void
-remote_download_tracepoint (struct target_ops *self, struct bp_location *loc)
+void
+remote_target::download_tracepoint (struct bp_location *loc)
 {
 #define BUF_SIZE 2048
 
@@ -12417,8 +12713,8 @@ remote_download_tracepoint (struct target_ops *self, struct bp_location *loc)
     }
 }
 
-static int
-remote_can_download_tracepoint (struct target_ops *self)
+int
+remote_target::can_download_tracepoint ()
 {
   struct remote_state *rs = get_remote_state ();
   struct trace_status *ts;
@@ -12431,7 +12727,7 @@ remote_can_download_tracepoint (struct target_ops *self)
     return 0;
 
   ts = current_trace_status ();
-  status = remote_get_trace_status (self, ts);
+  status = get_trace_status (ts);
 
   if (status == -1 || !ts->running_known || !ts->running)
     return 0;
@@ -12445,9 +12741,8 @@ remote_can_download_tracepoint (struct target_ops *self)
 }
 
 
-static void
-remote_download_trace_state_variable (struct target_ops *self,
-      const trace_state_variable &tsv)
+void
+remote_target::download_trace_state_variable (const trace_state_variable &tsv)
 {
   struct remote_state *rs = get_remote_state ();
   char *p;
@@ -12468,9 +12763,8 @@ remote_download_trace_state_variable (struct target_ops *self,
     error (_("Error on target while downloading trace state variable."));
 }
 
-static void
-remote_enable_tracepoint (struct target_ops *self,
-  struct bp_location *location)
+void
+remote_target::enable_tracepoint (struct bp_location *location)
 {
   struct remote_state *rs = get_remote_state ();
   char addr_buf[40];
@@ -12486,9 +12780,8 @@ remote_enable_tracepoint (struct target_ops *self,
     error (_("Error on target while enabling tracepoint."));
 }
 
-static void
-remote_disable_tracepoint (struct target_ops *self,
-   struct bp_location *location)
+void
+remote_target::disable_tracepoint (struct bp_location *location)
 {
   struct remote_state *rs = get_remote_state ();
   char addr_buf[40];
@@ -12504,8 +12797,8 @@ remote_disable_tracepoint (struct target_ops *self,
     error (_("Error on target while disabling tracepoint."));
 }
 
-static void
-remote_trace_set_readonly_regions (struct target_ops *self)
+void
+remote_target::trace_set_readonly_regions ()
 {
   asection *s;
   bfd *abfd = NULL;
@@ -12555,8 +12848,8 @@ Too many sections for read-only sections definition packet."));
     }
 }
 
-static void
-remote_trace_start (struct target_ops *self)
+void
+remote_target::trace_start ()
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -12568,8 +12861,8 @@ remote_trace_start (struct target_ops *self)
     error (_("Bogus reply from target: %s"), rs->buf);
 }
 
-static int
-remote_get_trace_status (struct target_ops *self, struct trace_status *ts)
+int
+remote_target::get_trace_status (struct trace_status *ts)
 {
   /* Initialize it just to avoid a GCC false warning.  */
   char *p = NULL;
@@ -12620,9 +12913,9 @@ remote_get_trace_status (struct target_ops *self, struct trace_status *ts)
   return ts->running;
 }
 
-static void
-remote_get_tracepoint_status (struct target_ops *self, struct breakpoint *bp,
-      struct uploaded_tp *utp)
+void
+remote_target::get_tracepoint_status (struct breakpoint *bp,
+      struct uploaded_tp *utp)
 {
   struct remote_state *rs = get_remote_state ();
   char *reply;
@@ -12667,8 +12960,8 @@ remote_get_tracepoint_status (struct target_ops *self, struct breakpoint *bp,
     }
 }
 
-static void
-remote_trace_stop (struct target_ops *self)
+void
+remote_target::trace_stop ()
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -12680,11 +12973,10 @@ remote_trace_stop (struct target_ops *self)
     error (_("Bogus reply from target: %s"), rs->buf);
 }
 
-static int
-remote_trace_find (struct target_ops *self,
-   enum trace_find_type type, int num,
-   CORE_ADDR addr1, CORE_ADDR addr2,
-   int *tpp)
+int
+remote_target::trace_find (enum trace_find_type type, int num,
+   CORE_ADDR addr1, CORE_ADDR addr2,
+   int *tpp)
 {
   struct remote_state *rs = get_remote_state ();
   char *endbuf = rs->buf + get_remote_packet_size ();
@@ -12763,9 +13055,8 @@ remote_trace_find (struct target_ops *self,
   return target_frameno;
 }
 
-static int
-remote_get_trace_state_variable_value (struct target_ops *self,
-       int tsvnum, LONGEST *val)
+int
+remote_target::get_trace_state_variable_value (int tsvnum, LONGEST *val)
 {
   struct remote_state *rs = get_remote_state ();
   char *reply;
@@ -12788,8 +13079,8 @@ remote_get_trace_state_variable_value (struct target_ops *self,
   return 0;
 }
 
-static int
-remote_save_trace_data (struct target_ops *self, const char *filename)
+int
+remote_target::save_trace_data (const char *filename)
 {
   struct remote_state *rs = get_remote_state ();
   char *p, *reply;
@@ -12815,9 +13106,8 @@ remote_save_trace_data (struct target_ops *self, const char *filename)
    memory, plus we want to be able to ask for as much as possible, but
    not be unhappy if we don't get as much as we ask for.  */
 
-static LONGEST
-remote_get_raw_trace_data (struct target_ops *self,
-   gdb_byte *buf, ULONGEST offset, LONGEST len)
+LONGEST
+remote_target::get_raw_trace_data (gdb_byte *buf, ULONGEST offset, LONGEST len)
 {
   struct remote_state *rs = get_remote_state ();
   char *reply;
@@ -12854,8 +13144,8 @@ remote_get_raw_trace_data (struct target_ops *self,
   return -1;
 }
 
-static void
-remote_set_disconnected_tracing (struct target_ops *self, int val)
+void
+remote_target::set_disconnected_tracing (int val)
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -12875,8 +13165,8 @@ remote_set_disconnected_tracing (struct target_ops *self, int val)
     warning (_("Target does not support disconnected tracing."));
 }
 
-static int
-remote_core_of_thread (struct target_ops *ops, ptid_t ptid)
+int
+remote_target::core_of_thread (ptid_t ptid)
 {
   struct thread_info *info = find_thread_ptid (ptid);
 
@@ -12886,8 +13176,8 @@ remote_core_of_thread (struct target_ops *ops, ptid_t ptid)
   return -1;
 }
 
-static void
-remote_set_circular_trace_buffer (struct target_ops *self, int val)
+void
+remote_target::set_circular_trace_buffer (int val)
 {
   struct remote_state *rs = get_remote_state ();
   char *reply;
@@ -12901,8 +13191,8 @@ remote_set_circular_trace_buffer (struct target_ops *self, int val)
     error (_("Bogus reply from target: %s"), reply);
 }
 
-static traceframe_info_up
-remote_traceframe_info (struct target_ops *self)
+traceframe_info_up
+remote_target::traceframe_info ()
 {
   gdb::optional<gdb::char_vector> text
     = target_read_stralloc (target_stack, TARGET_OBJECT_TRACEFRAME_INFO,
@@ -12918,8 +13208,8 @@ remote_traceframe_info (struct target_ops *self)
    if the packet is not supported, and 0 if the minimum instruction
    length is unknown.  */
 
-static int
-remote_get_min_fast_tracepoint_insn_len (struct target_ops *self)
+int
+remote_target::get_min_fast_tracepoint_insn_len ()
 {
   struct remote_state *rs = get_remote_state ();
   char *reply;
@@ -12947,8 +13237,8 @@ remote_get_min_fast_tracepoint_insn_len (struct target_ops *self)
     }
 }
 
-static void
-remote_set_trace_buffer_size (struct target_ops *self, LONGEST val)
+void
+remote_target::set_trace_buffer_size (LONGEST val)
 {
   if (packet_support (PACKET_QTBuffer_size) != PACKET_DISABLE)
     {
@@ -12978,10 +13268,9 @@ remote_set_trace_buffer_size (struct target_ops *self, LONGEST val)
     }
 }
 
-static int
-remote_set_trace_notes (struct target_ops *self,
- const char *user, const char *notes,
- const char *stop_notes)
+int
+remote_target::set_trace_notes (const char *user, const char *notes,
+ const char *stop_notes)
 {
   struct remote_state *rs = get_remote_state ();
   char *reply;
@@ -13025,8 +13314,8 @@ remote_set_trace_notes (struct target_ops *self,
   return 1;
 }
 
-static int
-remote_use_agent (struct target_ops *self, int use)
+int
+remote_target::use_agent (int use)
 {
   if (packet_support (PACKET_QAgent) != PACKET_DISABLE)
     {
@@ -13039,7 +13328,7 @@ remote_use_agent (struct target_ops *self, int use)
 
       if (strcmp (rs->buf, "OK") == 0)
  {
-  use_agent = use;
+  ::use_agent = use;
   return 1;
  }
     }
@@ -13047,8 +13336,8 @@ remote_use_agent (struct target_ops *self, int use)
   return 0;
 }
 
-static int
-remote_can_use_agent (struct target_ops *self)
+int
+remote_target::can_use_agent ()
 {
   return (packet_support (PACKET_QAgent) != PACKET_DISABLE);
 }
@@ -13197,9 +13486,8 @@ remote_btrace_maybe_reopen (void)
 
 /* Enable branch tracing.  */
 
-static struct btrace_target_info *
-remote_enable_btrace (struct target_ops *self, ptid_t ptid,
-      const struct btrace_config *conf)
+struct btrace_target_info *
+remote_target::enable_btrace (ptid_t ptid, const struct btrace_config *conf)
 {
   struct btrace_target_info *tinfo = NULL;
   struct packet_config *packet = NULL;
@@ -13260,9 +13548,8 @@ remote_enable_btrace (struct target_ops *self, ptid_t ptid,
 
 /* Disable branch tracing.  */
 
-static void
-remote_disable_btrace (struct target_ops *self,
-       struct btrace_target_info *tinfo)
+void
+remote_target::disable_btrace (struct btrace_target_info *tinfo)
 {
   struct packet_config *packet = &remote_protocol_packets[PACKET_Qbtrace_off];
   struct remote_state *rs = get_remote_state ();
@@ -13293,9 +13580,8 @@ remote_disable_btrace (struct target_ops *self,
 
 /* Teardown branch tracing.  */
 
-static void
-remote_teardown_btrace (struct target_ops *self,
- struct btrace_target_info *tinfo)
+void
+remote_target::teardown_btrace (struct btrace_target_info *tinfo)
 {
   /* We must not talk to the target during teardown.  */
   xfree (tinfo);
@@ -13303,11 +13589,10 @@ remote_teardown_btrace (struct target_ops *self,
 
 /* Read the branch trace.  */
 
-static enum btrace_error
-remote_read_btrace (struct target_ops *self,
-    struct btrace_data *btrace,
-    struct btrace_target_info *tinfo,
-    enum btrace_read_type type)
+enum btrace_error
+remote_target::read_btrace (struct btrace_data *btrace,
+    struct btrace_target_info *tinfo,
+    enum btrace_read_type type)
 {
   struct packet_config *packet = &remote_protocol_packets[PACKET_qXfer_btrace];
   const char *annex;
@@ -13346,15 +13631,14 @@ remote_read_btrace (struct target_ops *self,
   return BTRACE_ERR_NONE;
 }
 
-static const struct btrace_config *
-remote_btrace_conf (struct target_ops *self,
-    const struct btrace_target_info *tinfo)
+const struct btrace_config *
+remote_target::btrace_conf (const struct btrace_target_info *tinfo)
 {
   return &tinfo->conf;
 }
 
-static int
-remote_augmented_libraries_svr4_read (struct target_ops *self)
+int
+remote_target::augmented_libraries_svr4_read ()
 {
   return (packet_support (PACKET_augmented_libraries_svr4_read_feature)
   == PACKET_ENABLE);
@@ -13362,8 +13646,8 @@ remote_augmented_libraries_svr4_read (struct target_ops *self)
 
 /* Implementation of to_load.  */
 
-static void
-remote_load (struct target_ops *self, const char *name, int from_tty)
+void
+remote_target::load (const char *name, int from_tty)
 {
   generic_load (name, from_tty);
 }
@@ -13372,8 +13656,8 @@ remote_load (struct target_ops *self, const char *name, int from_tty)
    can be opened on the remote side to get the symbols for the child
    process.  Returns NULL if the operation is not supported.  */
 
-static char *
-remote_pid_to_exec_file (struct target_ops *self, int pid)
+char *
+remote_target::pid_to_exec_file (int pid)
 {
   static gdb::optional<gdb::char_vector> filename;
   struct inferior *inf;
@@ -13403,8 +13687,8 @@ remote_pid_to_exec_file (struct target_ops *self, int pid)
 
 /* Implement the to_can_do_single_step target_ops method.  */
 
-static int
-remote_can_do_single_step (struct target_ops *ops)
+int
+remote_target::can_do_single_step ()
 {
   /* We can only tell whether target supports single step or not by
      supported s and S vCont actions if the stub supports vContSupported
@@ -13427,8 +13711,8 @@ remote_can_do_single_step (struct target_ops *ops)
 /* Implementation of the to_execution_direction method for the remote
    target.  */
 
-static enum exec_direction_kind
-remote_execution_direction (struct target_ops *self)
+enum exec_direction_kind
+remote_target::execution_direction ()
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -13438,11 +13722,10 @@ remote_execution_direction (struct target_ops *self)
 /* Return pointer to the thread_info struct which corresponds to
    THREAD_HANDLE (having length HANDLE_LEN).  */
 
-static struct thread_info *
-remote_thread_handle_to_thread_info (struct target_ops *ops,
-     const gdb_byte *thread_handle,
-     int handle_len,
-     struct inferior *inf)
+thread_info *
+remote_target::thread_handle_to_thread_info (const gdb_byte *thread_handle,
+     int handle_len,
+     inferior *inf)
 {
   struct thread_info *tp;
 
@@ -13464,182 +13747,8 @@ remote_thread_handle_to_thread_info (struct target_ops *ops,
   return NULL;
 }
 
-static void
-init_remote_ops (void)
-{
-  remote_ops.to_shortname = "remote";
-  remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
-  remote_ops.to_doc =
-    "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.).";
-  remote_ops.to_open = remote_open;
-  remote_ops.to_close = remote_close;
-  remote_ops.to_detach = remote_detach;
-  remote_ops.to_disconnect = remote_disconnect;
-  remote_ops.to_resume = remote_resume;
-  remote_ops.to_commit_resume = remote_commit_resume;
-  remote_ops.to_wait = remote_wait;
-  remote_ops.to_fetch_registers = remote_fetch_registers;
-  remote_ops.to_store_registers = remote_store_registers;
-  remote_ops.to_prepare_to_store = remote_prepare_to_store;
-  remote_ops.to_files_info = remote_files_info;
-  remote_ops.to_insert_breakpoint = remote_insert_breakpoint;
-  remote_ops.to_remove_breakpoint = remote_remove_breakpoint;
-  remote_ops.to_stopped_by_sw_breakpoint = remote_stopped_by_sw_breakpoint;
-  remote_ops.to_supports_stopped_by_sw_breakpoint = remote_supports_stopped_by_sw_breakpoint;
-  remote_ops.to_stopped_by_hw_breakpoint = remote_stopped_by_hw_breakpoint;
-  remote_ops.to_supports_stopped_by_hw_breakpoint = remote_supports_stopped_by_hw_breakpoint;
-  remote_ops.to_stopped_by_watchpoint = remote_stopped_by_watchpoint;
-  remote_ops.to_stopped_data_address = remote_stopped_data_address;
-  remote_ops.to_watchpoint_addr_within_range =
-    remote_watchpoint_addr_within_range;
-  remote_ops.to_can_use_hw_breakpoint = remote_check_watch_resources;
-  remote_ops.to_insert_hw_breakpoint = remote_insert_hw_breakpoint;
-  remote_ops.to_remove_hw_breakpoint = remote_remove_hw_breakpoint;
-  remote_ops.to_region_ok_for_hw_watchpoint
-     = remote_region_ok_for_hw_watchpoint;
-  remote_ops.to_insert_watchpoint = remote_insert_watchpoint;
-  remote_ops.to_remove_watchpoint = remote_remove_watchpoint;
-  remote_ops.to_kill = remote_kill;
-  remote_ops.to_load = remote_load;
-  remote_ops.to_mourn_inferior = remote_mourn;
-  remote_ops.to_pass_signals = remote_pass_signals;
-  remote_ops.to_set_syscall_catchpoint = remote_set_syscall_catchpoint;
-  remote_ops.to_program_signals = remote_program_signals;
-  remote_ops.to_thread_alive = remote_thread_alive;
-  remote_ops.to_thread_name = remote_thread_name;
-  remote_ops.to_update_thread_list = remote_update_thread_list;
-  remote_ops.to_pid_to_str = remote_pid_to_str;
-  remote_ops.to_extra_thread_info = remote_threads_extra_info;
-  remote_ops.to_get_ada_task_ptid = remote_get_ada_task_ptid;
-  remote_ops.to_stop = remote_stop;
-  remote_ops.to_interrupt = remote_interrupt;
-  remote_ops.to_pass_ctrlc = remote_pass_ctrlc;
-  remote_ops.to_xfer_partial = remote_xfer_partial;
-  remote_ops.to_get_memory_xfer_limit = remote_get_memory_xfer_limit;
-  remote_ops.to_rcmd = remote_rcmd;
-  remote_ops.to_pid_to_exec_file = remote_pid_to_exec_file;
-  remote_ops.to_log_command = serial_log_command;
-  remote_ops.to_get_thread_local_address = remote_get_thread_local_address;
-  remote_ops.to_stratum = process_stratum;
-  remote_ops.to_has_all_memory = default_child_has_all_memory;
-  remote_ops.to_has_memory = default_child_has_memory;
-  remote_ops.to_has_stack = default_child_has_stack;
-  remote_ops.to_has_registers = default_child_has_registers;
-  remote_ops.to_has_execution = default_child_has_execution;
-  remote_ops.to_has_thread_control = tc_schedlock;    /* can lock scheduler */
-  remote_ops.to_can_execute_reverse = remote_can_execute_reverse;
-  remote_ops.to_magic = OPS_MAGIC;
-  remote_ops.to_memory_map = remote_memory_map;
-  remote_ops.to_flash_erase = remote_flash_erase;
-  remote_ops.to_flash_done = remote_flash_done;
-  remote_ops.to_read_description = remote_read_description;
-  remote_ops.to_search_memory = remote_search_memory;
-  remote_ops.to_can_async_p = remote_can_async_p;
-  remote_ops.to_is_async_p = remote_is_async_p;
-  remote_ops.to_async = remote_async;
-  remote_ops.to_thread_events = remote_thread_events;
-  remote_ops.to_can_do_single_step = remote_can_do_single_step;
-  remote_ops.to_terminal_inferior = remote_terminal_inferior;
-  remote_ops.to_terminal_ours = remote_terminal_ours;
-  remote_ops.to_supports_non_stop = remote_supports_non_stop;
-  remote_ops.to_supports_multi_process = remote_supports_multi_process;
-  remote_ops.to_supports_disable_randomization
-    = remote_supports_disable_randomization;
-  remote_ops.to_filesystem_is_local = remote_filesystem_is_local;
-  remote_ops.to_fileio_open = remote_hostio_open;
-  remote_ops.to_fileio_pwrite = remote_hostio_pwrite;
-  remote_ops.to_fileio_pread = remote_hostio_pread;
-  remote_ops.to_fileio_fstat = remote_hostio_fstat;
-  remote_ops.to_fileio_close = remote_hostio_close;
-  remote_ops.to_fileio_unlink = remote_hostio_unlink;
-  remote_ops.to_fileio_readlink = remote_hostio_readlink;
-  remote_ops.to_supports_enable_disable_tracepoint = remote_supports_enable_disable_tracepoint;
-  remote_ops.to_supports_string_tracing = remote_supports_string_tracing;
-  remote_ops.to_supports_evaluation_of_breakpoint_conditions = remote_supports_cond_breakpoints;
-  remote_ops.to_can_run_breakpoint_commands = remote_can_run_breakpoint_commands;
-  remote_ops.to_trace_init = remote_trace_init;
-  remote_ops.to_download_tracepoint = remote_download_tracepoint;
-  remote_ops.to_can_download_tracepoint = remote_can_download_tracepoint;
-  remote_ops.to_download_trace_state_variable
-    = remote_download_trace_state_variable;
-  remote_ops.to_enable_tracepoint = remote_enable_tracepoint;
-  remote_ops.to_disable_tracepoint = remote_disable_tracepoint;
-  remote_ops.to_trace_set_readonly_regions = remote_trace_set_readonly_regions;
-  remote_ops.to_trace_start = remote_trace_start;
-  remote_ops.to_get_trace_status = remote_get_trace_status;
-  remote_ops.to_get_tracepoint_status = remote_get_tracepoint_status;
-  remote_ops.to_trace_stop = remote_trace_stop;
-  remote_ops.to_trace_find = remote_trace_find;
-  remote_ops.to_get_trace_state_variable_value
-    = remote_get_trace_state_variable_value;
-  remote_ops.to_save_trace_data = remote_save_trace_data;
-  remote_ops.to_upload_tracepoints = remote_upload_tracepoints;
-  remote_ops.to_upload_trace_state_variables
-    = remote_upload_trace_state_variables;
-  remote_ops.to_get_raw_trace_data = remote_get_raw_trace_data;
-  remote_ops.to_get_min_fast_tracepoint_insn_len = remote_get_min_fast_tracepoint_insn_len;
-  remote_ops.to_set_disconnected_tracing = remote_set_disconnected_tracing;
-  remote_ops.to_set_circular_trace_buffer = remote_set_circular_trace_buffer;
-  remote_ops.to_set_trace_buffer_size = remote_set_trace_buffer_size;
-  remote_ops.to_set_trace_notes = remote_set_trace_notes;
-  remote_ops.to_core_of_thread = remote_core_of_thread;
-  remote_ops.to_verify_memory = remote_verify_memory;
-  remote_ops.to_get_tib_address = remote_get_tib_address;
-  remote_ops.to_set_permissions = remote_set_permissions;
-  remote_ops.to_static_tracepoint_marker_at
-    = remote_static_tracepoint_marker_at;
-  remote_ops.to_static_tracepoint_markers_by_strid
-    = remote_static_tracepoint_markers_by_strid;
-  remote_ops.to_traceframe_info = remote_traceframe_info;
-  remote_ops.to_use_agent = remote_use_agent;
-  remote_ops.to_can_use_agent = remote_can_use_agent;
-  remote_ops.to_enable_btrace = remote_enable_btrace;
-  remote_ops.to_disable_btrace = remote_disable_btrace;
-  remote_ops.to_teardown_btrace = remote_teardown_btrace;
-  remote_ops.to_read_btrace = remote_read_btrace;
-  remote_ops.to_btrace_conf = remote_btrace_conf;
-  remote_ops.to_augmented_libraries_svr4_read =
-    remote_augmented_libraries_svr4_read;
-  remote_ops.to_follow_fork = remote_follow_fork;
-  remote_ops.to_follow_exec = remote_follow_exec;
-  remote_ops.to_insert_fork_catchpoint = remote_insert_fork_catchpoint;
-  remote_ops.to_remove_fork_catchpoint = remote_remove_fork_catchpoint;
-  remote_ops.to_insert_vfork_catchpoint = remote_insert_vfork_catchpoint;
-  remote_ops.to_remove_vfork_catchpoint = remote_remove_vfork_catchpoint;
-  remote_ops.to_insert_exec_catchpoint = remote_insert_exec_catchpoint;
-  remote_ops.to_remove_exec_catchpoint = remote_remove_exec_catchpoint;
-  remote_ops.to_execution_direction = remote_execution_direction;
-  remote_ops.to_thread_handle_to_thread_info =
-    remote_thread_handle_to_thread_info;
-}
-
-/* Set up the extended remote vector by making a copy of the standard
-   remote vector and adding to it.  */
-
-static void
-init_extended_remote_ops (void)
-{
-  extended_remote_ops = remote_ops;
-
-  extended_remote_ops.to_shortname = "extended-remote";
-  extended_remote_ops.to_longname =
-    "Extended remote serial target in gdb-specific protocol";
-  extended_remote_ops.to_doc =
-    "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
-Specify the serial device it is connected to (e.g. /dev/ttya).";
-  extended_remote_ops.to_open = extended_remote_open;
-  extended_remote_ops.to_create_inferior = extended_remote_create_inferior;
-  extended_remote_ops.to_detach = extended_remote_detach;
-  extended_remote_ops.to_attach = extended_remote_attach;
-  extended_remote_ops.to_post_attach = extended_remote_post_attach;
-  extended_remote_ops.to_supports_disable_randomization
-    = extended_remote_supports_disable_randomization;
-}
-
-static int
-remote_can_async_p (struct target_ops *ops)
+int
+remote_target::can_async_p ()
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -13652,8 +13761,8 @@ remote_can_async_p (struct target_ops *ops)
   return serial_can_async_p (rs->remote_desc);
 }
 
-static int
-remote_is_async_p (struct target_ops *ops)
+int
+remote_target::is_async_p ()
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -13685,8 +13794,8 @@ remote_async_inferior_event_handler (gdb_client_data data)
   inferior_event_handler (INF_REG_EVENT, NULL);
 }
 
-static void
-remote_async (struct target_ops *ops, int enable)
+void
+remote_target::async (int enable)
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -13720,8 +13829,8 @@ remote_async (struct target_ops *ops, int enable)
 
 /* Implementation of the to_thread_events method.  */
 
-static void
-remote_thread_events (struct target_ops *ops, int enable)
+void
+remote_target::thread_events (int enable)
 {
   struct remote_state *rs = get_remote_state ();
   size_t size = get_remote_packet_size ();
@@ -13799,8 +13908,8 @@ remote_new_objfile (struct objfile *objfile)
    tracepoints yet, we don't want to mess up the user's existing
    collection.  */
   
-static int
-remote_upload_tracepoints (struct target_ops *self, struct uploaded_tp **utpp)
+int
+remote_target::upload_tracepoints (struct uploaded_tp **utpp)
 {
   struct remote_state *rs = get_remote_state ();
   char *p;
@@ -13820,9 +13929,8 @@ remote_upload_tracepoints (struct target_ops *self, struct uploaded_tp **utpp)
   return 0;
 }
 
-static int
-remote_upload_trace_state_variables (struct target_ops *self,
-     struct uploaded_tsv **utsvp)
+int
+remote_target::upload_trace_state_variables (struct uploaded_tsv **utsvp)
 {
   struct remote_state *rs = get_remote_state ();
   char *p;
@@ -13901,10 +14009,7 @@ _initialize_remote (void)
      time.  */
   remote_state = new_remote_state ();
 
-  init_remote_ops ();
   add_target (&remote_ops);
-
-  init_extended_remote_ops ();
   add_target (&extended_remote_ops);
 
   /* Hook into new objfile notification.  */
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 12/40] target_ops/C++: target remote-sim

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.
---
 gdb/remote-sim.c | 220 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 111 insertions(+), 109 deletions(-)

diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 456fa8a3fe..3d484bcd85 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -68,35 +68,79 @@ static void gdb_os_evprintf_filtered (host_callback *, const char *, va_list);
 static void gdb_os_error (host_callback *, const char *, ...)
      ATTRIBUTE_NORETURN;
 
-static void gdbsim_kill (struct target_ops *);
+void simulator_command (char *args, int from_tty);
 
-static void gdbsim_load (struct target_ops *self, const char *prog,
- int fromtty);
+/* Naming convention:
 
-static void gdbsim_open (const char *args, int from_tty);
+   sim_* are the interface to the simulator (see remote-sim.h).
+   gdbsim_* are stuff which is internal to gdb.  */
 
-static void gdbsim_close (struct target_ops *self);
+struct gdbsim_target
+  : public memory_breakpoint_target<target_ops>
+{
+  gdbsim_target ()
+  { to_stratum = process_stratum; }
 
-static void gdbsim_detach (struct target_ops *ops, inferior *inf, int from_tty);
+  const char *shortname () override
+  { return "sim"; }
 
-static void gdbsim_prepare_to_store (struct target_ops *self,
-     struct regcache *regcache);
+  const char *longname () override
+  { return _("simulator"); }
 
-static void gdbsim_files_info (struct target_ops *target);
+  const char *doc () override
+  { return _("Use the compiled-in simulator."); }
 
-static void gdbsim_mourn_inferior (struct target_ops *target);
+  void open (const char *, int) override;
+  void close () override;
 
-static void gdbsim_interrupt (struct target_ops *self);
+  void detach (inferior *inf, int) override;
 
-void simulator_command (char *args, int from_tty);
+  void resume (ptid_t, int, enum gdb_signal) override;
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
 
-/* Naming convention:
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+  void prepare_to_store (struct regcache *) override;
 
-   sim_* are the interface to the simulator (see remote-sim.h).
-   gdbsim_* are stuff which is internal to gdb.  */
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+  void files_info () override;
+
+  void kill () override;
+
+  void load (const char *, int) override;
+
+  bool can_create_inferior () override { return true; }
+  void create_inferior (const char *, const std::string &,
+ char **, int) override;
+
+  void mourn_inferior () override;
+
+  void interrupt () override;
+
+  int thread_alive (ptid_t ptid) override;
 
-/* Forward data declarations */
-extern struct target_ops gdbsim_ops;
+  const char *pid_to_str (ptid_t) override;
+
+  int has_all_memory ()  override;
+  int has_memory ()  override;
+
+  int has_stack ()  override
+  { return default_child_has_stack (); }
+
+  int has_registers ()  override
+  { return default_child_has_registers (); }
+
+  int has_execution (ptid_t ptid) override
+  { return default_child_has_execution (ptid); }
+};
+
+static struct gdbsim_target gdbsim_ops;
 
 static const struct inferior_data *sim_inferior_data_key;
 
@@ -422,9 +466,8 @@ one2one_register_sim_regno (struct gdbarch *gdbarch, int regnum)
   return regnum;
 }
 
-static void
-gdbsim_fetch_register (struct target_ops *ops,
-       struct regcache *regcache, int regno)
+void
+gdbsim_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   struct inferior *inf = find_inferior_ptid (regcache_get_ptid (regcache));
@@ -434,7 +477,7 @@ gdbsim_fetch_register (struct target_ops *ops,
   if (regno == -1)
     {
       for (regno = 0; regno < gdbarch_num_regs (gdbarch); regno++)
- gdbsim_fetch_register (ops, regcache, regno);
+ fetch_registers (regcache, regno);
       return;
     }
 
@@ -492,9 +535,8 @@ gdbsim_fetch_register (struct target_ops *ops,
 }
 
 
-static void
-gdbsim_store_register (struct target_ops *ops,
-       struct regcache *regcache, int regno)
+void
+gdbsim_target::store_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   struct inferior *inf = find_inferior_ptid (regcache_get_ptid (regcache));
@@ -504,7 +546,7 @@ gdbsim_store_register (struct target_ops *ops,
   if (regno == -1)
     {
       for (regno = 0; regno < gdbarch_num_regs (gdbarch); regno++)
- gdbsim_store_register (ops, regcache, regno);
+ store_registers (regcache, regno);
       return;
     }
   else if (gdbarch_register_sim_regno (gdbarch, regno) >= 0)
@@ -541,8 +583,8 @@ gdbsim_store_register (struct target_ops *ops,
 /* Kill the running program.  This may involve closing any open files
    and releasing other resources acquired by the simulated program.  */
 
-static void
-gdbsim_kill (struct target_ops *ops)
+void
+gdbsim_target::kill ()
 {
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "gdbsim_kill\n");
@@ -556,8 +598,8 @@ gdbsim_kill (struct target_ops *ops)
    not only bring new code into the target process, but also to update
    GDB's symbol tables to match.  */
 
-static void
-gdbsim_load (struct target_ops *self, const char *args, int fromtty)
+void
+gdbsim_target::load (const char *args, int fromtty)
 {
   const char *prog;
   struct sim_inferior_data *sim_data
@@ -597,9 +639,10 @@ gdbsim_load (struct target_ops *self, const char *args, int fromtty)
 /* This is called not only when we first attach, but also when the
    user types "run" after having attached.  */
 
-static void
-gdbsim_create_inferior (struct target_ops *target, const char *exec_file,
- const std::string &allargs, char **env, int from_tty)
+void
+gdbsim_target::create_inferior (const char *exec_file,
+ const std::string &allargs,
+ char **env, int from_tty)
 {
   struct sim_inferior_data *sim_data
     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
@@ -619,7 +662,7 @@ gdbsim_create_inferior (struct target_ops *target, const char *exec_file,
  args);
 
   if (ptid_equal (inferior_ptid, sim_data->remote_sim_ptid))
-    gdbsim_kill (target);
+    kill ();
   remove_breakpoints ();
   init_wait_for_inferior ();
 
@@ -658,8 +701,8 @@ gdbsim_create_inferior (struct target_ops *target, const char *exec_file,
    Targets should supply this routine, if only to provide an error message.  */
 /* Called when selecting the simulator.  E.g. (gdb) target sim name.  */
 
-static void
-gdbsim_open (const char *args, int from_tty)
+void
+gdbsim_target::open (const char *args, int from_tty)
 {
   int len;
   char *arg_buf;
@@ -789,8 +832,8 @@ gdbsim_close_inferior (struct inferior *inf, void *arg)
 
 /* Close out all files and local state before this target loses control.  */
 
-static void
-gdbsim_close (struct target_ops *self)
+void
+gdbsim_target::close ()
 {
   struct sim_inferior_data *sim_data
     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
@@ -819,13 +862,13 @@ gdbsim_close (struct target_ops *self)
 /* Terminate the open connection to the remote debugger.
    Use this when you want to detach and do something else with your gdb.  */
 
-static void
-gdbsim_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+gdbsim_target::detach (inferior *inf, int from_tty)
 {
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "gdbsim_detach\n");
 
-  unpush_target (ops); /* calls gdbsim_close to do the real work */
+  unpush_target (this); /* calls gdbsim_close to do the real work */
   if (from_tty)
     printf_filtered ("Ending simulator %s debugging\n", target_shortname);
 }
@@ -864,9 +907,8 @@ gdbsim_resume_inferior (struct inferior *inf, void *arg)
   return 0;
 }
 
-static void
-gdbsim_resume (struct target_ops *ops,
-       ptid_t ptid, int step, enum gdb_signal siggnal)
+void
+gdbsim_target::resume (ptid_t ptid, int step, enum gdb_signal siggnal)
 {
   struct resume_data rd;
   struct sim_inferior_data *sim_data
@@ -919,8 +961,8 @@ gdbsim_interrupt_inferior (struct inferior *inf, void *arg)
   return 0;
 }
 
-static void
-gdbsim_interrupt (struct target_ops *self)
+void
+gdbsim_target::interrupt ()
 {
   iterate_over_inferiors (gdbsim_interrupt_inferior, NULL);
 }
@@ -946,12 +988,11 @@ gdb_os_poll_quit (host_callback *p)
 static void
 gdbsim_cntrl_c (int signo)
 {
-  gdbsim_interrupt (NULL);
+  gdbsim_ops.interrupt ();
 }
 
-static ptid_t
-gdbsim_wait (struct target_ops *ops,
-     ptid_t ptid, struct target_waitstatus *status, int options)
+ptid_t
+gdbsim_target::wait (ptid_t ptid, struct target_waitstatus *status, int options)
 {
   struct sim_inferior_data *sim_data;
   static sighandler_t prev_sigint;
@@ -1035,8 +1076,8 @@ gdbsim_wait (struct target_ops *ops,
    that registers contains all the registers from the program being
    debugged.  */
 
-static void
-gdbsim_prepare_to_store (struct target_ops *self, struct regcache *regcache)
+void
+gdbsim_target::prepare_to_store (struct regcache *regcache)
 {
   /* Do nothing, since we can store individual regs.  */
 }
@@ -1056,7 +1097,7 @@ gdbsim_xfer_memory (struct target_ops *target,
   /* If this target doesn't have memory yet, return 0 causing the
      request to be passed to a lower target, hopefully an exec
      file.  */
-  if (!target->to_has_memory (target))
+  if (!target->has_memory ())
     return TARGET_XFER_EOF;
 
   if (!sim_data->program_loaded)
@@ -1104,16 +1145,16 @@ gdbsim_xfer_memory (struct target_ops *target,
 
 /* Target to_xfer_partial implementation.  */
 
-static enum target_xfer_status
-gdbsim_xfer_partial (struct target_ops *ops, enum target_object object,
-     const char *annex, gdb_byte *readbuf,
-     const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
-     ULONGEST *xfered_len)
+enum target_xfer_status
+gdbsim_target::xfer_partial (enum target_object object,
+     const char *annex, gdb_byte *readbuf,
+     const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+     ULONGEST *xfered_len)
 {
   switch (object)
     {
     case TARGET_OBJECT_MEMORY:
-      return gdbsim_xfer_memory (ops, readbuf, writebuf, offset, len,
+      return gdbsim_xfer_memory (this, readbuf, writebuf, offset, len,
  xfered_len);
 
     default:
@@ -1121,8 +1162,8 @@ gdbsim_xfer_partial (struct target_ops *ops, enum target_object object,
     }
 }
 
-static void
-gdbsim_files_info (struct target_ops *target)
+void
+gdbsim_target::files_info ()
 {
   struct sim_inferior_data *sim_data
     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
@@ -1144,8 +1185,8 @@ gdbsim_files_info (struct target_ops *target)
 
 /* Clear the simulator's notion of what the break points are.  */
 
-static void
-gdbsim_mourn_inferior (struct target_ops *target)
+void
+gdbsim_target::mourn_inferior ()
 {
   struct sim_inferior_data *sim_data
     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
@@ -1247,8 +1288,8 @@ sim_command_completer (struct cmd_list_element *ignore,
 
 /* Check to see if a thread is still alive.  */
 
-static int
-gdbsim_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+gdbsim_target::thread_alive (ptid_t ptid)
 {
   struct sim_inferior_data *sim_data
     = get_sim_inferior_data_by_ptid (ptid, SIM_INSTANCE_NOT_NEEDED);
@@ -1266,16 +1307,16 @@ gdbsim_thread_alive (struct target_ops *ops, ptid_t ptid)
 /* Convert a thread ID to a string.  Returns the string in a static
    buffer.  */
 
-static const char *
-gdbsim_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+gdbsim_target::pid_to_str (ptid_t ptid)
 {
   return normal_pid_to_str (ptid);
 }
 
 /* Simulator memory may be accessed after the program has been loaded.  */
 
-static int
-gdbsim_has_all_memory (struct target_ops *ops)
+int
+gdbsim_target::has_all_memory ()
 {
   struct sim_inferior_data *sim_data
     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
@@ -1286,8 +1327,8 @@ gdbsim_has_all_memory (struct target_ops *ops)
   return 1;
 }
 
-static int
-gdbsim_has_memory (struct target_ops *ops)
+int
+gdbsim_target::has_memory ()
 {
   struct sim_inferior_data *sim_data
     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED);
@@ -1298,50 +1339,11 @@ gdbsim_has_memory (struct target_ops *ops)
   return 1;
 }
 
-/* Define the target subroutine names.  */
-
-struct target_ops gdbsim_ops;
-
-static void
-init_gdbsim_ops (void)
-{
-  gdbsim_ops.to_shortname = "sim";
-  gdbsim_ops.to_longname = "simulator";
-  gdbsim_ops.to_doc = "Use the compiled-in simulator.";
-  gdbsim_ops.to_open = gdbsim_open;
-  gdbsim_ops.to_close = gdbsim_close;
-  gdbsim_ops.to_detach = gdbsim_detach;
-  gdbsim_ops.to_resume = gdbsim_resume;
-  gdbsim_ops.to_wait = gdbsim_wait;
-  gdbsim_ops.to_fetch_registers = gdbsim_fetch_register;
-  gdbsim_ops.to_store_registers = gdbsim_store_register;
-  gdbsim_ops.to_prepare_to_store = gdbsim_prepare_to_store;
-  gdbsim_ops.to_xfer_partial = gdbsim_xfer_partial;
-  gdbsim_ops.to_files_info = gdbsim_files_info;
-  gdbsim_ops.to_insert_breakpoint = memory_insert_breakpoint;
-  gdbsim_ops.to_remove_breakpoint = memory_remove_breakpoint;
-  gdbsim_ops.to_kill = gdbsim_kill;
-  gdbsim_ops.to_load = gdbsim_load;
-  gdbsim_ops.to_create_inferior = gdbsim_create_inferior;
-  gdbsim_ops.to_mourn_inferior = gdbsim_mourn_inferior;
-  gdbsim_ops.to_interrupt = gdbsim_interrupt;
-  gdbsim_ops.to_thread_alive = gdbsim_thread_alive;
-  gdbsim_ops.to_pid_to_str = gdbsim_pid_to_str;
-  gdbsim_ops.to_stratum = process_stratum;
-  gdbsim_ops.to_has_all_memory = gdbsim_has_all_memory;
-  gdbsim_ops.to_has_memory = gdbsim_has_memory;
-  gdbsim_ops.to_has_stack = default_child_has_stack;
-  gdbsim_ops.to_has_registers = default_child_has_registers;
-  gdbsim_ops.to_has_execution = default_child_has_execution;
-  gdbsim_ops.to_magic = OPS_MAGIC;
-}
-
 void
 _initialize_remote_sim (void)
 {
   struct cmd_list_element *c;
 
-  init_gdbsim_ops ();
   add_target (&gdbsim_ops);
 
   c = add_com ("sim", class_obscure, simulator_command,
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 13/40] target_ops/C++: GNU/Linux + x86/AMD64

Pedro Alves-7
In reply to this post by Pedro Alves-7
This converts the x86/AMD64 GNU/Linux ports to C++ified target_ops.

- inf-child/"native" is converted to an actual base class
  (inf_child_target), that is inherited by the linux-nat target.
  inf_child_target will be inherited by all other native targets too,
  of course, in the following patches.

- The old weird double-target linux_ops mechanism in linux-nat.c, is
  gone, replaced by adding a few virtual methods to linux-nat.h's
  target_ops, called low_XXX, that the concrete linux-nat
  implementations override.  Sort of like gdbserver's
  linux_target_ops, but simpler, for requiring only one
  target_ops-like hierarchy, which spares implementing the same method
  twice when we need to forward the method to a low implementation.
  The low target simply reimplements the target_ops method directly in
  that case.

  There are a few remaining linux-nat.c hooks that would be better
  converted to low_ methods like above too.  E.g.:

   linux_nat_set_new_thread (t, x86_linux_new_thread);
   linux_nat_set_new_fork (t, x86_linux_new_fork);
   linux_nat_set_forget_process

  That'll be done in a follow up patch.

- We can no longer use functions like x86_use_watchpoints to install
  custom methods on an arbitrary base target.  The patch replaces that
  with a template mixin.  See x86_nat_target in x86-nat.h.  That will
  be used by other non-Linux x86 targets in following patches.

- linux-thread-db is converted here too.
---
 gdb/amd64-linux-nat.c |  33 ++--
 gdb/i386-linux-nat.c  |  42 ++---
 gdb/inf-child.c       | 295 +++++++++++++++----------------
 gdb/inf-child.h       | 112 ++++++++++--
 gdb/inf-ptrace.c      | 142 ++++++---------
 gdb/inf-ptrace.h      |  67 +++++--
 gdb/linux-nat.c       | 480 +++++++++++++++++++-------------------------------
 gdb/linux-nat.h       | 141 +++++++++++++--
 gdb/linux-thread-db.c | 155 ++++++++--------
 gdb/x86-linux-nat.c   |  80 +++------
 gdb/x86-linux-nat.h   |  44 ++++-
 gdb/x86-nat.c         |  64 ++-----
 gdb/x86-nat.h         |  79 ++++++++-
 13 files changed, 926 insertions(+), 808 deletions(-)

diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
index ad942435b8..cee364476c 100644
--- a/gdb/amd64-linux-nat.c
+++ b/gdb/amd64-linux-nat.c
@@ -30,7 +30,6 @@
 #include "gdb_proc_service.h"
 
 #include "amd64-nat.h"
-#include "linux-nat.h"
 #include "amd64-tdep.h"
 #include "amd64-linux-tdep.h"
 #include "i386-linux-tdep.h"
@@ -46,6 +45,15 @@
 #define PTRACE_ARCH_PRCTL      30
 #endif
 
+struct amd64_linux_nat_target final : public x86_linux_nat_target
+{
+  /* Add our register access methods.  */
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+};
+
+static amd64_linux_nat_target the_amd64_linux_nat_target;
+
 /* Mapping between the general-purpose registers in GNU/Linux x86-64
    `struct user' format and GDB's register cache layout for GNU/Linux
    i386.
@@ -130,9 +138,8 @@ fill_fpregset (const struct regcache *regcache,
    this for all registers (including the floating point and SSE
    registers).  */
 
-static void
-amd64_linux_fetch_inferior_registers (struct target_ops *ops,
-      struct regcache *regcache, int regnum)
+void
+amd64_linux_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   int tid;
@@ -209,9 +216,8 @@ amd64_linux_fetch_inferior_registers (struct target_ops *ops,
    -1, do this for all registers (including the floating-point and SSE
    registers).  */
 
-static void
-amd64_linux_store_inferior_registers (struct target_ops *ops,
-      struct regcache *regcache, int regnum)
+void
+amd64_linux_nat_target::store_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   int tid;
@@ -399,8 +405,6 @@ amd64_linux_siginfo_fixup (siginfo_t *ptrace, gdb_byte *inf, int direction)
 void
 _initialize_amd64_linux_nat (void)
 {
-  struct target_ops *t;
-
   amd64_native_gregset32_reg_offset = amd64_linux_gregset32_reg_offset;
   amd64_native_gregset32_num_regs = I386_LINUX_NUM_REGS;
   amd64_native_gregset64_reg_offset = amd64_linux_gregset_reg_offset;
@@ -409,16 +413,11 @@ _initialize_amd64_linux_nat (void)
   gdb_assert (ARRAY_SIZE (amd64_linux_gregset32_reg_offset)
       == amd64_native_gregset32_num_regs);
 
-  /* Create a generic x86 GNU/Linux target.  */
-  t = x86_linux_create_target ();
-
-  /* Add our register access methods.  */
-  t->to_fetch_registers = amd64_linux_fetch_inferior_registers;
-  t->to_store_registers = amd64_linux_store_inferior_registers;
+  linux_target = &the_amd64_linux_nat_target;
 
   /* Add the target.  */
-  x86_linux_add_target (t);
+  x86_linux_add_target (linux_target);
 
   /* Add our siginfo layout converter.  */
-  linux_nat_set_siginfo_fixup (t, amd64_linux_siginfo_fixup);
+  linux_nat_set_siginfo_fixup (linux_target, amd64_linux_siginfo_fixup);
 }
diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
index d1d32e1b20..b923e65712 100644
--- a/gdb/i386-linux-nat.c
+++ b/gdb/i386-linux-nat.c
@@ -33,11 +33,22 @@
 #include "i386-linux-tdep.h"
 #include "x86-xstate.h"
 
-#include "linux-nat.h"
 #include "x86-linux-nat.h"
 #include "nat/linux-ptrace.h"
 #include "inf-ptrace.h"
 
+struct i386_linux_nat_target final : public x86_linux_nat_target
+{
+  /* Add our register access methods.  */
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  /* Override the default ptrace resume method.  */
+  void low_resume (ptid_t ptid, int step, enum gdb_signal sig) override;
+};
+
+static i386_linux_nat_target the_i386_linux_nat_target;
+
 /* The register sets used in GNU/Linux ELF core-dumps are identical to
    the register sets in `struct user' that is used for a.out
    core-dumps, and is also used by `ptrace'.  The corresponding types
@@ -446,9 +457,8 @@ store_fpxregs (const struct regcache *regcache, int tid, int regno)
    this for all registers (including the floating point and SSE
    registers).  */
 
-static void
-i386_linux_fetch_inferior_registers (struct target_ops *ops,
-     struct regcache *regcache, int regno)
+void
+i386_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   pid_t tid;
 
@@ -478,7 +488,7 @@ i386_linux_fetch_inferior_registers (struct target_ops *ops,
       /* The call above might reset `have_ptrace_getregs'.  */
       if (!have_ptrace_getregs)
  {
-  i386_linux_fetch_inferior_registers (ops, regcache, regno);
+  fetch_registers (regcache, regno);
   return;
  }
 
@@ -524,9 +534,8 @@ i386_linux_fetch_inferior_registers (struct target_ops *ops,
 /* Store register REGNO back into the child process.  If REGNO is -1,
    do this for all registers (including the floating point and SSE
    registers).  */
-static void
-i386_linux_store_inferior_registers (struct target_ops *ops,
-     struct regcache *regcache, int regno)
+void
+i386_linux_nat_target::store_registers (struct regcache *regcache, int regno)
 {
   pid_t tid;
 
@@ -635,9 +644,8 @@ static const unsigned char linux_syscall[] = { 0xcd, 0x80 };
    If STEP is nonzero, single-step it.
    If SIGNAL is nonzero, give it that signal.  */
 
-static void
-i386_linux_resume (struct target_ops *ops,
-   ptid_t ptid, int step, enum gdb_signal signal)
+void
+i386_linux_nat_target::low_resume (ptid_t ptid, int step, enum gdb_signal signal)
 {
   int pid = ptid_get_lwp (ptid);
   int request;
@@ -706,16 +714,8 @@ i386_linux_resume (struct target_ops *ops,
 void
 _initialize_i386_linux_nat (void)
 {
-  /* Create a generic x86 GNU/Linux target.  */
-  struct target_ops *t = x86_linux_create_target ();
-
-  /* Override the default ptrace resume method.  */
-  t->to_resume = i386_linux_resume;
-
-  /* Add our register access methods.  */
-  t->to_fetch_registers = i386_linux_fetch_inferior_registers;
-  t->to_store_registers = i386_linux_store_inferior_registers;
+  linux_target = &the_i386_linux_nat_target;
 
   /* Add the target.  */
-  x86_linux_add_target (t);
+  x86_linux_add_target (linux_target);
 }
diff --git a/gdb/inf-child.c b/gdb/inf-child.c
index c7c45530b6..7b2f2a25a2 100644
--- a/gdb/inf-child.c
+++ b/gdb/inf-child.c
@@ -39,11 +39,6 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-/* A pointer to what is returned by inf_child_target.  Used by
-   inf_child_open to push the most-derived target in reaction to
-   "target native".  */
-static struct target_ops *inf_child_ops = NULL;
-
 /* 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.  */
@@ -67,35 +62,11 @@ store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
     }
 }
 
-/* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
-   for all registers.  */
-
-static void
-inf_child_fetch_inferior_registers (struct target_ops *ops,
-    struct regcache *regcache, int regnum)
-{
-  if (regnum == -1)
-    {
-      for (regnum = 0;
-   regnum < gdbarch_num_regs (regcache->arch ());
-   regnum++)
- regcache_raw_supply (regcache, regnum, NULL);
-    }
-  else
-    regcache_raw_supply (regcache, regnum, NULL);
-}
-
-/* Store register REGNUM back into the inferior.  If REGNUM is -1, do
-   this for all registers (including the floating point registers).  */
-
-static void
-inf_child_store_inferior_registers (struct target_ops *ops,
-    struct regcache *regcache, int regnum)
-{
-}
+inf_child_target::~inf_child_target ()
+{}
 
-static void
-inf_child_post_attach (struct target_ops *self, int pid)
+void
+inf_child_target::post_attach (int pid)
 {
   /* This target doesn't require a meaningful "post attach" operation
      by a debugger.  */
@@ -107,12 +78,59 @@ inf_child_post_attach (struct target_ops *self, int pid)
    makes sure that registers contains all the registers from the
    program being debugged.  */
 
-static void
-inf_child_prepare_to_store (struct target_ops *self,
-    struct regcache *regcache)
+void
+inf_child_target::prepare_to_store (struct regcache *regcache)
 {
 }
 
+bool
+inf_child_target::supports_terminal_ours ()
+{
+  return true;
+}
+
+void
+inf_child_target::terminal_init ()
+{
+  child_terminal_init (this);
+}
+
+void
+inf_child_target::terminal_inferior ()
+{
+  child_terminal_inferior (this);
+}
+
+void
+inf_child_target::terminal_ours_for_output ()
+{
+  child_terminal_ours_for_output (this);
+}
+
+void
+inf_child_target::terminal_ours ()
+{
+  child_terminal_ours (this);
+}
+
+void
+inf_child_target::interrupt ()
+{
+  child_interrupt (this);
+}
+
+void
+inf_child_target::pass_ctrlc ()
+{
+  child_pass_ctrlc (this);
+}
+
+void
+inf_child_target::terminal_info (const char *args, int from_tty)
+{
+  child_terminal_info (this, args, from_tty);
+}
+
 /* True if the user did "target native".  In that case, we won't
    unpush the child target automatically when the last inferior is
    gone.  */
@@ -131,16 +149,16 @@ inf_child_open_target (struct target_ops *target, const char *arg,
     printf_filtered ("Done.  Use the \"run\" command to start a process.\n");
 }
 
-static void
-inf_child_open (const char *arg, int from_tty)
+void
+inf_child_target::open (const char *arg, int from_tty)
 {
-  inf_child_open_target (inf_child_ops, arg, from_tty);
+  inf_child_open_target (this, arg, from_tty);
 }
 
 /* Implement the to_disconnect target_ops method.  */
 
-static void
-inf_child_disconnect (struct target_ops *target, const char *args, int from_tty)
+void
+inf_child_target::disconnect (const char *args, int from_tty)
 {
   if (args != NULL)
     error (_("Argument given to \"disconnect\"."));
@@ -152,65 +170,98 @@ inf_child_disconnect (struct target_ops *target, const char *args, int from_tty)
 
 /* Implement the to_close target_ops method.  */
 
-static void
-inf_child_close (struct target_ops *target)
+void
+inf_child_target::close ()
 {
   /* In case we were forcibly closed.  */
   inf_child_explicitly_opened = 0;
 }
 
 void
-inf_child_mourn_inferior (struct target_ops *ops)
+inf_child_target::mourn_inferior ()
 {
   generic_mourn_inferior ();
-  inf_child_maybe_unpush_target (ops);
+  maybe_unpush_target ();
 }
 
 /* See inf-child.h.  */
 
 void
-inf_child_maybe_unpush_target (struct target_ops *ops)
+inf_child_target::maybe_unpush_target ()
 {
   if (!inf_child_explicitly_opened && !have_inferiors ())
-    unpush_target (ops);
+    unpush_target (this);
 }
 
-static void
-inf_child_post_startup_inferior (struct target_ops *self, ptid_t ptid)
+void
+inf_child_target::post_startup_inferior (ptid_t ptid)
 {
   /* This target doesn't require a meaningful "post startup inferior"
      operation by a debugger.  */
 }
 
-static int
-inf_child_follow_fork (struct target_ops *ops, int follow_child,
-       int detach_fork)
+int
+inf_child_target::can_run ()
 {
-  /* This target doesn't support following fork or vfork events.  */
-  return 0;
+  return 1;
 }
 
-static int
-inf_child_can_run (struct target_ops *self)
+bool
+inf_child_target::can_create_inferior ()
 {
-  return 1;
+  return true;
+}
+
+bool
+inf_child_target::can_attach ()
+{
+  return true;
 }
 
-static char *
-inf_child_pid_to_exec_file (struct target_ops *self, int pid)
+char *
+inf_child_target::pid_to_exec_file (int pid)
 {
   /* This target doesn't support translation of a process ID to the
      filename of the executable file.  */
   return NULL;
 }
 
+int
+inf_child_target::has_all_memory ()
+{
+  return default_child_has_all_memory ();
+}
+
+int
+inf_child_target::has_memory ()
+{
+  return default_child_has_memory ();
+}
+
+int
+inf_child_target::has_stack ()
+{
+  return default_child_has_stack ();
+}
+
+int
+inf_child_target::has_registers ()
+{
+  return default_child_has_registers ();
+}
+
+int
+inf_child_target::has_execution (ptid_t ptid)
+{
+  return default_child_has_execution (ptid);
+}
+
 /* Implementation of to_fileio_open.  */
 
-static int
-inf_child_fileio_open (struct target_ops *self,
-       struct inferior *inf, const char *filename,
-       int flags, int mode, int warn_if_slow,
-       int *target_errno)
+int
+inf_child_target::fileio_open (struct inferior *inf, const char *filename,
+       int flags, int mode, int warn_if_slow,
+       int *target_errno)
 {
   int nat_flags;
   mode_t nat_mode;
@@ -232,10 +283,9 @@ inf_child_fileio_open (struct target_ops *self,
 
 /* Implementation of to_fileio_pwrite.  */
 
-static int
-inf_child_fileio_pwrite (struct target_ops *self,
- int fd, const gdb_byte *write_buf, int len,
- ULONGEST offset, int *target_errno)
+int
+inf_child_target::fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
+ ULONGEST offset, int *target_errno)
 {
   int ret;
 
@@ -260,10 +310,9 @@ inf_child_fileio_pwrite (struct target_ops *self,
 
 /* Implementation of to_fileio_pread.  */
 
-static int
-inf_child_fileio_pread (struct target_ops *self,
- int fd, gdb_byte *read_buf, int len,
- ULONGEST offset, int *target_errno)
+int
+inf_child_target::fileio_pread (int fd, gdb_byte *read_buf, int len,
+ ULONGEST offset, int *target_errno)
 {
   int ret;
 
@@ -288,9 +337,8 @@ inf_child_fileio_pread (struct target_ops *self,
 
 /* Implementation of to_fileio_fstat.  */
 
-static int
-inf_child_fileio_fstat (struct target_ops *self, int fd,
- struct stat *sb, int *target_errno)
+int
+inf_child_target::fileio_fstat (int fd, struct stat *sb, int *target_errno)
 {
   int ret;
 
@@ -303,12 +351,12 @@ inf_child_fileio_fstat (struct target_ops *self, int fd,
 
 /* Implementation of to_fileio_close.  */
 
-static int
-inf_child_fileio_close (struct target_ops *self, int fd, int *target_errno)
+int
+inf_child_target::fileio_close (int fd, int *target_errno)
 {
   int ret;
 
-  ret = close (fd);
+  ret = ::close (fd);
   if (ret == -1)
     *target_errno = host_to_fileio_error (errno);
 
@@ -317,10 +365,9 @@ inf_child_fileio_close (struct target_ops *self, int fd, int *target_errno)
 
 /* Implementation of to_fileio_unlink.  */
 
-static int
-inf_child_fileio_unlink (struct target_ops *self,
- struct inferior *inf, const char *filename,
- int *target_errno)
+int
+inf_child_target::fileio_unlink (struct inferior *inf, const char *filename,
+ int *target_errno)
 {
   int ret;
 
@@ -333,10 +380,9 @@ inf_child_fileio_unlink (struct target_ops *self,
 
 /* Implementation of to_fileio_readlink.  */
 
-static gdb::optional<std::string>
-inf_child_fileio_readlink (struct target_ops *self,
-   struct inferior *inf, const char *filename,
-   int *target_errno)
+gdb::optional<std::string>
+inf_child_target::fileio_readlink (struct inferior *inf, const char *filename,
+   int *target_errno)
 {
   /* We support readlink only on systems that also provide a compile-time
      maximum path length (PATH_MAX), at least for now.  */
@@ -358,86 +404,25 @@ inf_child_fileio_readlink (struct target_ops *self,
 #endif
 }
 
-static int
-inf_child_use_agent (struct target_ops *self, int use)
+int
+inf_child_target::use_agent (int use)
 {
   if (agent_loaded_p ())
     {
-      use_agent = use;
+      ::use_agent = use;
       return 1;
     }
   else
     return 0;
 }
 
-static int
-inf_child_can_use_agent (struct target_ops *self)
+int
+inf_child_target::can_use_agent ()
 {
   return agent_loaded_p ();
 }
 
-/* Default implementation of the to_can_async_p and
-   to_supports_non_stop methods.  */
-
-static int
-return_zero (struct target_ops *ignore)
-{
-  return 0;
-}
-
-struct target_ops *
-inf_child_target (void)
-{
-  struct target_ops *t = XCNEW (struct target_ops);
-
-  t->to_shortname = "native";
-  t->to_longname = "Native process";
-  t->to_doc = "Native process (started by the \"run\" command).";
-  t->to_open = inf_child_open;
-  t->to_close = inf_child_close;
-  t->to_disconnect = inf_child_disconnect;
-  t->to_post_attach = inf_child_post_attach;
-  t->to_fetch_registers = inf_child_fetch_inferior_registers;
-  t->to_store_registers = inf_child_store_inferior_registers;
-  t->to_prepare_to_store = inf_child_prepare_to_store;
-  t->to_insert_breakpoint = memory_insert_breakpoint;
-  t->to_remove_breakpoint = memory_remove_breakpoint;
-  t->to_terminal_init = child_terminal_init;
-  t->to_terminal_inferior = child_terminal_inferior;
-  t->to_terminal_save_inferior = child_terminal_save_inferior;
-  t->to_terminal_ours_for_output = child_terminal_ours_for_output;
-  t->to_terminal_ours = child_terminal_ours;
-  t->to_terminal_info = child_terminal_info;
-  t->to_pass_ctrlc = child_pass_ctrlc;
-  t->to_interrupt = child_interrupt;
-  t->to_post_startup_inferior = inf_child_post_startup_inferior;
-  t->to_follow_fork = inf_child_follow_fork;
-  t->to_can_run = inf_child_can_run;
-  /* We must default these because they must be implemented by any
-     target that can run.  */
-  t->to_can_async_p = return_zero;
-  t->to_supports_non_stop = return_zero;
-  t->to_pid_to_exec_file = inf_child_pid_to_exec_file;
-  t->to_stratum = process_stratum;
-  t->to_has_all_memory = default_child_has_all_memory;
-  t->to_has_memory = default_child_has_memory;
-  t->to_has_stack = default_child_has_stack;
-  t->to_has_registers = default_child_has_registers;
-  t->to_has_execution = default_child_has_execution;
-  t->to_fileio_open = inf_child_fileio_open;
-  t->to_fileio_pwrite = inf_child_fileio_pwrite;
-  t->to_fileio_pread = inf_child_fileio_pread;
-  t->to_fileio_fstat = inf_child_fileio_fstat;
-  t->to_fileio_close = inf_child_fileio_close;
-  t->to_fileio_unlink = inf_child_fileio_unlink;
-  t->to_fileio_readlink = inf_child_fileio_readlink;
-  t->to_magic = OPS_MAGIC;
-  t->to_use_agent = inf_child_use_agent;
-  t->to_can_use_agent = inf_child_can_use_agent;
-
-  /* Store a pointer so we can push the most-derived target from
-     inf_child_open.  */
-  inf_child_ops = t;
-
-  return t;
+inf_child_target::inf_child_target ()
+{
+  this->to_stratum = process_stratum;
 }
diff --git a/gdb/inf-child.h b/gdb/inf-child.h
index 5fb966d506..1b9c8c53ae 100644
--- a/gdb/inf-child.h
+++ b/gdb/inf-child.h
@@ -20,33 +20,107 @@
 #ifndef INF_CHILD_H
 #define INF_CHILD_H
 
-/* Create a prototype child target.  The client can override it with
-   local methods.  */
+#include "target.h"
 
-extern struct target_ops *inf_child_target (void);
+/* A prototype child target.  The client can override it with local
+   methods.  */
 
-/* Functions for helping to write a native target.  */
+class inf_child_target
+  : public memory_breakpoint_target<target_ops>
+{
+public:
+  inf_child_target ();
+  ~inf_child_target () override = 0;
 
-/* This is for native targets which use a unix/POSIX-style waitstatus.  */
-extern void store_waitstatus (struct target_waitstatus *, int);
+  const char *shortname () override
+  { return "native"; }
+
+  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;
+
+  void fetch_registers (struct regcache *, int) override = 0;
+  void store_registers (struct regcache *, int) override = 0;
+
+  void prepare_to_store (struct regcache *) override;
+
+  bool supports_terminal_ours () override;
+  void terminal_init () override;
+  void terminal_inferior () override;
+  void terminal_ours_for_output () override;
+  void terminal_ours () override;
+  void terminal_info (const char *, int) override;
+
+  void interrupt () override;
+  void pass_ctrlc () override;
 
-/* This is to be called by the native target's open routine to push
-   the target, in case it need to override to_open.  */
+  void post_startup_inferior (ptid_t) override;
 
-extern void inf_child_open_target (struct target_ops *target,
-   const char *arg, int from_tty);
+  void mourn_inferior () override;
 
-/* To be called by the native target's to_mourn_inferior routine.  */
+  int can_run () override;
 
-extern void inf_child_mourn_inferior (struct target_ops *ops);
+  bool can_create_inferior () override;
+  void create_inferior (const char *, const std::string &,
+ char **, int) = 0;
 
-/* Unpush the target if it wasn't explicitly open with "target native"
-   and there are no live inferiors left.  Note: if calling this as a
-   result of a mourn or detach, the current inferior shall already
-   have its PID cleared, so it isn't counted as live.  That's usually
-   done by calling either generic_mourn_inferior or
-   detach_inferior.  */
+  bool can_attach () override;
+  void attach (const char *, int) override = 0;
 
-extern void inf_child_maybe_unpush_target (struct target_ops *ops);
+  void post_attach (int);
+
+  /* We must default these because they must be implemented by any
+     target that can run.  */
+  int can_async_p ()  override { return 0; }
+  int supports_non_stop ()  override { return 0; }
+
+  char *pid_to_exec_file (int pid) override;
+
+  int has_all_memory () override;
+  int has_memory () override;
+  int has_stack () override;
+  int has_registers () override;
+  int has_execution (ptid_t) override;
+
+  int fileio_open (struct inferior *inf, const char *filename,
+   int flags, int mode, int warn_if_slow,
+   int *target_errno) override;
+  int fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
+     ULONGEST offset, int *target_errno) override;
+  int fileio_pread (int fd, gdb_byte *read_buf, int len,
+    ULONGEST offset, int *target_errno) override;
+  int fileio_fstat (int fd, struct stat *sb, int *target_errno) override;
+  int fileio_close (int fd, int *target_errno) override;
+  int fileio_unlink (struct inferior *inf,
+     const char *filename,
+     int *target_errno) override;
+  gdb::optional<std::string> fileio_readlink (struct inferior *inf,
+      const char *filename,
+      int *target_errno) override;
+  int use_agent (int use) override;
+
+  int can_use_agent () override;
+
+protected:
+  /* Unpush the target if it wasn't explicitly open with "target native"
+     and there are no live inferiors left.  Note: if calling this as a
+     result of a mourn or detach, the current inferior shall already
+     have its PID cleared, so it isn't counted as live.  That's usually
+     done by calling either generic_mourn_inferior or
+     detach_inferior.  */
+  void maybe_unpush_target ();
+};
+
+/* Functions for helping to write a native target.  */
+
+/* This is for native targets which use a unix/POSIX-style waitstatus.  */
+extern void store_waitstatus (struct target_waitstatus *, int);
 
 #endif
diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
index 7c4d597be9..8f5a378353 100644
--- a/gdb/inf-ptrace.c
+++ b/gdb/inf-ptrace.c
@@ -52,14 +52,16 @@ typedef std::unique_ptr<struct target_ops, target_unpusher> target_unpush_up;
 
 
 
+inf_ptrace_target::~inf_ptrace_target ()
+{}
+
 #ifdef PT_GET_PROCESS_STATE
 
 /* Target hook for follow_fork.  On entry and at return inferior_ptid is
    the ptid of the followed inferior.  */
 
-static int
-inf_ptrace_follow_fork (struct target_ops *ops, int follow_child,
- int detach_fork)
+int
+inf_ptrace_target::follow_fork (int follow_child, int detach_fork)
 {
   if (!follow_child)
     {
@@ -76,14 +78,14 @@ inf_ptrace_follow_fork (struct target_ops *ops, int follow_child,
   return 0;
 }
 
-static int
-inf_ptrace_insert_fork_catchpoint (struct target_ops *self, int pid)
+int
+inf_ptrace_target::insert_fork_catchpoint (int pid)
 {
   return 0;
 }
 
-static int
-inf_ptrace_remove_fork_catchpoint (struct target_ops *self, int pid)
+int
+inf_ptrace_target::remove_fork_catchpoint (int pid)
 {
   return 0;
 }
@@ -106,24 +108,24 @@ inf_ptrace_me (void)
    ENV is the environment vector to pass.  If FROM_TTY is non-zero, be
    chatty about it.  */
 
-static void
-inf_ptrace_create_inferior (struct target_ops *ops,
-    const char *exec_file, const std::string &allargs,
-    char **env, int from_tty)
+void
+inf_ptrace_target::create_inferior (const char *exec_file,
+    const std::string &allargs,
+    char **env, int from_tty)
 {
   pid_t pid;
   ptid_t ptid;
 
   /* Do not change either targets above or the same target if already present.
      The reason is the target stack is shared across multiple inferiors.  */
-  int ops_already_pushed = target_is_pushed (ops);
+  int ops_already_pushed = target_is_pushed (this);
 
   target_unpush_up unpusher;
   if (! ops_already_pushed)
     {
       /* Clear possible core file with its process_stratum.  */
-      push_target (ops);
-      unpusher.reset (ops);
+      push_target (this);
+      unpusher.reset (this);
     }
 
   pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL,
@@ -146,8 +148,8 @@ inf_ptrace_create_inferior (struct target_ops *ops,
 
 #ifdef PT_GET_PROCESS_STATE
 
-static void
-inf_ptrace_post_startup_inferior (struct target_ops *self, ptid_t pid)
+void
+inf_ptrace_target::post_startup_inferior (ptid_t pid)
 {
   ptrace_event_t pe;
 
@@ -163,8 +165,8 @@ inf_ptrace_post_startup_inferior (struct target_ops *self, ptid_t pid)
 
 /* Clean up a rotting corpse of an inferior after it died.  */
 
-static void
-inf_ptrace_mourn_inferior (struct target_ops *ops)
+void
+inf_ptrace_target::mourn_inferior ()
 {
   int status;
 
@@ -174,14 +176,14 @@ inf_ptrace_mourn_inferior (struct target_ops *ops)
      only report its exit status to its original parent.  */
   waitpid (ptid_get_pid (inferior_ptid), &status, 0);
 
-  inf_child_mourn_inferior (ops);
+  inf_child_target::mourn_inferior ();
 }
 
 /* Attach to the process specified by ARGS.  If FROM_TTY is non-zero,
    be chatty about it.  */
 
-static void
-inf_ptrace_attach (struct target_ops *ops, const char *args, int from_tty)
+void
+inf_ptrace_target::attach (const char *args, int from_tty)
 {
   char *exec_file;
   pid_t pid;
@@ -189,7 +191,7 @@ inf_ptrace_attach (struct target_ops *ops, const char *args, int from_tty)
 
   /* Do not change either targets above or the same target if already present.
      The reason is the target stack is shared across multiple inferiors.  */
-  int ops_already_pushed = target_is_pushed (ops);
+  int ops_already_pushed = target_is_pushed (this);
 
   pid = parse_pid_to_attach (args);
 
@@ -201,8 +203,8 @@ inf_ptrace_attach (struct target_ops *ops, const char *args, int from_tty)
     {
       /* target_pid_to_str already uses the target.  Also clear possible core
  file with its process_stratum.  */
-      push_target (ops);
-      unpusher.reset (ops);
+      push_target (this);
+      unpusher.reset (this);
     }
 
   if (from_tty)
@@ -242,8 +244,8 @@ inf_ptrace_attach (struct target_ops *ops, const char *args, int from_tty)
 
 #ifdef PT_GET_PROCESS_STATE
 
-static void
-inf_ptrace_post_attach (struct target_ops *self, int pid)
+void
+inf_ptrace_target::post_attach (int pid)
 {
   ptrace_event_t pe;
 
@@ -259,8 +261,8 @@ inf_ptrace_post_attach (struct target_ops *self, int pid)
 
 /* Detach from the inferior.  If FROM_TTY is non-zero, be chatty about it.  */
 
-static void
-inf_ptrace_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+inf_ptrace_target::detach (inferior *inf, int from_tty)
 {
   pid_t pid = ptid_get_pid (inferior_ptid);
 
@@ -279,24 +281,24 @@ inf_ptrace_detach (struct target_ops *ops, inferior *inf, int from_tty)
   error (_("This system does not support detaching from a process"));
 #endif
 
-  inf_ptrace_detach_success (ops, inf);
+  detach_success (inf);
 }
 
 /* See inf-ptrace.h.  */
 
 void
-inf_ptrace_detach_success (struct target_ops *ops, inferior *inf)
+inf_ptrace_target::detach_success (inferior *inf)
 {
   inferior_ptid = null_ptid;
   detach_inferior (inf);
 
-  inf_child_maybe_unpush_target (ops);
+  maybe_unpush_target ();
 }
 
 /* Kill the inferior.  */
 
-static void
-inf_ptrace_kill (struct target_ops *ops)
+void
+inf_ptrace_target::kill ()
 {
   pid_t pid = ptid_get_pid (inferior_ptid);
   int status;
@@ -330,9 +332,8 @@ get_ptrace_pid (ptid_t ptid)
    STEP is nonzero, single-step it.  If SIGNAL is nonzero, give it
    that signal.  */
 
-static void
-inf_ptrace_resume (struct target_ops *ops,
-   ptid_t ptid, int step, enum gdb_signal signal)
+void
+inf_ptrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
 {
   pid_t pid;
   int request;
@@ -372,9 +373,9 @@ inf_ptrace_resume (struct target_ops *ops,
    process ID of the child, or MINUS_ONE_PTID in case of error; store
    the status in *OURSTATUS.  */
 
-static ptid_t
-inf_ptrace_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus, int options)
+ptid_t
+inf_ptrace_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
+ int options)
 {
   pid_t pid;
   int status, save_errno;
@@ -520,11 +521,11 @@ inf_ptrace_peek_poke (pid_t pid, gdb_byte *readbuf,
 
 /* Implement the to_xfer_partial target_ops method.  */
 
-static enum target_xfer_status
-inf_ptrace_xfer_partial (struct target_ops *ops, enum target_object object,
- const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf,
- ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+inf_ptrace_target::xfer_partial (enum target_object object,
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
 {
   pid_t pid = get_ptrace_pid (inferior_ptid);
 
@@ -606,17 +607,17 @@ inf_ptrace_xfer_partial (struct target_ops *ops, enum target_object object,
 
 /* Return non-zero if the thread specified by PTID is alive.  */
 
-static int
-inf_ptrace_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+inf_ptrace_target::thread_alive (ptid_t ptid)
 {
   /* ??? Is kill the right way to do this?  */
-  return (kill (ptid_get_pid (ptid), 0) != -1);
+  return (::kill (ptid_get_pid (ptid), 0) != -1);
 }
 
 /* Print status information about what we're accessing.  */
 
-static void
-inf_ptrace_files_info (struct target_ops *ignore)
+void
+inf_ptrace_target::files_info ()
 {
   struct inferior *inf = current_inferior ();
 
@@ -625,8 +626,8 @@ inf_ptrace_files_info (struct target_ops *ignore)
    target_pid_to_str (inferior_ptid));
 }
 
-static const char *
-inf_ptrace_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+inf_ptrace_target::pid_to_str (ptid_t ptid)
 {
   return normal_pid_to_str (ptid);
 }
@@ -638,9 +639,9 @@ inf_ptrace_pid_to_str (struct target_ops *ops, ptid_t ptid)
    Return -1 if there is insufficient buffer for a whole entry.
    Return 1 if an entry was read into *TYPEP and *VALP.  */
 
-static int
-inf_ptrace_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
-       gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+int
+inf_ptrace_target::auxv_parse (gdb_byte **readptr, gdb_byte *endptr,
+       CORE_ADDR *typep, CORE_ADDR *valp)
 {
   struct type *int_type = builtin_type (target_gdbarch ())->builtin_int;
   struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
@@ -665,37 +666,4 @@ inf_ptrace_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
 }
 
 #endif
-
-/* Create a prototype ptrace target.  The client can override it with
-   local methods.  */
-
-struct target_ops *
-inf_ptrace_target (void)
-{
-  struct target_ops *t = inf_child_target ();
-
-  t->to_attach = inf_ptrace_attach;
-  t->to_detach = inf_ptrace_detach;
-  t->to_resume = inf_ptrace_resume;
-  t->to_wait = inf_ptrace_wait;
-  t->to_files_info = inf_ptrace_files_info;
-  t->to_kill = inf_ptrace_kill;
-  t->to_create_inferior = inf_ptrace_create_inferior;
-#ifdef PT_GET_PROCESS_STATE
-  t->to_follow_fork = inf_ptrace_follow_fork;
-  t->to_insert_fork_catchpoint = inf_ptrace_insert_fork_catchpoint;
-  t->to_remove_fork_catchpoint = inf_ptrace_remove_fork_catchpoint;
-  t->to_post_startup_inferior = inf_ptrace_post_startup_inferior;
-  t->to_post_attach = inf_ptrace_post_attach;
-#endif
-  t->to_mourn_inferior = inf_ptrace_mourn_inferior;
-  t->to_thread_alive = inf_ptrace_thread_alive;
-  t->to_pid_to_str = inf_ptrace_pid_to_str;
-  t->to_xfer_partial = inf_ptrace_xfer_partial;
-#if defined (PT_IO) && defined (PIOD_READ_AUXV)
-  t->to_auxv_parse = inf_ptrace_auxv_parse;
-#endif
-
-  return t;
-}
 
diff --git a/gdb/inf-ptrace.h b/gdb/inf-ptrace.h
index d10f64ae56..bd9b609ab4 100644
--- a/gdb/inf-ptrace.h
+++ b/gdb/inf-ptrace.h
@@ -20,26 +20,67 @@
 #ifndef INF_PTRACE_H
 #define INF_PTRACE_H
 
-/* Create a prototype ptrace target.  The client can override it with
-   local methods.  */
+#include "inf-child.h"
 
-extern struct target_ops *inf_ptrace_target (void);
+/* An abstract prototype ptrace target.  The client can override it
+   with local methods.  */
 
-/* Create a "traditional" ptrace target.  REGISTER_U_OFFSET should be
-   a function returning the offset within the user area where a
-   particular register is stored.  */
+struct inf_ptrace_target : public inf_child_target
+{
+  ~inf_ptrace_target () override = 0;
 
-extern struct target_ops *
-  inf_ptrace_trad_target (CORE_ADDR (*register_u_offset)
- (struct gdbarch *, int, int));
+  void attach (const char *, int) override;
+
+  void detach (inferior *inf, int) override;
+
+  void resume (ptid_t, int, enum gdb_signal) override;
+
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+
+  void files_info () override;
+
+  void kill () override;
+
+  void create_inferior (const char *, const std::string &,
+ char **, int) override;
+#ifdef PT_GET_PROCESS_STATE
+  int follow_fork (int, int) override;
+
+  int insert_fork_catchpoint (int) override;
+
+  int remove_fork_catchpoint (int) override;
+
+  void post_startup_inferior (ptid_t) override;
+
+  void post_attach (int) override;
+#endif
+
+  void mourn_inferior () override;
+
+  int thread_alive (ptid_t ptid) override;
+
+  const char *pid_to_str (ptid_t) override;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+#if defined (PT_IO) && defined (PIOD_READ_AUXV)
+  int auxv_parse (gdb_byte **readptr,
+  gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp) override;
+#endif
+
+protected:
+  /* Cleanup the inferior after a successful ptrace detach.  */
+  void detach_success (inferior *inf);
+};
 
 /* Return which PID to pass to ptrace in order to observe/control the
    tracee identified by PTID.  */
 
 extern pid_t get_ptrace_pid (ptid_t);
 
-
-/* Cleanup the inferior after a successful ptrace detach.  */
-extern void inf_ptrace_detach_success (struct target_ops *ops, inferior *inf);
-
 #endif
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index c23f83e057..bfc2e46ed6 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -186,14 +186,11 @@ leader.  */
 #define O_LARGEFILE 0
 #endif
 
+struct linux_nat_target *linux_target;
+
 /* Does the current host support PTRACE_GETREGSET?  */
 enum tribool have_ptrace_getregset = TRIBOOL_UNKNOWN;
 
-/* The single-threaded native GNU/Linux target_ops.  We save a pointer for
-   the use of the multi-threaded target.  */
-static struct target_ops *linux_ops;
-static struct target_ops linux_ops_saved;
-
 /* The method to call, if any, when a new thread is attached.  */
 static void (*linux_nat_new_thread) (struct lwp_info *);
 
@@ -217,10 +214,6 @@ static int (*linux_nat_siginfo_fixup) (siginfo_t *,
        gdb_byte *,
        int);
 
-/* The saved to_xfer_partial method, inherited from inf-ptrace.c.
-   Called by our to_xfer_partial.  */
-static target_xfer_partial_ftype *super_xfer_partial;
-
 /* The saved to_close method, inherited from inf-ptrace.c.
    Called by our to_close.  */
 static void (*super_close) (struct target_ops *);
@@ -431,14 +424,17 @@ linux_init_ptrace (pid_t pid, int attached)
   linux_ptrace_init_warnings ();
 }
 
-static void
-linux_child_post_attach (struct target_ops *self, int pid)
+linux_nat_target::~linux_nat_target ()
+{}
+
+void
+linux_nat_target::post_attach (int pid)
 {
   linux_init_ptrace (pid, 1);
 }
 
-static void
-linux_child_post_startup_inferior (struct target_ops *self, ptid_t ptid)
+void
+linux_nat_target::post_startup_inferior (ptid_t ptid)
 {
   linux_init_ptrace (ptid_get_pid (ptid), 0);
 }
@@ -472,9 +468,8 @@ delete_lwp_cleanup (void *lp_voidp)
    ptid of the followed inferior.  At return, inferior_ptid will be
    unchanged.  */
 
-static int
-linux_child_follow_fork (struct target_ops *ops, int follow_child,
- int detach_fork)
+int
+linux_nat_target::follow_fork (int follow_child, int detach_fork)
 {
   if (!follow_child)
     {
@@ -638,46 +633,45 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child,
 }
 
 
-static int
-linux_child_insert_fork_catchpoint (struct target_ops *self, int pid)
+int
+linux_nat_target::insert_fork_catchpoint (int pid)
 {
   return !linux_supports_tracefork ();
 }
 
-static int
-linux_child_remove_fork_catchpoint (struct target_ops *self, int pid)
+int
+linux_nat_target::remove_fork_catchpoint (int pid)
 {
   return 0;
 }
 
-static int
-linux_child_insert_vfork_catchpoint (struct target_ops *self, int pid)
+int
+linux_nat_target::insert_vfork_catchpoint (int pid)
 {
   return !linux_supports_tracefork ();
 }
 
-static int
-linux_child_remove_vfork_catchpoint (struct target_ops *self, int pid)
+int
+linux_nat_target::remove_vfork_catchpoint (int pid)
 {
   return 0;
 }
 
-static int
-linux_child_insert_exec_catchpoint (struct target_ops *self, int pid)
+int
+linux_nat_target::insert_exec_catchpoint (int pid)
 {
   return !linux_supports_tracefork ();
 }
 
-static int
-linux_child_remove_exec_catchpoint (struct target_ops *self, int pid)
+int
+linux_nat_target::remove_exec_catchpoint (int pid)
 {
   return 0;
 }
 
-static int
-linux_child_set_syscall_catchpoint (struct target_ops *self,
-    int pid, bool needed, int any_count,
-    gdb::array_view<const int> syscall_counts)
+int
+linux_nat_target::set_syscall_catchpoint (int pid, bool needed, int any_count,
+  gdb::array_view<const int> syscall_counts)
 {
   if (!linux_supports_tracesysgood ())
     return 1;
@@ -811,9 +805,8 @@ restore_child_signals_mask (sigset_t *prev_mask)
 static sigset_t pass_mask;
 
 /* Update signals to pass to the inferior.  */
-static void
-linux_nat_pass_signals (struct target_ops *self,
- int numsigs, unsigned char *pass_signals)
+void
+linux_nat_target::pass_signals (int numsigs, unsigned char *pass_signals)
 {
   int signo;
 
@@ -831,7 +824,6 @@ linux_nat_pass_signals (struct target_ops *self,
 
 /* Prototypes for local functions.  */
 static int stop_wait_callback (struct lwp_info *lp, void *data);
-static char *linux_child_pid_to_exec_file (struct target_ops *self, int pid);
 static int resume_stopped_resumed_lwps (struct lwp_info *lp, void *data);
 static int check_ptrace_stopped_lwp_gone (struct lwp_info *lp);
 
@@ -1113,10 +1105,10 @@ linux_nat_post_attach_wait (ptid_t ptid, int *signalled)
   return status;
 }
 
-static void
-linux_nat_create_inferior (struct target_ops *ops,
-   const char *exec_file, const std::string &allargs,
-   char **env, int from_tty)
+void
+linux_nat_target::create_inferior (const char *exec_file,
+   const std::string &allargs,
+   char **env, int from_tty)
 {
   maybe_disable_address_space_randomization restore_personality
     (disable_randomization);
@@ -1125,9 +1117,9 @@ linux_nat_create_inferior (struct target_ops *ops,
      we have to mask the async mode.  */
 
   /* Make sure we report all signals during startup.  */
-  linux_nat_pass_signals (ops, 0, NULL);
+  pass_signals (0, NULL);
 
-  linux_ops->to_create_inferior (ops, exec_file, allargs, env, from_tty);
+  inf_ptrace_target::create_inferior (exec_file, allargs, env, from_tty);
 }
 
 /* Callback for linux_proc_attach_tgid_threads.  Attach to PTID if not
@@ -1207,19 +1199,19 @@ attach_proc_task_lwp_callback (ptid_t ptid)
   return 0;
 }
 
-static void
-linux_nat_attach (struct target_ops *ops, const char *args, int from_tty)
+void
+linux_nat_target::attach (const char *args, int from_tty)
 {
   struct lwp_info *lp;
   int status;
   ptid_t ptid;
 
   /* Make sure we report all signals during attach.  */
-  linux_nat_pass_signals (ops, 0, NULL);
+  pass_signals (0, NULL);
 
   TRY
     {
-      linux_ops->to_attach (ops, args, from_tty);
+      inf_ptrace_target::attach (args, from_tty);
     }
   CATCH (ex, RETURN_MASK_ERROR)
     {
@@ -1496,8 +1488,8 @@ detach_callback (struct lwp_info *lp, void *data)
   return 0;
 }
 
-static void
-linux_nat_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+linux_nat_target::detach (inferior *inf, int from_tty)
 {
   struct lwp_info *main_lwp;
   int pid = inf->pid;
@@ -1536,7 +1528,7 @@ linux_nat_detach (struct target_ops *ops, inferior *inf, int from_tty)
 
       detach_one_lwp (main_lwp, &signo);
 
-      inf_ptrace_detach_success (ops, inf);
+      detach_success (inf);
     }
 }
 
@@ -1563,7 +1555,7 @@ linux_resume_one_lwp_throw (struct lwp_info *lp, int step,
 
   if (linux_nat_prepare_to_resume != NULL)
     linux_nat_prepare_to_resume (lp);
-  linux_ops->to_resume (linux_ops, lp->ptid, step, signo);
+  linux_target->low_resume (lp->ptid, step, signo);
 
   /* Successfully resumed.  Clear state that no longer makes sense,
      and mark the LWP as running.  Must not do this before resuming
@@ -1716,9 +1708,8 @@ resume_set_callback (struct lwp_info *lp, void *data)
   return 0;
 }
 
-static void
-linux_nat_resume (struct target_ops *ops,
-  ptid_t ptid, int step, enum gdb_signal signo)
+void
+linux_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
 {
   struct lwp_info *lp;
   int resume_many;
@@ -2117,7 +2108,7 @@ linux_handle_extended_wait (struct lwp_info *lp, int status)
 
       ourstatus->kind = TARGET_WAITKIND_EXECD;
       ourstatus->value.execd_pathname
- = xstrdup (linux_child_pid_to_exec_file (NULL, pid));
+ = xstrdup (linux_proc_pid_to_exec_file (pid));
 
       /* The thread that execed must have been resumed, but, when a
  thread execs, it changes its tid to the tgid, and the old
@@ -2468,22 +2459,14 @@ maybe_clear_ignore_sigint (struct lwp_info *lp)
 static int
 check_stopped_by_watchpoint (struct lwp_info *lp)
 {
-  if (linux_ops->to_stopped_by_watchpoint == NULL)
-    return 0;
-
   scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
   inferior_ptid = lp->ptid;
 
-  if (linux_ops->to_stopped_by_watchpoint (linux_ops))
+  if (linux_target->low_stopped_by_watchpoint ())
     {
       lp->stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
-
-      if (linux_ops->to_stopped_data_address != NULL)
- lp->stopped_data_address_p =
-  linux_ops->to_stopped_data_address (&current_target,
-      &lp->stopped_data_address);
-      else
- lp->stopped_data_address_p = 0;
+      lp->stopped_data_address_p
+ = linux_target->low_stopped_data_address (&lp->stopped_data_address);
     }
 
   return lp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
@@ -2491,8 +2474,8 @@ check_stopped_by_watchpoint (struct lwp_info *lp)
 
 /* Returns true if the LWP had stopped for a watchpoint.  */
 
-static int
-linux_nat_stopped_by_watchpoint (struct target_ops *ops)
+int
+linux_nat_target::stopped_by_watchpoint ()
 {
   struct lwp_info *lp = find_lwp_pid (inferior_ptid);
 
@@ -2501,8 +2484,8 @@ linux_nat_stopped_by_watchpoint (struct target_ops *ops)
   return lp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
 }
 
-static int
-linux_nat_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
+int
+linux_nat_target::stopped_data_address (CORE_ADDR *addr_p)
 {
   struct lwp_info *lp = find_lwp_pid (inferior_ptid);
 
@@ -2852,8 +2835,8 @@ save_stop_reason (struct lwp_info *lp)
 
 /* Returns true if the LWP had stopped for a software breakpoint.  */
 
-static int
-linux_nat_stopped_by_sw_breakpoint (struct target_ops *ops)
+int
+linux_nat_target::stopped_by_sw_breakpoint ()
 {
   struct lwp_info *lp = find_lwp_pid (inferior_ptid);
 
@@ -2864,8 +2847,8 @@ linux_nat_stopped_by_sw_breakpoint (struct target_ops *ops)
 
 /* Implement the supports_stopped_by_sw_breakpoint method.  */
 
-static int
-linux_nat_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
+int
+linux_nat_target::supports_stopped_by_sw_breakpoint ()
 {
   return USE_SIGTRAP_SIGINFO;
 }
@@ -2873,8 +2856,8 @@ linux_nat_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
 /* Returns true if the LWP had stopped for a hardware
    breakpoint/watchpoint.  */
 
-static int
-linux_nat_stopped_by_hw_breakpoint (struct target_ops *ops)
+int
+linux_nat_target::stopped_by_hw_breakpoint ()
 {
   struct lwp_info *lp = find_lwp_pid (inferior_ptid);
 
@@ -2885,8 +2868,8 @@ linux_nat_stopped_by_hw_breakpoint (struct target_ops *ops)
 
 /* Implement the supports_stopped_by_hw_breakpoint method.  */
 
-static int
-linux_nat_supports_stopped_by_hw_breakpoint (struct target_ops *ops)
+int
+linux_nat_target::supports_stopped_by_hw_breakpoint ()
 {
   return USE_SIGTRAP_SIGINFO;
 }
@@ -3297,8 +3280,7 @@ filter_exit_event (struct lwp_info *event_child,
 }
 
 static ptid_t
-linux_nat_wait_1 (struct target_ops *ops,
-  ptid_t ptid, struct target_waitstatus *ourstatus,
+linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
   int target_options)
 {
   sigset_t prev_mask;
@@ -3600,10 +3582,9 @@ resume_stopped_resumed_lwps (struct lwp_info *lp, void *data)
   return 0;
 }
 
-static ptid_t
-linux_nat_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus,
- int target_options)
+ptid_t
+linux_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
+ int target_options)
 {
   ptid_t event_ptid;
 
@@ -3633,7 +3614,7 @@ linux_nat_wait (struct target_ops *ops,
   if (target_is_non_stop_p ())
     iterate_over_lwps (minus_one_ptid, resume_stopped_resumed_lwps, &ptid);
 
-  event_ptid = linux_nat_wait_1 (ops, ptid, ourstatus, target_options);
+  event_ptid = linux_nat_wait_1 (ptid, ourstatus, target_options);
 
   /* If we requested any event, and something came out, assume there
      may be more.  If we requested a specific lwp or process, also
@@ -3759,8 +3740,8 @@ kill_unfollowed_fork_children (struct inferior *inf)
       }
 }
 
-static void
-linux_nat_kill (struct target_ops *ops)
+void
+linux_nat_target::kill ()
 {
   /* If we're stopped while forking and we haven't followed yet,
      kill the other task.  We need to do this first because the
@@ -3790,8 +3771,8 @@ linux_nat_kill (struct target_ops *ops)
   target_mourn_inferior (inferior_ptid);
 }
 
-static void
-linux_nat_mourn_inferior (struct target_ops *ops)
+void
+linux_nat_target::mourn_inferior ()
 {
   int pid = ptid_get_pid (inferior_ptid);
 
@@ -3799,7 +3780,7 @@ linux_nat_mourn_inferior (struct target_ops *ops)
 
   if (! forks_exist_p ())
     /* Normal case, no other forks available.  */
-    linux_ops->to_mourn_inferior (ops);
+    inf_ptrace_target::mourn_inferior ();
   else
     /* Multi-fork case.  The current inferior_ptid has exited, but
        there are other viable forks to debug.  Delete the exiting
@@ -3833,7 +3814,7 @@ siginfo_fixup (siginfo_t *siginfo, gdb_byte *inf_siginfo, int direction)
 }
 
 static enum target_xfer_status
-linux_xfer_siginfo (struct target_ops *ops, enum target_object object,
+linux_xfer_siginfo (enum target_object object,
                     const char *annex, gdb_byte *readbuf,
     const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
     ULONGEST *xfered_len)
@@ -3888,15 +3869,33 @@ linux_xfer_siginfo (struct target_ops *ops, enum target_object object,
 }
 
 static enum target_xfer_status
-linux_nat_xfer_partial (struct target_ops *ops, enum target_object object,
- const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf,
- ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
+linux_nat_xfer_osdata (enum target_object object,
+       const char *annex, gdb_byte *readbuf,
+       const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+       ULONGEST *xfered_len);
+
+static enum target_xfer_status
+linux_proc_xfer_spu (enum target_object object,
+     const char *annex, gdb_byte *readbuf,
+     const gdb_byte *writebuf,
+     ULONGEST offset, ULONGEST len, ULONGEST *xfered_len);
+
+static enum target_xfer_status
+linux_proc_xfer_partial (enum target_object object,
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, LONGEST len, ULONGEST *xfered_len);
+
+enum target_xfer_status
+linux_nat_target::xfer_partial (enum target_object object,
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
 {
   enum target_xfer_status xfer;
 
   if (object == TARGET_OBJECT_SIGNAL_INFO)
-    return linux_xfer_siginfo (ops, object, annex, readbuf, writebuf,
+    return linux_xfer_siginfo (object, annex, readbuf, writebuf,
        offset, len, xfered_len);
 
   /* The target is connected but no live inferior is selected.  Pass
@@ -3905,14 +3904,44 @@ linux_nat_xfer_partial (struct target_ops *ops, enum target_object object,
   if (object == TARGET_OBJECT_MEMORY && ptid_equal (inferior_ptid, null_ptid))
     return TARGET_XFER_EOF;
 
-  xfer = linux_ops->to_xfer_partial (ops, object, annex, readbuf, writebuf,
-     offset, len, xfered_len);
+  if (object == TARGET_OBJECT_AUXV)
+    return memory_xfer_auxv (this, object, annex, readbuf, writebuf,
+     offset, len, xfered_len);
+
+  if (object == TARGET_OBJECT_OSDATA)
+    return linux_nat_xfer_osdata (object, annex, readbuf, writebuf,
+  offset, len, xfered_len);
 
-  return xfer;
+  if (object == TARGET_OBJECT_SPU)
+    return linux_proc_xfer_spu (object, annex, readbuf, writebuf,
+ offset, len, xfered_len);
+
+  /* GDB calculates all addresses in the largest possible address
+     width.
+     The address width must be masked before its final use - either by
+     linux_proc_xfer_partial or inf_ptrace_target::xfer_partial.
+
+     Compare ADDR_BIT first to avoid a compiler warning on shift overflow.  */
+
+  if (object == TARGET_OBJECT_MEMORY)
+    {
+      int addr_bit = gdbarch_addr_bit (target_gdbarch ());
+
+      if (addr_bit < (sizeof (ULONGEST) * HOST_CHAR_BIT))
+ offset &= ((ULONGEST) 1 << addr_bit) - 1;
+    }
+
+  xfer = linux_proc_xfer_partial (object, annex, readbuf, writebuf,
+  offset, len, xfered_len);
+  if (xfer != TARGET_XFER_EOF)
+    return xfer;
+
+  return inf_ptrace_target::xfer_partial (object, annex, readbuf, writebuf,
+  offset, len, xfered_len);
 }
 
-static int
-linux_nat_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+linux_nat_target::thread_alive (ptid_t ptid)
 {
   /* As long as a PTID is in lwp list, consider it alive.  */
   return find_lwp_pid (ptid) != NULL;
@@ -3921,8 +3950,8 @@ linux_nat_thread_alive (struct target_ops *ops, ptid_t ptid)
 /* Implement the to_update_thread_list target method for this
    target.  */
 
-static void
-linux_nat_update_thread_list (struct target_ops *ops)
+void
+linux_nat_target::update_thread_list ()
 {
   struct lwp_info *lwp;
 
@@ -3943,8 +3972,8 @@ linux_nat_update_thread_list (struct target_ops *ops)
     }
 }
 
-static const char *
-linux_nat_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+linux_nat_target::pid_to_str (ptid_t ptid)
 {
   static char buf[64];
 
@@ -3959,8 +3988,8 @@ linux_nat_pid_to_str (struct target_ops *ops, ptid_t ptid)
   return normal_pid_to_str (ptid);
 }
 
-static const char *
-linux_nat_thread_name (struct target_ops *self, struct thread_info *thr)
+const char *
+linux_nat_target::thread_name (struct thread_info *thr)
 {
   return linux_proc_tid_get_name (thr->ptid);
 }
@@ -3968,8 +3997,8 @@ linux_nat_thread_name (struct target_ops *self, struct thread_info *thr)
 /* Accepts an integer PID; Returns a string representing a file that
    can be opened to get the symbols for the child process.  */
 
-static char *
-linux_child_pid_to_exec_file (struct target_ops *self, int pid)
+char *
+linux_nat_target::pid_to_exec_file (int pid)
 {
   return linux_proc_pid_to_exec_file (pid);
 }
@@ -3979,7 +4008,7 @@ linux_child_pid_to_exec_file (struct target_ops *self, int pid)
    efficient than banging away at PTRACE_PEEKTEXT.  */
 
 static enum target_xfer_status
-linux_proc_xfer_partial (struct target_ops *ops, enum target_object object,
+linux_proc_xfer_partial (enum target_object object,
  const char *annex, gdb_byte *readbuf,
  const gdb_byte *writebuf,
  ULONGEST offset, LONGEST len, ULONGEST *xfered_len)
@@ -4083,7 +4112,7 @@ spu_enumerate_spu_ids (int pid, gdb_byte *buf, ULONGEST offset, ULONGEST len)
    object type, using the /proc file system.  */
 
 static enum target_xfer_status
-linux_proc_xfer_spu (struct target_ops *ops, enum target_object object,
+linux_proc_xfer_spu (enum target_object object,
      const char *annex, gdb_byte *readbuf,
      const gdb_byte *writebuf,
      ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
@@ -4223,7 +4252,7 @@ linux_proc_pending_signals (int pid, sigset_t *pending,
 }
 
 static enum target_xfer_status
-linux_nat_xfer_osdata (struct target_ops *ops, enum target_object object,
+linux_nat_xfer_osdata (enum target_object object,
        const char *annex, gdb_byte *readbuf,
        const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
        ULONGEST *xfered_len)
@@ -4237,49 +4266,6 @@ linux_nat_xfer_osdata (struct target_ops *ops, enum target_object object,
     return TARGET_XFER_OK;
 }
 
-static enum target_xfer_status
-linux_xfer_partial (struct target_ops *ops, enum target_object object,
-                    const char *annex, gdb_byte *readbuf,
-    const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
-    ULONGEST *xfered_len)
-{
-  enum target_xfer_status xfer;
-
-  if (object == TARGET_OBJECT_AUXV)
-    return memory_xfer_auxv (ops, object, annex, readbuf, writebuf,
-     offset, len, xfered_len);
-
-  if (object == TARGET_OBJECT_OSDATA)
-    return linux_nat_xfer_osdata (ops, object, annex, readbuf, writebuf,
-  offset, len, xfered_len);
-
-  if (object == TARGET_OBJECT_SPU)
-    return linux_proc_xfer_spu (ops, object, annex, readbuf, writebuf,
- offset, len, xfered_len);
-
-  /* GDB calculates all the addresses in possibly larget width of the address.
-     Address width needs to be masked before its final use - either by
-     linux_proc_xfer_partial or inf_ptrace_xfer_partial.
-
-     Compare ADDR_BIT first to avoid a compiler warning on shift overflow.  */
-
-  if (object == TARGET_OBJECT_MEMORY)
-    {
-      int addr_bit = gdbarch_addr_bit (target_gdbarch ());
-
-      if (addr_bit < (sizeof (ULONGEST) * HOST_CHAR_BIT))
- offset &= ((ULONGEST) 1 << addr_bit) - 1;
-    }
-
-  xfer = linux_proc_xfer_partial (ops, object, annex, readbuf, writebuf,
-  offset, len, xfered_len);
-  if (xfer != TARGET_XFER_EOF)
-    return xfer;
-
-  return super_xfer_partial (ops, object, annex, readbuf, writebuf,
-     offset, len, xfered_len);
-}
-
 static void
 cleanup_target_stop (void *arg)
 {
@@ -4291,9 +4277,8 @@ cleanup_target_stop (void *arg)
   target_continue_no_signal (*ptid);
 }
 
-static std::vector<static_tracepoint_marker>
-linux_child_static_tracepoint_markers_by_strid (struct target_ops *self,
- const char *strid)
+std::vector<static_tracepoint_marker>
+linux_nat_target::static_tracepoint_markers_by_strid (const char *strid)
 {
   char s[IPA_CMD_BUF_SIZE];
   struct cleanup *old_chain;
@@ -4335,70 +4320,34 @@ linux_child_static_tracepoint_markers_by_strid (struct target_ops *self,
   return markers;
 }
 
-/* Create a prototype generic GNU/Linux target.  The client can override
-   it with local methods.  */
-
-void
-linux_target_install_ops (struct target_ops *t)
-{
-  t->to_insert_fork_catchpoint = linux_child_insert_fork_catchpoint;
-  t->to_remove_fork_catchpoint = linux_child_remove_fork_catchpoint;
-  t->to_insert_vfork_catchpoint = linux_child_insert_vfork_catchpoint;
-  t->to_remove_vfork_catchpoint = linux_child_remove_vfork_catchpoint;
-  t->to_insert_exec_catchpoint = linux_child_insert_exec_catchpoint;
-  t->to_remove_exec_catchpoint = linux_child_remove_exec_catchpoint;
-  t->to_set_syscall_catchpoint = linux_child_set_syscall_catchpoint;
-  t->to_pid_to_exec_file = linux_child_pid_to_exec_file;
-  t->to_post_startup_inferior = linux_child_post_startup_inferior;
-  t->to_post_attach = linux_child_post_attach;
-  t->to_follow_fork = linux_child_follow_fork;
-
-  super_xfer_partial = t->to_xfer_partial;
-  t->to_xfer_partial = linux_xfer_partial;
-
-  t->to_static_tracepoint_markers_by_strid
-    = linux_child_static_tracepoint_markers_by_strid;
-}
-
-struct target_ops *
-linux_target (void)
-{
-  struct target_ops *t;
-
-  t = inf_ptrace_target ();
-  linux_target_install_ops (t);
-
-  return t;
-}
-
 /* target_is_async_p implementation.  */
 
-static int
-linux_nat_is_async_p (struct target_ops *ops)
+int
+linux_nat_target::is_async_p ()
 {
   return linux_is_async_p ();
 }
 
 /* target_can_async_p implementation.  */
 
-static int
-linux_nat_can_async_p (struct target_ops *ops)
+int
+linux_nat_target::can_async_p ()
 {
   /* We're always async, unless the user explicitly prevented it with the
      "maint set target-async" command.  */
   return target_async_permitted;
 }
 
-static int
-linux_nat_supports_non_stop (struct target_ops *self)
+int
+linux_nat_target::supports_non_stop ()
 {
   return 1;
 }
 
 /* to_always_non_stop_p implementation.  */
 
-static int
-linux_nat_always_non_stop_p (struct target_ops *self)
+int
+linux_nat_target::always_non_stop_p ()
 {
   return 1;
 }
@@ -4408,14 +4357,14 @@ linux_nat_always_non_stop_p (struct target_ops *self)
 
 int linux_multi_process = 1;
 
-static int
-linux_nat_supports_multi_process (struct target_ops *self)
+int
+linux_nat_target::supports_multi_process ()
 {
   return linux_multi_process;
 }
 
-static int
-linux_nat_supports_disable_randomization (struct target_ops *self)
+int
+linux_nat_target::supports_disable_randomization ()
 {
 #ifdef HAVE_PERSONALITY
   return 1;
@@ -4494,8 +4443,8 @@ linux_async_pipe (int enable)
 
 /* target_async implementation.  */
 
-static void
-linux_nat_async (struct target_ops *ops, int enable)
+void
+linux_nat_target::async (int enable)
 {
   if (enable)
     {
@@ -4563,23 +4512,20 @@ linux_nat_stop_lwp (struct lwp_info *lwp, void *data)
   return 0;
 }
 
-static void
-linux_nat_stop (struct target_ops *self, ptid_t ptid)
+void
+linux_nat_target::stop (ptid_t ptid)
 {
   iterate_over_lwps (ptid, linux_nat_stop_lwp, NULL);
 }
 
-static void
-linux_nat_close (struct target_ops *self)
+void
+linux_nat_target::close ()
 {
   /* Unregister from the event loop.  */
-  if (linux_nat_is_async_p (self))
-    linux_nat_async (self, 0);
+  if (is_async_p ())
+    async (0);
 
-  if (linux_ops->to_close)
-    linux_ops->to_close (linux_ops);
-
-  super_close (self);
+  inf_ptrace_target::close ();
 }
 
 /* When requests are passed down from the linux-nat layer to the
@@ -4589,8 +4535,8 @@ linux_nat_close (struct target_ops *self)
    lwpid is a "main" process id or not (it assumes so).  We reverse
    look up the "main" process id from the lwp here.  */
 
-static struct address_space *
-linux_nat_thread_address_space (struct target_ops *t, ptid_t ptid)
+struct address_space *
+linux_nat_target::thread_address_space (ptid_t ptid)
 {
   struct lwp_info *lwp;
   struct inferior *inf;
@@ -4616,8 +4562,8 @@ linux_nat_thread_address_space (struct target_ops *t, ptid_t ptid)
 
 /* Return the cached value of the processor core for thread PTID.  */
 
-static int
-linux_nat_core_of_thread (struct target_ops *ops, ptid_t ptid)
+int
+linux_nat_target::core_of_thread (ptid_t ptid)
 {
   struct lwp_info *info = find_lwp_pid (ptid);
 
@@ -4628,8 +4574,8 @@ linux_nat_core_of_thread (struct target_ops *ops, ptid_t ptid)
 
 /* Implementation of to_filesystem_is_local.  */
 
-static int
-linux_nat_filesystem_is_local (struct target_ops *ops)
+int
+linux_nat_target::filesystem_is_local ()
 {
   struct inferior *inf = current_inferior ();
 
@@ -4658,11 +4604,10 @@ linux_nat_fileio_pid_of (struct inferior *inf)
 
 /* Implementation of to_fileio_open.  */
 
-static int
-linux_nat_fileio_open (struct target_ops *self,
-       struct inferior *inf, const char *filename,
-       int flags, int mode, int warn_if_slow,
-       int *target_errno)
+int
+linux_nat_target::fileio_open (struct inferior *inf, const char *filename,
+       int flags, int mode, int warn_if_slow,
+       int *target_errno)
 {
   int nat_flags;
   mode_t nat_mode;
@@ -4685,10 +4630,9 @@ linux_nat_fileio_open (struct target_ops *self,
 
 /* Implementation of to_fileio_readlink.  */
 
-static gdb::optional<std::string>
-linux_nat_fileio_readlink (struct target_ops *self,
-   struct inferior *inf, const char *filename,
-   int *target_errno)
+gdb::optional<std::string>
+linux_nat_target::fileio_readlink (struct inferior *inf, const char *filename,
+   int *target_errno)
 {
   char buf[PATH_MAX];
   int len;
@@ -4706,10 +4650,9 @@ linux_nat_fileio_readlink (struct target_ops *self,
 
 /* Implementation of to_fileio_unlink.  */
 
-static int
-linux_nat_fileio_unlink (struct target_ops *self,
- struct inferior *inf, const char *filename,
- int *target_errno)
+int
+linux_nat_target::fileio_unlink (struct inferior *inf, const char *filename,
+ int *target_errno)
 {
   int ret;
 
@@ -4723,76 +4666,19 @@ linux_nat_fileio_unlink (struct target_ops *self,
 
 /* Implementation of the to_thread_events method.  */
 
-static void
-linux_nat_thread_events (struct target_ops *ops, int enable)
+void
+linux_nat_target::thread_events (int enable)
 {
   report_thread_events = enable;
 }
 
-void
-linux_nat_add_target (struct target_ops *t)
-{
-  /* Save the provided single-threaded target.  We save this in a separate
-     variable because another target we've inherited from (e.g. inf-ptrace)
-     may have saved a pointer to T; we want to use it for the final
-     process stratum target.  */
-  linux_ops_saved = *t;
-  linux_ops = &linux_ops_saved;
-
-  /* Override some methods for multithreading.  */
-  t->to_create_inferior = linux_nat_create_inferior;
-  t->to_attach = linux_nat_attach;
-  t->to_detach = linux_nat_detach;
-  t->to_resume = linux_nat_resume;
-  t->to_wait = linux_nat_wait;
-  t->to_pass_signals = linux_nat_pass_signals;
-  t->to_xfer_partial = linux_nat_xfer_partial;
-  t->to_kill = linux_nat_kill;
-  t->to_mourn_inferior = linux_nat_mourn_inferior;
-  t->to_thread_alive = linux_nat_thread_alive;
-  t->to_update_thread_list = linux_nat_update_thread_list;
-  t->to_pid_to_str = linux_nat_pid_to_str;
-  t->to_thread_name = linux_nat_thread_name;
-  t->to_has_thread_control = tc_schedlock;
-  t->to_thread_address_space = linux_nat_thread_address_space;
-  t->to_stopped_by_watchpoint = linux_nat_stopped_by_watchpoint;
-  t->to_stopped_data_address = linux_nat_stopped_data_address;
-  t->to_stopped_by_sw_breakpoint = linux_nat_stopped_by_sw_breakpoint;
-  t->to_supports_stopped_by_sw_breakpoint = linux_nat_supports_stopped_by_sw_breakpoint;
-  t->to_stopped_by_hw_breakpoint = linux_nat_stopped_by_hw_breakpoint;
-  t->to_supports_stopped_by_hw_breakpoint = linux_nat_supports_stopped_by_hw_breakpoint;
-  t->to_thread_events = linux_nat_thread_events;
-
-  t->to_can_async_p = linux_nat_can_async_p;
-  t->to_is_async_p = linux_nat_is_async_p;
-  t->to_supports_non_stop = linux_nat_supports_non_stop;
-  t->to_always_non_stop_p = linux_nat_always_non_stop_p;
-  t->to_async = linux_nat_async;
-
-  super_close = t->to_close;
-  t->to_close = linux_nat_close;
-
-  t->to_stop = linux_nat_stop;
-
-  t->to_supports_multi_process = linux_nat_supports_multi_process;
-
-  t->to_supports_disable_randomization
-    = linux_nat_supports_disable_randomization;
-
-  t->to_core_of_thread = linux_nat_core_of_thread;
-
-  t->to_filesystem_is_local = linux_nat_filesystem_is_local;
-  t->to_fileio_open = linux_nat_fileio_open;
-  t->to_fileio_readlink = linux_nat_fileio_readlink;
-  t->to_fileio_unlink = linux_nat_fileio_unlink;
-
+linux_nat_target::linux_nat_target ()
+{
   /* We don't change the stratum; this target will sit at
      process_stratum and thread_db will set at thread_stratum.  This
      is a little strange, since this is a multi-threaded-capable
      target, but we want to be on the stack below thread_db, and we
      also want to be used for single-threaded processes.  */
-
-  add_target (t);
 }
 
 /* Register a method to call whenever a new thread is attached.  */
diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h
index 03c2021911..da5357a21e 100644
--- a/gdb/linux-nat.h
+++ b/gdb/linux-nat.h
@@ -18,9 +18,138 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "nat/linux-nat.h"
+#include "inf-ptrace.h"
 #include "target.h"
 #include <signal.h>
 
+/* A prototype generic GNU/Linux target.  A concrete instance should
+   override it with local methods.  */
+
+class linux_nat_target : public inf_ptrace_target
+{
+public:
+  linux_nat_target ();
+  ~linux_nat_target () override = 0;
+
+  thread_control_capabilities get_thread_control_capabilities () override
+  { return tc_schedlock; }
+
+  void create_inferior (const char *, const std::string &,
+ char **, int) override;
+
+  void attach (const char *, int) override;
+
+  void detach (inferior *, int) override;
+
+  void resume (ptid_t, int, enum gdb_signal) override;
+
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+
+  void pass_signals (int, unsigned char *) override;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+  void kill () override;
+
+  void mourn_inferior () override;
+  int thread_alive (ptid_t ptid) override;
+
+  void update_thread_list () override;
+
+  const char *pid_to_str (ptid_t) override;
+
+  const char *thread_name (struct thread_info *) override;
+
+  struct address_space *thread_address_space (ptid_t) override;
+
+  int stopped_by_watchpoint () override;
+
+  int stopped_data_address (CORE_ADDR *) override;
+
+  int stopped_by_sw_breakpoint () override;
+  int supports_stopped_by_sw_breakpoint () override;
+
+  int stopped_by_hw_breakpoint () override;
+  int supports_stopped_by_hw_breakpoint () override;
+
+  void thread_events (int) override;
+
+  int can_async_p () override;
+  int is_async_p () override;
+
+  int supports_non_stop () override;
+  int always_non_stop_p () override;
+
+  void async (int) override;
+
+  void close () override;
+
+  void stop (ptid_t) override;
+
+  int supports_multi_process () override;
+
+  int supports_disable_randomization () override;
+
+  int core_of_thread (ptid_t ptid) override;
+
+  int filesystem_is_local () override;
+
+  int fileio_open (struct inferior *inf, const char *filename,
+   int flags, int mode, int warn_if_slow,
+   int *target_errno) override;
+
+  gdb::optional<std::string>
+    fileio_readlink (struct inferior *inf,
+     const char *filename,
+     int *target_errno) override;
+
+  int fileio_unlink (struct inferior *inf,
+     const char *filename,
+     int *target_errno) override;
+
+  int insert_fork_catchpoint (int) override;
+  int remove_fork_catchpoint (int) override;
+  int insert_vfork_catchpoint (int) override;
+  int remove_vfork_catchpoint (int) override;
+
+  int insert_exec_catchpoint (int) override;
+  int remove_exec_catchpoint (int) override;
+
+  int set_syscall_catchpoint (int pid, bool needed, int any_count,
+      gdb::array_view<const int> syscall_counts) override;
+
+  char *pid_to_exec_file (int pid) override;
+
+  void post_startup_inferior (ptid_t) override;
+
+  void post_attach (int) override;
+
+  int follow_fork (int, int) override;
+
+  std::vector<static_tracepoint_marker>
+    static_tracepoint_markers_by_strid (const char *id) override;
+
+  /* Methods that are meant to overridden by the concrete
+     arch-specific target instance.  */
+
+  virtual void low_resume (ptid_t ptid, int step, enum gdb_signal sig)
+  { inf_ptrace_target::resume (ptid, step, sig); }
+
+  virtual int low_stopped_by_watchpoint ()
+  { return 0; }
+
+  virtual int low_stopped_data_address (CORE_ADDR *addr_p)
+  { return 0; }
+};
+
+/* The final/concrete instance.  */
+extern linux_nat_target *linux_target;
+
 struct arch_lwp_info;
 
 /* Structure describing an LWP.  This is public only for the purposes
@@ -149,18 +278,6 @@ extern void linux_stop_and_wait_all_lwps (void);
    left stopped.)  */
 extern void linux_unstop_all_lwps (void);
 
-/* Create a prototype generic GNU/Linux target.  The client can
-   override it with local methods.  */
-struct target_ops * linux_target (void);
-
-/* Make a prototype generic GNU/Linux target.  The client can override
-   it with local methods.  */
-void linux_target_install_ops (struct target_ops *t);
-
-/* Register the customized GNU/Linux target.  This should be used
-   instead of calling add_target directly.  */
-void linux_nat_add_target (struct target_ops *);
-
 /* Register a method to call whenever a new thread is attached.  */
 void linux_nat_set_new_thread (struct target_ops *, void (*) (struct lwp_info *));
 
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 08e3cfbc8b..a7b0772d45 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -75,6 +75,40 @@
    of the ptid_t prevents thread IDs changing when libpthread is
    loaded or unloaded.  */
 
+class thread_db_target : 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."); }
+
+  void detach (inferior *, int) override;
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+  void resume (ptid_t, int, enum gdb_signal) override;
+  void mourn_inferior () override;
+  void update_thread_list () override;
+  const char *pid_to_str (ptid_t) override;
+  CORE_ADDR get_thread_local_address (ptid_t ptid,
+      CORE_ADDR load_module_addr,
+      CORE_ADDR offset) override;
+  const char *extra_thread_info (struct thread_info *) override;
+  ptid_t get_ada_task_ptid (long lwp, long thread) override;
+
+  thread_info *thread_handle_to_thread_info (const gdb_byte *thread_handle,
+     int handle_len,
+     inferior *inf) override;
+};
+
+thread_db_target::thread_db_target()
+{
+  this->to_stratum = thread_stratum;
+}
+
 static char *libthread_db_search_path;
 
 /* Set to non-zero if thread_db auto-loading is enabled
@@ -118,7 +152,7 @@ show_libthread_db_debug (struct ui_file *file, int from_tty,
    threads.  */
 
 /* This module's target vector.  */
-static struct target_ops thread_db_ops;
+static thread_db_target the_thread_db_target;
 
 /* Non-zero if we have determined the signals used by the threads
    library.  */
@@ -635,7 +669,7 @@ try_thread_db_load_1 (struct thread_db_info *info)
   /* The thread library was detected.  Activate the thread_db target
      if this is the first process using it.  */
   if (thread_db_list->next == NULL)
-    push_target (&thread_db_ops);
+    push_target (&the_thread_db_target);
 
   return 1;
 }
@@ -889,7 +923,7 @@ thread_db_load (void)
     return 0;
 
   /* Don't attempt to use thread_db for remote targets.  */
-  if (!(target_can_run (&current_target) || core_bfd))
+  if (!(target_can_run () || core_bfd))
     return 0;
 
   if (thread_db_load_search ())
@@ -980,7 +1014,7 @@ static void
 check_pid_namespace_match (void)
 {
   /* Check is only relevant for local targets targets.  */
-  if (target_can_run (&current_target))
+  if (target_can_run ())
     {
       /* If the child is in a different PID namespace, its idea of its
  PID will differ from our idea of its PID.  When we scan the
@@ -1055,32 +1089,31 @@ record_thread (struct thread_db_info *info,
   return tp;
 }
 
-static void
-thread_db_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+thread_db_target::detach (inferior *inf, int from_tty)
 {
-  struct target_ops *target_beneath = find_target_beneath (ops);
+  struct target_ops *target_beneath = find_target_beneath (this);
 
   delete_thread_db_info (inf->pid);
 
-  target_beneath->to_detach (target_beneath, inf, from_tty);
+  target_beneath->detach (inf, from_tty);
 
   /* NOTE: From this point on, inferior_ptid is null_ptid.  */
 
   /* If there are no more processes using libpthread, detach the
      thread_db target ops.  */
   if (!thread_db_list)
-    unpush_target (&thread_db_ops);
+    unpush_target (this);
 }
 
-static ptid_t
-thread_db_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus,
- int options)
+ptid_t
+thread_db_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
+ int options)
 {
   struct thread_db_info *info;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
-  ptid = beneath->to_wait (beneath, ptid, ourstatus, options);
+  ptid = beneath->wait (ptid, ourstatus, options);
 
   switch (ourstatus->kind)
     {
@@ -1103,7 +1136,7 @@ thread_db_wait (struct target_ops *ops,
  not unless we find otherwise.  */
       delete_thread_db_info (ptid_get_pid (ptid));
       if (!thread_db_list)
- unpush_target (&thread_db_ops);
+ unpush_target (&the_thread_db_target);
 
       return ptid;
     }
@@ -1114,18 +1147,18 @@ thread_db_wait (struct target_ops *ops,
   return ptid;
 }
 
-static void
-thread_db_mourn_inferior (struct target_ops *ops)
+void
+thread_db_target::mourn_inferior ()
 {
-  struct target_ops *target_beneath = find_target_beneath (ops);
+  struct target_ops *target_beneath = find_target_beneath (this);
 
   delete_thread_db_info (ptid_get_pid (inferior_ptid));
 
-  target_beneath->to_mourn_inferior (target_beneath);
+  target_beneath->mourn_inferior ();
 
   /* Detach thread_db target ops.  */
   if (!thread_db_list)
-    unpush_target (ops);
+    unpush_target (&the_thread_db_target);
 }
 
 struct callback_data
@@ -1293,8 +1326,8 @@ thread_db_find_new_threads_1 (ptid_t ptid)
 /* Implement the to_update_thread_list target method for this
    target.  */
 
-static void
-thread_db_update_thread_list (struct target_ops *ops)
+void
+thread_db_target::update_thread_list ()
 {
   struct thread_db_info *info;
   struct inferior *inf;
@@ -1334,11 +1367,11 @@ thread_db_update_thread_list (struct target_ops *ops)
     }
 
   /* Give the beneath target a chance to do extra processing.  */
-  ops->beneath->to_update_thread_list (ops->beneath);
+  this->beneath->update_thread_list ();
 }
 
-static const char *
-thread_db_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+thread_db_target::pid_to_str (ptid_t ptid)
 {
   struct thread_info *thread_info = find_thread_ptid (ptid);
   struct target_ops *beneath;
@@ -1354,16 +1387,15 @@ thread_db_pid_to_str (struct target_ops *ops, ptid_t ptid)
       return buf;
     }
 
-  beneath = find_target_beneath (ops);
-  return beneath->to_pid_to_str (beneath, ptid);
+  beneath = find_target_beneath (this);
+  return beneath->pid_to_str (ptid);
 }
 
 /* Return a string describing the state of the thread specified by
    INFO.  */
 
-static const char *
-thread_db_extra_thread_info (struct target_ops *self,
-     struct thread_info *info)
+const char *
+thread_db_target::extra_thread_info (thread_info *info)
 {
   if (info->priv == NULL)
     return NULL;
@@ -1379,11 +1411,10 @@ thread_db_extra_thread_info (struct target_ops *self,
 /* Return pointer to the thread_info struct which corresponds to
    THREAD_HANDLE (having length HANDLE_LEN).  */
 
-static struct thread_info *
-thread_db_thread_handle_to_thread_info (struct target_ops *ops,
- const gdb_byte *thread_handle,
- int handle_len,
- struct inferior *inf)
+thread_info *
+thread_db_target::thread_handle_to_thread_info (const gdb_byte *thread_handle,
+ int handle_len,
+ inferior *inf)
 {
   struct thread_info *tp;
   thread_t handle_tid;
@@ -1412,11 +1443,10 @@ thread_db_thread_handle_to_thread_info (struct target_ops *ops,
 /* Get the address of the thread local variable in load module LM which
    is stored at OFFSET within the thread local storage for thread PTID.  */
 
-static CORE_ADDR
-thread_db_get_thread_local_address (struct target_ops *ops,
-    ptid_t ptid,
-    CORE_ADDR lm,
-    CORE_ADDR offset)
+CORE_ADDR
+thread_db_target::get_thread_local_address (ptid_t ptid,
+    CORE_ADDR lm,
+    CORE_ADDR offset)
 {
   struct thread_info *thread_info;
   struct target_ops *beneath;
@@ -1491,24 +1521,23 @@ thread_db_get_thread_local_address (struct target_ops *ops,
       : (CORE_ADDR) (uintptr_t) address);
     }
 
-  beneath = find_target_beneath (ops);
-  return beneath->to_get_thread_local_address (beneath, ptid, lm, offset);
+  beneath = find_target_beneath (this);
+  return beneath->get_thread_local_address (ptid, lm, offset);
 }
 
 /* Implement the to_get_ada_task_ptid target method for this target.  */
 
-static ptid_t
-thread_db_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
+ptid_t
+thread_db_target::get_ada_task_ptid (long lwp, long thread)
 {
   /* NPTL uses a 1:1 model, so the LWP id suffices.  */
   return ptid_build (ptid_get_pid (inferior_ptid), lwp, 0);
 }
 
-static void
-thread_db_resume (struct target_ops *ops,
-  ptid_t ptid, int step, enum gdb_signal signo)
+void
+thread_db_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   struct thread_db_info *info;
 
   if (ptid_equal (ptid, minus_one_ptid))
@@ -1522,7 +1551,7 @@ thread_db_resume (struct target_ops *ops,
   if (info)
     info->need_stale_parent_threads_check = 0;
 
-  beneath->to_resume (beneath, ptid, step, signo);
+  beneath->resume (ptid, step, signo);
 }
 
 /* std::sort helper function for info_auto_load_libthread_db, sort the
@@ -1637,35 +1666,9 @@ info_auto_load_libthread_db (const char *args, int from_tty)
     uiout->message (_("No auto-loaded libthread-db.\n"));
 }
 
-static void
-init_thread_db_ops (void)
-{
-  thread_db_ops.to_shortname = "multi-thread";
-  thread_db_ops.to_longname = "multi-threaded child process.";
-  thread_db_ops.to_doc = "Threads and pthreads support.";
-  thread_db_ops.to_detach = thread_db_detach;
-  thread_db_ops.to_wait = thread_db_wait;
-  thread_db_ops.to_resume = thread_db_resume;
-  thread_db_ops.to_mourn_inferior = thread_db_mourn_inferior;
-  thread_db_ops.to_update_thread_list = thread_db_update_thread_list;
-  thread_db_ops.to_pid_to_str = thread_db_pid_to_str;
-  thread_db_ops.to_stratum = thread_stratum;
-  thread_db_ops.to_has_thread_control = tc_schedlock;
-  thread_db_ops.to_get_thread_local_address
-    = thread_db_get_thread_local_address;
-  thread_db_ops.to_extra_thread_info = thread_db_extra_thread_info;
-  thread_db_ops.to_get_ada_task_ptid = thread_db_get_ada_task_ptid;
-  thread_db_ops.to_thread_handle_to_thread_info = thread_db_thread_handle_to_thread_info;
-  thread_db_ops.to_magic = OPS_MAGIC;
-
-  complete_target_initialization (&thread_db_ops);
-}
-
 void
 _initialize_thread_db (void)
 {
-  init_thread_db_ops ();
-
   /* Defer loading of libthread_db.so until inferior is running.
      This allows gdb to load correct libthread_db for a given
      executable -- there could be multiple versions of glibc,
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index a3bdafffa2..0910d0047e 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -27,7 +27,6 @@
 #include <sys/uio.h>
 
 #include "x86-nat.h"
-#include "linux-nat.h"
 #ifndef __x86_64__
 #include "i386-linux-nat.h"
 #endif
@@ -78,14 +77,15 @@ x86_linux_new_fork (struct lwp_info *parent, pid_t child_pid)
 }
 
 
-static void (*super_post_startup_inferior) (struct target_ops *self,
-    ptid_t ptid);
+x86_linux_nat_target::~x86_linux_nat_target ()
+{
+}
 
-static void
-x86_linux_child_post_startup_inferior (struct target_ops *self, ptid_t ptid)
+void
+x86_linux_nat_target::post_startup_inferior (ptid_t ptid)
 {
   x86_cleanup_dregs ();
-  super_post_startup_inferior (self, ptid);
+  linux_nat_target::post_startup_inferior (ptid);
 }
 
 #ifdef __x86_64__
@@ -102,8 +102,8 @@ x86_linux_child_post_startup_inferior (struct target_ops *self, ptid_t ptid)
 
 /* Get Linux/x86 target description from running target.  */
 
-static const struct target_desc *
-x86_linux_read_description (struct target_ops *ops)
+const struct target_desc *
+x86_linux_nat_target::read_description ()
 {
   int tid;
   int is_64bit = 0;
@@ -212,9 +212,9 @@ x86_linux_read_description (struct target_ops *ops)
 
 /* Enable branch tracing.  */
 
-static struct btrace_target_info *
-x86_linux_enable_btrace (struct target_ops *self, ptid_t ptid,
- const struct btrace_config *conf)
+struct btrace_target_info *
+x86_linux_nat_target::enable_btrace (ptid_t ptid,
+     const struct btrace_config *conf)
 {
   struct btrace_target_info *tinfo = nullptr;
   TRY
@@ -233,9 +233,8 @@ x86_linux_enable_btrace (struct target_ops *self, ptid_t ptid,
 
 /* Disable branch tracing.  */
 
-static void
-x86_linux_disable_btrace (struct target_ops *self,
-  struct btrace_target_info *tinfo)
+void
+x86_linux_nat_target::disable_btrace (struct btrace_target_info *tinfo)
 {
   enum btrace_error errcode = linux_disable_btrace (tinfo);
 
@@ -245,28 +244,25 @@ x86_linux_disable_btrace (struct target_ops *self,
 
 /* Teardown branch tracing.  */
 
-static void
-x86_linux_teardown_btrace (struct target_ops *self,
-   struct btrace_target_info *tinfo)
+void
+x86_linux_nat_target::teardown_btrace (struct btrace_target_info *tinfo)
 {
   /* Ignore errors.  */
   linux_disable_btrace (tinfo);
 }
 
-static enum btrace_error
-x86_linux_read_btrace (struct target_ops *self,
-       struct btrace_data *data,
-       struct btrace_target_info *btinfo,
-       enum btrace_read_type type)
+enum btrace_error
+x86_linux_nat_target::read_btrace (struct btrace_data *data,
+   struct btrace_target_info *btinfo,
+   enum btrace_read_type type)
 {
   return linux_read_btrace (data, btinfo, type);
 }
 
 /* See to_btrace_conf in target.h.  */
 
-static const struct btrace_config *
-x86_linux_btrace_conf (struct target_ops *self,
-       const struct btrace_target_info *btinfo)
+const struct btrace_config *
+x86_linux_nat_target::btrace_conf (const struct btrace_target_info *btinfo)
 {
   return linux_btrace_conf (btinfo);
 }
@@ -315,16 +311,12 @@ x86_linux_get_thread_area (pid_t pid, void *addr, unsigned int *base_addr)
 }
 
 
-/* Create an x86 GNU/Linux target.  */
+/* Add an x86 GNU/Linux target.  */
 
-struct target_ops *
-x86_linux_create_target (void)
+void
+x86_linux_add_target (linux_nat_target *t)
 {
-  /* Fill in the generic GNU/Linux methods.  */
-  struct target_ops *t = linux_target ();
-
   /* Initialize the debug register function vectors.  */
-  x86_use_watchpoints (t);
   x86_dr_low.set_control = x86_linux_dr_set_control;
   x86_dr_low.set_addr = x86_linux_dr_set_addr;
   x86_dr_low.get_addr = x86_linux_dr_get_addr;
@@ -332,29 +324,7 @@ x86_linux_create_target (void)
   x86_dr_low.get_control = x86_linux_dr_get_control;
   x86_set_debug_register_length (sizeof (void *));
 
-  /* Override the GNU/Linux inferior startup hook.  */
-  super_post_startup_inferior = t->to_post_startup_inferior;
-  t->to_post_startup_inferior = x86_linux_child_post_startup_inferior;
-
-  /* Add the description reader.  */
-  t->to_read_description = x86_linux_read_description;
-
-  /* Add btrace methods.  */
-  t->to_enable_btrace = x86_linux_enable_btrace;
-  t->to_disable_btrace = x86_linux_disable_btrace;
-  t->to_teardown_btrace = x86_linux_teardown_btrace;
-  t->to_read_btrace = x86_linux_read_btrace;
-  t->to_btrace_conf = x86_linux_btrace_conf;
-
-  return t;
-}
-
-/* Add an x86 GNU/Linux target.  */
-
-void
-x86_linux_add_target (struct target_ops *t)
-{
-  linux_nat_add_target (t);
+  add_target (t);
   linux_nat_set_new_thread (t, x86_linux_new_thread);
   linux_nat_set_delete_thread (t, x86_linux_delete_thread);
   linux_nat_set_new_fork (t, x86_linux_new_fork);
diff --git a/gdb/x86-linux-nat.h b/gdb/x86-linux-nat.h
index 383bfd5314..0bafaaa71f 100644
--- a/gdb/x86-linux-nat.h
+++ b/gdb/x86-linux-nat.h
@@ -21,6 +21,44 @@
 #define X86_LINUX_NAT_H 1
 
 #include "gdb_proc_service.h"  /* For ps_err_e.  */
+#include "linux-nat.h"
+#include "x86-nat.h"
+
+struct x86_linux_nat_target : public x86_nat_target<linux_nat_target>
+{
+  virtual ~x86_linux_nat_target () override = 0;
+
+  /* Override the GNU/Linux inferior startup hook.  */
+  void post_startup_inferior (ptid_t) override;
+
+  /* Add the description reader.  */
+  const struct target_desc *read_description () override;
+
+  struct btrace_target_info *enable_btrace (ptid_t ptid,
+    const struct btrace_config *conf) override;
+  void disable_btrace (struct btrace_target_info *tinfo) override;
+  void teardown_btrace (struct btrace_target_info *tinfo) override;
+  enum btrace_error read_btrace (struct btrace_data *data,
+ struct btrace_target_info *btinfo,
+ enum btrace_read_type type) override;
+  const struct btrace_config *btrace_conf (const struct btrace_target_info *) override;
+
+  /* These two are rewired to low_ versions.  linux-nat.c queries
+     stopped-by-watchpoint info as soon as an lwp stops (via the low_
+     methods) and caches the result, to be returned via the normal
+     non-low methods.  */
+  int stopped_by_watchpoint () override
+  { return linux_nat_target::stopped_by_watchpoint (); }
+
+  int stopped_data_address (CORE_ADDR *addr_p) override
+  { return linux_nat_target::stopped_data_address (addr_p); }
+
+  int low_stopped_by_watchpoint () override
+  { return x86_nat_target::stopped_by_watchpoint (); }
+
+  int low_stopped_data_address (CORE_ADDR *addr_p) override
+  { return x86_nat_target::stopped_data_address (addr_p); }
+};
 
 
 
@@ -32,12 +70,8 @@ extern ps_err_e x86_linux_get_thread_area (pid_t pid, void *addr,
    unsigned int *base_addr);
 
 
-/* Create an x86 GNU/Linux target.  */
-
-extern struct target_ops *x86_linux_create_target (void);
-
 /* Add an x86 GNU/Linux target.  */
 
-extern void x86_linux_add_target (struct target_ops *t);
+extern void x86_linux_add_target (linux_nat_target *t);
 
 #endif
diff --git a/gdb/x86-nat.c b/gdb/x86-nat.c
index bec51373a6..cfd293c17f 100644
--- a/gdb/x86-nat.c
+++ b/gdb/x86-nat.c
@@ -146,8 +146,8 @@ x86_cleanup_dregs (void)
    address ADDR and whose length is LEN bytes.  Watch memory accesses
    of the type TYPE.  Return 0 on success, -1 on failure.  */
 
-static int
-x86_insert_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
+int
+x86_insert_watchpoint (CORE_ADDR addr, int len,
        enum target_hw_bp_type type, struct expression *cond)
 {
   struct x86_debug_reg_state *state
@@ -159,8 +159,8 @@ x86_insert_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
 /* Remove a watchpoint that watched the memory region which starts at
    address ADDR, whose length is LEN bytes, and for accesses of the
    type TYPE.  Return 0 on success, -1 on failure.  */
-static int
-x86_remove_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
+int
+x86_remove_watchpoint (CORE_ADDR addr, int len,
        enum target_hw_bp_type type, struct expression *cond)
 {
   struct x86_debug_reg_state *state
@@ -172,9 +172,8 @@ x86_remove_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
 /* Return non-zero if we can watch a memory region that starts at
    address ADDR and whose length is LEN bytes.  */
 
-static int
-x86_region_ok_for_watchpoint (struct target_ops *self,
-      CORE_ADDR addr, int len)
+int
+x86_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
 {
   struct x86_debug_reg_state *state
     = x86_debug_reg_state (ptid_get_pid (inferior_ptid));
@@ -186,8 +185,8 @@ x86_region_ok_for_watchpoint (struct target_ops *self,
    address associated with that break/watchpoint and return non-zero.
    Otherwise, return zero.  */
 
-static int
-x86_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
+int
+x86_stopped_data_address (CORE_ADDR *addr_p)
 {
   struct x86_debug_reg_state *state
     = x86_debug_reg_state (ptid_get_pid (inferior_ptid));
@@ -198,8 +197,8 @@ x86_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
 /* Return non-zero if the inferior has some watchpoint that triggered.
    Otherwise return zero.  */
 
-static int
-x86_stopped_by_watchpoint (struct target_ops *ops)
+int
+x86_stopped_by_watchpoint ()
 {
   struct x86_debug_reg_state *state
     = x86_debug_reg_state (ptid_get_pid (inferior_ptid));
@@ -210,9 +209,8 @@ x86_stopped_by_watchpoint (struct target_ops *ops)
 /* Insert a hardware-assisted breakpoint at BP_TGT->reqstd_address.
    Return 0 on success, EBUSY on failure.  */
 
-static int
-x86_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
-  struct bp_target_info *bp_tgt)
+int
+x86_insert_hw_breakpoint (struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
 {
   struct x86_debug_reg_state *state
     = x86_debug_reg_state (ptid_get_pid (inferior_ptid));
@@ -225,8 +223,8 @@ x86_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
 /* Remove a hardware-assisted breakpoint at BP_TGT->placed_address.
    Return 0 on success, -1 on failure.  */
 
-static int
-x86_remove_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
+int
+x86_remove_hw_breakpoint (struct gdbarch *gdbarch,
   struct bp_target_info *bp_tgt)
 {
   struct x86_debug_reg_state *state
@@ -253,9 +251,8 @@ x86_remove_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
    virtually unlimited number of watchpoints, due to debug register
    sharing implemented via reference counts in x86-nat.c.  */
 
-static int
-x86_can_use_hw_breakpoint (struct target_ops *self,
-   enum bptype type, int cnt, int othertype)
+int
+x86_can_use_hw_breakpoint (enum bptype type, int cnt, int othertype)
 {
   return 1;
 }
@@ -263,8 +260,8 @@ x86_can_use_hw_breakpoint (struct target_ops *self,
 /* Return non-zero if the inferior has some breakpoint that triggered.
    Otherwise return zero.  */
 
-static int
-x86_stopped_by_hw_breakpoint (struct target_ops *ops)
+int
+x86_stopped_by_hw_breakpoint ()
 {
   struct x86_debug_reg_state *state
     = x86_debug_reg_state (ptid_get_pid (inferior_ptid));
@@ -291,30 +288,7 @@ triggers a breakpoint or watchpoint."),
    &maintenance_show_cmdlist);
 }
 
-/* There are only two global functions left.  */
-
-void
-x86_use_watchpoints (struct target_ops *t)
-{
-  /* After a watchpoint trap, the PC points to the instruction after the
-     one that caused the trap.  Therefore we don't need to step over it.
-     But we do need to reset the status register to avoid another trap.  */
-  t->to_have_continuable_watchpoint = 1;
-
-  t->to_can_use_hw_breakpoint = x86_can_use_hw_breakpoint;
-  t->to_region_ok_for_hw_watchpoint = x86_region_ok_for_watchpoint;
-  t->to_stopped_by_watchpoint = x86_stopped_by_watchpoint;
-  t->to_stopped_data_address = x86_stopped_data_address;
-  t->to_insert_watchpoint = x86_insert_watchpoint;
-  t->to_remove_watchpoint = x86_remove_watchpoint;
-  t->to_insert_hw_breakpoint = x86_insert_hw_breakpoint;
-  t->to_remove_hw_breakpoint = x86_remove_hw_breakpoint;
-
-  /* A target must provide an implementation of the
-     "to_supports_stopped_by_hw_breakpoint" target method before this
-     callback will be used.  */
-  t->to_stopped_by_hw_breakpoint = x86_stopped_by_hw_breakpoint;
-}
+/* See x86-nat.h.  */
 
 void
 x86_set_debug_register_length (int len)
diff --git a/gdb/x86-nat.h b/gdb/x86-nat.h
index 80c7fdfa80..8ad1821360 100644
--- a/gdb/x86-nat.h
+++ b/gdb/x86-nat.h
@@ -23,16 +23,12 @@
 #ifndef X86_NAT_H
 #define X86_NAT_H 1
 
+#include "breakpoint.h"
 #include "nat/x86-dregs.h"
+#include "target.h"
 
 /* Hardware-assisted breakpoints and watchpoints.  */
 
-/* Add watchpoint methods to the provided target_ops.  
-   Targets using x86 family debug registers for watchpoints should call
-   this.  */
-struct target_ops;
-extern void x86_use_watchpoints (struct target_ops *);
-
 /* Use this function to set x86_dr_low debug_register_length field
    rather than setting it directly to check that the length is only
    set once.  It also enables the 'maint set/show show-debug-regs'
@@ -49,4 +45,75 @@ extern void x86_cleanup_dregs (void);
 
 extern void x86_forget_process (pid_t pid);
 
+/* Helper functions used by x86_nat_target below.  See their
+   definitions.  */
+
+extern int x86_can_use_hw_breakpoint (enum bptype type, int cnt, int othertype);
+extern int x86_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len);
+extern int x86_stopped_by_watchpoint ();
+extern int x86_stopped_data_address (CORE_ADDR *addr_p);
+extern int x86_insert_watchpoint (CORE_ADDR addr, int len,
+   enum target_hw_bp_type type,
+   struct expression *cond);
+extern int x86_remove_watchpoint (CORE_ADDR addr, int len,
+   enum target_hw_bp_type type,
+   struct expression *cond);
+extern int x86_insert_hw_breakpoint (struct gdbarch *gdbarch,
+      struct bp_target_info *bp_tgt);
+extern int x86_remove_hw_breakpoint (struct gdbarch *gdbarch,
+     struct bp_target_info *bp_tgt);
+extern int x86_stopped_by_hw_breakpoint ();
+
+/* Convenience template mixin used to add x86 watchpoints support to a
+   target.  */
+
+template <typename BaseTarget>
+struct x86_nat_target : public BaseTarget
+{
+  /* Hook in the x86 hardware watchpoints/breakpoints support.  */
+
+  /* After a watchpoint trap, the PC points to the instruction after
+     the one that caused the trap.  Therefore we don't need to step
+     over it.  But we do need to reset the status register to avoid
+     another trap.  */
+  bool have_continuable_watchpoint () override
+  { return true; }
+
+  int can_use_hw_breakpoint (enum bptype type, int cnt, int othertype) override
+  { return x86_can_use_hw_breakpoint (type, cnt, othertype); }
+
+  int region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) override
+  { return x86_region_ok_for_hw_watchpoint (addr, len); }
+
+  int insert_watchpoint (CORE_ADDR addr, int len,
+ enum target_hw_bp_type type,
+ struct expression *cond) override
+  { return x86_insert_watchpoint (addr, len, type, cond); }
+
+  int remove_watchpoint (CORE_ADDR addr, int len,
+ enum target_hw_bp_type type,
+ struct expression *cond) override
+  { return x86_remove_watchpoint (addr, len, type, cond); }
+
+  int insert_hw_breakpoint (struct gdbarch *gdbarch,
+    struct bp_target_info *bp_tgt) override
+  { return x86_insert_hw_breakpoint (gdbarch, bp_tgt); }
+
+  int remove_hw_breakpoint (struct gdbarch *gdbarch,
+    struct bp_target_info *bp_tgt) override
+  { return x86_remove_hw_breakpoint (gdbarch, bp_tgt); }
+
+  int stopped_by_watchpoint () override
+  { return x86_stopped_by_watchpoint (); }
+
+  int stopped_data_address (CORE_ADDR *addr_p) override
+  { return x86_stopped_data_address (addr_p); }
+
+  /* A target must provide an implementation of the
+     "supports_stopped_by_hw_breakpoint" target method before this
+     callback will be used.  */
+  int stopped_by_hw_breakpoint () override
+  { return x86_stopped_by_hw_breakpoint (); }
+};
+
 #endif /* X86_NAT_H */
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 14/40] target_ops/C++: PPC/PPC64 GNU/Linux

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.  I'd tested this on the GCC compile farm.
---
 gdb/ppc-linux-nat.c | 193 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 106 insertions(+), 87 deletions(-)

diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index e1b728016c..c9f0f9d48d 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -267,6 +267,57 @@ int have_ptrace_getsetregs = 1;
    them and gotten an error.  */
 int have_ptrace_getsetfpregs = 1;
 
+struct ppc_linux_nat_target final : public linux_nat_target
+{
+  /* Add our register access methods.  */
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  /* Add our breakpoint/watchpoint methods.  */
+  int can_use_hw_breakpoint (enum bptype, int, int) override;
+
+  int insert_hw_breakpoint (struct gdbarch *, struct bp_target_info *)
+    override;
+
+  int remove_hw_breakpoint (struct gdbarch *, struct bp_target_info *)
+    override;
+
+  int region_ok_for_hw_watchpoint (CORE_ADDR, int) override;
+
+  int insert_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
+ struct expression *) override;
+
+  int remove_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
+ struct expression *) override;
+
+  int insert_mask_watchpoint (CORE_ADDR, CORE_ADDR, enum target_hw_bp_type)
+    override;
+
+  int remove_mask_watchpoint (CORE_ADDR, CORE_ADDR, enum target_hw_bp_type)
+    override;
+
+  int stopped_by_watchpoint () override;
+
+  int stopped_data_address (CORE_ADDR *) override;
+
+  int watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int) override;
+
+  int can_accel_watchpoint_condition (CORE_ADDR, int, int, struct expression *)
+    override;
+
+  int masked_watch_num_registers (CORE_ADDR, CORE_ADDR) override;
+
+  int ranged_break_num_registers () override;
+
+  const struct target_desc *read_description ()  override;
+
+  int auxv_parse (gdb_byte **readptr,
+  gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+    override;
+};
+
+static ppc_linux_nat_target the_ppc_linux_nat_target;
+
 /* *INDENT-OFF* */
 /* registers layout, as presented by the ptrace interface:
 PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5, PT_R6, PT_R7,
@@ -806,9 +857,8 @@ fetch_ppc_registers (struct regcache *regcache, int tid)
 /* Fetch registers from the child process.  Fetch all registers if
    regno == -1, otherwise fetch all general registers or all floating
    point registers depending upon the value of regno.  */
-static void
-ppc_linux_fetch_inferior_registers (struct target_ops *ops,
-    struct regcache *regcache, int regno)
+void
+ppc_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   pid_t tid = get_ptrace_pid (regcache_get_ptid (regcache));
 
@@ -1385,9 +1435,8 @@ have_ptrace_hwdebug_interface (void)
   return have_ptrace_hwdebug_interface;
 }
 
-static int
-ppc_linux_can_use_hw_breakpoint (struct target_ops *self,
- enum bptype type, int cnt, int ot)
+int
+ppc_linux_nat_target::can_use_hw_breakpoint (enum bptype type, int cnt, int ot)
 {
   int total_hw_wp, total_hw_bp;
 
@@ -1443,9 +1492,8 @@ ppc_linux_can_use_hw_breakpoint (struct target_ops *self,
   return 1;
 }
 
-static int
-ppc_linux_region_ok_for_hw_watchpoint (struct target_ops *self,
-       CORE_ADDR addr, int len)
+int
+ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
 {
   /* Handle sub-8-byte quantities.  */
   if (len <= 0)
@@ -1603,8 +1651,8 @@ hwdebug_remove_point (struct ppc_hw_breakpoint *b, int tid)
 
 /* Return the number of registers needed for a ranged breakpoint.  */
 
-static int
-ppc_linux_ranged_break_num_registers (struct target_ops *target)
+int
+ppc_linux_nat_target::ranged_break_num_registers ()
 {
   return ((have_ptrace_hwdebug_interface ()
    && hwdebug_info.features & PPC_DEBUG_FEATURE_INSN_BP_RANGE)?
@@ -1614,10 +1662,9 @@ ppc_linux_ranged_break_num_registers (struct target_ops *target)
 /* Insert the hardware breakpoint described by BP_TGT.  Returns 0 for
    success, 1 if hardware breakpoints are not supported or -1 for failure.  */
 
-static int
-ppc_linux_insert_hw_breakpoint (struct target_ops *self,
- struct gdbarch *gdbarch,
-  struct bp_target_info *bp_tgt)
+int
+ppc_linux_nat_target::insert_hw_breakpoint (struct gdbarch *gdbarch,
+    struct bp_target_info *bp_tgt)
 {
   struct lwp_info *lp;
   struct ppc_hw_breakpoint p;
@@ -1651,10 +1698,9 @@ ppc_linux_insert_hw_breakpoint (struct target_ops *self,
   return 0;
 }
 
-static int
-ppc_linux_remove_hw_breakpoint (struct target_ops *self,
- struct gdbarch *gdbarch,
-  struct bp_target_info *bp_tgt)
+int
+ppc_linux_nat_target::remove_hw_breakpoint (struct gdbarch *gdbarch,
+    struct bp_target_info *bp_tgt)
 {
   struct lwp_info *lp;
   struct ppc_hw_breakpoint p;
@@ -1708,9 +1754,9 @@ get_trigger_type (enum target_hw_bp_type type)
    or hw_access for an access watchpoint.  Returns 0 on success and throws
    an error on failure.  */
 
-static int
-ppc_linux_insert_mask_watchpoint (struct target_ops *ops, CORE_ADDR addr,
-  CORE_ADDR mask, enum target_hw_bp_type rw)
+int
+ppc_linux_nat_target::insert_mask_watchpoint (CORE_ADDR addr,  CORE_ADDR mask,
+      target_hw_bp_type rw)
 {
   struct lwp_info *lp;
   struct ppc_hw_breakpoint p;
@@ -1736,9 +1782,9 @@ ppc_linux_insert_mask_watchpoint (struct target_ops *ops, CORE_ADDR addr,
    or hw_access for an access watchpoint.  Returns 0 on success and throws
    an error on failure.  */
 
-static int
-ppc_linux_remove_mask_watchpoint (struct target_ops *ops, CORE_ADDR addr,
-  CORE_ADDR mask, enum target_hw_bp_type rw)
+int
+ppc_linux_nat_target::remove_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask,
+      target_hw_bp_type rw)
 {
   struct lwp_info *lp;
   struct ppc_hw_breakpoint p;
@@ -1940,10 +1986,10 @@ check_condition (CORE_ADDR watch_addr, struct expression *cond,
 /* Return non-zero if the target is capable of using hardware to evaluate
    the condition expression, thus only triggering the watchpoint when it is
    true.  */
-static int
-ppc_linux_can_accel_watchpoint_condition (struct target_ops *self,
-  CORE_ADDR addr, int len, int rw,
-  struct expression *cond)
+int
+ppc_linux_nat_target::can_accel_watchpoint_condition (CORE_ADDR addr, int len,
+      int rw,
+      struct expression *cond)
 {
   CORE_ADDR data_value;
 
@@ -2003,10 +2049,10 @@ create_watchpoint_request (struct ppc_hw_breakpoint *p, CORE_ADDR addr,
   p->addr = (uint64_t) addr;
 }
 
-static int
-ppc_linux_insert_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
-     enum target_hw_bp_type type,
-     struct expression *cond)
+int
+ppc_linux_nat_target::insert_watchpoint (CORE_ADDR addr, int len,
+ enum target_hw_bp_type type,
+ struct expression *cond)
 {
   struct lwp_info *lp;
   int ret = -1;
@@ -2072,10 +2118,10 @@ ppc_linux_insert_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
   return ret;
 }
 
-static int
-ppc_linux_remove_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
-     enum target_hw_bp_type type,
-     struct expression *cond)
+int
+ppc_linux_nat_target::remove_watchpoint (CORE_ADDR addr, int len,
+ enum target_hw_bp_type type,
+ struct expression *cond)
 {
   struct lwp_info *lp;
   int ret = -1;
@@ -2176,8 +2222,8 @@ ppc_linux_thread_exit (struct thread_info *tp, int silent)
   xfree (t);
 }
 
-static int
-ppc_linux_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
+int
+ppc_linux_nat_target::stopped_data_address (CORE_ADDR *addr_p)
 {
   siginfo_t siginfo;
 
@@ -2215,17 +2261,17 @@ ppc_linux_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
   return 1;
 }
 
-static int
-ppc_linux_stopped_by_watchpoint (struct target_ops *ops)
+int
+ppc_linux_nat_target::stopped_by_watchpoint ()
 {
   CORE_ADDR addr;
-  return ppc_linux_stopped_data_address (ops, &addr);
+  return stopped_data_address (&addr);
 }
 
-static int
-ppc_linux_watchpoint_addr_within_range (struct target_ops *target,
- CORE_ADDR addr,
- CORE_ADDR start, int length)
+int
+ppc_linux_nat_target::watchpoint_addr_within_range (CORE_ADDR addr,
+    CORE_ADDR start,
+    int length)
 {
   int mask;
 
@@ -2245,9 +2291,8 @@ ppc_linux_watchpoint_addr_within_range (struct target_ops *target,
 
 /* Return the number of registers needed for a masked hardware watchpoint.  */
 
-static int
-ppc_linux_masked_watch_num_registers (struct target_ops *target,
-      CORE_ADDR addr, CORE_ADDR mask)
+int
+ppc_linux_nat_target::masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask)
 {
   if (!have_ptrace_hwdebug_interface ()
    || (hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_MASK) == 0)
@@ -2263,9 +2308,8 @@ ppc_linux_masked_watch_num_registers (struct target_ops *target,
     return 2;
 }
 
-static void
-ppc_linux_store_inferior_registers (struct target_ops *ops,
-    struct regcache *regcache, int regno)
+void
+ppc_linux_nat_target::store_registers (struct regcache *regcache, int regno)
 {
   pid_t tid = get_ptrace_pid (regcache_get_ptid (regcache));
 
@@ -2342,9 +2386,10 @@ ppc_linux_target_wordsize (void)
   return wordsize;
 }
 
-static int
-ppc_linux_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
-                      gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+int
+ppc_linux_nat_target::auxv_parse (gdb_byte **readptr,
+  gdb_byte *endptr, CORE_ADDR *typep,
+  CORE_ADDR *valp)
 {
   int sizeof_auxv_field = ppc_linux_target_wordsize ();
   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
@@ -2365,8 +2410,8 @@ ppc_linux_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
   return 1;
 }
 
-static const struct target_desc *
-ppc_linux_read_description (struct target_ops *ops)
+const struct target_desc *
+ppc_linux_nat_target::read_description ()
 {
   int altivec = 0;
   int vsx = 0;
@@ -2456,38 +2501,12 @@ ppc_linux_read_description (struct target_ops *ops)
 void
 _initialize_ppc_linux_nat (void)
 {
-  struct target_ops *t;
-
-  /* Fill in the generic GNU/Linux methods.  */
-  t = linux_target ();
-
-  /* Add our register access methods.  */
-  t->to_fetch_registers = ppc_linux_fetch_inferior_registers;
-  t->to_store_registers = ppc_linux_store_inferior_registers;
-
-  /* Add our breakpoint/watchpoint methods.  */
-  t->to_can_use_hw_breakpoint = ppc_linux_can_use_hw_breakpoint;
-  t->to_insert_hw_breakpoint = ppc_linux_insert_hw_breakpoint;
-  t->to_remove_hw_breakpoint = ppc_linux_remove_hw_breakpoint;
-  t->to_region_ok_for_hw_watchpoint = ppc_linux_region_ok_for_hw_watchpoint;
-  t->to_insert_watchpoint = ppc_linux_insert_watchpoint;
-  t->to_remove_watchpoint = ppc_linux_remove_watchpoint;
-  t->to_insert_mask_watchpoint = ppc_linux_insert_mask_watchpoint;
-  t->to_remove_mask_watchpoint = ppc_linux_remove_mask_watchpoint;
-  t->to_stopped_by_watchpoint = ppc_linux_stopped_by_watchpoint;
-  t->to_stopped_data_address = ppc_linux_stopped_data_address;
-  t->to_watchpoint_addr_within_range = ppc_linux_watchpoint_addr_within_range;
-  t->to_can_accel_watchpoint_condition
-    = ppc_linux_can_accel_watchpoint_condition;
-  t->to_masked_watch_num_registers = ppc_linux_masked_watch_num_registers;
-  t->to_ranged_break_num_registers = ppc_linux_ranged_break_num_registers;
-
-  t->to_read_description = ppc_linux_read_description;
-  t->to_auxv_parse = ppc_linux_auxv_parse;
+  linux_target = &the_ppc_linux_nat_target;
 
   gdb::observers::thread_exit.attach (ppc_linux_thread_exit);
 
   /* Register the target.  */
-  linux_nat_add_target (t);
-  linux_nat_set_new_thread (t, ppc_linux_new_thread);
+  add_target (linux_target);
+
+  linux_nat_set_new_thread (linux_target, ppc_linux_new_thread);
 }
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 15/40] target_ops/C++: Solaris/procfs

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.  I'd tested this on a Solaris VM.
---
 gdb/procfs.c     | 304 ++++++++++++++++++++++++-------------------------------
 gdb/sol-thread.c | 165 +++++++++++++++---------------
 2 files changed, 220 insertions(+), 249 deletions(-)

diff --git a/gdb/procfs.c b/gdb/procfs.c
index 478770d0fe..abae358c44 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -86,69 +86,88 @@
 
 /* This module defines the GDB target vector and its methods.  */
 
-static void procfs_attach (struct target_ops *, const char *, int);
-static void procfs_detach (struct target_ops *, inferior *, int);
-static void procfs_resume (struct target_ops *,
-   ptid_t, int, enum gdb_signal);
-static void procfs_files_info (struct target_ops *);
-static void procfs_fetch_registers (struct target_ops *,
-    struct regcache *, int);
-static void procfs_store_registers (struct target_ops *,
-    struct regcache *, int);
-static void procfs_pass_signals (struct target_ops *self,
- int, unsigned char *);
-static void procfs_kill_inferior (struct target_ops *ops);
-static void procfs_mourn_inferior (struct target_ops *ops);
-static void procfs_create_inferior (struct target_ops *, const char *,
-    const std::string &, char **, int);
-static ptid_t procfs_wait (struct target_ops *,
-   ptid_t, struct target_waitstatus *, int);
+
 static enum target_xfer_status procfs_xfer_memory (gdb_byte *,
    const gdb_byte *,
    ULONGEST, ULONGEST,
    ULONGEST *);
-static target_xfer_partial_ftype procfs_xfer_partial;
 
-static int procfs_thread_alive (struct target_ops *ops, ptid_t);
+class procfs_target final : public inf_child_target
+{
+public:
+  void create_inferior (const char *, const std::string &,
+ char **, int) override;
+
+  void kill () override;
+
+  void mourn_inferior () override;
+
+  void attach (const char *, int) override;
+  void detach (inferior *inf, int) override;
+
+  void resume (ptid_t, int, enum gdb_signal) override;
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+  void pass_signals (int, unsigned char *) override;
 
-static void procfs_update_thread_list (struct target_ops *ops);
-static const char *procfs_pid_to_str (struct target_ops *, ptid_t);
+  void files_info () override;
 
-static int proc_find_memory_regions (struct target_ops *self,
-     find_memory_region_ftype, void *);
+  void update_thread_list () override;
 
-static char *procfs_make_note_section (struct target_ops *self,
-       bfd *, int *);
+  int thread_alive (ptid_t ptid) override;
 
-static int procfs_can_use_hw_breakpoint (struct target_ops *self,
- enum bptype, int, int);
+  const char *pid_to_str (ptid_t) override;
 
-static void procfs_info_proc (struct target_ops *, const char *,
-      enum info_proc_what);
+  thread_control_capabilities get_thread_control_capabilities () override
+  { return tc_schedlock; }
 
-static int procfs_stopped_by_watchpoint (struct target_ops *);
+  /* find_memory_regions support method for gcore */
+  int find_memory_regions (find_memory_region_ftype func, void *data)
+    override;
 
-static int procfs_insert_watchpoint (struct target_ops *,
-     CORE_ADDR, int,
-     enum target_hw_bp_type,
-     struct expression *);
+  char *make_corefile_notes (bfd *, int *) override;
 
-static int procfs_remove_watchpoint (struct target_ops *,
-     CORE_ADDR, int,
-     enum target_hw_bp_type,
-     struct expression *);
+  bool info_proc (const char *, enum info_proc_what) override;
+
+#if defined(PR_MODEL_NATIVE) && (PR_MODEL_NATIVE == PR_MODEL_LP64)
+  int auxv_parse (gdb_byte **readptr,
+  gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+    override;
+#endif
+
+  int stopped_by_watchpoint () override;
+
+  int insert_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
+ struct expression *) override;
+
+  int remove_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
+ struct expression *) override;
+
+  int region_ok_for_hw_watchpoint (CORE_ADDR, int) override;
+
+  int can_use_hw_breakpoint (enum bptype, int, int) override;
+  int stopped_data_address (CORE_ADDR *) override;
+};
 
-static int procfs_region_ok_for_hw_watchpoint (struct target_ops *,
-       CORE_ADDR, int);
-static int procfs_stopped_data_address (struct target_ops *, CORE_ADDR *);
+static procfs_target the_procfs_target;
 
 #if defined (PR_MODEL_NATIVE) && (PR_MODEL_NATIVE == PR_MODEL_LP64)
 /* When GDB is built as 64-bit application on Solaris, the auxv data
    is presented in 64-bit format.  We need to provide a custom parser
    to handle that.  */
-static int
-procfs_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
-   gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+int
+procfs_target::auxv_parse (gdb_byte **readptr,
+   gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
   gdb_byte *ptr = *readptr;
@@ -171,51 +190,6 @@ procfs_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
 }
 #endif
 
-/* Create a procfs target.  */
-
-static struct target_ops *
-procfs_target (void)
-{
-  struct target_ops *t = inf_child_target ();
-
-  t->to_create_inferior = procfs_create_inferior;
-  t->to_kill = procfs_kill_inferior;
-  t->to_mourn_inferior = procfs_mourn_inferior;
-  t->to_attach = procfs_attach;
-  t->to_detach = procfs_detach;
-  t->to_wait = procfs_wait;
-  t->to_resume = procfs_resume;
-  t->to_fetch_registers = procfs_fetch_registers;
-  t->to_store_registers = procfs_store_registers;
-  t->to_xfer_partial = procfs_xfer_partial;
-  t->to_pass_signals = procfs_pass_signals;
-  t->to_files_info = procfs_files_info;
-
-  t->to_update_thread_list = procfs_update_thread_list;
-  t->to_thread_alive = procfs_thread_alive;
-  t->to_pid_to_str = procfs_pid_to_str;
-
-  t->to_has_thread_control = tc_schedlock;
-  t->to_find_memory_regions = proc_find_memory_regions;
-  t->to_make_corefile_notes = procfs_make_note_section;
-  t->to_info_proc = procfs_info_proc;
-
-#if defined(PR_MODEL_NATIVE) && (PR_MODEL_NATIVE == PR_MODEL_LP64)
-  t->to_auxv_parse = procfs_auxv_parse;
-#endif
-
-  t->to_stopped_by_watchpoint = procfs_stopped_by_watchpoint;
-  t->to_insert_watchpoint = procfs_insert_watchpoint;
-  t->to_remove_watchpoint = procfs_remove_watchpoint;
-  t->to_region_ok_for_hw_watchpoint = procfs_region_ok_for_hw_watchpoint;
-  t->to_can_use_hw_breakpoint = procfs_can_use_hw_breakpoint;
-  t->to_stopped_data_address = procfs_stopped_data_address;
-
-  t->to_magic = OPS_MAGIC;
-
-  return t;
-}
-
 /* =================== END, TARGET_OPS "MODULE" =================== */
 
 /* World Unification:
@@ -1912,8 +1886,8 @@ procfs_debug_inferior (procinfo *pi)
   return 0;
 }
 
-static void
-procfs_attach (struct target_ops *ops, const char *args, int from_tty)
+void
+procfs_target::attach (const char *args, int from_tty)
 {
   char *exec_file;
   int   pid;
@@ -1937,12 +1911,12 @@ procfs_attach (struct target_ops *ops, const char *args, int from_tty)
       fflush (stdout);
     }
   inferior_ptid = do_attach (pid_to_ptid (pid));
-  if (!target_is_pushed (ops))
-    push_target (ops);
+  if (!target_is_pushed (this))
+    push_target (this);
 }
 
-static void
-procfs_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+procfs_target::detach (inferior *inf, int from_tty)
 {
   int pid = ptid_get_pid (inferior_ptid);
 
@@ -1963,7 +1937,7 @@ procfs_detach (struct target_ops *ops, inferior *inf, int from_tty)
 
   inferior_ptid = null_ptid;
   detach_inferior (pid);
-  inf_child_maybe_unpush_target (ops);
+  maybe_unpush_target ();
 }
 
 static ptid_t
@@ -2092,9 +2066,8 @@ do_detach ()
    registers.  So we cache the results, and mark the cache invalid
    when the process is resumed.  */
 
-static void
-procfs_fetch_registers (struct target_ops *ops,
- struct regcache *regcache, int regnum)
+void
+procfs_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   gdb_gregset_t *gregs;
   procinfo *pi;
@@ -2142,9 +2115,8 @@ procfs_fetch_registers (struct target_ops *ops,
    FIXME: is that a really bad idea?  Have to think about cases where
    writing one register might affect the value of others, etc.  */
 
-static void
-procfs_store_registers (struct target_ops *ops,
- struct regcache *regcache, int regnum)
+void
+procfs_target::store_registers (struct regcache *regcache, int regnum)
 {
   gdb_gregset_t *gregs;
   procinfo *pi;
@@ -2228,9 +2200,9 @@ syscall_is_lwp_create (procinfo *pi, int scall)
    Returns the id of process (and possibly thread) that incurred the
    event.  Event codes are returned through a pointer parameter.  */
 
-static ptid_t
-procfs_wait (struct target_ops *ops,
-     ptid_t ptid, struct target_waitstatus *status, int options)
+ptid_t
+procfs_target::wait (ptid_t ptid, struct target_waitstatus *status,
+     int options)
 {
   /* First cut: loosely based on original version 2.1.  */
   procinfo *pi;
@@ -2271,7 +2243,7 @@ wait_again:
       int wait_retval;
 
       /* /proc file not found; presumably child has terminated.  */
-      wait_retval = wait (&wstat); /* "wait" for the child's exit.  */
+      wait_retval = ::wait (&wstat); /* "wait" for the child's exit.  */
 
       /* Wrong child?  */
       if (wait_retval != ptid_get_pid (inferior_ptid))
@@ -2364,7 +2336,7 @@ wait_again:
       }
     else
       {
- int temp = wait (&wstat);
+ int temp = ::wait (&wstat);
 
  /* FIXME: shouldn't I make sure I get the right
    event from the right process?  If (for
@@ -2594,11 +2566,11 @@ wait_again:
 /* Perform a partial transfer to/from the specified object.  For
    memory transfers, fall back to the old memory xfer functions.  */
 
-static enum target_xfer_status
-procfs_xfer_partial (struct target_ops *ops, enum target_object object,
-     const char *annex, gdb_byte *readbuf,
-     const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
-     ULONGEST *xfered_len)
+enum target_xfer_status
+procfs_target::xfer_partial (enum target_object object,
+     const char *annex, gdb_byte *readbuf,
+     const gdb_byte *writebuf, ULONGEST offset,
+     ULONGEST len, ULONGEST *xfered_len)
 {
   switch (object)
     {
@@ -2606,13 +2578,13 @@ procfs_xfer_partial (struct target_ops *ops, enum target_object object,
       return procfs_xfer_memory (readbuf, writebuf, offset, len, xfered_len);
 
     case TARGET_OBJECT_AUXV:
-      return memory_xfer_auxv (ops, object, annex, readbuf, writebuf,
+      return memory_xfer_auxv (this, object, annex, readbuf, writebuf,
        offset, len, xfered_len);
 
     default:
-      return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
-    readbuf, writebuf, offset, len,
-    xfered_len);
+      return this->beneath->xfer_partial (object, annex,
+  readbuf, writebuf, offset, len,
+  xfered_len);
     }
 }
 
@@ -2741,9 +2713,8 @@ make_signal_thread_runnable (procinfo *process, procinfo *pi, void *ptr)
    allow any child thread to run; if non-zero, then allow only the
    indicated thread to run.  (not implemented yet).  */
 
-static void
-procfs_resume (struct target_ops *ops,
-       ptid_t ptid, int step, enum gdb_signal signo)
+void
+procfs_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
 {
   procinfo *pi, *thread;
   int native_signo;
@@ -2821,9 +2792,8 @@ procfs_resume (struct target_ops *ops,
 
 /* Set up to trace signals in the child process.  */
 
-static void
-procfs_pass_signals (struct target_ops *self,
-     int numsigs, unsigned char *pass_signals)
+void
+procfs_target::pass_signals (int numsigs, unsigned char *pass_signals)
 {
   sigset_t signals;
   procinfo *pi = find_procinfo_or_die (ptid_get_pid (inferior_ptid), 0);
@@ -2844,8 +2814,8 @@ procfs_pass_signals (struct target_ops *self,
 
 /* Print status information about the child process.  */
 
-static void
-procfs_files_info (struct target_ops *ignore)
+void
+procfs_target::files_info ()
 {
   struct inferior *inf = current_inferior ();
 
@@ -2887,8 +2857,8 @@ unconditionally_kill_inferior (procinfo *pi)
 /* We're done debugging it, and we want it to go away.  Then we want
    GDB to forget all about it.  */
 
-static void
-procfs_kill_inferior (struct target_ops *ops)
+void
+procfs_target::kill ()
 {
   if (!ptid_equal (inferior_ptid, null_ptid)) /* ? */
     {
@@ -2903,8 +2873,8 @@ procfs_kill_inferior (struct target_ops *ops)
 
 /* Forget we ever debugged this thing!  */
 
-static void
-procfs_mourn_inferior (struct target_ops *ops)
+void
+procfs_target::mourn_inferior ()
 {
   procinfo *pi;
 
@@ -2918,7 +2888,7 @@ procfs_mourn_inferior (struct target_ops *ops)
 
   generic_mourn_inferior ();
 
-  inf_child_maybe_unpush_target (ops);
+  maybe_unpush_target ();
 }
 
 /* When GDB forks to create a runnable inferior process, this function
@@ -3081,9 +3051,10 @@ procfs_set_exec_trap (void)
    abstracted out and shared with other unix targets such as
    inf-ptrace?  */
 
-static void
-procfs_create_inferior (struct target_ops *ops, const char *exec_file,
- const std::string &allargs, char **env, int from_tty)
+void
+procfs_target::create_inferior (const char *exec_file,
+ const std::string &allargs,
+ char **env, int from_tty)
 {
   char *shell_file = getenv ("SHELL");
   char *tryname;
@@ -3165,7 +3136,7 @@ procfs_create_inferior (struct target_ops *ops, const char *exec_file,
      pid shouldn't change.  */
   add_thread_silent (pid_to_ptid (pid));
 
-  procfs_init_inferior (ops, pid);
+  procfs_init_inferior (this, pid);
 }
 
 /* An observer for the "inferior_created" event.  */
@@ -3191,8 +3162,8 @@ procfs_notice_thread (procinfo *pi, procinfo *thread, void *ptr)
 /* Query all the threads that the target knows about, and give them
    back to GDB to add to its list.  */
 
-static void
-procfs_update_thread_list (struct target_ops *ops)
+void
+procfs_target::update_thread_list ()
 {
   procinfo *pi;
 
@@ -3208,8 +3179,8 @@ procfs_update_thread_list (struct target_ops *ops)
    really seem to be doing his job.  Got to investigate how to tell
    when a thread is really gone.  */
 
-static int
-procfs_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+procfs_target::thread_alive (ptid_t ptid)
 {
   int proc, thread;
   procinfo *pi;
@@ -3235,8 +3206,8 @@ procfs_thread_alive (struct target_ops *ops, ptid_t ptid)
 /* Convert PTID to a string.  Returns the string in a static
    buffer.  */
 
-static const char *
-procfs_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+procfs_target::pid_to_str (ptid_t ptid)
 {
   static char buf[80];
 
@@ -3306,10 +3277,8 @@ procfs_set_watchpoint (ptid_t ptid, CORE_ADDR addr, int len, int rwflag,
    procfs.c targets due to the fact that some of them still define
    target_can_use_hardware_watchpoint.  */
 
-static int
-procfs_can_use_hw_breakpoint (struct target_ops *self,
-      enum bptype type,
-      int cnt, int othertype)
+int
+procfs_target::can_use_hw_breakpoint (enum bptype type, int cnt, int othertype)
 {
   /* Due to the way that proc_set_watchpoint() is implemented, host
      and target pointers must be of the same size.  If they are not,
@@ -3332,8 +3301,8 @@ procfs_can_use_hw_breakpoint (struct target_ops *self,
 /* Returns non-zero if process is stopped on a hardware watchpoint
    fault, else returns zero.  */
 
-static int
-procfs_stopped_by_watchpoint (struct target_ops *ops)
+int
+procfs_target::stopped_by_watchpoint ()
 {
   procinfo *pi;
 
@@ -3356,8 +3325,8 @@ procfs_stopped_by_watchpoint (struct target_ops *ops)
    procfs_stopped_by_watchpoint returned 1, thus no further checks are
    done.  The function also assumes that ADDR is not NULL.  */
 
-static int
-procfs_stopped_data_address (struct target_ops *targ, CORE_ADDR *addr)
+int
+procfs_target::stopped_data_address (CORE_ADDR *addr)
 {
   procinfo *pi;
 
@@ -3365,11 +3334,10 @@ procfs_stopped_data_address (struct target_ops *targ, CORE_ADDR *addr)
   return proc_watchpoint_address (pi, addr);
 }
 
-static int
-procfs_insert_watchpoint (struct target_ops *self,
-  CORE_ADDR addr, int len,
-  enum target_hw_bp_type type,
-  struct expression *cond)
+int
+procfs_target::insert_watchpoint (CORE_ADDR addr, int len,
+  enum target_hw_bp_type type,
+  struct expression *cond)
 {
   if (!target_have_steppable_watchpoint
       && !gdbarch_have_nonsteppable_watchpoint (target_gdbarch ()))
@@ -3389,18 +3357,16 @@ procfs_insert_watchpoint (struct target_ops *self,
     }
 }
 
-static int
-procfs_remove_watchpoint (struct target_ops *self,
-  CORE_ADDR addr, int len,
-  enum target_hw_bp_type type,
-  struct expression *cond)
+int
+procfs_target::remove_watchpoint (CORE_ADDR addr, int len,
+  enum target_hw_bp_type type,
+  struct expression *cond)
 {
   return procfs_set_watchpoint (inferior_ptid, addr, 0, 0, 0);
 }
 
-static int
-procfs_region_ok_for_hw_watchpoint (struct target_ops *self,
-    CORE_ADDR addr, int len)
+int
+procfs_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
 {
   /* The man page for proc(4) on Solaris 2.6 and up says that the
      system can support "thousands" of hardware watchpoints, but gives
@@ -3494,9 +3460,8 @@ find_memory_regions_callback (struct prmap *map,
    Stops iterating and returns the first non-zero value returned by
    the callback.  */
 
-static int
-proc_find_memory_regions (struct target_ops *self,
-  find_memory_region_ftype func, void *data)
+int
+procfs_target::find_memory_regions (find_memory_region_ftype func, void *data)
 {
   procinfo *pi = find_procinfo_or_die (ptid_get_pid (inferior_ptid), 0);
 
@@ -3586,9 +3551,8 @@ info_proc_mappings (procinfo *pi, int summary)
 
 /* Implement the "info proc" command.  */
 
-static void
-procfs_info_proc (struct target_ops *ops, const char *args,
-  enum info_proc_what what)
+bool
+procfs_target::info_proc (const char *args, enum info_proc_what what)
 {
   struct cleanup *old_chain;
   procinfo *process  = NULL;
@@ -3673,6 +3637,8 @@ procfs_info_proc (struct target_ops *ops, const char *args,
     }
 
   do_cleanups (old_chain);
+
+  return true;
 }
 
 /* Modify the status of the system call identified by SYSCALLNUM in
@@ -3773,7 +3739,7 @@ _initialize_procfs (void)
   add_com ("proc-untrace-exit", no_class, proc_untrace_sysexit_cmd,
    _("Cancel a trace of exits from the syscall."));
 
-  add_target (procfs_target ());
+  add_target (&the_procfs_target);
 }
 
 /* =================== END, GDB  "MODULE" =================== */
@@ -3881,8 +3847,8 @@ find_stop_signal (void)
     return GDB_SIGNAL_0;
 }
 
-static char *
-procfs_make_note_section (struct target_ops *self, bfd *obfd, int *note_size)
+char *
+procfs_target::make_corefile_notes (bfd *obfd, int *note_size)
 {
   struct cleanup *old_chain;
   gdb_gregset_t gregs;
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
index 62d839cd41..0572da30c0 100644
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -69,7 +69,41 @@
 #include "minsyms.h"
 #include "objfiles.h"
 
-struct target_ops sol_thread_ops;
+class sol_thread_target : 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."); }
+
+  void detach (inferior *, int) override;
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+  void resume (ptid_t, int, enum gdb_signal) override;
+  void mourn_inferior () override;
+  const char *pid_to_str (ptid_t) override;
+  ptid_t get_ada_task_ptid (long lwp, long thread) override;
+
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+  int thread_alive (ptid_t ptid) override;
+  void update_thread_list () override;
+};
+
+static sol_thread_target sol_thread_ops;
 
 /* Prototypes for supply_gregset etc.  */
 #include "gregset.h"
@@ -93,8 +127,6 @@ static struct ps_prochandle main_ph;
 static td_thragent_t *main_ta;
 static int sol_thread_active = 0;
 
-static void init_sol_thread_ops (void);
-
 /* Default definitions: These must be defined in tm.h if they are to
    be shared with a process module such as procfs.  */
 
@@ -347,15 +379,15 @@ lwp_to_thread (ptid_t lwp)
    process to have been previously attached.  It *might* work if the
    program was started via the normal ptrace (PTRACE_TRACEME).  */
 
-static void
-sol_thread_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+sol_thread_target::detach (inferior *inf, int from_tty)
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   sol_thread_active = 0;
   inferior_ptid = pid_to_ptid (ptid_get_pid (main_ph.ptid));
-  unpush_target (ops);
-  beneath->to_detach (beneath, inf, from_tty);
+  unpush_target (this);
+  beneath->detach (inf, from_tty);
 }
 
 /* Resume execution of process PTID.  If STEP is nozero, then just
@@ -363,11 +395,10 @@ sol_thread_detach (struct target_ops *ops, inferior *inf, int from_tty)
    activated.  We may have to convert PTID from a thread ID to an LWP
    ID for procfs.  */
 
-static void
-sol_thread_resume (struct target_ops *ops,
-   ptid_t ptid, int step, enum gdb_signal signo)
+void
+sol_thread_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
 
@@ -387,19 +418,19 @@ sol_thread_resume (struct target_ops *ops,
  ptid_get_tid (save_ptid));
     }
 
-  beneath->to_resume (beneath, ptid, step, signo);
+  beneath->resume (ptid, step, signo);
 }
 
 /* Wait for any threads to stop.  We may have to convert PTID from a
    thread ID to an LWP ID, and vice versa on the way out.  */
 
-static ptid_t
-sol_thread_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus, int options)
+ptid_t
+sol_thread_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
+ int options)
 {
   ptid_t rtnval;
   ptid_t save_ptid;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   save_ptid = inferior_ptid;
   scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
@@ -420,7 +451,7 @@ sol_thread_wait (struct target_ops *ops,
  ptid_get_tid (save_ptid));
     }
 
-  rtnval = beneath->to_wait (beneath, ptid, ourstatus, options);
+  rtnval = beneath->wait (ptid, ourstatus, options);
 
   if (ourstatus->kind != TARGET_WAITKIND_EXITED)
     {
@@ -444,9 +475,8 @@ sol_thread_wait (struct target_ops *ops,
   return rtnval;
 }
 
-static void
-sol_thread_fetch_registers (struct target_ops *ops,
-    struct regcache *regcache, int regnum)
+void
+sol_thread_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   thread_t thread;
   td_thrhandle_t thandle;
@@ -455,13 +485,13 @@ sol_thread_fetch_registers (struct target_ops *ops,
   prfpregset_t fpregset;
   gdb_gregset_t *gregset_p = &gregset;
   gdb_fpregset_t *fpregset_p = &fpregset;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
   ptid_t ptid = regcache_get_ptid (regcache);
 
   if (!ptid_tid_p (ptid))
     {
       /* It's an LWP; pass the request on to the layer beneath.  */
-      beneath->to_fetch_registers (beneath, regcache, regnum);
+      beneath->fetch_registers (regcache, regnum);
       return;
     }
 
@@ -500,9 +530,8 @@ sol_thread_fetch_registers (struct target_ops *ops,
   supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset_p);
 }
 
-static void
-sol_thread_store_registers (struct target_ops *ops,
-    struct regcache *regcache, int regnum)
+void
+sol_thread_target::store_registers (struct regcache *regcache, int regnum)
 {
   thread_t thread;
   td_thrhandle_t thandle;
@@ -513,10 +542,10 @@ sol_thread_store_registers (struct target_ops *ops,
 
   if (!ptid_tid_p (ptid))
     {
-      struct target_ops *beneath = find_target_beneath (ops);
+      struct target_ops *beneath = find_target_beneath (this);
 
       /* It's an LWP; pass the request on to the layer beneath.  */
-      beneath->to_store_registers (beneath, regcache, regnum);
+      beneath->store_registers (regcache, regnum);
       return;
     }
 
@@ -557,13 +586,14 @@ sol_thread_store_registers (struct target_ops *ops,
    target_write_partial for details of each variant.  One, and only
    one, of readbuf or writebuf must be non-NULL.  */
 
-static enum target_xfer_status
-sol_thread_xfer_partial (struct target_ops *ops, enum target_object object,
-  const char *annex, gdb_byte *readbuf,
-  const gdb_byte *writebuf,
- ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+sol_thread_target::xfer_partial (enum target_object object,
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len)
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
 
@@ -577,8 +607,8 @@ sol_thread_xfer_partial (struct target_ops *ops, enum target_object object,
       inferior_ptid = procfs_first_available ();
     }
 
-  return beneath->to_xfer_partial (beneath, object, annex, readbuf,
-   writebuf, offset, len, xfered_len);
+  return beneath->xfer_partial (object, annex, readbuf,
+ writebuf, offset, len, xfered_len);
 }
 
 static void
@@ -588,7 +618,7 @@ check_for_thread_db (void)
   ptid_t ptid;
 
   /* Don't attempt to use thread_db for remote targets.  */
-  if (!(target_can_run (&current_target) || core_bfd))
+  if (!(target_can_run () || core_bfd))
     return;
 
   /* Do nothing if we couldn't load libthread_db.so.1.  */
@@ -656,22 +686,22 @@ sol_thread_new_objfile (struct objfile *objfile)
 
 /* Clean up after the inferior dies.  */
 
-static void
-sol_thread_mourn_inferior (struct target_ops *ops)
+void
+sol_thread_target::mourn_inferior ()
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   sol_thread_active = 0;
 
-  unpush_target (ops);
+  unpush_target (this);
 
-  beneath->to_mourn_inferior (beneath);
+  beneath->mourn_inferior ();
 }
 
 /* Return true if PTID is still active in the inferior.  */
 
-static int
-sol_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+sol_thread_target::thread_alive (ptid_t ptid)
 {
   if (ptid_tid_p (ptid))
     {
@@ -689,10 +719,10 @@ sol_thread_alive (struct target_ops *ops, ptid_t ptid)
     }
   else
     {
-      struct target_ops *beneath = find_target_beneath (ops);
+      struct target_ops *beneath = find_target_beneath (this);
 
       /* It's an LPW; pass the request on to the layer below.  */
-      return beneath->to_thread_alive (beneath, ptid);
+      return beneath->thread_alive (ptid);
     }
 }
 
@@ -976,8 +1006,8 @@ ps_lgetLDT (struct ps_prochandle *ph, lwpid_t lwpid,
 
 /* Convert PTID to printable form.  */
 
-static const char *
-solaris_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+sol_thread_target::pid_to_str (ptid_t ptid)
 {
   static char buf[100];
 
@@ -1027,16 +1057,16 @@ sol_update_thread_list_callback (const td_thrhandle_t *th, void *ignored)
   return 0;
 }
 
-static void
-sol_update_thread_list (struct target_ops *ops)
+void
+sol_thread_target::update_thread_list ()
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   /* Delete dead threads.  */
   prune_threads ();
 
   /* Find any new LWP's.  */
-  beneath->to_update_thread_list (beneath);
+  beneath->update_thread_list ();
 
   /* Then find any new user-level threads.  */
   p_td_ta_thr_iter (main_ta, sol_update_thread_list_callback, (void *) 0,
@@ -1143,8 +1173,8 @@ thread_db_find_thread_from_tid (struct thread_info *thread, void *data)
   return 0;
 }
 
-static ptid_t
-sol_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
+ptid_t
+sol_thread_target::get_ada_task_ptid (long lwp, long thread)
 {
   struct thread_info *thread_info =
     iterate_over_threads (thread_db_find_thread_from_tid, &thread);
@@ -1153,7 +1183,7 @@ sol_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
     {
       /* The list of threads is probably not up to date.  Find any
          thread that is missing from the list, and try again.  */
-      sol_update_thread_list (&current_target);
+      update_thread_list ();
       thread_info = iterate_over_threads (thread_db_find_thread_from_tid,
                                           &thread);
     }
@@ -1163,34 +1193,11 @@ sol_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
   return (thread_info->ptid);
 }
 
-static void
-init_sol_thread_ops (void)
-{
-  sol_thread_ops.to_shortname = "solaris-threads";
-  sol_thread_ops.to_longname = "Solaris threads and pthread.";
-  sol_thread_ops.to_doc = "Solaris threads and pthread support.";
-  sol_thread_ops.to_detach = sol_thread_detach;
-  sol_thread_ops.to_resume = sol_thread_resume;
-  sol_thread_ops.to_wait = sol_thread_wait;
-  sol_thread_ops.to_fetch_registers = sol_thread_fetch_registers;
-  sol_thread_ops.to_store_registers = sol_thread_store_registers;
-  sol_thread_ops.to_xfer_partial = sol_thread_xfer_partial;
-  sol_thread_ops.to_mourn_inferior = sol_thread_mourn_inferior;
-  sol_thread_ops.to_thread_alive = sol_thread_alive;
-  sol_thread_ops.to_pid_to_str = solaris_pid_to_str;
-  sol_thread_ops.to_update_thread_list = sol_update_thread_list;
-  sol_thread_ops.to_stratum = thread_stratum;
-  sol_thread_ops.to_get_ada_task_ptid = sol_get_ada_task_ptid;
-  sol_thread_ops.to_magic = OPS_MAGIC;
-}
-
 void
 _initialize_sol_thread (void)
 {
   void *dlhandle;
 
-  init_sol_thread_ops ();
-
   dlhandle = dlopen ("libthread_db.so.1", RTLD_NOW);
   if (!dlhandle)
     goto die;
@@ -1223,8 +1230,6 @@ _initialize_sol_thread (void)
   resolve (td_thr_getgregs);
   resolve (td_thr_setgregs);
 
-  complete_target_initialization (&sol_thread_ops);
-
   add_cmd ("sol-threads", class_maintenance, info_solthreads,
    _("Show info on Solaris user threads."), &maintenanceinfolist);
 
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 16/40] target_ops/C++: Windows targets

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.  I'd tested this with a cross compiler.
---
 gdb/windows-nat.c | 216 ++++++++++++++++++++++++++++--------------------------
 1 file changed, 114 insertions(+), 102 deletions(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 95e3c5816b..589ef47c67 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -201,10 +201,6 @@ typedef enum
 #define DEBUG_MEM(x) if (debug_memory) printf_unfiltered x
 #define DEBUG_EXCEPT(x) if (debug_exceptions) printf_unfiltered x
 
-static void windows_interrupt (struct target_ops *self);
-static int windows_thread_alive (struct target_ops *, ptid_t);
-static void windows_kill_inferior (struct target_ops *);
-
 static void cygwin_set_dr (int i, CORE_ADDR addr);
 static void cygwin_set_dr7 (unsigned long val);
 static CORE_ADDR cygwin_get_dr (int i);
@@ -302,6 +298,58 @@ static const struct xlate_exception
   {STATUS_FLOAT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE},
   {-1, GDB_SIGNAL_UNKNOWN}};
 
+
+struct windows_nat_target final : public x86_nat_target<inf_child_target>
+{
+  void close () override;
+
+  void attach (const char *, int) override;
+
+  bool attach_no_wait () override
+  { return true; }
+
+  void detach (inferior *, int) override;
+
+  void resume (ptid_t, int , enum gdb_signal) override;
+
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+  void files_info () override;
+
+  void kill () override;
+
+  void create_inferior (const char *, const std::string &,
+ char **, int) override;
+
+  void mourn_inferior () override;
+
+  int thread_alive (ptid_t ptid) override;
+
+  const char *pid_to_str (ptid_t) override;
+
+  void interrupt () override;
+
+  char *pid_to_exec_file (int pid) override;
+
+  ptid_t get_ada_task_ptid (long lwp, long thread) override;
+
+  int get_tib_address (ptid_t ptid, CORE_ADDR *addr) override;
+
+  const char *thread_name (struct thread_info *) override;
+};
+
+static windows_nat_target the_windows_nat_target;
+
 /* Set the MAPPINGS static global to OFFSETS.
    See the description of MAPPINGS for more details.  */
 
@@ -531,9 +579,8 @@ do_windows_fetch_inferior_registers (struct regcache *regcache,
     }
 }
 
-static void
-windows_fetch_inferior_registers (struct target_ops *ops,
-  struct regcache *regcache, int r)
+void
+windows_nat_target::fetch_registers (struct regcache *regcache, int r)
 {
   DWORD pid = ptid_get_tid (regcache_get_ptid (regcache));
   windows_thread_info *th = thread_rec (pid, TRUE);
@@ -560,9 +607,9 @@ do_windows_store_inferior_registers (const struct regcache *regcache,
 
 /* Store a new register value into the context of the thread tied to
    REGCACHE.  */
-static void
-windows_store_inferior_registers (struct target_ops *ops,
-  struct regcache *regcache, int r)
+
+void
+windows_nat_target::store_registers (struct regcache *regcache, int r)
 {
   DWORD pid = ptid_get_tid (regcache_get_ptid (regcache));
   windows_thread_info *th = thread_rec (pid, TRUE);
@@ -1310,9 +1357,8 @@ fake_create_process (void)
   return main_thread_id;
 }
 
-static void
-windows_resume (struct target_ops *ops,
- ptid_t ptid, int step, enum gdb_signal sig)
+void
+windows_nat_target::resume (ptid_t ptid, int step, enum gdb_signal sig)
 {
   windows_thread_info *th;
   DWORD continue_status = DBG_CONTINUE;
@@ -1373,8 +1419,7 @@ windows_resume (struct target_ops *ops,
   /* Single step by setting t bit.  */
   struct regcache *regcache = get_current_regcache ();
   struct gdbarch *gdbarch = regcache->arch ();
-  windows_fetch_inferior_registers (ops, regcache,
-    gdbarch_ps_regnum (gdbarch));
+  fetch_registers (regcache, gdbarch_ps_regnum (gdbarch));
   th->context.EFlags |= FLAG_TRACE_BIT;
  }
 
@@ -1631,9 +1676,9 @@ out:
 }
 
 /* Wait for interesting events to occur in the target process.  */
-static ptid_t
-windows_wait (struct target_ops *ops,
-      ptid_t ptid, struct target_waitstatus *ourstatus, int options)
+ptid_t
+windows_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
+  int options)
 {
   int pid = -1;
 
@@ -1676,7 +1721,7 @@ windows_wait (struct target_ops *ops,
      the user tries to resume the execution in the inferior.
      This is a classic race that we should try to fix one day.  */
       SetConsoleCtrlHandler (&ctrl_c_handler, TRUE);
-      retval = get_windows_debug_event (ops, pid, ourstatus);
+      retval = get_windows_debug_event (this, pid, ourstatus);
       SetConsoleCtrlHandler (&ctrl_c_handler, FALSE);
 
       if (retval)
@@ -1689,7 +1734,7 @@ windows_wait (struct target_ops *ops,
     detach = deprecated_ui_loop_hook (0);
 
   if (detach)
-    windows_kill_inferior (ops);
+    kill ();
  }
     }
 }
@@ -1791,7 +1836,7 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
     {
       struct target_waitstatus status;
 
-      windows_wait (ops, minus_one_ptid, &status, 0);
+      ops->wait (minus_one_ptid, &status, 0);
 
       /* Note windows_wait returns TARGET_WAITKIND_SPURIOUS for thread
  events.  */
@@ -1799,7 +1844,7 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
   && status.kind != TARGET_WAITKIND_SPURIOUS)
  break;
 
-      windows_resume (ops, minus_one_ptid, 0, GDB_SIGNAL_0);
+      ops->resume (minus_one_ptid, 0, GDB_SIGNAL_0);
     }
 
   /* Now that the inferior has been started and all DLLs have been mapped,
@@ -1873,8 +1918,9 @@ out:
 }
 
 /* Attach to process PID, then initialize for debugging it.  */
-static void
-windows_attach (struct target_ops *ops, const char *args, int from_tty)
+
+void
+windows_nat_target::attach (const char *args, int from_tty)
 {
   BOOL ok;
   DWORD pid;
@@ -1922,17 +1968,17 @@ windows_attach (struct target_ops *ops, const char *args, int from_tty)
       gdb_flush (gdb_stdout);
     }
 
-  do_initial_windows_stuff (ops, pid, 1);
+  do_initial_windows_stuff (this, pid, 1);
   target_terminal::ours ();
 }
 
-static void
-windows_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+windows_nat_target::detach (inferior *inf, int from_tty)
 {
   int detached = 1;
 
   ptid_t ptid = minus_one_ptid;
-  windows_resume (ops, ptid, 0, GDB_SIGNAL_0);
+  resume (ptid, 0, GDB_SIGNAL_0);
 
   if (!DebugActiveProcessStop (current_event.dwProcessId))
     {
@@ -1956,7 +2002,7 @@ windows_detach (struct target_ops *ops, inferior *inf, int from_tty)
   inferior_ptid = null_ptid;
   detach_inferior (current_event.dwProcessId);
 
-  inf_child_maybe_unpush_target (ops);
+  maybe_unpush_target ();
 }
 
 /* Try to determine the executable filename.
@@ -2013,8 +2059,8 @@ windows_get_exec_module_filename (char *exe_name_ret, size_t exe_name_max_len)
 
 /* The pid_to_exec_file target_ops method for this platform.  */
 
-static char *
-windows_pid_to_exec_file (struct target_ops *self, int pid)
+char *
+windows_nat_target::pid_to_exec_file (int pid)
 {
   static char path[__PMAX];
 #ifdef __CYGWIN__
@@ -2041,8 +2087,8 @@ windows_pid_to_exec_file (struct target_ops *self, int pid)
 
 /* Print status information about what we're accessing.  */
 
-static void
-windows_files_info (struct target_ops *ignore)
+void
+windows_nat_target::files_info ()
 {
   struct inferior *inf = current_inferior ();
 
@@ -2430,10 +2476,10 @@ redirect_inferior_handles (const char *cmd_orig, char *cmd,
    ALLARGS is a string containing the arguments to the program.
    ENV is the environment vector to pass.  Errors reported with error().  */
 
-static void
-windows_create_inferior (struct target_ops *ops, const char *exec_file,
- const std::string &origallargs, char **in_env,
- int from_tty)
+void
+windows_nat_target::create_inferior (const char *exec_file,
+     const std::string &origallargs,
+     char **in_env, int from_tty)
 {
   STARTUPINFO si;
 #ifdef __CYGWIN__
@@ -2751,13 +2797,13 @@ windows_create_inferior (struct target_ops *ops, const char *exec_file,
   else
     saw_create = 0;
 
-  do_initial_windows_stuff (ops, pi.dwProcessId, 0);
+  do_initial_windows_stuff (this, pi.dwProcessId, 0);
 
   /* windows_continue (DBG_CONTINUE, -1, 0); */
 }
 
-static void
-windows_mourn_inferior (struct target_ops *ops)
+void
+windows_nat_target::mourn_inferior ()
 {
   (void) windows_continue (DBG_CONTINUE, -1, 0);
   x86_cleanup_dregs();
@@ -2766,14 +2812,14 @@ windows_mourn_inferior (struct target_ops *ops)
       CHECK (CloseHandle (current_process_handle));
       open_process_used = 0;
     }
-  inf_child_mourn_inferior (ops);
+  inf_child_target::mourn_inferior ();
 }
 
 /* Send a SIGINT to the process group.  This acts just like the user typed a
    ^C on the controlling terminal.  */
 
-static void
-windows_interrupt (struct target_ops *self)
+void
+windows_nat_target::interrupt ()
 {
   DEBUG_EVENTS (("gdb: GenerateConsoleCtrlEvent (CTRLC_EVENT, 0)\n"));
   CHECK (GenerateConsoleCtrlEvent (CTRL_C_EVENT, current_event.dwProcessId));
@@ -2820,8 +2866,8 @@ windows_xfer_memory (gdb_byte *readbuf, const gdb_byte *writebuf,
     return success ? TARGET_XFER_OK : TARGET_XFER_E_IO;
 }
 
-static void
-windows_kill_inferior (struct target_ops *ops)
+void
+windows_nat_target::kill ()
 {
   CHECK (TerminateProcess (current_process_handle, 0));
 
@@ -2838,16 +2884,16 @@ windows_kill_inferior (struct target_ops *ops)
   target_mourn_inferior (inferior_ptid); /* Or just windows_mourn_inferior?  */
 }
 
-static void
-windows_close (struct target_ops *self)
+void
+windows_nat_target::close ()
 {
   DEBUG_EVENTS (("gdb: windows_close, inferior_ptid=%d\n",
  ptid_get_pid (inferior_ptid)));
 }
 
 /* Convert pid to printable format.  */
-static const char *
-windows_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+windows_nat_target::pid_to_str (ptid_t ptid)
 {
   static char buf[80];
 
@@ -2904,11 +2950,11 @@ windows_xfer_shared_libraries (struct target_ops *ops,
   return len != 0 ? TARGET_XFER_OK : TARGET_XFER_EOF;
 }
 
-static enum target_xfer_status
-windows_xfer_partial (struct target_ops *ops, enum target_object object,
-      const char *annex, gdb_byte *readbuf,
-      const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
-      ULONGEST *xfered_len)
+enum target_xfer_status
+windows_nat_target::xfer_partial (enum target_object object,
+  const char *annex, gdb_byte *readbuf,
+  const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+  ULONGEST *xfered_len)
 {
   switch (object)
     {
@@ -2916,22 +2962,21 @@ windows_xfer_partial (struct target_ops *ops, enum target_object object,
       return windows_xfer_memory (readbuf, writebuf, offset, len, xfered_len);
 
     case TARGET_OBJECT_LIBRARIES:
-      return windows_xfer_shared_libraries (ops, object, annex, readbuf,
+      return windows_xfer_shared_libraries (this, object, annex, readbuf,
     writebuf, offset, len, xfered_len);
 
     default:
-      return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
-    readbuf, writebuf, offset, len,
-    xfered_len);
+      return beneath->xfer_partial (object, annex,
+    readbuf, writebuf, offset, len,
+    xfered_len);
     }
 }
 
 /* Provide thread local base, i.e. Thread Information Block address.
    Returns 1 if ptid is found and sets *ADDR to thread_local_base.  */
 
-static int
-windows_get_tib_address (struct target_ops *self,
- ptid_t ptid, CORE_ADDR *addr)
+int
+windows_nat_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
 {
   windows_thread_info *th;
 
@@ -2945,58 +2990,24 @@ windows_get_tib_address (struct target_ops *self,
   return 1;
 }
 
-static ptid_t
-windows_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
+ptid_t
+windows_nat_target::get_ada_task_ptid (long lwp, long thread)
 {
   return ptid_build (ptid_get_pid (inferior_ptid), 0, lwp);
 }
 
 /* Implementation of the to_thread_name method.  */
 
-static const char *
-windows_thread_name (struct target_ops *self, struct thread_info *thr)
+const char *
+windows_nat_target::thread_name (struct thread_info *thr)
 {
   return thread_rec (ptid_get_tid (thr->ptid), 0)->name;
 }
 
-static struct target_ops *
-windows_target (void)
-{
-  struct target_ops *t = inf_child_target ();
-
-  t->to_close = windows_close;
-  t->to_attach = windows_attach;
-  t->to_attach_no_wait = 1;
-  t->to_detach = windows_detach;
-  t->to_resume = windows_resume;
-  t->to_wait = windows_wait;
-  t->to_fetch_registers = windows_fetch_inferior_registers;
-  t->to_store_registers = windows_store_inferior_registers;
-  t->to_xfer_partial = windows_xfer_partial;
-  t->to_files_info = windows_files_info;
-  t->to_kill = windows_kill_inferior;
-  t->to_create_inferior = windows_create_inferior;
-  t->to_mourn_inferior = windows_mourn_inferior;
-  t->to_thread_alive = windows_thread_alive;
-  t->to_pid_to_str = windows_pid_to_str;
-  t->to_interrupt = windows_interrupt;
-  t->to_pid_to_exec_file = windows_pid_to_exec_file;
-  t->to_get_ada_task_ptid = windows_get_ada_task_ptid;
-  t->to_get_tib_address = windows_get_tib_address;
-  t->to_thread_name = windows_thread_name;
-
-  return t;
-}
 
 void
 _initialize_windows_nat (void)
 {
-  struct target_ops *t;
-
-  t = windows_target ();
-
-  x86_use_watchpoints (t);
-
   x86_dr_low.set_control = cygwin_set_dr7;
   x86_dr_low.set_addr = cygwin_set_dr;
   x86_dr_low.get_addr = cygwin_get_dr;
@@ -3007,7 +3018,7 @@ _initialize_windows_nat (void)
      calling x86_set_debug_register_length function
      in processor windows specific native file.  */
 
-  add_target (t);
+  add_target (&the_windows_nat_target);
 
 #ifdef __CYGWIN__
   cygwin_internal (CW_SET_DOS_FILE_WARNING, 0);
@@ -3144,8 +3155,9 @@ cygwin_get_dr7 (void)
 /* Determine if the thread referenced by "ptid" is alive
    by "polling" it.  If WaitForSingleObject returns WAIT_OBJECT_0
    it means that the thread has died.  Otherwise it is assumed to be alive.  */
-static int
-windows_thread_alive (struct target_ops *ops, ptid_t ptid)
+
+int
+windows_nat_target::thread_alive (ptid_t ptid)
 {
   int tid;
 
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 17/40] target_ops/C++: macOS/Darwin target

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.  I'd checked that this builds with a cross
compiler.
---
 gdb/darwin-nat.c      | 142 +++++++++++++++-----------------------------------
 gdb/darwin-nat.h      |  46 ++++++++++++++--
 gdb/i386-darwin-nat.c |  28 ++++++----
 3 files changed, 99 insertions(+), 117 deletions(-)

diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index e98ac6c548..919643145a 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -83,36 +83,12 @@
 #define PTRACE(CMD, PID, ADDR, SIG) \
  darwin_ptrace(#CMD, CMD, (PID), (ADDR), (SIG))
 
-static void darwin_interrupt (struct target_ops *self);
-
-static void darwin_resume_to (struct target_ops *ops, ptid_t ptid, int step,
-                              enum gdb_signal signal);
-static void darwin_resume (ptid_t ptid, int step,
-   enum gdb_signal signal);
-
-static ptid_t darwin_wait_to (struct target_ops *ops, ptid_t ptid,
-                              struct target_waitstatus *status, int options);
 static ptid_t darwin_wait (ptid_t ptid, struct target_waitstatus *status);
 
-static void darwin_mourn_inferior (struct target_ops *ops);
-
-static void darwin_kill_inferior (struct target_ops *ops);
-
 static void darwin_ptrace_me (void);
 
 static void darwin_ptrace_him (int pid);
 
-static void darwin_create_inferior (struct target_ops *ops,
-    const char *exec_file,
-    const std::string &allargs,
-    char **env, int from_tty);
-
-static void darwin_files_info (struct target_ops *ops);
-
-static const char *darwin_pid_to_str (struct target_ops *ops, ptid_t tpid);
-
-static int darwin_thread_alive (struct target_ops *ops, ptid_t tpid);
-
 static void darwin_encode_reply (mig_reply_error_t *reply,
  mach_msg_header_t *hdr, integer_t code);
 
@@ -942,8 +918,8 @@ darwin_suspend_inferior_threads (struct inferior *inf)
     }
 }
 
-static void
-darwin_resume (ptid_t ptid, int step, enum gdb_signal signal)
+void
+darwin_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
 {
   struct target_waitstatus status;
   int pid;
@@ -1007,13 +983,6 @@ darwin_resume (ptid_t ptid, int step, enum gdb_signal signal)
     }
 }
 
-static void
-darwin_resume_to (struct target_ops *ops, ptid_t ptid, int step,
-                  enum gdb_signal signal)
-{
-  return darwin_resume (ptid, step, signal);
-}
-
 static ptid_t
 darwin_decode_message (mach_msg_header_t *hdr,
        darwin_thread_t **pthread,
@@ -1334,22 +1303,22 @@ darwin_wait (ptid_t ptid, struct target_waitstatus *status)
   return res;
 }
 
-static ptid_t
-darwin_wait_to (struct target_ops *ops,
-                ptid_t ptid, struct target_waitstatus *status, int options)
+ptid_t
+darwin_nat_target::wait (ptid_t ptid, struct target_waitstatus *status,
+ int options)
 {
   return darwin_wait (ptid, status);
 }
 
-static void
-darwin_interrupt (struct target_ops *self)
+void
+darwin_nat_target::interrupt ()
 {
   struct inferior *inf = current_inferior ();
   darwin_inferior *priv = get_darwin_inferior (inf);
 
   /* FIXME: handle in no_ptrace mode.  */
   gdb_assert (!priv->no_ptrace);
-  kill (inf->pid, SIGINT);
+  ::kill (inf->pid, SIGINT);
 }
 
 /* Deallocate threads port and vector.  */
@@ -1368,8 +1337,8 @@ darwin_deallocate_threads (struct inferior *inf)
   priv->threads.clear ();
 }
 
-static void
-darwin_mourn_inferior (struct target_ops *ops)
+void
+darwin_nat_target::mourn_inferior ()
 {
   struct inferior *inf = current_inferior ();
   darwin_inferior *priv = get_darwin_inferior (inf);
@@ -1414,7 +1383,7 @@ darwin_mourn_inferior (struct target_ops *ops)
 
   inf->priv = NULL;
 
-  inf_child_mourn_inferior (ops);
+  inf_child_target::mourn_inferior ();
 }
 
 static void
@@ -1538,8 +1507,8 @@ darwin_setup_exceptions (struct inferior *inf)
    kret);
 }
 
-static void
-darwin_kill_inferior (struct target_ops *ops)
+void
+darwin_nat_target::kill ()
 {
   struct inferior *inf = current_inferior ();
   darwin_inferior *priv = get_darwin_inferior (inf);
@@ -1559,7 +1528,7 @@ darwin_kill_inferior (struct target_ops *ops)
 
   darwin_reply_to_all_pending_messages (inf);
 
-  res = kill (inf->pid, 9);
+  res = ::kill (inf->pid, 9);
 
   if (res == 0)
     {
@@ -1835,11 +1804,10 @@ darwin_execvp (const char *file, char * const argv[], char * const env[])
   posix_spawnp (NULL, argv[0], NULL, &attr, argv, env);
 }
 
-static void
-darwin_create_inferior (struct target_ops *ops,
- const char *exec_file,
- const std::string &allargs,
- char **env, int from_tty)
+void
+darwin_nat_target::create_inferior (const char *exec_file,
+    const std::string &allargs,
+    char **env, int from_tty)
 {
   /* Do the hard work.  */
   fork_inferior (exec_file, allargs, env, darwin_ptrace_me,
@@ -1877,8 +1845,8 @@ darwin_setup_fake_stop_event (struct inferior *inf)
 
 /* Attach to process PID, then initialize for debugging it
    and wait for the trace-trap that results from attaching.  */
-static void
-darwin_attach (struct target_ops *ops, const char *args, int from_tty)
+void
+darwin_nat_target::attach (const char *args, int from_tty)
 {
   pid_t pid;
   pid_t pid2;
@@ -1906,7 +1874,7 @@ darwin_attach (struct target_ops *ops, const char *args, int from_tty)
       gdb_flush (gdb_stdout);
     }
 
-  if (pid == 0 || kill (pid, 0) < 0)
+  if (pid == 0 || ::kill (pid, 0) < 0)
     error (_("Can't attach to process %d: %s (%d)"),
            pid, safe_strerror (errno), errno);
 
@@ -1937,8 +1905,9 @@ darwin_attach (struct target_ops *ops, const char *args, int from_tty)
    to work, it may be necessary for the process to have been
    previously attached.  It *might* work if the program was
    started via fork.  */
-static void
-darwin_detach (struct target_ops *ops, inferior *inf, int from_tty)
+
+void
+darwin_nat_target::detach (inferior *inf, int from_tty)
 {
   pid_t pid = ptid_get_pid (inferior_ptid);
   darwin_inferior *priv = get_darwin_inferior (inf);
@@ -1971,16 +1940,11 @@ darwin_detach (struct target_ops *ops, inferior *inf, int from_tty)
   if (priv->no_ptrace)
     darwin_resume_inferior (inf);
 
-  darwin_mourn_inferior (ops);
+  mourn_inferior ();
 }
 
-static void
-darwin_files_info (struct target_ops *ops)
-{
-}
-
-static const char *
-darwin_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+darwin_nat_target::pid_to_str (ptid_t ptid)
 {
   static char buf[80];
   long tid = ptid_get_tid (ptid);
@@ -1995,8 +1959,8 @@ darwin_pid_to_str (struct target_ops *ops, ptid_t ptid)
   return normal_pid_to_str (ptid);
 }
 
-static int
-darwin_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+darwin_nat_target::thread_alive (ptid_t ptid)
 {
   return 1;
 }
@@ -2193,11 +2157,11 @@ darwin_read_dyld_info (task_t task, CORE_ADDR addr, gdb_byte *rdaddr,
 
 
 
-static enum target_xfer_status
-darwin_xfer_partial (struct target_ops *ops,
-     enum target_object object, const char *annex,
-     gdb_byte *readbuf, const gdb_byte *writebuf,
-     ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+darwin_nat_target::xfer_partial (enum target_object object, const char *annex,
+ gdb_byte *readbuf, const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len)
 {
   struct inferior *inf = current_inferior ();
   darwin_inferior *priv = get_darwin_inferior (inf);
@@ -2264,8 +2228,8 @@ set_enable_mach_exceptions (const char *args, int from_tty,
     }
 }
 
-static char *
-darwin_pid_to_exec_file (struct target_ops *self, int pid)
+char *
+darwin_nat_target::pid_to_exec_file (int pid)
 {
   static char path[PATH_MAX];
   int res;
@@ -2277,8 +2241,8 @@ darwin_pid_to_exec_file (struct target_ops *self, int pid)
     return NULL;
 }
 
-static ptid_t
-darwin_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
+ptid_t
+darwin_nat_target::get_ada_task_ptid (long lwp, long thread)
 {
   struct inferior *inf = current_inferior ();
   darwin_inferior *priv = get_darwin_inferior (inf);
@@ -2342,14 +2306,14 @@ darwin_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
     return null_ptid;
 }
 
-static int
-darwin_supports_multi_process (struct target_ops *self)
+int
+darwin_nat_target::supports_multi_process ()
 {
   return 1;
 }
 
 void
-_initialize_darwin_inferior (void)
+_initialize_darwin_nat (void)
 {
   kern_return_t kret;
 
@@ -2364,30 +2328,6 @@ _initialize_darwin_inferior (void)
       MACH_CHECK_ERROR (kret);
     }
 
-  darwin_ops = inf_child_target ();
-
-  darwin_ops->to_create_inferior = darwin_create_inferior;
-  darwin_ops->to_attach = darwin_attach;
-  darwin_ops->to_attach_no_wait = 0;
-  darwin_ops->to_detach = darwin_detach;
-  darwin_ops->to_files_info = darwin_files_info;
-  darwin_ops->to_wait = darwin_wait_to;
-  darwin_ops->to_mourn_inferior = darwin_mourn_inferior;
-  darwin_ops->to_kill = darwin_kill_inferior;
-  darwin_ops->to_interrupt = darwin_interrupt;
-  darwin_ops->to_resume = darwin_resume_to;
-  darwin_ops->to_thread_alive = darwin_thread_alive;
-  darwin_ops->to_pid_to_str = darwin_pid_to_str;
-  darwin_ops->to_pid_to_exec_file = darwin_pid_to_exec_file;
-  darwin_ops->to_load = NULL;
-  darwin_ops->to_xfer_partial = darwin_xfer_partial;
-  darwin_ops->to_supports_multi_process = darwin_supports_multi_process;
-  darwin_ops->to_get_ada_task_ptid = darwin_get_ada_task_ptid;
-
-  darwin_complete_target (darwin_ops);
-
-  add_target (darwin_ops);
-
   inferior_debug (2, _("GDB task: 0x%lx, pid: %d\n"),
   (unsigned long) mach_task_self (), getpid ());
 
diff --git a/gdb/darwin-nat.h b/gdb/darwin-nat.h
index 0eacb5530d..d4a06d9c27 100644
--- a/gdb/darwin-nat.h
+++ b/gdb/darwin-nat.h
@@ -17,9 +17,50 @@
 #ifndef __DARWIN_NAT_H__
 #define __DARWIN_NAT_H__
 
+#include "inf-child.h"
 #include <mach/mach.h>
 #include "gdbthread.h"
 
+/* This needs to be overridden by the platform specific nat code.  */
+
+class darwin_nat_target : public inf_child_target
+{
+  void create_inferior (const char *exec_file,
+ const std::string &allargs,
+ char **env, int from_tty);
+
+  void attach (const char *, int) override;
+
+  void detach (inferior *, int) override;
+
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+
+  void mourn_inferior () override;
+
+  void kill () override;
+
+  void interrupt () override;
+
+  void resume (ptid_t, int , enum gdb_signal) override;
+
+  int thread_alive (ptid_t ptid) override;
+
+  const char *pid_to_str (ptid_t) override;
+
+  char *pid_to_exec_file (int pid) override;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+  int supports_multi_process () override;
+
+  ptid_t get_ada_task_ptid (long lwp, long thread) override;
+};
+
 /* Describe the mach exception handling state for a task.  This state is saved
    before being changed and restored when a process is detached.
    For more information on these fields see task_get_exception_ports manual
@@ -158,11 +199,6 @@ extern void mach_check_error (kern_return_t ret, const char *file,
 
 void darwin_set_sstep (thread_t thread, int enable);
 
-/* This one is called in darwin-nat.c, but needs to be provided by the
-   platform specific nat code.  It allows each platform to add platform specific
-   stuff to the darwin_ops.  */
-extern void darwin_complete_target (struct target_ops *target);
-
 void darwin_check_osabi (darwin_inferior *inf, thread_t thread);
 
 #endif /* __DARWIN_NAT_H__ */
diff --git a/gdb/i386-darwin-nat.c b/gdb/i386-darwin-nat.c
index 023643fa56..48f1a7921d 100644
--- a/gdb/i386-darwin-nat.c
+++ b/gdb/i386-darwin-nat.c
@@ -43,12 +43,21 @@
 #include "amd64-darwin-tdep.h"
 #endif
 
+struct i386_darwin_nat_target final : public x86_nat_target<darwin_nat_target>
+{
+  /* Add our register access methods.  */
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+};
+
+static struct i386_darwin_nat_target darwin_target;
+
 /* Read register values from the inferior process.
    If REGNO is -1, do this for all registers.
    Otherwise, REGNO specifies which register (so we can save time).  */
-static void
-i386_darwin_fetch_inferior_registers (struct target_ops *ops,
-      struct regcache *regcache, int regno)
+
+void
+i386_darwin_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   thread_t current_thread = ptid_get_tid (regcache_get_ptid (regcache));
   int fetched = 0;
@@ -163,9 +172,9 @@ i386_darwin_fetch_inferior_registers (struct target_ops *ops,
    If REGNO is -1, do this for all registers.
    Otherwise, REGNO specifies which register (so we can save time).  */
 
-static void
-i386_darwin_store_inferior_registers (struct target_ops *ops,
-      struct regcache *regcache, int regno)
+void
+i386_darwin_nat_target::store_registers (struct regcache *regcache,
+ int regno)
 {
   thread_t current_thread = ptid_get_tid (regcache_get_ptid (regcache));
   struct gdbarch *gdbarch = regcache->arch ();
@@ -628,7 +637,7 @@ darwin_set_sstep (thread_t thread, int enable)
 }
 
 void
-darwin_complete_target (struct target_ops *target)
+_initialize_i386_darwin_nat (void)
 {
 #ifdef BFD64
   amd64_native_gregset64_reg_offset = amd64_darwin_thread_state_reg_offset;
@@ -637,8 +646,6 @@ darwin_complete_target (struct target_ops *target)
   amd64_native_gregset32_num_regs = i386_darwin_thread_state_num_regs;
 #endif
 
-  x86_use_watchpoints (target);
-
   x86_dr_low.set_control = i386_darwin_dr_set_control;
   x86_dr_low.set_addr = i386_darwin_dr_set_addr;
   x86_dr_low.get_addr = i386_darwin_dr_get_addr;
@@ -652,6 +659,5 @@ darwin_complete_target (struct target_ops *target)
   x86_set_debug_register_length (4);
 #endif
 
-  target->to_fetch_registers = i386_darwin_fetch_inferior_registers;
-  target->to_store_registers = i386_darwin_store_inferior_registers;
+  add_target (&darwin_target);
 }
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 18/40] target_ops/C++: linux_trad_target, MIPS and Alpha GNU/Linux

Pedro Alves-7
In reply to this post by Pedro Alves-7
This converts the code in the new linux-nat-trad.h/c files, that was
split off of inf-ptrace.h/c recently, to a C++ base class, and makes
the MIPS and Alpha GNU/Linux ports use it.

Otherwise, it's a straighforward conversion.

I'd checked with a cross compiler that the MIPS port builds.  I don't
have an Alpha compiler handy.
---
 gdb/alpha-linux-nat.c |  17 +++--
 gdb/linux-nat-trad.c  |  54 +++++-----------
 gdb/linux-nat-trad.h  |  24 +++++--
 gdb/mips-linux-nat.c  | 175 ++++++++++++++++++++++++++------------------------
 4 files changed, 138 insertions(+), 132 deletions(-)

diff --git a/gdb/alpha-linux-nat.c b/gdb/alpha-linux-nat.c
index 8d46af4176..70997e5f4a 100644
--- a/gdb/alpha-linux-nat.c
+++ b/gdb/alpha-linux-nat.c
@@ -32,6 +32,15 @@
 /* The address of UNIQUE for ptrace.  */
 #define ALPHA_UNIQUE_PTRACE_ADDR 65
 
+class alpha_linux_nat_target final : public linux_nat_trad_target
+{
+protected:
+  /* Override linux_nat_trad_target methods.  */
+  CORE_ADDR register_u_offset (struct gdbarch *gdbarch,
+       int regno, int store_p) override;
+};
+
+static alpha_linux_nat_target the_alpha_linux_nat_target;
 
 /* See the comment in m68k-tdep.c regarding the utility of these
    functions.  */
@@ -77,9 +86,9 @@ fill_fpregset (const struct regcache *regcache,
   alpha_fill_fp_regs (regcache, regno, regp, regp + 31);
 }
 
-
-static CORE_ADDR
-alpha_linux_register_u_offset (struct gdbarch *gdbarch, int regno, int store_p)
+CORE_ADDR
+alpha_linux_nat_target::register_u_offset (struct gdbarch *gdbarch,
+   int regno, int store_p)
 {
   if (regno == gdbarch_pc_regnum (gdbarch))
     return PC;
@@ -94,5 +103,5 @@ alpha_linux_register_u_offset (struct gdbarch *gdbarch, int regno, int store_p)
 void
 _initialize_alpha_linux_nat (void)
 {
-  linux_nat_add_target (linux_trad_target (alpha_linux_register_u_offset));
+  add_target (&the_alpha_linux_nat_target);
 }
diff --git a/gdb/linux-nat-trad.c b/gdb/linux-nat-trad.c
index 75130be0f4..066d15a352 100644
--- a/gdb/linux-nat-trad.c
+++ b/gdb/linux-nat-trad.c
@@ -23,14 +23,10 @@
 #include "nat/gdb_ptrace.h"
 #include "inf-ptrace.h"
 
-/* Pointer to a function that returns the offset within the user area
-   where a particular register is stored.  */
-static CORE_ADDR (*inf_ptrace_register_u_offset)(struct gdbarch *, int, int);
-
 /* Fetch register REGNUM from the inferior.  */
 
-static void
-inf_ptrace_fetch_register (struct regcache *regcache, int regnum)
+void
+linux_nat_trad_target::fetch_register (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   CORE_ADDR addr;
@@ -40,7 +36,7 @@ inf_ptrace_fetch_register (struct regcache *regcache, int regnum)
   int i;
 
   /* This isn't really an address, but ptrace thinks of it as one.  */
-  addr = inf_ptrace_register_u_offset (gdbarch, regnum, 0);
+  addr = register_u_offset (gdbarch, regnum, 0);
   if (addr == (CORE_ADDR)-1
       || gdbarch_cannot_fetch_register (gdbarch, regnum))
     {
@@ -72,23 +68,23 @@ inf_ptrace_fetch_register (struct regcache *regcache, int regnum)
 /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
    for all registers.  */
 
-static void
-inf_ptrace_fetch_registers (struct target_ops *ops,
-    struct regcache *regcache, int regnum)
+void
+linux_nat_trad_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   if (regnum == -1)
     for (regnum = 0;
  regnum < gdbarch_num_regs (regcache->arch ());
  regnum++)
-      inf_ptrace_fetch_register (regcache, regnum);
+      fetch_register (regcache, regnum);
   else
-    inf_ptrace_fetch_register (regcache, regnum);
+    fetch_register (regcache, regnum);
 }
 
 /* Store register REGNUM into the inferior.  */
 
-static void
-inf_ptrace_store_register (const struct regcache *regcache, int regnum)
+void
+linux_nat_trad_target::store_register (const struct regcache *regcache,
+       int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   CORE_ADDR addr;
@@ -98,7 +94,7 @@ inf_ptrace_store_register (const struct regcache *regcache, int regnum)
   int i;
 
   /* This isn't really an address, but ptrace thinks of it as one.  */
-  addr = inf_ptrace_register_u_offset (gdbarch, regnum, 1);
+  addr = register_u_offset (gdbarch, regnum, 1);
   if (addr == (CORE_ADDR)-1
       || gdbarch_cannot_store_register (gdbarch, regnum))
     return;
@@ -127,34 +123,14 @@ inf_ptrace_store_register (const struct regcache *regcache, int regnum)
 /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
    this for all registers.  */
 
-static void
-inf_ptrace_store_registers (struct target_ops *ops,
-    struct regcache *regcache, int regnum)
+void
+linux_nat_trad_target::store_registers (struct regcache *regcache, int regnum)
 {
   if (regnum == -1)
     for (regnum = 0;
  regnum < gdbarch_num_regs (regcache->arch ());
  regnum++)
-      inf_ptrace_store_register (regcache, regnum);
+      store_register (regcache, regnum);
   else
-    inf_ptrace_store_register (regcache, regnum);
-}
-
-/* Create a "traditional" Linux/ptrace target.  REGISTER_U_OFFSET
-   should be a function returning the offset within the user area
-   where a particular register is stored.  */
-
-struct target_ops *
-linux_trad_target (CORE_ADDR (*register_u_offset)(struct gdbarch *, int, int))
-{
-  struct target_ops *t = inf_ptrace_target();
-
-  gdb_assert (register_u_offset);
-  inf_ptrace_register_u_offset = register_u_offset;
-  t->to_fetch_registers = inf_ptrace_fetch_registers;
-  t->to_store_registers = inf_ptrace_store_registers;
-
-  linux_target_install_ops (t);
-
-  return t;
+    store_register (regcache, regnum);
 }
diff --git a/gdb/linux-nat-trad.h b/gdb/linux-nat-trad.h
index 3b4a6c8595..240a95139c 100644
--- a/gdb/linux-nat-trad.h
+++ b/gdb/linux-nat-trad.h
@@ -22,9 +22,25 @@
 
 #include "linux-nat.h"
 
-/* Create a generic GNU/Linux target using traditional
-   ptrace register access.  */
-struct target_ops *linux_trad_target
-  (CORE_ADDR (*register_u_offset)(struct gdbarch *, int, int));
+/* A prototype GNU/Linux target using traditional ptrace register
+   access.  A concrete type should override REGISTER_U_OFFSET.  */
+
+class linux_nat_trad_target : public linux_nat_target
+{
+public:
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+protected:
+  /* Return the offset within the user area where a particular
+     register is stored.  */
+  virtual CORE_ADDR register_u_offset (struct gdbarch *gdbarch,
+       int regnum, int store) = 0;
+
+private:
+  /* Helpers.  See definition.  */
+  void fetch_register (struct regcache *regcache, int regnum);
+  void store_register (const struct regcache *regcache, int regnum);
+};
 
 #endif /* LINUX_NAT_TRAD_H */
diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c
index 17e70b603b..1cd97d53c7 100644
--- a/gdb/mips-linux-nat.c
+++ b/gdb/mips-linux-nat.c
@@ -42,19 +42,49 @@
 #define PTRACE_GET_THREAD_AREA 25
 #endif
 
-/* Assume that we have PTRACE_GETREGS et al. support.  If we do not,
-   we'll clear this and use PTRACE_PEEKUSER instead.  */
-static int have_ptrace_regsets = 1;
+class mips_linux_nat_target final : public linux_nat_trad_target
+{
+public:
+  /* Add our register access methods.  */
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  void close () override;
+
+  int can_use_hw_breakpoint (enum bptype, int, int) override;
+
+  int remove_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
+ struct expression *) override;
+
+  int insert_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
+ struct expression *) override;
+
+  int stopped_by_watchpoint () override;
+
+  int stopped_data_address (CORE_ADDR *) override;
 
-/* Saved function pointers to fetch and store a single register using
-   PTRACE_PEEKUSER and PTRACE_POKEUSER.  */
+  int region_ok_for_hw_watchpoint (CORE_ADDR, int) override;
 
-static void (*super_fetch_registers) (struct target_ops *,
-      struct regcache *, int);
-static void (*super_store_registers) (struct target_ops *,
-      struct regcache *, int);
+  const struct target_desc *read_description () override;
 
-static void (*super_close) (struct target_ops *);
+protected:
+  /* Override linux_nat_trad_target methods.  */
+  CORE_ADDR register_u_offset (struct gdbarch *gdbarch,
+       int regno, int store_p) override;
+
+private:
+  /* Helpers.  See definitions.  */
+  void mips64_regsets_store_registers (struct regcache *regcache,
+       int regno);
+  void mips64_regsets_fetch_registers (struct regcache *regcache,
+       int regno);
+};
+
+static mips_linux_nat_target the_mips_linux_nat_target;
+
+/* Assume that we have PTRACE_GETREGS et al. support.  If we do not,
+   we'll clear this and use PTRACE_PEEKUSER instead.  */
+static int have_ptrace_regsets = 1;
 
 /* Map gdb internal register number to ptrace ``address''.
    These ``addresses'' are normally defined in <asm/ptrace.h>.
@@ -208,9 +238,9 @@ fill_fpregset (const struct regcache *regcache,
 /* Fetch REGNO (or all registers if REGNO == -1) from the target
    using PTRACE_GETREGS et al.  */
 
-static void
-mips64_linux_regsets_fetch_registers (struct target_ops *ops,
-      struct regcache *regcache, int regno)
+void
+mips_linux_nat_target::mips64_regsets_fetch_registers
+  (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   int is_fp, is_dsp;
@@ -280,23 +310,24 @@ mips64_linux_regsets_fetch_registers (struct target_ops *ops,
     }
 
   if (is_dsp)
-    super_fetch_registers (ops, regcache, regno);
+    linux_nat_trad_target::fetch_registers (regcache, regno);
   else if (regno == -1 && have_dsp)
     {
       for (regi = mips_regnum (gdbarch)->dspacc;
    regi < mips_regnum (gdbarch)->dspacc + 6;
    regi++)
- super_fetch_registers (ops, regcache, regi);
-      super_fetch_registers (ops, regcache, mips_regnum (gdbarch)->dspctl);
+ linux_nat_trad_target::fetch_registers (regcache, regi);
+      linux_nat_trad_target::fetch_registers (regcache,
+      mips_regnum (gdbarch)->dspctl);
     }
 }
 
 /* Store REGNO (or all registers if REGNO == -1) to the target
    using PTRACE_SETREGS et al.  */
 
-static void
-mips64_linux_regsets_store_registers (struct target_ops *ops,
-      struct regcache *regcache, int regno)
+void
+mips_linux_nat_target::mips64_regsets_store_registers
+  (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   int is_fp, is_dsp;
@@ -357,56 +388,56 @@ mips64_linux_regsets_store_registers (struct target_ops *ops,
     }
 
   if (is_dsp)
-    super_store_registers (ops, regcache, regno);
+    linux_nat_trad_target::store_registers (regcache, regno);
   else if (regno == -1 && have_dsp)
     {
       for (regi = mips_regnum (gdbarch)->dspacc;
    regi < mips_regnum (gdbarch)->dspacc + 6;
    regi++)
- super_store_registers (ops, regcache, regi);
-      super_store_registers (ops, regcache, mips_regnum (gdbarch)->dspctl);
+ linux_nat_trad_target::store_registers (regcache, regi);
+      linux_nat_trad_target::store_registers (regcache,
+      mips_regnum (gdbarch)->dspctl);
     }
 }
 
 /* Fetch REGNO (or all registers if REGNO == -1) from the target
    using any working method.  */
 
-static void
-mips64_linux_fetch_registers (struct target_ops *ops,
-      struct regcache *regcache, int regnum)
+void
+mips_linux_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   /* Unless we already know that PTRACE_GETREGS does not work, try it.  */
   if (have_ptrace_regsets)
-    mips64_linux_regsets_fetch_registers (ops, regcache, regnum);
+    mips64_regsets_fetch_registers (regcache, regnum);
 
   /* If we know, or just found out, that PTRACE_GETREGS does not work, fall
      back to PTRACE_PEEKUSER.  */
   if (!have_ptrace_regsets)
-    super_fetch_registers (ops, regcache, regnum);
+    linux_nat_trad_target::fetch_registers (regcache, regnum);
 }
 
 /* Store REGNO (or all registers if REGNO == -1) to the target
    using any working method.  */
 
-static void
-mips64_linux_store_registers (struct target_ops *ops,
-      struct regcache *regcache, int regnum)
+void
+mips_linux_nat_target::store_registers (struct regcache *regcache, int regnum)
 {
   /* Unless we already know that PTRACE_GETREGS does not work, try it.  */
   if (have_ptrace_regsets)
-    mips64_linux_regsets_store_registers (ops, regcache, regnum);
+    mips64_regsets_store_registers (regcache, regnum);
 
   /* If we know, or just found out, that PTRACE_GETREGS does not work, fall
      back to PTRACE_PEEKUSER.  */
   if (!have_ptrace_regsets)
-    super_store_registers (ops, regcache, regnum);
+    linux_nat_trad_target::store_registers (regcache, regnum);
 }
 
 /* Return the address in the core dump or inferior of register
    REGNO.  */
 
-static CORE_ADDR
-mips_linux_register_u_offset (struct gdbarch *gdbarch, int regno, int store_p)
+CORE_ADDR
+mips_linux_nat_target::register_u_offset (struct gdbarch *gdbarch,
+  int regno, int store_p)
 {
   if (mips_abi_regsize (gdbarch) == 8)
     return mips64_linux_register_addr (gdbarch, regno, store_p);
@@ -414,8 +445,8 @@ mips_linux_register_u_offset (struct gdbarch *gdbarch, int regno, int store_p)
     return mips_linux_register_addr (gdbarch, regno, store_p);
 }
 
-static const struct target_desc *
-mips_linux_read_description (struct target_ops *ops)
+const struct target_desc *
+mips_linux_nat_target::read_description ()
 {
   static int have_dsp = -1;
 
@@ -499,10 +530,9 @@ mips_show_dr (const char *func, CORE_ADDR addr,
 /* Target to_can_use_hw_breakpoint implementation.  Return 1 if we can
    handle the specified watch type.  */
 
-static int
-mips_linux_can_use_hw_breakpoint (struct target_ops *self,
-  enum bptype type,
-  int cnt, int ot)
+int
+mips_linux_nat_target::can_use_hw_breakpoint (enum bptype type,
+      int cnt, int ot)
 {
   int i;
   uint32_t wanted_mask, irw_mask;
@@ -542,8 +572,8 @@ mips_linux_can_use_hw_breakpoint (struct target_ops *self,
    stopped by watchpoint.  The watchhi R and W bits indicate the watch
    register triggered.  */
 
-static int
-mips_linux_stopped_by_watchpoint (struct target_ops *ops)
+int
+mips_linux_nat_target::stopped_by_watchpoint ()
 {
   int n;
   int num_valid;
@@ -566,8 +596,8 @@ mips_linux_stopped_by_watchpoint (struct target_ops *ops)
    where the watch triggered (if known).  Return 1 if the address was
    known.  */
 
-static int
-mips_linux_stopped_data_address (struct target_ops *t, CORE_ADDR *paddr)
+int
+mips_linux_nat_target::stopped_data_address (CORE_ADDR *paddr)
 {
   /* On mips we don't know the low order 3 bits of the data address,
      so we must return false.  */
@@ -577,9 +607,8 @@ mips_linux_stopped_data_address (struct target_ops *t, CORE_ADDR *paddr)
 /* Target to_region_ok_for_hw_watchpoint implementation.  Return 1 if
    the specified region can be covered by the watch registers.  */
 
-static int
-mips_linux_region_ok_for_hw_watchpoint (struct target_ops *self,
- CORE_ADDR addr, int len)
+int
+mips_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
 {
   struct pt_watch_regs dummy_regs;
   int i;
@@ -633,11 +662,10 @@ mips_linux_new_thread (struct lwp_info *lp)
 /* Target to_insert_watchpoint implementation.  Try to insert a new
    watch.  Return zero on success.  */
 
-static int
-mips_linux_insert_watchpoint (struct target_ops *self,
-      CORE_ADDR addr, int len,
-      enum target_hw_bp_type type,
-      struct expression *cond)
+int
+mips_linux_nat_target::insert_watchpoint (CORE_ADDR addr, int len,
+  enum target_hw_bp_type type,
+  struct expression *cond)
 {
   struct pt_watch_regs regs;
   struct mips_watchpoint *new_watch;
@@ -687,11 +715,10 @@ mips_linux_insert_watchpoint (struct target_ops *self,
 /* Target to_remove_watchpoint implementation.  Try to remove a watch.
    Return zero on success.  */
 
-static int
-mips_linux_remove_watchpoint (struct target_ops *self,
-      CORE_ADDR addr, int len,
-      enum target_hw_bp_type type,
-      struct expression *cond)
+int
+mips_linux_nat_target::remove_watchpoint (CORE_ADDR addr, int len,
+  enum target_hw_bp_type type,
+  struct expression *cond)
 {
   int retval;
   int deleted_one;
@@ -736,8 +763,8 @@ mips_linux_remove_watchpoint (struct target_ops *self,
 /* Target to_close implementation.  Free any watches and call the
    super implementation.  */
 
-static void
-mips_linux_close (struct target_ops *self)
+void
+mips_linux_nat_target::close ()
 {
   struct mips_watchpoint *w;
   struct mips_watchpoint *nw;
@@ -752,15 +779,12 @@ mips_linux_close (struct target_ops *self)
     }
   current_watches = NULL;
 
-  if (super_close)
-    super_close (self);
+  linux_nat_trad_target::close ();
 }
 
 void
 _initialize_mips_linux_nat (void)
 {
-  struct target_ops *t;
-
   add_setshow_boolean_cmd ("show-debug-regs", class_maintenance,
    &show_debug_regs, _("\
 Set whether to show variables that mirror the mips debug registers."), _("\
@@ -774,26 +798,7 @@ triggers a breakpoint or watchpoint."),
    &maintenance_set_cmdlist,
    &maintenance_show_cmdlist);
 
-  t = linux_trad_target (mips_linux_register_u_offset);
-
-  super_close = t->to_close;
-  t->to_close = mips_linux_close;
-
-  super_fetch_registers = t->to_fetch_registers;
-  super_store_registers = t->to_store_registers;
-
-  t->to_fetch_registers = mips64_linux_fetch_registers;
-  t->to_store_registers = mips64_linux_store_registers;
-
-  t->to_can_use_hw_breakpoint = mips_linux_can_use_hw_breakpoint;
-  t->to_remove_watchpoint = mips_linux_remove_watchpoint;
-  t->to_insert_watchpoint = mips_linux_insert_watchpoint;
-  t->to_stopped_by_watchpoint = mips_linux_stopped_by_watchpoint;
-  t->to_stopped_data_address = mips_linux_stopped_data_address;
-  t->to_region_ok_for_hw_watchpoint = mips_linux_region_ok_for_hw_watchpoint;
-
-  t->to_read_description = mips_linux_read_description;
-
-  linux_nat_add_target (t);
-  linux_nat_set_new_thread (t, mips_linux_new_thread);
+  add_target (&the_mips_linux_nat_target);
+  linux_nat_set_new_thread (&the_mips_linux_nat_target,
+    mips_linux_new_thread);
 }
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 19/40] target_ops/C++: AIX target

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.  Tested on AIX 7.2 on the compile farm.
---
 gdb/aix-thread.c | 161 +++++++++++++++++++++++++++++--------------------------
 gdb/rs6000-nat.c |  95 +++++++++++++++++---------------
 2 files changed, 138 insertions(+), 118 deletions(-)

diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index d2b951d94d..3727336fcb 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -108,7 +108,45 @@ struct pd_thread {
 
 /* This module's target-specific operations, active while pd_able is true.  */
 
-static struct target_ops aix_thread_ops;
+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"); }
+
+  void detach (inferior *, int) override;
+  void resume (ptid_t, int, enum gdb_signal) override;
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+  void mourn_inferior () override;
+
+  int thread_alive (ptid_t ptid) override;
+
+  const char *pid_to_str (ptid_t) override;
+
+  const char *extra_thread_info (struct thread_info *) override;
+
+  ptid_t get_ada_task_ptid (long lwp, long thread) override;
+};
+
+static aix_thread_target aix_thread_ops;
 
 /* Address of the function that libpthread will call when libpthdebug
    is ready to be initialized.  */
@@ -980,21 +1018,20 @@ aix_thread_inferior_created (struct target_ops *ops, int from_tty)
 
 /* Detach from the process attached to by aix_thread_attach().  */
 
-static void
-aix_thread_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+aix_thread_target::detach (inferior *inf, int from_tty)
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   pd_disable ();
-  beneath->to_detach (beneath, inf, from_tty);
+  beneath->detach (inf, from_tty);
 }
 
 /* Tell the inferior process to continue running thread PID if != -1
    and all threads otherwise.  */
 
-static void
-aix_thread_resume (struct target_ops *ops,
-                   ptid_t ptid, int step, enum gdb_signal sig)
+void
+aix_thread_target::resume (ptid_t ptid, int step, enum gdb_signal sig)
 {
   struct thread_info *thread;
   pthdb_tid_t tid[2];
@@ -1002,10 +1039,10 @@ aix_thread_resume (struct target_ops *ops,
   if (!PD_TID (ptid))
     {
       scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
-      struct target_ops *beneath = find_target_beneath (ops);
+      struct target_ops *beneath = find_target_beneath (this);
       
       inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
-      beneath->to_resume (beneath, ptid, step, sig);
+      beneath->resume (ptid, step, sig);
     }
   else
     {
@@ -1035,11 +1072,11 @@ aix_thread_resume (struct target_ops *ops,
    If an error occurs, return -1, else return the pid of the stopped
    thread.  */
 
-static ptid_t
-aix_thread_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status, int options)
+ptid_t
+aix_thread_target::wait (ptid_t ptid, struct target_waitstatus *status,
+ int options)
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   {
     scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
@@ -1047,7 +1084,7 @@ aix_thread_wait (struct target_ops *ops,
     pid_to_prc (&ptid);
 
     inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
-    ptid = beneath->to_wait (beneath, ptid, status, options);
+    ptid = beneath->wait (ptid, status, options);
   }
 
   if (ptid_get_pid (ptid) == -1)
@@ -1319,16 +1356,15 @@ fetch_regs_kernel_thread (struct regcache *regcache, int regno,
 /* Fetch register REGNO if != -1 or all registers otherwise from the
    thread/process connected to REGCACHE.  */
 
-static void
-aix_thread_fetch_registers (struct target_ops *ops,
-                            struct regcache *regcache, int regno)
+void
+aix_thread_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct thread_info *thread;
   pthdb_tid_t tid;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   if (!PD_TID (regcache_get_ptid (regcache)))
-    beneath->to_fetch_registers (beneath, regcache, regno);
+    beneath->fetch_registers (regcache, regno);
   else
     {
       thread = find_thread_ptid (regcache_get_ptid (regcache));
@@ -1674,16 +1710,15 @@ store_regs_kernel_thread (const struct regcache *regcache, int regno,
 /* Store gdb's current view of the register set into the
    thread/process connected to REGCACHE.  */
 
-static void
-aix_thread_store_registers (struct target_ops *ops,
-                            struct regcache *regcache, int regno)
+void
+aix_thread_target::store_registers (struct regcache *regcache, int regno)
 {
   struct thread_info *thread;
   pthdb_tid_t tid;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   if (!PD_TID (regcache_get_ptid (regcache)))
-    beneath->to_store_registers (beneath, regcache, regno);
+    beneath->store_registers (regcache, regno);
   else
     {
       thread = find_thread_ptid (regcache_get_ptid (regcache));
@@ -1699,40 +1734,41 @@ aix_thread_store_registers (struct target_ops *ops,
 
 /* Implement the to_xfer_partial target_ops method.  */
 
-static enum target_xfer_status
-aix_thread_xfer_partial (struct target_ops *ops, enum target_object object,
- const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf,
- ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+aix_thread_target::xfer_partial (enum target_object object,
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len)
 {
   scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
-  return beneath->to_xfer_partial (beneath, object, annex, readbuf,
-   writebuf, offset, len, xfered_len);
+  return beneath->xfer_partial (object, annex, readbuf,
+ writebuf, offset, len, xfered_len);
 }
 
 /* Clean up after the inferior exits.  */
 
-static void
-aix_thread_mourn_inferior (struct target_ops *ops)
+void
+aix_thread_target::mourn_inferior ()
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   pd_deactivate ();
-  beneath->to_mourn_inferior (beneath);
+  beneath->mourn_inferior ();
 }
 
 /* Return whether thread PID is still valid.  */
 
-static int
-aix_thread_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+aix_thread_target::thread_alive (ptid_t ptid)
 {
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   if (!PD_TID (ptid))
-    return beneath->to_thread_alive (beneath, ptid);
+    return beneath->thread_alive (ptid);
 
   /* We update the thread list every time the child stops, so all
      valid threads should be in the thread list.  */
@@ -1742,14 +1778,14 @@ aix_thread_thread_alive (struct target_ops *ops, ptid_t ptid)
 /* Return a printable representation of composite PID for use in
    "info threads" output.  */
 
-static const char *
-aix_thread_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+aix_thread_target::pid_to_str (ptid_t ptid)
 {
   static char *ret = NULL;
-  struct target_ops *beneath = find_target_beneath (ops);
+  struct target_ops *beneath = find_target_beneath (this);
 
   if (!PD_TID (ptid))
-    return beneath->to_pid_to_str (beneath, ptid);
+    return beneath->pid_to_str (ptid);
 
   /* Free previous return value; a new one will be allocated by
      xstrprintf().  */
@@ -1762,9 +1798,8 @@ aix_thread_pid_to_str (struct target_ops *ops, ptid_t ptid)
 /* Return a printable representation of extra information about
    THREAD, for use in "info threads" output.  */
 
-static const char *
-aix_thread_extra_thread_info (struct target_ops *self,
-      struct thread_info *thread)
+const char *
+aix_thread_target::extra_thread_info (struct thread_info *thread)
 {
   int status;
   pthdb_pthread_t pdtid;
@@ -1819,35 +1854,12 @@ aix_thread_extra_thread_info (struct target_ops *self,
   return ret;
 }
 
-static ptid_t
-aix_thread_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
+ptid_t
+aix_thread_target::get_ada_task_ptid (long lwp, long thread)
 {
   return ptid_build (ptid_get_pid (inferior_ptid), 0, thread);
 }
 
-/* Initialize target aix_thread_ops.  */
-
-static void
-init_aix_thread_ops (void)
-{
-  aix_thread_ops.to_shortname = "aix-threads";
-  aix_thread_ops.to_longname = _("AIX pthread support");
-  aix_thread_ops.to_doc = _("AIX pthread support");
-
-  aix_thread_ops.to_detach = aix_thread_detach;
-  aix_thread_ops.to_resume = aix_thread_resume;
-  aix_thread_ops.to_wait = aix_thread_wait;
-  aix_thread_ops.to_fetch_registers = aix_thread_fetch_registers;
-  aix_thread_ops.to_store_registers = aix_thread_store_registers;
-  aix_thread_ops.to_xfer_partial = aix_thread_xfer_partial;
-  aix_thread_ops.to_mourn_inferior = aix_thread_mourn_inferior;
-  aix_thread_ops.to_thread_alive = aix_thread_thread_alive;
-  aix_thread_ops.to_pid_to_str = aix_thread_pid_to_str;
-  aix_thread_ops.to_extra_thread_info = aix_thread_extra_thread_info;
-  aix_thread_ops.to_get_ada_task_ptid = aix_thread_get_ada_task_ptid;
-  aix_thread_ops.to_stratum = thread_stratum;
-  aix_thread_ops.to_magic = OPS_MAGIC;
-}
 
 /* Module startup initialization function, automagically called by
    init.c.  */
@@ -1855,9 +1867,6 @@ init_aix_thread_ops (void)
 void
 _initialize_aix_thread (void)
 {
-  init_aix_thread_ops ();
-  complete_target_initialization (&aix_thread_ops);
-
   /* Notice when object files get loaded and unloaded.  */
   gdb::observers::new_objfile.attach (new_objfile);
 
diff --git a/gdb/rs6000-nat.c b/gdb/rs6000-nat.c
index d8c15f00ea..0880d3748e 100644
--- a/gdb/rs6000-nat.c
+++ b/gdb/rs6000-nat.c
@@ -74,7 +74,34 @@
 # define ARCH64() (register_size (target_gdbarch (), 0) == 8)
 #endif
 
-static target_xfer_partial_ftype rs6000_xfer_shared_libraries;
+class rs6000_nat_target final : public inf_ptrace_target
+{
+public:
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
+  void create_inferior (const char *, const std::string &,
+ char **, int) override;
+
+  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+
+private:
+  enum target_xfer_status
+    xfer_shared_libraries (enum target_object object,
+   const char *annex, gdb_byte *readbuf,
+   const gdb_byte *writebuf,
+   ULONGEST offset, ULONGEST len,
+   ULONGEST *xfered_len);
+};
+
+static rs6000_nat_target the_rs6000_nat_target;
 
 /* Given REGNO, a gdb register number, return the corresponding
    number suitable for use as a ptrace() parameter.  Return -1 if
@@ -277,9 +304,8 @@ store_register (struct regcache *regcache, int regno)
 /* Read from the inferior all registers if REGNO == -1 and just register
    REGNO otherwise.  */
 
-static void
-rs6000_fetch_inferior_registers (struct target_ops *ops,
- struct regcache *regcache, int regno)
+void
+rs6000_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   if (regno != -1)
@@ -320,9 +346,8 @@ rs6000_fetch_inferior_registers (struct target_ops *ops,
    If REGNO is -1, do this for all registers.
    Otherwise, REGNO specifies which register (so we can save time).  */
 
-static void
-rs6000_store_inferior_registers (struct target_ops *ops,
- struct regcache *regcache, int regno)
+void
+rs6000_nat_target::store_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   if (regno != -1)
@@ -361,11 +386,12 @@ rs6000_store_inferior_registers (struct target_ops *ops,
 
 /* Implement the to_xfer_partial target_ops method.  */
 
-static enum target_xfer_status
-rs6000_xfer_partial (struct target_ops *ops, enum target_object object,
-     const char *annex, gdb_byte *readbuf,
-     const gdb_byte *writebuf,
-     ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+rs6000_nat_target::xfer_partial (enum target_object object,
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len)
 {
   pid_t pid = ptid_get_pid (inferior_ptid);
   int arch64 = ARCH64 ();
@@ -373,9 +399,9 @@ rs6000_xfer_partial (struct target_ops *ops, enum target_object object,
   switch (object)
     {
     case TARGET_OBJECT_LIBRARIES_AIX:
-      return rs6000_xfer_shared_libraries (ops, object, annex,
-   readbuf, writebuf,
-   offset, len, xfered_len);
+      return xfer_shared_libraries (object, annex,
+    readbuf, writebuf,
+    offset, len, xfered_len);
     case TARGET_OBJECT_MEMORY:
       {
  union
@@ -467,9 +493,9 @@ rs6000_xfer_partial (struct target_ops *ops, enum target_object object,
    process ID of the child, or MINUS_ONE_PTID in case of error; store
    the status in *OURSTATUS.  */
 
-static ptid_t
-rs6000_wait (struct target_ops *ops,
-     ptid_t ptid, struct target_waitstatus *ourstatus, int options)
+ptid_t
+rs6000_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
+ int options)
 {
   pid_t pid;
   int status, save_errno;
@@ -524,20 +550,17 @@ rs6000_wait (struct target_ops *ops,
 /* Set the current architecture from the host running GDB.  Called when
    starting a child process.  */
 
-static void (*super_create_inferior) (struct target_ops *,
-      const char *exec_file,
-      const std::string &allargs,
-      char **env, int from_tty);
-static void
-rs6000_create_inferior (struct target_ops * ops, const char *exec_file,
- const std::string &allargs, char **env, int from_tty)
+void
+rs6000_nat_target::create_inferior (const char *exec_file,
+    const std::string &allargs,
+    char **env, int from_tty)
 {
   enum bfd_architecture arch;
   unsigned long mach;
   bfd abfd;
   struct gdbarch_info info;
 
-  super_create_inferior (ops, exec_file, allargs, env, from_tty);
+  inf_ptrace_target::create_inferior (exec_file, allargs, env, from_tty);
 
   if (__power_rs ())
     {
@@ -617,9 +640,9 @@ rs6000_ptrace_ldinfo (ptid_t ptid)
 /* Implement the to_xfer_partial target_ops method for
    TARGET_OBJECT_LIBRARIES_AIX objects.  */
 
-static enum target_xfer_status
-rs6000_xfer_shared_libraries
-  (struct target_ops *ops, enum target_object object,
+enum target_xfer_status
+rs6000_nat_target::xfer_shared_libraries
+  (enum target_object object,
    const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf,
    ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
 {
@@ -648,17 +671,5 @@ rs6000_xfer_shared_libraries
 void
 _initialize_rs6000_nat (void)
 {
-  struct target_ops *t;
-
-  t = inf_ptrace_target ();
-  t->to_fetch_registers = rs6000_fetch_inferior_registers;
-  t->to_store_registers = rs6000_store_inferior_registers;
-  t->to_xfer_partial = rs6000_xfer_partial;
-
-  super_create_inferior = t->to_create_inferior;
-  t->to_create_inferior = rs6000_create_inferior;
-
-  t->to_wait = rs6000_wait;
-
-  add_target (t);
+  add_target (&the_rs6000_nat_target);
 }
--
2.14.3

Reply | Threaded
Open this post in threaded view
|

[PATCH 20/40] target_ops/C++: ARM GNU/Linux

Pedro Alves-7
In reply to this post by Pedro Alves-7
Straighforward conversion.  Smoke tested on the compile farm.
---
 gdb/arm-linux-nat.c | 137 +++++++++++++++++++++++++++-------------------------
 1 file changed, 71 insertions(+), 66 deletions(-)

diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
index d41ef723ff..75d89f284e 100644
--- a/gdb/arm-linux-nat.c
+++ b/gdb/arm-linux-nat.c
@@ -66,6 +66,38 @@
 
 extern int arm_apcs_32;
 
+class arm_linux_nat_target final : public linux_nat_target
+{
+public:
+  /* Add our register access methods.  */
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+
+  /* Add our hardware breakpoint and watchpoint implementation.  */
+  int can_use_hw_breakpoint (enum bptype, int, int) override;
+
+  int insert_hw_breakpoint (struct gdbarch *, struct bp_target_info *) override;
+
+  int remove_hw_breakpoint (struct gdbarch *, struct bp_target_info *) override;
+
+  int region_ok_for_hw_watchpoint (CORE_ADDR, int) override;
+
+  int insert_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
+ struct expression *) override;
+
+  int remove_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
+ struct expression *) override;
+  int stopped_by_watchpoint () override;
+
+  int stopped_data_address (CORE_ADDR *) override;
+
+  int watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int) override;
+
+  const struct target_desc *read_description () override;
+};
+
+static arm_linux_nat_target the_arm_linux_nat_target;
+
 /* Get the whole floating point state of the process and store it
    into regcache.  */
 
@@ -374,9 +406,8 @@ store_vfp_regs (const struct regcache *regcache)
    regno == -1, otherwise fetch all general registers or all floating
    point registers depending upon the value of regno.  */
 
-static void
-arm_linux_fetch_inferior_registers (struct target_ops *ops,
-    struct regcache *regcache, int regno)
+void
+arm_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
@@ -412,9 +443,8 @@ arm_linux_fetch_inferior_registers (struct target_ops *ops,
    regno == -1, otherwise store all general registers or all floating
    point registers depending upon the value of regno.  */
 
-static void
-arm_linux_store_inferior_registers (struct target_ops *ops,
-    struct regcache *regcache, int regno)
+void
+arm_linux_nat_target::store_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
@@ -495,8 +525,8 @@ ps_get_thread_area (struct ps_prochandle *ph,
   return PS_OK;
 }
 
-static const struct target_desc *
-arm_linux_read_description (struct target_ops *ops)
+const struct target_desc *
+arm_linux_nat_target::read_description ()
 {
   CORE_ADDR arm_hwcap = 0;
 
@@ -516,9 +546,9 @@ arm_linux_read_description (struct target_ops *ops)
  have_ptrace_getregset = TRIBOOL_TRUE;
     }
 
-  if (target_auxv_search (ops, AT_HWCAP, &arm_hwcap) != 1)
+  if (target_auxv_search (this, AT_HWCAP, &arm_hwcap) != 1)
     {
-      return ops->beneath->to_read_description (ops->beneath);
+      return this->beneath->read_description ();
     }
 
   if (arm_hwcap & HWCAP_IWMMXT)
@@ -551,7 +581,7 @@ arm_linux_read_description (struct target_ops *ops)
       return result;
     }
 
-  return ops->beneath->to_read_description (ops->beneath);
+  return this->beneath->read_description ();
 }
 
 /* Information describing the hardware breakpoint capabilities.  */
@@ -635,10 +665,9 @@ arm_linux_get_hw_watchpoint_count (void)
 
 /* Have we got a free break-/watch-point available for use?  Returns -1 if
    there is not an appropriate resource available, otherwise returns 1.  */
-static int
-arm_linux_can_use_hw_breakpoint (struct target_ops *self,
- enum bptype type,
- int cnt, int ot)
+int
+arm_linux_nat_target::can_use_hw_breakpoint (enum bptype type,
+     int cnt, int ot)
 {
   if (type == bp_hardware_watchpoint || type == bp_read_watchpoint
       || type == bp_access_watchpoint || type == bp_watchpoint)
@@ -1026,10 +1055,9 @@ arm_linux_remove_hw_breakpoint1 (const struct arm_linux_hw_breakpoint *bpt,
 }
 
 /* Insert a Hardware breakpoint.  */
-static int
-arm_linux_insert_hw_breakpoint (struct target_ops *self,
- struct gdbarch *gdbarch,
- struct bp_target_info *bp_tgt)
+int
+arm_linux_nat_target::insert_hw_breakpoint (struct gdbarch *gdbarch,
+    struct bp_target_info *bp_tgt)
 {
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
@@ -1045,10 +1073,9 @@ arm_linux_insert_hw_breakpoint (struct target_ops *self,
 }
 
 /* Remove a hardware breakpoint.  */
-static int
-arm_linux_remove_hw_breakpoint (struct target_ops *self,
- struct gdbarch *gdbarch,
- struct bp_target_info *bp_tgt)
+int
+arm_linux_nat_target::remove_hw_breakpoint (struct gdbarch *gdbarch,
+    struct bp_target_info *bp_tgt)
 {
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
@@ -1065,9 +1092,8 @@ arm_linux_remove_hw_breakpoint (struct target_ops *self,
 
 /* Are we able to use a hardware watchpoint for the LEN bytes starting at
    ADDR?  */
-static int
-arm_linux_region_ok_for_hw_watchpoint (struct target_ops *self,
-       CORE_ADDR addr, int len)
+int
+arm_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
 {
   const struct arm_linux_hwbp_cap *cap = arm_linux_get_hwbp_cap ();
   CORE_ADDR max_wp_length, aligned_addr;
@@ -1098,11 +1124,10 @@ arm_linux_region_ok_for_hw_watchpoint (struct target_ops *self,
 }
 
 /* Insert a Hardware breakpoint.  */
-static int
-arm_linux_insert_watchpoint (struct target_ops *self,
-     CORE_ADDR addr, int len,
-     enum target_hw_bp_type rw,
-     struct expression *cond)
+int
+arm_linux_nat_target::insert_watchpoint (CORE_ADDR addr, int len,
+ enum target_hw_bp_type rw,
+ struct expression *cond)
 {
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
@@ -1118,10 +1143,10 @@ arm_linux_insert_watchpoint (struct target_ops *self,
 }
 
 /* Remove a hardware breakpoint.  */
-static int
-arm_linux_remove_watchpoint (struct target_ops *self, CORE_ADDR addr,
-     int len, enum target_hw_bp_type rw,
-     struct expression *cond)
+int
+arm_linux_nat_target::remove_watchpoint (CORE_ADDR addr,
+ int len, enum target_hw_bp_type rw,
+ struct expression *cond)
 {
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
@@ -1137,8 +1162,8 @@ arm_linux_remove_watchpoint (struct target_ops *self, CORE_ADDR addr,
 }
 
 /* What was the data address the target was stopped on accessing.  */
-static int
-arm_linux_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
+int
+arm_linux_nat_target::stopped_data_address (CORE_ADDR *addr_p)
 {
   siginfo_t siginfo;
   int slot;
@@ -1167,17 +1192,17 @@ arm_linux_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
 }
 
 /* Has the target been stopped by hitting a watchpoint?  */
-static int
-arm_linux_stopped_by_watchpoint (struct target_ops *ops)
+int
+arm_linux_nat_target::stopped_by_watchpoint ()
 {
   CORE_ADDR addr;
-  return arm_linux_stopped_data_address (ops, &addr);
+  return stopped_data_address (&addr);
 }
 
-static int
-arm_linux_watchpoint_addr_within_range (struct target_ops *target,
- CORE_ADDR addr,
- CORE_ADDR start, int length)
+int
+arm_linux_nat_target::watchpoint_addr_within_range (CORE_ADDR addr,
+    CORE_ADDR start,
+    int length)
 {
   return start <= addr && start + length - 1 >= addr;
 }
@@ -1294,30 +1319,10 @@ arm_linux_new_fork (struct lwp_info *parent, pid_t child_pid)
 void
 _initialize_arm_linux_nat (void)
 {
-  struct target_ops *t;
-
-  /* Fill in the generic GNU/Linux methods.  */
-  t = linux_target ();
-
-  /* Add our register access methods.  */
-  t->to_fetch_registers = arm_linux_fetch_inferior_registers;
-  t->to_store_registers = arm_linux_store_inferior_registers;
-
-  /* Add our hardware breakpoint and watchpoint implementation.  */
-  t->to_can_use_hw_breakpoint = arm_linux_can_use_hw_breakpoint;
-  t->to_insert_hw_breakpoint = arm_linux_insert_hw_breakpoint;
-  t->to_remove_hw_breakpoint = arm_linux_remove_hw_breakpoint;
-  t->to_region_ok_for_hw_watchpoint = arm_linux_region_ok_for_hw_watchpoint;
-  t->to_insert_watchpoint = arm_linux_insert_watchpoint;
-  t->to_remove_watchpoint = arm_linux_remove_watchpoint;
-  t->to_stopped_by_watchpoint = arm_linux_stopped_by_watchpoint;
-  t->to_stopped_data_address = arm_linux_stopped_data_address;
-  t->to_watchpoint_addr_within_range = arm_linux_watchpoint_addr_within_range;
-
-  t->to_read_description = arm_linux_read_description;
+  target_ops *t = &the_arm_linux_nat_target;
 
   /* Register the target.  */
-  linux_nat_add_target (t);
+  add_target (t);
 
   /* Handle thread creation and exit.  */
   linux_nat_set_new_thread (t, arm_linux_new_thread);
--
2.14.3

1234