]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.xml/tdesc-regs.exp
gdb: provide and use sparc{32,64} target description XML files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.xml / tdesc-regs.exp
1 # Copyright 2007-2017 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 if {[gdb_skip_xml_test]} {
17 unsupported "tdesc-regs.exp"
18 return -1
19 }
20
21 gdb_start
22
23 # To test adding registers, we need a core set of registers for this
24 # architecture, or the description will be rejected.
25
26 set core-regs ""
27 set regdir ""
28 set architecture ""
29 switch -glob -- [istarget] {
30 "aarch64*-*-*" {
31 set core-regs {aarch64-core.xml}
32 }
33 "arc*-*-*" {
34 set architecture "arc:ARCv2"
35 set core-regs {arc-v2.xml}
36 }
37 "arm*-*-*" {
38 set regdir "arm/"
39 set core-regs {arm-core.xml}
40 }
41 "*m68k-*-*" {
42 set core-regs {m68k-core.xml}
43 }
44 "mips*-*-*" {
45 set core-regs {mips-cpu.xml mips-cp0.xml mips-fpu.xml mips-dsp.xml}
46 }
47 "nds32*-*-*" {
48 set core-regs {nds32-core.xml}
49 }
50 "nios2-*-*" {
51 set core-regs {nios2-cpu.xml}
52 }
53 "powerpc*-*-*" {
54 set regdir "rs6000/"
55 set core-regs {power-core.xml}
56 }
57 "s390*-*-*" {
58 set core-regs {s390-core32.xml s390-acr.xml s390-fpr.xml}
59 }
60 "sparc-*-*" {
61 set regdir "sparc/"
62 set core-regs {sparc32-cpu.xml sparc32-fpu.xml sparc32-cp0.xml}
63 }
64 "sparc64-*-*" {
65 set architecture "sparc:v9"
66 set regdir "sparc/"
67 set core-regs {sparc64-cpu.xml sparc64-fpu.xml sparc64-cp0.xml}
68 }
69 "spu*-*-*" {
70 # This may be either the spu-linux-nat target, or the Cell/B.E.
71 # multi-architecture debugger in SPU standalone executable mode.
72 # We do not support XML register sets on SPU in either case.
73 # However, the multi-arch debugger will accept XML registers sets
74 # (on the PowerPC side), hence the test below would fail.
75 # Simply return unconditionally here.
76 unsupported "register tests"
77 return 0
78 }
79 "tic6x-*-*" {
80 set core-regs {tic6x-core.xml}
81 }
82 "i?86-*-*" {
83 set architecture "i386"
84 set regdir "i386/"
85 set core-regs {32bit-core.xml 32bit-sse.xml}
86 }
87 "x86_64-*-*" {
88 set architecture "i386:x86-64"
89 set regdir "i386/"
90 set core-regs {64bit-core.xml 64bit-sse.xml}
91 }
92 }
93
94 # If no core registers were specified, assume this target does not
95 # support target-defined registers. Verify that we get a warning if
96 # we try to use them. This not only tests the warning, but also
97 # reminds maintainers to add test support when they add the feature.
98
99 set single_reg_xml [gdb_remote_download host \
100 "$srcdir/$subdir/single-reg.xml"]
101
102 if {[string equal ${core-regs} ""]} {
103 gdb_test "set tdesc file $single_reg_xml" \
104 "warning: Target-supplied registers are not supported.*" \
105 "set tdesc file single-reg.xml"
106 unsupported "register tests"
107 return 0
108 }
109
110 # Otherwise, we support both XML and target defined registers.
111
112 # Make sure we reject a description missing standard registers,
113 # like the PC.
114 gdb_test "set tdesc file $single_reg_xml" \
115 "warning: Architecture rejected target-supplied description" \
116 "set tdesc file single-reg.xml"
117
118 # Copy the core registers into the objdir if necessary, so that they
119 # will be found by <xi:include>.
120 foreach src ${core-regs} {
121 set remote_filename($src) \
122 [gdb_remote_download host "$srcdir/../features/$regdir$src"]
123 }
124
125 # Similarly, we need to copy files under test into the objdir.
126 proc load_description { file errmsg xml_file } {
127 global srcdir
128 global subdir
129 global gdb_prompt
130 global core-regs
131 global architecture
132 global remote_filename
133
134 set regs_file [standard_output_file $xml_file]
135
136 file delete $regs_file
137 set ifd [open "$srcdir/$subdir/$file" r]
138 set ofd [open $regs_file w]
139 while {[gets $ifd line] >= 0} {
140 if {[regexp {<xi:include href="core-regs.xml"/>} $line]} {
141 if {! [string equal ${architecture} ""]} {
142 puts $ofd " <architecture>${architecture}</architecture>"
143 }
144 foreach src ${core-regs} {
145 puts $ofd " <xi:include href=\"$src\"/>"
146 }
147 } else {
148 puts $ofd $line
149 }
150 }
151 close $ifd
152 close $ofd
153
154 if {[is_remote host]} {
155 set regs_file [remote_download host "$subdir/$xml_file" $xml_file]
156 }
157
158 # Anchor the test output, so that error messages are detected.
159 set cmd "set tdesc filename [file tail $regs_file]"
160 set msg "set tdesc filename $xml_file - from $file"
161 set cmd_regex [string_to_regexp $cmd]
162 gdb_test_multiple $cmd $msg {
163 -re "^$cmd_regex\r\n$errmsg$gdb_prompt $" {
164 pass $msg
165 }
166 }
167 }
168
169 if {![is_remote host]} {
170 gdb_test "cd [standard_output_file {}]" "Working directory .*" \
171 "cd to directory holding xml"
172 }
173
174 load_description "extra-regs.xml" "" "test-extra-regs.xml"
175 gdb_test "ptype \$extrareg" "type = (int|long|long long)"
176 gdb_test "ptype \$uintreg" "type = uint32_t"
177 gdb_test "ptype \$vecreg" "type = int8_t __attribute__ \\(\\(vector_size\\(4\\)\\)\\)"
178 gdb_test "ptype \$unionreg" \
179 "type = union {\r\n *v4int8 v4;\r\n *v2int16 v2;\r\n}"
180 gdb_test "ptype \$unionreg.v4" "type = int8_t __attribute__ \\(\\(vector_size\\(4\\)\\)\\)"
181 gdb_test "ptype \$structreg" \
182 "type = struct struct1 {\r\n *v4int8 v4;\r\n *v2int16 v2;\r\n}"
183 gdb_test "ptype \$structreg.v4" "type = int8_t __attribute__ \\(\\(vector_size\\(4\\)\\)\\)"
184 gdb_test "ptype \$bitfields" \
185 "type = struct struct2 {\r\n *uint64_t f1 : 35;\r\n *uint64_t f2 : 1;\r\n}"
186 gdb_test "ptype \$flags" \
187 "type = flag flags {\r\n *bool X @0;\r\n *uint32_t Y @2;\r\n}"
188 gdb_test "ptype \$mixed_flags" \
189 "type = flag mixed_flags {\r\n *bool A @0;\r\n *uint32_t B @1-3;\r\n *bool C @4;\r\n *uint32_t D @5;\r\n *uint32_t @6-7;\r\n *enum {yes = 1, no = 0, maybe = 2, so} Z @8-9;\r\n}"
190
191 load_description "core-only.xml" "" "test-regs.xml"
192 # The extra register from the previous description should be gone.
193 gdb_test "ptype \$extrareg" "type = void"