public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/58] Turn gdbserver's process_stratum_target into a class
@ 2020-02-11  9:02 Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 04/58] gdbserver: turn target op 'attach' into a method Tankut Baris Aktemur
                   ` (59 more replies)
  0 siblings, 60 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:02 UTC (permalink / raw)
  To: gdb-patches

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 6962 bytes --]

Hi All,

This is a C++'ification series that aims to convert the target ops
vector in gdbserver into a class.  Currently, the target ops is a
struct of function pointers.  At the end of the series, it becomes a
class with methods, and the existing low target definitions become
subclasses.  That is, we end up with the following class hierarchy:

process_stratum_target
^
├── linux-low
├── lynx-low
├── nto-low
└── win32-low

process_stratum_target either defines the default behavior for the
target ops or leaves them as pure virtual for the subclasses to
override.

PATCH 1's commit message gives more details about the approach in this
transformation.

If and when this series is accepted, the next step is to C++'ify linux
low targets, giving a hierarchy that looks like below.  (This second
phase is not included in this series.)

process_stratum_target
^
├── linux-low
│   ^
│   ├── linux-arm-low
│   ├── linux-ppc-low
│   ├── linux-x86-low
│   └── ...
├── lynx-low
├── nto-low
└── win32-low

My goal in this series was to make gdbserver buildable after each
patch.  I could test this for linux-low, but not for other targets --
in particular, for lynx-low, nto-low, and win32-low.  I verified their
code manually to my best; however, I may have made typos or some
oversights that break build on these systems.  Can builbot be used to
test?

The patches are also available at

https://github.com/barisaktemur/gdb/commits/gdbserver-cppify-target-v1

Thanks.
Baris

Tankut Baris Aktemur (58):
  gdbserver: start turning the target ops vector into a class
  gdbserver: turn target op 'create_inferior' into a method
  gdbserver: turn target op 'post_create_inferior' into a method
  gdbserver: turn target op 'attach' into a method
  gdbserver: turn target op 'kill' into a method
  gdbserver: turn target op 'detach' into a method
  gdbserver: turn target op 'mourn' into a method
  gdbserver: turn target op 'join' into a method
  gdbserver: turn target op 'thread_alive' into a method
  gdbserver: turn target op 'resume' into a method
  gdbserver: turn target op 'wait' into a method
  gdbserver: turn target ops 'fetch_registers' and 'store_registers'
    into methods
  gdbserver: turn prepare_to_access_memory & done_accessing_memory into
    methods
  gdbserver: turn target ops 'read_memory' and 'write_memory' into
    methods
  gdbserver: turn target op 'look_up_symbols' into a method
  gdbserver: turn target op 'request_interrupt' into a method
  gdbserver: turn target op 'read_auxv' into a method
  gdbserver: turn target op 'supports_z_point_type' into a method
  gdbserver: turn target ops 'insert_point' and 'remove_point' into
    methods
  gdbserver: turn target op '{supports_}stopped_by_sw_breakpoint' into a
    method
  gdbserver: turn target op '{supports_}stopped_by_hw_breakpoint' into a
    method
  gdbserver: turn target op 'supports_hardware_single_step' into a
    method
  gdbserver: turn target ops 'stopped_by_watchpoint' and
    'stopped_data_address' into methods
  gdbserver: turn target op 'read_offsets' into a method
  gdbserver: turn target op 'get_tls_address' into a method
  gdbserver: turn target op 'hostio_last_error' into a method
  gdbserver: turn target op 'qxfer_osdata' into a method
  gdbserver: turn target op 'qxfer_siginfo' into a method
  gdbserver: turn non-stop and async target ops into methods
  gdbserver: turn target op 'supports_multi_process' into a method
  gdbserver: turn target ops 'supports_{fork,vfork,exec}_events' into
    methods
  gdbserver: turn target op 'handle_new_gdb_connection' into a method
  gdbserver: turn target op 'handle_monitor_command' into a method
  gdbserver: turn target op 'core_of_thread' into a method
  gdbserver: turn target op 'read_loadmap' into a method
  gdbserver: turn target op 'process_qsupported' into a method
  gdbserver: turn target op 'supports_tracepoints' into a method
  gdbserver: turn target ops 'read_pc' and 'write_pc' into methods
  gdbserver: turn target op 'thread_stopped' into a method
  gdbserver: turn target op 'get_tib_address' into a method
  gdbserver: turn target ops 'pause_all' and 'unpause_all' into methods
  gdbserver: turn target op 'stabilize_threads' into a method
  gdbserver: turn fast tracepoint target ops into methods
  gdbserver: turn target op 'emit_ops' into a method
  gdbserver: turn target op 'supports_disable_randomization' into a
    method
  gdbserver: turn target op 'qxfer_libraries_svr4' into a method
  gdbserver: turn target op 'supports_agent' into a method
  gdbserver: turn btrace-related target ops into methods
  gdbserver: turn target op 'supports_range_stepping' into a method
  gdbserver: turn target op 'pid_to_exec_file' into a method
  gdbserver: turn target ops 'multifs_{open, readlink, unlink}' into
    methods
  gdbserver: turn breakpoint kind-related target ops into methods
  gdbserver: turn target ops 'thread_name' and 'thread_handle' into
    methods
  gdbserver: turn target op 'supports_software_single_step' into a
    method
  gdbserver: turn target op 'supports_catch_syscall' into a method
  gdbserver: turn target op 'get_ipa_tdesc_idx' into a method
  gdbserver: use unique_ptr for 'the_target'
  gdbserver: finish turning the target ops vector into a class

 gdbserver/fork-child.c        |   2 +-
 gdbserver/hostio.c            |  13 +-
 gdbserver/linux-aarch32-low.c |   6 +-
 gdbserver/linux-aarch64-low.c |   4 +-
 gdbserver/linux-arm-low.c     |   8 +-
 gdbserver/linux-cris-low.c    |   4 +-
 gdbserver/linux-crisv32-low.c |   4 +-
 gdbserver/linux-low.c         | 635 ++++++++++++++++++----------------
 gdbserver/linux-low.h         | 222 ++++++++++++
 gdbserver/linux-m32r-low.c    |   4 +-
 gdbserver/linux-mips-low.c    |   2 +-
 gdbserver/linux-nios2-low.c   |   4 +-
 gdbserver/linux-ppc-low.c     |   2 +-
 gdbserver/linux-sh-low.c      |   2 +-
 gdbserver/linux-sparc-low.c   |   6 +-
 gdbserver/linux-tic6x-low.c   |   2 +-
 gdbserver/linux-tile-low.c    |   2 +-
 gdbserver/linux-x86-low.c     |   2 +-
 gdbserver/linux-xtensa-low.c  |   4 +-
 gdbserver/lynx-low.c          | 128 +++----
 gdbserver/lynx-low.h          |  42 +++
 gdbserver/mem-break.c         |  11 +-
 gdbserver/nto-low.c           | 208 ++++-------
 gdbserver/nto-low.h           |  59 ++++
 gdbserver/regcache.c          |  16 +-
 gdbserver/remote-utils.c      |  15 +-
 gdbserver/server.c            |  77 +++--
 gdbserver/target.c            | 578 +++++++++++++++++++++++++++----
 gdbserver/target.h            | 555 ++++++++++++++---------------
 gdbserver/tracepoint.c        |  54 ++-
 gdbserver/win32-low.c         | 214 +++++-------
 gdbserver/win32-low.h         |  68 ++++
 32 files changed, 1803 insertions(+), 1150 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 15/58] gdbserver: turn target op 'look_up_symbols' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (27 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 19/58] gdbserver: turn target ops 'insert_point' and 'remove_point' into methods Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-13 20:28   ` Pedro Alves
  2020-02-11  9:03 ` [PATCH 13/58] gdbserver: turn prepare_to_access_memory & done_accessing_memory into methods Tankut Baris Aktemur
                   ` (30 subsequent siblings)
  59 siblings, 1 reply; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's look_up_symbols op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	* target.c (process_target::look_up_symbols): Define.

	Update the derived structs and callers below.

	* server.c (handle_query): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_look_up_symbols): Turn into ...
	(linux_process_target::look_up_symbols): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c |  5 ++---
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/server.c    |  4 ++--
 gdbserver/target.c    |  6 ++++++
 gdbserver/target.h    | 15 +++++++--------
 gdbserver/win32-low.c |  1 -
 8 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index dad9dcf86fc..89ef5ab9224 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -5898,8 +5898,8 @@ linux_process_target::write_memory (CORE_ADDR memaddr,
   return 0;
 }
 
-static void
-linux_look_up_symbols (void)
+void
+linux_process_target::look_up_symbols ()
 {
 #ifdef USE_THREAD_DB
   struct process_info *proc = current_process ();
@@ -7369,7 +7369,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_look_up_symbols,
   linux_request_interrupt,
   linux_read_auxv,
   linux_supports_z_point_type,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 58fd665ba66..ae9484d8211 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -304,6 +304,8 @@ public:
 
   int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
 		    int len) override;
+
+  void look_up_symbols () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index fe55f9bcdf3..21a03cf5d00 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -729,7 +729,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* look_up_symbols */
   lynx_request_interrupt,
   NULL,  /* read_auxv */
   NULL,  /* supports_z_point_type */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index f1c4be09f7f..fc548ff72ba 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -943,7 +943,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* nto_look_up_symbols */
   nto_request_interrupt,
   nto_read_auxv,
   nto_supports_z_point_type,
diff --git a/gdbserver/server.c b/gdbserver/server.c
index 92feff36516..4785eabaf06 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -2192,8 +2192,8 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (target_supports_tracepoints ())
 	tracepoint_look_up_symbols ();
 
-      if (current_thread != NULL && the_target->look_up_symbols != NULL)
-	(*the_target->look_up_symbols) ();
+      if (current_thread != NULL)
+	the_target->pt->look_up_symbols ();
 
       current_thread = save_thread;
 
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 49302f61dfb..dd9ee8dfd47 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -408,3 +408,9 @@ process_target::done_accessing_memory ()
 {
   /* Nop.  */
 }
+
+void
+process_target::look_up_symbols ()
+{
+  /* Nop.  */
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 5621dc1d60e..73343bd0c03 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,14 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Query GDB for the values of any symbols we're interested in.
-     This function is called whenever we receive a "qSymbols::"
-     query, which corresponds to every time more symbols (might)
-     become available.  NULL if we aren't interested in any
-     symbols.  */
-
-  void (*look_up_symbols) (void);
-
   /* Send an interrupt request to the inferior process,
      however is appropriate.  */
 
@@ -476,6 +468,13 @@ public:
      Returns 0 on success and errno on failure.  */
   virtual int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
 			    int len) = 0;
+
+  /* Query GDB for the values of any symbols we're interested in.
+     This function is called whenever we receive a "qSymbols::"
+     query, which corresponds to every time more symbols (might)
+     become available.  NULL if we aren't interested in any
+     symbols.  */
+  virtual void look_up_symbols ();
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 1a56c9c45a4..8baf4a32e4f 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* lookup_symbols */
   win32_request_interrupt,
   NULL, /* read_auxv */
   win32_supports_z_point_type,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 28/58] gdbserver: turn target op 'qxfer_siginfo' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (3 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 48/58] gdbserver: turn btrace-related target ops into methods Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 06/58] gdbserver: turn target op 'detach' " Tankut Baris Aktemur
                   ` (54 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's qxfer_siginfo op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.  Also add
	'supports_qxfer_siginfo'.
	* target.c (process_target::qxfer_siginfo): Define.
	(process_target::supports_qxfer_siginfo): Define.

	Update the derived structs and callers below.

	* server.c (handle_qxfer_siginfo): Update.
	(handle_query): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::supports_qxfer_siginfo): Define.
	(linux_xfer_siginfo): Turn into ...
	(linux_process_target::qxfer_siginfo): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 15 +++++++++++----
 gdbserver/linux-low.h |  6 ++++++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/server.c    |  6 +++---
 gdbserver/target.c    | 14 ++++++++++++++
 gdbserver/target.h    | 13 ++++++++-----
 gdbserver/win32-low.c | 15 +++++++++++----
 gdbserver/win32-low.h |  6 ++++++
 9 files changed, 59 insertions(+), 18 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 595b4282ce2..387e160b8de 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6171,9 +6171,17 @@ siginfo_fixup (siginfo_t *siginfo, gdb_byte *inf_siginfo, int direction)
     }
 }
 
-static int
-linux_xfer_siginfo (const char *annex, unsigned char *readbuf,
-		    unsigned const char *writebuf, CORE_ADDR offset, int len)
+bool
+linux_process_target::supports_qxfer_siginfo ()
+{
+  return true;
+}
+
+int
+linux_process_target::qxfer_siginfo (const char *annex,
+				     unsigned char *readbuf,
+				     unsigned const char *writebuf,
+				     CORE_ADDR offset, int len)
 {
   int pid;
   siginfo_t siginfo;
@@ -7410,7 +7418,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_xfer_siginfo,
   linux_supports_non_stop,
   linux_async,
   linux_start_non_stop,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 5d1164ee944..a008dac66f4 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -354,6 +354,12 @@ public:
   int qxfer_osdata (const char *annex, unsigned char *readbuf,
 		    unsigned const char *writebuf,
 		    CORE_ADDR offset, int len) override;
+
+  bool supports_qxfer_siginfo () override;
+
+  int qxfer_siginfo (const char *annex, unsigned char *readbuf,
+		     unsigned const char *writebuf,
+		     CORE_ADDR offset, int len) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index f9a6b6891dc..d45e598cb26 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* qxfer_siginfo */
   NULL,  /* supports_non_stop */
   NULL,  /* async */
   NULL,  /* start_non_stop */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 002b655d407..4d3ef38a976 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -956,7 +956,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* xfer_siginfo */
   nto_supports_non_stop,
   NULL, /* async */
   NULL, /* start_non_stop */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index 59eb1c0c3d7..ece75f01868 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -1600,13 +1600,13 @@ handle_qxfer_siginfo (const char *annex,
 		      gdb_byte *readbuf, const gdb_byte *writebuf,
 		      ULONGEST offset, LONGEST len)
 {
-  if (the_target->qxfer_siginfo == NULL)
+  if (!the_target->pt->supports_qxfer_siginfo ())
     return -2;
 
   if (annex[0] != '\0' || current_thread == NULL)
     return -1;
 
-  return (*the_target->qxfer_siginfo) (annex, readbuf, writebuf, offset, len);
+  return the_target->pt->qxfer_siginfo (annex, readbuf, writebuf, offset, len);
 }
 
 /* Handle qXfer:statictrace:read.  */
@@ -2377,7 +2377,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (the_target->pt->supports_read_auxv ())
 	strcat (own_buf, ";qXfer:auxv:read+");
 
-      if (the_target->qxfer_siginfo != NULL)
+      if (the_target->pt->supports_qxfer_siginfo ())
 	strcat (own_buf, ";qXfer:siginfo:read+;qXfer:siginfo:write+");
 
       if (the_target->read_loadmap != NULL)
diff --git a/gdbserver/target.c b/gdbserver/target.c
index c6ed544e669..94bb45fcace 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -527,3 +527,17 @@ process_target::qxfer_osdata (const char *annex, unsigned char *readbuf,
 {
   gdb_assert_not_reached ("target op qxfer_osdata not supported");
 }
+
+bool
+process_target::supports_qxfer_siginfo ()
+{
+  return false;
+}
+
+int
+process_target::qxfer_siginfo (const char *annex, unsigned char *readbuf,
+			       unsigned const char *writebuf,
+			       CORE_ADDR offset, int len)
+{
+  gdb_assert_not_reached ("target op qxfer_siginfo not supported");
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index ecc32e16f87..bec147de089 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,11 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Read/Write extra signal info.  */
-  int (*qxfer_siginfo) (const char *annex, unsigned char *readbuf,
-			unsigned const char *writebuf,
-			CORE_ADDR offset, int len);
-
   int (*supports_non_stop) (void);
 
   /* Enables async target events.  Returns the previous enable
@@ -482,6 +477,14 @@ public:
   virtual int qxfer_osdata (const char *annex, unsigned char *readbuf,
 			    unsigned const char *writebuf,
 			    CORE_ADDR offset, int len);
+
+  /* Return true if the qxfer_siginfo target op is supported.  */
+  virtual bool supports_qxfer_siginfo ();
+
+  /* Read/Write extra signal info.  */
+  virtual int qxfer_siginfo (const char *annex, unsigned char *readbuf,
+			     unsigned const char *writebuf,
+			     CORE_ADDR offset, int len);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 749460ea1aa..45fd49458e7 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1783,11 +1783,19 @@ win32_process_target::hostio_last_error (char *buf)
 }
 #endif
 
+bool
+win32_process_target::supports_qxfer_siginfo ()
+{
+  return true;
+}
+
 /* Write Windows signal info.  */
 
-static int
-win32_xfer_siginfo (const char *annex, unsigned char *readbuf,
-		    unsigned const char *writebuf, CORE_ADDR offset, int len)
+int
+win32_process_target::qxfer_siginfo (const char *annex,
+				     unsigned char *readbuf,
+				     unsigned const char *writebuf,
+				     CORE_ADDR offset, int len)
 {
   if (siginfo_er.ExceptionCode == 0)
     return -1;
@@ -1834,7 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_xfer_siginfo,
   NULL, /* supports_non_stop */
   NULL, /* async */
   NULL, /* start_non_stop */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 776f41faf10..105c1443968 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -155,6 +155,12 @@ public:
 #ifdef _WIN32_WCE
   void hostio_last_error (char *buf) override;
 #endif
+
+  bool supports_qxfer_siginfo () override;
+
+  int qxfer_siginfo (const char *annex, unsigned char *readbuf,
+		     unsigned const char *writebuf,
+		     CORE_ADDR offset, int len) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 23/58] gdbserver: turn target ops 'stopped_by_watchpoint' and 'stopped_data_address' into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (12 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 09/58] gdbserver: turn target op 'thread_alive' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 25/58] gdbserver: turn target op 'get_tls_address' into a method Tankut Baris Aktemur
                   ` (45 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's stopped_by_watchpoint and
	stopped_data_address ops methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	* target.c (process_target::stopped_by_watchpoint): Define.
	(process_target::stopped_data_address): Define.

	Update the derived structs and callers below.

	* remote-utils.c (prepare_resume_reply): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_stopped_by_watchpoint): Turn into ...
	(linux_process_target::stopped_by_watchpoint): ... this.
	(linux_stopped_data_address): Turn into ...
	(linux_process_target::stopped_data_address): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_stopped_by_watchpoint): Turn into ...
	(nto_process_target::stopped_by_watchpoint): ... this.
	(nto_stopped_data_address): Turn into ...
	(nto_process_target::stopped_data_address): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_stopped_by_watchpoint): Turn into ...
	(win32_process_target::stopped_by_watchpoint): ... this.
	(win32_stopped_data_address): Turn into ...
	(win32_process_target::stopped_data_address): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c    | 11 ++++-------
 gdbserver/linux-low.h    |  4 ++++
 gdbserver/lynx-low.c     |  2 --
 gdbserver/nto-low.c      | 16 +++++++---------
 gdbserver/nto-low.h      |  4 ++++
 gdbserver/remote-utils.c |  5 ++---
 gdbserver/target.c       | 12 ++++++++++++
 gdbserver/target.h       | 17 ++++++++---------
 gdbserver/win32-low.c    | 12 +++++-------
 gdbserver/win32-low.h    |  4 ++++
 10 files changed, 50 insertions(+), 37 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index d43483c5e0b..a01ecd0c562 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -269,7 +269,6 @@ static int linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
 					  int *wstat, int options);
 static int linux_wait_for_event (ptid_t ptid, int *wstat, int options);
 static struct lwp_info *add_lwp (ptid_t ptid);
-static int linux_stopped_by_watchpoint (void);
 static void mark_lwp_dead (struct lwp_info *lwp, int wstat);
 static int lwp_is_marked_dead (struct lwp_info *lwp);
 static void proceed_all_lwps (void);
@@ -6044,16 +6043,16 @@ linux_supports_software_single_step (void)
   return can_software_single_step ();
 }
 
-static int
-linux_stopped_by_watchpoint (void)
+bool
+linux_process_target::stopped_by_watchpoint ()
 {
   struct lwp_info *lwp = get_thread_lwp (current_thread);
 
   return lwp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
 }
 
-static CORE_ADDR
-linux_stopped_data_address (void)
+CORE_ADDR
+linux_process_target::stopped_data_address ()
 {
   struct lwp_info *lwp = get_thread_lwp (current_thread);
 
@@ -7376,8 +7375,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_stopped_by_watchpoint,
-  linux_stopped_data_address,
 #if defined(__UCLIBC__) && defined(HAS_NOMMU)	      \
     && defined(PT_TEXT_ADDR) && defined(PT_DATA_ADDR) \
     && defined(PT_TEXT_END_ADDR)
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 00e563eddbe..59a1d9321d9 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -331,6 +331,10 @@ public:
   bool supports_stopped_by_hw_breakpoint () override;
 
   bool supports_hardware_single_step () override;
+
+  bool stopped_by_watchpoint () override;
+
+  CORE_ADDR stopped_data_address () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 23dc32c31f8..0d4934fb313 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,8 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* stopped_by_watchpoint */
-  NULL,  /* stopped_data_address */
   NULL,  /* read_offsets */
   NULL,  /* get_tls_address */
   NULL,  /* hostio_last_error */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 20db2dba3f4..fc7a6032fd6 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -878,12 +878,12 @@ nto_process_target::supports_hardware_single_step ()
 /* Check if the reason of stop for current thread (CURRENT_INFERIOR) is
    a watchpoint.
 
-   Return 1 if stopped by watchpoint, 0 otherwise.  */
+   Return true if stopped by watchpoint, false otherwise.  */
 
-static int
-nto_stopped_by_watchpoint (void)
+bool
+nto_process_target::stopped_by_watchpoint ()
 {
-  int ret = 0;
+  bool ret = false;
 
   TRACE ("%s\n", __func__);
   if (nto_inferior.ctl_fd != -1 && current_thread != NULL)
@@ -899,7 +899,7 @@ nto_stopped_by_watchpoint (void)
 	  err = devctl (nto_inferior.ctl_fd, DCMD_PROC_STATUS, &status,
 			sizeof (status), 0);
 	  if (err == EOK && (status.flags & watchmask))
-	    ret = 1;
+	    ret = true;
 	}
     }
   TRACE ("%s: %s\n", __func__, ret ? "yes" : "no");
@@ -910,8 +910,8 @@ nto_stopped_by_watchpoint (void)
 
    Return inferior's instruction pointer value, or 0 on error.  */ 
 
-static CORE_ADDR
-nto_stopped_data_address (void)
+CORE_ADDR
+nto_process_target::stopped_data_address ()
 {
   CORE_ADDR ret = (CORE_ADDR)0;
 
@@ -956,8 +956,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_stopped_by_watchpoint,
-  nto_stopped_data_address,
   NULL, /* nto_read_offsets */
   NULL, /* thread_db_set_tls_address */
   hostio_last_error_from_errno,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index 7b321077607..ad60bf913bf 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -93,6 +93,10 @@ public:
 		    int size, raw_breakpoint *bp) override;
 
   bool supports_hardware_single_step () override;
+
+  bool stopped_by_watchpoint () override;
+
+  CORE_ADDR stopped_data_address () override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/remote-utils.c b/gdbserver/remote-utils.c
index b5248ab368e..316f04e32ee 100644
--- a/gdbserver/remote-utils.c
+++ b/gdbserver/remote-utils.c
@@ -1214,8 +1214,7 @@ prepare_resume_reply (char *buf, ptid_t ptid,
 
 	regcache = get_thread_regcache (current_thread, 1);
 
-	if (the_target->stopped_by_watchpoint != NULL
-	    && (*the_target->stopped_by_watchpoint) ())
+	if (the_target->pt->stopped_by_watchpoint ())
 	  {
 	    CORE_ADDR addr;
 	    int i;
@@ -1223,7 +1222,7 @@ prepare_resume_reply (char *buf, ptid_t ptid,
 	    memcpy (buf, "watch:", 6);
 	    buf += 6;
 
-	    addr = (*the_target->stopped_data_address) ();
+	    addr = the_target->pt->stopped_data_address ();
 
 	    /* Convert each byte of the address into two hexadecimal
 	       chars.  Note that we take sizeof (void *) instead of
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 09b3a633fc8..00f5f794b85 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -469,3 +469,15 @@ process_target::supports_hardware_single_step ()
 {
   return false;
 }
+
+bool
+process_target::stopped_by_watchpoint ()
+{
+  return false;
+}
+
+CORE_ADDR
+process_target::stopped_data_address ()
+{
+  return 0;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 263efaf104f..f9c749fdfcb 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,15 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise.  */
-
-  int (*stopped_by_watchpoint) (void);
-
-  /* Returns the address associated with the watchpoint that hit, if any;
-     returns 0 otherwise.  */
-
-  CORE_ADDR (*stopped_data_address) (void);
-
   /* Reports the text, data offsets of the executable.  This is
      needed for uclinux where the executable is relocated during load
      time.  */
@@ -476,6 +467,14 @@ public:
 
   /* Returns true if the target can do hardware single step.  */
   virtual bool supports_hardware_single_step ();
+
+  /* Returns true if target was stopped due to a watchpoint hit, false
+     otherwise.  */
+  virtual bool stopped_by_watchpoint ();
+
+  /* Returns the address associated with the watchpoint that hit, if any;
+     returns 0 otherwise.  */
+  virtual CORE_ADDR stopped_data_address ();
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 0c4a948a37a..970c532c149 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -284,17 +284,17 @@ win32_process_target::remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
     return 1;
 }
 
-static int
-win32_stopped_by_watchpoint (void)
+bool
+win32_process_target::stopped_by_watchpoint ()
 {
   if (the_low_target.stopped_by_watchpoint != NULL)
     return the_low_target.stopped_by_watchpoint ();
   else
-    return 0;
+    return false;
 }
 
-static CORE_ADDR
-win32_stopped_data_address (void)
+CORE_ADDR
+win32_process_target::stopped_data_address ()
 {
   if (the_low_target.stopped_data_address != NULL)
     return the_low_target.stopped_data_address ();
@@ -1834,8 +1834,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_stopped_by_watchpoint,
-  win32_stopped_data_address,
   NULL, /* read_offsets */
   NULL, /* get_tls_address */
 #ifdef _WIN32_WCE
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index b13c53c4ed3..36926801f1e 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -147,6 +147,10 @@ public:
 		    int size, raw_breakpoint *bp) override;
 
   bool supports_hardware_single_step () override;
+
+  bool stopped_by_watchpoint () override;
+
+  CORE_ADDR stopped_data_address () override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 32/58] gdbserver: turn target op 'handle_new_gdb_connection' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (18 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 43/58] gdbserver: turn fast tracepoint target ops into methods Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 01/58] gdbserver: start turning the target ops vector into a class Tankut Baris Aktemur
                   ` (39 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's handle_new_gdb_connection op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_handle_new_gdb_connection): Update the macro.
	* target.c (process_target::handle_new_gdb_connection): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_handle_new_gdb_connection): Turn into ...
	(linux_process_target::handle_new_gdb_connection): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c |  5 ++---
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/target.c    |  6 ++++++
 gdbserver/target.h    | 12 ++++--------
 gdbserver/win32-low.c |  1 -
 7 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 0d133eb856e..4ec396af289 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6361,8 +6361,8 @@ linux_process_target::supports_exec_events ()
    ptrace flags for all inferiors.  This is in case the new GDB connection
    doesn't support the same set of events that the previous one did.  */
 
-static void
-linux_handle_new_gdb_connection (void)
+void
+linux_process_target::handle_new_gdb_connection ()
 {
   /* Request that all the lwps reset their ptrace options.  */
   for_each_thread ([] (thread_info *thread)
@@ -7418,7 +7418,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_handle_new_gdb_connection,
 #ifdef USE_THREAD_DB
   thread_db_handle_monitor_command,
 #else
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index d6482311829..0881155cc5e 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -374,6 +374,8 @@ public:
   bool supports_vfork_events () override;
 
   bool supports_exec_events () override;
+
+  void handle_new_gdb_connection () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index eaca6cde875..7bfd71c5321 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* handle_new_gdb_connection */
   NULL,  /* handle_monitor_command */
   NULL,  /* core_of_thread */
   NULL,  /* read_loadmap */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 9ae100f9000..8ff8063dfba 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* handle_new_gdb_connection */
   NULL, /* handle_monitor_command */
   NULL, /* core_of_thread */
   NULL, /* read_loadmap */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 15d48427f31..3416a3f449f 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -571,3 +571,9 @@ process_target::supports_exec_events ()
 {
   return false;
 }
+
+void
+process_target::handle_new_gdb_connection ()
+{
+  /* Nop.  */
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index ff09b1f9618..1138ed2e440 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Allows target to re-initialize connection-specific settings.  */
-  void (*handle_new_gdb_connection) (void);
-
   /* If not NULL, target-specific routine to process monitor command.
      Returns 1 if handled, or 0 to perform default processing.  */
   int (*handle_monitor_command) (char *);
@@ -486,6 +483,9 @@ public:
 
   /* Returns true if exec events are supported.  */
   virtual bool supports_exec_events ();
+
+  /* Allows target to re-initialize connection-specific settings.  */
+  virtual void handle_new_gdb_connection ();
 };
 
 extern process_stratum_target *the_target;
@@ -513,11 +513,7 @@ int kill_inferior (process_info *proc);
   the_target->pt->supports_exec_events ()
 
 #define target_handle_new_gdb_connection()		 \
-  do							 \
-    {							 \
-      if (the_target->handle_new_gdb_connection != NULL) \
-	(*the_target->handle_new_gdb_connection) ();	 \
-    } while (0)
+  the_target->pt->handle_new_gdb_connection ()
 
 #define detach_inferior(proc) \
   the_target->pt->detach (proc)
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index a60b223beb4..bee5cbbf643 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1842,7 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* handle_new_gdb_connection */
   NULL, /* handle_monitor_command */
   NULL, /* core_of_thread */
   NULL, /* read_loadmap */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 46/58] gdbserver: turn target op 'qxfer_libraries_svr4' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (31 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 11/58] gdbserver: turn target op 'wait' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 14/58] gdbserver: turn target ops 'read_memory' and 'write_memory' into methods Tankut Baris Aktemur
                   ` (26 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's qxfer_libraries_svr4 op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.  Also add
	'supports_qxfer_libraries_svr4'.
	* target.c (process_target::qxfer_libraries_svr4): Define.
	(process_target::supports_qxfer_libraries_svr4): Define.

	Update the derived structs and callers below.

	* server.c (handle_qxfer_libraries_svr4): Update.
	(handle_query): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::supports_qxfer_libraries_svr4): Define.
	(linux_qxfer_libraries_svr4): Turn into ...
	(linux_process_target::qxfer_libraries_svr4): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 16 +++++++++++-----
 gdbserver/linux-low.h |  7 +++++++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/server.c    |  8 +++++---
 gdbserver/target.c    | 15 +++++++++++++++
 gdbserver/target.h    | 14 +++++++++-----
 gdbserver/win32-low.c |  1 -
 8 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 1a35b5ed681..fcca23f0510 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6920,6 +6920,12 @@ read_one_ptr (CORE_ADDR memaddr, CORE_ADDR *ptr, int ptr_size)
   return ret;
 }
 
+bool
+linux_process_target::supports_qxfer_libraries_svr4 ()
+{
+  return true;
+}
+
 struct link_map_offsets
   {
     /* Offset and size of r_debug.r_version.  */
@@ -6946,10 +6952,11 @@ struct link_map_offsets
 
 /* Construct qXfer:libraries-svr4:read reply.  */
 
-static int
-linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
-			    unsigned const char *writebuf,
-			    CORE_ADDR offset, int len)
+int
+linux_process_target::qxfer_libraries_svr4 (const char *annex,
+					    unsigned char *readbuf,
+					    unsigned const char *writebuf,
+					    CORE_ADDR offset, int len)
 {
   struct process_info_private *const priv = current_process ()->priv;
   char filename[PATH_MAX];
@@ -7445,7 +7452,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_qxfer_libraries_svr4,
   linux_supports_agent,
 #ifdef HAVE_LINUX_BTRACE
   linux_enable_btrace,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 90569ec2abc..e0938fdf340 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -427,6 +427,13 @@ public:
   struct emit_ops *emit_ops () override;
 
   bool supports_disable_randomization () override;
+
+  bool supports_qxfer_libraries_svr4 () override;
+
+  int qxfer_libraries_svr4 (const char *annex,
+			    unsigned char *readbuf,
+			    unsigned const char *writebuf,
+			    CORE_ADDR offset, int len) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 0f2eb05c4ef..43fa36c5fbd 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* qxfer_libraries_svr4 */
   NULL,  /* support_agent */
   NULL,  /* enable_btrace */
   NULL,  /* disable_btrace */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 2c6ad118026..7940325c3b5 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* qxfer_libraries_svr4 */
   NULL, /* support_agent */
   NULL, /* enable_btrace */
   NULL, /* disable_btrace */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index 448089fd47c..61346e3ce5b 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -1574,10 +1574,12 @@ handle_qxfer_libraries_svr4 (const char *annex,
   if (writebuf != NULL)
     return -2;
 
-  if (current_thread == NULL || the_target->qxfer_libraries_svr4 == NULL)
+  if (current_thread == NULL
+      || !the_target->pt->supports_qxfer_libraries_svr4 ())
     return -1;
 
-  return the_target->qxfer_libraries_svr4 (annex, readbuf, writebuf, offset, len);
+  return the_target->pt->qxfer_libraries_svr4 (annex, readbuf, writebuf,
+					       offset, len);
 }
 
 /* Handle qXfer:osadata:read.  */
@@ -2364,7 +2366,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (target_supports_catch_syscall ())
 	strcat (own_buf, ";QCatchSyscalls+");
 
-      if (the_target->qxfer_libraries_svr4 != NULL)
+      if (the_target->pt->supports_qxfer_libraries_svr4 ())
 	strcat (own_buf, ";qXfer:libraries-svr4:read+"
 		";augmented-libraries-svr4-read+");
       else
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 0c8c13ae2f3..34b3ffd1cfd 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -705,3 +705,18 @@ process_target::supports_disable_randomization ()
 {
   return false;
 }
+
+bool
+process_target::supports_qxfer_libraries_svr4 ()
+{
+  return false;
+}
+
+int
+process_target::qxfer_libraries_svr4 (const char *annex,
+				      unsigned char *readbuf,
+				      unsigned const char *writebuf,
+				      CORE_ADDR offset, int len)
+{
+  gdb_assert_not_reached ("target op qxfer_libraries_svr4 not supported");
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 85ce8034543..3e90227c4fd 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,11 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Read solib info on SVR4 platforms.  */
-  int (*qxfer_libraries_svr4) (const char *annex, unsigned char *readbuf,
-			       unsigned const char *writebuf,
-			       CORE_ADDR offset, int len);
-
   /* Return true if target supports debugging agent.  */
   int (*supports_agent) (void);
 
@@ -493,6 +488,15 @@ public:
 
   /* Returns true if the target supports disabling randomization.  */
   virtual bool supports_disable_randomization ();
+
+  /* Return true if the qxfer_libraries_svr4 op is supported.  */
+  virtual bool supports_qxfer_libraries_svr4 ();
+
+  /* Read solib info on SVR4 platforms.  */
+  virtual int qxfer_libraries_svr4 (const char *annex,
+				    unsigned char *readbuf,
+				    unsigned const char *writebuf,
+				    CORE_ADDR offset, int len);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 81c04f65251..f54d1bf0ef3 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,7 +1848,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* qxfer_libraries_svr4 */
   NULL, /* support_agent */
   NULL, /* enable_btrace */
   NULL, /* disable_btrace */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 11/58] gdbserver: turn target op 'wait' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (30 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 18/58] gdbserver: turn target op 'supports_z_point_type' into a method Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 46/58] gdbserver: turn target op 'qxfer_libraries_svr4' " Tankut Baris Aktemur
                   ` (27 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's wait op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.

	Update the derived structs and callers below.

	* target.c (target_wait): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_wait): Turn into ...
	(linux_process_target::wait): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_wait): Turn into ...
	(lynx_process_target::wait): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_wait): Turn into ...
	(nto_process_target::wait): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_wait): Turn into ...
	(win32_process_target::wait): ... this.
	(do_initial_child_stuff): Update.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c |  8 ++++----
 gdbserver/linux-low.h |  3 +++
 gdbserver/lynx-low.c  |  6 +++---
 gdbserver/lynx-low.h  |  3 +++
 gdbserver/nto-low.c   |  7 +++----
 gdbserver/nto-low.h   |  3 +++
 gdbserver/target.c    |  2 +-
 gdbserver/target.h    | 26 +++++++++++++-------------
 gdbserver/win32-low.c | 12 +++++-------
 gdbserver/win32-low.h |  3 +++
 10 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 5722752fd12..9f6f1064f45 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -3833,9 +3833,10 @@ async_file_mark (void)
      be awakened anyway.  */
 }
 
-static ptid_t
-linux_wait (ptid_t ptid,
-	    struct target_waitstatus *ourstatus, int target_options)
+ptid_t
+linux_process_target::wait (ptid_t ptid,
+			    target_waitstatus *ourstatus,
+			    int target_options)
 {
   ptid_t event_ptid;
 
@@ -7358,7 +7359,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_wait,
   linux_fetch_registers,
   linux_store_registers,
   linux_prepare_to_access_memory,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 48d92f73ced..c402d8e1c94 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -287,6 +287,9 @@ public:
   bool thread_alive (ptid_t pid) override;
 
   void resume (thread_resume *resume_info, size_t n) override;
+
+  ptid_t wait (ptid_t ptid, target_waitstatus *status,
+	       int options) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index b3eacd8b6c2..24830d1c289 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -505,8 +505,9 @@ retry:
 /* A wrapper around lynx_wait_1 that also prints debug traces when
    such debug traces have been activated.  */
 
-static ptid_t
-lynx_wait (ptid_t ptid, struct target_waitstatus *status, int options)
+ptid_t
+lynx_process_target::wait (ptid_t ptid, target_waitstatus *status,
+			   int options)
 {
   ptid_t new_ptid;
 
@@ -726,7 +727,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_wait,
   lynx_fetch_registers,
   lynx_store_registers,
   NULL,  /* prepare_to_access_memory */
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index 6ad41545679..1b21ffb4c0a 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -73,6 +73,9 @@ public:
   bool thread_alive (ptid_t pid) override;
 
   void resume (thread_resume *resume_info, size_t n) override;
+
+  ptid_t wait (ptid_t ptid, target_waitstatus *status,
+	       int options) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index aba63786203..462936f5eb7 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -518,9 +518,9 @@ nto_process_target::resume (thread_resume *resume_info, size_t n)
 
    Return ptid of thread that caused the event.  */
 
-static ptid_t
-nto_wait (ptid_t ptid,
-	  struct target_waitstatus *ourstatus, int target_options)
+ptid_t
+nto_process_target::wait (ptid_t ptid, target_waitstatus *ourstatus,
+			  int target_options)
 {
   sigset_t set;
   siginfo_t info;
@@ -941,7 +941,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_wait,
   nto_fetch_registers,
   nto_store_registers,
   NULL, /* prepare_to_access_memory */
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index b0ca4247e69..faa7cab2941 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -63,6 +63,9 @@ public:
   bool thread_alive (ptid_t pid) override;
 
   void resume (thread_resume *resume_info, size_t n) override;
+
+  ptid_t wait (ptid_t ptid, target_waitstatus *status,
+	       int options) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.c b/gdbserver/target.c
index eca53de982e..b73c4465f1c 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -223,7 +223,7 @@ target_stop_and_wait (ptid_t ptid)
 ptid_t
 target_wait (ptid_t ptid, struct target_waitstatus *status, int options)
 {
-  return (*the_target->wait) (ptid, status, options);
+  return the_target->pt->wait (ptid, status, options);
 }
 
 /* See target/target.h.  */
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 0a07d7f8c85..43532161f34 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,19 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Wait for the inferior process or thread to change state.  Store
-     status through argument pointer STATUS.
-
-     PTID = -1 to wait for any pid to do something, PTID(pid,0,0) to
-     wait for any thread of process pid to do something.  Return ptid
-     of child, or -1 in case of error; store status through argument
-     pointer STATUS.  OPTIONS is a bit set of options defined as
-     TARGET_W* above.  If options contains TARGET_WNOHANG and there's
-     no child stop to report, return is
-     null_ptid/TARGET_WAITKIND_IGNORE.  */
-
-  ptid_t (*wait) (ptid_t ptid, struct target_waitstatus *status, int options);
-
   /* Fetch registers from the inferior process.
 
      If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO.  */
@@ -481,6 +468,19 @@ public:
 
   /* Resume the inferior process.  */
   virtual void resume (thread_resume *resume_info, size_t n) = 0;
+
+  /* Wait for the inferior process or thread to change state.  Store
+     status through argument pointer STATUS.
+
+     PTID = -1 to wait for any pid to do something, PTID(pid,0,0) to
+     wait for any thread of process pid to do something.  Return ptid
+     of child, or -1 in case of error; store status through argument
+     pointer STATUS.  OPTIONS is a bit set of options defined as
+     TARGET_W* above.  If options contains TARGET_WNOHANG and there's
+     no child stop to report, return is
+     null_ptid/TARGET_WAITKIND_IGNORE.  */
+  virtual ptid_t wait (ptid_t ptid, target_waitstatus *status,
+		       int options) = 0;
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index fcbf3075e80..b2723b6d292 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -103,8 +103,6 @@ typedef BOOL (WINAPI *winapi_DebugSetProcessKillOnExit) (BOOL KillOnExit);
 typedef BOOL (WINAPI *winapi_DebugBreakProcess) (HANDLE);
 typedef BOOL (WINAPI *winapi_GenerateConsoleCtrlEvent) (DWORD, DWORD);
 
-static ptid_t win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus,
-			  int options);
 static void win32_resume (struct thread_resume *resume_info, size_t n);
 #ifndef _WIN32_WCE
 static void win32_add_all_dlls (void);
@@ -380,7 +378,7 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
     {
       struct target_waitstatus status;
 
-      win32_wait (minus_one_ptid, &status, 0);
+      the_target->pt->wait (minus_one_ptid, &status, 0);
 
       /* Note win32_wait doesn't return thread events.  */
       if (status.kind != TARGET_WAITKIND_LOADED)
@@ -707,7 +705,7 @@ win32_process_target::create_inferior (
 
   /* Wait till we are at 1st instruction in program, return new pid
      (assuming success).  */
-  cs.last_ptid = win32_wait (ptid_t (current_process_id), &cs.last_status, 0);
+  cs.last_ptid = wait (ptid_t (current_process_id), &cs.last_status, 0);
 
   return current_process_id;
 }
@@ -1600,8 +1598,9 @@ get_child_debug_event (struct target_waitstatus *ourstatus)
 /* Wait for the inferior process to change state.
    STATUS will be filled in with a response code to send to GDB.
    Returns the signal which caused the process to stop. */
-static ptid_t
-win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options)
+ptid_t
+win32_process_target::wait (ptid_t ptid, target_waitstatus *ourstatus,
+			    int options)
 {
   struct regcache *regcache;
 
@@ -1828,7 +1827,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_wait,
   win32_fetch_inferior_registers,
   win32_store_inferior_registers,
   NULL, /* prepare_to_access_memory */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 472be13d518..aa509f64ca8 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -122,6 +122,9 @@ public:
   bool thread_alive (ptid_t pid) override;
 
   void resume (thread_resume *resume_info, size_t n) override;
+
+  ptid_t wait (ptid_t ptid, target_waitstatus *status,
+	       int options) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 26/58] gdbserver: turn target op 'hostio_last_error' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 04/58] gdbserver: turn target op 'attach' into a method Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 22/58] gdbserver: turn target op 'supports_hardware_single_step' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 48/58] gdbserver: turn btrace-related target ops into methods Tankut Baris Aktemur
                   ` (56 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's hostio_last_error op a
	method of process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	* target.c: Add "hostio.h" to includes.
	(process_target::hostio_last_error): Define.

	Update the derived structs and callers below.

	* hostio.c (hostio_error): Update.
	* linux-low.c: Remove "hostio.h" from includes.
	(linux_target_ops): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.h (class win32_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(wince_hostio_last_error): Turn into ...
	(win32_process_target::hostio_last_error): ... this.
---
 gdbserver/hostio.c    | 2 +-
 gdbserver/linux-low.c | 2 --
 gdbserver/lynx-low.c  | 1 -
 gdbserver/nto-low.c   | 1 -
 gdbserver/target.c    | 7 +++++++
 gdbserver/target.h    | 8 ++++----
 gdbserver/win32-low.c | 9 ++-------
 gdbserver/win32-low.h | 4 ++++
 8 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/gdbserver/hostio.c b/gdbserver/hostio.c
index 8af4fbf4087..a3b32cd0fdc 100644
--- a/gdbserver/hostio.c
+++ b/gdbserver/hostio.c
@@ -196,7 +196,7 @@ require_valid_fd (int fd)
 static void
 hostio_error (char *own_buf)
 {
-  the_target->hostio_last_error (own_buf);
+  the_target->pt->hostio_last_error (own_buf);
 }
 
 static void
diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 66732a2d77f..d8209527f0e 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -45,7 +45,6 @@
 #include <sys/uio.h>
 #include "gdbsupport/filestuff.h"
 #include "tracepoint.h"
-#include "hostio.h"
 #include <inttypes.h>
 #include "gdbsupport/common-inferior.h"
 #include "nat/fork-inferior.h"
@@ -7404,7 +7403,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  hostio_last_error_from_errno,
   linux_qxfer_osdata,
   linux_xfer_siginfo,
   linux_supports_non_stop,
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 4525d6e694a..493c48ef355 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* hostio_last_error */
   NULL,  /* qxfer_osdata */
   NULL,  /* qxfer_siginfo */
   NULL,  /* supports_non_stop */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 38ddcbaa33a..e5f7af2b66e 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -956,7 +956,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  hostio_last_error_from_errno,
   NULL, /* nto_qxfer_osdata */
   NULL, /* xfer_siginfo */
   nto_supports_non_stop,
diff --git a/gdbserver/target.c b/gdbserver/target.c
index f578dbea0da..e09ee7d0fa4 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -21,6 +21,7 @@
 #include "server.h"
 #include "tracepoint.h"
 #include "gdbsupport/byte-vector.h"
+#include "hostio.h"
 
 process_stratum_target *the_target;
 
@@ -506,3 +507,9 @@ process_target::get_tls_address (thread_info *thread, CORE_ADDR offset,
 {
   gdb_assert_not_reached ("target op get_tls_address not supported");
 }
+
+void
+process_target::hostio_last_error (char *buf)
+{
+  hostio_last_error_from_errno (buf);
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index aed363991ef..b3ceaa34ad0 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Fill BUF with an hostio error packet representing the last hostio
-     error.  */
-  void (*hostio_last_error) (char *buf);
-
   /* Read/Write OS data using qXfer packets.  */
   int (*qxfer_osdata) (const char *annex, unsigned char *readbuf,
 		       unsigned const char *writebuf, CORE_ADDR offset,
@@ -479,6 +475,10 @@ public:
      support the operation.  */
   virtual int get_tls_address (thread_info *thread, CORE_ADDR offset,
 			       CORE_ADDR load_module, CORE_ADDR *address);
+
+  /* Fill BUF with an hostio error packet representing the last hostio
+     error.  */
+  virtual void hostio_last_error (char *buf);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 21008ccc7ab..dc75221d361 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1774,8 +1774,8 @@ win32_error_to_fileio_error (DWORD err)
   return FILEIO_EUNKNOWN;
 }
 
-static void
-wince_hostio_last_error (char *buf)
+void
+win32_process_target::hostio_last_error (char *buf)
 {
   DWORD winerr = GetLastError ();
   int fileio_err = win32_error_to_fileio_error (winerr);
@@ -1834,11 +1834,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-#ifdef _WIN32_WCE
-  wince_hostio_last_error,
-#else
-  hostio_last_error_from_errno,
-#endif
   NULL, /* qxfer_osdata */
   win32_xfer_siginfo,
   NULL, /* supports_non_stop */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 36926801f1e..776f41faf10 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -151,6 +151,10 @@ public:
   bool stopped_by_watchpoint () override;
 
   CORE_ADDR stopped_data_address () override;
+
+#ifdef _WIN32_WCE
+  void hostio_last_error (char *buf) override;
+#endif
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 01/58] gdbserver: start turning the target ops vector into a class
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (19 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 32/58] gdbserver: turn target op 'handle_new_gdb_connection' into a method Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-13 20:26   ` Pedro Alves
  2020-02-11  9:03 ` [PATCH 40/58] gdbserver: turn target op 'get_tib_address' into a method Tankut Baris Aktemur
                   ` (38 subsequent siblings)
  59 siblings, 1 reply; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

This is the beginning of a series of patches where the goal is to turn
the target ops vector into a class and all the target op function
pointers into methods of this class.  This is done by first
introducing a helper class, called 'process_target', that is initially
empty.  An instance of this class is added to the end of the current
target ops vector.  This new field is called 'pt'.  We will gradually
carry target ops to the new class, one by one, whereas the invocation
of the target op will be converted to a method call on 'pt'.

For instance, target op 'attach' is currently invoked as

  (*the_target->attach) (args)

After moving 'attach' as a method to 'process_target', it will be
invoked as

  the_target->pt->attach (args)

In this process, the concrete target vector definitions
(e.g. linux-low, win32-low, nto-low, etc.) are turned into derived
classes of 'process_target', so that they can either inherit the
default behavior of the target ops or can override the method.

We prefer to make this transition gradually rather than in a single
giant patch, to yield bite-size patches.  The goal is that after each
patch gdbserver will still be buildable and testable.

The general rule of thumb when converting a target op to a method is
this:

(1) If the function call is protected with a NULL-check with an
obvious default behavior, simply implement that default behavior in
the base class (e.g.: supports_non_stop).

(2) If there is no NULL-check guard, the method becomes pure
virtual, and the derived targets are required to implement the method
(e.g.: attach).

(3) If there is a NULL-check but no apparent default behavior, or if
the NULL-check is utilized to populate a feature support packet,
introduce a 'supports_XYZ' method (e.g.: pid_to_exec_file).

The overall strategy is to preserve the existing behavior as much as
possible.

When we're done moving all the target ops into 'process_target', the
target op vector will contain nothing but the field 'pt'.  At that
point, the auxiliary class 'process_target' will simply meld into
'process_stratum_target' and the method calls of the form
'the_target->pt->xyz' will be turned into 'the_target->xyz'.

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* target.h (class process_target): Define.
	(struct process_stratum_target): Add a new 'pt' field, which is
	a pointer to a 'process_target'.
	* linux-low.h (class linux_process_target): Define as a derived
	class of 'process_target'.
	* linux-low.c (linux_target_ops): Add a linux_process_target*
	as the 'pt' field.
	* lynx-low.h (class lynx_process_target): Define as a derived
	class of 'process_target'.
	* lynx-low.c (lynx_target_ops): Add a lynx_process_target*
	as the 'pt' field.
	* nto-low.h (class nto_process_target): Define as a derived
	class of 'process_target'.
	* nto-low.c (nto_target_ops): Add an nto_process_target*
	as the 'pt' field.
	* win32-low.h (class win32_process_target): Define as a derived
	class of 'process_target'.
	* win32-low.c (win32_target_ops): Add a win32_process_target*
	as the 'pt' field.
---
 gdbserver/linux-low.c |  5 +++++
 gdbserver/linux-low.h |  7 +++++++
 gdbserver/lynx-low.c  | 39 +++++++++++++++++++++++++++++++++++++++
 gdbserver/lynx-low.h  |  7 +++++++
 gdbserver/nto-low.c   | 10 ++++++++++
 gdbserver/nto-low.h   |  7 +++++++
 gdbserver/target.h    | 11 +++++++++++
 gdbserver/win32-low.c | 11 +++++++++++
 gdbserver/win32-low.h |  7 +++++++
 9 files changed, 104 insertions(+)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 676dea26c63..17f360639a4 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -7354,6 +7354,10 @@ linux_get_hwcap2 (int wordsize)
   return hwcap2;
 }
 
+/* The linux target ops object.  */
+
+static linux_process_target the_linux_target;
+
 static process_stratum_target linux_target_ops = {
   linux_create_inferior,
   linux_post_create_inferior,
@@ -7457,6 +7461,7 @@ static process_stratum_target linux_target_ops = {
 #else
   NULL,
 #endif
+  &the_linux_target,
 };
 
 #ifdef HAVE_LINUX_REGSETS
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index e25ddd024dd..f17ac95fae8 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -264,6 +264,13 @@ struct linux_target_ops
 
 extern struct linux_target_ops the_low_target;
 
+/* Target ops definitions for a Linux target.  */
+
+class linux_process_target : public process_target {
+public:
+
+};
+
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
 #define get_lwp_thread(lwp) ((lwp)->thread)
 
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index a5b019396fa..f1177920921 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -719,6 +719,10 @@ lynx_request_interrupt (void)
   kill (lynx_ptid_get_pid (inferior_ptid), SIGINT);
 }
 
+/* The LynxOS target ops object.  */
+
+static lynx_process_target the_lynx_target;
+
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
@@ -765,6 +769,41 @@ static process_stratum_target lynx_target_ops = {
   NULL,  /* supports_exec_events */
   NULL,  /* handle_new_gdb_connection */
   NULL,  /* handle_monitor_command */
+  NULL,  /* core_of_thread */
+  NULL,  /* read_loadmap */
+  NULL,  /* process_qsupported */
+  NULL,  /* supports_tracepoints */
+  NULL,  /* read_pc */
+  NULL,  /* write_pc */
+  NULL,  /* thread_stopped */
+  NULL,  /* get_tib_address */
+  NULL,  /* pause_all */
+  NULL,  /* unpause_all */
+  NULL,  /* stabilize_threads */
+  NULL,  /* install_fast_tracepoint_jump_pad */
+  NULL,  /* emit_ops */
+  NULL,  /* supports_disable_randomization */
+  NULL,  /* get_min_fast_tracepoint_insn_len */
+  NULL,  /* qxfer_libraries_svr4 */
+  NULL,  /* support_agent */
+  NULL,  /* enable_btrace */
+  NULL,  /* disable_btrace */
+  NULL,  /* read_btrace */
+  NULL,  /* read_btrace_conf */
+  NULL,  /* supports_range_stepping */
+  NULL,  /* pid_to_exec_file */
+  NULL,  /* multifs_open */
+  NULL,  /* multifs_unlink */
+  NULL,  /* multifs_readlink */
+  NULL,  /* breakpoint_kind_from_pc */
+  NULL,  /* sw_breakpoint_from_kind */
+  NULL,  /* thread_name */
+  NULL,  /* breakpoint_kind_from_current_state */
+  NULL,  /* supports_software_single_step */
+  NULL,  /* supports_catch_syscall */
+  NULL,  /* get_ipa_tdesc_idx */
+  NULL,  /* thread_handle */
+  &the_lynx_target,
 };
 
 void
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index b122298fb88..ca9601b221b 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -52,6 +52,13 @@ struct lynx_target_ops
 
 extern struct lynx_target_ops the_low_target;
 
+/* Target ops definitions for a LynxOS target.  */
+
+class lynx_process_target : public process_target {
+public:
+
+};
+
 /* The inferior's target description.  This is a global because the
    LynxOS ports support neither bi-arch nor multi-process.  */
 extern const struct target_desc *lynx_tdesc;
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index b4dea479b9c..6f12a735c12 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -930,6 +930,9 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
   return the_low_target.breakpoint;
 }
 
+/* The QNX Neutrino target ops object.  */
+
+static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
   nto_create_inferior,
@@ -1003,6 +1006,13 @@ static process_stratum_target nto_target_ops = {
   NULL, /* multifs_readlink */
   NULL, /* breakpoint_kind_from_pc */
   nto_sw_breakpoint_from_kind,
+  NULL, /* thread_name */
+  NULL, /* breakpoint_kind_from_current_state */
+  NULL, /* supports_software_single_step */
+  NULL, /* supports_catch_syscall */
+  NULL, /* get_ipa_tdesc_idx */
+  NULL, /* thread_handle */
+  &the_nto_target,
 };
 
 
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index 393b8a98695..398382113b6 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -42,6 +42,13 @@ struct nto_target_ops
 
 extern struct nto_target_ops the_low_target;
 
+/* Target ops definitions for a QNX Neutrino target.  */
+
+class nto_process_target : public process_target {
+public:
+
+};
+
 /* The inferior's target description.  This is a global because the
    LynxOS ports support neither bi-arch nor multi-process.  */
 extern const struct target_desc *nto_tdesc;
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 1b0810ba049..af3995425a3 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -63,6 +63,8 @@ struct thread_resume
   CORE_ADDR step_range_end;	/* Exclusive */
 };
 
+class process_target;
+
 /* GDBserver doesn't have a concept of strata like GDB, but we call
    its target vector "process_stratum" anyway for the benefit of
    shared code.  */
@@ -477,6 +479,15 @@ struct process_stratum_target
      false for failure.  Return pointer to thread handle via HANDLE
      and the handle's length via HANDLE_LEN.  */
   bool (*thread_handle) (ptid_t ptid, gdb_byte **handle, int *handle_len);
+
+  /* The object that will gradually replace this struct.  */
+  process_target *pt;
+};
+
+class process_target {
+public:
+
+  virtual ~process_target () = default;
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 9d0343788f1..b0b54a10669 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1823,6 +1823,10 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
   return the_low_target.breakpoint;
 }
 
+/* The win32 target ops object.  */
+
+static win32_process_target the_win32_target;
+
 static process_stratum_target win32_target_ops = {
   win32_create_inferior,
   NULL,  /* post_create_inferior */
@@ -1899,6 +1903,13 @@ static process_stratum_target win32_target_ops = {
   NULL, /* multifs_readlink */
   NULL, /* breakpoint_kind_from_pc */
   win32_sw_breakpoint_from_kind,
+  NULL, /* thread_name */
+  NULL, /* breakpoint_kind_from_current_state */
+  NULL, /* supports_software_single_step */
+  NULL, /* supports_catch_syscall */
+  NULL, /* get_ipa_tdesc_idx */
+  NULL, /* thread_handle */
+  &the_win32_target,
 };
 
 /* Initialize the Win32 backend.  */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 7a3eeda6e24..f8cc0b27c7f 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -101,6 +101,13 @@ struct win32_target_ops
 
 extern struct win32_target_ops the_low_target;
 
+/* Target ops definitions for a Win32 target.  */
+
+class win32_process_target : public process_target {
+public:
+
+};
+
 /* Retrieve the context for this thread, if not already retrieved.  */
 extern void win32_require_context (win32_thread_info *th);
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 25/58] gdbserver: turn target op 'get_tls_address' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (13 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 23/58] gdbserver: turn target ops 'stopped_by_watchpoint' and 'stopped_data_address' into methods Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 21/58] gdbserver: turn target op '{supports_}stopped_by_hw_breakpoint' " Tankut Baris Aktemur
                   ` (44 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's get_tls_address op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.  Also add
	'supports_get_tls_address'.
	* target.c (process_target::get_tls_address): Define.
	(process_target::supports_get_tls_address): Define.

	Update the derived structs and callers below.

	* server.c (handle_query): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::supports_get_tls_address): Define.
	(linux_process_target::get_tls_address): Define.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 28 +++++++++++++++++++++++-----
 gdbserver/linux-low.h |  5 +++++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/server.c    |  6 +++---
 gdbserver/target.c    | 13 +++++++++++++
 gdbserver/target.h    | 20 +++++++++++---------
 gdbserver/win32-low.c |  1 -
 8 files changed, 55 insertions(+), 20 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 93cd2bf57d4..66732a2d77f 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6112,6 +6112,29 @@ linux_process_target::read_offsets (CORE_ADDR *text_p, CORE_ADDR *data_p)
 }
 #endif
 
+bool
+linux_process_target::supports_get_tls_address ()
+{
+#ifdef USE_THREAD_DB
+  return true;
+#else
+  return false;
+#endif
+}
+
+int
+linux_process_target::get_tls_address (thread_info *thread,
+				       CORE_ADDR offset,
+				       CORE_ADDR load_module,
+				       CORE_ADDR *address)
+{
+#ifdef USE_THREAD_DB
+  return thread_db_get_tls_address (thread, offset, load_module, address);
+#else
+  return -1;
+#endif
+}
+
 static int
 linux_qxfer_osdata (const char *annex,
 		    unsigned char *readbuf, unsigned const char *writebuf,
@@ -7381,11 +7404,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-#ifdef USE_THREAD_DB
-  thread_db_get_tls_address,
-#else
-  NULL,
-#endif
   hostio_last_error_from_errno,
   linux_qxfer_osdata,
   linux_xfer_siginfo,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 5cf2e62dffb..be6310da723 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -343,6 +343,11 @@ public:
 
   int read_offsets (CORE_ADDR *text, CORE_ADDR *data) override;
 #endif
+
+  bool supports_get_tls_address () override;
+
+  int get_tls_address (thread_info *thread, CORE_ADDR offset,
+		       CORE_ADDR load_module, CORE_ADDR *address) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 2a3eda61b5f..4525d6e694a 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* get_tls_address */
   NULL,  /* hostio_last_error */
   NULL,  /* qxfer_osdata */
   NULL,  /* qxfer_siginfo */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 5d4540cff7e..38ddcbaa33a 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -956,7 +956,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* thread_db_set_tls_address */
   hostio_last_error_from_errno,
   NULL, /* nto_qxfer_osdata */
   NULL, /* xfer_siginfo */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index b4fd9c6a5e5..01d41af0f89 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -2467,7 +2467,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
     }
 
   /* Thread-local storage support.  */
-  if (the_target->get_tls_address != NULL
+  if (the_target->pt->supports_get_tls_address ()
       && startswith (own_buf, "qGetTLSAddr:"))
     {
       char *p = own_buf + 12;
@@ -2513,8 +2513,8 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 	  if (thread == NULL)
 	    err = 2;
 	  else
-	    err = the_target->get_tls_address (thread, parts[0], parts[1],
-					       &address);
+	    err = the_target->pt->get_tls_address (thread, parts[0], parts[1],
+						   &address);
 	}
 
       if (err == 0)
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 501a8d675db..f578dbea0da 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -493,3 +493,16 @@ process_target::read_offsets (CORE_ADDR *text, CORE_ADDR *data)
 {
   gdb_assert_not_reached ("target op read_offsets not supported");
 }
+
+bool
+process_target::supports_get_tls_address ()
+{
+  return false;
+}
+
+int
+process_target::get_tls_address (thread_info *thread, CORE_ADDR offset,
+				 CORE_ADDR load_module, CORE_ADDR *address)
+{
+  gdb_assert_not_reached ("target op get_tls_address not supported");
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 8919d43317e..aed363991ef 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,15 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Fetch the address associated with a specific thread local storage
-     area, determined by the specified THREAD, OFFSET, and LOAD_MODULE.
-     Stores it in *ADDRESS and returns zero on success; otherwise returns
-     an error code.  A return value of -1 means this system does not
-     support the operation.  */
-
-  int (*get_tls_address) (struct thread_info *thread, CORE_ADDR offset,
-			  CORE_ADDR load_module, CORE_ADDR *address);
-
   /* Fill BUF with an hostio error packet representing the last hostio
      error.  */
   void (*hostio_last_error) (char *buf);
@@ -477,6 +468,17 @@ public:
      needed for uclinux where the executable is relocated during load
      time.  */
   virtual int read_offsets (CORE_ADDR *text, CORE_ADDR *data);
+
+  /* Return true if the get_tls_address target op is supported.  */
+  virtual bool supports_get_tls_address ();
+
+  /* Fetch the address associated with a specific thread local storage
+     area, determined by the specified THREAD, OFFSET, and LOAD_MODULE.
+     Stores it in *ADDRESS and returns zero on success; otherwise returns
+     an error code.  A return value of -1 means this system does not
+     support the operation.  */
+  virtual int get_tls_address (thread_info *thread, CORE_ADDR offset,
+			       CORE_ADDR load_module, CORE_ADDR *address);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 48b70a5e334..21008ccc7ab 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1834,7 +1834,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* get_tls_address */
 #ifdef _WIN32_WCE
   wince_hostio_last_error,
 #else
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 43/58] gdbserver: turn fast tracepoint target ops into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (17 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 08/58] gdbserver: turn target op 'join' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 32/58] gdbserver: turn target op 'handle_new_gdb_connection' into a method Tankut Baris Aktemur
                   ` (40 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's install_fast_tracepoint_jump_pad and
	get_min_fast_tracepoint_insn_len ops methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.  Also add
	'supports_fast_tracepoints'.
	(target_supports_fast_tracepoints): Update the macro.
	(target_get_min_fast_tracepoint_insn_len): Update the macro.
	(install_fast_tracepoint_jump_pad): Update and rename the macro
	to ...
	(target_install_fast_tracepoint_jump_pad): ... this.
	* target.c (process_target::supports_fast_tracepoints): Define.
	(process_target::install_fast_tracepoint_jump_pad): Define.
	(process_target::get_min_fast_tracepoint_insn_len): Define.

	Update the derived structs and callers below.

	* tracepoint.c (install_fast_tracepoint): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::supports_fast_tracepoints): Define.
	(linux_install_fast_tracepoint_jump_pad): Turn into ...
	(linux_process_target::install_fast_tracepoint_jump_pad): ... this.
	(linux_get_min_fast_tracepoint_insn_len): Turn into ...
	(linux_process_target::get_min_fast_tracepoint_insn_len): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c  |  33 ++++++-------
 gdbserver/linux-low.h  |  18 +++++++
 gdbserver/lynx-low.c   |   2 -
 gdbserver/nto-low.c    |   2 -
 gdbserver/target.c     |  25 ++++++++++
 gdbserver/target.h     | 108 ++++++++++++++++++++---------------------
 gdbserver/tracepoint.c |  16 ++----
 gdbserver/win32-low.c  |   2 -
 8 files changed, 117 insertions(+), 89 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 6b6412f0808..d3f6edce5bc 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6609,19 +6609,20 @@ linux_process_target::done_accessing_memory ()
     target_unpause_all (true);
 }
 
-static int
-linux_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, CORE_ADDR tpaddr,
-					CORE_ADDR collector,
-					CORE_ADDR lockaddr,
-					ULONGEST orig_size,
-					CORE_ADDR *jump_entry,
-					CORE_ADDR *trampoline,
-					ULONGEST *trampoline_size,
-					unsigned char *jjump_pad_insn,
-					ULONGEST *jjump_pad_insn_size,
-					CORE_ADDR *adjusted_insn_addr,
-					CORE_ADDR *adjusted_insn_addr_end,
-					char *err)
+bool
+linux_process_target::supports_fast_tracepoints ()
+{
+  return true;
+}
+
+int
+linux_process_target::install_fast_tracepoint_jump_pad (
+    CORE_ADDR tpoint, CORE_ADDR tpaddr, CORE_ADDR collector,
+    CORE_ADDR lockaddr, ULONGEST orig_size, CORE_ADDR *jump_entry,
+    CORE_ADDR *trampoline, ULONGEST *trampoline_size,
+    unsigned char *jjump_pad_insn, ULONGEST *jjump_pad_insn_size,
+    CORE_ADDR *adjusted_insn_addr, CORE_ADDR *adjusted_insn_addr_end,
+    char *err)
 {
   return (*the_low_target.install_fast_tracepoint_jump_pad)
     (tpoint, tpaddr, collector, lockaddr, orig_size,
@@ -6640,8 +6641,8 @@ linux_emit_ops (void)
     return NULL;
 }
 
-static int
-linux_get_min_fast_tracepoint_insn_len (void)
+int
+linux_process_target::get_min_fast_tracepoint_insn_len ()
 {
   return (*the_low_target.get_min_fast_tracepoint_insn_len) ();
 }
@@ -7444,10 +7445,8 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_install_fast_tracepoint_jump_pad,
   linux_emit_ops,
   linux_supports_disable_randomization,
-  linux_get_min_fast_tracepoint_insn_len,
   linux_qxfer_libraries_svr4,
   linux_supports_agent,
 #ifdef HAVE_LINUX_BTRACE
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 91395038724..475e882712b 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -405,6 +405,24 @@ public:
   void unpause_all (bool unfreeze) override;
 
   void stabilize_threads () override;
+
+  bool supports_fast_tracepoints () override;
+
+  int install_fast_tracepoint_jump_pad (CORE_ADDR tpoint,
+					CORE_ADDR tpaddr,
+					CORE_ADDR collector,
+					CORE_ADDR lockaddr,
+					ULONGEST orig_size,
+					CORE_ADDR *jump_entry,
+					CORE_ADDR *trampoline,
+					ULONGEST *trampoline_size,
+					unsigned char *jjump_pad_insn,
+					ULONGEST *jjump_pad_insn_size,
+					CORE_ADDR *adjusted_insn_addr,
+					CORE_ADDR *adjusted_insn_addr_end,
+					char *err) override;
+
+  int get_min_fast_tracepoint_insn_len () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 742c2a85543..6520302ef7e 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,10 +735,8 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* install_fast_tracepoint_jump_pad */
   NULL,  /* emit_ops */
   NULL,  /* supports_disable_randomization */
-  NULL,  /* get_min_fast_tracepoint_insn_len */
   NULL,  /* qxfer_libraries_svr4 */
   NULL,  /* support_agent */
   NULL,  /* enable_btrace */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 2e1039a83ea..555cba190b5 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,10 +947,8 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* install_fast_tracepoint_jump_pad */
   NULL, /* emit_ops */
   NULL, /* supports_disable_randomization */
-  NULL, /* get_min_fast_tracepoint_insn_len */
   NULL, /* qxfer_libraries_svr4 */
   NULL, /* support_agent */
   NULL, /* enable_btrace */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index d4c0884fd7c..5f0316bf081 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -668,3 +668,28 @@ process_target::stabilize_threads ()
 {
   /* Nop.  */
 }
+
+bool
+process_target::supports_fast_tracepoints ()
+{
+  return false;
+}
+
+int
+process_target::install_fast_tracepoint_jump_pad (
+    CORE_ADDR tpoint, CORE_ADDR tpaddr, CORE_ADDR collector,
+    CORE_ADDR lockaddr, ULONGEST orig_size, CORE_ADDR *jump_entry,
+    CORE_ADDR *trampoline, ULONGEST *trampoline_size,
+    unsigned char *jjump_pad_insn, ULONGEST *jjump_pad_insn_size,
+    CORE_ADDR *adjusted_insn_addr, CORE_ADDR *adjusted_insn_addr_end,
+    char *err)
+{
+  gdb_assert_not_reached ("target op install_fast_tracepoint_jump_pad "
+			  "not supported");
+}
+
+int
+process_target::get_min_fast_tracepoint_insn_len ()
+{
+  return 0;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index f1a59d8f09f..c1276be152c 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,34 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Install a fast tracepoint jump pad.  TPOINT is the address of the
-     tracepoint internal object as used by the IPA agent.  TPADDR is
-     the address of tracepoint.  COLLECTOR is address of the function
-     the jump pad redirects to.  LOCKADDR is the address of the jump
-     pad lock object.  ORIG_SIZE is the size in bytes of the
-     instruction at TPADDR.  JUMP_ENTRY points to the address of the
-     jump pad entry, and on return holds the address past the end of
-     the created jump pad.  If a trampoline is created by the function,
-     then TRAMPOLINE and TRAMPOLINE_SIZE return the address and size of
-     the trampoline, else they remain unchanged.  JJUMP_PAD_INSN is a
-     buffer containing a copy of the instruction at TPADDR.
-     ADJUST_INSN_ADDR and ADJUST_INSN_ADDR_END are output parameters that
-     return the address range where the instruction at TPADDR was relocated
-     to.  If an error occurs, the ERR may be used to pass on an error
-     message.  */
-  int (*install_fast_tracepoint_jump_pad) (CORE_ADDR tpoint, CORE_ADDR tpaddr,
-					   CORE_ADDR collector,
-					   CORE_ADDR lockaddr,
-					   ULONGEST orig_size,
-					   CORE_ADDR *jump_entry,
-					   CORE_ADDR *trampoline,
-					   ULONGEST *trampoline_size,
-					   unsigned char *jjump_pad_insn,
-					   ULONGEST *jjump_pad_insn_size,
-					   CORE_ADDR *adjusted_insn_addr,
-					   CORE_ADDR *adjusted_insn_addr_end,
-					   char *err);
-
   /* Return the bytecode operations vector for the current inferior.
      Returns NULL if bytecode compilation is not supported.  */
   struct emit_ops *(*emit_ops) (void);
@@ -105,10 +77,6 @@ struct process_stratum_target
   /* Returns true if the target supports disabling randomization.  */
   int (*supports_disable_randomization) (void);
 
-  /* Return the minimum length of an instruction that can be safely overwritten
-     for use as a fast tracepoint.  */
-  int (*get_min_fast_tracepoint_insn_len) (void);
-
   /* Read solib info on SVR4 platforms.  */
   int (*qxfer_libraries_svr4) (const char *annex, unsigned char *readbuf,
 			       unsigned const char *writebuf,
@@ -494,6 +462,37 @@ public:
 
   /* Stabilize all threads.  That is, force them out of jump pads.  */
   virtual void stabilize_threads ();
+
+  /* Return true if the install_fast_tracepoint_jump_pad op is
+     supported.  */
+  virtual bool supports_fast_tracepoints ();
+
+  /* Install a fast tracepoint jump pad.  TPOINT is the address of the
+     tracepoint internal object as used by the IPA agent.  TPADDR is
+     the address of tracepoint.  COLLECTOR is address of the function
+     the jump pad redirects to.  LOCKADDR is the address of the jump
+     pad lock object.  ORIG_SIZE is the size in bytes of the
+     instruction at TPADDR.  JUMP_ENTRY points to the address of the
+     jump pad entry, and on return holds the address past the end of
+     the created jump pad.  If a trampoline is created by the function,
+     then TRAMPOLINE and TRAMPOLINE_SIZE return the address and size of
+     the trampoline, else they remain unchanged.  JJUMP_PAD_INSN is a
+     buffer containing a copy of the instruction at TPADDR.
+     ADJUST_INSN_ADDR and ADJUST_INSN_ADDR_END are output parameters that
+     return the address range where the instruction at TPADDR was relocated
+     to.  If an error occurs, the ERR may be used to pass on an error
+     message.  */
+  virtual int install_fast_tracepoint_jump_pad
+      (CORE_ADDR tpoint, CORE_ADDR tpaddr, CORE_ADDR collector,
+       CORE_ADDR lockaddr, ULONGEST orig_size, CORE_ADDR *jump_entry,
+       CORE_ADDR *trampoline, ULONGEST *trampoline_size,
+       unsigned char *jjump_pad_insn, ULONGEST *jjump_pad_insn_size,
+       CORE_ADDR *adjusted_insn_addr, CORE_ADDR *adjusted_insn_addr_end,
+       char *err);
+
+  /* Return the minimum length of an instruction that can be safely
+     overwritten for use as a fast tracepoint.  */
+  virtual int get_min_fast_tracepoint_insn_len ();
 };
 
 extern process_stratum_target *the_target;
@@ -559,11 +558,10 @@ int kill_inferior (process_info *proc);
   the_target->pt->supports_tracepoints ()
 
 #define target_supports_fast_tracepoints()		\
-  (the_target->install_fast_tracepoint_jump_pad != NULL)
+  the_target->pt->supports_fast_tracepoints ()
 
 #define target_get_min_fast_tracepoint_insn_len()	\
-  (the_target->get_min_fast_tracepoint_insn_len		\
-   ? (*the_target->get_min_fast_tracepoint_insn_len) () : 0)
+  the_target->pt->get_min_fast_tracepoint_insn_len ()
 
 #define target_thread_stopped(thread) \
   the_target->pt->thread_stopped (thread)
@@ -577,26 +575,26 @@ int kill_inferior (process_info *proc);
 #define target_stabilize_threads()		\
   the_target->pt->stabilize_threads ()
 
-#define install_fast_tracepoint_jump_pad(tpoint, tpaddr,		\
-					 collector, lockaddr,		\
-					 orig_size,			\
-					 jump_entry,			\
-					 trampoline, trampoline_size,	\
-					 jjump_pad_insn,		\
-					 jjump_pad_insn_size,		\
-					 adjusted_insn_addr,		\
-					 adjusted_insn_addr_end,	\
-					 err)				\
-  (*the_target->install_fast_tracepoint_jump_pad) (tpoint, tpaddr,	\
-						   collector,lockaddr,	\
-						   orig_size, jump_entry, \
-						   trampoline,		\
-						   trampoline_size,	\
-						   jjump_pad_insn,	\
-						   jjump_pad_insn_size, \
-						   adjusted_insn_addr,	\
-						   adjusted_insn_addr_end, \
-						   err)
+#define target_install_fast_tracepoint_jump_pad(tpoint, tpaddr,		\
+						collector, lockaddr,	\
+						orig_size,		\
+						jump_entry,		\
+						trampoline, trampoline_size, \
+						jjump_pad_insn,		\
+						jjump_pad_insn_size,	\
+						adjusted_insn_addr,	\
+						adjusted_insn_addr_end,	\
+						err)			\
+  the_target->pt->install_fast_tracepoint_jump_pad (tpoint, tpaddr,	\
+						    collector,lockaddr,	\
+						    orig_size, jump_entry, \
+						    trampoline,		\
+						    trampoline_size,	\
+						    jjump_pad_insn,	\
+						    jjump_pad_insn_size, \
+						    adjusted_insn_addr,	\
+						    adjusted_insn_addr_end, \
+						    err)
 
 #define target_emit_ops() \
   (the_target->emit_ops ? (*the_target->emit_ops) () : NULL)
diff --git a/gdbserver/tracepoint.c b/gdbserver/tracepoint.c
index be40c9b4cf1..e587d6561dc 100644
--- a/gdbserver/tracepoint.c
+++ b/gdbserver/tracepoint.c
@@ -3117,17 +3117,11 @@ install_fast_tracepoint (struct tracepoint *tpoint, char *errbuf)
   trampoline_size = 0;
 
   /* Install the jump pad.  */
-  err = install_fast_tracepoint_jump_pad (tpoint->obj_addr_on_target,
-					  tpoint->address,
-					  collect,
-					  ipa_sym_addrs.addr_collecting,
-					  tpoint->orig_size,
-					  &jentry,
-					  &trampoline, &trampoline_size,
-					  fjump, &fjump_size,
-					  &tpoint->adjusted_insn_addr,
-					  &tpoint->adjusted_insn_addr_end,
-					  errbuf);
+  err = target_install_fast_tracepoint_jump_pad
+    (tpoint->obj_addr_on_target, tpoint->address, collect,
+     ipa_sym_addrs.addr_collecting, tpoint->orig_size, &jentry,
+     &trampoline, &trampoline_size, fjump, &fjump_size,
+     &tpoint->adjusted_insn_addr, &tpoint->adjusted_insn_addr_end, errbuf);
 
   if (err)
     return 1;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 693e0de4a3c..7108f39c6f9 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,10 +1848,8 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* install_fast_tracepoint_jump_pad */
   NULL, /* emit_ops */
   NULL, /* supports_disable_randomization */
-  NULL, /* get_min_fast_tracepoint_insn_len */
   NULL, /* qxfer_libraries_svr4 */
   NULL, /* support_agent */
   NULL, /* enable_btrace */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 21/58] gdbserver: turn target op '{supports_}stopped_by_hw_breakpoint' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (14 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 25/58] gdbserver: turn target op 'get_tls_address' into a method Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 03/58] gdbserver: turn target op 'post_create_inferior' " Tankut Baris Aktemur
                   ` (43 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's {supports_}stopped_by_hw_breakpoint
	ops methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	(target_stopped_by_hw_breakpoint): Update the macro.
	(target_supports_stopped_by_hw_breakpoint): Update the macro.
	* target.c (process_target::stopped_by_hw_breakpoint): Define.
	(process_target::supports_stopped_by_hw_breakpoint): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_stopped_by_hw_breakpoint): Turn into ...
	(linux_process_target::stopped_by_hw_breakpoint): ... this.
	(linux_supports_stopped_by_hw_breakpoint): Turn into ...
	(linux_process_target::supports_stopped_by_hw_breakpoint): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 14 ++++++--------
 gdbserver/linux-low.h |  4 ++++
 gdbserver/lynx-low.c  |  2 --
 gdbserver/nto-low.c   |  2 --
 gdbserver/target.c    | 12 ++++++++++++
 gdbserver/target.h    | 20 +++++++++-----------
 gdbserver/win32-low.c |  2 --
 7 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 636a4933841..9d02e96f6f0 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6010,22 +6010,22 @@ linux_process_target::supports_stopped_by_sw_breakpoint ()
   return USE_SIGTRAP_SIGINFO;
 }
 
-/* Implement the to_stopped_by_hw_breakpoint target_ops
+/* Implement the stopped_by_hw_breakpoint target_ops
    method.  */
 
-static int
-linux_stopped_by_hw_breakpoint (void)
+bool
+linux_process_target::stopped_by_hw_breakpoint ()
 {
   struct lwp_info *lwp = get_thread_lwp (current_thread);
 
   return (lwp->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT);
 }
 
-/* Implement the to_supports_stopped_by_hw_breakpoint target_ops
+/* Implement the supports_stopped_by_hw_breakpoint target_ops
    method.  */
 
-static int
-linux_supports_stopped_by_hw_breakpoint (void)
+bool
+linux_process_target::supports_stopped_by_hw_breakpoint ()
 {
   return USE_SIGTRAP_SIGINFO;
 }
@@ -7376,8 +7376,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_stopped_by_hw_breakpoint,
-  linux_supports_stopped_by_hw_breakpoint,
   linux_supports_hardware_single_step,
   linux_stopped_by_watchpoint,
   linux_stopped_data_address,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 4ef1a3f4cf9..41f99591b3e 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -325,6 +325,10 @@ public:
   bool stopped_by_sw_breakpoint () override;
 
   bool supports_stopped_by_sw_breakpoint () override;
+
+  bool stopped_by_hw_breakpoint () override;
+
+  bool supports_stopped_by_hw_breakpoint () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 91ff7a1dd0b..7f074445f37 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -729,8 +729,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* stopped_by_hw_breakpoint */
-  NULL,  /* supports_stopped_by_hw_breakpoint */
   target_can_do_hardware_single_step,
   NULL,  /* stopped_by_watchpoint */
   NULL,  /* stopped_data_address */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 8a412868829..b7adc82da69 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -950,8 +950,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* stopped_by_hw_breakpoint */
-  NULL, /* supports_stopped_by_hw_breakpoint */
   target_can_do_hardware_single_step,
   nto_stopped_by_watchpoint,
   nto_stopped_data_address,
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 70630db6d84..f7dc0f4d658 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -459,3 +459,15 @@ process_target::supports_stopped_by_sw_breakpoint ()
 {
   return false;
 }
+
+bool
+process_target::stopped_by_hw_breakpoint ()
+{
+  return false;
+}
+
+bool
+process_target::supports_stopped_by_hw_breakpoint ()
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 3be0ff9cdb8..aae0e3afd24 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,13 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Returns 1 if the target stopped for a hardware breakpoint.  */
-  int (*stopped_by_hw_breakpoint) (void);
-
-  /* Returns true if the target knows whether a trap was caused by a
-     HW breakpoint triggering.  */
-  int (*supports_stopped_by_hw_breakpoint) (void);
-
   /* Returns true if the target can do hardware single step.  */
   int (*supports_hardware_single_step) (void);
 
@@ -476,6 +469,13 @@ public:
   /* Returns true if the target knows whether a trap was caused by a
      SW breakpoint triggering.  */
   virtual bool supports_stopped_by_sw_breakpoint ();
+
+  /* Returns true if the target stopped for a hardware breakpoint.  */
+  virtual bool stopped_by_hw_breakpoint ();
+
+  /* Returns true if the target knows whether a trap was caused by a
+     HW breakpoint triggering.  */
+  virtual bool supports_stopped_by_hw_breakpoint ();
 };
 
 extern process_stratum_target *the_target;
@@ -665,16 +665,14 @@ target_read_btrace_conf (struct btrace_target_info *tinfo,
   the_target->pt->stopped_by_sw_breakpoint ()
 
 #define target_supports_stopped_by_hw_breakpoint() \
-  (the_target->supports_stopped_by_hw_breakpoint ? \
-   (*the_target->supports_stopped_by_hw_breakpoint) () : 0)
+  the_target->pt->supports_stopped_by_hw_breakpoint ()
 
 #define target_supports_hardware_single_step() \
   (the_target->supports_hardware_single_step ? \
    (*the_target->supports_hardware_single_step) () : 0)
 
 #define target_stopped_by_hw_breakpoint() \
-  (the_target->stopped_by_hw_breakpoint ? \
-   (*the_target->stopped_by_hw_breakpoint) () : 0)
+  the_target->pt->stopped_by_hw_breakpoint ()
 
 #define target_breakpoint_kind_from_pc(pcptr) \
   (the_target->breakpoint_kind_from_pc \
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 31be06c0af2..9e8a3801099 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1828,8 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* stopped_by_hw_breakpoint */
-  NULL, /* supports_stopped_by_hw_breakpoint */
   target_can_do_hardware_single_step,
   win32_stopped_by_watchpoint,
   win32_stopped_data_address,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 36/58] gdbserver: turn target op 'process_qsupported' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (21 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 40/58] gdbserver: turn target op 'get_tib_address' into a method Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 02/58] gdbserver: turn target op 'create_inferior' " Tankut Baris Aktemur
                   ` (36 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's process_qsupported op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_process_qsupported): Update the macro.
	* target.c (process_target::process_qsupported): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_process_qsupported): Turn into ...
	(linux_process_target::process_qsupported): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c |  5 ++---
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/target.c    |  6 ++++++
 gdbserver/target.h    | 14 +++++---------
 gdbserver/win32-low.c |  1 -
 7 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index a048364242b..3bcfa8dd390 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6512,8 +6512,8 @@ linux_process_target::read_loadmap (const char *annex, CORE_ADDR offset,
 }
 #endif /* defined PT_GETDSBT || defined PTRACE_GETFDPIC */
 
-static void
-linux_process_qsupported (char **features, int count)
+void
+linux_process_target::process_qsupported (char **features, int count)
 {
   if (the_low_target.process_qsupported != NULL)
     the_low_target.process_qsupported (features, count);
@@ -7438,7 +7438,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_process_qsupported,
   linux_supports_tracepoints,
   linux_read_pc,
   linux_write_pc,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 020db879ed3..e84d3421e89 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -387,6 +387,8 @@ public:
   int read_loadmap (const char *annex, CORE_ADDR offset,
 		    unsigned char *myaddr, unsigned int len) override;
 #endif
+
+  void process_qsupported (char **features, int count) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index d6eec84642e..eb058ad27b6 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* process_qsupported */
   NULL,  /* supports_tracepoints */
   NULL,  /* read_pc */
   NULL,  /* write_pc */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 2bea7eae975..d460c805e26 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* process_qsupported */
   NULL, /* supports_tracepoints */
   NULL, /* read_pc */
   NULL, /* write_pc */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 26b9d8b6afe..49e4b01495c 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -602,3 +602,9 @@ process_target::read_loadmap (const char *annex, CORE_ADDR offset,
 {
   gdb_assert_not_reached ("target op read_loadmap not supported");
 }
+
+void
+process_target::process_qsupported (char **features, int count)
+{
+  /* Nop.  */
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index bfced1b10dd..f39950e7c9e 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Target specific qSupported support.  FEATURES is an array of
-     features with COUNT elements.  */
-  void (*process_qsupported) (char **features, int count);
-
   /* Return 1 if the target supports tracepoints, 0 (or leave the
      callback NULL) otherwise.  */
   int (*supports_tracepoints) (void);
@@ -489,6 +485,10 @@ public:
   /* Read loadmaps.  Read LEN bytes at OFFSET into a buffer at MYADDR.  */
   virtual int read_loadmap (const char *annex, CORE_ADDR offset,
 			    unsigned char *myaddr, unsigned int len);
+
+  /* Target specific qSupported support.  FEATURES is an array of
+     features with COUNT elements.  */
+  virtual void process_qsupported (char **features, int count);
 };
 
 extern process_stratum_target *the_target;
@@ -540,11 +540,7 @@ int kill_inferior (process_info *proc);
   the_target->pt->async (enable)
 
 #define target_process_qsupported(features, count)	\
-  do							\
-    {							\
-      if (the_target->process_qsupported)		\
-	the_target->process_qsupported (features, count); \
-    } while (0)
+  the_target->pt->process_qsupported (features, count)
 
 #define target_supports_catch_syscall()              	\
   (the_target->supports_catch_syscall ?			\
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 39a81e0826e..0db3adde2f2 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1842,7 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* process_qsupported */
   NULL, /* supports_tracepoints */
   NULL, /* read_pc */
   NULL, /* write_pc */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 03/58] gdbserver: turn target op 'post_create_inferior' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (15 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 21/58] gdbserver: turn target op '{supports_}stopped_by_hw_breakpoint' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 08/58] gdbserver: turn target op 'join' " Tankut Baris Aktemur
                   ` (42 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's post_create_inferior op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_post_create_inferior): Update the macro.
	* target.c (process_target::post_create_inferior): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_post_create_inferior): Turn into ...
	(linux_process_target::post_create_inferior): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c |  5 ++---
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/target.c    |  9 +++++++++
 gdbserver/target.h    | 14 +++++---------
 gdbserver/win32-low.c |  1 -
 7 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index fd122535cc5..9e4c6758581 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -1029,8 +1029,8 @@ linux_process_target::create_inferior (
 
 /* Implement the post_create_inferior target_ops method.  */
 
-static void
-linux_post_create_inferior (void)
+void
+linux_process_target::post_create_inferior ()
 {
   struct lwp_info *lwp = get_thread_lwp (current_thread);
 
@@ -7359,7 +7359,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_post_create_inferior,
   linux_attach,
   linux_kill,
   linux_detach,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index acaca0c0070..fab08a6bb7d 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -271,6 +271,8 @@ public:
 
   int create_inferior (const char *program,
 		       const std::vector<char *> &program_args) override;
+
+  void post_create_inferior () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 61b56739e36..c6880bc7bc2 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -726,7 +726,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* post_create_inferior */
   lynx_attach,
   lynx_kill,
   lynx_detach,
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index e5df5b3e9db..ce37443385d 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -935,7 +935,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL,  /* post_create_inferior */
   nto_attach,
   nto_kill,
   nto_detach,
diff --git a/gdbserver/target.c b/gdbserver/target.c
index a4593cf6df9..81092e81ea4 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -393,3 +393,12 @@ target_terminal::info (const char *arg, int from_tty)
 {
   /* Placeholder.  */
 }
+
+/* Default implementations of target ops.
+   See target.h for definitions.  */
+
+void
+process_target::post_create_inferior ()
+{
+  /* Nop.  */
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 7caf096b111..bede0a8556c 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Do additional setup after a new process is created, including
-     exec-wrapper completion.  */
-  void (*post_create_inferior) (void);
-
   /* Attach to a running process.
 
      PID is the process ID to attach to, specified by the user
@@ -488,6 +484,10 @@ public:
      process with the process list.  */
   virtual int create_inferior
       (const char *program, const std::vector<char *> &program_args) = 0;
+
+  /* Do additional setup after a new process is created, including
+     exec-wrapper completion.  */
+  virtual void post_create_inferior ();
 };
 
 extern process_stratum_target *the_target;
@@ -498,11 +498,7 @@ void set_target_ops (process_stratum_target *);
   the_target->pt->create_inferior (program, program_args)
 
 #define target_post_create_inferior()			 \
-  do							 \
-    {							 \
-      if (the_target->post_create_inferior != NULL)	 \
-	(*the_target->post_create_inferior) ();		 \
-    } while (0)
+  the_target->pt->post_create_inferior ()
 
 #define myattach(pid) \
   (*the_target->attach) (pid)
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 2e1028b9a8d..e8d4347a4b9 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL,  /* post_create_inferior */
   win32_attach,
   win32_kill,
   win32_detach,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 08/58] gdbserver: turn target op 'join' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (16 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 03/58] gdbserver: turn target op 'post_create_inferior' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 43/58] gdbserver: turn fast tracepoint target ops into methods Tankut Baris Aktemur
                   ` (41 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's join op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(join_inferior): Update the macro.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_join): Turn into ...
	(linux_process_target::join): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_join): Turn into ...
	(lynx_process_target::join): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_process_target::join): Define.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_join): Turn into ...
	(win32_process_target::join): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c | 5 ++---
 gdbserver/linux-low.h | 2 ++
 gdbserver/lynx-low.c  | 5 ++---
 gdbserver/lynx-low.h  | 2 ++
 gdbserver/nto-low.c   | 7 ++++++-
 gdbserver/nto-low.h   | 2 ++
 gdbserver/target.h    | 9 ++++-----
 gdbserver/win32-low.c | 5 ++---
 gdbserver/win32-low.h | 2 ++
 9 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index fb2f79c2204..4a621acccdf 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -1669,8 +1669,8 @@ linux_process_target::mourn (process_info *process)
   remove_process (process);
 }
 
-static void
-linux_join (int pid)
+void
+linux_process_target::join (int pid)
 {
   int status, ret;
 
@@ -7358,7 +7358,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_join,
   linux_thread_alive,
   linux_resume,
   linux_wait,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 4b9d6ce65b6..37ee4b45a41 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -281,6 +281,8 @@ public:
   int detach (process_info *proc) override;
 
   void mourn (process_info *proc) override;
+
+  void join (int pid) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 55721ac87b2..e4694f4d053 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -561,8 +561,8 @@ lynx_process_target::mourn (struct process_info *proc)
 
 /* Implement the join target_ops method.  */
 
-static void
-lynx_join (int pid)
+void
+lynx_process_target::join (int pid)
 {
   /* The PTRACE_DETACH is sufficient to detach from the process.
      So no need to do anything extra.  */
@@ -726,7 +726,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_join,
   lynx_thread_alive,
   lynx_resume,
   lynx_wait,
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index b290922e4b4..a0d5099918e 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -67,6 +67,8 @@ public:
   int detach (process_info *proc) override;
 
   void mourn (process_info *proc) override;
+
+  void join (int pid) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 09ae60219a6..9fc66088109 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -423,6 +423,12 @@ nto_process_target::mourn (struct process_info *process)
   remove_process (process);
 }
 
+void
+nto_process_target::join (int pid)
+{
+  error (_("nto target does not implement the join op"));
+}
+
 /* Check if the given thread is alive.  
 
    Return 1 if alive, 0 otherwise.  */
@@ -935,7 +941,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* nto_join */
   nto_thread_alive,
   nto_resume,
   nto_wait,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index fd675811753..dc321c14405 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -57,6 +57,8 @@ public:
   int detach (process_info *proc) override;
 
   void mourn (process_info *proc) override;
+
+  void join (int pid) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 4c0a98b3ed0..a32667ee6d9 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Wait for process PID to exit.  */
-
-  void (*join) (int pid);
-
   /* Return 1 iff the thread with process ID PID is alive.  */
 
   int (*thread_alive) (ptid_t pid);
@@ -484,6 +480,9 @@ public:
 
   /* The inferior process has died.  Do what is right.  */
   virtual void mourn (process_info *proc) = 0;
+
+  /* Wait for process PID to exit.  */
+  virtual void join (int pid) = 0;
 };
 
 extern process_stratum_target *the_target;
@@ -533,7 +532,7 @@ int kill_inferior (process_info *proc);
   (*the_target->store_registers) (regcache, regno)
 
 #define join_inferior(pid) \
-  (*the_target->join) (pid)
+  the_target->pt->join (pid)
 
 #define target_supports_non_stop() \
   (the_target->supports_non_stop ? (*the_target->supports_non_stop ) () : 0)
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index c7ba29567d4..af80ba77023 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -875,8 +875,8 @@ win32_process_target::mourn (struct process_info *process)
 
 /* Implementation of target_ops::join.  */
 
-static void
-win32_join (int pid)
+void
+win32_process_target::join (int pid)
 {
   HANDLE h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
   if (h != NULL)
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_join,
   win32_thread_alive,
   win32_resume,
   win32_wait,
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 4ab92dbdae8..0204f2fee35 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -116,6 +116,8 @@ public:
   int detach (process_info *proc) override;
 
   void mourn (process_info *proc) override;
+
+  void join (int pid) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 19/58] gdbserver: turn target ops 'insert_point' and 'remove_point' into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (26 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 05/58] gdbserver: turn target op 'kill' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 15/58] gdbserver: turn target op 'look_up_symbols' into a method Tankut Baris Aktemur
                   ` (31 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's insert_point and remove_point ops
	methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	* target.c (process_target::insert_point): Define.
	(process_target::remove_point): Define.

	Update the derived structs and callers below.

	* mem-break.c (set_raw_breakpoint_at): Update.
	(delete_raw_breakpoint): Update.
	(uninsert_raw_breakpoint): Update.
	(reinsert_raw_breakpoint): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_insert_point): Turn into ...
	(linux_process_target::insert_point): ... this.
	(linux_remove_point): Turn into ...
	(linux_process_target::remove_point): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_insert_point): Turn into ...
	(nto_process_target::insert_point): ... this.
	(nto_remove_point): Turn into ...
	(nto_process_target::remove_point): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_insert_point): Turn into ...
	(win32_process_target::insert_point): ... this.
	(win32_remove_point): Turn into ...
	(win32_process_target::remove_point): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c | 14 ++++++--------
 gdbserver/linux-low.h |  6 ++++++
 gdbserver/lynx-low.c  |  2 --
 gdbserver/mem-break.c | 10 +++++-----
 gdbserver/nto-low.c   | 14 ++++++--------
 gdbserver/nto-low.h   |  6 ++++++
 gdbserver/target.c    | 14 ++++++++++++++
 gdbserver/target.h    | 16 ++++++++--------
 gdbserver/win32-low.c | 14 ++++++--------
 gdbserver/win32-low.h |  6 ++++++
 10 files changed, 63 insertions(+), 39 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index da03b8c3b03..9427b9bdeb9 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -5964,9 +5964,9 @@ linux_process_target::supports_z_point_type (char z_type)
 	  && the_low_target.supports_z_point_type (z_type));
 }
 
-static int
-linux_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
-		    int size, struct raw_breakpoint *bp)
+int
+linux_process_target::insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
+				    int size, raw_breakpoint *bp)
 {
   if (type == raw_bkpt_type_sw)
     return insert_memory_breakpoint (bp);
@@ -5977,9 +5977,9 @@ linux_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
     return 1;
 }
 
-static int
-linux_remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
-		    int size, struct raw_breakpoint *bp)
+int
+linux_process_target::remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
+				    int size, raw_breakpoint *bp)
 {
   if (type == raw_bkpt_type_sw)
     return remove_memory_breakpoint (bp);
@@ -7376,8 +7376,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_insert_point,
-  linux_remove_point,
   linux_stopped_by_sw_breakpoint,
   linux_supports_stopped_by_sw_breakpoint,
   linux_stopped_by_hw_breakpoint,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index c51027bb0dc..0887c932d6c 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -315,6 +315,12 @@ public:
 		 unsigned int len) override;
 
   bool supports_z_point_type (char z_type) override;
+
+  int insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
+		    int size, raw_breakpoint *bp) override;
+
+  int remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
+		    int size, raw_breakpoint *bp) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 4be6e841d44..60748ae03db 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -729,8 +729,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* insert_point */
-  NULL,  /* remove_point */
   NULL,  /* stopped_by_sw_breakpoint */
   NULL,  /* supports_stopped_by_sw_breakpoint */
   NULL,  /* stopped_by_hw_breakpoint */
diff --git a/gdbserver/mem-break.c b/gdbserver/mem-break.c
index b00e9fca353..682b3bc1832 100644
--- a/gdbserver/mem-break.c
+++ b/gdbserver/mem-break.c
@@ -460,7 +460,7 @@ set_raw_breakpoint_at (enum raw_bkpt_type type, CORE_ADDR where, int kind,
 
   if (!bp->inserted)
     {
-      *err = the_target->insert_point (bp->raw_type, bp->pc, bp->kind, bp);
+      *err = the_target->pt->insert_point (bp->raw_type, bp->pc, bp->kind, bp);
       if (*err != 0)
 	{
 	  if (debug_threads)
@@ -890,8 +890,8 @@ delete_raw_breakpoint (struct process_info *proc, struct raw_breakpoint *todel)
 
 	      *bp_link = bp->next;
 
-	      ret = the_target->remove_point (bp->raw_type, bp->pc, bp->kind,
-					      bp);
+	      ret = the_target->pt->remove_point (bp->raw_type, bp->pc,
+						  bp->kind, bp);
 	      if (ret != 0)
 		{
 		  /* Something went wrong, relink the breakpoint.  */
@@ -1532,7 +1532,7 @@ uninsert_raw_breakpoint (struct raw_breakpoint *bp)
 
       bp->inserted = 0;
 
-      err = the_target->remove_point (bp->raw_type, bp->pc, bp->kind, bp);
+      err = the_target->pt->remove_point (bp->raw_type, bp->pc, bp->kind, bp);
       if (err != 0)
 	{
 	  bp->inserted = 1;
@@ -1621,7 +1621,7 @@ reinsert_raw_breakpoint (struct raw_breakpoint *bp)
   if (bp->inserted)
     return;
 
-  err = the_target->insert_point (bp->raw_type, bp->pc, bp->kind, bp);
+  err = the_target->pt->insert_point (bp->raw_type, bp->pc, bp->kind, bp);
   if (err == 0)
     bp->inserted = 1;
   else if (debug_threads)
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 132d57bfe79..c554d91ceea 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -807,9 +807,9 @@ nto_process_target::supports_z_point_type (char z_type)
 
 /* Insert {break/watch}point at address ADDR.  SIZE is not used.  */
 
-static int
-nto_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
-		  int size, struct raw_breakpoint *bp)
+int
+nto_process_target::insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
+				  int size, raw_breakpoint *bp)
 {
   int wtype = _DEBUG_BREAK_HW; /* Always request HW.  */
 
@@ -839,9 +839,9 @@ nto_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
 
 /* Remove {break/watch}point at address ADDR.  SIZE is not used.  */
 
-static int
-nto_remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
-		  int size, struct raw_breakpoint *bp)
+int
+nto_process_target::remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
+				  int size, raw_breakpoint *bp)
 {
   int wtype = _DEBUG_BREAK_HW; /* Always request HW.  */
 
@@ -950,8 +950,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_insert_point,
-  nto_remove_point,
   NULL, /* stopped_by_sw_breakpoint */
   NULL, /* supports_stopped_by_sw_breakpoint */
   NULL, /* stopped_by_hw_breakpoint */
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index d99d5d7acc7..a51477789e7 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -85,6 +85,12 @@ public:
 		 unsigned int len) override;
 
   bool supports_z_point_type (char z_type) override;
+
+  int insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
+		    int size, raw_breakpoint *bp) override;
+
+  int remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
+		    int size, raw_breakpoint *bp) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 22339622e09..fd443efd61e 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -433,3 +433,17 @@ process_target::supports_z_point_type (char z_type)
 {
   return false;
 }
+
+int
+process_target::insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
+			      int size, raw_breakpoint *bp)
+{
+  return 1;
+}
+
+int
+process_target::remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
+			      int size, raw_breakpoint *bp)
+{
+  return 1;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 383a848fcb9..966741f21ed 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,14 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Insert and remove a break or watchpoint.
-     Returns 0 on success, -1 on failure and 1 on unsupported.  */
-
-  int (*insert_point) (enum raw_bkpt_type type, CORE_ADDR addr,
-		       int size, struct raw_breakpoint *bp);
-  int (*remove_point) (enum raw_bkpt_type type, CORE_ADDR addr,
-		       int size, struct raw_breakpoint *bp);
-
   /* Returns 1 if the target stopped because it executed a software
      breakpoint instruction, 0 otherwise.  */
   int (*stopped_by_sw_breakpoint) (void);
@@ -476,6 +468,14 @@ public:
        '4' - access watchpoint
   */
   virtual bool supports_z_point_type (char z_type);
+
+  /* Insert and remove a break or watchpoint.
+     Returns 0 on success, -1 on failure and 1 on unsupported.  */
+  virtual int insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
+			    int size, raw_breakpoint *bp);
+
+  virtual int remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
+			    int size, raw_breakpoint *bp);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 74b70659465..9f705507e96 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -262,9 +262,9 @@ win32_process_target::supports_z_point_type (char z_type)
 	  && the_low_target.supports_z_point_type (z_type));
 }
 
-static int
-win32_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
-		    int size, struct raw_breakpoint *bp)
+int
+win32_process_target::insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
+				    int size, raw_breakpoint *bp)
 {
   if (the_low_target.insert_point != NULL)
     return the_low_target.insert_point (type, addr, size, bp);
@@ -273,9 +273,9 @@ win32_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
     return 1;
 }
 
-static int
-win32_remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
-		    int size, struct raw_breakpoint *bp)
+int
+win32_process_target::remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
+				    int size, raw_breakpoint *bp)
 {
   if (the_low_target.remove_point != NULL)
     return the_low_target.remove_point (type, addr, size, bp);
@@ -1828,8 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_insert_point,
-  win32_remove_point,
   NULL, /* stopped_by_sw_breakpoint */
   NULL, /* supports_stopped_by_sw_breakpoint */
   NULL, /* stopped_by_hw_breakpoint */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index f40dfb48822..39c4a4ce917 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -139,6 +139,12 @@ public:
   void request_interrupt () override;
 
   bool supports_z_point_type (char z_type) override;
+
+  int insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
+		    int size, raw_breakpoint *bp) override;
+
+  int remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
+		    int size, raw_breakpoint *bp) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 09/58] gdbserver: turn target op 'thread_alive' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (11 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 37/58] gdbserver: turn target op 'supports_tracepoints' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 23/58] gdbserver: turn target ops 'stopped_by_watchpoint' and 'stopped_data_address' into methods Tankut Baris Aktemur
                   ` (46 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's thread_alive op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(mythread_alive): Update the macro.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_thread_alive): Turn into ...
	(linux_process_target::thread_alive): ... this.
	(wait_for_sigstop): Update.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_thread_alive): Turn into ...
	(lynx_process_target::thread_alive): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_thread_alive): Turn into ...
	(nto_process_target::thread_alive): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_thread_alive): Turn into ...
	(win32_process_target::thread_alive): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c | 10 +++++-----
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  5 ++---
 gdbserver/lynx-low.h  |  2 ++
 gdbserver/nto-low.c   |  7 +++----
 gdbserver/nto-low.h   |  2 ++
 gdbserver/target.h    |  9 ++++-----
 gdbserver/win32-low.c |  7 +++----
 gdbserver/win32-low.h |  2 ++
 9 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 4a621acccdf..ae10d5a2282 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -1681,9 +1681,10 @@ linux_process_target::join (int pid)
   } while (ret != -1 || errno != ECHILD);
 }
 
-/* Return nonzero if the given thread is still alive.  */
-static int
-linux_thread_alive (ptid_t ptid)
+/* Return true if the given thread is still alive.  */
+
+bool
+linux_process_target::thread_alive (ptid_t ptid)
 {
   struct lwp_info *lwp = find_lwp_pid (ptid);
 
@@ -4004,7 +4005,7 @@ wait_for_sigstop (void)
 				       &wstat, __WALL);
   gdb_assert (ret == -1);
 
-  if (saved_thread == NULL || linux_thread_alive (saved_tid))
+  if (saved_thread == NULL || mythread_alive (saved_tid))
     current_thread = saved_thread;
   else
     {
@@ -7358,7 +7359,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_thread_alive,
   linux_resume,
   linux_wait,
   linux_fetch_registers,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 37ee4b45a41..f3bb7826a68 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -283,6 +283,8 @@ public:
   void mourn (process_info *proc) override;
 
   void join (int pid) override;
+
+  bool thread_alive (ptid_t pid) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index e4694f4d053..99ef605f27d 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -570,8 +570,8 @@ lynx_process_target::join (int pid)
 
 /* Implement the thread_alive target_ops method.  */
 
-static int
-lynx_thread_alive (ptid_t ptid)
+bool
+lynx_process_target::thread_alive (ptid_t ptid)
 {
   /* The list of threads is updated at the end of each wait, so it
      should be up to date.  No need to re-fetch it.  */
@@ -726,7 +726,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_thread_alive,
   lynx_resume,
   lynx_wait,
   lynx_fetch_registers,
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index a0d5099918e..aa5d4b20505 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -69,6 +69,8 @@ public:
   void mourn (process_info *proc) override;
 
   void join (int pid) override;
+
+  bool thread_alive (ptid_t pid) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 9fc66088109..bd2ee687147 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -431,10 +431,10 @@ nto_process_target::join (int pid)
 
 /* Check if the given thread is alive.  
 
-   Return 1 if alive, 0 otherwise.  */
+   Return true if alive, false otherwise.  */
 
-static int
-nto_thread_alive (ptid_t ptid)
+bool
+nto_process_target::thread_alive (ptid_t ptid)
 {
   int res;
 
@@ -941,7 +941,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_thread_alive,
   nto_resume,
   nto_wait,
   nto_fetch_registers,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index dc321c14405..056186e0071 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -59,6 +59,8 @@ public:
   void mourn (process_info *proc) override;
 
   void join (int pid) override;
+
+  bool thread_alive (ptid_t pid) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.h b/gdbserver/target.h
index a32667ee6d9..e2bdddcb137 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return 1 iff the thread with process ID PID is alive.  */
-
-  int (*thread_alive) (ptid_t pid);
-
   /* Resume the inferior process.  */
 
   void (*resume) (struct thread_resume *resume_info, size_t n);
@@ -483,6 +479,9 @@ public:
 
   /* Wait for process PID to exit.  */
   virtual void join (int pid) = 0;
+
+  /* Return true iff the thread with process ID PID is alive.  */
+  virtual bool thread_alive (ptid_t pid) = 0;
 };
 
 extern process_stratum_target *the_target;
@@ -523,7 +522,7 @@ int kill_inferior (process_info *proc);
   the_target->pt->detach (proc)
 
 #define mythread_alive(pid) \
-  (*the_target->thread_alive) (pid)
+  the_target->pt->thread_alive (pid)
 
 #define fetch_inferior_registers(regcache, regno)	\
   (*the_target->fetch_registers) (regcache, regno)
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index af80ba77023..adf0dc4d902 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -886,9 +886,9 @@ win32_process_target::join (int pid)
     }
 }
 
-/* Return 1 iff the thread with thread ID TID is alive.  */
-static int
-win32_thread_alive (ptid_t ptid)
+/* Return true iff the thread with thread ID TID is alive.  */
+bool
+win32_process_target::thread_alive (ptid_t ptid)
 {
   /* Our thread list is reliable; don't bother to poll target
      threads.  */
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_thread_alive,
   win32_resume,
   win32_wait,
   win32_fetch_inferior_registers,
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 0204f2fee35..e73569b07b3 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -118,6 +118,8 @@ public:
   void mourn (process_info *proc) override;
 
   void join (int pid) override;
+
+  bool thread_alive (ptid_t pid) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 45/58] gdbserver: turn target op 'supports_disable_randomization' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (23 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 02/58] gdbserver: turn target op 'create_inferior' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 27/58] gdbserver: turn target op 'qxfer_osdata' " Tankut Baris Aktemur
                   ` (34 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's supports_disable_randomization op
	a method of process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_supports_disable_randomization): Update the macro.
	* target.c (process_target::supports_disable_randomization): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_supports_disable_randomization): Turn into ...
	(linux_process_target::supports_disable_randomization): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 9 ++++-----
 gdbserver/linux-low.h | 2 ++
 gdbserver/lynx-low.c  | 1 -
 gdbserver/nto-low.c   | 1 -
 gdbserver/target.c    | 6 ++++++
 gdbserver/target.h    | 9 ++++-----
 gdbserver/win32-low.c | 1 -
 7 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 93a79cb4e37..1a35b5ed681 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6403,13 +6403,13 @@ linux_process_target::core_of_thread (ptid_t ptid)
   return linux_common_core_of_thread (ptid);
 }
 
-static int
-linux_supports_disable_randomization (void)
+bool
+linux_process_target::supports_disable_randomization ()
 {
 #ifdef HAVE_PERSONALITY
-  return 1;
+  return true;
 #else
-  return 0;
+  return false;
 #endif
 }
 
@@ -7445,7 +7445,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_supports_disable_randomization,
   linux_qxfer_libraries_svr4,
   linux_supports_agent,
 #ifdef HAVE_LINUX_BTRACE
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 6f53450898e..90569ec2abc 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -425,6 +425,8 @@ public:
   int get_min_fast_tracepoint_insn_len () override;
 
   struct emit_ops *emit_ops () override;
+
+  bool supports_disable_randomization () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 8b5d26b8956..0f2eb05c4ef 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* supports_disable_randomization */
   NULL,  /* qxfer_libraries_svr4 */
   NULL,  /* support_agent */
   NULL,  /* enable_btrace */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index be496bd6686..2c6ad118026 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* supports_disable_randomization */
   NULL, /* qxfer_libraries_svr4 */
   NULL, /* support_agent */
   NULL, /* enable_btrace */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 5bd591df16d..0c8c13ae2f3 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -699,3 +699,9 @@ process_target::emit_ops ()
 {
   return nullptr;
 }
+
+bool
+process_target::supports_disable_randomization ()
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index fea4f8e23e5..85ce8034543 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Returns true if the target supports disabling randomization.  */
-  int (*supports_disable_randomization) (void);
-
   /* Read solib info on SVR4 platforms.  */
   int (*qxfer_libraries_svr4) (const char *annex, unsigned char *readbuf,
 			       unsigned const char *writebuf,
@@ -493,6 +490,9 @@ public:
   /* Return the bytecode operations vector for the current inferior.
      Returns nullptr if bytecode compilation is not supported.  */
   virtual struct emit_ops *emit_ops ();
+
+  /* Returns true if the target supports disabling randomization.  */
+  virtual bool supports_disable_randomization ();
 };
 
 extern process_stratum_target *the_target;
@@ -600,8 +600,7 @@ int kill_inferior (process_info *proc);
   the_target->pt->emit_ops ()
 
 #define target_supports_disable_randomization() \
-  (the_target->supports_disable_randomization ? \
-   (*the_target->supports_disable_randomization) () : 0)
+  the_target->pt->supports_disable_randomization ()
 
 #define target_supports_agent() \
   (the_target->supports_agent ? \
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 342f19fcdcf..81c04f65251 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,7 +1848,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* supports_disable_randomization */
   NULL, /* qxfer_libraries_svr4 */
   NULL, /* support_agent */
   NULL, /* enable_btrace */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 37/58] gdbserver: turn target op 'supports_tracepoints' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (10 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 24/58] gdbserver: turn target op 'read_offsets' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 09/58] gdbserver: turn target op 'thread_alive' " Tankut Baris Aktemur
                   ` (47 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's supports_tracepoints op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_supports_tracepoints): Update the macro.
	* target.c (process_target::supports_tracepoints): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_supports_tracepoints): Turn into ...
	(linux_process_target::supports_tracepoints): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c |  7 +++----
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/target.c    |  6 ++++++
 gdbserver/target.h    | 10 ++++------
 gdbserver/win32-low.c |  1 -
 7 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 3bcfa8dd390..758dd1108f8 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6535,11 +6535,11 @@ linux_get_ipa_tdesc_idx (void)
   return (*the_low_target.get_ipa_tdesc_idx) ();
 }
 
-static int
-linux_supports_tracepoints (void)
+bool
+linux_process_target::supports_tracepoints ()
 {
   if (*the_low_target.supports_tracepoints == NULL)
-    return 0;
+    return false;
 
   return (*the_low_target.supports_tracepoints) ();
 }
@@ -7438,7 +7438,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_supports_tracepoints,
   linux_read_pc,
   linux_write_pc,
   linux_thread_stopped,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index e84d3421e89..e142f6bfeb1 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -389,6 +389,8 @@ public:
 #endif
 
   void process_qsupported (char **features, int count) override;
+
+  bool supports_tracepoints () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index eb058ad27b6..eeeddc5f175 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* supports_tracepoints */
   NULL,  /* read_pc */
   NULL,  /* write_pc */
   NULL,  /* thread_stopped */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index d460c805e26..d76014808ba 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* supports_tracepoints */
   NULL, /* read_pc */
   NULL, /* write_pc */
   NULL, /* thread_stopped */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 49e4b01495c..ded8f3fee9d 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -608,3 +608,9 @@ process_target::process_qsupported (char **features, int count)
 {
   /* Nop.  */
 }
+
+bool
+process_target::supports_tracepoints ()
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index f39950e7c9e..8a0146e4c32 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return 1 if the target supports tracepoints, 0 (or leave the
-     callback NULL) otherwise.  */
-  int (*supports_tracepoints) (void);
-
   /* Read PC from REGCACHE.  */
   CORE_ADDR (*read_pc) (struct regcache *regcache);
 
@@ -489,6 +485,9 @@ public:
   /* Target specific qSupported support.  FEATURES is an array of
      features with COUNT elements.  */
   virtual void process_qsupported (char **features, int count);
+
+  /* Return true if the target supports tracepoints, false otherwise.  */
+  virtual bool supports_tracepoints ();
 };
 
 extern process_stratum_target *the_target;
@@ -551,8 +550,7 @@ int kill_inferior (process_info *proc);
    ? (*the_target->get_ipa_tdesc_idx) () : 0)
 
 #define target_supports_tracepoints()			\
-  (the_target->supports_tracepoints			\
-   ? (*the_target->supports_tracepoints) () : 0)
+  the_target->pt->supports_tracepoints ()
 
 #define target_supports_fast_tracepoints()		\
   (the_target->install_fast_tracepoint_jump_pad != NULL)
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 0db3adde2f2..81746dedcbb 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1842,7 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* supports_tracepoints */
   NULL, /* read_pc */
   NULL, /* write_pc */
   NULL, /* thread_stopped */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 05/58] gdbserver: turn target op 'kill' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (25 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 27/58] gdbserver: turn target op 'qxfer_osdata' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 19/58] gdbserver: turn target ops 'insert_point' and 'remove_point' into methods Tankut Baris Aktemur
                   ` (32 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's kill op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.

	Update the derived structs and callers below.

	* target.c (kill_inferior): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_kill): Turn into ...
	(linux_process_target::kill): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_kill): Turn into ...
	(lynx_process_target::kill): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_kill): Turn into ...
	(nto_process_target::kill): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_kill): Turn into ...
	(win32_process_target::kill): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c | 5 ++---
 gdbserver/linux-low.h | 2 ++
 gdbserver/lynx-low.c  | 5 ++---
 gdbserver/lynx-low.h  | 2 ++
 gdbserver/nto-low.c   | 5 ++---
 gdbserver/nto-low.h   | 2 ++
 gdbserver/target.c    | 2 +-
 gdbserver/target.h    | 7 +++----
 gdbserver/win32-low.c | 5 ++---
 gdbserver/win32-low.h | 2 ++
 10 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 8e62ed91a77..3298d142f26 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -1386,8 +1386,8 @@ kill_one_lwp_callback (thread_info *thread, int pid)
   kill_wait_lwp (lwp);
 }
 
-static int
-linux_kill (process_info *process)
+int
+linux_process_target::kill (process_info *process)
 {
   int pid = process->pid;
 
@@ -7359,7 +7359,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_kill,
   linux_detach,
   linux_mourn,
   linux_join,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 673c5bbc407..636032e3212 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -275,6 +275,8 @@ public:
   void post_create_inferior () override;
 
   int attach (unsigned long pid) override;
+
+  int kill (process_info *proc) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 2e2535e1d61..fb59d5105cb 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -521,8 +521,8 @@ lynx_wait (ptid_t ptid, struct target_waitstatus *status, int options)
 
 /* Implement the kill target_ops method.  */
 
-static int
-lynx_kill (process_info *process)
+int
+lynx_process_target::kill (process_info *process)
 {
   ptid_t ptid = lynx_ptid_t (process->pid, 0);
   struct target_waitstatus status;
@@ -726,7 +726,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_kill,
   lynx_detach,
   lynx_mourn,
   lynx_join,
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index 7a3f03fb36e..749b0dee19f 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -61,6 +61,8 @@ public:
 		       const std::vector<char *> &program_args) override;
 
   int attach (unsigned long pid) override;
+
+  int kill (process_info *proc) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 47be6eeab86..0af8fb1bcee 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -396,8 +396,8 @@ nto_process_target::attach (unsigned long pid)
 
 /* Send signal to process PID.  */
 
-static int
-nto_kill (process_info *proc)
+int
+nto_process_target::kill (process_info *proc)
 {
   int pid = proc->pid;
 
@@ -935,7 +935,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_kill,
   nto_detach,
   nto_mourn,
   NULL, /* nto_join */
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index e5d2fa83135..fbef01dedc9 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -51,6 +51,8 @@ public:
 		       const std::vector<char *> &program_args) override;
 
   int attach (unsigned long pid) override;
+
+  int kill (process_info *proc) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 81092e81ea4..a9632aa8cd9 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -319,7 +319,7 @@ kill_inferior (process_info *proc)
 {
   gdb_agent_about_to_close (proc->pid);
 
-  return (*the_target->kill) (proc);
+  return the_target->pt->kill (proc);
 }
 
 /* Target can do hardware single step.  */
diff --git a/gdbserver/target.h b/gdbserver/target.h
index a2bbfed5b07..a1e9de15c2a 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Kill process PROC.  Return -1 on failure, and 0 on success.  */
-
-  int (*kill) (process_info *proc);
-
   /* Detach from process PROC.  Return -1 on failure, and 0 on
      success.  */
 
@@ -487,6 +483,9 @@ public:
      Returns -1 if attaching is unsupported, 0 on success, and calls
      error() otherwise.  */
   virtual int attach (unsigned long pid) = 0;
+
+  /* Kill process PROC.  Return -1 on failure, and 0 on success.  */
+  virtual int kill (process_info *proc) = 0;
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 1acab18d09f..7c86080ed3b 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -808,8 +808,8 @@ win32_clear_inferiors (void)
 
 /* Implementation of target_ops::kill.  */
 
-static int
-win32_kill (process_info *process)
+int
+win32_process_target::kill (process_info *process)
 {
   TerminateProcess (current_process_handle, 0);
   for (;;)
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_kill,
   win32_detach,
   win32_mourn,
   win32_join,
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index f626db6cf60..c2d5b577e98 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -110,6 +110,8 @@ public:
 		       const std::vector<char *> &program_args) override;
 
   int attach (unsigned long pid) override;
+
+  int kill (process_info *proc) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 22/58] gdbserver: turn target op 'supports_hardware_single_step' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 04/58] gdbserver: turn target op 'attach' into a method Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 26/58] gdbserver: turn target op 'hostio_last_error' " Tankut Baris Aktemur
                   ` (57 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's supports_hardware_single_step op a
	method of process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_supports_hardware_single_step): Update the macro.
	(target_can_do_hardware_single_step): Remove declaration.
	* target.c (process_target::supports_hardware_single_step): Define.
	(target_can_do_hardware_single_step): Remove.

	Update the derived structs and callers below.

	* linux-low.h (class linux_process_target): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_supports_hardware_single_step): Turn into ...
	(linux_process_target::supports_hardware_single_step): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_process_target::supports_hardware_single_step): Define.
	* nto-low.h (class nto_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_process_target::supports_hardware_single_step): Define.
	* win32-low.h (class win32_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_process_target::supports_hardware_single_step): Define.
---
 gdbserver/linux-low.c |  5 ++---
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  7 ++++++-
 gdbserver/lynx-low.h  |  2 ++
 gdbserver/nto-low.c   |  7 ++++++-
 gdbserver/nto-low.h   |  2 ++
 gdbserver/target.c    | 14 ++++++--------
 gdbserver/target.h    | 11 ++++-------
 gdbserver/win32-low.c |  7 ++++++-
 gdbserver/win32-low.h |  2 ++
 10 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 9d02e96f6f0..d43483c5e0b 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6032,8 +6032,8 @@ linux_process_target::supports_stopped_by_hw_breakpoint ()
 
 /* Implement the supports_hardware_single_step target_ops method.  */
 
-static int
-linux_supports_hardware_single_step (void)
+bool
+linux_process_target::supports_hardware_single_step ()
 {
   return can_hardware_single_step ();
 }
@@ -7376,7 +7376,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_supports_hardware_single_step,
   linux_stopped_by_watchpoint,
   linux_stopped_data_address,
 #if defined(__UCLIBC__) && defined(HAS_NOMMU)	      \
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 41f99591b3e..00e563eddbe 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -329,6 +329,8 @@ public:
   bool stopped_by_hw_breakpoint () override;
 
   bool supports_stopped_by_hw_breakpoint () override;
+
+  bool supports_hardware_single_step () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 7f074445f37..23dc32c31f8 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -722,6 +722,12 @@ lynx_process_target::request_interrupt ()
   kill (lynx_ptid_get_pid (inferior_ptid), SIGINT);
 }
 
+bool
+lynx_process_target::supports_hardware_single_step ()
+{
+  return true;
+}
+
 /* The LynxOS target ops object.  */
 
 static lynx_process_target the_lynx_target;
@@ -729,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  target_can_do_hardware_single_step,
   NULL,  /* stopped_by_watchpoint */
   NULL,  /* stopped_data_address */
   NULL,  /* read_offsets */
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index 3560c22abc1..4f542118704 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -88,6 +88,8 @@ public:
 		    int len) override;
 
   void request_interrupt () override;
+
+  bool supports_hardware_single_step () override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index b7adc82da69..20db2dba3f4 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -869,6 +869,12 @@ nto_process_target::remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
   return nto_breakpoint (addr, wtype, -1);
 }
 
+bool
+nto_process_target::supports_hardware_single_step ()
+{
+  return true;
+}
+
 /* Check if the reason of stop for current thread (CURRENT_INFERIOR) is
    a watchpoint.
 
@@ -950,7 +956,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  target_can_do_hardware_single_step,
   nto_stopped_by_watchpoint,
   nto_stopped_data_address,
   NULL, /* nto_read_offsets */
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index a51477789e7..7b321077607 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -91,6 +91,8 @@ public:
 
   int remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
 		    int size, raw_breakpoint *bp) override;
+
+  bool supports_hardware_single_step () override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.c b/gdbserver/target.c
index f7dc0f4d658..09b3a633fc8 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -316,14 +316,6 @@ kill_inferior (process_info *proc)
   return the_target->pt->kill (proc);
 }
 
-/* Target can do hardware single step.  */
-
-int
-target_can_do_hardware_single_step (void)
-{
-  return 1;
-}
-
 /* Default implementation for breakpoint_kind_for_pc.
 
    The default behavior for targets that don't implement breakpoint_kind_for_pc
@@ -471,3 +463,9 @@ process_target::supports_stopped_by_hw_breakpoint ()
 {
   return false;
 }
+
+bool
+process_target::supports_hardware_single_step ()
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index aae0e3afd24..263efaf104f 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Returns true if the target can do hardware single step.  */
-  int (*supports_hardware_single_step) (void);
-
   /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise.  */
 
   int (*stopped_by_watchpoint) (void);
@@ -476,6 +473,9 @@ public:
   /* Returns true if the target knows whether a trap was caused by a
      HW breakpoint triggering.  */
   virtual bool supports_stopped_by_hw_breakpoint ();
+
+  /* Returns true if the target can do hardware single step.  */
+  virtual bool supports_hardware_single_step ();
 };
 
 extern process_stratum_target *the_target;
@@ -668,8 +668,7 @@ target_read_btrace_conf (struct btrace_target_info *tinfo,
   the_target->pt->supports_stopped_by_hw_breakpoint ()
 
 #define target_supports_hardware_single_step() \
-  (the_target->supports_hardware_single_step ? \
-   (*the_target->supports_hardware_single_step) () : 0)
+  the_target->pt->supports_hardware_single_step ()
 
 #define target_stopped_by_hw_breakpoint() \
   the_target->pt->stopped_by_hw_breakpoint ()
@@ -720,8 +719,6 @@ int set_desired_thread ();
 
 const char *target_pid_to_str (ptid_t);
 
-int target_can_do_hardware_single_step (void);
-
 int default_breakpoint_kind_from_pc (CORE_ADDR *pcptr);
 
 #endif /* GDBSERVER_TARGET_H */
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 9e8a3801099..0c4a948a37a 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1718,6 +1718,12 @@ win32_process_target::request_interrupt ()
   soft_interrupt_requested = 1;
 }
 
+bool
+win32_process_target::supports_hardware_single_step ()
+{
+  return true;
+}
+
 #ifdef _WIN32_WCE
 int
 win32_error_to_fileio_error (DWORD err)
@@ -1828,7 +1834,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  target_can_do_hardware_single_step,
   win32_stopped_by_watchpoint,
   win32_stopped_data_address,
   NULL, /* read_offsets */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 39c4a4ce917..b13c53c4ed3 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -145,6 +145,8 @@ public:
 
   int remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
 		    int size, raw_breakpoint *bp) override;
+
+  bool supports_hardware_single_step () override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 06/58] gdbserver: turn target op 'detach' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (4 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 28/58] gdbserver: turn target op 'qxfer_siginfo' into a method Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 12/58] gdbserver: turn target ops 'fetch_registers' and 'store_registers' into methods Tankut Baris Aktemur
                   ` (53 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's detach op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(detach_inferior): Update the macro.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_detach): Turn into ...
	(linux_process_target::detach): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_detach): Turn into ...
	(lynx_process_target::detach): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_detach): Turn into ...
	(nto_process_target::detach): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_detach): Turn into ...
	(win32_process_target::detach): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c |  5 ++---
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  5 ++---
 gdbserver/lynx-low.h  |  2 ++
 gdbserver/nto-low.c   |  5 ++---
 gdbserver/nto-low.h   |  2 ++
 gdbserver/target.h    | 11 +++++------
 gdbserver/win32-low.c |  5 ++---
 gdbserver/win32-low.h |  2 ++
 9 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 3298d142f26..5fe0cae0b8a 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -1603,8 +1603,8 @@ linux_detach_lwp_callback (thread_info *thread)
   linux_detach_one_lwp (lwp);
 }
 
-static int
-linux_detach (process_info *process)
+int
+linux_process_target::detach (process_info *process)
 {
   struct lwp_info *main_lwp;
 
@@ -7359,7 +7359,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_detach,
   linux_mourn,
   linux_join,
   linux_thread_alive,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 636032e3212..b2e8b7d591f 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -277,6 +277,8 @@ public:
   int attach (unsigned long pid) override;
 
   int kill (process_info *proc) override;
+
+  int detach (process_info *proc) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index fb59d5105cb..e3887020df0 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -535,8 +535,8 @@ lynx_process_target::kill (process_info *process)
 
 /* Implement the detach target_ops method.  */
 
-static int
-lynx_detach (process_info *process)
+int
+lynx_process_target::detach (process_info *process)
 {
   ptid_t ptid = lynx_ptid_t (process->pid, 0);
 
@@ -726,7 +726,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_detach,
   lynx_mourn,
   lynx_join,
   lynx_thread_alive,
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index 749b0dee19f..42c5eff4e62 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -63,6 +63,8 @@ public:
   int attach (unsigned long pid) override;
 
   int kill (process_info *proc) override;
+
+  int detach (process_info *proc) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 0af8fb1bcee..d5ad30ad5ad 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -409,8 +409,8 @@ nto_process_target::kill (process_info *proc)
 
 /* Detach from process PID.  */
 
-static int
-nto_detach (process_info *proc)
+int
+nto_process_target::detach (process_info *proc)
 {
   TRACE ("%s %d\n", __func__, proc->pid);
   do_detach ();
@@ -935,7 +935,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_detach,
   nto_mourn,
   NULL, /* nto_join */
   nto_thread_alive,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index fbef01dedc9..87e6c824cf2 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -53,6 +53,8 @@ public:
   int attach (unsigned long pid) override;
 
   int kill (process_info *proc) override;
+
+  int detach (process_info *proc) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.h b/gdbserver/target.h
index a1e9de15c2a..7637bd2b7bc 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,11 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Detach from process PROC.  Return -1 on failure, and 0 on
-     success.  */
-
-  int (*detach) (process_info *proc);
-
   /* The inferior process has died.  Do what is right.  */
 
   void (*mourn) (struct process_info *proc);
@@ -486,6 +481,10 @@ public:
 
   /* Kill process PROC.  Return -1 on failure, and 0 on success.  */
   virtual int kill (process_info *proc) = 0;
+
+  /* Detach from process PROC.  Return -1 on failure, and 0 on
+     success.  */
+  virtual int detach (process_info *proc) = 0;
 };
 
 extern process_stratum_target *the_target;
@@ -523,7 +522,7 @@ int kill_inferior (process_info *proc);
     } while (0)
 
 #define detach_inferior(proc) \
-  (*the_target->detach) (proc)
+  the_target->pt->detach (proc)
 
 #define mythread_alive(pid) \
   (*the_target->thread_alive) (pid)
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 7c86080ed3b..a215afec0aa 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -832,8 +832,8 @@ win32_process_target::kill (process_info *process)
 
 /* Implementation of target_ops::detach.  */
 
-static int
-win32_detach (process_info *process)
+int
+win32_process_target::detach (process_info *process)
 {
   winapi_DebugActiveProcessStop DebugActiveProcessStop = NULL;
   winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_detach,
   win32_mourn,
   win32_join,
   win32_thread_alive,
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index c2d5b577e98..54a11c981c8 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -112,6 +112,8 @@ public:
   int attach (unsigned long pid) override;
 
   int kill (process_info *proc) override;
+
+  int detach (process_info *proc) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 48/58] gdbserver: turn btrace-related target ops into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (2 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 26/58] gdbserver: turn target op 'hostio_last_error' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 28/58] gdbserver: turn target op 'qxfer_siginfo' into a method Tankut Baris Aktemur
                   ` (55 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's btrace-related ops (enable_btrace,
	disable_btrace, read_btrace, read_btrace_conf) methods of
	process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	(target_enable_btrace): Update.
	(target_disable_btrace): Update.
	(target_read_btrace): Update.
	(target_read_btrace_conf): Update.
	* target.c (process_target::enable_btrace): Define.
	(process_target::disable_btrace): Define.
	(process_target::read_btrace): Define.
	(process_target::read_btrace_conf): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_process_target:enable_btrace): Define as a wrapper around
	linux_enable_btrace.
	(linux_low_disable_btrace): Turn into ...
	(linux_process_target::disable_btrace): ... this.
	(linux_low_read_btrace): Turn into ...
	(linux_process_target::read_btrace): ... this.
	(linux_low_btrace_conf): Turn into ...
	(linux_process_target::read_btrace_conf): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 35 ++++++++++++-------------
 gdbserver/linux-low.h | 13 +++++++++
 gdbserver/lynx-low.c  |  4 ---
 gdbserver/nto-low.c   |  4 ---
 gdbserver/target.c    | 27 +++++++++++++++++++
 gdbserver/target.h    | 61 ++++++++++++++++++-------------------------
 gdbserver/win32-low.c |  4 ---
 7 files changed, 81 insertions(+), 67 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 5a3390bff54..4cd18de5249 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -7142,10 +7142,17 @@ linux_process_target::qxfer_libraries_svr4 (const char *annex,
 
 #ifdef HAVE_LINUX_BTRACE
 
+btrace_target_info *
+linux_process_target::enable_btrace (ptid_t ptid,
+				     const btrace_config *conf)
+{
+  return linux_enable_btrace (ptid, conf);
+}
+
 /* See to_disable_btrace target method.  */
 
-static int
-linux_low_disable_btrace (struct btrace_target_info *tinfo)
+int
+linux_process_target::disable_btrace (btrace_target_info *tinfo)
 {
   enum btrace_error err;
 
@@ -7204,9 +7211,10 @@ linux_low_encode_raw (struct buffer *buffer, const gdb_byte *data,
 
 /* See to_read_btrace target method.  */
 
-static int
-linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
-		       enum btrace_read_type type)
+int
+linux_process_target::read_btrace (btrace_target_info *tinfo,
+				   buffer *buffer,
+				   enum btrace_read_type type)
 {
   struct btrace_data btrace;
   enum btrace_error err;
@@ -7263,9 +7271,9 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
 
 /* See to_btrace_conf target method.  */
 
-static int
-linux_low_btrace_conf (const struct btrace_target_info *tinfo,
-		       struct buffer *buffer)
+int
+linux_process_target::read_btrace_conf (const btrace_target_info *tinfo,
+					buffer *buffer)
 {
   const struct btrace_config *conf;
 
@@ -7452,17 +7460,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-#ifdef HAVE_LINUX_BTRACE
-  linux_enable_btrace,
-  linux_low_disable_btrace,
-  linux_low_read_btrace,
-  linux_low_btrace_conf,
-#else
-  NULL,
-  NULL,
-  NULL,
-  NULL,
-#endif
   linux_supports_range_stepping,
   linux_proc_pid_to_exec_file,
   linux_mntns_open_cloexec,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 63cb52e9204..090700cf011 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -436,6 +436,19 @@ public:
 			    CORE_ADDR offset, int len) override;
 
   bool supports_agent () override;
+
+#ifdef HAVE_LINUX_BTRACE
+  btrace_target_info *enable_btrace (ptid_t ptid,
+				     const btrace_config *conf) override;
+
+  int disable_btrace (btrace_target_info *tinfo) override;
+
+  int read_btrace (btrace_target_info *tinfo, buffer *buf,
+		   enum btrace_read_type type) override;
+
+  int read_btrace_conf (const btrace_target_info *tinfo,
+			buffer *buf) override;
+#endif
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index bfa76cf7de6..b2a5c2cc22b 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,10 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* enable_btrace */
-  NULL,  /* disable_btrace */
-  NULL,  /* read_btrace */
-  NULL,  /* read_btrace_conf */
   NULL,  /* supports_range_stepping */
   NULL,  /* pid_to_exec_file */
   NULL,  /* multifs_open */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index e97ebe395f7..5978dbbc742 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,10 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* enable_btrace */
-  NULL, /* disable_btrace */
-  NULL, /* read_btrace */
-  NULL, /* read_btrace_conf */
   NULL, /* supports_range_stepping */
   NULL, /* pid_to_exec_file */
   NULL, /* multifs_open */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 3e4d9730b6f..534508446b4 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -726,3 +726,30 @@ process_target::supports_agent ()
 {
   return false;
 }
+
+btrace_target_info *
+process_target::enable_btrace (ptid_t ptid, const btrace_config *conf)
+{
+  error (_("Target does not support branch tracing."));
+}
+
+int
+process_target::disable_btrace (btrace_target_info *tinfo)
+{
+  error (_("Target does not support branch tracing."));
+}
+
+int
+process_target::read_btrace (btrace_target_info *tinfo,
+			     buffer *buffer,
+			     enum btrace_read_type type)
+{
+  error (_("Target does not support branch tracing."));
+}
+
+int
+process_target::read_btrace_conf (const btrace_target_info *tinfo,
+				  buffer *buffer)
+{
+  error (_("Target does not support branch tracing."));
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index a89f7b14269..d3a8cc9d581 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,26 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Enable branch tracing for PTID based on CONF and allocate a branch trace
-     target information struct for reading and for disabling branch trace.  */
-  struct btrace_target_info *(*enable_btrace)
-    (ptid_t ptid, const struct btrace_config *conf);
-
-  /* Disable branch tracing.
-     Returns zero on success, non-zero otherwise.  */
-  int (*disable_btrace) (struct btrace_target_info *tinfo);
-
-  /* Read branch trace data into buffer.
-     Return 0 on success; print an error message into BUFFER and return -1,
-     otherwise.  */
-  int (*read_btrace) (struct btrace_target_info *, struct buffer *,
-		      enum btrace_read_type type);
-
-  /* Read the branch trace configuration into BUFFER.
-     Return 0 on success; print an error message into BUFFER and return -1
-     otherwise.  */
-  int (*read_btrace_conf) (const struct btrace_target_info *, struct buffer *);
-
   /* Return true if target supports range stepping.  */
   int (*supports_range_stepping) (void);
 
@@ -497,6 +477,27 @@ public:
 
   /* Return true if target supports debugging agent.  */
   virtual bool supports_agent ();
+
+  /* Enable branch tracing for PTID based on CONF and allocate a branch trace
+     target information struct for reading and for disabling branch trace.  */
+  virtual btrace_target_info *enable_btrace (ptid_t ptid,
+					     const btrace_config *conf);
+
+  /* Disable branch tracing.
+     Returns zero on success, non-zero otherwise.  */
+  virtual int disable_btrace (btrace_target_info *tinfo);
+
+  /* Read branch trace data into buffer.
+     Return 0 on success; print an error message into BUFFER and return -1,
+     otherwise.  */
+  virtual int read_btrace (btrace_target_info *tinfo, buffer *buf,
+			   enum btrace_read_type type);
+
+  /* Read the branch trace configuration into BUFFER.
+     Return 0 on success; print an error message into BUFFER and return -1
+     otherwise.  */
+  virtual int read_btrace_conf (const btrace_target_info *tinfo,
+				buffer *buf);
 };
 
 extern process_stratum_target *the_target;
@@ -612,19 +613,13 @@ int kill_inferior (process_info *proc);
 static inline struct btrace_target_info *
 target_enable_btrace (ptid_t ptid, const struct btrace_config *conf)
 {
-  if (the_target->enable_btrace == nullptr)
-    error (_("Target does not support branch tracing."));
-
-  return (*the_target->enable_btrace) (ptid, conf);
+  return the_target->pt->enable_btrace (ptid, conf);
 }
 
 static inline int
 target_disable_btrace (struct btrace_target_info *tinfo)
 {
-  if (the_target->disable_btrace == nullptr)
-    error (_("Target does not support branch tracing."));
-
-  return (*the_target->disable_btrace) (tinfo);
+  return the_target->pt->disable_btrace (tinfo);
 }
 
 static inline int
@@ -632,20 +627,14 @@ target_read_btrace (struct btrace_target_info *tinfo,
 		    struct buffer *buffer,
 		    enum btrace_read_type type)
 {
-  if (the_target->read_btrace == nullptr)
-    error (_("Target does not support branch tracing."));
-
-  return (*the_target->read_btrace) (tinfo, buffer, type);
+  return the_target->pt->read_btrace (tinfo, buffer, type);
 }
 
 static inline int
 target_read_btrace_conf (struct btrace_target_info *tinfo,
 			 struct buffer *buffer)
 {
-  if (the_target->read_btrace_conf == nullptr)
-    error (_("Target does not support branch tracing."));
-
-  return (*the_target->read_btrace_conf) (tinfo, buffer);
+  return the_target->pt->read_btrace_conf (tinfo, buffer);
 }
 
 #define target_supports_range_stepping() \
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index e24c6ced43d..d54bd2cfff1 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,10 +1848,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* enable_btrace */
-  NULL, /* disable_btrace */
-  NULL, /* read_btrace */
-  NULL, /* read_btrace_conf */
   NULL, /* supports_range_stepping */
   NULL, /* pid_to_exec_file */
   NULL, /* multifs_open */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 24/58] gdbserver: turn target op 'read_offsets' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (9 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 33/58] gdbserver: turn target op 'handle_monitor_command' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-13 20:29   ` Pedro Alves
  2020-02-11  9:03 ` [PATCH 37/58] gdbserver: turn target op 'supports_tracepoints' " Tankut Baris Aktemur
                   ` (48 subsequent siblings)
  59 siblings, 1 reply; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's read_offsets op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.  Also add
	'supports_read_offsets'.
	* target.c (process_target::read_offsets): Define.
	(process_target::supports_read_offsets): Define.

	Update the derived structs and callers below.

	* server.c (handle_query): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::supports_read_offsets): Define.
	(linux_read_offsets): Turn into ...
	(linux_process_target::read_offsets): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 17 ++++++++---------
 gdbserver/linux-low.h |  8 ++++++++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/server.c    |  4 ++--
 gdbserver/target.c    | 12 ++++++++++++
 gdbserver/target.h    | 14 ++++++++------
 gdbserver/win32-low.c |  1 -
 8 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index a01ecd0c562..93cd2bf57d4 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6068,11 +6068,17 @@ linux_process_target::stopped_data_address ()
    the target has different ways of acquiring this information, like
    loadmaps.  */
 
+bool
+linux_process_target::supports_read_offsets ()
+{
+  return true;
+}
+
 /* Under uClinux, programs are loaded at non-zero offsets, which we need
    to tell gdb about.  */
 
-static int
-linux_read_offsets (CORE_ADDR *text_p, CORE_ADDR *data_p)
+int
+linux_process_target::read_offsets (CORE_ADDR *text_p, CORE_ADDR *data_p)
 {
   unsigned long text, text_end, data;
   int pid = lwpid_of (current_thread);
@@ -7375,13 +7381,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-#if defined(__UCLIBC__) && defined(HAS_NOMMU)	      \
-    && defined(PT_TEXT_ADDR) && defined(PT_DATA_ADDR) \
-    && defined(PT_TEXT_END_ADDR)
-  linux_read_offsets,
-#else
-  NULL,
-#endif
 #ifdef USE_THREAD_DB
   thread_db_get_tls_address,
 #else
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 59a1d9321d9..5cf2e62dffb 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -335,6 +335,14 @@ public:
   bool stopped_by_watchpoint () override;
 
   CORE_ADDR stopped_data_address () override;
+
+#if defined(__UCLIBC__) && defined(HAS_NOMMU)	      \
+    && defined(PT_TEXT_ADDR) && defined(PT_DATA_ADDR) \
+    && defined(PT_TEXT_END_ADDR)
+  bool supports_read_offsets () override;
+
+  int read_offsets (CORE_ADDR *text, CORE_ADDR *data) override;
+#endif
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 0d4934fb313..2a3eda61b5f 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* read_offsets */
   NULL,  /* get_tls_address */
   NULL,  /* hostio_last_error */
   NULL,  /* qxfer_osdata */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index fc7a6032fd6..5d4540cff7e 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -956,7 +956,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* nto_read_offsets */
   NULL, /* thread_db_set_tls_address */
   hostio_last_error_from_errno,
   NULL, /* nto_qxfer_osdata */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index f13061c871b..b4fd9c6a5e5 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -2234,13 +2234,13 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 	}
     }
 
-  if (the_target->read_offsets != NULL
+  if (the_target->pt->supports_read_offsets ()
       && strcmp ("qOffsets", own_buf) == 0)
     {
       CORE_ADDR text, data;
 
       require_running_or_return (own_buf);
-      if (the_target->read_offsets (&text, &data))
+      if (the_target->pt->read_offsets (&text, &data))
 	sprintf (own_buf, "Text=%lX;Data=%lX;Bss=%lX",
 		 (long)text, (long)data, (long)data);
       else
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 00f5f794b85..501a8d675db 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -481,3 +481,15 @@ process_target::stopped_data_address ()
 {
   return 0;
 }
+
+bool
+process_target::supports_read_offsets ()
+{
+  return false;
+}
+
+int
+process_target::read_offsets (CORE_ADDR *text, CORE_ADDR *data)
+{
+  gdb_assert_not_reached ("target op read_offsets not supported");
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index f9c749fdfcb..8919d43317e 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,12 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Reports the text, data offsets of the executable.  This is
-     needed for uclinux where the executable is relocated during load
-     time.  */
-
-  int (*read_offsets) (CORE_ADDR *text, CORE_ADDR *data);
-
   /* Fetch the address associated with a specific thread local storage
      area, determined by the specified THREAD, OFFSET, and LOAD_MODULE.
      Stores it in *ADDRESS and returns zero on success; otherwise returns
@@ -475,6 +469,14 @@ public:
   /* Returns the address associated with the watchpoint that hit, if any;
      returns 0 otherwise.  */
   virtual CORE_ADDR stopped_data_address ();
+
+  /* Return true if the read_offsets target op is supported.  */
+  virtual bool supports_read_offsets ();
+
+  /* Reports the text, data offsets of the executable.  This is
+     needed for uclinux where the executable is relocated during load
+     time.  */
+  virtual int read_offsets (CORE_ADDR *text, CORE_ADDR *data);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 970c532c149..48b70a5e334 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1834,7 +1834,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* read_offsets */
   NULL, /* get_tls_address */
 #ifdef _WIN32_WCE
   wince_hostio_last_error,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 13/58] gdbserver: turn prepare_to_access_memory & done_accessing_memory into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (28 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 15/58] gdbserver: turn target op 'look_up_symbols' into a method Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 18/58] gdbserver: turn target op 'supports_z_point_type' into a method Tankut Baris Aktemur
                   ` (29 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's prepare_to_access_memory and
	done_accessing_memory ops methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	* target.c (process_target::prepare_to_access_memory): Define.
	(process_target::done_accessing_memory): Define.
	(prepare_to_access_memory): Update.
	(done_accessing_memory): Update.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_prepare_to_access_memory): Turn into ...
	(linux_process_target::prepare_to_access_memory): ... this.
	(linux_done_accessing_memory): Turn into ...
	(linux_process_target::done_accessing_memory): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 10 ++++------
 gdbserver/linux-low.h |  4 ++++
 gdbserver/lynx-low.c  |  2 --
 gdbserver/nto-low.c   |  2 --
 gdbserver/target.c    | 26 ++++++++++++++++----------
 gdbserver/target.h    | 32 +++++++++++++++-----------------
 gdbserver/win32-low.c |  2 --
 7 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 9514cffb589..1d05e1b9ff0 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6505,8 +6505,8 @@ linux_unpause_all (int unfreeze)
   unstop_all_lwps (unfreeze, NULL);
 }
 
-static int
-linux_prepare_to_access_memory (void)
+int
+linux_process_target::prepare_to_access_memory ()
 {
   /* Neither ptrace nor /proc/PID/mem allow accessing memory through a
      running LWP.  */
@@ -6515,8 +6515,8 @@ linux_prepare_to_access_memory (void)
   return 0;
 }
 
-static void
-linux_done_accessing_memory (void)
+void
+linux_process_target::done_accessing_memory ()
 {
   /* Neither ptrace nor /proc/PID/mem allow accessing memory through a
      running LWP.  */
@@ -7359,8 +7359,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_prepare_to_access_memory,
-  linux_done_accessing_memory,
   linux_read_memory,
   linux_write_memory,
   linux_look_up_symbols,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index e361f29877c..51622f6d211 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -294,6 +294,10 @@ public:
   void fetch_registers (regcache *regcache, int regno) override;
 
   void store_registers (regcache *regcache, int regno) override;
+
+  int prepare_to_access_memory () override;
+
+  void done_accessing_memory () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index c27c1182415..365f82b55ce 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -727,8 +727,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* prepare_to_access_memory */
-  NULL,  /* done_accessing_memory */
   lynx_read_memory,
   lynx_write_memory,
   NULL,  /* look_up_symbols */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 7dce2fa9cb5..2e75225b01e 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -941,8 +941,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* prepare_to_access_memory */
-  NULL, /* done_accessing_memory */
   nto_read_memory,
   nto_write_memory,
   NULL, /* nto_look_up_symbols */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index b73c4465f1c..f88e9faf191 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -57,14 +57,9 @@ prepare_to_access_memory (void)
      it.  */
   prev_general_thread = cs.general_thread;
 
-  if (the_target->prepare_to_access_memory != NULL)
-    {
-      int res;
-
-      res = the_target->prepare_to_access_memory ();
-      if (res != 0)
-	return res;
-    }
+  int res = the_target->pt->prepare_to_access_memory ();
+  if (res != 0)
+    return res;
 
   for_each_thread (prev_general_thread.pid (), [&] (thread_info *thread)
     {
@@ -114,8 +109,7 @@ done_accessing_memory (void)
 {
   client_state &cs = get_client_state ();
 
-  if (the_target->done_accessing_memory != NULL)
-    the_target->done_accessing_memory ();
+  the_target->pt->done_accessing_memory ();
 
   /* Restore the previous selected thread.  */
   cs.general_thread = prev_general_thread;
@@ -402,3 +396,15 @@ process_target::post_create_inferior ()
 {
   /* Nop.  */
 }
+
+int
+process_target::prepare_to_access_memory ()
+{
+  return 0;
+}
+
+void
+process_target::done_accessing_memory ()
+{
+  /* Nop.  */
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 41f1fc2e27d..16ff5ab6baa 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,23 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Prepare to read or write memory from the inferior process.
-     Targets use this to do what is necessary to get the state of the
-     inferior such that it is possible to access memory.
-
-     This should generally only be called from client facing routines,
-     such as gdb_read_memory/gdb_write_memory, or the GDB breakpoint
-     insertion routine.
-
-     Like `read_memory' and `write_memory' below, returns 0 on success
-     and errno on failure.  */
-
-  int (*prepare_to_access_memory) (void);
-
-  /* Undo the effects of prepare_to_access_memory.  */
-
-  void (*done_accessing_memory) (void);
-
   /* Read memory from the inferior process.  This should generally be
      called through read_inferior_memory, which handles breakpoint shadowing.
 
@@ -479,6 +462,21 @@ public:
 
      If REGNO is -1, store all registers; otherwise, store at least REGNO.  */
   virtual void store_registers (regcache *regcache, int regno) = 0;
+
+  /* Prepare to read or write memory from the inferior process.
+     Targets use this to do what is necessary to get the state of the
+     inferior such that it is possible to access memory.
+
+     This should generally only be called from client facing routines,
+     such as gdb_read_memory/gdb_write_memory, or the GDB breakpoint
+     insertion routine.
+
+     Like `read_memory' and `write_memory' below, returns 0 on success
+     and errno on failure.  */
+  virtual int prepare_to_access_memory ();
+
+  /* Undo the effects of prepare_to_access_memory.  */
+  virtual void done_accessing_memory ();
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 1774c22ca9b..6639401b1ae 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1827,8 +1827,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* prepare_to_access_memory */
-  NULL, /* done_accessing_memory */
   win32_read_inferior_memory,
   win32_write_inferior_memory,
   NULL, /* lookup_symbols */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 07/58] gdbserver: turn target op 'mourn' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (7 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 20/58] gdbserver: turn target op '{supports_}stopped_by_sw_breakpoint' into a method Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 33/58] gdbserver: turn target op 'handle_monitor_command' " Tankut Baris Aktemur
                   ` (50 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's mourn op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.

	Update the derived structs and callers below.

	* target.c (target_mourn_inferior): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_mourn): Turn into ...
	(linux_process_target::mourn): ... this.
	(handle_extended_wait): Update.
	(linux_process_target::kill): Update.
	(linux_process_target::detach): Update.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_mourn): Turn into ...
	(lynx_process_target::mourn): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_mourn): Turn into ...
	(nto_process_target::mourn): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_mourn): Turn into ...
	(win32_process_target::mourn): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c | 12 +++++-------
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  9 ++++-----
 gdbserver/lynx-low.h  |  2 ++
 gdbserver/nto-low.c   |  5 ++---
 gdbserver/nto-low.h   |  2 ++
 gdbserver/target.c    |  2 +-
 gdbserver/target.h    |  7 +++----
 gdbserver/win32-low.c |  5 ++---
 gdbserver/win32-low.h |  2 ++
 10 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 5fe0cae0b8a..fb2f79c2204 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -270,7 +270,6 @@ static int linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
 					  int *wstat, int options);
 static int linux_wait_for_event (ptid_t ptid, int *wstat, int options);
 static struct lwp_info *add_lwp (ptid_t ptid);
-static void linux_mourn (struct process_info *process);
 static int linux_stopped_by_watchpoint (void);
 static void mark_lwp_dead (struct lwp_info *lwp, int wstat);
 static int lwp_is_marked_dead (struct lwp_info *lwp);
@@ -707,7 +706,7 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat)
       syscalls_to_catch = std::move (proc->syscalls_to_catch);
 
       /* Delete the execing process and all its threads.  */
-      linux_mourn (proc);
+      the_target->pt->mourn (proc);
       current_thread = NULL;
 
       /* Create a new process/lwp/thread.  */
@@ -1413,7 +1412,7 @@ linux_process_target::kill (process_info *process)
   else
     kill_wait_lwp (lwp);
 
-  the_target->mourn (process);
+  mourn (process);
 
   /* Since we presently can only stop all lwps of all processes, we
      need to unstop lwps of other processes.  */
@@ -1634,7 +1633,7 @@ linux_process_target::detach (process_info *process)
   main_lwp = find_lwp_pid (ptid_t (process->pid));
   linux_detach_one_lwp (main_lwp);
 
-  the_target->mourn (process);
+  mourn (process);
 
   /* Since we presently can only stop all lwps of all processes, we
      need to unstop lwps of other processes.  */
@@ -1644,8 +1643,8 @@ linux_process_target::detach (process_info *process)
 
 /* Remove all LWPs that belong to process PROC from the lwp list.  */
 
-static void
-linux_mourn (struct process_info *process)
+void
+linux_process_target::mourn (process_info *process)
 {
   struct process_info_private *priv;
 
@@ -7359,7 +7358,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_mourn,
   linux_join,
   linux_thread_alive,
   linux_resume,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index b2e8b7d591f..4b9d6ce65b6 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -279,6 +279,8 @@ public:
   int kill (process_info *proc) override;
 
   int detach (process_info *proc) override;
+
+  void mourn (process_info *proc) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index e3887020df0..55721ac87b2 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -529,7 +529,7 @@ lynx_process_target::kill (process_info *process)
 
   lynx_ptrace (PTRACE_KILL, ptid, 0, 0, 0);
   lynx_wait (ptid, &status, 0);
-  the_target->mourn (process);
+  mourn (process);
   return 0;
 }
 
@@ -541,14 +541,14 @@ lynx_process_target::detach (process_info *process)
   ptid_t ptid = lynx_ptid_t (process->pid, 0);
 
   lynx_ptrace (PTRACE_DETACH, ptid, 0, 0, 0);
-  the_target->mourn (process);
+  mourn (process);
   return 0;
 }
 
 /* Implement the mourn target_ops method.  */
 
-static void
-lynx_mourn (struct process_info *proc)
+void
+lynx_process_target::mourn (struct process_info *proc)
 {
   for_each_thread (proc->pid, remove_thread);
 
@@ -726,7 +726,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_mourn,
   lynx_join,
   lynx_thread_alive,
   lynx_resume,
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index 42c5eff4e62..b290922e4b4 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -65,6 +65,8 @@ public:
   int kill (process_info *proc) override;
 
   int detach (process_info *proc) override;
+
+  void mourn (process_info *proc) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index d5ad30ad5ad..09ae60219a6 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -417,8 +417,8 @@ nto_process_target::detach (process_info *proc)
   return 0;
 }
 
-static void
-nto_mourn (struct process_info *process)
+void
+nto_process_target::mourn (struct process_info *process)
 {
   remove_process (process);
 }
@@ -935,7 +935,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_mourn,
   NULL, /* nto_join */
   nto_thread_alive,
   nto_resume,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index 87e6c824cf2..fd675811753 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -55,6 +55,8 @@ public:
   int kill (process_info *proc) override;
 
   int detach (process_info *proc) override;
+
+  void mourn (process_info *proc) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.c b/gdbserver/target.c
index a9632aa8cd9..f6d8d927b85 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -231,7 +231,7 @@ target_wait (ptid_t ptid, struct target_waitstatus *status, int options)
 void
 target_mourn_inferior (ptid_t ptid)
 {
-  (*the_target->mourn) (find_process_pid (ptid.pid ()));
+  the_target->pt->mourn (find_process_pid (ptid.pid ()));
 }
 
 /* See target/target.h.  */
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 7637bd2b7bc..4c0a98b3ed0 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* The inferior process has died.  Do what is right.  */
-
-  void (*mourn) (struct process_info *proc);
-
   /* Wait for process PID to exit.  */
 
   void (*join) (int pid);
@@ -485,6 +481,9 @@ public:
   /* Detach from process PROC.  Return -1 on failure, and 0 on
      success.  */
   virtual int detach (process_info *proc) = 0;
+
+  /* The inferior process has died.  Do what is right.  */
+  virtual void mourn (process_info *proc) = 0;
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index a215afec0aa..c7ba29567d4 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -867,8 +867,8 @@ win32_process_target::detach (process_info *process)
   return 0;
 }
 
-static void
-win32_mourn (struct process_info *process)
+void
+win32_process_target::mourn (struct process_info *process)
 {
   remove_process (process);
 }
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_mourn,
   win32_join,
   win32_thread_alive,
   win32_resume,
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 54a11c981c8..4ab92dbdae8 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -114,6 +114,8 @@ public:
   int kill (process_info *proc) override;
 
   int detach (process_info *proc) override;
+
+  void mourn (process_info *proc) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 12/58] gdbserver: turn target ops 'fetch_registers' and 'store_registers' into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (5 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 06/58] gdbserver: turn target op 'detach' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 20/58] gdbserver: turn target op '{supports_}stopped_by_sw_breakpoint' into a method Tankut Baris Aktemur
                   ` (52 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's fetch_registers and store_registers
	ops methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	(fetch_inferior_registers): Update the macro.
	(store_inferior_registers): Update the macro.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_fetch_registers): Turn into ...
	(linux_process_target::fetch_registers): ... this.
	(linux_store_registers): Turn into ...
	(linux_process_target::store_registers): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_fetch_registers): Turn into ...
	(lynx_process_target::fetch_registers): ... this.
	(lynx_store_registers): Turn into ...
	(lynx_process_target::store_registers): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_fetch_registers): Turn into ...
	(nto_process_target::fetch_registers): ... this.
	(nto_store_registers): Turn into ...
	(nto_process_target::store_registers): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_fetch_inferior_registers): Turn into ...
	(win32_process_target::fetch_registers): ... this.
	(win32_store_inferior_registers): Turn into ...
	(win32_process_target::store_registers): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c | 10 ++++------
 gdbserver/linux-low.h |  4 ++++
 gdbserver/lynx-low.c  | 10 ++++------
 gdbserver/lynx-low.h  |  4 ++++
 gdbserver/nto-low.c   | 10 ++++------
 gdbserver/nto-low.h   |  4 ++++
 gdbserver/target.h    | 26 ++++++++++++--------------
 gdbserver/win32-low.c | 10 ++++------
 gdbserver/win32-low.h |  4 ++++
 9 files changed, 44 insertions(+), 38 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 9f6f1064f45..9514cffb589 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -5650,8 +5650,8 @@ usr_store_inferior_registers (const struct regs_info *regs_info,
 #endif
 
 
-static void
-linux_fetch_registers (struct regcache *regcache, int regno)
+void
+linux_process_target::fetch_registers (regcache *regcache, int regno)
 {
   int use_regsets;
   int all = 0;
@@ -5683,8 +5683,8 @@ linux_fetch_registers (struct regcache *regcache, int regno)
     }
 }
 
-static void
-linux_store_registers (struct regcache *regcache, int regno)
+void
+linux_process_target::store_registers (regcache *regcache, int regno)
 {
   int use_regsets;
   int all = 0;
@@ -7359,8 +7359,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_fetch_registers,
-  linux_store_registers,
   linux_prepare_to_access_memory,
   linux_done_accessing_memory,
   linux_read_memory,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index c402d8e1c94..e361f29877c 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -290,6 +290,10 @@ public:
 
   ptid_t wait (ptid_t ptid, target_waitstatus *status,
 	       int options) override;
+
+  void fetch_registers (regcache *regcache, int regno) override;
+
+  void store_registers (regcache *regcache, int regno) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 24830d1c289..c27c1182415 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -581,8 +581,8 @@ lynx_process_target::thread_alive (ptid_t ptid)
 
 /* Implement the fetch_registers target_ops method.  */
 
-static void
-lynx_fetch_registers (struct regcache *regcache, int regno)
+void
+lynx_process_target::fetch_registers (regcache *regcache, int regno)
 {
   struct lynx_regset_info *regset = lynx_target_regsets;
   ptid_t inferior_ptid = ptid_of (current_thread);
@@ -606,8 +606,8 @@ lynx_fetch_registers (struct regcache *regcache, int regno)
 
 /* Implement the store_registers target_ops method.  */
 
-static void
-lynx_store_registers (struct regcache *regcache, int regno)
+void
+lynx_process_target::store_registers (regcache *regcache, int regno)
 {
   struct lynx_regset_info *regset = lynx_target_regsets;
   ptid_t inferior_ptid = ptid_of (current_thread);
@@ -727,8 +727,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_fetch_registers,
-  lynx_store_registers,
   NULL,  /* prepare_to_access_memory */
   NULL,  /* done_accessing_memory */
   lynx_read_memory,
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index 1b21ffb4c0a..0d82f86e94e 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -76,6 +76,10 @@ public:
 
   ptid_t wait (ptid_t ptid, target_waitstatus *status,
 	       int options) override;
+
+  void fetch_registers (regcache *regcache, int regno) override;
+
+  void store_registers (regcache *regcache, int regno) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 462936f5eb7..7dce2fa9cb5 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -623,8 +623,8 @@ nto_process_target::wait (ptid_t ptid, target_waitstatus *ourstatus,
 /* Fetch inferior's registers for currently selected thread (CURRENT_INFERIOR).
    If REGNO is -1, fetch all registers, or REGNO register only otherwise.  */
 
-static void
-nto_fetch_registers (struct regcache *regcache, int regno)
+void
+nto_process_target::fetch_registers (regcache *regcache, int regno)
 {
   int regsize;
   procfs_greg greg;
@@ -671,8 +671,8 @@ nto_fetch_registers (struct regcache *regcache, int regno)
 /* Store registers for currently selected thread (CURRENT_INFERIOR).  
    We always store all registers, regardless of REGNO.  */
 
-static void
-nto_store_registers (struct regcache *regcache, int regno)
+void
+nto_process_target::store_registers (regcache *regcache, int regno)
 {
   procfs_greg greg;
   int err;
@@ -941,8 +941,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_fetch_registers,
-  nto_store_registers,
   NULL, /* prepare_to_access_memory */
   NULL, /* done_accessing_memory */
   nto_read_memory,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index faa7cab2941..1fb57f4f73d 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -66,6 +66,10 @@ public:
 
   ptid_t wait (ptid_t ptid, target_waitstatus *status,
 	       int options) override;
+
+  void fetch_registers (regcache *regcache, int regno) override;
+
+  void store_registers (regcache *regcache, int regno) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 43532161f34..41f1fc2e27d 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,18 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Fetch registers from the inferior process.
-
-     If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO.  */
-
-  void (*fetch_registers) (struct regcache *regcache, int regno);
-
-  /* Store registers to the inferior process.
-
-     If REGNO is -1, store all registers; otherwise, store at least REGNO.  */
-
-  void (*store_registers) (struct regcache *regcache, int regno);
-
   /* Prepare to read or write memory from the inferior process.
      Targets use this to do what is necessary to get the state of the
      inferior such that it is possible to access memory.
@@ -481,6 +469,16 @@ public:
      null_ptid/TARGET_WAITKIND_IGNORE.  */
   virtual ptid_t wait (ptid_t ptid, target_waitstatus *status,
 		       int options) = 0;
+
+  /* Fetch registers from the inferior process.
+
+     If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO.  */
+  virtual void fetch_registers (regcache *regcache, int regno) = 0;
+
+  /* Store registers to the inferior process.
+
+     If REGNO is -1, store all registers; otherwise, store at least REGNO.  */
+  virtual void store_registers (regcache *regcache, int regno) = 0;
 };
 
 extern process_stratum_target *the_target;
@@ -524,10 +522,10 @@ int kill_inferior (process_info *proc);
   the_target->pt->thread_alive (pid)
 
 #define fetch_inferior_registers(regcache, regno)	\
-  (*the_target->fetch_registers) (regcache, regno)
+  the_target->pt->fetch_registers (regcache, regno)
 
 #define store_inferior_registers(regcache, regno) \
-  (*the_target->store_registers) (regcache, regno)
+  the_target->pt->store_registers (regcache, regno)
 
 #define join_inferior(pid) \
   the_target->pt->join (pid)
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index b2723b6d292..1774c22ca9b 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1649,16 +1649,16 @@ win32_process_target::wait (ptid_t ptid, target_waitstatus *ourstatus,
 
 /* Fetch registers from the inferior process.
    If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO.  */
-static void
-win32_fetch_inferior_registers (struct regcache *regcache, int regno)
+void
+win32_process_target::fetch_registers (regcache *regcache, int regno)
 {
   child_fetch_inferior_registers (regcache, regno);
 }
 
 /* Store registers to the inferior process.
    If REGNO is -1, store all registers; otherwise, store at least REGNO.  */
-static void
-win32_store_inferior_registers (struct regcache *regcache, int regno)
+void
+win32_process_target::store_registers (regcache *regcache, int regno)
 {
   child_store_inferior_registers (regcache, regno);
 }
@@ -1827,8 +1827,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_fetch_inferior_registers,
-  win32_store_inferior_registers,
   NULL, /* prepare_to_access_memory */
   NULL, /* done_accessing_memory */
   win32_read_inferior_memory,
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index aa509f64ca8..451c3f1b17d 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -125,6 +125,10 @@ public:
 
   ptid_t wait (ptid_t ptid, target_waitstatus *status,
 	       int options) override;
+
+  void fetch_registers (regcache *regcache, int regno) override;
+
+  void store_registers (regcache *regcache, int regno) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 02/58] gdbserver: turn target op 'create_inferior' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (22 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 36/58] gdbserver: turn target op 'process_qsupported' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-13 20:27   ` Pedro Alves
  2020-02-11  9:03 ` [PATCH 45/58] gdbserver: turn target op 'supports_disable_randomization' " Tankut Baris Aktemur
                   ` (35 subsequent siblings)
  59 siblings, 1 reply; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's create_inferior op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(create_inferior): Rename the macro to ...
	(target_create_inferior): ... this.

	Update the derived structs and callers below.

	* server.c (handle_v_run): Update.
	(captured_main): Update.
	(process_serial_event): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_create_inferior): Turn into ...
	(linux_process_target::create_inferior): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_create_inferior): Turn into ...
	(lynx_process_target::create_inferior): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_create_inferior): Turn into ...
	(nto_process_target::create_inferior): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_create_inferior): Turn into ...
	(win32_process_target::create_inferior): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c |  7 +++----
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  7 +++----
 gdbserver/lynx-low.h  |  2 ++
 gdbserver/nto-low.c   |  7 +++----
 gdbserver/nto-low.h   |  2 ++
 gdbserver/server.c    |  6 +++---
 gdbserver/target.h    | 26 +++++++++++++-------------
 gdbserver/win32-low.c |  7 +++----
 gdbserver/win32-low.h |  2 ++
 10 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 17f360639a4..fd122535cc5 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -996,9 +996,9 @@ linux_ptrace_fun ()
    PROGRAM is the name of the program to be started, and PROGRAM_ARGS
    are its arguments.  */
 
-static int
-linux_create_inferior (const char *program,
-		       const std::vector<char *> &program_args)
+int
+linux_process_target::create_inferior (
+    const char *program, const std::vector<char *> &program_args)
 {
   client_state &cs = get_client_state ();
   struct lwp_info *new_lwp;
@@ -7359,7 +7359,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_create_inferior,
   linux_post_create_inferior,
   linux_attach,
   linux_kill,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index f17ac95fae8..acaca0c0070 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -269,6 +269,8 @@ extern struct linux_target_ops the_low_target;
 class linux_process_target : public process_target {
 public:
 
+  int create_inferior (const char *program,
+		       const std::vector<char *> &program_args) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index f1177920921..61b56739e36 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -248,9 +248,9 @@ lynx_ptrace_fun ()
 
 /* Implement the create_inferior method of the target_ops vector.  */
 
-static int
-lynx_create_inferior (const char *program,
-		      const std::vector<char *> &program_args)
+int
+lynx_process_target::create_inferior (
+    const char *program, const std::vector<char *> &program_args)
 {
   int pid;
   std::string str_program_args = stringify_argv (program_args);
@@ -726,7 +726,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_create_inferior,
   NULL,  /* post_create_inferior */
   lynx_attach,
   lynx_kill,
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index ca9601b221b..e74d80be5b4 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -57,6 +57,8 @@ extern struct lynx_target_ops the_low_target;
 class lynx_process_target : public process_target {
 public:
 
+  int create_inferior (const char *program,
+		       const std::vector<char *> &program_args) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 6f12a735c12..e5df5b3e9db 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -350,9 +350,9 @@ nto_read_auxv_from_initial_stack (CORE_ADDR initial_stack,
 /* Start inferior specified by PROGRAM, using PROGRAM_ARGS as its
    arguments.  */
 
-static int
-nto_create_inferior (const char *program,
-		     const std::vector<char *> &program_args)
+int
+nto_process_target::create_inferior (
+    const char *program, const std::vector<char *> &program_args)
 {
   struct inheritance inherit;
   pid_t pid;
@@ -935,7 +935,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_create_inferior,
   NULL,  /* post_create_inferior */
   nto_attach,
   nto_kill,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index 398382113b6..cc028d7e07d 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -47,6 +47,8 @@ extern struct nto_target_ops the_low_target;
 class nto_process_target : public process_target {
 public:
 
+  int create_inferior (const char *program,
+		       const std::vector<char *> &program_args) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/server.c b/gdbserver/server.c
index 3fc026f78eb..73f8e185477 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -3028,7 +3028,7 @@ handle_v_run (char *own_buf)
   free_vector_argv (program_args);
   program_args = new_argv;
 
-  create_inferior (program_path.get (), program_args);
+  target_create_inferior (program_path.get (), program_args);
 
   if (cs.last_status.kind == TARGET_WAITKIND_STOPPED)
     {
@@ -3784,7 +3784,7 @@ captured_main (int argc, char *argv[])
       program_args.push_back (NULL);
 
       /* Wait till we are at first instruction in program.  */
-      create_inferior (program_path.get (), program_args);
+      target_create_inferior (program_path.get (), program_args);
 
       /* We are now (hopefully) stopped at the first instruction of
 	 the target process.  This assumes that the target process was
@@ -4303,7 +4303,7 @@ process_serial_event (void)
 	  /* Wait till we are at 1st instruction in prog.  */
 	  if (program_path.get () != NULL)
 	    {
-	      create_inferior (program_path.get (), program_args);
+	      target_create_inferior (program_path.get (), program_args);
 
 	      if (cs.last_status.kind == TARGET_WAITKIND_STOPPED)
 		{
diff --git a/gdbserver/target.h b/gdbserver/target.h
index af3995425a3..7caf096b111 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,17 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Start a new process.
-
-     PROGRAM is a path to the program to execute.
-     PROGRAM_ARGS is a standard NULL-terminated array of arguments,
-     to be passed to the inferior as ``argv'' (along with PROGRAM).
-
-     Returns the new PID on success, -1 on failure.  Registers the new
-     process with the process list.  */
-  int (*create_inferior) (const char *program,
-			  const std::vector<char *> &program_args);
-
   /* Do additional setup after a new process is created, including
      exec-wrapper completion.  */
   void (*post_create_inferior) (void);
@@ -488,14 +477,25 @@ class process_target {
 public:
 
   virtual ~process_target () = default;
+
+  /* Start a new process.
+
+     PROGRAM is a path to the program to execute.
+     PROGRAM_ARGS is a standard NULL-terminated array of arguments,
+     to be passed to the inferior as ``argv'' (along with PROGRAM).
+
+     Returns the new PID on success, -1 on failure.  Registers the new
+     process with the process list.  */
+  virtual int create_inferior
+      (const char *program, const std::vector<char *> &program_args) = 0;
 };
 
 extern process_stratum_target *the_target;
 
 void set_target_ops (process_stratum_target *);
 
-#define create_inferior(program, program_args)	\
-  (*the_target->create_inferior) (program, program_args)
+#define target_create_inferior(program, program_args)	\
+  the_target->pt->create_inferior (program, program_args)
 
 #define target_post_create_inferior()			 \
   do							 \
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index b0b54a10669..2e1028b9a8d 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -625,9 +625,9 @@ Could not convert the expanded inferior cwd to wide-char."));
    PROGRAM_ARGS is the vector containing the inferior's args.
    Returns the new PID on success, -1 on failure.  Registers the new
    process with the process list.  */
-static int
-win32_create_inferior (const char *program,
-		       const std::vector<char *> &program_args)
+int
+win32_process_target::create_inferior (
+    const char *program, const std::vector<char *> &program_args)
 {
   client_state &cs = get_client_state ();
 #ifndef USE_WIN32API
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_create_inferior,
   NULL,  /* post_create_inferior */
   win32_attach,
   win32_kill,
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index f8cc0b27c7f..661d8a385c1 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -106,6 +106,8 @@ extern struct win32_target_ops the_low_target;
 class win32_process_target : public process_target {
 public:
 
+  int create_inferior (const char *program,
+		       const std::vector<char *> &program_args) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 27/58] gdbserver: turn target op 'qxfer_osdata' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (24 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 45/58] gdbserver: turn target op 'supports_disable_randomization' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 05/58] gdbserver: turn target op 'kill' " Tankut Baris Aktemur
                   ` (33 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's qxfer_osdata op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.  Also add
	'supports_qxfer_osdata'.
	* target.c (process_target::qxfer_osdata): Define.
	(process_target::supports_qxfer_osdata): Define.

	Update the derived structs and callers below.

	* server.c (handle_qxfer_osdata): Update.
	(handle_query): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::supports_qxfer_osdata): Define.
	(linux_qxfer_osdata): Turn into ...
	(linux_process_target::qxfer_osdata): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 16 +++++++++++-----
 gdbserver/linux-low.h |  6 ++++++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/server.c    |  6 +++---
 gdbserver/target.c    | 14 ++++++++++++++
 gdbserver/target.h    | 13 ++++++++-----
 gdbserver/win32-low.c |  1 -
 8 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index d8209527f0e..595b4282ce2 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6134,10 +6134,17 @@ linux_process_target::get_tls_address (thread_info *thread,
 #endif
 }
 
-static int
-linux_qxfer_osdata (const char *annex,
-		    unsigned char *readbuf, unsigned const char *writebuf,
-		    CORE_ADDR offset, int len)
+bool
+linux_process_target::supports_qxfer_osdata ()
+{
+  return true;
+}
+
+int
+linux_process_target::qxfer_osdata (const char *annex,
+				    unsigned char *readbuf,
+				    unsigned const char *writebuf,
+				    CORE_ADDR offset, int len)
 {
   return linux_common_xfer_osdata (annex, readbuf, offset, len);
 }
@@ -7403,7 +7410,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_qxfer_osdata,
   linux_xfer_siginfo,
   linux_supports_non_stop,
   linux_async,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index be6310da723..5d1164ee944 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -348,6 +348,12 @@ public:
 
   int get_tls_address (thread_info *thread, CORE_ADDR offset,
 		       CORE_ADDR load_module, CORE_ADDR *address) override;
+
+  bool supports_qxfer_osdata () override;
+
+  int qxfer_osdata (const char *annex, unsigned char *readbuf,
+		    unsigned const char *writebuf,
+		    CORE_ADDR offset, int len) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 493c48ef355..f9a6b6891dc 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* qxfer_osdata */
   NULL,  /* qxfer_siginfo */
   NULL,  /* supports_non_stop */
   NULL,  /* async */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index e5f7af2b66e..002b655d407 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -956,7 +956,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* nto_qxfer_osdata */
   NULL, /* xfer_siginfo */
   nto_supports_non_stop,
   NULL, /* async */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index 01d41af0f89..59eb1c0c3d7 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -1587,10 +1587,10 @@ handle_qxfer_osdata (const char *annex,
 		     gdb_byte *readbuf, const gdb_byte *writebuf,
 		     ULONGEST offset, LONGEST len)
 {
-  if (the_target->qxfer_osdata == NULL || writebuf != NULL)
+  if (!the_target->pt->supports_qxfer_osdata () || writebuf != NULL)
     return -2;
 
-  return (*the_target->qxfer_osdata) (annex, readbuf, NULL, offset, len);
+  return the_target->pt->qxfer_osdata (annex, readbuf, NULL, offset, len);
 }
 
 /* Handle qXfer:siginfo:read and qXfer:siginfo:write.  */
@@ -2392,7 +2392,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (cs.transport_is_reliable)
 	strcat (own_buf, ";QStartNoAckMode+");
 
-      if (the_target->qxfer_osdata != NULL)
+      if (the_target->pt->supports_qxfer_osdata ())
 	strcat (own_buf, ";qXfer:osdata:read+");
 
       if (target_supports_multi_process ())
diff --git a/gdbserver/target.c b/gdbserver/target.c
index e09ee7d0fa4..c6ed544e669 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -513,3 +513,17 @@ process_target::hostio_last_error (char *buf)
 {
   hostio_last_error_from_errno (buf);
 }
+
+bool
+process_target::supports_qxfer_osdata ()
+{
+  return false;
+}
+
+int
+process_target::qxfer_osdata (const char *annex, unsigned char *readbuf,
+			      unsigned const char *writebuf,
+			      CORE_ADDR offset, int len)
+{
+  gdb_assert_not_reached ("target op qxfer_osdata not supported");
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index b3ceaa34ad0..ecc32e16f87 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,11 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Read/Write OS data using qXfer packets.  */
-  int (*qxfer_osdata) (const char *annex, unsigned char *readbuf,
-		       unsigned const char *writebuf, CORE_ADDR offset,
-		       int len);
-
   /* Read/Write extra signal info.  */
   int (*qxfer_siginfo) (const char *annex, unsigned char *readbuf,
 			unsigned const char *writebuf,
@@ -479,6 +474,14 @@ public:
   /* Fill BUF with an hostio error packet representing the last hostio
      error.  */
   virtual void hostio_last_error (char *buf);
+
+  /* Return true if the qxfer_osdata target op is supported.  */
+  virtual bool supports_qxfer_osdata ();
+
+  /* Read/Write OS data using qXfer packets.  */
+  virtual int qxfer_osdata (const char *annex, unsigned char *readbuf,
+			    unsigned const char *writebuf,
+			    CORE_ADDR offset, int len);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index dc75221d361..749460ea1aa 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1834,7 +1834,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* qxfer_osdata */
   win32_xfer_siginfo,
   NULL, /* supports_non_stop */
   NULL, /* async */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 18/58] gdbserver: turn target op 'supports_z_point_type' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (29 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 13/58] gdbserver: turn prepare_to_access_memory & done_accessing_memory into methods Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 11/58] gdbserver: turn target op 'wait' " Tankut Baris Aktemur
                   ` (28 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's supports_z_point_type op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	* target.c (process_target::supports_z_point_type): Define.

	Update the derived structs and callers below.

	* mem-break.c (z_type_supported): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_supports_z_point_type): Turn into ...
	(linux_process_target::supports_z_point_type): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_supports_z_point_type): Turn into ...
	(nto_process_target::supports_z_point_type): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_supports_z_point_type): Turn into ...
	(win32_process_target::supports_z_point_type): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c |  5 ++---
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/mem-break.c |  3 +--
 gdbserver/nto-low.c   |  9 ++++-----
 gdbserver/nto-low.h   |  2 ++
 gdbserver/target.c    |  6 ++++++
 gdbserver/target.h    | 20 ++++++++++----------
 gdbserver/win32-low.c |  5 ++---
 gdbserver/win32-low.h |  2 ++
 10 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 1bbd215d775..da03b8c3b03 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -5957,8 +5957,8 @@ linux_process_target::read_auxv (CORE_ADDR offset, unsigned char *myaddr,
    pass on the function call if the target has registered a
    corresponding function.  */
 
-static int
-linux_supports_z_point_type (char z_type)
+bool
+linux_process_target::supports_z_point_type (char z_type)
 {
   return (the_low_target.supports_z_point_type != NULL
 	  && the_low_target.supports_z_point_type (z_type));
@@ -7376,7 +7376,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_supports_z_point_type,
   linux_insert_point,
   linux_remove_point,
   linux_stopped_by_sw_breakpoint,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index eccd65c795e..c51027bb0dc 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -313,6 +313,8 @@ public:
 
   int read_auxv (CORE_ADDR offset, unsigned char *myaddr,
 		 unsigned int len) override;
+
+  bool supports_z_point_type (char z_type) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 730c66a33a3..4be6e841d44 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -729,7 +729,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* supports_z_point_type */
   NULL,  /* insert_point */
   NULL,  /* remove_point */
   NULL,  /* stopped_by_sw_breakpoint */
diff --git a/gdbserver/mem-break.c b/gdbserver/mem-break.c
index 43a07c390d1..b00e9fca353 100644
--- a/gdbserver/mem-break.c
+++ b/gdbserver/mem-break.c
@@ -1005,8 +1005,7 @@ static int
 z_type_supported (char z_type)
 {
   return (z_type >= '0' && z_type <= '4'
-	  && the_target->supports_z_point_type != NULL
-	  && the_target->supports_z_point_type (z_type));
+	  && the_target->pt->supports_z_point_type (z_type));
 }
 
 /* Create a new GDB breakpoint of type Z_TYPE at ADDR with kind KIND.
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index c5de7540079..132d57bfe79 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -789,8 +789,8 @@ nto_process_target::read_auxv (CORE_ADDR offset, unsigned char *myaddr,
   return nto_read_auxv_from_initial_stack (initial_stack, myaddr, len);
 }
 
-static int
-nto_supports_z_point_type (char z_type)
+bool
+nto_process_target::supports_z_point_type (char z_type)
 {
   switch (z_type)
     {
@@ -799,9 +799,9 @@ nto_supports_z_point_type (char z_type)
     case Z_PACKET_WRITE_WP:
     case Z_PACKET_READ_WP:
     case Z_PACKET_ACCESS_WP:
-      return 1;
+      return true;
     default:
-      return 0;
+      return false;
     }
 }
 
@@ -950,7 +950,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_supports_z_point_type,
   nto_insert_point,
   nto_remove_point,
   NULL, /* stopped_by_sw_breakpoint */
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index f1e9e31478c..d99d5d7acc7 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -83,6 +83,8 @@ public:
 
   int read_auxv (CORE_ADDR offset, unsigned char *myaddr,
 		 unsigned int len) override;
+
+  bool supports_z_point_type (char z_type) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 97e9d4ac507..22339622e09 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -427,3 +427,9 @@ process_target::read_auxv (CORE_ADDR offset, unsigned char *myaddr,
 {
   gdb_assert_not_reached ("target op read_auxv not supported");
 }
+
+bool
+process_target::supports_z_point_type (char z_type)
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 0d3e16c6ed5..383a848fcb9 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,16 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Returns true if GDB Z breakpoint type TYPE is supported, false
-     otherwise.  The type is coded as follows:
-       '0' - software-breakpoint
-       '1' - hardware-breakpoint
-       '2' - write watchpoint
-       '3' - read watchpoint
-       '4' - access watchpoint
-  */
-  int (*supports_z_point_type) (char z_type);
-
   /* Insert and remove a break or watchpoint.
      Returns 0 on success, -1 on failure and 1 on unsupported.  */
 
@@ -476,6 +466,16 @@ public:
      Read LEN bytes at OFFSET into a buffer at MYADDR.  */
   virtual int read_auxv (CORE_ADDR offset, unsigned char *myaddr,
 			 unsigned int len);
+
+  /* Returns true if GDB Z breakpoint type TYPE is supported, false
+     otherwise.  The type is coded as follows:
+       '0' - software-breakpoint
+       '1' - hardware-breakpoint
+       '2' - write watchpoint
+       '3' - read watchpoint
+       '4' - access watchpoint
+  */
+  virtual bool supports_z_point_type (char z_type);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 18e977993dc..74b70659465 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -255,8 +255,8 @@ child_delete_thread (DWORD pid, DWORD tid)
 /* These watchpoint related wrapper functions simply pass on the function call
    if the low target has registered a corresponding function.  */
 
-static int
-win32_supports_z_point_type (char z_type)
+bool
+win32_process_target::supports_z_point_type (char z_type)
 {
   return (the_low_target.supports_z_point_type != NULL
 	  && the_low_target.supports_z_point_type (z_type));
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_supports_z_point_type,
   win32_insert_point,
   win32_remove_point,
   NULL, /* stopped_by_sw_breakpoint */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 078ae7255f3..f40dfb48822 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -137,6 +137,8 @@ public:
 		    int len) override;
 
   void request_interrupt () override;
+
+  bool supports_z_point_type (char z_type) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 04/58] gdbserver: turn target op 'attach' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 22/58] gdbserver: turn target op 'supports_hardware_single_step' " Tankut Baris Aktemur
                   ` (58 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's attach op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(myattach): Update the macro.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_attach): Turn into ...
	(linux_process_target::attach): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_attach): Turn into ...
	(lynx_process_target::attach): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_attach): Turn into ...
	(nto_process_target::attach): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_attach): Turn into ...
	(win32_process_target::attach): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c |  5 ++---
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  5 ++---
 gdbserver/lynx-low.h  |  2 ++
 gdbserver/nto-low.c   |  5 ++---
 gdbserver/nto-low.h   |  2 ++
 gdbserver/target.h    | 21 ++++++++++-----------
 gdbserver/win32-low.c |  5 ++---
 gdbserver/win32-low.h |  2 ++
 9 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 9e4c6758581..8e62ed91a77 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -1181,8 +1181,8 @@ static void async_file_mark (void);
 /* Attach to PID.  If PID is the tgid, attach to it and all
    of its threads.  */
 
-static int
-linux_attach (unsigned long pid)
+int
+linux_process_target::attach (unsigned long pid)
 {
   struct process_info *proc;
   struct thread_info *initial_thread;
@@ -7359,7 +7359,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_attach,
   linux_kill,
   linux_detach,
   linux_mourn,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index fab08a6bb7d..673c5bbc407 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -273,6 +273,8 @@ public:
 		       const std::vector<char *> &program_args) override;
 
   void post_create_inferior () override;
+
+  int attach (unsigned long pid) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index c6880bc7bc2..2e2535e1d61 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -309,8 +309,8 @@ lynx_add_threads_after_attach (int pid)
 
 /* Implement the attach target_ops method.  */
 
-static int
-lynx_attach (unsigned long pid)
+int
+lynx_process_target::attach (unsigned long pid)
 {
   ptid_t ptid = lynx_ptid_t (pid, 0);
 
@@ -726,7 +726,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_attach,
   lynx_kill,
   lynx_detach,
   lynx_mourn,
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index e74d80be5b4..7a3f03fb36e 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -59,6 +59,8 @@ public:
 
   int create_inferior (const char *program,
 		       const std::vector<char *> &program_args) override;
+
+  int attach (unsigned long pid) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index ce37443385d..47be6eeab86 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -385,8 +385,8 @@ nto_process_target::create_inferior (
 
 /* Attach to process PID.  */
 
-static int
-nto_attach (unsigned long pid)
+int
+nto_process_target::attach (unsigned long pid)
 {
   TRACE ("%s %ld\n", __func__, pid);
   if (do_attach (pid) != pid)
@@ -935,7 +935,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_attach,
   nto_kill,
   nto_detach,
   nto_mourn,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index cc028d7e07d..e5d2fa83135 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -49,6 +49,8 @@ public:
 
   int create_inferior (const char *program,
 		       const std::vector<char *> &program_args) override;
+
+  int attach (unsigned long pid) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.h b/gdbserver/target.h
index bede0a8556c..a2bbfed5b07 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,16 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Attach to a running process.
-
-     PID is the process ID to attach to, specified by the user
-     or a higher layer.
-
-     Returns -1 if attaching is unsupported, 0 on success, and calls
-     error() otherwise.  */
-
-  int (*attach) (unsigned long pid);
-
   /* Kill process PROC.  Return -1 on failure, and 0 on success.  */
 
   int (*kill) (process_info *proc);
@@ -488,6 +478,15 @@ public:
   /* Do additional setup after a new process is created, including
      exec-wrapper completion.  */
   virtual void post_create_inferior ();
+
+  /* Attach to a running process.
+
+     PID is the process ID to attach to, specified by the user
+     or a higher layer.
+
+     Returns -1 if attaching is unsupported, 0 on success, and calls
+     error() otherwise.  */
+  virtual int attach (unsigned long pid) = 0;
 };
 
 extern process_stratum_target *the_target;
@@ -501,7 +500,7 @@ void set_target_ops (process_stratum_target *);
   the_target->pt->post_create_inferior ()
 
 #define myattach(pid) \
-  (*the_target->attach) (pid)
+  the_target->pt->attach (pid)
 
 int kill_inferior (process_info *proc);
 
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index e8d4347a4b9..1acab18d09f 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -715,8 +715,8 @@ win32_process_target::create_inferior (
 /* Attach to a running process.
    PID is the process ID to attach to, specified by the user
    or a higher layer.  */
-static int
-win32_attach (unsigned long pid)
+int
+win32_process_target::attach (unsigned long pid)
 {
   HANDLE h;
   winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_attach,
   win32_kill,
   win32_detach,
   win32_mourn,
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 661d8a385c1..f626db6cf60 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -108,6 +108,8 @@ public:
 
   int create_inferior (const char *program,
 		       const std::vector<char *> &program_args) override;
+
+  int attach (unsigned long pid) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 20/58] gdbserver: turn target op '{supports_}stopped_by_sw_breakpoint' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (6 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 12/58] gdbserver: turn target ops 'fetch_registers' and 'store_registers' into methods Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 07/58] gdbserver: turn target op 'mourn' " Tankut Baris Aktemur
                   ` (51 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's {supports_}stopped_by_sw_breakpoint
	ops methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	(target_stopped_by_sw_breakpoint): Update the macro.
	(target_supports_stopped_by_sw_breakpoint): Update the macro.
	* target.c (process_target::stopped_by_sw_breakpoint): Define.
	(process_target::supports_stopped_by_sw_breakpoint): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_stopped_by_sw_breakpoint): Turn into ...
	(linux_process_target::stopped_by_sw_breakpoint): ... this.
	(linux_supports_stopped_by_sw_breakpoint): Turn into ...
	(linux_process_target::supports_stopped_by_sw_breakpoint): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 14 ++++++--------
 gdbserver/linux-low.h |  4 ++++
 gdbserver/lynx-low.c  |  2 --
 gdbserver/nto-low.c   |  2 --
 gdbserver/target.c    | 12 ++++++++++++
 gdbserver/target.h    | 22 ++++++++++------------
 gdbserver/win32-low.c |  2 --
 7 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 9427b9bdeb9..636a4933841 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -5990,22 +5990,22 @@ linux_process_target::remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
     return 1;
 }
 
-/* Implement the to_stopped_by_sw_breakpoint target_ops
+/* Implement the stopped_by_sw_breakpoint target_ops
    method.  */
 
-static int
-linux_stopped_by_sw_breakpoint (void)
+bool
+linux_process_target::stopped_by_sw_breakpoint ()
 {
   struct lwp_info *lwp = get_thread_lwp (current_thread);
 
   return (lwp->stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT);
 }
 
-/* Implement the to_supports_stopped_by_sw_breakpoint target_ops
+/* Implement the supports_stopped_by_sw_breakpoint target_ops
    method.  */
 
-static int
-linux_supports_stopped_by_sw_breakpoint (void)
+bool
+linux_process_target::supports_stopped_by_sw_breakpoint ()
 {
   return USE_SIGTRAP_SIGINFO;
 }
@@ -7376,8 +7376,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_stopped_by_sw_breakpoint,
-  linux_supports_stopped_by_sw_breakpoint,
   linux_stopped_by_hw_breakpoint,
   linux_supports_stopped_by_hw_breakpoint,
   linux_supports_hardware_single_step,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 0887c932d6c..4ef1a3f4cf9 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -321,6 +321,10 @@ public:
 
   int remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
 		    int size, raw_breakpoint *bp) override;
+
+  bool stopped_by_sw_breakpoint () override;
+
+  bool supports_stopped_by_sw_breakpoint () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 60748ae03db..91ff7a1dd0b 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -729,8 +729,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* stopped_by_sw_breakpoint */
-  NULL,  /* supports_stopped_by_sw_breakpoint */
   NULL,  /* stopped_by_hw_breakpoint */
   NULL,  /* supports_stopped_by_hw_breakpoint */
   target_can_do_hardware_single_step,
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index c554d91ceea..8a412868829 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -950,8 +950,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* stopped_by_sw_breakpoint */
-  NULL, /* supports_stopped_by_sw_breakpoint */
   NULL, /* stopped_by_hw_breakpoint */
   NULL, /* supports_stopped_by_hw_breakpoint */
   target_can_do_hardware_single_step,
diff --git a/gdbserver/target.c b/gdbserver/target.c
index fd443efd61e..70630db6d84 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -447,3 +447,15 @@ process_target::remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
 {
   return 1;
 }
+
+bool
+process_target::stopped_by_sw_breakpoint ()
+{
+  return false;
+}
+
+bool
+process_target::supports_stopped_by_sw_breakpoint ()
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 966741f21ed..3be0ff9cdb8 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,14 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Returns 1 if the target stopped because it executed a software
-     breakpoint instruction, 0 otherwise.  */
-  int (*stopped_by_sw_breakpoint) (void);
-
-  /* Returns true if the target knows whether a trap was caused by a
-     SW breakpoint triggering.  */
-  int (*supports_stopped_by_sw_breakpoint) (void);
-
   /* Returns 1 if the target stopped for a hardware breakpoint.  */
   int (*stopped_by_hw_breakpoint) (void);
 
@@ -476,6 +468,14 @@ public:
 
   virtual int remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
 			    int size, raw_breakpoint *bp);
+
+  /* Returns true if the target stopped because it executed a software
+     breakpoint instruction, false otherwise.  */
+  virtual bool stopped_by_sw_breakpoint ();
+
+  /* Returns true if the target knows whether a trap was caused by a
+     SW breakpoint triggering.  */
+  virtual bool supports_stopped_by_sw_breakpoint ();
 };
 
 extern process_stratum_target *the_target;
@@ -659,12 +659,10 @@ target_read_btrace_conf (struct btrace_target_info *tinfo,
    (*the_target->supports_range_stepping) () : 0)
 
 #define target_supports_stopped_by_sw_breakpoint() \
-  (the_target->supports_stopped_by_sw_breakpoint ? \
-   (*the_target->supports_stopped_by_sw_breakpoint) () : 0)
+  the_target->pt->supports_stopped_by_sw_breakpoint ()
 
 #define target_stopped_by_sw_breakpoint() \
-  (the_target->stopped_by_sw_breakpoint ? \
-   (*the_target->stopped_by_sw_breakpoint) () : 0)
+  the_target->pt->stopped_by_sw_breakpoint ()
 
 #define target_supports_stopped_by_hw_breakpoint() \
   (the_target->supports_stopped_by_hw_breakpoint ? \
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 9f705507e96..31be06c0af2 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1828,8 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* stopped_by_sw_breakpoint */
-  NULL, /* supports_stopped_by_sw_breakpoint */
   NULL, /* stopped_by_hw_breakpoint */
   NULL, /* supports_stopped_by_hw_breakpoint */
   target_can_do_hardware_single_step,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 33/58] gdbserver: turn target op 'handle_monitor_command' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (8 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 07/58] gdbserver: turn target op 'mourn' " Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 24/58] gdbserver: turn target op 'read_offsets' " Tankut Baris Aktemur
                   ` (49 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's handle_monitor_command op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_handle_monitor_command): Update the macro.
	* target.c (process_target::handle_monitor_command): Define.

	Update the derived structs and callers below.

	* server.c (handle_query): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::handle_monitor_command): Define.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 15 ++++++++++-----
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/server.c    |  3 +--
 gdbserver/target.c    |  6 ++++++
 gdbserver/target.h    |  8 ++++----
 gdbserver/win32-low.c |  1 -
 8 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 4ec396af289..ef68a8a89e2 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6387,6 +6387,16 @@ linux_process_target::handle_new_gdb_connection ()
     });
 }
 
+int
+linux_process_target::handle_monitor_command (char *mon)
+{
+#ifdef USE_THREAD_DB
+  return thread_db_handle_monitor_command (mon);
+#else
+  return 0;
+#endif
+}
+
 static int
 linux_supports_disable_randomization (void)
 {
@@ -7418,11 +7428,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-#ifdef USE_THREAD_DB
-  thread_db_handle_monitor_command,
-#else
-  NULL,
-#endif
   linux_common_core_of_thread,
   linux_read_loadmap,
   linux_process_qsupported,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 0881155cc5e..c37db38749b 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -376,6 +376,8 @@ public:
   bool supports_exec_events () override;
 
   void handle_new_gdb_connection () override;
+
+  int handle_monitor_command (char *mon) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 7bfd71c5321..5db9d2f154d 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* handle_monitor_command */
   NULL,  /* core_of_thread */
   NULL,  /* read_loadmap */
   NULL,  /* process_qsupported */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 8ff8063dfba..880e8ccecd1 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* handle_monitor_command */
   NULL, /* core_of_thread */
   NULL, /* read_loadmap */
   NULL, /* process_qsupported */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index f427e7706fb..f9817881d77 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -2577,8 +2577,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 
       write_ok (own_buf);
 
-      if (the_target->handle_monitor_command == NULL
-	  || (*the_target->handle_monitor_command) (mon) == 0)
+      if (the_target->pt->handle_monitor_command (mon) == 0)
 	/* Default processing.  */
 	handle_monitor_command (mon, own_buf);
 
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 3416a3f449f..74cd90a48a4 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -577,3 +577,9 @@ process_target::handle_new_gdb_connection ()
 {
   /* Nop.  */
 }
+
+int
+process_target::handle_monitor_command (char *mon)
+{
+  return 0;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 1138ed2e440..7d7e371cf32 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* If not NULL, target-specific routine to process monitor command.
-     Returns 1 if handled, or 0 to perform default processing.  */
-  int (*handle_monitor_command) (char *);
-
   /* Returns the core given a thread, or -1 if not known.  */
   int (*core_of_thread) (ptid_t);
 
@@ -486,6 +482,10 @@ public:
 
   /* Allows target to re-initialize connection-specific settings.  */
   virtual void handle_new_gdb_connection ();
+
+  /* The target-specific routine to process monitor command.
+     Returns 1 if handled, or 0 to perform default processing.  */
+  virtual int handle_monitor_command (char *mon);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index bee5cbbf643..ed847447e40 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1842,7 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* handle_monitor_command */
   NULL, /* core_of_thread */
   NULL, /* read_loadmap */
   NULL, /* process_qsupported */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 40/58] gdbserver: turn target op 'get_tib_address' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (20 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 01/58] gdbserver: start turning the target ops vector into a class Tankut Baris Aktemur
@ 2020-02-11  9:03 ` Tankut Baris Aktemur
  2020-02-11  9:03 ` [PATCH 36/58] gdbserver: turn target op 'process_qsupported' " Tankut Baris Aktemur
                   ` (37 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:03 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's get_tib_address op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.  Also add
	'supports_get_tib_address'.
	* target.c (process_target::get_tib_address): Define.
	(process_target::supports_get_tib_address): Define.

	Update the derived structs and callers below.

	* server.c (handle_query): Update.
	* linux-low.c (win32_target_ops): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_process_target::supports_get_tib_address): Define.
	(win32_get_tib_address): Turn into ...
	(win32_process_target::get_tib_address): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c |  1 -
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/server.c    |  4 ++--
 gdbserver/target.c    | 12 ++++++++++++
 gdbserver/target.h    |  9 ++++++---
 gdbserver/win32-low.c | 11 ++++++++---
 gdbserver/win32-low.h |  4 ++++
 8 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index dc7b70b5e59..a75c7ade312 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -7444,7 +7444,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  NULL,
   linux_pause_all,
   linux_unpause_all,
   linux_stabilize_threads,
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 2842036d7ca..5553e87a137 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* get_tib_address */
   NULL,  /* pause_all */
   NULL,  /* unpause_all */
   NULL,  /* stabilize_threads */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index ce25e335e3b..877e264e1dc 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* get_tib_address */
   NULL, /* pause_all */
   NULL, /* unpause_all */
   NULL, /* stabilize_threads */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index f3dca8d3ce0..77155935fab 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -2532,7 +2532,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
     }
 
   /* Windows OS Thread Information Block address support.  */
-  if (the_target->get_tib_address != NULL
+  if (the_target->pt->supports_get_tib_address ()
       && startswith (own_buf, "qGetTIBAddr:"))
     {
       const char *annex;
@@ -2540,7 +2540,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       CORE_ADDR tlb;
       ptid_t ptid = read_ptid (own_buf + 12, &annex);
 
-      n = (*the_target->get_tib_address) (ptid, &tlb);
+      n = the_target->pt->get_tib_address (ptid, &tlb);
       if (n == 1)
 	{
 	  strcpy (own_buf, paddress(tlb));
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 34805ef5b88..f1cdfc0446d 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -638,3 +638,15 @@ process_target::thread_stopped (thread_info *thread)
 {
   gdb_assert_not_reached ("target op thread_stopped not supported");
 }
+
+bool
+process_target::supports_get_tib_address ()
+{
+  return false;
+}
+
+int
+process_target::get_tib_address (ptid_t ptid, CORE_ADDR *address)
+{
+  gdb_assert_not_reached ("target op get_tib_address not supported");
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 554bfe09af1..aba4bbfab96 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Read Thread Information Block address.  */
-  int (*get_tib_address) (ptid_t ptid, CORE_ADDR *address);
-
   /* Pause all threads.  If FREEZE, arrange for any resume attempt to
      be ignored until an unpause_all call unfreezes threads again.
      There can be nested calls to pause_all, so a freeze counter
@@ -491,6 +488,12 @@ public:
 
   /* Return true if THREAD is known to be stopped now.  */
   virtual bool thread_stopped (thread_info *thread);
+
+  /* Return true if the get_tib_address op is supported.  */
+  virtual bool supports_get_tib_address ();
+
+  /* Read Thread Information Block address.  */
+  virtual int get_tib_address (ptid_t ptid, CORE_ADDR *address);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 5e9a05ac97c..781ca7557a9 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1814,10 +1814,16 @@ win32_process_target::qxfer_siginfo (const char *annex,
   return len;
 }
 
+bool
+win32_process_target::supports_get_tib_address ()
+{
+  return true;
+}
+
 /* Write Windows OS Thread Information Block address.  */
 
-static int
-win32_get_tib_address (ptid_t ptid, CORE_ADDR *addr)
+int
+win32_process_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
 {
   win32_thread_info *th;
   th = thread_rec (ptid, 0);
@@ -1842,7 +1848,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_get_tib_address,
   NULL, /* pause_all */
   NULL, /* unpause_all */
   NULL, /* stabilize_threads */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 105c1443968..fcd50e2a45b 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -161,6 +161,10 @@ public:
   int qxfer_siginfo (const char *annex, unsigned char *readbuf,
 		     unsigned const char *writebuf,
 		     CORE_ADDR offset, int len) override;
+
+  bool supports_get_tib_address () override;
+
+  int get_tib_address (ptid_t ptid, CORE_ADDR *addr) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 42/58] gdbserver: turn target op 'stabilize_threads' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (40 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 17/58] gdbserver: turn target op 'read_auxv' " Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 53/58] gdbserver: turn target ops 'thread_name' and 'thread_handle' into methods Tankut Baris Aktemur
                   ` (17 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's stabilize_threads op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_stabilize_threads): Update the macro.
	* target.c (process_target::stabilize_threads): Define.

	Update the derived structs and callers below.

	* server.c (handle_status): Update.
	* tracepoint.c (cmd_qtdp): Update.
	(cmd_qtstart): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_stabilize_threads): Turn into ...
	(linux_process_target::stabilize_threads): ... this.
	(linux_wait_1): Update.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c  |  9 ++++-----
 gdbserver/linux-low.h  |  2 ++
 gdbserver/lynx-low.c   |  1 -
 gdbserver/nto-low.c    |  1 -
 gdbserver/server.c     |  2 +-
 gdbserver/target.c     |  6 ++++++
 gdbserver/target.h     | 14 +++++---------
 gdbserver/tracepoint.c |  4 ++--
 gdbserver/win32-low.c  |  1 -
 9 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 696eec432fc..6b6412f0808 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -1620,7 +1620,7 @@ linux_process_target::detach (process_info *process)
 #endif
 
   /* Stabilize threads (move out of jump pads).  */
-  stabilize_threads ();
+  target_stabilize_threads ();
 
   /* Detach from the clone lwps first.  If the thread group exits just
      while we're detaching, we must reap the clone lwps before we're
@@ -2926,8 +2926,8 @@ static ptid_t linux_wait_1 (ptid_t ptid,
    since for something else in the new run, the thread would now
    execute the wrong / random instructions.  */
 
-static void
-linux_stabilize_threads (void)
+void
+linux_process_target::stabilize_threads ()
 {
   thread_info *thread_stuck = find_thread (stuck_in_jump_pad_callback);
 
@@ -3713,7 +3713,7 @@ linux_wait_1 (ptid_t ptid,
 
       /* Stabilize threads (move out of jump pads).  */
       if (!non_stop)
-	stabilize_threads ();
+	target_stabilize_threads ();
     }
   else
     {
@@ -7444,7 +7444,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_stabilize_threads,
   linux_install_fast_tracepoint_jump_pad,
   linux_emit_ops,
   linux_supports_disable_randomization,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index f219a90528b..91395038724 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -403,6 +403,8 @@ public:
   void pause_all (bool freeze) override;
 
   void unpause_all (bool unfreeze) override;
+
+  void stabilize_threads () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 1b4b3b74d7a..742c2a85543 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* stabilize_threads */
   NULL,  /* install_fast_tracepoint_jump_pad */
   NULL,  /* emit_ops */
   NULL,  /* supports_disable_randomization */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 3c4ba5dcc28..2e1039a83ea 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* stabilize_threads */
   NULL, /* install_fast_tracepoint_jump_pad */
   NULL, /* emit_ops */
   NULL, /* supports_disable_randomization */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index 670c0fed968..448089fd47c 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -3324,7 +3324,7 @@ handle_status (char *own_buf)
       thread_info *thread = NULL;
 
       target_pause_all (false);
-      stabilize_threads ();
+      target_stabilize_threads ();
       gdb_wants_all_threads_stopped ();
 
       /* We can only report one status, but we might be coming out of
diff --git a/gdbserver/target.c b/gdbserver/target.c
index aea66038e1f..d4c0884fd7c 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -662,3 +662,9 @@ process_target::unpause_all (bool unfreeze)
 {
   /* Nop.  */
 }
+
+void
+process_target::stabilize_threads ()
+{
+  /* Nop.  */
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 183a35a593e..f1a59d8f09f 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Stabilize all threads.  That is, force them out of jump pads.  */
-  void (*stabilize_threads) (void);
-
   /* Install a fast tracepoint jump pad.  TPOINT is the address of the
      tracepoint internal object as used by the IPA agent.  TPADDR is
      the address of tracepoint.  COLLECTOR is address of the function
@@ -494,6 +491,9 @@ public:
      pair should not end up resuming threads that were stopped before
      the pause call.  */
   virtual void unpause_all (bool unfreeze);
+
+  /* Stabilize all threads.  That is, force them out of jump pads.  */
+  virtual void stabilize_threads ();
 };
 
 extern process_stratum_target *the_target;
@@ -574,12 +574,8 @@ int kill_inferior (process_info *proc);
 #define target_unpause_all(unfreeze)		\
   the_target->pt->unpause_all (unfreeze)
 
-#define stabilize_threads()			\
-  do						\
-    {						\
-      if (the_target->stabilize_threads)     	\
-	(*the_target->stabilize_threads) ();  	\
-    } while (0)
+#define target_stabilize_threads()		\
+  the_target->pt->stabilize_threads ()
 
 #define install_fast_tracepoint_jump_pad(tpoint, tpaddr,		\
 					 collector, lockaddr,		\
diff --git a/gdbserver/tracepoint.c b/gdbserver/tracepoint.c
index ffa819cf24e..be40c9b4cf1 100644
--- a/gdbserver/tracepoint.c
+++ b/gdbserver/tracepoint.c
@@ -2606,7 +2606,7 @@ cmd_qtdp (char *own_buf)
 
       /* download_tracepoint will update global `tracepoints'
 	 list, so it is unsafe to leave threads in jump pad.  */
-      stabilize_threads ();
+      target_stabilize_threads ();
 
       /* Freeze threads.  */
       target_pause_all (true);
@@ -3226,7 +3226,7 @@ cmd_qtstart (char *packet)
      top level command.  And, required to do here, since we're
      deleting/rewriting jump pads.  */
 
-  stabilize_threads ();
+  target_stabilize_threads ();
 
   /* Freeze threads.  */
   target_pause_all (true);
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 4cfdeae88f4..693e0de4a3c 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,7 +1848,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* stabilize_threads */
   NULL, /* install_fast_tracepoint_jump_pad */
   NULL, /* emit_ops */
   NULL, /* supports_disable_randomization */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 17/58] gdbserver: turn target op 'read_auxv' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (39 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 54/58] gdbserver: turn target op 'supports_software_single_step' " Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 42/58] gdbserver: turn target op 'stabilize_threads' " Tankut Baris Aktemur
                   ` (18 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's read_auxv op a method of
	process_target.

	* target.h (class process_stratum_target): Remove the target op.
	(struct process_target): Add the target op.  Also add
	'supports_read_auxv'.
	* target.c (process_target::read_auxv): Define.
	(process_target::supports_read_auxv): Define.

	Update the derived classs and callers below.

	* server.c (handle_qxfer_auxv): Update.
	(handle_query): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::supports_read_auxv): Define.
	(linux_read_auxv): Turn into ...
	(linux_process_target::read_auxv): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_process_target::supports_read_auxv): Define.
	(nto_read_auxv): Turn into ...
	(nto_process_target::read_auxv): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 14 ++++++++++----
 gdbserver/linux-low.h |  5 +++++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   | 12 +++++++++---
 gdbserver/nto-low.h   |  5 +++++
 gdbserver/server.c    |  6 +++---
 gdbserver/target.c    | 13 +++++++++++++
 gdbserver/target.h    | 16 +++++++++-------
 gdbserver/win32-low.c |  1 -
 9 files changed, 54 insertions(+), 19 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index cf5192fef61..1bbd215d775 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -5919,11 +5919,18 @@ linux_process_target::request_interrupt ()
   ::kill (-signal_pid, SIGINT);
 }
 
+bool
+linux_process_target::supports_read_auxv ()
+{
+  return true;
+}
+
 /* Copy LEN bytes from inferior's auxiliary vector starting at OFFSET
    to debugger memory starting at MYADDR.  */
 
-static int
-linux_read_auxv (CORE_ADDR offset, unsigned char *myaddr, unsigned int len)
+int
+linux_process_target::read_auxv (CORE_ADDR offset, unsigned char *myaddr,
+				 unsigned int len)
 {
   char filename[PATH_MAX];
   int fd, n;
@@ -7317,7 +7324,7 @@ linux_get_auxv (int wordsize, CORE_ADDR match, CORE_ADDR *valp)
 
   gdb_assert (wordsize == 4 || wordsize == 8);
 
-  while ((*the_target->read_auxv) (offset, data, 2 * wordsize) == 2 * wordsize)
+  while (the_target->pt->read_auxv (offset, data, 2 * wordsize) == 2 * wordsize)
     {
       if (wordsize == 4)
 	{
@@ -7369,7 +7376,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_read_auxv,
   linux_supports_z_point_type,
   linux_insert_point,
   linux_remove_point,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 9340c78cdd0..eccd65c795e 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -308,6 +308,11 @@ public:
   void look_up_symbols () override;
 
   void request_interrupt () override;
+
+  bool supports_read_auxv () override;
+
+  int read_auxv (CORE_ADDR offset, unsigned char *myaddr,
+		 unsigned int len) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 0687aacfe61..730c66a33a3 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -729,7 +729,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* read_auxv */
   NULL,  /* supports_z_point_type */
   NULL,  /* insert_point */
   NULL,  /* remove_point */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index f7b08b4524f..c5de7540079 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -755,14 +755,21 @@ nto_process_target::request_interrupt ()
     TRACE ("Error stopping inferior.\n");
 }
 
+bool
+nto_process_target::supports_read_auxv ()
+{
+  return true;
+}
+
 /* Read auxiliary vector from inferior's memory into gdbserver's buffer
    MYADDR.  We always read whole auxv.  
    
    Return number of bytes stored in MYADDR buffer, 0 if OFFSET > 0
    or -1 on error.  */
 
-static int
-nto_read_auxv (CORE_ADDR offset, unsigned char *myaddr, unsigned int len)
+int
+nto_process_target::read_auxv (CORE_ADDR offset, unsigned char *myaddr,
+			       unsigned int len)
 {
   int err;
   CORE_ADDR initial_stack;
@@ -943,7 +950,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_read_auxv,
   nto_supports_z_point_type,
   nto_insert_point,
   nto_remove_point,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index 1ce518189c6..f1e9e31478c 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -78,6 +78,11 @@ public:
 		    int len) override;
 
   void request_interrupt () override;
+
+  bool supports_read_auxv () override;
+
+  int read_auxv (CORE_ADDR offset, unsigned char *myaddr,
+		 unsigned int len) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/server.c b/gdbserver/server.c
index bc497f87b7f..f13061c871b 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -1442,13 +1442,13 @@ handle_qxfer_auxv (const char *annex,
 		   gdb_byte *readbuf, const gdb_byte *writebuf,
 		   ULONGEST offset, LONGEST len)
 {
-  if (the_target->read_auxv == NULL || writebuf != NULL)
+  if (!the_target->pt->supports_read_auxv () || writebuf != NULL)
     return -2;
 
   if (annex[0] != '\0' || current_thread == NULL)
     return -1;
 
-  return (*the_target->read_auxv) (offset, readbuf, len);
+  return the_target->pt->read_auxv (offset, readbuf, len);
 }
 
 /* Handle qXfer:exec-file:read.  */
@@ -2374,7 +2374,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 	  strcat (own_buf, ";qXfer:libraries:read+");
 	}
 
-      if (the_target->read_auxv != NULL)
+      if (the_target->pt->supports_read_auxv ())
 	strcat (own_buf, ";qXfer:auxv:read+");
 
       if (the_target->qxfer_siginfo != NULL)
diff --git a/gdbserver/target.c b/gdbserver/target.c
index dd9ee8dfd47..97e9d4ac507 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -414,3 +414,16 @@ process_target::look_up_symbols ()
 {
   /* Nop.  */
 }
+
+bool
+process_target::supports_read_auxv ()
+{
+  return false;
+}
+
+int
+process_target::read_auxv (CORE_ADDR offset, unsigned char *myaddr,
+			   unsigned int len)
+{
+  gdb_assert_not_reached ("target op read_auxv not supported");
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 1eb5657045c..0d3e16c6ed5 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,13 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Read auxiliary vector data from the inferior process.
-
-     Read LEN bytes at OFFSET into a buffer at MYADDR.  */
-
-  int (*read_auxv) (CORE_ADDR offset, unsigned char *myaddr,
-		    unsigned int len);
-
   /* Returns true if GDB Z breakpoint type TYPE is supported, false
      otherwise.  The type is coded as follows:
        '0' - software-breakpoint
@@ -474,6 +467,15 @@ public:
   /* Send an interrupt request to the inferior process,
      however is appropriate.  */
   virtual void request_interrupt () = 0;
+
+  /* Return true if the read_auxv target op is supported.  */
+  virtual bool supports_read_auxv ();
+
+  /* Read auxiliary vector data from the inferior process.
+
+     Read LEN bytes at OFFSET into a buffer at MYADDR.  */
+  virtual int read_auxv (CORE_ADDR offset, unsigned char *myaddr,
+			 unsigned int len);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index b2ed7f8b01e..18e977993dc 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* read_auxv */
   win32_supports_z_point_type,
   win32_insert_point,
   win32_remove_point,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 53/58] gdbserver: turn target ops 'thread_name' and 'thread_handle' into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (41 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 42/58] gdbserver: turn target op 'stabilize_threads' " Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 56/58] gdbserver: turn target op 'get_ipa_tdesc_idx' into a method Tankut Baris Aktemur
                   ` (16 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's thread_name and thread_handle ops
	methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	(target_thread_name): Update the macro.
	(target_thread_handle): Update the macro.
	* target.c (process_target::thread_name): Define.
	(process_target::thread_handle): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::thread_name): Define.
	(linux_process_target::thread_handle): Define.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 21 +++++++++++++++------
 gdbserver/linux-low.h |  7 +++++++
 gdbserver/lynx-low.c  |  2 --
 gdbserver/nto-low.c   |  2 --
 gdbserver/target.c    | 13 +++++++++++++
 gdbserver/target.h    | 27 +++++++++++++--------------
 gdbserver/win32-low.c |  2 --
 7 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index de011c126c0..82bb9a680bf 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -7386,6 +7386,21 @@ linux_process_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
     return breakpoint_kind_from_pc (pcptr);
 }
 
+const char *
+linux_process_target::thread_name (ptid_t thread)
+{
+  return linux_proc_tid_get_name (thread);
+}
+
+#if USE_THREAD_DB
+bool
+linux_process_target::thread_handle (ptid_t ptid, gdb_byte **handle,
+				     int *handle_len)
+{
+  return thread_db_thread_handle (ptid, handle, handle_len);
+}
+#endif
+
 /* Default implementation of linux_target_ops method "set_pc" for
    32-bit pc register which is literally named "pc".  */
 
@@ -7498,15 +7513,9 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_proc_tid_get_name,
   linux_supports_software_single_step,
   linux_supports_catch_syscall,
   linux_get_ipa_tdesc_idx,
-#if USE_THREAD_DB
-  thread_db_thread_handle,
-#else
-  NULL,
-#endif
   &the_linux_target,
 };
 
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 6a531ed3aab..e77c54043b8 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -471,6 +471,13 @@ public:
   const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
 
   int breakpoint_kind_from_current_state (CORE_ADDR *pcptr) override;
+
+  const char *thread_name (ptid_t thread) override;
+
+#if USE_THREAD_DB
+  bool thread_handle (ptid_t ptid, gdb_byte **handle,
+		      int *handle_len) override;
+#endif
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index aa4c5b24b0e..3f0dbd385fa 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -742,11 +742,9 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* thread_name */
   NULL,  /* supports_software_single_step */
   NULL,  /* supports_catch_syscall */
   NULL,  /* get_ipa_tdesc_idx */
-  NULL,  /* thread_handle */
   &the_lynx_target,
 };
 
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 3e2e8eaa521..89c59a0f4bb 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,11 +947,9 @@ nto_process_target::sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* thread_name */
   NULL, /* supports_software_single_step */
   NULL, /* supports_catch_syscall */
   NULL, /* get_ipa_tdesc_idx */
-  NULL, /* thread_handle */
   &the_nto_target,
 };
 
diff --git a/gdbserver/target.c b/gdbserver/target.c
index a29c9fda4eb..b8c58be751a 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -801,3 +801,16 @@ process_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
 {
   return breakpoint_kind_from_pc (pcptr);
 }
+
+const char *
+process_target::thread_name (ptid_t thread)
+{
+  return nullptr;
+}
+
+bool
+process_target::thread_handle (ptid_t ptid, gdb_byte **handle,
+			       int *handle_len)
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 8da04a58150..1b63376a495 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return the thread's name, or NULL if the target is unable to determine it.
-     The returned value must not be freed by the caller.  */
-  const char *(*thread_name) (ptid_t thread);
-
   /* Returns true if the target can software single step.  */
   int (*supports_software_single_step) (void);
 
@@ -84,11 +80,6 @@ struct process_stratum_target
   /* Return tdesc index for IPA.  */
   int (*get_ipa_tdesc_idx) (void);
 
-  /* Thread ID to (numeric) thread handle: Return true on success and
-     false for failure.  Return pointer to thread handle via HANDLE
-     and the handle's length via HANDLE_LEN.  */
-  bool (*thread_handle) (ptid_t ptid, gdb_byte **handle, int *handle_len);
-
   /* The object that will gradually replace this struct.  */
   process_target *pt;
 };
@@ -503,6 +494,17 @@ public:
      PC.  The PCPTR is adjusted to the real memory location in case a
      flag (e.g., the Thumb bit on ARM) is present in the  PC.  */
   virtual int breakpoint_kind_from_current_state (CORE_ADDR *pcptr);
+
+  /* Return the thread's name, or NULL if the target is unable to
+     determine it.  The returned value must not be freed by the
+     caller.  */
+  virtual const char *thread_name (ptid_t thread);
+
+  /* Thread ID to (numeric) thread handle: Return true on success and
+     false for failure.  Return pointer to thread handle via HANDLE
+     and the handle's length via HANDLE_LEN.  */
+  virtual bool thread_handle (ptid_t ptid, gdb_byte **handle,
+			      int *handle_len);
 };
 
 extern process_stratum_target *the_target;
@@ -683,13 +685,10 @@ void done_accessing_memory (void);
   the_target->pt->core_of_thread (ptid)
 
 #define target_thread_name(ptid)                                \
-  (the_target->thread_name ? (*the_target->thread_name) (ptid)  \
-   : NULL)
+  the_target->pt->thread_name (ptid)
 
 #define target_thread_handle(ptid, handle, handle_len) \
-   (the_target->thread_handle ? (*the_target->thread_handle) \
-                                  (ptid, handle, handle_len) \
-   : false)
+  the_target->pt->thread_handle (ptid, handle, handle_len)
 
 int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len);
 
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 017cfd3c245..ef8f7408669 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,11 +1848,9 @@ win32_process_target::sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* thread_name */
   NULL, /* supports_software_single_step */
   NULL, /* supports_catch_syscall */
   NULL, /* get_ipa_tdesc_idx */
-  NULL, /* thread_handle */
   &the_win32_target,
 };
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 39/58] gdbserver: turn target op 'thread_stopped' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (35 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 47/58] gdbserver: turn target op 'supports_agent' " Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 52/58] gdbserver: turn breakpoint kind-related target ops into methods Tankut Baris Aktemur
                   ` (22 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's thread_stopped op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.  Also add
	'supports_thread_stopped'.
	(target_thread_stopped): Update the macro.
	* target.c (process_target::thread_stopped): Define.
	(process_target::supports_thread_stopped): Define.
	(prepare_to_access_memory): Update.

	Update the derived structs and callers below.

	* server.c (queue_stop_reply_callback): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::supports_thread_stopped): Define.
	(linux_thread_stopped): Turn into ...
	(linux_process_target::thread_stopped): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 11 ++++++++---
 gdbserver/linux-low.h |  4 ++++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/server.c    |  4 ++--
 gdbserver/target.c    | 16 ++++++++++++++--
 gdbserver/target.h    | 13 ++++++++-----
 gdbserver/win32-low.c |  1 -
 8 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 3ac40a0ad38..dc7b70b5e59 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6561,8 +6561,14 @@ linux_process_target::write_pc (regcache *regcache, CORE_ADDR pc)
   (*the_low_target.set_pc) (regcache, pc);
 }
 
-static int
-linux_thread_stopped (struct thread_info *thread)
+bool
+linux_process_target::supports_thread_stopped ()
+{
+  return true;
+}
+
+bool
+linux_process_target::thread_stopped (thread_info *thread)
 {
   return get_thread_lwp (thread)->stopped;
 }
@@ -7438,7 +7444,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_thread_stopped,
   NULL,
   linux_pause_all,
   linux_unpause_all,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 01f21b9f29c..2c4d078ecd5 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -395,6 +395,10 @@ public:
   CORE_ADDR read_pc (regcache *regcache) override;
 
   void write_pc (regcache *regcache, CORE_ADDR pc) override;
+
+  bool supports_thread_stopped () override;
+
+  bool thread_stopped (thread_info *thread) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 667e06fd2fd..2842036d7ca 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* thread_stopped */
   NULL,  /* get_tib_address */
   NULL,  /* pause_all */
   NULL,  /* unpause_all */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 6a8baa08b2c..ce25e335e3b 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* thread_stopped */
   NULL, /* get_tib_address */
   NULL, /* pause_all */
   NULL, /* unpause_all */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index df307f5594c..f3dca8d3ce0 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -3217,7 +3217,7 @@ queue_stop_reply_callback (thread_info *thread)
 {
   /* For now, assume targets that don't have this callback also don't
      manage the thread's last_status field.  */
-  if (the_target->thread_stopped == NULL)
+  if (!the_target->pt->supports_thread_stopped ())
     {
       struct vstop_notif *new_notif = new struct vstop_notif;
 
@@ -3229,7 +3229,7 @@ queue_stop_reply_callback (thread_info *thread)
     }
   else
     {
-      if (thread_stopped (thread))
+      if (target_thread_stopped (thread))
 	{
 	  if (debug_threads)
 	    {
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 2fb13b348e4..34805ef5b88 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -66,8 +66,8 @@ prepare_to_access_memory (void)
     {
       if (mythread_alive (thread->id))
 	{
-	  if (stopped == NULL && the_target->thread_stopped != NULL
-	      && thread_stopped (thread))
+	  if (stopped == NULL && the_target->pt->supports_thread_stopped ()
+	      && target_thread_stopped (thread))
 	    stopped = thread;
 
 	  if (first == NULL)
@@ -626,3 +626,15 @@ process_target::write_pc (regcache *regcache, CORE_ADDR pc)
 {
   gdb_assert_not_reached ("regcache_write_pc: Unable to update PC");
 }
+
+bool
+process_target::supports_thread_stopped ()
+{
+  return false;
+}
+
+bool
+process_target::thread_stopped (thread_info *thread)
+{
+  gdb_assert_not_reached ("target op thread_stopped not supported");
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 00b473e61dc..554bfe09af1 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return true if THREAD is known to be stopped now.  */
-  int (*thread_stopped) (struct thread_info *thread);
-
   /* Read Thread Information Block address.  */
   int (*get_tib_address) (ptid_t ptid, CORE_ADDR *address);
 
@@ -488,6 +485,12 @@ public:
 
   /* Write PC to REGCACHE.  */
   virtual void write_pc (regcache *regcache, CORE_ADDR pc);
+
+  /* Return true if the thread_stopped op is supported.  */
+  virtual bool supports_thread_stopped ();
+
+  /* Return true if THREAD is known to be stopped now.  */
+  virtual bool thread_stopped (thread_info *thread);
 };
 
 extern process_stratum_target *the_target;
@@ -559,8 +562,8 @@ int kill_inferior (process_info *proc);
   (the_target->get_min_fast_tracepoint_insn_len		\
    ? (*the_target->get_min_fast_tracepoint_insn_len) () : 0)
 
-#define thread_stopped(thread) \
-  (*the_target->thread_stopped) (thread)
+#define target_thread_stopped(thread) \
+  the_target->pt->thread_stopped (thread)
 
 #define pause_all(freeze)			\
   do						\
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 6d5860f595f..5e9a05ac97c 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1842,7 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* thread_stopped */
   win32_get_tib_address,
   NULL, /* pause_all */
   NULL, /* unpause_all */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 38/58] gdbserver: turn target ops 'read_pc' and 'write_pc' into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (45 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 57/58] gdbserver: use unique_ptr for 'the_target' Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-13 20:29   ` Pedro Alves
  2020-02-11  9:04 ` [PATCH 50/58] gdbserver: turn target op 'pid_to_exec_file' into a method Tankut Baris Aktemur
                   ` (12 subsequent siblings)
  59 siblings, 1 reply; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's read_pc and write_pc ops methods of
	process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	* target.c (process_target::read_pc): Define.
	(process_target::write_pc): Define.

	Update the derived structs and callers below.

	* regcache.c (regcache_read_pc): Update.
	(regcache_write_pc): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_read_pc): Turn into ...
	(linux_process_target::read_pc): ... this.
	(linux_write_pc): Turn into ...
	(linux_process_target::write_pc): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 10 ++++------
 gdbserver/linux-low.h |  4 ++++
 gdbserver/lynx-low.c  |  2 --
 gdbserver/nto-low.c   |  2 --
 gdbserver/regcache.c  | 16 ++--------------
 gdbserver/target.c    | 12 ++++++++++++
 gdbserver/target.h    | 12 ++++++------
 gdbserver/win32-low.c |  2 --
 8 files changed, 28 insertions(+), 32 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 758dd1108f8..3ac40a0ad38 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6544,8 +6544,8 @@ linux_process_target::supports_tracepoints ()
   return (*the_low_target.supports_tracepoints) ();
 }
 
-static CORE_ADDR
-linux_read_pc (struct regcache *regcache)
+CORE_ADDR
+linux_process_target::read_pc (regcache *regcache)
 {
   if (the_low_target.get_pc == NULL)
     return 0;
@@ -6553,8 +6553,8 @@ linux_read_pc (struct regcache *regcache)
   return (*the_low_target.get_pc) (regcache);
 }
 
-static void
-linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
+void
+linux_process_target::write_pc (regcache *regcache, CORE_ADDR pc)
 {
   gdb_assert (the_low_target.set_pc != NULL);
 
@@ -7438,8 +7438,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_read_pc,
-  linux_write_pc,
   linux_thread_stopped,
   NULL,
   linux_pause_all,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index e142f6bfeb1..01f21b9f29c 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -391,6 +391,10 @@ public:
   void process_qsupported (char **features, int count) override;
 
   bool supports_tracepoints () override;
+
+  CORE_ADDR read_pc (regcache *regcache) override;
+
+  void write_pc (regcache *regcache, CORE_ADDR pc) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index eeeddc5f175..667e06fd2fd 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,8 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* read_pc */
-  NULL,  /* write_pc */
   NULL,  /* thread_stopped */
   NULL,  /* get_tib_address */
   NULL,  /* pause_all */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index d76014808ba..6a8baa08b2c 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,8 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* read_pc */
-  NULL, /* write_pc */
   NULL, /* thread_stopped */
   NULL, /* get_tib_address */
   NULL, /* pause_all */
diff --git a/gdbserver/regcache.c b/gdbserver/regcache.c
index f63463344af..ec9d70d42fb 100644
--- a/gdbserver/regcache.c
+++ b/gdbserver/regcache.c
@@ -477,25 +477,13 @@ collect_register_by_name (struct regcache *regcache,
 CORE_ADDR
 regcache_read_pc (struct regcache *regcache)
 {
-  CORE_ADDR pc_val;
-
-  if (the_target->read_pc)
-    pc_val = the_target->read_pc (regcache);
-  else
-    internal_error (__FILE__, __LINE__,
-		    "regcache_read_pc: Unable to find PC");
-
-  return pc_val;
+  return the_target->pt->read_pc (regcache);
 }
 
 void
 regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
-  if (the_target->write_pc)
-    the_target->write_pc (regcache, pc);
-  else
-    internal_error (__FILE__, __LINE__,
-		    "regcache_write_pc: Unable to update PC");
+  the_target->pt->write_pc (regcache, pc);
 }
 
 #endif
diff --git a/gdbserver/target.c b/gdbserver/target.c
index ded8f3fee9d..2fb13b348e4 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -614,3 +614,15 @@ process_target::supports_tracepoints ()
 {
   return false;
 }
+
+CORE_ADDR
+process_target::read_pc (regcache *regcache)
+{
+  gdb_assert_not_reached ("regcache_read_pc: Unable to find PC");
+}
+
+void
+process_target::write_pc (regcache *regcache, CORE_ADDR pc)
+{
+  gdb_assert_not_reached ("regcache_write_pc: Unable to update PC");
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 8a0146e4c32..00b473e61dc 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,12 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Read PC from REGCACHE.  */
-  CORE_ADDR (*read_pc) (struct regcache *regcache);
-
-  /* Write PC to REGCACHE.  */
-  void (*write_pc) (struct regcache *regcache, CORE_ADDR pc);
-
   /* Return true if THREAD is known to be stopped now.  */
   int (*thread_stopped) (struct thread_info *thread);
 
@@ -488,6 +482,12 @@ public:
 
   /* Return true if the target supports tracepoints, false otherwise.  */
   virtual bool supports_tracepoints ();
+
+  /* Read PC from REGCACHE.  */
+  virtual CORE_ADDR read_pc (regcache *regcache);
+
+  /* Write PC to REGCACHE.  */
+  virtual void write_pc (regcache *regcache, CORE_ADDR pc);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 81746dedcbb..6d5860f595f 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1842,8 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* read_pc */
-  NULL, /* write_pc */
   NULL, /* thread_stopped */
   win32_get_tib_address,
   NULL, /* pause_all */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 54/58] gdbserver: turn target op 'supports_software_single_step' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (38 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 34/58] gdbserver: turn target op 'core_of_thread' into a method Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 17/58] gdbserver: turn target op 'read_auxv' " Tankut Baris Aktemur
                   ` (19 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's supports_software_single_step op a
	method of process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_supports_software_single_step): Update the macro.
	* target.c (process_target::supports_software_single_step): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_supports_software_single_step): Turn into ...
	(linux_process_target::supports_software_single_step): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 5 ++---
 gdbserver/linux-low.h | 2 ++
 gdbserver/lynx-low.c  | 1 -
 gdbserver/nto-low.c   | 1 -
 gdbserver/target.c    | 6 ++++++
 gdbserver/target.h    | 9 ++++-----
 gdbserver/win32-low.c | 1 -
 7 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 82bb9a680bf..9b0d8a18278 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6036,8 +6036,8 @@ linux_process_target::supports_hardware_single_step ()
   return can_hardware_single_step ();
 }
 
-static int
-linux_supports_software_single_step (void)
+bool
+linux_process_target::supports_software_single_step ()
 {
   return can_software_single_step ();
 }
@@ -7513,7 +7513,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_supports_software_single_step,
   linux_supports_catch_syscall,
   linux_get_ipa_tdesc_idx,
   &the_linux_target,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index e77c54043b8..582d5c1924d 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -478,6 +478,8 @@ public:
   bool thread_handle (ptid_t ptid, gdb_byte **handle,
 		      int *handle_len) override;
 #endif
+
+  bool supports_software_single_step () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 3f0dbd385fa..ab4238cf373 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -742,7 +742,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* supports_software_single_step */
   NULL,  /* supports_catch_syscall */
   NULL,  /* get_ipa_tdesc_idx */
   &the_lynx_target,
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 89c59a0f4bb..192d6a53ba8 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_process_target::sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* supports_software_single_step */
   NULL, /* supports_catch_syscall */
   NULL, /* get_ipa_tdesc_idx */
   &the_nto_target,
diff --git a/gdbserver/target.c b/gdbserver/target.c
index b8c58be751a..03145cce280 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -814,3 +814,9 @@ process_target::thread_handle (ptid_t ptid, gdb_byte **handle,
 {
   return false;
 }
+
+bool
+process_target::supports_software_single_step ()
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 1b63376a495..8854bf3791f 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Returns true if the target can software single step.  */
-  int (*supports_software_single_step) (void);
-
   /* Return 1 if the target supports catch syscall, 0 (or leave the
      callback NULL) otherwise.  */
   int (*supports_catch_syscall) (void);
@@ -505,6 +502,9 @@ public:
      and the handle's length via HANDLE_LEN.  */
   virtual bool thread_handle (ptid_t ptid, gdb_byte **handle,
 			      int *handle_len);
+
+  /* Returns true if the target can software single step.  */
+  virtual bool supports_software_single_step ();
 };
 
 extern process_stratum_target *the_target;
@@ -669,8 +669,7 @@ target_read_btrace_conf (struct btrace_target_info *tinfo,
   the_target->pt->breakpoint_kind_from_current_state (pcptr)
 
 #define target_supports_software_single_step() \
-  (the_target->supports_software_single_step ? \
-   (*the_target->supports_software_single_step) () : 0)
+  the_target->pt->supports_software_single_step ()
 
 ptid_t mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options,
 	       int connected_wait);
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index ef8f7408669..c4c52e7b2aa 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,7 +1848,6 @@ win32_process_target::sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* supports_software_single_step */
   NULL, /* supports_catch_syscall */
   NULL, /* get_ipa_tdesc_idx */
   &the_win32_target,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 14/58] gdbserver: turn target ops 'read_memory' and 'write_memory' into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (32 preceding siblings ...)
  2020-02-11  9:03 ` [PATCH 46/58] gdbserver: turn target op 'qxfer_libraries_svr4' " Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 49/58] gdbserver: turn target op 'supports_range_stepping' into a method Tankut Baris Aktemur
                   ` (25 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's read_memory and write_memory
	ops methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	(read_inferior_memory): Update the macro.
	(write_inferior_memory): Update the macro.

	Update the derived structs and callers below.

	* linux-aarch32-low.c (arm_breakpoint_at): Update.
	* linux-aarch64-low.c (aarch64_breakpoint_at): Update.
	* linux-arm-low.c (arm_sigreturn_next_pc): Update.
	(arm_get_syscall_trapinfo): Update.
	* linux-cris-low.c (cris_breakpoint_at): Update.
	* linux-crisv32-low.c (cris_breakpoint_at): Update.
	* linux-m32r-low.c (m32r_breakpoint_at): Update.
	* linux-mips-low.c (mips_breakpoint_at): Update.
	* linux-nios2-low.c (nios2_breakpoint_at): Update.
	* linux-ppc-low.c (parse_spufs_run): Update.
	(ppc_get_pc): Update.
	(ppc_set_pc): Update.
	(ppc_breakpoint_at): Update.
	* linux-sh-low.c (sh_breakpoint_at): Update.
	* linux-sparc-low.c (sparc_fill_gregset_to_stack): Update.
	(sparc_store_gregset_from_stack): Update.
	(sparc_breakpoint_at): Update.
	* linux-tic6x-low.c (tic6x_breakpoint_at): Update.
	* linux-tile-low.c (tile_breakpoint_at): Update.
	* linux-x86-low.c (x86_breakpoint_at): Update.
	* linux-xtensa-low.c (xtensa_breakpoint_at): Update.
	* mem-break.c (insert_memory_breakpoint): Update.
	(validate_inserted_breakpoint): Update.
	* target.c (read_inferior_memory): Update.
	(write_inferior_memory): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_read_memory): Make a wrapper around the read_memory target
	op call.
	(linux_process_target::read_memory): Rename from linux_read_memory.
	(linux_write_memory): Turn into ...
	(linux_process_target::write_memory): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_read_memory): Turn into ...
	(lynx_process_target::read_memory): ... this.
	(lynx_write_memory): Turn into ...
	(lynx_process_target::write_memory): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_read_memory): Turn into ...
	(nto_process_target::read_memory): ... this.
	(nto_write_memory): Turn into ...
	(nto_process_target::write_memory): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_read_inferior_memory): Turn into ...
	(win32_process_target::read_memory): ... this.
	(win32_write_inferior_memory): Turn into ...
	(win32_process_target::write_memory): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-aarch32-low.c |  6 +++---
 gdbserver/linux-aarch64-low.c |  4 ++--
 gdbserver/linux-arm-low.c     |  8 ++++----
 gdbserver/linux-cris-low.c    |  4 ++--
 gdbserver/linux-crisv32-low.c |  4 ++--
 gdbserver/linux-low.c         | 20 +++++++++++++------
 gdbserver/linux-low.h         |  6 ++++++
 gdbserver/linux-m32r-low.c    |  4 ++--
 gdbserver/linux-mips-low.c    |  2 +-
 gdbserver/linux-nios2-low.c   |  4 ++--
 gdbserver/linux-ppc-low.c     |  2 +-
 gdbserver/linux-sh-low.c      |  2 +-
 gdbserver/linux-sparc-low.c   |  6 +++---
 gdbserver/linux-tic6x-low.c   |  2 +-
 gdbserver/linux-tile-low.c    |  2 +-
 gdbserver/linux-x86-low.c     |  2 +-
 gdbserver/linux-xtensa-low.c  |  4 ++--
 gdbserver/lynx-low.c          | 14 ++++++-------
 gdbserver/lynx-low.h          |  6 ++++++
 gdbserver/mem-break.c         |  6 +++---
 gdbserver/nto-low.c           | 12 ++++++------
 gdbserver/nto-low.h           |  6 ++++++
 gdbserver/target.c            |  4 ++--
 gdbserver/target.h            | 37 +++++++++++++++++------------------
 gdbserver/win32-low.c         | 13 ++++++------
 gdbserver/win32-low.h         |  6 ++++++
 26 files changed, 108 insertions(+), 78 deletions(-)

diff --git a/gdbserver/linux-aarch32-low.c b/gdbserver/linux-aarch32-low.c
index c6a70249d3b..41e018ab528 100644
--- a/gdbserver/linux-aarch32-low.c
+++ b/gdbserver/linux-aarch32-low.c
@@ -192,13 +192,13 @@ arm_breakpoint_at (CORE_ADDR where)
       /* Thumb mode.  */
       unsigned short insn;
 
-      (*the_target->read_memory) (where, (unsigned char *) &insn, 2);
+      the_target->pt->read_memory (where, (unsigned char *) &insn, 2);
       if (insn == thumb_breakpoint)
 	return 1;
 
       if (insn == thumb2_breakpoint[0])
 	{
-	  (*the_target->read_memory) (where + 2, (unsigned char *) &insn, 2);
+	  the_target->pt->read_memory (where + 2, (unsigned char *) &insn, 2);
 	  if (insn == thumb2_breakpoint[1])
 	    return 1;
 	}
@@ -208,7 +208,7 @@ arm_breakpoint_at (CORE_ADDR where)
       /* ARM mode.  */
       unsigned long insn;
 
-      (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+      the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
       if (insn == arm_abi_breakpoint)
 	return 1;
 
diff --git a/gdbserver/linux-aarch64-low.c b/gdbserver/linux-aarch64-low.c
index 961fd5b3cc4..97117f05780 100644
--- a/gdbserver/linux-aarch64-low.c
+++ b/gdbserver/linux-aarch64-low.c
@@ -192,8 +192,8 @@ aarch64_breakpoint_at (CORE_ADDR where)
     {
       gdb_byte insn[aarch64_breakpoint_len];
 
-      (*the_target->read_memory) (where, (unsigned char *) &insn,
-				  aarch64_breakpoint_len);
+      the_target->pt->read_memory (where, (unsigned char *) &insn,
+				   aarch64_breakpoint_len);
       if (memcmp (insn, aarch64_breakpoint, aarch64_breakpoint_len) == 0)
 	return 1;
 
diff --git a/gdbserver/linux-arm-low.c b/gdbserver/linux-arm-low.c
index 9f046c098bf..e7cc1196857 100644
--- a/gdbserver/linux-arm-low.c
+++ b/gdbserver/linux-arm-low.c
@@ -779,15 +779,15 @@ arm_sigreturn_next_pc (struct regcache *regcache, int svc_number,
   gdb_assert (svc_number == __NR_sigreturn || svc_number == __NR_rt_sigreturn);
 
   collect_register_by_name (regcache, "sp", &sp);
-  (*the_target->read_memory) (sp, (unsigned char *) &sp_data, 4);
+  the_target->pt->read_memory (sp, (unsigned char *) &sp_data, 4);
 
   pc_offset = arm_linux_sigreturn_next_pc_offset
     (sp, sp_data, svc_number, __NR_sigreturn == svc_number ? 1 : 0);
 
-  (*the_target->read_memory) (sp + pc_offset, (unsigned char *) &next_pc, 4);
+  the_target->pt->read_memory (sp + pc_offset, (unsigned char *) &next_pc, 4);
 
   /* Set IS_THUMB according the CPSR saved on the stack.  */
-  (*the_target->read_memory) (sp + pc_offset + 4, (unsigned char *) &cpsr, 4);
+  the_target->pt->read_memory (sp + pc_offset + 4, (unsigned char *) &cpsr, 4);
   *is_thumb = ((cpsr & CPSR_T) != 0);
 
   return next_pc;
@@ -939,7 +939,7 @@ arm_get_syscall_trapinfo (struct regcache *regcache, int *sysno)
 
       collect_register_by_name (regcache, "pc", &pc);
 
-      if ((*the_target->read_memory) (pc - 4, (unsigned char *) &insn, 4))
+      if (the_target->pt->read_memory (pc - 4, (unsigned char *) &insn, 4))
 	*sysno = UNKNOWN_SYSCALL;
       else
 	{
diff --git a/gdbserver/linux-cris-low.c b/gdbserver/linux-cris-low.c
index 8ea5af92e31..6a4e8b1946a 100644
--- a/gdbserver/linux-cris-low.c
+++ b/gdbserver/linux-cris-low.c
@@ -76,8 +76,8 @@ cris_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn,
-			      cris_breakpoint_len);
+  the_target->pt->read_memory (where, (unsigned char *) &insn,
+			       cris_breakpoint_len);
   if (insn == cris_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-crisv32-low.c b/gdbserver/linux-crisv32-low.c
index facb5c5c274..fe12624c3b6 100644
--- a/gdbserver/linux-crisv32-low.c
+++ b/gdbserver/linux-crisv32-low.c
@@ -72,8 +72,8 @@ cris_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn,
-			      cris_breakpoint_len);
+  the_target->pt->read_memory (where, (unsigned char *) &insn,
+			       cris_breakpoint_len);
   if (insn == cris_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 1d05e1b9ff0..dad9dcf86fc 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -5709,11 +5709,20 @@ linux_process_target::store_registers (regcache *regcache, int regno)
 }
 
 
-/* Copy LEN bytes from inferior's memory starting at MEMADDR
-   to debugger memory starting at MYADDR.  */
+/* A wrapper for the read_memory target op.  */
 
 static int
 linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
+{
+  return the_target->pt->read_memory (memaddr, myaddr, len);
+}
+
+/* Copy LEN bytes from inferior's memory starting at MEMADDR
+   to debugger memory starting at MYADDR.  */
+
+int
+linux_process_target::read_memory (CORE_ADDR memaddr,
+				   unsigned char *myaddr, int len)
 {
   int pid = lwpid_of (current_thread);
   PTRACE_XFER_TYPE *buffer;
@@ -5801,8 +5810,9 @@ linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
    memory at MEMADDR.  On failure (cannot write to the inferior)
    returns the value of errno.  Always succeeds if LEN is zero.  */
 
-static int
-linux_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
+int
+linux_process_target::write_memory (CORE_ADDR memaddr,
+				    const unsigned char *myaddr, int len)
 {
   int i;
   /* Round starting address down to longword boundary.  */
@@ -7359,8 +7369,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_read_memory,
-  linux_write_memory,
   linux_look_up_symbols,
   linux_request_interrupt,
   linux_read_auxv,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 51622f6d211..58fd665ba66 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -298,6 +298,12 @@ public:
   int prepare_to_access_memory () override;
 
   void done_accessing_memory () override;
+
+  int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+		   int len) override;
+
+  int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
+		    int len) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/linux-m32r-low.c b/gdbserver/linux-m32r-low.c
index c52e816e341..8fe8389618f 100644
--- a/gdbserver/linux-m32r-low.c
+++ b/gdbserver/linux-m32r-low.c
@@ -70,8 +70,8 @@ m32r_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn,
-			      m32r_breakpoint_len);
+  the_target->pt->read_memory (where, (unsigned char *) &insn,
+			       m32r_breakpoint_len);
   if (insn == m32r_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-mips-low.c b/gdbserver/linux-mips-low.c
index f94e141be79..cb7eb53e3eb 100644
--- a/gdbserver/linux-mips-low.c
+++ b/gdbserver/linux-mips-low.c
@@ -302,7 +302,7 @@ mips_breakpoint_at (CORE_ADDR where)
 {
   unsigned int insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == mips_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-nios2-low.c b/gdbserver/linux-nios2-low.c
index bfc5aee165d..6e5d3084dad 100644
--- a/gdbserver/linux-nios2-low.c
+++ b/gdbserver/linux-nios2-low.c
@@ -131,12 +131,12 @@ nios2_breakpoint_at (CORE_ADDR where)
 
   /* For R2, first check for the 2-byte CDX trap.n breakpoint encoding.  */
 #if defined(__nios2_arch__) && __nios2_arch__ == 2
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 2);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 2);
   if (insn == CDX_BREAKPOINT)
     return 1;
 #endif
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == nios2_breakpoint)
     return 1;
   return 0;
diff --git a/gdbserver/linux-ppc-low.c b/gdbserver/linux-ppc-low.c
index 5d8d67bec2f..93b3511a2e1 100644
--- a/gdbserver/linux-ppc-low.c
+++ b/gdbserver/linux-ppc-low.c
@@ -277,7 +277,7 @@ ppc_breakpoint_at (CORE_ADDR where)
 {
   unsigned int insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == ppc_breakpoint)
     return 1;
   /* If necessary, recognize more trap instructions here.  GDB only uses
diff --git a/gdbserver/linux-sh-low.c b/gdbserver/linux-sh-low.c
index abe71ff4766..06ce8118ebf 100644
--- a/gdbserver/linux-sh-low.c
+++ b/gdbserver/linux-sh-low.c
@@ -76,7 +76,7 @@ sh_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 2);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 2);
   if (insn == sh_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-sparc-low.c b/gdbserver/linux-sparc-low.c
index cfa76c0b8e6..b0b6c96b3de 100644
--- a/gdbserver/linux-sparc-low.c
+++ b/gdbserver/linux-sparc-low.c
@@ -133,7 +133,7 @@ sparc_fill_gregset_to_stack (struct regcache *regcache, const void *buf)
   for (i = l0_regno; i <= i7_regno; i++)
     {
       collect_register (regcache, i, tmp_reg_buf);
-      (*the_target->write_memory) (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
+      the_target->pt->write_memory (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
       addr += sizeof (tmp_reg_buf);
     }
 }
@@ -184,7 +184,7 @@ sparc_store_gregset_from_stack (struct regcache *regcache, const void *buf)
 
   for (i = l0_regno; i <= i7_regno; i++)
     {
-      (*the_target->read_memory) (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
+      the_target->pt->read_memory (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
       supply_register (regcache, i, tmp_reg_buf);
       addr += sizeof (tmp_reg_buf);
     }
@@ -242,7 +242,7 @@ sparc_breakpoint_at (CORE_ADDR where)
 {
   unsigned char insn[INSN_SIZE];
 
-  (*the_target->read_memory) (where, (unsigned char *) insn, sizeof (insn));
+  the_target->pt->read_memory (where, (unsigned char *) insn, sizeof (insn));
 
   if (memcmp (sparc_breakpoint, insn, sizeof (insn)) == 0)
     return 1;
diff --git a/gdbserver/linux-tic6x-low.c b/gdbserver/linux-tic6x-low.c
index 51a31c7876a..b57f8c57710 100644
--- a/gdbserver/linux-tic6x-low.c
+++ b/gdbserver/linux-tic6x-low.c
@@ -241,7 +241,7 @@ tic6x_breakpoint_at (CORE_ADDR where)
 {
   unsigned int insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == tic6x_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-tile-low.c b/gdbserver/linux-tile-low.c
index cd85e945a46..baee93a5c24 100644
--- a/gdbserver/linux-tile-low.c
+++ b/gdbserver/linux-tile-low.c
@@ -85,7 +85,7 @@ tile_breakpoint_at (CORE_ADDR where)
 {
   uint64_t insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 8);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 8);
   if (insn == tile_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-x86-low.c b/gdbserver/linux-x86-low.c
index 09ec22ff678..cb2d3f59580 100644
--- a/gdbserver/linux-x86-low.c
+++ b/gdbserver/linux-x86-low.c
@@ -515,7 +515,7 @@ x86_breakpoint_at (CORE_ADDR pc)
 {
   unsigned char c;
 
-  (*the_target->read_memory) (pc, &c, 1);
+  the_target->pt->read_memory (pc, &c, 1);
   if (c == 0xCC)
     return 1;
 
diff --git a/gdbserver/linux-xtensa-low.c b/gdbserver/linux-xtensa-low.c
index 83af11e11dc..31e7bad36b8 100644
--- a/gdbserver/linux-xtensa-low.c
+++ b/gdbserver/linux-xtensa-low.c
@@ -207,8 +207,8 @@ xtensa_breakpoint_at (CORE_ADDR where)
 {
     unsigned long insn;
 
-    (*the_target->read_memory) (where, (unsigned char *) &insn,
-				xtensa_breakpoint_len);
+    the_target->pt->read_memory (where, (unsigned char *) &insn,
+				 xtensa_breakpoint_len);
     return memcmp((char *) &insn,
 		  xtensa_breakpoint, xtensa_breakpoint_len) == 0;
 }
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 365f82b55ce..fe55f9bcdf3 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -638,8 +638,9 @@ lynx_process_target::store_registers (regcache *regcache, int regno)
 
 /* Implement the read_memory target_ops method.  */
 
-static int
-lynx_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
+int
+lynx_process_target::read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+				  int len)
 {
   /* On LynxOS, memory reads needs to be performed in chunks the size
      of int types, and they should also be aligned accordingly.  */
@@ -671,8 +672,9 @@ lynx_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
 
 /* Implement the write_memory target_ops method.  */
 
-static int
-lynx_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
+int
+lynx_process_target::write_memory (CORE_ADDR memaddr,
+				   const unsigned char *myaddr, int len)
 {
   /* On LynxOS, memory writes needs to be performed in chunks the size
      of int types, and they should also be aligned accordingly.  */
@@ -694,7 +696,7 @@ lynx_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
 	{
 	  /* We need to read the memory at this address in order to preserve
 	     the data that we are not overwriting.  */
-	  lynx_read_memory (addr, (unsigned char *) &buf, xfer_size);
+	  read_memory (addr, (unsigned char *) &buf, xfer_size);
 	  if (errno)
 	    return errno;
 	}
@@ -727,8 +729,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_read_memory,
-  lynx_write_memory,
   NULL,  /* look_up_symbols */
   lynx_request_interrupt,
   NULL,  /* read_auxv */
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index 0d82f86e94e..05223ec9774 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -80,6 +80,12 @@ public:
   void fetch_registers (regcache *regcache, int regno) override;
 
   void store_registers (regcache *regcache, int regno) override;
+
+  int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+		   int len) override;
+
+  int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
+		    int len) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/mem-break.c b/gdbserver/mem-break.c
index 1b6f2365814..43a07c390d1 100644
--- a/gdbserver/mem-break.c
+++ b/gdbserver/mem-break.c
@@ -380,8 +380,8 @@ insert_memory_breakpoint (struct raw_breakpoint *bp)
     {
       memcpy (bp->old_data, buf, bp_size (bp));
 
-      err = (*the_target->write_memory) (bp->pc, bp_opcode (bp),
-					 bp_size (bp));
+      err = the_target->pt->write_memory (bp->pc, bp_opcode (bp),
+					  bp_size (bp));
       if (err != 0)
 	{
 	  if (debug_threads)
@@ -1857,7 +1857,7 @@ validate_inserted_breakpoint (struct raw_breakpoint *bp)
   gdb_assert (bp->raw_type == raw_bkpt_type_sw);
 
   buf = (unsigned char *) alloca (bp_size (bp));
-  err = (*the_target->read_memory) (bp->pc, buf, bp_size (bp));
+  err = the_target->pt->read_memory (bp->pc, buf, bp_size (bp));
   if (err || memcmp (buf, bp_opcode (bp), bp_size (bp)) != 0)
     {
       /* Tag it as gone.  */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 2e75225b01e..f1c4be09f7f 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -706,8 +706,9 @@ nto_process_target::store_registers (regcache *regcache, int regno)
 
    Return 0 on success -1 otherwise.  */
 
-static int
-nto_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
+int
+nto_process_target::read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+				 int len)
 {
   TRACE ("%s memaddr:0x%08lx, len:%d\n", __func__, memaddr, len);
 
@@ -725,8 +726,9 @@ nto_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
 
    Return 0 on success -1 otherwise.  */
 
-static int
-nto_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
+int
+nto_process_target::write_memory (CORE_ADDR memaddr,
+				  const unsigned char *myaddr, int len)
 {
   int len_written;
 
@@ -941,8 +943,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_read_memory,
-  nto_write_memory,
   NULL, /* nto_look_up_symbols */
   nto_request_interrupt,
   nto_read_auxv,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index 1fb57f4f73d..6f420219ad4 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -70,6 +70,12 @@ public:
   void fetch_registers (regcache *regcache, int regno) override;
 
   void store_registers (regcache *regcache, int regno) override;
+
+  int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+		   int len) override;
+
+  int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
+		    int len) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.c b/gdbserver/target.c
index f88e9faf191..49302f61dfb 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -120,7 +120,7 @@ int
 read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
 {
   int res;
-  res = (*the_target->read_memory) (memaddr, myaddr, len);
+  res = the_target->pt->read_memory (memaddr, myaddr, len);
   check_mem_read (memaddr, myaddr, len);
   return res;
 }
@@ -151,7 +151,7 @@ target_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
      update it.  */
   gdb::byte_vector buffer (myaddr, myaddr + len);
   check_mem_write (memaddr, buffer.data (), myaddr, len);
-  return (*the_target->write_memory) (memaddr, buffer.data (), len);
+  return the_target->pt->write_memory (memaddr, buffer.data (), len);
 }
 
 ptid_t
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 16ff5ab6baa..5621dc1d60e 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,25 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Read memory from the inferior process.  This should generally be
-     called through read_inferior_memory, which handles breakpoint shadowing.
-
-     Read LEN bytes at MEMADDR into a buffer at MYADDR.
-  
-     Returns 0 on success and errno on failure.  */
-
-  int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len);
-
-  /* Write memory to the inferior process.  This should generally be
-     called through target_write_memory, which handles breakpoint shadowing.
-
-     Write LEN bytes from the buffer at MYADDR to MEMADDR.
-
-     Returns 0 on success and errno on failure.  */
-
-  int (*write_memory) (CORE_ADDR memaddr, const unsigned char *myaddr,
-		       int len);
-
   /* Query GDB for the values of any symbols we're interested in.
      This function is called whenever we receive a "qSymbols::"
      query, which corresponds to every time more symbols (might)
@@ -477,6 +458,24 @@ public:
 
   /* Undo the effects of prepare_to_access_memory.  */
   virtual void done_accessing_memory ();
+
+  /* Read memory from the inferior process.  This should generally be
+     called through read_inferior_memory, which handles breakpoint shadowing.
+
+     Read LEN bytes at MEMADDR into a buffer at MYADDR.
+
+     Returns 0 on success and errno on failure.  */
+  virtual int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+			   int len) = 0;
+
+  /* Write memory to the inferior process.  This should generally be
+     called through target_write_memory, which handles breakpoint shadowing.
+
+     Write LEN bytes from the buffer at MYADDR to MEMADDR.
+
+     Returns 0 on success and errno on failure.  */
+  virtual int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
+			    int len) = 0;
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 6639401b1ae..1a56c9c45a4 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1666,8 +1666,9 @@ win32_process_target::store_registers (regcache *regcache, int regno)
 /* Read memory from the inferior process.  This should generally be
    called through read_inferior_memory, which handles breakpoint shadowing.
    Read LEN bytes at MEMADDR into a buffer at MYADDR.  */
-static int
-win32_read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
+int
+win32_process_target::read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+				   int len)
 {
   return child_xfer_memory (memaddr, (char *) myaddr, len, 0, 0) != len;
 }
@@ -1676,9 +1677,9 @@ win32_read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
    called through write_inferior_memory, which handles breakpoint shadowing.
    Write LEN bytes from the buffer at MYADDR to MEMADDR.
    Returns 0 on success and errno on failure.  */
-static int
-win32_write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
-			     int len)
+int
+win32_process_target::write_memory (CORE_ADDR memaddr,
+				    const unsigned char *myaddr, int len)
 {
   return child_xfer_memory (memaddr, (char *) myaddr, len, 1, 0) != len;
 }
@@ -1827,8 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_read_inferior_memory,
-  win32_write_inferior_memory,
   NULL, /* lookup_symbols */
   win32_request_interrupt,
   NULL, /* read_auxv */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 451c3f1b17d..27ba64ce916 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -129,6 +129,12 @@ public:
   void fetch_registers (regcache *regcache, int regno) override;
 
   void store_registers (regcache *regcache, int regno) override;
+
+  int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+		   int len) override;
+
+  int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
+		    int len) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 34/58] gdbserver: turn target op 'core_of_thread' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (37 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 52/58] gdbserver: turn breakpoint kind-related target ops into methods Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 54/58] gdbserver: turn target op 'supports_software_single_step' " Tankut Baris Aktemur
                   ` (20 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's core_of_thread op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_core_of_thread): Update the macro.
	* target.c (process_target::core_of_thread): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::core_of_thread): Define.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 7 ++++++-
 gdbserver/linux-low.h | 2 ++
 gdbserver/lynx-low.c  | 1 -
 gdbserver/nto-low.c   | 1 -
 gdbserver/target.c    | 6 ++++++
 gdbserver/target.h    | 9 ++++-----
 gdbserver/win32-low.c | 1 -
 7 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index ef68a8a89e2..713ad3af8aa 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6397,6 +6397,12 @@ linux_process_target::handle_monitor_command (char *mon)
 #endif
 }
 
+int
+linux_process_target::core_of_thread (ptid_t ptid)
+{
+  return linux_common_core_of_thread (ptid);
+}
+
 static int
 linux_supports_disable_randomization (void)
 {
@@ -7428,7 +7434,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_common_core_of_thread,
   linux_read_loadmap,
   linux_process_qsupported,
   linux_supports_tracepoints,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index c37db38749b..57663ef9419 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -378,6 +378,8 @@ public:
   void handle_new_gdb_connection () override;
 
   int handle_monitor_command (char *mon) override;
+
+  int core_of_thread (ptid_t ptid) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 5db9d2f154d..aa744e5e6a3 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* core_of_thread */
   NULL,  /* read_loadmap */
   NULL,  /* process_qsupported */
   NULL,  /* supports_tracepoints */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 880e8ccecd1..1700fd54278 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* core_of_thread */
   NULL, /* read_loadmap */
   NULL, /* process_qsupported */
   NULL, /* supports_tracepoints */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 74cd90a48a4..e1c802d65bc 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -583,3 +583,9 @@ process_target::handle_monitor_command (char *mon)
 {
   return 0;
 }
+
+int
+process_target::core_of_thread (ptid_t ptid)
+{
+  return -1;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 7d7e371cf32..7b077a5a89a 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Returns the core given a thread, or -1 if not known.  */
-  int (*core_of_thread) (ptid_t);
-
   /* Read loadmaps.  Read LEN bytes at OFFSET into a buffer at MYADDR.  */
   int (*read_loadmap) (const char *annex, CORE_ADDR offset,
 		       unsigned char *myaddr, unsigned int len);
@@ -486,6 +483,9 @@ public:
   /* The target-specific routine to process monitor command.
      Returns 1 if handled, or 0 to perform default processing.  */
   virtual int handle_monitor_command (char *mon);
+
+  /* Returns the core given a thread, or -1 if not known.  */
+  virtual int core_of_thread (ptid_t ptid);
 };
 
 extern process_stratum_target *the_target;
@@ -700,8 +700,7 @@ int prepare_to_access_memory (void);
 void done_accessing_memory (void);
 
 #define target_core_of_thread(ptid)		\
-  (the_target->core_of_thread ? (*the_target->core_of_thread) (ptid) \
-   : -1)
+  the_target->pt->core_of_thread (ptid)
 
 #define target_thread_name(ptid)                                \
   (the_target->thread_name ? (*the_target->thread_name) (ptid)  \
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index ed847447e40..bc1fdc845b7 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1842,7 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* core_of_thread */
   NULL, /* read_loadmap */
   NULL, /* process_qsupported */
   NULL, /* supports_tracepoints */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 55/58] gdbserver: turn target op 'supports_catch_syscall' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (47 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 50/58] gdbserver: turn target op 'pid_to_exec_file' into a method Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:05 ` [PATCH 44/58] gdbserver: turn target op 'emit_ops' " Tankut Baris Aktemur
                   ` (10 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's supports_catch_syscall op a method
	of process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_supports_catch_syscall): Update the macro.
	* target.c (process_target::supports_catch_syscall): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_supports_catch_syscall): Turn into ...
	(linux_process_target::supports_catch_syscall): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c |  5 ++---
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/target.c    |  6 ++++++
 gdbserver/target.h    | 10 ++++------
 gdbserver/win32-low.c |  1 -
 7 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 9b0d8a18278..4cbb82429a7 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6557,8 +6557,8 @@ linux_process_target::process_qsupported (char **features, int count)
     the_low_target.process_qsupported (features, count);
 }
 
-static int
-linux_supports_catch_syscall (void)
+bool
+linux_process_target::supports_catch_syscall ()
 {
   return (the_low_target.get_syscall_trapinfo != NULL
 	  && linux_supports_tracesysgood ());
@@ -7513,7 +7513,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_supports_catch_syscall,
   linux_get_ipa_tdesc_idx,
   &the_linux_target,
 };
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 582d5c1924d..7d8931598b3 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -480,6 +480,8 @@ public:
 #endif
 
   bool supports_software_single_step () override;
+
+  bool supports_catch_syscall () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index ab4238cf373..888adb1cfb6 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -742,7 +742,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* supports_catch_syscall */
   NULL,  /* get_ipa_tdesc_idx */
   &the_lynx_target,
 };
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 192d6a53ba8..b3d80c48f33 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_process_target::sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* supports_catch_syscall */
   NULL, /* get_ipa_tdesc_idx */
   &the_nto_target,
 };
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 03145cce280..16c1d661f6c 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -820,3 +820,9 @@ process_target::supports_software_single_step ()
 {
   return false;
 }
+
+bool
+process_target::supports_catch_syscall ()
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 8854bf3791f..b825cbd53a7 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return 1 if the target supports catch syscall, 0 (or leave the
-     callback NULL) otherwise.  */
-  int (*supports_catch_syscall) (void);
-
   /* Return tdesc index for IPA.  */
   int (*get_ipa_tdesc_idx) (void);
 
@@ -505,6 +501,9 @@ public:
 
   /* Returns true if the target can software single step.  */
   virtual bool supports_software_single_step ();
+
+  /* Return true if the target supports catch syscall.  */
+  virtual bool supports_catch_syscall ();
 };
 
 extern process_stratum_target *the_target;
@@ -559,8 +558,7 @@ int kill_inferior (process_info *proc);
   the_target->pt->process_qsupported (features, count)
 
 #define target_supports_catch_syscall()              	\
-  (the_target->supports_catch_syscall ?			\
-   (*the_target->supports_catch_syscall) () : 0)
+  the_target->pt->supports_catch_syscall ()
 
 #define target_get_ipa_tdesc_idx()			\
   (the_target->get_ipa_tdesc_idx			\
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index c4c52e7b2aa..c45c81beff8 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,7 +1848,6 @@ win32_process_target::sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* supports_catch_syscall */
   NULL, /* get_ipa_tdesc_idx */
   &the_win32_target,
 };
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 49/58] gdbserver: turn target op 'supports_range_stepping' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (33 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 14/58] gdbserver: turn target ops 'read_memory' and 'write_memory' into methods Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 47/58] gdbserver: turn target op 'supports_agent' " Tankut Baris Aktemur
                   ` (24 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's supports_range_stepping op a method
	of process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_supports_range_stepping): Update the macro.
	* target.c (process_target::supports_range_stepping): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_supports_range_stepping): Turn into ...
	(linux_process_target::supports_range_stepping): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 9 ++++-----
 gdbserver/linux-low.h | 2 ++
 gdbserver/lynx-low.c  | 1 -
 gdbserver/nto-low.c   | 1 -
 gdbserver/target.c    | 6 ++++++
 gdbserver/target.h    | 9 ++++-----
 gdbserver/win32-low.c | 1 -
 7 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 4cd18de5249..0d814bd7325 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6419,13 +6419,13 @@ linux_process_target::supports_agent ()
   return true;
 }
 
-static int
-linux_supports_range_stepping (void)
+bool
+linux_process_target::supports_range_stepping ()
 {
   if (can_software_single_step ())
-    return 1;
+    return true;
   if (*the_low_target.supports_range_stepping == NULL)
-    return 0;
+    return false;
 
   return (*the_low_target.supports_range_stepping) ();
 }
@@ -7460,7 +7460,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_supports_range_stepping,
   linux_proc_pid_to_exec_file,
   linux_mntns_open_cloexec,
   linux_mntns_unlink,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 090700cf011..f0618758941 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -449,6 +449,8 @@ public:
   int read_btrace_conf (const btrace_target_info *tinfo,
 			buffer *buf) override;
 #endif
+
+  bool supports_range_stepping () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index b2a5c2cc22b..066134d11d6 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* supports_range_stepping */
   NULL,  /* pid_to_exec_file */
   NULL,  /* multifs_open */
   NULL,  /* multifs_unlink */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 5978dbbc742..142edf71d77 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* supports_range_stepping */
   NULL, /* pid_to_exec_file */
   NULL, /* multifs_open */
   NULL, /* multifs_unlink */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 534508446b4..2c35fe5459b 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -753,3 +753,9 @@ process_target::read_btrace_conf (const btrace_target_info *tinfo,
 {
   error (_("Target does not support branch tracing."));
 }
+
+bool
+process_target::supports_range_stepping ()
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index d3a8cc9d581..c0c38331426 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return true if target supports range stepping.  */
-  int (*supports_range_stepping) (void);
-
   /* Return the full absolute name of the executable file that was
      run to create the process PID.  If the executable file cannot
      be determined, NULL is returned.  Otherwise, a pointer to a
@@ -498,6 +495,9 @@ public:
      otherwise.  */
   virtual int read_btrace_conf (const btrace_target_info *tinfo,
 				buffer *buf);
+
+  /* Return true if target supports range stepping.  */
+  virtual bool supports_range_stepping ();
 };
 
 extern process_stratum_target *the_target;
@@ -638,8 +638,7 @@ target_read_btrace_conf (struct btrace_target_info *tinfo,
 }
 
 #define target_supports_range_stepping() \
-  (the_target->supports_range_stepping ? \
-   (*the_target->supports_range_stepping) () : 0)
+  the_target->pt->supports_range_stepping ()
 
 #define target_supports_stopped_by_sw_breakpoint() \
   the_target->pt->supports_stopped_by_sw_breakpoint ()
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index d54bd2cfff1..55dbc3a3386 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,7 +1848,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* supports_range_stepping */
   NULL, /* pid_to_exec_file */
   NULL, /* multifs_open */
   NULL, /* multifs_unlink */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 57/58] gdbserver: use unique_ptr for 'the_target'
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (44 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 31/58] gdbserver: turn target ops 'supports_{fork,vfork,exec}_events' into methods Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11 16:43   ` Christian Biesinger via gdb-patches
  2020-02-13 20:31   ` Pedro Alves
  2020-02-11  9:04 ` [PATCH 38/58] gdbserver: turn target ops 'read_pc' and 'write_pc' into methods Tankut Baris Aktemur
                   ` (13 subsequent siblings)
  59 siblings, 2 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

The target op vector is about to be replaced with a process_target
object.  In the current state, the 'set_target_ops' function takes a
target op vector and creates a clone of it via XNEW and memcpy.  As we
are now switching to using classes and polymorphism, this memcpy'ing
will no longer be possible.  For proper memory managament, switch to
using a unique_ptr.

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* target.h (set_target_ops): Remove.
	(<the_target>): Change the type to
	std::unique_ptr<process_stratum_target>.
	* target.c (set_target_ops): Remove.
	(done_accessing_memory): Update the usage of the_target.
	* fork-child.c (post_fork_inferior): Update the usage of
	the_target.
	* remote-utils.c (prepare_resume_reply): Ditto.
	* linux-low.c (initialize_low): Set the value of the_target.
	(struct linux_target_ops): Delete.
	* lynx-low.c (initialize_low): Set the value of the_target.
	(struct lynx_target_ops): Delete.
	* nto-low.c (initialize_low): Set the value of the_target.
	(struct nto_target_ops): Delete.
	* win32-low.c (initialize_low): Set the value of the_target.
	(struct win32_target_ops): Delete.
---
 gdbserver/fork-child.c   |  2 +-
 gdbserver/linux-low.c    |  7 ++-----
 gdbserver/lynx-low.c     |  9 ++-------
 gdbserver/nto-low.c      |  8 ++------
 gdbserver/remote-utils.c |  2 +-
 gdbserver/target.c       | 11 ++---------
 gdbserver/target.h       |  4 +---
 gdbserver/win32-low.c    |  7 ++-----
 8 files changed, 13 insertions(+), 37 deletions(-)

diff --git a/gdbserver/fork-child.c b/gdbserver/fork-child.c
index 7a71ec0b1ca..3702c1a8c2e 100644
--- a/gdbserver/fork-child.c
+++ b/gdbserver/fork-child.c
@@ -107,7 +107,7 @@ post_fork_inferior (int pid, const char *program)
   atexit (restore_old_foreground_pgrp);
 #endif
 
-  startup_inferior (the_target, pid,
+  startup_inferior (the_target.get (), pid,
 		    START_INFERIOR_TRAPS_EXPECTED,
 		    &cs.last_status, &cs.last_ptid);
   current_thread->last_resume_kind = resume_stop;
diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index cd84cef326a..87cf2fd8afb 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -7512,10 +7512,6 @@ linux_get_hwcap2 (int wordsize)
 
 static linux_process_target the_linux_target;
 
-static process_stratum_target linux_target_ops = {
-  &the_linux_target,
-};
-
 #ifdef HAVE_LINUX_REGSETS
 void
 initialize_regsets_info (struct regsets_info *info)
@@ -7533,7 +7529,8 @@ initialize_low (void)
   struct sigaction sigchld_action;
 
   memset (&sigchld_action, 0, sizeof (sigchld_action));
-  set_target_ops (&linux_target_ops);
+  the_target.reset (new process_stratum_target);
+  the_target->pt = &the_linux_target;
 
   linux_ptrace_init_warnings ();
   linux_proc_init_warnings ();
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 778afd190b6..1377ccaf4ae 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -739,16 +739,11 @@ lynx_process_target::sw_breakpoint_from_kind (int kind, int *size)
 
 static lynx_process_target the_lynx_target;
 
-/* The LynxOS target_ops vector.  */
-
-static process_stratum_target lynx_target_ops = {
-  &the_lynx_target,
-};
-
 void
 initialize_low (void)
 {
-  set_target_ops (&lynx_target_ops);
+  the_target.reset (new process_stratum_target);
+  the_target->pt = &the_lynx_target;
   the_low_target.arch_setup ();
 }
 
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index cd461be8378..bbcc5046659 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -946,11 +946,6 @@ nto_process_target::sw_breakpoint_from_kind (int kind, int *size)
 
 static nto_process_target the_nto_target;
 
-static process_stratum_target nto_target_ops = {
-  &the_nto_target,
-};
-
-
 /* Global function called by server.c.  Initializes QNX Neutrino
    gdbserver.  */
 
@@ -960,7 +955,8 @@ initialize_low (void)
   sigset_t set;
 
   TRACE ("%s\n", __func__);
-  set_target_ops (&nto_target_ops);
+  the_target.reset (new process_stratum_target);
+  the_target->pt = &the_nto_target;
 
   /* We use SIGUSR1 to gain control after we block waiting for a process.
      We use sigwaitevent to wait.  */
diff --git a/gdbserver/remote-utils.c b/gdbserver/remote-utils.c
index 316f04e32ee..14e89332db4 100644
--- a/gdbserver/remote-utils.c
+++ b/gdbserver/remote-utils.c
@@ -1208,7 +1208,7 @@ prepare_resume_reply (char *buf, ptid_t ptid,
 
 	saved_thread = current_thread;
 
-	switch_to_thread (the_target, ptid);
+	switch_to_thread (the_target.get (), ptid);
 
 	regp = current_target_desc ()->expedite_regs;
 
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 5c80a379f65..048fd5ad6e9 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -27,7 +27,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-process_stratum_target *the_target;
+std::unique_ptr<process_stratum_target> the_target;
 
 int
 set_desired_thread ()
@@ -118,7 +118,7 @@ done_accessing_memory (void)
 
   /* Restore the previous selected thread.  */
   cs.general_thread = prev_general_thread;
-  switch_to_thread (the_target, cs.general_thread);
+  switch_to_thread (the_target.get (), cs.general_thread);
 }
 
 int
@@ -267,13 +267,6 @@ target_supports_multi_process (void)
   return the_target->pt->supports_multi_process ();
 }
 
-void
-set_target_ops (process_stratum_target *target)
-{
-  the_target = XNEW (process_stratum_target);
-  memcpy (the_target, target, sizeof (*the_target));
-}
-
 /* Convert pid to printable format.  */
 
 const char *
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 1b5059c1beb..ac0ada0cd38 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -506,9 +506,7 @@ public:
   virtual int get_ipa_tdesc_idx ();
 };
 
-extern process_stratum_target *the_target;
-
-void set_target_ops (process_stratum_target *);
+extern std::unique_ptr<process_stratum_target> the_target;
 
 #define target_create_inferior(program, program_args)	\
   the_target->pt->create_inferior (program, program_args)
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 567e2ebe3db..5b4dd36f5d0 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1847,14 +1847,11 @@ win32_process_target::sw_breakpoint_from_kind (int kind, int *size)
 
 static win32_process_target the_win32_target;
 
-static process_stratum_target win32_target_ops = {
-  &the_win32_target,
-};
-
 /* Initialize the Win32 backend.  */
 void
 initialize_low (void)
 {
-  set_target_ops (&win32_target_ops);
+  the_target.reset (new process_stratum_target);
+  the_target->pt = &the_win32_target;
   the_low_target.arch_setup ();
 }
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 31/58] gdbserver: turn target ops 'supports_{fork,vfork,exec}_events' into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (43 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 56/58] gdbserver: turn target op 'get_ipa_tdesc_idx' into a method Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 57/58] gdbserver: use unique_ptr for 'the_target' Tankut Baris Aktemur
                   ` (14 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's supports_fork_events,
	supports_vfork_events, and supports_exec_events ops
	methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	(target_supports_fork_events): Update the macro.
	(target_supports_vfork_events): Update the macro.
	(target_supports_exec_events): Update the macro.
	* target.c (process_target::supports_fork_events): Define.
	(process_target::supports_vfork_events): Define.
	(process_target::supports_exec_events): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_supports_fork_events): Turn into ...
	(linux_process_target::supports_fork_events): ... this.
	(linux_supports_vfork_events): Turn into ...
	(linux_process_target::supports_vfork_events): ... this.
	(linux_supports_exec_events): Turn into ...
	(linux_process_target::supports_exec_events): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 15 ++++++---------
 gdbserver/linux-low.h |  6 ++++++
 gdbserver/lynx-low.c  |  3 ---
 gdbserver/nto-low.c   |  3 ---
 gdbserver/target.c    | 18 ++++++++++++++++++
 gdbserver/target.h    | 27 ++++++++++++---------------
 gdbserver/win32-low.c |  3 ---
 7 files changed, 42 insertions(+), 33 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 30c65bf0bfd..0d133eb856e 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6335,24 +6335,24 @@ linux_process_target::supports_multi_process ()
 
 /* Check if fork events are supported.  */
 
-static int
-linux_supports_fork_events (void)
+bool
+linux_process_target::supports_fork_events ()
 {
   return linux_supports_tracefork ();
 }
 
 /* Check if vfork events are supported.  */
 
-static int
-linux_supports_vfork_events (void)
+bool
+linux_process_target::supports_vfork_events ()
 {
   return linux_supports_tracefork ();
 }
 
 /* Check if exec events are supported.  */
 
-static int
-linux_supports_exec_events (void)
+bool
+linux_process_target::supports_exec_events ()
 {
   return linux_supports_traceexec ();
 }
@@ -7418,9 +7418,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_supports_fork_events,
-  linux_supports_vfork_events,
-  linux_supports_exec_events,
   linux_handle_new_gdb_connection,
 #ifdef USE_THREAD_DB
   thread_db_handle_monitor_command,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index ed3546f4356..d6482311829 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -368,6 +368,12 @@ public:
   int start_non_stop (bool enable) override;
 
   bool supports_multi_process () override;
+
+  bool supports_fork_events () override;
+
+  bool supports_vfork_events () override;
+
+  bool supports_exec_events () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 11179ce3c4e..eaca6cde875 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,9 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* supports_fork_events */
-  NULL,  /* supports_vfork_events */
-  NULL,  /* supports_exec_events */
   NULL,  /* handle_new_gdb_connection */
   NULL,  /* handle_monitor_command */
   NULL,  /* core_of_thread */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index a26c6696104..9ae100f9000 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,9 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* supports_fork_events */
-  NULL, /* supports_vfork_events */
-  NULL, /* supports_exec_events */
   NULL, /* handle_new_gdb_connection */
   NULL, /* handle_monitor_command */
   NULL, /* core_of_thread */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 485eecbee91..15d48427f31 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -553,3 +553,21 @@ process_target::supports_multi_process ()
 {
   return false;
 }
+
+bool
+process_target::supports_fork_events ()
+{
+  return false;
+}
+
+bool
+process_target::supports_vfork_events ()
+{
+  return false;
+}
+
+bool
+process_target::supports_exec_events ()
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index b9e36af456f..ff09b1f9618 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,15 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Returns true if fork events are supported.  */
-  int (*supports_fork_events) (void);
-
-  /* Returns true if vfork events are supported.  */
-  int (*supports_vfork_events) (void);
-
-  /* Returns true if exec events are supported.  */
-  int (*supports_exec_events) (void);
-
   /* Allows target to re-initialize connection-specific settings.  */
   void (*handle_new_gdb_connection) (void);
 
@@ -486,6 +477,15 @@ public:
 
   /* Returns true if the target supports multi-process debugging.  */
   virtual bool supports_multi_process ();
+
+  /* Returns true if fork events are supported.  */
+  virtual bool supports_fork_events ();
+
+  /* Returns true if vfork events are supported.  */
+  virtual bool supports_vfork_events ();
+
+  /* Returns true if exec events are supported.  */
+  virtual bool supports_exec_events ();
 };
 
 extern process_stratum_target *the_target;
@@ -504,16 +504,13 @@ void set_target_ops (process_stratum_target *);
 int kill_inferior (process_info *proc);
 
 #define target_supports_fork_events() \
-  (the_target->supports_fork_events ? \
-   (*the_target->supports_fork_events) () : 0)
+  the_target->pt->supports_fork_events ()
 
 #define target_supports_vfork_events() \
-  (the_target->supports_vfork_events ? \
-   (*the_target->supports_vfork_events) () : 0)
+  the_target->pt->supports_vfork_events ()
 
 #define target_supports_exec_events() \
-  (the_target->supports_exec_events ? \
-   (*the_target->supports_exec_events) () : 0)
+  the_target->pt->supports_exec_events ()
 
 #define target_handle_new_gdb_connection()		 \
   do							 \
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 8d6fba16240..a60b223beb4 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1842,9 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* supports_fork_events */
-  NULL, /* supports_vfork_events */
-  NULL, /* supports_exec_events */
   NULL, /* handle_new_gdb_connection */
   NULL, /* handle_monitor_command */
   NULL, /* core_of_thread */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 50/58] gdbserver: turn target op 'pid_to_exec_file' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (46 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 38/58] gdbserver: turn target ops 'read_pc' and 'write_pc' into methods Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 55/58] gdbserver: turn target op 'supports_catch_syscall' " Tankut Baris Aktemur
                   ` (11 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's pid_to_exec_file op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.  Also add
	'supports_pid_to_exec_file'.
	* target.c (process_target::pid_to_exec_file): Define.
	(process_target::supports_pid_to_exec_file): Define.

	Update the derived structs and callers below.

	* server.c (handle_qxfer_exec_file): Update.
	(handle_query): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::supports_pid_to_exec_file): Define.
	(linux_process_target::pid_to_exec_file): Define.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 13 ++++++++++++-
 gdbserver/linux-low.h |  4 ++++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/server.c    |  6 +++---
 gdbserver/target.c    | 12 ++++++++++++
 gdbserver/target.h    | 19 +++++++++++--------
 gdbserver/win32-low.c |  1 -
 8 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 0d814bd7325..476ad1c5eaa 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6430,6 +6430,18 @@ linux_process_target::supports_range_stepping ()
   return (*the_low_target.supports_range_stepping) ();
 }
 
+bool
+linux_process_target::supports_pid_to_exec_file ()
+{
+  return true;
+}
+
+char *
+linux_process_target::pid_to_exec_file (int pid)
+{
+  return linux_proc_pid_to_exec_file (pid);
+}
+
 #if defined PT_GETDSBT || defined PTRACE_GETFDPIC
 struct target_loadseg
 {
@@ -7460,7 +7472,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_proc_pid_to_exec_file,
   linux_mntns_open_cloexec,
   linux_mntns_unlink,
   linux_mntns_readlink,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index f0618758941..cb11c199033 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -451,6 +451,10 @@ public:
 #endif
 
   bool supports_range_stepping () override;
+
+  bool supports_pid_to_exec_file () override;
+
+  char *pid_to_exec_file (int pid) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 066134d11d6..132087ce7ea 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* pid_to_exec_file */
   NULL,  /* multifs_open */
   NULL,  /* multifs_unlink */
   NULL,  /* multifs_readlink */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 142edf71d77..8927293d75d 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* pid_to_exec_file */
   NULL, /* multifs_open */
   NULL, /* multifs_unlink */
   NULL, /* multifs_readlink */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index 61346e3ce5b..00456d8d7ed 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -1462,7 +1462,7 @@ handle_qxfer_exec_file (const char *annex,
   ULONGEST pid;
   int total_len;
 
-  if (the_target->pid_to_exec_file == NULL || writebuf != NULL)
+  if (!the_target->pt->supports_pid_to_exec_file () || writebuf != NULL)
     return -2;
 
   if (annex[0] == '\0')
@@ -1482,7 +1482,7 @@ handle_qxfer_exec_file (const char *annex,
   if (pid <= 0)
     return -1;
 
-  file = (*the_target->pid_to_exec_file) (pid);
+  file = the_target->pt->pid_to_exec_file (pid);
   if (file == NULL)
     return -1;
 
@@ -2452,7 +2452,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (target_supports_stopped_by_hw_breakpoint ())
 	strcat (own_buf, ";hwbreak+");
 
-      if (the_target->pid_to_exec_file != NULL)
+      if (the_target->pt->supports_pid_to_exec_file ())
 	strcat (own_buf, ";qXfer:exec-file:read+");
 
       strcat (own_buf, ";vContSupported+");
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 2c35fe5459b..b1c318f59b8 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -759,3 +759,15 @@ process_target::supports_range_stepping ()
 {
   return false;
 }
+
+bool
+process_target::supports_pid_to_exec_file ()
+{
+  return false;
+}
+
+char *
+process_target::pid_to_exec_file (int pid)
+{
+  gdb_assert_not_reached ("target op pid_to_exec_file not supported");
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index c0c38331426..6de6c3cdaec 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,14 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return the full absolute name of the executable file that was
-     run to create the process PID.  If the executable file cannot
-     be determined, NULL is returned.  Otherwise, a pointer to a
-     character string containing the pathname is returned.  This
-     string should be copied into a buffer by the client if the string
-     will not be immediately used, or if it must persist.  */
-  char *(*pid_to_exec_file) (int pid);
-
   /* Multiple-filesystem-aware open.  Like open(2), but operating in
      the filesystem as it appears to process PID.  Systems where all
      processes share a common filesystem should set this to NULL.
@@ -498,6 +490,17 @@ public:
 
   /* Return true if target supports range stepping.  */
   virtual bool supports_range_stepping ();
+
+  /* Return true if the pid_to_exec_file op is supported.  */
+  virtual bool supports_pid_to_exec_file ();
+
+  /* Return the full absolute name of the executable file that was
+     run to create the process PID.  If the executable file cannot
+     be determined, NULL is returned.  Otherwise, a pointer to a
+     character string containing the pathname is returned.  This
+     string should be copied into a buffer by the client if the string
+     will not be immediately used, or if it must persist.  */
+  virtual char *pid_to_exec_file (int pid);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 55dbc3a3386..d5e15202ae1 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,7 +1848,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* pid_to_exec_file */
   NULL, /* multifs_open */
   NULL, /* multifs_unlink */
   NULL, /* multifs_readlink */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 56/58] gdbserver: turn target op 'get_ipa_tdesc_idx' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (42 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 53/58] gdbserver: turn target ops 'thread_name' and 'thread_handle' into methods Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 31/58] gdbserver: turn target ops 'supports_{fork,vfork,exec}_events' into methods Tankut Baris Aktemur
                   ` (15 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's get_ipa_tdesc_idx op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_get_ipa_tdesc_idx): Update the macro.
	* target.c (process_target::get_ipa_tdesc_idx): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_get_ipa_tdesc_idx): Turn into ...
	(linux_process_target::get_ipa_tdesc_idx): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 5 ++---
 gdbserver/linux-low.h | 2 ++
 gdbserver/lynx-low.c  | 1 -
 gdbserver/nto-low.c   | 1 -
 gdbserver/target.c    | 6 ++++++
 gdbserver/target.h    | 9 ++++-----
 gdbserver/win32-low.c | 1 -
 7 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 4cbb82429a7..cd84cef326a 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6564,8 +6564,8 @@ linux_process_target::supports_catch_syscall ()
 	  && linux_supports_tracesysgood ());
 }
 
-static int
-linux_get_ipa_tdesc_idx (void)
+int
+linux_process_target::get_ipa_tdesc_idx ()
 {
   if (the_low_target.get_ipa_tdesc_idx == NULL)
     return 0;
@@ -7513,7 +7513,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_get_ipa_tdesc_idx,
   &the_linux_target,
 };
 
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 7d8931598b3..b1960645939 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -482,6 +482,8 @@ public:
   bool supports_software_single_step () override;
 
   bool supports_catch_syscall () override;
+
+  int get_ipa_tdesc_idx () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 888adb1cfb6..778afd190b6 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -742,7 +742,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* get_ipa_tdesc_idx */
   &the_lynx_target,
 };
 
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index b3d80c48f33..cd461be8378 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_process_target::sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* get_ipa_tdesc_idx */
   &the_nto_target,
 };
 
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 16c1d661f6c..5c80a379f65 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -826,3 +826,9 @@ process_target::supports_catch_syscall ()
 {
   return false;
 }
+
+int
+process_target::get_ipa_tdesc_idx ()
+{
+  return 0;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index b825cbd53a7..1b5059c1beb 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return tdesc index for IPA.  */
-  int (*get_ipa_tdesc_idx) (void);
-
   /* The object that will gradually replace this struct.  */
   process_target *pt;
 };
@@ -504,6 +501,9 @@ public:
 
   /* Return true if the target supports catch syscall.  */
   virtual bool supports_catch_syscall ();
+
+  /* Return tdesc index for IPA.  */
+  virtual int get_ipa_tdesc_idx ();
 };
 
 extern process_stratum_target *the_target;
@@ -561,8 +561,7 @@ int kill_inferior (process_info *proc);
   the_target->pt->supports_catch_syscall ()
 
 #define target_get_ipa_tdesc_idx()			\
-  (the_target->get_ipa_tdesc_idx			\
-   ? (*the_target->get_ipa_tdesc_idx) () : 0)
+  the_target->pt->get_ipa_tdesc_idx ()
 
 #define target_supports_tracepoints()			\
   the_target->pt->supports_tracepoints ()
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index c45c81beff8..567e2ebe3db 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,7 +1848,6 @@ win32_process_target::sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* get_ipa_tdesc_idx */
   &the_win32_target,
 };
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 52/58] gdbserver: turn breakpoint kind-related target ops into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (36 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 39/58] gdbserver: turn target op 'thread_stopped' " Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-13 20:29   ` Pedro Alves
  2020-02-11  9:04 ` [PATCH 34/58] gdbserver: turn target op 'core_of_thread' into a method Tankut Baris Aktemur
                   ` (21 subsequent siblings)
  59 siblings, 1 reply; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's breakpoint_kind_from_pc,
	sw_breakpoint_from_kind, and breakpoint_kind_from_current_state
	ops methods ofprocess_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_breakpoint_kind_from_pc): Update the macro.
	(target_breakpoint_kind_from_current_state): Update the macro.
	(default_breakpoint_kind_from_pc): Remove declaration.
	* target.c (default_breakpoint_kind_from_pc): Turn into ...
	(process_target::breakpoint_kind_from_pc): ... this.
	(process_target::breakpoint_kind_from_current_state): Define.

	Update the derived structs and callers below.

	* mem-break.c (bp_size): Update.
	(bp_opcode): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_wait_1): Update.
	(linux_breakpoint_kind_from_pc): Turn into ...
	(linux_process_target::breakpoint_kind_from_pc): ... this.
	(linux_sw_breakpoint_from_kind): Turn into ...
	(linux_process_target::sw_breakpoint_from_kind): ... this.
	(linux_breakpoint_kind_from_current_state): Turn into ...
	(linux_process_target::breakpoint_kind_from_current_state): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_process_target::sw_breakpoint_from_kind): Define.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_sw_breakpoint_from_kind): Turn into ...
	(nto_process_target::sw_breakpoint_from_kind): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_sw_breakpoint_from_kind): Turn iwin32 ...
	(win32_process_target::sw_breakpoint_from_kind): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c | 23 ++++++++++-------------
 gdbserver/linux-low.h |  6 ++++++
 gdbserver/lynx-low.c  | 10 +++++++---
 gdbserver/lynx-low.h  |  2 ++
 gdbserver/mem-break.c |  4 ++--
 gdbserver/nto-low.c   |  7 ++-----
 gdbserver/nto-low.h   |  2 ++
 gdbserver/target.c    | 32 ++++++++++++++++----------------
 gdbserver/target.h    | 42 ++++++++++++++++++------------------------
 gdbserver/win32-low.c |  7 ++-----
 gdbserver/win32-low.h |  2 ++
 11 files changed, 69 insertions(+), 68 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index b19c3458bc5..de011c126c0 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -3218,8 +3218,8 @@ linux_wait_1 (ptid_t ptid,
       CORE_ADDR stop_pc = event_child->stop_pc;
 
       breakpoint_kind =
-	the_target->breakpoint_kind_from_current_state (&stop_pc);
-      the_target->sw_breakpoint_from_kind (breakpoint_kind, &increment_pc);
+	the_target->pt->breakpoint_kind_from_current_state (&stop_pc);
+      the_target->pt->sw_breakpoint_from_kind (breakpoint_kind, &increment_pc);
 
       if (debug_threads)
 	{
@@ -7355,19 +7355,19 @@ current_lwp_ptid (void)
 
 /* Implementation of the target_ops method "breakpoint_kind_from_pc".  */
 
-static int
-linux_breakpoint_kind_from_pc (CORE_ADDR *pcptr)
+int
+linux_process_target::breakpoint_kind_from_pc (CORE_ADDR *pcptr)
 {
   if (the_low_target.breakpoint_kind_from_pc != NULL)
     return (*the_low_target.breakpoint_kind_from_pc) (pcptr);
   else
-    return default_breakpoint_kind_from_pc (pcptr);
+    return process_target::breakpoint_kind_from_pc (pcptr);
 }
 
 /* Implementation of the target_ops method "sw_breakpoint_from_kind".  */
 
-static const gdb_byte *
-linux_sw_breakpoint_from_kind (int kind, int *size)
+const gdb_byte *
+linux_process_target::sw_breakpoint_from_kind (int kind, int *size)
 {
   gdb_assert (the_low_target.sw_breakpoint_from_kind != NULL);
 
@@ -7377,13 +7377,13 @@ linux_sw_breakpoint_from_kind (int kind, int *size)
 /* Implementation of the target_ops method
    "breakpoint_kind_from_current_state".  */
 
-static int
-linux_breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
+int
+linux_process_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
 {
   if (the_low_target.breakpoint_kind_from_current_state != NULL)
     return (*the_low_target.breakpoint_kind_from_current_state) (pcptr);
   else
-    return linux_breakpoint_kind_from_pc (pcptr);
+    return breakpoint_kind_from_pc (pcptr);
 }
 
 /* Default implementation of linux_target_ops method "set_pc" for
@@ -7498,10 +7498,7 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_breakpoint_kind_from_pc,
-  linux_sw_breakpoint_from_kind,
   linux_proc_tid_get_name,
-  linux_breakpoint_kind_from_current_state,
   linux_supports_software_single_step,
   linux_supports_catch_syscall,
   linux_get_ipa_tdesc_idx,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 7ee9c0c03d0..6a531ed3aab 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -465,6 +465,12 @@ public:
 
   ssize_t multifs_readlink (int pid, const char *filename, char *buf,
 			    size_t bufsiz) override;
+
+  int breakpoint_kind_from_pc (CORE_ADDR *pcptr) override;
+
+  const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
+
+  int breakpoint_kind_from_current_state (CORE_ADDR *pcptr) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 11a7ab9e6a6..aa4c5b24b0e 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -728,6 +728,13 @@ lynx_process_target::supports_hardware_single_step ()
   return true;
 }
 
+const gdb_byte *
+lynx_process_target::sw_breakpoint_from_kind (int kind, int *size)
+{
+  error (_("Target does not implement the sw_breakpoint_from_kind op"));
+  return nullptr;
+}
+
 /* The LynxOS target ops object.  */
 
 static lynx_process_target the_lynx_target;
@@ -735,10 +742,7 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* breakpoint_kind_from_pc */
-  NULL,  /* sw_breakpoint_from_kind */
   NULL,  /* thread_name */
-  NULL,  /* breakpoint_kind_from_current_state */
   NULL,  /* supports_software_single_step */
   NULL,  /* supports_catch_syscall */
   NULL,  /* get_ipa_tdesc_idx */
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index 4f542118704..d4d265ca2f3 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -90,6 +90,8 @@ public:
   void request_interrupt () override;
 
   bool supports_hardware_single_step () override;
+
+  const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/mem-break.c b/gdbserver/mem-break.c
index 682b3bc1832..3802d72a573 100644
--- a/gdbserver/mem-break.c
+++ b/gdbserver/mem-break.c
@@ -223,7 +223,7 @@ bp_size (struct raw_breakpoint *bp)
 {
   int size = 0;
 
-  the_target->sw_breakpoint_from_kind (bp->kind, &size);
+  the_target->pt->sw_breakpoint_from_kind (bp->kind, &size);
   return size;
 }
 
@@ -234,7 +234,7 @@ bp_opcode (struct raw_breakpoint *bp)
 {
   int size = 0;
 
-  return the_target->sw_breakpoint_from_kind (bp->kind, &size);
+  return the_target->pt->sw_breakpoint_from_kind (bp->kind, &size);
 }
 
 /* See mem-break.h.  */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index f5919baa5cb..3e2e8eaa521 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -935,8 +935,8 @@ nto_process_target::stopped_data_address ()
 
 /* Implementation of the target_ops method "sw_breakpoint_from_kind".  */
 
-static const gdb_byte *
-nto_sw_breakpoint_from_kind (int kind, int *size)
+const gdb_byte *
+nto_process_target::sw_breakpoint_from_kind (int kind, int *size)
 {
   *size = the_low_target.breakpoint_len;
   return the_low_target.breakpoint;
@@ -947,10 +947,7 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* breakpoint_kind_from_pc */
-  nto_sw_breakpoint_from_kind,
   NULL, /* thread_name */
-  NULL, /* breakpoint_kind_from_current_state */
   NULL, /* supports_software_single_step */
   NULL, /* supports_catch_syscall */
   NULL, /* get_ipa_tdesc_idx */
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index ad60bf913bf..be4634079ad 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -97,6 +97,8 @@ public:
   bool stopped_by_watchpoint () override;
 
   CORE_ADDR stopped_data_address () override;
+
+  const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 39e763dffc8..a29c9fda4eb 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -306,22 +306,6 @@ kill_inferior (process_info *proc)
   return the_target->pt->kill (proc);
 }
 
-/* Default implementation for breakpoint_kind_for_pc.
-
-   The default behavior for targets that don't implement breakpoint_kind_for_pc
-   is to use the size of a breakpoint as the kind.  */
-
-int
-default_breakpoint_kind_from_pc (CORE_ADDR *pcptr)
-{
-  int size = 0;
-
-  gdb_assert (the_target->sw_breakpoint_from_kind != NULL);
-
-  (*the_target->sw_breakpoint_from_kind) (0, &size);
-  return size;
-}
-
 /* Define it.  */
 
 target_terminal_state target_terminal::m_terminal_state
@@ -801,3 +785,19 @@ process_target::multifs_readlink (int pid, const char *filename,
 {
   return readlink (filename, buf, bufsiz);
 }
+
+int
+process_target::breakpoint_kind_from_pc (CORE_ADDR *pcptr)
+{
+  /* The default behavior is to use the size of a breakpoint as the
+     kind.  */
+  int size = 0;
+  sw_breakpoint_from_kind (0, &size);
+  return size;
+}
+
+int
+process_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
+{
+  return breakpoint_kind_from_pc (pcptr);
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index f7f0e6b779c..8da04a58150 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,26 +70,10 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return the breakpoint kind for this target based on PC.  The PCPTR is
-     adjusted to the real memory location in case a flag (e.g., the Thumb bit on
-     ARM) was present in the PC.  */
-  int (*breakpoint_kind_from_pc) (CORE_ADDR *pcptr);
-
-  /* Return the software breakpoint from KIND.  KIND can have target
-     specific meaning like the Z0 kind parameter.
-     SIZE is set to the software breakpoint's length in memory.  */
-  const gdb_byte *(*sw_breakpoint_from_kind) (int kind, int *size);
-
   /* Return the thread's name, or NULL if the target is unable to determine it.
      The returned value must not be freed by the caller.  */
   const char *(*thread_name) (ptid_t thread);
 
-  /* Return the breakpoint kind for this target based on the current
-     processor state (e.g. the current instruction mode on ARM) and the
-     PC.  The PCPTR is adjusted to the real memory location in case a flag
-     (e.g., the Thumb bit on ARM) is present in the PC.  */
-  int (*breakpoint_kind_from_current_state) (CORE_ADDR *pcptr);
-
   /* Returns true if the target can software single step.  */
   int (*supports_software_single_step) (void);
 
@@ -503,6 +487,22 @@ public:
      not override this.  The default behavior is to use readlink(2).  */
   virtual ssize_t multifs_readlink (int pid, const char *filename,
 				    char *buf, size_t bufsiz);
+
+  /* Return the breakpoint kind for this target based on PC.  The
+     PCPTR is adjusted to the real memory location in case a flag
+     (e.g., the Thumb bit on ARM) was present in the PC.  */
+  virtual int breakpoint_kind_from_pc (CORE_ADDR *pcptr);
+
+  /* Return the software breakpoint from KIND.  KIND can have target
+     specific meaning like the Z0 kind parameter.
+     SIZE is set to the software breakpoint's length in memory.  */
+  virtual const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) = 0;
+
+  /* Return the breakpoint kind for this target based on the current
+     processor state (e.g. the current instruction mode on ARM) and the
+     PC.  The PCPTR is adjusted to the real memory location in case a
+     flag (e.g., the Thumb bit on ARM) is present in the  PC.  */
+  virtual int breakpoint_kind_from_current_state (CORE_ADDR *pcptr);
 };
 
 extern process_stratum_target *the_target;
@@ -661,14 +661,10 @@ target_read_btrace_conf (struct btrace_target_info *tinfo,
   the_target->pt->stopped_by_hw_breakpoint ()
 
 #define target_breakpoint_kind_from_pc(pcptr) \
-  (the_target->breakpoint_kind_from_pc \
-   ? (*the_target->breakpoint_kind_from_pc) (pcptr) \
-   : default_breakpoint_kind_from_pc (pcptr))
+  the_target->pt->breakpoint_kind_from_pc (pcptr)
 
 #define target_breakpoint_kind_from_current_state(pcptr) \
-  (the_target->breakpoint_kind_from_current_state \
-   ? (*the_target->breakpoint_kind_from_current_state) (pcptr) \
-   : target_breakpoint_kind_from_pc (pcptr))
+  the_target->pt->breakpoint_kind_from_current_state (pcptr)
 
 #define target_supports_software_single_step() \
   (the_target->supports_software_single_step ? \
@@ -701,6 +697,4 @@ int set_desired_thread ();
 
 const char *target_pid_to_str (ptid_t);
 
-int default_breakpoint_kind_from_pc (CORE_ADDR *pcptr);
-
 #endif /* GDBSERVER_TARGET_H */
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index ecece2d579c..017cfd3c245 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1836,8 +1836,8 @@ win32_process_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
 
 /* Implementation of the target_ops method "sw_breakpoint_from_kind".  */
 
-static const gdb_byte *
-win32_sw_breakpoint_from_kind (int kind, int *size)
+const gdb_byte *
+win32_process_target::sw_breakpoint_from_kind (int kind, int *size)
 {
   *size = the_low_target.breakpoint_len;
   return the_low_target.breakpoint;
@@ -1848,10 +1848,7 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* breakpoint_kind_from_pc */
-  win32_sw_breakpoint_from_kind,
   NULL, /* thread_name */
-  NULL, /* breakpoint_kind_from_current_state */
   NULL, /* supports_software_single_step */
   NULL, /* supports_catch_syscall */
   NULL, /* get_ipa_tdesc_idx */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index fcd50e2a45b..dc0bdcc714a 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -165,6 +165,8 @@ public:
   bool supports_get_tib_address () override;
 
   int get_tib_address (ptid_t ptid, CORE_ADDR *addr) override;
+
+  const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 47/58] gdbserver: turn target op 'supports_agent' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (34 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 49/58] gdbserver: turn target op 'supports_range_stepping' into a method Tankut Baris Aktemur
@ 2020-02-11  9:04 ` Tankut Baris Aktemur
  2020-02-11  9:04 ` [PATCH 39/58] gdbserver: turn target op 'thread_stopped' " Tankut Baris Aktemur
                   ` (23 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:04 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's supports_agent op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_supports_agent): Update the macro.
	* target.c (process_target::supports_agent): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_supports_agent): Turn into ...
	(linux_process_target::supports_agent): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 7 +++----
 gdbserver/linux-low.h | 2 ++
 gdbserver/lynx-low.c  | 1 -
 gdbserver/nto-low.c   | 1 -
 gdbserver/target.c    | 6 ++++++
 gdbserver/target.h    | 9 ++++-----
 gdbserver/win32-low.c | 1 -
 7 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index fcca23f0510..5a3390bff54 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6413,10 +6413,10 @@ linux_process_target::supports_disable_randomization ()
 #endif
 }
 
-static int
-linux_supports_agent (void)
+bool
+linux_process_target::supports_agent ()
 {
-  return 1;
+  return true;
 }
 
 static int
@@ -7452,7 +7452,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_supports_agent,
 #ifdef HAVE_LINUX_BTRACE
   linux_enable_btrace,
   linux_low_disable_btrace,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index e0938fdf340..63cb52e9204 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -434,6 +434,8 @@ public:
 			    unsigned char *readbuf,
 			    unsigned const char *writebuf,
 			    CORE_ADDR offset, int len) override;
+
+  bool supports_agent () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 43fa36c5fbd..bfa76cf7de6 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* support_agent */
   NULL,  /* enable_btrace */
   NULL,  /* disable_btrace */
   NULL,  /* read_btrace */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 7940325c3b5..e97ebe395f7 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* support_agent */
   NULL, /* enable_btrace */
   NULL, /* disable_btrace */
   NULL, /* read_btrace */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 34b3ffd1cfd..3e4d9730b6f 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -720,3 +720,9 @@ process_target::qxfer_libraries_svr4 (const char *annex,
 {
   gdb_assert_not_reached ("target op qxfer_libraries_svr4 not supported");
 }
+
+bool
+process_target::supports_agent ()
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 3e90227c4fd..a89f7b14269 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return true if target supports debugging agent.  */
-  int (*supports_agent) (void);
-
   /* Enable branch tracing for PTID based on CONF and allocate a branch trace
      target information struct for reading and for disabling branch trace.  */
   struct btrace_target_info *(*enable_btrace)
@@ -497,6 +494,9 @@ public:
 				    unsigned char *readbuf,
 				    unsigned const char *writebuf,
 				    CORE_ADDR offset, int len);
+
+  /* Return true if target supports debugging agent.  */
+  virtual bool supports_agent ();
 };
 
 extern process_stratum_target *the_target;
@@ -607,8 +607,7 @@ int kill_inferior (process_info *proc);
   the_target->pt->supports_disable_randomization ()
 
 #define target_supports_agent() \
-  (the_target->supports_agent ? \
-   (*the_target->supports_agent) () : 0)
+  the_target->pt->supports_agent ()
 
 static inline struct btrace_target_info *
 target_enable_btrace (ptid_t ptid, const struct btrace_config *conf)
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index f54d1bf0ef3..e24c6ced43d 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,7 +1848,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* support_agent */
   NULL, /* enable_btrace */
   NULL, /* disable_btrace */
   NULL, /* read_btrace */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 51/58] gdbserver: turn target ops 'multifs_{open, readlink, unlink}' into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (54 preceding siblings ...)
  2020-02-11  9:05 ` [PATCH 35/58] gdbserver: turn target op 'read_loadmap' " Tankut Baris Aktemur
@ 2020-02-11  9:05 ` Tankut Baris Aktemur
  2020-02-11  9:05 ` [PATCH 16/58] gdbserver: turn target op 'request_interrupt' into a method Tankut Baris Aktemur
                   ` (3 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:05 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's multifs_open, multifs_readlink,
	multifs_unlink ops methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.  Also add
	'supports_multifs'.
	* target.c: Include "fcntl.h", "unistd.h", "sys/types.h", and
	"sys/stat.h".
	(process_target::supports_multifs): Define.
	(process_target::multifs_open): Define.
	(process_target::multifs_readlink): Define.
	(process_target::multifs_unlink): Define.

	Update the derived structs and callers below.

	* hostio.c (handle_setfs): Update.
	(handle_open): Update.
	(handle_unlink): Update.
	(handle_readlink): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::supports_multifs): Define.
	(linux_process_target::multifs_open): Define.
	(linux_process_target::multifs_readlink): Define.
	(linux_process_target::multifs_unlink): Define.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/hostio.c    | 22 ++++++++++------------
 gdbserver/linux-low.c | 29 +++++++++++++++++++++++++---
 gdbserver/linux-low.h | 10 ++++++++++
 gdbserver/lynx-low.c  |  3 ---
 gdbserver/nto-low.c   |  3 ---
 gdbserver/target.c    | 30 +++++++++++++++++++++++++++++
 gdbserver/target.h    | 44 ++++++++++++++++++++++---------------------
 gdbserver/win32-low.c |  3 ---
 8 files changed, 99 insertions(+), 45 deletions(-)

diff --git a/gdbserver/hostio.c b/gdbserver/hostio.c
index a3b32cd0fdc..6223b24a887 100644
--- a/gdbserver/hostio.c
+++ b/gdbserver/hostio.c
@@ -272,9 +272,7 @@ handle_setfs (char *own_buf)
      then there's no point in GDB sending "vFile:setfs:" packets.  We
      reply with an empty packet (i.e. we pretend we don't understand
      "vFile:setfs:") and that should stop GDB sending any more.  */
-  if (the_target->multifs_open == NULL
-      && the_target->multifs_unlink == NULL
-      && the_target->multifs_readlink == NULL)
+  if (!the_target->pt->supports_multifs ())
     {
       own_buf[0] = '\0';
       return;
@@ -321,9 +319,9 @@ handle_open (char *own_buf)
 
   /* We do not need to convert MODE, since the fileio protocol
      uses the standard values.  */
-  if (hostio_fs_pid != 0 && the_target->multifs_open != NULL)
-    fd = the_target->multifs_open (hostio_fs_pid, filename,
-				   flags, mode);
+  if (hostio_fs_pid != 0)
+    fd = the_target->pt->multifs_open (hostio_fs_pid, filename,
+				       flags, mode);
   else
     fd = open (filename, flags, mode);
 
@@ -541,8 +539,8 @@ handle_unlink (char *own_buf)
       return;
     }
 
-  if (hostio_fs_pid != 0 && the_target->multifs_unlink != NULL)
-    ret = the_target->multifs_unlink (hostio_fs_pid, filename);
+  if (hostio_fs_pid != 0)
+    ret = the_target->pt->multifs_unlink (hostio_fs_pid, filename);
   else
     ret = unlink (filename);
 
@@ -571,10 +569,10 @@ handle_readlink (char *own_buf, int *new_packet_len)
       return;
     }
 
-  if (hostio_fs_pid != 0 && the_target->multifs_readlink != NULL)
-    ret = the_target->multifs_readlink (hostio_fs_pid, filename,
-					linkname,
-					sizeof (linkname) - 1);
+  if (hostio_fs_pid != 0)
+    ret = the_target->pt->multifs_readlink (hostio_fs_pid, filename,
+					    linkname,
+					    sizeof (linkname) - 1);
   else
     ret = readlink (filename, linkname, sizeof (linkname) - 1);
 
diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 476ad1c5eaa..b19c3458bc5 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6442,6 +6442,32 @@ linux_process_target::pid_to_exec_file (int pid)
   return linux_proc_pid_to_exec_file (pid);
 }
 
+bool
+linux_process_target::supports_multifs ()
+{
+  return true;
+}
+
+int
+linux_process_target::multifs_open (int pid, const char *filename,
+				    int flags, mode_t mode)
+{
+  return linux_mntns_open_cloexec (pid, filename, flags, mode);
+}
+
+int
+linux_process_target::multifs_unlink (int pid, const char *filename)
+{
+  return linux_mntns_unlink (pid, filename);
+}
+
+ssize_t
+linux_process_target::multifs_readlink (int pid, const char *filename,
+					char *buf, size_t bufsiz)
+{
+  return linux_mntns_readlink (pid, filename, buf, bufsiz);
+}
+
 #if defined PT_GETDSBT || defined PTRACE_GETFDPIC
 struct target_loadseg
 {
@@ -7472,9 +7498,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_mntns_open_cloexec,
-  linux_mntns_unlink,
-  linux_mntns_readlink,
   linux_breakpoint_kind_from_pc,
   linux_sw_breakpoint_from_kind,
   linux_proc_tid_get_name,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index cb11c199033..7ee9c0c03d0 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -455,6 +455,16 @@ public:
   bool supports_pid_to_exec_file () override;
 
   char *pid_to_exec_file (int pid) override;
+
+  bool supports_multifs () override;
+
+  int multifs_open (int pid, const char *filename, int flags,
+		    mode_t mode) override;
+
+  int multifs_unlink (int pid, const char *filename) override;
+
+  ssize_t multifs_readlink (int pid, const char *filename, char *buf,
+			    size_t bufsiz) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 132087ce7ea..11a7ab9e6a6 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,9 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* multifs_open */
-  NULL,  /* multifs_unlink */
-  NULL,  /* multifs_readlink */
   NULL,  /* breakpoint_kind_from_pc */
   NULL,  /* sw_breakpoint_from_kind */
   NULL,  /* thread_name */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 8927293d75d..f5919baa5cb 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,9 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* multifs_open */
-  NULL, /* multifs_unlink */
-  NULL, /* multifs_readlink */
   NULL, /* breakpoint_kind_from_pc */
   nto_sw_breakpoint_from_kind,
   NULL, /* thread_name */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index b1c318f59b8..39e763dffc8 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -22,6 +22,10 @@
 #include "tracepoint.h"
 #include "gdbsupport/byte-vector.h"
 #include "hostio.h"
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 process_stratum_target *the_target;
 
@@ -771,3 +775,29 @@ process_target::pid_to_exec_file (int pid)
 {
   gdb_assert_not_reached ("target op pid_to_exec_file not supported");
 }
+
+bool
+process_target::supports_multifs ()
+{
+  return false;
+}
+
+int
+process_target::multifs_open (int pid, const char *filename,
+			      int flags, mode_t mode)
+{
+  return open (filename, flags, mode);
+}
+
+int
+process_target::multifs_unlink (int pid, const char *filename)
+{
+  return unlink (filename);
+}
+
+ssize_t
+process_target::multifs_readlink (int pid, const char *filename,
+				  char *buf, size_t bufsiz)
+{
+  return readlink (filename, buf, bufsiz);
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 6de6c3cdaec..f7f0e6b779c 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,27 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Multiple-filesystem-aware open.  Like open(2), but operating in
-     the filesystem as it appears to process PID.  Systems where all
-     processes share a common filesystem should set this to NULL.
-     If NULL, the caller should fall back to open(2).  */
-  int (*multifs_open) (int pid, const char *filename,
-		       int flags, mode_t mode);
-
-  /* Multiple-filesystem-aware unlink.  Like unlink(2), but operates
-     in the filesystem as it appears to process PID.  Systems where
-     all processes share a common filesystem should set this to NULL.
-     If NULL, the caller should fall back to unlink(2).  */
-  int (*multifs_unlink) (int pid, const char *filename);
-
-  /* Multiple-filesystem-aware readlink.  Like readlink(2), but
-     operating in the filesystem as it appears to process PID.
-     Systems where all processes share a common filesystem should
-     set this to NULL.  If NULL, the caller should fall back to
-     readlink(2).  */
-  ssize_t (*multifs_readlink) (int pid, const char *filename,
-			       char *buf, size_t bufsiz);
-
   /* Return the breakpoint kind for this target based on PC.  The PCPTR is
      adjusted to the real memory location in case a flag (e.g., the Thumb bit on
      ARM) was present in the PC.  */
@@ -501,6 +480,29 @@ public:
      string should be copied into a buffer by the client if the string
      will not be immediately used, or if it must persist.  */
   virtual char *pid_to_exec_file (int pid);
+
+  /* Return true if any of the multifs ops is supported.  */
+  virtual bool supports_multifs ();
+
+  /* Multiple-filesystem-aware open.  Like open(2), but operating in
+     the filesystem as it appears to process PID.  Systems where all
+     processes share a common filesystem should not override this.
+     The default behavior is to use open(2).  */
+  virtual int multifs_open (int pid, const char *filename,
+			    int flags, mode_t mode);
+
+  /* Multiple-filesystem-aware unlink.  Like unlink(2), but operates
+     in the filesystem as it appears to process PID.  Systems where
+     all processes share a common filesystem should not override this.
+     The default behavior is to use unlink(2).  */
+  virtual int multifs_unlink (int pid, const char *filename);
+
+  /* Multiple-filesystem-aware readlink.  Like readlink(2), but
+     operating in the filesystem as it appears to process PID.
+     Systems where all processes share a common filesystem should
+     not override this.  The default behavior is to use readlink(2).  */
+  virtual ssize_t multifs_readlink (int pid, const char *filename,
+				    char *buf, size_t bufsiz);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index d5e15202ae1..ecece2d579c 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,9 +1848,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* multifs_open */
-  NULL, /* multifs_unlink */
-  NULL, /* multifs_readlink */
   NULL, /* breakpoint_kind_from_pc */
   win32_sw_breakpoint_from_kind,
   NULL, /* thread_name */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 30/58] gdbserver: turn target op 'supports_multi_process' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (49 preceding siblings ...)
  2020-02-11  9:05 ` [PATCH 44/58] gdbserver: turn target op 'emit_ops' " Tankut Baris Aktemur
@ 2020-02-11  9:05 ` Tankut Baris Aktemur
  2020-02-11  9:05 ` [PATCH 58/58] gdbserver: finish turning the target ops vector into a class Tankut Baris Aktemur
                   ` (8 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:05 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's supports_multi_process op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	* target.c (process_target::supports_multi_process): Define.
	(target_supports_multi_process): Update.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_supports_multi_process): Turn into ...
	(linux_process_target::supports_multi_process): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 7 +++----
 gdbserver/linux-low.h | 2 ++
 gdbserver/lynx-low.c  | 1 -
 gdbserver/nto-low.c   | 1 -
 gdbserver/target.c    | 9 +++++++--
 gdbserver/target.h    | 6 +++---
 gdbserver/win32-low.c | 1 -
 7 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index a13edfd067b..30c65bf0bfd 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6327,10 +6327,10 @@ linux_process_target::start_non_stop (bool nonstop)
   return 0;
 }
 
-static int
-linux_supports_multi_process (void)
+bool
+linux_process_target::supports_multi_process ()
 {
-  return 1;
+  return true;
 }
 
 /* Check if fork events are supported.  */
@@ -7418,7 +7418,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_supports_multi_process,
   linux_supports_fork_events,
   linux_supports_vfork_events,
   linux_supports_exec_events,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 0f1dfa45fba..ed3546f4356 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -366,6 +366,8 @@ public:
   bool async (bool enable) override;
 
   int start_non_stop (bool enable) override;
+
+  bool supports_multi_process () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index ad2c2f72a73..11179ce3c4e 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* supports_multi_process */
   NULL,  /* supports_fork_events */
   NULL,  /* supports_vfork_events */
   NULL,  /* supports_exec_events */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index cbbf67af917..a26c6696104 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* supports_multi_process */
   NULL, /* supports_fork_events */
   NULL, /* supports_vfork_events */
   NULL, /* supports_exec_events */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 33e31a748ef..485eecbee91 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -260,8 +260,7 @@ target_continue (ptid_t ptid, enum gdb_signal signal)
 int
 target_supports_multi_process (void)
 {
-  return (the_target->supports_multi_process != NULL ?
-	  (*the_target->supports_multi_process) () : 0);
+  return the_target->pt->supports_multi_process ();
 }
 
 void
@@ -548,3 +547,9 @@ process_target::start_non_stop (bool enable)
   else
     return 0;
 }
+
+bool
+process_target::supports_multi_process ()
+{
+  return false;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 88b4762a30c..b9e36af456f 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,9 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Returns true if the target supports multi-process debugging.  */
-  int (*supports_multi_process) (void);
-
   /* Returns true if fork events are supported.  */
   int (*supports_fork_events) (void);
 
@@ -486,6 +483,9 @@ public:
   /* Switch to non-stop (ENABLE == true) or all-stop (ENABLE == false)
      mode.  Return 0 on success, -1 otherwise.  */
   virtual int start_non_stop (bool enable);
+
+  /* Returns true if the target supports multi-process debugging.  */
+  virtual bool supports_multi_process ();
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 15431047814..8d6fba16240 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1842,7 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* supports_multi_process */
   NULL, /* supports_fork_events */
   NULL, /* supports_vfork_events */
   NULL, /* supports_exec_events */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 41/58] gdbserver: turn target ops 'pause_all' and 'unpause_all' into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (56 preceding siblings ...)
  2020-02-11  9:05 ` [PATCH 16/58] gdbserver: turn target op 'request_interrupt' into a method Tankut Baris Aktemur
@ 2020-02-11  9:05 ` Tankut Baris Aktemur
  2020-02-11 17:41 ` [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Christian Biesinger via gdb-patches
  2020-02-13 20:26 ` Pedro Alves
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:05 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's pause_all and unpause_all ops
	methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	(pause_all): Update the macro and rename to...
	(target_pause_all): ... this.
	(unpause_all): Update the macro and rename to...
	(target_unpause_all): ... this.
	* target.c (process_target::pause_all): Define.
	(process_target::unpause_all): Define.

	Update the derived structs and callers below.

	* server.c (handle_status): Update.
	* tracepoint.c (clear_installed_tracepoints): Update.
	(cmd_qtdp): Update.
	(cmd_qtstart): Update.
	(stop_tracing): Update.
	(cmd_qtstatus): Update.
	(upload_fast_traceframes): Update.
	(run_inferior_command): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_pause_all): Turn into ...
	(linux_process_target::pause_all): ... this.
	(linux_unpause_all): Turn into ...
	(linux_process_target::unpause_all): ... this.
	(linux_process_target::prepare_to_access_memory): Update.
	(linux_process_target::done_accessing_memory): Update.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c  | 14 ++++++--------
 gdbserver/linux-low.h  |  4 ++++
 gdbserver/lynx-low.c   |  2 --
 gdbserver/nto-low.c    |  2 --
 gdbserver/server.c     |  2 +-
 gdbserver/target.c     | 12 ++++++++++++
 gdbserver/target.h     | 40 ++++++++++++++++------------------------
 gdbserver/tracepoint.c | 34 +++++++++++++++++-----------------
 gdbserver/win32-low.c  |  2 --
 9 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index a75c7ade312..696eec432fc 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6575,8 +6575,8 @@ linux_process_target::thread_stopped (thread_info *thread)
 
 /* This exposes stop-all-threads functionality to other modules.  */
 
-static void
-linux_pause_all (int freeze)
+void
+linux_process_target::pause_all (bool freeze)
 {
   stop_all_lwps (freeze, NULL);
 }
@@ -6584,8 +6584,8 @@ linux_pause_all (int freeze)
 /* This exposes unstop-all-threads functionality to other gdbserver
    modules.  */
 
-static void
-linux_unpause_all (int unfreeze)
+void
+linux_process_target::unpause_all (bool unfreeze)
 {
   unstop_all_lwps (unfreeze, NULL);
 }
@@ -6596,7 +6596,7 @@ linux_process_target::prepare_to_access_memory ()
   /* Neither ptrace nor /proc/PID/mem allow accessing memory through a
      running LWP.  */
   if (non_stop)
-    linux_pause_all (1);
+    target_pause_all (true);
   return 0;
 }
 
@@ -6606,7 +6606,7 @@ linux_process_target::done_accessing_memory ()
   /* Neither ptrace nor /proc/PID/mem allow accessing memory through a
      running LWP.  */
   if (non_stop)
-    linux_unpause_all (1);
+    target_unpause_all (true);
 }
 
 static int
@@ -7444,8 +7444,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_pause_all,
-  linux_unpause_all,
   linux_stabilize_threads,
   linux_install_fast_tracepoint_jump_pad,
   linux_emit_ops,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 2c4d078ecd5..f219a90528b 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -399,6 +399,10 @@ public:
   bool supports_thread_stopped () override;
 
   bool thread_stopped (thread_info *thread) override;
+
+  void pause_all (bool freeze) override;
+
+  void unpause_all (bool unfreeze) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 5553e87a137..1b4b3b74d7a 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,8 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* pause_all */
-  NULL,  /* unpause_all */
   NULL,  /* stabilize_threads */
   NULL,  /* install_fast_tracepoint_jump_pad */
   NULL,  /* emit_ops */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 877e264e1dc..3c4ba5dcc28 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,8 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* pause_all */
-  NULL, /* unpause_all */
   NULL, /* stabilize_threads */
   NULL, /* install_fast_tracepoint_jump_pad */
   NULL, /* emit_ops */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index 77155935fab..670c0fed968 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -3323,7 +3323,7 @@ handle_status (char *own_buf)
     {
       thread_info *thread = NULL;
 
-      pause_all (0);
+      target_pause_all (false);
       stabilize_threads ();
       gdb_wants_all_threads_stopped ();
 
diff --git a/gdbserver/target.c b/gdbserver/target.c
index f1cdfc0446d..aea66038e1f 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -650,3 +650,15 @@ process_target::get_tib_address (ptid_t ptid, CORE_ADDR *address)
 {
   gdb_assert_not_reached ("target op get_tib_address not supported");
 }
+
+void
+process_target::pause_all (bool freeze)
+{
+  /* Nop.  */
+}
+
+void
+process_target::unpause_all (bool unfreeze)
+{
+  /* Nop.  */
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index aba4bbfab96..183a35a593e 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,18 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Pause all threads.  If FREEZE, arrange for any resume attempt to
-     be ignored until an unpause_all call unfreezes threads again.
-     There can be nested calls to pause_all, so a freeze counter
-     should be maintained.  */
-  void (*pause_all) (int freeze);
-
-  /* Unpause all threads.  Threads that hadn't been resumed by the
-     client should be left stopped.  Basically a pause/unpause call
-     pair should not end up resuming threads that were stopped before
-     the pause call.  */
-  void (*unpause_all) (int unfreeze);
-
   /* Stabilize all threads.  That is, force them out of jump pads.  */
   void (*stabilize_threads) (void);
 
@@ -494,6 +482,18 @@ public:
 
   /* Read Thread Information Block address.  */
   virtual int get_tib_address (ptid_t ptid, CORE_ADDR *address);
+
+  /* Pause all threads.  If FREEZE, arrange for any resume attempt to
+     be ignored until an unpause_all call unfreezes threads again.
+     There can be nested calls to pause_all, so a freeze counter
+     should be maintained.  */
+  virtual void pause_all (bool freeze);
+
+  /* Unpause all threads.  Threads that hadn't been resumed by the
+     client should be left stopped.  Basically a pause/unpause call
+     pair should not end up resuming threads that were stopped before
+     the pause call.  */
+  virtual void unpause_all (bool unfreeze);
 };
 
 extern process_stratum_target *the_target;
@@ -568,19 +568,11 @@ int kill_inferior (process_info *proc);
 #define target_thread_stopped(thread) \
   the_target->pt->thread_stopped (thread)
 
-#define pause_all(freeze)			\
-  do						\
-    {						\
-      if (the_target->pause_all)		\
-	(*the_target->pause_all) (freeze);	\
-    } while (0)
+#define target_pause_all(freeze)		\
+  the_target->pt->pause_all (freeze)
 
-#define unpause_all(unfreeze)			\
-  do						\
-    {						\
-      if (the_target->unpause_all)		\
-	(*the_target->unpause_all) (unfreeze);	\
-    } while (0)
+#define target_unpause_all(unfreeze)		\
+  the_target->pt->unpause_all (unfreeze)
 
 #define stabilize_threads()			\
   do						\
diff --git a/gdbserver/tracepoint.c b/gdbserver/tracepoint.c
index bbca48b2efd..ffa819cf24e 100644
--- a/gdbserver/tracepoint.c
+++ b/gdbserver/tracepoint.c
@@ -2433,7 +2433,7 @@ clear_installed_tracepoints (void)
   struct tracepoint *tpoint;
   struct tracepoint *prev_stpoint;
 
-  pause_all (1);
+  target_pause_all (true);
 
   prev_stpoint = NULL;
 
@@ -2486,7 +2486,7 @@ clear_installed_tracepoints (void)
       tpoint->handle = NULL;
     }
 
-  unpause_all (1);
+  target_unpause_all (true);
 }
 
 /* Parse a packet that defines a tracepoint.  */
@@ -2602,14 +2602,14 @@ cmd_qtdp (char *own_buf)
       struct tracepoint *tp = NULL;
 
       /* Pause all threads temporarily while we patch tracepoints.  */
-      pause_all (0);
+      target_pause_all (false);
 
       /* download_tracepoint will update global `tracepoints'
 	 list, so it is unsafe to leave threads in jump pad.  */
       stabilize_threads ();
 
       /* Freeze threads.  */
-      pause_all (1);
+      target_pause_all (true);
 
 
       if (tpoint->type != trap_tracepoint)
@@ -2658,7 +2658,7 @@ cmd_qtdp (char *own_buf)
 	    write_ok (own_buf);
 	}
 
-      unpause_all (1);
+      target_unpause_all (true);
       return;
     }
 
@@ -3220,7 +3220,7 @@ cmd_qtstart (char *packet)
   trace_debug ("Starting the trace");
 
   /* Pause all threads temporarily while we patch tracepoints.  */
-  pause_all (0);
+  target_pause_all (false);
 
   /* Get threads out of jump pads.  Safe to do here, since this is a
      top level command.  And, required to do here, since we're
@@ -3229,7 +3229,7 @@ cmd_qtstart (char *packet)
   stabilize_threads ();
 
   /* Freeze threads.  */
-  pause_all (1);
+  target_pause_all (true);
 
   /* Sync the fast tracepoints list in the inferior ftlib.  */
   if (agent_loaded_p ())
@@ -3370,7 +3370,7 @@ cmd_qtstart (char *packet)
       clear_installed_tracepoints ();
       if (*packet == '\0')
 	write_enn (packet);
-      unpause_all (1);
+      target_unpause_all (true);
       return;
     }
 
@@ -3418,7 +3418,7 @@ cmd_qtstart (char *packet)
 	error ("Error setting flush_trace_buffer breakpoint");
     }
 
-  unpause_all (1);
+  target_unpause_all (true);
 
   write_ok (packet);
 }
@@ -3445,7 +3445,7 @@ stop_tracing (void)
      when we're sure we can move all threads out of the jump pads).
      We can't now, since we may be getting here due to the inferior
      agent calling us.  */
-  pause_all (1);
+  target_pause_all (true);
 
   /* Stop logging. Tracepoints can still be hit, but they will not be
      recorded.  */
@@ -3522,7 +3522,7 @@ stop_tracing (void)
       flush_trace_buffer_bkpt = NULL;
     }
 
-  unpause_all (1);
+  target_unpause_all (true);
 }
 
 static int
@@ -3668,11 +3668,11 @@ cmd_qtstatus (char *packet)
 
   if (agent_loaded_p ())
     {
-      pause_all (1);
+      target_pause_all (true);
 
       upload_fast_traceframes ();
 
-      unpause_all (1);
+      target_unpause_all (true);
    }
 
   stop_reason_rsp = (char *) tracing_stop_reason;
@@ -6578,12 +6578,12 @@ upload_fast_traceframes (void)
 
   trace_debug ("Done uploading traceframes [%d]\n", curr_tbctrl_idx);
 
-  pause_all (1);
+  target_pause_all (true);
 
   delete_breakpoint (about_to_request_buffer_space_bkpt);
   about_to_request_buffer_space_bkpt = NULL;
 
-  unpause_all (1);
+  target_unpause_all (true);
 
   if (trace_buffer_is_full)
     stop_tracing ();
@@ -6861,13 +6861,13 @@ run_inferior_command (char *cmd, int len)
 
   trace_debug ("run_inferior_command: running: %s", cmd);
 
-  pause_all (0);
+  target_pause_all (false);
   uninsert_all_breakpoints ();
 
   err = agent_run_command (pid, (const char *) cmd, len);
 
   reinsert_all_breakpoints ();
-  unpause_all (0);
+  target_unpause_all (false);
 
   return err;
 }
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 781ca7557a9..4cfdeae88f4 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,8 +1848,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* pause_all */
-  NULL, /* unpause_all */
   NULL, /* stabilize_threads */
   NULL, /* install_fast_tracepoint_jump_pad */
   NULL, /* emit_ops */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 10/58] gdbserver: turn target op 'resume' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (52 preceding siblings ...)
  2020-02-11  9:05 ` [PATCH 29/58] gdbserver: turn non-stop and async target ops into methods Tankut Baris Aktemur
@ 2020-02-11  9:05 ` Tankut Baris Aktemur
  2020-02-11  9:05 ` [PATCH 35/58] gdbserver: turn target op 'read_loadmap' " Tankut Baris Aktemur
                   ` (5 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:05 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's resume op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.

	Update the derived structs and callers below.

	* server.c (resume): Update.
	* target.c (target_stop_and_wait): Update.
	(target_continue_no_signal): Update.
	(target_continue): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_resume): Turn into ...
	(linux_process_target::resume): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_resume): Turn into ...
	(lynx_process_target::resume): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_resume): Turn into ...
	(nto_process_target::resume): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_resume): Turn into ...
	(win32_process_target::resume): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c | 6 ++----
 gdbserver/linux-low.h | 2 ++
 gdbserver/lynx-low.c  | 5 ++---
 gdbserver/lynx-low.h  | 2 ++
 gdbserver/nto-low.c   | 5 ++---
 gdbserver/nto-low.h   | 2 ++
 gdbserver/server.c    | 2 +-
 gdbserver/target.c    | 6 +++---
 gdbserver/target.h    | 7 +++----
 gdbserver/win32-low.c | 5 ++---
 gdbserver/win32-low.h | 2 ++
 11 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index ae10d5a2282..5722752fd12 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -262,7 +262,6 @@ static int stabilizing_threads;
 
 static void linux_resume_one_lwp (struct lwp_info *lwp,
 				  int step, int signal, siginfo_t *info);
-static void linux_resume (struct thread_resume *resume_info, size_t n);
 static void stop_all_lwps (int suspend, struct lwp_info *except);
 static void unstop_all_lwps (int unsuspend, struct lwp_info *except);
 static void unsuspend_all_lwps (struct lwp_info *except);
@@ -5002,8 +5001,8 @@ linux_resume_one_thread (thread_info *thread, bool leave_all_stopped)
   lwp->resume = NULL;
 }
 
-static void
-linux_resume (struct thread_resume *resume_info, size_t n)
+void
+linux_process_target::resume (thread_resume *resume_info, size_t n)
 {
   struct thread_info *need_step_over = NULL;
 
@@ -7359,7 +7358,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_resume,
   linux_wait,
   linux_fetch_registers,
   linux_store_registers,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index f3bb7826a68..48d92f73ced 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -285,6 +285,8 @@ public:
   void join (int pid) override;
 
   bool thread_alive (ptid_t pid) override;
+
+  void resume (thread_resume *resume_info, size_t n) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 99ef605f27d..b3eacd8b6c2 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -326,8 +326,8 @@ lynx_process_target::attach (unsigned long pid)
 
 /* Implement the resume target_ops method.  */
 
-static void
-lynx_resume (struct thread_resume *resume_info, size_t n)
+void
+lynx_process_target::resume (thread_resume *resume_info, size_t n)
 {
   ptid_t ptid = resume_info[0].thread;
   const int request
@@ -726,7 +726,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_resume,
   lynx_wait,
   lynx_fetch_registers,
   lynx_store_registers,
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index aa5d4b20505..6ad41545679 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -71,6 +71,8 @@ public:
   void join (int pid) override;
 
   bool thread_alive (ptid_t pid) override;
+
+  void resume (thread_resume *resume_info, size_t n) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index bd2ee687147..aba63786203 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -451,8 +451,8 @@ nto_process_target::thread_alive (ptid_t ptid)
 
 /* Resume inferior's execution.  */
 
-static void
-nto_resume (struct thread_resume *resume_info, size_t n)
+void
+nto_process_target::resume (thread_resume *resume_info, size_t n)
 {
   /* We can only work in all-stop mode.  */
   procfs_status status;
@@ -941,7 +941,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_resume,
   nto_wait,
   nto_fetch_registers,
   nto_store_registers,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index 056186e0071..b0ca4247e69 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -61,6 +61,8 @@ public:
   void join (int pid) override;
 
   bool thread_alive (ptid_t pid) override;
+
+  void resume (thread_resume *resume_info, size_t n) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/server.c b/gdbserver/server.c
index 73f8e185477..92feff36516 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -2847,7 +2847,7 @@ resume (struct thread_resume *actions, size_t num_actions)
       enable_async_io ();
     }
 
-  (*the_target->resume) (actions, num_actions);
+  the_target->pt->resume (actions, num_actions);
 
   if (non_stop)
     write_ok (cs.own_buf);
diff --git a/gdbserver/target.c b/gdbserver/target.c
index f6d8d927b85..eca53de982e 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -211,7 +211,7 @@ target_stop_and_wait (ptid_t ptid)
   resume_info.thread = ptid;
   resume_info.kind = resume_stop;
   resume_info.sig = GDB_SIGNAL_0;
-  (*the_target->resume) (&resume_info, 1);
+  the_target->pt->resume (&resume_info, 1);
 
   non_stop = true;
   mywait (ptid, &status, 0, 0);
@@ -244,7 +244,7 @@ target_continue_no_signal (ptid_t ptid)
   resume_info.thread = ptid;
   resume_info.kind = resume_continue;
   resume_info.sig = GDB_SIGNAL_0;
-  (*the_target->resume) (&resume_info, 1);
+  the_target->pt->resume (&resume_info, 1);
 }
 
 /* See target/target.h.  */
@@ -257,7 +257,7 @@ target_continue (ptid_t ptid, enum gdb_signal signal)
   resume_info.thread = ptid;
   resume_info.kind = resume_continue;
   resume_info.sig = gdb_signal_to_host (signal);
-  (*the_target->resume) (&resume_info, 1);
+  the_target->pt->resume (&resume_info, 1);
 }
 
 /* See target/target.h.  */
diff --git a/gdbserver/target.h b/gdbserver/target.h
index e2bdddcb137..0a07d7f8c85 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Resume the inferior process.  */
-
-  void (*resume) (struct thread_resume *resume_info, size_t n);
-
   /* Wait for the inferior process or thread to change state.  Store
      status through argument pointer STATUS.
 
@@ -482,6 +478,9 @@ public:
 
   /* Return true iff the thread with process ID PID is alive.  */
   virtual bool thread_alive (ptid_t pid) = 0;
+
+  /* Resume the inferior process.  */
+  virtual void resume (thread_resume *resume_info, size_t n) = 0;
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index adf0dc4d902..fcbf3075e80 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -897,8 +897,8 @@ win32_process_target::thread_alive (ptid_t ptid)
 
 /* Resume the inferior process.  RESUME_INFO describes how we want
    to resume.  */
-static void
-win32_resume (struct thread_resume *resume_info, size_t n)
+void
+win32_process_target::resume (thread_resume *resume_info, size_t n)
 {
   DWORD tid;
   enum gdb_signal sig;
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_resume,
   win32_wait,
   win32_fetch_inferior_registers,
   win32_store_inferior_registers,
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index e73569b07b3..472be13d518 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -120,6 +120,8 @@ public:
   void join (int pid) override;
 
   bool thread_alive (ptid_t pid) override;
+
+  void resume (thread_resume *resume_info, size_t n) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 44/58] gdbserver: turn target op 'emit_ops' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (48 preceding siblings ...)
  2020-02-11  9:04 ` [PATCH 55/58] gdbserver: turn target op 'supports_catch_syscall' " Tankut Baris Aktemur
@ 2020-02-11  9:05 ` Tankut Baris Aktemur
  2020-02-11  9:05 ` [PATCH 30/58] gdbserver: turn target op 'supports_multi_process' " Tankut Baris Aktemur
                   ` (9 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:05 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's emit_ops op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.
	(target_emit_ops): Update the macro.
	* target.c (process_target::emit_ops): Define.

	Update the derived structs and callers below.

	* linux-low.c (linux_target_ops): Update.
	(linux_emit_ops): Turn into ...
	(linux_process_target::emit_ops): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c |  5 ++---
 gdbserver/linux-low.h |  2 ++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/target.c    |  6 ++++++
 gdbserver/target.h    | 10 +++++-----
 gdbserver/win32-low.c |  1 -
 7 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index d3f6edce5bc..93a79cb4e37 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6632,8 +6632,8 @@ linux_process_target::install_fast_tracepoint_jump_pad (
      err);
 }
 
-static struct emit_ops *
-linux_emit_ops (void)
+emit_ops *
+linux_process_target::emit_ops ()
 {
   if (the_low_target.emit_ops != NULL)
     return (*the_low_target.emit_ops) ();
@@ -7445,7 +7445,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_emit_ops,
   linux_supports_disable_randomization,
   linux_qxfer_libraries_svr4,
   linux_supports_agent,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 475e882712b..6f53450898e 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -423,6 +423,8 @@ public:
 					char *err) override;
 
   int get_min_fast_tracepoint_insn_len () override;
+
+  struct emit_ops *emit_ops () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 6520302ef7e..8b5d26b8956 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* emit_ops */
   NULL,  /* supports_disable_randomization */
   NULL,  /* qxfer_libraries_svr4 */
   NULL,  /* support_agent */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 555cba190b5..be496bd6686 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* emit_ops */
   NULL, /* supports_disable_randomization */
   NULL, /* qxfer_libraries_svr4 */
   NULL, /* support_agent */
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 5f0316bf081..5bd591df16d 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -693,3 +693,9 @@ process_target::get_min_fast_tracepoint_insn_len ()
 {
   return 0;
 }
+
+struct emit_ops *
+process_target::emit_ops ()
+{
+  return nullptr;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index c1276be152c..fea4f8e23e5 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return the bytecode operations vector for the current inferior.
-     Returns NULL if bytecode compilation is not supported.  */
-  struct emit_ops *(*emit_ops) (void);
-
   /* Returns true if the target supports disabling randomization.  */
   int (*supports_disable_randomization) (void);
 
@@ -493,6 +489,10 @@ public:
   /* Return the minimum length of an instruction that can be safely
      overwritten for use as a fast tracepoint.  */
   virtual int get_min_fast_tracepoint_insn_len ();
+
+  /* Return the bytecode operations vector for the current inferior.
+     Returns nullptr if bytecode compilation is not supported.  */
+  virtual struct emit_ops *emit_ops ();
 };
 
 extern process_stratum_target *the_target;
@@ -597,7 +597,7 @@ int kill_inferior (process_info *proc);
 						    err)
 
 #define target_emit_ops() \
-  (the_target->emit_ops ? (*the_target->emit_ops) () : NULL)
+  the_target->pt->emit_ops ()
 
 #define target_supports_disable_randomization() \
   (the_target->supports_disable_randomization ? \
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 7108f39c6f9..342f19fcdcf 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1848,7 +1848,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* emit_ops */
   NULL, /* supports_disable_randomization */
   NULL, /* qxfer_libraries_svr4 */
   NULL, /* support_agent */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 58/58] gdbserver: finish turning the target ops vector into a class
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (50 preceding siblings ...)
  2020-02-11  9:05 ` [PATCH 30/58] gdbserver: turn target op 'supports_multi_process' " Tankut Baris Aktemur
@ 2020-02-11  9:05 ` Tankut Baris Aktemur
  2020-02-13 20:31   ` Pedro Alves
  2020-02-11  9:05 ` [PATCH 29/58] gdbserver: turn non-stop and async target ops into methods Tankut Baris Aktemur
                   ` (7 subsequent siblings)
  59 siblings, 1 reply; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:05 UTC (permalink / raw)
  To: gdb-patches

Now that 'process_stratum_target' has a single field left, namely 'pt'
of type 'process_target', and that all the requests to a
'process_stratum_target' are forwarded to 'pt', meld the
'process_target' class into 'process_stratum_target'.

This essentially means

1. All the references of the form 'the_target->pt' become 'the_target'.

2. All the uses of the name 'process_target' become
   'process_stratum_target'.

3. The platform-specific target op vectors (e.g. linux_target_ops) are
   removed and instances of their "process target" classes are used
   instead.

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* target.h (struct process_stratum_target): Remove.
	(class process_target): Rename to ...
	(class process_stratum_target): ... this.
	* linux-low.h (class linux_process_target): Derive from
	'process_stratum_target'.
	* linux-low.c (linux_target_ops): Remove.
	(initialize_low): Reset the_target to an instance of
	linux_process_target.
	* lynx-low.h (class lynx_process_target): Derive from
	'process_stratum_target'.
	* lynx-low.c (lynx_target_ops): Remove.
	(initialize_low): Reset the_target to an instance of
	lynx_process_target.
	* nto-low.h (class nto_process_target): Derive from
	'process_stratum_target'.
	* nto-low.c (nto_target_ops): Remove.
	(initialize_low): Reset the_target to an instance of
	nto_process_target.
	* win32-low.h (class win32_process_target): Derive from
	'process_stratum_target'.
	* win32-low.c (win32_target_ops): Remove.
	(initialize_low): Reset the_target to an instance of
	win32_process_target.

	Replace 'the_target->pt' with 'the_target' in the uses below.

	* hostio.c (hostio_error):
	(handle_setfs):
	(handle_open):
	(handle_unlink):
	(handle_readlink):
	* linux-aarch32-low.c (arm_breakpoint_at):
	* linux-aarch64-low.c (aarch64_breakpoint_at):
	* linux-arm-low.c (arm_sigreturn_next_pc):
	(arm_get_hwcap):
	(arm_get_syscall_trapinfo):
	* linux-cris-low.c (cris_breakpoint_at):
	* linux-crisv32-low.c (cris_breakpoint_at):
	* linux-low.c (handle_extended_wait):
	(linux_wait_1):
	(linux_read_memory):
	(linux_process_target::breakpoint_kind_from_pc):
	(linux_get_auxv):
	* linux-m32r-low.c (m32r_breakpoint_at):
	* linux-mips-low.c (mips_breakpoint_at):
	* linux-nios2-low.c (nios2_breakpoint_at):
	* linux-ppc-low.c (ppc_get_pc):
	(ppc_set_pc):
	(ppc_get_auxv):
	(ppc_breakpoint_at):
	* linux-s390-low.c (s390_get_hwcap):
	* linux-sh-low.c (sh_breakpoint_at):
	* linux-sparc-low.c (sparc_fill_gregset_to_stack):
	(sparc_store_gregset_from_stack):
	(sparc_breakpoint_at):
	* linux-tic6x-low.c (tic6x_breakpoint_at):
	* linux-tile-low.c (tile_breakpoint_at):
	* linux-x86-low.c (x86_breakpoint_at):
	* linux-xtensa-low.c (xtensa_breakpoint_at):
	* mem-break.c (bp_size):
	(bp_opcode):
	(insert_memory_breakpoint):
	(set_raw_breakpoint_at):
	(delete_raw_breakpoint):
	(z_type_supported):
	(uninsert_raw_breakpoint):
	(reinsert_raw_breakpoint):
	(validate_inserted_breakpoint):
	* regcache.c (regcache_read_pc):
	(regcache_write_pc):
	* remote-utils.c (putpkt_binary_1):
	(input_interrupt):
	(getpkt):
	(prepare_resume_reply):
	* server.c (handle_general_set):
	(handle_detach):
	(handle_qxfer_auxv):
	(handle_qxfer_exec_file):
	(handle_qxfer_libraries_svr4):
	(handle_qxfer_osdata):
	(handle_qxfer_siginfo):
	(handle_qxfer_fdpic):
	(handle_query):
	(resume):
	(handle_v_requests):
	(queue_stop_reply_callback):
	(captured_main):
	* target.c (prepare_to_access_memory):
	(done_accessing_memory):
	(read_inferior_memory):
	(target_write_memory):
	(target_stop_and_wait):
	(target_wait):
	(target_mourn_inferior):
	(target_continue_no_signal):
	(target_continue):
	(target_supports_multi_process):
	(kill_inferior):
	* target.h
	(target_create_inferior):
	(target_post_create_inferior):
	(myattach):
	(target_supports_fork_events):
	(target_supports_vfork_events):
	(target_supports_exec_events):
	(target_handle_new_gdb_connection):
	(detach_inferior):
	(mythread_alive):
	(fetch_inferior_registers):
	(store_inferior_registers):
	(join_inferior):
	(target_supports_non_stop):
	(target_async):
	(target_process_qsupported):
	(target_supports_catch_syscall):
	(target_get_ipa_tdesc_idx):
	(target_supports_tracepoints):
	(target_supports_fast_tracepoints):
	(target_get_min_fast_tracepoint_insn_len):
	(target_thread_stopped):
	(target_pause_all):
	(target_unpause_all):
	(target_stabilize_threads):
	(target_install_fast_tracepoint_jump_pad):
	(target_emit_ops):
	(target_supports_disable_randomization):
	(target_supports_agent):
	(target_enable_btrace):
	(target_disable_btrace):
	(target_read_btrace):
	(target_read_btrace_conf):
	(target_supports_range_stepping):
	(target_supports_stopped_by_sw_breakpoint):
	(target_stopped_by_sw_breakpoint):
	(target_supports_stopped_by_hw_breakpoint):
	(target_supports_hardware_single_step):
	(target_stopped_by_hw_breakpoint):
	(target_breakpoint_kind_from_pc):
	(target_breakpoint_kind_from_current_state):
	(target_supports_software_single_step):
	(target_core_of_thread):
	(target_thread_name):
	(target_thread_handle):
	* win32-low.c (do_initial_child_stuff):

	Rename target op default definitions listed below.

	* target.c (process_target::post_create_inferior): Rename as ...
	(process_stratum_target::post_create_inferior): ... this.
	(process_target::prepare_to_access_memory): Rename as ...
	(process_stratum_target::prepare_to_access_memory): ... this.
	(process_target::done_accessing_memory): Rename as ...
	(process_stratum_target::done_accessing_memory): ... this.
	(process_target::look_up_symbols): Rename as ...
	(process_stratum_target::look_up_symbols): ... this.
	(process_target::supports_read_auxv): Rename as ...
	(process_stratum_target::supports_read_auxv): ... this.
	(process_target::read_auxv): Rename as ...
	(process_stratum_target::read_auxv): ... this.
	(process_target::supports_z_point_type): Rename as ...
	(process_stratum_target::supports_z_point_type): ... this.
	(process_target::insert_point): Rename as ...
	(process_stratum_target::insert_point): ... this.
	(process_target::remove_point): Rename as ...
	(process_stratum_target::remove_point): ... this.
	(process_target::stopped_by_sw_breakpoint): Rename as ...
	(process_stratum_target::stopped_by_sw_breakpoint): ... this.
	(process_target::supports_stopped_by_sw_breakpoint): Rename as ...
	(process_stratum_target::supports_stopped_by_sw_breakpoint): ... this.
	(process_target::stopped_by_hw_breakpoint): Rename as ...
	(process_stratum_target::stopped_by_hw_breakpoint): ... this.
	(process_target::supports_stopped_by_hw_breakpoint): Rename as ...
	(process_stratum_target::supports_stopped_by_hw_breakpoint): ... this.
	(process_target::supports_hardware_single_step): Rename as ...
	(process_stratum_target::supports_hardware_single_step): ... this.
	(process_target::stopped_by_watchpoint): Rename as ...
	(process_stratum_target::stopped_by_watchpoint): ... this.
	(process_target::stopped_data_address): Rename as ...
	(process_stratum_target::stopped_data_address): ... this.
	(process_target::supports_read_offsets): Rename as ...
	(process_stratum_target::supports_read_offsets): ... this.
	(process_target::read_offsets): Rename as ...
	(process_stratum_target::read_offsets): ... this.
	(process_target::supports_get_tls_address): Rename as ...
	(process_stratum_target::supports_get_tls_address): ... this.
	(process_target::get_tls_address): Rename as ...
	(process_stratum_target::get_tls_address): ... this.
	(process_target::hostio_last_error): Rename as ...
	(process_stratum_target::hostio_last_error): ... this.
	(process_target::supports_qxfer_osdata): Rename as ...
	(process_stratum_target::supports_qxfer_osdata): ... this.
	(process_target::qxfer_osdata): Rename as ...
	(process_stratum_target::qxfer_osdata): ... this.
	(process_target::supports_qxfer_siginfo): Rename as ...
	(process_stratum_target::supports_qxfer_siginfo): ... this.
	(process_target::qxfer_siginfo): Rename as ...
	(process_stratum_target::qxfer_siginfo): ... this.
	(process_target::supports_non_stop): Rename as ...
	(process_stratum_target::supports_non_stop): ... this.
	(process_target::async): Rename as ...
	(process_stratum_target::async): ... this.
	(process_target::start_non_stop): Rename as ...
	(process_stratum_target::start_non_stop): ... this.
	(process_target::supports_multi_process): Rename as ...
	(process_stratum_target::supports_multi_process): ... this.
	(process_target::supports_fork_events): Rename as ...
	(process_stratum_target::supports_fork_events): ... this.
	(process_target::supports_vfork_events): Rename as ...
	(process_stratum_target::supports_vfork_events): ... this.
	(process_target::supports_exec_events): Rename as ...
	(process_stratum_target::supports_exec_events): ... this.
	(process_target::handle_new_gdb_connection): Rename as ...
	(process_stratum_target::handle_new_gdb_connection): ... this.
	(process_target::handle_monitor_command): Rename as ...
	(process_stratum_target::handle_monitor_command): ... this.
	(process_target::core_of_thread): Rename as ...
	(process_stratum_target::core_of_thread): ... this.
	(process_target::supports_read_loadmap): Rename as ...
	(process_stratum_target::supports_read_loadmap): ... this.
	(process_target::read_loadmap): Rename as ...
	(process_stratum_target::read_loadmap): ... this.
	(process_target::process_qsupported): Rename as ...
	(process_stratum_target::process_qsupported): ... this.
	(process_target::supports_tracepoints): Rename as ...
	(process_stratum_target::supports_tracepoints): ... this.
	(process_target::read_pc): Rename as ...
	(process_stratum_target::read_pc): ... this.
	(process_target::write_pc): Rename as ...
	(process_stratum_target::write_pc): ... this.
	(process_target::supports_thread_stopped): Rename as ...
	(process_stratum_target::supports_thread_stopped): ... this.
	(process_target::thread_stopped): Rename as ...
	(process_stratum_target::thread_stopped): ... this.
	(process_target::supports_get_tib_address): Rename as ...
	(process_stratum_target::supports_get_tib_address): ... this.
	(process_target::get_tib_address): Rename as ...
	(process_stratum_target::get_tib_address): ... this.
	(process_target::pause_all): Rename as ...
	(process_stratum_target::pause_all): ... this.
	(process_target::unpause_all): Rename as ...
	(process_stratum_target::unpause_all): ... this.
	(process_target::stabilize_threads): Rename as ...
	(process_stratum_target::stabilize_threads): ... this.
	(process_target::supports_fast_tracepoints): Rename as ...
	(process_stratum_target::supports_fast_tracepoints): ... this.
	(process_target::get_min_fast_tracepoint_insn_len): Rename as ...
	(process_stratum_target::get_min_fast_tracepoint_insn_len): ... this.
	(process_target::emit_ops): Rename as ...
	(process_stratum_target::emit_ops): ... this.
	(process_target::supports_disable_randomization): Rename as ...
	(process_stratum_target::supports_disable_randomization): ... this.
	(process_target::supports_qxfer_libraries_svr4): Rename as ...
	(process_stratum_target::supports_qxfer_libraries_svr4): ... this.
	(process_target::qxfer_libraries_svr4): Rename as ...
	(process_stratum_target::qxfer_libraries_svr4): ... this.
	(process_target::supports_agent): Rename as ...
	(process_stratum_target::supports_agent): ... this.
	(process_target::enable_btrace): Rename as ...
	(process_stratum_target::enable_btrace): ... this.
	(process_target::disable_btrace): Rename as ...
	(process_stratum_target::disable_btrace): ... this.
	(process_target::read_btrace): Rename as ...
	(process_stratum_target::read_btrace): ... this.
	(process_target::read_btrace_conf): Rename as ...
	(process_stratum_target::read_btrace_conf): ... this.
	(process_target::supports_range_stepping): Rename as ...
	(process_stratum_target::supports_range_stepping): ... this.
	(process_target::supports_pid_to_exec_file): Rename as ...
	(process_stratum_target::supports_pid_to_exec_file): ... this.
	(process_target::pid_to_exec_file): Rename as ...
	(process_stratum_target::pid_to_exec_file): ... this.
	(process_target::supports_multifs): Rename as ...
	(process_stratum_target::supports_multifs): ... this.
	(process_target::multifs_open): Rename as ...
	(process_stratum_target::multifs_open): ... this.
	(process_target::multifs_unlink): Rename as ...
	(process_stratum_target::multifs_unlink): ... this.
	(process_target::multifs_readlink): Rename as ...
	(process_stratum_target::multifs_readlink): ... this.
	(process_target::breakpoint_kind_from_pc): Rename as ...
	(process_stratum_target::breakpoint_kind_from_pc): ... this.
	(process_target::breakpoint_kind_from_current_state): Rename as ...
	(process_stratum_target::breakpoint_kind_from_current_state): ... this.
	(process_target::thread_name): Rename as ...
	(process_stratum_target::thread_name): ... this.
	(process_target::thread_handle): Rename as ...
	(process_stratum_target::thread_handle): ... this.
	(process_target::supports_software_single_step): Rename as ...
	(process_stratum_target::supports_software_single_step): ... this.
	(process_target::supports_catch_syscall): Rename as ...
	(process_stratum_target::supports_catch_syscall): ... this.
	(process_target::get_ipa_tdesc_idx): Rename as ...
	(process_stratum_target::get_ipa_tdesc_idx): ... this.
---
 gdbserver/hostio.c            |  15 ++-
 gdbserver/linux-aarch32-low.c |   6 +-
 gdbserver/linux-aarch64-low.c |   4 +-
 gdbserver/linux-arm-low.c     |   8 +-
 gdbserver/linux-cris-low.c    |   4 +-
 gdbserver/linux-crisv32-low.c |   4 +-
 gdbserver/linux-low.c         |  19 ++-
 gdbserver/linux-low.h         |   2 +-
 gdbserver/linux-m32r-low.c    |   4 +-
 gdbserver/linux-mips-low.c    |   2 +-
 gdbserver/linux-nios2-low.c   |   4 +-
 gdbserver/linux-ppc-low.c     |   2 +-
 gdbserver/linux-sh-low.c      |   2 +-
 gdbserver/linux-sparc-low.c   |   6 +-
 gdbserver/linux-tic6x-low.c   |   2 +-
 gdbserver/linux-tile-low.c    |   2 +-
 gdbserver/linux-x86-low.c     |   2 +-
 gdbserver/linux-xtensa-low.c  |   4 +-
 gdbserver/lynx-low.c          |   7 +-
 gdbserver/lynx-low.h          |   2 +-
 gdbserver/mem-break.c         |  22 ++--
 gdbserver/nto-low.c           |   7 +-
 gdbserver/nto-low.h           |   2 +-
 gdbserver/regcache.c          |   4 +-
 gdbserver/remote-utils.c      |  12 +-
 gdbserver/server.c            |  68 +++++------
 gdbserver/target.c            | 212 ++++++++++++++++++----------------
 gdbserver/target.h            | 118 +++++++++----------
 gdbserver/win32-low.c         |   9 +-
 gdbserver/win32-low.h         |   2 +-
 30 files changed, 268 insertions(+), 289 deletions(-)

diff --git a/gdbserver/hostio.c b/gdbserver/hostio.c
index 6223b24a887..0185a3ba038 100644
--- a/gdbserver/hostio.c
+++ b/gdbserver/hostio.c
@@ -196,7 +196,7 @@ require_valid_fd (int fd)
 static void
 hostio_error (char *own_buf)
 {
-  the_target->pt->hostio_last_error (own_buf);
+  the_target->hostio_last_error (own_buf);
 }
 
 static void
@@ -272,7 +272,7 @@ handle_setfs (char *own_buf)
      then there's no point in GDB sending "vFile:setfs:" packets.  We
      reply with an empty packet (i.e. we pretend we don't understand
      "vFile:setfs:") and that should stop GDB sending any more.  */
-  if (!the_target->pt->supports_multifs ())
+  if (!the_target->supports_multifs ())
     {
       own_buf[0] = '\0';
       return;
@@ -320,8 +320,7 @@ handle_open (char *own_buf)
   /* We do not need to convert MODE, since the fileio protocol
      uses the standard values.  */
   if (hostio_fs_pid != 0)
-    fd = the_target->pt->multifs_open (hostio_fs_pid, filename,
-				       flags, mode);
+    fd = the_target->multifs_open (hostio_fs_pid, filename, flags, mode);
   else
     fd = open (filename, flags, mode);
 
@@ -540,7 +539,7 @@ handle_unlink (char *own_buf)
     }
 
   if (hostio_fs_pid != 0)
-    ret = the_target->pt->multifs_unlink (hostio_fs_pid, filename);
+    ret = the_target->multifs_unlink (hostio_fs_pid, filename);
   else
     ret = unlink (filename);
 
@@ -570,9 +569,9 @@ handle_readlink (char *own_buf, int *new_packet_len)
     }
 
   if (hostio_fs_pid != 0)
-    ret = the_target->pt->multifs_readlink (hostio_fs_pid, filename,
-					    linkname,
-					    sizeof (linkname) - 1);
+    ret = the_target->multifs_readlink (hostio_fs_pid, filename,
+					linkname,
+					sizeof (linkname) - 1);
   else
     ret = readlink (filename, linkname, sizeof (linkname) - 1);
 
diff --git a/gdbserver/linux-aarch32-low.c b/gdbserver/linux-aarch32-low.c
index 41e018ab528..1ca0bfa8210 100644
--- a/gdbserver/linux-aarch32-low.c
+++ b/gdbserver/linux-aarch32-low.c
@@ -192,13 +192,13 @@ arm_breakpoint_at (CORE_ADDR where)
       /* Thumb mode.  */
       unsigned short insn;
 
-      the_target->pt->read_memory (where, (unsigned char *) &insn, 2);
+      the_target->read_memory (where, (unsigned char *) &insn, 2);
       if (insn == thumb_breakpoint)
 	return 1;
 
       if (insn == thumb2_breakpoint[0])
 	{
-	  the_target->pt->read_memory (where + 2, (unsigned char *) &insn, 2);
+	  the_target->read_memory (where + 2, (unsigned char *) &insn, 2);
 	  if (insn == thumb2_breakpoint[1])
 	    return 1;
 	}
@@ -208,7 +208,7 @@ arm_breakpoint_at (CORE_ADDR where)
       /* ARM mode.  */
       unsigned long insn;
 
-      the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
+      the_target->read_memory (where, (unsigned char *) &insn, 4);
       if (insn == arm_abi_breakpoint)
 	return 1;
 
diff --git a/gdbserver/linux-aarch64-low.c b/gdbserver/linux-aarch64-low.c
index 97117f05780..6ce5452945e 100644
--- a/gdbserver/linux-aarch64-low.c
+++ b/gdbserver/linux-aarch64-low.c
@@ -192,8 +192,8 @@ aarch64_breakpoint_at (CORE_ADDR where)
     {
       gdb_byte insn[aarch64_breakpoint_len];
 
-      the_target->pt->read_memory (where, (unsigned char *) &insn,
-				   aarch64_breakpoint_len);
+      the_target->read_memory (where, (unsigned char *) &insn,
+			       aarch64_breakpoint_len);
       if (memcmp (insn, aarch64_breakpoint, aarch64_breakpoint_len) == 0)
 	return 1;
 
diff --git a/gdbserver/linux-arm-low.c b/gdbserver/linux-arm-low.c
index e7cc1196857..f60543eae94 100644
--- a/gdbserver/linux-arm-low.c
+++ b/gdbserver/linux-arm-low.c
@@ -779,15 +779,15 @@ arm_sigreturn_next_pc (struct regcache *regcache, int svc_number,
   gdb_assert (svc_number == __NR_sigreturn || svc_number == __NR_rt_sigreturn);
 
   collect_register_by_name (regcache, "sp", &sp);
-  the_target->pt->read_memory (sp, (unsigned char *) &sp_data, 4);
+  the_target->read_memory (sp, (unsigned char *) &sp_data, 4);
 
   pc_offset = arm_linux_sigreturn_next_pc_offset
     (sp, sp_data, svc_number, __NR_sigreturn == svc_number ? 1 : 0);
 
-  the_target->pt->read_memory (sp + pc_offset, (unsigned char *) &next_pc, 4);
+  the_target->read_memory (sp + pc_offset, (unsigned char *) &next_pc, 4);
 
   /* Set IS_THUMB according the CPSR saved on the stack.  */
-  the_target->pt->read_memory (sp + pc_offset + 4, (unsigned char *) &cpsr, 4);
+  the_target->read_memory (sp + pc_offset + 4, (unsigned char *) &cpsr, 4);
   *is_thumb = ((cpsr & CPSR_T) != 0);
 
   return next_pc;
@@ -939,7 +939,7 @@ arm_get_syscall_trapinfo (struct regcache *regcache, int *sysno)
 
       collect_register_by_name (regcache, "pc", &pc);
 
-      if (the_target->pt->read_memory (pc - 4, (unsigned char *) &insn, 4))
+      if (the_target->read_memory (pc - 4, (unsigned char *) &insn, 4))
 	*sysno = UNKNOWN_SYSCALL;
       else
 	{
diff --git a/gdbserver/linux-cris-low.c b/gdbserver/linux-cris-low.c
index 6a4e8b1946a..81d84a1b5c8 100644
--- a/gdbserver/linux-cris-low.c
+++ b/gdbserver/linux-cris-low.c
@@ -76,8 +76,8 @@ cris_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  the_target->pt->read_memory (where, (unsigned char *) &insn,
-			       cris_breakpoint_len);
+  the_target->read_memory (where, (unsigned char *) &insn,
+			   cris_breakpoint_len);
   if (insn == cris_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-crisv32-low.c b/gdbserver/linux-crisv32-low.c
index fe12624c3b6..06135efcfa2 100644
--- a/gdbserver/linux-crisv32-low.c
+++ b/gdbserver/linux-crisv32-low.c
@@ -72,8 +72,8 @@ cris_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  the_target->pt->read_memory (where, (unsigned char *) &insn,
-			       cris_breakpoint_len);
+  the_target->read_memory (where, (unsigned char *) &insn,
+			   cris_breakpoint_len);
   if (insn == cris_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 87cf2fd8afb..93892aaf3af 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -703,7 +703,7 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat)
       syscalls_to_catch = std::move (proc->syscalls_to_catch);
 
       /* Delete the execing process and all its threads.  */
-      the_target->pt->mourn (proc);
+      the_target->mourn (proc);
       current_thread = NULL;
 
       /* Create a new process/lwp/thread.  */
@@ -3218,8 +3218,8 @@ linux_wait_1 (ptid_t ptid,
       CORE_ADDR stop_pc = event_child->stop_pc;
 
       breakpoint_kind =
-	the_target->pt->breakpoint_kind_from_current_state (&stop_pc);
-      the_target->pt->sw_breakpoint_from_kind (breakpoint_kind, &increment_pc);
+	the_target->breakpoint_kind_from_current_state (&stop_pc);
+      the_target->sw_breakpoint_from_kind (breakpoint_kind, &increment_pc);
 
       if (debug_threads)
 	{
@@ -5712,7 +5712,7 @@ linux_process_target::store_registers (regcache *regcache, int regno)
 static int
 linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
 {
-  return the_target->pt->read_memory (memaddr, myaddr, len);
+  return the_target->read_memory (memaddr, myaddr, len);
 }
 
 /* Copy LEN bytes from inferior's memory starting at MEMADDR
@@ -7361,7 +7361,7 @@ linux_process_target::breakpoint_kind_from_pc (CORE_ADDR *pcptr)
   if (the_low_target.breakpoint_kind_from_pc != NULL)
     return (*the_low_target.breakpoint_kind_from_pc) (pcptr);
   else
-    return process_target::breakpoint_kind_from_pc (pcptr);
+    return process_stratum_target::breakpoint_kind_from_pc (pcptr);
 }
 
 /* Implementation of the target_ops method "sw_breakpoint_from_kind".  */
@@ -7461,7 +7461,7 @@ linux_get_auxv (int wordsize, CORE_ADDR match, CORE_ADDR *valp)
 
   gdb_assert (wordsize == 4 || wordsize == 8);
 
-  while (the_target->pt->read_auxv (offset, data, 2 * wordsize) == 2 * wordsize)
+  while (the_target->read_auxv (offset, data, 2 * wordsize) == 2 * wordsize)
     {
       if (wordsize == 4)
 	{
@@ -7508,10 +7508,6 @@ linux_get_hwcap2 (int wordsize)
   return hwcap2;
 }
 
-/* The linux target ops object.  */
-
-static linux_process_target the_linux_target;
-
 #ifdef HAVE_LINUX_REGSETS
 void
 initialize_regsets_info (struct regsets_info *info)
@@ -7529,8 +7525,7 @@ initialize_low (void)
   struct sigaction sigchld_action;
 
   memset (&sigchld_action, 0, sizeof (sigchld_action));
-  the_target.reset (new process_stratum_target);
-  the_target->pt = &the_linux_target;
+  the_target.reset (new linux_process_target);
 
   linux_ptrace_init_warnings ();
   linux_proc_init_warnings ();
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index b1960645939..cf961b54f9a 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -266,7 +266,7 @@ extern struct linux_target_ops the_low_target;
 
 /* Target ops definitions for a Linux target.  */
 
-class linux_process_target : public process_target {
+class linux_process_target : public process_stratum_target {
 public:
 
   int create_inferior (const char *program,
diff --git a/gdbserver/linux-m32r-low.c b/gdbserver/linux-m32r-low.c
index 8fe8389618f..74e0f3f74c6 100644
--- a/gdbserver/linux-m32r-low.c
+++ b/gdbserver/linux-m32r-low.c
@@ -70,8 +70,8 @@ m32r_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  the_target->pt->read_memory (where, (unsigned char *) &insn,
-			       m32r_breakpoint_len);
+  the_target->read_memory (where, (unsigned char *) &insn,
+			   m32r_breakpoint_len);
   if (insn == m32r_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-mips-low.c b/gdbserver/linux-mips-low.c
index cb7eb53e3eb..3caab02e503 100644
--- a/gdbserver/linux-mips-low.c
+++ b/gdbserver/linux-mips-low.c
@@ -302,7 +302,7 @@ mips_breakpoint_at (CORE_ADDR where)
 {
   unsigned int insn;
 
-  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
+  the_target->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == mips_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-nios2-low.c b/gdbserver/linux-nios2-low.c
index 6e5d3084dad..a8bb87a390e 100644
--- a/gdbserver/linux-nios2-low.c
+++ b/gdbserver/linux-nios2-low.c
@@ -131,12 +131,12 @@ nios2_breakpoint_at (CORE_ADDR where)
 
   /* For R2, first check for the 2-byte CDX trap.n breakpoint encoding.  */
 #if defined(__nios2_arch__) && __nios2_arch__ == 2
-  the_target->pt->read_memory (where, (unsigned char *) &insn, 2);
+  the_target->read_memory (where, (unsigned char *) &insn, 2);
   if (insn == CDX_BREAKPOINT)
     return 1;
 #endif
 
-  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
+  the_target->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == nios2_breakpoint)
     return 1;
   return 0;
diff --git a/gdbserver/linux-ppc-low.c b/gdbserver/linux-ppc-low.c
index 93b3511a2e1..fd6d0369c48 100644
--- a/gdbserver/linux-ppc-low.c
+++ b/gdbserver/linux-ppc-low.c
@@ -277,7 +277,7 @@ ppc_breakpoint_at (CORE_ADDR where)
 {
   unsigned int insn;
 
-  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
+  the_target->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == ppc_breakpoint)
     return 1;
   /* If necessary, recognize more trap instructions here.  GDB only uses
diff --git a/gdbserver/linux-sh-low.c b/gdbserver/linux-sh-low.c
index 06ce8118ebf..f55402c3d41 100644
--- a/gdbserver/linux-sh-low.c
+++ b/gdbserver/linux-sh-low.c
@@ -76,7 +76,7 @@ sh_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  the_target->pt->read_memory (where, (unsigned char *) &insn, 2);
+  the_target->read_memory (where, (unsigned char *) &insn, 2);
   if (insn == sh_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-sparc-low.c b/gdbserver/linux-sparc-low.c
index b0b6c96b3de..e6cb43209af 100644
--- a/gdbserver/linux-sparc-low.c
+++ b/gdbserver/linux-sparc-low.c
@@ -133,7 +133,7 @@ sparc_fill_gregset_to_stack (struct regcache *regcache, const void *buf)
   for (i = l0_regno; i <= i7_regno; i++)
     {
       collect_register (regcache, i, tmp_reg_buf);
-      the_target->pt->write_memory (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
+      the_target->write_memory (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
       addr += sizeof (tmp_reg_buf);
     }
 }
@@ -184,7 +184,7 @@ sparc_store_gregset_from_stack (struct regcache *regcache, const void *buf)
 
   for (i = l0_regno; i <= i7_regno; i++)
     {
-      the_target->pt->read_memory (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
+      the_target->read_memory (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
       supply_register (regcache, i, tmp_reg_buf);
       addr += sizeof (tmp_reg_buf);
     }
@@ -242,7 +242,7 @@ sparc_breakpoint_at (CORE_ADDR where)
 {
   unsigned char insn[INSN_SIZE];
 
-  the_target->pt->read_memory (where, (unsigned char *) insn, sizeof (insn));
+  the_target->read_memory (where, (unsigned char *) insn, sizeof (insn));
 
   if (memcmp (sparc_breakpoint, insn, sizeof (insn)) == 0)
     return 1;
diff --git a/gdbserver/linux-tic6x-low.c b/gdbserver/linux-tic6x-low.c
index b57f8c57710..ca7c983a8ac 100644
--- a/gdbserver/linux-tic6x-low.c
+++ b/gdbserver/linux-tic6x-low.c
@@ -241,7 +241,7 @@ tic6x_breakpoint_at (CORE_ADDR where)
 {
   unsigned int insn;
 
-  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
+  the_target->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == tic6x_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-tile-low.c b/gdbserver/linux-tile-low.c
index baee93a5c24..1fe77a3fa57 100644
--- a/gdbserver/linux-tile-low.c
+++ b/gdbserver/linux-tile-low.c
@@ -85,7 +85,7 @@ tile_breakpoint_at (CORE_ADDR where)
 {
   uint64_t insn;
 
-  the_target->pt->read_memory (where, (unsigned char *) &insn, 8);
+  the_target->read_memory (where, (unsigned char *) &insn, 8);
   if (insn == tile_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-x86-low.c b/gdbserver/linux-x86-low.c
index cb2d3f59580..96818b85a86 100644
--- a/gdbserver/linux-x86-low.c
+++ b/gdbserver/linux-x86-low.c
@@ -515,7 +515,7 @@ x86_breakpoint_at (CORE_ADDR pc)
 {
   unsigned char c;
 
-  the_target->pt->read_memory (pc, &c, 1);
+  the_target->read_memory (pc, &c, 1);
   if (c == 0xCC)
     return 1;
 
diff --git a/gdbserver/linux-xtensa-low.c b/gdbserver/linux-xtensa-low.c
index 31e7bad36b8..510c9bd8879 100644
--- a/gdbserver/linux-xtensa-low.c
+++ b/gdbserver/linux-xtensa-low.c
@@ -207,8 +207,8 @@ xtensa_breakpoint_at (CORE_ADDR where)
 {
     unsigned long insn;
 
-    the_target->pt->read_memory (where, (unsigned char *) &insn,
-				 xtensa_breakpoint_len);
+    the_target->read_memory (where, (unsigned char *) &insn,
+			     xtensa_breakpoint_len);
     return memcmp((char *) &insn,
 		  xtensa_breakpoint, xtensa_breakpoint_len) == 0;
 }
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 1377ccaf4ae..a7a0a96a6eb 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,15 +735,10 @@ lynx_process_target::sw_breakpoint_from_kind (int kind, int *size)
   return nullptr;
 }
 
-/* The LynxOS target ops object.  */
-
-static lynx_process_target the_lynx_target;
-
 void
 initialize_low (void)
 {
-  the_target.reset (new process_stratum_target);
-  the_target->pt = &the_lynx_target;
+  the_target.reset (new lynx_process_target);
   the_low_target.arch_setup ();
 }
 
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index d4d265ca2f3..5a2c601e86e 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -54,7 +54,7 @@ extern struct lynx_target_ops the_low_target;
 
 /* Target ops definitions for a LynxOS target.  */
 
-class lynx_process_target : public process_target {
+class lynx_process_target : public process_stratum_target {
 public:
 
   int create_inferior (const char *program,
diff --git a/gdbserver/mem-break.c b/gdbserver/mem-break.c
index 3802d72a573..6b7af3a7d33 100644
--- a/gdbserver/mem-break.c
+++ b/gdbserver/mem-break.c
@@ -223,7 +223,7 @@ bp_size (struct raw_breakpoint *bp)
 {
   int size = 0;
 
-  the_target->pt->sw_breakpoint_from_kind (bp->kind, &size);
+  the_target->sw_breakpoint_from_kind (bp->kind, &size);
   return size;
 }
 
@@ -234,7 +234,7 @@ bp_opcode (struct raw_breakpoint *bp)
 {
   int size = 0;
 
-  return the_target->pt->sw_breakpoint_from_kind (bp->kind, &size);
+  return the_target->sw_breakpoint_from_kind (bp->kind, &size);
 }
 
 /* See mem-break.h.  */
@@ -380,8 +380,8 @@ insert_memory_breakpoint (struct raw_breakpoint *bp)
     {
       memcpy (bp->old_data, buf, bp_size (bp));
 
-      err = the_target->pt->write_memory (bp->pc, bp_opcode (bp),
-					  bp_size (bp));
+      err = the_target->write_memory (bp->pc, bp_opcode (bp),
+				      bp_size (bp));
       if (err != 0)
 	{
 	  if (debug_threads)
@@ -460,7 +460,7 @@ set_raw_breakpoint_at (enum raw_bkpt_type type, CORE_ADDR where, int kind,
 
   if (!bp->inserted)
     {
-      *err = the_target->pt->insert_point (bp->raw_type, bp->pc, bp->kind, bp);
+      *err = the_target->insert_point (bp->raw_type, bp->pc, bp->kind, bp);
       if (*err != 0)
 	{
 	  if (debug_threads)
@@ -890,8 +890,8 @@ delete_raw_breakpoint (struct process_info *proc, struct raw_breakpoint *todel)
 
 	      *bp_link = bp->next;
 
-	      ret = the_target->pt->remove_point (bp->raw_type, bp->pc,
-						  bp->kind, bp);
+	      ret = the_target->remove_point (bp->raw_type, bp->pc,
+					      bp->kind, bp);
 	      if (ret != 0)
 		{
 		  /* Something went wrong, relink the breakpoint.  */
@@ -1005,7 +1005,7 @@ static int
 z_type_supported (char z_type)
 {
   return (z_type >= '0' && z_type <= '4'
-	  && the_target->pt->supports_z_point_type (z_type));
+	  && the_target->supports_z_point_type (z_type));
 }
 
 /* Create a new GDB breakpoint of type Z_TYPE at ADDR with kind KIND.
@@ -1532,7 +1532,7 @@ uninsert_raw_breakpoint (struct raw_breakpoint *bp)
 
       bp->inserted = 0;
 
-      err = the_target->pt->remove_point (bp->raw_type, bp->pc, bp->kind, bp);
+      err = the_target->remove_point (bp->raw_type, bp->pc, bp->kind, bp);
       if (err != 0)
 	{
 	  bp->inserted = 1;
@@ -1621,7 +1621,7 @@ reinsert_raw_breakpoint (struct raw_breakpoint *bp)
   if (bp->inserted)
     return;
 
-  err = the_target->pt->insert_point (bp->raw_type, bp->pc, bp->kind, bp);
+  err = the_target->insert_point (bp->raw_type, bp->pc, bp->kind, bp);
   if (err == 0)
     bp->inserted = 1;
   else if (debug_threads)
@@ -1856,7 +1856,7 @@ validate_inserted_breakpoint (struct raw_breakpoint *bp)
   gdb_assert (bp->raw_type == raw_bkpt_type_sw);
 
   buf = (unsigned char *) alloca (bp_size (bp));
-  err = the_target->pt->read_memory (bp->pc, buf, bp_size (bp));
+  err = the_target->read_memory (bp->pc, buf, bp_size (bp));
   if (err || memcmp (buf, bp_opcode (bp), bp_size (bp)) != 0)
     {
       /* Tag it as gone.  */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index bbcc5046659..072a74bc738 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -942,10 +942,6 @@ nto_process_target::sw_breakpoint_from_kind (int kind, int *size)
   return the_low_target.breakpoint;
 }
 
-/* The QNX Neutrino target ops object.  */
-
-static nto_process_target the_nto_target;
-
 /* Global function called by server.c.  Initializes QNX Neutrino
    gdbserver.  */
 
@@ -955,8 +951,7 @@ initialize_low (void)
   sigset_t set;
 
   TRACE ("%s\n", __func__);
-  the_target.reset (new process_stratum_target);
-  the_target->pt = &the_nto_target;
+  the_target.reset (new nto_process_target);
 
   /* We use SIGUSR1 to gain control after we block waiting for a process.
      We use sigwaitevent to wait.  */
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index be4634079ad..189b6713b37 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -44,7 +44,7 @@ extern struct nto_target_ops the_low_target;
 
 /* Target ops definitions for a QNX Neutrino target.  */
 
-class nto_process_target : public process_target {
+class nto_process_target : public process_stratum_target {
 public:
 
   int create_inferior (const char *program,
diff --git a/gdbserver/regcache.c b/gdbserver/regcache.c
index ec9d70d42fb..33d38879dc6 100644
--- a/gdbserver/regcache.c
+++ b/gdbserver/regcache.c
@@ -477,13 +477,13 @@ collect_register_by_name (struct regcache *regcache,
 CORE_ADDR
 regcache_read_pc (struct regcache *regcache)
 {
-  return the_target->pt->read_pc (regcache);
+  return the_target->read_pc (regcache);
 }
 
 void
 regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
-  the_target->pt->write_pc (regcache, pc);
+  the_target->write_pc (regcache, pc);
 }
 
 #endif
diff --git a/gdbserver/remote-utils.c b/gdbserver/remote-utils.c
index 14e89332db4..712ac963653 100644
--- a/gdbserver/remote-utils.c
+++ b/gdbserver/remote-utils.c
@@ -710,7 +710,7 @@ putpkt_binary_1 (char *buf, int cnt, int is_notif)
 
       /* Check for an input interrupt while we're here.  */
       if (cc == '\003' && current_thread != NULL)
-	the_target->pt->request_interrupt ();
+	the_target->request_interrupt ();
     }
   while (cc != '+');
 
@@ -779,7 +779,7 @@ input_interrupt (int unused)
 	  return;
 	}
 
-      the_target->pt->request_interrupt ();
+      the_target->request_interrupt ();
     }
 }
 
@@ -986,7 +986,7 @@ getpkt (char *buf)
 	     check for an input interrupt.  */
 	  if (c == '\003')
 	    {
-	      the_target->pt->request_interrupt ();
+	      the_target->request_interrupt ();
 	      continue;
 	    }
 
@@ -1076,7 +1076,7 @@ getpkt (char *buf)
     {
       /* Consume the interrupt character in the buffer.  */
       readchar ();
-      the_target->pt->request_interrupt ();
+      the_target->request_interrupt ();
     }
 
   return bp - buf;
@@ -1214,7 +1214,7 @@ prepare_resume_reply (char *buf, ptid_t ptid,
 
 	regcache = get_thread_regcache (current_thread, 1);
 
-	if (the_target->pt->stopped_by_watchpoint ())
+	if (the_target->stopped_by_watchpoint ())
 	  {
 	    CORE_ADDR addr;
 	    int i;
@@ -1222,7 +1222,7 @@ prepare_resume_reply (char *buf, ptid_t ptid,
 	    memcpy (buf, "watch:", 6);
 	    buf += 6;
 
-	    addr = the_target->pt->stopped_data_address ();
+	    addr = the_target->stopped_data_address ();
 
 	    /* Convert each byte of the address into two hexadecimal
 	       chars.  Note that we take sizeof (void *) instead of
diff --git a/gdbserver/server.c b/gdbserver/server.c
index 00456d8d7ed..a4cb1eb4181 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -740,7 +740,7 @@ handle_general_set (char *own_buf)
 	}
 
       req_str = req ? "non-stop" : "all-stop";
-      if (the_target->pt->start_non_stop (req == 1) != 0)
+      if (the_target->start_non_stop (req == 1) != 0)
 	{
 	  fprintf (stderr, "Setting %s mode failed\n", req_str);
 	  write_enn (own_buf);
@@ -1234,7 +1234,7 @@ handle_detach (char *own_buf)
 	    debug_printf ("Forcing non-stop mode\n");
 
 	  non_stop = true;
-	  the_target->pt->start_non_stop (true);
+	  the_target->start_non_stop (true);
 	}
 
       process->gdb_detached = 1;
@@ -1442,13 +1442,13 @@ handle_qxfer_auxv (const char *annex,
 		   gdb_byte *readbuf, const gdb_byte *writebuf,
 		   ULONGEST offset, LONGEST len)
 {
-  if (!the_target->pt->supports_read_auxv () || writebuf != NULL)
+  if (!the_target->supports_read_auxv () || writebuf != NULL)
     return -2;
 
   if (annex[0] != '\0' || current_thread == NULL)
     return -1;
 
-  return the_target->pt->read_auxv (offset, readbuf, len);
+  return the_target->read_auxv (offset, readbuf, len);
 }
 
 /* Handle qXfer:exec-file:read.  */
@@ -1462,7 +1462,7 @@ handle_qxfer_exec_file (const char *annex,
   ULONGEST pid;
   int total_len;
 
-  if (!the_target->pt->supports_pid_to_exec_file () || writebuf != NULL)
+  if (!the_target->supports_pid_to_exec_file () || writebuf != NULL)
     return -2;
 
   if (annex[0] == '\0')
@@ -1482,7 +1482,7 @@ handle_qxfer_exec_file (const char *annex,
   if (pid <= 0)
     return -1;
 
-  file = the_target->pt->pid_to_exec_file (pid);
+  file = the_target->pid_to_exec_file (pid);
   if (file == NULL)
     return -1;
 
@@ -1575,11 +1575,11 @@ handle_qxfer_libraries_svr4 (const char *annex,
     return -2;
 
   if (current_thread == NULL
-      || !the_target->pt->supports_qxfer_libraries_svr4 ())
+      || !the_target->supports_qxfer_libraries_svr4 ())
     return -1;
 
-  return the_target->pt->qxfer_libraries_svr4 (annex, readbuf, writebuf,
-					       offset, len);
+  return the_target->qxfer_libraries_svr4 (annex, readbuf, writebuf,
+					   offset, len);
 }
 
 /* Handle qXfer:osadata:read.  */
@@ -1589,10 +1589,10 @@ handle_qxfer_osdata (const char *annex,
 		     gdb_byte *readbuf, const gdb_byte *writebuf,
 		     ULONGEST offset, LONGEST len)
 {
-  if (!the_target->pt->supports_qxfer_osdata () || writebuf != NULL)
+  if (!the_target->supports_qxfer_osdata () || writebuf != NULL)
     return -2;
 
-  return the_target->pt->qxfer_osdata (annex, readbuf, NULL, offset, len);
+  return the_target->qxfer_osdata (annex, readbuf, NULL, offset, len);
 }
 
 /* Handle qXfer:siginfo:read and qXfer:siginfo:write.  */
@@ -1602,13 +1602,13 @@ handle_qxfer_siginfo (const char *annex,
 		      gdb_byte *readbuf, const gdb_byte *writebuf,
 		      ULONGEST offset, LONGEST len)
 {
-  if (!the_target->pt->supports_qxfer_siginfo ())
+  if (!the_target->supports_qxfer_siginfo ())
     return -2;
 
   if (annex[0] != '\0' || current_thread == NULL)
     return -1;
 
-  return the_target->pt->qxfer_siginfo (annex, readbuf, writebuf, offset, len);
+  return the_target->qxfer_siginfo (annex, readbuf, writebuf, offset, len);
 }
 
 /* Handle qXfer:statictrace:read.  */
@@ -1794,13 +1794,13 @@ static int
 handle_qxfer_fdpic (const char *annex, gdb_byte *readbuf,
 		    const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
 {
-  if (!the_target->pt->supports_read_loadmap ())
+  if (!the_target->supports_read_loadmap ())
     return -2;
 
   if (current_thread == NULL)
     return -1;
 
-  return the_target->pt->read_loadmap (annex, offset, readbuf, len);
+  return the_target->read_loadmap (annex, offset, readbuf, len);
 }
 
 /* Handle qXfer:btrace:read.  */
@@ -2195,7 +2195,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 	tracepoint_look_up_symbols ();
 
       if (current_thread != NULL)
-	the_target->pt->look_up_symbols ();
+	the_target->look_up_symbols ();
 
       current_thread = save_thread;
 
@@ -2236,13 +2236,13 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 	}
     }
 
-  if (the_target->pt->supports_read_offsets ()
+  if (the_target->supports_read_offsets ()
       && strcmp ("qOffsets", own_buf) == 0)
     {
       CORE_ADDR text, data;
 
       require_running_or_return (own_buf);
-      if (the_target->pt->read_offsets (&text, &data))
+      if (the_target->read_offsets (&text, &data))
 	sprintf (own_buf, "Text=%lX;Data=%lX;Bss=%lX",
 		 (long)text, (long)data, (long)data);
       else
@@ -2366,7 +2366,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (target_supports_catch_syscall ())
 	strcat (own_buf, ";QCatchSyscalls+");
 
-      if (the_target->pt->supports_qxfer_libraries_svr4 ())
+      if (the_target->supports_qxfer_libraries_svr4 ())
 	strcat (own_buf, ";qXfer:libraries-svr4:read+"
 		";augmented-libraries-svr4-read+");
       else
@@ -2376,13 +2376,13 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 	  strcat (own_buf, ";qXfer:libraries:read+");
 	}
 
-      if (the_target->pt->supports_read_auxv ())
+      if (the_target->supports_read_auxv ())
 	strcat (own_buf, ";qXfer:auxv:read+");
 
-      if (the_target->pt->supports_qxfer_siginfo ())
+      if (the_target->supports_qxfer_siginfo ())
 	strcat (own_buf, ";qXfer:siginfo:read+;qXfer:siginfo:write+");
 
-      if (the_target->pt->supports_read_loadmap ())
+      if (the_target->supports_read_loadmap ())
 	strcat (own_buf, ";qXfer:fdpic:read+");
 
       /* We always report qXfer:features:read, as targets may
@@ -2394,7 +2394,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (cs.transport_is_reliable)
 	strcat (own_buf, ";QStartNoAckMode+");
 
-      if (the_target->pt->supports_qxfer_osdata ())
+      if (the_target->supports_qxfer_osdata ())
 	strcat (own_buf, ";qXfer:osdata:read+");
 
       if (target_supports_multi_process ())
@@ -2452,7 +2452,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (target_supports_stopped_by_hw_breakpoint ())
 	strcat (own_buf, ";hwbreak+");
 
-      if (the_target->pt->supports_pid_to_exec_file ())
+      if (the_target->supports_pid_to_exec_file ())
 	strcat (own_buf, ";qXfer:exec-file:read+");
 
       strcat (own_buf, ";vContSupported+");
@@ -2469,7 +2469,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
     }
 
   /* Thread-local storage support.  */
-  if (the_target->pt->supports_get_tls_address ()
+  if (the_target->supports_get_tls_address ()
       && startswith (own_buf, "qGetTLSAddr:"))
     {
       char *p = own_buf + 12;
@@ -2515,8 +2515,8 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 	  if (thread == NULL)
 	    err = 2;
 	  else
-	    err = the_target->pt->get_tls_address (thread, parts[0], parts[1],
-						   &address);
+	    err = the_target->get_tls_address (thread, parts[0], parts[1],
+					       &address);
 	}
 
       if (err == 0)
@@ -2534,7 +2534,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
     }
 
   /* Windows OS Thread Information Block address support.  */
-  if (the_target->pt->supports_get_tib_address ()
+  if (the_target->supports_get_tib_address ()
       && startswith (own_buf, "qGetTIBAddr:"))
     {
       const char *annex;
@@ -2542,7 +2542,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       CORE_ADDR tlb;
       ptid_t ptid = read_ptid (own_buf + 12, &annex);
 
-      n = the_target->pt->get_tib_address (ptid, &tlb);
+      n = the_target->get_tib_address (ptid, &tlb);
       if (n == 1)
 	{
 	  strcpy (own_buf, paddress(tlb));
@@ -2579,7 +2579,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 
       write_ok (own_buf);
 
-      if (the_target->pt->handle_monitor_command (mon) == 0)
+      if (the_target->handle_monitor_command (mon) == 0)
 	/* Default processing.  */
 	handle_monitor_command (mon, own_buf);
 
@@ -2848,7 +2848,7 @@ resume (struct thread_resume *actions, size_t num_actions)
       enable_async_io ();
     }
 
-  the_target->pt->resume (actions, num_actions);
+  the_target->resume (actions, num_actions);
 
   if (non_stop)
     write_ok (cs.own_buf);
@@ -3089,7 +3089,7 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
     {
       if (strcmp (own_buf, "vCtrlC") == 0)
 	{
-	  the_target->pt->request_interrupt ();
+	  the_target->request_interrupt ();
 	  write_ok (own_buf);
 	  return;
 	}
@@ -3219,7 +3219,7 @@ queue_stop_reply_callback (thread_info *thread)
 {
   /* For now, assume targets that don't have this callback also don't
      manage the thread's last_status field.  */
-  if (!the_target->pt->supports_thread_stopped ())
+  if (!the_target->supports_thread_stopped ())
     {
       struct vstop_notif *new_notif = new struct vstop_notif;
 
@@ -3886,7 +3886,7 @@ captured_main (int argc, char *argv[])
 		     down without informing GDB.  */
 		  if (!non_stop)
 		    {
-		      if (the_target->pt->start_non_stop (true))
+		      if (the_target->start_non_stop (true))
 			non_stop = 1;
 
 		      /* Detaching implicitly resumes all threads;
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 048fd5ad6e9..e72935d7c55 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -62,7 +62,7 @@ prepare_to_access_memory (void)
      it.  */
   prev_general_thread = cs.general_thread;
 
-  int res = the_target->pt->prepare_to_access_memory ();
+  int res = the_target->prepare_to_access_memory ();
   if (res != 0)
     return res;
 
@@ -70,7 +70,7 @@ prepare_to_access_memory (void)
     {
       if (mythread_alive (thread->id))
 	{
-	  if (stopped == NULL && the_target->pt->supports_thread_stopped ()
+	  if (stopped == NULL && the_target->supports_thread_stopped ()
 	      && target_thread_stopped (thread))
 	    stopped = thread;
 
@@ -114,7 +114,7 @@ done_accessing_memory (void)
 {
   client_state &cs = get_client_state ();
 
-  the_target->pt->done_accessing_memory ();
+  the_target->done_accessing_memory ();
 
   /* Restore the previous selected thread.  */
   cs.general_thread = prev_general_thread;
@@ -125,7 +125,7 @@ int
 read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
 {
   int res;
-  res = the_target->pt->read_memory (memaddr, myaddr, len);
+  res = the_target->read_memory (memaddr, myaddr, len);
   check_mem_read (memaddr, myaddr, len);
   return res;
 }
@@ -156,7 +156,7 @@ target_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
      update it.  */
   gdb::byte_vector buffer (myaddr, myaddr + len);
   check_mem_write (memaddr, buffer.data (), myaddr, len);
-  return the_target->pt->write_memory (memaddr, buffer.data (), len);
+  return the_target->write_memory (memaddr, buffer.data (), len);
 }
 
 ptid_t
@@ -210,7 +210,7 @@ target_stop_and_wait (ptid_t ptid)
   resume_info.thread = ptid;
   resume_info.kind = resume_stop;
   resume_info.sig = GDB_SIGNAL_0;
-  the_target->pt->resume (&resume_info, 1);
+  the_target->resume (&resume_info, 1);
 
   non_stop = true;
   mywait (ptid, &status, 0, 0);
@@ -222,7 +222,7 @@ target_stop_and_wait (ptid_t ptid)
 ptid_t
 target_wait (ptid_t ptid, struct target_waitstatus *status, int options)
 {
-  return the_target->pt->wait (ptid, status, options);
+  return the_target->wait (ptid, status, options);
 }
 
 /* See target/target.h.  */
@@ -230,7 +230,7 @@ target_wait (ptid_t ptid, struct target_waitstatus *status, int options)
 void
 target_mourn_inferior (ptid_t ptid)
 {
-  the_target->pt->mourn (find_process_pid (ptid.pid ()));
+  the_target->mourn (find_process_pid (ptid.pid ()));
 }
 
 /* See target/target.h.  */
@@ -243,7 +243,7 @@ target_continue_no_signal (ptid_t ptid)
   resume_info.thread = ptid;
   resume_info.kind = resume_continue;
   resume_info.sig = GDB_SIGNAL_0;
-  the_target->pt->resume (&resume_info, 1);
+  the_target->resume (&resume_info, 1);
 }
 
 /* See target/target.h.  */
@@ -256,7 +256,7 @@ target_continue (ptid_t ptid, enum gdb_signal signal)
   resume_info.thread = ptid;
   resume_info.kind = resume_continue;
   resume_info.sig = gdb_signal_to_host (signal);
-  the_target->pt->resume (&resume_info, 1);
+  the_target->resume (&resume_info, 1);
 }
 
 /* See target/target.h.  */
@@ -264,7 +264,7 @@ target_continue (ptid_t ptid, enum gdb_signal signal)
 int
 target_supports_multi_process (void)
 {
-  return the_target->pt->supports_multi_process ();
+  return the_target->supports_multi_process ();
 }
 
 /* Convert pid to printable format.  */
@@ -296,7 +296,7 @@ kill_inferior (process_info *proc)
 {
   gdb_agent_about_to_close (proc->pid);
 
-  return the_target->pt->kill (proc);
+  return the_target->kill (proc);
 }
 
 /* Define it.  */
@@ -351,177 +351,183 @@ target_terminal::info (const char *arg, int from_tty)
    See target.h for definitions.  */
 
 void
-process_target::post_create_inferior ()
+process_stratum_target::post_create_inferior ()
 {
   /* Nop.  */
 }
 
 int
-process_target::prepare_to_access_memory ()
+process_stratum_target::prepare_to_access_memory ()
 {
   return 0;
 }
 
 void
-process_target::done_accessing_memory ()
+process_stratum_target::done_accessing_memory ()
 {
   /* Nop.  */
 }
 
 void
-process_target::look_up_symbols ()
+process_stratum_target::look_up_symbols ()
 {
   /* Nop.  */
 }
 
 bool
-process_target::supports_read_auxv ()
+process_stratum_target::supports_read_auxv ()
 {
   return false;
 }
 
 int
-process_target::read_auxv (CORE_ADDR offset, unsigned char *myaddr,
-			   unsigned int len)
+process_stratum_target::read_auxv (CORE_ADDR offset, unsigned char *myaddr,
+				   unsigned int len)
 {
   gdb_assert_not_reached ("target op read_auxv not supported");
 }
 
 bool
-process_target::supports_z_point_type (char z_type)
+process_stratum_target::supports_z_point_type (char z_type)
 {
   return false;
 }
 
 int
-process_target::insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
-			      int size, raw_breakpoint *bp)
+process_stratum_target::insert_point (enum raw_bkpt_type type,
+				      CORE_ADDR addr,
+				      int size, raw_breakpoint *bp)
 {
   return 1;
 }
 
 int
-process_target::remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
-			      int size, raw_breakpoint *bp)
+process_stratum_target::remove_point (enum raw_bkpt_type type,
+				      CORE_ADDR addr,
+				      int size, raw_breakpoint *bp)
 {
   return 1;
 }
 
 bool
-process_target::stopped_by_sw_breakpoint ()
+process_stratum_target::stopped_by_sw_breakpoint ()
 {
   return false;
 }
 
 bool
-process_target::supports_stopped_by_sw_breakpoint ()
+process_stratum_target::supports_stopped_by_sw_breakpoint ()
 {
   return false;
 }
 
 bool
-process_target::stopped_by_hw_breakpoint ()
+process_stratum_target::stopped_by_hw_breakpoint ()
 {
   return false;
 }
 
 bool
-process_target::supports_stopped_by_hw_breakpoint ()
+process_stratum_target::supports_stopped_by_hw_breakpoint ()
 {
   return false;
 }
 
 bool
-process_target::supports_hardware_single_step ()
+process_stratum_target::supports_hardware_single_step ()
 {
   return false;
 }
 
 bool
-process_target::stopped_by_watchpoint ()
+process_stratum_target::stopped_by_watchpoint ()
 {
   return false;
 }
 
 CORE_ADDR
-process_target::stopped_data_address ()
+process_stratum_target::stopped_data_address ()
 {
   return 0;
 }
 
 bool
-process_target::supports_read_offsets ()
+process_stratum_target::supports_read_offsets ()
 {
   return false;
 }
 
 int
-process_target::read_offsets (CORE_ADDR *text, CORE_ADDR *data)
+process_stratum_target::read_offsets (CORE_ADDR *text, CORE_ADDR *data)
 {
   gdb_assert_not_reached ("target op read_offsets not supported");
 }
 
 bool
-process_target::supports_get_tls_address ()
+process_stratum_target::supports_get_tls_address ()
 {
   return false;
 }
 
 int
-process_target::get_tls_address (thread_info *thread, CORE_ADDR offset,
-				 CORE_ADDR load_module, CORE_ADDR *address)
+process_stratum_target::get_tls_address (thread_info *thread,
+					 CORE_ADDR offset,
+					 CORE_ADDR load_module,
+					 CORE_ADDR *address)
 {
   gdb_assert_not_reached ("target op get_tls_address not supported");
 }
 
 void
-process_target::hostio_last_error (char *buf)
+process_stratum_target::hostio_last_error (char *buf)
 {
   hostio_last_error_from_errno (buf);
 }
 
 bool
-process_target::supports_qxfer_osdata ()
+process_stratum_target::supports_qxfer_osdata ()
 {
   return false;
 }
 
 int
-process_target::qxfer_osdata (const char *annex, unsigned char *readbuf,
-			      unsigned const char *writebuf,
-			      CORE_ADDR offset, int len)
+process_stratum_target::qxfer_osdata (const char *annex,
+				      unsigned char *readbuf,
+				      unsigned const char *writebuf,
+				      CORE_ADDR offset, int len)
 {
   gdb_assert_not_reached ("target op qxfer_osdata not supported");
 }
 
 bool
-process_target::supports_qxfer_siginfo ()
+process_stratum_target::supports_qxfer_siginfo ()
 {
   return false;
 }
 
 int
-process_target::qxfer_siginfo (const char *annex, unsigned char *readbuf,
-			       unsigned const char *writebuf,
-			       CORE_ADDR offset, int len)
+process_stratum_target::qxfer_siginfo (const char *annex,
+				       unsigned char *readbuf,
+				       unsigned const char *writebuf,
+				       CORE_ADDR offset, int len)
 {
   gdb_assert_not_reached ("target op qxfer_siginfo not supported");
 }
 
 bool
-process_target::supports_non_stop ()
+process_stratum_target::supports_non_stop ()
 {
   return false;
 }
 
 bool
-process_target::async (bool enable)
+process_stratum_target::async (bool enable)
 {
   return false;
 }
 
 int
-process_target::start_non_stop (bool enable)
+process_stratum_target::start_non_stop (bool enable)
 {
   if (enable)
     return -1;
@@ -530,134 +536,136 @@ process_target::start_non_stop (bool enable)
 }
 
 bool
-process_target::supports_multi_process ()
+process_stratum_target::supports_multi_process ()
 {
   return false;
 }
 
 bool
-process_target::supports_fork_events ()
+process_stratum_target::supports_fork_events ()
 {
   return false;
 }
 
 bool
-process_target::supports_vfork_events ()
+process_stratum_target::supports_vfork_events ()
 {
   return false;
 }
 
 bool
-process_target::supports_exec_events ()
+process_stratum_target::supports_exec_events ()
 {
   return false;
 }
 
 void
-process_target::handle_new_gdb_connection ()
+process_stratum_target::handle_new_gdb_connection ()
 {
   /* Nop.  */
 }
 
 int
-process_target::handle_monitor_command (char *mon)
+process_stratum_target::handle_monitor_command (char *mon)
 {
   return 0;
 }
 
 int
-process_target::core_of_thread (ptid_t ptid)
+process_stratum_target::core_of_thread (ptid_t ptid)
 {
   return -1;
 }
 
 bool
-process_target::supports_read_loadmap ()
+process_stratum_target::supports_read_loadmap ()
 {
   return false;
 }
 
 int
-process_target::read_loadmap (const char *annex, CORE_ADDR offset,
-			      unsigned char *myaddr, unsigned int len)
+process_stratum_target::read_loadmap (const char *annex,
+				      CORE_ADDR offset,
+				      unsigned char *myaddr,
+				      unsigned int len)
 {
   gdb_assert_not_reached ("target op read_loadmap not supported");
 }
 
 void
-process_target::process_qsupported (char **features, int count)
+process_stratum_target::process_qsupported (char **features, int count)
 {
   /* Nop.  */
 }
 
 bool
-process_target::supports_tracepoints ()
+process_stratum_target::supports_tracepoints ()
 {
   return false;
 }
 
 CORE_ADDR
-process_target::read_pc (regcache *regcache)
+process_stratum_target::read_pc (regcache *regcache)
 {
   gdb_assert_not_reached ("regcache_read_pc: Unable to find PC");
 }
 
 void
-process_target::write_pc (regcache *regcache, CORE_ADDR pc)
+process_stratum_target::write_pc (regcache *regcache, CORE_ADDR pc)
 {
   gdb_assert_not_reached ("regcache_write_pc: Unable to update PC");
 }
 
 bool
-process_target::supports_thread_stopped ()
+process_stratum_target::supports_thread_stopped ()
 {
   return false;
 }
 
 bool
-process_target::thread_stopped (thread_info *thread)
+process_stratum_target::thread_stopped (thread_info *thread)
 {
   gdb_assert_not_reached ("target op thread_stopped not supported");
 }
 
 bool
-process_target::supports_get_tib_address ()
+process_stratum_target::supports_get_tib_address ()
 {
   return false;
 }
 
 int
-process_target::get_tib_address (ptid_t ptid, CORE_ADDR *address)
+process_stratum_target::get_tib_address (ptid_t ptid, CORE_ADDR *address)
 {
   gdb_assert_not_reached ("target op get_tib_address not supported");
 }
 
 void
-process_target::pause_all (bool freeze)
+process_stratum_target::pause_all (bool freeze)
 {
   /* Nop.  */
 }
 
 void
-process_target::unpause_all (bool unfreeze)
+process_stratum_target::unpause_all (bool unfreeze)
 {
   /* Nop.  */
 }
 
 void
-process_target::stabilize_threads ()
+process_stratum_target::stabilize_threads ()
 {
   /* Nop.  */
 }
 
 bool
-process_target::supports_fast_tracepoints ()
+process_stratum_target::supports_fast_tracepoints ()
 {
   return false;
 }
 
 int
-process_target::install_fast_tracepoint_jump_pad (
+process_stratum_target::install_fast_tracepoint_jump_pad (
     CORE_ADDR tpoint, CORE_ADDR tpaddr, CORE_ADDR collector,
     CORE_ADDR lockaddr, ULONGEST orig_size, CORE_ADDR *jump_entry,
     CORE_ADDR *trampoline, ULONGEST *trampoline_size,
@@ -670,58 +678,58 @@ process_target::install_fast_tracepoint_jump_pad (
 }
 
 int
-process_target::get_min_fast_tracepoint_insn_len ()
+process_stratum_target::get_min_fast_tracepoint_insn_len ()
 {
   return 0;
 }
 
 struct emit_ops *
-process_target::emit_ops ()
+process_stratum_target::emit_ops ()
 {
   return nullptr;
 }
 
 bool
-process_target::supports_disable_randomization ()
+process_stratum_target::supports_disable_randomization ()
 {
   return false;
 }
 
 bool
-process_target::supports_qxfer_libraries_svr4 ()
+process_stratum_target::supports_qxfer_libraries_svr4 ()
 {
   return false;
 }
 
 int
-process_target::qxfer_libraries_svr4 (const char *annex,
-				      unsigned char *readbuf,
-				      unsigned const char *writebuf,
-				      CORE_ADDR offset, int len)
+process_stratum_target::qxfer_libraries_svr4 (const char *annex,
+					      unsigned char *readbuf,
+					      unsigned const char *writebuf,
+					      CORE_ADDR offset, int len)
 {
   gdb_assert_not_reached ("target op qxfer_libraries_svr4 not supported");
 }
 
 bool
-process_target::supports_agent ()
+process_stratum_target::supports_agent ()
 {
   return false;
 }
 
 btrace_target_info *
-process_target::enable_btrace (ptid_t ptid, const btrace_config *conf)
+process_stratum_target::enable_btrace (ptid_t ptid, const btrace_config *conf)
 {
   error (_("Target does not support branch tracing."));
 }
 
 int
-process_target::disable_btrace (btrace_target_info *tinfo)
+process_stratum_target::disable_btrace (btrace_target_info *tinfo)
 {
   error (_("Target does not support branch tracing."));
 }
 
 int
-process_target::read_btrace (btrace_target_info *tinfo,
+process_stratum_target::read_btrace (btrace_target_info *tinfo,
 			     buffer *buffer,
 			     enum btrace_read_type type)
 {
@@ -729,58 +737,58 @@ process_target::read_btrace (btrace_target_info *tinfo,
 }
 
 int
-process_target::read_btrace_conf (const btrace_target_info *tinfo,
-				  buffer *buffer)
+process_stratum_target::read_btrace_conf (const btrace_target_info *tinfo,
+					  buffer *buffer)
 {
   error (_("Target does not support branch tracing."));
 }
 
 bool
-process_target::supports_range_stepping ()
+process_stratum_target::supports_range_stepping ()
 {
   return false;
 }
 
 bool
-process_target::supports_pid_to_exec_file ()
+process_stratum_target::supports_pid_to_exec_file ()
 {
   return false;
 }
 
 char *
-process_target::pid_to_exec_file (int pid)
+process_stratum_target::pid_to_exec_file (int pid)
 {
   gdb_assert_not_reached ("target op pid_to_exec_file not supported");
 }
 
 bool
-process_target::supports_multifs ()
+process_stratum_target::supports_multifs ()
 {
   return false;
 }
 
 int
-process_target::multifs_open (int pid, const char *filename,
-			      int flags, mode_t mode)
+process_stratum_target::multifs_open (int pid, const char *filename,
+				      int flags, mode_t mode)
 {
   return open (filename, flags, mode);
 }
 
 int
-process_target::multifs_unlink (int pid, const char *filename)
+process_stratum_target::multifs_unlink (int pid, const char *filename)
 {
   return unlink (filename);
 }
 
 ssize_t
-process_target::multifs_readlink (int pid, const char *filename,
-				  char *buf, size_t bufsiz)
+process_stratum_target::multifs_readlink (int pid, const char *filename,
+					  char *buf, size_t bufsiz)
 {
   return readlink (filename, buf, bufsiz);
 }
 
 int
-process_target::breakpoint_kind_from_pc (CORE_ADDR *pcptr)
+process_stratum_target::breakpoint_kind_from_pc (CORE_ADDR *pcptr)
 {
   /* The default behavior is to use the size of a breakpoint as the
      kind.  */
@@ -790,38 +798,38 @@ process_target::breakpoint_kind_from_pc (CORE_ADDR *pcptr)
 }
 
 int
-process_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
+process_stratum_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
 {
   return breakpoint_kind_from_pc (pcptr);
 }
 
 const char *
-process_target::thread_name (ptid_t thread)
+process_stratum_target::thread_name (ptid_t thread)
 {
   return nullptr;
 }
 
 bool
-process_target::thread_handle (ptid_t ptid, gdb_byte **handle,
-			       int *handle_len)
+process_stratum_target::thread_handle (ptid_t ptid, gdb_byte **handle,
+				       int *handle_len)
 {
   return false;
 }
 
 bool
-process_target::supports_software_single_step ()
+process_stratum_target::supports_software_single_step ()
 {
   return false;
 }
 
 bool
-process_target::supports_catch_syscall ()
+process_stratum_target::supports_catch_syscall ()
 {
   return false;
 }
 
 int
-process_target::get_ipa_tdesc_idx ()
+process_stratum_target::get_ipa_tdesc_idx ()
 {
   return 0;
 }
diff --git a/gdbserver/target.h b/gdbserver/target.h
index ac0ada0cd38..efdabaef580 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -63,21 +63,13 @@ struct thread_resume
   CORE_ADDR step_range_end;	/* Exclusive */
 };
 
-class process_target;
-
 /* GDBserver doesn't have a concept of strata like GDB, but we call
    its target vector "process_stratum" anyway for the benefit of
    shared code.  */
-struct process_stratum_target
-{
-  /* The object that will gradually replace this struct.  */
-  process_target *pt;
-};
-
-class process_target {
+class process_stratum_target {
 public:
 
-  virtual ~process_target () = default;
+  virtual ~process_stratum_target () = default;
 
   /* Start a new process.
 
@@ -509,78 +501,78 @@ public:
 extern std::unique_ptr<process_stratum_target> the_target;
 
 #define target_create_inferior(program, program_args)	\
-  the_target->pt->create_inferior (program, program_args)
+  the_target->create_inferior (program, program_args)
 
 #define target_post_create_inferior()			 \
-  the_target->pt->post_create_inferior ()
+  the_target->post_create_inferior ()
 
 #define myattach(pid) \
-  the_target->pt->attach (pid)
+  the_target->attach (pid)
 
 int kill_inferior (process_info *proc);
 
 #define target_supports_fork_events() \
-  the_target->pt->supports_fork_events ()
+  the_target->supports_fork_events ()
 
 #define target_supports_vfork_events() \
-  the_target->pt->supports_vfork_events ()
+  the_target->supports_vfork_events ()
 
 #define target_supports_exec_events() \
-  the_target->pt->supports_exec_events ()
+  the_target->supports_exec_events ()
 
 #define target_handle_new_gdb_connection()		 \
-  the_target->pt->handle_new_gdb_connection ()
+  the_target->handle_new_gdb_connection ()
 
 #define detach_inferior(proc) \
-  the_target->pt->detach (proc)
+  the_target->detach (proc)
 
 #define mythread_alive(pid) \
-  the_target->pt->thread_alive (pid)
+  the_target->thread_alive (pid)
 
 #define fetch_inferior_registers(regcache, regno)	\
-  the_target->pt->fetch_registers (regcache, regno)
+  the_target->fetch_registers (regcache, regno)
 
 #define store_inferior_registers(regcache, regno) \
-  the_target->pt->store_registers (regcache, regno)
+  the_target->store_registers (regcache, regno)
 
 #define join_inferior(pid) \
-  the_target->pt->join (pid)
+  the_target->join (pid)
 
 #define target_supports_non_stop() \
-  the_target->pt->supports_non_stop ()
+  the_target->supports_non_stop ()
 
 #define target_async(enable) \
-  the_target->pt->async (enable)
+  the_target->async (enable)
 
 #define target_process_qsupported(features, count)	\
-  the_target->pt->process_qsupported (features, count)
+  the_target->process_qsupported (features, count)
 
 #define target_supports_catch_syscall()              	\
-  the_target->pt->supports_catch_syscall ()
+  the_target->supports_catch_syscall ()
 
 #define target_get_ipa_tdesc_idx()			\
-  the_target->pt->get_ipa_tdesc_idx ()
+  the_target->get_ipa_tdesc_idx ()
 
 #define target_supports_tracepoints()			\
-  the_target->pt->supports_tracepoints ()
+  the_target->supports_tracepoints ()
 
 #define target_supports_fast_tracepoints()		\
-  the_target->pt->supports_fast_tracepoints ()
+  the_target->supports_fast_tracepoints ()
 
 #define target_get_min_fast_tracepoint_insn_len()	\
-  the_target->pt->get_min_fast_tracepoint_insn_len ()
+  the_target->get_min_fast_tracepoint_insn_len ()
 
 #define target_thread_stopped(thread) \
-  the_target->pt->thread_stopped (thread)
+  the_target->thread_stopped (thread)
 
 #define target_pause_all(freeze)		\
-  the_target->pt->pause_all (freeze)
+  the_target->pause_all (freeze)
 
 #define target_unpause_all(unfreeze)		\
-  the_target->pt->unpause_all (unfreeze)
+  the_target->unpause_all (unfreeze)
 
 #define target_stabilize_threads()		\
-  the_target->pt->stabilize_threads ()
+  the_target->stabilize_threads ()
 
 #define target_install_fast_tracepoint_jump_pad(tpoint, tpaddr,		\
 						collector, lockaddr,	\
@@ -592,36 +584,36 @@ int kill_inferior (process_info *proc);
 						adjusted_insn_addr,	\
 						adjusted_insn_addr_end,	\
 						err)			\
-  the_target->pt->install_fast_tracepoint_jump_pad (tpoint, tpaddr,	\
-						    collector,lockaddr,	\
-						    orig_size, jump_entry, \
-						    trampoline,		\
-						    trampoline_size,	\
-						    jjump_pad_insn,	\
-						    jjump_pad_insn_size, \
-						    adjusted_insn_addr,	\
-						    adjusted_insn_addr_end, \
-						    err)
+  the_target->install_fast_tracepoint_jump_pad (tpoint, tpaddr,	\
+						collector,lockaddr,	\
+						orig_size, jump_entry,	\
+						trampoline,		\
+						trampoline_size,	\
+						jjump_pad_insn,		\
+						jjump_pad_insn_size,	\
+						adjusted_insn_addr,	\
+						adjusted_insn_addr_end, \
+						err)
 
 #define target_emit_ops() \
-  the_target->pt->emit_ops ()
+  the_target->emit_ops ()
 
 #define target_supports_disable_randomization() \
-  the_target->pt->supports_disable_randomization ()
+  the_target->supports_disable_randomization ()
 
 #define target_supports_agent() \
-  the_target->pt->supports_agent ()
+  the_target->supports_agent ()
 
 static inline struct btrace_target_info *
 target_enable_btrace (ptid_t ptid, const struct btrace_config *conf)
 {
-  return the_target->pt->enable_btrace (ptid, conf);
+  return the_target->enable_btrace (ptid, conf);
 }
 
 static inline int
 target_disable_btrace (struct btrace_target_info *tinfo)
 {
-  return the_target->pt->disable_btrace (tinfo);
+  return the_target->disable_btrace (tinfo);
 }
 
 static inline int
@@ -629,42 +621,42 @@ target_read_btrace (struct btrace_target_info *tinfo,
 		    struct buffer *buffer,
 		    enum btrace_read_type type)
 {
-  return the_target->pt->read_btrace (tinfo, buffer, type);
+  return the_target->read_btrace (tinfo, buffer, type);
 }
 
 static inline int
 target_read_btrace_conf (struct btrace_target_info *tinfo,
 			 struct buffer *buffer)
 {
-  return the_target->pt->read_btrace_conf (tinfo, buffer);
+  return the_target->read_btrace_conf (tinfo, buffer);
 }
 
 #define target_supports_range_stepping() \
-  the_target->pt->supports_range_stepping ()
+  the_target->supports_range_stepping ()
 
 #define target_supports_stopped_by_sw_breakpoint() \
-  the_target->pt->supports_stopped_by_sw_breakpoint ()
+  the_target->supports_stopped_by_sw_breakpoint ()
 
 #define target_stopped_by_sw_breakpoint() \
-  the_target->pt->stopped_by_sw_breakpoint ()
+  the_target->stopped_by_sw_breakpoint ()
 
 #define target_supports_stopped_by_hw_breakpoint() \
-  the_target->pt->supports_stopped_by_hw_breakpoint ()
+  the_target->supports_stopped_by_hw_breakpoint ()
 
 #define target_supports_hardware_single_step() \
-  the_target->pt->supports_hardware_single_step ()
+  the_target->supports_hardware_single_step ()
 
 #define target_stopped_by_hw_breakpoint() \
-  the_target->pt->stopped_by_hw_breakpoint ()
+  the_target->stopped_by_hw_breakpoint ()
 
 #define target_breakpoint_kind_from_pc(pcptr) \
-  the_target->pt->breakpoint_kind_from_pc (pcptr)
+  the_target->breakpoint_kind_from_pc (pcptr)
 
 #define target_breakpoint_kind_from_current_state(pcptr) \
-  the_target->pt->breakpoint_kind_from_current_state (pcptr)
+  the_target->breakpoint_kind_from_current_state (pcptr)
 
 #define target_supports_software_single_step() \
-  the_target->pt->supports_software_single_step ()
+  the_target->supports_software_single_step ()
 
 ptid_t mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options,
 	       int connected_wait);
@@ -676,13 +668,13 @@ int prepare_to_access_memory (void);
 void done_accessing_memory (void);
 
 #define target_core_of_thread(ptid)		\
-  the_target->pt->core_of_thread (ptid)
+  the_target->core_of_thread (ptid)
 
 #define target_thread_name(ptid)                                \
-  the_target->pt->thread_name (ptid)
+  the_target->thread_name (ptid)
 
 #define target_thread_handle(ptid, handle, handle_len) \
-  the_target->pt->thread_handle (ptid, handle, handle_len)
+  the_target->thread_handle (ptid, handle, handle_len)
 
 int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len);
 
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 5b4dd36f5d0..c112aceae87 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -378,7 +378,7 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
     {
       struct target_waitstatus status;
 
-      the_target->pt->wait (minus_one_ptid, &status, 0);
+      the_target->wait (minus_one_ptid, &status, 0);
 
       /* Note win32_wait doesn't return thread events.  */
       if (status.kind != TARGET_WAITKIND_LOADED)
@@ -1843,15 +1843,10 @@ win32_process_target::sw_breakpoint_from_kind (int kind, int *size)
   return the_low_target.breakpoint;
 }
 
-/* The win32 target ops object.  */
-
-static win32_process_target the_win32_target;
-
 /* Initialize the Win32 backend.  */
 void
 initialize_low (void)
 {
-  the_target.reset (new process_stratum_target);
-  the_target->pt = &the_win32_target;
+  the_target.reset (new win32_process_target);
   the_low_target.arch_setup ();
 }
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index dc0bdcc714a..03d6dd1d569 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -103,7 +103,7 @@ extern struct win32_target_ops the_low_target;
 
 /* Target ops definitions for a Win32 target.  */
 
-class win32_process_target : public process_target {
+class win32_process_target : public process_stratum_target {
 public:
 
   int create_inferior (const char *program,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 35/58] gdbserver: turn target op 'read_loadmap' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (53 preceding siblings ...)
  2020-02-11  9:05 ` [PATCH 10/58] gdbserver: turn target op 'resume' into a method Tankut Baris Aktemur
@ 2020-02-11  9:05 ` Tankut Baris Aktemur
  2020-02-11  9:05 ` [PATCH 51/58] gdbserver: turn target ops 'multifs_{open, readlink, unlink}' into methods Tankut Baris Aktemur
                   ` (4 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:05 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's read_loadmap op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.  Also add
	'supports_read_loadmap'.
	* target.c (process_target::read_loadmap): Define.
	(process_target::supports_read_loadmap): Define.

	Update the derived structs and callers below.

	* server.c (handle_qxfer_fdpic): Update.
	(handle_query): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_process_target::supports_read_loadmap): Define.
	(linux_read_loadmap): Turn into ...
	(linux_process_target::read_loadmap): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 15 +++++++++------
 gdbserver/linux-low.h |  7 +++++++
 gdbserver/lynx-low.c  |  1 -
 gdbserver/nto-low.c   |  1 -
 gdbserver/server.c    |  6 +++---
 gdbserver/target.c    | 13 +++++++++++++
 gdbserver/target.h    | 11 +++++++----
 gdbserver/win32-low.c |  1 -
 8 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 713ad3af8aa..a048364242b 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6472,9 +6472,15 @@ struct target_loadmap
 #  define LINUX_LOADMAP_INTERP	PTRACE_GETFDPIC_INTERP
 # endif
 
-static int
-linux_read_loadmap (const char *annex, CORE_ADDR offset,
-		    unsigned char *myaddr, unsigned int len)
+bool
+linux_process_target::supports_read_loadmap ()
+{
+  return true;
+}
+
+int
+linux_process_target::read_loadmap (const char *annex, CORE_ADDR offset,
+				    unsigned char *myaddr, unsigned int len)
 {
   int pid = lwpid_of (current_thread);
   int addr = -1;
@@ -6504,8 +6510,6 @@ linux_read_loadmap (const char *annex, CORE_ADDR offset,
   memcpy (myaddr, (char *) data + offset, copy_length);
   return copy_length;
 }
-#else
-# define linux_read_loadmap NULL
 #endif /* defined PT_GETDSBT || defined PTRACE_GETFDPIC */
 
 static void
@@ -7434,7 +7438,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_read_loadmap,
   linux_process_qsupported,
   linux_supports_tracepoints,
   linux_read_pc,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 57663ef9419..020db879ed3 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -380,6 +380,13 @@ public:
   int handle_monitor_command (char *mon) override;
 
   int core_of_thread (ptid_t ptid) override;
+
+#if defined PT_GETDSBT || defined PTRACE_GETFDPIC
+  bool supports_read_loadmap () override;
+
+  int read_loadmap (const char *annex, CORE_ADDR offset,
+		    unsigned char *myaddr, unsigned int len) override;
+#endif
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index aa744e5e6a3..d6eec84642e 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,7 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* read_loadmap */
   NULL,  /* process_qsupported */
   NULL,  /* supports_tracepoints */
   NULL,  /* read_pc */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 1700fd54278..2bea7eae975 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -947,7 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* read_loadmap */
   NULL, /* process_qsupported */
   NULL, /* supports_tracepoints */
   NULL, /* read_pc */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index f9817881d77..df307f5594c 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -1792,13 +1792,13 @@ static int
 handle_qxfer_fdpic (const char *annex, gdb_byte *readbuf,
 		    const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
 {
-  if (the_target->read_loadmap == NULL)
+  if (!the_target->pt->supports_read_loadmap ())
     return -2;
 
   if (current_thread == NULL)
     return -1;
 
-  return (*the_target->read_loadmap) (annex, offset, readbuf, len);
+  return the_target->pt->read_loadmap (annex, offset, readbuf, len);
 }
 
 /* Handle qXfer:btrace:read.  */
@@ -2380,7 +2380,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (the_target->pt->supports_qxfer_siginfo ())
 	strcat (own_buf, ";qXfer:siginfo:read+;qXfer:siginfo:write+");
 
-      if (the_target->read_loadmap != NULL)
+      if (the_target->pt->supports_read_loadmap ())
 	strcat (own_buf, ";qXfer:fdpic:read+");
 
       /* We always report qXfer:features:read, as targets may
diff --git a/gdbserver/target.c b/gdbserver/target.c
index e1c802d65bc..26b9d8b6afe 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -589,3 +589,16 @@ process_target::core_of_thread (ptid_t ptid)
 {
   return -1;
 }
+
+bool
+process_target::supports_read_loadmap ()
+{
+  return false;
+}
+
+int
+process_target::read_loadmap (const char *annex, CORE_ADDR offset,
+			      unsigned char *myaddr, unsigned int len)
+{
+  gdb_assert_not_reached ("target op read_loadmap not supported");
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 7b077a5a89a..bfced1b10dd 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,10 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Read loadmaps.  Read LEN bytes at OFFSET into a buffer at MYADDR.  */
-  int (*read_loadmap) (const char *annex, CORE_ADDR offset,
-		       unsigned char *myaddr, unsigned int len);
-
   /* Target specific qSupported support.  FEATURES is an array of
      features with COUNT elements.  */
   void (*process_qsupported) (char **features, int count);
@@ -486,6 +482,13 @@ public:
 
   /* Returns the core given a thread, or -1 if not known.  */
   virtual int core_of_thread (ptid_t ptid);
+
+  /* Returns true if the read_loadmap target op is supported.  */
+  virtual bool supports_read_loadmap ();
+
+  /* Read loadmaps.  Read LEN bytes at OFFSET into a buffer at MYADDR.  */
+  virtual int read_loadmap (const char *annex, CORE_ADDR offset,
+			    unsigned char *myaddr, unsigned int len);
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index bc1fdc845b7..39a81e0826e 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1842,7 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* read_loadmap */
   NULL, /* process_qsupported */
   NULL, /* supports_tracepoints */
   NULL, /* read_pc */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 16/58] gdbserver: turn target op 'request_interrupt' into a method
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (55 preceding siblings ...)
  2020-02-11  9:05 ` [PATCH 51/58] gdbserver: turn target ops 'multifs_{open, readlink, unlink}' into methods Tankut Baris Aktemur
@ 2020-02-11  9:05 ` Tankut Baris Aktemur
  2020-02-11  9:05 ` [PATCH 41/58] gdbserver: turn target ops 'pause_all' and 'unpause_all' into methods Tankut Baris Aktemur
                   ` (2 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:05 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's request_interrupt op a method of
	process_target.

	* target.h (struct process_stratum_target): Remove the target op.
	(class process_target): Add the target op.

	Update the derived structs and callers below.

	* remote-utils.c (putpkt_binary_1): Update.
	(input_interrupt): Update.
	(getpkt): Update.
	* server.c (handle_v_requests): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_request_interrupt): Turn into ...
	(linux_process_target::request_interrupt): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_request_interrupt): Turn into ...
	(lynx_process_target::request_interrupt): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_request_interrupt): Turn into ...
	(nto_process_target::request_interrupt): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_request_interrupt): Turn into ...
	(win32_process_target::request_interrupt): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-low.c    | 7 +++----
 gdbserver/linux-low.h    | 2 ++
 gdbserver/lynx-low.c     | 5 ++---
 gdbserver/lynx-low.h     | 2 ++
 gdbserver/nto-low.c      | 5 ++---
 gdbserver/nto-low.h      | 2 ++
 gdbserver/remote-utils.c | 8 ++++----
 gdbserver/server.c       | 2 +-
 gdbserver/target.h       | 9 ++++-----
 gdbserver/win32-low.c    | 5 ++---
 gdbserver/win32-low.h    | 2 ++
 11 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 89ef5ab9224..cf5192fef61 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -5911,12 +5911,12 @@ linux_process_target::look_up_symbols ()
 #endif
 }
 
-static void
-linux_request_interrupt (void)
+void
+linux_process_target::request_interrupt ()
 {
   /* Send a SIGINT to the process group.  This acts just like the user
      typed a ^C on the controlling terminal.  */
-  kill (-signal_pid, SIGINT);
+  ::kill (-signal_pid, SIGINT);
 }
 
 /* Copy LEN bytes from inferior's auxiliary vector starting at OFFSET
@@ -7369,7 +7369,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_request_interrupt,
   linux_read_auxv,
   linux_supports_z_point_type,
   linux_insert_point,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index ae9484d8211..9340c78cdd0 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -306,6 +306,8 @@ public:
 		    int len) override;
 
   void look_up_symbols () override;
+
+  void request_interrupt () override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 21a03cf5d00..0687aacfe61 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -714,8 +714,8 @@ lynx_process_target::write_memory (CORE_ADDR memaddr,
 
 /* Implement the kill_request target_ops method.  */
 
-static void
-lynx_request_interrupt (void)
+void
+lynx_process_target::request_interrupt ()
 {
   ptid_t inferior_ptid = ptid_of (get_first_thread ());
 
@@ -729,7 +729,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_request_interrupt,
   NULL,  /* read_auxv */
   NULL,  /* supports_z_point_type */
   NULL,  /* insert_point */
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index 05223ec9774..3560c22abc1 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -86,6 +86,8 @@ public:
 
   int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
 		    int len) override;
+
+  void request_interrupt () override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index fc548ff72ba..f7b08b4524f 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -746,8 +746,8 @@ nto_process_target::write_memory (CORE_ADDR memaddr,
 
 /* Stop inferior.  We always stop all threads.  */
 
-static void
-nto_request_interrupt (void)
+void
+nto_process_target::request_interrupt ()
 {
   TRACE ("%s\n", __func__);
   nto_set_thread (ptid_t (nto_inferior.pid, 1, 0));
@@ -943,7 +943,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_request_interrupt,
   nto_read_auxv,
   nto_supports_z_point_type,
   nto_insert_point,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index 6f420219ad4..1ce518189c6 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -76,6 +76,8 @@ public:
 
   int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
 		    int len) override;
+
+  void request_interrupt () override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/remote-utils.c b/gdbserver/remote-utils.c
index b8a8c6576f9..b5248ab368e 100644
--- a/gdbserver/remote-utils.c
+++ b/gdbserver/remote-utils.c
@@ -710,7 +710,7 @@ putpkt_binary_1 (char *buf, int cnt, int is_notif)
 
       /* Check for an input interrupt while we're here.  */
       if (cc == '\003' && current_thread != NULL)
-	(*the_target->request_interrupt) ();
+	the_target->pt->request_interrupt ();
     }
   while (cc != '+');
 
@@ -779,7 +779,7 @@ input_interrupt (int unused)
 	  return;
 	}
 
-      (*the_target->request_interrupt) ();
+      the_target->pt->request_interrupt ();
     }
 }
 
@@ -986,7 +986,7 @@ getpkt (char *buf)
 	     check for an input interrupt.  */
 	  if (c == '\003')
 	    {
-	      (*the_target->request_interrupt) ();
+	      the_target->pt->request_interrupt ();
 	      continue;
 	    }
 
@@ -1076,7 +1076,7 @@ getpkt (char *buf)
     {
       /* Consume the interrupt character in the buffer.  */
       readchar ();
-      (*the_target->request_interrupt) ();
+      the_target->pt->request_interrupt ();
     }
 
   return bp - buf;
diff --git a/gdbserver/server.c b/gdbserver/server.c
index 4785eabaf06..bc497f87b7f 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -3088,7 +3088,7 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
     {
       if (strcmp (own_buf, "vCtrlC") == 0)
 	{
-	  (*the_target->request_interrupt) ();
+	  the_target->pt->request_interrupt ();
 	  write_ok (own_buf);
 	  return;
 	}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 73343bd0c03..1eb5657045c 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,11 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Send an interrupt request to the inferior process,
-     however is appropriate.  */
-
-  void (*request_interrupt) (void);
-
   /* Read auxiliary vector data from the inferior process.
 
      Read LEN bytes at OFFSET into a buffer at MYADDR.  */
@@ -475,6 +470,10 @@ public:
      become available.  NULL if we aren't interested in any
      symbols.  */
   virtual void look_up_symbols ();
+
+  /* Send an interrupt request to the inferior process,
+     however is appropriate.  */
+  virtual void request_interrupt () = 0;
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 8baf4a32e4f..b2ed7f8b01e 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1685,8 +1685,8 @@ win32_process_target::write_memory (CORE_ADDR memaddr,
 }
 
 /* Send an interrupt request to the inferior process. */
-static void
-win32_request_interrupt (void)
+void
+win32_process_target::request_interrupt ()
 {
   winapi_DebugBreakProcess DebugBreakProcess;
   winapi_GenerateConsoleCtrlEvent GenerateConsoleCtrlEvent;
@@ -1828,7 +1828,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_request_interrupt,
   NULL, /* read_auxv */
   win32_supports_z_point_type,
   win32_insert_point,
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 27ba64ce916..078ae7255f3 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -135,6 +135,8 @@ public:
 
   int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
 		    int len) override;
+
+  void request_interrupt () override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* [PATCH 29/58] gdbserver: turn non-stop and async target ops into methods
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (51 preceding siblings ...)
  2020-02-11  9:05 ` [PATCH 58/58] gdbserver: finish turning the target ops vector into a class Tankut Baris Aktemur
@ 2020-02-11  9:05 ` Tankut Baris Aktemur
  2020-02-11  9:05 ` [PATCH 10/58] gdbserver: turn target op 'resume' into a method Tankut Baris Aktemur
                   ` (6 subsequent siblings)
  59 siblings, 0 replies; 75+ messages in thread
From: Tankut Baris Aktemur @ 2020-02-11  9:05 UTC (permalink / raw)
  To: gdb-patches

gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's supports_non_stop, async, and
	start_non_stop ops methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	(target_supports_non_stop): Update the macro.
	(target_async): Update the macro.
	(start_non_stop): Remove declaration.
	* target.c (process_target::supports_non_stop): Define.
	(process_target::async): Define.
	(process_target::start_non_stop): Define.
	(start_non_stop): Remove.

	Update the derived structs and callers below.

	* server.c (handle_qxfer_siginfo): Update.
	(handle_query): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_supports_non_stop): Turn into ...
	(linux_process_target::supports_non_stop): ... this.
	(linux_async): Turn into ...
	(linux_process_target::async): ... this.
	(linux_start_non_stop): Turn into ...
	(linux_process_target::start_non_stop): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_supports_non_stop): Remove; rely on the default behavior
	instead.
	* win32-low.c (win32_target_ops): Update.
---
 gdbserver/linux-low.c | 23 ++++++++++-------------
 gdbserver/linux-low.h |  6 ++++++
 gdbserver/lynx-low.c  |  3 ---
 gdbserver/nto-low.c   | 12 ------------
 gdbserver/server.c    |  6 +++---
 gdbserver/target.c    | 35 +++++++++++++++++++++--------------
 gdbserver/target.h    | 29 +++++++++++++----------------
 gdbserver/win32-low.c |  3 ---
 8 files changed, 53 insertions(+), 64 deletions(-)

diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 387e160b8de..a13edfd067b 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -6254,16 +6254,16 @@ sigchld_handler (int signo)
   errno = old_errno;
 }
 
-static int
-linux_supports_non_stop (void)
+bool
+linux_process_target::supports_non_stop ()
 {
-  return 1;
+  return true;
 }
 
-static int
-linux_async (int enable)
+bool
+linux_process_target::async (bool enable)
 {
-  int previous = target_is_async_p ();
+  bool previous = target_is_async_p ();
 
   if (debug_threads)
     debug_printf ("linux_async (%d), previous=%d\n",
@@ -6315,13 +6315,13 @@ linux_async (int enable)
   return previous;
 }
 
-static int
-linux_start_non_stop (int nonstop)
+int
+linux_process_target::start_non_stop (bool nonstop)
 {
   /* Register or unregister from event-loop accordingly.  */
-  linux_async (nonstop);
+  target_async (nonstop);
 
-  if (target_is_async_p () != (nonstop != 0))
+  if (target_is_async_p () != (nonstop != false))
     return -1;
 
   return 0;
@@ -7418,9 +7418,6 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_supports_non_stop,
-  linux_async,
-  linux_start_non_stop,
   linux_supports_multi_process,
   linux_supports_fork_events,
   linux_supports_vfork_events,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index a008dac66f4..0f1dfa45fba 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -360,6 +360,12 @@ public:
   int qxfer_siginfo (const char *annex, unsigned char *readbuf,
 		     unsigned const char *writebuf,
 		     CORE_ADDR offset, int len) override;
+
+  bool supports_non_stop () override;
+
+  bool async (bool enable) override;
+
+  int start_non_stop (bool enable) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index d45e598cb26..ad2c2f72a73 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -735,9 +735,6 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* supports_non_stop */
-  NULL,  /* async */
-  NULL,  /* start_non_stop */
   NULL,  /* supports_multi_process */
   NULL,  /* supports_fork_events */
   NULL,  /* supports_vfork_events */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 4d3ef38a976..cbbf67af917 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -933,15 +933,6 @@ nto_process_target::stopped_data_address ()
   return ret;
 }
 
-/* We do not currently support non-stop.  */
-
-static int
-nto_supports_non_stop (void)
-{
-  TRACE ("%s\n", __func__);
-  return 0;
-}
-
 /* Implementation of the target_ops method "sw_breakpoint_from_kind".  */
 
 static const gdb_byte *
@@ -956,9 +947,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_supports_non_stop,
-  NULL, /* async */
-  NULL, /* start_non_stop */
   NULL, /* supports_multi_process */
   NULL, /* supports_fork_events */
   NULL, /* supports_vfork_events */
diff --git a/gdbserver/server.c b/gdbserver/server.c
index ece75f01868..f427e7706fb 100644
--- a/gdbserver/server.c
+++ b/gdbserver/server.c
@@ -740,7 +740,7 @@ handle_general_set (char *own_buf)
 	}
 
       req_str = req ? "non-stop" : "all-stop";
-      if (start_non_stop (req) != 0)
+      if (the_target->pt->start_non_stop (req == 1) != 0)
 	{
 	  fprintf (stderr, "Setting %s mode failed\n", req_str);
 	  write_enn (own_buf);
@@ -1234,7 +1234,7 @@ handle_detach (char *own_buf)
 	    debug_printf ("Forcing non-stop mode\n");
 
 	  non_stop = true;
-	  start_non_stop (1);
+	  the_target->pt->start_non_stop (true);
 	}
 
       process->gdb_detached = 1;
@@ -3885,7 +3885,7 @@ captured_main (int argc, char *argv[])
 		     down without informing GDB.  */
 		  if (!non_stop)
 		    {
-		      if (start_non_stop (1))
+		      if (the_target->pt->start_non_stop (true))
 			non_stop = 1;
 
 		      /* Detaching implicitly resumes all threads;
diff --git a/gdbserver/target.c b/gdbserver/target.c
index 94bb45fcace..33e31a748ef 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -264,20 +264,6 @@ target_supports_multi_process (void)
 	  (*the_target->supports_multi_process) () : 0);
 }
 
-int
-start_non_stop (int nonstop)
-{
-  if (the_target->start_non_stop == NULL)
-    {
-      if (nonstop)
-	return -1;
-      else
-	return 0;
-    }
-
-  return (*the_target->start_non_stop) (nonstop);
-}
-
 void
 set_target_ops (process_stratum_target *target)
 {
@@ -541,3 +527,24 @@ process_target::qxfer_siginfo (const char *annex, unsigned char *readbuf,
 {
   gdb_assert_not_reached ("target op qxfer_siginfo not supported");
 }
+
+bool
+process_target::supports_non_stop ()
+{
+  return false;
+}
+
+bool
+process_target::async (bool enable)
+{
+  return false;
+}
+
+int
+process_target::start_non_stop (bool enable)
+{
+  if (enable)
+    return -1;
+  else
+    return 0;
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index bec147de089..88b4762a30c 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,16 +70,6 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  int (*supports_non_stop) (void);
-
-  /* Enables async target events.  Returns the previous enable
-     state.  */
-  int (*async) (int enable);
-
-  /* Switch to non-stop (1) or all-stop (0) mode.  Return 0 on
-     success, -1 otherwise.  */
-  int (*start_non_stop) (int);
-
   /* Returns true if the target supports multi-process debugging.  */
   int (*supports_multi_process) (void);
 
@@ -485,6 +475,17 @@ public:
   virtual int qxfer_siginfo (const char *annex, unsigned char *readbuf,
 			     unsigned const char *writebuf,
 			     CORE_ADDR offset, int len);
+
+  /* Return true if non-stop mode is supported.  */
+  virtual bool supports_non_stop ();
+
+  /* Enables async target events.  Returns the previous enable
+     state.  */
+  virtual bool async (bool enable);
+
+  /* Switch to non-stop (ENABLE == true) or all-stop (ENABLE == false)
+     mode.  Return 0 on success, -1 otherwise.  */
+  virtual int start_non_stop (bool enable);
 };
 
 extern process_stratum_target *the_target;
@@ -537,10 +538,10 @@ int kill_inferior (process_info *proc);
   the_target->pt->join (pid)
 
 #define target_supports_non_stop() \
-  (the_target->supports_non_stop ? (*the_target->supports_non_stop ) () : 0)
+  the_target->pt->supports_non_stop ()
 
 #define target_async(enable) \
-  (the_target->async ? (*the_target->async) (enable) : 0)
+  the_target->pt->async (enable)
 
 #define target_process_qsupported(features, count)	\
   do							\
@@ -696,10 +697,6 @@ target_read_btrace_conf (struct btrace_target_info *tinfo,
   (the_target->supports_software_single_step ? \
    (*the_target->supports_software_single_step) () : 0)
 
-/* Start non-stop mode, returns 0 on success, -1 on failure.   */
-
-int start_non_stop (int nonstop);
-
 ptid_t mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options,
 	       int connected_wait);
 
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 45fd49458e7..15431047814 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1842,9 +1842,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* supports_non_stop */
-  NULL, /* async */
-  NULL, /* start_non_stop */
   NULL, /* supports_multi_process */
   NULL, /* supports_fork_events */
   NULL, /* supports_vfork_events */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 57/58] gdbserver: use unique_ptr for 'the_target'
  2020-02-11  9:04 ` [PATCH 57/58] gdbserver: use unique_ptr for 'the_target' Tankut Baris Aktemur
@ 2020-02-11 16:43   ` Christian Biesinger via gdb-patches
  2020-02-12  8:32     ` Aktemur, Tankut Baris
  2020-02-13 20:31   ` Pedro Alves
  1 sibling, 1 reply; 75+ messages in thread
From: Christian Biesinger via gdb-patches @ 2020-02-11 16:43 UTC (permalink / raw)
  To: Tankut Baris Aktemur; +Cc: gdb-patches

On Tue, Feb 11, 2020 at 3:08 AM Tankut Baris Aktemur
<tankut.baris.aktemur@intel.com> wrote:
>
> The target op vector is about to be replaced with a process_target
> object.  In the current state, the 'set_target_ops' function takes a
> target op vector and creates a clone of it via XNEW and memcpy.  As we
> are now switching to using classes and polymorphism, this memcpy'ing
> will no longer be possible.  For proper memory managament, switch to
> using a unique_ptr.
>
> gdbserver/ChangeLog:
> 2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
>
>         * target.h (set_target_ops): Remove.
>         (<the_target>): Change the type to
>         std::unique_ptr<process_stratum_target>.
>         * target.c (set_target_ops): Remove.
>         (done_accessing_memory): Update the usage of the_target.
>         * fork-child.c (post_fork_inferior): Update the usage of
>         the_target.
>         * remote-utils.c (prepare_resume_reply): Ditto.
>         * linux-low.c (initialize_low): Set the value of the_target.
>         (struct linux_target_ops): Delete.
>         * lynx-low.c (initialize_low): Set the value of the_target.
>         (struct lynx_target_ops): Delete.
>         * nto-low.c (initialize_low): Set the value of the_target.
>         (struct nto_target_ops): Delete.
>         * win32-low.c (initialize_low): Set the value of the_target.
>         (struct win32_target_ops): Delete.
> ---
>  gdbserver/fork-child.c   |  2 +-
>  gdbserver/linux-low.c    |  7 ++-----
>  gdbserver/lynx-low.c     |  9 ++-------
>  gdbserver/nto-low.c      |  8 ++------
>  gdbserver/remote-utils.c |  2 +-
>  gdbserver/target.c       | 11 ++---------
>  gdbserver/target.h       |  4 +---
>  gdbserver/win32-low.c    |  7 ++-----
>  8 files changed, 13 insertions(+), 37 deletions(-)
>
> diff --git a/gdbserver/fork-child.c b/gdbserver/fork-child.c
> index 7a71ec0b1ca..3702c1a8c2e 100644
> --- a/gdbserver/fork-child.c
> +++ b/gdbserver/fork-child.c
> @@ -107,7 +107,7 @@ post_fork_inferior (int pid, const char *program)
>    atexit (restore_old_foreground_pgrp);
>  #endif
>
> -  startup_inferior (the_target, pid,
> +  startup_inferior (the_target.get (), pid,
>                     START_INFERIOR_TRAPS_EXPECTED,
>                     &cs.last_status, &cs.last_ptid);
>    current_thread->last_resume_kind = resume_stop;
> diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
> index cd84cef326a..87cf2fd8afb 100644
> --- a/gdbserver/linux-low.c
> +++ b/gdbserver/linux-low.c
> @@ -7512,10 +7512,6 @@ linux_get_hwcap2 (int wordsize)
>
>  static linux_process_target the_linux_target;
>
> -static process_stratum_target linux_target_ops = {
> -  &the_linux_target,
> -};
> -
>  #ifdef HAVE_LINUX_REGSETS
>  void
>  initialize_regsets_info (struct regsets_info *info)
> @@ -7533,7 +7529,8 @@ initialize_low (void)
>    struct sigaction sigchld_action;
>
>    memset (&sigchld_action, 0, sizeof (sigchld_action));
> -  set_target_ops (&linux_target_ops);
> +  the_target.reset (new process_stratum_target);
> +  the_target->pt = &the_linux_target;

Should this now be a constructor argument?

>
>    linux_ptrace_init_warnings ();
>    linux_proc_init_warnings ();
> diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
> index 778afd190b6..1377ccaf4ae 100644
> --- a/gdbserver/lynx-low.c
> +++ b/gdbserver/lynx-low.c
> @@ -739,16 +739,11 @@ lynx_process_target::sw_breakpoint_from_kind (int kind, int *size)
>
>  static lynx_process_target the_lynx_target;
>
> -/* The LynxOS target_ops vector.  */
> -
> -static process_stratum_target lynx_target_ops = {
> -  &the_lynx_target,
> -};
> -
>  void
>  initialize_low (void)
>  {
> -  set_target_ops (&lynx_target_ops);
> +  the_target.reset (new process_stratum_target);
> +  the_target->pt = &the_lynx_target;
>    the_low_target.arch_setup ();
>  }
>
> diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
> index cd461be8378..bbcc5046659 100644
> --- a/gdbserver/nto-low.c
> +++ b/gdbserver/nto-low.c
> @@ -946,11 +946,6 @@ nto_process_target::sw_breakpoint_from_kind (int kind, int *size)
>
>  static nto_process_target the_nto_target;
>
> -static process_stratum_target nto_target_ops = {
> -  &the_nto_target,
> -};
> -
> -
>  /* Global function called by server.c.  Initializes QNX Neutrino
>     gdbserver.  */
>
> @@ -960,7 +955,8 @@ initialize_low (void)
>    sigset_t set;
>
>    TRACE ("%s\n", __func__);
> -  set_target_ops (&nto_target_ops);
> +  the_target.reset (new process_stratum_target);
> +  the_target->pt = &the_nto_target;
>
>    /* We use SIGUSR1 to gain control after we block waiting for a process.
>       We use sigwaitevent to wait.  */
> diff --git a/gdbserver/remote-utils.c b/gdbserver/remote-utils.c
> index 316f04e32ee..14e89332db4 100644
> --- a/gdbserver/remote-utils.c
> +++ b/gdbserver/remote-utils.c
> @@ -1208,7 +1208,7 @@ prepare_resume_reply (char *buf, ptid_t ptid,
>
>         saved_thread = current_thread;
>
> -       switch_to_thread (the_target, ptid);
> +       switch_to_thread (the_target.get (), ptid);
>
>         regp = current_target_desc ()->expedite_regs;
>
> diff --git a/gdbserver/target.c b/gdbserver/target.c
> index 5c80a379f65..048fd5ad6e9 100644
> --- a/gdbserver/target.c
> +++ b/gdbserver/target.c
> @@ -27,7 +27,7 @@
>  #include <sys/types.h>
>  #include <sys/stat.h>
>
> -process_stratum_target *the_target;
> +std::unique_ptr<process_stratum_target> the_target;
>
>  int
>  set_desired_thread ()
> @@ -118,7 +118,7 @@ done_accessing_memory (void)
>
>    /* Restore the previous selected thread.  */
>    cs.general_thread = prev_general_thread;
> -  switch_to_thread (the_target, cs.general_thread);
> +  switch_to_thread (the_target.get (), cs.general_thread);
>  }
>
>  int
> @@ -267,13 +267,6 @@ target_supports_multi_process (void)
>    return the_target->pt->supports_multi_process ();
>  }
>
> -void
> -set_target_ops (process_stratum_target *target)
> -{
> -  the_target = XNEW (process_stratum_target);
> -  memcpy (the_target, target, sizeof (*the_target));
> -}
> -
>  /* Convert pid to printable format.  */
>
>  const char *
> diff --git a/gdbserver/target.h b/gdbserver/target.h
> index 1b5059c1beb..ac0ada0cd38 100644
> --- a/gdbserver/target.h
> +++ b/gdbserver/target.h
> @@ -506,9 +506,7 @@ public:
>    virtual int get_ipa_tdesc_idx ();
>  };
>
> -extern process_stratum_target *the_target;
> -
> -void set_target_ops (process_stratum_target *);
> +extern std::unique_ptr<process_stratum_target> the_target;
>
>  #define target_create_inferior(program, program_args)  \
>    the_target->pt->create_inferior (program, program_args)
> diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
> index 567e2ebe3db..5b4dd36f5d0 100644
> --- a/gdbserver/win32-low.c
> +++ b/gdbserver/win32-low.c
> @@ -1847,14 +1847,11 @@ win32_process_target::sw_breakpoint_from_kind (int kind, int *size)
>
>  static win32_process_target the_win32_target;
>
> -static process_stratum_target win32_target_ops = {
> -  &the_win32_target,
> -};
> -
>  /* Initialize the Win32 backend.  */
>  void
>  initialize_low (void)
>  {
> -  set_target_ops (&win32_target_ops);
> +  the_target.reset (new process_stratum_target);
> +  the_target->pt = &the_win32_target;
>    the_low_target.arch_setup ();
>  }
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 00/58] Turn gdbserver's process_stratum_target into a class
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (57 preceding siblings ...)
  2020-02-11  9:05 ` [PATCH 41/58] gdbserver: turn target ops 'pause_all' and 'unpause_all' into methods Tankut Baris Aktemur
@ 2020-02-11 17:41 ` Christian Biesinger via gdb-patches
  2020-02-12  8:18   ` Aktemur, Tankut Baris
  2020-02-13 20:26 ` Pedro Alves
  59 siblings, 1 reply; 75+ messages in thread
From: Christian Biesinger via gdb-patches @ 2020-02-11 17:41 UTC (permalink / raw)
  To: Tankut Baris Aktemur; +Cc: gdb-patches

On Tue, Feb 11, 2020 at 3:03 AM Tankut Baris Aktemur
<tankut.baris.aktemur@intel.com> wrote:
>
> Hi All,
>
> This is a C++'ification series that aims to convert the target ops
> vector in gdbserver into a class.  Currently, the target ops is a
> struct of function pointers.  At the end of the series, it becomes a
> class with methods, and the existing low target definitions become
> subclasses.  That is, we end up with the following class hierarchy:
>
> process_stratum_target
> ^
> ├── linux-low
> ├── lynx-low
> ├── nto-low
> └── win32-low
>
> process_stratum_target either defines the default behavior for the
> target ops or leaves them as pure virtual for the subclasses to
> override.
>
> PATCH 1's commit message gives more details about the approach in this
> transformation.
>
> If and when this series is accepted, the next step is to C++'ify linux
> low targets, giving a hierarchy that looks like below.  (This second
> phase is not included in this series.)
>
> process_stratum_target
> ^
> ├── linux-low
> │   ^
> │   ├── linux-arm-low
> │   ├── linux-ppc-low
> │   ├── linux-x86-low
> │   └── ...
> ├── lynx-low
> ├── nto-low
> └── win32-low
>
> My goal in this series was to make gdbserver buildable after each
> patch.  I could test this for linux-low, but not for other targets --
> in particular, for lynx-low, nto-low, and win32-low.  I verified their
> code manually to my best; however, I may have made typos or some
> oversights that break build on these systems.  Can builbot be used to
> test?

I'm not a patch approver (and I only skimmed most of the patches), but
I really like this work!

You can use buildbot to test win32 (the Fedora-x86_64-w64-mingw32 bot
tests it by crosscompiling from linux to windows). Testing lynx and
nto may be harder, you may have to track down a cross compiler and/or
a qemu image...


Christian

>
> The patches are also available at
>
> https://github.com/barisaktemur/gdb/commits/gdbserver-cppify-target-v1
>
> Thanks.
> Baris
>
> Tankut Baris Aktemur (58):
>   gdbserver: start turning the target ops vector into a class
>   gdbserver: turn target op 'create_inferior' into a method
>   gdbserver: turn target op 'post_create_inferior' into a method
>   gdbserver: turn target op 'attach' into a method
>   gdbserver: turn target op 'kill' into a method
>   gdbserver: turn target op 'detach' into a method
>   gdbserver: turn target op 'mourn' into a method
>   gdbserver: turn target op 'join' into a method
>   gdbserver: turn target op 'thread_alive' into a method
>   gdbserver: turn target op 'resume' into a method
>   gdbserver: turn target op 'wait' into a method
>   gdbserver: turn target ops 'fetch_registers' and 'store_registers'
>     into methods
>   gdbserver: turn prepare_to_access_memory & done_accessing_memory into
>     methods
>   gdbserver: turn target ops 'read_memory' and 'write_memory' into
>     methods
>   gdbserver: turn target op 'look_up_symbols' into a method
>   gdbserver: turn target op 'request_interrupt' into a method
>   gdbserver: turn target op 'read_auxv' into a method
>   gdbserver: turn target op 'supports_z_point_type' into a method
>   gdbserver: turn target ops 'insert_point' and 'remove_point' into
>     methods
>   gdbserver: turn target op '{supports_}stopped_by_sw_breakpoint' into a
>     method
>   gdbserver: turn target op '{supports_}stopped_by_hw_breakpoint' into a
>     method
>   gdbserver: turn target op 'supports_hardware_single_step' into a
>     method
>   gdbserver: turn target ops 'stopped_by_watchpoint' and
>     'stopped_data_address' into methods
>   gdbserver: turn target op 'read_offsets' into a method
>   gdbserver: turn target op 'get_tls_address' into a method
>   gdbserver: turn target op 'hostio_last_error' into a method
>   gdbserver: turn target op 'qxfer_osdata' into a method
>   gdbserver: turn target op 'qxfer_siginfo' into a method
>   gdbserver: turn non-stop and async target ops into methods
>   gdbserver: turn target op 'supports_multi_process' into a method
>   gdbserver: turn target ops 'supports_{fork,vfork,exec}_events' into
>     methods
>   gdbserver: turn target op 'handle_new_gdb_connection' into a method
>   gdbserver: turn target op 'handle_monitor_command' into a method
>   gdbserver: turn target op 'core_of_thread' into a method
>   gdbserver: turn target op 'read_loadmap' into a method
>   gdbserver: turn target op 'process_qsupported' into a method
>   gdbserver: turn target op 'supports_tracepoints' into a method
>   gdbserver: turn target ops 'read_pc' and 'write_pc' into methods
>   gdbserver: turn target op 'thread_stopped' into a method
>   gdbserver: turn target op 'get_tib_address' into a method
>   gdbserver: turn target ops 'pause_all' and 'unpause_all' into methods
>   gdbserver: turn target op 'stabilize_threads' into a method
>   gdbserver: turn fast tracepoint target ops into methods
>   gdbserver: turn target op 'emit_ops' into a method
>   gdbserver: turn target op 'supports_disable_randomization' into a
>     method
>   gdbserver: turn target op 'qxfer_libraries_svr4' into a method
>   gdbserver: turn target op 'supports_agent' into a method
>   gdbserver: turn btrace-related target ops into methods
>   gdbserver: turn target op 'supports_range_stepping' into a method
>   gdbserver: turn target op 'pid_to_exec_file' into a method
>   gdbserver: turn target ops 'multifs_{open, readlink, unlink}' into
>     methods
>   gdbserver: turn breakpoint kind-related target ops into methods
>   gdbserver: turn target ops 'thread_name' and 'thread_handle' into
>     methods
>   gdbserver: turn target op 'supports_software_single_step' into a
>     method
>   gdbserver: turn target op 'supports_catch_syscall' into a method
>   gdbserver: turn target op 'get_ipa_tdesc_idx' into a method
>   gdbserver: use unique_ptr for 'the_target'
>   gdbserver: finish turning the target ops vector into a class
>
>  gdbserver/fork-child.c        |   2 +-
>  gdbserver/hostio.c            |  13 +-
>  gdbserver/linux-aarch32-low.c |   6 +-
>  gdbserver/linux-aarch64-low.c |   4 +-
>  gdbserver/linux-arm-low.c     |   8 +-
>  gdbserver/linux-cris-low.c    |   4 +-
>  gdbserver/linux-crisv32-low.c |   4 +-
>  gdbserver/linux-low.c         | 635 ++++++++++++++++++----------------
>  gdbserver/linux-low.h         | 222 ++++++++++++
>  gdbserver/linux-m32r-low.c    |   4 +-
>  gdbserver/linux-mips-low.c    |   2 +-
>  gdbserver/linux-nios2-low.c   |   4 +-
>  gdbserver/linux-ppc-low.c     |   2 +-
>  gdbserver/linux-sh-low.c      |   2 +-
>  gdbserver/linux-sparc-low.c   |   6 +-
>  gdbserver/linux-tic6x-low.c   |   2 +-
>  gdbserver/linux-tile-low.c    |   2 +-
>  gdbserver/linux-x86-low.c     |   2 +-
>  gdbserver/linux-xtensa-low.c  |   4 +-
>  gdbserver/lynx-low.c          | 128 +++----
>  gdbserver/lynx-low.h          |  42 +++
>  gdbserver/mem-break.c         |  11 +-
>  gdbserver/nto-low.c           | 208 ++++-------
>  gdbserver/nto-low.h           |  59 ++++
>  gdbserver/regcache.c          |  16 +-
>  gdbserver/remote-utils.c      |  15 +-
>  gdbserver/server.c            |  77 +++--
>  gdbserver/target.c            | 578 +++++++++++++++++++++++++++----
>  gdbserver/target.h            | 555 ++++++++++++++---------------
>  gdbserver/tracepoint.c        |  54 ++-
>  gdbserver/win32-low.c         | 214 +++++-------
>  gdbserver/win32-low.h         |  68 ++++
>  32 files changed, 1803 insertions(+), 1150 deletions(-)
>
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 00/58] Turn gdbserver's process_stratum_target into a class
  2020-02-11 17:41 ` [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Christian Biesinger via gdb-patches
@ 2020-02-12  8:18   ` Aktemur, Tankut Baris
  2020-02-12 16:43     ` Christian Biesinger via gdb-patches
  0 siblings, 1 reply; 75+ messages in thread
From: Aktemur, Tankut Baris @ 2020-02-12  8:18 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: gdb-patches

On Tuesday, February 11, 2020 6:41 PM, Christian Biesinger wrote:
> On Tue, Feb 11, 2020 at 3:03 AM Tankut Baris Aktemur
> <tankut.baris.aktemur@intel.com> wrote:
> >
> > Hi All,
> >
> > This is a C++'ification series that aims to convert the target ops
> > vector in gdbserver into a class.  Currently, the target ops is a
> > struct of function pointers.  At the end of the series, it becomes a
> > class with methods, and the existing low target definitions become
> > subclasses.  That is, we end up with the following class hierarchy:
> >
> > process_stratum_target
> > ^
> > ├── linux-low
> > ├── lynx-low
> > ├── nto-low
> > └── win32-low
> >
> > process_stratum_target either defines the default behavior for the
> > target ops or leaves them as pure virtual for the subclasses to
> > override.
> >
> > PATCH 1's commit message gives more details about the approach in this
> > transformation.
> >
> > If and when this series is accepted, the next step is to C++'ify linux
> > low targets, giving a hierarchy that looks like below.  (This second
> > phase is not included in this series.)
> >
> > process_stratum_target
> > ^
> > ├── linux-low
> > │   ^
> > │   ├── linux-arm-low
> > │   ├── linux-ppc-low
> > │   ├── linux-x86-low
> > │   └── ...
> > ├── lynx-low
> > ├── nto-low
> > └── win32-low
> >
> > My goal in this series was to make gdbserver buildable after each
> > patch.  I could test this for linux-low, but not for other targets --
> > in particular, for lynx-low, nto-low, and win32-low.  I verified their
> > code manually to my best; however, I may have made typos or some
> > oversights that break build on these systems.  Can builbot be used to
> > test?
> 
> I'm not a patch approver (and I only skimmed most of the patches), but
> I really like this work!

Thank you!

> You can use buildbot to test win32 (the Fedora-x86_64-w64-mingw32 bot
> tests it by crosscompiling from linux to windows). Testing lynx and
> nto may be harder, you may have to track down a cross compiler and/or
> a qemu image...
> 
> 
> Christian

As far as I understand, I need to contact Sergio to ask for access:
https://sourceware.org/gdb/wiki/BuildBot

The builbot page at https://gdb-buildbot.osci.io does not contain much
instructions.  If there are other pointers one needs to know, please let me know!

Thanks.
-Baris


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 57/58] gdbserver: use unique_ptr for 'the_target'
  2020-02-11 16:43   ` Christian Biesinger via gdb-patches
@ 2020-02-12  8:32     ` Aktemur, Tankut Baris
  0 siblings, 0 replies; 75+ messages in thread
From: Aktemur, Tankut Baris @ 2020-02-12  8:32 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: gdb-patches

On Tuesday, February 11, 2020 5:43 PM, Christian Biesinger wrote:
> On Tue, Feb 11, 2020 at 3:08 AM Tankut Baris Aktemur
> <tankut.baris.aktemur@intel.com> wrote:
> >
> > The target op vector is about to be replaced with a process_target
> > object.  In the current state, the 'set_target_ops' function takes a
> > target op vector and creates a clone of it via XNEW and memcpy.  As we
> > are now switching to using classes and polymorphism, this memcpy'ing
> > will no longer be possible.  For proper memory managament, switch to
> > using a unique_ptr.
> >
> > gdbserver/ChangeLog:
> > 2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
> >
> >         * target.h (set_target_ops): Remove.
> >         (<the_target>): Change the type to
> >         std::unique_ptr<process_stratum_target>.
> >         * target.c (set_target_ops): Remove.
> >         (done_accessing_memory): Update the usage of the_target.
> >         * fork-child.c (post_fork_inferior): Update the usage of
> >         the_target.
> >         * remote-utils.c (prepare_resume_reply): Ditto.
> >         * linux-low.c (initialize_low): Set the value of the_target.
> >         (struct linux_target_ops): Delete.
> >         * lynx-low.c (initialize_low): Set the value of the_target.
> >         (struct lynx_target_ops): Delete.
> >         * nto-low.c (initialize_low): Set the value of the_target.
> >         (struct nto_target_ops): Delete.
> >         * win32-low.c (initialize_low): Set the value of the_target.
> >         (struct win32_target_ops): Delete.
> > ---
> >  gdbserver/fork-child.c   |  2 +-
> >  gdbserver/linux-low.c    |  7 ++-----
> >  gdbserver/lynx-low.c     |  9 ++-------
> >  gdbserver/nto-low.c      |  8 ++------
> >  gdbserver/remote-utils.c |  2 +-
> >  gdbserver/target.c       | 11 ++---------
> >  gdbserver/target.h       |  4 +---
> >  gdbserver/win32-low.c    |  7 ++-----
> >  8 files changed, 13 insertions(+), 37 deletions(-)
> >
> > diff --git a/gdbserver/fork-child.c b/gdbserver/fork-child.c
> > index 7a71ec0b1ca..3702c1a8c2e 100644
> > --- a/gdbserver/fork-child.c
> > +++ b/gdbserver/fork-child.c
> > @@ -107,7 +107,7 @@ post_fork_inferior (int pid, const char *program)
> >    atexit (restore_old_foreground_pgrp);
> >  #endif
> >
> > -  startup_inferior (the_target, pid,
> > +  startup_inferior (the_target.get (), pid,
> >                     START_INFERIOR_TRAPS_EXPECTED,
> >                     &cs.last_status, &cs.last_ptid);
> >    current_thread->last_resume_kind = resume_stop;
> > diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
> > index cd84cef326a..87cf2fd8afb 100644
> > --- a/gdbserver/linux-low.c
> > +++ b/gdbserver/linux-low.c
> > @@ -7512,10 +7512,6 @@ linux_get_hwcap2 (int wordsize)
> >
> >  static linux_process_target the_linux_target;
> >
> > -static process_stratum_target linux_target_ops = {
> > -  &the_linux_target,
> > -};
> > -
> >  #ifdef HAVE_LINUX_REGSETS
> >  void
> >  initialize_regsets_info (struct regsets_info *info)
> > @@ -7533,7 +7529,8 @@ initialize_low (void)
> >    struct sigaction sigchld_action;
> >
> >    memset (&sigchld_action, 0, sizeof (sigchld_action));
> > -  set_target_ops (&linux_target_ops);
> > +  the_target.reset (new process_stratum_target);
> > +  the_target->pt = &the_linux_target;
> 
> Should this now be a constructor argument?

Yes, this would make it better; however, to be frank, I did not care too
much because the next patch in the series (PATCH 58/58) deletes the
process_target class and the 'pt' field, making the following change:

  -  the_target.reset (new process_stratum_target);
  -  the_target->pt = &the_linux_target;
  +  the_target.reset (new linux_process_target);

So the code above is temporary -- if I introduce a constructor here, it
would have to be deleted/modified in the next patch.  Given this, is it OK
to leave this patch as it is?

An alternative is to squash PATCH 57 and 58, but 58 is already the longest
patch in the series.

-Baris


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 00/58] Turn gdbserver's process_stratum_target into a class
  2020-02-12  8:18   ` Aktemur, Tankut Baris
@ 2020-02-12 16:43     ` Christian Biesinger via gdb-patches
  0 siblings, 0 replies; 75+ messages in thread
From: Christian Biesinger via gdb-patches @ 2020-02-12 16:43 UTC (permalink / raw)
  To: Aktemur, Tankut Baris; +Cc: gdb-patches

On Wed, Feb 12, 2020 at 2:18 AM Aktemur, Tankut Baris
<tankut.baris.aktemur@intel.com> wrote:
>
> On Tuesday, February 11, 2020 6:41 PM, Christian Biesinger wrote:
> > On Tue, Feb 11, 2020 at 3:03 AM Tankut Baris Aktemur
> > <tankut.baris.aktemur@intel.com> wrote:
> > >
> > > Hi All,
> > >
> > > This is a C++'ification series that aims to convert the target ops
> > > vector in gdbserver into a class.  Currently, the target ops is a
> > > struct of function pointers.  At the end of the series, it becomes a
> > > class with methods, and the existing low target definitions become
> > > subclasses.  That is, we end up with the following class hierarchy:
> > >
> > > process_stratum_target
> > > ^
> > > ├── linux-low
> > > ├── lynx-low
> > > ├── nto-low
> > > └── win32-low
> > >
> > > process_stratum_target either defines the default behavior for the
> > > target ops or leaves them as pure virtual for the subclasses to
> > > override.
> > >
> > > PATCH 1's commit message gives more details about the approach in this
> > > transformation.
> > >
> > > If and when this series is accepted, the next step is to C++'ify linux
> > > low targets, giving a hierarchy that looks like below.  (This second
> > > phase is not included in this series.)
> > >
> > > process_stratum_target
> > > ^
> > > ├── linux-low
> > > │   ^
> > > │   ├── linux-arm-low
> > > │   ├── linux-ppc-low
> > > │   ├── linux-x86-low
> > > │   └── ...
> > > ├── lynx-low
> > > ├── nto-low
> > > └── win32-low
> > >
> > > My goal in this series was to make gdbserver buildable after each
> > > patch.  I could test this for linux-low, but not for other targets --
> > > in particular, for lynx-low, nto-low, and win32-low.  I verified their
> > > code manually to my best; however, I may have made typos or some
> > > oversights that break build on these systems.  Can builbot be used to
> > > test?
> >
> > I'm not a patch approver (and I only skimmed most of the patches), but
> > I really like this work!
>
> Thank you!
>
> > You can use buildbot to test win32 (the Fedora-x86_64-w64-mingw32 bot
> > tests it by crosscompiling from linux to windows). Testing lynx and
> > nto may be harder, you may have to track down a cross compiler and/or
> > a qemu image...
> >
> >
> > Christian
>
> As far as I understand, I need to contact Sergio to ask for access:
> https://sourceware.org/gdb/wiki/BuildBot
>
> The builbot page at https://gdb-buildbot.osci.io does not contain much
> instructions.  If there are other pointers one needs to know, please let me know!

Yes, https://sourceware.org/gdb/wiki/BuildBot#TL.3BDR is the process
(email gdb@ and cc sergio)

https://sourceware.org/gdb/wiki/BuildBot#Installing_buildbot has the
instructions for how to set it up. At the time, I had to use vpython
and buildbot from their git repository, hopefully that is not
necessary anymore.

It occurs to me that buildbot has a maximum patch size. Hopefully,
your patch series fits under that!

Otherwise, you can install the mingw crosscompiler yourself and test
the build locally; Debian has a g++-mingw-w64 package for that. I'm
sure Fedora has a package too but I don't know what it's called. Then
you can just build GDB with configure --build=x86_64-pc-linux-gnu
--host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --without-python
--disable-nls --without-nls --disable-source-highlight.

Christian

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 01/58] gdbserver: start turning the target ops vector into a class
  2020-02-11  9:03 ` [PATCH 01/58] gdbserver: start turning the target ops vector into a class Tankut Baris Aktemur
@ 2020-02-13 20:26   ` Pedro Alves
  0 siblings, 0 replies; 75+ messages in thread
From: Pedro Alves @ 2020-02-13 20:26 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 2/11/20 9:01 AM, Tankut Baris Aktemur wrote:

> diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
> index e25ddd024dd..f17ac95fae8 100644
> --- a/gdbserver/linux-low.h
> +++ b/gdbserver/linux-low.h
> @@ -264,6 +264,13 @@ struct linux_target_ops
>  
>  extern struct linux_target_ops the_low_target;
>  
> +/* Target ops definitions for a Linux target.  */
> +
> +class linux_process_target : public process_target {

Let's follow formatting conventions here -- "{" goes on the
next line.

class linux_process_target : public process_target
{

This applies to all new classes.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 00/58] Turn gdbserver's process_stratum_target into a class
  2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
                   ` (58 preceding siblings ...)
  2020-02-11 17:41 ` [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Christian Biesinger via gdb-patches
@ 2020-02-13 20:26 ` Pedro Alves
  59 siblings, 0 replies; 75+ messages in thread
From: Pedro Alves @ 2020-02-13 20:26 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 2/11/20 9:01 AM, Tankut Baris Aktemur wrote:
> Hi All,
> 
> This is a C++'ification series that aims to convert the target ops
> vector in gdbserver into a class.  Currently, the target ops is a
> struct of function pointers.  At the end of the series, it becomes a
> class with methods, and the existing low target definitions become
> subclasses.  That is, we end up with the following class hierarchy:

Pretty cool!

I'm sending comments to some of the individual patches.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 02/58] gdbserver: turn target op 'create_inferior' into a method
  2020-02-11  9:03 ` [PATCH 02/58] gdbserver: turn target op 'create_inferior' " Tankut Baris Aktemur
@ 2020-02-13 20:27   ` Pedro Alves
  2020-02-14 11:01     ` Aktemur, Tankut Baris
  0 siblings, 1 reply; 75+ messages in thread
From: Pedro Alves @ 2020-02-13 20:27 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 2/11/20 9:01 AM, Tankut Baris Aktemur wrote:
> -static int
> -linux_create_inferior (const char *program,
> -		       const std::vector<char *> &program_args)
> +int
> +linux_process_target::create_inferior (
> +    const char *program, const std::vector<char *> &program_args)

No '(' at end of line, please.  You can either write:

linux_process_target::create_inferior 
  (const char *program, const std::vector<char *> &program_args)

... with two leading spaces, or:

linux_process_target::create_inferior (const char *program, 
                                       const std::vector<char *> &program_args)

since that fits in 79 cols.

The occurs in a number of other spots in the series, but I won't
comment on them.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 15/58] gdbserver: turn target op 'look_up_symbols' into a method
  2020-02-11  9:03 ` [PATCH 15/58] gdbserver: turn target op 'look_up_symbols' into a method Tankut Baris Aktemur
@ 2020-02-13 20:28   ` Pedro Alves
  0 siblings, 0 replies; 75+ messages in thread
From: Pedro Alves @ 2020-02-13 20:28 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 2/11/20 9:01 AM, Tankut Baris Aktemur wrote:
> @@ -476,6 +468,13 @@ public:
>       Returns 0 on success and errno on failure.  */
>    virtual int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
>  			    int len) = 0;
> +
> +  /* Query GDB for the values of any symbols we're interested in.
> +     This function is called whenever we receive a "qSymbols::"
> +     query, which corresponds to every time more symbols (might)
> +     become available.  NULL if we aren't interested in any
> +     symbols.  */

This "NULL if we aren't interested ..." remark no longer makes
sense, since a method can never be null.  Please double-check
whether other methods need similar adjustment as well.

> +  virtual void look_up_symbols ();

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 52/58] gdbserver: turn breakpoint kind-related target ops into methods
  2020-02-11  9:04 ` [PATCH 52/58] gdbserver: turn breakpoint kind-related target ops into methods Tankut Baris Aktemur
@ 2020-02-13 20:29   ` Pedro Alves
  0 siblings, 0 replies; 75+ messages in thread
From: Pedro Alves @ 2020-02-13 20:29 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 2/11/20 9:02 AM, Tankut Baris Aktemur wrote:
> +const gdb_byte *
> +lynx_process_target::sw_breakpoint_from_kind (int kind, int *size)
> +{
> +  error (_("Target does not implement the sw_breakpoint_from_kind op"));
> +  return nullptr;

The return statement is unreachable.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 24/58] gdbserver: turn target op 'read_offsets' into a method
  2020-02-11  9:03 ` [PATCH 24/58] gdbserver: turn target op 'read_offsets' " Tankut Baris Aktemur
@ 2020-02-13 20:29   ` Pedro Alves
  0 siblings, 0 replies; 75+ messages in thread
From: Pedro Alves @ 2020-02-13 20:29 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 2/11/20 9:01 AM, Tankut Baris Aktemur wrote:
> --- a/gdbserver/linux-low.h
> +++ b/gdbserver/linux-low.h
> @@ -335,6 +335,14 @@ public:
>    bool stopped_by_watchpoint () override;
>  
>    CORE_ADDR stopped_data_address () override;
> +
> +#if defined(__UCLIBC__) && defined(HAS_NOMMU)	      \
> +    && defined(PT_TEXT_ADDR) && defined(PT_DATA_ADDR) \
> +    && defined(PT_TEXT_END_ADDR)

You'll need to move more things to the header.  E.g.,
this in linux-low.c:

 /* Some targets did not define these ptrace constants from the start,
    so gdbserver defines them locally here.  In the future, these may
    be removed after they are added to asm/ptrace.h.  */
 #if !(defined(PT_TEXT_ADDR) \
       || defined(PT_DATA_ADDR) \
       || defined(PT_TEXT_END_ADDR))
 #if defined(__mcoldfire__)
 /* These are still undefined in 3.10 kernels.  */
 #define PT_TEXT_ADDR 49*4
 #define PT_DATA_ADDR 50*4

You may need to move some #includes as well.

Alternatively, always define the methods, and make linux-low.c
put the #ifdef conditionals inside 
linux_process_target::supports_read_offsets and
linux_process_target::read_offsets.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 38/58] gdbserver: turn target ops 'read_pc' and 'write_pc' into methods
  2020-02-11  9:04 ` [PATCH 38/58] gdbserver: turn target ops 'read_pc' and 'write_pc' into methods Tankut Baris Aktemur
@ 2020-02-13 20:29   ` Pedro Alves
  0 siblings, 0 replies; 75+ messages in thread
From: Pedro Alves @ 2020-02-13 20:29 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 2/11/20 9:01 AM, Tankut Baris Aktemur wrote:

> +
> +CORE_ADDR
> +process_target::read_pc (regcache *regcache)
> +{
> +  gdb_assert_not_reached ("regcache_read_pc: Unable to find PC");

"regcache_read_pc" is stale.

> +}
> +
> +void
> +process_target::write_pc (regcache *regcache, CORE_ADDR pc)
> +{
> +  gdb_assert_not_reached ("regcache_write_pc: Unable to update PC");

Ditto "regcache_write_pc".

> +}

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 58/58] gdbserver: finish turning the target ops vector into a class
  2020-02-11  9:05 ` [PATCH 58/58] gdbserver: finish turning the target ops vector into a class Tankut Baris Aktemur
@ 2020-02-13 20:31   ` Pedro Alves
  0 siblings, 0 replies; 75+ messages in thread
From: Pedro Alves @ 2020-02-13 20:31 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 2/11/20 9:02 AM, Tankut Baris Aktemur wrote:

> @@ -7508,10 +7508,6 @@ linux_get_hwcap2 (int wordsize)
>    return hwcap2;
>  }
>  
> -/* The linux target ops object.  */
> -
> -static linux_process_target the_linux_target;
> -

...


>  #ifdef HAVE_LINUX_REGSETS
>  void
>  initialize_regsets_info (struct regsets_info *info)
> @@ -7529,8 +7525,7 @@ initialize_low (void)
>    struct sigaction sigchld_action;
>  
>    memset (&sigchld_action, 0, sizeof (sigchld_action));
> -  the_target.reset (new process_stratum_target);
> -  the_target->pt = &the_linux_target;
> +  the_target.reset (new linux_process_target);

So to follow up to the comment in the previous patch,
I don't think this is better than the other way around, of keeping
the "the_linux_target" global, like GDB does.  The global approach has
the advantage that auxiliary functions in linux-low.c and siblings can
refer to the global without needing to pass around a "this" pointer,
for example.  This object is a singleton, so should be OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 57/58] gdbserver: use unique_ptr for 'the_target'
  2020-02-11  9:04 ` [PATCH 57/58] gdbserver: use unique_ptr for 'the_target' Tankut Baris Aktemur
  2020-02-11 16:43   ` Christian Biesinger via gdb-patches
@ 2020-02-13 20:31   ` Pedro Alves
  1 sibling, 0 replies; 75+ messages in thread
From: Pedro Alves @ 2020-02-13 20:31 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 2/11/20 9:02 AM, Tankut Baris Aktemur wrote:
> The target op vector is about to be replaced with a process_target
> object.  In the current state, the 'set_target_ops' function takes a
> target op vector and creates a clone of it via XNEW and memcpy.  As we
> are now switching to using classes and polymorphism, this memcpy'ing
> will no longer be possible.  For proper memory managament, switch to
> using a unique_ptr.

Typo: "management"

I find it unfortunate to expose the unique_ptr-ness throughtout, since
the target object is really a singleton.  I don't immediately see why
do we need to heap-allocate and copy the target object?
On the gdb side, we define the target as a global instance and then
register a pointer as the native target.  How about we do that in
gdbserver too?

I.e., just make set_target_ops do (with whatever intermediate steps
to get there):

void
set_target_ops (process_stratum_target *target)
{
  the_target = target;
}

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 75+ messages in thread

* RE: [PATCH 02/58] gdbserver: turn target op 'create_inferior' into a method
  2020-02-13 20:27   ` Pedro Alves
@ 2020-02-14 11:01     ` Aktemur, Tankut Baris
  2020-02-14 13:07       ` Pedro Alves
  0 siblings, 1 reply; 75+ messages in thread
From: Aktemur, Tankut Baris @ 2020-02-14 11:01 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Thursday, February 13, 2020 9:27 PM, Pedro Alves wrote:
> On 2/11/20 9:01 AM, Tankut Baris Aktemur wrote:
> > -static int
> > -linux_create_inferior (const char *program,
> > -		       const std::vector<char *> &program_args)
> > +int
> > +linux_process_target::create_inferior (
> > +    const char *program, const std::vector<char *> &program_args)
> 
> No '(' at end of line, please.  You can either write:
> 
> linux_process_target::create_inferior
>   (const char *program, const std::vector<char *> &program_args)
> 
> ... with two leading spaces, or:
> 
> linux_process_target::create_inferior (const char *program,
>                                        const std::vector<char *> &program_args)
> 
> since that fits in 79 cols.

Thanks for your comments!

I had seen existing cases of

  some_very_long_function_name
    (int param1...)

but then I went with the formatting above based on 
https://gcc.gnu.org/codingconventions.html#Member_Form 
thinking that this is perhaps a C/C++ difference.

I also typed

  class linux_process_target : public process_target {

instead of

  class linux_process_target : public process_target
  {

because of the example shown at 
https://gcc.gnu.org/codingconventions.html#Class_Form

I'll fix all occurrences of both formatting issues in v2 of the series.

Thanks,
-Baris


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 75+ messages in thread

* Re: [PATCH 02/58] gdbserver: turn target op 'create_inferior' into a method
  2020-02-14 11:01     ` Aktemur, Tankut Baris
@ 2020-02-14 13:07       ` Pedro Alves
  0 siblings, 0 replies; 75+ messages in thread
From: Pedro Alves @ 2020-02-14 13:07 UTC (permalink / raw)
  To: Aktemur, Tankut Baris; +Cc: gdb-patches

On 2/14/20 11:01 AM, Aktemur, Tankut Baris wrote:
> On Thursday, February 13, 2020 9:27 PM, Pedro Alves wrote:
>> On 2/11/20 9:01 AM, Tankut Baris Aktemur wrote:
>>> -static int
>>> -linux_create_inferior (const char *program,
>>> -		       const std::vector<char *> &program_args)
>>> +int
>>> +linux_process_target::create_inferior (
>>> +    const char *program, const std::vector<char *> &program_args)
>>
>> No '(' at end of line, please.  You can either write:
>>
>> linux_process_target::create_inferior
>>   (const char *program, const std::vector<char *> &program_args)
>>
>> ... with two leading spaces, or:
>>
>> linux_process_target::create_inferior (const char *program,
>>                                        const std::vector<char *> &program_args)
>>
>> since that fits in 79 cols.
> 
> Thanks for your comments!
> 
> I had seen existing cases of
> 
>   some_very_long_function_name
>     (int param1...)
> 
> but then I went with the formatting above based on 
> https://gcc.gnu.org/codingconventions.html#Member_Form 
> thinking that this is perhaps a C/C++ difference.
> 
> I also typed
> 
>   class linux_process_target : public process_target {
> 
> instead of
> 
>   class linux_process_target : public process_target
>   {
> 
> because of the example shown at 
> https://gcc.gnu.org/codingconventions.html#Class_Form
> 

Yeah, I don't think even GCC follows those specific points in
the convention much.  They were written years ago when GCC was
converting to C++.  I think diverging from usual GNU conventions in
these specific cases just adds to confusion, IMO.

> I'll fix all occurrences of both formatting issues in v2 of the series.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 75+ messages in thread

end of thread, other threads:[~2020-02-14 13:07 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-11  9:02 [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 04/58] gdbserver: turn target op 'attach' into a method Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 22/58] gdbserver: turn target op 'supports_hardware_single_step' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 26/58] gdbserver: turn target op 'hostio_last_error' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 48/58] gdbserver: turn btrace-related target ops into methods Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 28/58] gdbserver: turn target op 'qxfer_siginfo' into a method Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 06/58] gdbserver: turn target op 'detach' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 12/58] gdbserver: turn target ops 'fetch_registers' and 'store_registers' into methods Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 20/58] gdbserver: turn target op '{supports_}stopped_by_sw_breakpoint' into a method Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 07/58] gdbserver: turn target op 'mourn' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 33/58] gdbserver: turn target op 'handle_monitor_command' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 24/58] gdbserver: turn target op 'read_offsets' " Tankut Baris Aktemur
2020-02-13 20:29   ` Pedro Alves
2020-02-11  9:03 ` [PATCH 37/58] gdbserver: turn target op 'supports_tracepoints' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 09/58] gdbserver: turn target op 'thread_alive' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 23/58] gdbserver: turn target ops 'stopped_by_watchpoint' and 'stopped_data_address' into methods Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 25/58] gdbserver: turn target op 'get_tls_address' into a method Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 21/58] gdbserver: turn target op '{supports_}stopped_by_hw_breakpoint' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 03/58] gdbserver: turn target op 'post_create_inferior' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 08/58] gdbserver: turn target op 'join' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 43/58] gdbserver: turn fast tracepoint target ops into methods Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 32/58] gdbserver: turn target op 'handle_new_gdb_connection' into a method Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 01/58] gdbserver: start turning the target ops vector into a class Tankut Baris Aktemur
2020-02-13 20:26   ` Pedro Alves
2020-02-11  9:03 ` [PATCH 40/58] gdbserver: turn target op 'get_tib_address' into a method Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 36/58] gdbserver: turn target op 'process_qsupported' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 02/58] gdbserver: turn target op 'create_inferior' " Tankut Baris Aktemur
2020-02-13 20:27   ` Pedro Alves
2020-02-14 11:01     ` Aktemur, Tankut Baris
2020-02-14 13:07       ` Pedro Alves
2020-02-11  9:03 ` [PATCH 45/58] gdbserver: turn target op 'supports_disable_randomization' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 27/58] gdbserver: turn target op 'qxfer_osdata' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 05/58] gdbserver: turn target op 'kill' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 19/58] gdbserver: turn target ops 'insert_point' and 'remove_point' into methods Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 15/58] gdbserver: turn target op 'look_up_symbols' into a method Tankut Baris Aktemur
2020-02-13 20:28   ` Pedro Alves
2020-02-11  9:03 ` [PATCH 13/58] gdbserver: turn prepare_to_access_memory & done_accessing_memory into methods Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 18/58] gdbserver: turn target op 'supports_z_point_type' into a method Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 11/58] gdbserver: turn target op 'wait' " Tankut Baris Aktemur
2020-02-11  9:03 ` [PATCH 46/58] gdbserver: turn target op 'qxfer_libraries_svr4' " Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 14/58] gdbserver: turn target ops 'read_memory' and 'write_memory' into methods Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 49/58] gdbserver: turn target op 'supports_range_stepping' into a method Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 47/58] gdbserver: turn target op 'supports_agent' " Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 39/58] gdbserver: turn target op 'thread_stopped' " Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 52/58] gdbserver: turn breakpoint kind-related target ops into methods Tankut Baris Aktemur
2020-02-13 20:29   ` Pedro Alves
2020-02-11  9:04 ` [PATCH 34/58] gdbserver: turn target op 'core_of_thread' into a method Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 54/58] gdbserver: turn target op 'supports_software_single_step' " Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 17/58] gdbserver: turn target op 'read_auxv' " Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 42/58] gdbserver: turn target op 'stabilize_threads' " Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 53/58] gdbserver: turn target ops 'thread_name' and 'thread_handle' into methods Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 56/58] gdbserver: turn target op 'get_ipa_tdesc_idx' into a method Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 31/58] gdbserver: turn target ops 'supports_{fork,vfork,exec}_events' into methods Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 57/58] gdbserver: use unique_ptr for 'the_target' Tankut Baris Aktemur
2020-02-11 16:43   ` Christian Biesinger via gdb-patches
2020-02-12  8:32     ` Aktemur, Tankut Baris
2020-02-13 20:31   ` Pedro Alves
2020-02-11  9:04 ` [PATCH 38/58] gdbserver: turn target ops 'read_pc' and 'write_pc' into methods Tankut Baris Aktemur
2020-02-13 20:29   ` Pedro Alves
2020-02-11  9:04 ` [PATCH 50/58] gdbserver: turn target op 'pid_to_exec_file' into a method Tankut Baris Aktemur
2020-02-11  9:04 ` [PATCH 55/58] gdbserver: turn target op 'supports_catch_syscall' " Tankut Baris Aktemur
2020-02-11  9:05 ` [PATCH 44/58] gdbserver: turn target op 'emit_ops' " Tankut Baris Aktemur
2020-02-11  9:05 ` [PATCH 30/58] gdbserver: turn target op 'supports_multi_process' " Tankut Baris Aktemur
2020-02-11  9:05 ` [PATCH 58/58] gdbserver: finish turning the target ops vector into a class Tankut Baris Aktemur
2020-02-13 20:31   ` Pedro Alves
2020-02-11  9:05 ` [PATCH 29/58] gdbserver: turn non-stop and async target ops into methods Tankut Baris Aktemur
2020-02-11  9:05 ` [PATCH 10/58] gdbserver: turn target op 'resume' into a method Tankut Baris Aktemur
2020-02-11  9:05 ` [PATCH 35/58] gdbserver: turn target op 'read_loadmap' " Tankut Baris Aktemur
2020-02-11  9:05 ` [PATCH 51/58] gdbserver: turn target ops 'multifs_{open, readlink, unlink}' into methods Tankut Baris Aktemur
2020-02-11  9:05 ` [PATCH 16/58] gdbserver: turn target op 'request_interrupt' into a method Tankut Baris Aktemur
2020-02-11  9:05 ` [PATCH 41/58] gdbserver: turn target ops 'pause_all' and 'unpause_all' into methods Tankut Baris Aktemur
2020-02-11 17:41 ` [PATCH 00/58] Turn gdbserver's process_stratum_target into a class Christian Biesinger via gdb-patches
2020-02-12  8:18   ` Aktemur, Tankut Baris
2020-02-12 16:43     ` Christian Biesinger via gdb-patches
2020-02-13 20:26 ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).