[v2,5/6] remote.c: Add terminal handling functions

Message ID 20240119115659.491195-7-ahajkova@redhat.com
State New
Headers
Series Add vDefaultInferiorFd feature |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Alexandra Petlanova Hajkova Jan. 19, 2024, 11:56 a.m. UTC
  Re-use terminal handling functions from inf-child.c so GDBserver can
call them. This helps local remote target to behave more like native
target.
---
 gdb/remote.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
  

Patch

diff --git a/gdb/remote.c b/gdb/remote.c
index d90e071f4fb..3406eaf43e7 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -607,6 +607,10 @@  class remote_state
      qSupported.  */
   gdb_thread_options supported_thread_options = 0;
 
+  /* gdbserver accepted the file descriptor numbers of the terminal
+     GDB is connected to.  */
+  bool fds_accepted = false;
+
 private:
   /* Asynchronous signal handle registered as event loop source for
      when we have pending events ready to be passed to the core.  */
@@ -908,10 +912,18 @@  class remote_target : public process_stratum_target
 
   int can_do_single_step () override;
 
+  bool supports_terminal_ours () override;
+
+  void terminal_init () override;
+
   void terminal_inferior () override;
 
+  void terminal_save_inferior() override;
+
   void terminal_ours () override;
 
+  void terminal_ours_for_output() override;
+
   bool supports_non_stop () override;
 
   bool supports_multi_process () override;
@@ -1731,6 +1743,36 @@  remote_target::get_remote_state ()
   return &m_remote_state;
 }
 
+bool
+remote_target::supports_terminal_ours ()
+{
+  return true;
+}
+
+void
+remote_target::terminal_init ()
+{
+  struct remote_state *rs = get_remote_state ();
+  if (rs->fds_accepted)
+    child_terminal_init (this);
+}
+
+void
+remote_target::terminal_save_inferior ()
+{
+  struct remote_state *rs = get_remote_state ();
+  if (rs->fds_accepted)
+    child_terminal_save_inferior (this);
+}
+
+void
+remote_target::terminal_ours_for_output ()
+{
+  struct remote_state *rs = get_remote_state ();
+  if (rs->fds_accepted)
+    child_terminal_ours_for_output (this);
+}
+
 /* Fetch the remote exec-file from the current program space.  */
 
 static const char *
@@ -5035,6 +5077,12 @@  remote_target::start_remote_1 (int from_tty, int extended_p)
 
       putpkt (rs->buf);
       getpkt (&rs->buf, 0);
+
+      if (m_features.packet_ok (rs->buf, PACKET_vDefaultInferiorFd) == PACKET_OK)
+        rs->fds_accepted = true;
+      else
+        error (_("Remote replied unexpectedly to 'vDefaultInferiorFd': %s"),
+               rs->buf.data ());
   }
 
   /* Check vCont support and set the remote state's vCont_action_support
@@ -7565,11 +7613,18 @@  remote_target::terminal_inferior ()
   /* NOTE: At this point we could also register our selves as the
      recipient of all input.  Any characters typed could then be
      passed on down to the target.  */
+
+    struct remote_state *rs = get_remote_state ();
+    if (rs->fds_accepted)
+        child_terminal_inferior (this);
 }
 
 void
 remote_target::terminal_ours ()
 {
+    struct remote_state *rs = get_remote_state ();
+    if (rs->fds_accepted)
+        child_terminal_ours (this);
 }
 
 static void