From: Luis Machado <lgustavo@codesourcery.com>
To: gdb-patches@sourceware.org, Pedro Alves <pedro@codesourcery.com>
Subject: [PATCH] Speed up target_read_string
Date: Fri, 19 Aug 2011 17:11:00 -0000 [thread overview]
Message-ID: <4E4E9926.9000800@codesourcery.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 332 bytes --]
Hi,
The following change is aimed at increasing the performance of
target_read_string for remote debugging. To accomplish that, the buffer
has been increased to 64 bytes and we now use target_read_partial
instead of target_read_memory.
The increase in the buffer size reduces the impact of the remote
transfer overhead.
Luis
[-- Attachment #2: target_read_string.diff --]
[-- Type: text/x-patch, Size: 2708 bytes --]
2011-08-19 Pedro Alves <pedro@codesourcery.com>
Luis Machado <lgustavo@codesourcery.com>
* target.c (target_read_partial): Declare prototype.
(target_read_string): Use 64-bytes blocks for reads and use
target_read_partial instead of target_read_memory.
Index: gdb/target.c
===================================================================
--- gdb/target.c.orig 2011-08-18 12:13:58.773749146 -0300
+++ gdb/target.c 2011-08-19 11:13:00.297749146 -0300
@@ -88,6 +88,11 @@
void *readbuf, const void *writebuf,
ULONGEST offset, LONGEST len);
+static LONGEST target_read_partial (struct target_ops *ops,
+ enum target_object object,
+ const char *annex, gdb_byte *buf,
+ ULONGEST offset, LONGEST len);
+
static struct gdbarch *default_thread_architecture (struct target_ops *ops,
ptid_t ptid);
@@ -1185,55 +1190,51 @@
int
target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
{
- int tlen, origlen, offset, i;
- gdb_byte buf[4];
- int errcode = 0;
- char *buffer;
- int buffer_allocated;
- char *bufptr;
- unsigned int nbytes_read = 0;
+ int tlen, i, errcode = 0, buffer_allocated;
+ gdb_byte buf[64];
+ char *buffer, *bufptr;
+ unsigned int nbytes_read = 0, raw_read = 0;
+ LONGEST xfered;
gdb_assert (string);
/* Small for testing. */
- buffer_allocated = 4;
+ buffer_allocated = 64;
buffer = xmalloc (buffer_allocated);
bufptr = buffer;
- origlen = len;
-
while (len > 0)
{
- tlen = MIN (len, 4 - (memaddr & 3));
- offset = memaddr & 3;
+ tlen = MIN (len, 64);
- errcode = target_read_memory (memaddr & ~3, buf, sizeof buf);
- if (errcode != 0)
+ xfered = target_read_partial (current_target.beneath,
+ TARGET_OBJECT_MEMORY,
+ NULL, buf,
+ memaddr, tlen);
+ if (xfered <= 0)
{
/* The transfer request might have crossed the boundary to an
unallocated region of memory. Retry the transfer, requesting
a single byte. */
tlen = 1;
- offset = 0;
errcode = target_read_memory (memaddr, buf, 1);
if (errcode != 0)
goto done;
}
+ else
+ raw_read += tlen;
- if (bufptr - buffer + tlen > buffer_allocated)
+ if (raw_read > buffer_allocated)
{
- unsigned int bytes;
-
- bytes = bufptr - buffer;
buffer_allocated *= 2;
buffer = xrealloc (buffer, buffer_allocated);
- bufptr = buffer + bytes;
+ bufptr = buffer + raw_read - tlen;
}
for (i = 0; i < tlen; i++)
{
- *bufptr++ = buf[i + offset];
- if (buf[i + offset] == '\000')
+ *bufptr++ = buf[i];
+ if (buf[i] == '\000')
{
nbytes_read += i + 1;
goto done;
next reply other threads:[~2011-08-19 17:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-19 17:11 Luis Machado [this message]
2011-08-20 18:37 ` Jan Kratochvil
2011-08-20 21:11 ` Daniel Jacobowitz
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=4E4E9926.9000800@codesourcery.com \
--to=lgustavo@codesourcery.com \
--cc=gdb-patches@sourceware.org \
--cc=pedro@codesourcery.com \
/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