Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / args.exp
CommitLineData
88b9d363 1# Copyright 2003-2022 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
19ea9e73
MS
18# Skip test if target does not support argument passing.
19if [target_info exists noargs] {
4ec70201 20 return
19ea9e73
MS
21}
22
75d04512
SM
23# This test requires starting new inferior processes, skip it if the target
24# board is a stub.
25if [use_gdb_stub] {
26 return
27}
28
a64d2530 29standard_testfile
8f9ab801 30
a64d2530
TT
31if {[build_executable $testfile.exp $testfile \
32 $srcfile {debug nowarnings}] == -1} {
5b362f04 33 untested "failed to compile"
b60f0898 34 return -1
8f9ab801
EZ
35}
36
18263be7
SM
37# If SINGLE_QUOTES_NEWLINE_KFAIL true, arguments made of exactly '' or a
38# newline character will fail, so kfail those tests.
39
40proc args_test { name arglist {single_quotes_newline_kfail false}} {
ae018d1a
DJ
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 {
18263be7
SM
58 if { $single_quotes_newline_kfail
59 && ($arg == {''} || $arg == {\\n}) } {
60 setup_kfail "gdb/27989" "*-*-*"
61 }
ae018d1a
DJ
62 gdb_test "print argv\[$i\]" "\\\$$decimal = $hex \"$arg\"" \
63 "argv\[$i\] for $name"
64 set i [expr $i + 1]
65 }
66}
67
8f9ab801
EZ
68#
69# Test that the --args are processed correctly.
70#
6b8ce727 71
18b5aade
SM
72save_vars { GDBFLAGS } {
73 set old_gdbflags $GDBFLAGS
8f9ab801 74
18263be7
SM
75 # Single quotes and newlines are not well handled by the extended-remote
76 # target: https://sourceware.org/bugzilla/show_bug.cgi?id=27989
77 set single_quotes_newline_kfail \
78 [expr { [target_info exists gdb_protocol] \
79 && [target_info gdb_protocol] == "extended-remote" }]
80
18b5aade
SM
81 set GDBFLAGS "$old_gdbflags --args $binfile 1 3"
82 args_test basic {{1} {3}}
8f9ab801 83
18b5aade
SM
84 #
85 # Test that the --args are processed correctly even if one of them is empty.
86 # The syntax needed is a little peculiar; DejaGNU treats the arguments as a
87 # list and expands them itself, since no shell redirection is involved.
88 #
89 set GDBFLAGS "$old_gdbflags --args $binfile 1 {} 3"
90 args_test "one empty" {{1} {} {3}}
ae018d1a 91
18b5aade
SM
92 #
93 # try with 2 empty args
94 #
95 set GDBFLAGS "$old_gdbflags --args $binfile 1 {} {} 3"
96 args_test "two empty" {{1} {} {} 3}
ae018d1a 97
18b5aade 98 # Try with arguments containing literal single quotes.
ae018d1a 99
18b5aade 100 set GDBFLAGS "$old_gdbflags --args $binfile 1 '' 3"
18263be7 101 args_test "one empty with single quotes" {{1} {''} {3}} $single_quotes_newline_kfail
8f9ab801 102
18b5aade 103 set GDBFLAGS "$old_gdbflags --args $binfile 1 '' '' 3"
18263be7 104 args_test "two empty with single quotes" {{1} {''} {''} {3}} $single_quotes_newline_kfail
c2226152 105
18b5aade 106 # try with arguments containing literal newlines.
c2226152 107
c4ddc1da 108 set GDBFLAGS "$old_gdbflags --args $binfile 1 {\n} 3"
18263be7 109 args_test "one newline" {{1} {\\n} {3}} $single_quotes_newline_kfail
c2226152 110
c4ddc1da 111 set GDBFLAGS "$old_gdbflags --args $binfile 1 {\n} {\n} 3"
18263be7 112 args_test "two newlines" {{1} {\\n} {\\n} {3}} $single_quotes_newline_kfail
18b5aade 113}
This page took 2.354259 seconds and 4 git commands to generate.