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 {
35 -re ".*Group\[ \t\]+Type\[ \t\]+\r\n" {
38 -re "^ (\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" {
39 lappend groups $expect_out(1,string)
45 gdb_assert {[llength $groups] > 0} \
46 "Found at least one register group"
48 # Now get the same register names using Python API.
49 gdb_py_test_silent_cmd \
50 "python frame = gdb.selected_frame()" "get frame" 0
51 gdb_py_test_silent_cmd \
52 "python arch = frame.architecture()" "get arch" 0
53 gdb_py_test_silent_cmd \
54 "python groups = list (arch.register_groups ())" \
55 "get register groups" 0
56 gdb_py_test_silent_cmd \
57 "python groups = map (lambda obj: obj.name, groups)" \
58 "convert groups to names" 0
61 gdb_test_multiple "python print (\"\\n\".join (groups))" \
62 "register groups from python" {
63 -re "^python print \[^\r\n\]+\r\n" {
66 -re "^(\[^\r\n\]+)\r\n" {
67 lappend py_groups $expect_out(1,string)
74 gdb_assert {[llength $py_groups] > 0} \
75 "Found at least one register group from python"
76 gdb_assert {[llength $py_groups] == [llength $groups]} \
77 "Same numnber of registers groups found"
80 for { set i 0 } { $i < [llength $groups] } { incr i } {
81 if {[lindex $groups $i] != [lindex $py_groups $i]} {
85 gdb_assert { $found_non_match == 0 } "all register groups match"
87 # Check that we get the same register group descriptors from two
88 # different iterators.
89 gdb_py_test_silent_cmd \
90 "python iter1 = arch.register_groups ()" \
91 "get first all register group iterator" 0
92 gdb_py_test_silent_cmd \
93 "python iter2 = arch.register_groups ()" \
94 "get second all register group iterator" 0
95 gdb_py_test_silent_cmd \
98 "for r1, r2 in zip(iter1, iter2):" \
99 " if (r1.name != r2.name):"\
100 " raise gdb.GdbError (\"miss-matched names\")" \
102 " raise gdb.GdbError (\"miss-matched objects\")" \
104 "check names and objects match" 1