Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / paginate-execution-startup.exp
blob4c52d0f73c213de50b16eb472500e96a44ef8702
1 # Copyright (C) 2014-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 # 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 global GDBFLAGS
31 set saved_gdbflags $GDBFLAGS
33 # Returns true if the board can 'gdb -ex "start"', false otherwise.
35 proc probe_can_run_cmdline {} {
36 global srcfile file_arg
37 global saved_gdbflags GDBFLAGS
38 global gdb_prompt
40 set GDBFLAGS $saved_gdbflags
41 append GDBFLAGS " -ex \"set height 0\""
42 append GDBFLAGS " -ex \"start\""
43 append GDBFLAGS " --args \"$file_arg\""
45 with_test_prefix "probe support" {
46 set test "run to main"
48 gdb_exit
49 set res [gdb_spawn]
50 if { $res != 0} {
51 fail $test
52 return -1
55 set res -1
56 gdb_test_multiple "" $test {
57 -re "main .* at .*$srcfile.*$gdb_prompt $" {
58 set res 1
59 pass $test
61 -re "Don't know how to run.*$gdb_prompt $" {
62 set res 0
63 unsupported $test
67 # In case the board file wants to send further commands.
68 gdb_test_no_output "set height unlimited"
69 return $res
73 # Check that we handle pagination correctly when it triggers due to an
74 # execution command entered directly on the command line.
76 proc test_fg_execution_pagination_return {} {
77 global file_arg
78 global saved_gdbflags GDBFLAGS
79 global gdb_prompt pagination_prompt
81 set GDBFLAGS $saved_gdbflags
82 append GDBFLAGS " -ex \"set height 2\""
83 append GDBFLAGS " -ex \"start\""
84 append GDBFLAGS " --args \"$file_arg\""
86 with_test_prefix "return" {
87 set test "run to pagination"
89 gdb_exit
90 set res [gdb_spawn]
91 if { $res != 0} {
92 fail $test
93 return $res
95 gdb_test_multiple "" $test {
96 -re "$pagination_prompt$" {
97 pass $test
99 -re "$gdb_prompt $" {
100 fail $test
104 send_gdb "\n"
106 set saw_pagination_prompt 0
107 set test "send \\n to GDB"
108 gdb_test_multiple "" $test {
109 -re "$pagination_prompt$" {
110 set saw_pagination_prompt 1
111 send_gdb "\n"
112 exp_continue
114 -re "$gdb_prompt $" {
115 gdb_assert $saw_pagination_prompt $test
119 gdb_test "p 1" " = 1" "GDB accepts further input"
121 # In case the board file wants to send further commands.
122 gdb_test_no_output "set height unlimited"
126 # Check that we handle canceling pagination correctly when it triggers
127 # due to an execution command entered directly on the command line.
129 proc test_fg_execution_pagination_cancel { how } {
130 global file_arg
131 global saved_gdbflags GDBFLAGS
132 global gdb_prompt pagination_prompt
134 set GDBFLAGS $saved_gdbflags
136 append GDBFLAGS " -ex \"set height 2\""
137 append GDBFLAGS " -ex \"start\""
138 append GDBFLAGS " --args \"$file_arg\""
140 with_test_prefix "cancel with $how" {
141 set test "run to pagination"
143 gdb_exit
144 set res [gdb_spawn]
145 if { $res != 0} {
146 fail $test
147 return $res
149 gdb_test_multiple "" $test {
150 -re "$pagination_prompt$" {
151 pass $test
155 set test "cancel pagination"
156 if { $how == "ctrl-c" } {
157 send_gdb "\003"
158 } else {
159 send_gdb "q\n"
162 gdb_test_multiple "" $test {
163 -re "Quit\r\n$gdb_prompt $" {
164 pass $test
168 gdb_test "p 1" " = 1" "GDB accepts further input"
170 # In case the board file wants to send further commands.
171 gdb_test_no_output "set height unlimited"
175 save_vars { INTERNAL_GDBFLAGS } {
176 set INTERNAL_GDBFLAGS [string map {"-q" ""} $INTERNAL_GDBFLAGS]
178 if {[probe_can_run_cmdline] > 0} {
179 test_fg_execution_pagination_return
180 if ![target_info exists gdb,nointerrupts] {
181 test_fg_execution_pagination_cancel "ctrl-c"
183 test_fg_execution_pagination_cancel "quit"
187 set GDBFLAGS $saved_gdbflags