1 # Copyright 2013-2020 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 # This testcase was originally for PR gdb/15415, a problem with the "run"
17 # command expanding symlinks in the name of the program being run.
18 # This test uses pathnames on build to create symbolic links on host and
19 # expects the test program running on target to see those symbolic links.
20 # Therefore, it can't work reliably on anything other than configurations
21 # where build/host/target are all the same.
24 unsupported "argv0-symlink.exp not supported on non-native target"
28 if { [is_remote host] } {
29 unsupported "argv0-symlink.exp not supported on remote host"
35 set has_argv0 [gdb_has_argv0]
37 if { [build_executable ${testfile}.exp ${testfile} ${srcfile}] == -1 } {
41 set test "kept file symbolic link name"
42 set filelink "${testfile}-filelink"
44 remote_file host delete [standard_output_file $filelink]
45 set status [remote_exec host "ln -sf ${testfile} [standard_output_file $filelink]"]
46 if {[lindex $status 0] != 0} {
47 unsupported "$test (host does not support symbolic links)"
51 clean_restart "$filelink"
54 untested "could not run to main"
58 gdb_test_no_output "set print repeats 10000"
59 gdb_test_no_output "set print elements 10000"
62 gdb_test {print argv[0]} "/$filelink\"" $test
67 # For a link named /PATH/TO/DIR/LINK, we want to check the output
68 # against "/DIR/LINK", but computed in a way that doesn't make
69 # assumptions about the test directory layout.
70 set full_filelink [standard_output_file $filelink]
71 set lastdir [file tail [file dirname $full_filelink]]
73 gdb_test "info inferiors" "/$lastdir/$filelink *" "$test for info inferiors"
76 set test "kept directory symbolic link name"
77 set dirlink "${testfile}-dirlink"
79 # 'ln -sf' does not overwrite symbol link to a directory.
80 # 'remote_file host delete' uses stat (not lstat), therefore it refuses to
82 remote_exec host "rm -f [standard_output_file $dirlink]"
83 set status [remote_exec host "ln -sf . [standard_output_file $dirlink]"]
84 if {[lindex $status 0] != 0} {
85 unsupported "$test (host does not support symbolic links)"
89 clean_restart "$dirlink/$filelink"
92 untested "could not run to main"
96 gdb_test_no_output "set print repeats 10000"
97 gdb_test_no_output "set print elements 10000"
100 # gdbserver in extended-remote mode does not have this issue.
101 # Plain remote does, however.
102 if {[target_info gdb_protocol] != "extended-remote" || ![target_is_gdbserver]} {
103 setup_kfail "*-*-*" gdb/15934
105 gdb_test {print argv[0]} "/$dirlink/$filelink\"" $test
110 gdb_test "info inferiors" "/$lastdir/$filelink *" "$test for info inferiors"