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.registers 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 'info registers' to get a list of register names.
32 gdb_test_multiple "info registers general" "info registers general" {
33 -re "^info registers general\r\n" {
36 -re "^(\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" {
37 set reg $expect_out(1,string)
44 gdb_assert {[llength $regs] > 0} \
45 "Found at least one register"
47 # Now get the same register names using Python API.
48 gdb_py_test_silent_cmd \
49 "python frame = gdb.selected_frame()" "get frame" 0
50 gdb_py_test_silent_cmd \
51 "python arch = frame.architecture()" "get arch" 0
52 gdb_py_test_silent_cmd \
53 "python regs = list (arch.registers (\"general\"))" \
54 "get general registers" 0
55 gdb_py_test_silent_cmd \
56 "python regs = map (lambda r : r.name, regs)" \
57 "get names of general registers" 0
60 gdb_test_multiple "python print (\"\\n\".join (regs))" \
61 "general register from python" {
62 -re "^python print \[^\r\n\]+\r\n" {
65 -re "^(\[^\r\n\]+)\r\n" {
66 set reg $expect_out(1,string)
74 gdb_assert {[llength $py_regs] > 0} \
75 "Found at least one register from python"
76 gdb_assert {[llength $py_regs] == [llength $regs]} \
77 "Same numnber of registers found"
80 for { set i 0 } { $i < [llength $regs] } { incr i } {
81 if {[lindex $regs $i] != [lindex $py_regs $i]} {
85 gdb_assert { $found_non_match == 0 } "all registers match"
87 # Check that we get the same register descriptors from two different
89 gdb_py_test_silent_cmd \
90 "python iter1 = arch.registers ()" \
91 "get first all register iterator" 0
92 gdb_py_test_silent_cmd \
93 "python iter2 = arch.registers ()" \
94 "get second all register 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
106 # Ensure that the '.find' method on the iterator returns the same
107 # Python object as we got from the iterator's list of descriptors.
108 gdb_py_test_silent_cmd \
111 "def check_regs (arch, regs):" \
112 " for r in (regs):" \
113 " if (arch.registers ().find (r.name) != r):" \
114 " raise gdb.GdbError (\"object miss-match\")" \
116 "build check_obj function" 0
117 gdb_py_test_silent_cmd \
118 "python check_regs (arch, arch.registers (\"general\"))" \
119 "ensure find gets expected descriptors" 1