---
 gdb-6.3.50/gdb/gdbserver/linux-i386-low.c |    4 +
 gdb-6.3.50/gdb/gdbserver/remote-utils.c   |   60 ++++++++++++++++++++----
 gdb-6.3.50/gdb/gdbserver/server.c         |   73 +++++++++++++++++++++---------
 gdb-6.3.50/gdb/gdbserver/server.h         |    2 
 4 files changed, 107 insertions(+), 32 deletions(-)

Index: b/gdb-6.3.50/gdb/gdbserver/linux-i386-low.c
===================================================================
--- a/gdb-6.3.50/gdb/gdbserver/linux-i386-low.c
+++ b/gdb-6.3.50/gdb/gdbserver/linux-i386-low.c
@@ -41,6 +41,10 @@
 
 #ifdef HAVE_SYS_REG_H
 #include <sys/reg.h>
+#else
+#  if defined ELINOS_LIBC5
+#  include <linux/ptrace.h>
+#  endif
 #endif
 
 #ifndef PTRACE_GET_THREAD_AREA
Index: b/gdb-6.3.50/gdb/gdbserver/remote-utils.c
===================================================================
--- a/gdb-6.3.50/gdb/gdbserver/remote-utils.c
+++ b/gdb-6.3.50/gdb/gdbserver/remote-utils.c
@@ -65,10 +65,50 @@ extern int debug_threads;
    NAME is the filename used for communication.  */
 
 void
