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