omp-par-scope.exp revision 1.1.1.2 1 # Copyright 2017-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 file is part of the gdb testsuite.
17
18 # Tests which verify (or not) that GDB can access in-scope variables
19 # when stopped within an OpenMP parallel region.
20
21 standard_testfile
22
23 set have_nested_function_support 0
24 set opts {openmp debug}
25 if [support_nested_function_tests] {
26 lappend opts "additional_flags=-DHAVE_NESTED_FUNCTION_SUPPORT"
27 set have_nested_function_support 1
28 }
29
30 if {[prepare_for_testing "failed to prepare" $testfile $srcfile $opts]} {
31 return -1
32 }
33
34 # gdb_openmp_setup may be defined to set auto-load safe-path and possibly
35 # sysroot. These settings are required for gdb to be able to find
36 # the libgomp python plugin. (sysroot only needs to be defined for
37 # remote debugging.)
38 #
39 # This approach has both pros and cons. On the plus side, it's easy
40 # to automatically set a precise auto-load safe-path. (It's easy because
41 # the output of ldd on the binary may be examined to learn the location
42 # of libgomp.so.)
43 #
44 # However, making these settings is also a drawback due to potentially
45 # overriding settings made by a board file. Therefore, this proc
46 # is optional and will only be called if it's defined.
47
48 if {[info procs gdb_openmp_setup] != ""} {
49 if {[gdb_openmp_setup $binfile] != ""} {
50 untested "could not set up OpenMP environment"
51 return -1
52 }
53 }
54
55 if {![runto_main]} {
56 return -1
57 }
58
59 # We want to invoke setup_kfail (and in some cases setup_xfail) when
60 # GDB does not yet have support for finding the values of variables in
61 # (non-master) threads. We'll check this by looking at the output of
62 # "maint print thread-parent". If this command is undefined, then GDB
63 # does not yet have thread parent support, and it makes sense to kfail
64 # tests which won't work. It's possible for GDB to have this support,
65 # but not work. E.g. it may be the case that the plugin doesn't
66 # exist or is not found. We may eventually need to add additional
67 # constraints related to setting allow_kfail to 0. But, for the moment,
68 # this simple test should be sufficient.
69
70 set allow_kfail 1
71 gdb_test_multiple "maint print thread-parent" "maint print thread-parent" {
72 -re "Undefined maintenance print command.*$gdb_prompt" {
73 pass "maint print thread-parent (does not exist)"
74 }
75 -re "No parent found.*" {
76 pass "maint print thread-parent"
77 set allow_kfail 0
78 }
79 }
80
81 # Determine whether to xfail some of the tests based on GCC version.
82 #
83 # This may need to be tweaked somewhat. Testing shows that GCC 7.3.1
84 # needs the xfails. GCC 8.3.1 and 9.1.1 do not. The assumption made
85 # below is that all versions of gcc 8 and above won't require the
86 # XFAIL setup and that all versions of gcc 7 and below will, but it's
87 # possible that there are versions in between 7.3.1 and 8.3.1 for
88 # which this assumption is invalid.
89
90 set have_older_gcc 0
91 if {[test_compiler_info {gcc-[0-7]-*}]} {
92 set have_older_gcc 1
93 }
94
95 # maybe_setup_kfail will set up a kfail for gdb/22214 when COND holds in
96 # addition to considering the values of $have_older_gcc and $allow_kfail.
97 #
98 # When $have_older_gcc evaluates to true, setup_xfail will invoked
99 # instead.
100
101 proc maybe_setup_kfail {cond} {
102 global have_older_gcc allow_kfail
103 if {$have_older_gcc} {
104 setup_xfail *-*-*
105 } elseif {[uplevel 1 [list expr $cond]] && $allow_kfail} {
106 setup_kfail "gdb/22214" *-*-*
107 }
108 }
109
110 with_test_prefix "single_scope" {
111
112 gdb_breakpoint [gdb_get_line_number "single_scope: thread_num="]
113 gdb_breakpoint [gdb_get_line_number "single_scope: s1="]
114
115 foreach pref {"first thread" "second thread"} {
116 with_test_prefix $pref {
117 gdb_continue_to_breakpoint "at printf"
118
119 if {$have_older_gcc} { setup_xfail "*-*-*" }
120 set thread_num [get_valueof "" thread_num "unknown"]
121 if {$have_older_gcc} { setup_xfail "*-*-*" }
122 gdb_test "print s1" "= -41"
123 gdb_test "print s2" "= \[12\]02"
124 if {$have_older_gcc} { setup_xfail "*-*-*" }
125 gdb_test "print s3" "= -43"
126 gdb_test "print i1" "= 11"
127 gdb_test "print i2" "= \[12]12"
128 maybe_setup_kfail {$thread_num != 0}
129 gdb_test "print i3" "= 13"
130 }
131 }
132
133 with_test_prefix "after parallel region" {
134 gdb_continue_to_breakpoint "at printf"
135
136 gdb_test "print s1" "= -41"
137 gdb_test "print s2" "= -42"
138 gdb_test "print s3" "= -43"
139 gdb_test "print i1" "= 11"
140 gdb_test "print i2" "= 12"
141 gdb_test "print i3" "= 13"
142 }
143
144 }
145
146 with_test_prefix "multi_scope" {
147 gdb_breakpoint [gdb_get_line_number "multi_scope: thread_num="]
148 gdb_breakpoint [gdb_get_line_number "multi_scope: i01="]
149
150 foreach pref {"first thread" "second thread"} {
151 with_test_prefix $pref {
152 gdb_continue_to_breakpoint "at printf"
153
154 if {$have_older_gcc} { setup_xfail "*-*-*" }
155 set thread_num [get_valueof "" thread_num "unknown"]
156
157 gdb_test "print i01" "= 1"
158 maybe_setup_kfail {$thread_num != 0}
159 gdb_test "print i02" "= 2"
160 gdb_test "print i11" "= 11"
161 maybe_setup_kfail {$thread_num != 0}
162 gdb_test "print i12" "= 12"
163 gdb_test "print i21" "= \[12\]21"
164 maybe_setup_kfail {$thread_num != 0}
165 gdb_test "print i22" "= 22"
166 gdb_test "print file_scope_var" "= 9876"
167 }
168 }
169
170 with_test_prefix "after parallel" {
171 gdb_continue_to_breakpoint "at printf"
172
173 gdb_test "print i01" "= 1"
174 gdb_test "print i02" "= 2"
175 gdb_test "print i11" "= 11"
176 gdb_test "print i12" "= 12"
177 gdb_test "print i21" "= -21"
178 gdb_test "print i22" "= 22"
179 gdb_test "print file_scope_var" "= 9876"
180 }
181 }
182
183 # Nested functions in C are a GNU extension, so only do the nested function
184 # tests if compiling with -DHAVE_NESTED_FUNCTION_SUPPORT was successful.
185
186 if $have_nested_function_support {
187 with_test_prefix "nested_func" {
188 gdb_breakpoint [gdb_get_line_number "nested_func: tn="]
189
190 foreach call_prefix {"1st call" "2nd call"} {
191 with_test_prefix $call_prefix {
192 foreach thread_prefix {"1st thread" "2nd thread"} {
193 with_test_prefix $thread_prefix {
194 gdb_continue_to_breakpoint "at printf"
195
196 if {$have_older_gcc} { setup_xfail "*-*-*" }
197 set thread_num [get_valueof "" "tn" "unknown"]
198
199 gdb_test "print file_scope_var" "= 9876"
200 if {$have_older_gcc} { setup_xfail *-*-* }
201 gdb_test "print s1" "= -42"
202 if {$call_prefix eq "1st call"} {
203 gdb_test "print i" "= 1"
204 } else {
205 gdb_test "print i" "= 101"
206 }
207 gdb_test "print j" "= \[12\]000"
208 maybe_setup_kfail {$thread_num != 0}
209 if {$call_prefix eq "1st call"} {
210 gdb_test "print k" "= 3"
211 } else {
212 gdb_test "print k" "= 103"
213 }
214 if {$call_prefix eq "1st call"} {
215 gdb_test "print p" "= 10"
216 } else {
217 gdb_test "print p" "= 20"
218 }
219 gdb_test "print q" "= \[12\]001"
220 maybe_setup_kfail {$thread_num != 0}
221 if {$call_prefix eq "1st call"} {
222 gdb_test "print r" "= 12"
223 } else {
224 gdb_test "print r" "= 22"
225 }
226 gdb_test "print x" "= 4"
227 gdb_test "print y" "= \[12\]002"
228 maybe_setup_kfail {$thread_num != 0}
229 gdb_test "print z" "= 6"
230 if {$have_older_gcc} { setup_xfail "*-*-*" }
231 gdb_test "print tn" "= \[01\]"
232 }
233 }
234 }
235 }
236 }
237 }
238
239 with_test_prefix "nested_parallel" {
240 gdb_breakpoint [gdb_get_line_number "nested_parallel (inner threads)"]
241
242 with_test_prefix "inner_threads" {
243 foreach pref {"1st stop" "2nd stop" "3rd stop" "4th stop"} {
244 with_test_prefix $pref {
245 gdb_continue_to_breakpoint "at printf"
246
247 # Don't need setup_xfail here due to fact that num is made
248 # made known to the inner parallel region.
249 set thread_num [get_valueof "" "num" "unknown"]
250
251 if {$have_older_gcc} { setup_xfail "*-*-*" }
252 set inner_thread_num [get_valueof "" "inner_num" "unknown"]
253
254 gdb_test "print file_scope_var" "= 9876"
255 gdb_test "print num" "= \[01\]"
256 maybe_setup_kfail {$thread_num != 0 || $inner_thread_num != 0}
257 gdb_test "print i" "= 1"
258 maybe_setup_kfail {$thread_num != 0 || $inner_thread_num != 0}
259 gdb_test "print j" "= 2"
260 if {$have_older_gcc || ($inner_thread_num != 0 && $allow_kfail)} { setup_xfail *-*-* }
261 gdb_test "print l" "= 10\[24\]"
262 if {$have_older_gcc ||( $inner_thread_num != 0 && $allow_kfail)} { setup_xfail *-*-* }
263 gdb_test "print k" "= 10\[13\]"
264 }
265 }
266 }
267
268 with_test_prefix "outer_threads" {
269 gdb_breakpoint [gdb_get_line_number "nested_parallel (outer threads)"]
270
271 with_test_prefix "outer stop" {
272 gdb_continue_to_breakpoint "at printf"
273
274 if {$have_older_gcc} { setup_xfail "*-*-*" }
275 # Use get_local_valueof instead of get_valueof to avoid picking up
276 # some random 'num' in a shared library.
277 set thread_num [get_local_valueof "num" "unknown"]
278
279 gdb_test "print file_scope_var" "= 9876"
280 if {$have_older_gcc} { setup_xfail "*-*-*" }
281 gdb_test "print num" "= \[01\]"
282 maybe_setup_kfail {$thread_num != 0}
283 gdb_test "print i" "= 1"
284 maybe_setup_kfail {$thread_num != 0}
285 gdb_test "print j" "= 2"
286 gdb_test "print l" "= 10\[24\]"
287 if {$have_older_gcc} { setup_xfail "*-*-*" }
288 gdb_test "print k" "= 10\[13\]"
289 }
290 }
291 }
292