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