1 # Copyright 1992-2019 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 # This file was written by Fred Fish. (fnf@cygnus.com)
19 # Create and source the file that provides information about the compiler
20 # used to compile the test case.
21 if [get_compiler_info] {
25 standard_testfile opaque0.c opaque1.c
27 if {[prepare_for_testing "failed to prepare" $testfile \
28 [list $srcfile $srcfile2] debug]} {
33 # Test basic opaque structure handling (statically).
34 # The ordering of the tests is significant. We first try the things that
35 # might fail if gdb fails to connect the uses of opaque structures to
36 # the actual opaque structure definition.
38 # When we start up, gdb sets the file containing main() as the current
39 # source file. The actual structure foo is defined in a different file.
40 # A pointer (foop) to an instance of the opaque struct is defined in the same
41 # source file as main(). Ensure that gdb correctly "connected" the definition
42 # in the other file with the pointer to the opaque struct in the file containing
45 # Define a procedure to set up an xfail for all targets that do not support
46 # this sort of cross reference.
47 # Any target gcc that has a DBX_NO_XREFS definition in its config file will
48 # not support it (FIXME: Is this still true; I suspect maybe not).
50 # Native alpha ecoff doesn't support it either.
51 # I don't think this type of cross reference works for any COFF target
54 proc setup_xfail_on_opaque_pointer {} {
57 setup_xfail "vax-*-*" "i*86-sequent-bsd*"
58 if {!$gcc_compiled} then {
59 setup_xfail "alpha-*-*"
63 # This seems easier than trying to track different versions of xlc; I'm
64 # not sure there is much rhyme or reason regarding which tests it fails
65 # and which ones it passes.
66 if {[istarget "rs6000-*-aix*"] && !$gcc_compiled} then {
67 warning "xfails in opaque.exp may not be set up correctly for xlc"
70 setup_xfail_on_opaque_pointer
71 gdb_test "whatis foop" \
72 "type = struct foo \[*\]+" \
73 "whatis on opaque struct pointer (statically)"
76 # Ensure that we know the form of the structure that foop points to.
78 setup_xfail_on_opaque_pointer
79 if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" }
80 gdb_test "ptype foop" \
81 "type = struct foo \{\[\r\n\]+ int a;\[\r\n\]+ int b;\[\r\n\]+\} \[*\]+" \
82 "ptype on opaque struct pointer (statically)"
85 # An instance of the opaque structure (afoo) is defined in a different file.
86 # Ensure that we can locate afoo and the structure definition.
88 gdb_test "whatis afoo" \
90 "whatis on opaque struct instance (statically)"
93 # Ensure that we know the form of "afoo".
95 gdb_test "ptype afoo" \
96 "type = struct foo \{\[\r\n\]+ int a;\[\r\n\]+ int b;\[\r\n\]+\}" \
97 "ptype on opaque struct instance (statically)"
100 # Ensure that we know what a struct foo looks like.
102 gdb_test "ptype struct foo" \
103 "type = struct foo \{\[\r\n\]+ int a;\[\r\n\]+ int b;\[\r\n\]+\}" \
104 "ptype on opaque struct tagname (statically)"
108 # Done with static tests, now test dynamic opaque structure handling.
109 # We reload the symbol table so we forget about anything we might
110 # have learned during the static tests.
113 gdb_reinitialize_dir $srcdir/$subdir
116 # Run to main, where struct foo is incomplete.
118 perror "cannot run to breakpoint at main"
122 # The current source file is now the one containing main(). The structure foo
123 # is defined in a different file, but we have a pointer to an instance of
124 # the opaque structure in the current file. Ensure we know it's type.
126 setup_xfail_on_opaque_pointer
127 gdb_test "whatis foop" \
128 "type = struct foo \[*\]+" \
129 "whatis on opaque struct pointer (dynamically)"
132 # Ensure that we know the form of the thing foop points to.
134 setup_xfail_on_opaque_pointer
135 if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" }
136 gdb_test "ptype foop" \
137 "type = struct foo \{\[\r\n\]+ int a;\[\r\n\]+ int b;\[\r\n\]+\} \[*\]+" \
138 "ptype on opaque struct pointer (dynamically) 1"
140 gdb_test "whatis afoo" \
141 "type = struct foo" \
142 "whatis on opaque struct instance (dynamically) 1"
145 # Ensure that we know the form of afoo, an instance of a struct foo.
147 gdb_test "ptype afoo" \
148 "type = struct foo \{\[\r\n\]+ int a;\[\r\n\]+ int b;\[\r\n\]+\}" \
149 "ptype on opaque struct instance (dynamically) 1"
152 # Ensure that we know the form of an explicit struct foo.
154 if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" }
155 gdb_test "ptype struct foo" \
156 "type = struct foo \{\[\r\n\]+ int a;\[\r\n\]+ int b;\[\r\n\]+\}" \
157 "ptype on opaque struct tagname (dynamically) 1"
160 # Now reload the symbols again so we forget about anything we might
161 # have learned reading the symbols during the previous tests.
163 gdb_reinitialize_dir $srcdir/$subdir
166 # Run to getfoo, where struct foo is complete.
168 perror "cannot run to breakpoint at getfoo"
172 # Ensure that we know what foop is.
174 setup_xfail_on_opaque_pointer
175 gdb_test "whatis foop" \
176 "type = struct foo \[*\]+" \
177 "whatis on opaque struct pointer (dynamically) 1"
180 # Ensure that we know the form of the thing foop points to.
182 setup_xfail_on_opaque_pointer
183 gdb_test "ptype foop" \
184 "type = struct foo \{\[\r\n\]+ int a;\[\r\n\]+ int b;\[\r\n\]+\} \[*\]+" \
185 "ptype on opaque struct pointer (dynamically) 2"
187 gdb_test "whatis afoo" \
188 "type = struct foo" \
189 "whatis on opaque struct instance (dynamically) 2"
192 # Ensure that we know the form of afoo, an instance of a struct foo.
194 gdb_test "ptype afoo" \
195 "type = struct foo \{\[\r\n\]+ int a;\[\r\n\]+ int b;\[\r\n\]+\}" \
196 "ptype on opaque struct instance (dynamically) 2"
199 # Ensure that we know the form of an explicit struct foo.
201 gdb_test "ptype struct foo" \
202 "type = struct foo \{\[\r\n\]+ int a;\[\r\n\]+ int b;\[\r\n\]+\}" \
203 "ptype on opaque struct tagname (dynamically) 2"