]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-arch-reg-groups.exp
ltmain.sh: allow more flags at link-time
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-arch-reg-groups.exp
1 # Copyright 2020-2024 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # Check the gdb.Architecture.register_groups functionality.
17
18 load_lib gdb-python.exp
19 require allow_python_tests
20 standard_testfile py-arch.c
21
22 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
23 return -1
24 }
25
26 if ![runto_main] {
27 return -1
28 }
29
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 ".*Group\[ \t\]+Type\[ \t\]+\r\n" {
36 exp_continue
37 }
38 -re "^ (\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" {
39 lappend groups $expect_out(1,string)
40 exp_continue
41 }
42 -re "^$gdb_prompt " {
43 }
44 }
45 gdb_assert {[llength $groups] > 0} \
46 "Found at least one register group"
47
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
59
60 set py_groups {}
61 gdb_test_multiple "python print (\"\\n\".join (groups))" \
62 "register groups from python" {
63 -re "^python print \[^\r\n\]+\r\n" {
64 exp_continue
65 }
66 -re "^(\[^\r\n\]+)\r\n" {
67 lappend py_groups $expect_out(1,string)
68 exp_continue
69 }
70 -re "^$gdb_prompt " {
71 }
72 }
73
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"
78
79 set found_non_match 0
80 for { set i 0 } { $i < [llength $groups] } { incr i } {
81 if {[lindex $groups $i] != [lindex $py_groups $i]} {
82 set found_non_match 1
83 }
84 }
85 gdb_assert { $found_non_match == 0 } "all register groups match"
86
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 \
96 [multi_line_input \
97 "python" \
98 "for r1, r2 in zip(iter1, iter2):" \
99 " if (r1.name != r2.name):"\
100 " raise gdb.GdbError (\"miss-matched names\")" \
101 " if (r1 != r2):" \
102 " raise gdb.GdbError (\"miss-matched objects\")" \
103 "end" ] \
104 "check names and objects match" 1