1 # Copyright 2020 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 # Test running an inferior with arguments.
18 # This does not work on boards that don't support inferior arguments.
19 if [target_info exists noargs] then {
20 verbose "skipping gdb.base/inferior-args.exp because of noargs"
26 if {[build_executable "failed to prepare" $testfile $srcfile debug] == -1} {
30 proc do_test { method } {
33 # The second arg is an empty string on purpose.
34 set inferior_args { "first arg" "" "third-arg" }
36 clean_restart $binfile
38 if { $method == "start" } {
39 # The start command does not make sense for a stub.
40 if { [use_gdb_stub] } {
44 if { [gdb_start_cmd $inferior_args] < 0 } {
45 fail "could not issue start command"
49 # Consume up to the GDB prompt after the stop.
50 gdb_test "" ".*main.*" "stop at main"
52 } elseif { $method == "starti" } {
53 # The starti command does not make sense for a stub.
54 if { [use_gdb_stub] } {
58 if { [gdb_starti_cmd $inferior_args] < 0 } {
59 fail "could not issue start command"
63 # Consume up to the GDB prompt after the stop.
64 gdb_test "" "" "stop at first instruction"
66 # Put a breakpoint and continue until main.
67 if { ![gdb_breakpoint "main" message] } {
68 fail "could not set breakpoint on main"
72 if { [gdb_continue "main"] != 0 } {
73 fail "could not continue to main"
77 } elseif { $method == "run" } {
78 if { ![gdb_breakpoint "main" message] } {
79 fail "could not set breakpoint on main"
83 # The run command does not make sense for a stub, but GDB_RUN_CMD
84 # does the right thing when the target is a stub (start the stub,
85 # connect to it, and "continue").
87 # This allows us to test arguments passed on the gdbserver command
89 if { [gdb_run_cmd $inferior_args] < 0 } {
94 # Consume up to the GDB prompt after the stop.
95 gdb_test "" ".*main.*" "stop at main"
97 } elseif { $method == "set args" } {
98 # Using "set args" does not make sense with a stub.
99 if { [use_gdb_stub] } {
103 gdb_test_no_output "set args $inferior_args"
105 if { ![runto_main] } {
106 fail "could not run to main"
111 error "invalid method $method"
114 # Now that we are stopped at main, inspect argc/argv.
115 gdb_test "print argc" " = 4"
116 gdb_test "print argv\[0\]" " = $hex \".*\""
117 gdb_test "print argv\[1\]" " = $hex \"first arg\""
118 gdb_test "print argv\[2\]" " = $hex \"\""
119 gdb_test "print argv\[3\]" " = $hex \"third-arg\""
122 foreach_with_prefix method { "start" "starti" "run" "set args" } {