Implement proper "startup-with-shell" support on gdbserver
[external/binutils.git] / gdb / testsuite / gdb.base / startup-with-shell.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2017 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 # This test doesn't make sense on native-gdbserver.
19 if { [use_gdb_stub] } {
20     untested "not supported"
21     return
22 }
23
24 # There's no easy way to set environment variables on remote targets
25 # (via dejagnu) yet.
26 if { [is_remote target] } {
27     untested "remote board"
28     return
29 }
30
31 standard_testfile
32
33 if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } {
34     return -1
35 }
36
37 set unique_file [standard_output_file "unique-file.unique-extension"]
38 set unique_file_dir [standard_output_file ""]
39
40 run_on_host "touch $unique_file" "touch" "$unique_file"
41
42 # Initial setup for simple test (wildcard expansion, variable substitution).
43
44 proc initial_setup_simple { startup_with_shell run_args } {
45     global hex decimal binfile unique_file
46
47     clean_restart $binfile
48
49     gdb_test_no_output "set startup-with-shell $startup_with_shell"
50
51     gdb_test_no_output "set args $run_args"
52
53     set test "inferior started"
54     if { [runto_main] } {
55         pass $test
56     } else {
57         fail $test
58     }
59 }
60
61 ## Run the actual tests
62
63 with_test_prefix "startup_with_shell = on; run_args = *.unique-extension" {
64     initial_setup_simple "on" "$unique_file_dir/*.unique-extension"
65     gdb_test "print argv\[1\]" "\\\$$decimal = $hex \"$unique_file\"" \
66         "first argument expanded"
67 }
68
69 with_test_prefix "startup_with_shell = off; run_args = *.unique-extension" {
70     initial_setup_simple "off" "$unique_file_dir/*.unique-extension"
71     gdb_test "print argv\[1\]" "\\\$$decimal = $hex \"$unique_file_dir/\\\*\.unique-extension\"" \
72         "first argument not expanded"
73 }
74
75 with_test_prefix "startup_with_shell = on; run_args = \$TEST" {
76     set env(TEST) "1234"
77     initial_setup_simple "on" "\$TEST"
78     gdb_test "print argv\[1\]" "\\\$$decimal = $hex \"1234\"" \
79         "testing first argument"
80     unset env(TEST)
81 }
82
83 with_test_prefix "startup_with_shell = off; run_args = \$TEST" {
84     set env(TEST) "1234"
85     initial_setup_simple "off" "\$TEST"
86     gdb_test "print argv\[1\]" "\\\$$decimal = $hex \"\\\$TEST\"" \
87         "testing first argument"
88     unset env(TEST)
89 }