1999-04-16 09:35:26 +08:00
|
|
|
|
/* Generic serial interface routines
|
2001-01-31 09:24:03 +08:00
|
|
|
|
|
2016-01-01 12:33:14 +08:00
|
|
|
|
Copyright (C) 1992-2016 Free Software Foundation, Inc.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
This file is part of GDB.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
1999-07-08 04:19:36 +08: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-24 02:08:50 +08:00
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
1999-07-08 04:19:36 +08:00
|
|
|
|
(at your option) any later version.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
1999-07-08 04:19:36 +08: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 09:35:26 +08:00
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
You should have received a copy of the GNU General Public License
|
2007-08-24 02:08:50 +08:00
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include "serial.h"
|
|
|
|
|
#include "gdbcmd.h"
|
2013-03-08 05:57:30 +08:00
|
|
|
|
#include "cli/cli-utils.h"
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
1999-09-22 11:28:34 +08:00
|
|
|
|
extern void _initialize_serial (void);
|
1999-05-26 02:09:09 +08:00
|
|
|
|
|
2011-01-12 05:53:25 +08:00
|
|
|
|
/* Is serial being debugged? */
|
1999-10-06 07:13:56 +08:00
|
|
|
|
|
2012-08-02 17:36:40 +08:00
|
|
|
|
static unsigned int global_serial_debug_p;
|
1999-10-06 07:13:56 +08:00
|
|
|
|
|
2013-12-07 01:58:50 +08:00
|
|
|
|
typedef const struct serial_ops *serial_ops_p;
|
|
|
|
|
DEF_VEC_P (serial_ops_p);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
2013-12-07 01:58:50 +08:00
|
|
|
|
/* Serial I/O handlers. */
|
|
|
|
|
|
|
|
|
|
VEC (serial_ops_p) *serial_ops_list = NULL;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
2012-06-13 19:06:52 +08:00
|
|
|
|
/* Pointer to list of scb's. */
|
|
|
|
|
|
|
|
|
|
static struct serial *scb_base;
|
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
|
/* Non-NULL gives filename which contains a recording of the remote session,
|
2011-01-12 05:53:25 +08:00
|
|
|
|
suitable for playback by gdbserver. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
static char *serial_logfile = NULL;
|
2000-02-02 08:21:19 +08:00
|
|
|
|
static struct ui_file *serial_logfp = NULL;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
2013-12-07 01:58:50 +08:00
|
|
|
|
static const struct serial_ops *serial_interface_lookup (const char *);
|
2011-01-06 06:22:53 +08:00
|
|
|
|
static void serial_logchar (struct ui_file *stream,
|
|
|
|
|
int ch_type, int ch, int timeout);
|
2000-06-08 08:52:56 +08:00
|
|
|
|
static const char logbase_hex[] = "hex";
|
|
|
|
|
static const char logbase_octal[] = "octal";
|
|
|
|
|
static const char logbase_ascii[] = "ascii";
|
2012-01-29 02:08:22 +08:00
|
|
|
|
static const char *const logbase_enums[] =
|
1999-07-08 04:19:36 +08:00
|
|
|
|
{logbase_hex, logbase_octal, logbase_ascii, NULL};
|
2000-06-08 08:52:56 +08:00
|
|
|
|
static const char *serial_logbase = logbase_ascii;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
|
static int serial_current_type = 0;
|
|
|
|
|
|
2011-01-12 05:53:25 +08:00
|
|
|
|
/* Log char CH of type CHTYPE, with TIMEOUT. */
|
1999-04-16 09:35:26 +08: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 08:21:19 +08:00
|
|
|
|
serial_logchar (struct ui_file *stream, int ch_type, int ch, int timeout)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
if (ch_type != serial_current_type)
|
|
|
|
|
{
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fprintf_unfiltered (stream, "\n%c ", ch_type);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
serial_current_type = ch_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (serial_logbase != logbase_ascii)
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fputc_unfiltered (' ', stream);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
switch (ch)
|
|
|
|
|
{
|
|
|
|
|
case SERIAL_TIMEOUT:
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fprintf_unfiltered (stream, "<Timeout: %d seconds>", timeout);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
return;
|
|
|
|
|
case SERIAL_ERROR:
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fprintf_unfiltered (stream, "<Error: %s>", safe_strerror (errno));
|
1999-04-16 09:35:26 +08:00
|
|
|
|
return;
|
|
|
|
|
case SERIAL_EOF:
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fputs_unfiltered ("<Eof>", stream);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
return;
|
|
|
|
|
case SERIAL_BREAK:
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fputs_unfiltered ("<Break>", stream);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
if (serial_logbase == logbase_hex)
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fprintf_unfiltered (stream, "%02x", ch & 0xff);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
else if (serial_logbase == logbase_octal)
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fprintf_unfiltered (stream, "%03o", ch & 0xff);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
else
|
|
|
|
|
switch (ch)
|
|
|
|
|
{
|
1999-07-08 04:19:36 +08:00
|
|
|
|
case '\\':
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fputs_unfiltered ("\\\\", stream);
|
1999-07-08 04:19:36 +08:00
|
|
|
|
break;
|
|
|
|
|
case '\b':
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fputs_unfiltered ("\\b", stream);
|
1999-07-08 04:19:36 +08:00
|
|
|
|
break;
|
|
|
|
|
case '\f':
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fputs_unfiltered ("\\f", stream);
|
1999-07-08 04:19:36 +08:00
|
|
|
|
break;
|
|
|
|
|
case '\n':
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fputs_unfiltered ("\\n", stream);
|
1999-07-08 04:19:36 +08:00
|
|
|
|
break;
|
|
|
|
|
case '\r':
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fputs_unfiltered ("\\r", stream);
|
1999-07-08 04:19:36 +08:00
|
|
|
|
break;
|
|
|
|
|
case '\t':
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fputs_unfiltered ("\\t", stream);
|
1999-07-08 04:19:36 +08:00
|
|
|
|
break;
|
|
|
|
|
case '\v':
|
1999-10-06 07:13:56 +08:00
|
|
|
|
fputs_unfiltered ("\\v", stream);
|
1999-07-08 04:19:36 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2011-01-06 06:22:53 +08:00
|
|
|
|
fprintf_unfiltered (stream,
|
|
|
|
|
isprint (ch) ? "%c" : "\\x%02x", ch & 0xFF);
|
1999-07-08 04:19:36 +08:00
|
|
|
|
break;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-12-18 12:35:13 +08:00
|
|
|
|
serial_log_command (struct target_ops *self, const char *cmd)
|
1999-04-16 09:35:26 +08: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-12 05:53:25 +08:00
|
|
|
|
in case we are getting ready to dump core or something. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
gdb_flush (serial_logfp);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 11:28:34 +08:00
|
|
|
|
|
2013-12-07 01:58:50 +08:00
|
|
|
|
static const struct serial_ops *
|
2010-08-21 02:49:20 +08:00
|
|
|
|
serial_interface_lookup (const char *name)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
2013-12-07 01:58:50 +08:00
|
|
|
|
const struct serial_ops *ops;
|
|
|
|
|
int i;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
2013-12-07 01:58:50 +08:00
|
|
|
|
for (i = 0; VEC_iterate (serial_ops_p, serial_ops_list, i, ops); ++i)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
if (strcmp (name, ops->name) == 0)
|
|
|
|
|
return ops;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-12-07 01:58:50 +08:00
|
|
|
|
serial_add_interface (const struct serial_ops *optable)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
2013-12-07 01:58:50 +08:00
|
|
|
|
VEC_safe_push (serial_ops_p, serial_ops_list, optable);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 19:06:52 +08: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;
|
|
|
|
|
}
|
|
|
|
|
|
Introduce a serial interface for select'able events
This patch adds a new "event" struct serial type, that is an
abstraction specifically for waking up blocking waits/selects,
implemented on top of a pipe on POSIX, and on top of a native Windows
event (CreateEvent, etc.) on Windows.
This will be used to plug signal handler / mainline code races.
For example, GDB can indefinitely delay handling a quit request if the
user presses Ctrl-C between the last QUIT call and the next (blocking)
gdb_select call in the event loop:
QUIT;
<<< press ctrl-c here and end up blocked in gdb_select
indefinitely.
gdb_select (...); // whoops, SIGINT was already handled, no EINTR.
A global alone (either the quit flag, or the "ready" flag of the async
signal handlers in the event loop) is not sufficient.
To plug races such as these on POSIX systems, we have to register some
waitable file descriptor in the set of files gdb_select waits on, and
write to it from the signal handler. This is classically a pipe, and
the pattern called the self-pipe trick. On Linux, it could be a more
efficient eventfd instead, but I'm sticking with a pipe for
simplifity, as we need it for portability anyway.
(Alternatively, we could use pselect/ppoll, and block signals until
the pselect. The latter is not a design I think GDB could use,
because we want the QUIT macro to be super cheap, as it is used in
loops. Plus, Windows.)
This is a "struct serial" because Windows's gdb_select relies on that.
Windows's gdb_select, our "select" replacement, knows how to wait on
all kinds of handles (regular files, pipes, sockets, console, etc.)
unlike the native Windows "select" function, which can only wait on
sockets. Each file descriptor for a "serial" type that is not
normally waitable with WaitForMultipleObjects must have a
corresponding struct serial instance. gdb_select then internally
looks up the struct serial instance that wraps each file descriptor,
and asks it for the corresponding Windows waitable handle.
We could use serial_pipe() to create a "struct serial"-wrapped pipe
that is usable everywhere, including Windows. That's what currently
python/python.c uses for cross-thread posting of events.
However, serial_write and serial_readchar are not designed to be
async-signal-safe on POSIX hosts. It's easier to bypass those when
setting/clearing the event source.
And writing and a serial pipe is a bit heavy weight on Windows.
gdb_select requires an extra thread to wait on the pipe and several
Windows events, when a single manual-reset Windows event, with no
extra thread is sufficient.
The intended usage is simply:
- Call make_serial_event to create a serial event object.
- From the signal handler call serial_event_set to set the event.
- From mainline code, have select/poll wait for serial_event_fd(), in
addition to whatever other files you're about to wait for.
gdb/ChangeLog:
2016-04-12 Pedro Alves <palves@redhat.com>
* Makefile.in (SFILES): Add ser-event.c.
(HFILES_NO_SRCDIR): Add ser-event.h.
(COMMON_OBS): Add ser-event.o.
* ser-event.c, ser-event.h: New files.
* serial.c (new_serial): New function, factored out from
(serial_fdopen_ops): ... this.
(serial_open_ops_1): New function, factored out from
(serial_open): ... this.
(serial_open_ops): New function.
* serial.h (struct serial): Forware declare.
(serial_open_ops): New declaration.
2016-04-12 23:49:30 +08:00
|
|
|
|
/* Create a new serial for OPS. */
|
|
|
|
|
|
|
|
|
|
static struct serial *
|
|
|
|
|
new_serial (const struct serial_ops *ops)
|
|
|
|
|
{
|
|
|
|
|
struct serial *scb;
|
|
|
|
|
|
|
|
|
|
scb = XCNEW (struct serial);
|
|
|
|
|
|
|
|
|
|
scb->ops = ops;
|
|
|
|
|
|
|
|
|
|
scb->bufp = scb->buf;
|
|
|
|
|
scb->error_fd = -1;
|
|
|
|
|
scb->refcnt = 1;
|
|
|
|
|
|
|
|
|
|
return scb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct serial *serial_open_ops_1 (const struct serial_ops *ops,
|
|
|
|
|
const char *open_name);
|
|
|
|
|
|
2011-01-12 05:53:25 +08:00
|
|
|
|
/* Open up a device or a network socket, depending upon the syntax of NAME. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
2001-07-12 01:52:32 +08:00
|
|
|
|
struct serial *
|
1999-09-22 11:28:34 +08:00
|
|
|
|
serial_open (const char *name)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
2001-07-12 01:52:32 +08:00
|
|
|
|
struct serial *scb;
|
2013-12-07 01:58:50 +08:00
|
|
|
|
const struct serial_ops *ops;
|
1999-09-22 11:28:34 +08:00
|
|
|
|
const char *open_name = name;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
2002-02-24 11:59:50 +08:00
|
|
|
|
if (strcmp (name, "pc") == 0)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
ops = serial_interface_lookup ("pc");
|
2015-03-06 17:42:06 +08:00
|
|
|
|
else if (startswith (name, "lpt"))
|
1999-04-16 09:35:26 +08:00
|
|
|
|
ops = serial_interface_lookup ("parallel");
|
2015-03-06 17:42:06 +08:00
|
|
|
|
else if (startswith (name, "|"))
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
ops = serial_interface_lookup ("pipe");
|
2006-11-04 16:37:24 +08:00
|
|
|
|
/* Discard ``|'' and any space before the command itself. */
|
|
|
|
|
++open_name;
|
2013-03-08 05:57:30 +08:00
|
|
|
|
open_name = skip_spaces_const (open_name);
|
1999-09-22 11:28:34 +08:00
|
|
|
|
}
|
2006-04-12 04:33:12 +08: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 09:35:26 +08:00
|
|
|
|
else
|
|
|
|
|
ops = serial_interface_lookup ("hardwire");
|
|
|
|
|
|
|
|
|
|
if (!ops)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
Introduce a serial interface for select'able events
This patch adds a new "event" struct serial type, that is an
abstraction specifically for waking up blocking waits/selects,
implemented on top of a pipe on POSIX, and on top of a native Windows
event (CreateEvent, etc.) on Windows.
This will be used to plug signal handler / mainline code races.
For example, GDB can indefinitely delay handling a quit request if the
user presses Ctrl-C between the last QUIT call and the next (blocking)
gdb_select call in the event loop:
QUIT;
<<< press ctrl-c here and end up blocked in gdb_select
indefinitely.
gdb_select (...); // whoops, SIGINT was already handled, no EINTR.
A global alone (either the quit flag, or the "ready" flag of the async
signal handlers in the event loop) is not sufficient.
To plug races such as these on POSIX systems, we have to register some
waitable file descriptor in the set of files gdb_select waits on, and
write to it from the signal handler. This is classically a pipe, and
the pattern called the self-pipe trick. On Linux, it could be a more
efficient eventfd instead, but I'm sticking with a pipe for
simplifity, as we need it for portability anyway.
(Alternatively, we could use pselect/ppoll, and block signals until
the pselect. The latter is not a design I think GDB could use,
because we want the QUIT macro to be super cheap, as it is used in
loops. Plus, Windows.)
This is a "struct serial" because Windows's gdb_select relies on that.
Windows's gdb_select, our "select" replacement, knows how to wait on
all kinds of handles (regular files, pipes, sockets, console, etc.)
unlike the native Windows "select" function, which can only wait on
sockets. Each file descriptor for a "serial" type that is not
normally waitable with WaitForMultipleObjects must have a
corresponding struct serial instance. gdb_select then internally
looks up the struct serial instance that wraps each file descriptor,
and asks it for the corresponding Windows waitable handle.
We could use serial_pipe() to create a "struct serial"-wrapped pipe
that is usable everywhere, including Windows. That's what currently
python/python.c uses for cross-thread posting of events.
However, serial_write and serial_readchar are not designed to be
async-signal-safe on POSIX hosts. It's easier to bypass those when
setting/clearing the event source.
And writing and a serial pipe is a bit heavy weight on Windows.
gdb_select requires an extra thread to wait on the pipe and several
Windows events, when a single manual-reset Windows event, with no
extra thread is sufficient.
The intended usage is simply:
- Call make_serial_event to create a serial event object.
- From the signal handler call serial_event_set to set the event.
- From mainline code, have select/poll wait for serial_event_fd(), in
addition to whatever other files you're about to wait for.
gdb/ChangeLog:
2016-04-12 Pedro Alves <palves@redhat.com>
* Makefile.in (SFILES): Add ser-event.c.
(HFILES_NO_SRCDIR): Add ser-event.h.
(COMMON_OBS): Add ser-event.o.
* ser-event.c, ser-event.h: New files.
* serial.c (new_serial): New function, factored out from
(serial_fdopen_ops): ... this.
(serial_open_ops_1): New function, factored out from
(serial_open): ... this.
(serial_open_ops): New function.
* serial.h (struct serial): Forware declare.
(serial_open_ops): New declaration.
2016-04-12 23:49:30 +08:00
|
|
|
|
return serial_open_ops_1 (ops, open_name);
|
|
|
|
|
}
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
Introduce a serial interface for select'able events
This patch adds a new "event" struct serial type, that is an
abstraction specifically for waking up blocking waits/selects,
implemented on top of a pipe on POSIX, and on top of a native Windows
event (CreateEvent, etc.) on Windows.
This will be used to plug signal handler / mainline code races.
For example, GDB can indefinitely delay handling a quit request if the
user presses Ctrl-C between the last QUIT call and the next (blocking)
gdb_select call in the event loop:
QUIT;
<<< press ctrl-c here and end up blocked in gdb_select
indefinitely.
gdb_select (...); // whoops, SIGINT was already handled, no EINTR.
A global alone (either the quit flag, or the "ready" flag of the async
signal handlers in the event loop) is not sufficient.
To plug races such as these on POSIX systems, we have to register some
waitable file descriptor in the set of files gdb_select waits on, and
write to it from the signal handler. This is classically a pipe, and
the pattern called the self-pipe trick. On Linux, it could be a more
efficient eventfd instead, but I'm sticking with a pipe for
simplifity, as we need it for portability anyway.
(Alternatively, we could use pselect/ppoll, and block signals until
the pselect. The latter is not a design I think GDB could use,
because we want the QUIT macro to be super cheap, as it is used in
loops. Plus, Windows.)
This is a "struct serial" because Windows's gdb_select relies on that.
Windows's gdb_select, our "select" replacement, knows how to wait on
all kinds of handles (regular files, pipes, sockets, console, etc.)
unlike the native Windows "select" function, which can only wait on
sockets. Each file descriptor for a "serial" type that is not
normally waitable with WaitForMultipleObjects must have a
corresponding struct serial instance. gdb_select then internally
looks up the struct serial instance that wraps each file descriptor,
and asks it for the corresponding Windows waitable handle.
We could use serial_pipe() to create a "struct serial"-wrapped pipe
that is usable everywhere, including Windows. That's what currently
python/python.c uses for cross-thread posting of events.
However, serial_write and serial_readchar are not designed to be
async-signal-safe on POSIX hosts. It's easier to bypass those when
setting/clearing the event source.
And writing and a serial pipe is a bit heavy weight on Windows.
gdb_select requires an extra thread to wait on the pipe and several
Windows events, when a single manual-reset Windows event, with no
extra thread is sufficient.
The intended usage is simply:
- Call make_serial_event to create a serial event object.
- From the signal handler call serial_event_set to set the event.
- From mainline code, have select/poll wait for serial_event_fd(), in
addition to whatever other files you're about to wait for.
gdb/ChangeLog:
2016-04-12 Pedro Alves <palves@redhat.com>
* Makefile.in (SFILES): Add ser-event.c.
(HFILES_NO_SRCDIR): Add ser-event.h.
(COMMON_OBS): Add ser-event.o.
* ser-event.c, ser-event.h: New files.
* serial.c (new_serial): New function, factored out from
(serial_fdopen_ops): ... this.
(serial_open_ops_1): New function, factored out from
(serial_open): ... this.
(serial_open_ops): New function.
* serial.h (struct serial): Forware declare.
(serial_open_ops): New declaration.
2016-04-12 23:49:30 +08:00
|
|
|
|
/* Open up a serial for OPS, passing OPEN_NAME to the open method. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
Introduce a serial interface for select'able events
This patch adds a new "event" struct serial type, that is an
abstraction specifically for waking up blocking waits/selects,
implemented on top of a pipe on POSIX, and on top of a native Windows
event (CreateEvent, etc.) on Windows.
This will be used to plug signal handler / mainline code races.
For example, GDB can indefinitely delay handling a quit request if the
user presses Ctrl-C between the last QUIT call and the next (blocking)
gdb_select call in the event loop:
QUIT;
<<< press ctrl-c here and end up blocked in gdb_select
indefinitely.
gdb_select (...); // whoops, SIGINT was already handled, no EINTR.
A global alone (either the quit flag, or the "ready" flag of the async
signal handlers in the event loop) is not sufficient.
To plug races such as these on POSIX systems, we have to register some
waitable file descriptor in the set of files gdb_select waits on, and
write to it from the signal handler. This is classically a pipe, and
the pattern called the self-pipe trick. On Linux, it could be a more
efficient eventfd instead, but I'm sticking with a pipe for
simplifity, as we need it for portability anyway.
(Alternatively, we could use pselect/ppoll, and block signals until
the pselect. The latter is not a design I think GDB could use,
because we want the QUIT macro to be super cheap, as it is used in
loops. Plus, Windows.)
This is a "struct serial" because Windows's gdb_select relies on that.
Windows's gdb_select, our "select" replacement, knows how to wait on
all kinds of handles (regular files, pipes, sockets, console, etc.)
unlike the native Windows "select" function, which can only wait on
sockets. Each file descriptor for a "serial" type that is not
normally waitable with WaitForMultipleObjects must have a
corresponding struct serial instance. gdb_select then internally
looks up the struct serial instance that wraps each file descriptor,
and asks it for the corresponding Windows waitable handle.
We could use serial_pipe() to create a "struct serial"-wrapped pipe
that is usable everywhere, including Windows. That's what currently
python/python.c uses for cross-thread posting of events.
However, serial_write and serial_readchar are not designed to be
async-signal-safe on POSIX hosts. It's easier to bypass those when
setting/clearing the event source.
And writing and a serial pipe is a bit heavy weight on Windows.
gdb_select requires an extra thread to wait on the pipe and several
Windows events, when a single manual-reset Windows event, with no
extra thread is sufficient.
The intended usage is simply:
- Call make_serial_event to create a serial event object.
- From the signal handler call serial_event_set to set the event.
- From mainline code, have select/poll wait for serial_event_fd(), in
addition to whatever other files you're about to wait for.
gdb/ChangeLog:
2016-04-12 Pedro Alves <palves@redhat.com>
* Makefile.in (SFILES): Add ser-event.c.
(HFILES_NO_SRCDIR): Add ser-event.h.
(COMMON_OBS): Add ser-event.o.
* ser-event.c, ser-event.h: New files.
* serial.c (new_serial): New function, factored out from
(serial_fdopen_ops): ... this.
(serial_open_ops_1): New function, factored out from
(serial_open): ... this.
(serial_open_ops): New function.
* serial.h (struct serial): Forware declare.
(serial_open_ops): New declaration.
2016-04-12 23:49:30 +08:00
|
|
|
|
static struct serial *
|
|
|
|
|
serial_open_ops_1 (const struct serial_ops *ops, const char *open_name)
|
|
|
|
|
{
|
|
|
|
|
struct serial *scb;
|
|
|
|
|
|
|
|
|
|
scb = new_serial (ops);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
2011-02-28 00:25:38 +08:00
|
|
|
|
/* `...->open (...)' would get expanded by the open(2) syscall macro. */
|
2007-08-09 06:12:35 +08:00
|
|
|
|
if ((*scb->ops->open) (scb, open_name))
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
2000-12-15 09:01:51 +08:00
|
|
|
|
xfree (scb);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 19:06:52 +08:00
|
|
|
|
scb->next = scb_base;
|
|
|
|
|
scb_base = scb;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
if (serial_logfile != NULL)
|
|
|
|
|
{
|
|
|
|
|
serial_logfp = gdb_fopen (serial_logfile, "w");
|
|
|
|
|
if (serial_logfp == NULL)
|
|
|
|
|
perror_with_name (serial_logfile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return scb;
|
|
|
|
|
}
|
|
|
|
|
|
Introduce a serial interface for select'able events
This patch adds a new "event" struct serial type, that is an
abstraction specifically for waking up blocking waits/selects,
implemented on top of a pipe on POSIX, and on top of a native Windows
event (CreateEvent, etc.) on Windows.
This will be used to plug signal handler / mainline code races.
For example, GDB can indefinitely delay handling a quit request if the
user presses Ctrl-C between the last QUIT call and the next (blocking)
gdb_select call in the event loop:
QUIT;
<<< press ctrl-c here and end up blocked in gdb_select
indefinitely.
gdb_select (...); // whoops, SIGINT was already handled, no EINTR.
A global alone (either the quit flag, or the "ready" flag of the async
signal handlers in the event loop) is not sufficient.
To plug races such as these on POSIX systems, we have to register some
waitable file descriptor in the set of files gdb_select waits on, and
write to it from the signal handler. This is classically a pipe, and
the pattern called the self-pipe trick. On Linux, it could be a more
efficient eventfd instead, but I'm sticking with a pipe for
simplifity, as we need it for portability anyway.
(Alternatively, we could use pselect/ppoll, and block signals until
the pselect. The latter is not a design I think GDB could use,
because we want the QUIT macro to be super cheap, as it is used in
loops. Plus, Windows.)
This is a "struct serial" because Windows's gdb_select relies on that.
Windows's gdb_select, our "select" replacement, knows how to wait on
all kinds of handles (regular files, pipes, sockets, console, etc.)
unlike the native Windows "select" function, which can only wait on
sockets. Each file descriptor for a "serial" type that is not
normally waitable with WaitForMultipleObjects must have a
corresponding struct serial instance. gdb_select then internally
looks up the struct serial instance that wraps each file descriptor,
and asks it for the corresponding Windows waitable handle.
We could use serial_pipe() to create a "struct serial"-wrapped pipe
that is usable everywhere, including Windows. That's what currently
python/python.c uses for cross-thread posting of events.
However, serial_write and serial_readchar are not designed to be
async-signal-safe on POSIX hosts. It's easier to bypass those when
setting/clearing the event source.
And writing and a serial pipe is a bit heavy weight on Windows.
gdb_select requires an extra thread to wait on the pipe and several
Windows events, when a single manual-reset Windows event, with no
extra thread is sufficient.
The intended usage is simply:
- Call make_serial_event to create a serial event object.
- From the signal handler call serial_event_set to set the event.
- From mainline code, have select/poll wait for serial_event_fd(), in
addition to whatever other files you're about to wait for.
gdb/ChangeLog:
2016-04-12 Pedro Alves <palves@redhat.com>
* Makefile.in (SFILES): Add ser-event.c.
(HFILES_NO_SRCDIR): Add ser-event.h.
(COMMON_OBS): Add ser-event.o.
* ser-event.c, ser-event.h: New files.
* serial.c (new_serial): New function, factored out from
(serial_fdopen_ops): ... this.
(serial_open_ops_1): New function, factored out from
(serial_open): ... this.
(serial_open_ops): New function.
* serial.h (struct serial): Forware declare.
(serial_open_ops): New declaration.
2016-04-12 23:49:30 +08:00
|
|
|
|
/* See serial.h. */
|
|
|
|
|
|
|
|
|
|
struct serial *
|
|
|
|
|
serial_open_ops (const struct serial_ops *ops)
|
|
|
|
|
{
|
|
|
|
|
return serial_open_ops_1 (ops, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-21 02:49:20 +08:00
|
|
|
|
/* Open a new serial stream using a file handle, using serial
|
|
|
|
|
interface ops OPS. */
|
|
|
|
|
|
|
|
|
|
static struct serial *
|
2013-12-07 01:58:50 +08:00
|
|
|
|
serial_fdopen_ops (const int fd, const struct serial_ops *ops)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
2001-07-12 01:52:32 +08:00
|
|
|
|
struct serial *scb;
|
1999-04-16 09:35:26 +08: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-11 06:01:43 +08:00
|
|
|
|
if (!ops)
|
2010-08-21 02:49:20 +08:00
|
|
|
|
{
|
|
|
|
|
ops = serial_interface_lookup ("terminal");
|
|
|
|
|
if (!ops)
|
|
|
|
|
ops = serial_interface_lookup ("hardwire");
|
|
|
|
|
}
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
if (!ops)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
Introduce a serial interface for select'able events
This patch adds a new "event" struct serial type, that is an
abstraction specifically for waking up blocking waits/selects,
implemented on top of a pipe on POSIX, and on top of a native Windows
event (CreateEvent, etc.) on Windows.
This will be used to plug signal handler / mainline code races.
For example, GDB can indefinitely delay handling a quit request if the
user presses Ctrl-C between the last QUIT call and the next (blocking)
gdb_select call in the event loop:
QUIT;
<<< press ctrl-c here and end up blocked in gdb_select
indefinitely.
gdb_select (...); // whoops, SIGINT was already handled, no EINTR.
A global alone (either the quit flag, or the "ready" flag of the async
signal handlers in the event loop) is not sufficient.
To plug races such as these on POSIX systems, we have to register some
waitable file descriptor in the set of files gdb_select waits on, and
write to it from the signal handler. This is classically a pipe, and
the pattern called the self-pipe trick. On Linux, it could be a more
efficient eventfd instead, but I'm sticking with a pipe for
simplifity, as we need it for portability anyway.
(Alternatively, we could use pselect/ppoll, and block signals until
the pselect. The latter is not a design I think GDB could use,
because we want the QUIT macro to be super cheap, as it is used in
loops. Plus, Windows.)
This is a "struct serial" because Windows's gdb_select relies on that.
Windows's gdb_select, our "select" replacement, knows how to wait on
all kinds of handles (regular files, pipes, sockets, console, etc.)
unlike the native Windows "select" function, which can only wait on
sockets. Each file descriptor for a "serial" type that is not
normally waitable with WaitForMultipleObjects must have a
corresponding struct serial instance. gdb_select then internally
looks up the struct serial instance that wraps each file descriptor,
and asks it for the corresponding Windows waitable handle.
We could use serial_pipe() to create a "struct serial"-wrapped pipe
that is usable everywhere, including Windows. That's what currently
python/python.c uses for cross-thread posting of events.
However, serial_write and serial_readchar are not designed to be
async-signal-safe on POSIX hosts. It's easier to bypass those when
setting/clearing the event source.
And writing and a serial pipe is a bit heavy weight on Windows.
gdb_select requires an extra thread to wait on the pipe and several
Windows events, when a single manual-reset Windows event, with no
extra thread is sufficient.
The intended usage is simply:
- Call make_serial_event to create a serial event object.
- From the signal handler call serial_event_set to set the event.
- From mainline code, have select/poll wait for serial_event_fd(), in
addition to whatever other files you're about to wait for.
gdb/ChangeLog:
2016-04-12 Pedro Alves <palves@redhat.com>
* Makefile.in (SFILES): Add ser-event.c.
(HFILES_NO_SRCDIR): Add ser-event.h.
(COMMON_OBS): Add ser-event.o.
* ser-event.c, ser-event.h: New files.
* serial.c (new_serial): New function, factored out from
(serial_fdopen_ops): ... this.
(serial_open_ops_1): New function, factored out from
(serial_open): ... this.
(serial_open_ops): New function.
* serial.h (struct serial): Forware declare.
(serial_open_ops): New declaration.
2016-04-12 23:49:30 +08:00
|
|
|
|
scb = new_serial (ops);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
2012-06-13 19:06:52 +08:00
|
|
|
|
scb->next = scb_base;
|
|
|
|
|
scb_base = scb;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
2010-08-21 02:49:20 +08:00
|
|
|
|
if ((ops->fdopen) != NULL)
|
|
|
|
|
(*ops->fdopen) (scb, fd);
|
|
|
|
|
else
|
|
|
|
|
scb->fd = fd;
|
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
|
return scb;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-21 02:49:20 +08:00
|
|
|
|
struct serial *
|
|
|
|
|
serial_fdopen (const int fd)
|
|
|
|
|
{
|
|
|
|
|
return serial_fdopen_ops (fd, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 11:28:34 +08:00
|
|
|
|
static void
|
2001-07-12 01:52:32 +08:00
|
|
|
|
do_serial_close (struct serial *scb, int really_close)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
2001-07-12 01:52:32 +08:00
|
|
|
|
struct serial *tmp_scb;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
if (serial_logfp)
|
|
|
|
|
{
|
|
|
|
|
fputs_unfiltered ("\nEnd of log\n", serial_logfp);
|
|
|
|
|
serial_current_type = 0;
|
|
|
|
|
|
2011-01-12 05:53:25 +08:00
|
|
|
|
/* XXX - What if serial_logfp == gdb_stdout or gdb_stderr? */
|
2000-02-02 08:21:19 +08:00
|
|
|
|
ui_file_delete (serial_logfp);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
serial_logfp = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-12 05:53:25 +08:00
|
|
|
|
/* ensure that the FD has been taken out of async mode. */
|
1999-09-22 11:28:34 +08:00
|
|
|
|
if (scb->async_handler != NULL)
|
|
|
|
|
serial_async (scb, NULL, NULL);
|
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
|
if (really_close)
|
|
|
|
|
scb->ops->close (scb);
|
|
|
|
|
|
2012-06-12 04:36:53 +08:00
|
|
|
|
/* For serial_is_open. */
|
|
|
|
|
scb->bufp = NULL;
|
|
|
|
|
|
2012-06-13 19:06:52 +08: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-12 04:36:53 +08:00
|
|
|
|
serial_unref (scb);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 11:28:34 +08:00
|
|
|
|
void
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_close (struct serial *scb)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
do_serial_close (scb, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_un_fdopen (struct serial *scb)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
do_serial_close (scb, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 04:36:53 +08: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 11:28:34 +08:00
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_readchar (struct serial *scb, int timeout)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
int ch;
|
|
|
|
|
|
1999-10-12 12:37:53 +08:00
|
|
|
|
/* FIXME: cagney/1999-10-11: Don't enable this check until the ASYNC
|
2011-01-12 05:53:25 +08:00
|
|
|
|
code is finished. */
|
2001-07-16 04:34:14 +08:00
|
|
|
|
if (0 && serial_is_async_p (scb) && timeout < 0)
|
2001-02-08 14:03:54 +08: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-12 02:13:55 +08:00
|
|
|
|
_("serial_readchar: blocking read in async mode"));
|
1999-10-12 12:37:53 +08:00
|
|
|
|
|
1999-09-22 11:28:34 +08:00
|
|
|
|
ch = scb->ops->readchar (scb, timeout);
|
|
|
|
|
if (serial_logfp != NULL)
|
|
|
|
|
{
|
1999-10-06 07:13:56 +08:00
|
|
|
|
serial_logchar (serial_logfp, 'r', ch, timeout);
|
1999-09-22 11:28:34 +08:00
|
|
|
|
|
|
|
|
|
/* Make sure that the log file is as up-to-date as possible,
|
2011-01-12 05:53:25 +08:00
|
|
|
|
in case we are getting ready to dump core or something. */
|
1999-09-22 11:28:34 +08:00
|
|
|
|
gdb_flush (serial_logfp);
|
|
|
|
|
}
|
2001-07-16 04:34:14 +08:00
|
|
|
|
if (serial_debug_p (scb))
|
1999-10-06 07:13:56 +08:00
|
|
|
|
{
|
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "[");
|
|
|
|
|
serial_logchar (gdb_stdlog, 'r', ch, timeout);
|
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "]");
|
|
|
|
|
gdb_flush (gdb_stdlog);
|
|
|
|
|
}
|
1999-09-22 11:28:34 +08:00
|
|
|
|
|
|
|
|
|
return (ch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
serial_write: change prototype to take a void-pointer buffer.
While remote.c works with "char *" buffers most of the time, other
remote targets have binary-ish-er protocols, and choose to use
"unsigned char" throughout, like e.g., remote-mips.c or
remote-m32r-sdi.c. That results in -Wpointer-sign warnings in those
targets, unless we add casts in calls to serial_write. Since
serial_write is only concerned about sending raw host bytes out, and
serial_ops->write_prim already works with "void *"/"size_t", a similar
interface to the "write" or "send" system calls, I find it natural to
change serial_write's prototype accordingly, avoiding the need for
casts.
Tested on x86_64 Fedora 17, and also by building x86_64-mingw32
and DJGPP/go32 -hosted gdbs.
gdb/
2013-04-19 Pedro Alves <palves@redhat.com>
* ser-base.c (ser_base_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
* ser-base.h (ser_base_write): Adjust.
* ser-go32.c (cnts): Change type to size_t.
(dos_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
(dos_info): Print elements of 'cnts' as unsigned long.
* serial.c (serial_write): Likewise.
* serial.h (serial_write): Adjust.
(struct serial_ops) <write>: Change prototype -- take 'void *'
buffer and size_t size. Adjust.
2013-04-19 23:26:17 +08:00
|
|
|
|
serial_write (struct serial *scb, const void *buf, size_t count)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
if (serial_logfp != NULL)
|
|
|
|
|
{
|
2015-09-26 02:08:07 +08:00
|
|
|
|
const char *str = (const char *) buf;
|
serial_write: change prototype to take a void-pointer buffer.
While remote.c works with "char *" buffers most of the time, other
remote targets have binary-ish-er protocols, and choose to use
"unsigned char" throughout, like e.g., remote-mips.c or
remote-m32r-sdi.c. That results in -Wpointer-sign warnings in those
targets, unless we add casts in calls to serial_write. Since
serial_write is only concerned about sending raw host bytes out, and
serial_ops->write_prim already works with "void *"/"size_t", a similar
interface to the "write" or "send" system calls, I find it natural to
change serial_write's prototype accordingly, avoiding the need for
casts.
Tested on x86_64 Fedora 17, and also by building x86_64-mingw32
and DJGPP/go32 -hosted gdbs.
gdb/
2013-04-19 Pedro Alves <palves@redhat.com>
* ser-base.c (ser_base_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
* ser-base.h (ser_base_write): Adjust.
* ser-go32.c (cnts): Change type to size_t.
(dos_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
(dos_info): Print elements of 'cnts' as unsigned long.
* serial.c (serial_write): Likewise.
* serial.h (serial_write): Adjust.
(struct serial_ops) <write>: Change prototype -- take 'void *'
buffer and size_t size. Adjust.
2013-04-19 23:26:17 +08:00
|
|
|
|
size_t c;
|
1999-09-22 11:28:34 +08:00
|
|
|
|
|
serial_write: change prototype to take a void-pointer buffer.
While remote.c works with "char *" buffers most of the time, other
remote targets have binary-ish-er protocols, and choose to use
"unsigned char" throughout, like e.g., remote-mips.c or
remote-m32r-sdi.c. That results in -Wpointer-sign warnings in those
targets, unless we add casts in calls to serial_write. Since
serial_write is only concerned about sending raw host bytes out, and
serial_ops->write_prim already works with "void *"/"size_t", a similar
interface to the "write" or "send" system calls, I find it natural to
change serial_write's prototype accordingly, avoiding the need for
casts.
Tested on x86_64 Fedora 17, and also by building x86_64-mingw32
and DJGPP/go32 -hosted gdbs.
gdb/
2013-04-19 Pedro Alves <palves@redhat.com>
* ser-base.c (ser_base_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
* ser-base.h (ser_base_write): Adjust.
* ser-go32.c (cnts): Change type to size_t.
(dos_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
(dos_info): Print elements of 'cnts' as unsigned long.
* serial.c (serial_write): Likewise.
* serial.h (serial_write): Adjust.
(struct serial_ops) <write>: Change prototype -- take 'void *'
buffer and size_t size. Adjust.
2013-04-19 23:26:17 +08:00
|
|
|
|
for (c = 0; c < count; c++)
|
|
|
|
|
serial_logchar (serial_logfp, 'w', str[c] & 0xff, 0);
|
1999-09-22 11:28:34 +08:00
|
|
|
|
|
|
|
|
|
/* Make sure that the log file is as up-to-date as possible,
|
2011-01-12 05:53:25 +08:00
|
|
|
|
in case we are getting ready to dump core or something. */
|
1999-09-22 11:28:34 +08:00
|
|
|
|
gdb_flush (serial_logfp);
|
|
|
|
|
}
|
2010-04-27 05:45:50 +08:00
|
|
|
|
if (serial_debug_p (scb))
|
|
|
|
|
{
|
2015-09-26 02:08:07 +08:00
|
|
|
|
const char *str = (const char *) buf;
|
serial_write: change prototype to take a void-pointer buffer.
While remote.c works with "char *" buffers most of the time, other
remote targets have binary-ish-er protocols, and choose to use
"unsigned char" throughout, like e.g., remote-mips.c or
remote-m32r-sdi.c. That results in -Wpointer-sign warnings in those
targets, unless we add casts in calls to serial_write. Since
serial_write is only concerned about sending raw host bytes out, and
serial_ops->write_prim already works with "void *"/"size_t", a similar
interface to the "write" or "send" system calls, I find it natural to
change serial_write's prototype accordingly, avoiding the need for
casts.
Tested on x86_64 Fedora 17, and also by building x86_64-mingw32
and DJGPP/go32 -hosted gdbs.
gdb/
2013-04-19 Pedro Alves <palves@redhat.com>
* ser-base.c (ser_base_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
* ser-base.h (ser_base_write): Adjust.
* ser-go32.c (cnts): Change type to size_t.
(dos_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
(dos_info): Print elements of 'cnts' as unsigned long.
* serial.c (serial_write): Likewise.
* serial.h (serial_write): Adjust.
(struct serial_ops) <write>: Change prototype -- take 'void *'
buffer and size_t size. Adjust.
2013-04-19 23:26:17 +08:00
|
|
|
|
size_t c;
|
2010-04-27 05:45:50 +08:00
|
|
|
|
|
serial_write: change prototype to take a void-pointer buffer.
While remote.c works with "char *" buffers most of the time, other
remote targets have binary-ish-er protocols, and choose to use
"unsigned char" throughout, like e.g., remote-mips.c or
remote-m32r-sdi.c. That results in -Wpointer-sign warnings in those
targets, unless we add casts in calls to serial_write. Since
serial_write is only concerned about sending raw host bytes out, and
serial_ops->write_prim already works with "void *"/"size_t", a similar
interface to the "write" or "send" system calls, I find it natural to
change serial_write's prototype accordingly, avoiding the need for
casts.
Tested on x86_64 Fedora 17, and also by building x86_64-mingw32
and DJGPP/go32 -hosted gdbs.
gdb/
2013-04-19 Pedro Alves <palves@redhat.com>
* ser-base.c (ser_base_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
* ser-base.h (ser_base_write): Adjust.
* ser-go32.c (cnts): Change type to size_t.
(dos_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
(dos_info): Print elements of 'cnts' as unsigned long.
* serial.c (serial_write): Likewise.
* serial.h (serial_write): Adjust.
(struct serial_ops) <write>: Change prototype -- take 'void *'
buffer and size_t size. Adjust.
2013-04-19 23:26:17 +08:00
|
|
|
|
for (c = 0; c < count; c++)
|
2010-04-27 05:45:50 +08:00
|
|
|
|
{
|
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "[");
|
2014-06-06 23:28:27 +08:00
|
|
|
|
serial_logchar (gdb_stdlog, 'w', str[c] & 0xff, 0);
|
2010-04-27 05:45:50 +08:00
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "]");
|
|
|
|
|
}
|
|
|
|
|
gdb_flush (gdb_stdlog);
|
|
|
|
|
}
|
1999-09-22 11:28:34 +08:00
|
|
|
|
|
serial_write: change prototype to take a void-pointer buffer.
While remote.c works with "char *" buffers most of the time, other
remote targets have binary-ish-er protocols, and choose to use
"unsigned char" throughout, like e.g., remote-mips.c or
remote-m32r-sdi.c. That results in -Wpointer-sign warnings in those
targets, unless we add casts in calls to serial_write. Since
serial_write is only concerned about sending raw host bytes out, and
serial_ops->write_prim already works with "void *"/"size_t", a similar
interface to the "write" or "send" system calls, I find it natural to
change serial_write's prototype accordingly, avoiding the need for
casts.
Tested on x86_64 Fedora 17, and also by building x86_64-mingw32
and DJGPP/go32 -hosted gdbs.
gdb/
2013-04-19 Pedro Alves <palves@redhat.com>
* ser-base.c (ser_base_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
* ser-base.h (ser_base_write): Adjust.
* ser-go32.c (cnts): Change type to size_t.
(dos_write): Change prototype -- take 'void *'
buffer and size_t size. Adjust.
(dos_info): Print elements of 'cnts' as unsigned long.
* serial.c (serial_write): Likewise.
* serial.h (serial_write): Adjust.
(struct serial_ops) <write>: Change prototype -- take 'void *'
buffer and size_t size. Adjust.
2013-04-19 23:26:17 +08:00
|
|
|
|
return (scb->ops->write (scb, buf, count));
|
1999-09-22 11:28:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_printf (struct serial *desc, const char *format,...)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
char *buf;
|
|
|
|
|
va_start (args, format);
|
|
|
|
|
|
2004-06-29 22:57:39 +08:00
|
|
|
|
buf = xstrvprintf (format, args);
|
2001-07-16 04:34:14 +08:00
|
|
|
|
serial_write (desc, buf, strlen (buf));
|
1999-09-22 11:28:34 +08:00
|
|
|
|
|
2000-12-15 09:01:51 +08:00
|
|
|
|
xfree (buf);
|
1999-09-22 11:28:34 +08:00
|
|
|
|
va_end (args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_drain_output (struct serial *scb)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->drain_output (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_flush_output (struct serial *scb)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->flush_output (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_flush_input (struct serial *scb)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->flush_input (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_send_break (struct serial *scb)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
if (serial_logfp != NULL)
|
1999-10-06 07:13:56 +08:00
|
|
|
|
serial_logchar (serial_logfp, 'w', SERIAL_BREAK, 0);
|
1999-09-22 11:28:34 +08:00
|
|
|
|
|
|
|
|
|
return (scb->ops->send_break (scb));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_raw (struct serial *scb)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
scb->ops->go_raw (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serial_ttystate
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_get_tty_state (struct serial *scb)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->get_tty_state (scb);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-05 03:23:42 +08:00
|
|
|
|
serial_ttystate
|
|
|
|
|
serial_copy_tty_state (struct serial *scb, serial_ttystate ttystate)
|
|
|
|
|
{
|
|
|
|
|
return scb->ops->copy_tty_state (scb, ttystate);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 11:28:34 +08:00
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_set_tty_state (struct serial *scb, serial_ttystate ttystate)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->set_tty_state (scb, ttystate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_print_tty_state (struct serial *scb,
|
1999-09-22 11:28:34 +08:00
|
|
|
|
serial_ttystate ttystate,
|
2000-02-02 08:21:19 +08:00
|
|
|
|
struct ui_file *stream)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
scb->ops->print_tty_state (scb, ttystate, stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_noflush_set_tty_state (struct serial *scb,
|
1999-09-22 11:28:34 +08:00
|
|
|
|
serial_ttystate new_ttystate,
|
|
|
|
|
serial_ttystate old_ttystate)
|
|
|
|
|
{
|
|
|
|
|
return scb->ops->noflush_set_tty_state (scb, new_ttystate, old_ttystate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_setbaudrate (struct serial *scb, int rate)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->setbaudrate (scb, rate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_setstopbits (struct serial *scb, int num)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->setstopbits (scb, num);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-24 05:15:42 +08:00
|
|
|
|
/* See serial.h. */
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
serial_setparity (struct serial *scb, int parity)
|
|
|
|
|
{
|
|
|
|
|
return scb->ops->setparity (scb, parity);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 11:28:34 +08:00
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_can_async_p (struct serial *scb)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
return (scb->ops->async != NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_is_async_p (struct serial *scb)
|
1999-09-22 11:28:34 +08:00
|
|
|
|
{
|
|
|
|
|
return (scb->ops->async != NULL) && (scb->async_handler != NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_async (struct serial *scb,
|
1999-09-22 11:28:34 +08:00
|
|
|
|
serial_event_ftype *handler,
|
|
|
|
|
void *context)
|
|
|
|
|
{
|
2008-02-24 04:04:20 +08:00
|
|
|
|
int changed = ((scb->async_handler == NULL) != (handler == NULL));
|
2010-05-17 07:49:58 +08:00
|
|
|
|
|
1999-09-22 11:28:34 +08:00
|
|
|
|
scb->async_handler = handler;
|
|
|
|
|
scb->async_context = context;
|
2008-02-24 04:04:20 +08:00
|
|
|
|
/* Only change mode if there is a need. */
|
|
|
|
|
if (changed)
|
|
|
|
|
scb->ops->async (scb, handler != NULL);
|
1999-09-22 11:28:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-06 07:13:56 +08:00
|
|
|
|
void
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_debug (struct serial *scb, int debug_p)
|
1999-10-06 07:13:56 +08:00
|
|
|
|
{
|
|
|
|
|
scb->debug_p = debug_p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-12 01:52:32 +08:00
|
|
|
|
serial_debug_p (struct serial *scb)
|
1999-10-06 07:13:56 +08: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-11 06:01:43 +08: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-25 05:00:13 +08: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-11 06:01:43 +08:00
|
|
|
|
#endif
|
1999-10-06 07:13:56 +08:00
|
|
|
|
|
2010-08-21 02:49:20 +08:00
|
|
|
|
int
|
|
|
|
|
serial_pipe (struct serial *scbs[2])
|
|
|
|
|
{
|
2013-12-07 01:58:50 +08:00
|
|
|
|
const struct serial_ops *ops;
|
2010-08-21 02:49:20 +08:00
|
|
|
|
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-27 07:27:39 +08: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-06 06:22:53 +08:00
|
|
|
|
printf_unfiltered ("\"set serial\" must be followed "
|
|
|
|
|
"by the name of a command.\n");
|
make calls to help_list use enumerator
Currently there are many calls to help_list that pass the constant -1
as the "class" value. However, the parameter is declared as being of
type enum command_class, and uses of the constant violate this
abstraction.
This patch fixes the error everywhere it occurs in the gdb sources.
Tested by rebuilding.
2014-06-13 Tom Tromey <tromey@redhat.com>
* cp-support.c (maint_cplus_command): Pass all_commands, not -1,
to help_list.
* guile/guile.c (info_guile_command): Pass all_commands, not -1,
to help_list.
* tui/tui-win.c (tui_command): Pass all_commands, not -1, to
help_list.
* tui/tui-regs.c (tui_reg_command): Pass all_commands, not -1, to
help_list.Pass all_commands, not -1, to help_list.
* cli/cli-dump.c (dump_command, append_command)
(srec_dump_command, ihex_dump_command, tekhex_dump_command)
(binary_dump_command, binary_append_command): Pass all_commands,
not -1, to help_list.
* cli/cli-cmds.c (info_command, set_debug): Pass all_commands, not
-1, to help_list.
* valprint.c (set_print, set_print_raw): Pass all_commands, not
-1, to help_list.
* typeprint.c (set_print_type): Pass all_commands, not -1, to
help_list.
* top.c (set_history): Pass all_commands, not -1, to help_list.
* target-descriptions.c (set_tdesc_cmd, unset_tdesc_cmd): Pass
all_commands, not -1, to help_list.
* symfile.c (overlay_command): Pass all_commands, not -1, to
help_list.
* spu-tdep.c (info_spu_command): Pass all_commands, not -1, to
help_list.
* serial.c (serial_set_cmd): Pass all_commands, not -1, to
help_list.
* ser-tcp.c (set_tcp_cmd, show_tcp_cmd): Pass all_commands, not
-1, to help_list.
* remote.c (remote_command, set_remote_cmd): Pass all_commands,
not -1, to help_list.
* ravenscar-thread.c (set_ravenscar_command): Pass all_commands,
not -1, to help_list.
* maint.c (maintenance_command, maintenance_info_command)
(maintenance_print_command, maintenance_set_cmd): Pass
all_commands, not -1, to help_list.
* macrocmd.c (macro_command): Pass all_commands, not -1, to
help_list.
* language.c (set_check): Pass all_commands, not -1, to help_list.
* infcmd.c (unset_command): Pass all_commands, not -1, to
help_list.
* frame.c (set_backtrace_cmd): Pass all_commands, not -1, to
help_list.
* dwarf2read.c (set_dwarf2_cmd): Pass all_commands, not -1, to
help_list.
* dcache.c (set_dcache_command): Pass all_commands, not -1, to
help_list.
* breakpoint.c (save_command): Pass all_commands, not -1, to
help_list.
* ada-lang.c (maint_set_ada_cmd, set_ada_command): Pass
all_commands, not -1, to help_list.
2014-06-05 22:25:00 +08:00
|
|
|
|
help_list (serial_set_cmdlist, "set serial ", all_commands, gdb_stdout);
|
2001-09-27 07:27:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
serial_show_cmd (char *args, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
cmd_show_list (serial_show_cmdlist, from_tty, "");
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 13:50:20 +08:00
|
|
|
|
/* Baud rate specified for talking to serial target systems. Default
|
|
|
|
|
is left as -1, so targets can choose their own defaults. */
|
|
|
|
|
/* FIXME: This means that "show serial baud" and gr_files_info can
|
|
|
|
|
print -1 or (unsigned int)-1. This is a Bad User Interface. */
|
|
|
|
|
|
|
|
|
|
int baud_rate = -1;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
serial_baud_show_cmd (struct ui_file *file, int from_tty,
|
|
|
|
|
struct cmd_list_element *c, const char *value)
|
|
|
|
|
{
|
|
|
|
|
fprintf_filtered (file, _("Baud rate for remote serial I/O is %s.\n"),
|
|
|
|
|
value);
|
|
|
|
|
}
|
2001-09-27 07:27:39 +08:00
|
|
|
|
|
2015-03-24 05:15:42 +08:00
|
|
|
|
/* Parity for serial port. */
|
|
|
|
|
|
|
|
|
|
int serial_parity = GDBPARITY_NONE;
|
|
|
|
|
|
|
|
|
|
static const char parity_none[] = "none";
|
|
|
|
|
static const char parity_odd[] = "odd";
|
|
|
|
|
static const char parity_even[] = "even";
|
|
|
|
|
static const char *const parity_enums[] =
|
|
|
|
|
{parity_none, parity_odd, parity_even, NULL};
|
|
|
|
|
static const char *parity = parity_none;
|
|
|
|
|
|
|
|
|
|
/* Set serial_parity value. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_parity (char *ignore_args, int from_tty, struct cmd_list_element *c)
|
|
|
|
|
{
|
|
|
|
|
if (parity == parity_odd)
|
|
|
|
|
serial_parity = GDBPARITY_ODD;
|
|
|
|
|
else if (parity == parity_even)
|
|
|
|
|
serial_parity = GDBPARITY_EVEN;
|
|
|
|
|
else
|
|
|
|
|
serial_parity = GDBPARITY_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
|
void
|
1999-09-22 11:28:34 +08:00
|
|
|
|
_initialize_serial (void)
|
1999-04-16 09:35:26 +08: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 23:49:28 +08: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 09:35:26 +08: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 23:49:28 +08:00
|
|
|
|
add_prefix_cmd ("serial", class_maintenance, serial_set_cmd, _("\
|
|
|
|
|
Set default serial/parallel port configuration."),
|
2001-09-27 07:27:39 +08: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 23:49:28 +08:00
|
|
|
|
add_prefix_cmd ("serial", class_maintenance, serial_show_cmd, _("\
|
|
|
|
|
Show default serial/parallel port configuration."),
|
2001-09-27 07:27:39 +08:00
|
|
|
|
&serial_show_cmdlist, "show serial ",
|
|
|
|
|
0/*allow-unknown*/,
|
|
|
|
|
&showlist);
|
|
|
|
|
|
2013-10-10 13:50:20 +08:00
|
|
|
|
/* If target is open when baud changes, it doesn't take effect until
|
|
|
|
|
the next open (I think, not sure). */
|
|
|
|
|
add_setshow_zinteger_cmd ("baud", no_class, &baud_rate, _("\
|
|
|
|
|
Set baud rate for remote serial I/O."), _("\
|
|
|
|
|
Show baud rate for remote serial I/O."), _("\
|
|
|
|
|
This value is used to set the speed of the serial port when debugging\n\
|
|
|
|
|
using remote targets."),
|
|
|
|
|
NULL,
|
|
|
|
|
serial_baud_show_cmd,
|
|
|
|
|
&serial_set_cmdlist, &serial_show_cmdlist);
|
|
|
|
|
|
2015-03-24 05:15:42 +08:00
|
|
|
|
add_setshow_enum_cmd ("parity", no_class, parity_enums,
|
|
|
|
|
&parity, _("\
|
|
|
|
|
Set parity for remote serial I/O"), _("\
|
|
|
|
|
Show parity for remote serial I/O"), NULL,
|
|
|
|
|
set_parity,
|
|
|
|
|
NULL, /* FIXME: i18n: */
|
|
|
|
|
&serial_set_cmdlist, &serial_show_cmdlist);
|
|
|
|
|
|
2005-02-18 01:11:04 +08: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 09:35:26 +08:00
|
|
|
|
This file is used to record the remote session for future playback\n\
|
2005-02-18 01:11:04 +08:00
|
|
|
|
by gdbserver."),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL, /* FIXME: i18n: */
|
|
|
|
|
&setlist, &showlist);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
2005-02-21 12:31:59 +08: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-06 07:13:56 +08:00
|
|
|
|
|
2012-08-02 17:36:40 +08: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-19 02:58:56 +08:00
|
|
|
|
Set serial debugging."), _("\
|
|
|
|
|
Show serial debugging."), _("\
|
|
|
|
|
When non-zero, serial port debugging is enabled."),
|
2012-08-02 17:36:40 +08:00
|
|
|
|
NULL,
|
|
|
|
|
NULL, /* FIXME: i18n: */
|
|
|
|
|
&setdebuglist, &showdebuglist);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
}
|