]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/incomplete-type-overload.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / incomplete-type-overload.exp
1 # Copyright 2022-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
16 # This file is part of GDB's testsuite.
17
18 # This test intends to check the error message that GDB emits when unable
19 # to determine the correct overloaded function due to incomplete types.
20
21 load_lib dwarf.exp
22
23 if { [skip_cplus_tests] } { return }
24
25 if { ![dwarf2_support] } { return }
26
27 standard_testfile .cc .S
28 set asm_file [standard_output_file ${srcfile2}]
29
30 if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}] {
31 return
32 }
33
34 if ![runto_main] {
35 return
36 }
37
38 # Get important sizes to create fake dwarf for the test
39 set int_size [get_sizeof "int" -1]
40 set addr_size [get_sizeof "void *" -1]
41 set struct_base_size [get_sizeof "base" 4]
42 set struct_complete_size [get_sizeof "complete" 4]
43 get_func_info foo
44
45 # Create fake DWARF for the .cc file.
46 # This is the best way to ensure we have an incomplete type.
47 Dwarf::assemble ${asm_file} {
48 global srcdir subdir srcfile srcfile2 foo_start foo_end
49 global int_size addr_size struct_base_size struct_complete_size
50 declare_labels L
51
52 cu {} {
53 DW_TAG_compile_unit {
54 {DW_AT_language @DW_LANG_C_plus_plus}
55 {name $srcfile}
56 {stmt_list $L DW_FORM_sec_offset}
57 } {
58 declare_labels int_label base_label complete_label incomplete_label
59 declare_labels ptr_base_label ptr_inc_label ptr_comp_label ptr_int_label
60
61 int_label: DW_TAG_base_type {
62 {DW_AT_byte_size $int_size DW_FORM_sdata}
63 {DW_AT_encoding @DW_ATE_signed}
64 {DW_AT_name "int"}
65 }
66
67 base_label: DW_TAG_class_type {
68 {DW_AT_byte_size $struct_base_size DW_FORM_sdata}
69 {DW_AT_name "base"}
70 } {
71 DW_TAG_member {
72 {DW_AT_name "member"}
73 {DW_AT_type :$int_label}
74 {DW_AT_data_member_location 0 DW_FORM_sdata}
75 }
76 }
77
78 complete_label: DW_TAG_class_type {
79 {DW_AT_byte_size $struct_complete_size DW_FORM_sdata}
80 {DW_AT_name "complete"}
81 } {
82 DW_TAG_inheritance {
83 {DW_AT_type :$base_label}
84 {DW_AT_data_member_location 0 DW_FORM_sdata}
85 {DW_AT_accessibility 1 DW_FORM_data1}
86 }
87 }
88
89 incomplete_label: DW_TAG_class_type {
90 {DW_AT_name "incomplete"}
91 {DW_AT_declaration 1 DW_FORM_flag_present}
92 }
93
94 ptr_base_label: DW_TAG_pointer_type {
95 {DW_AT_byte_size $addr_size DW_FORM_udata}
96 {DW_AT_type :$base_label}
97 }
98
99 ptr_inc_label: DW_TAG_pointer_type {
100 {DW_AT_byte_size $addr_size DW_FORM_udata}
101 {DW_AT_type :$incomplete_label}
102 }
103
104 ptr_comp_label: DW_TAG_pointer_type {
105 {DW_AT_byte_size $addr_size DW_FORM_udata}
106 {DW_AT_type :$complete_label}
107 }
108
109 ptr_int_label: DW_TAG_pointer_type {
110 {DW_AT_byte_size $addr_size DW_FORM_udata}
111 {DW_AT_type :$int_label}
112 }
113
114 DW_TAG_variable {
115 {DW_AT_name "comp"}
116 {DW_AT_type :$complete_label}
117 {DW_AT_location {DW_OP_addr [gdb_target_symbol "comp"]} SPECIAL_expr}
118 {DW_AT_external 1 DW_FORM_flag}
119 }
120
121 DW_TAG_variable {
122 {DW_AT_name "cp"}
123 {DW_AT_type :$ptr_comp_label}
124 {DW_AT_location {DW_OP_addr [gdb_target_symbol "cp"]} SPECIAL_expr}
125 {DW_AT_external 1 DW_FORM_flag}
126 }
127
128 DW_TAG_variable {
129 {DW_AT_name "inc"}
130 {DW_AT_type :$ptr_inc_label}
131 {DW_AT_location {DW_OP_addr [gdb_target_symbol "inc"]} SPECIAL_expr}
132 {DW_AT_external 1 DW_FORM_flag}
133 }
134
135 DW_TAG_variable {
136 {DW_AT_name "ip"}
137 {DW_AT_type :$ptr_int_label}
138 {DW_AT_location {DW_OP_addr [gdb_target_symbol "ip"]} SPECIAL_expr}
139 {DW_AT_external 1 DW_FORM_flag}
140 }
141
142 DW_TAG_subprogram {
143 {MACRO_AT_func {"main"}}
144 {DW_AT_external 1 flag}
145 }
146 DW_TAG_subprogram {
147 {MACRO_AT_func {"foo"}}
148 {DW_AT_type :$int_label}
149 {DW_AT_external 1 flag}
150 } { formal_parameter {
151 {DW_AT_name "b"}
152 {DW_AT_type :$ptr_base_label}
153 }
154 }
155 }
156 }
157
158 lines {version 2} L {
159 include_dir "$srcdir/$subdir"
160 file_name $srcfile 1
161 }
162 }
163
164 if [prepare_for_testing "failed to prepare" $testfile [list $asm_file $srcfile] {}] {
165 return
166 }
167
168 if ![runto_main] {
169 return
170 }
171
172 gdb_test "print foo(cp)" "= 1" "successful invocation"
173 gdb_test "print foo(inc)"\
174 "The type. 'incomplete .' isn't fully known to GDB.*"\
175 "unsuccessful because declaration"
176 gdb_test "print foo(ip)"\
177 "Cannot resolve function foo to any overloaded instance."\
178 "unsuccessful because incorrect"