1 # Copyright 2013-2024 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/>.
18 remote_file host delete [standard_output_file ${testfile}.dwp]
19 if [remote_file host exists [standard_output_file ${testfile}.dwp]] {
20 unsupported "dwp file cannot be deleted"
23 if { [build_executable ${testfile}.exp ${testfile} ${srcfile}] == -1 } {
26 if ![remote_file host exists [standard_output_file ${testfile}.dwp]] {
27 unsupported "testsuite run does not produce dwp files"
31 set thelink "${testfile}-thelink"
33 remote_file host delete [standard_output_file ${thelink}]
34 remote_file host delete [standard_output_file ${thelink}.dwp]
35 # file link is only Tcl 8.4+.
36 remote_exec host "ln -sf ${testfile} [standard_output_file $thelink]"
37 if ![remote_file host exists [standard_output_file $thelink]] {
38 unsupported "host does not support symbolic links (binary symlink is missing)"
41 if [remote_file host exists [standard_output_file $thelink.dwp]] {
42 unsupported "host does not support symbolic links (we tried to delete a file and it is still there)"
46 clean_restart "$testfile"
48 set main_type_re [string_to_regexp "type = int (int, char **)"]
50 gdb_test "ptype main" $main_type_re "binary default, dwp default"
52 clean_restart "$thelink"
54 gdb_test "ptype main" $main_type_re "binary symlink, dwp default"
57 remote_exec host "mv -f [standard_output_file ${testfile}.dwp] [standard_output_file ${thelink}.dwp]"
58 if [remote_file host exists [standard_output_file ${testfile}.dwp]] {
59 unsupported "host does not support symbolic links (binary symlink exists)"
62 if ![remote_file host exists [standard_output_file ${thelink}.dwp]] {
63 unsupported "host does not support symbolic links (dwp symlink is missing)"
67 clean_restart "$testfile"
69 gdb_test "ptype main" \
70 "Could not find DWO CU .*" \
71 "binary default, dwp at symlink"
73 clean_restart "$thelink"
75 gdb_test "ptype main" $main_type_re "binary symlink, dwp at symlink"
77 # Verify we can still find the dwp if we change directories and we specified
78 # a relative path for the program.
80 # This is clean_restart, but specifying a relative path to the binary.
82 gdb_test "cd [file dirname [standard_output_file ${thelink}]]" \
83 "Working directory .*" \
84 "cd to dir containing binary"
86 gdb_load "./${thelink}"
88 gdb_test "cd .." "Working directory .*"
90 gdb_test "ptype main" {type = int \(int, char \*\*\)} \
91 "relative path, binary symlink, dwp at symlink"
93 # Rename the dwp file back to its original name.
94 remote_exec host "mv -f [standard_output_file ${thelink}.dwp] [standard_output_file ${testfile}.dwp]"
96 # N.B. At this point the active gdb is in, essentially, some random directory.
97 # Restart a new copy if you add more tests here.
99 # Now verify that the following scenario works:
100 # dir1/real-binary-with-random-name
101 # dir2/real-dwp-with-random-name
102 # dir3/symlink-to-real-binary
103 # dir3/symlink-to-real-binary.dwp
105 set dwp_bin_dir [standard_output_file dwp-dir1]
106 set dwp_dwp_dir [standard_output_file dwp-dir2]
107 set dwp_symlink_dir [standard_output_file dwp-dir3]
108 set dwp_real_binary "dwp-abc"
109 set dwp_real_dwp "dwp-def"
110 set dwp_symlink_binary "dwp-symlink-binary"
111 set dwp_symlink_dwp "${dwp_symlink_binary}.dwp"
113 remote_exec host "rm -rf ${dwp_bin_dir}"
114 remote_exec host "rm -rf ${dwp_dwp_dir}"
115 remote_exec host "rm -rf ${dwp_symlink_dir}"
116 remote_exec host "mkdir ${dwp_bin_dir}"
117 remote_exec host "mkdir ${dwp_dwp_dir}"
118 remote_exec host "mkdir ${dwp_symlink_dir}"
119 remote_exec host "cp [standard_output_file $testfile] ${dwp_bin_dir}/${dwp_real_binary}"
120 remote_exec host "cp [standard_output_file ${testfile}.dwp] ${dwp_dwp_dir}/${dwp_real_dwp}"
121 # We don't test for failure to create the symlink here.
122 # We assume that if the above symlinks are created ok, these will be too.
123 remote_exec host "ln -sf ${dwp_bin_dir}/${dwp_real_binary} ${dwp_symlink_dir}/${dwp_symlink_binary}"
124 remote_exec host "ln -sf ${dwp_dwp_dir}/${dwp_real_dwp} ${dwp_symlink_dir}/${dwp_symlink_dwp}"
126 clean_restart "${dwp_symlink_dir}/${dwp_symlink_binary}"
132 gdb_test {print argv[0]} "/${dwp_symlink_binary}\"" \
133 "separate executable/dwp symlinks"