1*b725ae77Skettenis /* Definitions used by the GDB event loop. 2*b725ae77Skettenis Copyright 1999, 2000 Free Software Foundation, Inc. 3*b725ae77Skettenis Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions. 4*b725ae77Skettenis 5*b725ae77Skettenis This file is part of GDB. 6*b725ae77Skettenis 7*b725ae77Skettenis This program is free software; you can redistribute it and/or modify 8*b725ae77Skettenis it under the terms of the GNU General Public License as published by 9*b725ae77Skettenis the Free Software Foundation; either version 2 of the License, or 10*b725ae77Skettenis (at your option) any later version. 11*b725ae77Skettenis 12*b725ae77Skettenis This program is distributed in the hope that it will be useful, 13*b725ae77Skettenis but WITHOUT ANY WARRANTY; without even the implied warranty of 14*b725ae77Skettenis MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*b725ae77Skettenis GNU General Public License for more details. 16*b725ae77Skettenis 17*b725ae77Skettenis You should have received a copy of the GNU General Public License 18*b725ae77Skettenis along with this program; if not, write to the Free Software 19*b725ae77Skettenis Foundation, Inc., 59 Temple Place - Suite 330, 20*b725ae77Skettenis Boston, MA 02111-1307, USA. */ 21*b725ae77Skettenis 22*b725ae77Skettenis /* An event loop listens for events from multiple event sources. When 23*b725ae77Skettenis an event arrives, it is queued and processed by calling the 24*b725ae77Skettenis appropriate event handler. The event loop then continues to listen 25*b725ae77Skettenis for more events. An event loop completes when there are no event 26*b725ae77Skettenis sources to listen on. External event sources can be plugged into 27*b725ae77Skettenis the loop. 28*b725ae77Skettenis 29*b725ae77Skettenis There are 3 main components: 30*b725ae77Skettenis - a list of file descriptors to be monitored, GDB_NOTIFIER. 31*b725ae77Skettenis - a list of events that have occurred, EVENT_QUEUE. 32*b725ae77Skettenis - a list of signal handling functions, SIGHANDLER_LIST. 33*b725ae77Skettenis 34*b725ae77Skettenis GDB_NOTIFIER keeps track of the event sources. Event sources for 35*b725ae77Skettenis gdb are currently the UI and the target. Gdb communicates with the 36*b725ae77Skettenis command line user interface via the readline library and usually 37*b725ae77Skettenis communicates with remote targets via a serial port. Serial ports 38*b725ae77Skettenis are represented in GDB as file descriptors and select/poll calls. 39*b725ae77Skettenis For native targets instead, the communication consists of calls to 40*b725ae77Skettenis ptrace and waits (via signals) or calls to poll/select (via file 41*b725ae77Skettenis descriptors). In the current gdb, the code handling events related 42*b725ae77Skettenis to the target resides in the wait_for_inferior function and in 43*b725ae77Skettenis various target specific files (*-tdep.c). 44*b725ae77Skettenis 45*b725ae77Skettenis EVENT_QUEUE keeps track of the events that have happened during the 46*b725ae77Skettenis last iteration of the event loop, and need to be processed. An 47*b725ae77Skettenis event is represented by a procedure to be invoked in order to 48*b725ae77Skettenis process the event. The queue is scanned head to tail. If the 49*b725ae77Skettenis event of interest is a change of state in a file descriptor, then a 50*b725ae77Skettenis call to poll or select will be made to detect it. 51*b725ae77Skettenis 52*b725ae77Skettenis If the events generate signals, they are also queued by special 53*b725ae77Skettenis functions that are invoked through traditional signal handlers. 54*b725ae77Skettenis The actions to be taken is response to such events will be executed 55*b725ae77Skettenis when the SIGHANDLER_LIST is scanned, the next time through the 56*b725ae77Skettenis infinite loop. 57*b725ae77Skettenis 58*b725ae77Skettenis Corollary tasks are the creation and deletion of event sources. */ 59*b725ae77Skettenis 60*b725ae77Skettenis typedef void *gdb_client_data; 61*b725ae77Skettenis struct async_signal_handler; 62*b725ae77Skettenis typedef void (handler_func) (int, gdb_client_data); 63*b725ae77Skettenis typedef void (sig_handler_func) (gdb_client_data); 64*b725ae77Skettenis typedef void (timer_handler_func) (gdb_client_data); 65*b725ae77Skettenis 66*b725ae77Skettenis /* Where to add an event onto the event queue, by queue_event. */ 67*b725ae77Skettenis typedef enum 68*b725ae77Skettenis { 69*b725ae77Skettenis /* Add at tail of queue. It will be processed in first in first 70*b725ae77Skettenis out order. */ 71*b725ae77Skettenis TAIL, 72*b725ae77Skettenis /* Add at head of queue. It will be processed in last in first out 73*b725ae77Skettenis order. */ 74*b725ae77Skettenis HEAD 75*b725ae77Skettenis } 76*b725ae77Skettenis queue_position; 77*b725ae77Skettenis 78*b725ae77Skettenis /* Tell create_file_handler what events we are interested in. 79*b725ae77Skettenis This is used by the select version of the event loop. */ 80*b725ae77Skettenis 81*b725ae77Skettenis #define GDB_READABLE (1<<1) 82*b725ae77Skettenis #define GDB_WRITABLE (1<<2) 83*b725ae77Skettenis #define GDB_EXCEPTION (1<<3) 84*b725ae77Skettenis 85*b725ae77Skettenis /* Exported functions from event-loop.c */ 86*b725ae77Skettenis 87*b725ae77Skettenis extern void start_event_loop (void); 88*b725ae77Skettenis extern int gdb_do_one_event (void *data); 89*b725ae77Skettenis extern void delete_file_handler (int fd); 90*b725ae77Skettenis extern void add_file_handler (int fd, handler_func * proc, gdb_client_data client_data); 91*b725ae77Skettenis extern void mark_async_signal_handler (struct async_signal_handler *async_handler_ptr); 92*b725ae77Skettenis extern struct async_signal_handler * 93*b725ae77Skettenis create_async_signal_handler (sig_handler_func * proc, gdb_client_data client_data); 94*b725ae77Skettenis extern void delete_async_signal_handler (struct async_signal_handler **async_handler_ptr); 95*b725ae77Skettenis extern int create_timer (int milliseconds, timer_handler_func * proc, gdb_client_data client_data); 96*b725ae77Skettenis extern void delete_timer (int id); 97