]>
Commit | Line | Data |
---|---|---|
4c38e0a4 | 1 | # Copyright 2008, 2009, 2010 Free Software Foundation, Inc. |
08388c79 DE |
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 | ||
08388c79 DE |
16 | # This tests the find command. |
17 | ||
18 | if $tracelevel then { | |
19 | strace $tracelevel | |
20 | } | |
21 | ||
22 | set testfile "find" | |
23 | set srcfile ${testfile}.c | |
24 | set binfile ${objdir}/${subdir}/${testfile} | |
25 | ||
26 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } { | |
27 | untested find.exp | |
28 | return -1 | |
29 | } | |
30 | ||
31 | gdb_exit | |
32 | gdb_start | |
33 | gdb_reinitialize_dir $srcdir/$subdir | |
34 | gdb_load ${binfile} | |
35 | ||
36 | gdb_test "break $srcfile:stop_here" \ | |
37 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
38 | "breakpoint function in file" | |
39 | ||
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 | } | |
51 | } | |
52 | ||
53 | # We've now got the target program in a state where we can test "find". | |
54 | ||
55 | set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*} | |
56 | set history_prefix {[$][0-9]* = } | |
09f00d9a | 57 | set newline "\[\r\n\]*" |
de90ada1 DE |
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\[.\]" | |
08388c79 DE |
61 | |
62 | # Test string pattern. | |
63 | ||
64 | gdb_test "set *(int32_t*) &int8_search_buf\[10\] = 0x61616161" "" "" | |
65 | ||
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" | |
69 | ||
70 | # Test not finding pattern because search range too small, with | |
71 | # potential find at the edge of the range. | |
72 | ||
73 | gdb_test "find &int8_search_buf\[0\], +10+3, \"aaaa\"" \ | |
74 | "${pattern_not_found}" \ | |
75 | "pattern not found at end of range" | |
76 | ||
77 | # Increase the search range by 1 and we should find the pattern. | |
78 | ||
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" | |
82 | ||
83 | # Test max-count, $_ and $numfound. | |
84 | ||
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" | |
88 | ||
89 | gdb_test "print \$_" \ | |
90 | "${history_prefix}.*${hex_number}" \ | |
91 | "\$_" | |
92 | ||
93 | gdb_test "print \$numfound" \ | |
94 | "${history_prefix}1" \ | |
95 | "\$numfound" | |
96 | ||
97 | # Test max-count with size-char. | |
98 | # They can be specified in either order. | |
99 | ||
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" | |
103 | ||
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" | |
107 | ||
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" | |
111 | ||
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" | |
115 | ||
116 | # Test specifying end address. | |
117 | ||
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" | |
121 | ||
122 | # Test 16-bit pattern. | |
123 | ||
124 | gdb_test "set int16_search_buf\[10\] = 0x1234" "" "" | |
125 | ||
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" | |
129 | ||
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" | |
133 | ||
134 | # Test 32-bit pattern. | |
135 | ||
136 | gdb_test "set int32_search_buf\[10\] = 0x12345678" "" "" | |
137 | ||
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" | |
141 | ||
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" | |
145 | ||
146 | # Test 64-bit pattern. | |
147 | ||
148 | gdb_test "set int64_search_buf\[10\] = 0xfedcba9876543210LL" "" "" | |
149 | ||
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" | |
153 | ||
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" | |
157 | ||
158 | # Test mixed-sized patterns. | |
159 | ||
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" "" "" | |
163 | ||
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" | |
167 | ||
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. | |
171 | ||
172 | set CHUNK_SIZE 16000 ;# see findcmd.c | |
173 | ||
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" "" "" | |
176 | ||
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" | |
180 | ||
181 | # For native targets, test a pattern straddling a chunk boundary. | |
182 | ||
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" | |
188 | } |