xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.mi/new-ui-mi-sync.exp (revision 7bdf38e5b7a28439665f2fdeff81e36913eef7dd)
1# Copyright 2016-2023 Free Software Foundation, Inc.
2
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.
7#
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.
12#
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/>.
15
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.
22
23# Do not run if gdb debug is enabled as it doesn't work for separate-mi-tty.
24if [gdb_debug_enabled] {
25    untested "debug is enabled"
26    return 0
27}
28
29load_lib mi-support.exp
30
31standard_testfile
32
33if {[build_executable $testfile.exp $testfile ${srcfile} "debug"] == -1} {
34    untested "failed to compile"
35    return -1
36}
37
38# The test driver.  SYNC_COMMAND specifies which command is used to
39# synchronously start the program running.
40
41proc 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
45
46    mi_gdb_exit
47
48    if {[mi_gdb_start "separate-mi-tty"] != 0} {
49	fail "could not start gdb"
50	return
51    }
52
53    mi_delete_breakpoints
54    mi_gdb_reinitialize_dir $srcdir/$subdir
55    mi_gdb_load $binfile
56
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} {
61	    pass $test
62	} else {
63	    return
64	}
65    } else {
66	if {[mi_runto_main] < 0} {
67	    return
68	}
69	if {[mi_send_resuming_command_raw "123-exec-continue" $test] >= 0} {
70	    pass $test
71	} else {
72	    return
73	}
74    }
75
76    # Send -thread-info immediately after.  If everything works
77    # correctly, this is only serviced by GDB when the execution
78    # stops.
79    send_gdb "456-thread-info\n"
80    pass "send -thread-info"
81
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 .*"
87    }
88
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" {
93	    -re "$gdb_prompt " {
94		gdb_test_multiple "" "$message" {
95		    -re "received signal SIGINT" {
96			pass $message
97		    }
98		}
99	    }
100	}
101    }
102
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"
107    }
108
109    # Look for the result of our -thread-info.  If input were
110    # re-enabled too soon, the thread would incorrectly show up with
111    # state="running".
112    with_spawn_id $mi_spawn_id {
113	mi_gdb_test "" "456\\^.*state=\"stopped\".*" \
114	    "got -thread-info output and thread is stopped"
115    }
116}
117
118foreach_with_prefix sync-command {"run" "continue"} {
119    do_test ${sync-command}
120}
121