step-over-trips-on-watchpoint.exp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # Copyright (C) 2014-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. # Test that when a step-over trips on a watchpoint, that watchpoint is
  15. # reported.
  16. standard_testfile
  17. set executable ${testfile}
  18. # This test verifies that a watchpoint is detected in a multithreaded
  19. # program so the test is only meaningful on a system with hardware
  20. # watchpoints.
  21. if {[skip_hw_watchpoint_tests]} {
  22. return 0
  23. }
  24. if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
  25. executable [list debug "incdir=${objdir}"]] != "" } {
  26. return -1
  27. }
  28. # The test proper. DISPLACED is true if we should try with displaced
  29. # stepping. WITH_BP is true if we should try with a thread-specific
  30. # breakpoint (for the wrong thread) right after the instruction that
  31. # triggers the watchpoint.
  32. proc do_test { displaced with_bp } {
  33. global executable
  34. global gdb_prompt
  35. global hex
  36. if ${with_bp} {
  37. set prefix "with thread-specific bp"
  38. } else {
  39. set prefix "no thread-specific bp"
  40. }
  41. with_test_prefix "displaced=$displaced: $prefix" {
  42. # Cover both stepping and non-stepping execution commands.
  43. foreach command {"step" "next" "continue" } {
  44. with_test_prefix $command {
  45. clean_restart $executable
  46. if ![runto_main] {
  47. continue
  48. }
  49. gdb_test_no_output "set displaced-stepping $displaced"
  50. set line [gdb_get_line_number "set wait-thread breakpoint here"]
  51. if { ![gdb_breakpoint $line] } {
  52. return
  53. }
  54. gdb_continue_to_breakpoint "run to wait-thread breakpoint"
  55. gdb_test "info threads" "\\\* 1 .* 2 .*" "info threads shows all threads"
  56. gdb_test_no_output "set scheduler-locking on"
  57. delete_breakpoints
  58. gdb_breakpoint [gdb_get_line_number "set breakpoint child here"]
  59. gdb_test "thread 2" "Switching to .*"
  60. gdb_continue_to_breakpoint "run to breakpoint in thread 2"
  61. set address_triggers_watch "<invalid>"
  62. set after_address_triggers_watch "<invalid>"
  63. # Let the watchpoint trigger once (with the other
  64. # thread locked), in order to find both the address of
  65. # the instruction that triggers the watchpoint and the
  66. # address of the instruction immediately after.
  67. with_test_prefix "find addresses" {
  68. gdb_test "p watch_me = 0" " = 0" "clear watch_me"
  69. gdb_test "watch watch_me" "Hardware watchpoint .*"
  70. gdb_test "continue" \
  71. "Hardware watchpoint.*: watch_me.*New value = 1.*" \
  72. "continue to watchpoint"
  73. set msg "find addresses"
  74. gdb_test_multiple "disassemble" $msg {
  75. -re " ($hex) \[^\r\n\]*\r\n=> ($hex) .*$gdb_prompt $" {
  76. set address_triggers_watch $expect_out(1,string)
  77. set after_address_triggers_watch $expect_out(2,string)
  78. pass $msg
  79. }
  80. }
  81. delete_breakpoints
  82. }
  83. gdb_test "break *$address_triggers_watch" "Breakpoint .*" \
  84. "set breakpoint at address that triggers watch"
  85. gdb_continue_to_breakpoint \
  86. "run to instruction that triggers watch in thread 2"
  87. gdb_test "p counter = 0" " = 0" "unbreak loop in thread 2"
  88. gdb_test "p watch_me = 0" " = 0" "clear watch_me"
  89. gdb_test "watch watch_me" "Hardware watchpoint .*"
  90. if ${with_bp} {
  91. gdb_test "b *$after_address_triggers_watch thread 1" \
  92. "Breakpoint .*" \
  93. "set breakpoint specific to thread 1"
  94. }
  95. # Switch back to thread 1 and disable scheduler locking.
  96. gdb_test "thread 1" "Switching to .*"
  97. gdb_test_no_output "set scheduler-locking off"
  98. # Thread 2 is still stopped at a breakpoint that needs
  99. # to be stepped over. However, the instruction that
  100. # is under the breakpoint triggers a watchpoint, which
  101. # should trap and be reported to the user.
  102. gdb_test "$command" "Hardware watchpoint.*: watch_me.*New value = 1.*"
  103. }
  104. }
  105. }
  106. }
  107. foreach displaced { "off" "on" } {
  108. if { $displaced != "off" && ![support_displaced_stepping] } {
  109. continue
  110. }
  111. foreach with_bp { 0 1 } {
  112. do_test $displaced $with_bp
  113. }
  114. }