]> Git Repo - binutils.git/blob - gdb/testsuite/gdb.base/args.exp
bff750dff24f76960412c73652e8a9403052bbe4
[binutils.git] / gdb / testsuite / gdb.base / args.exp
1 # Copyright 2003-2021 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 is a test for the gdb invocation option --args.
17
18 # Skip test if target does not support argument passing.
19 if [target_info exists noargs] {
20     return
21 }
22
23 # This test requires starting new inferior processes, skip it if the target
24 # board is a stub.
25 if [use_gdb_stub] {
26     return
27 }
28
29 standard_testfile
30
31 if {[build_executable $testfile.exp $testfile \
32          $srcfile {debug nowarnings}] == -1} {
33     untested "failed to compile"
34     return -1
35 }
36
37 proc args_test { name arglist } {
38     global srcdir
39     global subdir
40     global testfile
41     global hex
42     global decimal
43
44     clean_restart $testfile
45
46     runto_main
47     gdb_breakpoint [gdb_get_line_number "set breakpoint here"]
48     gdb_continue_to_breakpoint "breakpoint for $name"
49
50     set expected_len [expr 1 + [llength $arglist]]
51     gdb_test "print argc" "\\\$$decimal = $expected_len" "argc for $name"
52
53     set i 1
54     foreach arg $arglist {
55         gdb_test "print argv\[$i\]" "\\\$$decimal = $hex \"$arg\"" \
56             "argv\[$i\] for $name"
57         set i [expr $i + 1]
58     }
59 }
60
61 #
62 # Test that the --args are processed correctly.
63 #
64
65 save_vars { GDBFLAGS } {
66     set old_gdbflags $GDBFLAGS
67
68     set GDBFLAGS "$old_gdbflags --args $binfile 1 3"
69     args_test basic {{1} {3}}
70
71     #
72     # Test that the --args are processed correctly even if one of them is empty.
73     # The syntax needed is a little peculiar; DejaGNU treats the arguments as a
74     # list and expands them itself, since no shell redirection is involved.
75     #
76     set GDBFLAGS "$old_gdbflags --args $binfile 1 {} 3"
77     args_test "one empty" {{1} {} {3}}
78
79     #
80     # try with 2 empty args
81     #
82     set GDBFLAGS "$old_gdbflags --args $binfile 1 {} {} 3"
83     args_test "two empty" {{1} {} {} 3}
84
85     # Try with arguments containing literal single quotes.
86
87     set GDBFLAGS "$old_gdbflags --args $binfile 1 '' 3"
88     args_test "one empty (with single quotes)" {{1} {''} {3}}
89
90     set GDBFLAGS "$old_gdbflags --args $binfile 1 '' '' 3"
91     args_test "two empty (with single quotes)" {{1} {''} {''} {3}}
92
93     # try with arguments containing literal newlines.
94
95     set GDBFLAGS "-nx --args $binfile 1 {\n} 3"
96     args_test "one newline" {{1} {\\n} {3}}
97
98     set GDBFLAGS "-nx --args $binfile 1 {\n} {\n} 3"
99     args_test "two newlines" {{1} {\\n} {\\n} {3}}
100 }
This page took 0.019814 seconds and 2 git commands to generate.