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