1 # Copyright
2018-2024 Free Software Foundation
, Inc.
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.
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.
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
/>.
16 # This test is about restarting execution of a forked application when
17 # using gdb extended remote target.
19 # There are two issues that the test tries to expose in GDB
:
21 #
1. GDB would throw an assertion upon reconnecting to a remote target
22 #
if there was more than one inferior already active in GDB
, and
24 #
2. GDB would not prune transient inferiors from the inferior list
25 # when reconnecting to a remote target. So
, for example
, an inferior
26 # created by GDB to track the child of a fork would usually be removed
27 # from the inferior list once the child exited. However
, reconnecting
28 # to a remote target would result in the child inferior remaining in
31 # This test is only
for extended remote targets.
32 if {[target_info gdb_protocol
] != "extended-remote"} {
33 unsupported
"requires extended-remote"
37 # This test also makes use of
'detach-on-fork' which is not supported
39 require
{is_any_target
"*-*-linux*" "*-*-openbsd*"}
41 # And we need to be able to reconnect to gdbserver.
42 set gdbserver_reconnect_p
1
43 if { [info proc gdb_reconnect
] == "" } {
44 unsupported
"requires gdbserver reconnect"
50 if {[prepare_for_testing
"failed to prepare" $testfile $srcfile debug]} {
54 # Core of the test. DO_KILL_P controls whether we kill one of the
55 # inferiors before reconnecting. And FOLLOW_CHILD_P controls whether
56 # we follow the child or the parent at the fork.
57 proc test_reload
{ do_kill_p follow_child_p
} {
61 clean_restart $
{binfile
}
67 #
Set detach
-on-fork
off
68 gdb_test_no_output
"set detach-on-fork off"
70 set live_inf_ptn
"process $decimal"
71 set dead_inf_ptn
"<null>"
73 if $
{follow_child_p
} {
74 gdb_test_no_output
"set follow-fork child"
76 set child_prefix
"\\*"
77 set parent_inf_after_kill_ptn $
{live_inf_ptn
}
78 set child_inf_after_kill_ptn $
{dead_inf_ptn
}
80 gdb_test_no_output
"set follow-fork parent"
81 set parent_prefix
"\\*"
83 set parent_inf_after_kill_ptn $
{dead_inf_ptn
}
84 set child_inf_after_kill_ptn $
{live_inf_ptn
}
87 gdb_breakpoint
"breakpt"
88 gdb_continue_to_breakpoint
"breakpt"
91 set any_re
"\[^\r\n\]+"
92 set connection_re $any_re
93 set executable_re $any_re
95 gdb_test
"info inferiors" \
97 " Num${ws}Description${ws}Connection${ws}Executable${ws}" \
98 "${parent_prefix} 1${ws}${live_inf_ptn}${ws}${connection_re}${executable_re}" \
99 "${child_prefix} 2${ws}${live_inf_ptn}${ws}${connection_re}${executable_re}" ] \
100 "Check inferiors at breakpoint"
103 #
(Optional
) Kill one of the inferiors.
107 "Kill the program being debugged.*y or n. $" \
110 # Check the first inferior really did die.
111 gdb_test
"info inferiors" \
113 " Num${ws}Description${ws}Connection${ws}Executable${ws}" \
114 "${parent_prefix} 1${ws}${parent_inf_after_kill_ptn}${ws}${connection_re}${executable_re}" \
115 "${child_prefix} 2${ws}${child_inf_after_kill_ptn}${ws}${connection_re}${executable_re}" ] \
116 "Check inferior was killed"
119 #
Disconnect, and reconnect to the target.
120 gdb_test
"disconnect" ".*"
122 if { [gdb_reconnect
] == 0 } {
123 pass
"reconnect after fork"
125 fail
"reconnect after fork"
129 # Run all combinations of the test.
130 foreach do_kill_p
[list
1 0] {
131 foreach follow_child_p
[list
1 0] {
133 "kill: ${do_kill_p}, follow-child ${follow_child_p}" {
134 test_reload $
{do_kill_p
} $
{follow_child_p
}