2011-07-20 Pedro Alves Luis Machado gdb/ * 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. --- gdb/target.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) Index: src/gdb/target.c =================================================================== --- src.orig/gdb/target.c 2011-06-07 18:54:30.078164934 +0100 +++ src/gdb/target.c 2011-07-20 14:57:39.933657572 +0100 @@ -88,6 +88,11 @@ static LONGEST target_xfer_partial (stru 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 @@ target_translate_tls_address (struct obj 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;