1999-04-16 03:35:26 +02:00
|
|
|
|
/* Generic serial interface routines
|
2001-01-31 02:24:03 +01:00
|
|
|
|
|
2015-01-01 10:32:14 +01:00
|
|
|
|
Copyright (C) 1992-2015 Free Software Foundation, Inc.
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
|
This file is part of GDB.
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
1999-07-07 22:19:36 +02: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 20:08:50 +02:00
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
1999-07-07 22:19:36 +02:00
|
|
|
|
(at your option) any later version.
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
1999-07-07 22:19:36 +02: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 03:35:26 +02:00
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
|
You should have received a copy of the GNU General Public License
|
2007-08-23 20:08:50 +02:00
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include "serial.h"
|
|
|
|
|
#include "gdbcmd.h"
|
2013-03-07 22:57:30 +01:00
|
|
|
|
#include "cli/cli-utils.h"
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
1999-09-22 05:28:34 +02:00
|
|
|
|
extern void _initialize_serial (void);
|
1999-05-25 20:09:09 +02:00
|
|
|
|
|
2011-01-11 22:53:25 +01:00
|
|
|
|
/* Is serial being debugged? */
|
1999-10-06 01:13:56 +02:00
|
|
|
|
|
2012-08-02 11:36:40 +02:00
|
|
|
|
static unsigned int global_serial_debug_p;
|
1999-10-06 01:13:56 +02:00
|
|
|
|
|
2013-12-06 18:58:50 +01:00
|
|
|
|
typedef const struct serial_ops *serial_ops_p;
|
|
|
|
|
DEF_VEC_P (serial_ops_p);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
2013-12-06 18:58:50 +01:00
|
|
|
|
/* Serial I/O handlers. */
|
|
|
|
|
|
|
|
|
|
VEC (serial_ops_p) *serial_ops_list = NULL;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
2012-06-13 13:06:52 +02:00
|
|
|
|
/* Pointer to list of scb's. */
|
|
|
|
|
|
|
|
|
|
static struct serial *scb_base;
|
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
|
/* Non-NULL gives filename which contains a recording of the remote session,
|
2011-01-11 22:53:25 +01:00
|
|
|
|
suitable for playback by gdbserver. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
|
|
static char *serial_logfile = NULL;
|
2000-02-02 01:21:19 +01:00
|
|
|
|
static struct ui_file *serial_logfp = NULL;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
2013-12-06 18:58:50 +01:00
|
|
|
|
static const struct serial_ops *serial_interface_lookup (const char *);
|
2011-01-05 23:22:53 +01:00
|
|
|
|
static void serial_logchar (struct ui_file *stream,
|
|
|
|
|
int ch_type, int ch, int timeout);
|
2000-06-08 02:52:56 +02:00
|
|
|
|
static const char logbase_hex[] = "hex";
|
|
|
|
|
static const char logbase_octal[] = "octal";
|
|
|
|
|
static const char logbase_ascii[] = "ascii";
|
2012-01-28 19:08:22 +01:00
|
|
|
|
static const char *const logbase_enums[] =
|
1999-07-07 22:19:36 +02:00
|
|
|
|
{logbase_hex, logbase_octal, logbase_ascii, NULL};
|
2000-06-08 02:52:56 +02:00
|
|
|
|
static const char *serial_logbase = logbase_ascii;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
|
static int serial_current_type = 0;
|
|
|
|
|
|
2011-01-11 22:53:25 +01:00
|
|
|
|
/* Log char CH of type CHTYPE, with TIMEOUT. */
|
1999-04-16 03:35:26 +02: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 01:21:19 +01:00
|
|
|
|
serial_logchar (struct ui_file *stream, int ch_type, int ch, int timeout)
|
1999-04-16 03:35:26 +02:00
|
|
|
|
{
|
|
|
|
|
if (ch_type != serial_current_type)
|
|
|
|
|
{
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fprintf_unfiltered (stream, "\n%c ", ch_type);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
serial_current_type = ch_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (serial_logbase != logbase_ascii)
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fputc_unfiltered (' ', stream);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
|
|
switch (ch)
|
|
|
|
|
{
|
|
|
|
|
case SERIAL_TIMEOUT:
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fprintf_unfiltered (stream, "<Timeout: %d seconds>", timeout);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
return;
|
|
|
|
|
case SERIAL_ERROR:
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fprintf_unfiltered (stream, "<Error: %s>", safe_strerror (errno));
|
1999-04-16 03:35:26 +02:00
|
|
|
|
return;
|
|
|
|
|
case SERIAL_EOF:
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fputs_unfiltered ("<Eof>", stream);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
return;
|
|
|
|
|
case SERIAL_BREAK:
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fputs_unfiltered ("<Break>", stream);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
if (serial_logbase == logbase_hex)
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fprintf_unfiltered (stream, "%02x", ch & 0xff);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
else if (serial_logbase == logbase_octal)
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fprintf_unfiltered (stream, "%03o", ch & 0xff);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
else
|
|
|
|
|
switch (ch)
|
|
|
|
|
{
|
1999-07-07 22:19:36 +02:00
|
|
|
|
case '\\':
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fputs_unfiltered ("\\\\", stream);
|
1999-07-07 22:19:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case '\b':
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fputs_unfiltered ("\\b", stream);
|
1999-07-07 22:19:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case '\f':
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fputs_unfiltered ("\\f", stream);
|
1999-07-07 22:19:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case '\n':
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fputs_unfiltered ("\\n", stream);
|
1999-07-07 22:19:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case '\r':
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fputs_unfiltered ("\\r", stream);
|
1999-07-07 22:19:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case '\t':
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fputs_unfiltered ("\\t", stream);
|
1999-07-07 22:19:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case '\v':
|
1999-10-06 01:13:56 +02:00
|
|
|
|
fputs_unfiltered ("\\v", stream);
|
1999-07-07 22:19:36 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2011-01-05 23:22:53 +01:00
|
|
|
|
fprintf_unfiltered (stream,
|
|
|
|
|
isprint (ch) ? "%c" : "\\x%02x", ch & 0xFF);
|
1999-07-07 22:19:36 +02:00
|
|
|
|
break;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-12-18 05:35:13 +01:00
|
|
|
|
serial_log_command (struct target_ops *self, const char *cmd)
|
1999-04-16 03:35:26 +02: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 22:53:25 +01:00
|
|
|
|
in case we are getting ready to dump core or something. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
gdb_flush (serial_logfp);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 05:28:34 +02:00
|
|
|
|
|
2013-12-06 18:58:50 +01:00
|
|
|
|
static const struct serial_ops *
|
2010-08-20 20:49:20 +02:00
|
|
|
|
serial_interface_lookup (const char *name)
|
1999-04-16 03:35:26 +02:00
|
|
|
|
{
|
2013-12-06 18:58:50 +01:00
|
|
|
|
const struct serial_ops *ops;
|
|
|
|
|
int i;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
2013-12-06 18:58:50 +01:00
|
|
|
|
for (i = 0; VEC_iterate (serial_ops_p, serial_ops_list, i, ops); ++i)
|
1999-04-16 03:35:26 +02:00
|
|
|
|
if (strcmp (name, ops->name) == 0)
|
|
|
|
|
return ops;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-12-06 18:58:50 +01:00
|
|
|
|
serial_add_interface (const struct serial_ops *optable)
|
1999-04-16 03:35:26 +02:00
|
|
|
|
{
|
2013-12-06 18:58:50 +01:00
|
|
|
|
VEC_safe_push (serial_ops_p, serial_ops_list, optable);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 13:06:52 +02: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 22:53:25 +01:00
|
|
|
|
/* Open up a device or a network socket, depending upon the syntax of NAME. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
2001-07-11 19:52:32 +02:00
|
|
|
|
struct serial *
|
1999-09-22 05:28:34 +02:00
|
|
|
|
serial_open (const char *name)
|
1999-04-16 03:35:26 +02:00
|
|
|
|
{
|
2001-07-11 19:52:32 +02:00
|
|
|
|
struct serial *scb;
|
2013-12-06 18:58:50 +01:00
|
|
|
|
const struct serial_ops *ops;
|
1999-09-22 05:28:34 +02:00
|
|
|
|
const char *open_name = name;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
2002-02-24 04:59:50 +01:00
|
|
|
|
if (strcmp (name, "pc") == 0)
|
1999-04-16 03:35:26 +02:00
|
|
|
|
ops = serial_interface_lookup ("pc");
|
|
|
|
|
else if (strncmp (name, "lpt", 3) == 0)
|
|
|
|
|
ops = serial_interface_lookup ("parallel");
|
1999-07-12 13:15:22 +02:00
|
|
|
|
else if (strncmp (name, "|", 1) == 0)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
ops = serial_interface_lookup ("pipe");
|
2006-11-04 09:37:24 +01:00
|
|
|
|
/* Discard ``|'' and any space before the command itself. */
|
|
|
|
|
++open_name;
|
2013-03-07 22:57:30 +01:00
|
|
|
|
open_name = skip_spaces_const (open_name);
|
1999-09-22 05:28:34 +02:00
|
|
|
|
}
|
2006-04-11 22:33:12 +02: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 03:35:26 +02:00
|
|
|
|
else
|
|
|
|
|
ops = serial_interface_lookup ("hardwire");
|
|
|
|
|
|
|
|
|
|
if (!ops)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2013-12-28 23:31:23 +01:00
|
|
|
|
scb = XNEW (struct serial);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
|
|
scb->ops = ops;
|
|
|
|
|
|
|
|
|
|
scb->bufcnt = 0;
|
|
|
|
|
scb->bufp = scb->buf;
|
2007-04-08 17:20:07 +02:00
|
|
|
|
scb->error_fd = -1;
|
2012-06-11 22:36:53 +02:00
|
|
|
|
scb->refcnt = 1;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
2011-02-27 17:25:38 +01:00
|
|
|
|
/* `...->open (...)' would get expanded by the open(2) syscall macro. */
|
2007-08-09 00:12:35 +02:00
|
|
|
|
if ((*scb->ops->open) (scb, open_name))
|
1999-04-16 03:35:26 +02:00
|
|
|
|
{
|
2000-12-15 02:01:51 +01:00
|
|
|
|
xfree (scb);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-31 02:24:03 +01:00
|
|
|
|
scb->name = xstrdup (name);
|
2012-06-13 13:06:52 +02:00
|
|
|
|
scb->next = scb_base;
|
1999-10-06 01:13:56 +02:00
|
|
|
|
scb->debug_p = 0;
|
|
|
|
|
scb->async_state = 0;
|
1999-09-22 05:28:34 +02:00
|
|
|
|
scb->async_handler = NULL;
|
|
|
|
|
scb->async_context = NULL;
|
2012-06-13 13:06:52 +02:00
|
|
|
|
scb_base = scb;
|
1999-04-16 03:35:26 +02: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 20:49:20 +02:00
|
|
|
|
/* Open a new serial stream using a file handle, using serial
|
|
|
|
|
interface ops OPS. */
|
|
|
|
|
|
|
|
|
|
static struct serial *
|
2013-12-06 18:58:50 +01:00
|
|
|
|
serial_fdopen_ops (const int fd, const struct serial_ops *ops)
|
1999-04-16 03:35:26 +02:00
|
|
|
|
{
|
2001-07-11 19:52:32 +02:00
|
|
|
|
struct serial *scb;
|
1999-04-16 03:35:26 +02: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 23:01:43 +01:00
|
|
|
|
if (!ops)
|
2010-08-20 20:49:20 +02:00
|
|
|
|
{
|
|
|
|
|
ops = serial_interface_lookup ("terminal");
|
|
|
|
|
if (!ops)
|
|
|
|
|
ops = serial_interface_lookup ("hardwire");
|
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
|
|
if (!ops)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
replace XCALLOC with XCNEWVEC or XCNEW
This removes XCALLOC and replaces it either with XCNEWVEC, or, if the
number of elements being requested was 1, with XCNEW.
2014-01-13 Tom Tromey <tromey@redhat.com>
* defs.h (XCALLOC): Remove.
* bcache.c (bcache_xmalloc): Use XCNEW, not XCALLOC.
(print_bcache_statistics): Use XCNEWVEC, not XCALLOC.
* dwarf2loc.c (allocate_piece_closure): Likewise.
* elfread.c (elf_symfile_segments): Likewise.
(elf_symfile_segments): Likewise.
* gdbtypes.c (copy_type_recursive): Likewise.
* i386-tdep.c (i386_gdbarch_init): Use XCNEW, not XCALLOC.
* jit.c (jit_frame_sniffer): Use XCNEWVEC, not XCALLOC.
* minsyms.c (prim_record_minimal_symbol_full): Use XCNEW, not
XCALLOC.
* mt-tdep.c (mt_gdbarch_init): Likewise.
* opencl-lang.c (allocate_lval_closure): Use XCNEWVEC, not
XCALLOC.
* psymtab.c (psymbol_compare): Use XCNEW, not XCALLOC.
* regcache.c (regcache_xmalloc_1): Use XCNEWVEC, not XCALLOC.
* registry.c (registry_alloc_data): Likewise.
* rs6000-tdep.c (rs6000_gdbarch_init): Use XCNEW, not XCALLOC.
* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
* serial.c (serial_fdopen_ops): Likewise.
* solib-aix.c (solib_aix_get_section_offsets): Use XCNEWVEC, not
XCALLOC.
* spu-tdep.c (spu_gdbarch_init): Use XCNEW, not XCALLOC.
* symfile.c (default_symfile_segments): Use XCNEW and XCNEWVEC,
not XCALLOC.
2013-12-28 23:32:27 +01:00
|
|
|
|
scb = XCNEW (struct serial);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
|
|
scb->ops = ops;
|
|
|
|
|
|
|
|
|
|
scb->bufcnt = 0;
|
|
|
|
|
scb->bufp = scb->buf;
|
2010-08-20 20:49:20 +02:00
|
|
|
|
scb->error_fd = -1;
|
2012-06-11 22:36:53 +02:00
|
|
|
|
scb->refcnt = 1;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
|
|
scb->name = NULL;
|
2012-06-13 13:06:52 +02:00
|
|
|
|
scb->next = scb_base;
|
1999-10-06 01:13:56 +02:00
|
|
|
|
scb->debug_p = 0;
|
|
|
|
|
scb->async_state = 0;
|
1999-09-22 05:28:34 +02:00
|
|
|
|
scb->async_handler = NULL;
|
|
|
|
|
scb->async_context = NULL;
|
2012-06-13 13:06:52 +02:00
|
|
|
|
scb_base = scb;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
2010-08-20 20:49:20 +02:00
|
|
|
|
if ((ops->fdopen) != NULL)
|
|
|
|
|
(*ops->fdopen) (scb, fd);
|
|
|
|
|
else
|
|
|
|
|
scb->fd = fd;
|
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
|
return scb;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-20 20:49:20 +02:00
|
|
|
|
struct serial *
|
|
|
|
|
serial_fdopen (const int fd)
|
|
|
|
|
{
|
|
|
|
|
return serial_fdopen_ops (fd, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 05:28:34 +02:00
|
|
|
|
static void
|
2001-07-11 19:52:32 +02:00
|
|
|
|
do_serial_close (struct serial *scb, int really_close)
|
1999-04-16 03:35:26 +02:00
|
|
|
|
{
|
2001-07-11 19:52:32 +02:00
|
|
|
|
struct serial *tmp_scb;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
|
|
if (serial_logfp)
|
|
|
|
|
{
|
|
|
|
|
fputs_unfiltered ("\nEnd of log\n", serial_logfp);
|
|
|
|
|
serial_current_type = 0;
|
|
|
|
|
|
2011-01-11 22:53:25 +01:00
|
|
|
|
/* XXX - What if serial_logfp == gdb_stdout or gdb_stderr? */
|
2000-02-02 01:21:19 +01:00
|
|
|
|
ui_file_delete (serial_logfp);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
serial_logfp = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-11 22:53:25 +01:00
|
|
|
|
/* ensure that the FD has been taken out of async mode. */
|
1999-09-22 05:28:34 +02:00
|
|
|
|
if (scb->async_handler != NULL)
|
|
|
|
|
serial_async (scb, NULL, NULL);
|
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
|
if (really_close)
|
|
|
|
|
scb->ops->close (scb);
|
|
|
|
|
|
|
|
|
|
if (scb->name)
|
2000-12-15 02:01:51 +01:00
|
|
|
|
xfree (scb->name);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
2012-06-11 22:36:53 +02:00
|
|
|
|
/* For serial_is_open. */
|
|
|
|
|
scb->bufp = NULL;
|
|
|
|
|
|
2012-06-13 13:06:52 +02: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 22:36:53 +02:00
|
|
|
|
serial_unref (scb);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 05:28:34 +02:00
|
|
|
|
void
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_close (struct serial *scb)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
do_serial_close (scb, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_un_fdopen (struct serial *scb)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
do_serial_close (scb, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-11 22:36:53 +02: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 05:28:34 +02:00
|
|
|
|
int
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_readchar (struct serial *scb, int timeout)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
int ch;
|
|
|
|
|
|
1999-10-12 06:37:53 +02:00
|
|
|
|
/* FIXME: cagney/1999-10-11: Don't enable this check until the ASYNC
|
2011-01-11 22:53:25 +01:00
|
|
|
|
code is finished. */
|
2001-07-15 22:34:14 +02:00
|
|
|
|
if (0 && serial_is_async_p (scb) && timeout < 0)
|
2001-02-08 07:03:54 +01: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 19:13:55 +01:00
|
|
|
|
_("serial_readchar: blocking read in async mode"));
|
1999-10-12 06:37:53 +02:00
|
|
|
|
|
1999-09-22 05:28:34 +02:00
|
|
|
|
ch = scb->ops->readchar (scb, timeout);
|
|
|
|
|
if (serial_logfp != NULL)
|
|
|
|
|
{
|
1999-10-06 01:13:56 +02:00
|
|
|
|
serial_logchar (serial_logfp, 'r', ch, timeout);
|
1999-09-22 05:28:34 +02:00
|
|
|
|
|
|
|
|
|
/* Make sure that the log file is as up-to-date as possible,
|
2011-01-11 22:53:25 +01:00
|
|
|
|
in case we are getting ready to dump core or something. */
|
1999-09-22 05:28:34 +02:00
|
|
|
|
gdb_flush (serial_logfp);
|
|
|
|
|
}
|
2001-07-15 22:34:14 +02:00
|
|
|
|
if (serial_debug_p (scb))
|
1999-10-06 01:13:56 +02:00
|
|
|
|
{
|
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "[");
|
|
|
|
|
serial_logchar (gdb_stdlog, 'r', ch, timeout);
|
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "]");
|
|
|
|
|
gdb_flush (gdb_stdlog);
|
|
|
|
|
}
|
1999-09-22 05:28:34 +02: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 17:26:17 +02:00
|
|
|
|
serial_write (struct serial *scb, const void *buf, size_t count)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
if (serial_logfp != NULL)
|
|
|
|
|
{
|
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 17:26:17 +02:00
|
|
|
|
const char *str = buf;
|
|
|
|
|
size_t c;
|
1999-09-22 05:28:34 +02: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 17:26:17 +02:00
|
|
|
|
for (c = 0; c < count; c++)
|
|
|
|
|
serial_logchar (serial_logfp, 'w', str[c] & 0xff, 0);
|
1999-09-22 05:28:34 +02:00
|
|
|
|
|
|
|
|
|
/* Make sure that the log file is as up-to-date as possible,
|
2011-01-11 22:53:25 +01:00
|
|
|
|
in case we are getting ready to dump core or something. */
|
1999-09-22 05:28:34 +02:00
|
|
|
|
gdb_flush (serial_logfp);
|
|
|
|
|
}
|
2010-04-26 23:45:50 +02:00
|
|
|
|
if (serial_debug_p (scb))
|
|
|
|
|
{
|
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 17:26:17 +02:00
|
|
|
|
const char *str = buf;
|
|
|
|
|
size_t c;
|
2010-04-26 23:45:50 +02: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 17:26:17 +02:00
|
|
|
|
for (c = 0; c < count; c++)
|
2010-04-26 23:45:50 +02:00
|
|
|
|
{
|
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "[");
|
2014-06-06 17:28:27 +02:00
|
|
|
|
serial_logchar (gdb_stdlog, 'w', str[c] & 0xff, 0);
|
2010-04-26 23:45:50 +02:00
|
|
|
|
fprintf_unfiltered (gdb_stdlog, "]");
|
|
|
|
|
}
|
|
|
|
|
gdb_flush (gdb_stdlog);
|
|
|
|
|
}
|
1999-09-22 05:28:34 +02: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 17:26:17 +02:00
|
|
|
|
return (scb->ops->write (scb, buf, count));
|
1999-09-22 05:28:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_printf (struct serial *desc, const char *format,...)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
char *buf;
|
|
|
|
|
va_start (args, format);
|
|
|
|
|
|
2004-06-29 16:57:39 +02:00
|
|
|
|
buf = xstrvprintf (format, args);
|
2001-07-15 22:34:14 +02:00
|
|
|
|
serial_write (desc, buf, strlen (buf));
|
1999-09-22 05:28:34 +02:00
|
|
|
|
|
2000-12-15 02:01:51 +01:00
|
|
|
|
xfree (buf);
|
1999-09-22 05:28:34 +02:00
|
|
|
|
va_end (args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_drain_output (struct serial *scb)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->drain_output (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_flush_output (struct serial *scb)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->flush_output (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_flush_input (struct serial *scb)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->flush_input (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_send_break (struct serial *scb)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
if (serial_logfp != NULL)
|
1999-10-06 01:13:56 +02:00
|
|
|
|
serial_logchar (serial_logfp, 'w', SERIAL_BREAK, 0);
|
1999-09-22 05:28:34 +02:00
|
|
|
|
|
|
|
|
|
return (scb->ops->send_break (scb));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_raw (struct serial *scb)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
scb->ops->go_raw (scb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serial_ttystate
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_get_tty_state (struct serial *scb)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->get_tty_state (scb);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-04 20:23:42 +01:00
|
|
|
|
serial_ttystate
|
|
|
|
|
serial_copy_tty_state (struct serial *scb, serial_ttystate ttystate)
|
|
|
|
|
{
|
|
|
|
|
return scb->ops->copy_tty_state (scb, ttystate);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-22 05:28:34 +02:00
|
|
|
|
int
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_set_tty_state (struct serial *scb, serial_ttystate ttystate)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->set_tty_state (scb, ttystate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_print_tty_state (struct serial *scb,
|
1999-09-22 05:28:34 +02:00
|
|
|
|
serial_ttystate ttystate,
|
2000-02-02 01:21:19 +01:00
|
|
|
|
struct ui_file *stream)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
scb->ops->print_tty_state (scb, ttystate, stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_noflush_set_tty_state (struct serial *scb,
|
1999-09-22 05:28:34 +02: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 19:52:32 +02:00
|
|
|
|
serial_setbaudrate (struct serial *scb, int rate)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->setbaudrate (scb, rate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_setstopbits (struct serial *scb, int num)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
return scb->ops->setstopbits (scb, num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_can_async_p (struct serial *scb)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
return (scb->ops->async != NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_is_async_p (struct serial *scb)
|
1999-09-22 05:28:34 +02:00
|
|
|
|
{
|
|
|
|
|
return (scb->ops->async != NULL) && (scb->async_handler != NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_async (struct serial *scb,
|
1999-09-22 05:28:34 +02:00
|
|
|
|
serial_event_ftype *handler,
|
|
|
|
|
void *context)
|
|
|
|
|
{
|
2008-02-23 21:04:20 +01:00
|
|
|
|
int changed = ((scb->async_handler == NULL) != (handler == NULL));
|
2010-05-17 01:49:58 +02:00
|
|
|
|
|
1999-09-22 05:28:34 +02:00
|
|
|
|
scb->async_handler = handler;
|
|
|
|
|
scb->async_context = context;
|
2008-02-23 21:04:20 +01:00
|
|
|
|
/* Only change mode if there is a need. */
|
|
|
|
|
if (changed)
|
|
|
|
|
scb->ops->async (scb, handler != NULL);
|
1999-09-22 05:28:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-06 01:13:56 +02:00
|
|
|
|
void
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_debug (struct serial *scb, int debug_p)
|
1999-10-06 01:13:56 +02:00
|
|
|
|
{
|
|
|
|
|
scb->debug_p = debug_p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-07-11 19:52:32 +02:00
|
|
|
|
serial_debug_p (struct serial *scb)
|
1999-10-06 01:13:56 +02: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 23:01:43 +01: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 23:00:13 +02: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 23:01:43 +01:00
|
|
|
|
#endif
|
1999-10-06 01:13:56 +02:00
|
|
|
|
|
2010-08-20 20:49:20 +02:00
|
|
|
|
int
|
|
|
|
|
serial_pipe (struct serial *scbs[2])
|
|
|
|
|
{
|
2013-12-06 18:58:50 +01:00
|
|
|
|
const struct serial_ops *ops;
|
2010-08-20 20:49:20 +02: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 01:27:39 +02: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 23:22:53 +01: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 16:25:00 +02:00
|
|
|
|
help_list (serial_set_cmdlist, "set serial ", all_commands, gdb_stdout);
|
2001-09-27 01:27:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
serial_show_cmd (char *args, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
cmd_show_list (serial_show_cmdlist, from_tty, "");
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 07:50:20 +02: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 01:27:39 +02:00
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
|
void
|
1999-09-22 05:28:34 +02:00
|
|
|
|
_initialize_serial (void)
|
1999-04-16 03:35:26 +02: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 16:49:28 +01: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 03:35:26 +02: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 16:49:28 +01:00
|
|
|
|
add_prefix_cmd ("serial", class_maintenance, serial_set_cmd, _("\
|
|
|
|
|
Set default serial/parallel port configuration."),
|
2001-09-27 01:27:39 +02: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 16:49:28 +01:00
|
|
|
|
add_prefix_cmd ("serial", class_maintenance, serial_show_cmd, _("\
|
|
|
|
|
Show default serial/parallel port configuration."),
|
2001-09-27 01:27:39 +02:00
|
|
|
|
&serial_show_cmdlist, "show serial ",
|
|
|
|
|
0/*allow-unknown*/,
|
|
|
|
|
&showlist);
|
|
|
|
|
|
2013-10-10 07:50:20 +02: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);
|
|
|
|
|
|
2005-02-17 18:11:04 +01: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 03:35:26 +02:00
|
|
|
|
This file is used to record the remote session for future playback\n\
|
2005-02-17 18:11:04 +01:00
|
|
|
|
by gdbserver."),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL, /* FIXME: i18n: */
|
|
|
|
|
&setlist, &showlist);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
2005-02-21 05:31:59 +01: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 01:13:56 +02:00
|
|
|
|
|
2012-08-02 11:36:40 +02: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 19:58:56 +01:00
|
|
|
|
Set serial debugging."), _("\
|
|
|
|
|
Show serial debugging."), _("\
|
|
|
|
|
When non-zero, serial port debugging is enabled."),
|
2012-08-02 11:36:40 +02:00
|
|
|
|
NULL,
|
|
|
|
|
NULL, /* FIXME: i18n: */
|
|
|
|
|
&setdebuglist, &showdebuglist);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
}
|