watchpoint-fork.exp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. # Copyright 2012-2022 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. # Test case for forgotten hw-watchpoints after fork()-off of a process.
  16. set testfile watchpoint-fork
  17. # Set DEBUG to 0 or 1 in sources
  18. set debug 0
  19. proc test {type symbol} {
  20. global debug
  21. with_test_prefix "$type" {
  22. global testfile subdir srcdir gdb_prompt
  23. set srcfile_type ${srcdir}/${subdir}/${testfile}-${type}.c
  24. # no threads
  25. with_test_prefix "singlethreaded" {
  26. set executable ${testfile}-${type}-st
  27. set srcfile_main ${testfile}-st.c
  28. if {[build_executable $testfile.exp $executable \
  29. [list $srcfile_main ${testfile}-${type}.c] \
  30. [list debug additional_flags=-D$symbol \
  31. additional_flags=-DDEBUG=$debug]] == -1} {
  32. return -1
  33. }
  34. clean_restart $executable
  35. if [target_info exists gdb,no_hardware_watchpoints] {
  36. # The software watchpoint functionality is in GDB an unrelated test.
  37. gdb_test_no_output "set can-use-hw-watchpoints 0"
  38. # Software watchpoints can be quite slow on remote targets
  39. # on this test because it ends up single-stepping through
  40. # code to initialize dynamic libraries, etc.
  41. set factor 20
  42. } else {
  43. set factor 1
  44. }
  45. gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on\\."
  46. gdb_test_no_output "set follow-fork-mode $type"
  47. gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"\\."
  48. # Testcase uses it for the `follow-fork-mode child' type.
  49. gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*"
  50. if ![runto_main] {
  51. return
  52. }
  53. gdb_test "watch var" "atchpoint \[0-9\]+: var" "set the watchpoint"
  54. # It is never hit but it should not be left over in the fork()ed-off child.
  55. if [skip_hw_breakpoint_tests] {
  56. set hbreak "break"
  57. } else {
  58. set hbreak "hbreak"
  59. }
  60. gdb_test "$hbreak marker"
  61. gdb_breakpoint "mark_exit"
  62. with_timeout_factor $factor {
  63. gdb_test "continue" \
  64. "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work"
  65. gdb_test "continue" \
  66. "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work"
  67. gdb_test "continue" \
  68. "reakpoint \[0-9\]+, marker.*" "breakpoint after the first fork"
  69. gdb_test "continue" \
  70. "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork"
  71. gdb_test "continue" \
  72. "reakpoint \[0-9\]+, marker.*" "breakpoint after the second fork"
  73. gdb_test "continue" \
  74. "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*mark_exit \\(\\);" "watchpoint after the second fork"
  75. gdb_test "continue" "Continuing\\..*\r\n(Thread .* hit )?Breakpoint \[0-9\]+, mark_exit .*" "finish"
  76. }
  77. }
  78. # threads
  79. if [target_info exists gdb,no_hardware_watchpoints] {
  80. # Watchpoint hits would get detected in unexpected threads.
  81. return
  82. }
  83. with_test_prefix "multithreaded" {
  84. set executable ${testfile}-${type}-mt
  85. set srcfile_main ${srcdir}/${subdir}/${testfile}-mt.c
  86. if { [gdb_compile_pthreads "${srcfile_main} ${srcfile_type}" \
  87. [standard_output_file ${executable}] executable \
  88. [list debug "additional_flags=-D$symbol" \
  89. "additional_flags=-DDEBUG=$debug" \
  90. "-DTHREAD"]] != "" } {
  91. untested "failed to compile"
  92. return
  93. }
  94. clean_restart $executable
  95. gdb_test_no_output "set follow-fork-mode $type"
  96. # Testcase uses it for the `follow-fork-mode child' type.
  97. gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*"
  98. if ![runto_main] {
  99. return
  100. }
  101. gdb_test "watch var" "atchpoint \[0-9\]+: var" "set the watchpoint"
  102. # It should not be left over in the fork()ed-off child.
  103. gdb_test "$hbreak marker" {reakpoint [0-9]+.*}
  104. gdb_breakpoint "mark_exit"
  105. gdb_test "continue" \
  106. "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work"
  107. gdb_test "continue" \
  108. "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work"
  109. gdb_test "continue" \
  110. "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A"
  111. gdb_test "continue" \
  112. "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B"
  113. gdb_test "continue" \
  114. "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the first fork"
  115. gdb_test "continue" \
  116. "atchpoint \[0-9\]+: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork"
  117. gdb_test "continue" \
  118. "atchpoint \[0-9\]+: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork"
  119. gdb_test "continue" \
  120. "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the second fork"
  121. gdb_test "continue" \
  122. "atchpoint \[0-9\]+: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork"
  123. gdb_test "continue" \
  124. "atchpoint \[0-9\]+: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork"
  125. gdb_test "continue" "Continuing\\..*\r\nThread .* hit Breakpoint \[0-9\]+, mark_exit .*" "finish"
  126. }
  127. }
  128. }
  129. test parent FOLLOW_PARENT
  130. # Only GNU/Linux is known to support `set follow-fork-mode child'.
  131. if [istarget "*-*-linux*"] {
  132. test child FOLLOW_CHILD
  133. } else {
  134. untested "${testfile}: child"
  135. }