Remove path name from test case
[binutils-gdb.git] / gdb / testsuite / gdb.multi / multi-arch-exec.exp
1 # Copyright 2009-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 # Test multi-exec / multi-process features that work for all configurations,
17 # even ones that cannot run multiple processes simultaneously.
18
19 set testfile "multi-arch-exec"
20
21 # The plain remote target can't do multiple inferiors.
22 require !use_gdb_stub
23
24 # The 64-bit compile may succeed for i386-linux, but gdb won't be able
25 # to load the file.
26 if [istarget "i?86-*linux*"] {
27 return
28 }
29
30 # The testcase builds two programs, each of its own architecture. For
31 # example, one built with -m64, another with -m32. The exact compiler
32 # options depends on target triplet. We generically refer to the
33 # architectures simply as 'architecture 1' and 'architecture 2'. Each
34 # program is actually built twice, once for each architecture, because
35 # we test both execing from arch1 to arch2 and from arch2 to arch1.
36 # The architecture of the executable that execs is encoded in the
37 # binaries' names, like so:
38 #
39 # $first_arch-multi-arch-exec # execing program
40 # $first_arch-multi-arch-exec-hello # execed program
41
42 # Append the options necessary to build a program for architecture 1
43 # to the OPTIONS_VAR list.
44
45 proc append_arch1_options {options_var} {
46 upvar 1 $options_var options
47
48 if { [istarget "aarch64*-*-*"] } {
49 return 1
50 }
51
52 lappend options "additional_flags=-m64"
53 return 1
54 }
55
56 # Append the options necessary to build a program for architecture 2
57 # to the OPTIONS_VAR list.
58
59 proc append_arch2_options {options_var} {
60 upvar 1 $options_var options
61
62 if { [istarget "aarch64*-*-*"] } {
63 if {[arm_cc_for_target] != ""} {
64 lappend options "compiler=[arm_cc_for_target]"
65 return 1
66 } else {
67 unsupported "ARM compiler is not known"
68 return 0
69 }
70 }
71
72 if [istarget "powerpc64*-*-*"] {
73 set march "-m64"
74 } elseif [istarget "s390*-*-*"] {
75 set march "-m31"
76 } else {
77 set march "-m32"
78 }
79 lappend options "additional_flags=${march}"
80 return 1
81 }
82
83 # Append the options necessary to build a program for architecture
84 # ARCH to the OPTIONS_VAR list. Returns true on success.
85
86 proc append_arch_options {arch options_var} {
87 upvar 1 $options_var options
88
89 if {$arch == 1} {
90 return [append_arch1_options options]
91 } elseif {$arch == 2} {
92 return [append_arch2_options options]
93 } else {
94 error "unhandled architecture: $arch"
95 }
96 }
97
98 # Build the executables for testing with FIRST_ARCH (either 1 or 2) as
99 # the architecture before the exec. Returns true on success.
100
101 proc build_executables { first_arch } {
102
103 # Can't use standard_testfile, we want executables with specialized
104 # names.
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}]
108
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}]
112
113 # Build two executables, one for each arch.
114
115 if {$first_arch == 1} {
116 set from_arch 1
117 set to_arch 2
118 } elseif {$first_arch == 2} {
119 set from_arch 2
120 set to_arch 1
121 } else {
122 error "unhandled first architecture: $first_arch"
123 }
124
125 set from_options [list debug pthreads]
126 if {![append_arch_options $from_arch from_options]} {
127 return 0
128 }
129
130 if { [build_executable "failed to prepare" ${from_exec} "${from_srcfile}" \
131 $from_options] } {
132 return 0
133 }
134
135 set to_options [list debug]
136 if {![append_arch_options $to_arch to_options]} {
137 return 0
138 }
139
140 if { [build_executable "failed to prepare" ${to_exec} "${to_srcfile}" \
141 $to_options] } {
142 return 0
143 }
144
145 return 1
146 }
147
148 proc do_test { first_arch mode selected_thread } {
149 global bkptno_numopt_re
150 set from_exec "$first_arch-multi-arch-exec"
151
152 clean_restart ${from_exec}
153 if {![runto all_started]} {
154 return -1
155 }
156
157 # Delete the breakpoint at 'all_started' otherwise GDB may
158 # switch context back to thread 1 to step over the breakpoint.
159 delete_breakpoints
160
161 # A location for this breakpoint should be found in the new
162 # post-exec image too.
163 gdb_breakpoint main
164
165 gdb_test "thread $selected_thread" "Switching to thread $selected_thread .*"
166
167 gdb_test_no_output "set follow-exec-mode $mode"
168
169 # Test that GDB updates the target description / arch successfully
170 # after the exec.
171 gdb_test "continue" "Breakpoint $bkptno_numopt_re, main.*" "continue across exec that changes architecture"
172 }
173
174 # Test both arch1=>arch2 and arch2=>arch1.
175 foreach_with_prefix first_arch {1 2} {
176 if {![build_executables $first_arch]} {
177 continue
178 }
179
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
183 # architecture.
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
187 }
188 }
189 }