local-watch-wrong-thread.exp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # This testcase is part of GDB, the GNU debugger.
  2. # Copyright 2009-2022 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.
  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. # This test verifies that a local watchpoint isn't deleted when a
  16. # thread other than the thread the local watchpoint was set in stops
  17. # for a breakpoint.
  18. if {[skip_hw_watchpoint_multi_tests]} {
  19. return 0
  20. }
  21. standard_testfile
  22. if {[gdb_compile_pthreads \
  23. "${srcdir}/${subdir}/${srcfile}" \
  24. "${binfile}" executable {debug} ] != "" } {
  25. return -1
  26. }
  27. clean_restart ${binfile}
  28. gdb_test_no_output "set can-use-hw-watchpoints 1" ""
  29. if ![runto_main] then {
  30. return
  31. }
  32. set inc_line_1 [gdb_get_line_number "Loop increment 1"]
  33. set inc_line_2 [gdb_get_line_number "Loop increment 2"]
  34. set bkpt_here [gdb_get_line_number "set breakpoint here"]
  35. # Run to the loop within thread_function0, so we can set our local
  36. # watchpoint.
  37. gdb_test "break ${srcfile}:${inc_line_1}" \
  38. "Breakpoint 2 at .*: file .*${srcfile}, line .*" \
  39. "breakpoint on thread_function0"
  40. gdb_test "continue" \
  41. ".*Breakpoint 2.*thread_function0.*" \
  42. "continue to thread_function0"
  43. delete_breakpoints
  44. # Set the local watchpoint, and confirm that it traps as expected.
  45. gdb_test "watch *myp" \
  46. "Hardware watchpoint 3\: \\*myp.*" \
  47. "set local watchpoint on *myp"
  48. gdb_test "continue" \
  49. "Hardware watchpoint.*Old value.*New value.*thread_function0.*" \
  50. "local watchpoint triggers"
  51. delete_breakpoints
  52. # Recreate the watchpoint, but this time with a condition we know
  53. # won't trigger. This is so the watchpoint is inserted, and the
  54. # target reports events, but GDB doesn't stop for them. We want to
  55. # hit the breakpoints on the other thread, and make sure this
  56. # watchpoint isn't deleted then.
  57. gdb_test "watch *myp if trigger != 0" \
  58. "Hardware watchpoint 4\: \\*myp.*" \
  59. "set local watchpoint on *myp, with false conditional"
  60. # Run to a breakpoint on a different thread. The previous local
  61. # watchpoint should not be deleted with the standard 'the program has
  62. # left the block in which its expression is valid', because the
  63. # thread_function0 thread should still be running in the loop.
  64. gdb_test "break ${srcfile}:${inc_line_2}" \
  65. "Breakpoint 5 at .*: file .*${srcfile}, line .*" \
  66. "breakpoint on the other thread"
  67. gdb_test "continue" \
  68. "Breakpoint 5, thread_function1.*" \
  69. "the other thread stopped on breakpoint"
  70. # Delete the new breakpoint, we don't need it anymore.
  71. gdb_test_no_output "delete 5" ""
  72. # Check if the local watchpoint hasn't been deleted (is still listed).
  73. # This is simpler to check than expecting 'the program has left ...',
  74. # and, is immune to string changes in that warning.
  75. gdb_test "info breakpoints" \
  76. ".*4.*hw watchpoint.*keep.*y.*\\*myp.*" \
  77. "local watchpoint is still in breakpoint list"
  78. # Make the watchpoint condition eval true.
  79. gdb_test_no_output "set trigger=1" "let local watchpoint trigger"
  80. gdb_test "continue" \
  81. "Hardware watchpoint.*Old value.*New value.*thread_function0.*" \
  82. "local watchpoint still triggers"
  83. # Confirm that the local watchpoint is indeed deleted when
  84. # thread_function0 returns.
  85. gdb_test_no_output "set *myp=0" "let thread_function0 return"
  86. gdb_test "break ${srcfile}:${bkpt_here}" \
  87. "Breakpoint 6 at .*: file .*${srcfile}, line .*" \
  88. "breakpoint on thread_function0's caller"
  89. gdb_test "continue" \
  90. ".*Watchpoint.*deleted.*" \
  91. "local watchpoint automatically deleted"