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