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