53d951b8d637b2e940d3e47fb4affde249f236fa
1 /* Manages interpreters for GDB, the GNU debugger.
3 Copyright (C) 2000-2023 Free Software Foundation, Inc.
5 Written by Jim Ingham <jingham@apple.com> of Apple Computer, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "gdbsupport/intrusive_list.h"
31 class completion_tracker
;
33 typedef struct interp
*(*interp_factory_func
) (const char *name
);
35 /* Each interpreter kind (CLI, MI, etc.) registers itself with a call
36 to this function, passing along its name, and a pointer to a
37 function that creates a new instance of an interpreter with that
40 The memory for NAME must have static storage duration. */
41 extern void interp_factory_register (const char *name
,
42 interp_factory_func func
);
44 extern void interp_exec (struct interp
*interp
, const char *command
);
46 class interp
: public intrusive_list_node
<interp
>
49 explicit interp (const char *name
);
50 virtual ~interp () = 0;
52 virtual void init (bool top_level
)
55 virtual void resume () = 0;
56 virtual void suspend () = 0;
58 virtual void exec (const char *command
) = 0;
60 /* Returns the ui_out currently used to collect results for this
61 interpreter. It can be a formatter for stdout, as is the case
62 for the console & mi outputs, or it might be a result
64 virtual ui_out
*interp_ui_out () = 0;
66 /* Provides a hook for interpreters to do any additional
67 setup/cleanup that they might need when logging is enabled or
69 virtual void set_logging (ui_file_up logfile
, bool logging_redirect
,
70 bool debug_redirect
) = 0;
72 /* Called before starting an event loop, to give the interpreter a
73 chance to e.g., print a prompt. */
74 virtual void pre_command_loop ()
77 /* Returns true if this interpreter supports using the readline
78 library; false if it uses GDB's own simplified readline
80 virtual bool supports_command_editing ()
83 const char *name () const
86 /* Notify the interpreter that the current inferior has stopped with signal
88 virtual void on_signal_received (gdb_signal sig
) {}
90 /* Notify the interpreter that the current inferior has exited with signal
92 virtual void on_signal_exited (gdb_signal sig
) {}
94 /* Notify the interpreter that the current inferior has stopped normally. */
95 virtual void on_normal_stop (bpstat
*bs
, int print_frame
) {}
97 /* Notify the intepreter that the current inferior has exited normally with
99 virtual void on_exited (int status
) {}
101 /* Notify the interpreter that the current inferior has stopped reverse
102 execution because there is no more history. */
103 virtual void on_no_history () {}
105 /* Notify the interpreter that a synchronous command it started has
107 virtual void on_sync_execution_done () {}
109 /* Notify the interpreter that an error was caught while executing a
110 command on this interpreter. */
111 virtual void on_command_error () {}
114 /* The memory for this is static, it comes from literal strings (e.g. "cli"). */
118 /* Has the init method been run? */
122 /* Look up the interpreter for NAME, creating one if none exists yet.
123 If NAME is not a interpreter type previously registered with
124 interp_factory_register, return NULL; otherwise return a pointer to
126 extern struct interp
*interp_lookup (struct ui
*ui
, const char *name
);
128 /* Set the current UI's top level interpreter to the interpreter named
129 NAME. Throws an error if NAME is not a known interpreter or the
130 interpreter fails to initialize. */
131 extern void set_top_level_interpreter (const char *name
);
133 /* Temporarily set the current interpreter, and reset it on
135 class scoped_restore_interp
139 scoped_restore_interp (const char *name
)
140 : m_interp (set_interp (name
))
144 ~scoped_restore_interp ()
146 set_interp (m_interp
->name ());
149 scoped_restore_interp (const scoped_restore_interp
&) = delete;
150 scoped_restore_interp
&operator= (const scoped_restore_interp
&) = delete;
154 struct interp
*set_interp (const char *name
);
156 struct interp
*m_interp
;
159 extern int current_interp_named_p (const char *name
);
161 /* Call this function to give the current interpreter an opportunity
162 to do any special handling of streams when logging is enabled or
163 disabled. LOGFILE is the stream for the log file when logging is
164 starting and is NULL when logging is ending. LOGGING_REDIRECT is
165 the value of the "set logging redirect" setting. If true, the
166 interpreter should configure the output streams to send output only
167 to the logfile. If false, the interpreter should configure the
168 output streams to send output to both the current output stream
169 (i.e., the terminal) and the log file. DEBUG_REDIRECT is same as
170 LOGGING_REDIRECT, but for the value of "set logging debugredirect"
172 extern void current_interp_set_logging (ui_file_up logfile
,
173 bool logging_redirect
,
174 bool debug_redirect
);
176 /* Returns the top-level interpreter. */
177 extern struct interp
*top_level_interpreter (void);
179 /* Return the current UI's current interpreter. */
180 extern struct interp
*current_interpreter (void);
182 extern struct interp
*command_interp (void);
184 extern void clear_interpreter_hooks (void);
186 /* Returns true if INTERP supports using the readline library; false
187 if it uses GDB's own simplified form of readline. */
188 extern int interp_supports_command_editing (struct interp
*interp
);
190 /* Called before starting an event loop, to give the interpreter a
191 chance to e.g., print a prompt. */
192 extern void interp_pre_command_loop (struct interp
*interp
);
194 /* List the possible interpreters which could complete the given
196 extern void interpreter_completer (struct cmd_list_element
*ignore
,
197 completion_tracker
&tracker
,
201 /* Notify all interpreters that the current inferior has stopped with signal
203 extern void interps_notify_signal_received (gdb_signal sig
);
205 /* Notify all interpreters that the current inferior has exited with signal
207 extern void interps_notify_signal_exited (gdb_signal sig
);
209 /* Notify all interpreters that the current inferior has stopped normally. */
210 extern void interps_notify_normal_stop (bpstat
*bs
, int print_frame
);
212 /* Notify all interpreters that the current inferior has stopped reverse
213 execution because there is no more history. */
214 extern void interps_notify_no_history ();
216 /* Notify all interpreters that the current inferior has exited normally with
218 extern void interps_notify_exited (int status
);
220 /* well-known interpreters */
221 #define INTERP_CONSOLE "console"
222 #define INTERP_MI2 "mi2"
223 #define INTERP_MI3 "mi3"
224 #define INTERP_MI4 "mi4"
225 #define INTERP_MI "mi"
226 #define INTERP_TUI "tui"
227 #define INTERP_INSIGHT "insight"