Fix mi_gdb_exit with secondary MI channels
authorPedro Alves <pedro@palves.net>
Sun, 20 Sep 2020 14:58:26 +0000 (15:58 +0100)
committerPedro Alves <pedro@palves.net>
Sun, 20 Sep 2020 15:02:24 +0000 (16:02 +0100)
Tests that use a secondary MI channel (i.e., either tests that call
mi_gdb_start with separate-mi-tty, or all tests when
FORCE_SEPARATE_MI_TTY=1 is specified on the make check command line),
don't close GDB correctly.

E.g., if you run gdb.mi/mi-exec-run.exp in a loop:

  while true; do make check TESTS="gdb.mi/mi-exec-run.exp"; done

you can see more than one gdb running at the same time:

  $ ps -ef | grep -v grep | grep "gdb/gdb"
  pedro      40507       1  7 15:47 ?        00:00:00 /home/pedro/gdb/build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/pedro/gdb/build/gdb/testsuite/../data-directory
  pedro      40562       1  0 15:47 ?        00:00:00 /home/pedro/gdb/build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/pedro/gdb/build/gdb/testsuite/../data-directory
  pedro      40727       1  0 15:47 ?        00:00:00 /home/pedro/gdb/build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/pedro/gdb/build/gdb/testsuite/../data-directory
  pedro      40786       1  0 15:47 ?        00:00:00 /home/pedro/gdb/build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/pedro/gdb/build/gdb/testsuite/../data-directory

This commit fixes it.

gdb/testsuite/ChangeLog:

* lib/mi-support.exp (mi_uncatched_gdb_exit) Switch to the main
spawn_id before calling remote_close.  Close secondary MI channel.

gdb/testsuite/ChangeLog
gdb/testsuite/lib/mi-support.exp

index 71ec4951f16fb8442fa20f15a9e54e6e99a053e4..85bafbada4a60ca63c3b9d9a46175ddd5b6aeb0e 100644 (file)
@@ -1,3 +1,8 @@
+2020-09-20  Pedro Alves  <pedro@palves.net>
+
+       * lib/mi-support.exp (mi_uncatched_gdb_exit) Switch to the main
+       spawn_id before calling remote_close.  Close secondary MI channel.
+
 2020-09-20  Pedro Alves  <pedro@palves.net>
 
        * gdb.base/testenv.exp (find_env): Bail out if printing 'envp[$i]'
index 5c1fcca4d233f1e5afe91edc0f2c20d8e777d55a..0e7524ed0f65a28e882eb528f5a1313b932b94e8 100644 (file)
@@ -89,6 +89,18 @@ proc mi_uncatched_gdb_exit {} {
        }
     }
 
+    # Switch back to the main spawn id, so that remote_close below
+    # closes it, and not a secondary channel.  Closing a secondary
+    # channel does not make GDB exit.
+    if {$gdb_spawn_id != $gdb_main_spawn_id} {
+       switch_gdb_spawn_id $gdb_main_spawn_id
+    }
+
+    # Close secondary MI channel, if there's one.
+    if {$mi_spawn_id != $gdb_main_spawn_id} {
+       close -i $mi_spawn_id
+    }
+
     if ![is_remote host] {
        remote_close host
     }
This page took 0.038411 seconds and 4 git commands to generate.