1 # Copyright
2011-2024 Free Software Foundation
, Inc.
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
5 # the Free Software Foundation
; either version
3 of the License
, or
6 #
(at your option
) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this
program.
If not
, see
<http
://www.gnu.org
/licenses
/>.
16 # Test that the
"shell", "!", "|" and "pipe" commands work.
18 load_lib completion
-support.exp
23 gdb_test
"shell echo foo" "foo"
25 gdb_test
"! echo foo" "foo"
26 gdb_test
"!echo foo" "foo"
28 # Convenience variables with
shell command.
29 gdb_test_no_output
"! exit 0"
30 gdb_test
"p \$_shell_exitcode" " = 0" "shell success exitcode"
31 gdb_test
"p \$_shell_exitsignal" " = void" "shell success exitsignal"
33 gdb_test_no_output
"! exit 1"
34 gdb_test
"p \$_shell_exitcode" " = 1" "shell fail exitcode"
35 gdb_test
"p \$_shell_exitsignal" " = void" "shell fail exitsignal"
37 # This test will not work when the
shell is CMD.EXE.
38 if { ! [ishost
*-*-mingw
*] } {
39 gdb_test_no_output
"! kill -2 $$"
40 gdb_test
"p \$_shell_exitcode" " = void" "shell interrupt exitcode"
41 gdb_test
"p \$_shell_exitsignal" " = 2" "shell interrupt exitsignal"
44 # Test the $_shell convenience function.
46 with_test_prefix
"\$_shell convenience function" {
47 # Simple commands
, check the result code.
48 gdb_test
"p \$_shell(\"true\")" " = 0"
49 gdb_test
"p \$_shell(\"false\")" " = 1"
51 # Test command with arguments.
52 gdb_test
"p \$_shell(\"echo foo\")" "foo\r\n\\$${decimal} = 0"
54 # Check the type of the result.
55 gdb_test
"ptype \$_shell(\"true\")" "type = int"
57 # Test passing a non
-literal string as command
name.
58 gdb_test
"p \$cmd = \"echo bar\"" " = \"echo bar\""
59 gdb_test
"p \$_shell(\$cmd)" "bar\r\n\\$${decimal} = 0"
61 # Test executing a non
-existing command. The result is
62 #
shell-dependent
, but most
(all?
) POSIX
-like shells
return 127 in
64 gdb_test
"p \$_shell(\"non-existing-command-foo-bar-qux\")" " = 127"
66 gdb_test
"p \$_shell" \
67 " = <internal function _shell>"
68 gdb_test
"ptype \$_shell" \
69 "type = <internal function>"
71 # Test error scenarios.
72 gdb_test
"p \$_shell()" \
73 "You must provide one argument for \\\$_shell\\\."
74 gdb_test
"p \$_shell(\"a\", \"b\")" \
75 "You must provide one argument for \\\$_shell\\\."
76 gdb_test
"p \$_shell(1)" \
77 "Argument must be a string\\\."
80 #
Define the user command
"foo", used to test "pipe" command.
81 gdb_test_multiple
"define foo" "define foo" {
99 gdb_test
"pipe foo | wc -l" "3" "simple pipe"
100 gdb_test
"pipe foo brol| wc -l" "4" "simple pipe with arg"
101 gdb_test
"pipe foo truc2 | grep truc | wc -l" "2" "double pipe"
103 gdb_test
"| foo truc2 | grep truc | wc -l" "2" "double pipe, pipe char"
104 gdb_test
"|foo|grep truc|wc -l" "1" "no space around pipe char"
106 gdb_test
"echo coucou\\n" "coucou" "echo coucou"
107 gdb_test
"||wc -l" "1" "repeat previous command"
109 gdb_test
"| -d ! echo this contains a | character\\n ! sed -e \"s/|/PIPE/\"" \
110 "this contains a PIPE character" "alternate 1char delim"
112 gdb_test
"|-d ! echo this contains a | character\\n!sed -e \"s/|/PIPE/\"" \
113 "this contains a PIPE character" "alternate 1char delim, no space"
115 gdb_test
"| -d !!! echo this contains a | character\\n !!! sed -e \"s/|/PIPE/\"" \
116 "this contains a PIPE character" "alternate 3char delim"
118 gdb_test
"|-d !!! echo this contains a | character\\n!!!sed -e \"s/|/PIPE/\"" \
119 "this contains a PIPE character" "alternate 3char delim, no space"
121 # Convenience variables with pipe command.
122 gdb_test
"|p 123| exit 0" ""
123 gdb_test
"p \$_shell_exitcode" " = 0" "pipe success exitcode"
124 gdb_test
"p \$_shell_exitsignal" " = void" "pipe success exitsignal"
126 gdb_test
"|p 123| exit 1" ""
127 gdb_test
"p \$_shell_exitcode" " = 1" "pipe fail exitcode"
128 gdb_test
"p \$_shell_exitsignal" " = void" "pipe fail exitsignal"
130 # This test will not work when the
shell is CMD.EXE.
131 if { ! [ishost
*-*-mingw
*] } {
132 gdb_test
"|p 123| kill -2 $$" ""
133 gdb_test
"p \$_shell_exitcode" " = void" "pipe interrupt exitcode"
134 gdb_test
"p \$_shell_exitsignal" " = 2" "pipe interrupt exitsignal"
137 # Error handling verifications.
138 gdb_test
"|" "Missing COMMAND" "all missing"
139 gdb_test
"|-d" "-d requires an argument" "-d value missing"
140 gdb_test
"|-d " "-d requires an argument" "-d spaces value missing"
141 gdb_test
"| echo coucou" \
142 "Missing delimiter before SHELL_COMMAND" \
143 "| delimiter missing"
144 gdb_test
"|-d DELIM echo coucou" \
145 "Missing delimiter before SHELL_COMMAND" \
146 "DELIM delimiter missing"
147 gdb_test
"|echo coucou|" \
148 "Missing SHELL_COMMAND" \
149 "SHELL_COMMAND missing"
150 gdb_test
"|-d ! echo coucou !" \
151 "Missing SHELL_COMMAND" \
152 "SHELL_COMMAND missing with delimiter"
153 gdb_test
"|-d! echo coucou ! wc" \
154 "Missing delimiter before SHELL_COMMAND" \
155 "delimiter missing due to missing space"
159 test_gdb_complete_unique \
163 # Note that unlike
"pipe", "|" doesn't require a space. This checks
164 # that completion behaves that way too.
165 foreach cmd
{"pipe " "| " "|"} {
166 test_gdb_completion_offers_commands
"$cmd"
168 # There
's only one option.
169 test_gdb_complete_unique \
173 # Cannot complete "-d"'s
argument.
174 test_gdb_complete_none
"${cmd}-d "
175 test_gdb_complete_none
"${cmd}-d main"
177 # Check completing a GDB command
, with and without
-d.
178 test_gdb_complete_unique \
179 "${cmd}maint set test-se" \
180 "${cmd}maint set test-settings"
181 test_gdb_complete_unique \
182 "${cmd}-d XXX maint set test-se" \
183 "${cmd}-d XXX maint set test-settings"
185 # Check that GDB doesn
't try to complete the shell command.
186 test_gdb_complete_none \
189 # Same, while making sure that the completer understands "-d".
190 test_gdb_complete_unique \
191 "${cmd}-d XXX maint set" \
192 "${cmd}-d XXX maint set"
193 test_gdb_complete_none \
194 "${cmd}-d set maint set"
195 test_gdb_complete_none \
196 "${cmd}-d set maint set "