This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

more stub tweaks


The enclosed patch changes the i386 and m68k stubs to use the 'T'
response to return the values of the PC, FP, and SP registers in
addition to the signal value, instead of the 'S' response.  This
change improves the performance of single stepping, since GDB no
longer has to fetch all registers between steps.

This patch also changes all the stubs except those for the sh and 
m32r to not send a 'S' or 'T' unless GDB is expecting it (in other 
words, after GDB has issued a execution (c/C/s/S) command).  This
change makes the initial connection to the target more reliable.

Without this change, when handle_exception() is invoked (because of a
call to breakpoint() or a real target exception), it will attempt to
send a status response until it receives an ACK from GDB.  GDB sends
an ACK before it attempts to send any commands, but if it is lost or
mangled, GDB will not be able to establish communication with the 
target.  With this change, the target will wait passively until GDB
sends commands.

This was implemented by introducing a new static variable 'executing'
which is initially 0, but is set to 1 when an execution command is
handled.  If the stubs implemented the detach command, it would set
the value to 0.

This is not foolproof --- If communication between GDB and the target
is terminated abruptly, 'executing' will not be reset, and the stub
will be transmitting the execution status response when user attempts
to re-attach.  But it's no worse than before.

This change is also applicable to the m32r and sh stubs, but both 
have unique code at the beginning of handle_exception() (to handle
syscalls, single step, etc.)  Someone with a working development
environment would be a better candidate to make those changes).

        --JTC

1999-10-13  J.T. Conklin  <jtc@redback.com>

	* i386-stub.c, m68k-stub.c, sparc-stub.c, sparcl-stub.c,
 	sparclet-stub.c (handle_exception): Don't send 'S' or 'T'
 	responses unless GDB is expecting one because a execution
	command (c/C/s/S) was issued.

	* i386-stub.c, m68k-stub.c (handle_exception): Use 'T' response 
	to return PC, FP, and SP.

