[PATCH 29/30] Eliminate immediate_quit

Pedro Alves
2016-03-18T19:19:07Z

This finally gets rid of immediate_quit (and surrounding
infrustruture), as nothing sets it anymore.

gdb_call_async_signal_handler was only necessary in order to handle
immediate_quit. We can just call mark_async_signal_handler directly
on all hosts now.

In turn, we can clean up mingw-hdep.c's gdb_select a bit, as
sigint_event / sigint_handler is no longer needed.

gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>

* defs.h: Update comments on SIGINT handling.
(immediate_quit): Delete declaration.
* event-loop.c (call_async_signal_handler): Delete.
* event-loop.h (call_async_signal_handler): Delete declaration.
(mark_async_signal_handler): Update comments.
(gdb_call_async_signal_handler): Delete declaration.
* event-top.c (handle_sigint): Call mark_async_signal_handler
instead of gdb_call_async_signal_handler.
* exceptions.c (prepare_to_throw_exception): Remove reference to
immediate_quit.
(exception_fprintf): Remove comments about immediate_quit.
* mingw-hdep.c (sigint_event, sigint_handler): Delete.
(gdb_select): Don't wait on sigint_event.
(gdb_call_async_signal_handler): Delete.
(_initialize_mingw_hdep): Delete.
* posix-hdep.c (gdb_call_async_signal_handler): Delete.
* utils.c (immediate_quit): Delete.
---
gdb/defs.h | 11 ++++-------
gdb/event-loop.c | 9 ---------
gdb/event-loop.h | 24 +++---------------------
gdb/event-top.c | 13 +++----------
gdb/exceptions.c | 8 +-------
gdb/mingw-hdep.c | 52 +---------------------------------------------------
gdb/posix-hdep.c | 13 -------------
gdb/utils.c | 13 -------------
8 files changed, 12 insertions(+), 131 deletions(-)

diff --git a/gdb/defs.h b/gdb/defs.h
index 83e4e11..482ef1c 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -125,11 +125,10 @@ extern char *python_libdir;
/* * Search path for separate debug files. */
extern char *debug_file_directory;

-/* GDB has two methods for handling SIGINT. When immediate_quit is
- nonzero, a SIGINT results in an immediate longjmp out of the signal
- handler. Otherwise, SIGINT simply sets a flag; code that might
- take a long time, and which ought to be interruptible, checks this
- flag using the QUIT macro.
+/* GDB's SIGINT handler basically sets a flag; code that might take a
+ long time before it gets back to the event loop, and which ought to
+ be interruptible, checks this flag using the QUIT macro, which, if
+ GDB has the terminal, throws a quit exception.

In addition to setting a flag, the SIGINT handler also marks a
select/poll-able file descriptor as read-ready. That is used by
@@ -176,8 +175,6 @@ extern void default_quit_handler (void);
/* Flag that function quit should call quit_force. */
extern volatile int sync_quit_force_run;

-extern int immediate_quit;
-
extern void quit (void);

/* Helper for the QUIT macro. */
diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index 052d535..60ef2a5 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -911,15 +911,6 @@ create_async_signal_handler (sig_handler_func * proc,
return async_handler_ptr;
}

-/* Call the handler from HANDLER immediately. This function runs
- signal handlers when returning to the event loop would be too
- slow. */
-void
-call_async_signal_handler (struct async_signal_handler *handler)
-{
- (*handler->proc) (handler->client_data);
-}
-
/* Mark the handler (ASYNC_HANDLER_PTR) as ready. This information
will be used when the handlers are invoked, after we have waited
for some event. The caller of this function is the interrupt
diff --git a/gdb/event-loop.h b/gdb/event-loop.h
index 155dafa..7159d97 100644
--- a/gdb/event-loop.h
+++ b/gdb/event-loop.h
@@ -91,16 +91,9 @@ extern int create_timer (int milliseconds,
gdb_client_data client_data);
extern void delete_timer (int id);

-/* Call the handler from HANDLER immediately. This function
- runs signal handlers when returning to the event loop would be too
- slow. Do not call this directly; use gdb_call_async_signal_handler,
- below, with IMMEDIATE_P == 1. */
-void call_async_signal_handler (struct async_signal_handler *handler);
-
-/* Call the handler from HANDLER the next time through the event loop.
- Do not call this directly; use gdb_call_async_signal_handler,
- below, with IMMEDIATE_P == 0. */
-void mark_async_signal_handler (struct async_signal_handler *handler);
+/* Call the handler from HANDLER the next time through the event
+ loop. */
+extern void mark_async_signal_handler (struct async_signal_handler *handler);

/* Returns true if HANDLER is marked ready. */

@@ -111,17 +104,6 @@ extern int

extern void clear_async_signal_handler (struct async_signal_handler *handler);

-/* Wrapper for the body of signal handlers. Call this function from
- any SIGINT handler which needs to access GDB data structures or
- escape via longjmp. If IMMEDIATE_P is set, this triggers either
- immediately (for POSIX platforms), or from gdb_select (for
- MinGW). If IMMEDIATE_P is clear, the handler will run the next
- time we return to the event loop and any current select calls
- will be interrupted. */
-
-void gdb_call_async_signal_handler (struct async_signal_handler *handler,
- int immediate_p);
-
/* Create and register an asynchronous event source in the event loop,
and set PROC as its callback. CLIENT_DATA is passed as argument to
PROC upon its invocation. Returns a pointer to an opaque structure
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 386920e..d599d2a 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -900,18 +900,11 @@ handle_sigint (int sig)
it may be quite a while before we get back to the event loop. So
set quit_flag to 1 here. Then if QUIT is called before we get to
the event loop, we will unwind as expected. */
-
set_quit_flag ();

