advance-until-multiple-locations.exp revision 1.1 1 # Copyright 2020 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 # Test 'advance/until LINESPEC' where LINESPEC expands to multiple
17 # locations.
18
19 standard_testfile .cc
20
21 if { [skip_cplus_tests] } { continue }
22
23 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
24 {debug c++}] } {
25 return -1
26 }
27
28 set lineno [gdb_get_line_number "multiple locations here"]
29
30 # advance/until to an inlined line number, which has been inlined
31 # multiple times, when the program is stopped at the same inlined
32 # function.
33 proc_with_prefix until_advance_lineno_from_inlined {cmd} {
34 global lineno
35
36 if ![runto test] {
37 fail "can't run to test"
38 return
39 }
40
41 gdb_breakpoint $lineno
42 gdb_continue_to_breakpoint "break here"
43
44 set lineno2 [expr $lineno + 1]
45
46 gdb_test "$cmd $lineno2" \
47 "inline_func .* at .*:$lineno2.*return i.*" \
48 "$cmd line number"
49 }
50
51 # advance/until to a line number, which has been inlined multiple
52 # times, when the program is stopped at a non-inlined function.
53
54 proc_with_prefix until_advance_lineno_from_non_inlined {cmd} {
55 global lineno
56
57 if ![runto test] {
58 fail "can't run to test"
59 return
60 }
61
62 gdb_test "$cmd $lineno" \
63 "inline_func .* at .*:$lineno.*multiple locations here.*" \
64 "$cmd line number"
65 }
66
67 # Test advancing to an inlined function, which has been inlined
68 # multiple times.
69
70 proc_with_prefix until_advance_inline_func {cmd} {
71 global lineno
72
73 if ![runto test] {
74 fail "can't run to test"
75 return
76 }
77
78 gdb_test "$cmd inline_func" \
79 "inline_func .* at .*:$lineno.*multiple locations here.*"
80 }
81
82 # Test advancing to an overloaded function, which is another form of a
83 # linespec expanding to multiple locations. GDB will stop at the
84 # first overload called.
85
86 proc_with_prefix advance_overload {} {
87 global lineno
88
89 if ![runto test] {
90 fail "can't run to test"
91 return
92 }
93
94 # Test that advance stops at the first overload called by the
95 # program.
96
97 gdb_test "advance ovld_func" \
98 "ovld_func .* at .*global = 1.*" \
99 "first advance stops at ovld_func()"
100
101 # Now test that advance also stops at the other overload called by
102 # the program.
103
104 # Need to issue the advance twice, because advance also stops upon
105 # exit from the current stack frame.
106 gdb_test "advance ovld_func" \
107 "test \\(\\) at .*" \
108 "second advance stops at caller"
109
110 gdb_test "advance ovld_func" \
111 "ovld_func .* at .*global = 2.*" \
112 "third advance stops at ovld_func(int)"
113 }
114
115 # Test "until" to an overloaded function, which is another form of a
116 # linespec expanding to multiple locations. Unlike "advance", "until"
117 # only stops if still in the same frame. Since the overloaded
118 # function is a different frame, the program should stop at the caller
119 # frame instead.
120
121 proc_with_prefix until_overload {} {
122 global lineno
123
124 if ![runto test] {
125 fail "can't run to test"
126 return
127 }
128
129 # ovld_func is a different frame, so it shouldn't cause a stop.
130 # Instead, the program should stop at the caller frame.
131 gdb_test "until ovld_func" \
132 "main \\(\\) at .*"
133 }
134
135 foreach_with_prefix cmd {"until" "advance"} {
136 until_advance_lineno_from_inlined $cmd
137 until_advance_lineno_from_non_inlined $cmd
138 until_advance_inline_func $cmd
139 }
140
141 advance_overload
142 until_overload
143