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