All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: GDB patch
@ 2002-12-10 19:19 ` Nigel Stephens
  0 siblings, 0 replies; 9+ messages in thread
From: Nigel Stephens @ 2002-12-10 19:19 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Carsten Langgaard, Ralf Baechle, linux-mips

> On Tue, Dec 10, 2002 at 01:07:31PM +0100, Carsten Langgaard wrote:
> 
> > I've attached a patch for gdb-stub.c to make it work better with the
> > sde-gdb.
> > These changes should be backwards compatible with a standard gdb, so it
> > shouldn't break anything.
> > Ralf, could you please apply it.
> 
> 
> Strongly object.  While I didn't check the implementation, it's nice to
> see 'X' implemented.  And P.  But what the heck is this?
> 
> 
> > @@ -816,13 +839,64 @@
> >  		case 'k' :
> >  			break;		/* do nothing */
> >  
> > +		case 'R':
> > +			/* RNN[:SS],	Set the value of CPU register NN (size SS) */
> > +			/* FALL THROUGH */
> 
> 
> > -		/*
> > -		 * Reset the whole machine (FIXME: system dependent)
> > -		 */
> >  		case 'r':
> > -			break;
> > +			/* rNN[:SS]	Return the value of CPU register NN (size SS) */
> 
> 
> 
> We're not making up a protocol here, we're implementing one.  R and r
> don't have anything to do with setting registers.

Hi Dan

Actually Carsten *is* trying to implement a protocol, it's just that
it's an extension to the gdb remote debug protocol, as used in our
SDE-MIPS toolchain (viz sde-gdb).  Algorithmics (now MIPS Technologies
UK), always extended the gdb remote debug protocol to support reading
and writing of single registers, and to support variable register
sizes (to allow a 64-bit debug stub to inter-work with gdb debugging a
32-bit application).

When we first implemented these extensions we used the 'R' command to
write a single register, and 'r' to read one (they weren't then used
by gdb). Since then the remote protocol has gained the 'P' command to
write a single register, so we no longer use 'R' - and it would be
dangerous to do so since it can restart the target (so you can get rid
of the special 'R' case, Carsten).

But the standard gdb remote protocol still doesn't have the ability to
read a single register, so I believe that 'r' (or something like it)
is a useful addition, which speeds up the remote protocol
significantly when running over a serial line. And it won't break the
kernel to add support for this extension.

Regards

Nigel
-- 
                         Nigel Stephens         Mailto:nigel@mips.com
    _    _ ____  ___     MIPS Technologies (UK) Phone.: +44 1223 706200
    |\  /|||___)(___     The Fruit Farm         Direct: +44 1223 706207
    | \/ |||    ____)    Ely Road, Chittering   Fax...: +44 1223 706250
    TECHNOLOGIES (UK)    Cambridge CB5 9PH      Cell..: +44 7976 686470
 [formerly Algorithmics] England                http://www.algor.co.uk

^ permalink raw reply	[flat|nested] 9+ messages in thread
* GDB patch
@ 2002-12-10 12:07 Carsten Langgaard
  2002-12-10 16:51 ` Daniel Jacobowitz
  0 siblings, 1 reply; 9+ messages in thread
From: Carsten Langgaard @ 2002-12-10 12:07 UTC (permalink / raw)
  To: Ralf Baechle, linux-mips

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

I've attached a patch for gdb-stub.c to make it work better with the
sde-gdb.
These changes should be backwards compatible with a standard gdb, so it
shouldn't break anything.
Ralf, could you please apply it.

/Carsten

--
_    _ ____  ___   Carsten Langgaard   Mailto:carstenl@mips.com
|\  /|||___)(___   MIPS Denmark        Direct: +45 4486 5527
| \/ |||    ____)  Lautrupvang 4B      Switch: +45 4486 5555
  TECHNOLOGIES     2750 Ballerup       Fax...: +45 4486 5556
                   Denmark             http://www.mips.com



