]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/new-ui-mi-sync.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / new-ui-mi-sync.exp
1 # Copyright 2016-2024 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.
24 require !gdb_debug_enabled
25
26 load_lib mi-support.exp
27
28 standard_testfile
29
30 if {[build_executable $testfile.exp $testfile ${srcfile} "debug"] == -1} {
31 untested "failed to compile"
32 return -1
33 }
34
35 # The test driver. SYNC_COMMAND specifies which command is used to
36 # synchronously start the program running.
37
38 proc do_test {sync_command} {
39 global srcdir subdir binfile srcfile
40 global gdb_spawn_id gdb_main_spawn_id mi_spawn_id inferior_spawn_id
41 global gdb_prompt mi_gdb_prompt
42
43 if {[mi_clean_restart $binfile "separate-mi-tty"] != 0} {
44 fail "could not start gdb"
45 return
46 }
47
48 # Start a synchronous run/continue on the MI UI.
49 set test "send synchronous execution command"
50 if {$sync_command == "run"} {
51 if {[mi_run_cmd] >= 0} {
52 pass $test
53 } else {
54 return
55 }
56 } else {
57 if {[mi_runto_main] < 0} {
58 return
59 }
60 if {[mi_send_resuming_command_raw "123-exec-continue" $test] >= 0} {
61 pass $test
62 } else {
63 return
64 }
65 }
66
67 # Send -thread-info immediately after. If everything works
68 # correctly, this is only serviced by GDB when the execution
69 # stops.
70 send_gdb "456-thread-info\n"
71 pass "send -thread-info"
72
73 # Make sure we trigger an asynchronous event (=thread-group-added)
74 # in the separate MI UI. Note the "run" variant usually triggers
75 # =thread-group-started/=thread-created/=library-loaded as well.
76 with_spawn_id $gdb_main_spawn_id {
77 gdb_test "add-inferior" "Added inferior 2 on connection .*"
78 }
79
80 # Interrupt the program.
81 with_spawn_id $gdb_main_spawn_id {
82 set message "interrupt on the CLI"
83 gdb_test_multiple "interrupt" "$message" {
84 -re "$gdb_prompt " {
85 gdb_test_multiple "" "$message" {
86 -re "received signal SIGINT" {
87 pass $message
88 }
89 }
90 }
91 }
92 }
93
94 # On the MI channel, we should see the interrupt output _before_
95 # the -thread-info output.
96 with_spawn_id $mi_spawn_id {
97 mi_expect_interrupt "got MI interrupt output"
98 }
99
100 # Look for the result of our -thread-info. If input were
101 # re-enabled too soon, the thread would incorrectly show up with
102 # state="running".
103 with_spawn_id $mi_spawn_id {
104 mi_gdb_test "" "456\\^.*state=\"stopped\".*" \
105 "got -thread-info output and thread is stopped"
106 }
107 }
108
109 foreach_with_prefix sync-command {"run" "continue"} {
110 do_test ${sync-command}
111 }