X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fserial.c;h=a95f85e287b1a4097dcd139bae904871be930d3d;hb=73e6209faecc21516a981ed86a27b259f506098c;hp=d4435089d1ddcc132fc54e040e09f37ca6cae27c;hpb=0e58ee40a2cec3c4bf796980fb05f93540e40ec2;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/serial.c b/gdb/serial.c index d4435089d1..a95f85e287 100644 --- a/gdb/serial.c +++ b/gdb/serial.c @@ -1,6 +1,6 @@ /* Generic serial interface routines - Copyright (C) 1992-2014 Free Software Foundation, Inc. + Copyright (C) 1992-2016 Free Software Foundation, Inc. This file is part of GDB. @@ -20,7 +20,6 @@ #include "defs.h" #include #include "serial.h" -#include #include "gdbcmd.h" #include "cli/cli-utils.h" @@ -180,6 +179,27 @@ serial_for_fd (int fd) return NULL; } +/* 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); + /* Open up a device or a network socket, depending upon the syntax of NAME. */ struct serial * @@ -191,9 +211,9 @@ serial_open (const char *name) if (strcmp (name, "pc") == 0) ops = serial_interface_lookup ("pc"); - else if (strncmp (name, "lpt", 3) == 0) + else if (startswith (name, "lpt")) ops = serial_interface_lookup ("parallel"); - else if (strncmp (name, "|", 1) == 0) + else if (startswith (name, "|")) { ops = serial_interface_lookup ("pipe"); /* Discard ``|'' and any space before the command itself. */ @@ -211,14 +231,17 @@ serial_open (const char *name) if (!ops) return NULL; - scb = XNEW (struct serial); + return serial_open_ops_1 (ops, open_name); +} - scb->ops = ops; +/* Open up a serial for OPS, passing OPEN_NAME to the open method. */ - scb->bufcnt = 0; - scb->bufp = scb->buf; - scb->error_fd = -1; - scb->refcnt = 1; +static struct serial * +serial_open_ops_1 (const struct serial_ops *ops, const char *open_name) +{ + struct serial *scb; + + scb = new_serial (ops); /* `...->open (...)' would get expanded by the open(2) syscall macro. */ if ((*scb->ops->open) (scb, open_name)) @@ -227,12 +250,7 @@ serial_open (const char *name) return NULL; } - scb->name = xstrdup (name); scb->next = scb_base; - scb->debug_p = 0; - scb->async_state = 0; - scb->async_handler = NULL; - scb->async_context = NULL; scb_base = scb; if (serial_logfile != NULL) @@ -245,6 +263,14 @@ serial_open (const char *name) return scb; } +/* See serial.h. */ + +struct serial * +serial_open_ops (const struct serial_ops *ops) +{ + return serial_open_ops_1 (ops, NULL); +} + /* Open a new serial stream using a file handle, using serial interface ops OPS. */ @@ -263,21 +289,9 @@ serial_fdopen_ops (const int fd, const struct serial_ops *ops) if (!ops) return NULL; - scb = XCNEW (struct serial); - - scb->ops = ops; - - scb->bufcnt = 0; - scb->bufp = scb->buf; - scb->error_fd = -1; - scb->refcnt = 1; + scb = new_serial (ops); - scb->name = NULL; scb->next = scb_base; - scb->debug_p = 0; - scb->async_state = 0; - scb->async_handler = NULL; - scb->async_context = NULL; scb_base = scb; if ((ops->fdopen) != NULL) @@ -316,9 +330,6 @@ do_serial_close (struct serial *scb, int really_close) if (really_close) scb->ops->close (scb); - if (scb->name) - xfree (scb->name); - /* For serial_is_open. */ scb->bufp = NULL; @@ -405,7 +416,7 @@ serial_write (struct serial *scb, const void *buf, size_t count) { if (serial_logfp != NULL) { - const char *str = buf; + const char *str = (const char *) buf; size_t c; for (c = 0; c < count; c++) @@ -417,7 +428,7 @@ serial_write (struct serial *scb, const void *buf, size_t count) } if (serial_debug_p (scb)) { - const char *str = buf; + const char *str = (const char *) buf; size_t c; for (c = 0; c < count; c++) @@ -525,6 +536,14 @@ serial_setstopbits (struct serial *scb, int num) return scb->ops->setstopbits (scb, num); } +/* See serial.h. */ + +int +serial_setparity (struct serial *scb, int parity) +{ + return scb->ops->setparity (scb, parity); +} + int serial_can_async_p (struct serial *scb) { @@ -615,7 +634,7 @@ serial_set_cmd (char *args, int from_tty) { printf_unfiltered ("\"set serial\" must be followed " "by the name of a command.\n"); - help_list (serial_set_cmdlist, "set serial ", -1, gdb_stdout); + help_list (serial_set_cmdlist, "set serial ", all_commands, gdb_stdout); } static void @@ -639,6 +658,30 @@ serial_baud_show_cmd (struct ui_file *file, int from_tty, value); } +/* 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; +} + void _initialize_serial (void) { @@ -671,6 +714,14 @@ using remote targets."), serial_baud_show_cmd, &serial_set_cmdlist, &serial_show_cmdlist); + 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); + add_setshow_filename_cmd ("remotelogfile", no_class, &serial_logfile, _("\ Set filename for remote session recording."), _("\ Show filename for remote session recording."), _("\