Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.opt / inline-locals.exp
CommitLineData
88b9d363 1# Copyright 2008-2022 Free Software Foundation, Inc.
edb3359d
DJ
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
efc9d70a
TT
16standard_testfile .c inline-markers.c
17
5b362f04 18if {[prepare_for_testing "failed to prepare" $testfile \
1f960ced 19 [list $srcfile $srcfile2] {debug additional_flags=-Winline}]} {
edb3359d
DJ
20 return -1
21}
22
edb3359d
DJ
23runto_main
24
4c93b1db 25get_compiler_info
edb3359d
DJ
26get_debug_format
27if { [skip_inline_var_tests] } {
28 untested inline-bt.exp
29 return
30}
31
32set no_frames [skip_inline_frame_tests]
33
34set line1 [gdb_get_line_number "set breakpoint 1 here" ${srcfile2}]
35gdb_breakpoint $srcfile2:$line1
36
ddbb44cf 37gdb_test "continue" ".*set breakpoint 1 here.*" "continue to bar 1"
edb3359d 38
ddbb44cf 39gdb_test "continue" ".*set breakpoint 1 here.*" "continue to bar 2"
edb3359d
DJ
40
41if { ! $no_frames } {
42 gdb_test "backtrace" "#0 bar.*#1 .*func1.*#2 .*main.*" \
ddbb44cf
SM
43 "backtrace from bar 2"
44 gdb_test "up" "#1 .*func1 .* at .*" "up from bar 2"
45 gdb_test "info frame" ".*inlined into frame.*" "func1 inlined 2"
f0f9e75a 46 set pass_re "array = \\{0 <repeats 64 times>\\}"
d8c8b848 47 set kfail_re [multi_line $pass_re \
392e0bcc 48 "array = <optimized out>"]
d8c8b848
TV
49 gdb_test_multiple "info locals" "info locals above bar 2" {
50 -re -wrap $pass_re {
51 pass $gdb_test_name
52 }
53 -re -wrap $kfail_re {
54 kfail gdb/25695 $gdb_test_name
55 }
56 }
edb3359d 57
ddbb44cf 58 set msg "info args above bar 2"
edb3359d
DJ
59 gdb_test_multiple "info args" $msg {
60 -re "arg1 = $decimal\r\n$gdb_prompt $" {
61 pass $msg
62 }
585fdaa1 63 -re "arg1 = <optimized out>\r\n$gdb_prompt $" {
c38f313d
DJ
64 # GCC 4.3 and later lose location information for arg1. GCC 4.2 is OK.
65 if { [test_compiler_info "gcc-4-3-*"] || [test_compiler_info "gcc-4-4-*"]} {
edb3359d
DJ
66 setup_xfail *-*-*
67 }
68 fail $msg
69 }
70 }
71} else {
ddbb44cf
SM
72 gdb_test "up" "#1 .*main .* at .*" "up from bar 2"
73 gdb_test "info locals" ".*arg1 = 0.*" "info locals above bar 2"
edb3359d
DJ
74}
75
76# Make sure that locals on the stack are found. This is an array to
77# prevent it from living in a register.
ddbb44cf 78gdb_test "print array\[0\]" "\\\$$decimal = 0" "print local 2"
edb3359d
DJ
79
80if { ! $no_frames } {
81 # Verify that we do not print out variables from the inlined
82 # function's caller.
83 gdb_test "print val" "No symbol \"val\" in current context\\." \
84 "print out of scope local"
85}
86
87# Repeat the tests from a depth of two inlined functions, and with a
88# more interesting value in the local array.
ddbb44cf 89gdb_test "continue" ".*set breakpoint 1 here.*" "continue to bar 3"
edb3359d
DJ
90if { ! $no_frames } {
91 gdb_test "backtrace" "#0 bar.*#1 .*func1.*#2 .*func2.*#3 .*main.*" \
ddbb44cf
SM
92 "backtrace from bar 3"
93 gdb_test "up" "#1 .*func1 .* at .*" "up from bar 3"
94 gdb_test "info frame" ".*inlined into frame.*" "func1 inlined 3"
d8c8b848
TV
95 set pass_re "array = {$decimal, \[^\r\n\]*}"
96 set kfail_re [multi_line $pass_re \
392e0bcc 97 "array = <optimized out>"]
c9f3b40e 98 gdb_test_multiple "info locals" "info locals above bar 3" {
d8c8b848
TV
99 -re -wrap $pass_re {
100 pass $gdb_test_name
101 }
102 -re -wrap $kfail_re {
103 kfail gdb/25695 $gdb_test_name
104 }
105 }
edb3359d 106
ddbb44cf 107 set msg "info args above bar 3"
edb3359d
DJ
108 gdb_test_multiple "info args" $msg {
109 -re "arg1 = $decimal\r\n$gdb_prompt $" {
110 pass $msg
111 }
585fdaa1 112 -re "arg1 = <optimized out>\r\n$gdb_prompt $" {
c38f313d
DJ
113 # GCC 4.3 and later lose location information for arg1. GCC 4.2 is OK.
114 if { [test_compiler_info "gcc-4-3-*"] || [test_compiler_info "gcc-4-4-*"]} {
edb3359d
DJ
115 setup_xfail *-*-*
116 }
117 fail $msg
118 }
119 }
120} else {
ddbb44cf 121 gdb_test "up" "#1 .*main .* at .*" "up from bar 3"
edb3359d
DJ
122 gdb_test "info locals" ".*arg1 = 1.*" "info locals above bar (3a)"
123 gdb_test "info locals" ".*arg2 = 184.*" "info locals above bar (3b)"
124}
125
ddbb44cf 126gdb_test "print array\[0\]" "\\\$$decimal = 184" "print local 3"
34dc0f95
TBA
127
128# Test printing scoped local variables.
129
130proc check_scoped_locals {bp_label pass_re} {
131 global srcfile
132
133 set locals_bp [gdb_get_line_number $bp_label ${srcfile}]
134 gdb_breakpoint $srcfile:$locals_bp
135
136 gdb_continue_to_breakpoint "$bp_label" ".*$srcfile:$locals_bp.*"
137 set kfail_re [multi_line $pass_re ".*<optimized out>"]
138 gdb_test_multiple "info locals" "scoped info locals at $bp_label" {
139 -re -wrap $pass_re {
140 pass $gdb_test_name
141 }
142 -re -wrap $kfail_re {
143 if {[test_compiler_info {gcc-[0-8]-*-*}]} {
144 kfail gdb/25695 $gdb_test_name
145 } else {
146 fail $gdb_test_name
147 }
148 }
149 }
150}
151
152if {! $no_frames } {
153 check_scoped_locals "bp for locals 1" "loc2 = 20\r\nloc1 = 10"
154 check_scoped_locals "bp for locals 2" "loc3 = 30\r\nloc2 = 20\r\nloc1 = 10"
155 check_scoped_locals "bp for locals 3" "loc1 = 10"
156}
This page took 1.820335 seconds and 4 git commands to generate.