Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 2003-2016 Free Software Foundation, Inc. |
8f9ab801 EZ |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
8f9ab801 EZ |
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 | |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
8f9ab801 | 15 | |
8f9ab801 EZ |
16 | # This is a test for the gdb invocation option --args. |
17 | ||
8f9ab801 EZ |
18 | |
19 | global GDBFLAGS | |
20 | ||
19ea9e73 MS |
21 | # Skip test if target does not support argument passing. |
22 | if [target_info exists noargs] { | |
4ec70201 | 23 | return |
19ea9e73 MS |
24 | } |
25 | ||
a64d2530 | 26 | standard_testfile |
8f9ab801 | 27 | |
a64d2530 TT |
28 | if {[build_executable $testfile.exp $testfile \ |
29 | $srcfile {debug nowarnings}] == -1} { | |
30 | untested $testfile.exp | |
b60f0898 | 31 | return -1 |
8f9ab801 EZ |
32 | } |
33 | ||
ae018d1a DJ |
34 | proc args_test { name arglist } { |
35 | global srcdir | |
36 | global subdir | |
a64d2530 | 37 | global testfile |
ae018d1a DJ |
38 | global hex |
39 | global decimal | |
40 | ||
a64d2530 | 41 | clean_restart $testfile |
ae018d1a DJ |
42 | |
43 | runto_main | |
44 | gdb_breakpoint [gdb_get_line_number "set breakpoint here"] | |
45 | gdb_continue_to_breakpoint "breakpoint for $name" | |
46 | ||
47 | set expected_len [expr 1 + [llength $arglist]] | |
48 | gdb_test "print argc" "\\\$$decimal = $expected_len" "argc for $name" | |
49 | ||
50 | set i 1 | |
51 | foreach arg $arglist { | |
52 | gdb_test "print argv\[$i\]" "\\\$$decimal = $hex \"$arg\"" \ | |
53 | "argv\[$i\] for $name" | |
54 | set i [expr $i + 1] | |
55 | } | |
56 | } | |
57 | ||
8f9ab801 EZ |
58 | # |
59 | # Test that the --args are processed correctly. | |
60 | # | |
c362c33a | 61 | set old_gdbflags $GDBFLAGS |
6b8ce727 DE |
62 | |
63 | set GDBFLAGS "$old_gdbflags --args $binfile 1 3" | |
ae018d1a | 64 | args_test basic {{1} {3}} |
8f9ab801 EZ |
65 | |
66 | # | |
67 | # Test that the --args are processed correctly even if one of them is empty. | |
ae018d1a DJ |
68 | # The syntax needed is a little peculiar; DejaGNU treats the arguments as a |
69 | # list and expands them itself, since no shell redirection is involved. | |
8f9ab801 | 70 | # |
6b8ce727 | 71 | set GDBFLAGS "$old_gdbflags --args $binfile 1 {} 3" |
ae018d1a | 72 | args_test "one empty" {{1} {} {3}} |
8f9ab801 EZ |
73 | |
74 | # | |
75 | # try with 2 empty args | |
76 | # | |
6b8ce727 | 77 | set GDBFLAGS "$old_gdbflags --args $binfile 1 {} {} 3" |
ae018d1a DJ |
78 | args_test "two empty" {{1} {} {} 3} |
79 | ||
80 | # Try with arguments containing literal single quotes. | |
81 | ||
6b8ce727 | 82 | set GDBFLAGS "$old_gdbflags --args $binfile 1 '' 3" |
6f439c36 | 83 | args_test "one empty (with single quotes)" {{1} {''} {3}} |
ae018d1a | 84 | |
6b8ce727 | 85 | set GDBFLAGS "$old_gdbflags --args $binfile 1 '' '' 3" |
6f439c36 | 86 | args_test "two empty (with single quotes)" {{1} {''} {''} {3}} |
8f9ab801 | 87 | |
c2226152 AS |
88 | # try with arguments containing literal newlines. |
89 | ||
90 | set GDBFLAGS "-nx --args $binfile 1 {\n} 3" | |
91 | args_test "one newline" {{1} {\\n} {3}} | |
92 | ||
93 | set GDBFLAGS "-nx --args $binfile 1 {\n} {\n} 3" | |
94 | args_test "two newlines" {{1} {\\n} {\\n} {3}} | |
95 | ||
c362c33a | 96 | set GDBFLAGS $old_gdbflags |