10SN/A# Copyright (C) 2015-2020 Free Software Foundation, Inc.
22362SN/A#
30SN/A# This program is free software; you can redistribute it and/or modify
40SN/A# it under the terms of the GNU General Public License as published by
50SN/A# the Free Software Foundation; either version 3 of the License, or
60SN/A# (at your option) any later version.
72362SN/A#
80SN/A# This program is distributed in the hope that it will be useful,
92362SN/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
100SN/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
110SN/A# GNU General Public License for more details.
120SN/A#
130SN/A# You should have received a copy of the GNU General Public License
140SN/A# along with this program.  If not, see <http://www.gnu.org/licenses/>.
150SN/A
160SN/A# Check that forking a process after a previous process was attached to unsets
170SN/A# attach_flag.  This is done indirectly by inspecting GDB's quit prompt.
180SN/A
190SN/Aif ![can_spawn_for_attach] {
200SN/A    return 0
212362SN/A}
222362SN/A
232362SN/Astandard_testfile
240SN/Aset executable $testfile
250SN/A
260SN/Aif [prepare_for_testing "failed to prepare" $executable] {
270SN/A    return -1
280SN/A}
290SN/A
300SN/Aset test_spawn_id [spawn_wait_for_attach $binfile]
310SN/Aset test_pid [spawn_id_get_pid $test_spawn_id]
320SN/A
330SN/Aset test "attach to process"
340SN/Agdb_test "attach $test_pid" "Attaching to program.*" $test
350SN/A
360SN/Aset test "kill process"
370SN/Agdb_test "kill" "" $test \
380SN/A    "Kill the program being debugged.*y or n. $" "y"
390SN/A
400SN/Aset test "restart process"
410SN/Agdb_test "start" "Starting program.*Temporary breakpoint .*" $test
420SN/A
430SN/Aset test "attempt kill via quit"
440SN/A# The quit prompt should warn about killing the process, not about detaching the
450SN/A# process, since this process was not attached to.
460SN/Aset ok 0
470SN/Agdb_test_multiple "quit" $test {
480SN/A    -re "will be killed.*.y or n. $" {
490SN/A	set ok 1
500SN/A	send_gdb "n\n"
510SN/A	exp_continue
520SN/A    }
530SN/A    -re "will be detached.*.y or n. $" {
540SN/A	send_gdb "n\n"
550SN/A	exp_continue
560SN/A    }
570SN/A    -re "$gdb_prompt $" {
580SN/A	gdb_assert $ok $test
590SN/A    }
600SN/A}
610SN/A
620SN/Akill_wait_spawned_process $test_spawn_id
630SN/A