GDB (API)
|
00001 /* Definitions used by the GDB event loop. 00002 Copyright (C) 1999-2013 Free Software Foundation, Inc. 00003 Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 /* An event loop listens for events from multiple event sources. When 00021 an event arrives, it is queued and processed by calling the 00022 appropriate event handler. The event loop then continues to listen 00023 for more events. An event loop completes when there are no event 00024 sources to listen on. External event sources can be plugged into 00025 the loop. 00026 00027 There are 4 main components: 00028 - a list of file descriptors to be monitored, GDB_NOTIFIER. 00029 - a list of asynchronous event sources to be monitored, 00030 ASYNC_EVENT_HANDLER_LIST. 00031 - a list of events that have occurred, EVENT_QUEUE. 00032 - a list of signal handling functions, SIGHANDLER_LIST. 00033 00034 GDB_NOTIFIER keeps track of the file descriptor based event 00035 sources. ASYNC_EVENT_HANDLER_LIST keeps track of asynchronous 00036 event sources that are signalled by some component of gdb, usually 00037 a target_ops instance. Event sources for gdb are currently the UI 00038 and the target. Gdb communicates with the command line user 00039 interface via the readline library and usually communicates with 00040 remote targets via a serial port. Serial ports are represented in 00041 GDB as file descriptors and select/poll calls. For native targets 00042 instead, the communication varies across operating system debug 00043 APIs, but usually consists of calls to ptrace and waits (via 00044 signals) or calls to poll/select (via file descriptors). In the 00045 current gdb, the code handling events related to the target resides 00046 in wait_for_inferior for synchronous targets; or, for asynchronous 00047 capable targets, by having the target register either a target 00048 controlled file descriptor and/or an asynchronous event source in 00049 the event loop, with the fetch_inferior_event function as the event 00050 callback. In both the synchronous and asynchronous cases, usually 00051 the target event is collected through the target_wait interface. 00052 The target is free to install other event sources in the event loop 00053 if it so requires. 00054 00055 EVENT_QUEUE keeps track of the events that have happened during the 00056 last iteration of the event loop, and need to be processed. An 00057 event is represented by a procedure to be invoked in order to 00058 process the event. The queue is scanned head to tail. If the 00059 event of interest is a change of state in a file descriptor, then a 00060 call to poll or select will be made to detect it. 00061 00062 If the events generate signals, they are also queued by special 00063 functions that are invoked through traditional signal handlers. 00064 The actions to be taken is response to such events will be executed 00065 when the SIGHANDLER_LIST is scanned, the next time through the 00066 infinite loop. 00067 00068 Corollary tasks are the creation and deletion of event sources. */ 00069 00070 typedef void *gdb_client_data; 00071 struct async_signal_handler; 00072 struct async_event_handler; 00073 typedef void (handler_func) (int, gdb_client_data); 00074 typedef void (sig_handler_func) (gdb_client_data); 00075 typedef void (async_event_handler_func) (gdb_client_data); 00076 typedef void (timer_handler_func) (gdb_client_data); 00077 00078 /* Exported functions from event-loop.c */ 00079 00080 extern void initialize_event_loop (void); 00081 extern void start_event_loop (void); 00082 extern int gdb_do_one_event (void); 00083 extern void delete_file_handler (int fd); 00084 extern void add_file_handler (int fd, handler_func *proc, 00085 gdb_client_data client_data); 00086 extern struct async_signal_handler * 00087 create_async_signal_handler (sig_handler_func *proc, 00088 gdb_client_data client_data); 00089 extern void delete_async_signal_handler (struct async_signal_handler **); 00090 extern int create_timer (int milliseconds, 00091 timer_handler_func *proc, 00092 gdb_client_data client_data); 00093 extern void delete_timer (int id); 00094 00095 /* Call the handler from HANDLER immediately. This function 00096 runs signal handlers when returning to the event loop would be too 00097 slow. Do not call this directly; use gdb_call_async_signal_handler, 00098 below, with IMMEDIATE_P == 1. */ 00099 void call_async_signal_handler (struct async_signal_handler *handler); 00100 00101 /* Call the handler from HANDLER the next time through the event loop. 00102 Do not call this directly; use gdb_call_async_signal_handler, 00103 below, with IMMEDIATE_P == 0. */ 00104 void mark_async_signal_handler (struct async_signal_handler *handler); 00105 00106 /* Wrapper for the body of signal handlers. Call this function from 00107 any SIGINT handler which needs to access GDB data structures or 00108 escape via longjmp. If IMMEDIATE_P is set, this triggers either 00109 immediately (for POSIX platforms), or from gdb_select (for 00110 MinGW). If IMMEDIATE_P is clear, the handler will run the next 00111 time we return to the event loop and any current select calls 00112 will be interrupted. */ 00113 00114 void gdb_call_async_signal_handler (struct async_signal_handler *handler, 00115 int immediate_p); 00116 00117 /* Create and register an asynchronous event source in the event loop, 00118 and set PROC as its callback. CLIENT_DATA is passed as argument to 00119 PROC upon its invocation. Returns a pointer to an opaque structure 00120 used to mark as ready and to later delete this event source from 00121 the event loop. */ 00122 extern struct async_event_handler * 00123 create_async_event_handler (async_event_handler_func *proc, 00124 gdb_client_data client_data); 00125 00126 /* Remove the event source pointed by HANDLER_PTR created by 00127 CREATE_ASYNC_EVENT_HANDLER from the event loop, and release it. */ 00128 extern void 00129 delete_async_event_handler (struct async_event_handler **handler_ptr); 00130 00131 /* Call the handler from HANDLER the next time through the event 00132 loop. */ 00133 extern void mark_async_event_handler (struct async_event_handler *handler);