* config/tc-arm.c (arm_cpus): Add entry for ARM Cortex-M0.
[binutils-gdb.git] / gdb / testsuite / gdb.base / find.exp
blob748827dff7edb2ecb3e0ec4f216ab53a67abf4db
1 # Copyright 2008, 2009 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This tests the find command.
18 if $tracelevel then {
19     strace $tracelevel
22 set testfile "find"
23 set srcfile ${testfile}.c
24 set binfile ${objdir}/${subdir}/${testfile}
26 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
27     untested find.exp
28     return -1
31 gdb_exit
32 gdb_start
33 gdb_reinitialize_dir $srcdir/$subdir
34 gdb_load ${binfile}
36 gdb_test "break $srcfile:stop_here" \
37     "Breakpoint.*at.* file .*$srcfile, line.*" \
38     "breakpoint function in file"
40 gdb_run_cmd
41 gdb_expect {
42     -re "Breakpoint \[0-9\]+,.*stop_here.* at .*$srcfile:.*$gdb_prompt $" {
43         pass "run until function breakpoint"
44     }
45     -re "$gdb_prompt $" {
46         fail "run until function breakpoint"
47     }
48     timeout {
49         fail "run until function breakpoint (timeout)"
50     }
53 # We've now got the target program in a state where we can test "find".
55 set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*}
56 set history_prefix {[$][0-9]* = }
57 set newline "\[\r\n\]*"
58 set pattern_not_found "${newline}Pattern not found\[.\]"
59 set one_pattern_found "${newline}1 pattern found\[.\]"
60 set two_patterns_found "${newline}2 patterns found\[.\]"
62 # Test string pattern.
64 gdb_test "set *(int32_t*) &int8_search_buf\[10\] = 0x61616161" "" ""
66 gdb_test "find &int8_search_buf\[0\], +sizeof(int8_search_buf), 'a', 'a', 'a'" \
67     "${hex_number}.*<int8_search_buf\\+10>${newline}${hex_number}.*<int8_search_buf\\+11>${two_patterns_found}" \
68     "find string pattern"
70 # Test not finding pattern because search range too small, with
71 # potential find at the edge of the range.
73 gdb_test "find &int8_search_buf\[0\], +10+3, \"aaaa\"" \
74     "${pattern_not_found}" \
75     "pattern not found at end of range"
77 # Increase the search range by 1 and we should find the pattern.
79 gdb_test "find &int8_search_buf\[0\], +10+3+1, 'a', 'a', 'a', 'a'" \
80     "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
81     "pattern found at end of range"
83 # Test max-count, $_ and $numfound.
85 gdb_test "find /1 &int8_search_buf\[0\], +sizeof(int8_search_buf), 'a', 'a', 'a'" \
86     "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
87     "max-count"
89 gdb_test "print \$_" \
90     "${history_prefix}.*${hex_number}" \
91     "\$_"
93 gdb_test "print \$numfound" \
94     "${history_prefix}1" \
95     "\$numfound"
97 # Test max-count with size-char.
98 # They can be specified in either order.
100 gdb_test "find /1b &int8_search_buf\[0\], +sizeof(int8_search_buf), 0x61, 0x61, 0x61" \
101     "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
102     "size,max-count, /1b"
104 gdb_test "find /b1 &int8_search_buf\[0\], +sizeof(int8_search_buf), 0x61, 0x61, 0x61" \
105     "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
106     "size,max-count, /b1"
108 gdb_test "find /b /1 &int8_search_buf\[0\], +sizeof(int8_search_buf), 0x61, 0x61, 0x61" \
109     "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
110     "size,max-count, /b/1"
112 gdb_test "find /1 /b &int8_search_buf\[0\], +sizeof(int8_search_buf), 0x61, 0x61, 0x61" \
113     "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
114     "size,max-count, /1/b"
116 # Test specifying end address.
118 gdb_test "find /b &int8_search_buf\[0\], &int8_search_buf\[0\]+sizeof(int8_search_buf), 0x61, 0x61, 0x61, 0x61" \
119     "${hex_number}.*<int8_search_buf\\+10>${one_pattern_found}" \
120     "find byte pattern with end address"
122 # Test 16-bit pattern.
124 gdb_test "set int16_search_buf\[10\] = 0x1234" "" ""
126 gdb_test "find /h &int16_search_buf\[0\], +sizeof(int16_search_buf), 0x1234" \
127     "${hex_number}.*<int16_search_buf\\+20>${one_pattern_found}" \
128     "find 16-bit pattern"
130 gdb_test "find &int16_search_buf\[0\], +sizeof(int16_search_buf), (int16_t) 0x1234" \
131     "${hex_number}.*<int16_search_buf\\+20>${one_pattern_found}" \
132     "find 16-bit pattern"
134 # Test 32-bit pattern.
136 gdb_test "set int32_search_buf\[10\] = 0x12345678" "" ""
138 gdb_test "find &int32_search_buf\[0\], +sizeof(int32_search_buf), (int32_t) 0x12345678" \
139     "${hex_number}.*<int32_search_buf\\+40>${one_pattern_found}" \
140     "find 32-bit pattern"
142 gdb_test "find /w &int32_search_buf\[0\], +sizeof(int32_search_buf), 0x12345678" \
143     "${hex_number}.*<int32_search_buf\\+40>${one_pattern_found}" \
144     "find 32-bit pattern"
146 # Test 64-bit pattern.
148 gdb_test "set int64_search_buf\[10\] = 0xfedcba9876543210LL" "" ""
150 gdb_test "find &int64_search_buf\[0\], +sizeof(int64_search_buf), (int64_t) 0xfedcba9876543210LL" \
151     "${hex_number}.*<int64_search_buf\\+80>${one_pattern_found}" \
152     "find 64-bit pattern"
154 gdb_test "find /g &int64_search_buf\[0\], +sizeof(int64_search_buf), 0xfedcba9876543210LL" \
155     "${hex_number}.*<int64_search_buf\\+80>${one_pattern_found}" \
156     "find 64-bit pattern"
158 # Test mixed-sized patterns.
160 gdb_test "set *(int8_t*) &search_buf\[10\] = 0x62" "" ""
161 gdb_test "set *(int16_t*) &search_buf\[11\] = 0x6363" "" ""
162 gdb_test "set *(int32_t*) &search_buf\[13\] = 0x64646464" "" ""
164 gdb_test "find &search_buf\[0\], +100, (int8_t) 0x62, (int16_t) 0x6363, (int32_t) 0x64646464" \
165     "${hex_number}${one_pattern_found}" \
166     "find mixed-sized pattern"
168 # Test search spanning a large range, in the particular case of native
169 # targets, test the search spanning multiple chunks.
170 # Remote targets may implement the search differently.
172 set CHUNK_SIZE 16000 ;# see findcmd.c
174 gdb_test "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
175 gdb_test "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
177 gdb_test "find /w search_buf, +search_buf_size, 0x12345678" \
178     "${hex_number}${newline}${hex_number}${two_patterns_found}" \
179     "search spanning large range"
181 # For native targets, test a pattern straddling a chunk boundary.
183 if [isnative] {
184     gdb_test "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531" "" ""
185     gdb_test "find /w search_buf, +search_buf_size, 0xfdb97531" \
186     "${hex_number}${one_pattern_found}" \
187     "find pattern straddling chunk boundary"