1999-04-16 01:35:26 +00:00
|
|
|
|
/* Generic serial interface routines
|
2001-01-31 01:24:03 +00:00
|
|
|
|
|
2012-01-04 08:17:56 +00:00
|
|
|
|
Copyright (C) 1992-2002, 2004-2012 Free Software Foundation, Inc.
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
1999-07-07 20:19:36 +00:00
|
|
|
|
This file is part of GDB.
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
1999-07-07 20:19:36 +00:00
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-08-23 18:08:50 +00:00
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
1999-07-07 20:19:36 +00:00
|
|
|
|
(at your option) any later version.
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
1999-07-07 20:19:36 +00:00
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
1999-07-07 20:19:36 +00:00
|
|
|
|
You should have received a copy of the GNU General Public License
|
2007-08-23 18:08:50 +00:00
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include "serial.h"
|
|
|
|
|
#include "gdb_string.h"
|
|
|
|
|
#include "gdbcmd.h"
|
|
|
|
|
|
1999-09-22 03:28:34 +00:00
|
|
|
|
extern void _initialize_serial (void);
|
1999-05-25 18:09:09 +00:00
|
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
|
/* Is serial being debugged? */
|
1999-10-05 23:13:56 +00:00
|
|
|
|
|
2012-08-02 09:36:40 +00:00
|
|
|
|
static unsigned int global_serial_debug_p;
|
1999-10-05 23:13:56 +00:00
|
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
|
/* Linked list of serial I/O handlers. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
static struct serial_ops *serial_ops_list = NULL;
|
|
|
|
|
|
2012-06-13 11:06:52 +00:00
|
|
|
|
/* Pointer to list of scb's. */
|
|
|
|
|
|
|
|
|
|
static struct serial *scb_base;
|
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
|
/* Non-NULL gives filename which contains a recording of the remote session,
|
2011-01-11 21:53:25 +00:00
|
|
|
|
suitable for playback by gdbserver. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
static char *serial_logfile = NULL;
|
2000-02-02 00:21:19 +00:00
|
|
|
|
static struct ui_file *serial_logfp = NULL;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2010-08-20 18:49:20 +00:00
|
|
|
|
static struct serial_ops *serial_interface_lookup (const char *);
|
2011-01-05 22:22:53 +00:00
|
|
|
|
static void serial_logchar (struct ui_file *stream,
|
|
|
|
|
int ch_type, int ch, int timeout);
|
2000-06-08 00:52:56 +00:00
|
|
|
|
static const char logbase_hex[] = "hex";
|
|
|
|
|
static const char logbase_octal[] = "octal";
|
|
|
|
|
static const char logbase_ascii[] = "ascii";
|
2012-01-28 18:08:22 +00:00
|
|
|
|
static const char *const logbase_enums[] =
|
1999-07-07 20:19:36 +00:00
|
|
|
|
{logbase_hex, logbase_octal, logbase_ascii, NULL};
|
2000-06-08 00:52:56 +00:00
|
|
|
|
static const char *serial_logbase = logbase_ascii;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
1999-07-07 20:19:36 +00:00
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
|
static int serial_current_type = 0;
|
|
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
|
/* Log char CH of type CHTYPE, with TIMEOUT. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
/* Define bogus char to represent a BREAK. Should be careful to choose a value
|
|
|
|
|
that can't be confused with a normal char, or an error code. */
|
|
|
|
|
#define SERIAL_BREAK 1235
|
|
|
|
|
|
|
|
|
|
static void
|
2000-02-02 00:21:19 +00:00
|
|
|
|
serial_logchar (struct ui_file *stream, int ch_type, int ch, int timeout)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
|
|
|
|
if (ch_type != serial_current_type)
|
|
|
|
|
{
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fprintf_unfiltered (stream, "\n%c ", ch_type);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
serial_current_type = ch_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (serial_logbase != logbase_ascii)
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fputc_unfiltered (' ', stream);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
switch (ch)
|
|
|
|
|
{
|
|
|
|
|
case SERIAL_TIMEOUT:
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fprintf_unfiltered (stream, "<Timeout: %d seconds>", timeout);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
return;
|
|
|
|
|
case SERIAL_ERROR:
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fprintf_unfiltered (stream, "<Error: %s>", safe_strerror (errno));
|
1999-04-16 01:35:26 +00:00
|
|
|
|
return;
|
|
|
|
|
case SERIAL_EOF:
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fputs_unfiltered ("<Eof>", stream);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
return;
|
|
|
|
|
case SERIAL_BREAK:
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fputs_unfiltered ("<Break>", stream);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
if (serial_logbase == logbase_hex)
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fprintf_unfiltered (stream, "%02x", ch & 0xff);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
else if (serial_logbase == logbase_octal)
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fprintf_unfiltered (stream, "%03o", ch & 0xff);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
else
|
|
|
|
|
switch (ch)
|
|
|
|
|
{
|
1999-07-07 20:19:36 +00:00
|
|
|
|
case '\\':
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fputs_unfiltered ("\\\\", stream);
|
1999-07-07 20:19:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case '\b':
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fputs_unfiltered ("\\b", stream);
|
1999-07-07 20:19:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case '\f':
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fputs_unfiltered ("\\f", stream);
|
1999-07-07 20:19:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case '\n':
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fputs_unfiltered ("\\n", stream);
|
1999-07-07 20:19:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case '\r':
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fputs_unfiltered ("\\r", stream);
|
1999-07-07 20:19:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case '\t':
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fputs_unfiltered ("\\t", stream);
|
1999-07-07 20:19:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case '\v':
|
1999-10-05 23:13:56 +00:00
|
|
|
|
fputs_unfiltered ("\\v", stream);
|
1999-07-07 20:19:36 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2011-01-05 22:22:53 +00:00
|
|
|
|
fprintf_unfiltered (stream,
|
|
|
|
|
isprint (ch) ? "%c" : "\\x%02x", ch & 0xFF);
|
1999-07-07 20:19:36 +00:00
|
|
|
|
break;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
1999-09-22 03:28:34 +00:00
|
|
|
|
serial_log_command (const char *cmd)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
|
|
|
|
if (!serial_logfp)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
serial_current_type = 'c';
|
|
|
|
|
|
|
|
|
|
fputs_unfiltered ("\nc ", serial_logfp);
|
|
|
|
|
fputs_unfiltered (cmd, serial_logfp);
|
|
|
|
|
|
|
|
|
|
/* Make sure that the log file is as up-to-date as possible,
|
2011-01-11 21:53:25 +00:00
|
|
|
|
in case we are getting ready to dump core or something. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
gdb_flush (serial_logfp);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 03:28:34 +00:00
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
|
static struct serial_ops *
|
2010-08-20 18:49:20 +00:00
|
|
|
|
serial_interface_lookup (const char *name)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
|
|
|
|
struct serial_ops *ops;
|
|
|
|
|
|
|
|
|
|
for (ops = serial_ops_list; ops; ops = ops->next)
|
|
|
|
|
if (strcmp (name, ops->name) == 0)
|
|
|
|
|
return ops;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
1999-09-22 03:28:34 +00:00
|
|
|
|
serial_add_interface (struct serial_ops *optable)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
|
|
|
|
optable->next = serial_ops_list;
|
|
|
|
|
serial_ops_list = optable;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 11:06:52 +00:00
|
|
|
|
/* Return the open serial device for FD, if found, or NULL if FD is
|
|
|
|
|
not already opened. */
|
|
|
|
|
|
|
|
|
|
struct serial *
|
|
|
|
|
serial_for_fd (int fd)
|
|
|
|
|
{
|
|
|
|
|
struct serial *scb;
|
|
|
|
|
|
|
|
|
|
for (scb = scb_base; scb; scb = scb->next)
|
|
|
|
|
if (scb->fd == fd)
|
|
|
|
|
return scb;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
|
/* Open up a device or a network socket, depending upon the syntax of NAME. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2001-07-11 17:52:32 +00:00
|
|
|
|
struct serial *
|
1999-09-22 03:28:34 +00:00
|
|
|
|
serial_open (const char *name)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
2001-07-11 17:52:32 +00:00
|
|
|
|
struct serial *scb;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
struct serial_ops *ops;
|
1999-09-22 03:28:34 +00:00
|
|
|
|
const char *open_name = name;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2002-02-24 03:59:50 +00:00
|
|
|
|
if (strcmp (name, "pc") == 0)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
ops = serial_interface_lookup ("pc");
|
|
|
|
|
else if (strncmp (name, "lpt", 3) == 0)
|
|
|
|
|
ops = serial_interface_lookup ("parallel");
|
1999-07-12 11:15:22 +00:00
|
|
|
|
else if (strncmp (name, "|", 1) == 0)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
ops = serial_interface_lookup ("pipe");
|
2006-11-04 08:37:24 +00:00
|
|
|
|
/* Discard ``|'' and any space before the command itself. */
|
|
|
|
|
++open_name;
|
|
|
|
|
while (isspace (*open_name))
|
|
|
|
|
++open_name;
|
1999-09-22 03:28:34 +00:00
|
|
|
|
}
|
2006-04-11 20:33:12 +00:00
|
|
|
|
/* Check for a colon, suggesting an IP address/port pair.
|
|
|
|
|
Do this *after* checking for all the interesting prefixes. We
|
|
|
|
|
don't want to constrain the syntax of what can follow them. */
|
|
|
|
|
else if (strchr (name, ':'))
|
|
|
|
|
ops = serial_interface_lookup ("tcp");
|
1999-04-16 01:35:26 +00:00
|
|
|
|
else
|
|
|
|
|
ops = serial_interface_lookup ("hardwire");
|
|
|
|
|
|
|
|
|
|
if (!ops)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2001-07-09 14:38:49 +00:00
|
|
|
|
scb = XMALLOC (struct serial);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
scb->ops = ops;
|
|
|
|
|
|
|
|
|
|
scb->bufcnt = 0;
|
|
|
|
|
scb->bufp = scb->buf;
|
2007-04-08 15:20:07 +00:00
|
|
|
|
scb->error_fd = -1;
|
2012-06-11 20:36:53 +00:00
|
|
|
|
scb->refcnt = 1;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2011-02-27 16:25:38 +00:00
|
|
|
|
/* `...->open (...)' would get expanded by the open(2) syscall macro. */
|
2007-08-08 22:12:35 +00:00
|
|
|
|
if ((*scb->ops->open) (scb, open_name))
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
2000-12-15 01:01:51 +00:00
|
|
|
|
xfree (scb);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-31 01:24:03 +00:00
|
|
|
|
scb->name = xstrdup (name);
|
2012-06-13 11:06:52 +00:00
|
|
|
|
scb->next = scb_base;
|
1999-10-05 23:13:56 +00:00
|
|
|
|
scb->debug_p = 0;
|
|
|
|
|
scb->async_state = 0;
|
1999-09-22 03:28:34 +00:00
|
|
|
|
scb->async_handler = NULL;
|
|
|
|
|
scb->async_context = NULL;
|
2012-06-13 11:06:52 +00:00
|
|
|
|
scb_base = scb;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
if (serial_logfile != NULL)
|
|
|
|
|
{
|
|
|
|
|
serial_logfp = gdb_fopen (serial_logfile, "w");
|
|
|
|
|
if (serial_logfp == NULL)
|
|
|
|
|
perror_with_name (serial_logfile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return scb;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-20 18:49:20 +00:00
|
|
|
|
/* Open a new serial stream using a file handle, using serial
|
|
|
|
|
interface ops OPS. */
|
|
|
|
|
|
|
|
|
|
static struct serial *
|
|
|
|
|
serial_fdopen_ops (const int fd, struct serial_ops *ops)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
2001-07-11 17:52:32 +00:00
|
|
|
|
struct serial *scb;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
|
if (!ops)
|
2010-08-20 18:49:20 +00:00
|
|
|
|
{
|
|
|
|
|
ops = serial_interface_lookup ("terminal");
|
|
|
|
|
if (!ops)
|
|
|
|
|
ops = serial_interface_lookup ("hardwire");
|
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
if (!ops)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
|
scb = XCALLOC (1, struct serial);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
scb->ops = ops;
|
|
|
|
|
|
|
|
|
|
scb->bufcnt = 0;
|
|
|
|
|
scb->bufp = scb->buf;
|
2010-08-20 18:49:20 +00:00
|
|
|
|
scb->error_fd = -1;
|
2012-06-11 20:36:53 +00:00
|
|
|
|
scb->refcnt = 1;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
scb->name = NULL;
|
2012-06-13 11:06:52 +00:00
|
|
|
|
scb->next = scb_base;
|
1999-10-05 23:13:56 +00:00
|
|
|
|
scb->debug_p = 0;
|
|
|
|
|
scb->async_state = 0;
|
1999-09-22 03:28:34 +00:00
|
|
|
|
scb->async_handler = NULL;
|
|
|
|
|
scb->async_context = NULL;
|
2012-06-13 11:06:52 +00:00
|
|
|
|
scb_base = scb;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2010-08-20 18:49:20 +00:00
|
|
|
|
if ((ops->fdopen) != NULL)
|
|
|
|
|
(*ops->fdopen) (scb, fd);
|
|
|
|
|
else
|
|
|
|
|
scb->fd = fd;
|
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
|
return scb;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-20 18:49:20 +00:00
|
|
|
|
struct serial *
|
|
|
|
|
serial_fdopen (const int fd)
|
|
|
|
|
{
|
|
|
|
|
return serial_fdopen_ops (fd, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 03:28:34 +00:00
|
|
|
|
static void
|
2001-07-11 17:52:32 +00:00
|
|
|
|
do_serial_close (struct serial *scb, int really_close)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
2001-07-11 17:52:32 +00:00
|
|
|
|
struct serial *tmp_scb;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
if (serial_logfp)
|
|
|
|
|
{
|
|
|
|
|
fputs_unfiltered ("\nEnd of log\n", serial_logfp);
|
|
|
|
|
serial_current_type = 0;
|
|
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
|
/* XXX - What if serial_logfp == gdb_stdout or gdb_stderr? */
|
2000-02-02 00:21:19 +00:00
|
|
|
|
ui_file_delete (serial_logfp);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
serial_logfp = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
|
/* ensure that the FD has been taken out of async mode. */
|
1999-09-22 03:28:34 +00:00
|
|
|
|
if (scb->async_handler != NULL)
|
|
|
|
|
serial_async (scb, NULL, NULL);
|
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
|
if (really_close)
|
|
|
|
|
scb->ops->close (scb);
|
|
|
|
|
|
|
|
|
|
if (scb->name)
|
2000-12-15 01:01:51 +00:00
|
|
|
|
xfree (scb->name);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2012-06-11 20:36:53 +00:00
|
|
|
|
/* For serial_is_open. */
|
|
|
|
|
scb->bufp = NULL;
|
|
|
|
|
|
2012-06-13 11:06:52 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-11 20:36:53 +00:00
|
|
|
|
serial_unref (scb);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 03:28:34 +00:00
|
|
|
|
void
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_close (struct serial *scb)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
do_serial_close (scb, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_un_fdopen (struct serial *scb)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
do_serial_close (scb, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-11 20:36:53 +00:00
|
|
|
|
int
|
|
|
|
|
serial_is_open (struct serial *scb)
|
|
|
|
|
{
|
|
|
|
|
return scb->bufp != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
serial_ref (struct serial *scb)
|
|
|
|
|
{
|
|
|
|
|
scb->refcnt++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
serial_unref (struct serial *scb)
|
|
|
|
|
{
|
|
|
|
|
--scb->refcnt;
|
|
|
|
|
if (scb->refcnt == 0)
|
|
|
|
|
xfree (scb);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 03:28:34 +00:00
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_readchar (struct serial *scb, int timeout)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
int ch;
|
|
|
|
|
|
1999-10-12 04:37:53 +00:00
|
|
|
|
/* FIXME: cagney/1999-10-11: Don't enable this check until the ASYNC
|
2011-01-11 21:53:25 +00:00
|
|
|
|
code is finished. */
|
2001-07-15 20:34:14 +00:00
|
|
|
|
if (0 && serial_is_async_p (scb) && timeout < 0)
|
2001-02-08 06:03:54 +00:00
|
|
|
|
internal_error (__FILE__, __LINE__,
|
2005-02-11 Andrew Cagney <cagney@gnu.org>
Mark up error_no_arg, query, perror_with_name, complaint, and
internal_error.
* breakpoint.c, cp-abi.c, cp-namespace.c, cp-support.c: Update.
* cris-tdep.c, dbxread.c, dictionary.c, dsrec.c: Update.
* dummy-frame.c, dve3900-rom.c, dwarf2-frame.c, dwarf2expr.c: Update.
* dwarf2read.c, dwarfread.c, elfread.c, event-loop.c: Update.
* exceptions.c, exec.c, f-lang.c, findvar.c, fork-child.c: Update.
* frame-unwind.c, frame.c, frv-linux-tdep.c, frv-tdep.c: Update.
* gdb_assert.h, gdbarch.c, gdbtypes.c, gnu-nat.c: Update.
* go32-nat.c, hppa-tdep.c, hppabsd-nat.c, hpread.c: Update.
* i386-linux-nat.c, i386-nat.c, i386-tdep.c, i386bsd-nat.c: Update.
* i386fbsd-nat.c, inf-ptrace.c, inf-ttrace.c, infcall.c: Update.
* infcmd.c, inflow.c, infptrace.c, infrun.c, inftarg.c: Update.
* interps.c, language.c, linespec.c, linux-nat.c: Update.
* m32r-linux-nat.c, m68k-tdep.c, m68kbsd-nat.c: Update.
* m68klinux-nat.c, m88kbsd-nat.c, macroexp.c, macroscope.c: Update.
* macrotab.c, maint.c, mdebugread.c, memattr.c: Update.
* mips-linux-tdep.c, mips-tdep.c, mips64obsd-nat.c: Update.
* mipsnbsd-nat.c, mn10300-tdep.c, monitor.c, nto-procfs.c: Update.
* objc-lang.c, objfiles.c, objfiles.h, ocd.c, osabi.c: Update.
* parse.c, ppc-bdm.c, ppc-linux-nat.c, ppc-sysv-tdep.c: Update.
* ppcnbsd-nat.c, ppcobsd-nat.c, printcmd.c, procfs.c: Update.
* regcache.c, reggroups.c, remote-e7000.c, remote-mips.c: Update.
* remote-rdp.c, remote-sds.c, remote-sim.c, remote-st.c: Update.
* remote-utils.c, remote.c, rs6000-nat.c, rs6000-tdep.c: Update.
* s390-nat.c, s390-tdep.c, sentinel-frame.c, serial.c: Update.
* sh-tdep.c, sh3-rom.c, sh64-tdep.c, shnbsd-nat.c: Update.
* solib-aix5.c, solib-svr4.c, solib.c, source.c: Update.
* sparc-nat.c, stabsread.c, stack.c, symfile.c, symtab.c: Update.
* symtab.h, target.c, tracepoint.c, ui-file.c, ui-out.c: Update.
* utils.c, valops.c, valprint.c, vax-nat.c, vaxbsd-nat.c: Update.
* win32-nat.c, xcoffread.c, xstormy16-tdep.c: Update.
* cli/cli-cmds.c, cli/cli-logging.c, cli/cli-script.c: Update.
* cli/cli-setshow.c, mi/mi-cmd-break.c, mi/mi-cmds.c: Update.
* mi/mi-console.c, mi/mi-getopt.c, mi/mi-out.c: Update.
* tui/tui-file.c, tui/tui-interp.c: Update.
2005-02-11 18:13:55 +00:00
|
|
|
|
_("serial_readchar: blocking read in async mode"));
|
1999-10-12 04:37:53 +00:00
|
|
|
|
|
1999-09-22 03:28:34 +00:00
|
|
|
|
ch = scb->ops->readchar (scb, timeout);
|
|
|
|
|
if (serial_logfp != NULL)
|
|
|
|
|
{
|
1999-10-05 23:13:56 +00:00
|
|
|
|
serial_logchar (serial_logfp, 'r', ch, timeout);
|
1999-09-22 03:28:34 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure that the log file is as up-to-date as possible,
|
2011-01-11 21:53:25 +00:00
|
|
|
|
in case we are getting ready to dump core or something. */
|
1999-09-22 03:28:34 +00:00
|
|
|
|
gdb_flush (serial_logfp);
|
|
|
|
|
}
|
2001-07-15 20:34:14 +00:00
|
|
|
|
if (serial_debug_p (scb))
|
1999-10-05 23:13:56 +00:00
|
|
|
|
{
|
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "[");
|
|
|
|
|
serial_logchar (gdb_stdlog, 'r', ch, timeout);
|
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "]");
|
|
|
|
|
gdb_flush (gdb_stdlog);
|
|
|
|
|
}
|
1999-09-22 03:28:34 +00:00
|
|
|
|
|
|
|
|
|
return (ch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_write (struct serial *scb, const char *str, int len)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (serial_logfp != NULL)
|
|
|
|
|
{
|
|
|
|
|
int count;
|
|
|
|
|
|
|
|
|
|
for (count = 0; count < len; count++)
|
1999-10-05 23:13:56 +00:00
|
|
|
|
serial_logchar (serial_logfp, 'w', str[count] & 0xff, 0);
|
1999-09-22 03:28:34 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure that the log file is as up-to-date as possible,
|
2011-01-11 21:53:25 +00:00
|
|
|
|
in case we are getting ready to dump core or something. */
|
1999-09-22 03:28:34 +00:00
|
|
|
|
gdb_flush (serial_logfp);
|
|
|
|
|
}
|
2010-04-26 21:45:50 +00:00
|
|
|
|
if (serial_debug_p (scb))
|
|
|
|
|
{
|
|
|
|
|
int count;
|
|
|
|
|
|
|
|
|
|
for (count = 0; count < len; count++)
|
|
|
|
|
{
|
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "[");
|
|
|
|
|
serial_logchar (gdb_stdlog, 'w', str[count] & 0xff, 0);
|
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "]");
|
|
|
|
|
}
|
|
|
|
|
gdb_flush (gdb_stdlog);
|
|
|
|
|
}
|
1999-09-22 03:28:34 +00:00
|
|
|
|
|
|
|
|
|
return (scb->ops->write (scb, str, len));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_printf (struct serial *desc, const char *format,...)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
char *buf;
|
|
|
|
|
va_start (args, format);
|
|
|
|
|
|
2004-06-29 14:57:39 +00:00
|
|
|
|
buf = xstrvprintf (format, args);
|
2001-07-15 20:34:14 +00:00
|
|
|
|
serial_write (desc, buf, strlen (buf));
|
1999-09-22 03:28:34 +00:00
|
|
|
|
|
2000-12-15 01:01:51 +00:00
|
|
|
|
xfree (buf);
|
1999-09-22 03:28:34 +00:00
|
|
|
|
va_end (args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_drain_output (struct serial *scb)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->drain_output (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_flush_output (struct serial *scb)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->flush_output (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_flush_input (struct serial *scb)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->flush_input (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_send_break (struct serial *scb)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (serial_logfp != NULL)
|
1999-10-05 23:13:56 +00:00
|
|
|
|
serial_logchar (serial_logfp, 'w', SERIAL_BREAK, 0);
|
1999-09-22 03:28:34 +00:00
|
|
|
|
|
|
|
|
|
return (scb->ops->send_break (scb));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_raw (struct serial *scb)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
scb->ops->go_raw (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serial_ttystate
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_get_tty_state (struct serial *scb)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->get_tty_state (scb);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-04 19:23:42 +00:00
|
|
|
|
serial_ttystate
|
|
|
|
|
serial_copy_tty_state (struct serial *scb, serial_ttystate ttystate)
|
|
|
|
|
{
|
|
|
|
|
return scb->ops->copy_tty_state (scb, ttystate);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 03:28:34 +00:00
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_set_tty_state (struct serial *scb, serial_ttystate ttystate)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->set_tty_state (scb, ttystate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_print_tty_state (struct serial *scb,
|
1999-09-22 03:28:34 +00:00
|
|
|
|
serial_ttystate ttystate,
|
2000-02-02 00:21:19 +00:00
|
|
|
|
struct ui_file *stream)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
scb->ops->print_tty_state (scb, ttystate, stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_noflush_set_tty_state (struct serial *scb,
|
1999-09-22 03:28:34 +00:00
|
|
|
|
serial_ttystate new_ttystate,
|
|
|
|
|
serial_ttystate old_ttystate)
|
|
|
|
|
{
|
|
|
|
|
return scb->ops->noflush_set_tty_state (scb, new_ttystate, old_ttystate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_setbaudrate (struct serial *scb, int rate)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->setbaudrate (scb, rate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_setstopbits (struct serial *scb, int num)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->setstopbits (scb, num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_can_async_p (struct serial *scb)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
return (scb->ops->async != NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_is_async_p (struct serial *scb)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
return (scb->ops->async != NULL) && (scb->async_handler != NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_async (struct serial *scb,
|
1999-09-22 03:28:34 +00:00
|
|
|
|
serial_event_ftype *handler,
|
|
|
|
|
void *context)
|
|
|
|
|
{
|
2008-02-23 20:04:20 +00:00
|
|
|
|
int changed = ((scb->async_handler == NULL) != (handler == NULL));
|
2010-05-16 23:49:58 +00:00
|
|
|
|
|
1999-09-22 03:28:34 +00:00
|
|
|
|
scb->async_handler = handler;
|
|
|
|
|
scb->async_context = context;
|
2008-02-23 20:04:20 +00:00
|
|
|
|
/* Only change mode if there is a need. */
|
|
|
|
|
if (changed)
|
|
|
|
|
scb->ops->async (scb, handler != NULL);
|
1999-09-22 03:28:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
deprecated_serial_fd (struct serial *scb)
|
1999-09-22 03:28:34 +00:00
|
|
|
|
{
|
|
|
|
|
/* FIXME: should this output a warning that deprecated code is being
|
2011-01-11 21:53:25 +00:00
|
|
|
|
called? */
|
1999-09-22 03:28:34 +00:00
|
|
|
|
if (scb->fd < 0)
|
|
|
|
|
{
|
2001-02-08 06:03:54 +00:00
|
|
|
|
internal_error (__FILE__, __LINE__,
|
2005-02-11 Andrew Cagney <cagney@gnu.org>
Mark up error_no_arg, query, perror_with_name, complaint, and
internal_error.
* breakpoint.c, cp-abi.c, cp-namespace.c, cp-support.c: Update.
* cris-tdep.c, dbxread.c, dictionary.c, dsrec.c: Update.
* dummy-frame.c, dve3900-rom.c, dwarf2-frame.c, dwarf2expr.c: Update.
* dwarf2read.c, dwarfread.c, elfread.c, event-loop.c: Update.
* exceptions.c, exec.c, f-lang.c, findvar.c, fork-child.c: Update.
* frame-unwind.c, frame.c, frv-linux-tdep.c, frv-tdep.c: Update.
* gdb_assert.h, gdbarch.c, gdbtypes.c, gnu-nat.c: Update.
* go32-nat.c, hppa-tdep.c, hppabsd-nat.c, hpread.c: Update.
* i386-linux-nat.c, i386-nat.c, i386-tdep.c, i386bsd-nat.c: Update.
* i386fbsd-nat.c, inf-ptrace.c, inf-ttrace.c, infcall.c: Update.
* infcmd.c, inflow.c, infptrace.c, infrun.c, inftarg.c: Update.
* interps.c, language.c, linespec.c, linux-nat.c: Update.
* m32r-linux-nat.c, m68k-tdep.c, m68kbsd-nat.c: Update.
* m68klinux-nat.c, m88kbsd-nat.c, macroexp.c, macroscope.c: Update.
* macrotab.c, maint.c, mdebugread.c, memattr.c: Update.
* mips-linux-tdep.c, mips-tdep.c, mips64obsd-nat.c: Update.
* mipsnbsd-nat.c, mn10300-tdep.c, monitor.c, nto-procfs.c: Update.
* objc-lang.c, objfiles.c, objfiles.h, ocd.c, osabi.c: Update.
* parse.c, ppc-bdm.c, ppc-linux-nat.c, ppc-sysv-tdep.c: Update.
* ppcnbsd-nat.c, ppcobsd-nat.c, printcmd.c, procfs.c: Update.
* regcache.c, reggroups.c, remote-e7000.c, remote-mips.c: Update.
* remote-rdp.c, remote-sds.c, remote-sim.c, remote-st.c: Update.
* remote-utils.c, remote.c, rs6000-nat.c, rs6000-tdep.c: Update.
* s390-nat.c, s390-tdep.c, sentinel-frame.c, serial.c: Update.
* sh-tdep.c, sh3-rom.c, sh64-tdep.c, shnbsd-nat.c: Update.
* solib-aix5.c, solib-svr4.c, solib.c, source.c: Update.
* sparc-nat.c, stabsread.c, stack.c, symfile.c, symtab.c: Update.
* symtab.h, target.c, tracepoint.c, ui-file.c, ui-out.c: Update.
* utils.c, valops.c, valprint.c, vax-nat.c, vaxbsd-nat.c: Update.
* win32-nat.c, xcoffread.c, xstormy16-tdep.c: Update.
* cli/cli-cmds.c, cli/cli-logging.c, cli/cli-script.c: Update.
* cli/cli-setshow.c, mi/mi-cmd-break.c, mi/mi-cmds.c: Update.
* mi/mi-console.c, mi/mi-getopt.c, mi/mi-out.c: Update.
* tui/tui-file.c, tui/tui-interp.c: Update.
2005-02-11 18:13:55 +00:00
|
|
|
|
_("serial: FD not valid"));
|
1999-09-22 03:28:34 +00:00
|
|
|
|
}
|
|
|
|
|
return scb->fd; /* sigh */
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-05 23:13:56 +00:00
|
|
|
|
void
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_debug (struct serial *scb, int debug_p)
|
1999-10-05 23:13:56 +00:00
|
|
|
|
{
|
|
|
|
|
scb->debug_p = debug_p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 17:52:32 +00:00
|
|
|
|
serial_debug_p (struct serial *scb)
|
1999-10-05 23:13:56 +00:00
|
|
|
|
{
|
|
|
|
|
return scb->debug_p || global_serial_debug_p;
|
|
|
|
|
}
|
|
|
|
|
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
|
#ifdef USE_WIN32API
|
|
|
|
|
void
|
|
|
|
|
serial_wait_handle (struct serial *scb, HANDLE *read, HANDLE *except)
|
|
|
|
|
{
|
|
|
|
|
if (scb->ops->wait_handle)
|
|
|
|
|
scb->ops->wait_handle (scb, read, except);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*read = (HANDLE) _get_osfhandle (scb->fd);
|
|
|
|
|
*except = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-04-24 21:00:13 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
serial_done_wait_handle (struct serial *scb)
|
|
|
|
|
{
|
|
|
|
|
if (scb->ops->done_wait_handle)
|
|
|
|
|
scb->ops->done_wait_handle (scb);
|
|
|
|
|
}
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
|
#endif
|
1999-10-05 23:13:56 +00:00
|
|
|
|
|
2010-08-20 18:49:20 +00:00
|
|
|
|
int
|
|
|
|
|
serial_pipe (struct serial *scbs[2])
|
|
|
|
|
{
|
|
|
|
|
struct serial_ops *ops;
|
|
|
|
|
int fildes[2];
|
|
|
|
|
|
|
|
|
|
ops = serial_interface_lookup ("pipe");
|
|
|
|
|
if (!ops)
|
|
|
|
|
{
|
|
|
|
|
errno = ENOSYS;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gdb_pipe (fildes) == -1)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
scbs[0] = serial_fdopen_ops (fildes[0], ops);
|
|
|
|
|
scbs[1] = serial_fdopen_ops (fildes[1], ops);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-26 23:27:39 +00:00
|
|
|
|
/* Serial set/show framework. */
|
|
|
|
|
|
|
|
|
|
static struct cmd_list_element *serial_set_cmdlist;
|
|
|
|
|
static struct cmd_list_element *serial_show_cmdlist;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
serial_set_cmd (char *args, int from_tty)
|
|
|
|
|
{
|
2011-01-05 22:22:53 +00:00
|
|
|
|
printf_unfiltered ("\"set serial\" must be followed "
|
|
|
|
|
"by the name of a command.\n");
|
2001-09-26 23:27:39 +00:00
|
|
|
|
help_list (serial_set_cmdlist, "set serial ", -1, gdb_stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
serial_show_cmd (char *args, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
cmd_show_list (serial_show_cmdlist, from_tty, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
|
void
|
1999-09-22 03:28:34 +00:00
|
|
|
|
_initialize_serial (void)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
|
|
|
|
#if 0
|
2005-02-15 Andrew Cagney <cagney@gnu.org>
Mark up add_com, add_info and add_prefix_cmd.
* breakpoint.c, cp-support.c, dcache.c, dwarf2read.c: Update.
* exec.c, f-valprint.c, frame.c, gcore.c, gnu-nat.c: Update.
* go32-nat.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update.
* kod.c, language.c, linux-nat.c, m32r-rom.c, macrocmd.c: Update.
* maint.c, memattr.c, mips-tdep.c, nto-procfs.c, objc-lang.c: Update.
* ocd.c, pa64solib.c, printcmd.c, procfs.c, regcache.c: Update.
* remote-e7000.c, remote-m32r-sdi.c, remote-mips.c: Update.
* remote-sds.c, remote-sim.c, remote-st.c, remote-utils.c: Update.
* remote.c, rs6000-tdep.c, ser-go32.c, serial.c: Update.
* sh-tdep.c, solib.c, somsolib.c, source.c, stack.c: Update.
* symfile.c, symtab.c, target.c, thread.c, top.c: Update.
* tracepoint.c, typeprint.c, utils.c, valprint.c: Update.
* win32-nat.c, xcoffsolib.c, cli/cli-cmds.c, cli/cli-dump.c: Update.
* cli/cli-logging.c, tui/tui-layout.c, tui/tui-regs.c: Update.
* tui/tui-stack.c, tui/tui-win.c: Update.
2005-02-15 15:49:28 +00:00
|
|
|
|
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."));
|
1999-04-16 01:35:26 +00:00
|
|
|
|
#endif /* 0 */
|
|
|
|
|
|
2005-02-15 Andrew Cagney <cagney@gnu.org>
Mark up add_com, add_info and add_prefix_cmd.
* breakpoint.c, cp-support.c, dcache.c, dwarf2read.c: Update.
* exec.c, f-valprint.c, frame.c, gcore.c, gnu-nat.c: Update.
* go32-nat.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update.
* kod.c, language.c, linux-nat.c, m32r-rom.c, macrocmd.c: Update.
* maint.c, memattr.c, mips-tdep.c, nto-procfs.c, objc-lang.c: Update.
* ocd.c, pa64solib.c, printcmd.c, procfs.c, regcache.c: Update.
* remote-e7000.c, remote-m32r-sdi.c, remote-mips.c: Update.
* remote-sds.c, remote-sim.c, remote-st.c, remote-utils.c: Update.
* remote.c, rs6000-tdep.c, ser-go32.c, serial.c: Update.
* sh-tdep.c, solib.c, somsolib.c, source.c, stack.c: Update.
* symfile.c, symtab.c, target.c, thread.c, top.c: Update.
* tracepoint.c, typeprint.c, utils.c, valprint.c: Update.
* win32-nat.c, xcoffsolib.c, cli/cli-cmds.c, cli/cli-dump.c: Update.
* cli/cli-logging.c, tui/tui-layout.c, tui/tui-regs.c: Update.
* tui/tui-stack.c, tui/tui-win.c: Update.
2005-02-15 15:49:28 +00:00
|
|
|
|
add_prefix_cmd ("serial", class_maintenance, serial_set_cmd, _("\
|
|
|
|
|
Set default serial/parallel port configuration."),
|
2001-09-26 23:27:39 +00:00
|
|
|
|
&serial_set_cmdlist, "set serial ",
|
|
|
|
|
0/*allow-unknown*/,
|
|
|
|
|
&setlist);
|
|
|
|
|
|
2005-02-15 Andrew Cagney <cagney@gnu.org>
Mark up add_com, add_info and add_prefix_cmd.
* breakpoint.c, cp-support.c, dcache.c, dwarf2read.c: Update.
* exec.c, f-valprint.c, frame.c, gcore.c, gnu-nat.c: Update.
* go32-nat.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update.
* kod.c, language.c, linux-nat.c, m32r-rom.c, macrocmd.c: Update.
* maint.c, memattr.c, mips-tdep.c, nto-procfs.c, objc-lang.c: Update.
* ocd.c, pa64solib.c, printcmd.c, procfs.c, regcache.c: Update.
* remote-e7000.c, remote-m32r-sdi.c, remote-mips.c: Update.
* remote-sds.c, remote-sim.c, remote-st.c, remote-utils.c: Update.
* remote.c, rs6000-tdep.c, ser-go32.c, serial.c: Update.
* sh-tdep.c, solib.c, somsolib.c, source.c, stack.c: Update.
* symfile.c, symtab.c, target.c, thread.c, top.c: Update.
* tracepoint.c, typeprint.c, utils.c, valprint.c: Update.
* win32-nat.c, xcoffsolib.c, cli/cli-cmds.c, cli/cli-dump.c: Update.
* cli/cli-logging.c, tui/tui-layout.c, tui/tui-regs.c: Update.
* tui/tui-stack.c, tui/tui-win.c: Update.
2005-02-15 15:49:28 +00:00
|
|
|
|
add_prefix_cmd ("serial", class_maintenance, serial_show_cmd, _("\
|
|
|
|
|
Show default serial/parallel port configuration."),
|
2001-09-26 23:27:39 +00:00
|
|
|
|
&serial_show_cmdlist, "show serial ",
|
|
|
|
|
0/*allow-unknown*/,
|
|
|
|
|
&showlist);
|
|
|
|
|
|
2005-02-17 17:11:04 +00:00
|
|
|
|
add_setshow_filename_cmd ("remotelogfile", no_class, &serial_logfile, _("\
|
|
|
|
|
Set filename for remote session recording."), _("\
|
|
|
|
|
Show filename for remote session recording."), _("\
|
1999-04-16 01:35:26 +00:00
|
|
|
|
This file is used to record the remote session for future playback\n\
|
2005-02-17 17:11:04 +00:00
|
|
|
|
by gdbserver."),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL, /* FIXME: i18n: */
|
|
|
|
|
&setlist, &showlist);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2005-02-21 04:31:59 +00:00
|
|
|
|
add_setshow_enum_cmd ("remotelogbase", no_class, logbase_enums,
|
|
|
|
|
&serial_logbase, _("\
|
|
|
|
|
Set numerical base for remote session logging"), _("\
|
|
|
|
|
Show numerical base for remote session logging"), NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL, /* FIXME: i18n: */
|
|
|
|
|
&setlist, &showlist);
|
1999-10-05 23:13:56 +00:00
|
|
|
|
|
2012-08-02 09:36:40 +00:00
|
|
|
|
add_setshow_zuinteger_cmd ("serial", class_maintenance,
|
|
|
|
|
&global_serial_debug_p, _("\
|
2005-02-18 Andrew Cagney <cagney@gnu.org>
Use add_setshow_zinteger_cmd through out. Re-sync gdbarch.sh
and gdbarch.c.
* breakpoint.c, frame.c, gdb-events.sh, gdbarch.sh: Update.
* gdbtypes.c, infrun.c, linux-nat.c, maint.c, monitor.c: Update.
* pa64solib.c, parse.c, remote-mips.c, ser-go32.c: Update.
* serial.c, solib-frv.c, somsolib.c, target.c, top.c: Update.
* varobj.c, cli/cli-cmds.c: Update.
* gdbarch.c, gdb-events.c: Regenerate.
2005-02-18 18:58:56 +00:00
|
|
|
|
Set serial debugging."), _("\
|
|
|
|
|
Show serial debugging."), _("\
|
|
|
|
|
When non-zero, serial port debugging is enabled."),
|
2012-08-02 09:36:40 +00:00
|
|
|
|
NULL,
|
|
|
|
|
NULL, /* FIXME: i18n: */
|
|
|
|
|
&setdebuglist, &showdebuglist);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
}
|