-remote_open (char *name)
+remote_open (char *name, int baudrate)
 {
   int save_fcntl_flags;
   
+
+#ifdef HAVE_TERMIOS
+  const struct {
+         int rate;
+         int code;
+  } baud[] = {
+       { 50    , B50     },
+       { 75    , B75     },
+       { 110   , B110    },
+       { 134   , B134    },
+       { 150   , B150    },
+       { 200   , B200    },
+       { 300   , B300    },
+       { 600   , B600    },
+       { 1200  , B1200   },
+       { 1800  , B1800   },
+       { 2400  , B2400   },
+       { 4800  , B4800   },
+       { 9600  , B9600   },
+       { 19200 , B19200  },
+       { 38400 , B38400  },
+       { 57600 , B57600  },
+       { 115200, B115200 },
+       { -1    , -1      },
+  };
+  int i;
+
+  if (baudrate != -1)
+       {
+         for (i=0; baud[i].rate != -1; i++)
+               if (baud[i].rate == baudrate)
+               {
+                 baudrate = baud[i].code;
+                 break;
+               }
+         if (baud[i].rate == -1)
+               error("Illegal baudrate %d!\n", baudrate);
+       }
+#endif
+
   if (!strchr (name, ':'))
     {
       remote_desc = open (name, O_RDWR);
@@ -78,17 +118,15 @@ remote_open (char *name)
 #ifdef HAVE_TERMIOS
       {
 	struct termios termios;
-	tcgetattr (remote_desc, &termios);
-
-	termios.c_iflag = 0;
-	termios.c_oflag = 0;
-	termios.c_lflag = 0;
-	termios.c_cflag &= ~(CSIZE | PARENB);
-	termios.c_cflag |= CLOCAL | CS8;
-	termios.c_cc[VMIN] = 1;
-	termios.c_cc[VTIME] = 0;
 
-	tcsetattr (remote_desc, TCSANOW, &termios);
+        tcgetattr(remote_desc, &termios);
+        cfmakeraw(&termios);
+        if (baudrate != -1)
+        {
+               cfsetispeed(&termios, baudrate);
+               cfsetospeed(&termios, baudrate);
+        }
+        tcsetattr(remote_desc, TCSANOW, &termios);
       }
 #endif
 
Index: b/gdb-6.3.50/gdb/gdbserver/server.c
===================================================================
--- a/gdb-6.3.50/gdb/gdbserver/server.c
+++ b/gdb-6.3.50/gdb/gdbserver/server.c
@@ -21,6 +21,7 @@
    Boston, MA 02111-1307, USA.  */
 
 #include "server.h"
+#include <getopt.h>
 
 #include <unistd.h>
 #include <signal.h>
@@ -43,6 +44,10 @@ jmp_buf toplevel;
 
 unsigned long signal_pid;
 
+char *commname, **debuggee;
+int baudrate = -1;
+int c;
+
 static int
 start_inferior (char *argv[], char *statusptr)
 {
@@ -311,11 +316,19 @@ static int attached;
 static void
 gdbserver_usage (void)
 {
-  error ("Usage:\tgdbserver COMM PROG [ARGS ...]\n"
-	 "\tgdbserver COMM --attach PID\n"
+   error(
+      "Usage: gdbserver [OPTION] tty prog [args ...]\n"
+      "       gdbserver [OPTION] host:port prog [args ...]\n"
+      "\n"
+      "Remote server for the GDB debugger.\n"
 	 "\n"
-	 "COMM may either be a tty device (for serial debugging), or \n"
-	 "HOST:PORT to listen for a TCP connection.\n");
+      "  tty            use serial device to communicate with host GDB\n"
+      "  host:port      use TCP/IP to communicate with host GDB\n"
+      "\n"
+      "Options:\n"
+      "  -b rate        select baud rate of serial connection\n"
+      "  -h, -?         display this help and exit\n"
+      "  -a,--attach    attach to proccess\n");
 }
 
 int
@@ -330,6 +343,12 @@ main (int argc, char *argv[])
   int bad_attach;
   int pid;
   char *arg_end;
+  struct option longopts[] = {
+	 {name: "attach",
+	has_arg: 1,
+	flag: NULL,
+	val: 'a'} };
+
 
   if (setjmp (toplevel))
     {
@@ -340,21 +359,35 @@ main (int argc, char *argv[])
   bad_attach = 0;
   pid = 0;
   attached = 0;
-  if (argc >= 3 && strcmp (argv[2], "--attach") == 0)
+  /* make getopt() parse our options correctly */
+  setenv("POSIXLY_CORRECT", "Y", 1);
+  while ((c = getopt_long(argc, argv, "+b:a:h?", longopts, NULL)) != EOF)
     {
-      if (argc == 4
-	  && argv[3] != '\0'
-	  && (pid = strtoul (argv[3], &arg_end, 10)) != 0
-	  && *arg_end == '\0')
+       switch(c)
 	{
-	  ;
-	}
-      else
+	 case 'a':
+	     if ( ((pid = strtoul (optarg, &arg_end, 10)) == 0) || (*arg_end != '\0') )
 	bad_attach = 1;
-    }
+	     break;
+         case 'b':
+             baudrate = atoi(optarg);
+             break;
+         case 'h':
+         case '?':
+             gdbserver_usage();
+             exit(0);
+         default:
+             gdbserver_usage();
+             break;
+         }
+    }
+  if ( ((optind + 2 > argc) && (pid == 0))
+	|| ((optind + 1 > argc) && (pid != 0))
+	|| bad_attach )
+       error("Required arguments missing.\nTry `gdbserver -h' for more infomation.\n");
 
-  if (argc < 3 || bad_attach)
-    gdbserver_usage();
+  commname = argv[optind++];
+  debuggee = &argv[optind];
 
   initialize_low ();
 
@@ -363,7 +396,7 @@ main (int argc, char *argv[])
   if (pid == 0)
     {
       /* Wait till we are at first instruction in program.  */
-      signal = start_inferior (&argv[2], &status);
+      signal = start_inferior (debuggee, &status);
 
       /* We are now stopped at the first instruction of the target process */
     }
@@ -382,7 +415,7 @@ main (int argc, char *argv[])
 
   while (1)
     {
-      remote_open (argv[1]);
+      remote_open (commname, baudrate);
 
     restart:
       setjmp (toplevel);
@@ -599,7 +632,7 @@ main (int argc, char *argv[])
 		  fprintf (stderr, "GDBserver restarting\n");
 
 		  /* Wait till we are at 1st instruction in prog.  */
-		  signal = start_inferior (&argv[2], &status);
+		  signal = start_inferior (debuggee, &status);
 		  goto restart;
 		  break;
 		}
@@ -636,7 +669,7 @@ main (int argc, char *argv[])
 		  fprintf (stderr, "GDBserver restarting\n");
 
 		  /* Wait till we are at 1st instruction in prog.  */
-		  signal = start_inferior (&argv[2], &status);
+		  signal = start_inferior (debuggee, &status);
 		  goto restart;
 		  break;
 		}
@@ -678,7 +711,7 @@ main (int argc, char *argv[])
 		  fprintf (stderr, "GDBserver restarting\n");
 
 		  /* Wait till we are at 1st instruction in prog.  */
-		  signal = start_inferior (&argv[2], &status);
+		  signal = start_inferior (debuggee, &status);
 		  goto restart;
 		  break;
 		}
Index: b/gdb-6.3.50/gdb/gdbserver/server.h
===================================================================
--- a/gdb-6.3.50/gdb/gdbserver/server.h
+++ b/gdb-6.3.50/gdb/gdbserver/server.h
@@ -131,7 +131,7 @@ extern jmp_buf toplevel;
 
 int putpkt (char *buf);
 int getpkt (char *buf);
-void remote_open (char *name);
+void remote_open (char *name, int baudrate);
 void remote_close (void);
 void write_ok (char *buf);
 void write_enn (char *buf);

