#include "top.h"
#include "event-loop.h"
#include "event-top.h"
-#include "inferior.h" /* For fetch_inferior_event. */
#ifdef HAVE_POLL
#include <poll.h>
#else
/* Pointer to first in timer list. */
struct gdb_timer *first_timer;
- /* Length of timer list. */
+ /* Id of the last timer created. */
int num_timers;
}
timer_list;
static void invoke_async_signal_handler (void);
static void handle_file_event (int event_file_desc);
static int gdb_wait_for_event (void);
-static int gdb_do_one_event (void);
+static int gdb_do_one_event (void *data);
static int check_async_ready (void);
static void async_queue_event (gdb_event * event_ptr, queue_position position);
static gdb_event *create_file_event (int fd);
static int process_event (void);
static void handle_timer_event (int dummy);
static void poll_timers (void);
-static int fetch_inferior_event_wrapper (gdb_client_data client_data);
\f
/* Insert an event object into the gdb event queue at
/* Process one high level event. If nothing is ready at this time,
wait for something to happen (via gdb_wait_for_event), then process
- it. Returns 1 if something was done otherwise returns 0 (this can
- happen if there are no event sources to wait for). */
+ it. Returns >0 if something was done otherwise returns <0 (this
+ can happen if there are no event sources to wait for). If an error
+ occures catch_errors() which calls this function returns zero. */
+
static int
-gdb_do_one_event (void)
+gdb_do_one_event (void *data)
{
- int result = 0;
-
- while (1)
+ /* Any events already waiting in the queue? */
+ if (process_event ())
{
- if (!SET_TOP_LEVEL ())
- {
- /* Any events already waiting in the queue? */
- if (process_event ())
- {
- result = 1;
- break;
- }
-
- /* Are any timers that are ready? If so, put an event on the queue. */
- poll_timers ();
-
- /* Wait for a new event. If gdb_wait_for_event returns -1,
- we should get out because this means that there are no
- event sources left. This will make the event loop stop,
- and the application exit. */
-
- result = gdb_wait_for_event ();
- if (result < 0)
- {
- result = 0;
- break;
- }
+ return 1;
+ }
+
+ /* Are any timers that are ready? If so, put an event on the queue. */
+ poll_timers ();
+
+ /* Wait for a new event. If gdb_wait_for_event returns -1,
+ we should get out because this means that there are no
+ event sources left. This will make the event loop stop,
+ and the application exit. */
+
+ if (gdb_wait_for_event () < 0)
+ {
+ return -1;
+ }
+
+ /* Handle any new events occurred while waiting. */
+ if (process_event ())
+ {
+ return 1;
+ }
+
+ /* If gdb_wait_for_event has returned 1, it means that one
+ event has been handled. We break out of the loop. */
+ return 1;
+}
- /* Handle any new events occurred while waiting. */
- if (process_event ())
- {
- result = 1;
- break;
- }
+/* Start up the event loop. This is the entry point to the event loop
+ from the command loop. */
- /* If gdb_wait_for_event has returned 1, it means that one
- event has been handled. We break out of the loop. */
- if (result)
- break;
- } /* end of if !set_top_level */
- else
+void
+start_event_loop (void)
+{
+ /* Loop until there is nothing to do. This is the entry point to the
+ event loop engine. gdb_do_one_event, called via catch_errors()
+ will process one event for each invocation. It blocks waits for
+ an event and then processes it. >0 when an event is processed, 0
+ when catch_errors() caught an error and <0 when there are no
+ longer any event sources registered. */
+ while (1)
+ {
+ int result = catch_errors (gdb_do_one_event, 0, "", RETURN_MASK_ALL);
+ if (result < 0)
+ break;
+ if (result == 0)
{
/* FIXME: this should really be a call to a hook that is
interface specific, because interfaces can display the
whether display the prompt or not. */
}
}
- return result;
-}
-\f
-
-/* Start up the event loop. This is the entry point to the event loop
- from the command loop. */
-void
-start_event_loop (void)
-{
- /* Loop until there is something to do. This is the entry point to
- the event loop engine. gdb_do_one_event will process one event
- for each invocation. It always returns 1, unless there are no
- more event sources registered. In this case it returns 0. */
- while (gdb_do_one_event () != 0)
- ;
/* We are done with the event loop. There are no more event sources
to listen to. So we exit GDB. */
/* If there was a match, then call the handler. */
if (mask != 0)
- (*file_ptr->proc) (file_ptr->error, file_ptr->fd, file_ptr->client_data);
+ (*file_ptr->proc) (file_ptr->error, file_ptr->client_data);
break;
}
}
return async_handler_ready;
}
-/* FIXME: where does this function belong? */
-/* General function to handle events in the inferior. So far it just
- takes care of detecting errors reported by select() or poll(),
- otherwise it assumes that all is OK, and goes on reading data from
- the fd. This however may not always be what we want to do. */
-void
-inferior_event_handler (int error, gdb_client_data client_data, int fd)
-{
- if (error == 1)
- {
- printf_unfiltered ("error detected on fd %d\n", fd);
- delete_file_handler (fd);
- pop_target ();
- discard_all_continuations ();
- }
- else
- /* Use catch errors for now, until the inner layers of
- fetch_inferior_event (i.e. readchar) can return meaningful
- error status. If an error occurs while getting an event from
- the target, just get rid of the target. */
- if (!catch_errors (fetch_inferior_event_wrapper, client_data, "", RETURN_MASK_ALL))
- {
- delete_file_handler (fd);
- discard_all_continuations ();
- pop_target ();
- display_gdb_prompt (0);
- }
-}
-
-static int
-fetch_inferior_event_wrapper (gdb_client_data client_data)
-{
- fetch_inferior_event (client_data);
- return 1;
-}
-
/* Create a timer that will expire in MILLISECONDS from now. When the
timer is ready, PROC will be executed. At creation, the timer is
aded to the timers queue. This queue is kept sorted in order of
saved_timer = timer_ptr;
timer_ptr = timer_ptr->next;
/* Call the procedure associated with that timer. */
- (*saved_timer->proc) (timer_ptr->client_data);
+ (*saved_timer->proc) (saved_timer->client_data);
free (saved_timer);
}
struct timeval time_now, delta;
gdb_event *event_ptr;
- if (timer_list.num_timers)
+ if (timer_list.first_timer != NULL)
{
gettimeofday (&time_now, NULL);
delta.tv_sec = timer_list.first_timer->when.tv_sec - time_now.tv_sec;