1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# This testcase is part of GDB, the GNU debugger.
# Copyright 2017-2024 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This test doesn't make sense on native-gdbserver.
require !use_gdb_stub
# There's no easy way to set environment variables on remote targets
# (via dejagnu) yet.
require {!is_remote target}
standard_testfile
if { [build_executable "failed to prepare" $testfile $srcfile debug] } {
return -1
}
set unique_file [standard_output_file "unique-file.unique-extension"]
set unique_file_dir [standard_output_file ""]
run_on_host \
"touch OUTPUT_DIR/unique-file.unique-extension" \
"touch" "$unique_file"
# Initial setup for simple test (wildcard expansion, variable substitution).
proc initial_setup_simple { startup_with_shell run_args } {
global hex decimal binfile unique_file
clean_restart $binfile
gdb_test_no_output "set startup-with-shell $startup_with_shell"
gdb_test_no_output "set print characters unlimited"
gdb_test_no_output "set args $run_args" \
"set args \$run_args"
return [runto_main]
}
# Start GDB, set the inferior arguments to ARGS, and then run to main.
# Once at main, read the first argument from the inferior and compare
# it to ON_RE if startup-with-shell is on, otherwise compare to
# OFF_RE.
#
# If PROBLEMATIC_ON is true then when startup-with-shell is on we
# expect the comparison to fail, so setup an xfail.
#
# TESTNAME is a string used in the test names.
proc run_test { args on_re off_re testname { problematic_on false } } {
foreach startup_with_shell { "on" "off" } {
with_test_prefix "$testname, startup_with_shell: ${startup_with_shell}" {
if {![initial_setup_simple $startup_with_shell $args]} {
return -1
}
if { $startup_with_shell } {
set re $on_re
set problematic $problematic_on
} else {
set re $off_re
set problematic false
}
if { $problematic } {
setup_xfail "*-*-*" gdb/28392
}
gdb_test "print argv\[1\]" "\\\$$::decimal = $::hex $re" $testname
}
}
}
# This is like the run_test proc except that RE is used as the
# expected argument regexp when startup-with-shell is both on and off.
# For the other arguments, see run_test.
proc run_test_same { args re testname } {
run_test $args $re $re $testname
}
# The regexp to match a single '\' character.
set bs "\\\\"
# Are we using 'remote' or 'extended-remote' protocol?
set is_remote_p [gdb_protocol_is_remote]
## Run the actual tests
run_test "$unique_file_dir/*.unique-extension" \
"\"$unique_file\"" \
"\"$unique_file_dir/\\\*\.unique-extension\"" \
"arg is glob" \
$is_remote_p
run_test_same "$unique_file_dir/\\*.unique-extension" \
"\"$unique_file_dir/\\\*\.unique-extension\"" \
"arg is escaped glob"
save_vars { env(TEST) } {
set env(TEST) "1234"
run_test "\$TEST" \
"\"1234\"" \
"\"\\\$TEST\"" \
"arg is shell variable" \
$is_remote_p
run_test_same "\\\$TEST" \
"\"\\\$TEST\"" \
"arg is escaped shell variable"
}
run_test_same "\"\\a\"" \
"\"${bs}${bs}a\"" \
"retain backslash in double quote arg"
run_test_same "'\\a'" \
"\"${bs}${bs}a\"" \
"retain backslash in single quote arg"
run_test_same "\"\\\$\"" \
"\"\\\$\"" \
"'\$' can be escaped in double quote arg"
run_test_same "'\\\$'" \
"\"${bs}${bs}\\\$\"" \
"'\$' is not escaped in single quote arg"
run_test_same "\"\\`\"" \
"\"\\`\"" \
"'`' can be escaped in double quote arg"
run_test_same "'\\`'" \
"\"${bs}${bs}`\"" \
"'`' is not escaped in single quote arg"
run_test_same "\"\\\"\"" \
"\"${bs}\"\"" \
"'\"' can be escaped in double quote arg"
run_test_same "'\\\"'" \
"\"${bs}${bs}${bs}\"\"" \
"'\"' is not escaped in single quote arg"
run_test_same "\"\\\\\"" \
"\"${bs}${bs}\"" \
"'\\' can be escaped in double quote arg"
run_test_same "'\\\\'" \
"\"${bs}${bs}${bs}${bs}\"" \
"'\\' is not escaped in single quote arg"
|