Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.xml / tdesc-regs.exp
blob61efb96615af792a534032285059a74e02f090d5
1 # Copyright 2007-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 require allow_xml_test
18 gdb_start
20 # To test adding registers, we need a core set of registers for this
21 # architecture, or the description will be rejected.
23 set core-regs ""
24 set regdir ""
25 set architecture ""
26 switch -glob -- [istarget] {
27     "aarch64*-*-*" {
28         set core-regs {aarch64-core.xml}
29     }
30     "arc*-*-*" {
31         set architecture "arc:ARCv2"
32         set regdir "arc/"
33         set core-regs {v2-core.xml v2-aux.xml}
34     }
35     "arm*-*-*" {
36         set regdir "arm/"
37         set core-regs {arm-core.xml}
38     }
39     "*m68k-*-*" {
40         set core-regs {m68k-core.xml}
41     }
42     "mips*-*-*" {
43         set core-regs {mips-cpu.xml mips-cp0.xml mips-fpu.xml mips-dsp.xml}
44     }
45     "nds32*-*-*" {
46         set core-regs {nds32-core.xml}
47     }
48     "or1k-*-*" {
49         set core-regs {or1k-core.xml}
50     }
51     "powerpc*-*-*" {
52         set regdir "rs6000/"
53         set core-regs {power-core.xml}
54     }
55     "s390*-*-*" {
56         set core-regs {s390-core32.xml s390-acr.xml s390-fpr.xml}
57     }
58     "sparc-*-*" {
59         set regdir "sparc/"
60         set core-regs {sparc32-cpu.xml sparc32-fpu.xml sparc32-cp0.xml}
61     }
62     "sparc64-*-*" {
63         set architecture "sparc:v9"
64         set regdir "sparc/"
65         set core-regs {sparc64-cpu.xml sparc64-fpu.xml sparc64-cp0.xml}
66     }
67     "tic6x-*-*" {
68         set core-regs {tic6x-core.xml}
69     }
70     "i?86-*-*" {
71         set architecture "i386"
72         set regdir "i386/"
73         set core-regs {32bit-core.xml 32bit-sse.xml}
74     }
75     "x86_64-*-*" {
76         set architecture "i386:x86-64"
77         set regdir "i386/"
78         set core-regs {64bit-core.xml 64bit-sse.xml}
79     }
80     "riscv64*-*-*" {
81        set architecture "riscv:rv64"
82        set regdir "riscv/"
83        set core-regs 64bit-cpu.xml
84     }
87 set single_reg_xml [gdb_remote_download host  \
88                         "$srcdir/$subdir/single-reg.xml"]
90 if {[string equal ${core-regs} ""]} {
91     set test "set tdesc file single-reg.xml"
92     set feature_unsupported 0
93     set feature_test_unsupported 0
94     gdb_test_multiple "set tdesc file $single_reg_xml" $test {
95         -re -wrap "warning: Target-supplied registers are not supported" {
96             set feature_unsupported 1
97             pass $gdb_test_name
98         }
99         -re -wrap "warning: Architecture rejected target-supplied description" {
100             set feature_test_unsupported 1
101             pass $gdb_test_name
102         }
103     }
105     if { $feature_unsupported } {
106         unsupported "register tests"
107     } elseif { $feature_test_unsupported } {
108         # Remind maintainers to add test support.
109         unsupported "register tests (missing architecture-specific core-regs setting)"
110     }
112     return 0
115 # Otherwise, we support both XML and target defined registers.
117 # Make sure we reject a description missing standard registers,
118 # like the PC.
119 gdb_test "set tdesc file $single_reg_xml" \
120     "warning: Architecture rejected target-supplied description" \
121     "set tdesc file single-reg.xml"
123 # Copy the core registers into the objdir if necessary, so that they
124 # will be found by <xi:include>.
125 foreach src ${core-regs} {
126     set remote_filename($src) \
127         [gdb_remote_download host "$srcdir/../features/$regdir$src"]
130 # Similarly, we need to copy files under test into the objdir.
131 proc load_description { file errmsg xml_file } {
132     global srcdir
133     global subdir
134     global gdb_prompt
135     global core-regs
136     global architecture
137     global remote_filename
139     set regs_file [standard_output_file $xml_file]
141     file delete $regs_file
142     set ifd [open "$srcdir/$subdir/$file" r]
143     set ofd [open $regs_file w]
144     while {[gets $ifd line] >= 0} {
145         if {[regexp {<xi:include href="core-regs.xml"/>} $line]} {
146             if {! [string equal ${architecture} ""]} {
147                 puts $ofd "  <architecture>${architecture}</architecture>"
148             }
149             foreach src ${core-regs} {
150                 puts $ofd "  <xi:include href=\"$src\"/>"
151             }
152         } else {
153             puts $ofd $line
154         }
155     }
156     close $ifd
157     close $ofd
159     set host_regs_file [gdb_remote_download host "$regs_file"]
161     # Anchor the test output, so that error messages are detected.
162     set cmd "set tdesc filename $host_regs_file"
163     set msg "set tdesc filename $xml_file - from $file"
164     set cmd_regex [string_to_regexp $cmd]
165     gdb_test_multiple $cmd $msg {
166         -re "^$cmd_regex\r\n$errmsg$gdb_prompt $" {
167             pass $msg
168         }
169     }
172 if {![is_remote host]} {
173     gdb_test "cd [standard_output_file {}]" "Working directory .*" \
174         "cd to directory holding xml"
177 load_description "extra-regs.xml" "" "test-extra-regs.xml"
178 gdb_test "ptype \$extrareg" "type = (int32_t|int|long|long long)"
179 gdb_test "ptype \$uintreg" "type = uint32_t"
180 gdb_test "ptype \$vecreg" "type = int8_t __attribute__ \\(\\(vector_size\\(4\\)\\)\\)"
181 gdb_test "ptype \$unionreg" \
182     "type = union vecint {\r\n *v4int8 v4;\r\n *v2int16 v2;\r\n}"
183 gdb_test "ptype \$unionreg.v4" "type = int8_t __attribute__ \\(\\(vector_size\\(4\\)\\)\\)"
184 gdb_test "ptype \$structreg" \
185     "type = struct struct1 {\r\n *v4int8 v4;\r\n *v2int16 v2;\r\n}"
186 gdb_test "ptype \$structreg.v4" "type = int8_t __attribute__ \\(\\(vector_size\\(4\\)\\)\\)"
187 gdb_test "ptype \$bitfields" \
188     "type = struct struct2 {\r\n *uint64_t f1 : 35;\r\n *uint64_t f2 : 1;\r\n}"
189 gdb_test "ptype \$flags" \
190     "type = flag flags {\r\n *bool X @0;\r\n *uint32_t Y @2;\r\n}"
191 gdb_test "ptype \$mixed_flags" \
192     "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 Z_values {yes = 1, no = 0, maybe = 2, so} Z @8-9;\r\n}"
193 # Reggroups should have at least general and the extra foo group
194 gdb_test "maintenance print reggroups" \
195     "Group\[ \t\]+Type\[ \t\]+\r\n.*general\[ \t\]+user\[ \t\]+\r\n.*foo\[ \t\]+user\[ \t\]+"
197 with_test_prefix "core-only.xml" {
198     load_description "core-only.xml" "" "test-regs.xml"
199     # The extra register from the previous description should be gone.
200     gdb_test "ptype \$extrareg" "type = void"