Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Alexandra Hájková" <ahajkova@redhat.com>
To: gdb-patches@sourceware.org
Cc: ahajkova@redhat.com
Subject: [PATCH 5/6] remote.c: Add terminal handling functions
Date: Fri, 17 Nov 2023 12:18:39 +0100	[thread overview]
Message-ID: <20231117111840.2040709-6-ahajkova@redhat.com> (raw)
In-Reply-To: <20231117111840.2040709-1-ahajkova@redhat.com>

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(+)

diff --git a/gdb/remote.c b/gdb/remote.c
index 27d053c367c..68835a29244 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;
@@ -1732,6 +1744,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 *
@@ -5029,6 +5071,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
@@ -7558,11 +7606,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
-- 
2.41.0


  parent reply	other threads:[~2023-11-17 11:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17 11:18 [PATCH 0/6] Add vDefaultInferiorFd feature Alexandra Hájková
2023-11-17 11:18 ` [PATCH 1/6] gdb.server/non-existing-program.exp: Use gdbserver_start Alexandra Hájková
2023-11-17 11:18 ` [PATCH 2/6] gdb/ser-pipe.c: Duplicate the file descriptors Alexandra Hájková
2023-12-12 19:42   ` Tom Tromey
2023-11-17 11:18 ` [PATCH 3/6] Add new vDefaultInferiorFd packet Alexandra Hájková
2023-11-17 12:09   ` Eli Zaretskii
2023-12-12 20:03   ` Tom Tromey
2023-11-17 11:18 ` [PATCH 4/6] gdbserver/linux-low.cc: Connect the inferior to the terminal Alexandra Hájková
2023-12-12 20:10   ` Tom Tromey
2023-11-17 11:18 ` Alexandra Hájková [this message]
2023-12-12 20:11   ` [PATCH 5/6] remote.c: Add terminal handling functions Tom Tromey
2023-11-17 11:18 ` [PATCH 6/6] Add defaultinf.exp test to the testsuite Alexandra Hájková
2023-11-27 10:01 ` [PATCH 0/6] Add vDefaultInferiorFd feature Alexandra Petlanova Hajkova
2023-12-01 20:22 ` Tom Tromey
2023-12-04 11:08   ` Andrew Burgess
2023-12-04 12:11   ` Alexandra Petlanova Hajkova
2023-12-05 16:00     ` Tom Tromey
2023-12-08 13:06       ` Andrew Burgess
2023-12-12 20:14   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231117111840.2040709-6-ahajkova@redhat.com \
    --to=ahajkova@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox