event-loop.h revision 130803
198944Sobrien/* Definitions used by the GDB event loop. 298944Sobrien Copyright 1999, 2000 Free Software Foundation, Inc. 398944Sobrien Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions. 498944Sobrien 598944Sobrien This file is part of GDB. 698944Sobrien 798944Sobrien This program is free software; you can redistribute it and/or modify 898944Sobrien it under the terms of the GNU General Public License as published by 998944Sobrien the Free Software Foundation; either version 2 of the License, or 1098944Sobrien (at your option) any later version. 1198944Sobrien 1298944Sobrien This program is distributed in the hope that it will be useful, 1398944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1498944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1598944Sobrien GNU General Public License for more details. 1698944Sobrien 1798944Sobrien You should have received a copy of the GNU General Public License 1898944Sobrien along with this program; if not, write to the Free Software 1998944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2098944Sobrien Boston, MA 02111-1307, USA. */ 2198944Sobrien 2298944Sobrien/* An event loop listens for events from multiple event sources. When 2398944Sobrien an event arrives, it is queued and processed by calling the 2498944Sobrien appropriate event handler. The event loop then continues to listen 2598944Sobrien for more events. An event loop completes when there are no event 2698944Sobrien sources to listen on. External event sources can be plugged into 2798944Sobrien the loop. 2898944Sobrien 2998944Sobrien There are 3 main components: 3098944Sobrien - a list of file descriptors to be monitored, GDB_NOTIFIER. 3198944Sobrien - a list of events that have occurred, EVENT_QUEUE. 3298944Sobrien - a list of signal handling functions, SIGHANDLER_LIST. 3398944Sobrien 3498944Sobrien GDB_NOTIFIER keeps track of the event sources. Event sources for 3598944Sobrien gdb are currently the UI and the target. Gdb communicates with the 3698944Sobrien command line user interface via the readline library and usually 3798944Sobrien communicates with remote targets via a serial port. Serial ports 3898944Sobrien are represented in GDB as file descriptors and select/poll calls. 3998944Sobrien For native targets instead, the communication consists of calls to 4098944Sobrien ptrace and waits (via signals) or calls to poll/select (via file 4198944Sobrien descriptors). In the current gdb, the code handling events related 4298944Sobrien to the target resides in the wait_for_inferior function and in 4398944Sobrien various target specific files (*-tdep.c). 4498944Sobrien 4598944Sobrien EVENT_QUEUE keeps track of the events that have happened during the 4698944Sobrien last iteration of the event loop, and need to be processed. An 4798944Sobrien event is represented by a procedure to be invoked in order to 4898944Sobrien process the event. The queue is scanned head to tail. If the 4998944Sobrien event of interest is a change of state in a file descriptor, then a 5098944Sobrien call to poll or select will be made to detect it. 5198944Sobrien 5298944Sobrien If the events generate signals, they are also queued by special 5398944Sobrien functions that are invoked through traditional signal handlers. 5498944Sobrien The actions to be taken is response to such events will be executed 5598944Sobrien when the SIGHANDLER_LIST is scanned, the next time through the 5698944Sobrien infinite loop. 5798944Sobrien 5898944Sobrien Corollary tasks are the creation and deletion of event sources. */ 5998944Sobrien 6098944Sobrientypedef void *gdb_client_data; 6198944Sobrienstruct async_signal_handler; 6298944Sobrientypedef void (handler_func) (int, gdb_client_data); 6398944Sobrientypedef void (sig_handler_func) (gdb_client_data); 6498944Sobrientypedef void (timer_handler_func) (gdb_client_data); 6598944Sobrien 6698944Sobrien/* Where to add an event onto the event queue, by queue_event. */ 6798944Sobrientypedef enum 6898944Sobrien { 6998944Sobrien /* Add at tail of queue. It will be processed in first in first 7098944Sobrien out order. */ 7198944Sobrien TAIL, 7298944Sobrien /* Add at head of queue. It will be processed in last in first out 7398944Sobrien order. */ 7498944Sobrien HEAD 7598944Sobrien } 7698944Sobrienqueue_position; 7798944Sobrien 7898944Sobrien/* Tell create_file_handler what events we are interested in. 7998944Sobrien This is used by the select version of the event loop. */ 8098944Sobrien 8198944Sobrien#define GDB_READABLE (1<<1) 8298944Sobrien#define GDB_WRITABLE (1<<2) 8398944Sobrien#define GDB_EXCEPTION (1<<3) 8498944Sobrien 8598944Sobrien/* Exported functions from event-loop.c */ 8698944Sobrien 8798944Sobrienextern void start_event_loop (void); 88130803Smarcelextern int gdb_do_one_event (void *data); 8998944Sobrienextern void delete_file_handler (int fd); 9098944Sobrienextern void add_file_handler (int fd, handler_func * proc, gdb_client_data client_data); 9198944Sobrienextern void mark_async_signal_handler (struct async_signal_handler *async_handler_ptr); 9298944Sobrienextern struct async_signal_handler * 9398944Sobrien create_async_signal_handler (sig_handler_func * proc, gdb_client_data client_data); 9498944Sobrienextern void delete_async_signal_handler (struct async_signal_handler **async_handler_ptr); 9598944Sobrienextern int create_timer (int milliseconds, timer_handler_func * proc, gdb_client_data client_data); 9698944Sobrienextern void delete_timer (int id); 97