public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA] gdbserver support for qCRC: (compare-sections)
@ 2010-03-19 23:27 Michael Snyder
  2010-03-22 17:59 ` Michael Snyder
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Snyder @ 2010-03-19 23:27 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 292 bytes --]

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.


[-- Attachment #2: qcrc.txt --]
[-- Type: text/plain, Size: 1954 bytes --]

2010-03-19  Michael Snyder  <msnyder@vmware.com>

	* 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;

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-03-24  1:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-19 23:27 [RFA] gdbserver support for qCRC: (compare-sections) Michael Snyder
2010-03-22 17:59 ` Michael Snyder
2010-03-23 16:26   ` Pedro Alves
2010-03-23 18:16     ` Michael Snyder
2010-03-23 18:32       ` Pedro Alves
2010-03-23 22:44         ` Michael Snyder
2010-03-23 23:15           ` Pedro Alves
2010-03-24  0:16             ` Pedro Alves
2010-03-24  0:34               ` Michael Snyder
2010-03-24  1:15         ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).