]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/event-loop.h
2011-01-05 Michael Snyder <msnyder@vmware.com>
[thirdparty/binutils-gdb.git] / gdb / event-loop.h
CommitLineData
b5a0ac70 1/* Definitions used by the GDB event loop.
7b6bb8da 2 Copyright (C) 1999, 2000, 2007, 2008, 2009, 2010, 2011
4c38e0a4 3 Free Software Foundation, Inc.
b5a0ac70
SS
4 Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
b5a0ac70
SS
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
b5a0ac70 20
371d5dec 21/* An event loop listens for events from multiple event sources. When
b5a0ac70 22 an event arrives, it is queued and processed by calling the
371d5dec
MS
23 appropriate event handler. The event loop then continues to listen
24 for more events. An event loop completes when there are no event
b5a0ac70
SS
25 sources to listen on. External event sources can be plugged into
26 the loop.
27
50d01748 28 There are 4 main components:
371d5dec 29 - a list of file descriptors to be monitored, GDB_NOTIFIER.
50d01748
PA
30 - a list of asynchronous event sources to be monitored,
31 ASYNC_EVENT_HANDLER_LIST.
371d5dec 32 - a list of events that have occurred, EVENT_QUEUE.
b5a0ac70
SS
33 - a list of signal handling functions, SIGHANDLER_LIST.
34
50d01748
PA
35 GDB_NOTIFIER keeps track of the file descriptor based event
36 sources. ASYNC_EVENT_HANDLER_LIST keeps track of asynchronous
37 event sources that are signalled by some component of gdb, usually
38 a target_ops instance. Event sources for gdb are currently the UI
39 and the target. Gdb communicates with the command line user
40 interface via the readline library and usually communicates with
41 remote targets via a serial port. Serial ports are represented in
42 GDB as file descriptors and select/poll calls. For native targets
43 instead, the communication varies across operating system debug
44 APIs, but usually consists of calls to ptrace and waits (via
45 signals) or calls to poll/select (via file descriptors). In the
46 current gdb, the code handling events related to the target resides
47 in wait_for_inferior for synchronous targets; or, for asynchronous
48 capable targets, by having the target register either a target
49 controlled file descriptor and/or an asynchronous event source in
50 the event loop, with the fetch_inferior_event function as the event
51 callback. In both the synchronous and asynchronous cases, usually
52 the target event is collected through the target_wait interface.
53 The target is free to install other event sources in the event loop
54 if it so requires.
b5a0ac70
SS
55
56 EVENT_QUEUE keeps track of the events that have happened during the
57 last iteration of the event loop, and need to be processed. An
58 event is represented by a procedure to be invoked in order to
59 process the event. The queue is scanned head to tail. If the
60 event of interest is a change of state in a file descriptor, then a
61 call to poll or select will be made to detect it.
62
63 If the events generate signals, they are also queued by special
64 functions that are invoked through traditional signal handlers.
65 The actions to be taken is response to such events will be executed
66 when the SIGHANDLER_LIST is scanned, the next time through the
371d5dec 67 infinite loop.
b5a0ac70 68
371d5dec 69 Corollary tasks are the creation and deletion of event sources. */
b5a0ac70 70
97bb9d91 71typedef void *gdb_client_data;
c2c6d25f 72struct async_signal_handler;
50d01748 73struct async_event_handler;
2acceee2 74typedef void (handler_func) (int, gdb_client_data);
c2c6d25f 75typedef void (sig_handler_func) (gdb_client_data);
50d01748 76typedef void (async_event_handler_func) (gdb_client_data);
c2c6d25f 77typedef void (timer_handler_func) (gdb_client_data);
b5a0ac70 78
371d5dec 79/* Where to add an event onto the event queue, by queue_event. */
b5a0ac70
SS
80typedef enum
81 {
371d5dec
MS
82 /* Add at tail of queue. It will be processed in first in first
83 out order. */
b5a0ac70 84 TAIL,
371d5dec
MS
85 /* Add at head of queue. It will be processed in last in first
86 out order. */
c5aa993b 87 HEAD
b5a0ac70
SS
88 }
89queue_position;
90
085dd6e6 91/* Exported functions from event-loop.c */
0f71a2f6 92
c2c6d25f 93extern void start_event_loop (void);
99656a61 94extern int gdb_do_one_event (void *data);
c2c6d25f 95extern void delete_file_handler (int fd);
371d5dec
MS
96extern void add_file_handler (int fd, handler_func *proc,
97 gdb_client_data client_data);
6426a772 98extern struct async_signal_handler *
371d5dec
MS
99 create_async_signal_handler (sig_handler_func *proc,
100 gdb_client_data client_data);
3e43a32a 101extern void delete_async_signal_handler (struct async_signal_handler **);
371d5dec
MS
102extern int create_timer (int milliseconds,
103 timer_handler_func *proc,
104 gdb_client_data client_data);
c2c6d25f 105extern void delete_timer (int id);
b803fb0f
DJ
106
107/* Call the handler from HANDLER immediately. This function
108 runs signal handlers when returning to the event loop would be too
109 slow. Do not call this directly; use gdb_call_async_signal_handler,
110 below, with IMMEDIATE_P == 1. */
111void call_async_signal_handler (struct async_signal_handler *handler);
112
113/* Call the handler from HANDLER the next time through the event loop.
114 Do not call this directly; use gdb_call_async_signal_handler,
115 below, with IMMEDIATE_P == 0. */
116void mark_async_signal_handler (struct async_signal_handler *handler);
117
118/* Wrapper for the body of signal handlers. Call this function from
119 any SIGINT handler which needs to access GDB data structures or
120 escape via longjmp. If IMMEDIATE_P is set, this triggers either
121 immediately (for POSIX platforms), or from gdb_select (for
122 MinGW). If IMMEDIATE_P is clear, the handler will run the next
123 time we return to the event loop and any current select calls
124 will be interrupted. */
125
126void gdb_call_async_signal_handler (struct async_signal_handler *handler,
127 int immediate_p);
50d01748
PA
128
129/* Create and register an asynchronous event source in the event loop,
130 and set PROC as its callback. CLIENT_DATA is passed as argument to
131 PROC upon its invocation. Returns a pointer to an opaque structure
132 used to mark as ready and to later delete this event source from
133 the event loop. */
134extern struct async_event_handler *
135 create_async_event_handler (async_event_handler_func *proc,
136 gdb_client_data client_data);
137
138/* Remove the event source pointed by HANDLER_PTR created by
139 CREATE_ASYNC_EVENT_HANDLER from the event loop, and release it. */
140extern void
141 delete_async_event_handler (struct async_event_handler **handler_ptr);
142
143/* Call the handler from HANDLER the next time through the event
144 loop. */
145extern void mark_async_event_handler (struct async_event_handler *handler);