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