From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31124 invoked by alias); 19 Aug 2011 17:11:21 -0000 Received: (qmail 31115 invoked by uid 22791); 19 Aug 2011 17:11:20 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,TW_FP,TW_UF X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 19 Aug 2011 17:11:01 +0000 Received: (qmail 25517 invoked from network); 19 Aug 2011 17:11:00 -0000 Received: from unknown (HELO ?192.168.0.102?) (lgustavo@127.0.0.2) by mail.codesourcery.com with ESMTPA; 19 Aug 2011 17:11:00 -0000 Message-ID: <4E4E9926.9000800@codesourcery.com> Date: Fri, 19 Aug 2011 17:11:00 -0000 From: Luis Machado Reply-To: lgustavo@codesourcery.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 Thunderbird/3.1.11 MIME-Version: 1.0 To: gdb-patches@sourceware.org, Pedro Alves Subject: [PATCH] Speed up target_read_string Content-Type: multipart/mixed; boundary="------------000206080805090000090007" Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-08/txt/msg00377.txt.bz2 This is a multi-part message in MIME format. --------------000206080805090000090007 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 332 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 --------------000206080805090000090007 Content-Type: text/x-patch; name="target_read_string.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="target_read_string.diff" Content-length: 2708 2011-08-19 Pedro Alves Luis Machado * 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; --------------000206080805090000090007--