1 # Copyright
2018-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 # 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
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
31 # This test can only be run on targets which support DWARF-2 and use
33 if {![dwarf2_support]} {
37 standard_testfile dw2-unusual-field-names.c dw2-unusual-field-names.S
38 set asm_file [standard_output_file $srcfile2]
40 # We need to know the size of integer and address types in order to
41 # write some of the debugging info we'd like to generate.
43 #
For that
, we ask GDB by debugging our test
program.
Any program
44 # would
do, but since we already have one specifically
for this
45 # testcase
, might as well use that.
46 if [prepare_for_testing
"failed to prepare" ${testfile} ${srcfile}] {
49 set int_size
[get_sizeof
"int" -1]
51 # Rebuild the test binary with the single field within the structure
52 # renamed to FIELD_NAME
, then test that we can access the field
53 # through
'.' and through
'->'.
54 proc run_test
{ field_name
} {
55 global asm_file testfile srcfile subdir srcdir
58 Dwarf
::assemble $asm_file
{
59 global srcdir subdir srcfile
60 global field_name int_size
64 {DW_AT_language @DW_LANG_C
}
65 {DW_AT_name dw2
-unusual
-field
-names.c
}
68 declare_labels itype ptype stype
70 itype
: DW_TAG_base_type
{
71 {DW_AT_byte_size $int_size DW_FORM_sdata
}
72 {DW_AT_encoding @DW_ATE_signed
}
76 stype
: DW_TAG_structure_type
{
78 {DW_AT_byte_size $int_size DW_FORM_sdata
}
83 {data_member_location
0 data1
}
87 ptype
: DW_TAG_pointer_type
{
95 DW_OP_addr
[gdb_target_symbol
obj]
104 DW_OP_addr
[gdb_target_symbol ptr
]
112 if { [prepare_for_testing
"failed to prepare" ${testfile} \
113 [list $srcfile $asm_file
] {nodebug
}] } {
121 gdb_test
"p obj.$field_name" " = 0" \
122 "access a field named '$field_name' directly"
124 gdb_test
"p ptr->$field_name" " = 0" \
125 "access a field named '$field_name' through a pointer"
130 foreach field_name
{ double float char byte long
int short unsigned signed
} {