]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: imply --once if connecting via stdio
authorWilliam Ferreira <wqferr@gmail.com>
Thu, 18 Jul 2024 19:38:31 +0000 (16:38 -0300)
committerAndrew Burgess <aburgess@redhat.com>
Mon, 26 Aug 2024 14:45:01 +0000 (15:45 +0100)
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 <blarsen@redhat.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29796

Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/testsuite/gdb.server/server-pipe.exp
gdbserver/server.cc

index b369759b98a54bd9b52ae4ea087440285a8d1c6d..3d73c2e7ce6750ba63e117929b9f273ebfaf5447 100644 (file)
@@ -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 } {
index 7c2973df000cd320f73415fbaf8eb0229e79bdfa..ee537760cfe21552ad9eb5062726dd1f93dc5cdf 100644 (file)
@@ -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;
        }