gdb/event-loop.h - gdb

Data types defined

Source code

  1. /* Definitions used by the GDB event loop.
  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. /* An event loop listens for events from multiple event sources.  When
  16.    an event arrives, it is queued and processed by calling the
  17.    appropriate event handler.  The event loop then continues to listen
  18.    for more events.  An event loop completes when there are no event
  19.    sources to listen on.  External event sources can be plugged into
  20.    the loop.

  21.    There are 4 main components:
  22.    - a list of file descriptors to be monitored, GDB_NOTIFIER.
  23.    - a list of asynchronous event sources to be monitored,
  24.      ASYNC_EVENT_HANDLER_LIST.
  25.    - a list of events that have occurred, EVENT_QUEUE.
  26.    - a list of signal handling functions, SIGHANDLER_LIST.

  27.    GDB_NOTIFIER keeps track of the file descriptor based event
  28.    sources.  ASYNC_EVENT_HANDLER_LIST keeps track of asynchronous
  29.    event sources that are signalled by some component of gdb, usually
  30.    a target_ops instance.  Event sources for gdb are currently the UI
  31.    and the target.  Gdb communicates with the command line user
  32.    interface via the readline library and usually communicates with
  33.    remote targets via a serial port.  Serial ports are represented in
  34.    GDB as file descriptors and select/poll calls.  For native targets
  35.    instead, the communication varies across operating system debug
  36.    APIs, but usually consists of calls to ptrace and waits (via
  37.    signals) or calls to poll/select (via file descriptors).  In the
  38.    current gdb, the code handling events related to the target resides
  39.    in wait_for_inferior for synchronous targets; or, for asynchronous
  40.    capable targets, by having the target register either a target
  41.    controlled file descriptor and/or an asynchronous event source in
  42.    the event loop, with the fetch_inferior_event function as the event
  43.    callback.  In both the synchronous and asynchronous cases, usually
  44.    the target event is collected through the target_wait interface.
  45.    The target is free to install other event sources in the event loop
  46.    if it so requires.

  47.    EVENT_QUEUE keeps track of the events that have happened during the
  48.    last iteration of the event loop, and need to be processed.  An
  49.    event is represented by a procedure to be invoked in order to
  50.    process the event.  The queue is scanned head to tail.  If the
  51.    event of interest is a change of state in a file descriptor, then a
  52.    call to poll or select will be made to detect it.

  53.    If the events generate signals, they are also queued by special
  54.    functions that are invoked through traditional signal handlers.
  55.    The actions to be taken is response to such events will be executed
  56.    when the SIGHANDLER_LIST is scanned, the next time through the
  57.    infinite loop.

  58.    Corollary tasks are the creation and deletion of event sources.  */

  59. typedef void *gdb_client_data;
  60. struct async_signal_handler;
  61. struct async_event_handler;
  62. typedef void (handler_func) (int, gdb_client_data);
  63. typedef void (sig_handler_func) (gdb_client_data);
  64. typedef void (async_event_handler_func) (gdb_client_data);
  65. typedef void (timer_handler_func) (gdb_client_data);

  66. /* Exported functions from event-loop.c */

  67. extern void initialize_event_loop (void);
  68. extern void start_event_loop (void);
  69. extern int gdb_do_one_event (void);
  70. extern void delete_file_handler (int fd);
  71. extern void add_file_handler (int fd, handler_func *proc,
  72.                               gdb_client_data client_data);
  73. extern struct async_signal_handler *
  74.   create_async_signal_handler (sig_handler_func *proc,
  75.                                gdb_client_data client_data);
  76. extern void delete_async_signal_handler (struct async_signal_handler **);
  77. extern int create_timer (int milliseconds,
  78.                          timer_handler_func *proc,
  79.                          gdb_client_data client_data);
  80. extern void delete_timer (int id);

  81. /* Call the handler from HANDLER immediately.  This function
  82.    runs signal handlers when returning to the event loop would be too
  83.    slow.  Do not call this directly; use gdb_call_async_signal_handler,
  84.    below, with IMMEDIATE_P == 1.  */
  85. void call_async_signal_handler (struct async_signal_handler *handler);

  86. /* Call the handler from HANDLER the next time through the event loop.
  87.    Do not call this directly; use gdb_call_async_signal_handler,
  88.    below, with IMMEDIATE_P == 0.  */
  89. void mark_async_signal_handler (struct async_signal_handler *handler);

  90. /* Wrapper for the body of signal handlers.  Call this function from
  91.    any SIGINT handler which needs to access GDB data structures or
  92.    escape via longjmp.  If IMMEDIATE_P is set, this triggers either
  93.    immediately (for POSIX platforms), or from gdb_select (for
  94.    MinGW).  If IMMEDIATE_P is clear, the handler will run the next
  95.    time we return to the event loop and any current select calls
  96.    will be interrupted.  */

  97. void gdb_call_async_signal_handler (struct async_signal_handler *handler,
  98.                                     int immediate_p);

  99. /* Create and register an asynchronous event source in the event loop,
  100.    and set PROC as its callback.  CLIENT_DATA is passed as argument to
  101.    PROC upon its invocation.  Returns a pointer to an opaque structure
  102.    used to mark as ready and to later delete this event source from
  103.    the event loop.  */
  104. extern struct async_event_handler *
  105.   create_async_event_handler (async_event_handler_func *proc,
  106.                               gdb_client_data client_data);

  107. /* Remove the event source pointed by HANDLER_PTR created by
  108.    CREATE_ASYNC_EVENT_HANDLER from the event loop, and release it.  */
  109. extern void
  110.   delete_async_event_handler (struct async_event_handler **handler_ptr);

  111. /* Call the handler from HANDLER the next time through the event
  112.    loop.  */
  113. extern void mark_async_event_handler (struct async_event_handler *handler);