Home | History | Annotate | Line # | Download | only in gdb.dwarf2
dwp-symlink.exp revision 1.1.1.9
      1 # Copyright 2013-2024 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 standard_testfile
     17 
     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"
     21     return 0
     22 }
     23 if { [build_executable ${testfile}.exp ${testfile} ${srcfile}] == -1 } {
     24     return -1
     25 }
     26 if ![remote_file host exists [standard_output_file ${testfile}.dwp]] {
     27     unsupported "testsuite run does not produce dwp files"
     28     return 0
     29 }
     30 
     31 set thelink "${testfile}-thelink"
     32 
     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)"
     39     return 0
     40 }
     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)"
     43     return 0
     44 }
     45 
     46 clean_restart "$testfile"
     47 
     48 set main_type_re [string_to_regexp "type = int (int, char **)"]
     49 
     50 gdb_test "ptype main" $main_type_re "binary default, dwp default"
     51 
     52 clean_restart "$thelink"
     53 
     54 gdb_test "ptype main" $main_type_re "binary symlink, dwp default"
     55 
     56 gdb_exit
     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)"
     60     return 0
     61 }
     62 if ![remote_file host exists [standard_output_file ${thelink}.dwp]] {
     63     unsupported "host does not support symbolic links (dwp symlink is missing)"
     64     return 0
     65 }
     66 
     67 clean_restart "$testfile"
     68 
     69 gdb_test "ptype main" \
     70     "Could not find DWO CU .*" \
     71     "binary default, dwp at symlink"
     72 
     73 clean_restart "$thelink"
     74 
     75 gdb_test "ptype main" $main_type_re "binary symlink, dwp at symlink"
     76 
     77 # Verify we can still find the dwp if we change directories and we specified
     78 # a relative path for the program.
     79 
     80 # This is clean_restart, but specifying a relative path to the binary.
     81 clean_restart
     82 gdb_test "cd [file dirname [standard_output_file ${thelink}]]" \
     83     "Working directory .*" \
     84     "cd to dir containing binary"
     85 
     86 gdb_load "./${thelink}"
     87 
     88 gdb_test "cd .." "Working directory .*"
     89 
     90 gdb_test "ptype main" {type = int \(int, char \*\*\)} \
     91     "relative path, binary symlink, dwp at symlink"
     92 
     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]"
     95 
     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.
     98 
     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
    104 
    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"
    112 
    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}"
    125 
    126 clean_restart "${dwp_symlink_dir}/${dwp_symlink_binary}"
    127 
    128 if ![runto_main] {
    129     return -1
    130 }
    131 
    132 gdb_test {print argv[0]} "/${dwp_symlink_binary}\"" \
    133     "separate executable/dwp symlinks"
    134