Commit | Line | Data |
---|---|---|
50aeff07 | 1 | /* Header file for command creation. |
18a642a1 | 2 | |
61baf725 | 3 | Copyright (C) 1986-2017 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b JM |
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 | |
a9762ec7 | 7 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 8 | (at your option) any later version. |
c906108c | 9 | |
c5aa993b JM |
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. | |
c906108c | 14 | |
c5aa993b | 15 | You should have received a copy of the GNU General Public License |
a9762ec7 | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
17 | |
18 | #if !defined (COMMAND_H) | |
19 | #define COMMAND_H 1 | |
20 | ||
49c4e619 | 21 | #include "gdb_vecs.h" |
6e75794e | 22 | #include "common/scoped_restore.h" |
49c4e619 | 23 | |
eb3ff9a5 PA |
24 | struct completion_tracker; |
25 | ||
50aeff07 PA |
26 | /* This file defines the public interface for any code wanting to |
27 | create commands. */ | |
28 | ||
aff410f1 MS |
29 | /* Command classes are top-level categories into which commands are |
30 | broken down for "help" purposes. | |
31 | ||
6426a772 JM |
32 | Notes on classes: class_alias is for alias commands which are not |
33 | abbreviations of the original command. class-pseudo is for | |
34 | commands which are not really commands nor help topics ("stop"). */ | |
35 | ||
36 | enum command_class | |
37 | { | |
38 | /* Special args to help_list */ | |
6e381ba0 | 39 | class_deprecated = -3, all_classes = -2, all_commands = -1, |
6426a772 | 40 | /* Classes of commands */ |
aff410f1 MS |
41 | no_class = -1, class_run = 0, class_vars, class_stack, class_files, |
42 | class_support, class_info, class_breakpoint, class_trace, | |
6b04bdb7 | 43 | class_alias, class_bookmark, class_obscure, class_maintenance, |
db5f229b MS |
44 | class_pseudo, class_tui, class_user, class_xdb, |
45 | no_set_class /* Used for "show" commands that have no corresponding | |
46 | "set" command. */ | |
6426a772 JM |
47 | }; |
48 | ||
18a642a1 AC |
49 | /* FIXME: cagney/2002-03-17: Once cmd_type() has been removed, ``enum |
50 | cmd_types'' can be moved from "command.h" to "cli-decode.h". */ | |
c906108c SS |
51 | /* Not a set/show command. Note that some commands which begin with |
52 | "set" or "show" might be in this category, if their syntax does | |
53 | not fall into one of the following categories. */ | |
c5aa993b JM |
54 | typedef enum cmd_types |
55 | { | |
56 | not_set_cmd, | |
57 | set_cmd, | |
58 | show_cmd | |
59 | } | |
60 | cmd_types; | |
c906108c SS |
61 | |
62 | /* Types of "set" or "show" command. */ | |
c5aa993b JM |
63 | typedef enum var_types |
64 | { | |
65 | /* "on" or "off". *VAR is an integer which is nonzero for on, | |
66 | zero for off. */ | |
67 | var_boolean, | |
97c3646f AC |
68 | |
69 | /* "on" / "true" / "enable" or "off" / "false" / "disable" or | |
7f19b9a2 AC |
70 | "auto. *VAR is an ``enum auto_boolean''. NOTE: In general a |
71 | custom show command will need to be implemented - one that for | |
72 | "auto" prints both the "auto" and the current auto-selected | |
ebcd3b23 | 73 | value. */ |
97c3646f AC |
74 | var_auto_boolean, |
75 | ||
aff410f1 MS |
76 | /* Unsigned Integer. *VAR is an unsigned int. The user can type |
77 | 0 to mean "unlimited", which is stored in *VAR as UINT_MAX. */ | |
c5aa993b JM |
78 | var_uinteger, |
79 | ||
aff410f1 MS |
80 | /* Like var_uinteger but signed. *VAR is an int. The user can |
81 | type 0 to mean "unlimited", which is stored in *VAR as | |
6fc1c773 YQ |
82 | INT_MAX. The only remaining use of it is the Python API. |
83 | Don't use it elsewhere. */ | |
c5aa993b JM |
84 | var_integer, |
85 | ||
aff410f1 MS |
86 | /* String which the user enters with escapes (e.g. the user types |
87 | \n and it is a real newline in the stored string). | |
c5aa993b JM |
88 | *VAR is a malloc'd string, or NULL if the string is empty. */ |
89 | var_string, | |
90 | /* String which stores what the user types verbatim. | |
91 | *VAR is a malloc'd string, or NULL if the string is empty. */ | |
92 | var_string_noescape, | |
b4b4ac0b AC |
93 | /* String which stores a filename. (*VAR) is a malloc'd string, |
94 | or "" if the string was empty. */ | |
95 | var_optional_filename, | |
96 | /* String which stores a filename. (*VAR) is a malloc'd | |
97 | string. */ | |
c5aa993b | 98 | var_filename, |
a7c3d162 | 99 | /* ZeroableInteger. *VAR is an int. Like var_integer except |
c5aa993b JM |
100 | that zero really means zero. */ |
101 | var_zinteger, | |
1e8fb976 PA |
102 | /* ZeroableUnsignedInteger. *VAR is an unsigned int. Zero really |
103 | means zero. */ | |
104 | var_zuinteger, | |
b69b1fb1 YQ |
105 | /* ZeroableUnsignedInteger with unlimited value. *VAR is an int, |
106 | but its range is [0, INT_MAX]. -1 stands for unlimited and | |
107 | other negative numbers are not allowed. */ | |
6fc1c773 | 108 | var_zuinteger_unlimited, |
aff410f1 MS |
109 | /* Enumerated type. Can only have one of the specified values. |
110 | *VAR is a char pointer to the name of the element that we | |
111 | find. */ | |
c5aa993b JM |
112 | var_enum |
113 | } | |
114 | var_types; | |
c906108c SS |
115 | |
116 | /* This structure records one command'd definition. */ | |
18a642a1 | 117 | struct cmd_list_element; |
c906108c | 118 | |
82ae6c8d | 119 | typedef void cmd_cfunc_ftype (char *args, int from_tty); |
0450cc4c | 120 | typedef void cmd_const_cfunc_ftype (const char *args, int from_tty); |
82ae6c8d | 121 | |
4034d0ff AT |
122 | /* This structure specifies notifications to be suppressed by a cli |
123 | command interpreter. */ | |
124 | ||
125 | struct cli_suppress_notification | |
126 | { | |
127 | /* Inferior, thread, frame selected notification suppressed? */ | |
128 | int user_selected_context; | |
129 | }; | |
130 | ||
131 | extern struct cli_suppress_notification cli_suppress_notification; | |
132 | ||
18d5d590 | 133 | /* Forward-declarations of the entry-points of cli/cli-decode.c. */ |
c906108c | 134 | |
50aeff07 PA |
135 | /* API to the manipulation of command lists. */ |
136 | ||
5a56e9c5 DE |
137 | extern int valid_user_defined_cmd_name_p (const char *name); |
138 | ||
6f937416 | 139 | extern struct cmd_list_element *add_cmd (const char *, enum command_class, |
82ae6c8d | 140 | cmd_cfunc_ftype *fun, |
1947513d | 141 | const char *, |
a14ed312 KB |
142 | struct cmd_list_element **); |
143 | ||
0450cc4c TT |
144 | /* Const-correct variant of the above. */ |
145 | ||
146 | extern struct cmd_list_element *add_cmd (const char *, enum command_class, | |
147 | cmd_const_cfunc_ftype *fun, | |
148 | const char *, | |
149 | struct cmd_list_element **); | |
150 | ||
151 | /* Like add_cmd, but no command function is specified. */ | |
152 | ||
153 | extern struct cmd_list_element *add_cmd (const char *, enum command_class, | |
154 | const char *, | |
155 | struct cmd_list_element **); | |
156 | ||
6f937416 | 157 | extern struct cmd_list_element *add_alias_cmd (const char *, const char *, |
a14ed312 KB |
158 | enum command_class, int, |
159 | struct cmd_list_element **); | |
160 | ||
21873064 YQ |
161 | extern struct cmd_list_element *add_alias_cmd (const char *, |
162 | cmd_list_element *, | |
163 | enum command_class, int, | |
164 | struct cmd_list_element **); | |
165 | ||
166 | ||
6f937416 | 167 | extern struct cmd_list_element *add_prefix_cmd (const char *, enum command_class, |
981a3fb3 | 168 | cmd_const_cfunc_ftype *fun, |
1947513d | 169 | const char *, |
a14ed312 | 170 | struct cmd_list_element **, |
64e61d29 | 171 | const char *, int, |
a14ed312 KB |
172 | struct cmd_list_element **); |
173 | ||
6f937416 | 174 | extern struct cmd_list_element *add_abbrev_prefix_cmd (const char *, |
a14ed312 | 175 | enum command_class, |
ee7ddd71 | 176 | cmd_const_cfunc_ftype *fun, |
1947513d | 177 | const char *, |
a14ed312 | 178 | struct cmd_list_element |
64e61d29 | 179 | **, const char *, int, |
a14ed312 KB |
180 | struct cmd_list_element |
181 | **); | |
182 | ||
9773a94b AC |
183 | typedef void cmd_sfunc_ftype (char *args, int from_tty, |
184 | struct cmd_list_element *c); | |
9f60d481 | 185 | extern void set_cmd_sfunc (struct cmd_list_element *cmd, |
9773a94b | 186 | cmd_sfunc_ftype *sfunc); |
9f60d481 | 187 | |
eb3ff9a5 | 188 | /* A completion routine. Add possible completions to tracker. |
6e1dbf8c PA |
189 | |
190 | TEXT is the text beyond what was matched for the command itself | |
191 | (leading whitespace is skipped). It stops where we are supposed to | |
192 | stop completing (rl_point) and is '\0' terminated. WORD points in | |
193 | the same buffer as TEXT, and completions should be returned | |
194 | relative to this position. For example, suppose TEXT is "foo" and | |
195 | we want to complete to "foobar". If WORD is "oo", return "oobar"; | |
196 | if WORD is "baz/foo", return "baz/foobar". */ | |
eb3ff9a5 PA |
197 | typedef void completer_ftype (struct cmd_list_element *, |
198 | completion_tracker &tracker, | |
199 | const char *text, const char *word); | |
625e8578 | 200 | |
6e1dbf8c PA |
201 | /* Same, but for set_cmd_completer_handle_brkchars. */ |
202 | typedef void completer_handle_brkchars_ftype (struct cmd_list_element *, | |
eb3ff9a5 | 203 | completion_tracker &tracker, |
6e1dbf8c | 204 | const char *text, const char *word); |
7d793aa9 | 205 | |
625e8578 | 206 | extern void set_cmd_completer (struct cmd_list_element *, completer_ftype *); |
5ba2abeb | 207 | |
7d793aa9 SDJ |
208 | /* Set the completer_handle_brkchars callback. */ |
209 | ||
210 | extern void set_cmd_completer_handle_brkchars (struct cmd_list_element *, | |
6e1dbf8c | 211 | completer_handle_brkchars_ftype *); |
7d793aa9 | 212 | |
bbaca940 AC |
213 | /* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs |
214 | around in cmd objects to test the value of the commands sfunc(). */ | |
215 | extern int cmd_cfunc_eq (struct cmd_list_element *cmd, | |
82ae6c8d | 216 | cmd_cfunc_ftype *cfun); |
0450cc4c TT |
217 | extern int cmd_cfunc_eq (struct cmd_list_element *cmd, |
218 | cmd_const_cfunc_ftype *cfun); | |
9f60d481 | 219 | |
ebcd3b23 | 220 | /* Each command object has a local context attached to it. */ |
aff410f1 MS |
221 | extern void set_cmd_context (struct cmd_list_element *cmd, |
222 | void *context); | |
7d0766f3 AC |
223 | extern void *get_cmd_context (struct cmd_list_element *cmd); |
224 | ||
225 | ||
5913bcb0 AC |
226 | /* Execute CMD's pre/post hook. Throw an error if the command fails. |
227 | If already executing this pre/post hook, or there is no pre/post | |
228 | hook, the call is silently ignored. */ | |
229 | extern void execute_cmd_pre_hook (struct cmd_list_element *cmd); | |
230 | extern void execute_cmd_post_hook (struct cmd_list_element *cmd); | |
231 | ||
1868c04e | 232 | /* Return the type of the command. */ |
1868c04e AC |
233 | extern enum cmd_types cmd_type (struct cmd_list_element *cmd); |
234 | ||
50aeff07 PA |
235 | /* Flag for an ambiguous cmd_list result. */ |
236 | #define CMD_LIST_AMBIGUOUS ((struct cmd_list_element *) -1) | |
1868c04e | 237 | |
6f937416 | 238 | extern struct cmd_list_element *lookup_cmd (const char **, |
a121b7c1 PA |
239 | struct cmd_list_element *, |
240 | const char *, | |
a14ed312 KB |
241 | int, int); |
242 | ||
6f937416 | 243 | extern struct cmd_list_element *lookup_cmd_1 (const char **, |
a14ed312 KB |
244 | struct cmd_list_element *, |
245 | struct cmd_list_element **, | |
246 | int); | |
c906108c | 247 | |
aff410f1 | 248 | extern struct cmd_list_element *deprecate_cmd (struct cmd_list_element *, |
429e55ea | 249 | const char * ); |
56382845 | 250 | |
6f937416 | 251 | extern void deprecated_cmd_warning (const char *); |
56382845 | 252 | |
6f937416 | 253 | extern int lookup_cmd_composition (const char *text, |
aff410f1 MS |
254 | struct cmd_list_element **alias, |
255 | struct cmd_list_element **prefix_cmd, | |
256 | struct cmd_list_element **cmd); | |
56382845 | 257 | |
6f937416 | 258 | extern struct cmd_list_element *add_com (const char *, enum command_class, |
82ae6c8d | 259 | cmd_cfunc_ftype *fun, |
1947513d | 260 | const char *); |
c906108c | 261 | |
6f937416 | 262 | extern struct cmd_list_element *add_com_alias (const char *, const char *, |
a14ed312 | 263 | enum command_class, int); |
c906108c | 264 | |
4034d0ff AT |
265 | extern struct cmd_list_element *add_com_suppress_notification |
266 | (const char *name, enum command_class theclass, | |
1ee870c5 | 267 | cmd_const_cfunc_ftype *fun, const char *doc, |
4034d0ff AT |
268 | int *supress_notification); |
269 | ||
6f937416 | 270 | extern struct cmd_list_element *add_info (const char *, |
82ae6c8d | 271 | cmd_cfunc_ftype *fun, |
1947513d | 272 | const char *); |
c906108c | 273 | |
1947513d TT |
274 | extern struct cmd_list_element *add_info_alias (const char *, const char *, |
275 | int); | |
c906108c | 276 | |
eb3ff9a5 PA |
277 | extern void complete_on_cmdlist (struct cmd_list_element *, |
278 | completion_tracker &tracker, | |
279 | const char *, const char *, int); | |
c906108c | 280 | |
eb3ff9a5 PA |
281 | extern void complete_on_enum (completion_tracker &tracker, |
282 | const char *const *enumlist, | |
283 | const char *, const char *); | |
c906108c | 284 | |
50aeff07 | 285 | /* Functions that implement commands about CLI commands. */ |
c906108c | 286 | |
64e61d29 | 287 | extern void help_list (struct cmd_list_element *, const char *, |
d9fcf2fb | 288 | enum command_class, struct ui_file *); |
c906108c | 289 | |
08546159 AC |
290 | /* Method for show a set/show variable's VALUE on FILE. If this |
291 | method isn't supplied deprecated_show_value_hack() is called (which | |
292 | is not good). */ | |
293 | typedef void (show_value_ftype) (struct ui_file *file, | |
294 | int from_tty, | |
295 | struct cmd_list_element *cmd, | |
296 | const char *value); | |
297 | /* NOTE: i18n: This function is not i18n friendly. Callers should | |
298 | instead print the value out directly. */ | |
299 | extern show_value_ftype deprecated_show_value_hack; | |
300 | ||
6f937416 | 301 | extern void add_setshow_enum_cmd (const char *name, |
fe978cb0 | 302 | enum command_class theclass, |
40478521 | 303 | const char *const *enumlist, |
1b295c3d AC |
304 | const char **var, |
305 | const char *set_doc, | |
306 | const char *show_doc, | |
307 | const char *help_doc, | |
1b295c3d | 308 | cmd_sfunc_ftype *set_func, |
08546159 | 309 | show_value_ftype *show_func, |
1b295c3d | 310 | struct cmd_list_element **set_list, |
7376b4c2 | 311 | struct cmd_list_element **show_list); |
c906108c | 312 | |
6f937416 | 313 | extern void add_setshow_auto_boolean_cmd (const char *name, |
fe978cb0 | 314 | enum command_class theclass, |
e9e68a56 | 315 | enum auto_boolean *var, |
3b64bf98 AC |
316 | const char *set_doc, |
317 | const char *show_doc, | |
318 | const char *help_doc, | |
e9e68a56 | 319 | cmd_sfunc_ftype *set_func, |
08546159 | 320 | show_value_ftype *show_func, |
e9e68a56 AC |
321 | struct cmd_list_element **set_list, |
322 | struct cmd_list_element **show_list); | |
97c3646f | 323 | |
6f937416 | 324 | extern void add_setshow_boolean_cmd (const char *name, |
fe978cb0 | 325 | enum command_class theclass, |
e707bbc2 | 326 | int *var, |
3b64bf98 | 327 | const char *set_doc, const char *show_doc, |
2c5b56ce | 328 | const char *help_doc, |
e707bbc2 | 329 | cmd_sfunc_ftype *set_func, |
08546159 | 330 | show_value_ftype *show_func, |
e707bbc2 AC |
331 | struct cmd_list_element **set_list, |
332 | struct cmd_list_element **show_list); | |
f3796e26 | 333 | |
6f937416 | 334 | extern void add_setshow_filename_cmd (const char *name, |
fe978cb0 | 335 | enum command_class theclass, |
b3f42336 AC |
336 | char **var, |
337 | const char *set_doc, | |
338 | const char *show_doc, | |
339 | const char *help_doc, | |
b3f42336 | 340 | cmd_sfunc_ftype *set_func, |
08546159 | 341 | show_value_ftype *show_func, |
b3f42336 AC |
342 | struct cmd_list_element **set_list, |
343 | struct cmd_list_element **show_list); | |
344 | ||
6f937416 | 345 | extern void add_setshow_string_cmd (const char *name, |
fe978cb0 | 346 | enum command_class theclass, |
5efd5804 PA |
347 | char **var, |
348 | const char *set_doc, | |
349 | const char *show_doc, | |
350 | const char *help_doc, | |
351 | cmd_sfunc_ftype *set_func, | |
352 | show_value_ftype *show_func, | |
353 | struct cmd_list_element **set_list, | |
354 | struct cmd_list_element **show_list); | |
355 | ||
44478ab3 | 356 | extern struct cmd_list_element *add_setshow_string_noescape_cmd |
6f937416 | 357 | (const char *name, |
fe978cb0 | 358 | enum command_class theclass, |
44478ab3 TT |
359 | char **var, |
360 | const char *set_doc, | |
361 | const char *show_doc, | |
362 | const char *help_doc, | |
363 | cmd_sfunc_ftype *set_func, | |
364 | show_value_ftype *show_func, | |
365 | struct cmd_list_element **set_list, | |
366 | struct cmd_list_element **show_list); | |
26c41df3 | 367 | |
6f937416 | 368 | extern void add_setshow_optional_filename_cmd (const char *name, |
fe978cb0 | 369 | enum command_class theclass, |
b4b4ac0b AC |
370 | char **var, |
371 | const char *set_doc, | |
372 | const char *show_doc, | |
373 | const char *help_doc, | |
374 | cmd_sfunc_ftype *set_func, | |
375 | show_value_ftype *show_func, | |
376 | struct cmd_list_element **set_list, | |
377 | struct cmd_list_element **show_list); | |
378 | ||
6f937416 | 379 | extern void add_setshow_integer_cmd (const char *name, |
fe978cb0 | 380 | enum command_class theclass, |
5efd5804 PA |
381 | int *var, |
382 | const char *set_doc, | |
383 | const char *show_doc, | |
384 | const char *help_doc, | |
385 | cmd_sfunc_ftype *set_func, | |
386 | show_value_ftype *show_func, | |
387 | struct cmd_list_element **set_list, | |
388 | struct cmd_list_element **show_list); | |
c0d88b1b | 389 | |
6f937416 | 390 | extern void add_setshow_uinteger_cmd (const char *name, |
fe978cb0 | 391 | enum command_class theclass, |
5efd5804 PA |
392 | unsigned int *var, |
393 | const char *set_doc, | |
394 | const char *show_doc, | |
395 | const char *help_doc, | |
396 | cmd_sfunc_ftype *set_func, | |
397 | show_value_ftype *show_func, | |
398 | struct cmd_list_element **set_list, | |
399 | struct cmd_list_element **show_list); | |
15170568 | 400 | |
6f937416 | 401 | extern void add_setshow_zinteger_cmd (const char *name, |
fe978cb0 | 402 | enum command_class theclass, |
5efd5804 PA |
403 | int *var, |
404 | const char *set_doc, | |
405 | const char *show_doc, | |
406 | const char *help_doc, | |
407 | cmd_sfunc_ftype *set_func, | |
408 | show_value_ftype *show_func, | |
409 | struct cmd_list_element **set_list, | |
410 | struct cmd_list_element **show_list); | |
25d29d70 | 411 | |
6f937416 | 412 | extern void add_setshow_zuinteger_cmd (const char *name, |
fe978cb0 | 413 | enum command_class theclass, |
5efd5804 PA |
414 | unsigned int *var, |
415 | const char *set_doc, | |
416 | const char *show_doc, | |
417 | const char *help_doc, | |
6fc1c773 YQ |
418 | cmd_sfunc_ftype *set_func, |
419 | show_value_ftype *show_func, | |
420 | struct cmd_list_element **set_list, | |
421 | struct cmd_list_element **show_list); | |
422 | ||
423 | extern void | |
6f937416 | 424 | add_setshow_zuinteger_unlimited_cmd (const char *name, |
fe978cb0 | 425 | enum command_class theclass, |
b69b1fb1 | 426 | int *var, |
6fc1c773 YQ |
427 | const char *set_doc, |
428 | const char *show_doc, | |
429 | const char *help_doc, | |
5efd5804 PA |
430 | cmd_sfunc_ftype *set_func, |
431 | show_value_ftype *show_func, | |
432 | struct cmd_list_element **set_list, | |
433 | struct cmd_list_element **show_list); | |
1e8fb976 | 434 | |
c906108c SS |
435 | /* Do a "show" command for each thing on a command list. */ |
436 | ||
64e61d29 | 437 | extern void cmd_show_list (struct cmd_list_element *, int, const char *); |
c906108c | 438 | |
c25c4a8b | 439 | /* Used everywhere whenever at least one parameter is required and |
ebcd3b23 | 440 | none is specified. */ |
c25c4a8b | 441 | |
5b10184c | 442 | extern void error_no_arg (const char *) ATTRIBUTE_NORETURN; |
c906108c | 443 | |
a14ed312 | 444 | extern void dont_repeat (void); |
c906108c | 445 | |
1ac32117 | 446 | extern scoped_restore_tmpl<int> prevent_dont_repeat (void); |
47a80e90 | 447 | |
c906108c SS |
448 | /* Used to mark commands that don't do anything. If we just leave the |
449 | function field NULL, the command is interpreted as a help topic, or | |
450 | as a class of commands. */ | |
451 | ||
eb7c454d | 452 | extern void not_just_help_class_command (const char *, int); |
c906108c | 453 | |
aff410f1 | 454 | /* Check function pointer. */ |
f436dd25 MH |
455 | extern int cmd_func_p (struct cmd_list_element *cmd); |
456 | ||
aff410f1 MS |
457 | /* Call the command function. */ |
458 | extern void cmd_func (struct cmd_list_element *cmd, | |
459 | char *args, int from_tty); | |
f436dd25 | 460 | |
c906108c | 461 | #endif /* !defined (COMMAND_H) */ |