Update copyright year range in all GDB files.
[binutils-gdb.git] / gdb / testsuite / gdb.threads / omp-par-scope.exp
blob16441d3ec68d2d0c2e3e92a5a919e1d32140d595
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 # This file is part of the gdb testsuite.
18 # Tests which verify (or not) that GDB can access in-scope variables
19 # when stopped within an OpenMP parallel region.
21 standard_testfile
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
30 if {[prepare_for_testing "failed to prepare" $testfile $srcfile $opts]} {
31     return -1
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.)
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.)
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.
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     }
55 if {![runto_main]} {
56     untested "could not run to main"
57     return -1
60 # We want to invoke setup_kfail (and in some cases setup_xfail) when
61 # GDB does not yet have support for finding the values of variables in
62 # (non-master) threads.  We'll check this by looking at the output of
63 # "maint print thread-parent".  If this command is undefined, then GDB
64 # does not yet have thread parent support, and it makes sense to kfail
65 # tests which won't work.  It's possible for GDB to have this support,
66 # but not work.  E.g. it may be the case that the plugin doesn't
67 # exist or is not found.  We may eventually need to add additional
68 # constraints related to setting allow_kfail to 0.  But, for the moment,
69 # this simple test should be sufficient.
71 set allow_kfail 1
72 gdb_test_multiple "maint print thread-parent" "maint print thread-parent" {
73     -re "Undefined maintenance print command.*$gdb_prompt" {
74         pass "maint print thread-parent (does not exist)"
75     }
76     -re "No parent found.*" {
77         pass "maint print thread-parent"
78         set allow_kfail 0
79     }
82 # Determine whether to xfail some of the tests based on GCC version.
84 # This may need to be tweaked somewhat.  Testing shows that GCC 7.3.1
85 # needs the xfails.  GCC 8.3.1 and 9.1.1 do not.  The assumption made
86 # below is that all versions of gcc 8 and above won't require the
87 # XFAIL setup and that all versions of gcc 7 and below will, but it's
88 # possible that there are versions in between 7.3.1 and 8.3.1 for
89 # which this assumption is invalid.
91 set have_older_gcc 0
92 if {[test_compiler_info {gcc-[0-7]-*}]} {
93     set have_older_gcc 1
96 # maybe_setup_kfail will set up a kfail for gdb/22214 when COND holds in
97 # addition to considering the values of $have_older_gcc and $allow_kfail.
99 # When $have_older_gcc evaluates to true, setup_xfail will invoked
100 # instead.
102 proc maybe_setup_kfail {cond} {
103     global have_older_gcc allow_kfail
104     if {$have_older_gcc} {
105         setup_xfail *-*-*
106     } elseif {[uplevel 1 [list expr $cond]] && $allow_kfail} {
107         setup_kfail "gdb/22214" *-*-*
108     }
111 with_test_prefix "single_scope" {
113     gdb_breakpoint [gdb_get_line_number "single_scope: thread_num="]
114     gdb_breakpoint [gdb_get_line_number "single_scope: s1="]
116     foreach pref {"first thread" "second thread"} {
117         with_test_prefix $pref {
118             gdb_continue_to_breakpoint "at printf"
120             if {$have_older_gcc} { setup_xfail "*-*-*" }
121             set thread_num [get_valueof "" thread_num "unknown"]
122             if {$have_older_gcc} { setup_xfail "*-*-*" }
123             gdb_test "print s1" "= -41"
124             gdb_test "print s2" "= \[12\]02"
125             if {$have_older_gcc} { setup_xfail "*-*-*" }
126             gdb_test "print s3" "= -43"
127             gdb_test "print i1" "= 11"
128             gdb_test "print i2" "= \[12]12"
129             maybe_setup_kfail {$thread_num != 0}
130             gdb_test "print i3" "= 13"
131         }
132     }
134     with_test_prefix "after parallel region" {
135         gdb_continue_to_breakpoint "at printf"
137         gdb_test "print s1" "= -41"
138         gdb_test "print s2" "= -42"
139         gdb_test "print s3" "= -43"
140         gdb_test "print i1" "= 11"
141         gdb_test "print i2" "= 12"
142         gdb_test "print i3" "= 13"
143     }
147 with_test_prefix "multi_scope" {
148     gdb_breakpoint [gdb_get_line_number "multi_scope: thread_num="]
149     gdb_breakpoint [gdb_get_line_number "multi_scope: i01="]
151     foreach pref {"first thread" "second thread"} {
152         with_test_prefix $pref {
153             gdb_continue_to_breakpoint "at printf"
155             if {$have_older_gcc} { setup_xfail "*-*-*" }
156             set thread_num [get_valueof "" thread_num "unknown"]
158             gdb_test "print i01" "= 1"
159             maybe_setup_kfail {$thread_num != 0}
160             gdb_test "print i02" "= 2"
161             gdb_test "print i11" "= 11"
162             maybe_setup_kfail {$thread_num != 0}
163             gdb_test "print i12" "= 12"
164             gdb_test "print i21" "= \[12\]21"
165             maybe_setup_kfail {$thread_num != 0}
166             gdb_test "print i22" "= 22"
167             gdb_test "print file_scope_var" "= 9876"
168         }
169     }
171     with_test_prefix "after parallel" {
172         gdb_continue_to_breakpoint "at printf"
174         gdb_test "print i01" "= 1"
175         gdb_test "print i02" "= 2"
176         gdb_test "print i11" "= 11"
177         gdb_test "print i12" "= 12"
178         gdb_test "print i21" "= -21"
179         gdb_test "print i22" "= 22"
180         gdb_test "print file_scope_var" "= 9876"
181     }
184 # Nested functions in C are a GNU extension, so only do the nested function
185 # tests if compiling with -DHAVE_NESTED_FUNCTION_SUPPORT was successful.
187 if $have_nested_function_support {
188     with_test_prefix "nested_func" {
189         gdb_breakpoint [gdb_get_line_number "nested_func: tn="]
191         foreach call_prefix {"1st call" "2nd call"} {
192             with_test_prefix $call_prefix {
193                 foreach thread_prefix {"1st thread" "2nd thread"} {
194                     with_test_prefix $thread_prefix {
195                         gdb_continue_to_breakpoint "at printf"
197                         if {$have_older_gcc} { setup_xfail "*-*-*" }
198                         set thread_num [get_valueof "" "tn" "unknown"]
200                         gdb_test "print file_scope_var" "= 9876"
201                         if {$have_older_gcc} { setup_xfail *-*-* }
202                         gdb_test "print s1" "= -42"
203                         if {$call_prefix eq "1st call"} {
204                             gdb_test "print i" "= 1"
205                         } else {
206                             gdb_test "print i" "= 101"
207                         }
208                         gdb_test "print j" "= \[12\]000"
209                         maybe_setup_kfail {$thread_num != 0}
210                         if {$call_prefix eq "1st call"} {
211                             gdb_test "print k" "= 3"
212                         } else {
213                             gdb_test "print k" "= 103"
214                         }
215                         if {$call_prefix eq "1st call"} {
216                             gdb_test "print p" "= 10"
217                         } else {
218                             gdb_test "print p" "= 20"
219                         }
220                         gdb_test "print q" "= \[12\]001"
221                         maybe_setup_kfail {$thread_num != 0}
222                         if {$call_prefix eq "1st call"} {
223                             gdb_test "print r" "= 12"
224                         } else {
225                             gdb_test "print r" "= 22"
226                         }
227                         gdb_test "print x" "= 4"
228                         gdb_test "print y" "= \[12\]002"
229                         maybe_setup_kfail {$thread_num != 0}
230                         gdb_test "print z" "= 6"
231                         if {$have_older_gcc} { setup_xfail "*-*-*" }
232                         gdb_test "print tn" "= \[01\]"
233                     }
234                 }
235             }
236         }
237     }
240 with_test_prefix "nested_parallel" {
241     gdb_breakpoint [gdb_get_line_number "nested_parallel (inner threads)"]
243     with_test_prefix "inner_threads" {
244         foreach pref {"1st stop" "2nd stop" "3rd stop" "4th stop"} {
245             with_test_prefix $pref {
246                 gdb_continue_to_breakpoint "at printf"
248                 # Don't need setup_xfail here due to fact that num is made
249                 # made known to the inner parallel region.
250                 set thread_num [get_valueof "" "num" "unknown"]
252                 if {$have_older_gcc} { setup_xfail "*-*-*" }
253                 set inner_thread_num [get_valueof "" "inner_num" "unknown"]
255                 gdb_test "print file_scope_var" "= 9876"
256                 gdb_test "print num" "= \[01\]"
257                 maybe_setup_kfail {$thread_num != 0 || $inner_thread_num != 0}
258                 gdb_test "print i" "= 1"
259                 maybe_setup_kfail {$thread_num != 0 || $inner_thread_num != 0}
260                 gdb_test "print j" "= 2"
261                 if {$have_older_gcc || ($inner_thread_num != 0 && $allow_kfail)} { setup_xfail *-*-* }
262                 gdb_test "print l" "= 10\[24\]"
263                 if {$have_older_gcc ||( $inner_thread_num != 0 && $allow_kfail)} { setup_xfail *-*-* }
264                 gdb_test "print k" "= 10\[13\]"
265             }
266         }
267     }
269     with_test_prefix "outer_threads" {
270         gdb_breakpoint [gdb_get_line_number "nested_parallel (outer threads)"]
272         with_test_prefix "outer stop" {
273             gdb_continue_to_breakpoint "at printf"
275             if {$have_older_gcc} { setup_xfail "*-*-*" }
276             set thread_num [get_valueof "" "num" "unknown"]
278             gdb_test "print file_scope_var" "= 9876"
279             if {$have_older_gcc} { setup_xfail "*-*-*" }
280             gdb_test "print num" "= \[01\]"
281             maybe_setup_kfail {$thread_num != 0}
282             gdb_test "print i" "= 1"
283             maybe_setup_kfail {$thread_num != 0}
284             gdb_test "print j" "= 2"
285             gdb_test "print l" "= 10\[24\]"
286             if {$have_older_gcc} { setup_xfail "*-*-*" }
287             gdb_test "print k" "= 10\[13\]"
288         }
289     }