From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30964 invoked by alias); 19 Mar 2010 23:27:43 -0000 Received: (qmail 30956 invoked by uid 22791); 19 Mar 2010 23:27:42 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from smtp-outbound-1.vmware.com (HELO smtp-outbound-1.vmware.com) (65.115.85.69) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 19 Mar 2010 23:27:37 +0000 Received: from mailhost3.vmware.com (mailhost3.vmware.com [10.16.27.45]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 059C51301C for ; Fri, 19 Mar 2010 16:27:36 -0700 (PDT) Received: from [10.20.124.100] (promd-2s-dhcp100.eng.vmware.com [10.20.124.100]) by mailhost3.vmware.com (Postfix) with ESMTP id F0372CD90D for ; Fri, 19 Mar 2010 16:27:35 -0700 (PDT) Message-ID: <4BA40867.4090703@vmware.com> Date: Fri, 19 Mar 2010 23:27:00 -0000 From: Michael Snyder User-Agent: Thunderbird 2.0.0.22 (X11/20090609) MIME-Version: 1.0 To: "gdb-patches@sourceware.org" Subject: [RFA] gdbserver support for qCRC: (compare-sections) Content-Type: multipart/mixed; boundary="------------020908020908090004070906" 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/msg00744.txt.bz2 This is a multi-part message in MIME format. --------------020908020908090004070906 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 292 This patch adds support to gdbserver for the "qCRC:" request. This in turn supports the gdb "compare-sections" command, which basically lets you verify that the binary image on the target matches the executable that you're debugging. I borrowed code from gdb/remote.c, I assume that's OK. --------------020908020908090004070906 Content-Type: text/plain; name="qcrc.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qcrc.txt" Content-length: 1954 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 19 Mar 2010 23:23:15 -0000 @@ -788,6 +788,40 @@ handle_threads_qxfer (const char *annex, } +/* Table used by the crc32 function to calcuate the checksum. */ + +static unsigned long crc32_table[256] = +{0, 0}; + +static unsigned long +crc32 (CORE_ADDR base, int len, unsigned int crc) +{ + 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; + + /* Fixme -- no error checking. */ + read_inferior_memory (base, &byte, 1); + crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ byte) & 255]; + base++; + } + return crc; +} + /* Handle all of the extended 'q' packets. */ void handle_query (char *own_buf, int packet_len, int *new_packet_len_p) @@ -1421,6 +1455,23 @@ 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; + + if (*comma++ != ',') + { + write_enn (own_buf); + return; + } + len = strtoul (comma, NULL, 16); + sprintf (own_buf, "C%lx", crc32 (base, len, 0xffffffff)); + return; + } + /* Otherwise we didn't know what packet it was. Say we didn't understand it. */ own_buf[0] = 0; --------------020908020908090004070906--