1 /* Generic serial interface routines
2 Copyright 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* Linked list of serial I/O handlers */
25 static struct serial_ops *serial_ops_list = NULL;
27 /* This is the last serial stream opened. Used by connect command. */
29 static serial_t last_serial_opened = NULL;
31 static struct serial_ops *
32 serial_interface_lookup (name)
35 struct serial_ops *ops;
37 for (ops = serial_ops_list; ops; ops = ops->next)
38 if (strcmp (name, ops->name) == 0)
45 serial_add_interface(optable)
46 struct serial_ops *optable;
48 optable->next = serial_ops_list;
49 serial_ops_list = optable;
52 /* Open up a device or a network socket, depending upon the syntax of NAME. */
59 struct serial_ops *ops;
61 for (scb = scb_base; scb; scb = scb->next)
62 if (scb->name && strcmp (scb->name, name) == 0)
68 if (strcmp (name, "pc") == 0)
69 ops = serial_interface_lookup ("pc");
70 else if (strchr (name, ':'))
71 ops = serial_interface_lookup ("tcp");
73 ops = serial_interface_lookup ("hardwire");
78 scb = (serial_t)xmalloc (sizeof (struct _serial_t));
85 if (scb->ops->open(scb, name))
91 scb->name = strsave (name);
96 last_serial_opened = scb;
106 struct serial_ops *ops;
108 for (scb = scb_base; scb; scb = scb->next)
115 ops = serial_interface_lookup ("hardwire");
120 scb = (serial_t)xmalloc (sizeof (struct _serial_t));
125 scb->bufp = scb->buf;
130 scb->next = scb_base;
134 last_serial_opened = scb;
145 last_serial_opened = NULL;
147 /* This is bogus. It's not our fault if you pass us a bad scb...! Rob, you
148 should fix your code instead. */
157 scb->ops->close (scb);
163 scb_base = scb_base->next;
165 for (tmp_scb = scb_base; tmp_scb; tmp_scb = tmp_scb->next)
167 if (tmp_scb->next != scb)
170 tmp_scb->next = tmp_scb->next->next;
179 The connect command is #if 0 because I hadn't thought of an elegant
180 way to wait for I/O on two serial_t's simultaneously. Two solutions
183 1) Fork, and have have one fork handle the to user direction,
184 and have the other hand the to target direction. This
185 obviously won't cut it for MSDOS.
187 2) Use something like select. This assumes that stdin and
188 the target side can both be waited on via the same
189 mechanism. This may not be true for DOS, if GDB is
190 talking to the target via a TCP socket.
194 /* Connect the user directly to the remote system. This command acts just like
195 the 'cu' or 'tip' command. Use <CR>~. or <CR>~^D to break out. */
197 static serial_t tty_desc; /* Controlling terminal */
200 cleanup_tty(ttystate)
201 serial_ttystate ttystate;
203 printf_unfiltered ("\r\n[Exiting connect mode]\r\n");
204 SERIAL_SET_TTY_STATE (tty_desc, ttystate);
206 SERIAL_CLOSE (tty_desc);
210 connect_command (args, fromtty)
216 serial_ttystate ttystate;
217 serial_t port_desc; /* TTY port */
222 fprintf_unfiltered(gdb_stderr, "This command takes no args. They have been ignored.\n");
224 printf_unfiltered("[Entering connect mode. Use ~. or ~^D to escape]\n");
226 tty_desc = SERIAL_FDOPEN (0);
227 port_desc = last_serial_opened;
229 ttystate = SERIAL_GET_TTY_STATE (tty_desc);
231 SERIAL_RAW (tty_desc);
232 SERIAL_RAW (port_desc);
234 make_cleanup (cleanup_tty, ttystate);
240 mask = SERIAL_WAIT_2 (tty_desc, port_desc, -1);
248 c = SERIAL_READCHAR(tty_desc, 0);
250 if (c == SERIAL_TIMEOUT)
254 perror_with_name("connect");
257 SERIAL_WRITE(port_desc, &cx, 1);
272 if (c == '.' || c == '\004')
286 c = SERIAL_READCHAR(port_desc, 0);
288 if (c == SERIAL_TIMEOUT)
292 perror_with_name("connect");
296 SERIAL_WRITE(tty_desc, &cx, 1);
304 _initialize_serial ()
307 add_com ("connect", class_obscure, connect_command,
308 "Connect the terminal directly up to the command monitor.\n\
309 Use <CR>~. or <CR>~^D to break out.");