]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame_incremental - gdb/cli/cli-decode.h
gas: introduce .errif and .warnif
[thirdparty/binutils-gdb.git] / gdb / cli / cli-decode.h
... / ...
CommitLineData
1/* Header file for GDB command decoding library.
2
3 Copyright (C) 2000-2025 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#ifndef GDB_CLI_CLI_DECODE_H
19#define GDB_CLI_CLI_DECODE_H
20
21/* This file defines the private interfaces for any code implementing
22 command internals. */
23
24/* Include the public interfaces. */
25#include "command.h"
26#include "gdbsupport/gdb_regex.h"
27#include "cli-script.h"
28#include "completer.h"
29#include "gdbsupport/intrusive_list.h"
30#include "gdbsupport/buildargv.h"
31
32/* The allowed length of a line in a documentation string. */
33constexpr int cli_help_line_length = 80;
34
35/* Not a set/show command. Note that some commands which begin with
36 "set" or "show" might be in this category, if their syntax does
37 not fall into one of the following categories. */
38enum cmd_types
39{
40 not_set_cmd,
41 set_cmd,
42 show_cmd
43};
44
45/* This structure records one command'd definition. */
46
47
48struct cmd_list_element
49{
50 cmd_list_element (const char *name_, enum command_class theclass_,
51 const char *doc_)
52 : name (name_),
53 theclass (theclass_),
54 cmd_deprecated (0),
55 deprecated_warn_user (0),
56 malloced_replacement (0),
57 doc_allocated (0),
58 name_allocated (0),
59 hook_in (0),
60 allow_unknown (0),
61 abbrev_flag (0),
62 type (not_set_cmd),
63 doc (doc_)
64 {
65 gdb_assert (name != nullptr);
66 gdb_assert (doc != nullptr);
67 memset (&function, 0, sizeof (function));
68 }
69
70 ~cmd_list_element ()
71 {
72 if (doc && doc_allocated)
73 xfree ((char *) doc);
74 if (name_allocated)
75 xfree ((char *) name);
76 }
77
78 DISABLE_COPY_AND_ASSIGN (cmd_list_element);
79
80 /* For prefix commands, return a string containing prefix commands to
81 get here: this one plus any others needed to get to it. Ends in a
82 space. It is used before the word "command" in describing the
83 commands reached through this prefix.
84
85 For non-prefix commands, return an empty string. */
86 std::string prefixname () const;
87
88 /* Like prefixname, but do not append a trailing space. */
89 std::string prefixname_no_space () const;
90
91 /* Return a vector of strings describing the components of the full name
92 of this command. For example, if this command is 'set AA BB CC',
93 then the vector will contain 4 elements 'set', 'AA', 'BB', and 'CC'
94 in that order. */
95 std::vector<std::string> command_components () const;
96
97 /* Return true if this command is an alias of another command. */
98 bool is_alias () const
99 { return this->alias_target != nullptr; }
100
101 /* Return true if this command is a prefix command. */
102 bool is_prefix () const
103 { return this->subcommands != nullptr; }
104
105 /* Return true if this command is a "command class help" command. For
106 instance, a "stack" dummy command is registered so that one can do
107 "help stack" and show help for all commands of the "stack" class. */
108 bool is_command_class_help () const
109 { return this->func == nullptr; }
110
111 void set_context (void *context)
112 {
113 gdb_assert (m_context == nullptr);
114 m_context = context;
115 }
116
117 void *context () const
118 { return m_context; }
119
120 /* Points to next command in this list. */
121 struct cmd_list_element *next = nullptr;
122
123 /* Name of this command. */
124 const char *name;
125
126 /* Command class; class values are chosen by application program. */
127 enum command_class theclass;
128
129 /* When 1 indicated that this command is deprecated. It may be
130 removed from gdb's command set in the future. */
131
132 unsigned int cmd_deprecated : 1;
133
134 /* The user needs to be warned that this is a deprecated command.
135 The user should only be warned the first time a command is
136 used. */
137
138 unsigned int deprecated_warn_user : 1;
139
140 /* When functions are deprecated at compile time (this is the way
141 it should, in general, be done) the memory containing the
142 replacement string is statically allocated. In some cases it
143 makes sense to deprecate commands at runtime (the testsuite is
144 one example). In this case the memory for replacement is
145 malloc'ed. When a command is undeprecated or re-deprecated at
146 runtime we don't want to risk calling free on statically
147 allocated memory, so we check this flag. */
148
149 unsigned int malloced_replacement : 1;
150
151 /* Set if the doc field should be xfree'd. */
152
153 unsigned int doc_allocated : 1;
154
155 /* Set if the name field should be xfree'd. */
156
157 unsigned int name_allocated : 1;
158
159 /* Flag that specifies if this command is already running its hook. */
160 /* Prevents the possibility of hook recursion. */
161 unsigned int hook_in : 1;
162
163 /* For prefix commands only:
164 nonzero means do not get an error if subcommand is not
165 recognized; call the prefix's own function in that case. */
166 unsigned int allow_unknown : 1;
167
168 /* Nonzero says this is an abbreviation, and should not
169 be mentioned in lists of commands.
170 This allows "br<tab>" to complete to "break", which it
171 otherwise wouldn't. */
172 unsigned int abbrev_flag : 1;
173
174 /* Type of "set" or "show" command (or SET_NOT_SET if not "set"
175 or "show"). */
176 ENUM_BITFIELD (cmd_types) type : 2;
177
178 /* Function definition of this command. NULL for command class
179 names and for help topics that are not really commands. NOTE:
180 cagney/2002-02-02: This function signature is evolving. For
181 the moment suggest sticking with either set_cmd_cfunc() or
182 set_cmd_sfunc(). */
183 cmd_func_ftype *func;
184
185 /* The command's real callback. At present func() bounces through
186 to one of the below. */
187 union
188 {
189 /* Most commands don't need the cmd_list_element parameter passed to FUNC.
190 They therefore register a command of this type, which doesn't have the
191 cmd_list_element parameter. do_simple_func is installed as FUNC, and
192 acts as a shim between the two. */
193 cmd_simple_func_ftype *simple_func;
194 }
195 function;
196
197 /* Documentation of this command (or help topic).
198 First line is brief documentation; remaining lines form, with it,
199 the full documentation. First line should end with a period.
200 Entire string should also end with a period, not a newline. */
201 const char *doc;
202
203 /* For set/show commands. A method for printing the output to the
204 specified stream. */
205 show_value_ftype *show_value_func = nullptr;
206
207 /* If this command is deprecated, this is the replacement name. */
208 const char *replacement = nullptr;
209
210 /* Hook for another command to be executed before this command. */
211 struct cmd_list_element *hook_pre = nullptr;
212
213 /* Hook for another command to be executed after this command. */
214 struct cmd_list_element *hook_post = nullptr;
215
216 /* Default arguments to automatically prepend to the user
217 provided arguments when running this command or alias. */
218 std::string default_args;
219
220 /* Nonzero identifies a prefix command. For them, the address
221 of the variable containing the list of subcommands. */
222 struct cmd_list_element **subcommands = nullptr;
223
224 /* The prefix command of this command. */
225 struct cmd_list_element *prefix = nullptr;
226
227 /* Completion routine for this command. */
228 completer_ftype *completer = symbol_completer;
229
230 /* Handle the word break characters for this completer. Usually
231 this function need not be defined, but for some types of
232 completers (e.g., Python completers declared as methods inside
233 a class) the word break chars may need to be redefined
234 depending on the completer type (e.g., for filename
235 completers). */
236 completer_handle_brkchars_ftype *completer_handle_brkchars = nullptr;
237
238 /* Destruction routine for this command. If non-NULL, this is
239 called when this command instance is destroyed. This may be
240 used to finalize the CONTEXT field, if needed. */
241 void (*destroyer) (struct cmd_list_element *self, void *context) = nullptr;
242
243 /* Setting affected by "set" and "show". Not used if type is not_set_cmd. */
244 std::optional<setting> var;
245
246 /* Pointer to NULL terminated list of enumerated values (like
247 argv). */
248 const char *const *enums = nullptr;
249
250 /* Pointer to command strings of user-defined commands */
251 counted_command_line user_commands;
252
253 /* Pointer to command that is hooked by this one, (by hook_pre)
254 so the hook can be removed when this one is deleted. */
255 struct cmd_list_element *hookee_pre = nullptr;
256
257 /* Pointer to command that is hooked by this one, (by hook_post)
258 so the hook can be removed when this one is deleted. */
259 struct cmd_list_element *hookee_post = nullptr;
260
261 /* Pointer to command that is aliased by this one, so the
262 aliased command can be located in case it has been hooked. */
263 struct cmd_list_element *alias_target = nullptr;
264
265 /* Node to link aliases on an alias list. */
266 using aliases_list_node_type
267 = intrusive_list_node<cmd_list_element>;
268 aliases_list_node_type aliases_list_node;
269
270 /* Linked list of all aliases of this command. */
271 using aliases_list_member_node_type
272 = intrusive_member_node<cmd_list_element,
273 &cmd_list_element::aliases_list_node>;
274 using aliases_list_type
275 = intrusive_list<cmd_list_element, aliases_list_member_node_type>;
276 aliases_list_type aliases;
277
278 /* If non-null, the pointer to a field in 'struct
279 cli_suppress_notification', which will be set to true in cmd_func
280 when this command is being executed. It will be set back to false
281 when the command has been executed. */
282 bool *suppress_notification = nullptr;
283
284private:
285 /* Local state (context) for this command. This can be anything. */
286 void *m_context = nullptr;
287};
288
289/* Functions that implement commands about CLI commands. */
290
291extern void help_cmd (const char *, struct ui_file *);
292
293extern void apropos_cmd (struct ui_file *, struct cmd_list_element *,
294 bool verbose, compiled_regex &);
295
296/* Used to mark commands that don't do anything. If we just leave the
297 function field NULL, the command is interpreted as a help topic, or
298 as a class of commands. */
299
300extern void not_just_help_class_command (const char *arg, int from_tty);
301
302/* Print only the first line of STR on STREAM.
303 FOR_VALUE_PREFIX true indicates that the first line is output
304 to be a prefix to show a value (see deprecated_show_value_hack):
305 the first character is printed in uppercase, and the trailing
306 dot character is not printed. */
307
308extern void print_doc_line (struct ui_file *stream, const char *str,
309 bool for_value_prefix);
310
311/* The enums of boolean commands. */
312extern const char * const boolean_enums[];
313
314/* The enums of auto-boolean commands. */
315extern const char * const auto_boolean_enums[];
316
317/* Add the different possible completions of TEXT with color.
318
319 WORD points in the same buffer as TEXT, and completions should be
320 returned relative to this position. For example, suppose TEXT is "foo"
321 and we want to complete to "foobar". If WORD is "oo", return
322 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
323
324extern void complete_on_color (completion_tracker &tracker,
325 const char *text, const char *word);
326
327/* Parse ARGS, an option to a var_color variable.
328 *
329 Either returns the parsed value on success or throws an error. ARGS may be
330 one of strings {none, black, red, green, yellow, blue, magenta,
331 cyan, white}, or color number from 0 to 255, or RGB hex triplet #RRGGBB.
332 */
333extern ui_file_style::color parse_cli_var_color (const char **args);
334
335/* Same as above but additionally check that there is no junk in the end. */
336extern ui_file_style::color parse_var_color (const char *arg);
337
338/* Verify whether a given cmd_list_element is a user-defined command.
339 Return 1 if it is user-defined. Return 0 otherwise. */
340
341extern int cli_user_command_p (struct cmd_list_element *);
342
343extern int find_command_name_length (const char *);
344
345#endif /* GDB_CLI_CLI_DECODE_H */