1 # Copyright 2017-2020 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 # Common routines for testing multi-target features.
18 load_lib gdbserver-support.exp
20 standard_testfile multi-target.c
22 # Keep a list of (inferior ID, spawn ID).
23 set server_spawn_ids
[list]
25 proc connect_target_extended_remote
{binfile num
} {
26 set res
[gdbserver_start
"--multi" ""]
27 global server_spawn_ids server_spawn_id
28 lappend server_spawn_ids
$num $server_spawn_id
29 set gdbserver_gdbport
[lindex $res 1]
30 return [gdb_target_cmd
"extended-remote" $gdbserver_gdbport]
33 # Add and start inferior number NUM. Returns true on success, false
35 proc add_inferior
{num target binfile
{gcorefile
""}} {
36 # Start another inferior.
37 gdb_test
"add-inferior -no-connection" "Added inferior $num" \
38 "add empty inferior $num"
39 gdb_test
"inferior $num" "Switching to inferior $num.*" \
40 "switch to inferior $num"
41 gdb_test
"file ${binfile}" ".*" "load file in inferior $num"
42 gdb_test_no_output
"set remote exec-file ${binfile}" \
43 "set remote-exec file in inferior $num"
45 if {$target == "core"} {
46 gdb_test
"core $gcorefile" "Core was generated by.*" \
47 "core [file tail $gcorefile], inf $num"
51 if {$target == "extended-remote"} {
52 if {[connect_target_extended_remote
$binfile $num]} {
56 if ![runto
"all_started"] then
{
64 proc prepare_core
{} {
65 global gcorefile gcore_created
68 clean_restart
${binfile
}
70 if ![runto all_started
] then
{
75 set gcorefile
[standard_output_file
$testfile.gcore
]
76 set gcore_created
[gdb_gcore_cmd
$gcorefile "save a core file"]
79 proc next_live_inferior
{inf
} {
93 # Clean up the server_spawn_ids.
94 proc cleanup_gdbservers
{ } {
95 global server_spawn_id
96 global server_spawn_ids
97 foreach { inferior_id spawn_id
} $server_spawn_ids {
98 set server_spawn_id
$spawn_id
99 gdb_test
"inferior $inferior_id"
102 set server_spawn_ids
[list]
105 # Return true on success, false otherwise.
107 proc setup
{non-stop
} {
108 global gcorefile gcore_created
112 clean_restart
${binfile
}
114 # multi-target depends on target running in non-stop mode. Force
115 # it on for remote targets, until this is the default.
116 gdb_test_no_output
"maint set target-non-stop on"
118 gdb_test_no_output
"set non-stop ${non-stop}"
120 if ![runto all_started
] then
{
126 # inferior 1 -> native
127 # inferior 2 -> extended-remote
129 # inferior 4 -> native
130 # inferior 5 -> extended-remote
132 if {![add_inferior
2 "extended-remote" $binfile]} {
135 if {![add_inferior
3 "core" $binfile $gcorefile]} {
138 if {![add_inferior
4 "native" $binfile]} {
141 if {![add_inferior
5 "extended-remote" $binfile]} {
144 if {![add_inferior
6 "core" $binfile $gcorefile]} {
149 gdb_test
"info threads" ".*"
151 # Make "continue" resume all inferiors.
152 if {${non-stop
} == "off"} {
153 gdb_test_no_output
"set schedule-multiple on"
159 proc multi_target_prepare
{} {
160 global binfile srcfile
162 if { [skip_gdbserver_tests
] } {
166 # The plain remote target can't do multiple inferiors.
167 if {[target_info gdb_protocol
] != ""} {
171 if { [prepare_for_testing
"failed to prepare" ${binfile
} "${srcfile}" \
172 {debug pthreads
}] } {
176 # Make a core file with two threads upfront. Several tests load
177 # the same core file.
183 proc multi_target_cleanup
{} {