]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.server/extended-remote-restart.exp
Add unsupported calls where needed
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.server / extended-remote-restart.exp
1 # Copyright 2018-2023 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
16 # This test is about restarting execution of a forked application when
17 # using gdb extended remote target.
18 #
19 # There are two issues that the test tries to expose in GDB:
20 #
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
23 #
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
29 # the inferior list.
30
31 # This test is only for extended remote targets.
32 if {[target_info gdb_protocol] != "extended-remote"} {
33 unsupported "requires extended-remote"
34 return
35 }
36
37 # This test also makes use of 'detach-on-fork' which is not supported
38 # on all platforms.
39 require {is_any_target "*-*-linux*" "*-*-openbsd*"}
40
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"
45 return 0
46 }
47
48 standard_testfile
49
50 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
51 return -1
52 }
53
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 } {
58 global decimal
59 global binfile
60
61 clean_restart ${binfile}
62
63 if {![runto_main]} {
64 return 0
65 }
66
67 # Set detach-on-fork off
68 gdb_test_no_output "set detach-on-fork off"
69
70 set live_inf_ptn "process $decimal"
71 set dead_inf_ptn "<null>"
72
73 if ${follow_child_p} {
74 gdb_test_no_output "set follow-fork child"
75 set parent_prefix " "
76 set child_prefix "\\*"
77 set parent_inf_after_kill_ptn ${live_inf_ptn}
78 set child_inf_after_kill_ptn ${dead_inf_ptn}
79 } else {
80 gdb_test_no_output "set follow-fork parent"
81 set parent_prefix "\\*"
82 set child_prefix " "
83 set parent_inf_after_kill_ptn ${dead_inf_ptn}
84 set child_inf_after_kill_ptn ${live_inf_ptn}
85 }
86
87 gdb_breakpoint "breakpt"
88 gdb_continue_to_breakpoint "breakpt"
89
90 set ws "\[ \t\]+"
91 set any_re "\[^\r\n\]+"
92 set connection_re $any_re
93 set executable_re $any_re
94
95 gdb_test "info inferiors" \
96 [multi_line \
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"
101
102 if { $do_kill_p } {
103 # (Optional) Kill one of the inferiors.
104 gdb_test "kill" \
105 "" \
106 "Kill inferior" \
107 "Kill the program being debugged.*y or n. $" \
108 "y"
109
110 # Check the first inferior really did die.
111 gdb_test "info inferiors" \
112 [multi_line \
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"
117 }
118
119 # Disconnect, and reconnect to the target.
120 gdb_test "disconnect" ".*"
121
122 if { [gdb_reconnect] == 0 } {
123 pass "reconnect after fork"
124 } else {
125 fail "reconnect after fork"
126 }
127 }
128
129 # Run all combinations of the test.
130 foreach do_kill_p [list 1 0] {
131 foreach follow_child_p [list 1 0] {
132 with_test_prefix \
133 "kill: ${do_kill_p}, follow-child ${follow_child_p}" {
134 test_reload ${do_kill_p} ${follow_child_p}
135 }
136 }
137 }