xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/opaque.exp (revision 9616dacfef448e70e3fbbd865bddf60d54b656c5)
1# Copyright 1992-2015 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
16# This file was written by Fred Fish. (fnf@cygnus.com)
17
18
19# Create and source the file that provides information about the compiler
20# used to compile the test case.
21if [get_compiler_info] {
22    return -1
23}
24
25standard_testfile opaque0.c opaque1.c
26
27if {[prepare_for_testing $testfile.exp $testfile \
28	 [list $srcfile $srcfile2] debug]} {
29    untested $testfile.exp
30    return -1
31}
32
33#
34# Test basic opaque structure handling (statically).
35# The ordering of the tests is significant.  We first try the things that
36# might fail if gdb fails to connect the uses of opaque structures to
37# the actual opaque structure definition.
38
39# When we start up, gdb sets the file containing main() as the current
40# source file.  The actual structure foo is defined in a different file.
41# A pointer (foop) to an instance of the opaque struct is defined in the same
42# source file as main().  Ensure that gdb correctly "connected" the definition
43# in the other file with the pointer to the opaque struct in the file containing
44# "foop".
45
46# Define a procedure to set up an xfail for all targets that do not support
47# this sort of cross reference.
48# Any target gcc that has a DBX_NO_XREFS definition in its config file will
49# not support it (FIXME: Is this still true; I suspect maybe not).
50
51# Native alpha ecoff doesn't support it either.
52# I don't think this type of cross reference works for any COFF target
53# either.
54
55proc setup_xfail_on_opaque_pointer {} {
56	global gcc_compiled
57
58	setup_xfail "vax-*-*" "i*86-sequent-bsd*"
59       if {!$gcc_compiled} then {
60               setup_xfail "alpha-*-*"
61       }
62}
63
64# This seems easier than trying to track different versions of xlc; I'm
65# not sure there is much rhyme or reason regarding which tests it fails
66# and which ones it passes.
67if {[istarget "rs6000-*-aix*"] && !$gcc_compiled} then {
68    warning "xfails in opaque.exp may not be set up correctly for xlc"
69}
70
71setup_xfail_on_opaque_pointer
72gdb_test "whatis foop" \
73    "type = struct foo \[*\]+" \
74    "whatis on opaque struct pointer (statically)"
75
76
77# Ensure that we know the form of the structure that foop points to.
78
79setup_xfail_on_opaque_pointer
80if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" }
81gdb_test "ptype foop" \
82    "type = struct foo \{\[\r\n\]+    int a;\[\r\n\]+    int b;\[\r\n\]+\} \[*\]+" \
83    "ptype on opaque struct pointer (statically)"
84
85
86# An instance of the opaque structure (afoo) is defined in a different file.
87# Ensure that we can locate afoo and the structure definition.
88
89gdb_test "whatis afoo" \
90    "type = struct foo" \
91    "whatis on opaque struct instance (statically)"
92
93
94# Ensure that we know the form of "afoo".
95
96gdb_test "ptype afoo" \
97    "type = struct foo \{\[\r\n\]+    int a;\[\r\n\]+    int b;\[\r\n\]+\}" \
98    "ptype on opaque struct instance (statically)"
99
100
101# Ensure that we know what a struct foo looks like.
102
103gdb_test "ptype struct foo" \
104    "type = struct foo \{\[\r\n\]+    int a;\[\r\n\]+    int b;\[\r\n\]+\}" \
105    "ptype on opaque struct tagname (statically)"
106
107
108#
109# Done with static tests, now test dynamic opaque structure handling.
110# We reload the symbol table so we forget about anything we might
111# have learned during the static tests.
112#
113
114gdb_reinitialize_dir $srcdir/$subdir
115gdb_load ${binfile}
116
117# Run to main, where struct foo is incomplete.
118if ![runto_main] {
119    perror "cannot run to breakpoint at main"
120}
121
122
123# The current source file is now the one containing main().  The structure foo
124# is defined in a different file, but we have a pointer to an instance of
125# the opaque structure in the current file.  Ensure we know it's type.
126
127setup_xfail_on_opaque_pointer
128gdb_test "whatis foop" \
129    "type = struct foo \[*\]+" \
130    "whatis on opaque struct pointer (dynamically)"
131
132
133# Ensure that we know the form of the thing foop points to.
134
135setup_xfail_on_opaque_pointer
136if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" }
137gdb_test "ptype foop" \
138    "type = struct foo \{\[\r\n\]+    int a;\[\r\n\]+    int b;\[\r\n\]+\} \[*\]+" \
139    "ptype on opaque struct pointer (dynamically) 1"
140
141gdb_test "whatis afoo" \
142    "type = struct foo" \
143    "whatis on opaque struct instance (dynamically) 1"
144
145
146# Ensure that we know the form of afoo, an instance of a struct foo.
147
148gdb_test "ptype afoo" \
149    "type = struct foo \{\[\r\n\]+    int a;\[\r\n\]+    int b;\[\r\n\]+\}" \
150    "ptype on opaque struct instance (dynamically) 1"
151
152
153# Ensure that we know the form of an explicit struct foo.
154
155if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" }
156gdb_test "ptype struct foo" \
157    "type = struct foo \{\[\r\n\]+    int a;\[\r\n\]+    int b;\[\r\n\]+\}" \
158    "ptype on opaque struct tagname (dynamically) 1"
159
160
161# Now reload the symbols again so we forget about anything we might
162# have learned reading the symbols during the previous tests.
163
164gdb_reinitialize_dir $srcdir/$subdir
165gdb_load ${binfile}
166
167# Run to getfoo, where struct foo is complete.
168if ![runto getfoo] {
169    perror "cannot run to breakpoint at getfoo"
170}
171
172
173# Ensure that we know what foop is.
174
175setup_xfail_on_opaque_pointer
176gdb_test "whatis foop" \
177    "type = struct foo \[*\]+" \
178    "whatis on opaque struct pointer (dynamically) 1"
179
180
181# Ensure that we know the form of the thing foop points to.
182
183setup_xfail_on_opaque_pointer
184gdb_test "ptype foop" \
185    "type = struct foo \{\[\r\n\]+    int a;\[\r\n\]+    int b;\[\r\n\]+\} \[*\]+" \
186    "ptype on opaque struct pointer (dynamically) 2"
187
188gdb_test "whatis afoo" \
189    "type = struct foo" \
190    "whatis on opaque struct instance (dynamically) 2"
191
192
193# Ensure that we know the form of afoo, an instance of a struct foo.
194
195gdb_test "ptype afoo" \
196    "type = struct foo \{\[\r\n\]+    int a;\[\r\n\]+    int b;\[\r\n\]+\}" \
197    "ptype on opaque struct instance (dynamically) 2"
198
199
200# Ensure that we know the form of an explicit struct foo.
201
202gdb_test "ptype struct foo" \
203    "type = struct foo \{\[\r\n\]+    int a;\[\r\n\]+    int b;\[\r\n\]+\}" \
204    "ptype on opaque struct tagname (dynamically) 2"
205