- /* If immediate_quit is set, we go ahead and process the SIGINT right
- away, even if we usually would defer this to the event loop. The
- assumption here is that it is safe to process ^C immediately if
- immediate_quit is set. If we didn't, SIGINT would be really
- processed only the next time through the event loop. To get to
- that point, though, the command that we want to interrupt needs to
- finish first, which is unacceptable. If immediate quit is not set,
- we process SIGINT the next time through the loop, which is fine. */
- gdb_call_async_signal_handler (sigint_token, immediate_quit);
+ /* In case nothing calls QUIT before the event loop is reached, the
+ event loop handles it. */
+ mark_async_signal_handler (sigint_token);
}

/* See gdb_select.h. */
diff --git a/gdb/exceptions.c b/gdb/exceptions.c
index ffdd1f37..7f6599f 100644
--- a/gdb/exceptions.c
+++ b/gdb/exceptions.c
@@ -30,7 +30,6 @@
void
prepare_to_throw_exception (void)
{
- immediate_quit = 0;
}

static void
@@ -148,12 +147,7 @@ exception_fprintf (struct ui_file *file, struct gdb_exception e,
returned by catch_exceptions(). It is an internal_error() for
FUNC() to return a negative value.

- See exceptions.h for further usage details.
-
- Must not be called with immediate_quit in effect (bad things might
- happen, say we got a signal in the middle of a memcpy to quit_return).
- This is an OK restriction; with very few exceptions immediate_quit can
- be replaced by judicious use of QUIT. */
+ See exceptions.h for further usage details. */

/* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
error() et al. could maintain a set of flags that indicate the
diff --git a/gdb/mingw-hdep.c b/gdb/mingw-hdep.c
index 8247a8c..2e010fa 100644
--- a/gdb/mingw-hdep.c
+++ b/gdb/mingw-hdep.c
@@ -27,14 +27,6 @@

#include <windows.h>

-/* This event is signalled whenever an asynchronous SIGINT handler
- needs to perform an action in the main thread. */
-static HANDLE sigint_event;
-
-/* When SIGINT_EVENT is signalled, gdb_select will call this
- function. */
-struct async_signal_handler *sigint_handler;
-
/* Return an absolute file name of the running GDB, if possible, or
ARGV0 if not. The return value is in malloc'ed storage. */

@@ -120,8 +112,7 @@ gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
}
}

- gdb_assert (num_handles < MAXIMUM_WAIT_OBJECTS);
- handles[num_handles++] = sigint_event;
+ gdb_assert (num_handles <= MAXIMUM_WAIT_OBJECTS);

event = WaitForMultipleObjects (num_handles,
handles,
@@ -184,46 +175,5 @@ gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
while (RL_ISSTATE (RL_STATE_SIGHANDLER))
Sleep (1);

- if (h == sigint_event
- || WaitForSingleObject (sigint_event, 0) == WAIT_OBJECT_0)
- {
- if (sigint_handler != NULL)
- call_async_signal_handler (sigint_handler);
-
- if (num_ready == 0)
- {
- errno = EINTR;
- return -1;
- }
- }
-
return num_ready;
}
-
-/* Wrapper for the body of signal handlers. On Windows systems, a
- SIGINT handler runs in its own thread. We can't longjmp from
- there, and we shouldn't even prompt the user. Delay HANDLER
- until the main thread is next in gdb_select. */
-
-void
-gdb_call_async_signal_handler (struct async_signal_handler *handler,
- int immediate_p)
-{
- if (immediate_p)
- sigint_handler = handler;
- else
- {
- mark_async_signal_handler (handler);
- sigint_handler = NULL;
- }
- SetEvent (sigint_event);
-}
-
-/* -Wmissing-prototypes */
-extern initialize_file_ftype _initialize_mingw_hdep;
-
-void
-_initialize_mingw_hdep (void)
-{
- sigint_event = CreateEvent (0, FALSE, FALSE, 0);
-}
diff --git a/gdb/posix-hdep.c b/gdb/posix-hdep.c
index 90cab8f..e9db576 100644
--- a/gdb/posix-hdep.c
+++ b/gdb/posix-hdep.c
@@ -30,16 +30,3 @@ gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
{
return select (n, readfds, writefds, exceptfds, timeout);
}
-
-/* Wrapper for the body of signal handlers. Nothing special needed on
- POSIX platforms. */
-
-void
-gdb_call_async_signal_handler (struct async_signal_handler *handler,
- int immediate_p)
-{
- if (immediate_p)
- call_async_signal_handler (handler);
- else
- mark_async_signal_handler (handler);
-}
diff --git a/gdb/utils.c b/gdb/utils.c
index 5d778f6..d58c4c1 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -109,19 +109,6 @@ static int debug_timestamp = 0;

int job_control;

-/* Nonzero means quit immediately if Control-C is typed now, rather
- than waiting until QUIT is executed. Be careful in setting this;
- code which executes with immediate_quit set has to be very careful
- about being able to deal with being interrupted at any time. It is
- almost always better to use QUIT; the only exception I can think of
- is being able to quit out of a system call (using EINTR loses if
- the SIGINT happens between the previous QUIT and the system call).
- To immediately quit in the case in which a SIGINT happens between
- the previous QUIT and setting immediate_quit (desirable anytime we
- expect to block), call QUIT after setting immediate_quit. */
-
-int immediate_quit;
-
/* Nonzero means that strings with character values >0x7F should be printed
as octal escapes. Zero means just print the value (e.g. it's an
international character, and the terminal or window can cope.) */
--
2.5.0