signal-while-stepping-over-bp-other-thread.exp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Copyright (C) 2011-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 GDB doesn't inadvertently resume the stepped thread when a
  15. # signal arrives while stepping over the breakpoint that last caused a
  16. # stop, when the thread that hit that breakpoint is not the stepped
  17. # thread.
  18. # Test relies on checking gdb debug output. Do not run if gdb debug is
  19. # enabled as any debug will be redirected to the log.
  20. if [gdb_debug_enabled] {
  21. continue
  22. }
  23. standard_testfile
  24. set executable ${testfile}
  25. if [target_info exists gdb,nosignals] {
  26. verbose "Skipping ${testfile}.exp because of nosignals."
  27. return -1
  28. }
  29. if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
  30. executable [list debug "incdir=${objdir}"]] != "" } {
  31. return -1
  32. }
  33. proc get_value {var test} {
  34. global expect_out
  35. global gdb_prompt
  36. global decimal
  37. set value -1
  38. gdb_test_multiple "print $var" "$test" {
  39. -re ".*= ($decimal).*\r\n$gdb_prompt $" {
  40. set value $expect_out(1,string)
  41. pass "$test"
  42. }
  43. }
  44. return ${value}
  45. }
  46. # Start with a fresh gdb.
  47. clean_restart $executable
  48. if ![runto_main] {
  49. return -1
  50. }
  51. gdb_breakpoint [gdb_get_line_number "set wait-thread-2 breakpoint here"]
  52. gdb_continue_to_breakpoint "run to wait-thread-2 breakpoint"
  53. gdb_test "info threads" "" "info threads with thread 2"
  54. gdb_breakpoint [gdb_get_line_number "set wait-thread-3 breakpoint here"]
  55. gdb_continue_to_breakpoint "run to breakpoint"
  56. gdb_test "info threads" "" "info threads with thread 3"
  57. gdb_test "set scheduler-locking on"
  58. gdb_breakpoint [gdb_get_line_number "set breakpoint child_two here"]
  59. gdb_breakpoint [gdb_get_line_number "set breakpoint child_one here"]
  60. gdb_test "thread 3" "" "switch to thread 3 to run to its breakpoint"
  61. gdb_continue_to_breakpoint "run to breakpoint in thread 3"
  62. gdb_test "thread 2" "" "switch to thread 2 to run to its breakpoint"
  63. gdb_continue_to_breakpoint "run to breakpoint in thread 2"
  64. delete_breakpoints
  65. gdb_test "b *\$pc" "" "set breakpoint to be stepped over"
  66. # Make sure the first loop breaks without hitting the breakpoint
  67. # again.
  68. gdb_test "p *myp = 0" " = 0" "force loop break in thread 2"
  69. # We want "print" to make sure the target reports the signal to the
  70. # core.
  71. gdb_test "handle SIGUSR1 print nostop pass" "" ""
  72. gdb_test "thread 1" "" "switch to thread 1 to queue signal in thread 2"
  73. gdb_test "next 2" "pthread_join .*" "queue signal in thread 2"
  74. gdb_test "thread 3" "" "switch to thread 3 for stepping"
  75. set my_number [get_value "my_number" "get my_number"]
  76. set cnt_before [get_value "args\[$my_number\]" "get count before step"]
  77. gdb_test "set scheduler-locking off"
  78. # Make sure we're exercising the paths we want to.
  79. gdb_test "set debug infrun 1"
  80. set test "step"
  81. gdb_test_sequence $test $test -prompt "$gdb_prompt \\\[infrun\\\] fetch_inferior_event: exit\r\n$" {
  82. "need to step-over"
  83. "resume_1: step=1,"
  84. "signal arrived while stepping over breakpoint"
  85. "stepped to a different line"
  86. "callme"
  87. }
  88. set cnt_after [get_value "args\[$my_number\]" "get count after step"]
  89. # Test that GDB doesn't inadvertently resume the stepped thread when a
  90. # signal arrives while stepping over a breakpoint in another thread.
  91. gdb_assert { $cnt_before + 1 == $cnt_after } "stepped thread under control"