OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.2/] [gdb/] [testsuite/] [gdb.python/] [py-inferior.exp] - Blame information for rev 330

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
# 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 .
15
 
16
# This file is part of the GDB testsuite.  It tests the mechanism
17
# exposing inferiors to Python.
18
 
19
if $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.
25
proc 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
 
34
set testfile "py-inferior"
35
set srcfile ${testfile}.c
36
if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
37
    return -1
38
}
39
 
40
# Start with a fresh gdb.
41
clean_restart ${testfile}
42
 
43
# Skip all tests if Python scripting is not enabled.
44
if { [skip_python_tests] } { continue }
45
 
46
# The following tests require execution.
47
 
48
if ![runto_main] then {
49
    fail "Can't run to main"
50
    return 0
51
}
52
 
53
runto [gdb_get_line_number "Break here."]
54
 
55
# Test basic gdb.Inferior attributes and methods.
56
 
57
gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1
58
gdb_test "python print inferiors" "\\(,\\)" "verify inferiors list"
59
gdb_py_test_silent_cmd "python i0 = inferiors\[0\]" "get first inferior" 0
60
 
61
gdb_test "python print 'result =', i0 == inferiors\[0\]" " = True" "test equality comparison (true)"
62
gdb_test "python print 'result =', i0.num" " = \[0-9\]+" "test Inferior.num"
63
gdb_test "python print 'result =', i0.pid" " = \[0-9\]+" "test Inferior.pid"
64
gdb_test "python print 'result =', i0.was_attached" " = False" "test Inferior.was_attached"
65
gdb_test "python print i0.threads ()" "\\(,\\)" "test Inferior.threads"
66
 
67
# Test memory read and write operations.
68
 
69
gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
70
  "read str address" 0
71
gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5)" \
72
  "read str contents" 1
73
gdb_py_test_silent_cmd "python str\[1\] = 'a'" "change str" 0
74
gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \
75
  "write str" 1
76
gdb_test "print str" " = 0x\[\[:xdigit:\]\]+ \"hallo, testsuite\"" \
77
  "ensure str was changed in the inferior"
78
 
79
# Test memory search.
80
 
81
set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*}
82
set dec_number {[0-9]+}
83
set history_prefix {[$][0-9]* = }
84
set newline {[\r\n]+}
85
set pattern_not_found "${newline}.None"
86
set one_pattern_found "${newline}.${dec_number}"
87
 
88
# Test string pattern.
89
 
90
gdb_test "set *(int32_t*) &int8_search_buf\[10\] = 0x61616161" "" ""
91
gdb_test "py search_buf = gdb.selected_frame ().read_var ('int8_search_buf')" "" ""
92
gdb_test "py start_addr = search_buf.address" "" ""
93
gdb_test "py length = search_buf.type.sizeof" "" ""
94
 
95
gdb_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
 
101
gdb_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
 
106
gdb_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.
110
gdb_test "py from struct import *" "" ""
111
 
112
# Test 16-bit pattern.
113
 
114
gdb_test "set int16_search_buf\[10\] = 0x1234" "" ""
115
gdb_test "py search_buf = gdb.selected_frame ().read_var ('int16_search_buf')" "" ""
116
gdb_test "py start_addr = search_buf.address" "" ""
117
gdb_test "py length = search_buf.type.sizeof" "" ""
118
gdb_test "py pattern = pack('H',0x1234)" "" \
119
 
120
gdb_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
 
125
gdb_test "set int32_search_buf\[10\] = 0x12345678" "" ""
126
gdb_test "py search_buf = gdb.selected_frame ().read_var ('int32_search_buf')" "" ""
127
gdb_test "py start_addr = search_buf.address" "" ""
128
gdb_test "py length = search_buf.type.sizeof" "" ""
129
gdb_test "py pattern = pack('I',0x12345678)" "" \
130
 
131
gdb_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
 
136
gdb_test "set int64_search_buf\[10\] = 0xfedcba9876543210LL" "" ""
137
gdb_test "py search_buf = gdb.selected_frame ().read_var ('int64_search_buf')" "" ""
138
gdb_test "py start_addr = search_buf.address" "" ""
139
gdb_test "py length = search_buf.type.sizeof" "" ""
140
gdb_test "py pattern = pack('Q', 0xfedcba9876543210)" "" ""
141
 
142
gdb_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
 
147
gdb_test "set *(int8_t*) &search_buf\[10\] = 0x62" "" ""
148
gdb_test "set *(int16_t*) &search_buf\[11\] = 0x6363" "" ""
149
gdb_test "set *(int32_t*) &search_buf\[13\] = 0x64646464" "" ""
150
gdb_test "py search_buf = gdb.selected_frame ().read_var ('search_buf')" "" ""
151
gdb_test "py start_addr = search_buf\[0\].address" "" ""
152
gdb_test "py pattern1 = pack('B', 0x62)" "" ""
153
gdb_test "py pattern2 = pack('H', 0x6363)" "" ""
154
gdb_test "py pattern3 = pack('I', 0x64646464)" "" ""
155
 
156
gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern1)" \
157
    "${one_pattern_found}" "find mixed-sized pattern"
158
gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, pattern2)" \
159
    "${one_pattern_found}" "find mixed-sized pattern"
160
gdb_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
 
167
set CHUNK_SIZE 16000 ;
168
 
169
gdb_test "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
170
gdb_test "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
171
gdb_test "py start_addr = gdb.selected_frame ().read_var ('search_buf')" "" ""
172
gdb_test "py length = gdb.selected_frame ().read_var ('search_buf_size')" "" ""
173
gdb_test "py pattern = pack('I', 0x12345678)" "" ""
174
gdb_test "py first = gdb.inferiors()\[0\].search_memory (start_addr,length, pattern)" "" ""
175
gdb_test "py print first" "${one_pattern_found}" "search spanning large range 1st result"
176
gdb_test "py start_addr = first + 1"
177
gdb_test "py second = gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" "" ""
178
gdb_test "py print second" "${one_pattern_found}" "search spanning large range 2nd result"
179
gdb_test "py start_addr = second + 1"
180
gdb_test "py third = gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" "" ""
181
gdb_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
 
185
if [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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.