1# Copyright 2013-2016 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 16standard_testfile 17set executable ${testfile} 18 19if { [gdb_compile_pthreads \ 20 "${srcdir}/${subdir}/${srcfile}" \ 21 "${binfile}" \ 22 executable {debug}] != "" } { 23 untested "Couldn't compile test program." 24 return -1 25} 26 27clean_restart $executable 28 29# Start the second thread. 30if ![runto start] { 31 return -1 32} 33 34# Go back to the main thread, and leave it in the loop, where we're 35# reasonably sure we don't have 'conditional jmp $pc'-like 36# instructions. We wouldn't be able to detect whether a stepi makes 37# progress over those. 38gdb_test_no_output "set scheduler-locking on" 39gdb_test "thread 1" "Switching to .*" 40gdb_breakpoint $srcfile:[gdb_get_line_number "set break 2 here"] 41gdb_continue_to_breakpoint "loop" ".* set break 2 here .*" 42 43# Now back to thread 2, and let it queue a signal in thread 1. 44gdb_test "thread 2" "Switching to .*" 45gdb_breakpoint $srcfile:[gdb_get_line_number "set break here"] 46gdb_continue_to_breakpoint "after pthread_kill" ".* set break here .*" 47 48# We're now ready to stepi thread 1. It should immediately dequeue 49# the signal. 50gdb_test "thread 1" "Switching to .*" "thread 1 again" 51 52# No longer need these. 53delete_breakpoints 54 55# Turn on infrun debugging, so we can tell whether the signal is 56# really dequeued and that GDB sees it. 57gdb_test_no_output "set debug infrun 1" 58 59# Make sure the target backend reports the signal to GDB core. Some 60# backends (like Linux) skip reporting a signal if set to 61# pass/nostop/noprint, resuming the thread immediately instead. 62gdb_test "handle SIGCHLD print" 63 64# Helper to extract the current PC. PREFIX is used to make each call 65# have its own unique test name. 66 67proc get_pc { prefix } { 68 with_test_prefix "$prefix" { 69 return [get_hexadecimal_valueof "\$pc" ""] 70 } 71} 72 73set prev_addr [get_pc "before stepi"] 74if {$prev_addr == ""} { 75 return 76} 77 78# True if we saw the infrun path we want to test be exercised. 79set seen 0 80 81set test "stepi" 82if {[gdb_test_multiple "stepi" "$test" { 83 -re "infrun: random signal" { 84 set seen 1 85 exp_continue 86 } 87 -re "$gdb_prompt $" { 88 } 89}] != 0} { 90 return 91} 92 93if {$seen} { 94 pass "$test" 95} else { 96 fail "$test (no random signal)" 97} 98 99set addr [get_pc "after stepi"] 100if {$addr == ""} { 101 return 102} 103 104set test "stepi interfered by signal makes progress" 105if {$addr == $prev_addr} { 106 fail "$test" 107} else { 108 pass "$test" 109} 110