* config/tc-mips.c (md_begin): Use strncmp to compare TARGET_OS, in
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / find.exp
CommitLineData
08388c79
DE
1# Copyright 2008 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# Please email any bugs, comments, and/or additions to this file to:
17# bug-gdb@prep.ai.mit.edu
18
19# This tests the find command.
20
21if $tracelevel then {
22 strace $tracelevel
23}
24
25set testfile "find"
26set srcfile ${testfile}.c
27set binfile ${objdir}/${subdir}/${testfile}
28
29if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
30 untested find.exp
31 return -1
32}
33
34gdb_exit
35gdb_start
36gdb_reinitialize_dir $srcdir/$subdir
37gdb_load ${binfile}
38
39gdb_test "break $srcfile:stop_here" \
40 "Breakpoint.*at.* file .*$srcfile, line.*" \
41 "breakpoint function in file"
42
43gdb_run_cmd
44gdb_expect {
45 -re "Breakpoint \[0-9\]+,.*stop_here.* at .*$srcfile:.*$gdb_prompt $" {
46 pass "run until function breakpoint"
47 }
48 -re "$gdb_prompt $" {
49 fail "run until function breakpoint"
50 }
51 timeout {
52 fail "run until function breakpoint (timeout)"
53 }
54}
55
56# We've now got the target program in a state where we can test "find".
57
58set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*}
59set history_prefix {[$][0-9]* = }
60set newline {[\r\n]*}
61set pattern_not_found "${newline}pattern not found"
62set one_pattern_found "${newline}1 pattern found"
63set two_patterns_found "${newline}2 patterns found"
64
65# Test string pattern.
66
67gdb_test "set *(int32_t*) &int8_search_buf\[10\] = 0x61616161" "" ""
68
69gdb_test "find &int8_search_buf\[0\], +sizeof(int8_search_buf), 'a', 'a', 'a'" \
70 "${hex_number}.*<int8_search_buf\\+10>${newline}${hex_number}.*<int8_search_buf\\+11>${two_patterns_found}" \
71 "find string pattern"
72
73# Test not finding pattern because search range too small, with
74# potential find at the edge of the range.
75
76gdb_test "find &int8_search_buf\[0\], +10+3, \"aaaa\"" \
77 "${pattern_not_found}" \
78 "pattern not found at end of range"
79
80# Increase the search range by 1 and we should find the pattern.
81
82gdb_test "find &int8_search_buf\[0\], +10+3+1, 'a', 'a', 'a', 'a'" \
83 "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
84 "pattern found at end of range"
85
86# Test max-count, $_ and $numfound.
87
88gdb_test "find /1 &int8_search_buf\[0\], +sizeof(int8_search_buf), 'a', 'a', 'a'" \
89 "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
90 "max-count"
91
92gdb_test "print \$_" \
93 "${history_prefix}.*${hex_number}" \
94 "\$_"
95
96gdb_test "print \$numfound" \
97 "${history_prefix}1" \
98 "\$numfound"
99
100# Test max-count with size-char.
101# They can be specified in either order.
102
103gdb_test "find /1b &int8_search_buf\[0\], +sizeof(int8_search_buf), 0x61, 0x61, 0x61" \
104 "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
105 "size,max-count, /1b"
106
107gdb_test "find /b1 &int8_search_buf\[0\], +sizeof(int8_search_buf), 0x61, 0x61, 0x61" \
108 "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
109 "size,max-count, /b1"
110
111gdb_test "find /b /1 &int8_search_buf\[0\], +sizeof(int8_search_buf), 0x61, 0x61, 0x61" \
112 "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
113 "size,max-count, /b/1"
114
115gdb_test "find /1 /b &int8_search_buf\[0\], +sizeof(int8_search_buf), 0x61, 0x61, 0x61" \
116 "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
117 "size,max-count, /1/b"
118
119# Test specifying end address.
120
121gdb_test "find /b &int8_search_buf\[0\], &int8_search_buf\[0\]+sizeof(int8_search_buf), 0x61, 0x61, 0x61, 0x61" \
122 "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
123 "find byte pattern with end address"
124
125# Test 16-bit pattern.
126
127gdb_test "set int16_search_buf\[10\] = 0x1234" "" ""
128
129gdb_test "find /h &int16_search_buf\[0\], +sizeof(int16_search_buf), 0x1234" \
130 "${hex_number}.*<int16_search_buf\\+20>${one_pattern_found}" \
131 "find 16-bit pattern"
132
133gdb_test "find &int16_search_buf\[0\], +sizeof(int16_search_buf), (int16_t) 0x1234" \
134 "${hex_number}.*<int16_search_buf\\+20>${one_pattern_found}" \
135 "find 16-bit pattern"
136
137# Test 32-bit pattern.
138
139gdb_test "set int32_search_buf\[10\] = 0x12345678" "" ""
140
141gdb_test "find &int32_search_buf\[0\], +sizeof(int32_search_buf), (int32_t) 0x12345678" \
142 "${hex_number}.*<int32_search_buf\\+40>${one_pattern_found}" \
143 "find 32-bit pattern"
144
145gdb_test "find /w &int32_search_buf\[0\], +sizeof(int32_search_buf), 0x12345678" \
146 "${hex_number}.*<int32_search_buf\\+40>${one_pattern_found}" \
147 "find 32-bit pattern"
148
149# Test 64-bit pattern.
150
151gdb_test "set int64_search_buf\[10\] = 0xfedcba9876543210LL" "" ""
152
153gdb_test "find &int64_search_buf\[0\], +sizeof(int64_search_buf), (int64_t) 0xfedcba9876543210LL" \
154 "${hex_number}.*<int64_search_buf\\+80>${one_pattern_found}" \
155 "find 64-bit pattern"
156
157gdb_test "find /g &int64_search_buf\[0\], +sizeof(int64_search_buf), 0xfedcba9876543210LL" \
158 "${hex_number}.*<int64_search_buf\\+80>${one_pattern_found}" \
159 "find 64-bit pattern"
160
161# Test mixed-sized patterns.
162
163gdb_test "set *(int8_t*) &search_buf\[10\] = 0x62" "" ""
164gdb_test "set *(int16_t*) &search_buf\[11\] = 0x6363" "" ""
165gdb_test "set *(int32_t*) &search_buf\[13\] = 0x64646464" "" ""
166
167gdb_test "find &search_buf\[0\], +100, (int8_t) 0x62, (int16_t) 0x6363, (int32_t) 0x64646464" \
168 "${hex_number}${one_pattern_found}" \
169 "find mixed-sized pattern"
170
171# Test search spanning a large range, in the particular case of native
172# targets, test the search spanning multiple chunks.
173# Remote targets may implement the search differently.
174
175set CHUNK_SIZE 16000 ;# see findcmd.c
176
177gdb_test "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
178gdb_test "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
179
180gdb_test "find /w search_buf, +search_buf_size, 0x12345678" \
181 "${hex_number}${newline}${hex_number}${two_patterns_found}" \
182 "search spanning large range"
183
184# For native targets, test a pattern straddling a chunk boundary.
185
186if [isnative] {
187 gdb_test "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531" "" ""
188 gdb_test "find /w search_buf, +search_buf_size, 0xfdb97531" \
189 "${hex_number}${one_pattern_found}" \
190 "find pattern straddling chunk boundary"
191}
This page took 0.030758 seconds and 4 git commands to generate.