signal-delivered-right-thread.exp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. standard_testfile
  15. if [target_info exists gdb,nosignals] {
  16. verbose "Skipping ${testfile}.exp because of nosignals."
  17. return -1
  18. }
  19. if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
  20. executable { debug }] != "" } {
  21. return -1
  22. }
  23. # Run test proper. COMMAND indicates whether to resume the inferior
  24. # with "signal 0" or "continue".
  25. proc test { command } {
  26. global srcfile binfile
  27. with_test_prefix "$command" {
  28. clean_restart ${binfile}
  29. if ![runto_main] then {
  30. return 0
  31. }
  32. gdb_test "handle SIGUSR1 stop print pass"
  33. gdb_test "continue" "Thread 2 .*received signal SIGUSR1.*" "stop with SIGUSR1"
  34. set pattern "\\\* 2\[ \t\]+Thread.*"
  35. gdb_test "info threads" $pattern "thread 2 intercepted signal"
  36. gdb_test "break handler" "Breakpoint .* at .*$srcfile.*"
  37. gdb_test "thread 1" "Switching to thread 1.*"
  38. if { $command == "continue" } {
  39. gdb_test "continue" "handler .*"
  40. } elseif { $command == "signal 0" } {
  41. set queried 0
  42. set test "signal 0 queries"
  43. gdb_test_multiple "signal 0" $test {
  44. -re "stopped with.*stopped with.*Continue anyway.*y or n. $" {
  45. fail "$test (multiple threads noted)"
  46. set queried 1
  47. }
  48. -re "stopped with signal SIGUSR1.*\r\nContinuing .*still deliver .*Continue anyway.*y or n. $" {
  49. pass $test
  50. set queried 1
  51. }
  52. -re "Continue anyway.*y or n. $" {
  53. fail "$test (no threads noted)"
  54. set queried 1
  55. }
  56. }
  57. if {$queried} {
  58. gdb_test "y" "handler .*" "signal is delivered"
  59. }
  60. }
  61. gdb_test "info threads" $pattern "thread 2 got the signal"
  62. }
  63. }
  64. foreach command {"continue" "signal 0"} {
  65. test $command
  66. }