]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/attach-non-pgrp-leader.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / attach-non-pgrp-leader.exp
CommitLineData
1d506c26 1# Copyright 2017-2024 Free Software Foundation, Inc.
46f67f80
PA
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
16# Check that we can attach to processes that are not process group
17# leaders. We test that by attaching to a fork child that doesn't
18# call any of setpgrp/setpgid/setsid to move itself to a new process
19# group.
20
06e93b05 21require can_spawn_for_attach
46f67f80
PA
22
23standard_testfile
24
25if { [build_executable ${testfile}.exp ${testfile} $srcfile {debug}] == -1 } {
26 return -1
27}
28
29proc do_test {} {
30 global binfile
f67c0c91 31 global decimal
46f67f80
PA
32
33 set test_spawn_id [spawn_wait_for_attach $binfile]
34 set parent_pid [spawn_id_get_pid $test_spawn_id]
35
36 # Attach to the parent, run it to a known point, extract the
37 # child's PID, and detach.
38 with_test_prefix "parent" {
39 clean_restart ${binfile}
40
41 gdb_test "attach $parent_pid" \
42 "Attaching to program.*, process $parent_pid.*" \
43 "attach"
44
45 gdb_breakpoint "marker"
46 gdb_continue_to_breakpoint "marker"
47
48 set child_pid [get_integer_valueof "child_pid" -1]
49 if {$child_pid == -1} {
50 return
51 }
52
53 gdb_test "detach" \
f67c0c91 54 "Detaching from program: .*process $parent_pid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]"
46f67f80
PA
55 }
56
57 # Start over, and attach to the child this time.
58 with_test_prefix "child" {
59 clean_restart $binfile
60
61 gdb_test "attach $child_pid" \
62 "Attaching to program.*, process $child_pid.*" \
63 "attach"
64
65 gdb_breakpoint "marker"
66 gdb_continue_to_breakpoint "marker"
67
68 gdb_test "detach" \
f67c0c91 69 "Detaching from program: .*process $child_pid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]"
46f67f80
PA
70 }
71
72 kill_wait_spawned_process $test_spawn_id
73}
74
75do_test