1 # Copyright 2003, 2007-2012 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 # This is a test for the gdb invocation option --args.
21 # Skip test if target does not support argument passing.
22 if [target_info exists noargs] {
27 set srcfile ${testfile}.c
28 set binfile ${objdir}/${subdir}/${testfile}
30 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
35 proc args_test { name arglist } {
44 gdb_reinitialize_dir $srcdir/$subdir
46 # No loading needs to be done when the target is `exec'. Some targets
47 # require that the program be loaded, however, and it doesn't hurt
52 gdb_breakpoint [gdb_get_line_number "set breakpoint here"]
53 gdb_continue_to_breakpoint "breakpoint for $name"
55 set expected_len [expr 1 + [llength $arglist]]
56 gdb_test "print argc" "\\\$$decimal = $expected_len" "argc for $name"
59 foreach arg $arglist {
60 gdb_test "print argv\[$i\]" "\\\$$decimal = $hex \"$arg\"" \
61 "argv\[$i\] for $name"
67 # Test that the --args are processed correctly.
69 set old_gdbflags $GDBFLAGS
71 set GDBFLAGS "$old_gdbflags --args $binfile 1 3"
72 args_test basic {{1} {3}}
75 # Test that the --args are processed correctly even if one of them is empty.
76 # The syntax needed is a little peculiar; DejaGNU treats the arguments as a
77 # list and expands them itself, since no shell redirection is involved.
79 set GDBFLAGS "$old_gdbflags --args $binfile 1 {} 3"
80 args_test "one empty" {{1} {} {3}}
83 # try with 2 empty args
85 set GDBFLAGS "$old_gdbflags --args $binfile 1 {} {} 3"
86 args_test "two empty" {{1} {} {} 3}
88 # Try with arguments containing literal single quotes.
90 set GDBFLAGS "$old_gdbflags --args $binfile 1 '' 3"
91 args_test "one empty (with single quotes)" {{1} {''} {3}}
93 set GDBFLAGS "$old_gdbflags --args $binfile 1 '' '' 3"
94 args_test "two empty (with single quotes)" {{1} {''} {''} {3}}
96 # try with arguments containing literal newlines.
98 set GDBFLAGS "-nx --args $binfile 1 {\n} 3"
99 args_test "one newline" {{1} {\\n} {3}}
101 set GDBFLAGS "-nx --args $binfile 1 {\n} {\n} 3"
102 args_test "two newlines" {{1} {\\n} {\\n} {3}}
104 set GDBFLAGS $old_gdbflags