[Ada] array and bounds in fat pointer can be a stub
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-inferior.exp
CommitLineData
595939de
PM
1# Copyright (C) 2009, 2010 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# This file is part of the GDB testsuite. It tests the mechanism
17# exposing inferiors to Python.
18
19if $tracelevel then {
20 strace $tracelevel
21}
22
23# Run a command in GDB, and report a failure if a Python exception is thrown.
24# If report_pass is true, report a pass if no exception is thrown.
25proc gdb_py_test_silent_cmd {cmd name report_pass} {
26 global gdb_prompt
27
28 gdb_test_multiple $cmd $name {
29 -re "Traceback.*$gdb_prompt $" { fail $name }
30 -re "$gdb_prompt $" { if $report_pass { pass $name } }
31 }
32}
33
34set testfile "py-inferior"
35set srcfile ${testfile}.c
36if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
37 return -1
38}
39
40# Start with a fresh gdb.
41clean_restart ${testfile}
42
43# Skip all tests if Python scripting is not enabled.
44if { [skip_python_tests] } { continue }
45
46# The following tests require execution.
47
48if ![runto_main] then {
49 fail "Can't run to main"
50 return 0
51}
52
53runto [gdb_get_line_number "Break here."]
54
55# Test basic gdb.Inferior attributes and methods.
56
57gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1
58gdb_test "python print inferiors" "\\(<gdb.Inferior object at 0x\[\[:xdigit:\]\]+>,\\)" "verify inferiors list"
59gdb_py_test_silent_cmd "python i0 = inferiors\[0\]" "get first inferior" 0
60
61gdb_test "python print 'result =', i0 == inferiors\[0\]" " = True" "test equality comparison (true)"
62gdb_test "python print 'result =', i0.num" " = \[0-9\]+" "test Inferior.num"
63gdb_test "python print 'result =', i0.pid" " = \[0-9\]+" "test Inferior.pid"
64gdb_test "python print 'result =', i0.was_attached" " = False" "test Inferior.was_attached"
65gdb_test "python print i0.threads ()" "\\(<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads"
66
67# Test memory read and write operations.
68
69gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
70 "read str address" 0
71gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5)" \
72 "read str contents" 1
73gdb_py_test_silent_cmd "python str\[1\] = 'a'" "change str" 0
74gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \
75 "write str" 1
76gdb_test "print str" " = 0x\[\[:xdigit:\]\]+ \"hallo, testsuite\"" \
77 "ensure str was changed in the inferior"
78
79# Test memory search.
80
81set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*}
82set dec_number {[0-9]+}
83set history_prefix {[$][0-9]* = }
84set newline {[\r\n]+}
85set pattern_not_found "${newline}.None"
86set one_pattern_found "${newline}.${dec_number}"
87
88# Test string pattern.
89
90gdb_test "set *(int32_t*) &int8_search_buf\[10\] = 0x61616161" "" ""
91gdb_test "py search_buf = gdb.selected_frame ().read_var ('int8_search_buf')" "" ""
92gdb_test "py start_addr = search_buf.address" "" ""
93gdb_test "py length = search_buf.type.sizeof" "" ""
94
95gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 'aaa')" \
96 "${one_pattern_found}" "find string pattern"
97
98# Test not finding pattern because search range too small, with
99# potential find at the edge of the range.
100
101gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 10+3, 'aaaa')" \
102 "${pattern_not_found}" "pattern not found at end of range"
103
104# Increase the search range by 1 and we should find the pattern.
105
106gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 10+3+1, 'aaa')" \
107 "${one_pattern_found}" "pattern found at end of range"
108
109# Import struct to pack the following patterns.
110gdb_test "py from struct import *" "" ""
111
112# Test 16-bit pattern.
113
114gdb_test "set int16_search_buf\[10\] = 0x1234" "" ""
115gdb_test "py search_buf = gdb.selected_frame ().read_var ('int16_search_buf')" "" ""
116gdb_test "py start_addr = search_buf.address" "" ""
117gdb_test "py length = search_buf.type.sizeof" "" ""
118gdb_test "py pattern = pack('H',0x1234)" "" \
119
120gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
121 "${one_pattern_found}" "find 16-bit pattern, with value pattern"
122
123# Test 32-bit pattern.
124
125gdb_test "set int32_search_buf\[10\] = 0x12345678" "" ""
126gdb_test "py search_buf = gdb.selected_frame ().read_var ('int32_search_buf')" "" ""
127gdb_test "py start_addr = search_buf.address" "" ""
128gdb_test "py length = search_buf.type.sizeof" "" ""
129gdb_test "py pattern = pack('I',0x12345678)" "" \
130
131gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
132 "${one_pattern_found}" "find 32-bit pattern, with python pattern"
133
134# Test 64-bit pattern.
135
136gdb_test "set int64_search_buf\[10\] = 0xfedcba9876543210LL" "" ""
137gdb_test "py search_buf = gdb.selected_frame ().read_var ('int64_search_buf')" "" ""
138gdb_test "py start_addr = search_buf.address" "" ""
139gdb_test "py length = search_buf.type.sizeof" "" ""
140gdb_test "py pattern = pack('Q', 0xfedcba9876543210)" "" ""
141
142gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
143 "${one_pattern_found}" "find 64-bit pattern, with value pattern"
144
145# Test mixed-sized patterns.
146
147gdb_test "set *(int8_t*) &search_buf\[10\] = 0x62" "" ""
148gdb_test "set *(int16_t*) &search_buf\[11\] = 0x6363" "" ""
149gdb_test "set *(int32_t*) &search_buf\[13\] = 0x64646464" "" ""
150gdb_test "py search_buf = gdb.selected_frame ().read_var ('search_buf')" "" ""
151gdb_test "py start_addr = search_buf\[0\].address" "" ""
152gdb_test "py pattern1 = pack('B', 0x62)" "" ""
153gdb_test "py pattern2 = pack('H', 0x6363)" "" ""
154gdb_test "py pattern3 = pack('I', 0x64646464)" "" ""
155
156gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern1)" \
157 "${one_pattern_found}" "find mixed-sized pattern"
158gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern2)" \
159 "${one_pattern_found}" "find mixed-sized pattern"
160gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern3)" \
161 "${one_pattern_found}" "find mixed-sized pattern"
162
163# Test search spanning a large range, in the particular case of native
164# targets, test the search spanning multiple chunks.
165# Remote targets may implement the search differently.
166
167set CHUNK_SIZE 16000 ;
168
169gdb_test "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
170gdb_test "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
171gdb_test "py start_addr = gdb.selected_frame ().read_var ('search_buf')" "" ""
172gdb_test "py length = gdb.selected_frame ().read_var ('search_buf_size')" "" ""
173gdb_test "py pattern = pack('I', 0x12345678)" "" ""
174gdb_test "py first = gdb.inferiors()\[0\].search_memory (start_addr,length, pattern)" "" ""
175gdb_test "py print first" "${one_pattern_found}" "search spanning large range 1st result"
176gdb_test "py start_addr = first + 1"
177gdb_test "py second = gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" "" ""
178gdb_test "py print second" "${one_pattern_found}" "search spanning large range 2nd result"
179gdb_test "py start_addr = second + 1"
180gdb_test "py third = gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" "" ""
181gdb_test "py print third" "${pattern_not_found}" "search spanning large range 3rd result"
182
183# For native targets, test a pattern straddling a chunk boundary.
184
185if [isnative] {
186 gdb_test "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531" "" ""
187 gdb_test "py pattern = pack('I', 0xfdb97531)" "" ""
188 gdb_test "py start_addr = gdb.selected_frame ().read_var ('search_buf')" "" ""
189 gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
190 "${one_pattern_found}" "find pattern straddling chunk boundary"
191}
This page took 0.058017 seconds and 4 git commands to generate.