[gdbserver] Imply --once if connecting via stdio

Message ID 20240524211541.378520-1-wqferr@gmail.com
State New
Headers
Series [gdbserver] Imply --once if connecting via stdio |

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-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

William Ferreira May 24, 2024, 9:15 p.m. UTC
  Currently, gdbserver hangs after stdin is closed while it tries to
write: "Remote side has terminated connection.  GDBserver will reopen
the connection." This hang disappears if --once is also given. Since
the stdin connection won't ever reopen if it's closed, it's safe to
assume --once is desired.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29796
---
 gdbserver/server.cc | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Guinevere Larsen May 31, 2024, 4:04 p.m. UTC | #1
On 5/24/24 18:15, William Ferreira wrote:
> Currently, gdbserver hangs after stdin is closed while it tries to
> write: "Remote side has terminated connection.  GDBserver will reopen
> the connection." This hang disappears if --once is also given. Since
> the stdin connection won't ever reopen if it's closed, it's safe to
> assume --once is desired.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29796
> ---
Hi William!

Thanks for the patch!

Since I helped you develop this patch and its not an area I'm all too 
familiar with, I don't think its fair for me to review this patch. 
However, I have tested the patch with both native-gdbserver and 
native-extended-gdbserver, and I see no regressions, so feel free to add 
my tested tag to this!

Tested-By: Guinevere Larsen <blarsen@redhat.com>
  
Andrew Burgess June 3, 2024, 3:25 p.m. UTC | #2
William Ferreira <wqferr@gmail.com> writes:

> Currently, gdbserver hangs after stdin is closed while it tries to
> write: "Remote side has terminated connection.  GDBserver will reopen
> the connection." This hang disappears if --once is also given. Since
> the stdin connection won't ever reopen if it's closed, it's safe to
> assume --once is desired.

Thanks for working on this.

Ideally it would be nice to have a test added for this.  We already have
gdb.server/server-pipe.exp which uses 'target remote | ...', maybe this
test could be extended?  Or you could copy this test and change it as
needed?

Let me know if you need additional help writing a test.

Thanks,
Andrew


>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29796
> ---
>  gdbserver/server.cc | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/gdbserver/server.cc b/gdbserver/server.cc
> index 789af36d9a4..3ab7a1eed14 100644
> --- a/gdbserver/server.cc
> +++ b/gdbserver/server.cc
> @@ -4204,6 +4204,10 @@ captured_main (int argc, char *argv[])
>  	  /* "-" specifies a stdio connection and is a form of port
>  	     specification.  */
>  	  port = STDIO_CONNECTION_NAME;
> +
> +	  /* Implying --once here prevents a hang after stdin has been closed.  */
> +	  run_once = true;
> +
>  	  next_arg++;
>  	  break;
>  	}
> -- 
> 2.45.1
  

Patch

diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 789af36d9a4..3ab7a1eed14 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -4204,6 +4204,10 @@  captured_main (int argc, char *argv[])
 	  /* "-" specifies a stdio connection and is a form of port
 	     specification.  */
 	  port = STDIO_CONNECTION_NAME;
+
+	  /* Implying --once here prevents a hang after stdin has been closed.  */
+	  run_once = true;
+
 	  next_arg++;
 	  break;
 	}