85f7b8d5af1c805f959cd23d98e0bfca3afc7eae
[binutils-gdb.git] / gdb / testsuite / gdb.cp / step-and-next-inline.exp
1 # Copyright 2019-2021 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 standard_testfile .cc
17
18 if [get_compiler_info "c++"] {
19 unsupported "couldn't find a valid c++ compiler"
20 return -1
21 }
22
23 if {[test_compiler_info gcc*] && ![supports_statement_frontiers] } {
24 return -1
25 }
26
27 # Compile the test source with USE_NEXT_INLINE_H defined (when
28 # use_header is true), or not defined.
29 proc do_test { use_header } {
30 global srcfile testfile
31
32 if { $use_header } {
33 # This test will not pass due to poor debug information
34 # generated by GCC (at least upto 10.x). See
35 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94474
36 return
37 }
38
39 set options {c++ debug nowarnings optimize=-O2}
40 if { [supports_statement_frontiers] } {
41 lappend options additional_flags=-gstatement-frontiers
42 }
43 if { $use_header } {
44 lappend options additional_flags=-DUSE_NEXT_INLINE_H
45 set executable "$testfile-with-header"
46 set hdrfile "step-and-next-inline.h"
47 set prefix "use_header"
48 } else {
49 set executable "$testfile-no-header"
50 set hdrfile "$srcfile"
51 set prefix "no_header"
52 }
53
54 if { [prepare_for_testing "failed to prepare" $executable \
55 $srcfile $options] } {
56 return -1
57 }
58
59 with_test_prefix $prefix {
60
61 if ![runto_main] {
62 fail "can't run to main"
63 return
64 }
65
66 gdb_test "bt" "\\s*\\#0\\s+main.*" "in main"
67 gdb_test "step" ".*" "step into get_alias_set"
68 gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
69 "not in inline 1"
70 # It's possible that this first failure (when not using a header
71 # file) is GCC's fault, though the remaining failures would best
72 # be fixed by adding location views support (though it could be
73 # that some easier heuristic could be figured out). Still, it is
74 # not certain that the first failure wouldn't also be fixed by
75 # having location view support, so for now it is tagged as such.
76 if {[test_compiler_info gcc*] && !$use_header} {
77 setup_kfail "*-*-*" symtab/25507
78 }
79 gdb_test "next" ".*TREE_TYPE.*" "next step 1"
80 gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
81 "not in inline 2"
82 gdb_test "next" ".*TREE_TYPE.*" "next step 2"
83 gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
84 "not in inline 3"
85 if {[test_compiler_info gcc*] && !$use_header} {
86 setup_kfail "*-*-*" symtab/25507
87 }
88 gdb_test "next" ".*TREE_TYPE.*" "next step 3"
89 gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
90 "not in inline 4"
91 if {!$use_header} { setup_kfail "*-*-*" symtab/25507 }
92 gdb_test "next" "return 0.*" "next step 4"
93 gdb_test "bt" \
94 "\\s*\\#0\\s+(main|get_alias_set)\[^\r\]*${srcfile}:.*" \
95 "not in inline 5"
96
97 if {!$use_header} {
98 # With the debug from GCC 10.x (and earlier) GDB is currently
99 # unable to successfully complete the following tests when we
100 # are not using a header file.
101 kfail symtab/25507 "stepping tests"
102 return
103 }
104
105 clean_restart ${executable}
106
107 if ![runto_main] {
108 fail "can't run to main pass 2"
109 return
110 }
111
112 gdb_test "bt" "\\s*\\#0\\s+main.*" "in main pass 2"
113 gdb_test "step" ".*" "step into get_alias_set pass 2"
114 gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
115 "in get_alias_set pass 2"
116 gdb_test "step" ".*TREE_TYPE.*" "step 1"
117 gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
118 "not in inline 1 pass 2"
119 gdb_test "step" ".*if \\(t->x != i\\).*" "step 2"
120 gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
121 "in inline 1 pass 2"
122 gdb_test "step" ".*TREE_TYPE.*" "step 3"
123 gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
124 "not in inline 2 pass 2"
125 gdb_test "step" ".*if \\(t->x != i\\).*" "step 4"
126 gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
127 "in inline 2 pass 2"
128 gdb_test "step" ".*TREE_TYPE.*" "step 5"
129 gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
130 "not in inline 3 pass 2"
131 gdb_test "step" ".*if \\(t->x != i\\).*" "step 6"
132 gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
133 "in inline 3 pass 2"
134 gdb_test "step" "return 0.*" "step 7"
135 gdb_test "bt" \
136 "\\s*\\#0\\s+(main|get_alias_set)\[^\r\]*${srcfile}:.*" \
137 "not in inline 4 pass 2"
138 }
139 }
140
141 do_test 0
142 do_test 1