1 # Copyright 2009-2019 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 # Test multi-exec / multi-process features that work for all configurations,
17 # even ones that cannot run multiple processes simultaneously.
19 set testfile "multi-arch-exec"
21 # The plain remote target can't do multiple inferiors.
26 # The 64-bit compile may succeed for i386-linux, but gdb won't be able
28 if [istarget "i?86-*linux*"] {
32 # The testcase builds two programs, each of its own architecture. For
33 # example, one built with -m64, another with -m32. The exact compiler
34 # options depends on target triplet. We generically refer to the
35 # architectures simply as 'architecture 1' and 'architecture 2'. Each
36 # program is actually built twice, once for each architecture, because
37 # we test both execing from arch1 to arch2 and from arch2 to arch1.
38 # The architecture of the executable that execs is encoded in the
39 # binaries' names, like so:
41 # $first_arch-multi-arch-exec # execing program
42 # $first_arch-multi-arch-exec-hello # execed program
44 # Append the options necessary to build a program for architecture 1
45 # to the OPTIONS_VAR list.
47 proc append_arch1_options {options_var} {
48 upvar 1 $options_var options
50 if { [istarget "aarch64*-*-*"] } {
54 lappend options "additional_flags=-m64"
58 # Append the options necessary to build a program for architecture 2
59 # to the OPTIONS_VAR list.
61 proc append_arch2_options {options_var} {
62 upvar 1 $options_var options
64 if { [istarget "aarch64*-*-*"] } {
65 if {[info exists ARM_CC_FOR_TARGET]} {
66 lappend options "compiler=${ARM_CC_FOR_TARGET}"
69 unsupported "ARM compiler is not known"
74 if [istarget "s390*-*-*"] {
79 lappend options "additional_flags=${march}"
83 # Append the options necessary to build a program for architecture
84 # ARCH to the OPTIONS_VAR list. Returns true on success.
86 proc append_arch_options {arch options_var} {
87 upvar 1 $options_var options
90 return [append_arch1_options options]
91 } elseif {$arch == 2} {
92 return [append_arch2_options options]
94 error "unhandled architecture: $arch"
98 # Build the executables for testing with FIRST_ARCH (either 1 or 2) as
99 # the architecture before the exec. Returns true on success.
101 proc build_executables { first_arch } {
103 # Can't use standard_testfile, we want executables with specialized
105 set from_exec "$first_arch-multi-arch-exec"
106 set from_srcfile multi-arch-exec.c
107 set from_binfile [standard_output_file ${from_exec}]
109 set to_exec "$first_arch-multi-arch-exec-hello"
110 set to_srcfile hello.c
111 set to_binfile [standard_output_file ${to_exec}]
113 # Build two executables, one for each arch.
115 if {$first_arch == 1} {
118 } elseif {$first_arch == 2} {
122 error "unhandled first architecture: $first_arch"
125 set from_options [list debug pthreads]
126 if {![append_arch_options $from_arch from_options]} {
130 if { [build_executable "failed to prepare" ${from_exec} "${from_srcfile}" \
135 set to_options [list debug]
136 if {![append_arch_options $to_arch to_options]} {
140 if { [build_executable "failed to prepare" ${to_exec} "${to_srcfile}" \
148 proc do_test { first_arch mode selected_thread } {
149 set from_exec "$first_arch-multi-arch-exec"
151 clean_restart ${from_exec}
152 if ![runto all_started] then {
153 fail "couldn't run to all_started"
157 # Delete the breakpoint at 'all_started' otherwise GDB may
158 # switch context back to thread 1 to step over the breakpoint.
161 # A location for this breakpoint should be found in the new
162 # post-exec image too.
165 gdb_test "thread $selected_thread" "Switching to thread $selected_thread .*"
167 gdb_test_no_output "set follow-exec-mode $mode"
169 # Test that GDB updates the target description / arch successfuly
171 gdb_test "continue" "Breakpoint 2, main.*" "continue across exec that changes architecture"
174 # Test both arch1=>arch2 and arch2=>arch1.
175 foreach_with_prefix first_arch {1 2} {
176 if {![build_executables $first_arch]} {
180 # Test handling the exec event with either the main thread or the
181 # second thread selected. This tries to ensure that GDB doesn't read
182 # registers off of the execing thread before figuring out its
184 foreach_with_prefix selected_thread {1 2} {
185 foreach_with_prefix follow_exec_mode {"same" "new"} {
186 do_test $first_arch $follow_exec_mode $selected_thread