| 1 | /* Definitions used by the GDB event loop. |
| 2 | Copyright (C) 1999, 2000, 2007 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 2 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, write to the Free Software |
| 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 | Boston, MA 02110-1301, USA. */ |
| 21 | |
| 22 | /* An event loop listens for events from multiple event sources. When |
| 23 | an event arrives, it is queued and processed by calling the |
| 24 | appropriate event handler. The event loop then continues to listen |
| 25 | for more events. An event loop completes when there are no event |
| 26 | sources to listen on. External event sources can be plugged into |
| 27 | the loop. |
| 28 | |
| 29 | There are 3 main components: |
| 30 | - a list of file descriptors to be monitored, GDB_NOTIFIER. |
| 31 | - a list of events that have occurred, EVENT_QUEUE. |
| 32 | - a list of signal handling functions, SIGHANDLER_LIST. |
| 33 | |
| 34 | GDB_NOTIFIER keeps track of the event sources. Event sources for |
| 35 | gdb are currently the UI and the target. Gdb communicates with the |
| 36 | command line user interface via the readline library and usually |
| 37 | communicates with remote targets via a serial port. Serial ports |
| 38 | are represented in GDB as file descriptors and select/poll calls. |
| 39 | For native targets instead, the communication consists of calls to |
| 40 | ptrace and waits (via signals) or calls to poll/select (via file |
| 41 | descriptors). In the current gdb, the code handling events related |
| 42 | to the target resides in the wait_for_inferior function and in |
| 43 | various target specific files (*-tdep.c). |
| 44 | |
| 45 | EVENT_QUEUE keeps track of the events that have happened during the |
| 46 | last iteration of the event loop, and need to be processed. An |
| 47 | event is represented by a procedure to be invoked in order to |
| 48 | process the event. The queue is scanned head to tail. If the |
| 49 | event of interest is a change of state in a file descriptor, then a |
| 50 | call to poll or select will be made to detect it. |
| 51 | |
| 52 | If the events generate signals, they are also queued by special |
| 53 | functions that are invoked through traditional signal handlers. |
| 54 | The actions to be taken is response to such events will be executed |
| 55 | when the SIGHANDLER_LIST is scanned, the next time through the |
| 56 | infinite loop. |
| 57 | |
| 58 | Corollary tasks are the creation and deletion of event sources. */ |
| 59 | |
| 60 | typedef void *gdb_client_data; |
| 61 | struct async_signal_handler; |
| 62 | typedef void (handler_func) (int, gdb_client_data); |
| 63 | typedef void (sig_handler_func) (gdb_client_data); |
| 64 | typedef void (timer_handler_func) (gdb_client_data); |
| 65 | |
| 66 | /* Where to add an event onto the event queue, by queue_event. */ |
| 67 | typedef enum |
| 68 | { |
| 69 | /* Add at tail of queue. It will be processed in first in first |
| 70 | out order. */ |
| 71 | TAIL, |
| 72 | /* Add at head of queue. It will be processed in last in first out |
| 73 | order. */ |
| 74 | HEAD |
| 75 | } |
| 76 | queue_position; |
| 77 | |
| 78 | /* Tell create_file_handler what events we are interested in. |
| 79 | This is used by the select version of the event loop. */ |
| 80 | |
| 81 | #define GDB_READABLE (1<<1) |
| 82 | #define GDB_WRITABLE (1<<2) |
| 83 | #define GDB_EXCEPTION (1<<3) |
| 84 | |
| 85 | /* Exported functions from event-loop.c */ |
| 86 | |
| 87 | extern void start_event_loop (void); |
| 88 | extern int gdb_do_one_event (void *data); |
| 89 | extern void delete_file_handler (int fd); |
| 90 | extern void add_file_handler (int fd, handler_func * proc, gdb_client_data client_data); |
| 91 | extern void mark_async_signal_handler (struct async_signal_handler *async_handler_ptr); |
| 92 | extern struct async_signal_handler * |
| 93 | create_async_signal_handler (sig_handler_func * proc, gdb_client_data client_data); |
| 94 | extern void delete_async_signal_handler (struct async_signal_handler **async_handler_ptr); |
| 95 | extern int create_timer (int milliseconds, timer_handler_func * proc, gdb_client_data client_data); |
| 96 | extern void delete_timer (int id); |