* inftarg.c (child_thread_alive): New function to see if a
[deliverable/binutils-gdb.git] / gdb / serial.c
index 6913fd6e239893565bc94ebb10cdccd161021a81..291ff3da38ca60783aa562cc7938a60ef4e8e850 100644 (file)
@@ -52,13 +52,22 @@ serial_add_interface(optable)
 /* Open up a device or a network socket, depending upon the syntax of NAME. */
 
 serial_t
-serial_open(name)
+serial_open (name)
      const char *name;
 {
   serial_t scb;
   struct serial_ops *ops;
 
-  if (strchr (name, ':'))
+  for (scb = scb_base; scb; scb = scb->next)
+    if (scb->name && strcmp (scb->name, name) == 0)
+      {
+       scb->refcnt++;
+       return scb;
+      }
+
+  if (strcmp (name, "pc") == 0)
+    ops = serial_interface_lookup ("pc");
+  else if (strchr (name, ':'))
     ops = serial_interface_lookup ("tcp");
   else
     ops = serial_interface_lookup ("hardwire");
@@ -79,18 +88,30 @@ serial_open(name)
       return NULL;
     }
 
+  scb->name = strsave (name);
+  scb->next = scb_base;
+  scb->refcnt = 1;
+  scb_base = scb;
+
   last_serial_opened = scb;
 
   return scb;
 }
 
 serial_t
-serial_fdopen(fd)
+serial_fdopen (fd)
      const int fd;
 {
   serial_t scb;
   struct serial_ops *ops;
 
+  for (scb = scb_base; scb; scb = scb->next)
+    if (scb->fd == fd)
+      {
+       scb->refcnt++;
+       return scb;
+      }
+
   ops = serial_interface_lookup ("hardwire");
 
   if (!ops)
@@ -105,6 +126,11 @@ serial_fdopen(fd)
 
   scb->fd = fd;
 
+  scb->name = NULL;
+  scb->next = scb_base;
+  scb->refcnt = 1;
+  scb_base = scb;
+
   last_serial_opened = scb;
 
   return scb;
@@ -114,6 +140,8 @@ void
 serial_close(scb)
      serial_t scb;
 {
+  serial_t tmp_scb;
+
   last_serial_opened = NULL;
 
 /* This is bogus.  It's not our fault if you pass us a bad scb...!  Rob, you
@@ -122,7 +150,27 @@ serial_close(scb)
   if (!scb)
     return;
 
-  scb->ops->close(scb);
+  scb->refcnt--;
+  if (scb->refcnt > 0)
+    return;
+
+  scb->ops->close (scb);
+
+  if (scb->name)
+    free (scb->name);
+
+  if (scb_base == scb)
+    scb_base = scb_base->next;
+  else
+    for (tmp_scb = scb_base; tmp_scb; tmp_scb = tmp_scb->next)
+      {
+       if (tmp_scb->next != scb)
+         continue;
+
+       tmp_scb->next = tmp_scb->next->next;
+       break;
+      }
+
   free(scb);
 }
 
@@ -152,7 +200,7 @@ static void
 cleanup_tty(ttystate)
      serial_ttystate ttystate;
 {
-  printf ("\r\n[Exiting connect mode]\r\n");
+  printf_unfiltered ("\r\n[Exiting connect mode]\r\n");
   SERIAL_SET_TTY_STATE (tty_desc, ttystate);
   free (ttystate);
   SERIAL_CLOSE (tty_desc);
@@ -171,9 +219,9 @@ connect_command (args, fromtty)
   dont_repeat();
 
   if (args)
-    fprintf(stderr, "This command takes no args.  They have been ignored.\n");
+    fprintf_unfiltered(gdb_stderr, "This command takes no args.  They have been ignored.\n");
        
-  printf("[Entering connect mode.  Use ~. or ~^D to escape]\n");
+  printf_unfiltered("[Entering connect mode.  Use ~. or ~^D to escape]\n");
 
   tty_desc = SERIAL_FDOPEN (0);
   port_desc = last_serial_opened;
@@ -250,12 +298,14 @@ connect_command (args, fromtty)
        }
     }
 }
+#endif /* 0 */
 
 void
 _initialize_serial ()
 {
+#if 0
   add_com ("connect", class_obscure, connect_command,
           "Connect the terminal directly up to the command monitor.\n\
 Use <CR>~. or <CR>~^D to break out.");
-}
 #endif /* 0 */
+}
This page took 0.024976 seconds and 4 git commands to generate.