Commit | Line | Data |
---|---|---|
3666a048 | 1 | # Copyright 2003-2021 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 | ||
75d04512 SM |
26 | # This test requires starting new inferior processes, skip it if the target |
27 | # board is a stub. | |
28 | if [use_gdb_stub] { | |
29 | return | |
30 | } | |
31 | ||
a64d2530 | 32 | standard_testfile |
8f9ab801 | 33 | |
a64d2530 TT |
34 | if {[build_executable $testfile.exp $testfile \ |
35 | $srcfile {debug nowarnings}] == -1} { | |
5b362f04 | 36 | untested "failed to compile" |
b60f0898 | 37 | return -1 |
8f9ab801 EZ |
38 | } |
39 | ||
ae018d1a DJ |
40 | proc args_test { name arglist } { |
41 | global srcdir | |
42 | global subdir | |
a64d2530 | 43 | global testfile |
ae018d1a DJ |
44 | global hex |
45 | global decimal | |
46 | ||
a64d2530 | 47 | clean_restart $testfile |
ae018d1a DJ |
48 | |
49 | runto_main | |
50 | gdb_breakpoint [gdb_get_line_number "set breakpoint here"] | |
51 | gdb_continue_to_breakpoint "breakpoint for $name" | |
52 | ||
53 | set expected_len [expr 1 + [llength $arglist]] | |
54 | gdb_test "print argc" "\\\$$decimal = $expected_len" "argc for $name" | |
55 | ||
56 | set i 1 | |
57 | foreach arg $arglist { | |
58 | gdb_test "print argv\[$i\]" "\\\$$decimal = $hex \"$arg\"" \ | |
59 | "argv\[$i\] for $name" | |
60 | set i [expr $i + 1] | |
61 | } | |
62 | } | |
63 | ||
8f9ab801 EZ |
64 | # |
65 | # Test that the --args are processed correctly. | |
66 | # | |
c362c33a | 67 | set old_gdbflags $GDBFLAGS |
6b8ce727 DE |
68 | |
69 | set GDBFLAGS "$old_gdbflags --args $binfile 1 3" | |
ae018d1a | 70 | args_test basic {{1} {3}} |
8f9ab801 EZ |
71 | |
72 | # | |
73 | # Test that the --args are processed correctly even if one of them is empty. | |
ae018d1a DJ |
74 | # The syntax needed is a little peculiar; DejaGNU treats the arguments as a |
75 | # list and expands them itself, since no shell redirection is involved. | |
8f9ab801 | 76 | # |
6b8ce727 | 77 | set GDBFLAGS "$old_gdbflags --args $binfile 1 {} 3" |
ae018d1a | 78 | args_test "one empty" {{1} {} {3}} |
8f9ab801 EZ |
79 | |
80 | # | |
81 | # try with 2 empty args | |
82 | # | |
6b8ce727 | 83 | set GDBFLAGS "$old_gdbflags --args $binfile 1 {} {} 3" |
ae018d1a DJ |
84 | args_test "two empty" {{1} {} {} 3} |
85 | ||
86 | # Try with arguments containing literal single quotes. | |
87 | ||
6b8ce727 | 88 | set GDBFLAGS "$old_gdbflags --args $binfile 1 '' 3" |
6f439c36 | 89 | args_test "one empty (with single quotes)" {{1} {''} {3}} |
ae018d1a | 90 | |
6b8ce727 | 91 | set GDBFLAGS "$old_gdbflags --args $binfile 1 '' '' 3" |
6f439c36 | 92 | args_test "two empty (with single quotes)" {{1} {''} {''} {3}} |
8f9ab801 | 93 | |
c2226152 AS |
94 | # try with arguments containing literal newlines. |
95 | ||
96 | set GDBFLAGS "-nx --args $binfile 1 {\n} 3" | |
97 | args_test "one newline" {{1} {\\n} {3}} | |
98 | ||
99 | set GDBFLAGS "-nx --args $binfile 1 {\n} {\n} 3" | |
100 | args_test "two newlines" {{1} {\\n} {\\n} {3}} | |
101 | ||
c362c33a | 102 | set GDBFLAGS $old_gdbflags |