]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/attach-into-signal.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / attach-into-signal.exp
CommitLineData
1d506c26 1# Copyright 2008-2024 Free Software Foundation, Inc.
a0ef4274
DJ
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# This test was created by modifying attach-stopped.exp.
17# This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
18
19# This test only works on Linux
604f757b 20require !use_gdb_stub isnative
52c0551e
TT
21require {!is_remote host}
22require {istarget *-linux*}
a0ef4274 23
0efbbabc 24standard_testfile
cc51a170
PA
25set executable_nothr ${testfile}-nothr
26set executable_thr ${testfile}-thr
a0ef4274 27
cc51a170 28proc corefunc { threadtype executable } {
a0ef4274 29 global srcfile
a0ef4274
DJ
30 global srcdir
31 global subdir
32 global gdb_prompt
cc51a170 33
13fc3e3c
PA
34 with_test_prefix "$threadtype" {
35 clean_restart ${executable}
cc51a170 36
0efbbabc
TT
37 set binfile [standard_output_file $executable]
38 set escapedbinfile [string_to_regexp ${binfile}]
cc51a170 39
13fc3e3c
PA
40 gdb_test "handle SIGALRM stop print pass" "Yes.*Yes.*Yes.*"
41
2c8c5d37
PA
42 set test_spawn_id [spawn_wait_for_attach $binfile]
43 set testpid [spawn_id_get_pid $test_spawn_id]
13fc3e3c
PA
44
45 # Run 2 passes of the test.
46 # The C file inferior stops pending its signals if a single one is lost,
47 # we test successful redelivery of the caught signal by the 2nd pass.
48
49 # linux-2.6.20.4.x86_64 had maximal attempt # 20 in 4 test runs.
50 set attempts 100
51 set attempt 1
52 set passes 1
53 while { $passes < 3 && $attempt <= $attempts } {
eb2bfbad
PA
54 set test "attach (pass $passes), pending signal catch"
55 if {[gdb_test_multiple "attach $testpid" $test {
56 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.* received signal SIGALRM.*$gdb_prompt $" {
57 # nonthreaded:
58 pass $test
59 verbose -log "$test succeeded on the attempt # $attempt of $attempts"
60 set passes [expr $passes + 1]
61 }
62 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
63 set ok 0
64
65 if { $threadtype == "threaded" } {
66 # In the threaded case, the signal is left
67 # pending on the second thread. Check for
68 # that by peeking at the thread's siginfo.
69 # SIGALRM is 14, SIGSTOP is 19.
70
71 set test2 "thread apply 2 print \$_siginfo.si_signo"
72 gdb_test_multiple $test2 $test2 {
73 -re " = 14\r\n$gdb_prompt $" {
74 set ok 1
75 }
76 -re " = 19\r\n$gdb_prompt $" {
7da5b897 77 }
7da5b897 78 }
eb2bfbad
PA
79 } else {
80 # In the nonthreaded case, GDB should tell the
81 # user about having seen a signal.
82 }
7da5b897 83
eb2bfbad
PA
84 if { $ok == 0} {
85 # We just lack the luck, we should try it again.
86 set attempt [expr $attempt + 1]
87 } else {
88 pass $test
89 verbose -log "$test succeeded on the attempt # $attempt of $attempts"
90 set passes [expr $passes + 1]
7da5b897 91 }
c5a006e6 92 }
eb2bfbad
PA
93 }] != 0 } {
94 break
95 }
a0ef4274 96
cce0ae56 97 gdb_test -nopass "detach" "Detaching from.*"
13fc3e3c 98 }
7da5b897 99
13fc3e3c
PA
100 if {$passes < 3} {
101 if {$attempt > $attempts} {
102 unresolved $test
103 } else {
104 fail $test
105 }
a0ef4274 106 }
a0ef4274 107
13fc3e3c 108 # Exit and detach the process.
13fc3e3c 109 gdb_exit
a0ef4274 110
13fc3e3c
PA
111 # Continue the program - some Linux kernels need it before -9 if the
112 # process is stopped.
113 remote_exec build "kill -s CONT ${testpid}"
7da5b897 114
2c8c5d37 115 kill_wait_spawned_process $test_spawn_id
13fc3e3c 116 }
cc51a170 117}
a0ef4274
DJ
118
119# build the test case first without threads
120#
cc51a170
PA
121if {[build_executable $testfile $executable_nothr $srcfile] == -1} {
122 untested "attach-into-signal.exp (nonthreaded)"
c7a6ca08 123 return -1
a0ef4274
DJ
124}
125
cc51a170 126corefunc nonthreaded ${executable_nothr}
a0ef4274
DJ
127
128# build the test case also with threads
129#
0efbbabc 130if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" [standard_output_file ${executable_thr}] executable {debug additional_flags=-DUSE_THREADS}] != "" } {
c7a6ca08
PA
131 untested "attach-into-signal.exp (threaded)"
132 return -1
a0ef4274
DJ
133}
134
cc51a170 135corefunc threaded ${executable_thr}