]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/argv0-symlink.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / argv0-symlink.exp
1 # Copyright 2013-2021 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
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.
22
23 if { ![isnative] } {
24 unsupported "argv0-symlink.exp not supported on non-native target"
25 return -1
26 }
27
28 if { [is_remote host] } {
29 unsupported "argv0-symlink.exp not supported on remote host"
30 return -1
31 }
32
33 standard_testfile
34
35 set has_argv0 [gdb_has_argv0]
36
37 if { [build_executable ${testfile}.exp ${testfile} ${srcfile}] == -1 } {
38 return -1
39 }
40
41 set test "kept file symbolic link name"
42 set filelink "${testfile}-filelink"
43
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)"
48 return 0
49 }
50
51 clean_restart "$filelink"
52
53 if ![runto_main] {
54 untested "could not run to main"
55 return -1
56 }
57
58 gdb_test_no_output "set print repeats 10000"
59 gdb_test_no_output "set print elements 10000"
60
61 if { $has_argv0 } {
62 gdb_test {print argv[0]} "/$filelink\"" $test
63 } else {
64 unsupported $test
65 }
66
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]]
72
73 gdb_test "info inferiors" "/$lastdir/$filelink *" "$test for info inferiors"
74
75
76 set test "kept directory symbolic link name"
77 set dirlink "${testfile}-dirlink"
78
79 # 'ln -sf' does not overwrite symbol link to a directory.
80 # 'remote_file host delete' uses stat (not lstat), therefore it refuses to
81 # delete a directory.
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)"
86 return 0
87 }
88
89 clean_restart "$dirlink/$filelink"
90
91 if ![runto_main] {
92 untested "could not run to main"
93 return -1
94 }
95
96 gdb_test_no_output "set print repeats 10000"
97 gdb_test_no_output "set print elements 10000"
98
99 if { $has_argv0 } {
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
104 }
105 gdb_test {print argv[0]} "/$dirlink/$filelink\"" $test
106 } else {
107 unsupported $test
108 }
109
110 gdb_test "info inferiors" "/$lastdir/$filelink *" "$test for info inferiors"