[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / paginate-execution-startup.exp
blob134cf64ac8ef37f32b47bad840d6b539e827f2ec
1 # Copyright (C) 2014-2024 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 # A collection of tests related to pagination resulting from running
17 # execution commands directly from the command line, with "-ex".
19 standard_testfile
21 if {[build_executable "failed to prepare" $testfile $srcfile debug] == -1} {
22     return -1
25 set file_arg $binfile
26 if [is_remote host] {
27   set file_arg [remote_download host $file_arg]
30 # Returns true if the board can 'gdb -ex "start"', false otherwise.
32 proc probe_can_run_cmdline  {} {
33     global srcfile file_arg
34     global GDBFLAGS
35     global gdb_prompt
37     with_test_prefix "probe support" {
38         set test "run to main"
40         gdb_exit
41         save_vars { GDBFLAGS } {
42             append GDBFLAGS " -ex \"start\""
43             append GDBFLAGS " --args \"$file_arg\""
44             set res [gdb_spawn]
45         }
46         if { $res != 0} {
47             fail $test
48             return -1
49         }
51         set res -1
52         gdb_test_multiple "" $test {
53             -re "main .* at .*$srcfile.*$gdb_prompt $" {
54                 set res 1
55                 pass $test
56             }
57             -re "Don't know how to run.*$gdb_prompt $" {
58                 set res 0
59                 unsupported $test
60             }
61         }
63         # In case the board file wants to send further commands.
64         gdb_test_no_output "set height unlimited"
65         return $res
66     }
69 # Check that we handle pagination correctly when it triggers due to an
70 # execution command entered directly on the command line.
72 proc test_fg_execution_pagination_return {} {
73     global file_arg
74     global GDBFLAGS
75     global gdb_prompt pagination_prompt
77     with_test_prefix "return" {
78         set test "run to pagination"
80         gdb_exit
82         save_vars { GDBFLAGS  } {
83             append GDBFLAGS " -ex \"set height 2\""
84             append GDBFLAGS " -ex \"start\""
85             append GDBFLAGS " --args \"$file_arg\""
86             set res [gdb_spawn]
87         }
88         if { $res != 0} {
89             fail $test
90             return $res
91         }
93         gdb_test_multiple "" $test {
94             -re "$pagination_prompt$" {
95                 pass $test
96             }
97             -re "$gdb_prompt $" {
98                 fail $test
99             }
100         }
102         send_gdb "\n"
104         set saw_pagination_prompt 0
105         set test "send \\n to GDB"
106         gdb_test_multiple "" $test {
107             -re "$pagination_prompt$" {
108                 set saw_pagination_prompt 1
109                 send_gdb "\n"
110                 exp_continue
111             }
112             -re "$gdb_prompt $" {
113                 gdb_assert $saw_pagination_prompt $test
114             }
115         }
117         gdb_test "p 1" " = 1" "GDB accepts further input"
119         # In case the board file wants to send further commands.
120         gdb_test_no_output "set height unlimited"
121     }
124 # Check that we handle canceling pagination correctly when it triggers
125 # due to an execution command entered directly on the command line.
127 proc test_fg_execution_pagination_cancel { how } {
128     global file_arg
129     global GDBFLAGS
130     global gdb_prompt pagination_prompt
132     with_test_prefix "cancel with $how" {
133         set test "run to pagination"
135         gdb_exit
137         save_vars { GDBFLAGS } {
138             append GDBFLAGS " -ex \"set height 2\""
139             append GDBFLAGS " -ex \"start\""
140             append GDBFLAGS " --args \"$file_arg\""
141             set res [gdb_spawn]
142         }
143         if { $res != 0} {
144             fail $test
145             return $res
146         }
148         gdb_test_multiple "" $test {
149             -re "$pagination_prompt$" {
150                 pass $test
151             }
152         }
154         set test "cancel pagination"
155         if { $how == "ctrl-c" } {
156             send_gdb "\003"
157         } else {
158             send_gdb "q\n"
160         }
161         gdb_test_multiple "" $test {
162             -re "Quit\r\n$gdb_prompt $" {
163                 pass $test
164             }
165         }
167         gdb_test "p 1" " = 1" "GDB accepts further input"
169         # In case the board file wants to send further commands.
170         gdb_test_no_output "set height unlimited"
171     }
174 save_vars { INTERNAL_GDBFLAGS } {
175     set INTERNAL_GDBFLAGS [string map {"-q" ""} $INTERNAL_GDBFLAGS]
177     if {[probe_can_run_cmdline] > 0} {
178         test_fg_execution_pagination_return
179         if ![target_info exists gdb,nointerrupts] {
180             test_fg_execution_pagination_cancel "ctrl-c"
181         }
182         test_fg_execution_pagination_cancel "quit"
183     }