1 # Copyright 2020-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 # Check the gdb.Architecture.register_groups functionality.
18 load_lib gdb-python.exp
19 require allow_python_tests
20 standard_testfile py-arch.c
22 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
30 # First, use 'maint print reggroups' to get a list of all register
33 set test "maint print reggroups"
34 gdb_test_multiple $test $test {
38 -re "Group\[ \t\]+Type\[ \t\]+\r\n" {
41 -re "^(\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" {
42 lappend groups $expect_out(1,string)
48 gdb_assert {[llength $groups] > 0} \
49 "Found at least one register group"
51 # Now get the same register names using Python API.
52 gdb_py_test_silent_cmd \
53 "python frame = gdb.selected_frame()" "get frame" 0
54 gdb_py_test_silent_cmd \
55 "python arch = frame.architecture()" "get arch" 0
56 gdb_py_test_silent_cmd \
57 "python groups = list (arch.register_groups ())" \
58 "get register groups" 0
59 gdb_py_test_silent_cmd \
60 "python groups = map (lambda obj: obj.name, groups)" \
61 "convert groups to names" 0
64 gdb_test_multiple "python print (\"\\n\".join (groups))" \
65 "register groups from python" {
66 -re "^python print \[^\r\n\]+\r\n" {
69 -re "^(\[^\r\n\]+)\r\n" {
70 lappend py_groups $expect_out(1,string)
77 gdb_assert {[llength $py_groups] > 0} \
78 "Found at least one register group from python"
79 gdb_assert {[llength $py_groups] == [llength $groups]} \
80 "Same number of registers groups found"
83 for { set i 0 } { $i < [llength $groups] } { incr i } {
84 if {[lindex $groups $i] != [lindex $py_groups $i]} {
88 gdb_assert { $found_non_match == 0 } "all register groups match"
90 # Check that we get the same register group descriptors from two
91 # different iterators.
92 gdb_py_test_silent_cmd \
93 "python iter1 = arch.register_groups ()" \
94 "get first all register group iterator" 0
95 gdb_py_test_silent_cmd \
96 "python iter2 = arch.register_groups ()" \
97 "get second all register group iterator" 0
98 gdb_py_test_silent_cmd \
101 "for r1, r2 in zip(iter1, iter2):" \
102 " if (r1.name != r2.name):"\
103 " raise gdb.GdbError (\"miss-matched names\")" \
105 " raise gdb.GdbError (\"miss-matched objects\")" \
107 "check names and objects match" 1