]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2018-2024 Free Software Foundation, Inc. |
6f0ffe50 AB |
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 | # 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. | |
19 | # | |
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. | |
24 | # | |
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'. | |
28 | ||
29 | load_lib dwarf.exp | |
30 | ||
31 | # This test can only be run on targets which support DWARF-2 and use | |
32 | # gas. | |
ce8d533e | 33 | require dwarf2_support |
6f0ffe50 | 34 | |
d1c8a76d | 35 | standard_testfile .c .S |
6f0ffe50 AB |
36 | set asm_file [standard_output_file $srcfile2] |
37 | ||
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. | |
40 | # | |
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 | |
46 | } | |
47 | set int_size [get_sizeof "int" -1] | |
48 | ||
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 | |
55 | ||
56 | Dwarf::assemble $asm_file { | |
57 | global srcdir subdir srcfile | |
58 | global field_name int_size | |
59 | ||
60 | cu {} { | |
61 | DW_TAG_compile_unit { | |
62 | {DW_AT_language @DW_LANG_C} | |
9476b583 | 63 | {DW_AT_name $srcfile} |
6f0ffe50 AB |
64 | {DW_AT_comp_dir /tmp} |
65 | } { | |
66 | declare_labels itype ptype stype | |
67 | ||
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} | |
72 | } | |
73 | ||
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} | |
82 | } | |
83 | } | |
84 | ||
85 | ptype: DW_TAG_pointer_type { | |
86 | {DW_AT_type :$stype} | |
87 | } | |
88 | ||
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} | |
96 | } | |
97 | ||
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} | |
105 | } | |
106 | } | |
107 | } | |
108 | } | |
109 | ||
110 | if { [prepare_for_testing "failed to prepare" ${testfile} \ | |
111 | [list $srcfile $asm_file] {nodebug}] } { | |
112 | return -1 | |
113 | } | |
114 | ||
115 | if ![runto_main] { | |
116 | return -1 | |
117 | } | |
118 | ||
119 | gdb_test "p obj.$field_name" " = 0" \ | |
120 | "access a field named '$field_name' directly" | |
121 | ||
122 | gdb_test "p ptr->$field_name" " = 0" \ | |
123 | "access a field named '$field_name' through a pointer" | |
124 | ||
125 | gdb_exit | |
126 | } | |
127 | ||
128 | foreach field_name { double float char byte long int short unsigned signed } { | |
129 | run_test $field_name | |
130 | } |