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".
21 if {[build_executable "failed to prepare" $testfile $srcfile debug] == -1} {
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
37 with_test_prefix "probe support" {
38 set test "run to main"
41 save_vars { GDBFLAGS } {
42 append GDBFLAGS " -ex \"start\""
43 append GDBFLAGS " --args \"$file_arg\""
52 gdb_test_multiple "" $test {
53 -re "main .* at .*$srcfile.*$gdb_prompt $" {
57 -re "Don't know how to run.*$gdb_prompt $" {
63 # In case the board file wants to send further commands.
64 gdb_test_no_output "set height unlimited"
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 {} {
75 global gdb_prompt pagination_prompt
77 with_test_prefix "return" {
78 set test "run to pagination"
82 save_vars { GDBFLAGS } {
83 append GDBFLAGS " -ex \"set height 2\""
84 append GDBFLAGS " -ex \"start\""
85 append GDBFLAGS " --args \"$file_arg\""
93 gdb_test_multiple "" $test {
94 -re "$pagination_prompt$" {
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
112 -re "$gdb_prompt $" {
113 gdb_assert $saw_pagination_prompt $test
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"
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 } {
130 global gdb_prompt pagination_prompt
132 with_test_prefix "cancel with $how" {
133 set test "run to pagination"
137 save_vars { GDBFLAGS } {
138 append GDBFLAGS " -ex \"set height 2\""
139 append GDBFLAGS " -ex \"start\""
140 append GDBFLAGS " --args \"$file_arg\""
148 gdb_test_multiple "" $test {
149 -re "$pagination_prompt$" {
154 set test "cancel pagination"
155 if { $how == "ctrl-c" } {
161 gdb_test_multiple "" $test {
162 -re "Quit\r\n$gdb_prompt $" {
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"
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"
182 test_fg_execution_pagination_cancel "quit"