]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/command.h
Fix inconsistent output of prefix and bugs in 'show' command
[thirdparty/binutils-gdb.git] / gdb / command.h
1 /* Header file for command creation.
2
3 Copyright (C) 1986-2020 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 #if !defined (COMMAND_H)
19 #define COMMAND_H 1
20
21 #include "gdbsupport/gdb_vecs.h"
22 #include "gdbsupport/scoped_restore.h"
23
24 struct completion_tracker;
25
26 /* This file defines the public interface for any code wanting to
27 create commands. */
28
29 /* Command classes are top-level categories into which commands are
30 broken down for "help" purposes.
31
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 */
39 class_deprecated = -3, all_classes = -2, all_commands = -1,
40 /* Classes of commands */
41 no_class = -1, class_run = 0, class_vars, class_stack, class_files,
42 class_support, class_info, class_breakpoint, class_trace,
43 class_alias, class_bookmark, class_obscure, class_maintenance,
44 class_tui, class_user, class_xdb,
45 no_set_class /* Used for "show" commands that have no corresponding
46 "set" command. */
47 };
48
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". */
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. */
54 typedef enum cmd_types
55 {
56 not_set_cmd,
57 set_cmd,
58 show_cmd
59 }
60 cmd_types;
61
62 /* Types of "set" or "show" command. */
63 typedef enum var_types
64 {
65 /* "on" or "off". *VAR is a bool which is true for on,
66 false for off. */
67 var_boolean,
68
69 /* "on" / "true" / "enable" or "off" / "false" / "disable" or
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
73 value. */
74 var_auto_boolean,
75
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. */
78 var_uinteger,
79
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
82 INT_MAX. The only remaining use of it is the Python API.
83 Don't use it elsewhere. */
84 var_integer,
85
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).
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,
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. */
98 var_filename,
99 /* ZeroableInteger. *VAR is an int. Like var_integer except
100 that zero really means zero. */
101 var_zinteger,
102 /* ZeroableUnsignedInteger. *VAR is an unsigned int. Zero really
103 means zero. */
104 var_zuinteger,
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. */
108 var_zuinteger_unlimited,
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. */
112 var_enum
113 }
114 var_types;
115
116 /* This structure records one command'd definition. */
117 struct cmd_list_element;
118
119 typedef void cmd_const_cfunc_ftype (const char *args, int from_tty);
120
121 /* This structure specifies notifications to be suppressed by a cli
122 command interpreter. */
123
124 struct cli_suppress_notification
125 {
126 /* Inferior, thread, frame selected notification suppressed? */
127 int user_selected_context;
128 };
129
130 extern struct cli_suppress_notification cli_suppress_notification;
131
132 /* Forward-declarations of the entry-points of cli/cli-decode.c. */
133
134 /* API to the manipulation of command lists. */
135
136 /* Return TRUE if NAME is a valid user-defined command name.
137 This is a stricter subset of all gdb commands,
138 see find_command_name_length. */
139
140 extern bool valid_user_defined_cmd_name_p (const char *name);
141
142 /* Return TRUE if C is a valid command character. */
143
144 extern bool valid_cmd_char_p (int c);
145
146 /* Const-correct variant of the above. */
147
148 extern struct cmd_list_element *add_cmd (const char *, enum command_class,
149 cmd_const_cfunc_ftype *fun,
150 const char *,
151 struct cmd_list_element **);
152
153 /* Like add_cmd, but no command function is specified. */
154
155 extern struct cmd_list_element *add_cmd (const char *, enum command_class,
156 const char *,
157 struct cmd_list_element **);
158
159 extern struct cmd_list_element *add_cmd_suppress_notification
160 (const char *name, enum command_class theclass,
161 cmd_const_cfunc_ftype *fun, const char *doc,
162 struct cmd_list_element **list,
163 int *suppress_notification);
164
165 extern struct cmd_list_element *add_alias_cmd (const char *, const char *,
166 enum command_class, int,
167 struct cmd_list_element **);
168
169 extern struct cmd_list_element *add_alias_cmd (const char *,
170 cmd_list_element *,
171 enum command_class, int,
172 struct cmd_list_element **);
173
174
175 extern struct cmd_list_element *add_prefix_cmd (const char *, enum command_class,
176 cmd_const_cfunc_ftype *fun,
177 const char *,
178 struct cmd_list_element **,
179 const char *, int,
180 struct cmd_list_element **);
181
182 /* Like add_prefix_cmd, but sets the callback to a function that
183 simply calls help_list. */
184
185 extern struct cmd_list_element *add_basic_prefix_cmd
186 (const char *, enum command_class, const char *, struct cmd_list_element **,
187 const char *, int, struct cmd_list_element **);
188
189 /* Like add_prefix_cmd, but useful for "show" prefixes. This sets the
190 callback to a function that simply calls cmd_show_list. */
191
192 extern struct cmd_list_element *add_show_prefix_cmd
193 (const char *, enum command_class, const char *, struct cmd_list_element **,
194 const char *, int, struct cmd_list_element **);
195
196 extern struct cmd_list_element *add_prefix_cmd_suppress_notification
197 (const char *name, enum command_class theclass,
198 cmd_const_cfunc_ftype *fun,
199 const char *doc, struct cmd_list_element **prefixlist,
200 const char *prefixname, int allow_unknown,
201 struct cmd_list_element **list,
202 int *suppress_notification);
203
204 extern struct cmd_list_element *add_abbrev_prefix_cmd (const char *,
205 enum command_class,
206 cmd_const_cfunc_ftype *fun,
207 const char *,
208 struct cmd_list_element
209 **, const char *, int,
210 struct cmd_list_element
211 **);
212
213 typedef void cmd_const_sfunc_ftype (const char *args, int from_tty,
214 struct cmd_list_element *c);
215 extern void set_cmd_sfunc (struct cmd_list_element *cmd,
216 cmd_const_sfunc_ftype *sfunc);
217
218 /* A completion routine. Add possible completions to tracker.
219
220 TEXT is the text beyond what was matched for the command itself
221 (leading whitespace is skipped). It stops where we are supposed to
222 stop completing (rl_point) and is '\0' terminated. WORD points in
223 the same buffer as TEXT, and completions should be returned
224 relative to this position. For example, suppose TEXT is "foo" and
225 we want to complete to "foobar". If WORD is "oo", return "oobar";
226 if WORD is "baz/foo", return "baz/foobar". */
227 typedef void completer_ftype (struct cmd_list_element *,
228 completion_tracker &tracker,
229 const char *text, const char *word);
230
231 /* Same, but for set_cmd_completer_handle_brkchars. */
232 typedef void completer_handle_brkchars_ftype (struct cmd_list_element *,
233 completion_tracker &tracker,
234 const char *text, const char *word);
235
236 extern void set_cmd_completer (struct cmd_list_element *, completer_ftype *);
237
238 /* Set the completer_handle_brkchars callback. */
239
240 extern void set_cmd_completer_handle_brkchars (struct cmd_list_element *,
241 completer_handle_brkchars_ftype *);
242
243 /* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs
244 around in cmd objects to test the value of the commands sfunc(). */
245 extern int cmd_cfunc_eq (struct cmd_list_element *cmd,
246 cmd_const_cfunc_ftype *cfun);
247
248 /* Each command object has a local context attached to it. */
249 extern void set_cmd_context (struct cmd_list_element *cmd,
250 void *context);
251 extern void *get_cmd_context (struct cmd_list_element *cmd);
252
253
254 /* Execute CMD's pre/post hook. Throw an error if the command fails.
255 If already executing this pre/post hook, or there is no pre/post
256 hook, the call is silently ignored. */
257 extern void execute_cmd_pre_hook (struct cmd_list_element *cmd);
258 extern void execute_cmd_post_hook (struct cmd_list_element *cmd);
259
260 /* Return the type of the command. */
261 extern enum cmd_types cmd_type (struct cmd_list_element *cmd);
262
263 /* Flag for an ambiguous cmd_list result. */
264 #define CMD_LIST_AMBIGUOUS ((struct cmd_list_element *) -1)
265
266 extern struct cmd_list_element *lookup_cmd (const char **,
267 struct cmd_list_element *,
268 const char *,
269 int, int);
270
271 extern struct cmd_list_element *lookup_cmd_1 (const char **,
272 struct cmd_list_element *,
273 struct cmd_list_element **,
274 int);
275
276 extern struct cmd_list_element *deprecate_cmd (struct cmd_list_element *,
277 const char * );
278
279 extern void deprecated_cmd_warning (const char *);
280
281 extern int lookup_cmd_composition (const char *text,
282 struct cmd_list_element **alias,
283 struct cmd_list_element **prefix_cmd,
284 struct cmd_list_element **cmd);
285
286 extern struct cmd_list_element *add_com (const char *, enum command_class,
287 cmd_const_cfunc_ftype *fun,
288 const char *);
289
290 extern struct cmd_list_element *add_com_alias (const char *, const char *,
291 enum command_class, int);
292
293 extern struct cmd_list_element *add_com_suppress_notification
294 (const char *name, enum command_class theclass,
295 cmd_const_cfunc_ftype *fun, const char *doc,
296 int *supress_notification);
297
298 extern struct cmd_list_element *add_info (const char *,
299 cmd_const_cfunc_ftype *fun,
300 const char *);
301
302 extern struct cmd_list_element *add_info_alias (const char *, const char *,
303 int);
304
305 extern void complete_on_cmdlist (struct cmd_list_element *,
306 completion_tracker &tracker,
307 const char *, const char *, int);
308
309 extern void complete_on_enum (completion_tracker &tracker,
310 const char *const *enumlist,
311 const char *, const char *);
312
313 /* Functions that implement commands about CLI commands. */
314
315 extern void help_list (struct cmd_list_element *, const char *,
316 enum command_class, struct ui_file *);
317
318 /* Method for show a set/show variable's VALUE on FILE. If this
319 method isn't supplied deprecated_show_value_hack() is called (which
320 is not good). */
321 typedef void (show_value_ftype) (struct ui_file *file,
322 int from_tty,
323 struct cmd_list_element *cmd,
324 const char *value);
325 /* NOTE: i18n: This function is not i18n friendly. Callers should
326 instead print the value out directly. */
327 extern show_value_ftype deprecated_show_value_hack;
328
329 extern void add_setshow_enum_cmd (const char *name,
330 enum command_class theclass,
331 const char *const *enumlist,
332 const char **var,
333 const char *set_doc,
334 const char *show_doc,
335 const char *help_doc,
336 cmd_const_sfunc_ftype *set_func,
337 show_value_ftype *show_func,
338 struct cmd_list_element **set_list,
339 struct cmd_list_element **show_list,
340 void *context = nullptr);
341
342 extern void add_setshow_auto_boolean_cmd (const char *name,
343 enum command_class theclass,
344 enum auto_boolean *var,
345 const char *set_doc,
346 const char *show_doc,
347 const char *help_doc,
348 cmd_const_sfunc_ftype *set_func,
349 show_value_ftype *show_func,
350 struct cmd_list_element **set_list,
351 struct cmd_list_element **show_list);
352
353 extern cmd_list_element *
354 add_setshow_boolean_cmd (const char *name,
355 enum command_class theclass,
356 bool *var,
357 const char *set_doc, const char *show_doc,
358 const char *help_doc,
359 cmd_const_sfunc_ftype *set_func,
360 show_value_ftype *show_func,
361 struct cmd_list_element **set_list,
362 struct cmd_list_element **show_list);
363
364 extern void add_setshow_filename_cmd (const char *name,
365 enum command_class theclass,
366 char **var,
367 const char *set_doc,
368 const char *show_doc,
369 const char *help_doc,
370 cmd_const_sfunc_ftype *set_func,
371 show_value_ftype *show_func,
372 struct cmd_list_element **set_list,
373 struct cmd_list_element **show_list);
374
375 extern void add_setshow_string_cmd (const char *name,
376 enum command_class theclass,
377 char **var,
378 const char *set_doc,
379 const char *show_doc,
380 const char *help_doc,
381 cmd_const_sfunc_ftype *set_func,
382 show_value_ftype *show_func,
383 struct cmd_list_element **set_list,
384 struct cmd_list_element **show_list);
385
386 extern struct cmd_list_element *add_setshow_string_noescape_cmd
387 (const char *name,
388 enum command_class theclass,
389 char **var,
390 const char *set_doc,
391 const char *show_doc,
392 const char *help_doc,
393 cmd_const_sfunc_ftype *set_func,
394 show_value_ftype *show_func,
395 struct cmd_list_element **set_list,
396 struct cmd_list_element **show_list);
397
398 extern void add_setshow_optional_filename_cmd (const char *name,
399 enum command_class theclass,
400 char **var,
401 const char *set_doc,
402 const char *show_doc,
403 const char *help_doc,
404 cmd_const_sfunc_ftype *set_func,
405 show_value_ftype *show_func,
406 struct cmd_list_element **set_list,
407 struct cmd_list_element **show_list);
408
409 extern void add_setshow_integer_cmd (const char *name,
410 enum command_class theclass,
411 int *var,
412 const char *set_doc,
413 const char *show_doc,
414 const char *help_doc,
415 cmd_const_sfunc_ftype *set_func,
416 show_value_ftype *show_func,
417 struct cmd_list_element **set_list,
418 struct cmd_list_element **show_list);
419
420 extern void add_setshow_uinteger_cmd (const char *name,
421 enum command_class theclass,
422 unsigned int *var,
423 const char *set_doc,
424 const char *show_doc,
425 const char *help_doc,
426 cmd_const_sfunc_ftype *set_func,
427 show_value_ftype *show_func,
428 struct cmd_list_element **set_list,
429 struct cmd_list_element **show_list);
430
431 extern void add_setshow_zinteger_cmd (const char *name,
432 enum command_class theclass,
433 int *var,
434 const char *set_doc,
435 const char *show_doc,
436 const char *help_doc,
437 cmd_const_sfunc_ftype *set_func,
438 show_value_ftype *show_func,
439 struct cmd_list_element **set_list,
440 struct cmd_list_element **show_list);
441
442 extern void add_setshow_zuinteger_cmd (const char *name,
443 enum command_class theclass,
444 unsigned int *var,
445 const char *set_doc,
446 const char *show_doc,
447 const char *help_doc,
448 cmd_const_sfunc_ftype *set_func,
449 show_value_ftype *show_func,
450 struct cmd_list_element **set_list,
451 struct cmd_list_element **show_list);
452
453 extern void
454 add_setshow_zuinteger_unlimited_cmd (const char *name,
455 enum command_class theclass,
456 int *var,
457 const char *set_doc,
458 const char *show_doc,
459 const char *help_doc,
460 cmd_const_sfunc_ftype *set_func,
461 show_value_ftype *show_func,
462 struct cmd_list_element **set_list,
463 struct cmd_list_element **show_list);
464
465 /* Do a "show" command for each thing on a command list. */
466
467 extern void cmd_show_list (struct cmd_list_element *, int);
468
469 /* Used everywhere whenever at least one parameter is required and
470 none is specified. */
471
472 extern void error_no_arg (const char *) ATTRIBUTE_NORETURN;
473
474
475 /* Command line saving and repetition.
476 Each input line executed is saved to possibly be repeated either
477 when the user types an empty line, or be repeated by a command
478 that wants to repeat the previously executed command. The below
479 functions control command repetition. */
480
481 /* Commands call dont_repeat if they do not want to be repeated by null
482 lines or by repeat_previous (). */
483
484 extern void dont_repeat ();
485
486 /* Commands call repeat_previous if they want to repeat the previous
487 command. Such commands that repeat the previous command must
488 indicate to not repeat themselves, to avoid recursive repeat.
489 repeat_previous marks the current command as not repeating, and
490 ensures get_saved_command_line returns the previous command, so
491 that the currently executing command can repeat it. If there's no
492 previous command, throws an error. Otherwise, returns the result
493 of get_saved_command_line, which now points at the command to
494 repeat. */
495
496 extern const char *repeat_previous ();
497
498 /* Prevent dont_repeat from working, and return a cleanup that
499 restores the previous state. */
500
501 extern scoped_restore_tmpl<int> prevent_dont_repeat (void);
502
503 /* Set the arguments that will be passed if the current command is
504 repeated. Note that the passed-in string must be a constant. */
505
506 extern void set_repeat_arguments (const char *args);
507
508 /* Returns the saved command line to repeat.
509 When a command is being executed, this is the currently executing
510 command line, unless the currently executing command has called
511 repeat_previous (): in this case, get_saved_command_line returns
512 the previously saved command line. */
513
514 extern char *get_saved_command_line ();
515
516 /* Takes a copy of CMD, for possible repetition. */
517
518 extern void save_command_line (const char *cmd);
519
520 /* Used to mark commands that don't do anything. If we just leave the
521 function field NULL, the command is interpreted as a help topic, or
522 as a class of commands. */
523
524 extern void not_just_help_class_command (const char *, int);
525
526 /* Check function pointer. */
527 extern int cmd_func_p (struct cmd_list_element *cmd);
528
529 /* Call the command function. */
530 extern void cmd_func (struct cmd_list_element *cmd,
531 const char *args, int from_tty);
532
533 #endif /* !defined (COMMAND_H) */