1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
# Copyright 2024 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Test complex types, and their parts. Dwarf assembly counterpart of
# gdb.base/complex-parts.exp.
#
# In dwarf, base types are not allowed to have references to other types. And
# because complex types are modeled as base types, gdb has to figure out what
# the part type is.
#
# It would be easier for gdb if compilers would add a dwarf extension and
# supply this information, but that may or may not happen
# ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115272 ).
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
require dwarf2_support
standard_testfile main.c -debug.S
if [prepare_for_testing "failed to prepare" $testfile \
"${srcfile}" {}] {
return -1
}
set float_size [get_sizeof float 0]
set double_size [get_sizeof double 0]
set long_double_size [get_sizeof "long double" 0]
set int_size [get_sizeof int 0]
# Create the DWARF.
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
cu { version 2 } {
compile_unit {} {
# Main.
declare_labels int_type
int_type: DW_TAG_base_type {
{DW_AT_byte_size $::int_size DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_signed}
{DW_AT_name int}
}
DW_TAG_subprogram {
{MACRO_AT_func {main}}
{type :$int_type}
}
# GCC complex float.
declare_labels cf_type cd_type cld_type
cf_type: DW_TAG_base_type {
{DW_AT_byte_size [expr 2 * $::float_size] DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_complex_float}
{DW_AT_name "complex float"}
}
cd_type: DW_TAG_base_type {
{DW_AT_byte_size [expr 2 * $::double_size] DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_complex_float}
{DW_AT_name "complex double"}
}
cld_type: DW_TAG_base_type {
{DW_AT_byte_size [expr 2 * $::long_double_size] DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_complex_float}
{DW_AT_name "complex long double"}
}
DW_TAG_variable {
{name var_complex_float}
{DW_AT_type :$cf_type}
}
DW_TAG_variable {
{name var_complex_double}
{DW_AT_type :$cd_type}
}
DW_TAG_variable {
{name var_complex_long_double}
{DW_AT_type :$cld_type}
}
# GCC complex int.
# This is what gcc currently generates, see gcc PR debug/93988.
declare_labels ci_type
ci_type: DW_TAG_base_type {
{DW_AT_byte_size [expr 2 * $::int_size] DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_lo_user}
{DW_AT_name "complex int"}
}
DW_TAG_variable {
{name var_complex_int}
{DW_AT_type :$ci_type}
}
# Clang complex float.
# This is what clang currently generates, see this issue (
# https://github.com/llvm/llvm-project/issues/52996 ).
declare_labels clang_cf_type clang_cd_type clang_cld_type
clang_cf_type: DW_TAG_base_type {
{DW_AT_byte_size [expr 2 * $::float_size] DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_complex_float}
{DW_AT_name "complex"}
}
DW_TAG_variable {
{name var_complex_clang_float}
{DW_AT_type :$clang_cf_type}
}
clang_cd_type: DW_TAG_base_type {
{DW_AT_byte_size [expr 2 * $::double_size] DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_complex_float}
{DW_AT_name "complex"}
}
DW_TAG_variable {
{name var_complex_clang_double}
{DW_AT_type :$clang_cd_type}
}
clang_cld_type: DW_TAG_base_type {
{DW_AT_byte_size [expr 2 * $::long_double_size] DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_complex_float}
{DW_AT_name "complex"}
}
DW_TAG_variable {
{name var_complex_clang_long_double}
{DW_AT_type :$clang_cld_type}
}
}
}
}
if [prepare_for_testing "failed to prepare" $testfile \
"${asm_file} ${srcfile}" {}] {
return -1
}
if ![runto_main] {
return -1
}
proc do_test { type {clang 0}} {
with_test_prefix $type {
with_test_prefix clang=$clang {
if { $clang } {
set type_id [regsub -all " " $type _]
set var "var_complex_clang_$type_id"
# Gdb could try to synthesize better names, see enhancement
# PR symtab/31858.
set ctype "complex"
set ctype_id "complex"
} else {
set ctype "complex $type"
set type_id [regsub -all " " $type _]
set ctype_id [regsub -all " " $ctype _]
set var "var_$ctype_id"
}
gdb_test "ptype '$type'" \
"type = $type"
gdb_test "ptype '$ctype'" \
"type = $ctype"
eval set type_size \$::${type_id}_size
gdb_test "p sizeof ('$type')" \
" = $type_size"
if { ! $clang } {
# With clang, the ctype name does not uniquely map to a type,
# so the size is unpredictable.
gdb_test "p sizeof ('$ctype')" \
" = [expr 2 * $type_size]"
}
set re_kfail \
[string_to_regexp \
"'var_complex_int' has unknown type; cast it to its declared type"]
foreach f { {$_cimag} {$_creal} } {
gdb_test_multiple "p $f ($var)" "" {
-re -wrap " = <optimized out>" {
pass $gdb_test_name
}
-re -wrap $re_kfail {
kfail gdb/31857 $gdb_test_name
}
}
if { $clang } {
# Without a specific complex type name, it's
# unpredictable which type name the part will have.
gdb_test {ptype $} \
"type = (float|double|long double)" \
"ptype $f"
} else {
gdb_test {ptype $} \
"type = $type" \
"ptype $f"
}
}
}
}
}
do_test "float"
do_test "double"
do_test "long double"
do_test "int"
do_test "float" 1
do_test "double" 1
do_test "long double" 1
|