gdb/event-loop.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Event loop machinery for GDB, the GNU debugger.
  2.    Copyright (C) 1999-2015 Free Software Foundation, Inc.
  3.    Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.

  4.    This file is part of GDB.

  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  15. #include "defs.h"
  16. #include "event-loop.h"
  17. #include "event-top.h"
  18. #include "queue.h"

  19. #ifdef HAVE_POLL
  20. #if defined (HAVE_POLL_H)
  21. #include <poll.h>
  22. #elif defined (HAVE_SYS_POLL_H)
  23. #include <sys/poll.h>
  24. #endif
  25. #endif

  26. #include <sys/types.h>
  27. #include <sys/time.h>
  28. #include "gdb_select.h"
  29. #include "observer.h"

  30. /* Tell create_file_handler what events we are interested in.
  31.    This is used by the select version of the event loop.  */

  32. #define GDB_READABLE        (1<<1)
  33. #define GDB_WRITABLE        (1<<2)
  34. #define GDB_EXCEPTION        (1<<3)

  35. /* Data point to pass to the event handler.  */
  36. typedef union event_data
  37. {
  38.   void *ptr;
  39.   int integer;
  40. } event_data;

  41. typedef struct gdb_event gdb_event;
  42. typedef void (event_handler_func) (event_data);

  43. /* Event for the GDB event system.  Events are queued by calling
  44.    async_queue_event and serviced later on by gdb_do_one_event.  An
  45.    event can be, for instance, a file descriptor becoming ready to be
  46.    read.  Servicing an event simply means that the procedure PROC will
  47.    be called.  We have 2 queues, one for file handlers that we listen
  48.    to in the event loop, and one for the file handlers+events that are
  49.    ready.  The procedure PROC associated with each event is dependant
  50.    of the event source.  In the case of monitored file descriptors, it
  51.    is always the same (handle_file_event).  Its duty is to invoke the
  52.    handler associated with the file descriptor whose state change
  53.    generated the event, plus doing other cleanups and such.  In the
  54.    case of async signal handlers, it is
  55.    invoke_async_signal_handler.  */

  56. typedef struct gdb_event
  57.   {
  58.     /* Procedure to call to service this event.  */
  59.     event_handler_func *proc;

  60.     /* Data to pass to the event handler.  */
  61.     event_data data;
  62.   } *gdb_event_p;

  63. /* Information about each file descriptor we register with the event
  64.    loop.  */

  65. typedef struct file_handler
  66.   {
  67.     int fd;                        /* File descriptor.  */
  68.     int mask;                        /* Events we want to monitor: POLLIN, etc.  */
  69.     int ready_mask;                /* Events that have been seen since
  70.                                    the last time.  */
  71.     handler_func *proc;                /* Procedure to call when fd is ready.  */
  72.     gdb_client_data client_data;        /* Argument to pass to proc.  */
  73.     int error;                        /* Was an error detected on this fd?  */
  74.     struct file_handler *next_file;        /* Next registered file descriptor.  */
  75.   }
  76. file_handler;

  77. /* PROC is a function to be invoked when the READY flag is set.  This
  78.    happens when there has been a signal and the corresponding signal
  79.    handler has 'triggered' this async_signal_handler for execution.
  80.    The actual work to be done in response to a signal will be carried
  81.    out by PROC at a later time, within process_event.  This provides a
  82.    deferred execution of signal handlers.

  83.    Async_init_signals takes care of setting up such an
  84.    async_signal_handler for each interesting signal.  */

  85. typedef struct async_signal_handler
  86.   {
  87.     int ready;                            /* If ready, call this handler
  88.                                        from the main event loop, using
  89.                                        invoke_async_handler.  */
  90.     struct async_signal_handler *next_handler;        /* Ptr to next handler.  */
  91.     sig_handler_func *proc;            /* Function to call to do the work.  */
  92.     gdb_client_data client_data;    /* Argument to async_handler_func.  */
  93.   }
  94. async_signal_handler;

  95. /* PROC is a function to be invoked when the READY flag is set.  This
  96.    happens when the event has been marked with
  97.    MARK_ASYNC_EVENT_HANDLER.  The actual work to be done in response
  98.    to an event will be carried out by PROC at a later time, within
  99.    process_event.  This provides a deferred execution of event
  100.    handlers.  */
  101. typedef struct async_event_handler
  102.   {
  103.     /* If ready, call this handler from the main event loop, using
  104.        invoke_event_handler.  */
  105.     int ready;

  106.     /* Point to next handler.  */
  107.     struct async_event_handler *next_handler;

  108.     /* Function to call to do the work.  */
  109.     async_event_handler_func *proc;

  110.     /* Argument to PROC.  */
  111.     gdb_client_data client_data;
  112.   }
  113. async_event_handler;

  114. DECLARE_QUEUE_P(gdb_event_p);
  115. DEFINE_QUEUE_P(gdb_event_p);
  116. static QUEUE(gdb_event_p) *event_queue = NULL;

  117. /* Gdb_notifier is just a list of file descriptors gdb is interested in.
  118.    These are the input file descriptor, and the target file
  119.    descriptor.  We have two flavors of the notifier, one for platforms
  120.    that have the POLL function, the other for those that don't, and
  121.    only support SELECT.  Each of the elements in the gdb_notifier list is
  122.    basically a description of what kind of events gdb is interested
  123.    in, for each fd.  */

  124. /* As of 1999-04-30 only the input file descriptor is registered with the
  125.    event loop.  */

  126. /* Do we use poll or select ? */
  127. #ifdef HAVE_POLL
  128. #define USE_POLL 1
  129. #else
  130. #define USE_POLL 0
  131. #endif /* HAVE_POLL */

  132. static unsigned char use_poll = USE_POLL;

  133. #ifdef USE_WIN32API
  134. #include <windows.h>
  135. #include <io.h>
  136. #endif

  137. static struct
  138.   {
  139.     /* Ptr to head of file handler list.  */
  140.     file_handler *first_file_handler;

  141. #ifdef HAVE_POLL
  142.     /* Ptr to array of pollfd structures.  */
  143.     struct pollfd *poll_fds;

  144.     /* Timeout in milliseconds for calls to poll().  */
  145.     int poll_timeout;
  146. #endif

  147.     /* Masks to be used in the next call to select.
  148.        Bits are set in response to calls to create_file_handler.  */
  149.     fd_set check_masks[3];

  150.     /* What file descriptors were found ready by select.  */
  151.     fd_set ready_masks[3];

  152.     /* Number of file descriptors to monitor (for poll).  */
  153.     /* Number of valid bits (highest fd value + 1) (for select).  */
  154.     int num_fds;

  155.     /* Time structure for calls to select().  */
  156.     struct timeval select_timeout;

  157.     /* Flag to tell whether the timeout should be used.  */
  158.     int timeout_valid;
  159.   }
  160. gdb_notifier;

  161. /* Structure associated with a timer.  PROC will be executed at the
  162.    first occasion after WHEN.  */
  163. struct gdb_timer
  164.   {
  165.     struct timeval when;
  166.     int timer_id;
  167.     struct gdb_timer *next;
  168.     timer_handler_func *proc;            /* Function to call to do the work.  */
  169.     gdb_client_data client_data;    /* Argument to async_handler_func.  */
  170.   };

  171. /* List of currently active timers.  It is sorted in order of
  172.    increasing timers.  */
  173. static struct
  174.   {
  175.     /* Pointer to first in timer list.  */
  176.     struct gdb_timer *first_timer;

  177.     /* Id of the last timer created.  */
  178.     int num_timers;
  179.   }
  180. timer_list;

  181. /* All the async_signal_handlers gdb is interested in are kept onto
  182.    this list.  */
  183. static struct
  184.   {
  185.     /* Pointer to first in handler list.  */
  186.     async_signal_handler *first_handler;

  187.     /* Pointer to last in handler list.  */
  188.     async_signal_handler *last_handler;
  189.   }
  190. sighandler_list;

  191. /* All the async_event_handlers gdb is interested in are kept onto
  192.    this list.  */
  193. static struct
  194.   {
  195.     /* Pointer to first in handler list.  */
  196.     async_event_handler *first_handler;

  197.     /* Pointer to last in handler list.  */
  198.     async_event_handler *last_handler;
  199.   }
  200. async_event_handler_list;

  201. static int invoke_async_signal_handlers (void);
  202. static void create_file_handler (int fd, int mask, handler_func *proc,
  203.                                  gdb_client_data client_data);
  204. static void handle_file_event (event_data data);
  205. static void check_async_event_handlers (void);
  206. static int gdb_wait_for_event (int);
  207. static void poll_timers (void);


  208. /* Create a generic event, to be enqueued in the event queue for
  209.    processing.  PROC is the procedure associated to the event.  DATA
  210.    is passed to PROC upon PROC invocation.  */

  211. static gdb_event *
  212. create_event (event_handler_func proc, event_data data)
  213. {
  214.   gdb_event *event;

  215.   event = xmalloc (sizeof (*event));
  216.   event->proc = proc;
  217.   event->data = data;

  218.   return event;
  219. }

  220. /* Create a file event, to be enqueued in the event queue for
  221.    processing.  The procedure associated to this event is always
  222.    handle_file_event, which will in turn invoke the one that was
  223.    associated to FD when it was registered with the event loop.  */
  224. static gdb_event *
  225. create_file_event (int fd)
  226. {
  227.   event_data data;

  228.   data.integer = fd;
  229.   return create_event (handle_file_event, data);
  230. }


  231. /* Free EVENT.  */

  232. static void
  233. gdb_event_xfree (struct gdb_event *event)
  234. {
  235.   xfree (event);
  236. }

  237. /* Initialize the event queue.  */

  238. void
  239. initialize_event_loop (void)
  240. {
  241.   event_queue = QUEUE_alloc (gdb_event_p, gdb_event_xfree);
  242. }

  243. /* Process one event.
  244.    The event can be the next one to be serviced in the event queue,
  245.    or an asynchronous event handler can be invoked in response to
  246.    the reception of a signal.
  247.    If an event was processed (either way), 1 is returned otherwise
  248.    0 is returned.
  249.    Scan the queue from head to tail, processing therefore the high
  250.    priority events first, by invoking the associated event handler
  251.    procedure.  */
  252. static int
  253. process_event (void)
  254. {
  255.   /* First let's see if there are any asynchronous event handlers that
  256.      are ready.  These would be the result of invoking any of the
  257.      signal handlers.  */

  258.   if (invoke_async_signal_handlers ())
  259.     return 1;

  260.   /* Look in the event queue to find an event that is ready
  261.      to be processed.  */

  262.   if (!QUEUE_is_empty (gdb_event_p, event_queue))
  263.     {
  264.       /* Let's get rid of the event from the event queue.  We need to
  265.          do this now because while processing the event, the proc
  266.          function could end up calling 'error' and therefore jump out
  267.          to the caller of this function, gdb_do_one_event.  In that
  268.          case, we would have on the event queue an event wich has been
  269.          processed, but not deleted.  */
  270.       gdb_event *event_ptr = QUEUE_deque (gdb_event_p, event_queue);
  271.       /* Call the handler for the event.  */
  272.       event_handler_func *proc = event_ptr->proc;
  273.       event_data data = event_ptr->data;

  274.       gdb_event_xfree (event_ptr);

  275.       /* Now call the procedure associated with the event.  */
  276.       (*proc) (data);
  277.       return 1;
  278.     }

  279.   /* This is the case if there are no event on the event queue.  */
  280.   return 0;
  281. }

  282. /* Process one high level event.  If nothing is ready at this time,
  283.    wait for something to happen (via gdb_wait_for_event), then process
  284.    it.  Returns >0 if something was done otherwise returns <0 (this
  285.    can happen if there are no event sources to wait for).  */

  286. int
  287. gdb_do_one_event (void)
  288. {
  289.   static int event_source_head = 0;
  290.   const int number_of_sources = 3;
  291.   int current = 0;

  292.   /* Any events already waiting in the queue?  */
  293.   if (process_event ())
  294.     return 1;

  295.   /* To level the fairness across event sources, we poll them in a
  296.      round-robin fashion.  */
  297.   for (current = 0; current < number_of_sources; current++)
  298.     {
  299.       switch (event_source_head)
  300.         {
  301.         case 0:
  302.           /* Are any timers that are ready? If so, put an event on the
  303.              queue.  */
  304.           poll_timers ();
  305.           break;
  306.         case 1:
  307.           /* Are there events already waiting to be collected on the
  308.              monitored file descriptors?  */
  309.           gdb_wait_for_event (0);
  310.           break;
  311.         case 2:
  312.           /* Are there any asynchronous event handlers ready?  */
  313.           check_async_event_handlers ();
  314.           break;
  315.         }

  316.       event_source_head++;
  317.       if (event_source_head == number_of_sources)
  318.         event_source_head = 0;
  319.     }

  320.   /* Handle any new events collected.  */
  321.   if (process_event ())
  322.     return 1;

  323.   /* Block waiting for a new event.  If gdb_wait_for_event returns -1,
  324.      we should get out because this means that there are no event
  325.      sources left.  This will make the event loop stop, and the
  326.      application exit.  */

  327.   if (gdb_wait_for_event (1) < 0)
  328.     return -1;

  329.   /* Handle any new events occurred while waiting.  */
  330.   if (process_event ())
  331.     return 1;

  332.   /* If gdb_wait_for_event has returned 1, it means that one event has
  333.      been handled.  We break out of the loop.  */
  334.   return 1;
  335. }

  336. /* Start up the event loop.  This is the entry point to the event loop
  337.    from the command loop.  */

  338. void
  339. start_event_loop (void)
  340. {
  341.   /* Loop until there is nothing to do.  This is the entry point to
  342.      the event loop engine.  gdb_do_one_event will process one event
  343.      for each invocation.  It blocks waiting for an event and then
  344.      processes it.  */
  345.   while (1)
  346.     {
  347.       volatile struct gdb_exception ex;
  348.       int result = 0;

  349.       TRY_CATCH (ex, RETURN_MASK_ALL)
  350.         {
  351.           result = gdb_do_one_event ();
  352.         }
  353.       if (ex.reason < 0)
  354.         {
  355.           exception_print (gdb_stderr, ex);

  356.           /* If any exception escaped to here, we better enable
  357.              stdin.  Otherwise, any command that calls async_disable_stdin,
  358.              and then throws, will leave stdin inoperable.  */
  359.           async_enable_stdin ();
  360.           /* If we long-jumped out of do_one_event, we probably didn't
  361.              get around to resetting the prompt, which leaves readline
  362.              in a messed-up state.  Reset it here.  */
  363.           observer_notify_command_error ();
  364.           /* This call looks bizarre, but it is required.  If the user
  365.              entered a command that caused an error,
  366.              after_char_processing_hook won't be called from
  367.              rl_callback_read_char_wrapper.  Using a cleanup there
  368.              won't work, since we want this function to be called
  369.              after a new prompt is printed.  */
  370.           if (after_char_processing_hook)
  371.             (*after_char_processing_hook) ();
  372.           /* Maybe better to set a flag to be checked somewhere as to
  373.              whether display the prompt or not.  */
  374.         }
  375.       if (result < 0)
  376.         break;
  377.     }

  378.   /* We are done with the event loop.  There are no more event sources
  379.      to listen to.  So we exit GDB.  */
  380.   return;
  381. }


  382. /* Wrapper function for create_file_handler, so that the caller
  383.    doesn't have to know implementation details about the use of poll
  384.    vs. select.  */
  385. void
  386. add_file_handler (int fd, handler_func * proc, gdb_client_data client_data)
  387. {
  388. #ifdef HAVE_POLL
  389.   struct pollfd fds;
  390. #endif

  391.   if (use_poll)
  392.     {
  393. #ifdef HAVE_POLL
  394.       /* Check to see if poll () is usable.  If not, we'll switch to
  395.          use select.  This can happen on systems like
  396.          m68k-motorola-sys, `poll' cannot be used to wait for `stdin'.
  397.          On m68k-motorola-sysv, tty's are not stream-based and not
  398.          `poll'able.  */
  399.       fds.fd = fd;
  400.       fds.events = POLLIN;
  401.       if (poll (&fds, 1, 0) == 1 && (fds.revents & POLLNVAL))
  402.         use_poll = 0;
  403. #else
  404.       internal_error (__FILE__, __LINE__,
  405.                       _("use_poll without HAVE_POLL"));
  406. #endif /* HAVE_POLL */
  407.     }
  408.   if (use_poll)
  409.     {
  410. #ifdef HAVE_POLL
  411.       create_file_handler (fd, POLLIN, proc, client_data);
  412. #else
  413.       internal_error (__FILE__, __LINE__,
  414.                       _("use_poll without HAVE_POLL"));
  415. #endif
  416.     }
  417.   else
  418.     create_file_handler (fd, GDB_READABLE | GDB_EXCEPTION,
  419.                          proc, client_data);
  420. }

  421. /* Add a file handler/descriptor to the list of descriptors we are
  422.    interested in.

  423.    FD is the file descriptor for the file/stream to be listened to.

  424.    For the poll case, MASK is a combination (OR) of POLLIN,
  425.    POLLRDNORM, POLLRDBAND, POLLPRI, POLLOUT, POLLWRNORM, POLLWRBAND:
  426.    these are the events we are interested in.  If any of them occurs,
  427.    proc should be called.

  428.    For the select case, MASK is a combination of READABLE, WRITABLE,
  429.    EXCEPTION.  PROC is the procedure that will be called when an event
  430.    occurs for FD.  CLIENT_DATA is the argument to pass to PROC.  */

  431. static void
  432. create_file_handler (int fd, int mask, handler_func * proc,
  433.                      gdb_client_data client_data)
  434. {
  435.   file_handler *file_ptr;

  436.   /* Do we already have a file handler for this file?  (We may be
  437.      changing its associated procedure).  */
  438.   for (file_ptr = gdb_notifier.first_file_handler; file_ptr != NULL;
  439.        file_ptr = file_ptr->next_file)
  440.     {
  441.       if (file_ptr->fd == fd)
  442.         break;
  443.     }

  444.   /* It is a new file descriptor.  Add it to the list.  Otherwise, just
  445.      change the data associated with it.  */
  446.   if (file_ptr == NULL)
  447.     {
  448.       file_ptr = (file_handler *) xmalloc (sizeof (file_handler));
  449.       file_ptr->fd = fd;
  450.       file_ptr->ready_mask = 0;
  451.       file_ptr->next_file = gdb_notifier.first_file_handler;
  452.       gdb_notifier.first_file_handler = file_ptr;

  453.       if (use_poll)
  454.         {
  455. #ifdef HAVE_POLL
  456.           gdb_notifier.num_fds++;
  457.           if (gdb_notifier.poll_fds)
  458.             gdb_notifier.poll_fds =
  459.               (struct pollfd *) xrealloc (gdb_notifier.poll_fds,
  460.                                           (gdb_notifier.num_fds
  461.                                            * sizeof (struct pollfd)));
  462.           else
  463.             gdb_notifier.poll_fds =
  464.               (struct pollfd *) xmalloc (sizeof (struct pollfd));
  465.           (gdb_notifier.poll_fds + gdb_notifier.num_fds - 1)->fd = fd;
  466.           (gdb_notifier.poll_fds + gdb_notifier.num_fds - 1)->events = mask;
  467.           (gdb_notifier.poll_fds + gdb_notifier.num_fds - 1)->revents = 0;
  468. #else
  469.           internal_error (__FILE__, __LINE__,
  470.                           _("use_poll without HAVE_POLL"));
  471. #endif /* HAVE_POLL */
  472.         }
  473.       else
  474.         {
  475.           if (mask & GDB_READABLE)
  476.             FD_SET (fd, &gdb_notifier.check_masks[0]);
  477.           else
  478.             FD_CLR (fd, &gdb_notifier.check_masks[0]);

  479.           if (mask & GDB_WRITABLE)
  480.             FD_SET (fd, &gdb_notifier.check_masks[1]);
  481.           else
  482.             FD_CLR (fd, &gdb_notifier.check_masks[1]);

  483.           if (mask & GDB_EXCEPTION)
  484.             FD_SET (fd, &gdb_notifier.check_masks[2]);
  485.           else
  486.             FD_CLR (fd, &gdb_notifier.check_masks[2]);

  487.           if (gdb_notifier.num_fds <= fd)
  488.             gdb_notifier.num_fds = fd + 1;
  489.         }
  490.     }

  491.   file_ptr->proc = proc;
  492.   file_ptr->client_data = client_data;
  493.   file_ptr->mask = mask;
  494. }

  495. /* Remove the file descriptor FD from the list of monitored fd's:
  496.    i.e. we don't care anymore about events on the FD.  */
  497. void
  498. delete_file_handler (int fd)
  499. {
  500.   file_handler *file_ptr, *prev_ptr = NULL;
  501.   int i;
  502. #ifdef HAVE_POLL
  503.   int j;
  504.   struct pollfd *new_poll_fds;
  505. #endif

  506.   /* Find the entry for the given file.  */

  507.   for (file_ptr = gdb_notifier.first_file_handler; file_ptr != NULL;
  508.        file_ptr = file_ptr->next_file)
  509.     {
  510.       if (file_ptr->fd == fd)
  511.         break;
  512.     }

  513.   if (file_ptr == NULL)
  514.     return;

  515.   if (use_poll)
  516.     {
  517. #ifdef HAVE_POLL
  518.       /* Create a new poll_fds array by copying every fd's information
  519.          but the one we want to get rid of.  */

  520.       new_poll_fds = (struct pollfd *)
  521.         xmalloc ((gdb_notifier.num_fds - 1) * sizeof (struct pollfd));

  522.       for (i = 0, j = 0; i < gdb_notifier.num_fds; i++)
  523.         {
  524.           if ((gdb_notifier.poll_fds + i)->fd != fd)
  525.             {
  526.               (new_poll_fds + j)->fd = (gdb_notifier.poll_fds + i)->fd;
  527.               (new_poll_fds + j)->events = (gdb_notifier.poll_fds + i)->events;
  528.               (new_poll_fds + j)->revents
  529.                 = (gdb_notifier.poll_fds + i)->revents;
  530.               j++;
  531.             }
  532.         }
  533.       xfree (gdb_notifier.poll_fds);
  534.       gdb_notifier.poll_fds = new_poll_fds;
  535.       gdb_notifier.num_fds--;
  536. #else
  537.       internal_error (__FILE__, __LINE__,
  538.                       _("use_poll without HAVE_POLL"));
  539. #endif /* HAVE_POLL */
  540.     }
  541.   else
  542.     {
  543.       if (file_ptr->mask & GDB_READABLE)
  544.         FD_CLR (fd, &gdb_notifier.check_masks[0]);
  545.       if (file_ptr->mask & GDB_WRITABLE)
  546.         FD_CLR (fd, &gdb_notifier.check_masks[1]);
  547.       if (file_ptr->mask & GDB_EXCEPTION)
  548.         FD_CLR (fd, &gdb_notifier.check_masks[2]);

  549.       /* Find current max fd.  */

  550.       if ((fd + 1) == gdb_notifier.num_fds)
  551.         {
  552.           gdb_notifier.num_fds--;
  553.           for (i = gdb_notifier.num_fds; i; i--)
  554.             {
  555.               if (FD_ISSET (i - 1, &gdb_notifier.check_masks[0])
  556.                   || FD_ISSET (i - 1, &gdb_notifier.check_masks[1])
  557.                   || FD_ISSET (i - 1, &gdb_notifier.check_masks[2]))
  558.                 break;
  559.             }
  560.           gdb_notifier.num_fds = i;
  561.         }
  562.     }

  563.   /* Deactivate the file descriptor, by clearing its mask,
  564.      so that it will not fire again.  */

  565.   file_ptr->mask = 0;

  566.   /* Get rid of the file handler in the file handler list.  */
  567.   if (file_ptr == gdb_notifier.first_file_handler)
  568.     gdb_notifier.first_file_handler = file_ptr->next_file;
  569.   else
  570.     {
  571.       for (prev_ptr = gdb_notifier.first_file_handler;
  572.            prev_ptr->next_file != file_ptr;
  573.            prev_ptr = prev_ptr->next_file)
  574.         ;
  575.       prev_ptr->next_file = file_ptr->next_file;
  576.     }
  577.   xfree (file_ptr);
  578. }

  579. /* Handle the given event by calling the procedure associated to the
  580.    corresponding file handler.  Called by process_event indirectly,
  581.    through event_ptr->proc.  EVENT_FILE_DESC is file descriptor of the
  582.    event in the front of the event queue.  */
  583. static void
  584. handle_file_event (event_data data)
  585. {
  586.   file_handler *file_ptr;
  587.   int mask;
  588. #ifdef HAVE_POLL
  589.   int error_mask;
  590. #endif
  591.   int event_file_desc = data.integer;

  592.   /* Search the file handler list to find one that matches the fd in
  593.      the event.  */
  594.   for (file_ptr = gdb_notifier.first_file_handler; file_ptr != NULL;
  595.        file_ptr = file_ptr->next_file)
  596.     {
  597.       if (file_ptr->fd == event_file_desc)
  598.         {
  599.           /* With poll, the ready_mask could have any of three events
  600.              set to 1: POLLHUP, POLLERR, POLLNVAL.  These events
  601.              cannot be used in the requested event mask (events), but
  602.              they can be returned in the return mask (revents).  We
  603.              need to check for those event too, and add them to the
  604.              mask which will be passed to the handler.  */

  605.           /* See if the desired events (mask) match the received
  606.              events (ready_mask).  */

  607.           if (use_poll)
  608.             {
  609. #ifdef HAVE_POLL
  610.               /* POLLHUP means EOF, but can be combined with POLLIN to
  611.                  signal more data to read.  */
  612.               error_mask = POLLHUP | POLLERR | POLLNVAL;
  613.               mask = file_ptr->ready_mask & (file_ptr->mask | error_mask);

  614.               if ((mask & (POLLERR | POLLNVAL)) != 0)
  615.                 {
  616.                   /* Work in progress.  We may need to tell somebody
  617.                      what kind of error we had.  */
  618.                   if (mask & POLLERR)
  619.                     printf_unfiltered (_("Error detected on fd %d\n"),
  620.                                        file_ptr->fd);
  621.                   if (mask & POLLNVAL)
  622.                     printf_unfiltered (_("Invalid or non-`poll'able fd %d\n"),
  623.                                        file_ptr->fd);
  624.                   file_ptr->error = 1;
  625.                 }
  626.               else
  627.                 file_ptr->error = 0;
  628. #else
  629.               internal_error (__FILE__, __LINE__,
  630.                               _("use_poll without HAVE_POLL"));
  631. #endif /* HAVE_POLL */
  632.             }
  633.           else
  634.             {
  635.               if (file_ptr->ready_mask & GDB_EXCEPTION)
  636.                 {
  637.                   printf_unfiltered (_("Exception condition detected "
  638.                                        "on fd %d\n"), file_ptr->fd);
  639.                   file_ptr->error = 1;
  640.                 }
  641.               else
  642.                 file_ptr->error = 0;
  643.               mask = file_ptr->ready_mask & file_ptr->mask;
  644.             }

  645.           /* Clear the received events for next time around.  */
  646.           file_ptr->ready_mask = 0;

  647.           /* If there was a match, then call the handler.  */
  648.           if (mask != 0)
  649.             (*file_ptr->proc) (file_ptr->error, file_ptr->client_data);
  650.           break;
  651.         }
  652.     }
  653. }

  654. /* Called by gdb_do_one_event to wait for new events on the monitored
  655.    file descriptors.  Queue file events as they are detected by the
  656.    poll.  If BLOCK and if there are no events, this function will
  657.    block in the call to poll.  Return -1 if there are no file
  658.    descriptors to monitor, otherwise return 0.  */
  659. static int
  660. gdb_wait_for_event (int block)
  661. {
  662.   file_handler *file_ptr;
  663.   gdb_event *file_event_ptr;
  664.   int num_found = 0;
  665.   int i;

  666.   /* Make sure all output is done before getting another event.  */
  667.   gdb_flush (gdb_stdout);
  668.   gdb_flush (gdb_stderr);

  669.   if (gdb_notifier.num_fds == 0)
  670.     return -1;

  671.   if (use_poll)
  672.     {
  673. #ifdef HAVE_POLL
  674.       int timeout;

  675.       if (block)
  676.         timeout = gdb_notifier.timeout_valid ? gdb_notifier.poll_timeout : -1;
  677.       else
  678.         timeout = 0;

  679.       num_found = poll (gdb_notifier.poll_fds,
  680.                         (unsigned long) gdb_notifier.num_fds, timeout);

  681.       /* Don't print anything if we get out of poll because of a
  682.          signal.  */
  683.       if (num_found == -1 && errno != EINTR)
  684.         perror_with_name (("poll"));
  685. #else
  686.       internal_error (__FILE__, __LINE__,
  687.                       _("use_poll without HAVE_POLL"));
  688. #endif /* HAVE_POLL */
  689.     }
  690.   else
  691.     {
  692.       struct timeval select_timeout;
  693.       struct timeval *timeout_p;

  694.       if (block)
  695.         timeout_p = gdb_notifier.timeout_valid
  696.           ? &gdb_notifier.select_timeout : NULL;
  697.       else
  698.         {
  699.           memset (&select_timeout, 0, sizeof (select_timeout));
  700.           timeout_p = &select_timeout;
  701.         }

  702.       gdb_notifier.ready_masks[0] = gdb_notifier.check_masks[0];
  703.       gdb_notifier.ready_masks[1] = gdb_notifier.check_masks[1];
  704.       gdb_notifier.ready_masks[2] = gdb_notifier.check_masks[2];
  705.       num_found = gdb_select (gdb_notifier.num_fds,
  706.                               &gdb_notifier.ready_masks[0],
  707.                               &gdb_notifier.ready_masks[1],
  708.                               &gdb_notifier.ready_masks[2],
  709.                               timeout_p);

  710.       /* Clear the masks after an error from select.  */
  711.       if (num_found == -1)
  712.         {
  713.           FD_ZERO (&gdb_notifier.ready_masks[0]);
  714.           FD_ZERO (&gdb_notifier.ready_masks[1]);
  715.           FD_ZERO (&gdb_notifier.ready_masks[2]);

  716.           /* Dont print anything if we got a signal, let gdb handle
  717.              it.  */
  718.           if (errno != EINTR)
  719.             perror_with_name (("select"));
  720.         }
  721.     }

  722.   /* Enqueue all detected file events.  */

  723.   if (use_poll)
  724.     {
  725. #ifdef HAVE_POLL
  726.       for (i = 0; (i < gdb_notifier.num_fds) && (num_found > 0); i++)
  727.         {
  728.           if ((gdb_notifier.poll_fds + i)->revents)
  729.             num_found--;
  730.           else
  731.             continue;

  732.           for (file_ptr = gdb_notifier.first_file_handler;
  733.                file_ptr != NULL;
  734.                file_ptr = file_ptr->next_file)
  735.             {
  736.               if (file_ptr->fd == (gdb_notifier.poll_fds + i)->fd)
  737.                 break;
  738.             }

  739.           if (file_ptr)
  740.             {
  741.               /* Enqueue an event only if this is still a new event for
  742.                  this fd.  */
  743.               if (file_ptr->ready_mask == 0)
  744.                 {
  745.                   file_event_ptr = create_file_event (file_ptr->fd);
  746.                   QUEUE_enque (gdb_event_p, event_queue, file_event_ptr);
  747.                 }
  748.               file_ptr->ready_mask = (gdb_notifier.poll_fds + i)->revents;
  749.             }
  750.         }
  751. #else
  752.       internal_error (__FILE__, __LINE__,
  753.                       _("use_poll without HAVE_POLL"));
  754. #endif /* HAVE_POLL */
  755.     }
  756.   else
  757.     {
  758.       for (file_ptr = gdb_notifier.first_file_handler;
  759.            (file_ptr != NULL) && (num_found > 0);
  760.            file_ptr = file_ptr->next_file)
  761.         {
  762.           int mask = 0;

  763.           if (FD_ISSET (file_ptr->fd, &gdb_notifier.ready_masks[0]))
  764.             mask |= GDB_READABLE;
  765.           if (FD_ISSET (file_ptr->fd, &gdb_notifier.ready_masks[1]))
  766.             mask |= GDB_WRITABLE;
  767.           if (FD_ISSET (file_ptr->fd, &gdb_notifier.ready_masks[2]))
  768.             mask |= GDB_EXCEPTION;

  769.           if (!mask)
  770.             continue;
  771.           else
  772.             num_found--;

  773.           /* Enqueue an event only if this is still a new event for
  774.              this fd.  */

  775.           if (file_ptr->ready_mask == 0)
  776.             {
  777.               file_event_ptr = create_file_event (file_ptr->fd);
  778.               QUEUE_enque (gdb_event_p, event_queue, file_event_ptr);
  779.             }
  780.           file_ptr->ready_mask = mask;
  781.         }
  782.     }
  783.   return 0;
  784. }


  785. /* Create an asynchronous handler, allocating memory for it.
  786.    Return a pointer to the newly created handler.
  787.    This pointer will be used to invoke the handler by
  788.    invoke_async_signal_handler.
  789.    PROC is the function to call with CLIENT_DATA argument
  790.    whenever the handler is invoked.  */
  791. async_signal_handler *
  792. create_async_signal_handler (sig_handler_func * proc,
  793.                              gdb_client_data client_data)
  794. {
  795.   async_signal_handler *async_handler_ptr;

  796.   async_handler_ptr =
  797.     (async_signal_handler *) xmalloc (sizeof (async_signal_handler));
  798.   async_handler_ptr->ready = 0;
  799.   async_handler_ptr->next_handler = NULL;
  800.   async_handler_ptr->proc = proc;
  801.   async_handler_ptr->client_data = client_data;
  802.   if (sighandler_list.first_handler == NULL)
  803.     sighandler_list.first_handler = async_handler_ptr;
  804.   else
  805.     sighandler_list.last_handler->next_handler = async_handler_ptr;
  806.   sighandler_list.last_handler = async_handler_ptr;
  807.   return async_handler_ptr;
  808. }

  809. /* Call the handler from HANDLER immediately.  This function runs
  810.    signal handlers when returning to the event loop would be too
  811.    slow.  */
  812. void
  813. call_async_signal_handler (struct async_signal_handler *handler)
  814. {
  815.   (*handler->proc) (handler->client_data);
  816. }

  817. /* Mark the handler (ASYNC_HANDLER_PTR) as ready.  This information
  818.    will be used when the handlers are invoked, after we have waited
  819.    for some event.  The caller of this function is the interrupt
  820.    handler associated with a signal.  */
  821. void
  822. mark_async_signal_handler (async_signal_handler * async_handler_ptr)
  823. {
  824.   async_handler_ptr->ready = 1;
  825. }

  826. /* Call all the handlers that are ready.  Returns true if any was
  827.    indeed ready.  */
  828. static int
  829. invoke_async_signal_handlers (void)
  830. {
  831.   async_signal_handler *async_handler_ptr;
  832.   int any_ready = 0;

  833.   /* Invoke ready handlers.  */

  834.   while (1)
  835.     {
  836.       for (async_handler_ptr = sighandler_list.first_handler;
  837.            async_handler_ptr != NULL;
  838.            async_handler_ptr = async_handler_ptr->next_handler)
  839.         {
  840.           if (async_handler_ptr->ready)
  841.             break;
  842.         }
  843.       if (async_handler_ptr == NULL)
  844.         break;
  845.       any_ready = 1;
  846.       async_handler_ptr->ready = 0;
  847.       (*async_handler_ptr->proc) (async_handler_ptr->client_data);
  848.     }

  849.   return any_ready;
  850. }

  851. /* Delete an asynchronous handler (ASYNC_HANDLER_PTR).
  852.    Free the space allocated for it.  */
  853. void
  854. delete_async_signal_handler (async_signal_handler ** async_handler_ptr)
  855. {
  856.   async_signal_handler *prev_ptr;

  857.   if (sighandler_list.first_handler == (*async_handler_ptr))
  858.     {
  859.       sighandler_list.first_handler = (*async_handler_ptr)->next_handler;
  860.       if (sighandler_list.first_handler == NULL)
  861.         sighandler_list.last_handler = NULL;
  862.     }
  863.   else
  864.     {
  865.       prev_ptr = sighandler_list.first_handler;
  866.       while (prev_ptr && prev_ptr->next_handler != (*async_handler_ptr))
  867.         prev_ptr = prev_ptr->next_handler;
  868.       gdb_assert (prev_ptr);
  869.       prev_ptr->next_handler = (*async_handler_ptr)->next_handler;
  870.       if (sighandler_list.last_handler == (*async_handler_ptr))
  871.         sighandler_list.last_handler = prev_ptr;
  872.     }
  873.   xfree ((*async_handler_ptr));
  874.   (*async_handler_ptr) = NULL;
  875. }

  876. /* Create an asynchronous event handler, allocating memory for it.
  877.    Return a pointer to the newly created handler.  PROC is the
  878.    function to call with CLIENT_DATA argument whenever the handler is
  879.    invoked.  */
  880. async_event_handler *
  881. create_async_event_handler (async_event_handler_func *proc,
  882.                             gdb_client_data client_data)
  883. {
  884.   async_event_handler *h;

  885.   h = xmalloc (sizeof (*h));
  886.   h->ready = 0;
  887.   h->next_handler = NULL;
  888.   h->proc = proc;
  889.   h->client_data = client_data;
  890.   if (async_event_handler_list.first_handler == NULL)
  891.     async_event_handler_list.first_handler = h;
  892.   else
  893.     async_event_handler_list.last_handler->next_handler = h;
  894.   async_event_handler_list.last_handler = h;
  895.   return h;
  896. }

  897. /* Mark the handler (ASYNC_HANDLER_PTR) as ready.  This information
  898.    will be used by gdb_do_one_event.  The caller will be whoever
  899.    created the event source, and wants to signal that the event is
  900.    ready to be handled.  */
  901. void
  902. mark_async_event_handler (async_event_handler *async_handler_ptr)
  903. {
  904.   async_handler_ptr->ready = 1;
  905. }

  906. struct async_event_handler_data
  907. {
  908.   async_event_handler_func* proc;
  909.   gdb_client_data client_data;
  910. };

  911. static void
  912. invoke_async_event_handler (event_data data)
  913. {
  914.   struct async_event_handler_data *hdata = data.ptr;
  915.   async_event_handler_func* proc = hdata->proc;
  916.   gdb_client_data client_data = hdata->client_data;

  917.   xfree (hdata);
  918.   (*proc) (client_data);
  919. }

  920. /* Check if any asynchronous event handlers are ready, and queue
  921.    events in the ready queue for any that are.  */
  922. static void
  923. check_async_event_handlers (void)
  924. {
  925.   async_event_handler *async_handler_ptr;
  926.   struct async_event_handler_data *hdata;
  927.   struct gdb_event *event_ptr;
  928.   event_data data;

  929.   for (async_handler_ptr = async_event_handler_list.first_handler;
  930.        async_handler_ptr != NULL;
  931.        async_handler_ptr = async_handler_ptr->next_handler)
  932.     {
  933.       if (async_handler_ptr->ready)
  934.         {
  935.           async_handler_ptr->ready = 0;

  936.           hdata = xmalloc (sizeof (*hdata));

  937.           hdata->proc = async_handler_ptr->proc;
  938.           hdata->client_data = async_handler_ptr->client_data;

  939.           data.ptr = hdata;

  940.           event_ptr = create_event (invoke_async_event_handler, data);
  941.           QUEUE_enque (gdb_event_p, event_queue, event_ptr);
  942.         }
  943.     }
  944. }

  945. /* Delete an asynchronous handler (ASYNC_HANDLER_PTR).
  946.    Free the space allocated for it.  */
  947. void
  948. delete_async_event_handler (async_event_handler **async_handler_ptr)
  949. {
  950.   async_event_handler *prev_ptr;

  951.   if (async_event_handler_list.first_handler == *async_handler_ptr)
  952.     {
  953.       async_event_handler_list.first_handler
  954.         = (*async_handler_ptr)->next_handler;
  955.       if (async_event_handler_list.first_handler == NULL)
  956.         async_event_handler_list.last_handler = NULL;
  957.     }
  958.   else
  959.     {
  960.       prev_ptr = async_event_handler_list.first_handler;
  961.       while (prev_ptr && prev_ptr->next_handler != *async_handler_ptr)
  962.         prev_ptr = prev_ptr->next_handler;
  963.       gdb_assert (prev_ptr);
  964.       prev_ptr->next_handler = (*async_handler_ptr)->next_handler;
  965.       if (async_event_handler_list.last_handler == (*async_handler_ptr))
  966.         async_event_handler_list.last_handler = prev_ptr;
  967.     }
  968.   xfree (*async_handler_ptr);
  969.   *async_handler_ptr = NULL;
  970. }

  971. /* Create a timer that will expire in MILLISECONDS from now.  When the
  972.    timer is ready, PROC will be executed.  At creation, the timer is
  973.    aded to the timers queue.  This queue is kept sorted in order of
  974.    increasing timers.  Return a handle to the timer struct.  */
  975. int
  976. create_timer (int milliseconds, timer_handler_func * proc,
  977.               gdb_client_data client_data)
  978. {
  979.   struct gdb_timer *timer_ptr, *timer_index, *prev_timer;
  980.   struct timeval time_now, delta;

  981.   /* Compute seconds.  */
  982.   delta.tv_sec = milliseconds / 1000;
  983.   /* Compute microseconds.  */
  984.   delta.tv_usec = (milliseconds % 1000) * 1000;

  985.   gettimeofday (&time_now, NULL);

  986.   timer_ptr = (struct gdb_timer *) xmalloc (sizeof (*timer_ptr));
  987.   timer_ptr->when.tv_sec = time_now.tv_sec + delta.tv_sec;
  988.   timer_ptr->when.tv_usec = time_now.tv_usec + delta.tv_usec;
  989.   /* Carry?  */
  990.   if (timer_ptr->when.tv_usec >= 1000000)
  991.     {
  992.       timer_ptr->when.tv_sec += 1;
  993.       timer_ptr->when.tv_usec -= 1000000;
  994.     }
  995.   timer_ptr->proc = proc;
  996.   timer_ptr->client_data = client_data;
  997.   timer_list.num_timers++;
  998.   timer_ptr->timer_id = timer_list.num_timers;

  999.   /* Now add the timer to the timer queue, making sure it is sorted in
  1000.      increasing order of expiration.  */

  1001.   for (timer_index = timer_list.first_timer;
  1002.        timer_index != NULL;
  1003.        timer_index = timer_index->next)
  1004.     {
  1005.       /* If the seconds field is greater or if it is the same, but the
  1006.          microsecond field is greater.  */
  1007.       if ((timer_index->when.tv_sec > timer_ptr->when.tv_sec)
  1008.           || ((timer_index->when.tv_sec == timer_ptr->when.tv_sec)
  1009.               && (timer_index->when.tv_usec > timer_ptr->when.tv_usec)))
  1010.         break;
  1011.     }

  1012.   if (timer_index == timer_list.first_timer)
  1013.     {
  1014.       timer_ptr->next = timer_list.first_timer;
  1015.       timer_list.first_timer = timer_ptr;

  1016.     }
  1017.   else
  1018.     {
  1019.       for (prev_timer = timer_list.first_timer;
  1020.            prev_timer->next != timer_index;
  1021.            prev_timer = prev_timer->next)
  1022.         ;

  1023.       prev_timer->next = timer_ptr;
  1024.       timer_ptr->next = timer_index;
  1025.     }

  1026.   gdb_notifier.timeout_valid = 0;
  1027.   return timer_ptr->timer_id;
  1028. }

  1029. /* There is a chance that the creator of the timer wants to get rid of
  1030.    it before it expires.  */
  1031. void
  1032. delete_timer (int id)
  1033. {
  1034.   struct gdb_timer *timer_ptr, *prev_timer = NULL;

  1035.   /* Find the entry for the given timer.  */

  1036.   for (timer_ptr = timer_list.first_timer; timer_ptr != NULL;
  1037.        timer_ptr = timer_ptr->next)
  1038.     {
  1039.       if (timer_ptr->timer_id == id)
  1040.         break;
  1041.     }

  1042.   if (timer_ptr == NULL)
  1043.     return;
  1044.   /* Get rid of the timer in the timer list.  */
  1045.   if (timer_ptr == timer_list.first_timer)
  1046.     timer_list.first_timer = timer_ptr->next;
  1047.   else
  1048.     {
  1049.       for (prev_timer = timer_list.first_timer;
  1050.            prev_timer->next != timer_ptr;
  1051.            prev_timer = prev_timer->next)
  1052.         ;
  1053.       prev_timer->next = timer_ptr->next;
  1054.     }
  1055.   xfree (timer_ptr);

  1056.   gdb_notifier.timeout_valid = 0;
  1057. }

  1058. /* When a timer event is put on the event queue, it will be handled by
  1059.    this function.  Just call the associated procedure and delete the
  1060.    timer event from the event queue.  Repeat this for each timer that
  1061.    has expired.  */
  1062. static void
  1063. handle_timer_event (event_data dummy)
  1064. {
  1065.   struct timeval time_now;
  1066.   struct gdb_timer *timer_ptr, *saved_timer;

  1067.   gettimeofday (&time_now, NULL);
  1068.   timer_ptr = timer_list.first_timer;

  1069.   while (timer_ptr != NULL)
  1070.     {
  1071.       if ((timer_ptr->when.tv_sec > time_now.tv_sec)
  1072.           || ((timer_ptr->when.tv_sec == time_now.tv_sec)
  1073.               && (timer_ptr->when.tv_usec > time_now.tv_usec)))
  1074.         break;

  1075.       /* Get rid of the timer from the beginning of the list.  */
  1076.       timer_list.first_timer = timer_ptr->next;
  1077.       saved_timer = timer_ptr;
  1078.       timer_ptr = timer_ptr->next;
  1079.       /* Call the procedure associated with that timer.  */
  1080.       (*saved_timer->proc) (saved_timer->client_data);
  1081.       xfree (saved_timer);
  1082.     }

  1083.   gdb_notifier.timeout_valid = 0;
  1084. }

  1085. /* Check whether any timers in the timers queue are ready.  If at least
  1086.    one timer is ready, stick an event onto the event queue.  Even in
  1087.    case more than one timer is ready, one event is enough, because the
  1088.    handle_timer_event() will go through the timers list and call the
  1089.    procedures associated with all that have expired.l Update the
  1090.    timeout for the select() or poll() as well.  */
  1091. static void
  1092. poll_timers (void)
  1093. {
  1094.   struct timeval time_now, delta;
  1095.   gdb_event *event_ptr;

  1096.   if (timer_list.first_timer != NULL)
  1097.     {
  1098.       gettimeofday (&time_now, NULL);
  1099.       delta.tv_sec = timer_list.first_timer->when.tv_sec - time_now.tv_sec;
  1100.       delta.tv_usec = timer_list.first_timer->when.tv_usec - time_now.tv_usec;
  1101.       /* Borrow?  */
  1102.       if (delta.tv_usec < 0)
  1103.         {
  1104.           delta.tv_sec -= 1;
  1105.           delta.tv_usec += 1000000;
  1106.         }

  1107.       /* Oops it expired already.  Tell select / poll to return
  1108.          immediately.  (Cannot simply test if delta.tv_sec is negative
  1109.          because time_t might be unsigned.)  */
  1110.       if (timer_list.first_timer->when.tv_sec < time_now.tv_sec
  1111.           || (timer_list.first_timer->when.tv_sec == time_now.tv_sec
  1112.               && timer_list.first_timer->when.tv_usec < time_now.tv_usec))
  1113.         {
  1114.           delta.tv_sec = 0;
  1115.           delta.tv_usec = 0;
  1116.         }

  1117.       if (delta.tv_sec == 0 && delta.tv_usec == 0)
  1118.         {
  1119.           event_ptr = (gdb_event *) xmalloc (sizeof (gdb_event));
  1120.           event_ptr->proc = handle_timer_event;
  1121.           event_ptr->data.integer = timer_list.first_timer->timer_id;
  1122.           QUEUE_enque (gdb_event_p, event_queue, event_ptr);
  1123.         }

  1124.       /* Now we need to update the timeout for select/ poll, because
  1125.          we don't want to sit there while this timer is expiring.  */
  1126.       if (use_poll)
  1127.         {
  1128. #ifdef HAVE_POLL
  1129.           gdb_notifier.poll_timeout = delta.tv_sec * 1000;
  1130. #else
  1131.           internal_error (__FILE__, __LINE__,
  1132.                           _("use_poll without HAVE_POLL"));
  1133. #endif /* HAVE_POLL */
  1134.         }
  1135.       else
  1136.         {
  1137.           gdb_notifier.select_timeout.tv_sec = delta.tv_sec;
  1138.           gdb_notifier.select_timeout.tv_usec = delta.tv_usec;
  1139.         }
  1140.       gdb_notifier.timeout_valid = 1;
  1141.     }
  1142.   else
  1143.     gdb_notifier.timeout_valid = 0;
  1144. }