next-fork-other-thread.exp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # Copyright 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 doing a "next" on a thread during which forks or vforks happen in other
  15. # threads.
  16. standard_testfile
  17. # Line where to stop the main thread.
  18. set break_here_line [gdb_get_line_number "break here"]
  19. # Build executables, one for each fork flavor.
  20. foreach_with_prefix fork_func {fork vfork} {
  21. set opts [list debug pthreads additional_flags=-DFORK_FUNC=${fork_func}]
  22. if { [build_executable "failed to prepare" \
  23. ${testfile}-${fork_func} ${srcfile} $opts] } {
  24. return
  25. }
  26. }
  27. # If testing against GDBserver, consume all it its output.
  28. proc drain_gdbserver_output { } {
  29. if { [info exists ::server_spawn_id] } {
  30. gdb_test_multiple "" "" {
  31. -i "$::server_spawn_id"
  32. -timeout 0
  33. -re ".+" {
  34. exp_continue
  35. }
  36. }
  37. }
  38. }
  39. # Run the test with the given parameters:
  40. #
  41. # - FORK_FUNC: fork flavor, "fork" or "vfork".
  42. # - TARGET-NON-STOP: "maintenance set target-non-stop" value, "auto", "on" or
  43. # "off".
  44. # - NON-STOP: "set non-stop" value, "on" or "off".
  45. # - DISPLACED-STEPPING: "set displaced-stepping" value, "auto", "on" or "off".
  46. proc do_test { fork_func target-non-stop non-stop displaced-stepping } {
  47. save_vars { ::GDBFLAGS } {
  48. append ::GDBFLAGS " -ex \"maintenance set target-non-stop ${target-non-stop}\""
  49. append ::GDBFLAGS " -ex \"set non-stop ${non-stop}\""
  50. clean_restart ${::binfile}-${fork_func}
  51. }
  52. gdb_test_no_output "set displaced-stepping ${displaced-stepping}"
  53. if { ![runto_main] } {
  54. return
  55. }
  56. # The "Detached after (v)fork" messages get in the way in non-stop, disable
  57. # them.
  58. gdb_test_no_output "set print inferior-events off"
  59. # Advance the next-ing thread to the point where we'll execute the nexts.
  60. # Leave the breakpoint in: it will force GDB to step over it while next-ing,
  61. # which exercises some additional code paths.
  62. gdb_test "break $::break_here_line" "Breakpoint $::decimal at $::hex.*"
  63. gdb_test "continue" "hit Breakpoint $::decimal, main.*"
  64. # Next an arbitrary number of times over the lines of the loop.
  65. #
  66. # It is useful to bump this number to a larger value (e.g. 200) to stress
  67. # test more, but it makes the test case run for considerably longer. If
  68. # you increase the number of loops, you might want to adjust the alarm
  69. # time in the .c file accordingly.
  70. for { set i 0 } { $i < 20 } { incr i } {
  71. # If testing against GDBserver, the forking threads cause a lot of
  72. # "Detaching from process XYZ" messages to appear. If we don't consume
  73. # that output, GDBserver eventually blocks on a full stderr. Drain it
  74. # once every loop. It may not be needed for 20 iterations, but it's
  75. # needed if you increase to 200 iterations.
  76. drain_gdbserver_output
  77. with_test_prefix "i=$i" {
  78. if { [gdb_test "next" "other line.*" "next to other line"] != 0 } {
  79. return
  80. }
  81. if { [gdb_test "next" "for loop.*" "next to for loop"] != 0 } {
  82. return
  83. }
  84. if { [gdb_test "next" "break here.*" "next to break here"] != 0} {
  85. return
  86. }
  87. }
  88. }
  89. }
  90. foreach_with_prefix fork_func {fork vfork} {
  91. foreach_with_prefix target-non-stop {auto on off} {
  92. foreach_with_prefix non-stop {off on} {
  93. foreach_with_prefix displaced-stepping {auto on off} {
  94. do_test ${fork_func} ${target-non-stop} ${non-stop} ${displaced-stepping}
  95. }
  96. }
  97. }
  98. }