Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.python / py-arch-reg-groups.exp
blob3475bbcd33754b5d5b40bd89b2bed44c8e91f603
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}] } {
23     return -1
26 if ![runto_main] {
27    return -1
30 # First, use 'maint print reggroups' to get a list of all register
31 # groups.
32 set groups {}
33 set test "maint print reggroups"
34 gdb_test_multiple $test $test {
35     -re "^$test\r\n" {
36         exp_continue
37     }
38     -re "Group\[ \t\]+Type\[ \t\]+\r\n" {
39         exp_continue
40     }
41     -re "^(\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" {
42         lappend groups $expect_out(1,string)
43         exp_continue
44     }
45     -re "^$gdb_prompt " {
46     }
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
63 set py_groups {}
64 gdb_test_multiple "python print (\"\\n\".join (groups))" \
65     "register groups from python" {
66         -re "^python print \[^\r\n\]+\r\n" {
67             exp_continue
68         }
69         -re "^(\[^\r\n\]+)\r\n" {
70             lappend py_groups $expect_out(1,string)
71             exp_continue
72         }
73         -re "^$gdb_prompt " {
74         }
75     }
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"
82 set found_non_match 0
83 for { set i 0 } { $i < [llength $groups] } { incr i } {
84     if {[lindex $groups $i] != [lindex $py_groups $i]} {
85         set found_non_match 1
86     }
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 \
99     [multi_line_input \
100          "python" \
101          "for r1, r2 in zip(iter1, iter2):" \
102          "  if (r1.name != r2.name):"\
103          "    raise gdb.GdbError (\"miss-matched names\")" \
104          "  if (r1 != r2):" \
105          "    raise gdb.GdbError (\"miss-matched objects\")" \
106          "end" ] \
107     "check names and objects match" 1