Commit | Line | Data |
---|---|---|
4c38e0a4 | 1 | # Copyright 2003, 2007, 2008, 2009, 2010 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 | ||
18 | if $tracelevel then { | |
19 | strace $tracelevel | |
20 | } | |
21 | ||
22 | ||
23 | global GDBFLAGS | |
24 | ||
19ea9e73 MS |
25 | # Skip test if target does not support argument passing. |
26 | if [target_info exists noargs] { | |
27 | return; | |
28 | } | |
29 | ||
8f9ab801 EZ |
30 | set testfile "args" |
31 | set srcfile ${testfile}.c | |
32 | set binfile ${objdir}/${subdir}/${testfile} | |
33 | ||
fc91c6c2 | 34 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } { |
b60f0898 JB |
35 | untested args.exp |
36 | return -1 | |
8f9ab801 EZ |
37 | } |
38 | ||
ae018d1a DJ |
39 | proc args_test { name arglist } { |
40 | global srcdir | |
41 | global subdir | |
42 | global binfile | |
43 | global hex | |
44 | global decimal | |
45 | ||
46 | gdb_exit | |
47 | gdb_start | |
48 | gdb_reinitialize_dir $srcdir/$subdir | |
49 | ||
50 | # No loading needs to be done when the target is `exec'. Some targets | |
51 | # require that the program be loaded, however, and it doesn't hurt | |
52 | # for `exec'. | |
53 | gdb_load $binfile | |
54 | ||
55 | runto_main | |
56 | gdb_breakpoint [gdb_get_line_number "set breakpoint here"] | |
57 | gdb_continue_to_breakpoint "breakpoint for $name" | |
58 | ||
59 | set expected_len [expr 1 + [llength $arglist]] | |
60 | gdb_test "print argc" "\\\$$decimal = $expected_len" "argc for $name" | |
61 | ||
62 | set i 1 | |
63 | foreach arg $arglist { | |
64 | gdb_test "print argv\[$i\]" "\\\$$decimal = $hex \"$arg\"" \ | |
65 | "argv\[$i\] for $name" | |
66 | set i [expr $i + 1] | |
67 | } | |
68 | } | |
69 | ||
8f9ab801 EZ |
70 | # |
71 | # Test that the --args are processed correctly. | |
72 | # | |
c362c33a | 73 | set old_gdbflags $GDBFLAGS |
6b8ce727 DE |
74 | |
75 | set GDBFLAGS "$old_gdbflags --args $binfile 1 3" | |
ae018d1a | 76 | args_test basic {{1} {3}} |
8f9ab801 EZ |
77 | |
78 | # | |
79 | # Test that the --args are processed correctly even if one of them is empty. | |
ae018d1a DJ |
80 | # The syntax needed is a little peculiar; DejaGNU treats the arguments as a |
81 | # list and expands them itself, since no shell redirection is involved. | |
8f9ab801 | 82 | # |
6b8ce727 | 83 | set GDBFLAGS "$old_gdbflags --args $binfile 1 {} 3" |
ae018d1a | 84 | args_test "one empty" {{1} {} {3}} |
8f9ab801 EZ |
85 | |
86 | # | |
87 | # try with 2 empty args | |
88 | # | |
6b8ce727 | 89 | set GDBFLAGS "$old_gdbflags --args $binfile 1 {} {} 3" |
ae018d1a DJ |
90 | args_test "two empty" {{1} {} {} 3} |
91 | ||
92 | # Try with arguments containing literal single quotes. | |
93 | ||
6b8ce727 | 94 | set GDBFLAGS "$old_gdbflags --args $binfile 1 '' 3" |
6f439c36 | 95 | args_test "one empty (with single quotes)" {{1} {''} {3}} |
ae018d1a | 96 | |
6b8ce727 | 97 | set GDBFLAGS "$old_gdbflags --args $binfile 1 '' '' 3" |
6f439c36 | 98 | args_test "two empty (with single quotes)" {{1} {''} {''} {3}} |
8f9ab801 | 99 | |
c2226152 AS |
100 | # try with arguments containing literal newlines. |
101 | ||
102 | set GDBFLAGS "-nx --args $binfile 1 {\n} 3" | |
103 | args_test "one newline" {{1} {\\n} {3}} | |
104 | ||
105 | set GDBFLAGS "-nx --args $binfile 1 {\n} {\n} 3" | |
106 | args_test "two newlines" {{1} {\\n} {\\n} {3}} | |
107 | ||
c362c33a | 108 | set GDBFLAGS $old_gdbflags |