Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: gdb/testsuite/gdb.threads/attach-into-signal.exp

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/testsuite/gdb.threads/Makefile.in ('k') | gdb/testsuite/gdb.threads/attach-stopped.exp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2008-2012 Free Software Foundation, Inc. 1 # Copyright 2008-2012 Free Software Foundation, Inc.
2 2
3 # This program is free software; you can redistribute it and/or modify 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 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 5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version. 6 # (at your option) any later version.
7 # 7 #
8 # This program is distributed in the hope that it will be useful, 8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 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/>. 14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 15
16 # This test was created by modifying attach-stopped.exp. 16 # This test was created by modifying attach-stopped.exp.
17 # This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>. 17 # This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
18 18
19 # This test only works on Linux 19 # This test only works on Linux
20 if { ![isnative] || [is_remote host] || [target_info exists use_gdb_stub] 20 if { ![isnative] || [is_remote host] || [target_info exists use_gdb_stub]
21 || ![istarget *-linux*] } { 21 || ![istarget *-linux*] } {
22 continue 22 continue
23 } 23 }
24 24
25 set testfile "attach-into-signal" 25 standard_testfile
26 set srcfile ${testfile}.c 26 set executable_nothr ${testfile}-nothr
27 set binfile ${objdir}/${subdir}/${testfile} 27 set executable_thr ${testfile}-thr
28 set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
29 28
30 remote_exec build "rm -f ${binfile}" 29 proc corefunc { threadtype executable } {
31 # For debugging this test
32 #
33 #log_user 1
34
35 proc corefunc { threadtype } {
36 global srcfile 30 global srcfile
37 global binfile
38 global escapedbinfile
39 global srcdir 31 global srcdir
40 global subdir 32 global subdir
41 global gdb_prompt 33 global gdb_prompt
42 34
43 if [get_compiler_info ${binfile}] { 35 with_test_prefix "$threadtype" {
44 » return -1 36 » clean_restart ${executable}
45 }
46 37
47 # Start the program running and then wait for a bit, to be sure 38 » set binfile [standard_output_file $executable]
48 # that it can be attached to. 39 » set escapedbinfile [string_to_regexp ${binfile}]
49 # Statistically there is a better chance without giving process a nice.
50 40
51 set testpid [eval exec $binfile &] 41 » if [get_compiler_info] {
52 exec sleep 2 42 » return -1
43 » }
53 44
54 # Run 2 passes of the test. 45 » gdb_test "handle SIGALRM stop print pass" "Yes.*Yes.*Yes.*"
55 # The C file inferior stops pending its signals if a single one is lost,
56 # we test successful redelivery of the caught signal by the 2nd pass.
57 46
58 # linux-2.6.20.4.x86_64 had maximal attempt # 20 in 4 test runs. 47 » # Start the program running and then wait for a bit, to be sure
59 set attempts 100 48 » # that it can be attached to.
60 set attempt 1 49 » # Statistically there is a better chance without giving process a nice.
61 set passes 1 50
62 while { $passes < 3 && $attempt <= $attempts } { 51 » set testpid [eval exec $binfile &]
63 » set stoppedtry 0 52 » exec sleep 2
64 » while { $stoppedtry < 10 } { 53
65 » if [catch {open /proc/${testpid}/status r} fileid] { 54 » # Run 2 passes of the test.
66 » » set stoppedtry 10 55 » # The C file inferior stops pending its signals if a single one is lost,
56 » # we test successful redelivery of the caught signal by the 2nd pass.
57
58 » # linux-2.6.20.4.x86_64 had maximal attempt # 20 in 4 test runs.
59 » set attempts 100
60 » set attempt 1
61 » set passes 1
62 » while { $passes < 3 && $attempt <= $attempts } {
63 » set stoppedtry 0
64 » while { $stoppedtry < 10 } {
65 » » if [catch {open /proc/${testpid}/status r} fileid] {
66 » » set stoppedtry 10
67 » » break
68 » » }
69 » » gets $fileid line1;
70 » » gets $fileid line2;
71 » » close $fileid;
72
73 » » if {![string match "*(stopped)*" $line2]} {
74 » » # No PASS message as we may be looping in multiple
75 » » # attempts.
76 » » break
77 » » }
78 » » sleep 1
79 » » set stoppedtry [expr $stoppedtry + 1]
80 » }
81 » if { $stoppedtry >= 10 } {
82 » » verbose -log $line2
83 » » set test "process is still running on the attempt # $attempt of $attempts"
67 break 84 break
68 } 85 }
69 gets $fileid line1;
70 gets $fileid line2;
71 close $fileid;
72 86
73 » if {![string match "*(stopped)*" $line2]} { 87 » # Main test:
74 » » # No PASS message as we may be looping in multiple attempts. 88 » set test "attach (pass $passes), pending signal catch"
89 » if {[gdb_test_multiple "attach $testpid" $test {
90 » » -re "Attaching to program.*`?$escapedbinfile'?, process $testpid .*Program received signal SIGALRM.*$gdb_prompt $" {
91 » » # nonthreaded:
92 » » pass $test
93 » » verbose -log "$test succeeded on the attempt # $attempt of $ attempts"
94 » » set passes [expr $passes + 1]
95 » » }
96 » » -re "Attaching to program.*`?$escapedbinfile'?, process $testpid .*$gdb_prompt $" {
97 » » set ok 0
98
99 » » if { $threadtype == "threaded" } {
100 » » » # In the threaded case, the signal is left
101 » » » # pending on the second thread. Check for
102 » » » # that by peeking at the thread's siginfo.
103 » » » # SIGALRM is 14, SIGSTOP is 19.
104
105 » » » # With remote targets, we need to pull the
106 » » » # thread list explicitly before GDB even knows
107 » » » # about thread 2.
108 » » » set test2 "pull thread list"
109 » » » gdb_test_multiple "info threads" $test2 {
110 » » » -re "\r\n$gdb_prompt $" {
111 » » » }
112 » » » }
113
114 » » » set test2 "thread apply 2 print \$_siginfo.si_signo"
115 » » » gdb_test_multiple $test2 $test2 {
116 » » » -re " = 14\r\n$gdb_prompt $" {
117 » » » » set ok 1
118 » » » }
119 » » » -re " = 19\r\n$gdb_prompt $" {
120 » » » }
121 » » » }
122 » » } else {
123 » » » # In the nonthreaded case, GDB should tell the
124 » » » # user about having seen a signal.
125 » » }
126
127 » » if { $ok == 0} {
128 » » » # We just lack the luck, we should try it again.
129 » » » set attempt [expr $attempt + 1]
130 » » } else {
131 » » » pass $test
132 » » » verbose -log "$test succeeded on the attempt # $attempt of $attempts"
133 » » » set passes [expr $passes + 1]
134 » » }
135 » » }
136 » }] != 0 } {
75 break 137 break
76 } 138 }
77 » sleep 1 139
78 » set stoppedtry [expr $stoppedtry + 1] 140 » gdb_test "detach" "Detaching from.*" ""
79 } 141 }
80 » if { $stoppedtry >= 10 } { 142 » if {$passes < 3} {
81 » verbose -log $line2 143 » if {$attempt > $attempts} {
82 » set test "$threadtype: process is still running on the attempt # $at tempt of $attempts" 144 » » unresolved $test
83 » break 145 » } else {
146 » » fail $test
147 » }
84 } 148 }
85 149
86 » # Main test: 150 » # Exit and detach the process.
87 » set test "$threadtype: attach (pass $passes), pending signal catch" 151
88 » if {[gdb_test_multiple "attach $testpid" $test { 152 » gdb_exit
89 » -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*Re ceived Alarm clock.*$gdb_prompt $" {
90 » » # nonthreaded:
91 » » pass $test
92 » » verbose -log "$test succeeded on the attempt # $attempt of $atte mpts"
93 » » set passes [expr $passes + 1]
94 » }
95 » -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$g db_prompt $" {
96 » » # nonthreaded:
97 » » # We just lack the luck, we should try it again.
98 » » set attempt [expr $attempt + 1]
99 » }
100 » -re "Attaching to process $testpid.*Received Alarm clock.*$gdb_promp t $" {
101 » » # threaded:
102 » » pass $test
103 » » verbose -log "$test succeeded on the attempt # $attempt of $atte mpts"
104 » » set passes [expr $passes + 1]
105 » }
106 » -re "Attaching to process $testpid.*$gdb_prompt $" {
107 » » # threaded:
108 » » # We just lack the luck, we should try it again.
109 » » set attempt [expr $attempt - 1]
110 » }
111 » }] != 0 } {
112 » break
113 » }
114 153
115 » gdb_test "detach" "Detaching from.*" "" 154 » # Make sure we don't leave a process around to confuse the
155 » # next test run (and prevent the compile by keeping the text
156 » # file busy), in case the "set should_exit" didn't work.
157
158 » # Continue the program - some Linux kernels need it before -9 if the
159 » # process is stopped.
160 » remote_exec build "kill -s CONT ${testpid}"
161
162 » remote_exec build "kill -9 ${testpid}"
163
116 } 164 }
117 if {$passes < 3} {
118 if {$attempt > $attempts} {
119 unresolved $test
120 } else {
121 fail $test
122 }
123 }
124
125 # Exit and detach the process.
126
127 gdb_exit
128
129 # Make sure we don't leave a process around to confuse
130 # the next test run (and prevent the compile by keeping
131 # the text file busy), in case the "set should_exit" didn't
132 # work.
133
134 # Continue the program - some Linux kernels need it before -9 if the
135 # process is stopped.
136 remote_exec build "kill -s CONT ${testpid}"
137
138 remote_exec build "kill -9 ${testpid}"
139 } 165 }
140 166
141 # Start with clean gdb
142 gdb_exit
143
144 # build the test case first without threads 167 # build the test case first without threads
145 # 168 #
146 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb ug}] != "" } { 169 if {[build_executable $testfile $executable_nothr $srcfile] == -1} {
147 untested "attach-into-signal.exp (unthreaded)" 170 untested "attach-into-signal.exp (nonthreaded)"
148 return -1 171 return -1
149 } 172 }
150 173
151 gdb_start 174 corefunc nonthreaded ${executable_nothr}
152 gdb_reinitialize_dir $srcdir/$subdir
153 gdb_load ${binfile}
154 gdb_test_no_output "set debug lin-lwp 1" ""
155
156 corefunc nonthreaded
157 175
158 # build the test case also with threads 176 # build the test case also with threads
159 # 177 #
160 if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" execut able {debug additional_flags=-DUSE_THREADS}] != "" } { 178 if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" [standard_output_fi le ${executable_thr}] executable {debug additional_flags=-DUSE_THREADS}] != "" } {
161 untested "attach-into-signal.exp (threaded)" 179 untested "attach-into-signal.exp (threaded)"
162 return -1 180 return -1
163 } 181 }
164 182
165 gdb_start 183 corefunc threaded ${executable_thr}
166 gdb_reinitialize_dir $srcdir/$subdir
167 gdb_load ${binfile}
168 gdb_test_no_output "set debug lin-lwp 1" ""
169
170 corefunc threaded
OLDNEW
« no previous file with comments | « gdb/testsuite/gdb.threads/Makefile.in ('k') | gdb/testsuite/gdb.threads/attach-stopped.exp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698