Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / testsuite / gdb.python / py-arch-reg-groups.exp
blob9503e6c10f531084f41b1a2b8fd4fc4c8789d4a6
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}] } {
22 return -1
25 # Skip all tests if Python scripting is not enabled.
26 if { [skip_python_tests] } { continue }
28 if ![runto_main] {
29 return -1
32 # First, use 'maint print reggroups' to get a list of all register
33 # groups.
34 set groups {}
35 set test "maint print reggroups"
36 gdb_test_multiple $test $test {
37 -re ".*Group\[ \t\]+Type\[ \t\]+\r\n" {
38 exp_continue
40 -re "^ (\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" {
41 lappend groups $expect_out(1,string)
42 exp_continue
44 -re "^$gdb_prompt " {
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
62 set py_groups {}
63 gdb_test_multiple "python print (\"\\n\".join (groups))" \
64 "register groups from python" {
65 -re "^python print \[^\r\n\]+\r\n" {
66 exp_continue
68 -re "^(\[^\r\n\]+)\r\n" {
69 lappend py_groups $expect_out(1,string)
70 exp_continue
72 -re "^$gdb_prompt " {
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"
81 set found_non_match 0
82 for { set i 0 } { $i < [llength $groups] } { incr i } {
83 if {[lindex $groups $i] != [lindex $py_groups $i]} {
84 set found_non_match 1
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 \
98 [multi_line_input \
99 "python" \
100 "for r1, r2 in zip(iter1, iter2):" \
101 " if (r1.name != r2.name):"\
102 " raise gdb.GdbError (\"miss-matched names\")" \
103 " if (r1 != r2):" \
104 " raise gdb.GdbError (\"miss-matched objects\")" \
105 "\004" ] \
106 "check names and objects match" 1