From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [RFA] py-inferior.exp: Avoid searching pattern beyond buffer
Date: Wed, 02 Mar 2011 15:26:00 -0000 [thread overview]
Message-ID: <1299079586-23077-1-git-send-email-brobecker@adacore.com> (raw)
The testcase is searching patterns inside a buffer created by
the inferior (a 32,000 character array). At some point, it is
searching successively the same pattern 3 times. It finds the
first one, sets the new search address just right after the find,
then searches again from there, finds the second instance. And
finally does a third search, expecting it to fail because the buffer
has been setup to have only 2 instances of the pattern.
Unfortunately, each search was over the same length, which is 32,000
bytes. So, starting with the second search, we're already possibly
searching in memory beyond the buffer. We stop the search in time
because we find the second instance. But in the last search, we
happily search beyond the buffer, because we don't have a match
to stop our search!
We'd have to be pretty unlucky to see a failure, since the search
pattern is pretty specific. But in fact, I got a failure on LynxOS
(it found a match), and on sparc-solaris as well (we ran into
forbidden memory).
I fixed the problem by making recomputing the length at every search.
gdb/testsuite/ChangeLog:
* gdb.python/py-inferior.exp: Avoid searching pattern beyond
end of buffer.
Tested on x86_64-linux.
---
gdb/testsuite/gdb.python/py-inferior.exp | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index c219117..138c0fb 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -171,15 +171,15 @@ set CHUNK_SIZE 16000 ;
gdb_test_no_output "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678"
gdb_test_no_output "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678"
gdb_test_no_output "py start_addr = gdb.selected_frame ().read_var ('search_buf')"
-gdb_test_no_output "py length = gdb.selected_frame ().read_var ('search_buf_size')"
+gdb_test_no_output "py end_addr = start_addr + gdb.selected_frame ().read_var ('search_buf_size')"
gdb_test_no_output "py pattern = pack('${python_pack_char}I', 0x12345678)"
-gdb_test_no_output "py first = gdb.inferiors()\[0\].search_memory (start_addr,length, pattern)"
+gdb_test_no_output "py first = gdb.inferiors()\[0\].search_memory (start_addr,end_addr - start_addr, pattern)"
gdb_test "py print first" "${one_pattern_found}" "search spanning large range 1st result"
gdb_test_no_output "py start_addr = first + 1"
-gdb_test_no_output "py second = gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)"
+gdb_test_no_output "py second = gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)"
gdb_test "py print second" "${one_pattern_found}" "search spanning large range 2nd result"
gdb_test_no_output "py start_addr = second + 1"
-gdb_test_no_output "py third = gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)"
+gdb_test_no_output "py third = gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)"
gdb_test "py print third" "${pattern_not_found}" "search spanning large range 3rd result"
# For native targets, test a pattern straddling a chunk boundary.
@@ -188,6 +188,6 @@ if [isnative] {
gdb_test_no_output "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531"
gdb_test_no_output "py pattern = pack('${python_pack_char}I', 0xfdb97531)"
gdb_test_no_output "py start_addr = gdb.selected_frame ().read_var ('search_buf')"
- gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
+ gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)" \
"${one_pattern_found}" "find pattern straddling chunk boundary"
}
--
1.7.1
next reply other threads:[~2011-03-02 15:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-02 15:26 Joel Brobecker [this message]
2011-03-02 18:11 ` Tom Tromey
2011-03-03 4:02 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1299079586-23077-1-git-send-email-brobecker@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox