]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/top.h
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / top.h
CommitLineData
c906108c 1/* Top level stuff for GDB, the GNU debugger.
637537d0 2
213516ef 3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 19
17732724
AC
20#ifndef TOP_H
21#define TOP_H
22
268a13a5 23#include "gdbsupport/buffer.h"
400b5eca 24#include "gdbsupport/event-loop.h"
2dab0c7b 25#include "gdbsupport/next-iterator.h"
54f70bc1 26#include "value.h"
a74e1786 27
3b12939d
PA
28/* Prompt state. */
29
30enum 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
a74e1786
PA
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
55struct ui
56{
895b8f30
TT
57 /* Create a new UI. */
58 ui (FILE *instream, FILE *outstream, FILE *errstream);
59 ~ui ();
60
61 DISABLE_COPY_AND_ASSIGN (ui);
62
73ab01a0 63 /* Pointer to next in singly-linked list. */
d9f95811 64 struct ui *next = nullptr;
73ab01a0 65
2554f6f5
SM
66 /* Convenient handle (UI number). Unique across all UIs. */
67 int num;
68
a74e1786
PA
69 /* The UI's command line buffer. This is to used to accumulate
70 input until we have a whole command line. */
f8631e5e 71 std::string line_buffer;
a74e1786
PA
72
73 /* The callback used by the event loop whenever an event is detected
74 on the UI's input file descriptor. This function incrementally
75 builds a buffer where it accumulates the line read up to the
76 point of invocation. In the special case in which the character
77 read is newline, the function invokes the INPUT_HANDLER callback
78 (see below). */
d9f95811 79 void (*call_readline) (gdb_client_data) = nullptr;
a74e1786
PA
80
81 /* The function to invoke when a complete line of input is ready for
82 processing. */
d9f95811 83 void (*input_handler) (gdb::unique_xmalloc_ptr<char> &&) = nullptr;
79aa2fe8 84
3c216924
PA
85 /* True if this UI is using the readline library for command
86 editing; false if using GDB's own simple readline emulation, with
87 no editing support. */
d9f95811 88 int command_editing = 0;
3c216924 89
cb814510 90 /* Each UI has its own independent set of interpreters. */
d9f95811 91 struct ui_interp_info *interp_info = nullptr;
cb814510
PA
92
93 /* True if the UI is in async mode, false if in sync mode. If in
94 sync mode, a synchronous execution command (e.g, "next") does not
95 return until the command is finished. If in async mode, then
96 running a synchronous command returns right after resuming the
97 target. Waiting for the command's completion is later done on
98 the top event loop. For the main UI, this starts out disabled,
99 until all the explicit command line arguments (e.g., `gdb -ex
100 "start" -ex "next"') are processed. */
d9f95811 101 int async = 0;
cb814510 102
dbf30ca3
PA
103 /* The number of nested readline secondary prompts that are
104 currently active. */
d9f95811 105 int secondary_prompt_depth = 0;
dbf30ca3 106
268a799a
PA
107 /* The UI's stdin. Set to stdin for the main UI. */
108 FILE *stdin_stream;
109
f38d3ad1
PA
110 /* stdio stream that command input is being read from. Set to stdin
111 normally. Set by source_command to the file we are sourcing.
112 Set to NULL if we are executing a user-defined command or
113 interacting via a GUI. */
114 FILE *instream;
694ec099
PA
115 /* Standard output stream. */
116 FILE *outstream;
117 /* Standard error stream. */
118 FILE *errstream;
f38d3ad1 119
41fd2b0f 120 /* The file descriptor for the input stream, so that we can register
51cacdb5
TT
121 it with the event loop. This can be set to -1 to prevent this
122 registration. */
41fd2b0f
PA
123 int input_fd;
124
268a799a
PA
125 /* Whether ISATTY returns true on input_fd. Cached here because
126 quit_force needs to know this _after_ input_fd might be
127 closed. */
efd3baf0 128 bool m_input_interactive_p;
268a799a 129
3b12939d 130 /* See enum prompt_state's description. */
d9f95811 131 enum prompt_state prompt_state = PROMPT_NEEDED;
3b12939d 132
79aa2fe8
PA
133 /* The fields below that start with "m_" are "private". They're
134 meant to be accessed through wrapper macros that make them look
135 like globals. */
136
137 /* The ui_file streams. */
138 /* Normal results */
139 struct ui_file *m_gdb_stdout;
140 /* Input stream */
141 struct ui_file *m_gdb_stdin;
142 /* Serious error notifications */
143 struct ui_file *m_gdb_stderr;
144 /* Log/debug/trace messages that should bypass normal stdout/stderr
334c30c2 145 filtering. */
79aa2fe8 146 struct ui_file *m_gdb_stdlog;
b6dcde57
PA
147
148 /* The current ui_out. */
d9f95811 149 struct ui_out *m_current_uiout = nullptr;
8f7f9b3a
TT
150
151 /* Register the UI's input file descriptor in the event loop. */
152 void register_file_handler ();
153
154 /* Unregister the UI's input file descriptor from the event loop. */
155 void unregister_file_handler ();
efd3baf0
TT
156
157 /* Return true if this UI's input fd is a tty. */
158 bool input_interactive_p () const;
a74e1786
PA
159};
160
7c36c34e
PA
161/* The main UI. This is the UI that is bound to stdin/stdout/stderr.
162 It always exists and is created automatically when GDB starts
163 up. */
164extern struct ui *main_ui;
165
73ab01a0 166/* The current UI. */
a74e1786 167extern struct ui *current_ui;
b69d38af 168
73ab01a0
PA
169/* The list of all UIs. */
170extern struct ui *ui_list;
171
0e454242
TT
172/* State for SWITCH_THRU_ALL_UIS. */
173class switch_thru_all_uis
73ab01a0 174{
0e454242
TT
175public:
176
177 switch_thru_all_uis () : m_iter (ui_list), m_save_ui (&current_ui)
178 {
179 current_ui = ui_list;
180 }
181
1c3b85ad
LS
182 DISABLE_COPY_AND_ASSIGN (switch_thru_all_uis);
183
0e454242
TT
184 /* If done iterating, return true; otherwise return false. */
185 bool done () const
186 {
187 return m_iter == NULL;
188 }
189
190 /* Move to the next UI, setting current_ui if iteration is not yet
191 complete. */
192 void next ()
193 {
194 m_iter = m_iter->next;
195 if (m_iter != NULL)
196 current_ui = m_iter;
197 }
198
199 private:
200
0e454242
TT
201 /* Used to iterate through the UIs. */
202 struct ui *m_iter;
203
204 /* Save and restore current_ui. */
205 scoped_restore_tmpl<struct ui *> m_save_ui;
73ab01a0
PA
206};
207
73ab01a0
PA
208 /* Traverse through all UI, and switch the current UI to the one
209 being iterated. */
0e454242
TT
210#define SWITCH_THRU_ALL_UIS() \
211 for (switch_thru_all_uis stau_state; !stau_state.done (); stau_state.next ())
73ab01a0 212
9be25986
SM
213using ui_range = next_range<ui>;
214
2dab0c7b
TT
215/* An adapter that can be used to traverse over all UIs. */
216static inline
9be25986 217ui_range all_uis ()
2dab0c7b 218{
9be25986 219 return ui_range (ui_list);
2dab0c7b 220}
3b12939d 221
c906108c 222/* From top.c. */
491144b5 223extern bool confirm;
c906108c 224extern int inhibit_gdbinit;
c906108c 225
c61b06a1
TT
226/* Print the GDB version banner to STREAM. If INTERACTIVE is false,
227 then information referring to commands (e.g., "show configuration")
228 is omitted; this mode is used for the --version command line
229 option. If INTERACTIVE is true, then interactive commands are
230 mentioned. */
231extern void print_gdb_version (struct ui_file *stream, bool interactive);
232
6eaaf48b 233extern void print_gdb_configuration (struct ui_file *);
c906108c 234
a14ed312
KB
235extern void read_command_file (FILE *);
236extern void init_history (void);
237extern void command_loop (void);
a14ed312 238extern int quit_confirm (void);
36cf1806 239extern void quit_force (int *, int);
0b39b52e 240extern void quit_command (const char *, int);
b2cd6b29 241extern void quit_cover (void);
95a6b0a1 242extern void execute_command (const char *, int);
c906108c 243
98880d46
PA
244/* If the interpreter is in sync mode (we're running a user command's
245 list, running command hooks or similars), and we just ran a
246 synchronous command that started the target, wait for that command
247 to end. WAS_SYNC indicates whether sync_execution was set before
248 the command was run. */
249
250extern void maybe_wait_sync_command_done (int was_sync);
251
0b333c5e
PA
252/* Wait for a synchronous execution command to end. */
253extern void wait_sync_command_done (void);
254
77cce10f
PA
255extern void check_frame_language_change (void);
256
4e5d721f 257/* Prepare for execution of a command.
028d0ed5
TJB
258 Call this before every command, CLI or MI.
259 Returns a cleanup to be run after the command is completed. */
54f70bc1 260extern scoped_value_mark prepare_execute_command (void);
4e5d721f 261
c906108c 262/* This function returns a pointer to the string that is used
371d5dec 263 by gdb for its command prompt. */
e0700ba4 264extern const std::string &get_prompt ();
95298e72
PM
265
266/* This function returns a pointer to the string that is used
ab821bc6
PA
267 by gdb for its command prompt. */
268extern void set_prompt (const char *s);
c906108c 269
dbf30ca3
PA
270/* Return 1 if UI's current input handler is a secondary prompt, 0
271 otherwise. */
948578a9 272
dbf30ca3 273extern int gdb_in_secondary_prompt_p (struct ui *ui);
948578a9 274
371d5dec 275/* Perform _initialize initialization. */
a3b5ef3e 276extern void gdb_init ();
0f71a2f6 277
371d5dec
MS
278/* For use by event-top.c. */
279/* Variables from top.c. */
0f71a2f6 280extern int source_line_number;
6caa91b6 281extern std::string source_file_name;
491144b5 282extern bool history_expansion_p;
2f78cffc 283extern bool server_command;
6dd77b81 284extern char *lim_at_start;
17732724 285
08b13bdd
PP
286extern void gdb_add_history (const char *);
287
5fed81ff 288extern void show_commands (const char *args, int from_tty);
b9362cc7 289
eb4c3f4a 290extern void set_verbose (const char *, int, struct cmd_list_element *);
b9362cc7 291
f8631e5e
SM
292extern const char *handle_line_of_input (std::string &cmd_line_buffer,
293 const char *rl, int repeat,
294 const char *annotation_suffix);
b69d38af 295
5809fbf2
TT
296/* Call at startup to see if the user has requested that gdb start up
297 quietly. */
298
299extern bool check_quiet_mode ();
300
17732724 301#endif