]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/a2-run.exp
Fix typo in warning in gdb/configure
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / a2-run.exp
1 # Copyright 1988-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 # This file was written by Rob Savoye. (rob@cygnus.com)
17
18 # Can't do this test without stdio support.
19 require {!gdb_skip_stdio_test "a2run.exp"}
20
21 #
22 # test running programs
23 #
24
25 standard_testfile run.c
26
27 set flags {}
28 lappend flags debug
29 lappend_include_file flags $srcdir/lib/unbuffer_output.c
30
31 if { [prepare_for_testing "failed to prepare" $testfile $srcfile $flags] } {
32 return -1
33 }
34
35 # Run with no arguments.
36 gdb_run_cmd
37
38 set saw_usage 0
39 set saw_exit_wrapper 0
40 set saw_spurious_output 0
41
42 set test "run \"$testfile\" with no args"
43
44 # Indirect spawn id lists. Used to be able to disable the inferior
45 # and gdb's spawn_ids and regexes as soon as we see the expected
46 # output.
47 set inferior_spawn_list "$inferior_spawn_id"
48 set gdb_spawn_list "$gdb_spawn_id"
49
50 # Clear either the gdb or the inferior spawn_id list and iff
51 # afterwards we still have any spawn id in the indirect lists,
52 # continue expecting.
53 proc maybe_exp_continue {which} {
54 global inferior_spawn_list gdb_spawn_list
55
56 if {$which == "gdb"} {
57 set gdb_spawn_list ""
58 } elseif {$which == "inferior"} {
59 set inferior_spawn_list ""
60 } else {
61 error "invalid parameter"
62 }
63
64 if {$inferior_spawn_list != "" || $gdb_spawn_list != ""} {
65 exp_continue
66 }
67 }
68
69 # Note that if $inferior_spawn_id != $gdb_spawn_id the order we pick
70 # output from each spawn id is undefined.
71 set res [gdb_test_multiple "" $test {
72 -i inferior_spawn_list
73 -re "usage: factorial <number>" {
74 set saw_usage 1
75 maybe_exp_continue inferior
76 }
77 -re "EXIT code 1" {
78 set saw_exit_wrapper 1
79 maybe_exp_continue inferior
80 }
81 eof {
82 if {$inferior_spawn_id != $gdb_spawn_id} {
83 # In this case we may see the server/inferior exit before
84 # GDB's program exit output. Remove from spawn list and
85 # continue waiting.
86 maybe_exp_continue inferior
87 } else {
88 # GDB crash.
89 fail "$test (eof)"
90 }
91 }
92
93 -i gdb_spawn_list
94
95 -re "$inferior_exited_re with code 01.\r\n$gdb_prompt $" {
96 maybe_exp_continue gdb
97 }
98 -re "$inferior_exited_re with code 01.*$gdb_prompt $" {
99 set saw_spurious_output 1
100 maybe_exp_continue gdb
101 }
102
103 -re "$inferior_exited_re normally.\r\n$gdb_prompt $" {
104 # This is only considered a pass if we see the exit wrapper
105 # status.
106 maybe_exp_continue gdb
107 }
108 -re "$inferior_exited_re normally.*$gdb_prompt $" {
109 set saw_spurious_output 1
110 maybe_exp_continue gdb
111 }
112 }]
113
114 if {$res == 0} {
115 gdb_assert ${saw_usage} $test
116
117 if {$saw_exit_wrapper} {
118 set msg "$test (exit wrapper)"
119 } else {
120 set msg $test
121 }
122
123 gdb_assert !$saw_spurious_output "no spurious messages at program exit"
124
125 }
126
127 # The remaining tests don't work for targets can't take arguments...
128
129 if {[target_info exists noargs]} {
130 verbose "Skipping rest of a2-run.exp because of noargs."
131 return
132 }
133
134 # Now run with some arguments
135 setup_xfail "arm-*-coff"
136 gdb_run_cmd 5
137 gdb_test_stdio "" "120" "" "run \"$testfile\" with arg"
138
139 # Run again with same arguments.
140 gdb_run_cmd 5
141
142 setup_xfail "arm-*-coff"
143 gdb_test_stdio "" "120" "" "run \"$testfile\" again with same args"
144
145 # Use "set args" command to specify no arguments as default and run again.
146 gdb_test_no_output "set args"
147
148 gdb_run_cmd
149
150 gdb_test_stdio "" "usage: factorial <number>" "" "run after setting args to nil"
151
152 # The remaining tests pass inferior arguments through GDB, so doesn't
153 # work with stub targets, where GDB connects to debug an already started
154 # process.
155
156 if [use_gdb_stub] {
157 verbose "Skipping rest of a2-run.exp because target is a stub."
158 return
159 }
160
161 # Use "set args" command to specify an argument and run again.
162 gdb_test_no_output "set args 6"
163
164 gdb_run_cmd
165
166 setup_xfail "arm-*-coff"
167 gdb_test_stdio "" "720" "" "run \"$testfile\" again after setting args"
168
169 # GOAL: Test that shell is being used with "run". For remote debugging
170 # targets, there is no guarantee that a "shell" (whatever that is) is used.
171 if {![is_remote target]} {
172 gdb_test_stdio "run `echo 8`" \
173 "40320" "" "run \"$testfile\" with shell"
174 }