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