Handle UI's terminal closing
[external/binutils.git] / gdb / top.h
1 /* Top level stuff for GDB, the GNU debugger.
2
3    Copyright (C) 1986-2016 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.  */
19
20 #ifndef TOP_H
21 #define TOP_H
22
23 #include "buffer.h"
24 #include "event-loop.h"
25
26 struct tl_interp_info;
27
28 /* Prompt state.  */
29
30 enum prompt_state
31 {
32   /* The command line is blocked simulating synchronous execution.
33      This is used to implement the foreground execution commands
34      ('run', 'continue', etc.).  We won't display the prompt and
35      accept further commands until the execution is actually over.  */
36   PROMPT_BLOCKED,
37
38   /* The command finished; display the prompt before returning back to
39      the top level.  */
40   PROMPT_NEEDED,
41
42   /* We've displayed the prompt already, ready for input.  */
43   PROMPTED,
44 };
45
46 /* All about a user interface instance.  Each user interface has its
47    own I/O files/streams, readline state, its own top level
48    interpreter (for the main UI, this is the interpreter specified
49    with -i on the command line) and secondary interpreters (for
50    interpreter-exec ...), etc.  There's always one UI associated with
51    stdin/stdout/stderr, but the user can create secondary UIs, for
52    example, to create a separate MI channel on its own stdio
53    streams.  */
54
55 struct ui
56 {
57   /* Pointer to next in singly-linked list.  */
58   struct ui *next;
59
60   /* Convenient handle (UI number).  Unique across all UIs.  */
61   int num;
62
63   /* The UI's command line buffer.  This is to used to accumulate
64      input until we have a whole command line.  */
65   struct buffer line_buffer;
66
67   /* The callback used by the event loop whenever an event is detected
68      on the UI's input file descriptor.  This function incrementally
69      builds a buffer where it accumulates the line read up to the
70      point of invocation.  In the special case in which the character
71      read is newline, the function invokes the INPUT_HANDLER callback
72      (see below).  */
73   void (*call_readline) (gdb_client_data);
74
75   /* The function to invoke when a complete line of input is ready for
76      processing.  */
77   void (*input_handler) (char *);
78
79   /* True if this UI is using the readline library for command
80      editing; false if using GDB's own simple readline emulation, with
81      no editing support.  */
82   int command_editing;
83
84   /* Each UI has its own independent set of interpreters.  */
85   struct ui_interp_info *interp_info;
86
87   /* True if the UI is in async mode, false if in sync mode.  If in
88      sync mode, a synchronous execution command (e.g, "next") does not
89      return until the command is finished.  If in async mode, then
90      running a synchronous command returns right after resuming the
91      target.  Waiting for the command's completion is later done on
92      the top event loop.  For the main UI, this starts out disabled,
93      until all the explicit command line arguments (e.g., `gdb -ex
94      "start" -ex "next"') are processed.  */
95   int async;
96
97   /* The number of nested readline secondary prompts that are
98      currently active.  */
99   int secondary_prompt_depth;
100
101   /* stdio stream that command input is being read from.  Set to stdin
102      normally.  Set by source_command to the file we are sourcing.
103      Set to NULL if we are executing a user-defined command or
104      interacting via a GUI.  */
105   FILE *instream;
106   /* Standard output stream.  */
107   FILE *outstream;
108   /* Standard error stream.  */
109   FILE *errstream;
110
111   /* The file descriptor for the input stream, so that we can register
112      it with the event loop.  */
113   int input_fd;
114
115   /* See enum prompt_state's description.  */
116   enum prompt_state prompt_state;
117
118   /* The fields below that start with "m_" are "private".  They're
119      meant to be accessed through wrapper macros that make them look
120      like globals.  */
121
122   /* The ui_file streams.  */
123   /* Normal results */
124   struct ui_file *m_gdb_stdout;
125   /* Input stream */
126   struct ui_file *m_gdb_stdin;
127   /* Serious error notifications */
128   struct ui_file *m_gdb_stderr;
129   /* Log/debug/trace messages that should bypass normal stdout/stderr
130      filtering.  For moment, always call this stream using
131      *_unfiltered.  In the very near future that restriction shall be
132      removed - either call shall be unfiltered.  (cagney 1999-06-13).  */
133   struct ui_file *m_gdb_stdlog;
134
135   /* The current ui_out.  */
136   struct ui_out *m_current_uiout;
137 };
138
139 /* The main UI.  This is the UI that is bound to stdin/stdout/stderr.
140    It always exists and is created automatically when GDB starts
141    up.  */
142 extern struct ui *main_ui;
143
144 /* The current UI.  */
145 extern struct ui *current_ui;
146
147 /* The list of all UIs.  */
148 extern struct ui *ui_list;
149
150 /* State for SWITCH_THRU_ALL_UIS.  Declared here because it is meant
151    to be created on the stack, but should be treated as opaque.  */
152 struct switch_thru_all_uis
153 {
154   struct ui *iter;
155   struct cleanup *old_chain;
156 };
157
158 /* Functions to drive SWITCH_THRU_ALL_UIS.  Though declared here by
159    necessity, these functions should not be used other than via the
160    SWITCH_THRU_ALL_UIS macro defined below.  */
161 extern void switch_thru_all_uis_init (struct switch_thru_all_uis *state);
162 extern int switch_thru_all_uis_cond (struct switch_thru_all_uis *state);
163 extern void switch_thru_all_uis_next (struct switch_thru_all_uis *state);
164
165   /* Traverse through all UI, and switch the current UI to the one
166      being iterated.  */
167 #define SWITCH_THRU_ALL_UIS(STATE)              \
168   for (switch_thru_all_uis_init (&STATE);               \
169        switch_thru_all_uis_cond (&STATE);               \
170        switch_thru_all_uis_next (&STATE))
171
172 /* Traverse over all UIs.  */
173 #define ALL_UIS(UI)                             \
174   for (UI = ui_list; UI; UI = UI->next)         \
175
176 /* Create a new UI.  */
177 extern struct ui *new_ui (FILE *instream, FILE *outstream, FILE *errstream);
178 extern void delete_ui (struct ui *todel);
179
180 /* Cleanup that restores the current UI.  */
181 extern void restore_ui_cleanup (void *data);
182
183 /* From top.c.  */
184 extern char *saved_command_line;
185 extern int in_user_command;
186 extern int confirm;
187 extern char gdb_dirbuf[1024];
188 extern int inhibit_gdbinit;
189 extern const char gdbinit[];
190
191 extern void print_gdb_version (struct ui_file *);
192 extern void print_gdb_configuration (struct ui_file *);
193
194 extern void read_command_file (FILE *);
195 extern void init_history (void);
196 extern void command_loop (void);
197 extern int quit_confirm (void);
198 extern void quit_force (char *, int);
199 extern void quit_command (char *, int);
200 extern void quit_cover (void);
201 extern void execute_command (char *, int);
202
203 /* If the interpreter is in sync mode (we're running a user command's
204    list, running command hooks or similars), and we just ran a
205    synchronous command that started the target, wait for that command
206    to end.  WAS_SYNC indicates whether sync_execution was set before
207    the command was run.  */
208
209 extern void maybe_wait_sync_command_done (int was_sync);
210
211 /* Wait for a synchronous execution command to end.  */
212 extern void wait_sync_command_done (void);
213
214 extern void check_frame_language_change (void);
215
216 /* Prepare for execution of a command.
217    Call this before every command, CLI or MI.
218    Returns a cleanup to be run after the command is completed.  */
219 extern struct cleanup *prepare_execute_command (void);
220
221 /* This function returns a pointer to the string that is used
222    by gdb for its command prompt.  */
223 extern char *get_prompt (void);
224
225 /* This function returns a pointer to the string that is used
226    by gdb for its command prompt.  */
227 extern void set_prompt (const char *s);
228
229 /* Return 1 if UI's current input handler is a secondary prompt, 0
230    otherwise.  */
231
232 extern int gdb_in_secondary_prompt_p (struct ui *ui);
233
234 /* From random places.  */
235 extern int readnow_symbol_files;
236
237 /* Perform _initialize initialization.  */
238 extern void gdb_init (char *);
239
240 /* For use by event-top.c.  */
241 /* Variables from top.c.  */
242 extern int source_line_number;
243 extern const char *source_file_name;
244 extern int history_expansion_p;
245 extern int server_command;
246 extern char *lim_at_start;
247
248 extern void gdb_add_history (const char *);
249
250 extern void show_commands (char *args, int from_tty);
251
252 extern void set_history (char *, int);
253
254 extern void show_history (char *, int);
255
256 extern void set_verbose (char *, int, struct cmd_list_element *);
257
258 extern void do_restore_instream_cleanup (void *stream);
259
260 extern char *handle_line_of_input (struct buffer *cmd_line_buffer,
261                                    char *rl, int repeat,
262                                    char *annotation_suffix);
263
264 #endif