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