Commit | Line | Data |
---|---|---|
0f767f94 AB |
1 | # Copyright 2020 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.registers functionality. | |
17 | ||
18 | load_lib gdb-python.exp | |
19 | standard_testfile py-arch.c | |
20 | ||
21 | if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { | |
22 | return -1 | |
23 | } | |
24 | ||
25 | # Skip all tests if Python scripting is not enabled. | |
26 | if { [skip_python_tests] } { continue } | |
27 | ||
28 | if ![runto_main] { | |
29 | return -1 | |
30 | } | |
31 | ||
32 | # First, use 'info registers' to get a list of register names. | |
33 | set regs {} | |
34 | gdb_test_multiple "info registers general" "info registers general" { | |
35 | -re "^info registers general\r\n" { | |
36 | exp_continue | |
37 | } | |
38 | -re "^(\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" { | |
39 | set reg $expect_out(1,string) | |
40 | lappend regs $reg | |
41 | exp_continue | |
42 | } | |
43 | -re "^$gdb_prompt " { | |
44 | } | |
45 | } | |
46 | gdb_assert {[llength $regs] > 0} \ | |
47 | "Found at least one register" | |
48 | ||
49 | # Now get the same register names using Python API. | |
50 | gdb_py_test_silent_cmd \ | |
51 | "python frame = gdb.selected_frame()" "get frame" 0 | |
52 | gdb_py_test_silent_cmd \ | |
53 | "python arch = frame.architecture()" "get arch" 0 | |
54 | gdb_py_test_silent_cmd \ | |
55 | "python regs = list (arch.registers (\"general\"))" \ | |
56 | "get general registers" 0 | |
57 | gdb_py_test_silent_cmd \ | |
58 | "python regs = map (lambda r : r.name, regs)" \ | |
59 | "get names of general registers" 0 | |
60 | ||
61 | set py_regs {} | |
62 | gdb_test_multiple "python print (\"\\n\".join (regs))" \ | |
63 | "general register from python" { | |
64 | -re "^python print \[^\r\n\]+\r\n" { | |
65 | exp_continue | |
66 | } | |
67 | -re "^(\[^\r\n\]+)\r\n" { | |
68 | set reg $expect_out(1,string) | |
69 | lappend py_regs $reg | |
70 | exp_continue | |
71 | } | |
72 | -re "^$gdb_prompt " { | |
73 | } | |
74 | } | |
75 | ||
76 | gdb_assert {[llength $py_regs] > 0} \ | |
77 | "Found at least one register from python" | |
78 | gdb_assert {[llength $py_regs] == [llength $regs]} \ | |
79 | "Same numnber of registers found" | |
80 | ||
81 | set found_non_match 0 | |
82 | for { set i 0 } { $i < [llength $regs] } { incr i } { | |
83 | if {[lindex $regs $i] != [lindex $py_regs $i]} { | |
84 | set found_non_match 1 | |
85 | } | |
86 | } | |
87 | gdb_assert { $found_non_match == 0 } "all registers match" | |
f7306dac AB |
88 | |
89 | # Check that we get the same register descriptors from two different | |
90 | # iterators. | |
91 | gdb_py_test_silent_cmd \ | |
92 | "python iter1 = arch.registers ()" \ | |
93 | "get first all register iterator" 0 | |
94 | gdb_py_test_silent_cmd \ | |
95 | "python iter2 = arch.registers ()" \ | |
96 | "get second all register 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 | |
14fa8fb3 AB |
107 | |
108 | # Ensure that the '.find' method on the iterator returns the same | |
109 | # Python object as we got from the iterator's list of descriptors. | |
110 | gdb_py_test_silent_cmd \ | |
111 | [multi_line \ | |
112 | "python" \ | |
113 | "def check_regs (arch, regs):" \ | |
114 | " for r in (regs):" \ | |
115 | " if (arch.registers ().find (r.name) != r):" \ | |
116 | " raise gdb.GdbError (\"object miss-match\")" \ | |
117 | "end" ] \ | |
118 | "build check_obj function" 0 | |
119 | gdb_py_test_silent_cmd \ | |
120 | "python check_regs (arch, arch.registers (\"general\"))" \ | |
121 | "ensure find gets expected descriptors" 1 |