1 # Copyright 2016-2023 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test that on a separate MI UI (new-ui mi <tty>), the printing of an
17 # asynchronous event (e.g. =library-loaded) during the synchronous
18 # execution of a command (e.g. -exec-run or -exec-continue) does not
19 # prematurely re-enable MI input. After executing synchronous
20 # commands, MI should not process further commands until the inferior
21 # stops again. See PR gdb/20418.
23 # Do not run if gdb debug is enabled as it doesn't work for separate-mi-tty.
24 if [gdb_debug_enabled] {
25 untested "debug is enabled"
29 load_lib mi-support.exp
33 if {[build_executable $testfile.exp $testfile ${srcfile} "debug"] == -1} {
34 untested "failed to compile"
38 # The test driver. SYNC_COMMAND specifies which command is used to
39 # synchronously start the program running.
41 proc do_test {sync_command} {
42 global srcdir subdir binfile srcfile
43 global gdb_spawn_id gdb_main_spawn_id mi_spawn_id inferior_spawn_id
44 global gdb_prompt mi_gdb_prompt
48 if {[mi_gdb_start "separate-mi-tty"] != 0} {
49 fail "could not start gdb"
54 mi_gdb_reinitialize_dir $srcdir/$subdir
57 # Start a synchronous run/continue on the MI UI.
58 set test "send synchronous execution command"
59 if {$sync_command == "run"} {
60 if {[mi_run_cmd] >= 0} {
66 if {[mi_runto_main] < 0} {
69 if {[mi_send_resuming_command_raw "123-exec-continue" $test] >= 0} {
76 # Send -thread-info immediately after. If everything works
77 # correctly, this is only serviced by GDB when the execution
79 send_gdb "456-thread-info\n"
80 pass "send -thread-info"
82 # Make sure we trigger an asynchronous event (=thread-group-added)
83 # in the separate MI UI. Note the "run" variant usually triggers
84 # =thread-group-started/=thread-created/=library-loaded as well.
85 with_spawn_id $gdb_main_spawn_id {
86 gdb_test "add-inferior" "Added inferior 2 on connection .*"
89 # Interrupt the program.
90 with_spawn_id $gdb_main_spawn_id {
91 set message "interrupt on the CLI"
92 gdb_test_multiple "interrupt" "$message" {
94 gdb_test_multiple "" "$message" {
95 -re "received signal SIGINT" {
103 # On the MI channel, we should see the interrupt output _before_
104 # the -thread-info output.
105 with_spawn_id $mi_spawn_id {
106 mi_expect_interrupt "got MI interrupt output"
109 # Look for the result of our -thread-info. If input were
110 # re-enabled too soon, the thread would incorrectly show up with
112 with_spawn_id $mi_spawn_id {
113 mi_gdb_test "" "456\\^.*state=\"stopped\".*" \
114 "got -thread-info output and thread is stopped"
118 foreach_with_prefix sync-command {"run" "continue"} {
119 do_test ${sync-command}