1 # Copyright
2020-2022 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 # Check the gdb.Architecture.register_groups functionality.
18 load_lib gdb
-python.exp
19 standard_testfile py
-arch.c
21 if { [prepare_for_testing
"failed to prepare" ${testfile} ${srcfile}] } {
25 # Skip all tests
if Python scripting is not enabled.
26 if { [skip_python_tests
] } { continue }
32 # First
, use
'maint print reggroups' to
get a list of all register
35 set test
"maint print reggroups"
36 gdb_test_multiple $test $test
{
37 -re
".*Group\[ \t\]+Type\[ \t\]+\r\n" {
40 -re
"^ (\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" {
41 lappend groups $expect_out
(1,string
)
47 gdb_assert
{[llength $groups
] > 0} \
48 "Found at least one register group"
50 # Now
get the same register names using Python API.
51 gdb_py_test_silent_cmd \
52 "python frame = gdb.selected_frame()" "get frame" 0
53 gdb_py_test_silent_cmd \
54 "python arch = frame.architecture()" "get arch" 0
55 gdb_py_test_silent_cmd \
56 "python groups = list (arch.register_groups ())" \
57 "get register groups" 0
58 gdb_py_test_silent_cmd \
59 "python groups = map (lambda obj: obj.name, groups)" \
60 "convert groups to names" 0
63 gdb_test_multiple
"python print (\"\\n\".join (groups))" \
64 "register groups from python" {
65 -re
"^python print \[^\r\n\]+\r\n" {
68 -re
"^(\[^\r\n\]+)\r\n" {
69 lappend py_groups $expect_out
(1,string
)
76 gdb_assert
{[llength $py_groups
] > 0} \
77 "Found at least one register group from python"
78 gdb_assert
{[llength $py_groups
] == [llength $groups
]} \
79 "Same numnber of registers groups found"
82 for { set i
0 } { $i
< [llength $groups
] } { incr i
} {
83 if {[lindex $groups $i
] != [lindex $py_groups $i
]} {
87 gdb_assert
{ $found_non_match
== 0 } "all register groups match"
89 # Check that we
get the same register group descriptors from two
90 # different iterators.
91 gdb_py_test_silent_cmd \
92 "python iter1 = arch.register_groups ()" \
93 "get first all register group iterator" 0
94 gdb_py_test_silent_cmd \
95 "python iter2 = arch.register_groups ()" \
96 "get second all register group iterator" 0
97 gdb_py_test_silent_cmd \
100 "for r1, r2 in zip(iter1, iter2):" \
101 " if (r1.name != r2.name):"\
102 " raise gdb.GdbError (\"miss-matched names\")" \
104 " raise gdb.GdbError (\"miss-matched objects\")" \
106 "check names and objects match" 1