This is the mail archive of the gdb-patches@sources.redhat.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]

[PATCH] Add remote P packet handling to GDBSERVER



	The following patch add 'P' packet handling to GDBSERVER
	and does some code clean-up.  This patch replaces my
	GDBSERVER patch of April 26 at:

http://sources.redhat.com/ml/gdb-patches/2001-04/msg00256.html



2001-05-15  John S Kallal  <jskallal@home.com>

	* remote-utils.c (write_ok) : Changed to call standard function 
	strcpy().  (write_enn) ditto.
	
	* remote-utils.c (remote_open) : Changed to call with const pointer.
	(putpkt) ditto.  ( convert_int_to_ascii) ditto.

	* remote-utils.c (input_interrupt) : Added unused calling 
	variable per standards.

	* remote-utils.c (prepare_resume_reply) : Moved global variable 
	to function local scope.
	
	* remote-utils.c (do_P_packet): New function.

	* server.h : Adjusted to match above changes.

	* server.c (main): Removed unneeded variable i. Added case for 
	for detection and handling a 'P' packet.  Added some comments 
	and some code reformating.

	
diff -c -r ../gdb+dejagnu-20010515-org/gdb/gdbserver/remote-utils.c gdb/gdbserver/remote-utils.c
*** ../gdb+dejagnu-20010515-org/gdb/gdbserver/remote-utils.c	Tue Mar  6 03:21:44 2001
--- gdb/gdbserver/remote-utils.c	Tue May 15 13:05:37 2001
***************
*** 42,48 ****
     NAME is the filename used for communication.  */
  
  void
