libctf, binutils: support CTF archives like objdump
[deliverable/binutils-gdb.git] / gdb / command.h
CommitLineData
50aeff07 1/* Header file for command creation.
18a642a1 2
b811d2c2 3 Copyright (C) 1986-2020 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
268a13a5
TT
21#include "gdbsupport/gdb_vecs.h"
22#include "gdbsupport/scoped_restore.h"
49c4e619 23
eb3ff9a5
PA
24struct 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
57b4f16e
PW
32 The class_alias is used for the user-defined aliases, defined
33 using the "alias" command.
34
35 Aliases pre-defined by GDB (e.g. the alias "bt" of the "backtrace" command)
36 are not using the class_alias.
37 Different pre-defined aliases of the same command do not necessarily
38 have the same classes. For example, class_stack is used for the
39 "backtrace" and its "bt" alias", while "info stack" (also an alias
40 of "backtrace" uses class_info. */
6426a772
JM
41
42enum command_class
43{
57b4f16e
PW
44 /* Classes of commands followed by a comment giving the name
45 to use in "help <classname>".
46 Note that help accepts unambiguous abbreviated class names. */
47
48 /* Special classes to help_list */
49 class_deprecated = -3,
50 all_classes = -2, /* help without <classname> */
51 all_commands = -1, /* all */
52
6426a772 53 /* Classes of commands */
57b4f16e
PW
54 no_class = -1,
55 class_run = 0, /* running */
56 class_vars, /* data */
57 class_stack, /* stack */
58 class_files, /* files */
59 class_support, /* support */
60 class_info, /* status */
61 class_breakpoint, /* breakpoints */
62 class_trace, /* tracepoints */
63 class_alias, /* aliases */
64 class_bookmark,
65 class_obscure, /* obscure */
66 class_maintenance, /* internals */
e98d2e6d 67 class_tui, /* text-user-interface */
57b4f16e
PW
68 class_user, /* user-defined */
69
70 /* Used for "show" commands that have no corresponding "set" command. */
71 no_set_class
6426a772
JM
72};
73
18a642a1
AC
74/* FIXME: cagney/2002-03-17: Once cmd_type() has been removed, ``enum
75 cmd_types'' can be moved from "command.h" to "cli-decode.h". */
c906108c
SS
76/* Not a set/show command. Note that some commands which begin with
77 "set" or "show" might be in this category, if their syntax does
78 not fall into one of the following categories. */
c5aa993b
JM
79typedef enum cmd_types
80 {
81 not_set_cmd,
82 set_cmd,
83 show_cmd
84 }
85cmd_types;
c906108c
SS
86
87/* Types of "set" or "show" command. */
c5aa993b
JM
88typedef enum var_types
89 {
491144b5
CB
90 /* "on" or "off". *VAR is a bool which is true for on,
91 false for off. */
c5aa993b 92 var_boolean,
97c3646f
AC
93
94 /* "on" / "true" / "enable" or "off" / "false" / "disable" or
7f19b9a2
AC
95 "auto. *VAR is an ``enum auto_boolean''. NOTE: In general a
96 custom show command will need to be implemented - one that for
97 "auto" prints both the "auto" and the current auto-selected
ebcd3b23 98 value. */
97c3646f
AC
99 var_auto_boolean,
100
aff410f1
MS
101 /* Unsigned Integer. *VAR is an unsigned int. The user can type
102 0 to mean "unlimited", which is stored in *VAR as UINT_MAX. */
c5aa993b
JM
103 var_uinteger,
104
aff410f1
MS
105 /* Like var_uinteger but signed. *VAR is an int. The user can
106 type 0 to mean "unlimited", which is stored in *VAR as
6fc1c773
YQ
107 INT_MAX. The only remaining use of it is the Python API.
108 Don't use it elsewhere. */
c5aa993b
JM
109 var_integer,
110
aff410f1
MS
111 /* String which the user enters with escapes (e.g. the user types
112 \n and it is a real newline in the stored string).
c5aa993b
JM
113 *VAR is a malloc'd string, or NULL if the string is empty. */
114 var_string,
115 /* String which stores what the user types verbatim.
116 *VAR is a malloc'd string, or NULL if the string is empty. */
117 var_string_noescape,
b4b4ac0b
AC
118 /* String which stores a filename. (*VAR) is a malloc'd string,
119 or "" if the string was empty. */
120 var_optional_filename,
121 /* String which stores a filename. (*VAR) is a malloc'd
122 string. */
c5aa993b 123 var_filename,
a7c3d162 124 /* ZeroableInteger. *VAR is an int. Like var_integer except
c5aa993b
JM
125 that zero really means zero. */
126 var_zinteger,
1e8fb976
PA
127 /* ZeroableUnsignedInteger. *VAR is an unsigned int. Zero really
128 means zero. */
129 var_zuinteger,
b69b1fb1
YQ
130 /* ZeroableUnsignedInteger with unlimited value. *VAR is an int,
131 but its range is [0, INT_MAX]. -1 stands for unlimited and
132 other negative numbers are not allowed. */
6fc1c773 133 var_zuinteger_unlimited,
aff410f1
MS
134 /* Enumerated type. Can only have one of the specified values.
135 *VAR is a char pointer to the name of the element that we
136 find. */
c5aa993b
JM
137 var_enum
138 }
139var_types;
c906108c
SS
140
141/* This structure records one command'd definition. */
18a642a1 142struct cmd_list_element;
c906108c 143
0450cc4c 144typedef void cmd_const_cfunc_ftype (const char *args, int from_tty);
82ae6c8d 145
4034d0ff
AT
146/* This structure specifies notifications to be suppressed by a cli
147 command interpreter. */
148
149struct cli_suppress_notification
150{
151 /* Inferior, thread, frame selected notification suppressed? */
152 int user_selected_context;
153};
154
155extern struct cli_suppress_notification cli_suppress_notification;
156
18d5d590 157/* Forward-declarations of the entry-points of cli/cli-decode.c. */
c906108c 158
50aeff07
PA
159/* API to the manipulation of command lists. */
160
be09caf1
PW
161/* Return TRUE if NAME is a valid user-defined command name.
162 This is a stricter subset of all gdb commands,
163 see find_command_name_length. */
164
7f008c9e 165extern bool valid_user_defined_cmd_name_p (const char *name);
5a56e9c5 166
be09caf1
PW
167/* Return TRUE if C is a valid command character. */
168
169extern bool valid_cmd_char_p (int c);
170
0450cc4c
TT
171/* Const-correct variant of the above. */
172
173extern struct cmd_list_element *add_cmd (const char *, enum command_class,
174 cmd_const_cfunc_ftype *fun,
175 const char *,
176 struct cmd_list_element **);
177
178/* Like add_cmd, but no command function is specified. */
179
180extern struct cmd_list_element *add_cmd (const char *, enum command_class,
181 const char *,
182 struct cmd_list_element **);
183
f67ffa6a
AB
184extern struct cmd_list_element *add_cmd_suppress_notification
185 (const char *name, enum command_class theclass,
186 cmd_const_cfunc_ftype *fun, const char *doc,
187 struct cmd_list_element **list,
188 int *suppress_notification);
189
6f937416 190extern struct cmd_list_element *add_alias_cmd (const char *, const char *,
a14ed312
KB
191 enum command_class, int,
192 struct cmd_list_element **);
193
21873064
YQ
194extern struct cmd_list_element *add_alias_cmd (const char *,
195 cmd_list_element *,
196 enum command_class, int,
197 struct cmd_list_element **);
198
199
6f937416 200extern struct cmd_list_element *add_prefix_cmd (const char *, enum command_class,
981a3fb3 201 cmd_const_cfunc_ftype *fun,
1947513d 202 const char *,
a14ed312 203 struct cmd_list_element **,
64e61d29 204 const char *, int,
a14ed312
KB
205 struct cmd_list_element **);
206
0743fc83
TT
207/* Like add_prefix_cmd, but sets the callback to a function that
208 simply calls help_list. */
209
210extern struct cmd_list_element *add_basic_prefix_cmd
211 (const char *, enum command_class, const char *, struct cmd_list_element **,
212 const char *, int, struct cmd_list_element **);
213
214/* Like add_prefix_cmd, but useful for "show" prefixes. This sets the
215 callback to a function that simply calls cmd_show_list. */
216
217extern struct cmd_list_element *add_show_prefix_cmd
218 (const char *, enum command_class, const char *, struct cmd_list_element **,
219 const char *, int, struct cmd_list_element **);
220
f67ffa6a
AB
221extern struct cmd_list_element *add_prefix_cmd_suppress_notification
222 (const char *name, enum command_class theclass,
223 cmd_const_cfunc_ftype *fun,
224 const char *doc, struct cmd_list_element **prefixlist,
225 const char *prefixname, int allow_unknown,
226 struct cmd_list_element **list,
227 int *suppress_notification);
228
6f937416 229extern struct cmd_list_element *add_abbrev_prefix_cmd (const char *,
a14ed312 230 enum command_class,
ee7ddd71 231 cmd_const_cfunc_ftype *fun,
1947513d 232 const char *,
a14ed312 233 struct cmd_list_element
64e61d29 234 **, const char *, int,
a14ed312
KB
235 struct cmd_list_element
236 **);
237
eb4c3f4a
TT
238typedef void cmd_const_sfunc_ftype (const char *args, int from_tty,
239 struct cmd_list_element *c);
9f60d481 240extern void set_cmd_sfunc (struct cmd_list_element *cmd,
eb4c3f4a 241 cmd_const_sfunc_ftype *sfunc);
9f60d481 242
eb3ff9a5 243/* A completion routine. Add possible completions to tracker.
6e1dbf8c
PA
244
245 TEXT is the text beyond what was matched for the command itself
246 (leading whitespace is skipped). It stops where we are supposed to
247 stop completing (rl_point) and is '\0' terminated. WORD points in
248 the same buffer as TEXT, and completions should be returned
249 relative to this position. For example, suppose TEXT is "foo" and
250 we want to complete to "foobar". If WORD is "oo", return "oobar";
251 if WORD is "baz/foo", return "baz/foobar". */
eb3ff9a5
PA
252typedef void completer_ftype (struct cmd_list_element *,
253 completion_tracker &tracker,
254 const char *text, const char *word);
625e8578 255
6e1dbf8c
PA
256/* Same, but for set_cmd_completer_handle_brkchars. */
257typedef void completer_handle_brkchars_ftype (struct cmd_list_element *,
eb3ff9a5 258 completion_tracker &tracker,
6e1dbf8c 259 const char *text, const char *word);
7d793aa9 260
625e8578 261extern void set_cmd_completer (struct cmd_list_element *, completer_ftype *);
5ba2abeb 262
7d793aa9
SDJ
263/* Set the completer_handle_brkchars callback. */
264
265extern void set_cmd_completer_handle_brkchars (struct cmd_list_element *,
6e1dbf8c 266 completer_handle_brkchars_ftype *);
7d793aa9 267
bbaca940
AC
268/* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs
269 around in cmd objects to test the value of the commands sfunc(). */
0450cc4c
TT
270extern int cmd_cfunc_eq (struct cmd_list_element *cmd,
271 cmd_const_cfunc_ftype *cfun);
9f60d481 272
ebcd3b23 273/* Each command object has a local context attached to it. */
aff410f1
MS
274extern void set_cmd_context (struct cmd_list_element *cmd,
275 void *context);
7d0766f3
AC
276extern void *get_cmd_context (struct cmd_list_element *cmd);
277
278
5913bcb0
AC
279/* Execute CMD's pre/post hook. Throw an error if the command fails.
280 If already executing this pre/post hook, or there is no pre/post
281 hook, the call is silently ignored. */
282extern void execute_cmd_pre_hook (struct cmd_list_element *cmd);
283extern void execute_cmd_post_hook (struct cmd_list_element *cmd);
284
1868c04e 285/* Return the type of the command. */
1868c04e
AC
286extern enum cmd_types cmd_type (struct cmd_list_element *cmd);
287
50aeff07
PA
288/* Flag for an ambiguous cmd_list result. */
289#define CMD_LIST_AMBIGUOUS ((struct cmd_list_element *) -1)
1868c04e 290
6f937416 291extern struct cmd_list_element *lookup_cmd (const char **,
a121b7c1
PA
292 struct cmd_list_element *,
293 const char *,
cf00cd6f 294 std::string *,
a14ed312
KB
295 int, int);
296
6f937416 297extern struct cmd_list_element *lookup_cmd_1 (const char **,
a14ed312
KB
298 struct cmd_list_element *,
299 struct cmd_list_element **,
cf00cd6f 300 std::string *,
a14ed312 301 int);
c906108c 302
aff410f1 303extern struct cmd_list_element *deprecate_cmd (struct cmd_list_element *,
429e55ea 304 const char * );
56382845 305
6f937416 306extern void deprecated_cmd_warning (const char *);
56382845 307
6f937416 308extern int lookup_cmd_composition (const char *text,
aff410f1
MS
309 struct cmd_list_element **alias,
310 struct cmd_list_element **prefix_cmd,
311 struct cmd_list_element **cmd);
56382845 312
6f937416 313extern struct cmd_list_element *add_com (const char *, enum command_class,
0b39b52e 314 cmd_const_cfunc_ftype *fun,
1947513d 315 const char *);
c906108c 316
6f937416 317extern struct cmd_list_element *add_com_alias (const char *, const char *,
a14ed312 318 enum command_class, int);
c906108c 319
4034d0ff
AT
320extern struct cmd_list_element *add_com_suppress_notification
321 (const char *name, enum command_class theclass,
1ee870c5 322 cmd_const_cfunc_ftype *fun, const char *doc,
4034d0ff
AT
323 int *supress_notification);
324
6f937416 325extern struct cmd_list_element *add_info (const char *,
1d12d88f 326 cmd_const_cfunc_ftype *fun,
1947513d 327 const char *);
c906108c 328
1947513d
TT
329extern struct cmd_list_element *add_info_alias (const char *, const char *,
330 int);
c906108c 331
eb3ff9a5
PA
332extern void complete_on_cmdlist (struct cmd_list_element *,
333 completion_tracker &tracker,
334 const char *, const char *, int);
c906108c 335
eb3ff9a5
PA
336extern void complete_on_enum (completion_tracker &tracker,
337 const char *const *enumlist,
338 const char *, const char *);
c906108c 339
50aeff07 340/* Functions that implement commands about CLI commands. */
c906108c 341
64e61d29 342extern void help_list (struct cmd_list_element *, const char *,
d9fcf2fb 343 enum command_class, struct ui_file *);
c906108c 344
08546159
AC
345/* Method for show a set/show variable's VALUE on FILE. If this
346 method isn't supplied deprecated_show_value_hack() is called (which
347 is not good). */
348typedef void (show_value_ftype) (struct ui_file *file,
349 int from_tty,
350 struct cmd_list_element *cmd,
351 const char *value);
352/* NOTE: i18n: This function is not i18n friendly. Callers should
353 instead print the value out directly. */
354extern show_value_ftype deprecated_show_value_hack;
355
6f937416 356extern void add_setshow_enum_cmd (const char *name,
fe978cb0 357 enum command_class theclass,
40478521 358 const char *const *enumlist,
1b295c3d
AC
359 const char **var,
360 const char *set_doc,
361 const char *show_doc,
362 const char *help_doc,
eb4c3f4a 363 cmd_const_sfunc_ftype *set_func,
08546159 364 show_value_ftype *show_func,
1b295c3d 365 struct cmd_list_element **set_list,
7170dadf
TT
366 struct cmd_list_element **show_list,
367 void *context = nullptr);
c906108c 368
6f937416 369extern void add_setshow_auto_boolean_cmd (const char *name,
fe978cb0 370 enum command_class theclass,
e9e68a56 371 enum auto_boolean *var,
3b64bf98
AC
372 const char *set_doc,
373 const char *show_doc,
374 const char *help_doc,
eb4c3f4a 375 cmd_const_sfunc_ftype *set_func,
08546159 376 show_value_ftype *show_func,
e9e68a56
AC
377 struct cmd_list_element **set_list,
378 struct cmd_list_element **show_list);
97c3646f 379
2daf894e
PA
380extern cmd_list_element *
381 add_setshow_boolean_cmd (const char *name,
382 enum command_class theclass,
491144b5 383 bool *var,
2daf894e
PA
384 const char *set_doc, const char *show_doc,
385 const char *help_doc,
386 cmd_const_sfunc_ftype *set_func,
387 show_value_ftype *show_func,
388 struct cmd_list_element **set_list,
389 struct cmd_list_element **show_list);
f3796e26 390
6f937416 391extern void add_setshow_filename_cmd (const char *name,
fe978cb0 392 enum command_class theclass,
b3f42336
AC
393 char **var,
394 const char *set_doc,
395 const char *show_doc,
396 const char *help_doc,
eb4c3f4a 397 cmd_const_sfunc_ftype *set_func,
08546159 398 show_value_ftype *show_func,
b3f42336
AC
399 struct cmd_list_element **set_list,
400 struct cmd_list_element **show_list);
401
6f937416 402extern void add_setshow_string_cmd (const char *name,
fe978cb0 403 enum command_class theclass,
5efd5804
PA
404 char **var,
405 const char *set_doc,
406 const char *show_doc,
407 const char *help_doc,
eb4c3f4a 408 cmd_const_sfunc_ftype *set_func,
5efd5804
PA
409 show_value_ftype *show_func,
410 struct cmd_list_element **set_list,
411 struct cmd_list_element **show_list);
412
44478ab3 413extern struct cmd_list_element *add_setshow_string_noescape_cmd
6f937416 414 (const char *name,
fe978cb0 415 enum command_class theclass,
44478ab3
TT
416 char **var,
417 const char *set_doc,
418 const char *show_doc,
419 const char *help_doc,
eb4c3f4a 420 cmd_const_sfunc_ftype *set_func,
44478ab3
TT
421 show_value_ftype *show_func,
422 struct cmd_list_element **set_list,
423 struct cmd_list_element **show_list);
26c41df3 424
6f937416 425extern void add_setshow_optional_filename_cmd (const char *name,
fe978cb0 426 enum command_class theclass,
b4b4ac0b
AC
427 char **var,
428 const char *set_doc,
429 const char *show_doc,
430 const char *help_doc,
eb4c3f4a 431 cmd_const_sfunc_ftype *set_func,
b4b4ac0b
AC
432 show_value_ftype *show_func,
433 struct cmd_list_element **set_list,
434 struct cmd_list_element **show_list);
435
6f937416 436extern void add_setshow_integer_cmd (const char *name,
fe978cb0 437 enum command_class theclass,
5efd5804
PA
438 int *var,
439 const char *set_doc,
440 const char *show_doc,
441 const char *help_doc,
eb4c3f4a 442 cmd_const_sfunc_ftype *set_func,
5efd5804
PA
443 show_value_ftype *show_func,
444 struct cmd_list_element **set_list,
445 struct cmd_list_element **show_list);
c0d88b1b 446
6f937416 447extern void add_setshow_uinteger_cmd (const char *name,
fe978cb0 448 enum command_class theclass,
5efd5804
PA
449 unsigned int *var,
450 const char *set_doc,
451 const char *show_doc,
452 const char *help_doc,
eb4c3f4a 453 cmd_const_sfunc_ftype *set_func,
5efd5804
PA
454 show_value_ftype *show_func,
455 struct cmd_list_element **set_list,
456 struct cmd_list_element **show_list);
15170568 457
6f937416 458extern void add_setshow_zinteger_cmd (const char *name,
fe978cb0 459 enum command_class theclass,
5efd5804
PA
460 int *var,
461 const char *set_doc,
462 const char *show_doc,
463 const char *help_doc,
eb4c3f4a 464 cmd_const_sfunc_ftype *set_func,
5efd5804
PA
465 show_value_ftype *show_func,
466 struct cmd_list_element **set_list,
467 struct cmd_list_element **show_list);
25d29d70 468
6f937416 469extern void add_setshow_zuinteger_cmd (const char *name,
fe978cb0 470 enum command_class theclass,
5efd5804
PA
471 unsigned int *var,
472 const char *set_doc,
473 const char *show_doc,
474 const char *help_doc,
eb4c3f4a 475 cmd_const_sfunc_ftype *set_func,
6fc1c773
YQ
476 show_value_ftype *show_func,
477 struct cmd_list_element **set_list,
478 struct cmd_list_element **show_list);
479
480extern void
6f937416 481 add_setshow_zuinteger_unlimited_cmd (const char *name,
fe978cb0 482 enum command_class theclass,
b69b1fb1 483 int *var,
6fc1c773
YQ
484 const char *set_doc,
485 const char *show_doc,
486 const char *help_doc,
eb4c3f4a 487 cmd_const_sfunc_ftype *set_func,
5efd5804
PA
488 show_value_ftype *show_func,
489 struct cmd_list_element **set_list,
490 struct cmd_list_element **show_list);
1e8fb976 491
c906108c
SS
492/* Do a "show" command for each thing on a command list. */
493
7aa1b46f 494extern void cmd_show_list (struct cmd_list_element *, int);
c906108c 495
c25c4a8b 496/* Used everywhere whenever at least one parameter is required and
ebcd3b23 497 none is specified. */
c25c4a8b 498
5b10184c 499extern void error_no_arg (const char *) ATTRIBUTE_NORETURN;
c906108c 500
68bb5386
PW
501
502/* Command line saving and repetition.
503 Each input line executed is saved to possibly be repeated either
504 when the user types an empty line, or be repeated by a command
505 that wants to repeat the previously executed command. The below
506 functions control command repetition. */
507
508/* Commands call dont_repeat if they do not want to be repeated by null
509 lines or by repeat_previous (). */
510
511extern void dont_repeat ();
512
fdbc9870
PA
513/* Commands call repeat_previous if they want to repeat the previous
514 command. Such commands that repeat the previous command must
515 indicate to not repeat themselves, to avoid recursive repeat.
516 repeat_previous marks the current command as not repeating, and
517 ensures get_saved_command_line returns the previous command, so
518 that the currently executing command can repeat it. If there's no
519 previous command, throws an error. Otherwise, returns the result
520 of get_saved_command_line, which now points at the command to
521 repeat. */
522
523extern const char *repeat_previous ();
68bb5386
PW
524
525/* Prevent dont_repeat from working, and return a cleanup that
526 restores the previous state. */
c906108c 527
1ac32117 528extern scoped_restore_tmpl<int> prevent_dont_repeat (void);
47a80e90 529
85c4be7c
TT
530/* Set the arguments that will be passed if the current command is
531 repeated. Note that the passed-in string must be a constant. */
532
533extern void set_repeat_arguments (const char *args);
534
68bb5386
PW
535/* Returns the saved command line to repeat.
536 When a command is being executed, this is the currently executing
537 command line, unless the currently executing command has called
538 repeat_previous (): in this case, get_saved_command_line returns
539 the previously saved command line. */
540
541extern char *get_saved_command_line ();
542
543/* Takes a copy of CMD, for possible repetition. */
544
545extern void save_command_line (const char *cmd);
546
c906108c
SS
547/* Used to mark commands that don't do anything. If we just leave the
548 function field NULL, the command is interpreted as a help topic, or
549 as a class of commands. */
550
eb7c454d 551extern void not_just_help_class_command (const char *, int);
c906108c 552
aff410f1 553/* Check function pointer. */
f436dd25
MH
554extern int cmd_func_p (struct cmd_list_element *cmd);
555
aff410f1
MS
556/* Call the command function. */
557extern void cmd_func (struct cmd_list_element *cmd,
95a6b0a1 558 const char *args, int from_tty);
f436dd25 559
c906108c 560#endif /* !defined (COMMAND_H) */
This page took 1.326801 seconds and 4 git commands to generate.