Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 2013-2022 Free Software Foundation, Inc. |
1f0c4988 JK |
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 | ||
2ea1a07a SL |
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 | ||
1f0c4988 JK |
33 | standard_testfile |
34 | ||
673dc4a0 YQ |
35 | set has_argv0 [gdb_has_argv0] |
36 | ||
1f0c4988 JK |
37 | if { [build_executable ${testfile}.exp ${testfile} ${srcfile}] == -1 } { |
38 | return -1 | |
39 | } | |
40 | ||
657dcee4 | 41 | with_test_prefix "file symlink" { |
1f0c4988 | 42 | |
657dcee4 TV |
43 | set test "kept name" |
44 | set filelink "${testfile}-filelink" | |
1f0c4988 | 45 | |
657dcee4 TV |
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 | } | |
218c2655 | 53 | |
657dcee4 | 54 | clean_restart "$filelink" |
24890efd | 55 | |
657dcee4 TV |
56 | if ![runto_main] { |
57 | untested "could not run to main" | |
58 | return -1 | |
59 | } | |
24890efd | 60 | |
657dcee4 TV |
61 | gdb_test_no_output "set print repeats 10000" |
62 | gdb_test_no_output "set print elements 10000" | |
1f0c4988 | 63 | |
657dcee4 TV |
64 | if { $has_argv0 } { |
65 | gdb_test {print argv[0]} "/$filelink\"" $test | |
66 | } else { | |
67 | unsupported $test | |
68 | } | |
1f0c4988 | 69 | |
657dcee4 TV |
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]] | |
1f0c4988 | 75 | |
657dcee4 TV |
76 | gdb_test "info inferiors" "/$lastdir/$filelink *" \ |
77 | "$test for info inferiors" | |
1f0c4988 JK |
78 | } |
79 | ||
657dcee4 | 80 | with_test_prefix "dir symlink" { |
1f0c4988 | 81 | |
657dcee4 TV |
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 | } | |
1f0c4988 | 94 | |
657dcee4 | 95 | clean_restart "$dirlink/$filelink" |
218c2655 | 96 | |
657dcee4 TV |
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 | |
673dc4a0 | 115 | } |
673dc4a0 | 116 | |
657dcee4 TV |
117 | gdb_test "info inferiors" "/$lastdir/$filelink *" \ |
118 | "$test for info inferiors" | |
119 | } |