This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb/gdb-7.10-branch] Prelimit number of bytes to read in "vFile:pread:"
- From: Gary Benson <gary at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 19 Aug 2015 13:06:02 -0000
- Subject: [binutils-gdb/gdb-7.10-branch] Prelimit number of bytes to read in "vFile:pread:"
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5e83dd6fb19ba25a89e321a0eb1373b3d3fc3930
commit 5e83dd6fb19ba25a89e321a0eb1373b3d3fc3930
Author: Gary Benson <gbenson@redhat.com>
Date: Wed Aug 19 14:00:50 2015 +0100
Prelimit number of bytes to read in "vFile:pread:"
While handling "vFile:pread:" packets, gdbserver would read the
number of bytes requested regardless of whether this would fit
into the reply packet. gdbserver would then return a packet's
worth of data and discard the remainder. When accessing large
binaries GDB (via BFD) routinely makes large "vFile:pread:"
requests, resulting in gdbserver allocating large unnecessary
buffers and reading some portions of the file many times over.
This commit causes gdbserver to limit the number of bytes to be
read to a sensible maximum prior to allocating buffers and reading
data.
gdb/gdbserver/ChangeLog:
* hostio.c (handle_pread): Do not attempt to read more data
than hostio_reply_with_data can fit in a packet.
Diff:
---
gdb/gdbserver/ChangeLog | 5 +++++
gdb/gdbserver/hostio.c | 12 ++++++++++++
2 files changed, 17 insertions(+)
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index d035aae..c8bf717 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,8 @@
+2015-08-19 Gary Benson <gbenson@redhat.com>
+
+ * hostio.c (handle_pread): Do not attempt to read more data
+ than hostio_reply_with_data can fit in a packet.
+
2015-08-06 Pedro Alves <palves@redhat.com>
* linux-low.c (move_out_of_jump_pad_callback): Temporarily switch
diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c
index b38a6bd..8788f07 100644
--- a/gdb/gdbserver/hostio.c
+++ b/gdb/gdbserver/hostio.c
@@ -344,6 +344,7 @@ handle_pread (char *own_buf, int *new_packet_len)
{
int fd, ret, len, offset, bytes_sent;
char *p, *data;
+ static int max_reply_size = -1;
p = own_buf + strlen ("vFile:pread:");
@@ -359,6 +360,17 @@ handle_pread (char *own_buf, int *new_packet_len)
return;
}
+ /* Do not attempt to read more than the maximum number of bytes
+ hostio_reply_with_data can fit in a packet. We may still read
+ too much because of escaping, but this is handled below. */
+ if (max_reply_size == -1)
+ {
+ sprintf (own_buf, "F%x;", PBUFSIZ);
+ max_reply_size = PBUFSIZ - strlen (own_buf);
+ }
+ if (len > max_reply_size)
+ len = max_reply_size;
+
data = xmalloc (len);
#ifdef HAVE_PREAD
ret = pread (fd, data, len, offset);