1 /* Header file for GDB CLI command implementation library.
2 Copyright (C) 2000-2024 Free Software Foundation, Inc.
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
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #ifndef GDB_CLI_CLI_SCRIPT_H
18 #define GDB_CLI_CLI_SCRIPT_H
20 #include "compile/compile.h"
21 #include "gdbsupport/function-view.h"
24 struct cmd_list_element
;
26 /* * Control types for commands. */
28 enum misc_command_type
36 enum command_control_type
47 while_stepping_control
,
55 extern void free_command_lines (struct command_line
**);
57 /* A deleter for command_line that calls free_command_lines. */
59 struct command_lines_deleter
61 void operator() (command_line
*cmd_lines
) const
63 free_command_lines (&cmd_lines
);
67 /* A reference-counted struct command_line. */
68 typedef std::shared_ptr
<command_line
> counted_command_line
;
70 /* A unique_ptr specialization for command_line. */
71 typedef std::unique_ptr
<command_line
, command_lines_deleter
> command_line_up
;
73 /* * Structure for saved commands lines (for breakpoints, defined
78 explicit command_line (command_control_type type_
, char *line_
= nullptr)
82 memset (&control_u
, 0, sizeof (control_u
));
85 DISABLE_COPY_AND_ASSIGN (command_line
);
87 struct command_line
*next
= nullptr;
89 enum command_control_type control_type
;
94 enum compile_i_scope_types scope
;
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. */
103 counted_command_line body_list_0
;
104 counted_command_line body_list_1
;
108 friend void free_command_lines (struct command_line
**);
116 /* Prototype for a function to call to get one more input line.
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
122 using read_next_line_ftype
= gdb::function_view
<const char * (std::string
&)>;
124 extern counted_command_line read_command_lines
125 (const char *, int, int, gdb::function_view
<void (const char *)>);
126 extern counted_command_line read_command_lines_1
127 (read_next_line_ftype
, int, gdb::function_view
<void (const char *)>);
130 /* Exported to cli/cli-cmds.c */
132 extern void script_from_file (FILE *stream
, const char *file
);
134 extern void show_user_1 (struct cmd_list_element
*c
,
137 struct ui_file
*stream
);
139 /* Execute the commands in CMDLINES. */
141 extern void execute_control_commands (struct command_line
*cmdlines
,
144 /* Run execute_control_commands for COMMANDS. Capture its output into
145 the returned string, do not display it to the screen. BATCH_FLAG
146 will be temporarily set to true. */
148 extern std::string execute_control_commands_to_string
149 (struct command_line
*commands
, int from_tty
);
151 /* Exported to gdb/breakpoint.c */
153 extern enum command_control_type
154 execute_control_command (struct command_line
*cmd
,
157 extern enum command_control_type
158 execute_control_command_untraced (struct command_line
*cmd
);
160 extern counted_command_line
get_command_line (enum command_control_type
,
163 extern void print_command_lines (struct ui_out
*,
164 struct command_line
*, unsigned int);
166 /* Exported to gdb/infrun.c */
168 extern void execute_user_command (struct cmd_list_element
*c
, const char *args
);
170 /* If we're in a user-defined command, replace any $argc/$argN
171 reference found in LINE with the arguments that were passed to the
172 command. Otherwise, treat $argc/$argN as normal convenience
174 extern std::string
insert_user_defined_cmd_args (const char *line
);
176 /* Exported to top.c */
178 extern void print_command_trace (const char *cmd
, ...)
179 ATTRIBUTE_PRINTF (1, 2);
181 /* Exported to event-top.c */
183 extern void reset_command_nest_depth (void);
185 #endif /* GDB_CLI_CLI_SCRIPT_H */