! remote_open (char *name)
  {
    int save_fcntl_flags;
  
--- 42,48 ----
     NAME is the filename used for communication.  */
  
  void
! remote_open (const char *name)
  {
    int save_fcntl_flags;
  
***************
*** 195,201 ****
     The data of the packet is in BUF.  Returns >= 0 on success, -1 otherwise. */
  
  int
! putpkt (char *buf)
  {
    int i;
    unsigned char csum = 0;
--- 195,201 ----
     The data of the packet is in BUF.  Returns >= 0 on success, -1 otherwise. */
  
  int
! putpkt (const char *buf)
  {
    int i;
    unsigned char csum = 0;
***************
*** 259,265 ****
     will cause us to send a SIGINT to the child.  */
  
  static void
! input_interrupt (void)
  {
    int cc;
    char c;
--- 259,265 ----
     will cause us to send a SIGINT to the child.  */
  
  static void
! input_interrupt (int unused)
  {
    int cc;
    char c;
***************
*** 378,399 ****
  void
  write_ok (char *buf)
  {
!   buf[0] = 'O';
!   buf[1] = 'K';
!   buf[2] = '\0';
  }
  
  void
  write_enn (char *buf)
  {
!   buf[0] = 'E';
!   buf[1] = 'N';
!   buf[2] = 'N';
!   buf[3] = '\0';
  }
  
  void
! convert_int_to_ascii (char *from, char *to, int n)
  {
    int nib;
    char ch;
--- 378,394 ----
  void
  write_ok (char *buf)
  {
!   strcpy (buf,"OK");
  }
  
  void
  write_enn (char *buf)
  {
!   strcpy (buf,"ENN");
  }
  
  void
! convert_int_to_ascii (const char *from, char *to, int n)
  {
    int nib;
    char ch;
***************
*** 410,416 ****
  
  
  void
! convert_ascii_to_int (char *from, char *to, int n)
  {
    int nib1, nib2;
    while (n--)
--- 405,411 ----
  
  
  void
! convert_ascii_to_int (const char *from, char *to, int n)
  {
    int nib1, nib2;
    while (n--)
***************
*** 443,448 ****
--- 438,444 ----
  void
  prepare_resume_reply (char *buf, char status, unsigned char signo)
  {
+   static int old_thread_from_wait = 0;
    int nib;
  
    *buf++ = status;
***************
*** 497,503 ****
  }
  
  void
! decode_m_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr)
  {
    int i = 0, j = 0;
    char ch;
--- 493,499 ----
  }
  
  void
! decode_m_packet (const char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr)
  {
    int i = 0, j = 0;
    char ch;
***************
*** 519,525 ****
  }
  
  void
! decode_M_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr,
  		 char *to)
  {
    int i = 0;
--- 515,521 ----
  }
  
  void
! decode_M_packet (const char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr,
  		 char *to)
  {
    int i = 0;
***************
*** 539,542 ****
--- 535,565 ----
      }
  
    convert_ascii_to_int (&from[i++], to, *len_ptr);
+ }
+ 
+ static void
+ inreg (int regno, const char *buf)
+ {
+   int regsize = REGISTER_RAW_SIZE (regno);
+ 
+   convert_ascii_to_int (buf, &registers[REGISTER_BYTE (regno)], regsize );
+   return ;
+ }
+ 
+ void
+ do_P_packet (const char *from)
+ {
+   int regno;
+   char *pos;
+ 
+   errno= 0;
+   regno = strtol (from, &pos, 16 );
+   if ( pos==from || errno || (*pos)!='='  )
+       error ("Invalid P packet format '%s'.", from);
+ 
+   if ( regno<0 || regno>=NUM_REGS )
+       error ("Invalid register number %d.", regno);
+ 
+   inreg (regno, pos+1);
+   store_inferior_registers (regno);
  }
diff -c -r ../gdb+dejagnu-20010515-org/gdb/gdbserver/server.c gdb/gdbserver/server.c
*** ../gdb+dejagnu-20010515-org/gdb/gdbserver/server.c	Tue Mar  6 03:21:44 2001
--- gdb/gdbserver/server.c	Tue May 15 13:11:56 2001
***************
*** 24,30 ****
  int cont_thread;
  int general_thread;
  int thread_from_wait;
- int old_thread_from_wait;
  int extended_protocol;
  jmp_buf toplevel;
  int inferior_pid;
--- 24,29 ----
***************
*** 45,53 ****
  main (int argc, char *argv[])
  {
    char ch, status, own_buf[PBUFSIZ], mem_buf[2000];
!   int i = 0;
    unsigned char signal;
!   unsigned int len;
    CORE_ADDR mem_addr;
  
    if (setjmp (toplevel))
--- 44,53 ----
  main (int argc, char *argv[])
  {
    char ch, status, own_buf[PBUFSIZ], mem_buf[2000];
!   int err;
!   int regno;
    unsigned char signal;
!   unsigned len;
    CORE_ADDR mem_addr;
  
    if (setjmp (toplevel))
***************
*** 75,82 ****
        while (getpkt (own_buf) > 0)
  	{
  	  unsigned char sig;
! 	  i = 0;
! 	  ch = own_buf[i++];
  	  switch (ch)
  	    {
  	    case 'd':
--- 75,81 ----
        while (getpkt (own_buf) > 0)
  	{
  	  unsigned char sig;
! 	  ch = own_buf[0];
  	  switch (ch)
  	    {
  	    case 'd':
***************
*** 89,103 ****
  	    case '?':
  	      prepare_resume_reply (own_buf, status, signal);
  	      break;
! 	    case 'H':
  	      switch (own_buf[1])
  		{
! 		case 'g':
  		  general_thread = strtol (&own_buf[2], NULL, 16);
  		  write_ok (own_buf);
  		  fetch_inferior_registers (0);
  		  break;
! 		case 'c':
  		  cont_thread = strtol (&own_buf[2], NULL, 16);
  		  write_ok (own_buf);
  		  break;
--- 88,102 ----
  	    case '?':
  	      prepare_resume_reply (own_buf, status, signal);
  	      break;
! 	    case 'H':		/* Thread operations */
  	      switch (own_buf[1])
  		{
! 		case 'g':	/* Set thread ID for other actions */
  		  general_thread = strtol (&own_buf[2], NULL, 16);
  		  write_ok (own_buf);
  		  fetch_inferior_registers (0);
  		  break;
! 		case 'c':	/* Set thread ID for continue/set. */
  		  cont_thread = strtol (&own_buf[2], NULL, 16);
  		  write_ok (own_buf);
  		  break;
***************
*** 160,166 ****
  		{
  		  write_ok (own_buf);
  		  fprintf (stderr, "GDBserver restarting\n");
- 
  		  /* Wait till we are at 1st instruction in prog.  */
  		  signal = start_inferior (&argv[2], &status);
  		  goto restart;
--- 159,164 ----
***************
*** 171,176 ****
--- 169,178 ----
  		  exit (0);
  		  break;
  		}
+ 	    case 'P':
+ 	      do_P_packet (&own_buf[1]);
+ 	      write_ok (own_buf);
+ 	      break;
  	    case 'T':
  	      if (mythread_alive (strtol (&own_buf[1], NULL, 16)))
  		write_ok (own_buf);
***************
*** 210,217 ****
  	  putpkt (own_buf);
  
  	  if (status == 'W')
! 	    fprintf (stderr,
! 		     "\nChild exited with status %d\n", sig);
  	  if (status == 'X')
  	    fprintf (stderr, "\nChild terminated with signal = 0x%x\n", sig);
  	  if (status == 'W' || status == 'X')
--- 212,218 ----
  	  putpkt (own_buf);
  
  	  if (status == 'W')
! 	    fprintf (stderr, "\nChild exited with status %d\n", sig);
  	  if (status == 'X')
  	    fprintf (stderr, "\nChild terminated with signal = 0x%x\n", sig);
  	  if (status == 'W' || status == 'X')
***************
*** 250,256 ****
  	}
        else
  	{
! 	  fprintf (stderr, "Remote side has terminated connection.  GDBserver will reopen the connection.\n");
  
  	  remote_close ();
  	}
--- 251,258 ----
  	}
        else
  	{
! 	  fprintf (stderr,
! 		   "Remote side has terminated connection.  GDBserver will reopen the connection.\n");
  
  	  remote_close ();
  	}
diff -c -r ../gdb+dejagnu-20010515-org/gdb/gdbserver/server.h gdb/gdbserver/server.h
*** ../gdb+dejagnu-20010515-org/gdb/gdbserver/server.h	Tue Mar  6 03:21:44 2001
--- gdb/gdbserver/server.h	Tue May 15 13:11:42 2001
***************
*** 29,34 ****
--- 29,35 ----
  void fetch_inferior_registers (int regno);
  void store_inferior_registers (int regno);
  int mythread_alive (int pid);
+ int myattach_lwp (int pid);
  void myresume (int step, int signo);
  unsigned char mywait (char *status);
  void read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len);
***************
*** 45,74 ****
  extern int cont_thread;
  extern int general_thread;
  extern int thread_from_wait;
- extern int old_thread_from_wait;
- 
  extern jmp_buf toplevel;
  extern int inferior_pid;
  
  /* Functions from remote-utils.c */
  
! int putpkt (char *buf);
  int getpkt (char *buf);
! void remote_open (char *name);
  void remote_close (void);
  void write_ok (char *buf);
  void write_enn (char *buf);
  void enable_async_io (void);
  void disable_async_io (void);
! void convert_ascii_to_int (char *from, char *to, int n);
! void convert_int_to_ascii (char *from, char *to, int n);
  void prepare_resume_reply (char *buf, char status, unsigned char sig);
  
! void decode_m_packet (char *from, CORE_ADDR * mem_addr_ptr,
  		      unsigned int *len_ptr);
! void decode_M_packet (char *from, CORE_ADDR * mem_addr_ptr,
  		      unsigned int *len_ptr, char *to);
! 
  
  /* Functions from utils.c */
  
--- 46,73 ----
  extern int cont_thread;
  extern int general_thread;
  extern int thread_from_wait;
  extern jmp_buf toplevel;
  extern int inferior_pid;
  
  /* Functions from remote-utils.c */
  
! int putpkt (const char *buf);
  int getpkt (char *buf);
! void remote_open (const char *name);
  void remote_close (void);
  void write_ok (char *buf);
  void write_enn (char *buf);
  void enable_async_io (void);
  void disable_async_io (void);
! void convert_ascii_to_int (const char *from, char *to, int n);
! void convert_int_to_ascii (const char *from, char *to, int n);
  void prepare_resume_reply (char *buf, char status, unsigned char sig);
  
! void decode_m_packet (const char *from, CORE_ADDR * mem_addr_ptr,
  		      unsigned int *len_ptr);
! void decode_M_packet (const char *from, CORE_ADDR * mem_addr_ptr,
  		      unsigned int *len_ptr, char *to);
! void do_P_packet (const char *from);
  
  /* Functions from utils.c */
  


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