1# Copyright (C) 2009-2023 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 16# Test that a resume cancels a previously unfinished or unreported 17# single-step correctly. 18# 19# The test consists of several threads all running the same loop. 20# There is a breakpoint set in the loop, hence all threads may hit it. 21# The test then issues several "next" commands in a loop. 22# 23# scheduler-locking must be set to the default of "off". 24# 25# Here's what would happen in gdbserver: 26# 27# 1) We issue a "continue", and wait until a thread hits the 28# breakpoint. Could be any thread, but assume thread 1 hits it. 29# 30# 2) We issue a "next" --- this single-steps thread 1, and resumes all 31# other threads. 32# 33# 3) thread 2, due to scheduler-locking off, hits the breakpoint. 34# gdbserver stops all other threads by sending them SIGSTOPs. 35# 36# 4) While being stopped in step 3, thread 1 reports a SIGTRAP, that 37# corresponds to the finished single-step of step 2. gdbserver 38# leaves the SIGTRAP pending to report later. 39# 40# 5) We issue another "next" --- this requests thread 2 to 41# single-step, and all other threads to continue, including thread 42# 1. Before resuming any thread, gdbserver notices that it 43# remembers from step 4 a pending SIGTRAP to report for thread 1, 44# so reports it now. 45# 46# 6) From GDB's perpective, this SIGTRAP can't represent a finished 47# single-step, since thread 1 was not single-stepping (it was 48# continued in step 5). Neither does this SIGTRAP correspond to a 49# breakpoint hit. GDB reports to the user a spurious SIGTRAP. 50 51standard_testfile 52 53if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } { 54 return -1 55} 56 57clean_restart ${binfile} 58 59if {![runto_main]} { 60 return 0 61} 62 63gdb_breakpoint [gdb_get_line_number "insert breakpoint here"] 64gdb_continue_to_breakpoint "continue to first breakpoint hit" 65 66set test "next in multiple threads with breakpoints" 67set iterations 20 68set ok 0 69for {set i 0} {$i < $iterations} {incr i} { 70 set ok 0 71 gdb_test_multiple "next" "$test" { 72 -re " received signal SIGTRAP.*$gdb_prompt $" { 73 fail "$test (spurious SIGTRAP)" 74 } 75 -re "$gdb_prompt $" { 76 set ok 1 77 } 78 } 79 80 if { $ok == 0 } { 81 break 82 } 83} 84 85if { $ok } { 86 pass "$test" 87} 88