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