Index: i386-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/i386-stub.c,v
retrieving revision 1.9
diff -c -r1.9 i386-stub.c
*** i386-stub.c	1999/09/01 07:31:09	1.9
--- i386-stub.c	1999/10/08 22:23:29
***************
*** 700,705 ****
--- 700,706 ----
   */
  void handle_exception(int exceptionVector)
  {
+   static int executing = 0;
    int    sigval, stepping;
    int    addr, length;
    char * ptr;
***************
*** 714,725 ****
  
    /* reply to host that an exception has occurred */
    sigval = computeSignal( exceptionVector );
!   remcomOutBuffer[0] = 'S';
!   remcomOutBuffer[1] =  hexchars[sigval >> 4];
!   remcomOutBuffer[2] =  hexchars[sigval % 16];
!   remcomOutBuffer[3] = 0;
  
!   putpacket(remcomOutBuffer);
  
    stepping = 0;
  
--- 715,750 ----
  
    /* reply to host that an exception has occurred */
    sigval = computeSignal( exceptionVector );
!   if (executing) 
!     {
!       ptr = remcomOutBuffer;
! 
!       *ptr++ = 'T';
!       *ptr++ = hexchars[sigval >> 4];
!       *ptr++ = hexchars[sigval & 0xf];
!       
!       *ptr++ = hexchars[ESP >> 4];
!       *ptr++ = hexchars[ESP & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[ESP], ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[EBP >> 4];
!       *ptr++ = hexchars[EBP & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[EBP], ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[PC >> 4];
!       *ptr++ = hexchars[PC & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[PC], ptr, 4, 0);
!       *ptr++ = ';';
  
!       *ptr++ = 0;
! 
!       putpacket(remcomOutBuffer);
!     }
  
    stepping = 0;
  
***************
*** 822,827 ****
--- 847,854 ----
  
            /* set the trace bit if we're stepping */
            if (stepping) registers[ PS ] |= 0x100;
+ 
+ 	  executing = 1;
  
  	  _returnFromException(); /* this is a jump */
            break;
Index: m68k-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/m68k-stub.c,v
retrieving revision 1.10
diff -c -r1.10 m68k-stub.c
*** m68k-stub.c	1999/10/06 21:54:03	1.10
--- m68k-stub.c	1999/10/08 22:29:19
***************
*** 753,758 ****
--- 753,759 ----
   */
  void handle_exception(int exceptionVector)
  {
+   static int executing = 0;
    int    sigval, stepping;
    int    addr, length;
    char * ptr;
***************
*** 766,777 ****
  
    /* reply to host that an exception has occurred */
    sigval = computeSignal( exceptionVector );
!   remcomOutBuffer[0] = 'S';
!   remcomOutBuffer[1] =  hexchars[sigval >> 4];
!   remcomOutBuffer[2] =  hexchars[sigval % 16];
!   remcomOutBuffer[3] = 0;
  
!   putpacket(remcomOutBuffer); 
  
    stepping = 0;
  
--- 767,802 ----
  
    /* reply to host that an exception has occurred */
    sigval = computeSignal( exceptionVector );
!   if (executing) 
!     {
!       ptr = remcomOutBuffer;
! 
!       *ptr++ = 'T';
!       *ptr++ = hexchars[sigval >> 4];
!       *ptr++ = hexchars[sigval & 0xf];
!       
!       *ptr++ = hexchars[A6 >> 4];
!       *ptr++ = hexchars[A6 & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[A6], ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[A7 >> 4];
!       *ptr++ = hexchars[A7 & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[A7], ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[PC >> 4];
!       *ptr++ = hexchars[PC & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[PC], ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = 0;
  
!       putpacket(remcomOutBuffer);
!     }
  
    stepping = 0;
  
***************
*** 868,873 ****
--- 893,900 ----
            
            /* set the trace bit if we're stepping */
            if (stepping) registers[ PS ] |= 0x8000;
+ 
+           executing = 1;
            
            /*
             * look for newPC in the linked list of exception frames.
Index: sparc-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/sparc-stub.c,v
retrieving revision 1.7
diff -c -r1.7 sparc-stub.c
*** sparc-stub.c	1999/09/01 06:29:30	1.7
--- sparc-stub.c	1999/10/08 22:45:41
***************
*** 567,572 ****
--- 567,573 ----
  handle_exception (registers)
       unsigned long *registers;
  {
+   static int executing = 0;
    int tt;			/* Trap type */
    int sigval;
    int addr;
***************
*** 606,650 ****
  
    /* reply to host that an exception has occurred */
    sigval = computeSignal(tt);
!   ptr = remcomOutBuffer;
  
!   *ptr++ = 'T';
!   *ptr++ = hexchars[sigval >> 4];
!   *ptr++ = hexchars[sigval & 0xf];
! 
!   *ptr++ = hexchars[PC >> 4];
!   *ptr++ = hexchars[PC & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&registers[PC], ptr, 4, 0);
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[FP >> 4];
!   *ptr++ = hexchars[FP & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex(sp + 8 + 6, ptr, 4, 0); /* FP */
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[SP >> 4];
!   *ptr++ = hexchars[SP & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&sp, ptr, 4, 0);
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[NPC >> 4];
!   *ptr++ = hexchars[NPC & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&registers[NPC], ptr, 4, 0);
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[O7 >> 4];
!   *ptr++ = hexchars[O7 & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&registers[O7], ptr, 4, 0);
!   *ptr++ = ';';
  
!   *ptr++ = 0;
  
!   putpacket(remcomOutBuffer);
  
    while (1)
      {
--- 607,654 ----
  
    /* reply to host that an exception has occurred */
    sigval = computeSignal(tt);
!   if (executing) 
!     {
!       ptr = remcomOutBuffer;
  
!       *ptr++ = 'T';
!       *ptr++ = hexchars[sigval >> 4];
!       *ptr++ = hexchars[sigval & 0xf];
! 
!       *ptr++ = hexchars[PC >> 4];
!       *ptr++ = hexchars[PC & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[PC], ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[FP >> 4];
!       *ptr++ = hexchars[FP & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex(sp + 8 + 6, ptr, 4, 0); /* FP */
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[SP >> 4];
!       *ptr++ = hexchars[SP & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&sp, ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[NPC >> 4];
!       *ptr++ = hexchars[NPC & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[NPC], ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[O7 >> 4];
!       *ptr++ = hexchars[O7 & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[O7], ptr, 4, 0);
!       *ptr++ = ';';
  
!       *ptr++ = 0;
  
!       putpacket(remcomOutBuffer);
!     }
  
    while (1)
      {
***************
*** 745,750 ****
--- 749,756 ----
  	      registers[PC] = addr;
  	      registers[NPC] = addr + 4;
  	    }
+ 
+           executing = 1;
  
  /* Need to flush the instruction cache here, as we may have deposited a
     breakpoint, and the icache probably has no way of knowing that a data ref to
Index: sparcl-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/sparcl-stub.c,v
retrieving revision 1.7
diff -c -r1.7 sparcl-stub.c
*** sparcl-stub.c	1999/09/01 06:29:31	1.7
--- sparcl-stub.c	1999/10/08 22:47:19
***************
*** 695,700 ****
--- 695,701 ----
  handle_exception (registers)
       unsigned long *registers;
  {
+   static int executing = 0;
    int tt;			/* Trap type */
    int sigval;
    int addr;
***************
*** 749,793 ****
  
    /* reply to host that an exception has occurred */
    sigval = computeSignal(tt);
!   ptr = remcomOutBuffer;
  
!   *ptr++ = 'T';
!   *ptr++ = hexchars[sigval >> 4];
!   *ptr++ = hexchars[sigval & 0xf];
! 
!   *ptr++ = hexchars[PC >> 4];
!   *ptr++ = hexchars[PC & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&registers[PC], ptr, 4, 0);
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[FP >> 4];
!   *ptr++ = hexchars[FP & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex(sp + 8 + 6, ptr, 4, 0); /* FP */
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[SP >> 4];
!   *ptr++ = hexchars[SP & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&sp, ptr, 4, 0);
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[NPC >> 4];
!   *ptr++ = hexchars[NPC & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&registers[NPC], ptr, 4, 0);
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[O7 >> 4];
!   *ptr++ = hexchars[O7 & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&registers[O7], ptr, 4, 0);
!   *ptr++ = ';';
  
!   *ptr++ = 0;
  
!   putpacket(remcomOutBuffer);
  
    while (1)
      {
--- 750,797 ----
  
    /* reply to host that an exception has occurred */
    sigval = computeSignal(tt);
!   if (executing) 
!     {
!       ptr = remcomOutBuffer;
  
!       *ptr++ = 'T';
!       *ptr++ = hexchars[sigval >> 4];
!       *ptr++ = hexchars[sigval & 0xf];
! 
!       *ptr++ = hexchars[PC >> 4];
!       *ptr++ = hexchars[PC & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[PC], ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[FP >> 4];
!       *ptr++ = hexchars[FP & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex(sp + 8 + 6, ptr, 4, 0); /* FP */
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[SP >> 4];
!       *ptr++ = hexchars[SP & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&sp, ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[NPC >> 4];
!       *ptr++ = hexchars[NPC & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[NPC], ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[O7 >> 4];
!       *ptr++ = hexchars[O7 & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[O7], ptr, 4, 0);
!       *ptr++ = ';';
  
!       *ptr++ = 0;
  
!       putpacket(remcomOutBuffer);
!     }
  
    while (1)
      {
***************
*** 898,903 ****
--- 902,909 ----
  	      registers[PC] = addr;
  	      registers[NPC] = addr + 4;
  	    }
+ 
+           executing = 1;
  
  /* Need to flush the instruction cache here, as we may have deposited a
     breakpoint, and the icache probably has no way of knowing that a data ref to
Index: sparclet-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/sparclet-stub.c,v
retrieving revision 1.7
diff -c -r1.7 sparclet-stub.c
*** sparclet-stub.c	1999/09/01 06:29:31	1.7
--- sparclet-stub.c	1999/10/08 22:48:07
***************
*** 777,782 ****
--- 777,783 ----
  handle_exception (registers)
       unsigned long *registers;
  {
+   static int executing = 0;
    int tt;			/* Trap type */
    int sigval;
    int addr;
***************
*** 834,878 ****
  
    /* reply to host that an exception has occurred */
    sigval = computeSignal(tt);
!   ptr = remcomOutBuffer;
  
!   *ptr++ = 'T';
!   *ptr++ = hexchars[sigval >> 4];
!   *ptr++ = hexchars[sigval & 0xf];
! 
!   *ptr++ = hexchars[PC >> 4];
!   *ptr++ = hexchars[PC & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&registers[PC], ptr, 4, 0);
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[FP >> 4];
!   *ptr++ = hexchars[FP & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex(sp + 8 + 6, ptr, 4, 0); /* FP */
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[SP >> 4];
!   *ptr++ = hexchars[SP & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&sp, ptr, 4, 0);
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[NPC >> 4];
!   *ptr++ = hexchars[NPC & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&registers[NPC], ptr, 4, 0);
!   *ptr++ = ';';
! 
!   *ptr++ = hexchars[O7 >> 4];
!   *ptr++ = hexchars[O7 & 0xf];
!   *ptr++ = ':';
!   ptr = mem2hex((char *)&registers[O7], ptr, 4, 0);
!   *ptr++ = ';';
  
!   *ptr++ = 0;
  
!   putpacket(remcomOutBuffer);
  
    while (1)
      {
--- 835,882 ----
  
    /* reply to host that an exception has occurred */
    sigval = computeSignal(tt);
!   if (executing)
!     {
!       ptr = remcomOutBuffer;
  
!       *ptr++ = 'T';
!       *ptr++ = hexchars[sigval >> 4];
!       *ptr++ = hexchars[sigval & 0xf];
! 
!       *ptr++ = hexchars[PC >> 4];
!       *ptr++ = hexchars[PC & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[PC], ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[FP >> 4];
!       *ptr++ = hexchars[FP & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex(sp + 8 + 6, ptr, 4, 0); /* FP */
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[SP >> 4];
!       *ptr++ = hexchars[SP & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&sp, ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[NPC >> 4];
!       *ptr++ = hexchars[NPC & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[NPC], ptr, 4, 0);
!       *ptr++ = ';';
! 
!       *ptr++ = hexchars[O7 >> 4];
!       *ptr++ = hexchars[O7 & 0xf];
!       *ptr++ = ':';
!       ptr = mem2hex((char *)&registers[O7], ptr, 4, 0);
!       *ptr++ = ';';
  
!       *ptr++ = 0;
  
!       putpacket(remcomOutBuffer);
!     }
  
    while (1)
      {
***************
*** 1015,1020 ****
--- 1019,1026 ----
  	      registers[PC] = addr;
  	      registers[NPC] = addr + 4;
  	    }
+ 
+           executing = 1;
  
  /* Need to flush the instruction cache here, as we may have deposited a
     breakpoint, and the icache probably has no way of knowing that a data ref to



-- 
J.T. Conklin
RedBack Networks

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]