]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.opt/inline-break.exp
Update binutils release documentation to include using the -z option when invoking...
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.opt / inline-break.exp
CommitLineData
1d506c26 1# Copyright 2012-2024 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 20standard_testfile
481860b3 21
5b362f04 22if { [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
38proc 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.
e2f62013
AB
77 append result "in $func at .*$source"
78
79 if {$i < $locs} {
80 append result ${end}
81 }
4a27f119
KS
82 }
83
84 return $result
85}
86
481860b3
GB
87#
88# func1 is a static inlined function that is called once.
89# The result should be a single-location breakpoint.
90#
91gdb_test "break func1" \
efc9d70a 92 "Breakpoint.*at.* file .*$srcfile, line.*"
481860b3
GB
93
94#
95# func2 is a non-static inlined function that is called once.
96# The result should be a breakpoint with two locations: the
97# out-of-line function and the single inlined instance.
98#
99gdb_test "break func2" \
100 "Breakpoint.*at.*func2.*\\(2 locations\\)"
101
102#
103# func3b is a static inlined function that is called once from
104# within another static inlined function. The result should be
105# a single-location breakpoint.
106#
107gdb_test "break func3b" \
efc9d70a 108 "Breakpoint.*at.* file .*$srcfile, line.*"
481860b3
GB
109
110#
111# func4b is a static inlined function that is called once from
112# within a non-static inlined function. The result should be
113# a breakpoint with two locations: the inlined instance within
114# the inlined call to func4a in main, and the inlined instance
115# within the out-of-line func4a.
116#
117gdb_test "break func4b" \
118 "Breakpoint.*at.*func4b.*\\(2 locations\\)"
119
120#
121# func5b is a non-static inlined function that is called once
122# from within a static inlined function. The result should be a
123# breakpoint with two locations: the out-of-line function and the
124# inlined instance within the inlined call to func5a in main.
125#
126gdb_test "break func5b" \
127 "Breakpoint.*at.*func5b.*\\(2 locations\\)"
128#
129# func6b is a non-static inlined function that is called once from
130# within another non-static inlined function. The result should be
131# a breakpoint with three locations: the out-of-line function, the
132# inlined instance within the out-of-line func6a, and the inlined
133# instance within the inlined call to func6a in main,
134#
135gdb_test "break func6b" \
136 "Breakpoint.*at.*func6b.*\\(3 locations\\)"
137
138#
139# func7b is a static inlined function that is called twice: once from
140# func7a, and once from main. The result should be a breakpoint with
141# two locations: the inlined instance within the inlined instance of
142# func7a, and the inlined instance within main.
143#
144gdb_test "break func7b" \
145 "Breakpoint.*at.*func7b.*\\(2 locations\\)"
146
147#
148# func8b is a non-static inlined function that is called twice: once
149# func8a, and once from main. The result should be a breakpoint with
150# three locations: the out-of-line function, the inlined instance
151# within the inlined instance of func7a, and the inlined instance
152# within main.
153#
154gdb_test "break func8b" \
155 "Breakpoint.*at.*func8b.*\\(3 locations\\)"
156
157#
158# func1 is a static inlined function. The result should be that no
159# symbol is found to print.
160#
161gdb_test "print func1" \
162 "No symbol \"func1\" in current context."
163
164#
165# func2 is a non-static inlined function. The result should be that
166# one symbol is found to print, and that the printed symbol is called
167# "func2". Note that this does not cover the failure case that two
168# symbols were found, but that gdb chose the out-of-line copy to
169# print, but if this was failing the "print func1" test would likely
170# fail instead.
171#
172gdb_test "print func2" \
173 "\\\$.* = {int \\(int\\)} .* <func2>"
4a27f119
KS
174
175# Test that "info break" reports the location of the breakpoints "inside"
176# the inlined functions
177
178set results(1) [break_info_1 1 -source $srcfile -func "func1"]
179set results(2) [break_info_1 2 -locs 2 -source $srcfile -func "func2"]
180set results(3) [break_info_1 3 -source $srcfile -func "func3b"]
181set results(4) [break_info_1 4 -locs 2 -source $srcfile -func "func4b"]
182set results(5) [break_info_1 5 -locs 2 -source $srcfile -func "func5b"]
183set results(6) [break_info_1 6 -locs 3 -source $srcfile -func "func6b"]
184set results(7) [break_info_1 7 -locs 2 -source $srcfile -func "func7b"]
185set results(8) [break_info_1 8 -locs 3 -source $srcfile -func "func8b"]
186
187for {set i 1} {$i <= [array size results]} {incr i} {
188 send_log "Expecting: $results($i)\n"
189 gdb_test "info break $i" $results($i)
190}
191
ddfe970e
KS
192# Test "permanent" and "temporary" breakpoints.
193foreach_with_prefix cmd [list "break" "tbreak"] {
194
195 # Start with a clean state.
196 delete_breakpoints
50441f0f 197 if {![runto_main]} {
ddfe970e
KS
198 return -1
199 }
200
201 # Assemble flags to pass to gdb_breakpoint. Lame but this is just
202 # a test suite!
203 set break_flags "message"
204 if {[string match $cmd "tbreak"]} {
205 lappend break_flags "temporary"
206 }
207
208 # Insert breakpoints for all inline_func? and not_inline_func? and check
209 # that we actually stop where we think we should.
210 for {set i 1} {$i < 4} {incr i} {
211 foreach inline {"not_inline" "inline"} {
212 eval gdb_breakpoint "${inline}_func$i" $break_flags
213 }
214 }
215
216 set ws {[\r\n\t ]+}
217 set backtrace [list "(in|at)? main"]
218 for {set i 3} {$i > 0} {incr i -1} {
219
220 foreach inline {"not_inline" "inline"} {
221
222 # Check that we stop at the correct location and print out
223 # the (possibly) inlined frames.
224 set num [gdb_get_line_number "/* ${inline}_func$i */"]
225 set pattern ".*$srcfile:$num${ws}.*$num${ws}int y = $decimal;"
226 append pattern "${ws}/\\\* ${inline}_func$i \\\*/"
227 send_log "Expecting $pattern\n"
228 gdb_continue_to_breakpoint "${inline}_func$i" $pattern
229
230 # Also check for the correct backtrace.
231 set backtrace [linsert $backtrace 0 "(in|at)?${ws}${inline}_func$i"]
232 gdb_test_sequence "bt" "bt stopped in ${inline}_func$i" $backtrace
233 }
234 }
235}
236
61b04dd0
PA
237# func_extern_caller calls func_inline_caller which calls
238# func_inline_callee. The latter two are both inline functions. Test
239# that setting a breakpoint on each of the functions reports a stop at
240# that function. This exercises the inline frame skipping logic. If
241# we set a breakpoint at function A, we want to present the stop at A,
242# even if A's entry code is an inlined call to another inline function
243# B.
244
245foreach_with_prefix func {
246 "func_extern_caller"
247 "func_inline_caller"
248 "func_inline_callee"
249} {
250 clean_restart $binfile
251
50441f0f 252 if {![runto_main]} {
61b04dd0
PA
253 continue
254 }
255
256 gdb_breakpoint $func
257 gdb_test "continue" "Breakpoint .* $func .*at .*$srcfile.*" \
258 "breakpoint hit presents stop at breakpointed function"
259}
260
991ff292
PA
261# Test setting a breakpoint in an inline function by line number and
262# by address, and that GDB presents the stop there.
263
264set line [gdb_get_line_number "break here"]
265
266with_test_prefix "line number" {
267 clean_restart $binfile
268
50441f0f 269 if {![runto_main]} {
991ff292
PA
270 continue
271 }
272
273 # Set the breakpoint by line number, and check that GDB reports
274 # the breakpoint location being the inline function.
275 gdb_test "break $srcfile:$line" ".*Breakpoint .* at .*: file .*$srcfile, line $line."
cd2bb709
PA
276
277 gdb_test "info break \$bpnum" "in func1 at .*$srcfile:$line"
278
991ff292
PA
279 gdb_test "continue" "Breakpoint .*, func1 \\(x=1\\) at .*$srcfile:$line.*break here.*" \
280 "breakpoint hit presents stop at inlined function"
281
282 # Save the PC for the following by-address test.
283 set address [get_hexadecimal_valueof "\$pc" "0"]
284}
285
286# Test setting a breakpoint in an inline function by address, and that
287# GDB presents the stop there.
288
289with_test_prefix "address" {
290
291 clean_restart $binfile
292
50441f0f 293 if {![runto_main]} {
991ff292
PA
294 continue
295 }
296
297 # Set the breakpoint by address, and check that GDB reports the
298 # breakpoint location being the inline function.
48ca5676
TV
299 gdb_test "break *$address" \
300 ".*Breakpoint .* at $address: file .*$srcfile, line $line." \
301 "set breakpoint on address"
cd2bb709
PA
302
303 gdb_test "info break \$bpnum" "in func1 at .*$srcfile:$line"
304
991ff292
PA
305 gdb_test "continue" "Breakpoint .*, func1 \\(x=1\\) at .*$srcfile:$line.*break here.*" \
306 "breakpoint hit presents stop at inlined function"
307}
308
1871a62d
AB
309with_test_prefix "check alignment" {
310
311 clean_restart $binfile
312
50441f0f 313 if {![runto_main]} {
1871a62d
AB
314 continue
315 }
316
317 gdb_test "break func4b" \
318 "Breakpoint.*at.*func4b.*\\(2 locations\\)"
319
320 set expected_line_length -1
321 gdb_test_multiple "info break \$bpnum" "xxxx" {
322 -re "Num Type Disp Enb Address What\r\n" {
323 exp_continue
324 }
325 -re "($decimal \[^\r\n\]+)<MULTIPLE>\[^\r\n\]+\r\n" {
326 if {$expected_line_length != -1} {
327 fail "multiple header lines seen"
328 }
329 set expected_line_length [string length $expect_out(1,string)]
330 exp_continue
331 }
332 -re "($decimal\.($decimal) \[^\r\n\]+)$hex\[^\r\n\]+\r\n" {
333 set len [string length $expect_out(1,string)]
334 set loc $expect_out(2,string)
335 gdb_assert {$len == $expected_line_length} \
336 "check alignment of location line $loc"
337 exp_continue
338 }
339 -re "$gdb_prompt $" {
340 }
341 }
342}
343
4a27f119 344unset -nocomplain results