1 # Copyright 2013-2022 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 with_test_prefix "file symlink" {
44 set filelink "${testfile}-filelink"
46 remote_file host delete [standard_output_file $filelink]
47 set status [remote_exec host \
48 "ln -sf ${testfile} [standard_output_file $filelink]"]
49 if {[lindex $status 0] != 0} {
50 unsupported "$test (host does not support symbolic links)"
54 clean_restart "$filelink"
57 untested "could not run to main"
61 gdb_test_no_output "set print repeats 10000"
62 gdb_test_no_output "set print elements 10000"
65 gdb_test {print argv[0]} "/$filelink\"" $test
70 # For a link named /PATH/TO/DIR/LINK, we want to check the output
71 # against "/DIR/LINK", but computed in a way that doesn't make
72 # assumptions about the test directory layout.
73 set full_filelink [standard_output_file $filelink]
74 set lastdir [file tail [file dirname $full_filelink]]
76 gdb_test "info inferiors" "/$lastdir/$filelink *" \
77 "$test for info inferiors"
80 with_test_prefix "dir symlink" {
83 set dirlink "${testfile}-dirlink"
85 # 'ln -sf' does not overwrite symbol link to a directory.
86 # 'remote_file host delete' uses stat (not lstat), therefore it refuses to
88 remote_exec host "rm -f [standard_output_file $dirlink]"
89 set status [remote_exec host "ln -sf . [standard_output_file $dirlink]"]
90 if {[lindex $status 0] != 0} {
91 unsupported "$test (host does not support symbolic links)"
95 clean_restart "$dirlink/$filelink"
98 untested "could not run to main"
102 gdb_test_no_output "set print repeats 10000"
103 gdb_test_no_output "set print elements 10000"
106 # gdbserver in extended-remote mode does not have this issue.
107 # Plain remote does, however.
108 if { [target_info gdb_protocol] != "extended-remote"
109 || ![target_is_gdbserver] } {
110 setup_kfail "*-*-*" gdb/15934
112 gdb_test {print argv[0]} "/$dirlink/$filelink\"" $test
117 gdb_test "info inferiors" "/$lastdir/$filelink *" \
118 "$test for info inferiors"