]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/cli/cli-script.h
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdb / cli / cli-script.h
CommitLineData
d318976c 1/* Header file for GDB CLI command implementation library.
d01e8234 2 Copyright (C) 2000-2025 Free Software Foundation, Inc.
d318976c
FN
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
a9762ec7 6 the Free Software Foundation; either version 3 of the License, or
d318976c
FN
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
a9762ec7 15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
d318976c 16
cc709640
TT
17#ifndef GDB_CLI_CLI_SCRIPT_H
18#define GDB_CLI_CLI_SCRIPT_H
d318976c 19
5d2c2c84 20#include "compile/compile.h"
0d12e84c
TT
21#include "gdbsupport/function-view.h"
22
da3331ec 23struct ui_file;
da3331ec
AC
24struct cmd_list_element;
25
6b66338c
SM
26/* * Control types for commands. */
27
28enum misc_command_type
29{
30 ok_command,
31 end_command,
32 else_command,
33 nop_command
34};
35
36enum command_control_type
37{
38 simple_control,
39 break_control,
40 continue_control,
41 while_control,
42 if_control,
43 commands_control,
44 python_control,
45 compile_control,
46 guile_control,
47 while_stepping_control,
7a2c85f2 48 define_control,
a33fc9ae 49 document_control,
6b66338c
SM
50 invalid_control
51};
52
12973681
TT
53struct command_line;
54
55extern void free_command_lines (struct command_line **);
56
57/* A deleter for command_line that calls free_command_lines. */
58
59struct command_lines_deleter
60{
61 void operator() (command_line *cmd_lines) const
62 {
63 free_command_lines (&cmd_lines);
64 }
65};
66
67/* A reference-counted struct command_line. */
68typedef std::shared_ptr<command_line> counted_command_line;
69
bb6203bf
AH
70/* A unique_ptr specialization for command_line. */
71typedef std::unique_ptr<command_line, command_lines_deleter> command_line_up;
72
6b66338c
SM
73/* * Structure for saved commands lines (for breakpoints, defined
74 commands, etc). */
75
76struct command_line
77{
12973681
TT
78 explicit command_line (command_control_type type_, char *line_ = nullptr)
79 : line (line_),
80 control_type (type_)
81 {
82 memset (&control_u, 0, sizeof (control_u));
83 }
84
85 DISABLE_COPY_AND_ASSIGN (command_line);
86
87 struct command_line *next = nullptr;
6b66338c
SM
88 char *line;
89 enum command_control_type control_type;
90 union
91 {
92 struct
93 {
94 enum compile_i_scope_types scope;
95 void *scope_data;
96 }
97 compile;
98 }
99 control_u;
6b66338c
SM
100 /* * For composite commands, the nested lists of commands. For
101 example, for "if" command this will contain the then branch and
102 the else branch, if that is available. */
12973681
TT
103 counted_command_line body_list_0;
104 counted_command_line body_list_1;
6b66338c 105
12973681 106private:
6b66338c 107
12973681 108 friend void free_command_lines (struct command_line **);
6b66338c 109
12973681 110 ~command_line ()
6b66338c 111 {
12973681 112 xfree (line);
6b66338c
SM
113 }
114};
115
f8631e5e
SM
116/* Prototype for a function to call to get one more input line.
117
118 If the function needs to return a dynamically allocated string, it can place
119 in the passed-in buffer, and return a pointer to it. Otherwise, it can
120 simply ignore it. */
121
122using read_next_line_ftype = gdb::function_view<const char * (std::string &)>;
123
60b3cef2
TT
124extern counted_command_line read_command_lines
125 (const char *, int, int, gdb::function_view<void (const char *)>);
126extern counted_command_line read_command_lines_1
f8631e5e 127 (read_next_line_ftype, int, gdb::function_view<void (const char *)>);
6b66338c
SM
128
129
d318976c
FN
130/* Exported to cli/cli-cmds.c */
131
05159abe 132extern void script_from_file (FILE *stream, const char *file);
d318976c 133
6f937416
PA
134extern void show_user_1 (struct cmd_list_element *c,
135 const char *prefix,
136 const char *name,
137 struct ui_file *stream);
d318976c 138
56bcdbea
TT
139/* Execute the commands in CMDLINES. */
140
141extern void execute_control_commands (struct command_line *cmdlines,
142 int from_tty);
143
144/* Run execute_control_commands for COMMANDS. Capture its output into
145 the returned string, do not display it to the screen. BATCH_FLAG
e5348a7a
AB
146 will be temporarily set to true. When TERM_OUT is true the output is
147 collected with terminal behavior (e.g. with styling). When TERM_OUT is
148 false raw output will be collected (e.g. no styling). */
56bcdbea
TT
149
150extern std::string execute_control_commands_to_string
e5348a7a 151 (struct command_line *commands, int from_tty, bool term_out);
56bcdbea 152
d318976c
FN
153/* Exported to gdb/breakpoint.c */
154
155extern enum command_control_type
56bcdbea
TT
156 execute_control_command (struct command_line *cmd,
157 int from_tty = 0);
d318976c 158
d57a3c85
TJB
159extern enum command_control_type
160 execute_control_command_untraced (struct command_line *cmd);
161
12973681
TT
162extern counted_command_line get_command_line (enum command_control_type,
163 const char *);
d57a3c85 164
d318976c
FN
165extern void print_command_lines (struct ui_out *,
166 struct command_line *, unsigned int);
d318976c
FN
167
168/* Exported to gdb/infrun.c */
169
95a6b0a1 170extern void execute_user_command (struct cmd_list_element *c, const char *args);
d318976c 171
01770bbd
PA
172/* If we're in a user-defined command, replace any $argc/$argN
173 reference found in LINE with the arguments that were passed to the
174 command. Otherwise, treat $argc/$argN as normal convenience
175 variables. */
176extern std::string insert_user_defined_cmd_args (const char *line);
177
16026cd7
AS
178/* Exported to top.c */
179
1263a9d5
TT
180extern void print_command_trace (const char *cmd, ...)
181 ATTRIBUTE_PRINTF (1, 2);
16026cd7
AS
182
183/* Exported to event-top.c */
184
185extern void reset_command_nest_depth (void);
186
e83f6121
AB
187/* Return true if A and B are identical. Some commands carry around a
188 'void *' compilation context, in this case this function doesn't try to
189 validate if the context is actually the same or not, and will just
190 return false indicating the commands have changed. That is, a return
191 value of true is a guarantee that the commands are equal, a return
192 value of false means the commands are possibly different (and in most
193 cases are different). */
194
195extern bool commands_equal (const command_line *a, const command_line *b);
196
cc709640 197#endif /* GDB_CLI_CLI_SCRIPT_H */