xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/interrupt-daemon-attach.exp (revision 867d70fc718005c0918b8b8b2f9d7f2d52d0a0db)
1# Copyright 2019 Free Software Foundation, Inc.
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
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
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.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
15
16if [target_info exists gdb,nosignals] {
17    verbose "Skipping interrupt-daemon-attach.exp because of nosignals."
18    continue
19}
20
21# This test requires sending ^C to interrupt the running target.
22if [target_info exists gdb,nointerrupts] {
23    verbose "Skipping interrupt-daemon-attach.exp because of nointerrupts."
24    return
25}
26
27if { ![can_spawn_for_attach] } {
28    return 0
29}
30
31standard_testfile
32
33if { [build_executable ${testfile}.exp ${testfile} $srcfile {debug}] == -1 } {
34    return -1
35}
36
37proc do_test {} {
38    global binfile
39    global decimal
40
41    set test_spawn_id [spawn_wait_for_attach $binfile]
42    set parent_pid [spawn_id_get_pid $test_spawn_id]
43
44    # Attach to the parent, run it to a known point, extract the
45    # child's PID, and detach.
46    with_test_prefix "parent" {
47	clean_restart ${binfile}
48
49	gdb_test "attach $parent_pid" \
50	    "Attaching to program.*, process $parent_pid.*" \
51	    "attach"
52
53	gdb_breakpoint "marker"
54	gdb_continue_to_breakpoint "marker"
55
56	set child_pid [get_integer_valueof "child_pid" -1]
57	if {$child_pid == -1} {
58	    return
59	}
60
61	gdb_test "detach" \
62	    "Detaching from program: .*process $parent_pid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]"
63
64	remote_exec host "kill -9 $parent_pid"
65    }
66
67    # Start over, and attach to the child this time.
68    with_test_prefix "child" {
69	global gdb_prompt
70
71	clean_restart $binfile
72
73	gdb_test "attach $child_pid" \
74	    "Attaching to program.*, process $child_pid.*" \
75	    "attach"
76
77	gdb_test_multiple "continue" "continue" {
78	    -re "Continuing" {
79		pass "continue"
80	    }
81	}
82
83	after 500 {send_gdb "\003"}
84	gdb_test "" "(Program|Thread .*) received signal SIGINT.*" \
85	    "stop with control-c"
86
87	remote_exec host "kill -9 $child_pid"
88    }
89}
90
91do_test
92