Forgot to add these files in the previous commit. This is the
[deliverable/binutils-gdb.git] / gdb / inf-loop.c
CommitLineData
2acceee2
JM
1/* Handling of inferior events for the event loop for GDB, the GNU debugger.
2 Copyright 1999 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22#include "defs.h"
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"
27#include "inf-loop.h"
28
29static int fetch_inferior_event_wrapper (gdb_client_data client_data);
30static void complete_execution (void);
31
32/* General function to handle events in the inferior. So far it just
33 takes care of detecting errors reported by select() or poll(),
34 otherwise it assumes that all is OK, and goes on reading data from
35 the fd. This however may not always be what we want to do. */
36void
37inferior_event_handler (enum inferior_event_type event_type,
38 gdb_client_data client_data)
39{
40 switch (event_type)
41 {
42 case INF_ERROR:
43 printf_unfiltered ("error detected from target.\n");
44 target_async (NULL, 0);
45 pop_target ();
46 discard_all_continuations ();
47 do_exec_error_cleanups (ALL_CLEANUPS);
48 break;
49
50 case INF_REG_EVENT:
51 /* Use catch errors for now, until the inner layers of
52 fetch_inferior_event (i.e. readchar) can return meaningful
53 error status. If an error occurs while getting an event from
54 the target, just get rid of the target. */
55 if (!catch_errors (fetch_inferior_event_wrapper,
56 client_data, "", RETURN_MASK_ALL))
57 {
58 target_async (NULL, 0);
59 pop_target ();
60 discard_all_continuations ();
61 do_exec_error_cleanups (ALL_CLEANUPS);
62 display_gdb_prompt (0);
63 }
64 break;
65
66 case INF_EXEC_COMPLETE:
67 /* Is there anything left to do for the command issued to
68 complete? */
69 do_all_continuations ();
70 /* Reset things after target has stopped for the async commands. */
71 complete_execution ();
72 break;
73
74 case INF_QUIT_REQ:
75 case INF_TIMER:
76 default:
77 printf_unfiltered ("Event type not recognized.\n");
78 break;
79 }
80}
81
82static int
83fetch_inferior_event_wrapper (gdb_client_data client_data)
84{
85 fetch_inferior_event (client_data);
86 return 1;
87}
88
89/* Reset proper settings after an asynchronous command has finished.
90 If the execution command was in synchronous mode, register stdin
91 with the event loop, and reset the prompt. */
92
93static void
94complete_execution (void)
95{
96 target_executing = 0;
97
98 /* Unregister the inferior from the event loop. This is done so that
99 when the inferior is not running we don't get distracted by
100 spurious inferior output. */
101 target_async (NULL, 0);
102
103 if (sync_execution)
104 {
105 do_exec_error_cleanups (ALL_CLEANUPS);
106 display_gdb_prompt (0);
107 }
108 else
109 {
110 if (exec_done_display_p)
111 printf_unfiltered ("completed.\n");
112 }
113}
This page took 0.0270550000000001 seconds and 4 git commands to generate.