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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 /* Pointer to list of scb's. */
33 static serial_t scb_base
;
35 static struct serial_ops
*
36 serial_interface_lookup (name
)
39 struct serial_ops
*ops
;
41 for (ops
= serial_ops_list
; ops
; ops
= ops
->next
)
42 if (strcmp (name
, ops
->name
) == 0)
49 serial_add_interface(optable
)
50 struct serial_ops
*optable
;
52 optable
->next
= serial_ops_list
;
53 serial_ops_list
= optable
;
56 /* Open up a device or a network socket, depending upon the syntax of NAME. */
63 struct serial_ops
*ops
;
65 for (scb
= scb_base
; scb
; scb
= scb
->next
)
66 if (scb
->name
&& strcmp (scb
->name
, name
) == 0)
72 if (strcmp (name
, "pc") == 0)
73 ops
= serial_interface_lookup ("pc");
74 else if (strchr (name
, ':'))
75 ops
= serial_interface_lookup ("tcp");
77 ops
= serial_interface_lookup ("hardwire");
82 scb
= (serial_t
)xmalloc (sizeof (struct _serial_t
));
89 if (scb
->ops
->open(scb
, name
))
95 scb
->name
= strsave (name
);
100 last_serial_opened
= scb
;
110 struct serial_ops
*ops
;
112 for (scb
= scb_base
; scb
; scb
= scb
->next
)
119 ops
= serial_interface_lookup ("hardwire");
124 scb
= (serial_t
)xmalloc (sizeof (struct _serial_t
));
129 scb
->bufp
= scb
->buf
;
134 scb
->next
= scb_base
;
138 last_serial_opened
= scb
;
144 serial_close(scb
, really_close
)
150 last_serial_opened
= NULL
;
152 /* This is bogus. It's not our fault if you pass us a bad scb...! Rob, you
153 should fix your code instead. */
163 scb
->ops
->close (scb
);
169 scb_base
= scb_base
->next
;
171 for (tmp_scb
= scb_base
; tmp_scb
; tmp_scb
= tmp_scb
->next
)
173 if (tmp_scb
->next
!= scb
)
176 tmp_scb
->next
= tmp_scb
->next
->next
;
185 The connect command is #if 0 because I hadn't thought of an elegant
186 way to wait for I/O on two serial_t's simultaneously. Two solutions
189 1) Fork, and have have one fork handle the to user direction,
190 and have the other hand the to target direction. This
191 obviously won't cut it for MSDOS.
193 2) Use something like select. This assumes that stdin and
194 the target side can both be waited on via the same
195 mechanism. This may not be true for DOS, if GDB is
196 talking to the target via a TCP socket.
200 /* Connect the user directly to the remote system. This command acts just like
201 the 'cu' or 'tip' command. Use <CR>~. or <CR>~^D to break out. */
203 static serial_t tty_desc
; /* Controlling terminal */
206 cleanup_tty(ttystate
)
207 serial_ttystate ttystate
;
209 printf_unfiltered ("\r\n[Exiting connect mode]\r\n");
210 SERIAL_SET_TTY_STATE (tty_desc
, ttystate
);
212 SERIAL_CLOSE (tty_desc
);
216 connect_command (args
, fromtty
)
222 serial_ttystate ttystate
;
223 serial_t port_desc
; /* TTY port */
228 fprintf_unfiltered(gdb_stderr
, "This command takes no args. They have been ignored.\n");
230 printf_unfiltered("[Entering connect mode. Use ~. or ~^D to escape]\n");
232 tty_desc
= SERIAL_FDOPEN (0);
233 port_desc
= last_serial_opened
;
235 ttystate
= SERIAL_GET_TTY_STATE (tty_desc
);
237 SERIAL_RAW (tty_desc
);
238 SERIAL_RAW (port_desc
);
240 make_cleanup (cleanup_tty
, ttystate
);
246 mask
= SERIAL_WAIT_2 (tty_desc
, port_desc
, -1);
254 c
= SERIAL_READCHAR(tty_desc
, 0);
256 if (c
== SERIAL_TIMEOUT
)
260 perror_with_name("connect");
263 SERIAL_WRITE(port_desc
, &cx
, 1);
278 if (c
== '.' || c
== '\004')
292 c
= SERIAL_READCHAR(port_desc
, 0);
294 if (c
== SERIAL_TIMEOUT
)
298 perror_with_name("connect");
302 SERIAL_WRITE(tty_desc
, &cx
, 1);
310 _initialize_serial ()
313 add_com ("connect", class_obscure
, connect_command
,
314 "Connect the terminal directly up to the command monitor.\n\
315 Use <CR>~. or <CR>~^D to break out.");