Home | History | Annotate | Line # | Download | only in gdb.cp
      1  1.1.1.3  christos # Copyright 2019-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 standard_testfile .cc
     17      1.1  christos 
     18  1.1.1.2  christos if {[test_compiler_info gcc*] && ![supports_statement_frontiers] } {
     19      1.1  christos     return -1
     20      1.1  christos }
     21      1.1  christos 
     22      1.1  christos # Compile the test source with USE_NEXT_INLINE_H defined (when
     23      1.1  christos # use_header is true), or not defined.
     24      1.1  christos proc do_test { use_header } {
     25      1.1  christos     global srcfile testfile
     26      1.1  christos 
     27      1.1  christos     if { $use_header } {
     28      1.1  christos 	# This test will not pass due to poor debug information
     29  1.1.1.4  christos 	# generated by GCC (at least up to 10.x).  See
     30      1.1  christos 	# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94474
     31      1.1  christos 	return
     32      1.1  christos     }
     33      1.1  christos 
     34  1.1.1.2  christos     set options {c++ debug nowarnings optimize=-O2}
     35  1.1.1.2  christos     if { [supports_statement_frontiers] } {
     36  1.1.1.2  christos 	lappend options additional_flags=-gstatement-frontiers
     37  1.1.1.2  christos     }
     38      1.1  christos     if { $use_header } {
     39      1.1  christos 	lappend options additional_flags=-DUSE_NEXT_INLINE_H
     40      1.1  christos 	set executable "$testfile-with-header"
     41      1.1  christos 	set hdrfile "step-and-next-inline.h"
     42      1.1  christos 	set prefix "use_header"
     43      1.1  christos     } else {
     44      1.1  christos 	set executable "$testfile-no-header"
     45      1.1  christos 	set hdrfile "$srcfile"
     46      1.1  christos 	set prefix "no_header"
     47      1.1  christos     }
     48      1.1  christos 
     49      1.1  christos     if { [prepare_for_testing "failed to prepare" $executable \
     50      1.1  christos 	      $srcfile $options] } {
     51      1.1  christos 	return -1
     52      1.1  christos     }
     53      1.1  christos 
     54      1.1  christos     with_test_prefix $prefix {
     55      1.1  christos 
     56  1.1.1.2  christos     set main_location [gdb_get_line_number "Beginning of main" $srcfile]
     57  1.1.1.2  christos 
     58  1.1.1.4  christos     if {![runto_main]} {
     59  1.1.1.4  christos 	return
     60  1.1.1.4  christos     }
     61  1.1.1.4  christos 
     62  1.1.1.4  christos     gdb_breakpoint tree_check
     63  1.1.1.4  christos 
     64  1.1.1.4  christos     # Check that GDB can correctly stop in `tree_check`.  On some
     65  1.1.1.4  christos     # targets. gcc will use DW_AT_ranges to represent the addresses of
     66  1.1.1.4  christos     # tree_check, and in some cases, will create an empty sub-range
     67  1.1.1.4  christos     # for some of the tree_check code.  To really confuse things, gcc
     68  1.1.1.4  christos     # will then set the DW_AT_entry_pc to point at the address of the
     69  1.1.1.4  christos     # empty sub-range.
     70  1.1.1.4  christos     #
     71  1.1.1.4  christos     # The result of this is that GDB would stop at the DW_AT_entry_pc,
     72  1.1.1.4  christos     # but then GDB would fail to realise that this address was inside
     73  1.1.1.4  christos     # tree_check.
     74  1.1.1.4  christos     for { set i 1 } { $i < 4 } { incr i } {
     75  1.1.1.4  christos 	gdb_test "continue" \
     76  1.1.1.4  christos 	    [multi_line \
     77  1.1.1.4  christos 		 "Breakpoint $::decimal\\.$i, (?:$::hex in )?tree_check \\(\[^\r\n\]+\\) at \[^\r\n\]+/$hdrfile:$::decimal" \
     78  1.1.1.4  christos 		 "$::decimal\\s+\[^\r\n\]+"] \
     79  1.1.1.4  christos 	    "stop at tree_check, $i"
     80  1.1.1.4  christos     }
     81  1.1.1.4  christos 
     82  1.1.1.4  christos     clean_restart $executable
     83  1.1.1.4  christos 
     84  1.1.1.2  christos     if ![runto $main_location qualified] {
     85      1.1  christos 	return
     86      1.1  christos     }
     87      1.1  christos 
     88      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+main.*" "in main"
     89  1.1.1.3  christos     set line1 {\t\{}
     90  1.1.1.3  christos     set line2 {\t  if \(t != NULL}
     91  1.1.1.3  christos     gdb_test_multiple "step" "step into get_alias_set" {
     92  1.1.1.3  christos 	-re -wrap $line1 {
     93  1.1.1.3  christos 	    gdb_test "next" $line2 $gdb_test_name
     94  1.1.1.3  christos 	}
     95  1.1.1.3  christos 	-re -wrap $line2 {
     96  1.1.1.3  christos 	    pass $gdb_test_name
     97  1.1.1.3  christos 	}
     98  1.1.1.3  christos     }
     99      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
    100      1.1  christos 	"not in inline 1"
    101  1.1.1.2  christos 
    102      1.1  christos     # It's possible that this first failure (when not using a header
    103      1.1  christos     # file) is GCC's fault, though the remaining failures would best
    104      1.1  christos     # be fixed by adding location views support (though it could be
    105      1.1  christos     # that some easier heuristic could be figured out).  Still, it is
    106      1.1  christos     # not certain that the first failure wouldn't also be fixed by
    107      1.1  christos     # having location view support, so for now it is tagged as such.
    108  1.1.1.2  christos     set have_kfail [expr [test_compiler_info gcc*] && !$use_header]
    109  1.1.1.2  christos 
    110  1.1.1.2  christos     set ok 1
    111  1.1.1.2  christos     gdb_test_multiple "next" "next step 1" {
    112  1.1.1.2  christos 	-re -wrap "if \\(t->x != i\\)" {
    113  1.1.1.2  christos 	    set ok 0
    114  1.1.1.2  christos 	    send_gdb "next\n"
    115  1.1.1.2  christos 	    exp_continue
    116  1.1.1.2  christos 	}
    117  1.1.1.2  christos 	-re -wrap ".*TREE_TYPE.* != 1" {
    118  1.1.1.2  christos 	    if { $ok } {
    119  1.1.1.2  christos 		pass $gdb_test_name
    120  1.1.1.2  christos 	    } else {
    121  1.1.1.2  christos 		if { $have_kfail } {
    122  1.1.1.2  christos 		    setup_kfail "*-*-*" symtab/25507
    123  1.1.1.2  christos 		}
    124  1.1.1.2  christos 		fail $gdb_test_name
    125  1.1.1.2  christos 	    }
    126  1.1.1.2  christos 	}
    127  1.1.1.2  christos     }
    128      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
    129      1.1  christos 	"not in inline 2"
    130  1.1.1.2  christos 
    131  1.1.1.2  christos     set ok 1
    132  1.1.1.2  christos     gdb_test_multiple "next" "next step 2" {
    133  1.1.1.2  christos 	-re -wrap "return x;" {
    134  1.1.1.2  christos 	    set ok 0
    135  1.1.1.2  christos 	    send_gdb "next\n"
    136  1.1.1.2  christos 	    exp_continue
    137  1.1.1.2  christos 	}
    138  1.1.1.2  christos 	-re -wrap ".*TREE_TYPE.* != 2" {
    139  1.1.1.2  christos 	    if { $ok } {
    140  1.1.1.2  christos 		pass $gdb_test_name
    141  1.1.1.2  christos 	    } else {
    142  1.1.1.2  christos 		if { $have_kfail } {
    143  1.1.1.2  christos 		    setup_kfail "*-*-*" symtab/25507
    144  1.1.1.2  christos 		}
    145  1.1.1.2  christos 		fail $gdb_test_name
    146  1.1.1.2  christos 	    }
    147  1.1.1.2  christos 	}
    148  1.1.1.2  christos     }
    149      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
    150      1.1  christos 	"not in inline 3"
    151  1.1.1.2  christos 
    152  1.1.1.2  christos     set ok 1
    153  1.1.1.2  christos     gdb_test_multiple "next" "next step 3" {
    154  1.1.1.2  christos 	-re -wrap "return x;" {
    155  1.1.1.2  christos 	    set ok 0
    156  1.1.1.2  christos 	    send_gdb "next\n"
    157  1.1.1.2  christos 	    exp_continue
    158  1.1.1.2  christos 	}
    159  1.1.1.2  christos 	-re -wrap ".*TREE_TYPE.* != 3\\)" {
    160  1.1.1.2  christos 	    if { $ok } {
    161  1.1.1.2  christos 		pass $gdb_test_name
    162  1.1.1.2  christos 	    } else {
    163  1.1.1.2  christos 		if { $have_kfail } {
    164  1.1.1.2  christos 		    setup_kfail "*-*-*" symtab/25507
    165  1.1.1.2  christos 		}
    166  1.1.1.2  christos 		fail $gdb_test_name
    167  1.1.1.2  christos 	    }
    168  1.1.1.2  christos 	}
    169  1.1.1.2  christos     }
    170      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
    171      1.1  christos 	"not in inline 4"
    172  1.1.1.2  christos 
    173  1.1.1.2  christos     set ok 1
    174  1.1.1.2  christos     gdb_test_multiple "next" "next step 4" {
    175  1.1.1.2  christos 	-re -wrap "(if \\(t != NULL|\} // get_alias_set)" {
    176  1.1.1.2  christos 	    send_gdb "next\n"
    177  1.1.1.2  christos 	    exp_continue
    178  1.1.1.2  christos 	}
    179  1.1.1.2  christos 	-re -wrap "return x;" {
    180  1.1.1.2  christos 	    set ok 0
    181  1.1.1.2  christos 	    send_gdb "next\n"
    182  1.1.1.2  christos 	    exp_continue
    183  1.1.1.2  christos 	}
    184  1.1.1.2  christos 	-re -wrap "return 0.*" {
    185  1.1.1.2  christos 	    if { $ok } {
    186  1.1.1.2  christos 		pass $gdb_test_name
    187  1.1.1.2  christos 	    } else {
    188  1.1.1.2  christos 		if { $have_kfail } {
    189  1.1.1.2  christos 		    setup_kfail "*-*-*" symtab/25507
    190  1.1.1.2  christos 		}
    191  1.1.1.2  christos 		fail $gdb_test_name
    192  1.1.1.2  christos 	    }
    193  1.1.1.2  christos 	}
    194  1.1.1.2  christos     }
    195      1.1  christos     gdb_test "bt" \
    196      1.1  christos 	"\\s*\\#0\\s+(main|get_alias_set)\[^\r\]*${srcfile}:.*" \
    197      1.1  christos 	"not in inline 5"
    198      1.1  christos 
    199      1.1  christos     if {!$use_header} {
    200      1.1  christos 	# With the debug from GCC 10.x (and earlier) GDB is currently
    201      1.1  christos 	# unable to successfully complete the following tests when we
    202      1.1  christos 	# are not using a header file.
    203      1.1  christos 	kfail symtab/25507 "stepping tests"
    204      1.1  christos 	return
    205      1.1  christos     }
    206      1.1  christos 
    207      1.1  christos     clean_restart ${executable}
    208      1.1  christos 
    209      1.1  christos     if ![runto_main] {
    210      1.1  christos 	return
    211      1.1  christos     }
    212      1.1  christos 
    213      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+main.*" "in main pass 2"
    214      1.1  christos     gdb_test "step" ".*" "step into get_alias_set pass 2"
    215      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
    216      1.1  christos 	"in get_alias_set pass 2"
    217      1.1  christos     gdb_test "step" ".*TREE_TYPE.*" "step 1"
    218      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
    219      1.1  christos 	"not in inline 1 pass 2"
    220      1.1  christos     gdb_test "step" ".*if \\(t->x != i\\).*" "step 2"
    221      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
    222      1.1  christos 	"in inline 1 pass 2"
    223      1.1  christos     gdb_test "step" ".*TREE_TYPE.*" "step 3"
    224      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
    225      1.1  christos 	"not in inline 2 pass 2"
    226      1.1  christos     gdb_test "step" ".*if \\(t->x != i\\).*" "step 4"
    227      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
    228      1.1  christos 	"in inline 2 pass 2"
    229      1.1  christos     gdb_test "step" ".*TREE_TYPE.*" "step 5"
    230      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
    231      1.1  christos 	"not in inline 3 pass 2"
    232      1.1  christos     gdb_test "step" ".*if \\(t->x != i\\).*" "step 6"
    233      1.1  christos     gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
    234      1.1  christos 	"in inline 3 pass 2"
    235      1.1  christos     gdb_test "step" "return 0.*" "step 7"
    236      1.1  christos     gdb_test "bt" \
    237      1.1  christos 	"\\s*\\#0\\s+(main|get_alias_set)\[^\r\]*${srcfile}:.*" \
    238      1.1  christos 	"not in inline 4 pass 2"
    239      1.1  christos     }
    240      1.1  christos }
    241      1.1  christos 
    242      1.1  christos do_test 0
    243      1.1  christos do_test 1
    244