From patchwork Thu Aug 21 02:09:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 2477 Received: (qmail 30876 invoked by alias); 21 Aug 2014 02:13:22 -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 30857 invoked by uid 89); 21 Aug 2014 02:13:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Aug 2014 02:13:15 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1XKHsG-00043z-AP from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Wed, 20 Aug 2014 19:13:12 -0700 Received: from SVR-ORW-FEM-04.mgc.mentorg.com ([147.34.97.41]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 20 Aug 2014 19:13:12 -0700 Received: from qiyao.dyndns.org.com (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.2.247.3; Wed, 20 Aug 2014 19:13:11 -0700 From: Yao Qi To: Subject: [PATCH] Refine read_string Date: Thu, 21 Aug 2014 10:09:03 +0800 Message-ID: <1408586943-24077-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes In read_string, we have this line chunksize = (len == -1 ? min (8, fetchlimit) : fetchlimit); but chunksize is only used in the block that lne == -1, so IWBN to move chunksize to the block in which it is used, and simplify the condition setting chunksize. This patch also moves 'found_nul' to inner block. This patch also splits a paragraph of comment into two, and move them to different condition blocks (len > 0 and len == -1) respectively. Rebuild GDB on x86-linux. Is it OK? gdb: 2014-08-21 Yao Qi * valprint.c (read_string): Move local variables 'found_nul', 'chunksize' and 'limit' to inner scope. Update comments. --- gdb/valprint.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/gdb/valprint.c b/gdb/valprint.c index 8cb5c74..315e455 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -1794,36 +1794,23 @@ int read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit, enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read) { - int found_nul; /* Non-zero if we found the nul char. */ int errcode; /* Errno returned from bad reads. */ unsigned int nfetch; /* Chars to fetch / chars fetched. */ - unsigned int chunksize; /* Size of each fetch, in chars. */ gdb_byte *bufptr; /* Pointer to next available byte in buffer. */ - gdb_byte *limit; /* First location past end of fetch buffer. */ struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */ - /* Decide how large of chunks to try to read in one operation. This - is also pretty simple. If LEN >= zero, then we want fetchlimit chars, - so we might as well read them all in one operation. If LEN is -1, we - are looking for a NUL terminator to end the fetching, so we might as - well read in blocks that are large enough to be efficient, but not so - large as to be slow if fetchlimit happens to be large. So we choose the - minimum of 8 and fetchlimit. We used to use 200 instead of 8 but - 200 is way too big for remote debugging over a serial line. */ - - chunksize = (len == -1 ? min (8, fetchlimit) : fetchlimit); - /* Loop until we either have all the characters, or we encounter some error, such as bumping into the end of the address space. */ - found_nul = 0; *buffer = NULL; old_chain = make_cleanup (free_current_contents, buffer); if (len > 0) { + /* We want fetchlimit chars, so we might as well read them all in + one operation. */ unsigned int fetchlen = min (len, fetchlimit); *buffer = (gdb_byte *) xmalloc (fetchlen * width); @@ -1837,6 +1824,18 @@ read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit, else if (len == -1) { unsigned long bufsize = 0; + unsigned int chunksize; /* Size of each fetch, in chars. */ + int found_nul; /* Non-zero if we found the nul char. */ + gdb_byte *limit; /* First location past end of fetch buffer. */ + + found_nul = 0; + /* We are looking for a NUL terminator to end the fetching, so we + might as well read in blocks that are large enough to be efficient, + but not so large as to be slow if fetchlimit happens to be large. + So we choose the minimum of 8 and fetchlimit. We used to use 200 + instead of 8 but 200 is way too big for remote debugging over a + serial line. */ + chunksize = min (8, fetchlimit); do {