Add Rust support to source highlighting
[external/binutils.git] / gdb / event-loop.h
1 /* Definitions used by the GDB event loop.
2    Copyright (C) 1999-2019 Free Software Foundation, Inc.
3    Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #ifndef EVENT_LOOP_H
21 #define EVENT_LOOP_H
22
23 /* An event loop listens for events from multiple event sources.  When
24    an event arrives, it is queued and processed by calling the
25    appropriate event handler.  The event loop then continues to listen
26    for more events.  An event loop completes when there are no event
27    sources to listen on.  External event sources can be plugged into
28    the loop.
29
30    There are 4 main components:
31    - a list of file descriptors to be monitored, GDB_NOTIFIER.
32    - a list of asynchronous event sources to be monitored,
33      ASYNC_EVENT_HANDLER_LIST.
34    - a list of events that have occurred, EVENT_QUEUE.
35    - a list of signal handling functions, SIGHANDLER_LIST.
36
37    GDB_NOTIFIER keeps track of the file descriptor based event
38    sources.  ASYNC_EVENT_HANDLER_LIST keeps track of asynchronous
39    event sources that are signalled by some component of gdb, usually
40    a target_ops instance.  Event sources for gdb are currently the UI
41    and the target.  Gdb communicates with the command line user
42    interface via the readline library and usually communicates with
43    remote targets via a serial port.  Serial ports are represented in
44    GDB as file descriptors and select/poll calls.  For native targets
45    instead, the communication varies across operating system debug
46    APIs, but usually consists of calls to ptrace and waits (via
47    signals) or calls to poll/select (via file descriptors).  In the
48    current gdb, the code handling events related to the target resides
49    in wait_for_inferior for synchronous targets; or, for asynchronous
50    capable targets, by having the target register either a target
51    controlled file descriptor and/or an asynchronous event source in
52    the event loop, with the fetch_inferior_event function as the event
53    callback.  In both the synchronous and asynchronous cases, usually
54    the target event is collected through the target_wait interface.
55    The target is free to install other event sources in the event loop
56    if it so requires.
57
58    EVENT_QUEUE keeps track of the events that have happened during the
59    last iteration of the event loop, and need to be processed.  An
60    event is represented by a procedure to be invoked in order to
61    process the event.  The queue is scanned head to tail.  If the
62    event of interest is a change of state in a file descriptor, then a
63    call to poll or select will be made to detect it.
64
65    If the events generate signals, they are also queued by special
66    functions that are invoked through traditional signal handlers.
67    The actions to be taken is response to such events will be executed
68    when the SIGHANDLER_LIST is scanned, the next time through the
69    infinite loop.
70
71    Corollary tasks are the creation and deletion of event sources.  */
72
73 typedef void *gdb_client_data;
74 struct async_signal_handler;
75 struct async_event_handler;
76 typedef void (handler_func) (int, gdb_client_data);
77 typedef void (sig_handler_func) (gdb_client_data);
78 typedef void (async_event_handler_func) (gdb_client_data);
79 typedef void (timer_handler_func) (gdb_client_data);
80
81 /* Exported functions from event-loop.c */
82
83 extern void start_event_loop (void);
84 extern int gdb_do_one_event (void);
85 extern void delete_file_handler (int fd);
86 extern void add_file_handler (int fd, handler_func *proc, 
87                               gdb_client_data client_data);
88 extern struct async_signal_handler *
89   create_async_signal_handler (sig_handler_func *proc, 
90                                gdb_client_data client_data);
91 extern void delete_async_signal_handler (struct async_signal_handler **);
92 extern int create_timer (int milliseconds, 
93                          timer_handler_func *proc, 
94                          gdb_client_data client_data);
95 extern void delete_timer (int id);
96
97 /* Call the handler from HANDLER the next time through the event
98    loop.  */
99 extern void mark_async_signal_handler (struct async_signal_handler *handler);
100
101 /* Returns true if HANDLER is marked ready.  */
102
103 extern int
104   async_signal_handler_is_marked (struct async_signal_handler *handler);
105
106 /* Mark HANDLER as NOT ready.  */
107
108 extern void clear_async_signal_handler (struct async_signal_handler *handler);
109
110 /* Create and register an asynchronous event source in the event loop,
111    and set PROC as its callback.  CLIENT_DATA is passed as argument to
112    PROC upon its invocation.  Returns a pointer to an opaque structure
113    used to mark as ready and to later delete this event source from
114    the event loop.  */
115 extern struct async_event_handler *
116   create_async_event_handler (async_event_handler_func *proc,
117                               gdb_client_data client_data);
118
119 /* Remove the event source pointed by HANDLER_PTR created by
120    CREATE_ASYNC_EVENT_HANDLER from the event loop, and release it.  */
121 extern void
122   delete_async_event_handler (struct async_event_handler **handler_ptr);
123
124 /* Call the handler from HANDLER the next time through the event
125    loop.  */
126 extern void mark_async_event_handler (struct async_event_handler *handler);
127
128 /* Mark the handler (ASYNC_HANDLER_PTR) as NOT ready.  */
129
130 extern void clear_async_event_handler (struct async_event_handler *handler);
131
132 extern void initialize_async_signal_handlers (void);
133
134 #endif /* EVENT_LOOP_H */