Patch from Ian Lance Taylor <ian@airs.com>:

The RTEMS i386 stub in
        c/src/lib/libbsp/i386/shared/comm/i386-stub.c
    doesn't take advantage of some of the newer gdb remote features which
    permits shorter and fewer packets.

    Here is a patch which uses the 'T' response to report the registers
    which gdb generally needs, and implements the 'P' request to set only
    a single register.  The general effect is to avoid sending all the
    register contents back and forth between gdb and the stub every time
    the stub stops.  This also implements the 'D' request which handles
    the gdb detach command, so you can cleanly quit out of the debugger
    and leave the target board running.
This commit is contained in:
Joel Sherrill
1998-10-28 19:41:06 +00:00
parent b4e3b2bd68
commit 22fa583204

View File

@@ -124,8 +124,15 @@ void waitabit ();
static const char hexchars[] = "0123456789abcdef";
/* Number of registers. */
#define NUMREGS 16
/* Number of bytes per register. */
#define REGBYTES 4
/* Number of bytes of registers. */
#define NUMREGBYTES 64
#define NUMREGBYTES (NUMREGS * REGBYTES)
enum regnames
{
EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
@@ -137,7 +144,7 @@ enum regnames
/*
* these should not be static cuz they can be used outside this module
*/
int registers[NUMREGBYTES / 4];
int registers[NUMREGS];
#define STACKSIZE 10000
int remcomStack[STACKSIZE / sizeof (int)];
@@ -741,7 +748,7 @@ void
handle_exception (int exceptionVector)
{
int sigval;
int addr, length;
int addr, length, reg;
char *ptr;
int newPC;
@@ -753,12 +760,33 @@ handle_exception (int exceptionVector)
registers[PS],
registers[PC]);
/* reply to host that an exception has occurred */
/* Reply to host that an exception has occurred. Always return the
PC, SP, and FP, since gdb always wants them. */
ptr = remcomOutBuffer;
*ptr++ = 'T';
sigval = computeSignal (exceptionVector);
remcomOutBuffer[0] = 'S';
remcomOutBuffer[1] = hexchars[sigval >> 4];
remcomOutBuffer[2] = hexchars[sigval % 16];
remcomOutBuffer[3] = 0;
*ptr++ = hexchars[sigval >> 4];
*ptr++ = hexchars[sigval % 16];
*ptr++ = hexchars[ESP];
*ptr++ = ':';
mem2hex ((char *) &registers[ESP], ptr, REGBYTES, 0);
ptr += REGBYTES * 2;
*ptr++ = ';';
*ptr++ = hexchars[EBP];
*ptr++ = ':';
mem2hex ((char *) &registers[EBP], ptr, REGBYTES, 0);
ptr += REGBYTES * 2;
*ptr++ = ';';
*ptr++ = hexchars[PC];
*ptr++ = ':';
mem2hex ((char *) &registers[PC], ptr, REGBYTES, 0);
ptr += REGBYTES * 2;
*ptr++ = ';';
*ptr = '\0';
putpacket (remcomOutBuffer);
@@ -786,6 +814,22 @@ handle_exception (int exceptionVector)
strcpy (remcomOutBuffer, "OK");
break;
case 'P': /* Set specific register */
ptr = &remcomInBuffer[1];
if (hexToInt (&ptr, &reg)
&& *ptr++ == '=')
{
hex2mem (ptr, (char *) &registers[reg], REGBYTES, 0);
strcpy (remcomOutBuffer, "OK");
}
else
{
strcpy (remcomOutBuffer, "E01");
debug_error ("malformed register set command; %s",
remcomInBuffer);
}
break;
/* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
case 'm':
/* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */
@@ -864,6 +908,14 @@ handle_exception (int exceptionVector)
break;
/* Detach. */
case 'D':
putpacket (remcomOutBuffer);
registers[PS] &= 0xfffffeff;
_returnFromException (); /* this is a jump */
break;
/* kill the program */
case 'k': /* do nothing */
break;