GDB (xrefs)
Loading...
Searching...
No Matches
/tmp/gdb-13.1/gdb/top.h
Go to the documentation of this file.
1/* Top level stuff for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2023 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 "gdbsupport/buffer.h"
24#include "gdbsupport/event-loop.h"
25#include "gdbsupport/next-iterator.h"
26#include "value.h"
27
28/* Prompt state. */
29
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. */
37
38 /* The command finished; display the prompt before returning back to
39 the top level. */
41
42 /* We've displayed the prompt already, ready for input. */
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
55struct ui
56{
57 /* Create a new UI. */
58 ui (FILE *instream, FILE *outstream, FILE *errstream);
59 ~ui ();
60
62
63 /* Pointer to next in singly-linked list. */
64 struct ui *next = nullptr;
65
66 /* Convenient handle (UI number). Unique across all UIs. */
67 int num;
68
69 /* The UI's command line buffer. This is to used to accumulate
70 input until we have a whole command line. */
71 std::string line_buffer;
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). */
79 void (*call_readline) (gdb_client_data) = nullptr;
80
81 /* The function to invoke when a complete line of input is ready for
82 processing. */
83 void (*input_handler) (gdb::unique_xmalloc_ptr<char> &&) = nullptr;
84
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. */
89
90 /* Each UI has its own independent set of interpreters. */
91 struct ui_interp_info *interp_info = nullptr;
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. */
101 int async = 0;
102
103 /* The number of nested readline secondary prompts that are
104 currently active. */
106
107 /* The UI's stdin. Set to stdin for the main UI. */
109
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;
115 /* Standard output stream. */
117 /* Standard error stream. */
119
120 /* The file descriptor for the input stream, so that we can register
121 it with the event loop. This can be set to -1 to prevent this
122 registration. */
124
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. */
129
130 /* See enum prompt_state's description. */
132
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 */
140 /* Input stream */
142 /* Serious error notifications */
144 /* Log/debug/trace messages that should bypass normal stdout/stderr
145 filtering. */
147
148 /* The current ui_out. */
149 struct ui_out *m_current_uiout = nullptr;
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. */
156
157 /* Return true if this UI's input fd is a tty. */
158 bool input_interactive_p () const;
159};
160
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
166/* The current UI. */
167extern struct ui *current_ui;
168
169/* The list of all UIs. */
170extern struct ui *ui_list;
171
172/* State for SWITCH_THRU_ALL_UIS. */
174{
175public:
176
178 {
180 }
181
183
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)
197 }
198
199 private:
200
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;
206};
207
208 /* Traverse through all UI, and switch the current UI to the one
209 being iterated. */
210#define SWITCH_THRU_ALL_UIS() \
211 for (switch_thru_all_uis stau_state; !stau_state.done (); stau_state.next ())
212
213using ui_range = next_range<ui>;
214
215/* An adapter that can be used to traverse over all UIs. */
216static inline
218{
219 return ui_range (ui_list);
220}
221
222/* From top.c. */
223extern bool confirm;
224extern int inhibit_gdbinit;
225
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
233extern void print_gdb_configuration (struct ui_file *);
234
235extern void read_command_file (FILE *);
236extern void init_history (void);
237extern void command_loop (void);
238extern int quit_confirm (void);
239extern void quit_force (int *, int);
240extern void quit_command (const char *, int);
241extern void quit_cover (void);
242extern void execute_command (const char *, int);
243
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
252/* Wait for a synchronous execution command to end. */
253extern void wait_sync_command_done (void);
254
255extern void check_frame_language_change (void);
256
257/* Prepare for execution of a command.
258 Call this before every command, CLI or MI.
259 Returns a cleanup to be run after the command is completed. */
261
262/* This function returns a pointer to the string that is used
263 by gdb for its command prompt. */
264extern const std::string &get_prompt ();
265
266/* This function returns a pointer to the string that is used
267 by gdb for its command prompt. */
268extern void set_prompt (const char *s);
269
270/* Return 1 if UI's current input handler is a secondary prompt, 0
271 otherwise. */
272
273extern int gdb_in_secondary_prompt_p (struct ui *ui);
274
275/* Perform _initialize initialization. */
276extern void gdb_init ();
277
278/* For use by event-top.c. */
279/* Variables from top.c. */
280extern int source_line_number;
281extern std::string source_file_name;
282extern bool history_expansion_p;
283extern bool server_command;
284extern char *lim_at_start;
285
286extern void gdb_add_history (const char *);
287
288extern void show_commands (const char *args, int from_tty);
289
290extern void set_verbose (const char *, int, struct cmd_list_element *);
291
292extern const char *handle_line_of_input (std::string &cmd_line_buffer,
293 const char *rl, int repeat,
294 const char *annotation_suffix);
295
296/* Call at startup to see if the user has requested that gdb start up
297 quietly. */
298
299extern bool check_quiet_mode ();
300
301#endif
switch_thru_all_uis()
Definition: top.h:177
scoped_restore_tmpl< struct ui * > m_save_ui
Definition: top.h:205
DISABLE_COPY_AND_ASSIGN(switch_thru_all_uis)
bool done() const
Definition: top.h:185
void next()
Definition: top.h:192
struct ui * m_iter
Definition: top.h:202
Definition: ui-out.h:160
Definition: top.h:56
struct ui_file * m_gdb_stdin
Definition: top.h:141
int command_editing
Definition: top.h:88
struct ui_file * m_gdb_stdlog
Definition: top.h:146
int num
Definition: top.h:67
void(* input_handler)(gdb::unique_xmalloc_ptr< char > &&)
Definition: top.h:83
struct ui_file * m_gdb_stdout
Definition: top.h:139
int async
Definition: top.h:101
DISABLE_COPY_AND_ASSIGN(ui)
struct ui_interp_info * interp_info
Definition: top.h:91
struct ui_file * m_gdb_stderr
Definition: top.h:143
bool input_interactive_p() const
Definition: top.c:1918
FILE * outstream
Definition: top.h:116
int input_fd
Definition: top.h:123
struct ui * next
Definition: top.h:64
bool m_input_interactive_p
Definition: top.h:128
FILE * stdin_stream
Definition: top.h:108
~ui()
Definition: top.c:324
std::string line_buffer
Definition: top.h:71
void unregister_file_handler()
Definition: event-top.c:560
struct ui_out * m_current_uiout
Definition: top.h:149
int secondary_prompt_depth
Definition: top.h:105
void(* call_readline)(gdb_client_data)
Definition: top.h:79
void register_file_handler()
Definition: event-top.c:550
FILE * errstream
Definition: top.h:118
FILE * instream
Definition: top.h:114
void print_gdb_version(struct ui_file *stream, bool interactive)
Definition: top.c:1434
void wait_sync_command_done(void)
Definition: top.c:529
int inhibit_gdbinit
Definition: top.c:128
struct ui * ui_list
Definition: event-top.c:484
void print_gdb_configuration(struct ui_file *)
Definition: top.c:1506
const char * handle_line_of_input(std::string &cmd_line_buffer, const char *rl, int repeat, const char *annotation_suffix)
Definition: event-top.c:669
int source_line_number
Definition: top.c:427
void init_history(void)
Definition: top.c:2058
bool history_expansion_p
Definition: top.c:961
char * lim_at_start
void show_commands(const char *args, int from_tty)
Definition: top.c:1942
void set_prompt(const char *s)
Definition: top.c:1711
next_range< ui > ui_range
Definition: top.h:213
bool server_command
Definition: top.c:172
void quit_command(const char *, int)
Definition: cli-cmds.c:475
void quit_cover(void)
struct ui * main_ui
Definition: event-top.c:482
const std::string & get_prompt()
Definition: top.c:1703
int gdb_in_secondary_prompt_p(struct ui *ui)
Definition: top.c:1060
void quit_force(int *, int)
Definition: top.c:1808
int quit_confirm(void)
Definition: top.c:1765
void maybe_wait_sync_command_done(int was_sync)
Definition: top.c:550
void execute_command(const char *, int)
Definition: top.c:574
void command_loop(void)
prompt_state
Definition: top.h:31
@ PROMPT_BLOCKED
Definition: top.h:36
@ PROMPTED
Definition: top.h:43
@ PROMPT_NEEDED
Definition: top.h:40
void set_verbose(const char *, int, struct cmd_list_element *)
Definition: top.c:2026
struct ui * current_ui
Definition: event-top.c:483
bool confirm
Definition: top.c:133
std::string source_file_name
Definition: top.c:433
void gdb_add_history(const char *)
Definition: top.c:1233
void check_frame_language_change(void)
Definition: top.c:487
scoped_value_mark prepare_execute_command(void)
Definition: top.c:471
void read_command_file(FILE *)
Definition: top.c:437
bool check_quiet_mode()
Definition: top.c:2203
static ui_range all_uis()
Definition: top.h:217
void gdb_init()
Definition: top.c:2393