From patchwork Wed Aug 19 10:41:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 8293 Received: (qmail 111627 invoked by alias); 19 Aug 2015 10:41:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 111554 invoked by uid 89); 19 Aug 2015 10:41:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 19 Aug 2015 10:41:06 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id DAABC8F011; Wed, 19 Aug 2015 10:41:04 +0000 (UTC) Received: from blade.nx (ovpn-116-91.ams2.redhat.com [10.36.116.91]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7JAf3WE011305; Wed, 19 Aug 2015 06:41:04 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 2FDC4262FAA; Wed, 19 Aug 2015 11:41:03 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Cc: Pedro Alves , Sandra Loosemore , Joel Brobecker , Doug Evans , Jan Kratochvil , =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= , Paul Koning Subject: [PATCH] Prelimit number of bytes to read in "vFile:pread:" Date: Wed, 19 Aug 2015 11:41:02 +0100 Message-Id: <1439980862-21305-1-git-send-email-gbenson@redhat.com> In-Reply-To: <55D3DB83.4050204@redhat.com> References: <55D3DB83.4050204@redhat.com> X-IsSubscribed: yes Pedro Alves wrote: > The fact that Gary's chunk size limiting patch made things much > faster on the nios2 board is still mysterious to me. I'd expect the > slowness to be latency bound, given the request/response nature of > the RSP, but then I'd expect that more chunking would slow things > down, not speed it up. I think I figured this out... 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. Built and regtested on RHEL 6.6 x86_64. May I push this to HEAD and to the branch? Thanks, Gary --- gdb/gdbserver/ChangeLog: * hostio.c (handle_pread): Do not attempt to read more data than hostio_reply_with_data can fit in a packet. --- gdb/gdbserver/ChangeLog | 5 +++++ gdb/gdbserver/hostio.c | 12 ++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-) 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);