/* Serial interface for local (hardwired) serial ports on Windows systems
- Copyright (C) 2006-2014 Free Software Foundation, Inc.
+ Copyright (C) 2006-2018 Free Software Foundation, Inc.
This file is part of GDB.
#include <unistd.h>
#include <sys/types.h>
-#include <string.h>
-
#include "command.h"
-void _initialize_ser_windows (void);
-
struct ser_windows_state
{
int in_progress;
/* CancelIo is not available for Windows 95 OS, so we need to use
LoadLibrary/GetProcAddress to avoid a startup failure. */
#define CancelIo dyn_CancelIo
-static BOOL WINAPI (*CancelIo) (HANDLE);
+typedef BOOL WINAPI (CancelIo_ftype) (HANDLE);
+static CancelIo_ftype *CancelIo;
/* Open up a real live device for serial I/O. */
return -1;
}
- state = xmalloc (sizeof (struct ser_windows_state));
- memset (state, 0, sizeof (struct ser_windows_state));
+ state = XCNEW (struct ser_windows_state);
scb->state = state;
/* Create a manual reset event to watch the input buffer. */
if (GetCommState (h, &state) == 0)
return;
- state.fParity = FALSE;
state.fOutxCtsFlow = FALSE;
state.fOutxDsrFlow = FALSE;
state.fDtrControl = DTR_CONTROL_ENABLE;
state.fNull = FALSE;
state.fAbortOnError = FALSE;
state.ByteSize = 8;
- state.Parity = NOPARITY;
-
- scb->current_timeout = 0;
if (SetCommState (h, &state) == 0)
warning (_("SetCommState failed"));
return (SetCommState (h, &state) != 0) ? 0 : -1;
}
+/* Implement the "setparity" serial_ops callback. */
+
+static int
+ser_windows_setparity (struct serial *scb, int parity)
+{
+ HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
+ DCB state;
+
+ if (GetCommState (h, &state) == 0)
+ return -1;
+
+ switch (parity)
+ {
+ case GDBPARITY_NONE:
+ state.Parity = NOPARITY;
+ state.fParity = FALSE;
+ break;
+ case GDBPARITY_ODD:
+ state.Parity = ODDPARITY;
+ state.fParity = TRUE;
+ break;
+ case GDBPARITY_EVEN:
+ state.Parity = EVENPARITY;
+ state.fParity = TRUE;
+ break;
+ default:
+ internal_warning (__FILE__, __LINE__,
+ "Incorrect parity value: %d", parity);
+ return -1;
+ }
+
+ return (SetCommState (h, &state) != 0) ? 0 : -1;
+}
+
static int
ser_windows_setbaudrate (struct serial *scb, int rate)
{
by calling close (scb->fd) below. */
if (CancelIo)
CancelIo ((HANDLE) _get_osfhandle (scb->fd));
- state = scb->state;
+ state = (struct ser_windows_state *) scb->state;
CloseHandle (state->ov.hEvent);
CloseHandle (state->except_event);
DWORD errors;
HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
- state = scb->state;
+ state = (struct ser_windows_state *) scb->state;
*except = state->except_event;
*read = state->ov.hEvent;
HANDLE h;
gdb_byte *p;
- state = scb->state;
+ state = (struct ser_windows_state *) scb->state;
if (state->in_progress)
{
WaitForSingleObject (state->ov.hEvent, INFINITE);
static DWORD WINAPI
console_select_thread (void *arg)
{
- struct serial *scb = arg;
+ struct serial *scb = (struct serial *) arg;
struct ser_console_state *state;
int event_index;
HANDLE h;
- state = scb->state;
+ state = (struct ser_console_state *) scb->state;
h = (HANDLE) _get_osfhandle (scb->fd);
while (1)
static DWORD WINAPI
pipe_select_thread (void *arg)
{
- struct serial *scb = arg;
+ struct serial *scb = (struct serial *) arg;
struct ser_console_state *state;
int event_index;
HANDLE h;
- state = scb->state;
+ state = (struct ser_console_state *) scb->state;
h = (HANDLE) _get_osfhandle (scb->fd);
while (1)
static DWORD WINAPI
file_select_thread (void *arg)
{
- struct serial *scb = arg;
+ struct serial *scb = (struct serial *) arg;
struct ser_console_state *state;
int event_index;
HANDLE h;
- state = scb->state;
+ state = (struct ser_console_state *) scb->state;
h = (HANDLE) _get_osfhandle (scb->fd);
while (1)
static void
ser_console_wait_handle (struct serial *scb, HANDLE *read, HANDLE *except)
{
- struct ser_console_state *state = scb->state;
+ struct ser_console_state *state = (struct ser_console_state *) scb->state;
if (state == NULL)
{
return;
}
- state = xmalloc (sizeof (struct ser_console_state));
- memset (state, 0, sizeof (struct ser_console_state));
+ state = XCNEW (struct ser_console_state);
scb->state = state;
if (is_tty)
static void
ser_console_done_wait_handle (struct serial *scb)
{
- struct ser_console_state *state = scb->state;
+ struct ser_console_state *state = (struct ser_console_state *) scb->state;
if (state == NULL)
return;
static void
ser_console_close (struct serial *scb)
{
- struct ser_console_state *state = scb->state;
+ struct ser_console_state *state = (struct ser_console_state *) scb->state;
if (scb->state)
{
{
struct ser_console_ttystate *state;
- state = (struct ser_console_ttystate *) xmalloc (sizeof *state);
+ state = XNEW (struct ser_console_ttystate);
state->is_a_tty = 1;
return state;
}
static struct pipe_state *
make_pipe_state (void)
{
- struct pipe_state *ps = XNEW (struct pipe_state);
+ struct pipe_state *ps = XCNEW (struct pipe_state);
- memset (ps, 0, sizeof (*ps));
ps->wait.read_event = INVALID_HANDLE_VALUE;
ps->wait.except_event = INVALID_HANDLE_VALUE;
ps->wait.start_select = INVALID_HANDLE_VALUE;
static void
cleanup_pipe_state (void *untyped)
{
- struct pipe_state *ps = untyped;
+ struct pipe_state *ps = (struct pipe_state *) untyped;
free_pipe_state (ps);
}
{
struct pipe_state *ps;
FILE *pex_stderr;
- char **argv;
struct cleanup *back_to;
if (name == NULL)
error_no_arg (_("child command"));
- argv = gdb_buildargv (name);
- back_to = make_cleanup_freeargv (argv);
+ gdb_argv argv (name);
if (! argv[0] || argv[0][0] == '\0')
error (_("missing child command"));
ps = make_pipe_state ();
- make_cleanup (cleanup_pipe_state, ps);
+ back_to = make_cleanup (cleanup_pipe_state, ps);
ps->pex = pex_init (PEX_USE_PIPES, "target remote pipe", NULL);
if (! ps->pex)
const char *err_msg
= pex_run (ps->pex, PEX_SEARCH | PEX_BINARY_INPUT | PEX_BINARY_OUTPUT
| PEX_STDERR_TO_PIPE,
- argv[0], argv, NULL, NULL,
+ argv[0], argv.get (), NULL, NULL,
&err);
if (err_msg)
scb->state = (void *) ps;
+ argv.release ();
discard_cleanups (back_to);
return 0;
static void
pipe_windows_close (struct serial *scb)
{
- struct pipe_state *ps = scb->state;
+ struct pipe_state *ps = (struct pipe_state *) scb->state;
/* In theory, we should try to kill the subprocess here, but the pex
interface doesn't give us enough information to do that. Usually
static int
pipe_windows_write (struct serial *scb, const void *buf, size_t count)
{
- struct pipe_state *ps = scb->state;
+ struct pipe_state *ps = (struct pipe_state *) scb->state;
HANDLE pipeline_in;
DWORD written;
static void
pipe_wait_handle (struct serial *scb, HANDLE *read, HANDLE *except)
{
- struct pipe_state *ps = scb->state;
+ struct pipe_state *ps = (struct pipe_state *) scb->state;
/* Have we allocated our events yet? */
if (ps->wait.read_event == INVALID_HANDLE_VALUE)
static void
pipe_done_wait_handle (struct serial *scb)
{
- struct pipe_state *ps = scb->state;
+ struct pipe_state *ps = (struct pipe_state *) scb->state;
/* Have we allocated our events yet? */
if (ps->wait.read_event == INVALID_HANDLE_VALUE)
static int
net_windows_socket_check_pending (struct serial *scb)
{
- struct net_windows_state *state = scb->state;
+ struct net_windows_state *state = (struct net_windows_state *) scb->state;
unsigned long available;
if (ioctlsocket (scb->fd, FIONREAD, &available) != 0)
static DWORD WINAPI
net_windows_select_thread (void *arg)
{
- struct serial *scb = arg;
+ struct serial *scb = (struct serial *) arg;
struct net_windows_state *state;
int event_index;
- state = scb->state;
+ state = (struct net_windows_state *) scb->state;
while (1)
{
static void
net_windows_wait_handle (struct serial *scb, HANDLE *read, HANDLE *except)
{
- struct net_windows_state *state = scb->state;
+ struct net_windows_state *state = (struct net_windows_state *) scb->state;
/* Start from a clean slate. */
ResetEvent (state->base.read_event);
static void
net_windows_done_wait_handle (struct serial *scb)
{
- struct net_windows_state *state = scb->state;
+ struct net_windows_state *state = (struct net_windows_state *) scb->state;
stop_select_thread (&state->base);
}
if (ret != 0)
return ret;
- state = xmalloc (sizeof (struct net_windows_state));
- memset (state, 0, sizeof (struct net_windows_state));
+ state = XCNEW (struct net_windows_state);
scb->state = state;
/* Associate an event with the socket. */
static void
net_windows_close (struct serial *scb)
{
- struct net_windows_state *state = scb->state;
+ struct net_windows_state *state = (struct net_windows_state *) scb->state;
destroy_select_thread (&state->base);
CloseHandle (state->sock_event);
ser_base_copy_tty_state,
ser_base_set_tty_state,
ser_base_print_tty_state,
- ser_base_noflush_set_tty_state,
ser_windows_setbaudrate,
ser_windows_setstopbits,
+ ser_windows_setparity,
ser_windows_drain_output,
ser_base_async,
ser_windows_read_prim,
ser_base_copy_tty_state,
ser_base_set_tty_state,
ser_base_print_tty_state,
- ser_base_noflush_set_tty_state,
+ NULL,
NULL,
NULL,
ser_base_drain_output,
ser_base_copy_tty_state,
ser_base_set_tty_state,
ser_base_print_tty_state,
- ser_base_noflush_set_tty_state,
ser_base_setbaudrate,
ser_base_setstopbits,
+ ser_base_setparity,
ser_base_drain_output,
ser_base_async,
pipe_windows_read,
ser_base_copy_tty_state,
ser_base_set_tty_state,
ser_base_print_tty_state,
- ser_base_noflush_set_tty_state,
ser_base_setbaudrate,
ser_base_setstopbits,
+ ser_base_setparity,
ser_base_drain_output,
ser_base_async,
net_read_prim,
hm = LoadLibrary ("kernel32.dll");
if (hm)
{
- CancelIo = (void *) GetProcAddress (hm, "CancelIo");
+ CancelIo = (CancelIo_ftype *) GetProcAddress (hm, "CancelIo");
FreeLibrary (hm);
}
else