From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20855 invoked by alias); 23 Mar 2010 16:26:27 -0000 Received: (qmail 20830 invoked by uid 22791); 23 Mar 2010 16:26:25 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 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; Tue, 23 Mar 2010 16:26:18 +0000 Received: (qmail 25637 invoked from network); 23 Mar 2010 16:26:15 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 23 Mar 2010 16:26:15 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: [RFA] gdbserver support for qCRC: (compare-sections) Date: Tue, 23 Mar 2010 16:26:00 -0000 User-Agent: KMail/1.12.2 (Linux/2.6.31-20-generic; KDE/4.3.2; x86_64; ; ) Cc: Michael Snyder References: <4BA40867.4090703@vmware.com> <4BA7AFFD.6050308@vmware.com> In-Reply-To: <4BA7AFFD.6050308@vmware.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201003231626.13757.pedro@codesourcery.com> X-IsSubscribed: yes 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: 2010-03/txt/msg00790.txt.bz2 On Monday 22 March 2010 17:59:25, Michael Snyder wrote: > 2010-03-19 Michael Snyder > > * server.c (crc32): New function. > (handle_query): Add handling for 'qCRC:' request. > > Index: server.c > =================================================================== > RCS file: /cvs/src/src/gdb/gdbserver/server.c,v > retrieving revision 1.108 > diff -u -p -r1.108 server.c > --- server.c 20 Jan 2010 22:55:38 -0000 1.108 > +++ server.c 22 Mar 2010 17:57:32 -0000 > @@ -788,6 +788,47 @@ handle_threads_qxfer (const char *annex, > > } > > +/* Table used by the crc32 function to calcuate the checksum. */ > + > +static unsigned long crc32_table[256] = > +{0, 0}; > + I know you've copied this from remote.c, but, can't we make this an `unsigned int' table? longs are 64-bit on most 64-bit archs, so this uses up double more memory than needed. > +/* Compute 32 bit CRC from inferior memory. > + > + On success, return 32 bit CRC. > + On failure, return (unsigned long long) -1. */ > + > +static unsigned long long > +crc32 (CORE_ADDR base, int len, unsigned int crc) Can't say I'm thrilled by assuming sizeof (long long) > sizeof (long), but I guess it works on all targets gdbserver cares for presently. > +{ > + if (!crc32_table[1]) > + { > + /* Initialize the CRC table and the decoding table. */ > + int i, j; > + unsigned int c; > + > + for (i = 0; i < 256; i++) > + { > + for (c = i << 24, j = 8; j > 0; --j) > + c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1); > + crc32_table[i] = c; > + } > + } > + > + while (len--) > + { > + unsigned char byte = 0; > + > + /* Return failure if memory read fails. */ > + if (read_inferior_memory (base, &byte, 1) != 0) > + return (unsigned long long) -1; > + > + crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ byte) & 255]; > + base++; > + } > + return (unsigned long long) crc; > +} > + > /* Handle all of the extended 'q' packets. */ > void > handle_query (char *own_buf, int packet_len, int *new_packet_len_p) > @@ -1421,6 +1462,31 @@ handle_query (char *own_buf, int packet_ > return; > } > > + if (strncmp ("qCRC:", own_buf, 5) == 0) > + { > + /* CRC check (compare-segment). */ > + char *comma; > + CORE_ADDR base = strtoul (own_buf + 5, &comma, 16); > + int len; > + unsigned long long crc; > + A `require_running' call is missing here. > + if (*comma++ != ',') > + { > + write_enn (own_buf); > + return; > + } > + len = strtoul (comma, NULL, 16); > + crc = crc32 (base, len, 0xffffffff); > + /* Check for memory failure. */ > + if (crc == (unsigned long long) -1) > + { > + write_enn (own_buf); > + return; > + } > + sprintf (own_buf, "C%lx", (unsigned long) crc); > + return; > + } > + > /* Otherwise we didn't know what packet it was. Say we didn't > understand it. */ > own_buf[0] = 0; Otherwise, looks fine to me. -- Pedro Alves