GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg
[binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-unusual-field-names.exp
blobdf5896c1852646285439263c1136c2f2ed41b2ae
1 # Copyright 2018-2024 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 # Test that GDB can support accesing fields of a structure if the
17 # fields have non-standard names. Specifically, if the names are
18 # reserved C type names like 'double', 'float', 'int', etc.
20 # We don't expect to that such structures should be seen in real C
21 # code, but in some cases GDB will generate artificial structures, and
22 # in some cases, these type names are the obvious choice for field
23 # names.
25 # One specific example is RISC-V, the 64-bit floating point registers
26 # are represented as a structure with the field names 'float' and
27 # 'double'.
29 load_lib dwarf.exp
31 # This test can only be run on targets which support DWARF-2 and use
32 # gas.
33 require dwarf2_support
35 standard_testfile .c .S
36 set asm_file [standard_output_file $srcfile2]
38 # We need to know the size of integer and address types in order to
39 # write some of the debugging info we'd like to generate.
41 # For that, we ask GDB by debugging our test program. Any program
42 # would do, but since we already have one specifically for this
43 # testcase, might as well use that.
44 if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] {
45 return -1
47 set int_size [get_sizeof "int" -1]
49 # Rebuild the test binary with the single field within the structure
50 # renamed to FIELD_NAME, then test that we can access the field
51 # through '.' and through '->'.
52 proc run_test { field_name } {
53 global asm_file testfile srcfile subdir srcdir
54 global int_size
56 Dwarf::assemble $asm_file {
57 global srcdir subdir srcfile
58 global field_name int_size
60 cu {} {
61 DW_TAG_compile_unit {
62 {DW_AT_language @DW_LANG_C}
63 {DW_AT_name $srcfile}
64 {DW_AT_comp_dir /tmp}
65 } {
66 declare_labels itype ptype stype
68 itype: DW_TAG_base_type {
69 {DW_AT_byte_size $int_size DW_FORM_sdata}
70 {DW_AT_encoding @DW_ATE_signed}
71 {DW_AT_name int}
74 stype: DW_TAG_structure_type {
75 {DW_AT_name "foo"}
76 {DW_AT_byte_size $int_size DW_FORM_sdata}
77 } {
78 member {
79 {name $field_name}
80 {type :$itype}
81 {data_member_location 0 data1}
85 ptype: DW_TAG_pointer_type {
86 {DW_AT_type :$stype}
89 DW_TAG_variable {
90 {DW_AT_name obj}
91 {DW_AT_type :$stype}
92 {DW_AT_location {
93 DW_OP_addr [gdb_target_symbol obj]
94 } SPECIAL_expr}
95 {external 1 flag}
98 DW_TAG_variable {
99 {DW_AT_name ptr}
100 {DW_AT_type :$ptype}
101 {DW_AT_location {
102 DW_OP_addr [gdb_target_symbol ptr]
103 } SPECIAL_expr}
104 {external 1 flag}
110 if { [prepare_for_testing "failed to prepare" ${testfile} \
111 [list $srcfile $asm_file] {nodebug}] } {
112 return -1
115 if ![runto_main] {
116 return -1
119 gdb_test "p obj.$field_name" " = 0" \
120 "access a field named '$field_name' directly"
122 gdb_test "p ptr->$field_name" " = 0" \
123 "access a field named '$field_name' through a pointer"
125 gdb_exit
128 foreach field_name { double float char byte long int short unsigned signed } {
129 run_test $field_name