1 # Copyright
2008-2022 Free Software Foundation
, Inc.
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.
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.
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
/>.
16 load_lib mi
-support.exp
19 standard_testfile .c inline
-markers.c
21 if {[prepare_for_testing
"failed to prepare" $testfile \
22 [list $srcfile $srcfile2
] {debug additional_flags
=-Winline
}]} {
26 gdb_test_no_output
"set listsize 1"
32 if { [skip_inline_frame_tests
] } {
33 untested
"skipping inline frame tests"
37 # First
, check that the things we expected to be inlined really were
,
38 # and those that shouldn
't be weren't.
39 set line1
[gdb_get_line_number
"set breakpoint 1 here" ${srcfile2}]
40 gdb_breakpoint $srcfile2
:$line1
41 set line2
[gdb_get_line_number
"set breakpoint 2 here" ${srcfile2}]
42 gdb_breakpoint $srcfile2
:$line2
44 gdb_test
"continue" ".*set breakpoint 1 here.*" "continue to bar (1)"
45 gdb_test
"backtrace" "#0 bar.*#1 .*func1.*#2 .*main.*" \
46 "backtrace from bar (1)"
47 gdb_test
"up" "#1 .*func1.*" "up from bar (1)"
48 gdb_test
"info frame" ".*inlined into frame.*" "func1 inlined (1)"
50 gdb_test
"continue" ".*set breakpoint 1 here.*" "continue to bar (2)"
51 gdb_test
"backtrace" "#0 bar.*#1 .*func1.*#2 .*func2.*#3 .*main.*" \
52 "backtrace from bar (2)"
53 gdb_test
"up" "#1 .*func1.*" "up from bar (2)"
54 gdb_test
"info frame" ".*inlined into frame.*" "func1 inlined (2)"
55 gdb_test
"up" "#2 .*func2.*" "up from func1 (2)"
56 gdb_test
"info frame" ".*inlined into frame.*" "func2 inlined (2)"
58 gdb_test
"continue" ".*set breakpoint 2 here.*" "continue to marker"
59 gdb_test
"backtrace" "#0 marker.*#1 .*main.*" "backtrace from marker"
60 gdb_test
"info frame" ".*called by frame.*" "marker not inlined"
62 # Next
, check that we can next over inlined functions. We should not end up
67 # The lines before the first inlined
call.
68 set first
"x = 7|y = 8"
70 # Some extra lines that end up in our stepping due to code motion.
71 set opt
"start of main|result = 0"
73 # We start this test with a
"list" instead of a "next", in case the
74 # first non
-prologue instruction in main comes from the inlined function.
75 set msg
"next over inlined functions"
76 gdb_test_multiple
"list" $msg {
77 -re
"($first|result = func1|result = func2|$opt).*$gdb_prompt $" {
81 -re
"marker \\\(\\\);\r\n$gdb_prompt $" {
86 # Check that when next shows the
call of func1
, it has not happened yet.
89 # Like the
return value of gdb_test
: -1 something is wrong
, 0 passed
, 1 failed.
94 set last_was_func1_call
0
95 set msg
"next past inlined func1"
96 gdb_test_multiple
"list" $msg {
97 -re
"($first|$opt).*$gdb_prompt $" {
98 set last_was_func1_call
0
102 -re
"result = func1 \\\(\\\);\r\n$gdb_prompt $" {
103 # Check whether x has been
set.
If 0, we may be doing something
104 #
else associated with this line besides the inlined
call - e.g.
105 # loading the address of result.
If 7, we may be at the
call site.
106 #
If 15, though
, we might be past the
call and
back at the store to
107 # result
- that
's OK, as long as we weren't just here
(see
110 gdb_test_multiple
"print x" "" {
111 -re
"\\\$$decimal = (\[0-9\]*)\r\n$gdb_prompt $" {
112 set x_val $expect_out
(1,string
)
114 -re
"$gdb_prompt $" { }
116 if { $x_val
== 0 || $x_val
== 7 } {
117 if { $x_test
!= 1 } {
120 } elseif
{ $x_val
== 15 } {
121 if { $func1_step
== -1 } {
122 # We passed func1 without stopping at the
call site.
129 # func1 should not
show up
on backtraces
if we are at its
call
131 if { $bt_test
!= 1 } {
132 set bt_test
[gdb_test
"backtrace" "#0 \[^#]*main.*" ""]
135 # When we next over func1
, we should not
return to the same
136 # line. But we might go past the line
, according to source
137 # code order
, and
then come
back. A valid but odd layout is
138 # body of func1
, load result
's address into a register using
139 # the source location of "result = 0" several lines down, and
140 # then return to this line for the store. GCC 4.3 does that
142 if { $last_was_func1_call } {
144 } elseif { $func1_step == -1 } {
147 set last_was_func1_call 1
153 -re "result = func2 \\\(\\\);\r\n$gdb_prompt $" {
158 if { $x_test == 0 } {
159 pass "print x before func1"
161 fail "print x before func1"
164 if { $bt_test == 0 } {
165 pass "backtrace does not include func1"
167 fail "backtrace does not include func1"
170 if { $bt_test == 0 } {
171 pass "stepped over call to func1"
173 fail "stepped over call to func1"
176 # Next, check that we can single step into inlined functions. We should always
177 # "stop" at the call sites before entering them.
180 set msg "step into func1"
182 gdb_test_multiple "list" $msg {
183 -re "($first|$opt).*$gdb_prompt $" {
187 -re "result = func1.*$gdb_prompt $" {
192 -re "func1 \\\(\\\) at .*\r\n$decimal.*bar \\\(\\\);\r\n$gdb_prompt $" {
193 if { $saw_call_site } {
201 # Check finish out of an inlined function.
202 set msg "finish from func1"
203 gdb_test_multiple "finish" $msg {
204 -re "result = func1 \\\(\\\);\r\n$gdb_prompt $" {
207 -re "($first|$opt).*$gdb_prompt $" {
208 # Whoops. We finished, but ended up back at an earlier line. Keep
213 -re "func1 \\\(\\\) at .*\r\n$decimal.*bar \\\(\\\);\r\n$gdb_prompt $" {
219 # Test some corner cases involving consecutive inlined functions.
220 set line3 [gdb_get_line_number "set breakpoint 3 here"]
221 gdb_breakpoint $line3
222 gdb_continue_to_breakpoint "consecutive func1"
224 gdb_test "next" ".*func1 .*first call.*" "next to first func1"
225 gdb_test "next" ".*func1 .*second call.*" "next to second func1"
227 # It is easier when the two inlined functions are not on the same line.
228 set line4 [gdb_get_line_number "set breakpoint 4 here"]
229 gdb_breakpoint $line4
230 gdb_continue_to_breakpoint "func1 then func3"
232 gdb_test "next" ".*func1 \\\(\\\);" "next to func1 before func3"
233 gdb_test "next" ".*func3 \\\(\\\);" "next to func3"
235 # Test finishing out of one thing and into another.
236 set line5 [gdb_get_line_number "set breakpoint 5 here"]
237 gdb_breakpoint $line5
238 gdb_continue_to_breakpoint "finish into func1"
240 gdb_test "next" ".*marker \\\(\\\);" "next to finish marker"
241 gdb_test "step" ".*set breakpoint 2 here.*" "step into finish marker"
243 # Some architectures will have one or more instructions after
244 # the call instruction which still are part of the call sequence,
245 # so it should be expected to return to the caller line after issue
246 # a 'finish
' command.
247 gdb_test_multiple "finish" "finish from marker" {
248 -re "func1 \\\(\\\);.*\r\n$gdb_prompt $" {
249 pass "finish from marker to func1"
251 -re "marker \\\(\\\);.*\r\n$gdb_prompt $" {
252 pass "finish from marker"
253 gdb_test "step" "func1 \\\(\\\);.*" "step after marker to reach func1"
257 gdb_test "step" "bar \\\(\\\);" "step into func1 for finish"
258 gdb_test "finish" "func3 \\\(\\\);" "finish from func1 to func3"
260 # Test a deeper call stack.
261 set line6 [gdb_get_line_number "set breakpoint 6 here"]
262 gdb_breakpoint $line6
263 gdb_continue_to_breakpoint "before the outer_inline call"
264 gdb_test "step" "marker \\\(\\\) at .*" "reach 1 the outer_inline call"
265 gdb_test_multiple "finish" "finish from marker" {
266 -re "main \\\(\\\) at .*outer_inline2 \\\(\\\);.*\r\n$gdb_prompt $" {
267 pass "reach outer_inline2"
269 -re "main \\\(\\\) at .*marker \\\(\\\);.*\r\n$gdb_prompt $" {
270 pass "finish from marker"
271 gdb_test "step" "outer_inline2 \\\(\\\);.*" "step after marker to reach outer_inline2"
274 gdb_test "bt" "#0 main.*" "backtrace at main of outer_inline"
275 gdb_test "step" "outer_inline2 \\\(\\\) at .*" "enter outer_inline2"
276 gdb_test "bt" "#0 outer_inline2.*#1 main.*" "backtrace at outer_inline2"
277 gdb_test "step" "outer_inline1 \\\(\\\) at .*" "enter outer_inline1 from outer_inline2"
279 set msg "backtrace at outer_inline1"
280 gdb_test_multiple "bt" $msg {
281 -re "#0 outer_inline1.*#1 outer_inline2.*#2 main.*$gdb_prompt $" {
284 -re "#0 $hex in outer_inline1.*#1 outer_inline2.*#2 main.*$gdb_prompt $" {
285 # Binutils PR gas/6717. Gas moves .loc past .p2align and the
286 # leading nop of the inlined call appears to be on the same line
287 # as main's
call to marker.
289 gdb_test
"step" "noinline \\\(\\\);" "step to call of noinline"
293 gdb_test
"step" "noinline \\\(\\\) at .*" "enter noinline from outer_inline1"
294 gdb_test
"bt" "#0 noinline.*#1 .*outer_inline1.*#2 .*outer_inline2.*#3 main.*" "backtrace at noinline from outer_inline1"
295 gdb_test
"step" "inlined_fn \\\(\\\) at .*" "enter inlined_fn from noinline"
296 gdb_test
"bt" "#0 inlined_fn.*#1 noinline.*#2 .*outer_inline1.*#3 .*outer_inline2.*#4 main.*" "backtrace at inlined_fn from noinline"
297 gdb_test
"info frame" ".*inlined into frame.*" "inlined_fn from noinline inlined"
298 gdb_test
"up" "#1 noinline.*" "up to noinline"
299 gdb_test
"info frame" ".*\n called by frame.*" "noinline from outer_inline1 not inlined"
300 gdb_test
"up" "#2 .*outer_inline1.*" "up to outer_inline1"
301 gdb_test
"info frame" ".*inlined into frame.*" "outer_inline1 inlined"
302 gdb_test
"up" "#3 .*outer_inline2.*" "up to outer_inline2"
303 gdb_test
"info frame" ".*inlined into frame.*" "outer_inline2 inlined"
304 gdb_test
"up" "#4 main.*" "up from outer_inline2"
305 gdb_test
"info frame" ".*\n caller of frame.*" "main not inlined"
309 # Send a CLI
"step" command over MI. CLI_OUTPUT_RE is a regexp that
310 # matches the expected CLI output. MESSAGE is used as test message.
312 proc mi_cli_step
{cli_output_re message
} {
317 send_gdb
"interpreter-exec console \"step\"\n"
319 -re
"\\^running\r\n\\*running,thread-id=\"all\"\r\n${mi_gdb_prompt}${cli_output_re}" {
323 fail
"$message (timeout)"
326 fail
"$message (eof)"
330 # mi_expect_stop handles
"set mi-async on/off" differences.
331 mi_expect_stop
"end-stepping-range" "\[^\r\n\]*" "" ".*$srcfile" "$decimal" \
332 "" "got *stopped for $message"
335 # Test that stepping into an inlined function with the CLI
"step"
336 # command run
while the top interpreter is MI results in the expected
337 # CLI output sent to MI
's console.
338 with_test_prefix "mi" {
342 mi_gdb_load ${binfile}
345 set line_number [gdb_get_line_number "set mi break here"]
346 mi_gdb_test "-break-insert ${srcfile}:${line_number}" \
347 {\^done,bkpt=.number="2",type="breakpoint".*\}} \
350 mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*" ".*" \
351 { "" "disp=\"keep\"" } "breakpoint hit"
355 # Step to the line that does an inline call.
356 set re "~\"$line_number\\\\t result = func1 \\(\\);\\\\n\"\r\n"
357 mi_cli_step "${re}" "step to inline call"
359 # Step into the inlined function.
361 "~\"func1 \\(\\) at .*$srcfile:$decimal\\\\n\"" \
362 "~\"$decimal\\\\t bar \\(\\);\\\\n\"\r\n"]
363 mi_cli_step "${re}" "step into inline call"