[-- Attachment #2: gdb-stub.patch --]
[-- Type: text/plain, Size: 3896 bytes --]

Index: arch/mips/kernel/gdb-stub.c
===================================================================
RCS file: /home/cvs/linux/arch/mips/kernel/gdb-stub.c,v
retrieving revision 1.15.2.3
diff -u -r1.15.2.3 gdb-stub.c
--- arch/mips/kernel/gdb-stub.c	7 Nov 2002 01:47:45 -0000	1.15.2.3
+++ arch/mips/kernel/gdb-stub.c	10 Dec 2002 11:50:35 -0000
@@ -166,7 +166,7 @@
  * BUFMAX defines the maximum number of characters in inbound/outbound buffers
  * at least NUMREGBYTES*2 are needed for register packets
  */
-#define BUFMAX 2048
+#define BUFMAX 8192
 
 static char input_buffer[BUFMAX];
 static char output_buffer[BUFMAX];
@@ -218,7 +218,7 @@
 		 * now, read until a # or end of buffer is found
 		 */
 		while (count < BUFMAX) {
-			ch = getDebugChar() & 0x7f;
+			ch = getDebugChar();
 			if (ch == '#')
 				break;
 			checksum = checksum + ch;
@@ -324,19 +324,33 @@
  * may_fault is non-zero if we are reading from arbitrary memory, but is currently
  * not used.
  */
-static char *hex2mem(char *buf, char *mem, int count, int may_fault)
+static char *hex2mem(char *buf, char *mem, int count, int binary, int may_fault)
 {
 	int i;
 	unsigned char ch;
+	char *startadr = mem;
 
 	for (i=0; i<count; i++)
 	{
-		ch = hex(*buf++) << 4;
-		ch |= hex(*buf++);
+		if (binary) {
+			ch = *buf++;
+			if (ch == 0x7d)
+				ch = 0x20 ^ *buf++;
+		}
+		else {
+			ch = hex(*buf++) << 4;
+			ch |= hex(*buf++);
+		}
 		if (kgdb_write_byte(ch, mem++) != 0)
 			return 0;
 	}
 
+	/* 
+	 * Since we may have written to instruction space via 
+	 * the data path, the icache needs to be flushed here.
+	 */
+	flush_icache_range(startadr, count);
+
 	return mem;
 }
 
@@ -594,6 +608,7 @@
 	int length;
 	char *ptr;
 	unsigned long *stack;
+	int bflag;
 
 #if 0
 	printk("in handle_exception()\n");
@@ -695,6 +710,7 @@
 	 * Wait for input from remote GDB
 	 */
 	while (1) {
+		bflag = 0;
 		output_buffer[0] = 0;
 		getpacket(input_buffer);
 
@@ -767,6 +783,13 @@
 			break;
 
 		/*
+		 * XAA..AA,LLLL: Write LLLL escaped binary bytes at address AA.AA
+		 */
+		case 'X':
+			bflag = 1;
+			/* fall through */
+
+		/*
 		 * MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK
 		 */
 		case 'M':
@@ -776,7 +799,7 @@
 				&& *ptr++ == ','
 				&& hexToInt(&ptr, &length)
 				&& *ptr++ == ':') {
-				if (hex2mem(ptr, (char *)addr, length, 1))
+				if (hex2mem(ptr, (char *)addr, length, bflag, 1))
 					strcpy(output_buffer, "OK");
 				else
 					strcpy(output_buffer, "E03");
@@ -816,13 +839,64 @@
 		case 'k' :
 			break;		/* do nothing */
 
+		case 'R':
+			/* RNN[:SS],	Set the value of CPU register NN (size SS) */
+			/* FALL THROUGH */
+
+		case 'P':
+			/* PNN[:SS]=	Set the value of CPU register NN (size SS) */
+		{
+			int regno, regsize = 4, regval;
+			ptr = &input_buffer[1];
+
+			if (!hexToInt (&ptr, &regno))
+				goto error;
+
+			ptr++;
+			if (!hexToInt (&ptr, &regsize))
+				goto error;
+
+			if (regsize != 4)
+				goto error;
+			if (*ptr != ((input_buffer[0] == 'P') ? '=' : ','))
+				goto error;
+			ptr++;
+			if (!hex2mem (ptr, (char *)&regval, 4, 0, 0))
+				goto error;
+
+			memcpy ((char *)&regs->reg0+regno*4, &regval, 4);
+			strcpy (output_buffer, "OK");
+		}
+		break;
 
-		/*
-		 * Reset the whole machine (FIXME: system dependent)
-		 */
 		case 'r':
-			break;
+			/* rNN[:SS]	Return the value of CPU register NN (size SS) */
+		{
+			int regno, regsize = 4;
+			ptr = &input_buffer[1];
+			if (hexToInt (&ptr, &regno)) {
+				if (*ptr == ':') {
+					ptr++;
+					if (!hexToInt (&ptr, &regsize))
+						goto error;
+				}
+
+				if (regsize != 4)
+					goto error;
+				(void) mem2hex((char *)&regs->reg0+regno*4, 
+					       output_buffer, 4, 0);
+			}
+			else {
+			error:
+				strcpy(output_buffer,"E22 invalid arguments");
+			}
+		}
+		break;
 
+		case 'D':
+			putpacket("OK");
+			return;
+			/* NOTREACHED */
 
 		/*
 		 * Step to next instruction

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

end of thread, other threads:[~2002-12-11 17:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-10 19:19 GDB patch Nigel Stephens
2002-12-10 19:19 ` Nigel Stephens
2002-12-10 19:32 ` Daniel Jacobowitz
2002-12-10 20:40   ` Nigel Stephens
2002-12-11 16:52     ` Daniel Jacobowitz
2002-12-11 17:24       ` Nigel Stephens
2002-12-11 17:56         ` Daniel Jacobowitz
  -- strict thread matches above, loose matches on Subject: below --
2002-12-10 12:07 Carsten Langgaard
2002-12-10 16:51 ` Daniel Jacobowitz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.