Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 1997-2020 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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
74cf1395 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
74cf1395 JM |
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. | |
e22f8b7c | 12 | # |
74cf1395 | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
74cf1395 | 15 | |
60b3033e | 16 | if {![can_spawn_for_attach]} { |
74cf1395 JM |
17 | return 0 |
18 | } | |
19 | ||
a64d2530 TT |
20 | standard_testfile attach.c attach2.c |
21 | set binfile2 ${binfile}2 | |
22 | set escapedbinfile [string_to_regexp $binfile] | |
74cf1395 JM |
23 | |
24 | #execute_anywhere "rm -f ${binfile} ${binfile2}" | |
25 | remote_exec build "rm -f ${binfile} ${binfile2}" | |
26 | # For debugging this test | |
27 | # | |
28 | #log_user 1 | |
29 | ||
74cf1395 JM |
30 | # build the first test case |
31 | # | |
32 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
84c93cd5 | 33 | untested "failed to compile" |
b60f0898 | 34 | return -1 |
74cf1395 JM |
35 | } |
36 | ||
74cf1395 JM |
37 | # Build the in-system-call test |
38 | ||
39 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } { | |
84c93cd5 | 40 | untested "failed to compile in-system-call test" |
b60f0898 | 41 | return -1 |
74cf1395 JM |
42 | } |
43 | ||
4c93b1db | 44 | if [get_compiler_info] { |
74cf1395 JM |
45 | return -1 |
46 | } | |
47 | ||
df0da8a2 AH |
48 | # This is a test of the error cases for gdb's ability to attach to a |
49 | # running process. | |
50 | ||
51 | proc_with_prefix do_attach_failure_tests {} { | |
1279f4ff AC |
52 | global gdb_prompt |
53 | global binfile | |
54 | global escapedbinfile | |
55 | global srcfile | |
df0da8a2 AH |
56 | |
57 | clean_restart $binfile | |
58 | ||
1586c8fb GB |
59 | # Figure out a regular expression that will match the sysroot, |
60 | # noting that the default sysroot is "target:", and also noting | |
61 | # that GDB will strip "target:" from the start of filenames when | |
d4d38844 YQ |
62 | # operating on the local filesystem. However the default sysroot |
63 | # can be set via configure option --with-sysroot, which can be "/". | |
64 | # If $binfile is a absolute path, so pattern | |
65 | # "$sysroot$escapedbinfile" below is wrong. Use [^\r\n]* to make | |
66 | # $sysroot simple. | |
67 | set sysroot "\[^\r\n\]*" | |
1586c8fb | 68 | |
1279f4ff AC |
69 | # Start the program running and then wait for a bit, to be sure |
70 | # that it can be attached to. | |
71 | ||
2c8c5d37 PA |
72 | set test_spawn_id [spawn_wait_for_attach $binfile] |
73 | set testpid [spawn_id_get_pid $test_spawn_id] | |
1279f4ff AC |
74 | |
75 | # Verify that we cannot attach to nonsense. | |
76 | ||
8b1b3228 AC |
77 | set test "attach to nonsense is prohibited" |
78 | gdb_test_multiple "attach abc" "$test" { | |
74164c56 JK |
79 | -re "Illegal process-id: abc\\.\r\n$gdb_prompt $" { |
80 | pass "$test" | |
81 | } | |
82 | -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" { | |
83 | # Response expected from /proc-based systems. | |
84 | pass "$test" | |
85 | } | |
86 | -re "Can't attach to process..*$gdb_prompt $" { | |
87 | # Response expected on Cygwin | |
88 | pass "$test" | |
89 | } | |
90 | -re "Attaching to.*$gdb_prompt $" { | |
91 | fail "$test (bogus pid allowed)" | |
92 | } | |
93 | } | |
94 | ||
95 | # Verify that we cannot attach to nonsense even if its initial part is | |
96 | # a valid PID. | |
97 | ||
98 | set test "attach to digits-starting nonsense is prohibited" | |
99 | gdb_test_multiple "attach ${testpid}x" "$test" { | |
100 | -re "Illegal process-id: ${testpid}x\\.\r\n$gdb_prompt $" { | |
8b1b3228 | 101 | pass "$test" |
1279f4ff AC |
102 | } |
103 | -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" { | |
104 | # Response expected from /proc-based systems. | |
8b1b3228 | 105 | pass "$test" |
1279f4ff | 106 | } |
8b1b3228 | 107 | -re "Can't attach to process..*$gdb_prompt $" { |
1279f4ff | 108 | # Response expected on Cygwin |
8b1b3228 | 109 | pass "$test" |
1279f4ff AC |
110 | } |
111 | -re "Attaching to.*$gdb_prompt $" { | |
8b1b3228 | 112 | fail "$test (bogus pid allowed)" |
1279f4ff AC |
113 | } |
114 | } | |
115 | ||
116 | # Verify that we cannot attach to what appears to be a valid | |
117 | # process ID, but is a process that doesn't exist. Traditionally, | |
118 | # most systems didn't have a process with ID 0, so we take that as | |
119 | # the default. However, there are a few exceptions. | |
120 | ||
121 | set boguspid 0 | |
122 | if { [istarget "*-*-*bsd*"] } { | |
123 | # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead | |
124 | # (which should have the desired effect on any version of | |
125 | # FreeBSD, and probably other *BSD's too). | |
126 | set boguspid -1 | |
127 | } | |
8b1b3228 AC |
128 | set test "attach to nonexistent process is prohibited" |
129 | gdb_test_multiple "attach $boguspid" "$test" { | |
1279f4ff AC |
130 | -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $" { |
131 | # Response expected on ptrace-based systems (i.e. HP-UX 10.20). | |
8b1b3228 | 132 | pass "$test" |
1279f4ff AC |
133 | } |
134 | -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $" { | |
135 | # Response expected on ttrace-based systems (i.e. HP-UX 11.0). | |
8b1b3228 | 136 | pass "$test" |
1279f4ff AC |
137 | } |
138 | -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $" { | |
8b1b3228 | 139 | pass "$test" |
1279f4ff AC |
140 | } |
141 | -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $" { | |
8b1b3228 | 142 | pass "$test" |
1279f4ff AC |
143 | } |
144 | -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" { | |
145 | # Response expected from /proc-based systems. | |
8b1b3228 | 146 | pass "$test" |
1279f4ff | 147 | } |
8b1b3228 | 148 | -re "Can't attach to process..*$gdb_prompt $" { |
1279f4ff | 149 | # Response expected on Cygwin |
8b1b3228 | 150 | pass "$test" |
1279f4ff | 151 | } |
7cee1e54 PA |
152 | -re "Attaching to.*, process $boguspid.*failed.*$gdb_prompt $" { |
153 | # Response expected on the extended-remote target. | |
154 | pass "$test" | |
155 | } | |
1279f4ff AC |
156 | } |
157 | ||
df0da8a2 AH |
158 | # Verify that we can't double attach to the process. |
159 | ||
160 | set test "first attach" | |
161 | gdb_test_multiple "attach $testpid" "$test" { | |
162 | -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" { | |
163 | pass "$test" | |
164 | } | |
165 | -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" { | |
166 | # Response expected on Cygwin. | |
167 | pass "$test" | |
168 | } | |
169 | } | |
170 | ||
171 | gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2" | |
172 | gdb_test "inferior 2" "Switching to inferior 2.*" "switch to inferior 2" | |
173 | ||
174 | set test "fail to attach again" | |
175 | gdb_test_multiple "attach $testpid" "$test" { | |
176 | -re "Attaching to process $testpid.*warning: process .* is already traced by process .*$gdb_prompt $" { | |
177 | pass "$test" | |
178 | } | |
179 | -re "Attaching to process .* failed.*$gdb_prompt $" { | |
180 | # Response expected when using gdbserver. | |
181 | pass "$test" | |
182 | } | |
183 | } | |
184 | ||
185 | gdb_test "inferior 1" "Switching to inferior 1.*" "switch to inferior 1" | |
186 | set test "exit after attach failures" | |
187 | gdb_test "kill" \ | |
188 | "" \ | |
189 | "$test" \ | |
190 | "Kill the program being debugged.*y or n. $" \ | |
191 | "y" | |
192 | ||
193 | # Another "don't leave a process around" | |
194 | kill_wait_spawned_process $test_spawn_id | |
195 | } | |
196 | ||
197 | # This is a test of gdb's ability to attach to a running process. | |
198 | ||
199 | proc_with_prefix do_attach_tests {} { | |
200 | global gdb_prompt | |
201 | global binfile | |
202 | global escapedbinfile | |
203 | global srcfile | |
df0da8a2 AH |
204 | global timeout |
205 | global decimal | |
206 | ||
207 | clean_restart $binfile | |
208 | ||
209 | # Figure out a regular expression that will match the sysroot, | |
210 | # noting that the default sysroot is "target:", and also noting | |
211 | # that GDB will strip "target:" from the start of filenames when | |
212 | # operating on the local filesystem. However the default sysroot | |
213 | # can be set via configure option --with-sysroot, which can be "/". | |
214 | # If $binfile is a absolute path, so pattern | |
215 | # "$sysroot$escapedbinfile" below is wrong. Use [^\r\n]* to make | |
216 | # $sysroot simple. | |
217 | set sysroot "\[^\r\n\]*" | |
218 | ||
219 | # Start the program running and then wait for a bit, to be sure | |
220 | # that it can be attached to. | |
221 | ||
222 | set test_spawn_id [spawn_wait_for_attach $binfile] | |
223 | set testpid [spawn_id_get_pid $test_spawn_id] | |
224 | ||
1279f4ff AC |
225 | # Verify that we can attach to the process by first giving its |
226 | # executable name via the file command, and using attach with the | |
227 | # process ID. | |
228 | ||
229 | # (Actually, the test system appears to do this automatically for | |
230 | # us. So, we must also be prepared to be asked if we want to | |
231 | # discard an existing set of symbols.) | |
232 | ||
8b1b3228 AC |
233 | set test "set file, before attach1" |
234 | gdb_test_multiple "file $binfile" "$test" { | |
235 | -re "Load new symbol table from.*y or n. $" { | |
3453e7e4 | 236 | gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*" \ |
8b1b3228 | 237 | "$test (re-read)" |
1279f4ff | 238 | } |
3453e7e4 | 239 | -re "Reading symbols from $escapedbinfile\.\.\.*$gdb_prompt $" { |
8b1b3228 | 240 | pass "$test" |
1279f4ff AC |
241 | } |
242 | } | |
243 | ||
8b1b3228 AC |
244 | set test "attach1, after setting file" |
245 | gdb_test_multiple "attach $testpid" "$test" { | |
1279f4ff | 246 | -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" { |
8b1b3228 | 247 | pass "$test" |
1279f4ff AC |
248 | } |
249 | -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" { | |
250 | # Response expected on Cygwin | |
8b1b3228 | 251 | pass "$test" |
1279f4ff AC |
252 | } |
253 | } | |
254 | ||
255 | # Verify that we can "see" the variable "should_exit" in the | |
256 | # program, and that it is zero. | |
257 | ||
8b1b3228 | 258 | gdb_test "print should_exit" " = 0" "after attach1, print should_exit" |
1279f4ff AC |
259 | |
260 | # Detach the process. | |
261 | ||
8b1b3228 | 262 | gdb_test "detach" \ |
f67c0c91 | 263 | "Detaching from program: .*$escapedbinfile, process $testpid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]" \ |
8b1b3228 | 264 | "attach1 detach" |
1279f4ff AC |
265 | |
266 | # Wait a bit for gdb to finish detaching | |
267 | ||
268 | exec sleep 5 | |
269 | ||
270 | # Purge the symbols from gdb's brain. (We want to be certain the | |
271 | # next attach, which won't be preceded by a "file" command, is | |
272 | # really getting the executable file without our help.) | |
273 | ||
274 | set old_timeout $timeout | |
275 | set timeout 15 | |
8b1b3228 AC |
276 | set test "attach1, purging symbols after detach" |
277 | gdb_test_multiple "file" "$test" { | |
278 | -re "No executable file now.*Discard symbol table.*y or n. $" { | |
279 | gdb_test "y" "No symbol file now." "$test" | |
1279f4ff AC |
280 | } |
281 | } | |
282 | set timeout $old_timeout | |
283 | ||
284 | # Verify that we can attach to the process just by giving the | |
285 | # process ID. | |
286 | ||
7cee1e54 PA |
287 | set test "attach2, with no file" |
288 | set found_exec_file 0 | |
8b1b3228 | 289 | gdb_test_multiple "attach $testpid" "$test" { |
1586c8fb | 290 | -re "Attaching to process $testpid.*Load new symbol table from \"$sysroot$escapedbinfile\.exe\".*y or n. $" { |
1279f4ff AC |
291 | # On Cygwin, the DLL's symbol tables are loaded prior to the |
292 | # executable's symbol table. This in turn always results in | |
293 | # asking the user for actually loading the symbol table of the | |
294 | # executable. | |
3453e7e4 | 295 | gdb_test "y" "Reading symbols from $sysroot$escapedbinfile\.\.\.*" \ |
8b1b3228 | 296 | "$test (reset file)" |
7cee1e54 PA |
297 | |
298 | set found_exec_file 1 | |
1279f4ff | 299 | } |
1586c8fb | 300 | -re "Attaching to process $testpid.*Reading symbols from $sysroot$escapedbinfile.*main.*at .*$gdb_prompt $" { |
8b1b3228 | 301 | pass "$test" |
7cee1e54 PA |
302 | set found_exec_file 1 |
303 | } | |
304 | } | |
305 | ||
306 | if {$found_exec_file == 0} { | |
307 | set test "load file manually, after attach2" | |
308 | gdb_test_multiple "file $binfile" "$test" { | |
309 | -re "A program is being debugged already..*Are you sure you want to change the file.*y or n. $" { | |
3453e7e4 | 310 | gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*" \ |
7cee1e54 PA |
311 | "$test (re-read)" |
312 | } | |
3453e7e4 | 313 | -re "Reading symbols from $escapedbinfile\.\.\.*$gdb_prompt $" { |
7cee1e54 PA |
314 | pass "$test" |
315 | } | |
1279f4ff AC |
316 | } |
317 | } | |
318 | ||
319 | # Verify that we can modify the variable "should_exit" in the | |
320 | # program. | |
321 | ||
27d3a1a2 | 322 | gdb_test_no_output "set should_exit=1" "after attach2, set should_exit" |
1279f4ff AC |
323 | |
324 | # Verify that the modification really happened. | |
325 | ||
1cf2f1b0 JK |
326 | gdb_breakpoint [gdb_get_line_number "postloop"] temporary |
327 | gdb_continue_to_breakpoint "postloop" ".* postloop .*" | |
1279f4ff AC |
328 | |
329 | # Allow the test process to exit, to cleanup after ourselves. | |
330 | ||
fda326dd | 331 | gdb_continue_to_end "after attach2, exit" |
1279f4ff AC |
332 | |
333 | # Make sure we don't leave a process around to confuse | |
334 | # the next test run (and prevent the compile by keeping | |
335 | # the text file busy), in case the "set should_exit" didn't | |
336 | # work. | |
8b1b3228 | 337 | |
2c8c5d37 PA |
338 | kill_wait_spawned_process $test_spawn_id |
339 | ||
340 | set test_spawn_id [spawn_wait_for_attach $binfile] | |
341 | set testpid [spawn_id_get_pid $test_spawn_id] | |
1279f4ff AC |
342 | |
343 | # Verify that we can attach to the process, and find its a.out | |
344 | # when we're cd'd to some directory that doesn't contain the | |
345 | # a.out. (We use the source path set by the "dir" command.) | |
346 | ||
a64d2530 | 347 | gdb_test "dir [standard_output_file {}]" "Source directories searched: .*" \ |
8b1b3228 | 348 | "set source path" |
1279f4ff | 349 | |
8b1b3228 AC |
350 | gdb_test "cd /tmp" "Working directory /tmp." \ |
351 | "cd away from process working directory" | |
1279f4ff AC |
352 | |
353 | # Explicitly flush out any knowledge of the previous attachment. | |
1279f4ff | 354 | |
8b1b3228 | 355 | set test "before attach3, flush symbols" |
6c95b8df | 356 | gdb_test_multiple "symbol-file" "$test" { |
8b1b3228 AC |
357 | -re "Discard symbol table from.*y or n. $" { |
358 | gdb_test "y" "No symbol file now." \ | |
359 | "$test" | |
1279f4ff | 360 | } |
8b1b3228 AC |
361 | -re "No symbol file now.*$gdb_prompt $" { |
362 | pass "$test" | |
1279f4ff AC |
363 | } |
364 | } | |
365 | ||
8b1b3228 AC |
366 | gdb_test "exec" "No executable file now." \ |
367 | "before attach3, flush exec" | |
368 | ||
369 | gdb_test "attach $testpid" \ | |
1586c8fb | 370 | "Attaching to process $testpid.*Reading symbols from $sysroot$escapedbinfile.*main.*at .*" \ |
8b1b3228 AC |
371 | "attach when process' a.out not in cwd" |
372 | ||
373 | set test "after attach3, exit" | |
dfb88a23 MS |
374 | gdb_test "kill" \ |
375 | "" \ | |
376 | "$test" \ | |
377 | "Kill the program being debugged.*y or n. $" \ | |
378 | "y" | |
1279f4ff AC |
379 | |
380 | # Another "don't leave a process around" | |
2c8c5d37 | 381 | kill_wait_spawned_process $test_spawn_id |
74cf1395 JM |
382 | } |
383 | ||
df0da8a2 AH |
384 | # Test attaching when the target is inside a system call. |
385 | ||
386 | proc_with_prefix do_call_attach_tests {} { | |
1279f4ff AC |
387 | global gdb_prompt |
388 | global binfile2 | |
df0da8a2 AH |
389 | |
390 | clean_restart | |
391 | ||
2c8c5d37 PA |
392 | set test_spawn_id [spawn_wait_for_attach $binfile2] |
393 | set testpid [spawn_id_get_pid $test_spawn_id] | |
1279f4ff AC |
394 | |
395 | # Attach | |
396 | ||
8aed1c0d | 397 | gdb_test "file $binfile2" ".*" "load file" |
8b1b3228 AC |
398 | set test "attach call" |
399 | gdb_test_multiple "attach $testpid" "$test" { | |
400 | -re "warning: reading register.*I.*O error.*$gdb_prompt $" { | |
401 | fail "$test (read register error)" | |
1279f4ff AC |
402 | } |
403 | -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" { | |
8b1b3228 | 404 | pass "$test" |
1279f4ff AC |
405 | } |
406 | -re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" { | |
8b1b3228 | 407 | pass "$test" |
1279f4ff AC |
408 | } |
409 | } | |
410 | ||
411 | # See if other registers are problems | |
412 | ||
8b1b3228 AC |
413 | set test "info other register" |
414 | gdb_test_multiple "i r r3" "$test" { | |
415 | -re "warning: reading register.*$gdb_prompt $" { | |
416 | fail "$test" | |
1279f4ff | 417 | } |
8b1b3228 AC |
418 | -re "r3.*$gdb_prompt $" { |
419 | pass "$test" | |
1279f4ff | 420 | } |
1279f4ff | 421 | } |
74cf1395 | 422 | |
1279f4ff AC |
423 | # Get rid of the process |
424 | ||
8b1b3228 | 425 | gdb_test "p should_exit = 1" |
fda326dd | 426 | gdb_continue_to_end |
1279f4ff AC |
427 | |
428 | # Be paranoid | |
429 | ||
2c8c5d37 | 430 | kill_wait_spawned_process $test_spawn_id |
74cf1395 JM |
431 | } |
432 | ||
df0da8a2 | 433 | proc_with_prefix do_command_attach_tests {} { |
ccdd1909 HZ |
434 | global gdb_prompt |
435 | global binfile | |
ccdd1909 HZ |
436 | |
437 | if ![isnative] then { | |
438 | unsupported "command attach test" | |
439 | return 0 | |
440 | } | |
441 | ||
2c8c5d37 PA |
442 | set test_spawn_id [spawn_wait_for_attach $binfile] |
443 | set testpid [spawn_id_get_pid $test_spawn_id] | |
ccdd1909 HZ |
444 | |
445 | gdb_exit | |
ccdd1909 | 446 | |
fef1b293 TT |
447 | set res [gdb_spawn_with_cmdline_opts \ |
448 | "-quiet -iex \"set height 0\" -iex \"set width 0\" --pid=$testpid"] | |
ccdd1909 | 449 | set test "starting with --pid" |
2c8c5d37 | 450 | gdb_test_multiple "" $test { |
ccdd1909 HZ |
451 | -re "Reading symbols from.*$gdb_prompt $" { |
452 | pass "$test" | |
453 | } | |
ccdd1909 HZ |
454 | } |
455 | ||
456 | # Get rid of the process | |
2c8c5d37 | 457 | kill_wait_spawned_process $test_spawn_id |
ccdd1909 HZ |
458 | } |
459 | ||
98880d46 PA |
460 | # Test ' gdb --pid PID -ex "run" '. GDB used to have a bug where |
461 | # "run" would run before the attach finished - PR17347. | |
462 | ||
463 | proc test_command_line_attach_run {} { | |
464 | global gdb_prompt | |
465 | global binfile | |
466 | ||
b1468492 PW |
467 | # Skip test if we cannot attach on the command line and use the run command. |
468 | # ??? Unclear what condition to use to return here when using gdbserver. | |
469 | # ??? None of the below works. | |
470 | # ![isnative] || [target_is_gdbserver] | |
471 | # ![isnative] || [use_gdb_stub] | |
472 | if { ![isnative] || [is_remote target] } then { | |
98880d46 PA |
473 | unsupported "commandline attach run test" |
474 | return 0 | |
475 | } | |
476 | ||
477 | with_test_prefix "cmdline attach run" { | |
2c8c5d37 PA |
478 | set test_spawn_id [spawn_wait_for_attach $binfile] |
479 | set testpid [spawn_id_get_pid $test_spawn_id] | |
98880d46 PA |
480 | |
481 | set test "run to prompt" | |
482 | gdb_exit | |
483 | ||
484 | set res [gdb_spawn_with_cmdline_opts \ | |
fef1b293 | 485 | "-quiet -iex \"set height 0\" -iex \"set width 0\" --pid=$testpid -ex \"start\""] |
98880d46 PA |
486 | if { $res != 0} { |
487 | fail $test | |
2c8c5d37 | 488 | kill_wait_spawned_process $test_spawn_id |
98880d46 PA |
489 | return $res |
490 | } | |
491 | gdb_test_multiple "" $test { | |
492 | -re {Attaching to.*Start it from the beginning\? \(y or n\) } { | |
493 | pass $test | |
494 | } | |
495 | } | |
496 | ||
497 | send_gdb "y\n" | |
498 | ||
499 | set test "run to main" | |
500 | gdb_test_multiple "" $test { | |
501 | -re "Temporary breakpoint .* main .*$gdb_prompt $" { | |
502 | pass $test | |
503 | } | |
504 | } | |
505 | ||
506 | # Get rid of the process | |
2c8c5d37 | 507 | kill_wait_spawned_process $test_spawn_id |
98880d46 PA |
508 | } |
509 | } | |
74cf1395 | 510 | |
b1468492 PW |
511 | |
512 | # This is a test of 'set exec-file-mismatch' handling. | |
513 | ||
514 | proc_with_prefix do_attach_exec_mismatch_handling_tests {} { | |
515 | global gdb_prompt | |
516 | global binfile | |
517 | global binfile2 | |
518 | ||
519 | clean_restart $binfile | |
520 | ||
521 | # Start two programs that can be attached to. | |
522 | # The first program contains a 'int bidule' variable, the second a 'float bidule'. | |
523 | ||
524 | set test_spawn_id [spawn_wait_for_attach $binfile] | |
525 | set testpid [spawn_id_get_pid $test_spawn_id] | |
526 | set test_spawn_id2 [spawn_wait_for_attach $binfile2] | |
527 | set testpid2 [spawn_id_get_pid $test_spawn_id2] | |
528 | ||
529 | ||
530 | # Test with the default value of 'set exec-file-mismatch load". | |
531 | set test "mismatch load" | |
532 | gdb_test "attach $testpid" "Attaching to program.*" "$test attach1" | |
533 | # Verify that we can "see" the variable "bidule" in the | |
534 | # program, and that it is an integer. | |
535 | gdb_test "ptype bidule" " = int" "$test after attach1, bidule is int" | |
536 | # Detach the process. | |
537 | gdb_test "detach" "Detaching from program: .* detached\\\]" "$test detach1" | |
538 | gdb_test_multiple "attach $testpid2" "$test attach2" { | |
539 | -re "Attaching to program.*exec-file-mismatch handling is currently \"ask\".*Load new symbol table from .*attach2\".*\(y or n\)" { | |
540 | pass "$test attach2" | |
541 | } | |
542 | } | |
543 | gdb_test "y" "Reading symbols from .*attach2.*" "$test load attach2" | |
544 | # Verify that we can "see" the variable "bidule" in the | |
545 | # program, and that it is a float. | |
546 | gdb_test "ptype bidule" " = float" "$test after attach2 and load, bidule is float" | |
547 | # Detach the process. | |
548 | gdb_test "detach" "Detaching from program: .* detached\\\]" "$test detach attach2" | |
549 | ||
550 | ||
551 | # Test with 'set exec-file-mismatch warn". | |
552 | set test "mismatch warn" | |
553 | gdb_test_no_output "set exec-file-mismatch warn" | |
554 | gdb_test_multiple "attach $testpid" "$test attach" { | |
555 | -re "Attaching to program.*exec-file-mismatch handling is currently \"warn\".*$gdb_prompt" { | |
556 | pass "$test attach" | |
557 | } | |
558 | } | |
559 | # Verify that we still (wrongly) "see" the variable "bidule" as a float, | |
560 | # as we have not loaded the correct exec-file. | |
561 | gdb_test "ptype bidule" " = float" "$test after attach and warn, bidule is float" | |
562 | # Detach the process. | |
563 | gdb_test "detach" "Detaching from program: .* detached\\\]" "$test detach attach" | |
564 | ||
565 | ||
566 | # Same test but with 'set exec-file-mismatch off". | |
567 | set test "mismatch off" | |
568 | gdb_test_no_output "set exec-file-mismatch off" | |
569 | gdb_test_multiple "attach $testpid" "$test attach" { | |
570 | -re "Attaching to program.*$gdb_prompt" { | |
571 | pass "$test attach" | |
572 | } | |
573 | } | |
574 | # Verify that we still (wrongly) "see" the variable "bidule" as a float, | |
575 | # as we have not warned the user and not loaded the correct exec-file | |
576 | gdb_test "ptype bidule" " = float" "$test after attach and warn, bidule is float" | |
577 | # Detach the process. | |
578 | gdb_test "detach" "Detaching from program: .* detached\\\]" "$test detach attach" | |
579 | ||
580 | ||
581 | # Don't leave a process around | |
582 | kill_wait_spawned_process $test_spawn_id | |
583 | kill_wait_spawned_process $test_spawn_id2 | |
584 | } | |
585 | ||
74cf1395 | 586 | do_attach_tests |
df0da8a2 | 587 | do_attach_failure_tests |
74cf1395 | 588 | do_call_attach_tests |
b1468492 | 589 | do_attach_exec_mismatch_handling_tests |
74cf1395 | 590 | |
ccdd1909 HZ |
591 | # Test "gdb --pid" |
592 | ||
593 | do_command_attach_tests | |
594 | ||
b1468492 | 595 | |
98880d46 PA |
596 | test_command_line_attach_run |
597 | ||
74cf1395 | 598 | return 0 |