]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-arch.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-arch.exp
CommitLineData
1d506c26 1# Copyright 2013-2024 Free Software Foundation, Inc.
9f44fbc0
SCR
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/>.
5b791bb5 15load_lib gdb-python.exp
d82e5429 16require allow_python_tests
9f44fbc0
SCR
17standard_testfile
18
5b362f04 19if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
9f44fbc0
SCR
20 return -1
21}
22
9f44fbc0
SCR
23if ![runto_main] {
24 return -1
25}
26
96d9056e
PM
27# Test python/15461. Invalid architectures should not trigger an
28# internal GDB assert.
29gdb_py_test_silent_cmd "python empty = gdb.Architecture()" "get empty arch" 0
bb2bd584
MBB
30gdb_test "python print(repr (empty))" "<gdb\\.Architecture \\(invalid\\)>" \
31 "Test empty achitecture __repr__ does not trigger an assert"
96d9056e
PM
32gdb_test "python print(empty.name())" ".*Architecture is invalid.*" \
33 "Test empty architecture.name does not trigger an assert"
34gdb_test "python print(empty.disassemble())" ".*Architecture is invalid.*" \
35 "Test empty architecture.disassemble does not trigger an assert"
36
9f44fbc0
SCR
37gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "get frame" 0
38gdb_py_test_silent_cmd "python arch = frame.architecture()" "get arch" 0
39gdb_py_test_silent_cmd "python pc = frame.pc()" "get pc" 0
40gdb_py_test_silent_cmd "python insn_list1 = arch.disassemble(pc, pc, 1)" \
41 "disassemble" 0
42gdb_py_test_silent_cmd "python insn_list2 = arch.disassemble(pc, pc)" \
43 "disassemble no count" 0
44gdb_py_test_silent_cmd "python insn_list3 = arch.disassemble(pc, count=1)" \
45 "disassemble no end" 0
d19ca0b3 46gdb_py_test_silent_cmd "python insn_list4 = arch.disassemble(gdb.Value(pc))" \
9f44fbc0
SCR
47 "disassemble no end no count" 0
48
bb2bd584
MBB
49gdb_test "python print (repr (arch))" \
50 "<gdb.Architecture arch_name=.* printable_name=.*>" \
51 "test __repr__ for architecture"
52
8f28f522
PM
53gdb_test "python print (len(insn_list1))" "1" "test number of instructions 1"
54gdb_test "python print (len(insn_list2))" "1" "test number of instructions 2"
55gdb_test "python print (len(insn_list3))" "1" "test number of instructions 3"
56gdb_test "python print (len(insn_list4))" "1" "test number of instructions 4"
9f44fbc0
SCR
57
58gdb_py_test_silent_cmd "python insn = insn_list1\[0\]" "get instruction" 0
59
8f28f522
PM
60gdb_test "python print (\"addr\" in insn)" "True" "test key addr"
61gdb_test "python print (\"asm\" in insn)" "True" "test key asm"
62gdb_test "python print (\"length\" in insn)" "True" "test key length"
9f44fbc0 63
20c6f1e1
YQ
64if { ![is_address_zero_readable] } {
65 # Negative test
66 gdb_test "python arch.disassemble(0, 0)" ".*gdb\.MemoryError.*" \
67 "test bad memory access"
68}
8b87fbe6 69
d3771fe2 70foreach size {0 1 2 3 4 8 16} {
551b380f
AB
71 foreach sign_data {{"" True} \
72 {", True" True} \
73 {", False" False} \
74 {", None" False} \
75 {", \"blah\"" True}} {
76 set sign [lindex $sign_data 0]
77 # GDB's 0 bit type is always signed.
78 if { $size == 0 } {
79 set sign_result True
80 } else {
81 set sign_result [lindex $sign_data 1]
82 }
d3771fe2
TT
83 set fullsize [expr 8 * $size]
84 gdb_test_no_output "python t = arch.integer_type($fullsize$sign)" \
85 "get integer type for $size$sign"
86 gdb_test "python print(t.sizeof)" "$size" \
87 "print size of integer type for $size$sign"
551b380f
AB
88 gdb_test "python print(t.is_signed == ${sign_result})" "True" \
89 "check signedness of type for $size$sign"
d3771fe2
TT
90 }
91}
92
93gdb_test "python arch.integer_type(95)" \
94 ".*ValueError: no integer type of that size is available.*" \
95 "call integer_type with invalid size"
96
8b87fbe6
AB
97# Test for gdb.architecture_names(). First we're going to grab the
98# complete list of architecture names using the 'complete' command.
99set arch_names []
100gdb_test_no_output "set max-completions unlimited"
101gdb_test_multiple "complete set architecture " "" {
102 -re "complete set architecture\[^\r\n\]+\r\n" {
103 exp_continue
104 }
105 -re "^set architecture \(\[^\r\n\]+\)\r\n" {
106 set arch $expect_out(1,string)
107 if { "$arch" != "auto" } {
108 set arch_names [lappend arch_names $arch]
109 }
110 exp_continue
111 }
112 -re "^$gdb_prompt $" {
113 gdb_assert { [llength $arch_names] > 0 }
114 }
115}
116
117# Now find all of the architecture names using Python.
118set py_arch_names []
119gdb_test_no_output "python all_arch = gdb.architecture_names()"
120gdb_test_no_output "python all_arch.sort()"
121gdb_test_multiple "python print(\"\\n\".join((\"Arch: %s\" % a) for a in all_arch))" "" {
122 -re "python \[^\r\n\]+\r\n" {
123 exp_continue
124 }
125 -re "^Arch: \(\[^\r\n\]+\)\r\n" {
126 set arch $expect_out(1,string)
127 set py_arch_names [lappend py_arch_names $arch]
128 exp_continue
129 }
130 -re "$gdb_prompt $" {
131 gdb_assert { [llength $py_arch_names] > 0 }
132 }
133}
134
135# Check the two lists of architecture names are the same length, and
136# that the list contents all match.
137gdb_assert { [llength $arch_names] == [llength $py_arch_names] }
138set lists_match true
139foreach a $arch_names b $py_arch_names {
140 if { $a != $b } {
141 set lists_match false
142 verbose -log "Mismatch is architecture list '$a' != '$b'"
143 break
144 }
145}
146gdb_assert { $lists_match }