]>
Commit | Line | Data |
---|---|---|
213516ef | 1 | # Copyright 2012-2023 Free Software Foundation, Inc. |
481860b3 GB |
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 | # Note that the testcase gdb.dwarf2/dw2-inline-break.exp largely | |
17 | # mirrors this testcase, and should be updated if this testcase is | |
18 | # changed. | |
19 | ||
efc9d70a | 20 | standard_testfile |
481860b3 | 21 | |
5b362f04 | 22 | if { [prepare_for_testing "failed to prepare" $testfile $srcfile \ |
1f960ced | 23 | {debug additional_flags=-Winline}] } { |
481860b3 GB |
24 | return -1 |
25 | } | |
26 | ||
4a27f119 KS |
27 | # Return a string that may be used to match the output of "info break NUM". |
28 | # | |
29 | # Optional arguments: | |
30 | # | |
31 | # source - the name of the source file | |
32 | # func - the name of the function | |
33 | # disp - the event disposition | |
34 | # enabled - enable state | |
35 | # locs - number of locations | |
36 | # line - source line number (ignored without -source) | |
37 | ||
38 | proc break_info_1 {num args} { | |
39 | global decimal | |
40 | ||
41 | # Column delimiter | |
42 | set c {[\t ]+} | |
43 | ||
44 | # Row delimiter | |
45 | set end {[\r\n \t]+} | |
46 | ||
47 | # Table header | |
48 | set header "[join [list Num Type Disp Enb Address What] ${c}]" | |
49 | ||
50 | # Get/configure any optional parameters. | |
51 | parse_args [list {source ""} {func ".*"} {disp "keep"} \ | |
52 | {enabled "y"} {locs 1} [list line $decimal] \ | |
53 | {type "breakpoint"}] | |
54 | ||
55 | if {$source != ""} { | |
56 | set source "$source:$line" | |
57 | } | |
58 | ||
59 | # Result starts with the standard header. | |
60 | set result "$header${end}" | |
61 | ||
62 | # Set up for multi-location breakpoint marker. | |
63 | if {$locs == 1} { | |
64 | set multi ".*" | |
65 | } else { | |
66 | set multi "<MULTIPLE>${end}" | |
67 | } | |
68 | append result "[join [list $num $type $disp $enabled $multi] $c]" | |
69 | ||
70 | # Add location info. | |
71 | for {set i 1} {$i <= $locs} {incr i} { | |
72 | if {$locs > 1} { | |
73 | append result "[join [list $num.$i $enabled] $c].*" | |
74 | } | |
75 | ||
76 | # Add function/source file info. | |
77 | append result "in $func at .*$source${end}" | |
78 | } | |
79 | ||
80 | return $result | |
81 | } | |
82 | ||
481860b3 GB |
83 | # |
84 | # func1 is a static inlined function that is called once. | |
85 | # The result should be a single-location breakpoint. | |
86 | # | |
87 | gdb_test "break func1" \ | |
efc9d70a | 88 | "Breakpoint.*at.* file .*$srcfile, line.*" |
481860b3 GB |
89 | |
90 | # | |
91 | # func2 is a non-static inlined function that is called once. | |
92 | # The result should be a breakpoint with two locations: the | |
93 | # out-of-line function and the single inlined instance. | |
94 | # | |
95 | gdb_test "break func2" \ | |
96 | "Breakpoint.*at.*func2.*\\(2 locations\\)" | |
97 | ||
98 | # | |
99 | # func3b is a static inlined function that is called once from | |
100 | # within another static inlined function. The result should be | |
101 | # a single-location breakpoint. | |
102 | # | |
103 | gdb_test "break func3b" \ | |
efc9d70a | 104 | "Breakpoint.*at.* file .*$srcfile, line.*" |
481860b3 GB |
105 | |
106 | # | |
107 | # func4b is a static inlined function that is called once from | |
108 | # within a non-static inlined function. The result should be | |
109 | # a breakpoint with two locations: the inlined instance within | |
110 | # the inlined call to func4a in main, and the inlined instance | |
111 | # within the out-of-line func4a. | |
112 | # | |
113 | gdb_test "break func4b" \ | |
114 | "Breakpoint.*at.*func4b.*\\(2 locations\\)" | |
115 | ||
116 | # | |
117 | # func5b is a non-static inlined function that is called once | |
118 | # from within a static inlined function. The result should be a | |
119 | # breakpoint with two locations: the out-of-line function and the | |
120 | # inlined instance within the inlined call to func5a in main. | |
121 | # | |
122 | gdb_test "break func5b" \ | |
123 | "Breakpoint.*at.*func5b.*\\(2 locations\\)" | |
124 | # | |
125 | # func6b is a non-static inlined function that is called once from | |
126 | # within another non-static inlined function. The result should be | |
127 | # a breakpoint with three locations: the out-of-line function, the | |
128 | # inlined instance within the out-of-line func6a, and the inlined | |
129 | # instance within the inlined call to func6a in main, | |
130 | # | |
131 | gdb_test "break func6b" \ | |
132 | "Breakpoint.*at.*func6b.*\\(3 locations\\)" | |
133 | ||
134 | # | |
135 | # func7b is a static inlined function that is called twice: once from | |
136 | # func7a, and once from main. The result should be a breakpoint with | |
137 | # two locations: the inlined instance within the inlined instance of | |
138 | # func7a, and the inlined instance within main. | |
139 | # | |
140 | gdb_test "break func7b" \ | |
141 | "Breakpoint.*at.*func7b.*\\(2 locations\\)" | |
142 | ||
143 | # | |
144 | # func8b is a non-static inlined function that is called twice: once | |
145 | # func8a, and once from main. The result should be a breakpoint with | |
146 | # three locations: the out-of-line function, the inlined instance | |
147 | # within the inlined instance of func7a, and the inlined instance | |
148 | # within main. | |
149 | # | |
150 | gdb_test "break func8b" \ | |
151 | "Breakpoint.*at.*func8b.*\\(3 locations\\)" | |
152 | ||
153 | # | |
154 | # func1 is a static inlined function. The result should be that no | |
155 | # symbol is found to print. | |
156 | # | |
157 | gdb_test "print func1" \ | |
158 | "No symbol \"func1\" in current context." | |
159 | ||
160 | # | |
161 | # func2 is a non-static inlined function. The result should be that | |
162 | # one symbol is found to print, and that the printed symbol is called | |
163 | # "func2". Note that this does not cover the failure case that two | |
164 | # symbols were found, but that gdb chose the out-of-line copy to | |
165 | # print, but if this was failing the "print func1" test would likely | |
166 | # fail instead. | |
167 | # | |
168 | gdb_test "print func2" \ | |
169 | "\\\$.* = {int \\(int\\)} .* <func2>" | |
4a27f119 KS |
170 | |
171 | # Test that "info break" reports the location of the breakpoints "inside" | |
172 | # the inlined functions | |
173 | ||
174 | set results(1) [break_info_1 1 -source $srcfile -func "func1"] | |
175 | set results(2) [break_info_1 2 -locs 2 -source $srcfile -func "func2"] | |
176 | set results(3) [break_info_1 3 -source $srcfile -func "func3b"] | |
177 | set results(4) [break_info_1 4 -locs 2 -source $srcfile -func "func4b"] | |
178 | set results(5) [break_info_1 5 -locs 2 -source $srcfile -func "func5b"] | |
179 | set results(6) [break_info_1 6 -locs 3 -source $srcfile -func "func6b"] | |
180 | set results(7) [break_info_1 7 -locs 2 -source $srcfile -func "func7b"] | |
181 | set results(8) [break_info_1 8 -locs 3 -source $srcfile -func "func8b"] | |
182 | ||
183 | for {set i 1} {$i <= [array size results]} {incr i} { | |
184 | send_log "Expecting: $results($i)\n" | |
185 | gdb_test "info break $i" $results($i) | |
186 | } | |
187 | ||
ddfe970e KS |
188 | # Test "permanent" and "temporary" breakpoints. |
189 | foreach_with_prefix cmd [list "break" "tbreak"] { | |
190 | ||
191 | # Start with a clean state. | |
192 | delete_breakpoints | |
50441f0f | 193 | if {![runto_main]} { |
ddfe970e KS |
194 | return -1 |
195 | } | |
196 | ||
197 | # Assemble flags to pass to gdb_breakpoint. Lame but this is just | |
198 | # a test suite! | |
199 | set break_flags "message" | |
200 | if {[string match $cmd "tbreak"]} { | |
201 | lappend break_flags "temporary" | |
202 | } | |
203 | ||
204 | # Insert breakpoints for all inline_func? and not_inline_func? and check | |
205 | # that we actually stop where we think we should. | |
206 | for {set i 1} {$i < 4} {incr i} { | |
207 | foreach inline {"not_inline" "inline"} { | |
208 | eval gdb_breakpoint "${inline}_func$i" $break_flags | |
209 | } | |
210 | } | |
211 | ||
212 | set ws {[\r\n\t ]+} | |
213 | set backtrace [list "(in|at)? main"] | |
214 | for {set i 3} {$i > 0} {incr i -1} { | |
215 | ||
216 | foreach inline {"not_inline" "inline"} { | |
217 | ||
218 | # Check that we stop at the correct location and print out | |
219 | # the (possibly) inlined frames. | |
220 | set num [gdb_get_line_number "/* ${inline}_func$i */"] | |
221 | set pattern ".*$srcfile:$num${ws}.*$num${ws}int y = $decimal;" | |
222 | append pattern "${ws}/\\\* ${inline}_func$i \\\*/" | |
223 | send_log "Expecting $pattern\n" | |
224 | gdb_continue_to_breakpoint "${inline}_func$i" $pattern | |
225 | ||
226 | # Also check for the correct backtrace. | |
227 | set backtrace [linsert $backtrace 0 "(in|at)?${ws}${inline}_func$i"] | |
228 | gdb_test_sequence "bt" "bt stopped in ${inline}_func$i" $backtrace | |
229 | } | |
230 | } | |
231 | } | |
232 | ||
61b04dd0 PA |
233 | # func_extern_caller calls func_inline_caller which calls |
234 | # func_inline_callee. The latter two are both inline functions. Test | |
235 | # that setting a breakpoint on each of the functions reports a stop at | |
236 | # that function. This exercises the inline frame skipping logic. If | |
237 | # we set a breakpoint at function A, we want to present the stop at A, | |
238 | # even if A's entry code is an inlined call to another inline function | |
239 | # B. | |
240 | ||
241 | foreach_with_prefix func { | |
242 | "func_extern_caller" | |
243 | "func_inline_caller" | |
244 | "func_inline_callee" | |
245 | } { | |
246 | clean_restart $binfile | |
247 | ||
50441f0f | 248 | if {![runto_main]} { |
61b04dd0 PA |
249 | continue |
250 | } | |
251 | ||
252 | gdb_breakpoint $func | |
253 | gdb_test "continue" "Breakpoint .* $func .*at .*$srcfile.*" \ | |
254 | "breakpoint hit presents stop at breakpointed function" | |
255 | } | |
256 | ||
991ff292 PA |
257 | # Test setting a breakpoint in an inline function by line number and |
258 | # by address, and that GDB presents the stop there. | |
259 | ||
260 | set line [gdb_get_line_number "break here"] | |
261 | ||
262 | with_test_prefix "line number" { | |
263 | clean_restart $binfile | |
264 | ||
50441f0f | 265 | if {![runto_main]} { |
991ff292 PA |
266 | continue |
267 | } | |
268 | ||
269 | # Set the breakpoint by line number, and check that GDB reports | |
270 | # the breakpoint location being the inline function. | |
271 | gdb_test "break $srcfile:$line" ".*Breakpoint .* at .*: file .*$srcfile, line $line." | |
cd2bb709 PA |
272 | |
273 | gdb_test "info break \$bpnum" "in func1 at .*$srcfile:$line" | |
274 | ||
991ff292 PA |
275 | gdb_test "continue" "Breakpoint .*, func1 \\(x=1\\) at .*$srcfile:$line.*break here.*" \ |
276 | "breakpoint hit presents stop at inlined function" | |
277 | ||
278 | # Save the PC for the following by-address test. | |
279 | set address [get_hexadecimal_valueof "\$pc" "0"] | |
280 | } | |
281 | ||
282 | # Test setting a breakpoint in an inline function by address, and that | |
283 | # GDB presents the stop there. | |
284 | ||
285 | with_test_prefix "address" { | |
286 | ||
287 | clean_restart $binfile | |
288 | ||
50441f0f | 289 | if {![runto_main]} { |
991ff292 PA |
290 | continue |
291 | } | |
292 | ||
293 | # Set the breakpoint by address, and check that GDB reports the | |
294 | # breakpoint location being the inline function. | |
48ca5676 TV |
295 | gdb_test "break *$address" \ |
296 | ".*Breakpoint .* at $address: file .*$srcfile, line $line." \ | |
297 | "set breakpoint on address" | |
cd2bb709 PA |
298 | |
299 | gdb_test "info break \$bpnum" "in func1 at .*$srcfile:$line" | |
300 | ||
991ff292 PA |
301 | gdb_test "continue" "Breakpoint .*, func1 \\(x=1\\) at .*$srcfile:$line.*break here.*" \ |
302 | "breakpoint hit presents stop at inlined function" | |
303 | } | |
304 | ||
1871a62d AB |
305 | with_test_prefix "check alignment" { |
306 | ||
307 | clean_restart $binfile | |
308 | ||
50441f0f | 309 | if {![runto_main]} { |
1871a62d AB |
310 | continue |
311 | } | |
312 | ||
313 | gdb_test "break func4b" \ | |
314 | "Breakpoint.*at.*func4b.*\\(2 locations\\)" | |
315 | ||
316 | set expected_line_length -1 | |
317 | gdb_test_multiple "info break \$bpnum" "xxxx" { | |
318 | -re "Num Type Disp Enb Address What\r\n" { | |
319 | exp_continue | |
320 | } | |
321 | -re "($decimal \[^\r\n\]+)<MULTIPLE>\[^\r\n\]+\r\n" { | |
322 | if {$expected_line_length != -1} { | |
323 | fail "multiple header lines seen" | |
324 | } | |
325 | set expected_line_length [string length $expect_out(1,string)] | |
326 | exp_continue | |
327 | } | |
328 | -re "($decimal\.($decimal) \[^\r\n\]+)$hex\[^\r\n\]+\r\n" { | |
329 | set len [string length $expect_out(1,string)] | |
330 | set loc $expect_out(2,string) | |
331 | gdb_assert {$len == $expected_line_length} \ | |
332 | "check alignment of location line $loc" | |
333 | exp_continue | |
334 | } | |
335 | -re "$gdb_prompt $" { | |
336 | } | |
337 | } | |
338 | } | |
339 | ||
4a27f119 | 340 | unset -nocomplain results |