From: William Ferreira Date: Thu, 18 Jul 2024 19:38:31 +0000 (-0300) Subject: gdb: imply --once if connecting via stdio X-Git-Tag: gdb-16-branchpoint~1076 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a733b2c90463231d9fb8b143e168403d96efe54f;p=thirdparty%2Fbinutils-gdb.git gdb: imply --once if connecting via stdio 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. The gdb.server/server-pipe.exp test was also updated to reflect this change. There is now a second disconnect at the end of the proc, with a tighter-than-normal timeout to catch if the command hangs as it used to. Co-Authored-By: Guinevere Larsen Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29796 Approved-By: Andrew Burgess --- diff --git a/gdb/testsuite/gdb.server/server-pipe.exp b/gdb/testsuite/gdb.server/server-pipe.exp index b369759b98a..3d73c2e7ce6 100644 --- a/gdb/testsuite/gdb.server/server-pipe.exp +++ b/gdb/testsuite/gdb.server/server-pipe.exp @@ -49,11 +49,12 @@ if {[build_executable "failed to prepare" $testfile $srcfile debug]} { # or "extended-remote". Check the output of 'info connections', and # the contents of the gdb.TargetConnection.details string. proc do_test { target } { + global timeout clean_restart ${::binfile} # Make sure we're disconnected, in case we're testing with an # extended-remote board, therefore already connected. - gdb_test "disconnect" ".*" + gdb_test "disconnect" ".*" "disconnect before running the test" gdb_test "target ${target} | ${::gdbserver} - ${::binfile}" ".*" \ "start gdbserver using pipe syntax" @@ -68,6 +69,16 @@ proc do_test { target } { gdb_test_no_output "python conn = gdb.selected_inferior().connection" gdb_test "python print(conn.details)" "\| ${::gdbserver} - ${::binfile}" } + + # Make sure GDB server doesn't attempt to reconnect with a closed STDIN. + # Here we set the timeout to a short value to see if GDB will hang in an + # attempt to reconnect with the now closed STDIN. For this test to be + # useful the new temporary timeout MUST be shorter than PIPE_CLOSE_TIMEOUT + # defined in gdb/ser-pipe.c (5 seconds at the time of writing). + set prev_timeout $timeout + set timeout 2 + gdb_test "disconnect" ".*" "disconnect and test for hang" + set timeout $prev_timeout } save_vars { GDBFLAGS } { diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 7c2973df000..ee537760cfe 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -4209,6 +4209,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; }