]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.dwarf2/implptr.exp
[gdb/testsuite] Use require in gdb.dwarf2/implptr.exp
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / implptr.exp
CommitLineData
213516ef 1# Copyright 2010-2023 Free Software Foundation, Inc.
8cf6f0b1
TT
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/>.
810cfdbb 15load_lib dwarf.exp
8cf6f0b1
TT
16
17# Test DW_OP_GNU_implicit_pointer.
18
19# This test can only be run on targets which support DWARF-2 and use gas.
ce8d533e 20require dwarf2_support
8cf6f0b1 21
09ea7c9c
TV
22# This test can only be run on x86 targets.
23require is_x86_like_target
24
c83ee902 25standard_testfile .S
8cf6f0b1 26set csrcfile ${testfile}.c
0e37a63c
JK
27set opts {}
28
29if [info exists COMPILE] {
30 # make check RUNTESTFLAGS='gdb.dwarf2/implptr.exp COMPILE=1 CC_FOR_TARGET=gcc\ -m32'
31 set srcfile ${csrcfile}
32 lappend opts debug optimize=-O2
0e37a63c 33}
8cf6f0b1 34
5b362f04 35if {[prepare_for_testing "failed to prepare" ${testfile} $srcfile $opts]} {
8cf6f0b1
TT
36 return -1
37}
38
918dd910 39# Additional test to verify the referenced CU is not aged out.
b4f54984 40gdb_test_no_output "maintenance set dwarf max-cache-age 0"
918dd910 41
8cf6f0b1
TT
42if ![runto_main] {
43 return -1
44}
45
46# Test various pointer depths in bar.
47proc implptr_test_bar {} {
48 global csrcfile
49 set line [gdb_get_line_number "bar breakpoint" $csrcfile]
50 gdb_test "break implptr.c:$line" "Breakpoint 2.*" \
51 "set bar breakpoint for implptr"
52 gdb_continue_to_breakpoint "continue to bar breakpoint for implptr"
0e37a63c 53 gdb_test "print j" " = \\(intp\\) <synthetic pointer>" "print j in implptr:bar"
bb7da2bf 54 gdb_test {print sizeof (j[0])} " = 4" {print sizeof (j[0]) in implptr:bar}
8cf6f0b1
TT
55 gdb_test "print *j" " = 5" "print *j in implptr:bar"
56 gdb_test "print **k" " = 5" "print **k in implptr:bar"
57 gdb_test "print ***l" " = 5" "print ***l in implptr:bar"
58}
59
543305c9
JK
60# Test implicit pointer offset.
61proc implptr_test_baz {} {
62 global csrcfile
63 set line [gdb_get_line_number "baz breakpoint" $csrcfile]
64 gdb_test "break implptr.c:$line" "Breakpoint 3.*" \
65 "set baz breakpoint for implptr"
66 gdb_continue_to_breakpoint "continue to baz breakpoint for implptr"
ddfe970e
KS
67
68 # We are breaking in an inlined function. GDB should appear to
69 # have stopped "in" the inlined function.
70 gdb_test "up" "#1 foo .*"
543305c9
JK
71 gdb_test {p p[0].y} " = 92" "sanity check element 0"
72 gdb_test {p p[1].y} " = 46" "sanity check element 1"
ddfe970e 73 gdb_test "down" "#0 add .*"
543305c9
JK
74 gdb_test "p a->y" " = 92" "check element 0 for the offset"
75 gdb_test "p b->y" " = 46" "check element 1 for the offset"
76 gdb_continue_to_breakpoint "ignore the second baz breakpoint"
77}
78
8cf6f0b1
TT
79# Test some values in foo.
80proc implptr_test_foo {} {
81 global csrcfile
82 set line [gdb_get_line_number "foo breakpoint" $csrcfile]
543305c9 83 gdb_test "break implptr.c:$line" "Breakpoint 4.*" \
8cf6f0b1
TT
84 "set foo breakpoint for implptr"
85 gdb_continue_to_breakpoint "continue to foo breakpoint for implptr"
0e37a63c 86 gdb_test "print p\[0].x" " = \\(int \\*\\) <synthetic pointer>" \
8cf6f0b1
TT
87 "print p\[0].x in implptr:foo"
88 gdb_test "print *p\[0].x" " = 69" \
89 "print *p\[0].x in implptr:foo"
90 gdb_test "print/d *(((char *) p\[0].x) + 1)" " = 0" \
91 "print byte inside *p\[0].x in implptr:foo"
92 gdb_test "print *(p\[0].x + 10)" \
93 "access outside bounds of object referenced via synthetic pointer" \
94 "print invalid offset from *p\[0].x in implptr:foo"
95 gdb_test "print j" " = 69" \
96 "print j in implptr:foo"
97}
98
99implptr_test_bar
543305c9 100implptr_test_baz
8cf6f0b1 101implptr_test_foo