2006-02-11 05:53:51 +08:00
|
|
|
/* Host support routines for MinGW, for GDB, the GNU debugger.
|
|
|
|
|
2024-01-12 23:30:44 +08:00
|
|
|
Copyright (C) 2006-2024 Free Software Foundation, Inc.
|
2006-02-11 05:53:51 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
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
|
2006-02-11 05:53:51 +08:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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/>. */
|
2006-02-11 05:53:51 +08:00
|
|
|
|
2013-04-06 14:52:06 +08:00
|
|
|
#include "main.h"
|
* 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
|
|
|
#include "serial.h"
|
2020-04-14 02:42:59 +08:00
|
|
|
#include "gdbsupport/event-loop.h"
|
2020-04-14 02:42:59 +08:00
|
|
|
#include "gdbsupport/gdb_select.h"
|
2022-12-06 02:15:09 +08:00
|
|
|
#include "inferior.h"
|
2006-02-11 05:53:51 +08:00
|
|
|
|
|
|
|
#include <windows.h>
|
Fix control-c handling on Windows
As Hannes pointed out, the Windows target-async patches broke C-c
handling there. Looking into this, I found a few oddities, fixed
here.
First, windows_nat_target::interrupt calls GenerateConsoleCtrlEvent.
I think this event can be ignored by the inferior, so it's not a great
way to interrupt. Instead, using DebugBreakProcess (or a more
complicated thing for Wow64) seems better.
Second, windows_nat_target did not implement the pass_ctrlc method.
Implementing this lets us remove the special code to call
SetConsoleCtrlHandler and instead integrate into gdb's approach to C-c
handling. I believe that this should also fix the race that's
described in the comment that's being removed.
Initially, I thought a simpler version of this patch would work.
However, I think what happens is that some other library (I'm not sure
what) calls SetConsoleCtrlHandler while gdb is running, and this
intercepts and handles C-c -- so that the gdb SIGINT handler is not
called. C-break continues to work, presumably because whatever
handler is installed ignores it.
This patch works around this issue by ensuring that the gdb handler
always comes first.
2022-12-06 01:56:23 +08:00
|
|
|
#include <signal.h>
|
2006-02-11 05:53:51 +08:00
|
|
|
|
2013-04-06 14:52:06 +08:00
|
|
|
/* Return an absolute file name of the running GDB, if possible, or
|
|
|
|
ARGV0 if not. The return value is in malloc'ed storage. */
|
|
|
|
|
|
|
|
char *
|
|
|
|
windows_get_absolute_argv0 (const char *argv0)
|
|
|
|
{
|
|
|
|
char full_name[PATH_MAX];
|
|
|
|
|
|
|
|
if (GetModuleFileName (NULL, full_name, PATH_MAX))
|
|
|
|
return xstrdup (full_name);
|
|
|
|
return xstrdup (argv0);
|
|
|
|
}
|
|
|
|
|
* 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
|
|
|
/* Wrapper for select. On Windows systems, where the select interface
|
|
|
|
only works for sockets, this uses the GDB serial abstraction to
|
|
|
|
handle sockets, consoles, pipes, and serial ports.
|
|
|
|
|
|
|
|
The arguments to this function are the same as the traditional
|
|
|
|
arguments to select on POSIX platforms. */
|
|
|
|
|
|
|
|
int
|
|
|
|
gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
|
|
|
struct timeval *timeout)
|
|
|
|
{
|
|
|
|
static HANDLE never_handle;
|
|
|
|
HANDLE handles[MAXIMUM_WAIT_OBJECTS];
|
|
|
|
HANDLE h;
|
|
|
|
DWORD event;
|
|
|
|
DWORD num_handles;
|
2007-10-03 00:09:53 +08:00
|
|
|
/* SCBS contains serial control objects corresponding to file
|
|
|
|
descriptors in READFDS and WRITEFDS. */
|
|
|
|
struct serial *scbs[MAXIMUM_WAIT_OBJECTS];
|
|
|
|
/* The number of valid entries in SCBS. */
|
|
|
|
size_t num_scbs;
|
* 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
|
|
|
int fd;
|
|
|
|
int num_ready;
|
2007-10-03 00:09:53 +08:00
|
|
|
size_t indx;
|
* 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
|
|
|
|
Fix PR win32/24284: tcp_auto_retry doesn't work in MinGW
This was reported by Bernhard Wodok, along with a patch to fix the
issue. I adjusted the patch a bit, and I'm submitting the patch on
his behalf.
According to Bernhard, the issue can be reproduced by doing:
1. start gdb
2. enter 'target remote :2345'
3. observe that it throws a "connection refused" error immediately
instead of waiting and throwing a timeout error
I.e., I believe it can be reproduced by our current tests, which is
why I'm not proposing any extra tests here (well, I don't use nor have
any Windows system to test this, so...).
The problem happens because, on ser-tcp:wait_for_connect, we call
'gdb_select' passing 0 as its first argument, which, when using MinGW,
ends up using the 'gdb_select' version from mingw-hdep.c, and when the
first argument is 0 this means that WaitForMultipleObjects will be
called with 0 as its first argument as well. According to the MS API
docs, this is forbidden:
https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitformultipleobjects
The proposed fix is simple: we just call Sleep when N == 0 (and when
TIMEOUT is non-NULL), and return 0. It makes sense to me.
Both Bernhard and Paul Carroll confirmed that the fix works. I'm
Cc'ing Bernhard in case you have any questions about the patch.
OK?
gdb/ChangeLog:
2019-08-29 Bernhard Wodok <barto@gmx.net>
Sergio Durigan Junior <sergiodj@redhat.com>
PR win32/24284
* mingw-hdep.c (gdb_select): Handle case when 'n' is zero.
2019-08-27 23:40:31 +08:00
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
/* The MS API says that the first argument to
|
|
|
|
WaitForMultipleObjects cannot be zero. That's why we just
|
|
|
|
use a regular Sleep here. */
|
|
|
|
if (timeout != NULL)
|
|
|
|
Sleep (timeout->tv_sec * 1000 + timeout->tv_usec / 1000);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
* 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
|
|
|
num_ready = 0;
|
|
|
|
num_handles = 0;
|
2007-10-03 00:09:53 +08:00
|
|
|
num_scbs = 0;
|
* 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
|
|
|
for (fd = 0; fd < n; ++fd)
|
|
|
|
{
|
|
|
|
HANDLE read = NULL, except = NULL;
|
|
|
|
struct serial *scb;
|
|
|
|
|
|
|
|
/* There is no support yet for WRITEFDS. At present, this isn't
|
|
|
|
used by GDB -- but we do not want to silently ignore WRITEFDS
|
|
|
|
if something starts using it. */
|
|
|
|
gdb_assert (!writefds || !FD_ISSET (fd, writefds));
|
|
|
|
|
2006-06-11 02:24:32 +08:00
|
|
|
if ((!readfds || !FD_ISSET (fd, readfds))
|
|
|
|
&& (!exceptfds || !FD_ISSET (fd, exceptfds)))
|
* 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
|
|
|
continue;
|
|
|
|
|
|
|
|
scb = serial_for_fd (fd);
|
|
|
|
if (scb)
|
2007-10-03 00:09:53 +08:00
|
|
|
{
|
|
|
|
serial_wait_handle (scb, &read, &except);
|
|
|
|
scbs[num_scbs++] = 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
|
|
|
|
|
|
|
if (read == NULL)
|
2007-10-03 00:09:53 +08:00
|
|
|
read = (HANDLE) _get_osfhandle (fd);
|
* 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 (except == NULL)
|
|
|
|
{
|
|
|
|
if (!never_handle)
|
|
|
|
never_handle = CreateEvent (0, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
except = never_handle;
|
|
|
|
}
|
|
|
|
|
2006-06-11 02:24:32 +08:00
|
|
|
if (readfds && FD_ISSET (fd, readfds))
|
* 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
|
|
|
{
|
|
|
|
gdb_assert (num_handles < MAXIMUM_WAIT_OBJECTS);
|
|
|
|
handles[num_handles++] = read;
|
|
|
|
}
|
|
|
|
|
2006-06-11 02:24:32 +08:00
|
|
|
if (exceptfds && FD_ISSET (fd, exceptfds))
|
* 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
|
|
|
{
|
|
|
|
gdb_assert (num_handles < MAXIMUM_WAIT_OBJECTS);
|
|
|
|
handles[num_handles++] = except;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 23:49:32 +08:00
|
|
|
gdb_assert (num_handles <= MAXIMUM_WAIT_OBJECTS);
|
* 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
|
|
|
|
|
|
|
event = WaitForMultipleObjects (num_handles,
|
|
|
|
handles,
|
|
|
|
FALSE,
|
|
|
|
timeout
|
|
|
|
? (timeout->tv_sec * 1000
|
|
|
|
+ timeout->tv_usec / 1000)
|
|
|
|
: INFINITE);
|
|
|
|
/* EVENT can only be a value in the WAIT_ABANDONED_0 range if the
|
|
|
|
HANDLES included an abandoned mutex. Since GDB doesn't use
|
|
|
|
mutexes, that should never occur. */
|
|
|
|
gdb_assert (!(WAIT_ABANDONED_0 <= event
|
|
|
|
&& event < WAIT_ABANDONED_0 + num_handles));
|
2007-10-03 00:09:53 +08:00
|
|
|
/* We no longer need the helper threads to check for activity. */
|
|
|
|
for (indx = 0; indx < num_scbs; ++indx)
|
|
|
|
serial_done_wait_handle (scbs[indx]);
|
* 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 (event == WAIT_FAILED)
|
|
|
|
return -1;
|
|
|
|
if (event == WAIT_TIMEOUT)
|
|
|
|
return 0;
|
|
|
|
/* Run through the READFDS, clearing bits corresponding to descriptors
|
|
|
|
for which input is unavailable. */
|
|
|
|
h = handles[event - WAIT_OBJECT_0];
|
|
|
|
for (fd = 0, indx = 0; fd < n; ++fd)
|
|
|
|
{
|
|
|
|
HANDLE fd_h;
|
2006-04-25 05:00:13 +08:00
|
|
|
|
2006-06-11 02:24:32 +08:00
|
|
|
if ((!readfds || !FD_ISSET (fd, readfds))
|
|
|
|
&& (!exceptfds || !FD_ISSET (fd, exceptfds)))
|
2006-04-25 05:00:13 +08:00
|
|
|
continue;
|
* 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
|
|
|
|
2006-06-11 02:24:32 +08:00
|
|
|
if (readfds && FD_ISSET (fd, readfds))
|
* 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
|
|
|
{
|
|
|
|
fd_h = handles[indx++];
|
|
|
|
/* This handle might be ready, even though it wasn't the handle
|
|
|
|
returned by WaitForMultipleObjects. */
|
|
|
|
if (fd_h != h && WaitForSingleObject (fd_h, 0) != WAIT_OBJECT_0)
|
|
|
|
FD_CLR (fd, readfds);
|
|
|
|
else
|
|
|
|
num_ready++;
|
|
|
|
}
|
|
|
|
|
2006-06-11 02:24:32 +08:00
|
|
|
if (exceptfds && FD_ISSET (fd, exceptfds))
|
* 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
|
|
|
{
|
|
|
|
fd_h = handles[indx++];
|
|
|
|
/* This handle might be ready, even though it wasn't the handle
|
|
|
|
returned by WaitForMultipleObjects. */
|
|
|
|
if (fd_h != h && WaitForSingleObject (fd_h, 0) != WAIT_OBJECT_0)
|
|
|
|
FD_CLR (fd, exceptfds);
|
|
|
|
else
|
|
|
|
num_ready++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_ready;
|
|
|
|
}
|
2019-03-09 14:44:56 +08:00
|
|
|
|
|
|
|
/* Map COLOR's RGB triplet, with 8 bits per component, into 16 Windows
|
|
|
|
console colors, where each component has just 1 bit, plus a single
|
|
|
|
intensity bit which affects all 3 components. */
|
|
|
|
static int
|
|
|
|
rgb_to_16colors (const ui_file_style::color &color)
|
|
|
|
{
|
|
|
|
uint8_t rgb[3];
|
|
|
|
color.get_rgb (rgb);
|
|
|
|
|
|
|
|
int retval = 0;
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
/* Subdivide 256 possible values of each RGB component into 3
|
|
|
|
regions: no color, normal color, bright color. 256 / 3 = 85,
|
|
|
|
but ui-style.c follows xterm and uses 92 for R and G
|
|
|
|
components of the bright-blue color, so we bias the divisor a
|
|
|
|
bit to have the bright colors between 9 and 15 identical to
|
|
|
|
what ui-style.c expects. */
|
|
|
|
int bits = rgb[i] / 93;
|
|
|
|
retval |= ((bits > 0) << (2 - i)) | ((bits > 1) << 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero if not yet initialized, 1 if stdout is a console device, else -1. */
|
|
|
|
static int mingw_console_initialized;
|
|
|
|
|
|
|
|
/* Handle to stdout . */
|
|
|
|
static HANDLE hstdout = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
/* Text attribute to use for normal text (the "none" pseudo-color). */
|
|
|
|
static SHORT norm_attr;
|
|
|
|
|
|
|
|
/* The most recently applied style. */
|
|
|
|
static ui_file_style last_style;
|
|
|
|
|
|
|
|
/* Alternative for the libc 'fputs' which handles embedded SGR
|
|
|
|
sequences in support of styling. */
|
|
|
|
|
|
|
|
int
|
|
|
|
gdb_console_fputs (const char *linebuf, FILE *fstream)
|
|
|
|
{
|
|
|
|
if (!mingw_console_initialized)
|
|
|
|
{
|
|
|
|
hstdout = (HANDLE)_get_osfhandle (fileno (fstream));
|
|
|
|
DWORD cmode;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
|
|
|
if (hstdout != INVALID_HANDLE_VALUE
|
|
|
|
&& GetConsoleMode (hstdout, &cmode) != 0
|
|
|
|
&& GetConsoleScreenBufferInfo (hstdout, &csbi))
|
|
|
|
{
|
|
|
|
norm_attr = csbi.wAttributes;
|
|
|
|
mingw_console_initialized = 1;
|
|
|
|
}
|
|
|
|
else if (hstdout != INVALID_HANDLE_VALUE)
|
|
|
|
mingw_console_initialized = -1; /* valid, but not a console device */
|
|
|
|
}
|
|
|
|
/* If our stdout is not a console device, let the default 'fputs'
|
|
|
|
handle the task. */
|
|
|
|
if (mingw_console_initialized <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Mapping between 8 ANSI colors and Windows console attributes. */
|
|
|
|
static int fg_color[] = {
|
|
|
|
0, /* black */
|
|
|
|
FOREGROUND_RED, /* red */
|
|
|
|
FOREGROUND_GREEN, /* green */
|
|
|
|
FOREGROUND_GREEN | FOREGROUND_RED, /* yellow */
|
|
|
|
FOREGROUND_BLUE, /* blue */
|
|
|
|
FOREGROUND_BLUE | FOREGROUND_RED, /* magenta */
|
|
|
|
FOREGROUND_BLUE | FOREGROUND_GREEN, /* cyan */
|
|
|
|
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE /* gray */
|
|
|
|
};
|
|
|
|
static int bg_color[] = {
|
|
|
|
0, /* black */
|
|
|
|
BACKGROUND_RED, /* red */
|
|
|
|
BACKGROUND_GREEN, /* green */
|
|
|
|
BACKGROUND_GREEN | BACKGROUND_RED, /* yellow */
|
|
|
|
BACKGROUND_BLUE, /* blue */
|
|
|
|
BACKGROUND_BLUE | BACKGROUND_RED, /* magenta */
|
|
|
|
BACKGROUND_BLUE | BACKGROUND_GREEN, /* cyan */
|
|
|
|
BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE /* gray */
|
|
|
|
};
|
|
|
|
|
|
|
|
ui_file_style style = last_style;
|
|
|
|
unsigned char c;
|
|
|
|
size_t n_read;
|
|
|
|
|
|
|
|
for ( ; (c = *linebuf) != 0; linebuf += n_read)
|
|
|
|
{
|
|
|
|
if (c == '\033')
|
|
|
|
{
|
|
|
|
fflush (fstream);
|
|
|
|
bool parsed = style.parse (linebuf, &n_read);
|
|
|
|
if (n_read <= 0) /* should never happen */
|
|
|
|
n_read = 1;
|
|
|
|
if (!parsed)
|
|
|
|
{
|
|
|
|
/* This means we silently swallow SGR sequences we
|
|
|
|
cannot parse. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Colors. */
|
|
|
|
const ui_file_style::color &fg = style.get_foreground ();
|
|
|
|
const ui_file_style::color &bg = style.get_background ();
|
|
|
|
int fgcolor, bgcolor, bright, inverse;
|
|
|
|
if (fg.is_none ())
|
|
|
|
fgcolor = norm_attr & 15;
|
|
|
|
else if (fg.is_basic ())
|
|
|
|
fgcolor = fg_color[fg.get_value () & 15];
|
|
|
|
else
|
|
|
|
fgcolor = rgb_to_16colors (fg);
|
|
|
|
if (bg.is_none ())
|
|
|
|
bgcolor = norm_attr & (15 << 4);
|
|
|
|
else if (bg.is_basic ())
|
|
|
|
bgcolor = bg_color[bg.get_value () & 15];
|
|
|
|
else
|
|
|
|
bgcolor = rgb_to_16colors (bg) << 4;
|
|
|
|
|
|
|
|
/* Intensity. */
|
|
|
|
switch (style.get_intensity ())
|
|
|
|
{
|
|
|
|
case ui_file_style::NORMAL:
|
|
|
|
case ui_file_style::DIM:
|
|
|
|
bright = 0;
|
|
|
|
break;
|
|
|
|
case ui_file_style::BOLD:
|
|
|
|
bright = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gdb_assert_not_reached ("invalid intensity");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Inverse video. */
|
|
|
|
if (style.is_reverse ())
|
|
|
|
inverse = 1;
|
|
|
|
else
|
|
|
|
inverse = 0;
|
|
|
|
|
|
|
|
/* Construct the attribute. */
|
|
|
|
if (inverse)
|
|
|
|
{
|
|
|
|
int t = fgcolor;
|
|
|
|
fgcolor = (bgcolor >> 4);
|
|
|
|
bgcolor = (t << 4);
|
|
|
|
}
|
|
|
|
if (bright)
|
|
|
|
fgcolor |= FOREGROUND_INTENSITY;
|
|
|
|
|
|
|
|
SHORT attr = (bgcolor & (15 << 4)) | (fgcolor & 15);
|
|
|
|
|
|
|
|
/* Apply the attribute. */
|
|
|
|
SetConsoleTextAttribute (hstdout, attr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* When we are about to write newline, we need to clear to
|
|
|
|
EOL with the normal attribute, to avoid spilling the
|
|
|
|
colors to the next screen line. We assume here that no
|
|
|
|
non-default attribute extends beyond the newline. */
|
|
|
|
if (c == '\n')
|
|
|
|
{
|
|
|
|
DWORD nchars;
|
|
|
|
COORD start_pos;
|
|
|
|
DWORD written;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
|
|
|
fflush (fstream);
|
|
|
|
GetConsoleScreenBufferInfo (hstdout, &csbi);
|
|
|
|
|
|
|
|
if (csbi.wAttributes != norm_attr)
|
|
|
|
{
|
|
|
|
start_pos = csbi.dwCursorPosition;
|
|
|
|
nchars = csbi.dwSize.X - start_pos.X;
|
|
|
|
|
|
|
|
FillConsoleOutputAttribute (hstdout, norm_attr, nchars,
|
|
|
|
start_pos, &written);
|
|
|
|
FillConsoleOutputCharacter (hstdout, ' ', nchars,
|
|
|
|
start_pos, &written);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fputc (c, fstream);
|
|
|
|
n_read = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
last_style = style;
|
|
|
|
return 1;
|
|
|
|
}
|
2022-12-06 02:15:09 +08:00
|
|
|
|
|
|
|
/* See inferior.h. */
|
|
|
|
|
|
|
|
tribool
|
|
|
|
sharing_input_terminal (int pid)
|
|
|
|
{
|
|
|
|
std::vector<DWORD> results (10);
|
|
|
|
DWORD len = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
len = GetConsoleProcessList (results.data (), results.size ());
|
|
|
|
/* Note that LEN == 0 is a failure, but we can treat it the same
|
|
|
|
as a "no". */
|
Fix Windows sharing_input_terminal hang
After running a number of programs under Windows gdb and detaching
them, I typed run in gdb, and got a hang, here:
(top-gdb) bt
#0 sharing_input_terminal (pid=4672) at /home/pedro/gdb/src/gdb/mingw-hdep.c:388
#1 0x00007ff71a2d8678 in sharing_input_terminal (inf=0x23bf23dafb0) at /home/pedro/gdb/src/gdb/inflow.c:269
#2 0x00007ff71a2d887b in child_terminal_save_inferior (self=0x23bf23de060) at /home/pedro/gdb/src/gdb/inflow.c:423
#3 0x00007ff71a2c80c0 in inf_child_target::terminal_save_inferior (this=0x23bf23de060) at /home/pedro/gdb/src/gdb/inf-child.c:111
#4 0x00007ff71a429c0f in target_terminal_is_ours_kind (desired_state=target_terminal_state::is_ours_for_output) at /home/pedro/gdb/src/gdb/target.c:1037
#5 0x00007ff71a429e02 in target_terminal::ours_for_output () at /home/pedro/gdb/src/gdb/target.c:1094
#6 0x00007ff71a2ccc8e in post_create_inferior (from_tty=0) at /home/pedro/gdb/src/gdb/infcmd.c:245
#7 0x00007ff71a2cd431 in run_command_1 (args=0x0, from_tty=0, run_how=RUN_NORMAL) at /home/pedro/gdb/src/gdb/infcmd.c:502
#8 0x00007ff71a2cd58b in run_command (args=0x0, from_tty=0) at /home/pedro/gdb/src/gdb/infcmd.c:527
The problem is that the loop around GetConsoleProcessList looped
forever, because there were exactly 10 processes to return.
GetConsoleProcessList's documentation says:
If the buffer is too small to hold all the valid process identifiers,
the return value is the required number of array elements. The
function will have stored no identifiers in the buffer. In this
situation, use the return value to allocate a buffer that is large
enough to store the entire list and call the function again.
In this case, the buffer wasn't too small, it was exactly the right
size, so we should have broken out of the loop. We didn't due to a
"<" check that should have been "<=". That is fixed by this patch.
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Change-Id: I14e4909f2ac2fa83d0d9b6e64418b5831ac4e4e3
2023-04-29 02:11:31 +08:00
|
|
|
if (len <= results.size ())
|
2022-12-06 02:15:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
results.resize (len);
|
|
|
|
}
|
|
|
|
/* In case the vector was too big. */
|
|
|
|
results.resize (len);
|
|
|
|
if (std::find (results.begin (), results.end (), pid) != results.end ())
|
|
|
|
{
|
|
|
|
/* The pid is in the list sharing the console, so don't
|
|
|
|
interrupt the inferior -- it will get the signal itself. */
|
|
|
|
return TRIBOOL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRIBOOL_FALSE;
|
|
|
|
}
|
Fix control-c handling on Windows
As Hannes pointed out, the Windows target-async patches broke C-c
handling there. Looking into this, I found a few oddities, fixed
here.
First, windows_nat_target::interrupt calls GenerateConsoleCtrlEvent.
I think this event can be ignored by the inferior, so it's not a great
way to interrupt. Instead, using DebugBreakProcess (or a more
complicated thing for Wow64) seems better.
Second, windows_nat_target did not implement the pass_ctrlc method.
Implementing this lets us remove the special code to call
SetConsoleCtrlHandler and instead integrate into gdb's approach to C-c
handling. I believe that this should also fix the race that's
described in the comment that's being removed.
Initially, I thought a simpler version of this patch would work.
However, I think what happens is that some other library (I'm not sure
what) calls SetConsoleCtrlHandler while gdb is running, and this
intercepts and handles C-c -- so that the gdb SIGINT handler is not
called. C-break continues to work, presumably because whatever
handler is installed ignores it.
This patch works around this issue by ensuring that the gdb handler
always comes first.
2022-12-06 01:56:23 +08:00
|
|
|
|
|
|
|
/* Current C-c handler. */
|
|
|
|
static c_c_handler_ftype *current_handler;
|
|
|
|
|
|
|
|
/* The Windows callback that forwards requests to the C-c handler. */
|
|
|
|
static BOOL WINAPI
|
|
|
|
ctrl_c_handler (DWORD event_type)
|
|
|
|
{
|
|
|
|
if (event_type == CTRL_BREAK_EVENT || event_type == CTRL_C_EVENT)
|
|
|
|
{
|
|
|
|
if (current_handler != SIG_IGN)
|
|
|
|
current_handler (SIGINT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See inferior.h. */
|
|
|
|
|
|
|
|
c_c_handler_ftype *
|
|
|
|
install_sigint_handler (c_c_handler_ftype *fn)
|
|
|
|
{
|
|
|
|
/* We want to make sure the gdb handler always comes first, so that
|
|
|
|
gdb gets to handle the C-c. This is why the handler is always
|
|
|
|
removed and reinstalled here. Note that trying to remove the
|
|
|
|
function without installing it first will cause a crash. */
|
|
|
|
static bool installed = false;
|
|
|
|
if (installed)
|
|
|
|
SetConsoleCtrlHandler (ctrl_c_handler, FALSE);
|
|
|
|
SetConsoleCtrlHandler (ctrl_c_handler, TRUE);
|
|
|
|
installed = true;
|
|
|
|
|
|
|
|
c_c_handler_ftype *result = current_handler;
|
|
|
|
current_handler = fn;
|
|
|
|
return result;
|
|
|
|
}
|