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