]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.hp/attach.exp
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.hp / attach.exp
1 # Copyright (C) 1997 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # On HP-UX 11.0, this test is causing a process running
21 # the program "attach" to be left around spinning.
22 # Until we figure out why, I am commenting out the test
23 # to avoid polluting tiamat (our 11.0 nightly test machine)
24 # with these processes. RT
25 #
26 # Setting the magic bit in the target app should work.
27 # I added a "kill", and also a test for the R3 register
28 # warning. JB
29 #
30 if $tracelevel then {
31 strace $tracelevel
32 }
33
34 set prms_id 0
35 set bug_id 0
36
37
38 # are we on a target board
39 if ![isnative] then {
40 return
41 }
42
43 if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
44 #setup_xfail "*-*-*"
45 return 0
46 }
47
48 set testfile "attach"
49 set srcfile ${testfile}.c
50 set srcfile2 ${testfile}2.c
51 set binfile ${objdir}/${subdir}/${testfile}
52 set binfile2 ${objdir}/${subdir}/${testfile}2
53 set cleanupfile ${objdir}/${subdir}/${testfile}.awk
54
55 #execute_anywhere "rm -f ${binfile} ${binfile2}"
56 remote_exec build "rm -f ${binfile} ${binfile2}"
57 # For debugging this test
58 #
59 #log_user 1
60
61 # Clean out any old files from past runs.
62 #
63 remote_exec build "${cleanupfile}"
64
65 # build the first test case
66 #
67 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
68 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
69 }
70
71 # Build the in-system-call test
72
73 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
74 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
75 }
76
77 #if { [compile "-E ${srcdir}/${subdir}/compiler.c >> ${objdir}/${subdir}/${testfile}.tmp"] != ""# } {
78 # perror "Couldn't make ${testfile}.tmp"
79 # return -1
80 #}
81
82 #execute_anywhere "mv ${objdir}/${subdir}/${testfile}.tmp ${binfile}.ci"
83
84 #source ${binfile}.ci
85
86 proc do_attach_tests {} {
87 global gdb_prompt
88 global binfile
89 global srcfile
90 global testfile
91 global objdir
92 global subdir
93 global timeout
94
95 # Start the program running and then wait for a bit, to be sure
96 # that it can be attached to.
97 #
98 set testpid [eval exec $binfile &]
99 exec sleep 2
100
101 # Verify that we cannot attach to nonsense.
102 #
103 send_gdb "attach abc\n"
104 gdb_expect {
105 -re "Illegal process-id: abc.*$gdb_prompt $"\
106 {pass "attach to nonsense is prohibited"}
107 -re "Attaching to.*$gdb_prompt $"\
108 {fail "attach to nonsense is prohibited (bogus pid allowed)"}
109 -re "$gdb_prompt $" {fail "attach to nonsense is prohibited"}
110 timeout {fail "(timeout) attach to nonsense is prohibited"}
111 }
112
113 # Verify that we cannot attach to what appears to be a valid
114 # process ID, but is a process that doesn't exist. (I don't
115 # believe any process is ever assigned #0, at least on HPUX.)
116 #
117 send_gdb "attach 0\n"
118 gdb_expect {
119 # This reponse is expected on HP-UX 10.20 (i.e., ptrace-based).
120 -re "Attaching to.*, process 0.*No such process.*$gdb_prompt $"\
121 {pass "attach to nonexistent process is prohibited"}
122 # This response is expected on HP-UX 10.30 & 11.0 (i.e., ttrace-based).
123 -re "Attaching to.*, process 0.*Permission denied.*$gdb_prompt $"\
124 {pass "attach to nonexistent process is prohibited"}
125 -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
126 timeout {fail "(timeout) attach to nonexistent process is prohibited"}
127 }
128
129 # Verify that we can attach to the process by first giving its
130 # executable name via the file command, and using attach with
131 # the process ID.
132 #
133 # (Actually, the test system appears to do this automatically
134 # for us. So, we must also be prepared to be asked if we want
135 # to discard an existing set of symbols.)
136 #
137 send_gdb "file $binfile\n"
138 gdb_expect {
139 -re "Load new symbol table from.*y or n.*$" {
140 send_gdb "y\n"
141 gdb_expect {
142 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
143 {pass "(re)set file, before attach1"}
144 -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
145 timeout {fail "(timeout) (re)set file, before attach1"}
146 }
147 }
148 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
149 {pass "set file, before attach1"}
150 -re "$gdb_prompt $" {fail "set file, before attach1"}
151 timeout {fail "(timeout) set file, before attach1"}
152 }
153
154 send_gdb "attach $testpid\n"
155 gdb_expect {
156 -re "Attaching to program.*$binfile, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
157 {pass "attach1, after setting file"}
158 -re "$gdb_prompt $" {fail "attach1, after setting file"}
159 timeout {fail "(timeout) attach1, after setting file"}
160 }
161
162 # Verify that we can "see" the variable "should_exit" in the
163 # program, and that it is zero.
164 #
165 send_gdb "print should_exit\n"
166 gdb_expect {
167 -re ".* = 0.*$gdb_prompt $"\
168 {pass "after attach1, print should_exit"}
169 -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
170 timeout {fail "(timeout) after attach1, print should_exit"}
171 }
172
173 # Detach the process.
174 #
175 send_gdb "detach\n"
176 gdb_expect {
177 -re "Detaching from program: .*$binfile.*$gdb_prompt $"\
178 {pass "attach1 detach"}
179 -re "$gdb_prompt $" {fail "attach1 detach"}
180 timeout {fail "(timeout) attach1 detach"}
181 }
182
183 # Wait a bit for gdb to finish detaching
184 #
185 exec sleep 5
186
187 # Purge the symbols from gdb's brain. (We want to be certain
188 # the next attach, which won't be preceded by a "file" command,
189 # is really getting the executable file without our help.)
190 #
191 set old_timeout $timeout
192 set timeout [expr $timeout + 20]
193 send_gdb "file\n"
194 gdb_expect {
195 -re ".*gdb internal error.*$" {
196 fail "Internal error, prob. Memory corruption"
197 }
198 -re "No exec file now.*Discard symbol table.*y or n.*$" {
199 send_gdb "y\n"
200 gdb_expect {
201 -re "No symbol file now.*$gdb_prompt $"\
202 {pass "attach1, purging symbols after detach"}
203 -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
204 timeout {fail "(timeout) attach1, purging symbols after detach"}
205 }
206 }
207 -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
208 timeout {
209 fail "(timeout) attach1, purging file after detach"
210 }
211 }
212 set timeout $old_timeout
213
214 # Verify that we can attach to the process just by giving the
215 # process ID.
216 #
217 send_gdb "attach $testpid\n"
218 gdb_expect {
219 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
220 {pass "attach2"}
221 -re "$gdb_prompt $" {fail "attach2"}
222 timeout {fail "(timeout) attach2"}
223 }
224
225 # Verify that we can modify the variable "should_exit" in the
226 # program.
227 #
228 send_gdb "set should_exit=1\n"
229 gdb_expect {
230 -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
231 timeout {fail "(timeout) after attach2, set should_exit"}
232 }
233
234 # Verify that the modification really happened.
235 #
236 send_gdb "tbreak 19\n"
237 gdb_expect {
238 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
239 {pass "after attach2, set tbreak postloop"}
240 -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
241 timeout {fail "(timeout) after attach2, set tbreak postloop"}
242 }
243 send_gdb "continue\n"
244 gdb_expect {
245 -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
246 {pass "after attach2, reach tbreak postloop"}
247 -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
248 timeout {fail "(timeout) after attach2, reach tbreak postloop"}
249 }
250
251 # Allow the test process to exit, to cleanup after ourselves.
252 #
253 send_gdb "continue\n"
254 gdb_expect {
255 -re "Program exited normally.*$gdb_prompt $"\
256 {pass "after attach2, exit"}
257 -re "$gdb_prompt $" {fail "after attach2, exit"}
258 timeout {fail "(timeout) after attach2, exit"}
259 }
260
261 # Make sure we don't leave a process around to confuse
262 # the next test run (and prevent the compile by keeping
263 # the text file busy), in case the "set should_exit" didn't
264 # work.
265 #
266 # execute_anywhere "kill -9 ${testpid}"
267 remote_exec build "kill -9 ${testpid}"
268 # Start the program running and then wait for a bit, to be sure
269 # that it can be attached to.
270 #
271 set testpid [eval exec $binfile &]
272 exec sleep 2
273
274 # Verify that we can attach to the process, and find its a.out
275 # when we're cd'd to some directory that doesn't contain the
276 # a.out. (We use the source path set by the "dir" command.)
277 #
278 send_gdb "dir ${objdir}/${subdir}\n"
279 gdb_expect {
280 -re ".*Source directories searched: .*$gdb_prompt $"\
281 {pass "set source path"}
282 -re "$gdb_prompt $" {fail "set source path"}
283 timeout {fail "(timeout) set source path"}
284 }
285
286 send_gdb "cd /tmp\n"
287 gdb_expect {
288 -re ".*Working directory /tmp.*$gdb_prompt $"\
289 {pass "cd away from process' a.out"}
290 -re "$gdb_prompt $" {fail "cd away from process' a.out"}
291 timeout {fail "(timeout) cd away from process' a.out"}
292 }
293
294 # Explicitly flush out any knowledge of the previous attachment.
295 send_gdb "symbol\n"
296 gdb_expect {
297 -re ".*Discard symbol table from.*y or n. $"\
298 {send_gdb "y\n"
299 gdb_expect {
300 -re ".*No symbol file now.*$gdb_prompt $"\
301 {pass "before attach3, flush symbols"}
302 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
303 timeout {fail "(timeout) before attach3, flush symbols"}
304 }
305 }
306 -re ".*No symbol file now.*$gdb_prompt $"\
307 {pass "before attach3, flush symbols"}
308 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
309 timeout {fail "(timeout) before attach3, flush symbols"}
310 }
311 send_gdb "exec\n"
312 gdb_expect {
313 -re ".*No exec file now.*$gdb_prompt $"\
314 {pass "before attach3, flush exec"}
315 -re "$gdb_prompt $" {fail "before attach3, flush exec"}
316 timeout {fail "(timeout) before attach3, flush exec"}
317 }
318
319 send_gdb "attach $testpid\n"
320 gdb_expect {
321 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
322 {pass "attach when process' a.out not in cwd"}
323 -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
324 timeout {fail "(timeout) attach when process' a.out not in cwd"}
325 }
326
327 send_gdb "kill\n"
328 gdb_expect {
329 -re ".*Kill the program being debugged.*y or n. $"\
330 {send_gdb "y\n"
331 gdb_expect {
332 -re "$gdb_prompt $" {pass "after attach3, exit"}
333 timeout {fail "(timeout) after attach3, exit"}
334 }
335 }
336 -re "$gdb_prompt $" {fail "after attach3, exit"}
337 timeout {fail "(timeout) after attach3, exit"}
338 }
339 }
340
341 proc do_call_attach_tests {} {
342 global gdb_prompt
343 global binfile2
344
345 # Start the program running and then wait for a bit, to be sure
346 # that it can be attached to.
347 #
348 set testpid [eval exec $binfile2 &]
349 exec sleep 2
350
351 # Attach
352 #
353 send_gdb "attach $testpid\n"
354 gdb_expect {
355 -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
356 fail "attach call, read register 3 error"
357 }
358 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
359 pass "attach call"
360 }
361 -re "$gdb_prompt $" {fail "attach call"}
362 timeout {fail "(timeout) attach call"}
363 }
364
365 # See if other registers are problems
366 #
367 send_gdb "i r r3\n"
368 gdb_expect {
369 -re ".*warning: reading register.*$gdb_prompt $" {
370 pass "CHFts23490: known bug"
371 }
372 -re ".*r3.*$gdb_prompt $" {
373 pass "Bug fixed, Yayyy!"
374 }
375 timeout { fail "timeout on info reg" }
376 }
377
378 # Get rid of the process
379 #
380 gdb_test "p should_exit = 1" ".*" ""
381 gdb_test "c" ".*Program exited normally.*" ""
382
383 # Be paranoid
384 #
385 # execute_anywhere "kill -9 ${testpid}"
386 remote_exec build "kill -9 ${testpid}"
387
388 }
389
390
391 # Start with a fresh gdb
392 #
393 gdb_exit
394 gdb_start
395 gdb_reinitialize_dir $srcdir/$subdir
396 gdb_load ${binfile}
397
398 # This is a test of gdb's ability to attach to a running process.
399 #
400 do_attach_tests
401
402 # Test attaching when the target is inside a system call
403 #
404 gdb_exit
405 gdb_start
406 gdb_reinitialize_dir $srcdir/$subdir
407 do_call_attach_tests
408
409 # Until "set follow-fork-mode" and "catch fork" are implemented on
410 # other targets...
411 #
412 if ![istarget "hppa*-hp-hpux*"] then {
413 setup_xfail "*-*-*"
414 }
415
416 return 0