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