gdb: Add an overloaded ui_out::text accepting a const std::string &
[binutils-gdb.git] / gdb / cli / cli-decode.h
1 /* Header file for GDB command decoding library.
2
3 Copyright (C) 2000-2021 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 CLI_CLI_DECODE_H
19 #define 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 "gdb_regex.h"
27 #include "cli-script.h"
28 #include "completer.h"
29
30 /* Not a set/show command. Note that some commands which begin with
31 "set" or "show" might be in this category, if their syntax does
32 not fall into one of the following categories. */
33 enum cmd_types
34 {
35 not_set_cmd,
36 set_cmd,
37 show_cmd
38 };
39
40 /* This structure records one command'd definition. */
41
42
43 struct cmd_list_element
44 {
45 cmd_list_element (const char *name_, enum command_class theclass_,
46 const char *doc_)
47 : name (name_),
48 theclass (theclass_),
49 cmd_deprecated (0),
50 deprecated_warn_user (0),
51 malloced_replacement (0),
52 doc_allocated (0),
53 name_allocated (0),
54 hook_in (0),
55 allow_unknown (0),
56 abbrev_flag (0),
57 type (not_set_cmd),
58 var_type (var_boolean),
59 doc (doc_)
60 {
61 memset (&function, 0, sizeof (function));
62 }
63
64 ~cmd_list_element ()
65 {
66 if (doc && doc_allocated)
67 xfree ((char *) doc);
68 if (name_allocated)
69 xfree ((char *) name);
70 }
71
72 DISABLE_COPY_AND_ASSIGN (cmd_list_element);
73
74 /* For prefix commands, return a string containing prefix commands to
75 get here: this one plus any others needed to get to it. Ends in a
76 space. It is used before the word "command" in describing the
77 commands reached through this prefix.
78
79 For non-prefix commands, return an empty string. */
80 std::string prefixname () const;
81
82 /* Return true if this command is an alias of another command. */
83 bool is_alias () const
84 { return this->alias_target != nullptr; }
85
86 /* Return true if this command is a prefix command. */
87 bool is_prefix () const
88 { return this->subcommands != nullptr; }
89
90 /* Return true if this command is a "command class help" command. For
91 instance, a "stack" dummy command is registered so that one can do
92 "help stack" and show help for all commands of the "stack" class. */
93 bool is_command_class_help () const
94 { return this->func == nullptr; }
95
96 /* Points to next command in this list. */
97 struct cmd_list_element *next = nullptr;
98
99 /* Name of this command. */
100 const char *name;
101
102 /* Command class; class values are chosen by application program. */
103 enum command_class theclass;
104
105 /* When 1 indicated that this command is deprecated. It may be
106 removed from gdb's command set in the future. */
107
108 unsigned int cmd_deprecated : 1;
109
110 /* The user needs to be warned that this is a deprecated command.
111 The user should only be warned the first time a command is
112 used. */
113
114 unsigned int deprecated_warn_user : 1;
115
116 /* When functions are deprecated at compile time (this is the way
117 it should, in general, be done) the memory containing the
118 replacement string is statically allocated. In some cases it
119 makes sense to deprecate commands at runtime (the testsuite is
120 one example). In this case the memory for replacement is
121 malloc'ed. When a command is undeprecated or re-deprecated at
122 runtime we don't want to risk calling free on statically
123 allocated memory, so we check this flag. */
124
125 unsigned int malloced_replacement : 1;
126
127 /* Set if the doc field should be xfree'd. */
128
129 unsigned int doc_allocated : 1;
130
131 /* Set if the name field should be xfree'd. */
132
133 unsigned int name_allocated : 1;
134
135 /* Flag that specifies if this command is already running its hook. */
136 /* Prevents the possibility of hook recursion. */
137 unsigned int hook_in : 1;
138
139 /* For prefix commands only:
140 nonzero means do not get an error if subcommand is not
141 recognized; call the prefix's own function in that case. */
142 unsigned int allow_unknown : 1;
143
144 /* Nonzero says this is an abbreviation, and should not
145 be mentioned in lists of commands.
146 This allows "br<tab>" to complete to "break", which it
147 otherwise wouldn't. */
148 unsigned int abbrev_flag : 1;
149
150 /* Type of "set" or "show" command (or SET_NOT_SET if not "set"
151 or "show"). */
152 ENUM_BITFIELD (cmd_types) type : 2;
153
154 /* What kind of variable is *VAR? */
155 ENUM_BITFIELD (var_types) var_type : 4;
156
157 /* Function definition of this command. NULL for command class
158 names and for help topics that are not really commands. NOTE:
159 cagney/2002-02-02: This function signature is evolving. For
160 the moment suggest sticking with either set_cmd_cfunc() or
161 set_cmd_sfunc(). */
162 void (*func) (struct cmd_list_element *c, const char *args, int from_tty)
163 = nullptr;
164 /* The command's real callback. At present func() bounces through
165 to one of the below. */
166 union
167 {
168 /* If type is not_set_cmd, call it like this: */
169 cmd_const_cfunc_ftype *const_cfunc;
170 /* If type is set_cmd or show_cmd, first set the variables,
171 and then call this: */
172 cmd_const_sfunc_ftype *sfunc;
173 }
174 function;
175
176 /* Local state (context) for this command. This can be anything. */
177 void *context = nullptr;
178
179 /* Documentation of this command (or help topic).
180 First line is brief documentation; remaining lines form, with it,
181 the full documentation. First line should end with a period.
182 Entire string should also end with a period, not a newline. */
183 const char *doc;
184
185 /* For set/show commands. A method for printing the output to the
186 specified stream. */
187 show_value_ftype *show_value_func = nullptr;
188
189 /* If this command is deprecated, this is the replacement name. */
190 const char *replacement = nullptr;
191
192 /* Hook for another command to be executed before this command. */
193 struct cmd_list_element *hook_pre = nullptr;
194
195 /* Hook for another command to be executed after this command. */
196 struct cmd_list_element *hook_post = nullptr;
197
198 /* Default arguments to automatically prepend to the user
199 provided arguments when running this command or alias. */
200 std::string default_args;
201
202 /* Nonzero identifies a prefix command. For them, the address
203 of the variable containing the list of subcommands. */
204 struct cmd_list_element **subcommands = nullptr;
205
206 /* The prefix command of this command. */
207 struct cmd_list_element *prefix = nullptr;
208
209 /* Completion routine for this command. */
210 completer_ftype *completer = symbol_completer;
211
212 /* Handle the word break characters for this completer. Usually
213 this function need not be defined, but for some types of
214 completers (e.g., Python completers declared as methods inside
215 a class) the word break chars may need to be redefined
216 depending on the completer type (e.g., for filename
217 completers). */
218 completer_handle_brkchars_ftype *completer_handle_brkchars = nullptr;
219
220 /* Destruction routine for this command. If non-NULL, this is
221 called when this command instance is destroyed. This may be
222 used to finalize the CONTEXT field, if needed. */
223 void (*destroyer) (struct cmd_list_element *self, void *context) = nullptr;
224
225 /* Pointer to variable affected by "set" and "show". Doesn't
226 matter if type is not_set. */
227 void *var = nullptr;
228
229 /* Pointer to NULL terminated list of enumerated values (like
230 argv). */
231 const char *const *enums = nullptr;
232
233 /* Pointer to command strings of user-defined commands */
234 counted_command_line user_commands;
235
236 /* Pointer to command that is hooked by this one, (by hook_pre)
237 so the hook can be removed when this one is deleted. */
238 struct cmd_list_element *hookee_pre = nullptr;
239
240 /* Pointer to command that is hooked by this one, (by hook_post)
241 so the hook can be removed when this one is deleted. */
242 struct cmd_list_element *hookee_post = nullptr;
243
244 /* Pointer to command that is aliased by this one, so the
245 aliased command can be located in case it has been hooked. */
246 struct cmd_list_element *alias_target = nullptr;
247
248 /* Start of a linked list of all aliases of this command. */
249 struct cmd_list_element *aliases = nullptr;
250
251 /* Link pointer for aliases on an alias list. */
252 struct cmd_list_element *alias_chain = nullptr;
253
254 /* If non-null, the pointer to a field in 'struct
255 cli_suppress_notification', which will be set to true in cmd_func
256 when this command is being executed. It will be set back to false
257 when the command has been executed. */
258 int *suppress_notification = nullptr;
259 };
260
261 /* Functions that implement commands about CLI commands. */
262
263 extern void help_cmd (const char *, struct ui_file *);
264
265 extern void apropos_cmd (struct ui_file *, struct cmd_list_element *,
266 bool verbose, compiled_regex &, const char *);
267
268 /* Used to mark commands that don't do anything. If we just leave the
269 function field NULL, the command is interpreted as a help topic, or
270 as a class of commands. */
271
272 extern void not_just_help_class_command (const char *arg, int from_tty);
273
274 /* Print only the first line of STR on STREAM.
275 FOR_VALUE_PREFIX true indicates that the first line is output
276 to be a prefix to show a value (see deprecated_show_value_hack):
277 the first character is printed in uppercase, and the trailing
278 dot character is not printed. */
279
280 extern void print_doc_line (struct ui_file *stream, const char *str,
281 bool for_value_prefix);
282
283 /* The enums of boolean commands. */
284 extern const char * const boolean_enums[];
285
286 /* The enums of auto-boolean commands. */
287 extern const char * const auto_boolean_enums[];
288
289 /* Verify whether a given cmd_list_element is a user-defined command.
290 Return 1 if it is user-defined. Return 0 otherwise. */
291
292 extern int cli_user_command_p (struct cmd_list_element *);
293
294 extern int find_command_name_length (const char *);
295
296 #endif /* CLI_CLI_DECODE_H */