import gdb-1999-11-08 snapshot
[deliverable/binutils-gdb.git] / gdb / event-loop.c
index c3bbf01ec14975d0322c771a93cf019c3a1244d9..7e3e02c890c3e55d948b57ac18db0da45cf3e0fe 100644 (file)
@@ -256,7 +256,7 @@ static void create_file_handler (int fd, int mask, handler_func * proc, gdb_clie
 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);
@@ -388,52 +388,61 @@ process_event (void)
 
 /* 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
@@ -443,21 +452,6 @@ gdb_do_one_event (void)
             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. */
This page took 0.065272 seconds and 4 git commands to generate.