dwp-symlink.exp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # Copyright 2013-2022 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. standard_testfile
  15. remote_file host delete [standard_output_file ${testfile}.dwp]
  16. if [remote_file host exists [standard_output_file ${testfile}.dwp]] {
  17. unsupported "dwp file cannot be deleted"
  18. return 0
  19. }
  20. if { [build_executable ${testfile}.exp ${testfile} ${srcfile}] == -1 } {
  21. return -1
  22. }
  23. if ![remote_file host exists [standard_output_file ${testfile}.dwp]] {
  24. unsupported "testsuite run does not produce dwp files"
  25. return 0
  26. }
  27. set thelink "${testfile}-thelink"
  28. remote_file host delete [standard_output_file ${thelink}]
  29. remote_file host delete [standard_output_file ${thelink}.dwp]
  30. # file link is only Tcl 8.4+.
  31. remote_exec host "ln -sf ${testfile} [standard_output_file $thelink]"
  32. if ![remote_file host exists [standard_output_file $thelink]] {
  33. unsupported "host does not support symbolic links (binary symlink is missing)"
  34. return 0
  35. }
  36. if [remote_file host exists [standard_output_file $thelink.dwp]] {
  37. unsupported "host does not support symbolic links (we tried to delete a file and it is still there)"
  38. return 0
  39. }
  40. clean_restart "$testfile"
  41. gdb_test "ptype main" {type = int \(int, char \*\*\)} "binary default, dwp default"
  42. clean_restart "$thelink"
  43. gdb_test "ptype main" {type = int \(int, char \*\*\)} "binary symlink, dwp default"
  44. gdb_exit
  45. remote_exec host "mv -f [standard_output_file ${testfile}.dwp] [standard_output_file ${thelink}.dwp]"
  46. if [remote_file host exists [standard_output_file ${testfile}.dwp]] {
  47. unsupported "host does not support symbolic links (binary symlink exists)"
  48. return 0
  49. }
  50. if ![remote_file host exists [standard_output_file ${thelink}.dwp]] {
  51. unsupported "host does not support symbolic links (dwp symlink is missing)"
  52. return 0
  53. }
  54. clean_restart "$testfile"
  55. # This case cannot work.
  56. gdb_test "ptype main" {type = int \(\)} "binary default, dwp at symlink"
  57. clean_restart "$thelink"
  58. gdb_test "ptype main" {type = int \(int, char \*\*\)} "binary symlink, dwp at symlink"
  59. # Verify we can still find the dwp if we change directories and we specified
  60. # a relative path for the program.
  61. # This is clean_restart, but specifying a relative path to the binary.
  62. gdb_exit
  63. gdb_start
  64. gdb_reinitialize_dir $srcdir/$subdir
  65. gdb_test "cd [file dirname [standard_output_file ${thelink}]]" \
  66. "Working directory .*"
  67. gdb_load "./${thelink}"
  68. gdb_test "cd .." "Working directory .*"
  69. gdb_test "ptype main" {type = int \(int, char \*\*\)} \
  70. "relative path, binary symlink, dwp at symlink"
  71. # Rename the dwp file back to its original name.
  72. remote_exec host "mv -f [standard_output_file ${thelink}.dwp] [standard_output_file ${testfile}.dwp]"
  73. # N.B. At this point the active gdb is in, essentially, some random directory.
  74. # Restart a new copy if you add more tests here.
  75. # Now verify that the following scenario works:
  76. # dir1/real-binary-with-random-name
  77. # dir2/real-dwp-with-random-name
  78. # dir3/symlink-to-real-binary
  79. # dir3/symlink-to-real-binary.dwp
  80. set dwp_bin_dir [standard_output_file dwp-dir1]
  81. set dwp_dwp_dir [standard_output_file dwp-dir2]
  82. set dwp_symlink_dir [standard_output_file dwp-dir3]
  83. set dwp_real_binary "dwp-abc"
  84. set dwp_real_dwp "dwp-def"
  85. set dwp_symlink_binary "dwp-symlink-binary"
  86. set dwp_symlink_dwp "${dwp_symlink_binary}.dwp"
  87. remote_exec host "rm -rf ${dwp_bin_dir}"
  88. remote_exec host "rm -rf ${dwp_dwp_dir}"
  89. remote_exec host "rm -rf ${dwp_symlink_dir}"
  90. remote_exec host "mkdir ${dwp_bin_dir}"
  91. remote_exec host "mkdir ${dwp_dwp_dir}"
  92. remote_exec host "mkdir ${dwp_symlink_dir}"
  93. remote_exec host "cp [standard_output_file $testfile] ${dwp_bin_dir}/${dwp_real_binary}"
  94. remote_exec host "cp [standard_output_file ${testfile}.dwp] ${dwp_dwp_dir}/${dwp_real_dwp}"
  95. # We don't test for failure to create the symlink here.
  96. # We assume that if the above symlinks are created ok, these will be too.
  97. remote_exec host "ln -sf ${dwp_bin_dir}/${dwp_real_binary} ${dwp_symlink_dir}/${dwp_symlink_binary}"
  98. remote_exec host "ln -sf ${dwp_dwp_dir}/${dwp_real_dwp} ${dwp_symlink_dir}/${dwp_symlink_dwp}"
  99. clean_restart "${dwp_symlink_dir}/${dwp_symlink_binary}"
  100. if ![runto_main] {
  101. return -1
  102. }
  103. gdb_test {print argv[0]} "/${dwp_symlink_binary}\"" \
  104. "separate executable/dwp symlinks"