aboutsummaryrefslogtreecommitdiff
path: root/gdb/ser-mingw.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2023-02-08 15:36:23 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2023-02-08 15:46:02 -0500
commitc583a2520616c2736cffc389c89a48b159366e6c (patch)
treeb4925f26506fcee96c16119431c01760f05db95d /gdb/ser-mingw.c
parentca7f92c2f15b86b09c4a8ad14806bef666308d31 (diff)
downloadbinutils-users/simark/clang-format.zip
binutils-users/simark/clang-format.tar.gz
binutils-users/simark/clang-format.tar.bz2
Run clang-format.shusers/simark/clang-format
Change-Id: Ia948cc26d534b0dd02702244d52434b1a2093968
Diffstat (limited to 'gdb/ser-mingw.c')
-rw-r--r--gdb/ser-mingw.c293
1 files changed, 128 insertions, 165 deletions
diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index 7de55f6..95b5848 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -55,8 +55,8 @@ ser_windows_open (struct serial *scb, const char *name)
struct ser_windows_state *state;
COMMTIMEOUTS timeouts;
- h = CreateFile (name, GENERIC_READ | GENERIC_WRITE, 0, NULL,
- OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
+ h = CreateFile (name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
+ FILE_FLAG_OVERLAPPED, NULL);
if (h == INVALID_HANDLE_VALUE)
{
errno = ENOENT;
@@ -163,7 +163,7 @@ ser_windows_raw (struct serial *scb)
state.ByteSize = 8;
if (SetCommState (h, &state) == 0)
- warning (_("SetCommState failed"));
+ warning (_ ("SetCommState failed"));
}
static int
@@ -289,10 +289,10 @@ ser_windows_wait_handle (struct serial *scb, HANDLE *read, HANDLE *except)
cleared, and we get a duplicated event, if the last batch
of characters included at least two arriving close together. */
if (!SetCommMask (h, 0))
- warning (_("ser_windows_wait_handle: reseting mask failed"));
+ warning (_ ("ser_windows_wait_handle: reseting mask failed"));
if (!SetCommMask (h, EV_RXCHAR))
- warning (_("ser_windows_wait_handle: reseting mask failed (2)"));
+ warning (_ ("ser_windows_wait_handle: reseting mask failed (2)"));
/* There's a potential race condition here; we must check cbInQue
and not wait if that's nonzero. */
@@ -384,7 +384,8 @@ ser_windows_write_prim (struct serial *scb, const void *buf, size_t len)
wait_handle_done functions, which return the threads to the stopped
state. */
-enum select_thread_state {
+enum select_thread_state
+{
STS_STARTED,
STS_STOPPED
};
@@ -436,24 +437,23 @@ select_thread_wait (struct ser_console_state *state)
the started state, or that we exit this thread. */
wait_events[0] = state->start_select;
wait_events[1] = state->exit_select;
- if (WaitForMultipleObjects (2, wait_events, FALSE, INFINITE)
+ if (WaitForMultipleObjects (2, wait_events, FALSE, INFINITE)
!= WAIT_OBJECT_0)
/* Either the EXIT_SELECT event was signaled (requesting that the
thread exit) or an error has occurred. In either case, we exit
the thread. */
ExitThread (0);
-
+
/* We are now in the started state. */
SetEvent (state->have_started);
}
-typedef DWORD WINAPI (*thread_fn_type)(void *);
+typedef DWORD WINAPI (*thread_fn_type) (void *);
/* Create a new select thread for SCB executing THREAD_FN. The STATE
will be filled in by this function before return. */
static void
-create_select_thread (thread_fn_type thread_fn,
- struct serial *scb,
+create_select_thread (thread_fn_type thread_fn, struct serial *scb,
struct ser_console_state *state)
{
DWORD threadId;
@@ -548,8 +548,8 @@ console_select_thread (void *arg)
wait_events[0] = state->stop_select;
wait_events[1] = h;
- event_index = WaitForMultipleObjects (2, wait_events,
- FALSE, INFINITE);
+ event_index
+ = WaitForMultipleObjects (2, wait_events, FALSE, INFINITE);
if (event_index == WAIT_OBJECT_0
|| WaitForSingleObject (state->stop_select, 0) == WAIT_OBJECT_0)
@@ -583,16 +583,11 @@ console_select_thread (void *arg)
control key alone. */
if (record.Event.KeyEvent.uChar.AsciiChar != 0
- || keycode == VK_PRIOR
- || keycode == VK_NEXT
- || keycode == VK_END
- || keycode == VK_HOME
- || keycode == VK_LEFT
- || keycode == VK_UP
- || keycode == VK_RIGHT
- || keycode == VK_DOWN
- || keycode == VK_INSERT
- || keycode == VK_DELETE)
+ || keycode == VK_PRIOR || keycode == VK_NEXT
+ || keycode == VK_END || keycode == VK_HOME
+ || keycode == VK_LEFT || keycode == VK_UP
+ || keycode == VK_RIGHT || keycode == VK_DOWN
+ || keycode == VK_INSERT || keycode == VK_DELETE)
{
/* This is really a keypress. */
SetEvent (state->read_event);
@@ -609,7 +604,7 @@ console_select_thread (void *arg)
ReadConsoleInput (h, &record, 1, &n_records);
}
- SetEvent(state->have_stopped);
+ SetEvent (state->have_stopped);
}
return 0;
}
@@ -851,10 +846,7 @@ free_pipe_state (struct pipe_state *ps)
struct pipe_state_destroyer
{
- void operator() (pipe_state *ps) const
- {
- free_pipe_state (ps);
- }
+ void operator() (pipe_state *ps) const { free_pipe_state (ps); }
};
typedef std::unique_ptr<pipe_state, pipe_state_destroyer> pipe_state_up;
@@ -865,7 +857,7 @@ pipe_windows_open (struct serial *scb, const char *name)
FILE *pex_stderr;
if (name == NULL)
- error_no_arg (_("child command"));
+ error_no_arg (_ ("child command"));
if (*name == '|')
{
@@ -875,25 +867,24 @@ pipe_windows_open (struct serial *scb, const char *name)
gdb_argv argv (name);
- if (! argv[0] || argv[0][0] == '\0')
- error (_("missing child command"));
+ if (!argv[0] || argv[0][0] == '\0')
+ error (_ ("missing child command"));
pipe_state_up ps (make_pipe_state ());
ps->pex = pex_init (PEX_USE_PIPES, "target remote pipe", NULL);
- if (! ps->pex)
+ if (!ps->pex)
return -1;
ps->input = pex_input_pipe (ps->pex, 1);
- if (! ps->input)
+ if (!ps->input)
return -1;
{
int err;
- const char *err_msg
- = pex_run (ps->pex, PEX_SEARCH | PEX_BINARY_INPUT | PEX_BINARY_OUTPUT
- | PEX_STDERR_TO_PIPE,
- argv[0], argv.get (), NULL, NULL,
- &err);
+ const char *err_msg = pex_run (ps->pex,
+ PEX_SEARCH | PEX_BINARY_INPUT
+ | PEX_BINARY_OUTPUT | PEX_STDERR_TO_PIPE,
+ argv[0], argv.get (), NULL, NULL, &err);
if (err_msg)
{
@@ -902,21 +893,20 @@ pipe_windows_open (struct serial *scb, const char *name)
all the same information here, plus err_msg provided by
pex_run, so we just raise the error here. */
if (err)
- error (_("error starting child process '%s': %s: %s"),
- name, err_msg, safe_strerror (err));
+ error (_ ("error starting child process '%s': %s: %s"), name,
+ err_msg, safe_strerror (err));
else
- error (_("error starting child process '%s': %s"),
- name, err_msg);
+ error (_ ("error starting child process '%s': %s"), name, err_msg);
}
}
ps->output = pex_read_output (ps->pex, 1);
- if (! ps->output)
+ if (!ps->output)
return -1;
scb->fd = fileno (ps->output);
pex_stderr = pex_read_err (ps->pex, 1);
- if (! pex_stderr)
+ if (!pex_stderr)
return -1;
scb->error_fd = fileno (pex_stderr);
@@ -933,11 +923,11 @@ pipe_windows_fdopen (struct serial *scb, int fd)
ps = make_pipe_state ();
ps->input = fdopen (fd, "r+");
- if (! ps->input)
+ if (!ps->input)
goto fail;
ps->output = fdopen (fd, "r+");
- if (! ps->output)
+ if (!ps->output)
goto fail;
scb->fd = fd;
@@ -945,7 +935,7 @@ pipe_windows_fdopen (struct serial *scb, int fd)
return 0;
- fail:
+fail:
free_pipe_state (ps);
return -1;
}
@@ -962,7 +952,6 @@ pipe_windows_close (struct serial *scb)
free_pipe_state (ps);
}
-
static int
pipe_windows_read (struct serial *scb, size_t count)
{
@@ -973,19 +962,18 @@ pipe_windows_read (struct serial *scb, size_t count)
if (pipeline_out == INVALID_HANDLE_VALUE)
return -1;
- if (! PeekNamedPipe (pipeline_out, NULL, 0, NULL, &available, NULL))
+ if (!PeekNamedPipe (pipeline_out, NULL, 0, NULL, &available, NULL))
return -1;
if (count > available)
count = available;
- if (! ReadFile (pipeline_out, scb->buf, count, &bytes_read, NULL))
+ if (!ReadFile (pipeline_out, scb->buf, count, &bytes_read, NULL))
return -1;
return bytes_read;
}
-
static int
pipe_windows_write (struct serial *scb, const void *buf, size_t count)
{
@@ -1001,13 +989,12 @@ pipe_windows_write (struct serial *scb, const void *buf, size_t count)
if (pipeline_in == INVALID_HANDLE_VALUE)
return -1;
- if (! WriteFile (pipeline_in, buf, count, &written, NULL))
+ if (!WriteFile (pipeline_in, buf, count, &written, NULL))
return -1;
return written;
}
-
static void
pipe_wait_handle (struct serial *scb, HANDLE *read, HANDLE *except)
{
@@ -1064,7 +1051,7 @@ gdb_pipe (int pdes[2])
struct net_windows_state
{
struct ser_console_state base;
-
+
HANDLE sock_event;
};
@@ -1116,10 +1103,12 @@ net_windows_select_thread (void *arg)
/* Wait for something to happen on the socket. */
while (1)
{
- event_index = WaitForMultipleObjects (2, wait_events, FALSE, INFINITE);
+ event_index
+ = WaitForMultipleObjects (2, wait_events, FALSE, INFINITE);
if (event_index == WAIT_OBJECT_0
- || WaitForSingleObject (state->base.stop_select, 0) == WAIT_OBJECT_0)
+ || WaitForSingleObject (state->base.stop_select, 0)
+ == WAIT_OBJECT_0)
{
/* We have been requested to stop. */
break;
@@ -1213,7 +1202,6 @@ net_windows_open (struct serial *scb, const char *name)
return 0;
}
-
static void
net_windows_close (struct serial *scb)
{
@@ -1229,127 +1217,102 @@ net_windows_close (struct serial *scb)
/* The serial port driver. */
-static const struct serial_ops hardwire_ops =
-{
- "hardwire",
- ser_windows_open,
- ser_windows_close,
- NULL,
- ser_base_readchar,
- ser_base_write,
- ser_windows_flush_output,
- ser_windows_flush_input,
- ser_windows_send_break,
- ser_windows_raw,
- /* These are only used for stdin; we do not need them for serial
+static const struct serial_ops hardwire_ops
+ = { "hardwire", ser_windows_open, ser_windows_close, NULL, ser_base_readchar,
+ ser_base_write, ser_windows_flush_output, ser_windows_flush_input,
+ ser_windows_send_break, ser_windows_raw,
+ /* These are only used for stdin; we do not need them for serial
ports, so supply the standard dummies. */
- ser_base_get_tty_state,
- ser_base_copy_tty_state,
- ser_base_set_tty_state,
- ser_base_print_tty_state,
- ser_windows_setbaudrate,
- ser_windows_setstopbits,
- ser_windows_setparity,
- ser_windows_drain_output,
- ser_base_async,
- ser_windows_read_prim,
- ser_windows_write_prim,
- NULL,
- ser_windows_wait_handle
-};
+ ser_base_get_tty_state, ser_base_copy_tty_state, ser_base_set_tty_state,
+ ser_base_print_tty_state, ser_windows_setbaudrate,
+ ser_windows_setstopbits, ser_windows_setparity, ser_windows_drain_output,
+ ser_base_async, ser_windows_read_prim, ser_windows_write_prim, NULL,
+ ser_windows_wait_handle };
/* The dummy serial driver used for terminals. We only provide the
TTY-related methods. */
-static const struct serial_ops tty_ops =
-{
- "terminal",
- NULL,
- ser_console_close,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- ser_console_get_tty_state,
- ser_base_copy_tty_state,
- ser_base_set_tty_state,
- ser_base_print_tty_state,
- NULL,
- NULL,
- NULL,
- ser_base_drain_output,
- NULL,
- NULL,
- NULL,
- NULL,
- ser_console_wait_handle,
- ser_console_done_wait_handle
-};
+static const struct serial_ops tty_ops = { "terminal",
+ NULL,
+ ser_console_close,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ ser_console_get_tty_state,
+ ser_base_copy_tty_state,
+ ser_base_set_tty_state,
+ ser_base_print_tty_state,
+ NULL,
+ NULL,
+ NULL,
+ ser_base_drain_output,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ ser_console_wait_handle,
+ ser_console_done_wait_handle };
/* The pipe interface. */
-static const struct serial_ops pipe_ops =
-{
- "pipe",
- pipe_windows_open,
- pipe_windows_close,
- pipe_windows_fdopen,
- ser_base_readchar,
- ser_base_write,
- ser_base_flush_output,
- ser_base_flush_input,
- ser_base_send_break,
- ser_base_raw,
- ser_base_get_tty_state,
- ser_base_copy_tty_state,
- ser_base_set_tty_state,
- ser_base_print_tty_state,
- ser_base_setbaudrate,
- ser_base_setstopbits,
- ser_base_setparity,
- ser_base_drain_output,
- ser_base_async,
- pipe_windows_read,
- pipe_windows_write,
- pipe_avail,
- pipe_wait_handle,
- pipe_done_wait_handle
-};
+static const struct serial_ops pipe_ops = { "pipe",
+ pipe_windows_open,
+ pipe_windows_close,
+ pipe_windows_fdopen,
+ ser_base_readchar,
+ ser_base_write,
+ ser_base_flush_output,
+ ser_base_flush_input,
+ ser_base_send_break,
+ ser_base_raw,
+ ser_base_get_tty_state,
+ ser_base_copy_tty_state,
+ ser_base_set_tty_state,
+ ser_base_print_tty_state,
+ ser_base_setbaudrate,
+ ser_base_setstopbits,
+ ser_base_setparity,
+ ser_base_drain_output,
+ ser_base_async,
+ pipe_windows_read,
+ pipe_windows_write,
+ pipe_avail,
+ pipe_wait_handle,
+ pipe_done_wait_handle };
/* The TCP/UDP socket driver. */
-static const struct serial_ops tcp_ops =
-{
- "tcp",
- net_windows_open,
- net_windows_close,
- NULL,
- ser_base_readchar,
- ser_base_write,
- ser_base_flush_output,
- ser_base_flush_input,
- ser_tcp_send_break,
- ser_base_raw,
- ser_base_get_tty_state,
- ser_base_copy_tty_state,
- ser_base_set_tty_state,
- ser_base_print_tty_state,
- ser_base_setbaudrate,
- ser_base_setstopbits,
- ser_base_setparity,
- ser_base_drain_output,
- ser_base_async,
- net_read_prim,
- net_write_prim,
- NULL,
- net_windows_wait_handle,
- net_windows_done_wait_handle
-};
+static const struct serial_ops tcp_ops = { "tcp",
+ net_windows_open,
+ net_windows_close,
+ NULL,
+ ser_base_readchar,
+ ser_base_write,
+ ser_base_flush_output,
+ ser_base_flush_input,
+ ser_tcp_send_break,
+ ser_base_raw,
+ ser_base_get_tty_state,
+ ser_base_copy_tty_state,
+ ser_base_set_tty_state,
+ ser_base_print_tty_state,
+ ser_base_setbaudrate,
+ ser_base_setstopbits,
+ ser_base_setparity,
+ ser_base_drain_output,
+ ser_base_async,
+ net_read_prim,
+ net_write_prim,
+ NULL,
+ net_windows_wait_handle,
+ net_windows_done_wait_handle };
void _initialize_ser_windows ();
+
void
_initialize_ser_windows ()
{