1 /* Handling of inferior events for the event loop for GDB, the GNU debugger.
2 Copyright (C) 1999, 2007 Free Software Foundation, Inc.
3 Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
5 This file is part of GDB.
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.
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.
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. */
23 #include "inferior.h" /* For fetch_inferior_event. */
24 #include "target.h" /* For enum inferior_event_type. */
25 #include "event-loop.h"
26 #include "event-top.h"
29 #include "exceptions.h"
31 static int fetch_inferior_event_wrapper (gdb_client_data client_data
);
32 static void complete_execution (void);
35 inferior_event_handler_wrapper (gdb_client_data client_data
)
37 inferior_event_handler (INF_QUIT_REQ
, client_data
);
40 /* General function to handle events in the inferior. So far it just
41 takes care of detecting errors reported by select() or poll(),
42 otherwise it assumes that all is OK, and goes on reading data from
43 the fd. This however may not always be what we want to do. */
45 inferior_event_handler (enum inferior_event_type event_type
,
46 gdb_client_data client_data
)
51 printf_unfiltered (_("error detected from target.\n"));
52 target_async (NULL
, 0);
54 discard_all_continuations ();
55 do_exec_error_cleanups (ALL_CLEANUPS
);
59 /* Use catch errors for now, until the inner layers of
60 fetch_inferior_event (i.e. readchar) can return meaningful
61 error status. If an error occurs while getting an event from
62 the target, just get rid of the target. */
63 if (!catch_errors (fetch_inferior_event_wrapper
,
64 client_data
, "", RETURN_MASK_ALL
))
66 target_async (NULL
, 0);
68 discard_all_continuations ();
69 do_exec_error_cleanups (ALL_CLEANUPS
);
70 display_gdb_prompt (0);
74 case INF_EXEC_COMPLETE
:
75 /* Is there anything left to do for the command issued to
77 do_all_continuations ();
78 /* Reset things after target has stopped for the async commands. */
79 complete_execution ();
82 case INF_EXEC_CONTINUE
:
83 /* Is there anything left to do for the command issued to
85 do_all_intermediate_continuations ();
89 /* FIXME: ezannoni 1999-10-04. This call should really be a
90 target vector entry, so that it can be used for any kind of
92 async_remote_interrupt_twice (NULL
);
97 printf_unfiltered (_("Event type not recognized.\n"));
103 fetch_inferior_event_wrapper (gdb_client_data client_data
)
105 fetch_inferior_event (client_data
);
109 /* Reset proper settings after an asynchronous command has finished.
110 If the execution command was in synchronous mode, register stdin
111 with the event loop, and reset the prompt. */
114 complete_execution (void)
116 target_executing
= 0;
118 /* Unregister the inferior from the event loop. This is done so that
119 when the inferior is not running we don't get distracted by
120 spurious inferior output. */
121 target_async (NULL
, 0);
125 do_exec_error_cleanups (ALL_CLEANUPS
);
126 display_gdb_prompt (0);
130 if (exec_done_display_p
)
131 printf_unfiltered (_("completed.\n"));