Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / argv0-symlink.exp
1 # Copyright 2013-2022 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 with_test_prefix "file symlink" {
42
43 set test "kept name"
44 set filelink "${testfile}-filelink"
45
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)"
51 return 0
52 }
53
54 clean_restart "$filelink"
55
56 if ![runto_main] {
57 untested "could not run to main"
58 return -1
59 }
60
61 gdb_test_no_output "set print repeats 10000"
62 gdb_test_no_output "set print elements 10000"
63
64 if { $has_argv0 } {
65 gdb_test {print argv[0]} "/$filelink\"" $test
66 } else {
67 unsupported $test
68 }
69
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]]
75
76 gdb_test "info inferiors" "/$lastdir/$filelink *" \
77 "$test for info inferiors"
78 }
79
80 with_test_prefix "dir symlink" {
81
82 set test "kept name"
83 set dirlink "${testfile}-dirlink"
84
85 # 'ln -sf' does not overwrite symbol link to a directory.
86 # 'remote_file host delete' uses stat (not lstat), therefore it refuses to
87 # delete a directory.
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)"
92 return 0
93 }
94
95 clean_restart "$dirlink/$filelink"
96
97 if ![runto_main] {
98 untested "could not run to main"
99 return -1
100 }
101
102 gdb_test_no_output "set print repeats 10000"
103 gdb_test_no_output "set print elements 10000"
104
105 if { $has_argv0 } {
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
111 }
112 gdb_test {print argv[0]} "/$dirlink/$filelink\"" $test
113 } else {
114 unsupported $test
115 }
116
117 gdb_test "info inferiors" "/$lastdir/$filelink *" \
118 "$test for info inferiors"
119 }
This page took 0.031457 seconds and 4 git commands to generate.