gdb/riscv: Record information about unknown tdesc registers
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.arch / riscv-tdesc-regs.exp
1 # Copyright 2020 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 # Various tests to check which register names are available after
17 # loading a new target description file, and which registers show up
18 # in the output of the 'info registers' command.
19
20 if {![istarget "riscv*-*-*"]} {
21 verbose "Skipping ${gdb_test_file_name}."
22 return
23 }
24
25 standard_testfile
26
27 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
28 {debug quiet}] } {
29 unsupported "failed to compile"
30 return -1
31 }
32
33 if { ![runto_main] } {
34 untested "failed to runto main"
35 return -1
36 }
37
38 # First, figure out if we are 32-bit or 64-bit.
39 set xlen [get_valueof "/d" "sizeof (\$a0)" 0]
40 set flen [get_valueof "/d" "sizeof (\$fa0)" 0]
41
42 gdb_assert { $xlen != 0 && $flen != 0 } "read xlen and flen"
43
44 # We only handle 32-bit or 64-bit x-registers.
45 if { $xlen != 4 && $xlen != 8 } {
46 unsupported "unknown x-register size"
47 return -1
48 }
49
50 # If FLEN is 1 then the target doesn't have floating point support
51 # (the register $fa0 was not recognised). Otherwise, we can only
52 # proceed if FLEN equals XLEN, otherwise we'd need more test XML
53 # files.
54 if { $flen != 1 && $flen != $xlen } {
55 unsupport "unknown xlen/flen combination"
56 return -1
57 }
58
59 if { $xlen == 4 } {
60 set xml_tdesc "riscv-tdesc-regs-32.xml"
61 } else {
62 set xml_tdesc "riscv-tdesc-regs-64.xml"
63 }
64 set xml_tdesc "${srcdir}/${subdir}/${xml_tdesc}"
65
66 # Maybe copy the target over if we're remote testing.
67 if {[is_remote host]} {
68 set remote_file [remote_download host $xml_tdesc]
69 } else {
70 set remote_file $xml_tdesc
71 }
72
73 gdb_test_no_output "set tdesc filename $remote_file" \
74 "load the new target description"
75
76 # Check that an alias for an unknown CSR will give a suitable error.
77 gdb_test "info registers \$csr0" "Invalid register `csr0'"
78
79 # Check we can access the dscratch register using either of its names.
80 gdb_test "info registers \$dscratch0" "dscratch0\[ \t\]+.*"
81 gdb_test "info registers \$dscratch" "dscratch\[ \t\]+.*"
82
83 foreach rgroup {all save restore} {
84 # Now use 'info registers all' to see how many times the floating
85 # point status registers show up in the output.
86 array set reg_counts {}
87 set test "info registers $rgroup"
88 gdb_test_multiple $test $test {
89 -re ".*info registers all\r\n" {
90 verbose -log "Skip to first register"
91 exp_continue
92 }
93 -re "^(\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" {
94 set reg $expect_out(1,string)
95 incr reg_counts($reg)
96 exp_continue
97 }
98 -re "^$gdb_prompt $" {
99 # Done.
100 }
101 }
102
103 foreach reg {fflags frm fcsr unknown_csr dscratch} {
104 if { [info exists reg_counts($reg) ] } {
105 set count $reg_counts($reg)
106 } else {
107 set count 0
108 }
109 if {($reg == "unknown_csr" || $reg == "dscratch") \
110 && $rgroup != "all"} {
111 gdb_assert {$count == 0} \
112 "register $reg not seen in reggroup $rgroup"
113 } else {
114 gdb_assert {$count == 1} \
115 "register $reg seen once in reggroup $rgroup"
116 }
117 }
118 array unset reg_counts
119 }
This page took 0.035024 seconds and 4 git commands to generate.