[gdb/testsuite] Fix silent timeout in gdb.multi/multi-target.exp
authorTom de Vries <tdevries@suse.de>
Thu, 2 Apr 2020 07:46:00 +0000 (09:46 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 2 Apr 2020 07:46:00 +0000 (09:46 +0200)
While running test-case gdb.multi/multi-target.exp, I observed a silent
timeout related to "monitor exit".

By making the timeout explicit in an expect clause in gdbserver_gdb_exit:
...
+  timeout {
+    warning "Timed out waiting for EOF in server after $monitor_exit"
+  }
...
we get in the log:
...
monitor exit^M
"monitor" command not supported by this target.^M
(gdb) WARNING: Timed out waiting for EOF in server after monitor exit
...

What happens is the following:
- the inferior 5 is selected
- a breakpoint is set in inferior 1
- the breakpoint triggers and we switch to inferior 1
- setup is called by test_continue, which calls clean_restart, which calls
  gdbserver_gdb_exit (due to load_lib gdbserver-support.exp)
- gdbserver_gdb_exit issues "monitor exit"
- gdb responds with "not supported by this target" because inferior 1 is
  native

Fix this by keeping a list of server_spawn_id, and cleaning those up before
calling gdbserver_gdb_exit.

This reduces testing time from 1m22s to 32s.

gdb/testsuite/ChangeLog:

2020-04-02  Tom de Vries  <tdevries@suse.de>

* lib/gdbserver-support.exp (gdbserver_exit): Factor out of ...
(gdbserver_gdb_exit): ... here.  Add timeout warning.
* gdb.multi/multi-target.exp (server_spawn_ids): New global var.
(connect_target_extended_remote): Append new server_spawn_id to
server_spawn_ids.
(cleanup): New proc.
(setup, <toplevel>): Call cleanup.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.multi/multi-target.exp
gdb/testsuite/lib/gdbserver-support.exp

index 5dcb844bfde4b65edb6007c3745cf84fa9ad3d27..99813054d5db06cbed459da998c9c062aa05c672 100644 (file)
@@ -1,3 +1,13 @@
+2020-04-02  Tom de Vries  <tdevries@suse.de>
+
+       * lib/gdbserver-support.exp (gdbserver_exit): Factor out of ...
+       (gdbserver_gdb_exit): ... here.  Add timeout warning.
+       * gdb.multi/multi-target.exp (server_spawn_ids): New global var.
+       (connect_target_extended_remote): Append new server_spawn_id to
+       server_spawn_ids.
+       (cleanup): New proc.
+       (setup, <toplevel>): Call cleanup.
+
 2020-04-02  Tom de Vries  <tdevries@suse.de>
 
        * gdb.base/main-psymtab.exp: New file.
index 6c727b5e3bdbb5767925232808bf8ca0e39bbee4..b519eda4e8dba60941306ecefc8b38863712833b 100644 (file)
@@ -33,8 +33,13 @@ if { [prepare_for_testing "failed to prepare" ${binfile} "${srcfile}" \
     return
 }
 
-proc connect_target_extended_remote {binfile} {
+# Keep a list of (inferior ID, spawn ID).
+set server_spawn_ids [list]
+
+proc connect_target_extended_remote {binfile num} {
     set res [gdbserver_start "--multi" ""]
+    global server_spawn_ids server_spawn_id
+    lappend server_spawn_ids $num $server_spawn_id
     set gdbserver_gdbport [lindex $res 1]
     return [gdb_target_cmd "extended-remote" $gdbserver_gdbport]
 }
@@ -58,7 +63,7 @@ proc add_inferior {num target binfile {gcorefile ""}} {
     }
 
     if {$target == "extended-remote"} {
-       if {[connect_target_extended_remote $binfile]} {
+       if {[connect_target_extended_remote $binfile $num]} {
            return 0
        }
     }
@@ -99,12 +104,25 @@ proc next_live_inferior {inf} {
     return $inf
 }
 
+# Clean up the server_spawn_ids.
+proc cleanup_gdbservers { } {
+    global server_spawn_id
+    global server_spawn_ids
+    foreach { inferior_id spawn_id } $server_spawn_ids {
+       set server_spawn_id $spawn_id
+       gdb_test "inferior $inferior_id"
+       gdbserver_exit 0
+    }
+    set server_spawn_ids [list]
+}
+
 # Return true on success, false otherwise.
 
 proc setup {non-stop} {
     global gcorefile gcore_created
     global binfile
 
+    cleanup_gdbservers
     clean_restart ${binfile}
 
     # multi-target depends on target running in non-stop mode.  Force
@@ -448,3 +466,5 @@ with_test_prefix "info-inferiors" {
        test_info_inferiors $multi_process
     }
 }
+
+cleanup_gdbservers
index 706bbeb9df4b856fac416a9767e8d72f1563e583..a2cc80f28d7cf5da93eee6adefeb696181ec6df5 100644 (file)
@@ -431,21 +431,11 @@ if { [info procs gdbserver_orig_gdb_exit] == "" } {
     rename mi_gdb_exit gdbserver_orig_mi_gdb_exit
 }
 
-proc gdbserver_gdb_exit { is_mi } {
+# Cleanup gdbserver $server_spawn_id
+
+proc gdbserver_exit { is_mi } {
     global gdb_spawn_id server_spawn_id
     global gdb_prompt
-    global gdbserver_reconnect_p
-
-    # Leave GDBserver running if we're exiting GDB in order to
-    # reconnect to the same instance of GDBserver again.
-    if {[info exists gdbserver_reconnect_p] && $gdbserver_reconnect_p} {
-       if { $is_mi } {
-           gdbserver_orig_mi_gdb_exit
-       } else {
-           gdbserver_orig_gdb_exit
-       }
-       return
-    }
 
     if {[info exists gdb_spawn_id] && [info exists server_spawn_id]} {
        # GDB may be terminated in an expected way or an unexpected way,
@@ -469,10 +459,34 @@ proc gdbserver_gdb_exit { is_mi } {
                    wait -i $expect_out(spawn_id)
                    unset server_spawn_id
                }
+               timeout {
+                   warning "Timed out waiting for EOF in server after $monitor_exit"
+               }
            }
        }
     }
     close_gdbserver
+}
+
+# Local version of gdb_exit that also cleans up gdbserver $server_spawn_id.
+
+proc gdbserver_gdb_exit { is_mi } {
+    global gdb_spawn_id server_spawn_id
+    global gdb_prompt
+    global gdbserver_reconnect_p
+
+    # Leave GDBserver running if we're exiting GDB in order to
+    # reconnect to the same instance of GDBserver again.
+    if {[info exists gdbserver_reconnect_p] && $gdbserver_reconnect_p} {
+       if { $is_mi } {
+           gdbserver_orig_mi_gdb_exit
+       } else {
+           gdbserver_orig_gdb_exit
+       }
+       return
+    }
+
+    gdbserver_exit $is_mi
 
     if { $is_mi } {
        gdbserver_orig_mi_gdb_exit