* lib/ada.exp (standard_ada_testfile): New proc.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-inferior.exp
CommitLineData
c5a57081 1# Copyright (C) 2009-2012 Free Software Foundation, Inc.
595939de
PM
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# This file is part of the GDB testsuite. It tests the mechanism
17# exposing inferiors to Python.
18
a2c09bd0 19load_lib gdb-python.exp
595939de 20
b4a58790
TT
21standard_testfile
22
595939de
PM
23if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
24 return -1
25}
26
27# Start with a fresh gdb.
28clean_restart ${testfile}
29
30# Skip all tests if Python scripting is not enabled.
31if { [skip_python_tests] } { continue }
32
ae9d7ce4
NF
33gdb_test_multiple "show endian" "getting target endian" {
34 -re ".*little endian.*$gdb_prompt $" {
35 set python_pack_char "<"
36 # pass silently
37 }
38 -re ".*big endian.*$gdb_prompt $" {
39 set python_pack_char ">"
40 # pass silently
41 }
42}
43
595939de
PM
44# The following tests require execution.
45
46if ![runto_main] then {
47 fail "Can't run to main"
48 return 0
49}
50
51runto [gdb_get_line_number "Break here."]
52
53# Test basic gdb.Inferior attributes and methods.
54
55gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1
56gdb_test "python print inferiors" "\\(<gdb.Inferior object at 0x\[\[:xdigit:\]\]+>,\\)" "verify inferiors list"
57gdb_py_test_silent_cmd "python i0 = inferiors\[0\]" "get first inferior" 0
58
59gdb_test "python print 'result =', i0 == inferiors\[0\]" " = True" "test equality comparison (true)"
60gdb_test "python print 'result =', i0.num" " = \[0-9\]+" "test Inferior.num"
61gdb_test "python print 'result =', i0.pid" " = \[0-9\]+" "test Inferior.pid"
62gdb_test "python print 'result =', i0.was_attached" " = False" "test Inferior.was_attached"
63gdb_test "python print i0.threads ()" "\\(<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads"
64
65# Test memory read and write operations.
66
67gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
68 "read str address" 0
69gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5)" \
70 "read str contents" 1
71gdb_py_test_silent_cmd "python str\[1\] = 'a'" "change str" 0
72gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \
73 "write str" 1
b5916bbd 74gdb_test "print str" " = \"hallo, testsuite\"" \
595939de
PM
75 "ensure str was changed in the inferior"
76
77# Test memory search.
78
79set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*}
80set dec_number {[0-9]+}
81set history_prefix {[$][0-9]* = }
82set newline {[\r\n]+}
83set pattern_not_found "${newline}.None"
84set one_pattern_found "${newline}.${dec_number}"
85
86# Test string pattern.
87
88gdb_test "set *(int32_t*) &int8_search_buf\[10\] = 0x61616161" "" ""
89gdb_test "py search_buf = gdb.selected_frame ().read_var ('int8_search_buf')" "" ""
9a5193cb
JB
90gdb_test_no_output "py start_addr = search_buf.address"
91gdb_test_no_output "py length = search_buf.type.sizeof"
595939de
PM
92
93gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 'aaa')" \
94 "${one_pattern_found}" "find string pattern"
95
96# Test not finding pattern because search range too small, with
97# potential find at the edge of the range.
98
99gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 10+3, 'aaaa')" \
100 "${pattern_not_found}" "pattern not found at end of range"
101
102# Increase the search range by 1 and we should find the pattern.
103
104gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 10+3+1, 'aaa')" \
105 "${one_pattern_found}" "pattern found at end of range"
106
107# Import struct to pack the following patterns.
9a5193cb 108gdb_test_no_output "py from struct import *"
595939de
PM
109
110# Test 16-bit pattern.
111
9a5193cb
JB
112gdb_test_no_output "set int16_search_buf\[10\] = 0x1234"
113gdb_test_no_output "py search_buf = gdb.selected_frame ().read_var ('int16_search_buf')"
114gdb_test_no_output "py start_addr = search_buf.address"
115gdb_test_no_output "py length = search_buf.type.sizeof"
116gdb_test_no_output "py pattern = pack('${python_pack_char}H',0x1234)"
595939de
PM
117
118gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
119 "${one_pattern_found}" "find 16-bit pattern, with value pattern"
120
121# Test 32-bit pattern.
122
9a5193cb
JB
123gdb_test_no_output "set int32_search_buf\[10\] = 0x12345678"
124gdb_test_no_output "py search_buf = gdb.selected_frame ().read_var ('int32_search_buf')"
125gdb_test_no_output "py start_addr = search_buf.address"
126gdb_test_no_output "py length = search_buf.type.sizeof"
127gdb_test_no_output "py pattern = pack('${python_pack_char}I',0x12345678)"
595939de
PM
128
129gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
130 "${one_pattern_found}" "find 32-bit pattern, with python pattern"
131
132# Test 64-bit pattern.
133
9a5193cb
JB
134gdb_test_no_output "set int64_search_buf\[10\] = 0xfedcba9876543210LL"
135gdb_test_no_output "py search_buf = gdb.selected_frame ().read_var ('int64_search_buf')"
136gdb_test_no_output "py start_addr = search_buf.address"
137gdb_test_no_output "py length = search_buf.type.sizeof"
138gdb_test_no_output "py pattern = pack('${python_pack_char}Q', 0xfedcba9876543210)"
595939de
PM
139
140gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
141 "${one_pattern_found}" "find 64-bit pattern, with value pattern"
142
143# Test mixed-sized patterns.
144
9a5193cb
JB
145gdb_test_no_output "set *(int8_t*) &search_buf\[10\] = 0x62"
146gdb_test_no_output "set *(int16_t*) &search_buf\[11\] = 0x6363"
147gdb_test_no_output "set *(int32_t*) &search_buf\[13\] = 0x64646464"
148gdb_test_no_output "py search_buf = gdb.selected_frame ().read_var ('search_buf')"
149gdb_test_no_output "py start_addr = search_buf\[0\].address"
150gdb_test_no_output "py pattern1 = pack('B', 0x62)"
151gdb_test_no_output "py pattern2 = pack('${python_pack_char}H', 0x6363)"
152gdb_test_no_output "py pattern3 = pack('${python_pack_char}I', 0x64646464)"
595939de
PM
153
154gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern1)" \
155 "${one_pattern_found}" "find mixed-sized pattern"
156gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern2)" \
157 "${one_pattern_found}" "find mixed-sized pattern"
158gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern3)" \
159 "${one_pattern_found}" "find mixed-sized pattern"
160
161# Test search spanning a large range, in the particular case of native
162# targets, test the search spanning multiple chunks.
163# Remote targets may implement the search differently.
164
165set CHUNK_SIZE 16000 ;
166
9a5193cb
JB
167gdb_test_no_output "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678"
168gdb_test_no_output "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678"
169gdb_test_no_output "py start_addr = gdb.selected_frame ().read_var ('search_buf')"
c171f854 170gdb_test_no_output "py end_addr = start_addr + gdb.selected_frame ().read_var ('search_buf_size')"
9a5193cb 171gdb_test_no_output "py pattern = pack('${python_pack_char}I', 0x12345678)"
c171f854 172gdb_test_no_output "py first = gdb.inferiors()\[0\].search_memory (start_addr,end_addr - start_addr, pattern)"
595939de 173gdb_test "py print first" "${one_pattern_found}" "search spanning large range 1st result"
9a5193cb 174gdb_test_no_output "py start_addr = first + 1"
c171f854 175gdb_test_no_output "py second = gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)"
595939de 176gdb_test "py print second" "${one_pattern_found}" "search spanning large range 2nd result"
9a5193cb 177gdb_test_no_output "py start_addr = second + 1"
c171f854 178gdb_test_no_output "py third = gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)"
595939de
PM
179gdb_test "py print third" "${pattern_not_found}" "search spanning large range 3rd result"
180
181# For native targets, test a pattern straddling a chunk boundary.
182
183if [isnative] {
9a5193cb
JB
184 gdb_test_no_output "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531"
185 gdb_test_no_output "py pattern = pack('${python_pack_char}I', 0xfdb97531)"
186 gdb_test_no_output "py start_addr = gdb.selected_frame ().read_var ('search_buf')"
c171f854 187 gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)" \
595939de
PM
188 "${one_pattern_found}" "find pattern straddling chunk boundary"
189}
29703da4
PM
190
191# Test Inferior is_valid. This must always be the last test in
192# this testcase as it kills the inferior.
193
194gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get initial list" 1
195gdb_test "python print len(inf_list)" "1" "Get inferior list length"
196gdb_test "python print inf_list\[0\].is_valid()" "True" \
197 "Check inferior validity"
198gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
199gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get new list" 1
200gdb_test "python print len(inf_list)" "2" "Get inferior list length"
201gdb_test "python print inf_list\[0\].is_valid()" "True" \
202 "Check inferior validity"
203gdb_test "python print inf_list\[1\].is_valid()" "True" \
204 "Check inferior validity"
2aa48337 205gdb_test_no_output "remove-inferiors 2" "remove-inferiors 3"
29703da4
PM
206gdb_test "python print inf_list\[0\].is_valid()" "False" \
207 "Check inferior validity"
208gdb_test "python print inf_list\[1\].is_valid()" "True" \
209 "Check inferior validity"
2aa48337
KP
210
211# Test gdb.selected_inferior()
212gdb_test "inferior 1" ".*" "Switch to first inferior"
213gdb_test "py print gdb.selected_inferior().num" "1" "First inferior selected"
214
215gdb_test "add-inferior" "Added inferior 3" "Create new inferior"
216gdb_test "inferior 3" ".*" "Switch to third inferior"
217gdb_test "py print gdb.selected_inferior().num" "3" "Third inferior selected"
218gdb_test "inferior 1" ".*" "Switch to first inferior"
b4a58790 219gdb_test_no_output "remove-inferiors 3" "Remove second inferior"
This page took 0.271456 seconds and 4 git commands to generate.