1 /* Handle lists of commands, their decoding and documentation, for GDB.
3 Copyright (C) 1986-2022 Free Software Foundation, Inc.
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.
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.
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/>. */
21 #include "gdbsupport/gdb_regex.h"
22 #include "completer.h"
24 #include "cli/cli-cmds.h"
25 #include "cli/cli-decode.h"
26 #include "cli/cli-style.h"
27 #include "gdbsupport/gdb_optional.h"
29 /* Prototypes for local functions. */
31 static void undef_cmd_error (const char *, const char *);
33 static cmd_list_element::aliases_list_type delete_cmd
34 (const char *name
, cmd_list_element
**list
, cmd_list_element
**prehook
,
35 cmd_list_element
**prehookee
, cmd_list_element
**posthook
,
36 cmd_list_element
**posthookee
);
38 static struct cmd_list_element
*find_cmd (const char *command
,
40 struct cmd_list_element
*clist
,
41 int ignore_help_classes
,
44 static void help_cmd_list (struct cmd_list_element
*list
,
45 enum command_class theclass
,
47 struct ui_file
*stream
);
49 static void help_all (struct ui_file
*stream
);
51 static int lookup_cmd_composition_1 (const char *text
,
52 struct cmd_list_element
**alias
,
53 struct cmd_list_element
**prefix_cmd
,
54 struct cmd_list_element
**cmd
,
55 struct cmd_list_element
*cur_list
);
57 /* Look up a command whose 'subcommands' field is SUBCOMMANDS. Return the
58 command if found, otherwise return NULL. */
60 static struct cmd_list_element
*
61 lookup_cmd_with_subcommands (cmd_list_element
**subcommands
,
62 cmd_list_element
*list
)
64 struct cmd_list_element
*p
= NULL
;
66 for (p
= list
; p
!= NULL
; p
= p
->next
)
68 struct cmd_list_element
*q
;
73 else if (p
->subcommands
== subcommands
)
75 /* If we found an alias, we must return the aliased
77 return p
->is_alias () ? p
->alias_target
: p
;
80 q
= lookup_cmd_with_subcommands (subcommands
, *(p
->subcommands
));
89 print_help_for_command (const cmd_list_element
&c
,
90 bool recurse
, struct ui_file
*stream
);
93 do_simple_func (const char *args
, int from_tty
, cmd_list_element
*c
)
95 c
->function
.simple_func (args
, from_tty
);
99 set_cmd_simple_func (struct cmd_list_element
*cmd
, cmd_simple_func_ftype
*simple_func
)
101 if (simple_func
== NULL
)
104 cmd
->func
= do_simple_func
;
106 cmd
->function
.simple_func
= simple_func
;
110 cmd_simple_func_eq (struct cmd_list_element
*cmd
, cmd_simple_func_ftype
*simple_func
)
112 return (cmd
->func
== do_simple_func
113 && cmd
->function
.simple_func
== simple_func
);
117 set_cmd_completer (struct cmd_list_element
*cmd
, completer_ftype
*completer
)
119 cmd
->completer
= completer
; /* Ok. */
122 /* See definition in commands.h. */
125 set_cmd_completer_handle_brkchars (struct cmd_list_element
*cmd
,
126 completer_handle_brkchars_ftype
*func
)
128 cmd
->completer_handle_brkchars
= func
;
132 cmd_list_element::prefixname () const
134 if (!this->is_prefix ())
135 /* Not a prefix command. */
138 std::string prefixname
;
139 if (this->prefix
!= nullptr)
140 prefixname
= this->prefix
->prefixname ();
142 prefixname
+= this->name
;
148 /* See cli/cli-decode.h. */
150 std::vector
<std::string
>
151 cmd_list_element::command_components () const
153 std::vector
<std::string
> result
;
155 if (this->prefix
!= nullptr)
156 result
= this->prefix
->command_components ();
158 result
.emplace_back (std::string (this->name
));
162 /* Add element named NAME.
163 Space for NAME and DOC must be allocated by the caller.
164 CLASS is the top level category into which commands are broken down
166 FUN should be the function to execute the command;
167 it will get a character string as argument, with leading
168 and trailing blanks already eliminated.
170 DOC is a documentation string for the command.
171 Its first line should be a complete sentence.
172 It should start with ? for a command that is an abbreviation
173 or with * for a command that most users don't need to know about.
175 Add this command to command list *LIST.
177 Returns a pointer to the added command (not necessarily the head
180 static struct cmd_list_element
*
181 do_add_cmd (const char *name
, enum command_class theclass
,
182 const char *doc
, struct cmd_list_element
**list
)
184 struct cmd_list_element
*c
= new struct cmd_list_element (name
, theclass
,
187 /* Turn each alias of the old command into an alias of the new
189 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
190 &c
->hook_post
, &c
->hookee_post
);
192 for (cmd_list_element
&alias
: c
->aliases
)
193 alias
.alias_target
= c
;
196 c
->hook_pre
->hookee_pre
= c
;
199 c
->hookee_pre
->hook_pre
= c
;
202 c
->hook_post
->hookee_post
= c
;
205 c
->hookee_post
->hook_post
= c
;
207 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
214 cmd_list_element
*p
= *list
;
215 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
223 /* Search the prefix cmd of C, and assigns it to C->prefix.
224 See also add_prefix_cmd and update_prefix_field_of_prefixed_commands. */
225 cmd_list_element
*prefixcmd
= lookup_cmd_with_subcommands (list
, cmdlist
);
226 c
->prefix
= prefixcmd
;
232 struct cmd_list_element
*
233 add_cmd (const char *name
, enum command_class theclass
,
234 const char *doc
, struct cmd_list_element
**list
)
236 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
238 result
->function
.simple_func
= NULL
;
242 struct cmd_list_element
*
243 add_cmd (const char *name
, enum command_class theclass
,
244 cmd_simple_func_ftype
*fun
,
245 const char *doc
, struct cmd_list_element
**list
)
247 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
248 set_cmd_simple_func (result
, fun
);
252 /* Add an element with a suppress notification to the LIST of commands. */
254 struct cmd_list_element
*
255 add_cmd_suppress_notification (const char *name
, enum command_class theclass
,
256 cmd_simple_func_ftype
*fun
, const char *doc
,
257 struct cmd_list_element
**list
,
258 bool *suppress_notification
)
260 struct cmd_list_element
*element
;
262 element
= add_cmd (name
, theclass
, fun
, doc
, list
);
263 element
->suppress_notification
= suppress_notification
;
269 /* Deprecates a command CMD.
270 REPLACEMENT is the name of the command which should be used in
271 place of this command, or NULL if no such command exists.
273 This function does not check to see if command REPLACEMENT exists
274 since gdb may not have gotten around to adding REPLACEMENT when
275 this function is called.
277 Returns a pointer to the deprecated command. */
279 struct cmd_list_element
*
280 deprecate_cmd (struct cmd_list_element
*cmd
, const char *replacement
)
282 cmd
->cmd_deprecated
= 1;
283 cmd
->deprecated_warn_user
= 1;
285 if (replacement
!= NULL
)
286 cmd
->replacement
= replacement
;
288 cmd
->replacement
= NULL
;
293 struct cmd_list_element
*
294 add_alias_cmd (const char *name
, cmd_list_element
*target
,
295 enum command_class theclass
, int abbrev_flag
,
296 struct cmd_list_element
**list
)
298 gdb_assert (target
!= nullptr);
300 struct cmd_list_element
*c
= add_cmd (name
, theclass
, target
->doc
, list
);
302 /* If TARGET->DOC can be freed, we should make another copy. */
303 if (target
->doc_allocated
)
305 c
->doc
= xstrdup (target
->doc
);
306 c
->doc_allocated
= 1;
308 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
309 c
->func
= target
->func
;
310 c
->function
= target
->function
;
311 c
->subcommands
= target
->subcommands
;
312 c
->allow_unknown
= target
->allow_unknown
;
313 c
->abbrev_flag
= abbrev_flag
;
314 c
->alias_target
= target
;
315 target
->aliases
.push_front (*c
);
320 /* Update the prefix field of all sub-commands of the prefix command C.
321 We must do this when a prefix command is defined as the GDB init sequence
322 does not guarantee that a prefix command is created before its sub-commands.
323 For example, break-catch-sig.c initialization runs before breakpoint.c
324 initialization, but it is breakpoint.c that creates the "catch" command used
325 by the "catch signal" command created by break-catch-sig.c. */
328 update_prefix_field_of_prefixed_commands (struct cmd_list_element
*c
)
330 for (cmd_list_element
*p
= *c
->subcommands
; p
!= NULL
; p
= p
->next
)
334 /* We must recursively update the prefix field to cover
335 e.g. 'info auto-load libthread-db' where the creation
340 In such a case, when 'auto-load' was created by do_add_cmd,
341 the 'libthread-db' prefix field could not be updated, as the
342 'auto-load' command was not yet reachable by
343 lookup_cmd_for_subcommands (list, cmdlist)
344 that searches from the top level 'cmdlist'. */
346 update_prefix_field_of_prefixed_commands (p
);
351 /* Like add_cmd but adds an element for a command prefix: a name that
352 should be followed by a subcommand to be looked up in another
353 command list. SUBCOMMANDS should be the address of the variable
354 containing that list. */
356 struct cmd_list_element
*
357 add_prefix_cmd (const char *name
, enum command_class theclass
,
358 cmd_simple_func_ftype
*fun
,
359 const char *doc
, struct cmd_list_element
**subcommands
,
360 int allow_unknown
, struct cmd_list_element
**list
)
362 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
364 c
->subcommands
= subcommands
;
365 c
->allow_unknown
= allow_unknown
;
367 /* Now that prefix command C is defined, we need to set the prefix field
368 of all prefixed commands that were defined before C itself was defined. */
369 update_prefix_field_of_prefixed_commands (c
);
374 /* A helper function for add_basic_prefix_cmd. This is a command
375 function that just forwards to help_list. */
378 do_prefix_cmd (const char *args
, int from_tty
, struct cmd_list_element
*c
)
380 /* Look past all aliases. */
381 while (c
->is_alias ())
384 help_list (*c
->subcommands
, c
->prefixname ().c_str (),
385 all_commands
, gdb_stdout
);
390 struct cmd_list_element
*
391 add_basic_prefix_cmd (const char *name
, enum command_class theclass
,
392 const char *doc
, struct cmd_list_element
**subcommands
,
393 int allow_unknown
, struct cmd_list_element
**list
)
395 struct cmd_list_element
*cmd
= add_prefix_cmd (name
, theclass
, nullptr,
397 allow_unknown
, list
);
398 cmd
->func
= do_prefix_cmd
;
402 /* A helper function for add_show_prefix_cmd. This is a command
403 function that just forwards to cmd_show_list. */
406 do_show_prefix_cmd (const char *args
, int from_tty
, struct cmd_list_element
*c
)
408 cmd_show_list (*c
->subcommands
, from_tty
);
413 struct cmd_list_element
*
414 add_show_prefix_cmd (const char *name
, enum command_class theclass
,
415 const char *doc
, struct cmd_list_element
**subcommands
,
416 int allow_unknown
, struct cmd_list_element
**list
)
418 struct cmd_list_element
*cmd
= add_prefix_cmd (name
, theclass
, nullptr,
420 allow_unknown
, list
);
421 cmd
->func
= do_show_prefix_cmd
;
428 add_setshow_prefix_cmd (const char *name
, command_class theclass
,
429 const char *set_doc
, const char *show_doc
,
430 cmd_list_element
**set_subcommands_list
,
431 cmd_list_element
**show_subcommands_list
,
432 cmd_list_element
**set_list
,
433 cmd_list_element
**show_list
)
435 set_show_commands cmds
;
437 cmds
.set
= add_basic_prefix_cmd (name
, theclass
, set_doc
,
438 set_subcommands_list
, 0,
440 cmds
.show
= add_show_prefix_cmd (name
, theclass
, show_doc
,
441 show_subcommands_list
, 0,
447 /* Like ADD_PREFIX_CMD but sets the suppress_notification pointer on the
448 new command list element. */
450 struct cmd_list_element
*
451 add_prefix_cmd_suppress_notification
452 (const char *name
, enum command_class theclass
,
453 cmd_simple_func_ftype
*fun
,
454 const char *doc
, struct cmd_list_element
**subcommands
,
455 int allow_unknown
, struct cmd_list_element
**list
,
456 bool *suppress_notification
)
458 struct cmd_list_element
*element
459 = add_prefix_cmd (name
, theclass
, fun
, doc
, subcommands
,
460 allow_unknown
, list
);
461 element
->suppress_notification
= suppress_notification
;
465 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
467 struct cmd_list_element
*
468 add_abbrev_prefix_cmd (const char *name
, enum command_class theclass
,
469 cmd_simple_func_ftype
*fun
, const char *doc
,
470 struct cmd_list_element
**subcommands
,
471 int allow_unknown
, struct cmd_list_element
**list
)
473 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
475 c
->subcommands
= subcommands
;
476 c
->allow_unknown
= allow_unknown
;
481 /* This is an empty "simple func". */
483 not_just_help_class_command (const char *args
, int from_tty
)
487 /* This is an empty cmd func. */
490 empty_func (const char *args
, int from_tty
, cmd_list_element
*c
)
494 /* Add element named NAME to command list LIST (the list for set/show
495 or some sublist thereof).
496 TYPE is set_cmd or show_cmd.
497 CLASS is as in add_cmd.
498 VAR_TYPE is the kind of thing we are setting.
499 VAR is address of the variable being controlled by this command.
500 SET_SETTING_FUNC is a pointer to an optional function callback used to set
502 GET_SETTING_FUNC is a pointer to an optional function callback used to get
504 DOC is the documentation string. */
506 static struct cmd_list_element
*
507 add_set_or_show_cmd (const char *name
,
509 enum command_class theclass
,
511 const setting::erased_args
&arg
,
513 struct cmd_list_element
**list
)
515 struct cmd_list_element
*c
= add_cmd (name
, theclass
, doc
, list
);
517 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
519 c
->var
.emplace (var_type
, arg
);
521 /* This needs to be something besides NULL so that this isn't
522 treated as a help class. */
523 c
->func
= empty_func
;
527 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
528 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
529 setting. VAR is address of the variable being controlled by this
530 command. If nullptr is given as VAR, then both SET_SETTING_FUNC and
531 GET_SETTING_FUNC must be provided. SET_SETTING_FUNC and GET_SETTING_FUNC are
532 callbacks used to access and modify the underlying property, whatever its
533 storage is. SET_FUNC and SHOW_FUNC are the callback functions (if non-NULL).
534 SET_DOC, SHOW_DOC and HELP_DOC are the documentation strings.
536 Return the newly created set and show commands. */
538 static set_show_commands
539 add_setshow_cmd_full_erased (const char *name
,
540 enum command_class theclass
,
542 const setting::erased_args
&args
,
543 const char *set_doc
, const char *show_doc
,
544 const char *help_doc
,
545 cmd_func_ftype
*set_func
,
546 show_value_ftype
*show_func
,
547 struct cmd_list_element
**set_list
,
548 struct cmd_list_element
**show_list
)
550 struct cmd_list_element
*set
;
551 struct cmd_list_element
*show
;
552 gdb::unique_xmalloc_ptr
<char> full_set_doc
;
553 gdb::unique_xmalloc_ptr
<char> full_show_doc
;
555 if (help_doc
!= NULL
)
557 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
558 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
562 full_set_doc
= make_unique_xstrdup (set_doc
);
563 full_show_doc
= make_unique_xstrdup (show_doc
);
565 set
= add_set_or_show_cmd (name
, set_cmd
, theclass
, var_type
, args
,
566 full_set_doc
.release (), set_list
);
567 set
->doc_allocated
= 1;
569 if (set_func
!= NULL
)
570 set
->func
= set_func
;
572 show
= add_set_or_show_cmd (name
, show_cmd
, theclass
, var_type
, args
,
573 full_show_doc
.release (), show_list
);
574 show
->doc_allocated
= 1;
575 show
->show_value_func
= show_func
;
576 /* Disable the default symbol completer. Doesn't make much sense
577 for the "show" command to complete on anything. */
578 set_cmd_completer (show
, nullptr);
584 static set_show_commands
585 add_setshow_cmd_full (const char *name
,
586 enum command_class theclass
,
587 var_types var_type
, T
*var
,
588 const char *set_doc
, const char *show_doc
,
589 const char *help_doc
,
590 typename setting_func_types
<T
>::set set_setting_func
,
591 typename setting_func_types
<T
>::get get_setting_func
,
592 cmd_func_ftype
*set_func
,
593 show_value_ftype
*show_func
,
594 struct cmd_list_element
**set_list
,
595 struct cmd_list_element
**show_list
)
598 = setting::erase_args (var_type
, var
,
599 set_setting_func
, get_setting_func
);
601 return add_setshow_cmd_full_erased (name
,
603 var_type
, erased_args
,
612 /* Add element named NAME to command list LIST (the list for set or
613 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
614 of strings which may follow NAME. VAR is address of the variable
615 which will contain the matching string (from ENUMLIST). */
618 add_setshow_enum_cmd (const char *name
,
619 enum command_class theclass
,
620 const char *const *enumlist
,
623 const char *show_doc
,
624 const char *help_doc
,
625 cmd_func_ftype
*set_func
,
626 show_value_ftype
*show_func
,
627 struct cmd_list_element
**set_list
,
628 struct cmd_list_element
**show_list
)
630 /* We require *VAR to be initialized before this call, and
631 furthermore it must be == to one of the values in ENUMLIST. */
632 gdb_assert (var
!= nullptr && *var
!= nullptr);
633 for (int i
= 0; ; ++i
)
635 gdb_assert (enumlist
[i
] != nullptr);
636 if (*var
== enumlist
[i
])
640 set_show_commands commands
641 = add_setshow_cmd_full
<const char *> (name
, theclass
, var_enum
, var
,
642 set_doc
, show_doc
, help_doc
,
643 nullptr, nullptr, set_func
,
644 show_func
, set_list
, show_list
);
645 commands
.set
->enums
= enumlist
;
649 /* Same as above but using a getter and a setter function instead of a pointer
650 to a global storage buffer. */
653 add_setshow_enum_cmd (const char *name
, command_class theclass
,
654 const char *const *enumlist
, const char *set_doc
,
655 const char *show_doc
, const char *help_doc
,
656 setting_func_types
<const char *>::set set_func
,
657 setting_func_types
<const char *>::get get_func
,
658 show_value_ftype
*show_func
,
659 cmd_list_element
**set_list
,
660 cmd_list_element
**show_list
)
662 auto cmds
= add_setshow_cmd_full
<const char *> (name
, theclass
, var_enum
,
663 nullptr, set_doc
, show_doc
,
664 help_doc
, set_func
, get_func
,
665 nullptr, show_func
, set_list
,
668 cmds
.set
->enums
= enumlist
;
673 /* See cli-decode.h. */
674 const char * const auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
676 /* Add an auto-boolean command named NAME to both the set and show
677 command list lists. CLASS is as in add_cmd. VAR is address of the
678 variable which will contain the value. DOC is the documentation
679 string. FUNC is the corresponding callback. */
682 add_setshow_auto_boolean_cmd (const char *name
,
683 enum command_class theclass
,
684 enum auto_boolean
*var
,
685 const char *set_doc
, const char *show_doc
,
686 const char *help_doc
,
687 cmd_func_ftype
*set_func
,
688 show_value_ftype
*show_func
,
689 struct cmd_list_element
**set_list
,
690 struct cmd_list_element
**show_list
)
692 set_show_commands commands
693 = add_setshow_cmd_full
<enum auto_boolean
> (name
, theclass
, var_auto_boolean
,
694 var
, set_doc
, show_doc
, help_doc
,
695 nullptr, nullptr, set_func
,
696 show_func
, set_list
, show_list
);
698 commands
.set
->enums
= auto_boolean_enums
;
703 /* Same as above but using a getter and a setter function instead of a pointer
704 to a global storage buffer. */
707 add_setshow_auto_boolean_cmd (const char *name
, command_class theclass
,
708 const char *set_doc
, const char *show_doc
,
709 const char *help_doc
,
710 setting_func_types
<enum auto_boolean
>::set set_func
,
711 setting_func_types
<enum auto_boolean
>::get get_func
,
712 show_value_ftype
*show_func
,
713 cmd_list_element
**set_list
,
714 cmd_list_element
**show_list
)
716 auto cmds
= add_setshow_cmd_full
<enum auto_boolean
> (name
, theclass
,
722 set_list
, show_list
);
724 cmds
.set
->enums
= auto_boolean_enums
;
729 /* See cli-decode.h. */
730 const char * const boolean_enums
[] = { "on", "off", NULL
};
732 /* Add element named NAME to both the set and show command LISTs (the
733 list for set/show or some sublist thereof). CLASS is as in
734 add_cmd. VAR is address of the variable which will contain the
735 value. SET_DOC and SHOW_DOC are the documentation strings.
736 Returns the new command element. */
739 add_setshow_boolean_cmd (const char *name
, enum command_class theclass
, bool *var
,
740 const char *set_doc
, const char *show_doc
,
741 const char *help_doc
,
742 cmd_func_ftype
*set_func
,
743 show_value_ftype
*show_func
,
744 struct cmd_list_element
**set_list
,
745 struct cmd_list_element
**show_list
)
747 set_show_commands commands
748 = add_setshow_cmd_full
<bool> (name
, theclass
, var_boolean
, var
,
749 set_doc
, show_doc
, help_doc
,
750 nullptr, nullptr, set_func
, show_func
,
751 set_list
, show_list
);
753 commands
.set
->enums
= boolean_enums
;
758 /* Same as above but using a getter and a setter function instead of a pointer
759 to a global storage buffer. */
762 add_setshow_boolean_cmd (const char *name
, command_class theclass
,
763 const char *set_doc
, const char *show_doc
,
764 const char *help_doc
,
765 setting_func_types
<bool>::set set_func
,
766 setting_func_types
<bool>::get get_func
,
767 show_value_ftype
*show_func
,
768 cmd_list_element
**set_list
,
769 cmd_list_element
**show_list
)
771 auto cmds
= add_setshow_cmd_full
<bool> (name
, theclass
, var_boolean
, nullptr,
772 set_doc
, show_doc
, help_doc
,
773 set_func
, get_func
, nullptr,
774 show_func
, set_list
, show_list
);
776 cmds
.set
->enums
= boolean_enums
;
781 /* Add element named NAME to both the set and show command LISTs (the
782 list for set/show or some sublist thereof). */
785 add_setshow_filename_cmd (const char *name
, enum command_class theclass
,
787 const char *set_doc
, const char *show_doc
,
788 const char *help_doc
,
789 cmd_func_ftype
*set_func
,
790 show_value_ftype
*show_func
,
791 struct cmd_list_element
**set_list
,
792 struct cmd_list_element
**show_list
)
794 set_show_commands commands
795 = add_setshow_cmd_full
<std::string
> (name
, theclass
, var_filename
, var
,
796 set_doc
, show_doc
, help_doc
,
797 nullptr, nullptr, set_func
,
798 show_func
, set_list
, show_list
);
800 set_cmd_completer (commands
.set
, filename_completer
);
805 /* Same as above but using a getter and a setter function instead of a pointer
806 to a global storage buffer. */
809 add_setshow_filename_cmd (const char *name
, command_class theclass
,
810 const char *set_doc
, const char *show_doc
,
811 const char *help_doc
,
812 setting_func_types
<std::string
>::set set_func
,
813 setting_func_types
<std::string
>::get get_func
,
814 show_value_ftype
*show_func
,
815 cmd_list_element
**set_list
,
816 cmd_list_element
**show_list
)
818 auto cmds
= add_setshow_cmd_full
<std::string
> (name
, theclass
, var_filename
,
819 nullptr, set_doc
, show_doc
,
820 help_doc
, set_func
, get_func
,
821 nullptr, show_func
, set_list
,
824 set_cmd_completer (cmds
.set
, filename_completer
);
829 /* Add element named NAME to both the set and show command LISTs (the
830 list for set/show or some sublist thereof). */
833 add_setshow_string_cmd (const char *name
, enum command_class theclass
,
835 const char *set_doc
, const char *show_doc
,
836 const char *help_doc
,
837 cmd_func_ftype
*set_func
,
838 show_value_ftype
*show_func
,
839 struct cmd_list_element
**set_list
,
840 struct cmd_list_element
**show_list
)
842 set_show_commands commands
843 = add_setshow_cmd_full
<std::string
> (name
, theclass
, var_string
, var
,
844 set_doc
, show_doc
, help_doc
,
845 nullptr, nullptr, set_func
,
846 show_func
, set_list
, show_list
);
848 /* Disable the default symbol completer. */
849 set_cmd_completer (commands
.set
, nullptr);
854 /* Same as above but using a getter and a setter function instead of a pointer
855 to a global storage buffer. */
858 add_setshow_string_cmd (const char *name
, command_class theclass
,
859 const char *set_doc
, const char *show_doc
,
860 const char *help_doc
,
861 setting_func_types
<std::string
>::set set_func
,
862 setting_func_types
<std::string
>::get get_func
,
863 show_value_ftype
*show_func
,
864 cmd_list_element
**set_list
,
865 cmd_list_element
**show_list
)
867 auto cmds
= add_setshow_cmd_full
<std::string
> (name
, theclass
, var_string
,
868 nullptr, set_doc
, show_doc
,
869 help_doc
, set_func
, get_func
,
870 nullptr, show_func
, set_list
,
873 /* Disable the default symbol completer. */
874 set_cmd_completer (cmds
.set
, nullptr);
879 /* Add element named NAME to both the set and show command LISTs (the
880 list for set/show or some sublist thereof). */
883 add_setshow_string_noescape_cmd (const char *name
, enum command_class theclass
,
885 const char *set_doc
, const char *show_doc
,
886 const char *help_doc
,
887 cmd_func_ftype
*set_func
,
888 show_value_ftype
*show_func
,
889 struct cmd_list_element
**set_list
,
890 struct cmd_list_element
**show_list
)
892 set_show_commands commands
893 = add_setshow_cmd_full
<std::string
> (name
, theclass
, var_string_noescape
,
894 var
, set_doc
, show_doc
, help_doc
,
895 nullptr, nullptr, set_func
, show_func
,
896 set_list
, show_list
);
898 /* Disable the default symbol completer. */
899 set_cmd_completer (commands
.set
, nullptr);
904 /* Same as above but using a getter and a setter function instead of a pointer
905 to a global storage buffer. */
908 add_setshow_string_noescape_cmd (const char *name
, command_class theclass
,
909 const char *set_doc
, const char *show_doc
,
910 const char *help_doc
,
911 setting_func_types
<std::string
>::set set_func
,
912 setting_func_types
<std::string
>::get get_func
,
913 show_value_ftype
*show_func
,
914 cmd_list_element
**set_list
,
915 cmd_list_element
**show_list
)
917 auto cmds
= add_setshow_cmd_full
<std::string
> (name
, theclass
,
918 var_string_noescape
, nullptr,
919 set_doc
, show_doc
, help_doc
,
921 nullptr, show_func
, set_list
,
924 /* Disable the default symbol completer. */
925 set_cmd_completer (cmds
.set
, nullptr);
930 /* Add element named NAME to both the set and show command LISTs (the
931 list for set/show or some sublist thereof). */
934 add_setshow_optional_filename_cmd (const char *name
, enum command_class theclass
,
936 const char *set_doc
, const char *show_doc
,
937 const char *help_doc
,
938 cmd_func_ftype
*set_func
,
939 show_value_ftype
*show_func
,
940 struct cmd_list_element
**set_list
,
941 struct cmd_list_element
**show_list
)
943 set_show_commands commands
944 = add_setshow_cmd_full
<std::string
> (name
, theclass
, var_optional_filename
,
945 var
, set_doc
, show_doc
, help_doc
,
946 nullptr, nullptr, set_func
, show_func
,
947 set_list
, show_list
);
949 set_cmd_completer (commands
.set
, filename_completer
);
954 /* Same as above but using a getter and a setter function instead of a pointer
955 to a global storage buffer. */
958 add_setshow_optional_filename_cmd (const char *name
, command_class theclass
,
959 const char *set_doc
, const char *show_doc
,
960 const char *help_doc
,
961 setting_func_types
<std::string
>::set set_func
,
962 setting_func_types
<std::string
>::get get_func
,
963 show_value_ftype
*show_func
,
964 cmd_list_element
**set_list
,
965 cmd_list_element
**show_list
)
968 add_setshow_cmd_full
<std::string
> (name
, theclass
, var_optional_filename
,
969 nullptr, set_doc
, show_doc
, help_doc
,
970 set_func
, get_func
, nullptr, show_func
,
973 set_cmd_completer (cmds
.set
, filename_completer
);
978 /* Completes on literal "unlimited". Used by integer commands that
979 support a special "unlimited" value. */
982 integer_unlimited_completer (struct cmd_list_element
*ignore
,
983 completion_tracker
&tracker
,
984 const char *text
, const char *word
)
986 static const char * const keywords
[] =
992 complete_on_enum (tracker
, keywords
, text
, word
);
995 /* Add element named NAME to both the set and show command LISTs (the
996 list for set/show or some sublist thereof). CLASS is as in
997 add_cmd. VAR is address of the variable which will contain the
998 value. SET_DOC and SHOW_DOC are the documentation strings. This
999 function is only used in Python API. Please don't use it elsewhere. */
1002 add_setshow_integer_cmd (const char *name
, enum command_class theclass
,
1004 const char *set_doc
, const char *show_doc
,
1005 const char *help_doc
,
1006 cmd_func_ftype
*set_func
,
1007 show_value_ftype
*show_func
,
1008 struct cmd_list_element
**set_list
,
1009 struct cmd_list_element
**show_list
)
1011 set_show_commands commands
1012 = add_setshow_cmd_full
<int> (name
, theclass
, var_integer
, var
,
1013 set_doc
, show_doc
, help_doc
,
1014 nullptr, nullptr, set_func
,
1015 show_func
, set_list
, show_list
);
1017 set_cmd_completer (commands
.set
, integer_unlimited_completer
);
1022 /* Same as above but using a getter and a setter function instead of a pointer
1023 to a global storage buffer. */
1026 add_setshow_integer_cmd (const char *name
, command_class theclass
,
1027 const char *set_doc
, const char *show_doc
,
1028 const char *help_doc
,
1029 setting_func_types
<int>::set set_func
,
1030 setting_func_types
<int>::get get_func
,
1031 show_value_ftype
*show_func
,
1032 cmd_list_element
**set_list
,
1033 cmd_list_element
**show_list
)
1035 auto cmds
= add_setshow_cmd_full
<int> (name
, theclass
, var_integer
, nullptr,
1036 set_doc
, show_doc
, help_doc
, set_func
,
1037 get_func
, nullptr, show_func
, set_list
,
1040 set_cmd_completer (cmds
.set
, integer_unlimited_completer
);
1045 /* Add element named NAME to both the set and show command LISTs (the
1046 list for set/show or some sublist thereof). CLASS is as in
1047 add_cmd. VAR is address of the variable which will contain the
1048 value. SET_DOC and SHOW_DOC are the documentation strings. */
1051 add_setshow_uinteger_cmd (const char *name
, enum command_class theclass
,
1053 const char *set_doc
, const char *show_doc
,
1054 const char *help_doc
,
1055 cmd_func_ftype
*set_func
,
1056 show_value_ftype
*show_func
,
1057 struct cmd_list_element
**set_list
,
1058 struct cmd_list_element
**show_list
)
1060 set_show_commands commands
1061 = add_setshow_cmd_full
<unsigned int> (name
, theclass
, var_uinteger
, var
,
1062 set_doc
, show_doc
, help_doc
,
1063 nullptr, nullptr, set_func
,
1064 show_func
, set_list
, show_list
);
1066 set_cmd_completer (commands
.set
, integer_unlimited_completer
);
1071 /* Same as above but using a getter and a setter function instead of a pointer
1072 to a global storage buffer. */
1075 add_setshow_uinteger_cmd (const char *name
, command_class theclass
,
1076 const char *set_doc
, const char *show_doc
,
1077 const char *help_doc
,
1078 setting_func_types
<unsigned int>::set set_func
,
1079 setting_func_types
<unsigned int>::get get_func
,
1080 show_value_ftype
*show_func
,
1081 cmd_list_element
**set_list
,
1082 cmd_list_element
**show_list
)
1084 auto cmds
= add_setshow_cmd_full
<unsigned int> (name
, theclass
, var_uinteger
,
1085 nullptr, set_doc
, show_doc
,
1086 help_doc
, set_func
, get_func
,
1087 nullptr, show_func
, set_list
,
1090 set_cmd_completer (cmds
.set
, integer_unlimited_completer
);
1095 /* Add element named NAME to both the set and show command LISTs (the
1096 list for set/show or some sublist thereof). CLASS is as in
1097 add_cmd. VAR is address of the variable which will contain the
1098 value. SET_DOC and SHOW_DOC are the documentation strings. */
1101 add_setshow_zinteger_cmd (const char *name
, enum command_class theclass
,
1103 const char *set_doc
, const char *show_doc
,
1104 const char *help_doc
,
1105 cmd_func_ftype
*set_func
,
1106 show_value_ftype
*show_func
,
1107 struct cmd_list_element
**set_list
,
1108 struct cmd_list_element
**show_list
)
1110 return add_setshow_cmd_full
<int> (name
, theclass
, var_zinteger
, var
,
1111 set_doc
, show_doc
, help_doc
,
1112 nullptr, nullptr, set_func
,
1113 show_func
, set_list
, show_list
);
1116 /* Same as above but using a getter and a setter function instead of a pointer
1117 to a global storage buffer. */
1120 add_setshow_zinteger_cmd (const char *name
, command_class theclass
,
1121 const char *set_doc
, const char *show_doc
,
1122 const char *help_doc
,
1123 setting_func_types
<int>::set set_func
,
1124 setting_func_types
<int>::get get_func
,
1125 show_value_ftype
*show_func
,
1126 cmd_list_element
**set_list
,
1127 cmd_list_element
**show_list
)
1129 return add_setshow_cmd_full
<int> (name
, theclass
, var_zinteger
, nullptr,
1130 set_doc
, show_doc
, help_doc
, set_func
,
1131 get_func
, nullptr, show_func
, set_list
,
1136 add_setshow_zuinteger_unlimited_cmd (const char *name
,
1137 enum command_class theclass
,
1139 const char *set_doc
,
1140 const char *show_doc
,
1141 const char *help_doc
,
1142 cmd_func_ftype
*set_func
,
1143 show_value_ftype
*show_func
,
1144 struct cmd_list_element
**set_list
,
1145 struct cmd_list_element
**show_list
)
1147 set_show_commands commands
1148 = add_setshow_cmd_full
<int> (name
, theclass
, var_zuinteger_unlimited
, var
,
1149 set_doc
, show_doc
, help_doc
, nullptr,
1150 nullptr, set_func
, show_func
, set_list
,
1153 set_cmd_completer (commands
.set
, integer_unlimited_completer
);
1158 /* Same as above but using a getter and a setter function instead of a pointer
1159 to a global storage buffer. */
1162 add_setshow_zuinteger_unlimited_cmd (const char *name
, command_class theclass
,
1163 const char *set_doc
, const char *show_doc
,
1164 const char *help_doc
,
1165 setting_func_types
<int>::set set_func
,
1166 setting_func_types
<int>::get get_func
,
1167 show_value_ftype
*show_func
,
1168 cmd_list_element
**set_list
,
1169 cmd_list_element
**show_list
)
1172 = add_setshow_cmd_full
<int> (name
, theclass
, var_zuinteger_unlimited
,
1173 nullptr, set_doc
, show_doc
, help_doc
, set_func
,
1174 get_func
, nullptr, show_func
, set_list
,
1177 set_cmd_completer (cmds
.set
, integer_unlimited_completer
);
1182 /* Add element named NAME to both the set and show command LISTs (the
1183 list for set/show or some sublist thereof). CLASS is as in
1184 add_cmd. VAR is address of the variable which will contain the
1185 value. SET_DOC and SHOW_DOC are the documentation strings. */
1188 add_setshow_zuinteger_cmd (const char *name
, enum command_class theclass
,
1190 const char *set_doc
, const char *show_doc
,
1191 const char *help_doc
,
1192 cmd_func_ftype
*set_func
,
1193 show_value_ftype
*show_func
,
1194 struct cmd_list_element
**set_list
,
1195 struct cmd_list_element
**show_list
)
1197 return add_setshow_cmd_full
<unsigned int> (name
, theclass
, var_zuinteger
,
1198 var
, set_doc
, show_doc
, help_doc
,
1199 nullptr, nullptr, set_func
,
1200 show_func
, set_list
, show_list
);
1203 /* Same as above but using a getter and a setter function instead of a pointer
1204 to a global storage buffer. */
1207 add_setshow_zuinteger_cmd (const char *name
, command_class theclass
,
1208 const char *set_doc
, const char *show_doc
,
1209 const char *help_doc
,
1210 setting_func_types
<unsigned int>::set set_func
,
1211 setting_func_types
<unsigned int>::get get_func
,
1212 show_value_ftype
*show_func
,
1213 cmd_list_element
**set_list
,
1214 cmd_list_element
**show_list
)
1216 return add_setshow_cmd_full
<unsigned int> (name
, theclass
, var_zuinteger
,
1217 nullptr, set_doc
, show_doc
,
1218 help_doc
, set_func
, get_func
,
1219 nullptr, show_func
, set_list
,
1223 /* Remove the command named NAME from the command list. Return the list
1224 commands which were aliased to the deleted command. The various *HOOKs are
1225 set to the pre- and post-hook commands for the deleted command. If the
1226 command does not have a hook, the corresponding out parameter is set to
1229 static cmd_list_element::aliases_list_type
1230 delete_cmd (const char *name
, struct cmd_list_element
**list
,
1231 struct cmd_list_element
**prehook
,
1232 struct cmd_list_element
**prehookee
,
1233 struct cmd_list_element
**posthook
,
1234 struct cmd_list_element
**posthookee
)
1236 struct cmd_list_element
*iter
;
1237 struct cmd_list_element
**previous_chain_ptr
;
1238 cmd_list_element::aliases_list_type aliases
;
1244 previous_chain_ptr
= list
;
1246 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
1248 if (strcmp (iter
->name
, name
) == 0)
1250 if (iter
->destroyer
)
1251 iter
->destroyer (iter
, iter
->context ());
1253 if (iter
->hookee_pre
)
1254 iter
->hookee_pre
->hook_pre
= 0;
1255 *prehook
= iter
->hook_pre
;
1256 *prehookee
= iter
->hookee_pre
;
1257 if (iter
->hookee_post
)
1258 iter
->hookee_post
->hook_post
= 0;
1259 *posthook
= iter
->hook_post
;
1260 *posthookee
= iter
->hookee_post
;
1262 /* Update the link. */
1263 *previous_chain_ptr
= iter
->next
;
1265 aliases
= std::move (iter
->aliases
);
1267 /* If this command was an alias, remove it from the list of
1269 if (iter
->is_alias ())
1271 auto it
= iter
->alias_target
->aliases
.iterator_to (*iter
);
1272 iter
->alias_target
->aliases
.erase (it
);
1277 /* We won't see another command with the same name. */
1281 previous_chain_ptr
= &iter
->next
;
1287 /* Shorthands to the commands above. */
1289 /* Add an element to the list of info subcommands. */
1291 struct cmd_list_element
*
1292 add_info (const char *name
, cmd_simple_func_ftype
*fun
, const char *doc
)
1294 return add_cmd (name
, class_info
, fun
, doc
, &infolist
);
1297 /* Add an alias to the list of info subcommands. */
1300 add_info_alias (const char *name
, cmd_list_element
*target
, int abbrev_flag
)
1302 return add_alias_cmd (name
, target
, class_run
, abbrev_flag
, &infolist
);
1305 /* Add an element to the list of commands. */
1307 struct cmd_list_element
*
1308 add_com (const char *name
, enum command_class theclass
,
1309 cmd_simple_func_ftype
*fun
,
1312 return add_cmd (name
, theclass
, fun
, doc
, &cmdlist
);
1315 /* Add an alias or abbreviation command to the list of commands.
1316 For aliases predefined by GDB (such as bt), THECLASS must be
1317 different of class_alias, as class_alias is used to identify
1318 user defined aliases. */
1321 add_com_alias (const char *name
, cmd_list_element
*target
,
1322 command_class theclass
, int abbrev_flag
)
1324 return add_alias_cmd (name
, target
, theclass
, abbrev_flag
, &cmdlist
);
1327 /* Add an element with a suppress notification to the list of commands. */
1329 struct cmd_list_element
*
1330 add_com_suppress_notification (const char *name
, enum command_class theclass
,
1331 cmd_simple_func_ftype
*fun
, const char *doc
,
1332 bool *suppress_notification
)
1334 return add_cmd_suppress_notification (name
, theclass
, fun
, doc
,
1335 &cmdlist
, suppress_notification
);
1338 /* Print the prefix of C followed by name of C in title style. */
1341 fput_command_name_styled (const cmd_list_element
&c
, struct ui_file
*stream
)
1343 std::string prefixname
1344 = c
.prefix
== nullptr ? "" : c
.prefix
->prefixname ();
1346 fprintf_styled (stream
, title_style
.style (), "%s%s",
1347 prefixname
.c_str (), c
.name
);
1350 /* Print the definition of alias C using title style for alias
1351 and aliased command. */
1354 fput_alias_definition_styled (const cmd_list_element
&c
,
1355 struct ui_file
*stream
)
1357 gdb_assert (c
.is_alias ());
1358 gdb_puts (" alias ", stream
);
1359 fput_command_name_styled (c
, stream
);
1360 gdb_printf (stream
, " = ");
1361 fput_command_name_styled (*c
.alias_target
, stream
);
1362 gdb_printf (stream
, " %s\n", c
.default_args
.c_str ());
1365 /* Print the definition of the aliases of CMD that have default args. */
1368 fput_aliases_definition_styled (const cmd_list_element
&cmd
,
1369 struct ui_file
*stream
)
1371 for (const cmd_list_element
&alias
: cmd
.aliases
)
1372 if (!alias
.cmd_deprecated
&& !alias
.default_args
.empty ())
1373 fput_alias_definition_styled (alias
, stream
);
1377 /* If C has one or more aliases, style print the name of C and
1378 the name of its aliases, separated by commas.
1379 If ALWAYS_FPUT_C_NAME, print the name of C even if it has no aliases.
1380 If one or more names are printed, POSTFIX is printed after the last name.
1384 fput_command_names_styled (const cmd_list_element
&c
,
1385 bool always_fput_c_name
, const char *postfix
,
1386 struct ui_file
*stream
)
1388 /* First, check if we are going to print something. That is, either if
1389 ALWAYS_FPUT_C_NAME is true or if there exists at least one non-deprecated
1392 auto print_alias
= [] (const cmd_list_element
&alias
)
1394 return !alias
.cmd_deprecated
;
1397 bool print_something
= always_fput_c_name
;
1398 if (!print_something
)
1399 for (const cmd_list_element
&alias
: c
.aliases
)
1401 if (!print_alias (alias
))
1404 print_something
= true;
1408 if (print_something
)
1409 fput_command_name_styled (c
, stream
);
1411 for (const cmd_list_element
&alias
: c
.aliases
)
1413 if (!print_alias (alias
))
1416 gdb_puts (", ", stream
);
1417 stream
->wrap_here (3);
1418 fput_command_name_styled (alias
, stream
);
1421 if (print_something
)
1422 gdb_puts (postfix
, stream
);
1425 /* If VERBOSE, print the full help for command C and highlight the
1426 documentation parts matching HIGHLIGHT,
1427 otherwise print only one-line help for command C. */
1430 print_doc_of_command (const cmd_list_element
&c
, const char *prefix
,
1431 bool verbose
, compiled_regex
&highlight
,
1432 struct ui_file
*stream
)
1434 /* When printing the full documentation, add a line to separate
1435 this documentation from the previous command help, in the likely
1436 case that apropos finds several commands. */
1438 gdb_puts ("\n", stream
);
1440 fput_command_names_styled (c
, true,
1441 verbose
? "" : " -- ", stream
);
1444 gdb_puts ("\n", stream
);
1445 fput_aliases_definition_styled (c
, stream
);
1446 fputs_highlighted (c
.doc
, highlight
, stream
);
1447 gdb_puts ("\n", stream
);
1451 print_doc_line (stream
, c
.doc
, false);
1452 gdb_puts ("\n", stream
);
1453 fput_aliases_definition_styled (c
, stream
);
1457 /* Recursively walk the commandlist structures, and print out the
1458 documentation of commands that match our regex in either their
1459 name, or their documentation.
1460 If VERBOSE, prints the complete documentation and highlight the
1461 documentation parts matching REGEX, otherwise prints only
1465 apropos_cmd (struct ui_file
*stream
,
1466 struct cmd_list_element
*commandlist
,
1467 bool verbose
, compiled_regex
®ex
, const char *prefix
)
1469 struct cmd_list_element
*c
;
1472 /* Walk through the commands. */
1473 for (c
=commandlist
;c
;c
=c
->next
)
1477 /* Command aliases/abbreviations are skipped to ensure we print the
1478 doc of a command only once, when encountering the aliased
1483 returnvalue
= -1; /* Needed to avoid double printing. */
1484 if (c
->name
!= NULL
)
1486 size_t name_len
= strlen (c
->name
);
1488 /* Try to match against the name. */
1489 returnvalue
= regex
.search (c
->name
, name_len
, 0, name_len
, NULL
);
1490 if (returnvalue
>= 0)
1491 print_doc_of_command (*c
, prefix
, verbose
, regex
, stream
);
1493 /* Try to match against the name of the aliases. */
1494 for (const cmd_list_element
&alias
: c
->aliases
)
1496 name_len
= strlen (alias
.name
);
1497 returnvalue
= regex
.search (alias
.name
, name_len
, 0, name_len
, NULL
);
1498 if (returnvalue
>= 0)
1500 print_doc_of_command (*c
, prefix
, verbose
, regex
, stream
);
1505 if (c
->doc
!= NULL
&& returnvalue
< 0)
1507 size_t doc_len
= strlen (c
->doc
);
1509 /* Try to match against documentation. */
1510 if (regex
.search (c
->doc
, doc_len
, 0, doc_len
, NULL
) >= 0)
1511 print_doc_of_command (*c
, prefix
, verbose
, regex
, stream
);
1513 /* Check if this command has subcommands. */
1514 if (c
->is_prefix ())
1516 /* Recursively call ourselves on the subcommand list,
1517 passing the right prefix in. */
1518 apropos_cmd (stream
, *c
->subcommands
, verbose
, regex
,
1519 c
->prefixname ().c_str ());
1524 /* This command really has to deal with two things:
1525 1) I want documentation on *this string* (usually called by
1526 "help commandname").
1528 2) I want documentation on *this list* (usually called by giving a
1529 command that requires subcommands. Also called by saying just
1532 I am going to split this into two separate commands, help_cmd and
1536 help_cmd (const char *command
, struct ui_file
*stream
)
1538 struct cmd_list_element
*c
, *alias
, *prefix_cmd
, *c_cmd
;
1542 help_list (cmdlist
, "", all_classes
, stream
);
1546 if (strcmp (command
, "all") == 0)
1552 const char *orig_command
= command
;
1553 c
= lookup_cmd (&command
, cmdlist
, "", NULL
, 0, 0);
1558 lookup_cmd_composition (orig_command
, &alias
, &prefix_cmd
, &c_cmd
);
1560 /* There are three cases here.
1561 If c->subcommands is nonzero, we have a prefix command.
1562 Print its documentation, then list its subcommands.
1564 If c->func is non NULL, we really have a command. Print its
1565 documentation and return.
1567 If c->func is NULL, we have a class name. Print its
1568 documentation (as if it were a command) and then set class to the
1569 number of this class so that the commands in the class will be
1572 /* If the user asked 'help somecommand' and there is no alias,
1573 the false indicates to not output the (single) command name. */
1574 fput_command_names_styled (*c
, false, "\n", stream
);
1575 fput_aliases_definition_styled (*c
, stream
);
1576 gdb_puts (c
->doc
, stream
);
1577 gdb_puts ("\n", stream
);
1579 if (!c
->is_prefix () && !c
->is_command_class_help ())
1582 gdb_printf (stream
, "\n");
1584 /* If this is a prefix command, print it's subcommands. */
1585 if (c
->is_prefix ())
1586 help_list (*c
->subcommands
, c
->prefixname ().c_str (),
1587 all_commands
, stream
);
1589 /* If this is a class name, print all of the commands in the class. */
1590 if (c
->is_command_class_help ())
1591 help_list (cmdlist
, "", c
->theclass
, stream
);
1593 if (c
->hook_pre
|| c
->hook_post
)
1595 "\nThis command has a hook (or hooks) defined:\n");
1599 "\tThis command is run after : %s (pre hook)\n",
1603 "\tThis command is run before : %s (post hook)\n",
1604 c
->hook_post
->name
);
1608 * Get a specific kind of help on a command list.
1611 * CMDTYPE is the prefix to use in the title string.
1612 * CLASS is the class with which to list the nodes of this list (see
1613 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
1614 * everything, ALL_CLASSES for just classes, and non-negative for only things
1615 * in a specific class.
1616 * and STREAM is the output stream on which to print things.
1617 * If you call this routine with a class >= 0, it recurses.
1620 help_list (struct cmd_list_element
*list
, const char *cmdtype
,
1621 enum command_class theclass
, struct ui_file
*stream
)
1624 char *cmdtype1
, *cmdtype2
;
1626 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
1628 len
= strlen (cmdtype
);
1629 cmdtype1
= (char *) alloca (len
+ 1);
1631 cmdtype2
= (char *) alloca (len
+ 4);
1636 memcpy (cmdtype1
+ 1, cmdtype
, len
- 1);
1638 memcpy (cmdtype2
, cmdtype
, len
- 1);
1639 strcpy (cmdtype2
+ len
- 1, " sub");
1642 if (theclass
== all_classes
)
1643 gdb_printf (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
1645 gdb_printf (stream
, "List of %scommands:\n\n", cmdtype2
);
1647 help_cmd_list (list
, theclass
, theclass
>= 0, stream
);
1649 if (theclass
== all_classes
)
1651 gdb_printf (stream
, "\n\
1652 Type \"help%s\" followed by a class name for a list of commands in ",
1654 stream
->wrap_here (0);
1655 gdb_printf (stream
, "that class.");
1657 gdb_printf (stream
, "\n\
1658 Type \"help all\" for the list of all commands.");
1661 gdb_printf (stream
, "\nType \"help%s\" followed by %scommand name ",
1662 cmdtype1
, cmdtype2
);
1663 stream
->wrap_here (0);
1664 gdb_puts ("for ", stream
);
1665 stream
->wrap_here (0);
1666 gdb_puts ("full ", stream
);
1667 stream
->wrap_here (0);
1668 gdb_puts ("documentation.\n", stream
);
1669 gdb_puts ("Type \"apropos word\" to search "
1670 "for commands related to \"word\".\n", stream
);
1671 gdb_puts ("Type \"apropos -v word\" for full documentation", stream
);
1672 stream
->wrap_here (0);
1673 gdb_puts (" of commands related to \"word\".\n", stream
);
1674 gdb_puts ("Command name abbreviations are allowed if unambiguous.\n",
1679 help_all (struct ui_file
*stream
)
1681 struct cmd_list_element
*c
;
1682 int seen_unclassified
= 0;
1684 for (c
= cmdlist
; c
; c
= c
->next
)
1688 /* If this is a class name, print all of the commands in the
1691 if (c
->is_command_class_help ())
1693 gdb_printf (stream
, "\nCommand class: %s\n\n", c
->name
);
1694 help_cmd_list (cmdlist
, c
->theclass
, true, stream
);
1698 /* While it's expected that all commands are in some class,
1699 as a safety measure, we'll print commands outside of any
1700 class at the end. */
1702 for (c
= cmdlist
; c
; c
= c
->next
)
1707 if (c
->theclass
== no_class
)
1709 if (!seen_unclassified
)
1711 gdb_printf (stream
, "\nUnclassified commands\n\n");
1712 seen_unclassified
= 1;
1714 print_help_for_command (*c
, true, stream
);
1720 /* See cli-decode.h. */
1723 print_doc_line (struct ui_file
*stream
, const char *str
,
1724 bool for_value_prefix
)
1726 static char *line_buffer
= 0;
1727 static int line_size
;
1733 line_buffer
= (char *) xmalloc (line_size
);
1736 /* Searches for the first end of line or the end of STR. */
1738 while (*p
&& *p
!= '\n')
1740 if (p
- str
> line_size
- 1)
1742 line_size
= p
- str
+ 1;
1743 xfree (line_buffer
);
1744 line_buffer
= (char *) xmalloc (line_size
);
1746 strncpy (line_buffer
, str
, p
- str
);
1747 if (for_value_prefix
)
1749 if (islower (line_buffer
[0]))
1750 line_buffer
[0] = toupper (line_buffer
[0]);
1751 gdb_assert (p
> str
);
1752 if (line_buffer
[p
- str
- 1] == '.')
1753 line_buffer
[p
- str
- 1] = '\0';
1755 line_buffer
[p
- str
] = '\0';
1758 line_buffer
[p
- str
] = '\0';
1759 gdb_puts (line_buffer
, stream
);
1762 /* Print one-line help for command C.
1763 If RECURSE is non-zero, also print one-line descriptions
1764 of all prefixed subcommands. */
1766 print_help_for_command (const cmd_list_element
&c
,
1767 bool recurse
, struct ui_file
*stream
)
1769 fput_command_names_styled (c
, true, " -- ", stream
);
1770 print_doc_line (stream
, c
.doc
, false);
1771 gdb_puts ("\n", stream
);
1772 if (!c
.default_args
.empty ())
1773 fput_alias_definition_styled (c
, stream
);
1774 fput_aliases_definition_styled (c
, stream
);
1778 && c
.abbrev_flag
== 0)
1779 /* Subcommands of a prefix command typically have 'all_commands'
1780 as class. If we pass CLASS to recursive invocation,
1781 most often we won't see anything. */
1782 help_cmd_list (*c
.subcommands
, all_commands
, true, stream
);
1786 * Implement a help command on command list LIST.
1787 * RECURSE should be non-zero if this should be done recursively on
1788 * all sublists of LIST.
1789 * STREAM is the stream upon which the output should be written.
1790 * THECLASS should be:
1791 * A non-negative class number to list only commands in that
1792 * ALL_COMMANDS to list all commands in list.
1793 * ALL_CLASSES to list all classes in list.
1795 * Note that aliases are only shown when THECLASS is class_alias.
1796 * In the other cases, the aliases will be shown together with their
1799 * Note that RECURSE will be active on *all* sublists, not just the
1800 * ones selected by the criteria above (ie. the selection mechanism
1801 * is at the low level, not the high-level).
1805 help_cmd_list (struct cmd_list_element
*list
, enum command_class theclass
,
1806 bool recurse
, struct ui_file
*stream
)
1808 struct cmd_list_element
*c
;
1810 for (c
= list
; c
; c
= c
->next
)
1812 if (c
->abbrev_flag
== 1 || c
->cmd_deprecated
)
1814 /* Do not show abbreviations or deprecated commands. */
1818 if (c
->is_alias () && theclass
!= class_alias
)
1820 /* Do not show an alias, unless specifically showing the
1821 list of aliases: for all other classes, an alias is
1822 shown (if needed) together with its aliased command. */
1826 if (theclass
== all_commands
1827 || (theclass
== all_classes
&& c
->is_command_class_help ())
1828 || (theclass
== c
->theclass
&& !c
->is_command_class_help ()))
1831 - showing all commands
1832 - showing all classes and C is a help class
1833 - showing commands of THECLASS and C is not the help class */
1835 /* If we show the class_alias and C is an alias, do not recurse,
1836 as this would show the (possibly very long) not very useful
1837 list of sub-commands of the aliased command. */
1838 print_help_for_command
1840 recurse
&& (theclass
!= class_alias
|| !c
->is_alias ()),
1846 && (theclass
== class_user
|| theclass
== class_alias
)
1849 /* User-defined commands or aliases may be subcommands. */
1850 help_cmd_list (*c
->subcommands
, theclass
, recurse
, stream
);
1854 /* Do not show C or recurse on C, e.g. because C does not belong to
1855 THECLASS or because C is a help class. */
1860 /* Search the input clist for 'command'. Return the command if
1861 found (or NULL if not), and return the number of commands
1864 static struct cmd_list_element
*
1865 find_cmd (const char *command
, int len
, struct cmd_list_element
*clist
,
1866 int ignore_help_classes
, int *nfound
)
1868 struct cmd_list_element
*found
, *c
;
1872 for (c
= clist
; c
; c
= c
->next
)
1873 if (!strncmp (command
, c
->name
, len
)
1874 && (!ignore_help_classes
|| !c
->is_command_class_help ()))
1878 if (c
->name
[len
] == '\0')
1887 /* Return the length of command name in TEXT. */
1890 find_command_name_length (const char *text
)
1892 const char *p
= text
;
1894 /* Treating underscores as part of command words is important
1895 so that "set args_foo()" doesn't get interpreted as
1896 "set args _foo()". */
1897 /* Some characters are only used for TUI specific commands.
1898 However, they are always allowed for the sake of consistency.
1900 Note that this is larger than the character set allowed when
1901 creating user-defined commands. */
1903 /* Recognize the single character commands so that, e.g., "!ls"
1904 works as expected. */
1905 if (*p
== '!' || *p
== '|')
1908 while (valid_cmd_char_p (*p
)
1909 /* Characters used by TUI specific commands. */
1910 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')
1916 /* See command.h. */
1919 valid_cmd_char_p (int c
)
1921 /* Alas "42" is a legitimate user-defined command.
1922 In the interests of not breaking anything we preserve that. */
1924 return isalnum (c
) || c
== '-' || c
== '_' || c
== '.';
1927 /* See command.h. */
1930 valid_user_defined_cmd_name_p (const char *name
)
1937 for (p
= name
; *p
!= '\0'; ++p
)
1939 if (valid_cmd_char_p (*p
))
1948 /* See command.h. */
1950 struct cmd_list_element
*
1951 lookup_cmd_1 (const char **text
, struct cmd_list_element
*clist
,
1952 struct cmd_list_element
**result_list
, std::string
*default_args
,
1953 int ignore_help_classes
, bool lookup_for_completion_p
)
1957 struct cmd_list_element
*found
, *c
;
1958 bool found_alias
= false;
1959 const char *line
= *text
;
1961 while (**text
== ' ' || **text
== '\t')
1964 /* Identify the name of the command. */
1965 len
= find_command_name_length (*text
);
1967 /* If nothing but whitespace, return 0. */
1971 /* *text and p now bracket the first command word to lookup (and
1972 it's length is len). We copy this into a local temporary. */
1975 command
= (char *) alloca (len
+ 1);
1976 memcpy (command
, *text
, len
);
1977 command
[len
] = '\0';
1982 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1984 /* If nothing matches, we have a simple failure. */
1990 if (result_list
!= nullptr)
1991 /* Will be modified in calling routine
1992 if we know what the prefix command is. */
1994 if (default_args
!= nullptr)
1995 *default_args
= std::string ();
1996 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1999 /* We've matched something on this list. Move text pointer forward. */
2003 if (found
->is_alias ())
2005 /* We drop the alias (abbreviation) in favor of the command it
2006 is pointing to. If the alias is deprecated, though, we need to
2007 warn the user about it before we drop it. Note that while we
2008 are warning about the alias, we may also warn about the command
2009 itself and we will adjust the appropriate DEPRECATED_WARN_USER
2012 if (found
->deprecated_warn_user
&& !lookup_for_completion_p
)
2013 deprecated_cmd_warning (line
, clist
);
2016 /* Return the default_args of the alias, not the default_args
2017 of the command it is pointing to. */
2018 if (default_args
!= nullptr)
2019 *default_args
= found
->default_args
;
2020 found
= found
->alias_target
;
2023 /* If we found a prefix command, keep looking. */
2025 if (found
->is_prefix ())
2027 c
= lookup_cmd_1 (text
, *found
->subcommands
, result_list
, default_args
,
2028 ignore_help_classes
, lookup_for_completion_p
);
2031 /* Didn't find anything; this is as far as we got. */
2032 if (result_list
!= nullptr)
2033 *result_list
= clist
;
2034 if (!found_alias
&& default_args
!= nullptr)
2035 *default_args
= found
->default_args
;
2038 else if (c
== CMD_LIST_AMBIGUOUS
)
2040 /* We've gotten this far properly, but the next step is
2041 ambiguous. We need to set the result list to the best
2042 we've found (if an inferior hasn't already set it). */
2043 if (result_list
!= nullptr)
2045 /* This used to say *result_list = *found->subcommands.
2046 If that was correct, need to modify the documentation
2047 at the top of this function to clarify what is
2048 supposed to be going on. */
2049 *result_list
= found
;
2050 /* For ambiguous commands, do not return any default_args args. */
2051 if (default_args
!= nullptr)
2052 *default_args
= std::string ();
2063 if (result_list
!= nullptr)
2064 *result_list
= clist
;
2065 if (!found_alias
&& default_args
!= nullptr)
2066 *default_args
= found
->default_args
;
2071 /* All this hair to move the space to the front of cmdtype */
2074 undef_cmd_error (const char *cmdtype
, const char *q
)
2076 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
2079 *cmdtype
? " " : "",
2080 (int) strlen (cmdtype
) - 1,
2084 /* Look up the contents of *LINE as a command in the command list LIST.
2085 LIST is a chain of struct cmd_list_element's.
2086 If it is found, return the struct cmd_list_element for that command,
2087 update *LINE to point after the command name, at the first argument
2088 and update *DEFAULT_ARGS (if DEFAULT_ARGS is not null) to the default
2089 args to prepend to the user provided args when running the command.
2090 Note that if the found cmd_list_element is found via an alias,
2091 the default args of the alias are returned.
2093 If not found, call error if ALLOW_UNKNOWN is zero
2094 otherwise (or if error returns) return zero.
2095 Call error if specified command is ambiguous,
2096 unless ALLOW_UNKNOWN is negative.
2097 CMDTYPE precedes the word "command" in the error message.
2099 If IGNORE_HELP_CLASSES is nonzero, ignore any command list
2100 elements which are actually help classes rather than commands (i.e.
2101 the function field of the struct cmd_list_element is 0). */
2103 struct cmd_list_element
*
2104 lookup_cmd (const char **line
, struct cmd_list_element
*list
,
2105 const char *cmdtype
,
2106 std::string
*default_args
,
2107 int allow_unknown
, int ignore_help_classes
)
2109 struct cmd_list_element
*last_list
= 0;
2110 struct cmd_list_element
*c
;
2112 /* Note: Do not remove trailing whitespace here because this
2113 would be wrong for complete_command. Jim Kingdon */
2116 error (_("Lack of needed %scommand"), cmdtype
);
2118 c
= lookup_cmd_1 (line
, list
, &last_list
, default_args
, ignore_help_classes
);
2125 int len
= find_command_name_length (*line
);
2127 q
= (char *) alloca (len
+ 1);
2128 strncpy (q
, *line
, len
);
2130 undef_cmd_error (cmdtype
, q
);
2135 else if (c
== CMD_LIST_AMBIGUOUS
)
2137 /* Ambigous. Local values should be off subcommands or called
2139 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
2141 std::string local_cmdtype
2142 = last_list
? last_list
->prefixname () : cmdtype
;
2143 struct cmd_list_element
*local_list
=
2144 (last_list
? *(last_list
->subcommands
) : list
);
2146 if (local_allow_unknown
< 0)
2149 return last_list
; /* Found something. */
2151 return 0; /* Found nothing. */
2155 /* Report as error. */
2160 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
2161 && (*line
)[amb_len
] != '\t');
2166 for (c
= local_list
; c
; c
= c
->next
)
2167 if (!strncmp (*line
, c
->name
, amb_len
))
2169 if (strlen (ambbuf
) + strlen (c
->name
) + 6
2170 < (int) sizeof ambbuf
)
2172 if (strlen (ambbuf
))
2173 strcat (ambbuf
, ", ");
2174 strcat (ambbuf
, c
->name
);
2178 strcat (ambbuf
, "..");
2182 error (_("Ambiguous %scommand \"%s\": %s."),
2183 local_cmdtype
.c_str (), *line
, ambbuf
);
2188 if (c
->type
== set_cmd
&& **line
!= '\0' && !isspace (**line
))
2189 error (_("Argument must be preceded by space."));
2191 /* We've got something. It may still not be what the caller
2192 wants (if this command *needs* a subcommand). */
2193 while (**line
== ' ' || **line
== '\t')
2196 if (c
->is_prefix () && **line
&& !c
->allow_unknown
)
2197 undef_cmd_error (c
->prefixname ().c_str (), *line
);
2199 /* Seems to be what he wants. Return it. */
2205 /* See command.h. */
2207 struct cmd_list_element
*
2208 lookup_cmd_exact (const char *name
,
2209 struct cmd_list_element
*list
,
2210 bool ignore_help_classes
)
2212 const char *tem
= name
;
2213 struct cmd_list_element
*cmd
= lookup_cmd (&tem
, list
, "", NULL
, -1,
2214 ignore_help_classes
);
2215 if (cmd
!= nullptr && strcmp (name
, cmd
->name
) != 0)
2220 /* We are here presumably because an alias or command in TEXT is
2221 deprecated and a warning message should be generated. This
2222 function decodes TEXT and potentially generates a warning message
2225 Example for 'set endian big' which has a fictitious alias 'seb'.
2227 If alias wasn't used in TEXT, and the command is deprecated:
2228 "warning: 'set endian big' is deprecated."
2230 If alias was used, and only the alias is deprecated:
2231 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
2233 If alias was used and command is deprecated (regardless of whether
2234 the alias itself is deprecated:
2236 "warning: 'set endian big' (seb) is deprecated."
2238 After the message has been sent, clear the appropriate flags in the
2239 command and/or the alias so the user is no longer bothered.
2243 deprecated_cmd_warning (const char *text
, struct cmd_list_element
*list
)
2245 struct cmd_list_element
*alias
= nullptr;
2246 struct cmd_list_element
*cmd
= nullptr;
2248 /* Return if text doesn't evaluate to a command. We place this lookup
2249 within its own scope so that the PREFIX_CMD local is not visible
2250 later in this function. The value returned in PREFIX_CMD is based on
2251 the prefix found in TEXT, and is our case this prefix can be missing
2252 in some situations (when LIST is not the global CMDLIST).
2254 It is better for our purposes to use the prefix commands directly from
2255 the ALIAS and CMD results. */
2257 struct cmd_list_element
*prefix_cmd
= nullptr;
2258 if (!lookup_cmd_composition_1 (text
, &alias
, &prefix_cmd
, &cmd
, list
))
2262 /* Return if nothing is deprecated. */
2263 if (!((alias
!= nullptr ? alias
->deprecated_warn_user
: 0)
2264 || cmd
->deprecated_warn_user
))
2267 /* Join command prefix (if any) and the command name. */
2268 std::string tmp_cmd_str
;
2269 if (cmd
->prefix
!= nullptr)
2270 tmp_cmd_str
+= cmd
->prefix
->prefixname ();
2271 tmp_cmd_str
+= std::string (cmd
->name
);
2273 /* Display the appropriate first line, this warns that the thing the user
2274 entered is deprecated. */
2275 if (alias
!= nullptr)
2277 /* Join the alias prefix (if any) and the alias name. */
2278 std::string tmp_alias_str
;
2279 if (alias
->prefix
!= nullptr)
2280 tmp_alias_str
+= alias
->prefix
->prefixname ();
2281 tmp_alias_str
+= std::string (alias
->name
);
2283 if (cmd
->cmd_deprecated
)
2284 gdb_printf (_("Warning: command '%ps' (%ps) is deprecated.\n"),
2285 styled_string (title_style
.style (),
2286 tmp_cmd_str
.c_str ()),
2287 styled_string (title_style
.style (),
2288 tmp_alias_str
.c_str ()));
2290 gdb_printf (_("Warning: '%ps', an alias for the command '%ps', "
2291 "is deprecated.\n"),
2292 styled_string (title_style
.style (),
2293 tmp_alias_str
.c_str ()),
2294 styled_string (title_style
.style (),
2295 tmp_cmd_str
.c_str ()));
2298 gdb_printf (_("Warning: command '%ps' is deprecated.\n"),
2299 styled_string (title_style
.style (),
2300 tmp_cmd_str
.c_str ()));
2302 /* Now display a second line indicating what the user should use instead.
2303 If it is only the alias that is deprecated, we want to indicate the
2304 new alias, otherwise we'll indicate the new command. */
2305 const char *replacement
;
2306 if (alias
!= nullptr && !cmd
->cmd_deprecated
)
2307 replacement
= alias
->replacement
;
2309 replacement
= cmd
->replacement
;
2310 if (replacement
!= nullptr)
2311 gdb_printf (_("Use '%ps'.\n\n"),
2312 styled_string (title_style
.style (),
2315 gdb_printf (_("No alternative known.\n\n"));
2317 /* We've warned you, now we'll keep quiet. */
2318 if (alias
!= nullptr)
2319 alias
->deprecated_warn_user
= 0;
2320 cmd
->deprecated_warn_user
= 0;
2323 /* Look up the contents of TEXT as a command in the command list CUR_LIST.
2324 Return 1 on success, 0 on failure.
2326 If TEXT refers to an alias, *ALIAS will point to that alias.
2328 If TEXT is a subcommand (i.e. one that is preceded by a prefix
2329 command) set *PREFIX_CMD.
2331 Set *CMD to point to the command TEXT indicates.
2333 If any of *ALIAS, *PREFIX_CMD, or *CMD cannot be determined or do not
2334 exist, they are NULL when we return.
2339 lookup_cmd_composition_1 (const char *text
,
2340 struct cmd_list_element
**alias
,
2341 struct cmd_list_element
**prefix_cmd
,
2342 struct cmd_list_element
**cmd
,
2343 struct cmd_list_element
*cur_list
)
2346 *prefix_cmd
= cur_list
->prefix
;
2349 text
= skip_spaces (text
);
2351 /* Go through as many command lists as we need to, to find the command
2355 /* Identify the name of the command. */
2356 int len
= find_command_name_length (text
);
2358 /* If nothing but whitespace, return. */
2362 /* TEXT is the start of the first command word to lookup (and
2363 it's length is LEN). We copy this into a local temporary. */
2364 std::string
command (text
, len
);
2368 *cmd
= find_cmd (command
.c_str (), len
, cur_list
, 1, &nfound
);
2370 /* We only handle the case where a single command was found. */
2371 if (*cmd
== CMD_LIST_AMBIGUOUS
|| *cmd
== nullptr)
2375 if ((*cmd
)->is_alias ())
2377 /* If the command was actually an alias, we note that an
2378 alias was used (by assigning *ALIAS) and we set *CMD. */
2380 *cmd
= (*cmd
)->alias_target
;
2385 text
= skip_spaces (text
);
2387 if ((*cmd
)->is_prefix () && *text
!= '\0')
2389 cur_list
= *(*cmd
)->subcommands
;
2397 /* Look up the contents of TEXT as a command in the command list 'cmdlist'.
2398 Return 1 on success, 0 on failure.
2400 If TEXT refers to an alias, *ALIAS will point to that alias.
2402 If TEXT is a subcommand (i.e. one that is preceded by a prefix
2403 command) set *PREFIX_CMD.
2405 Set *CMD to point to the command TEXT indicates.
2407 If any of *ALIAS, *PREFIX_CMD, or *CMD cannot be determined or do not
2408 exist, they are NULL when we return.
2413 lookup_cmd_composition (const char *text
,
2414 struct cmd_list_element
**alias
,
2415 struct cmd_list_element
**prefix_cmd
,
2416 struct cmd_list_element
**cmd
)
2418 return lookup_cmd_composition_1 (text
, alias
, prefix_cmd
, cmd
, cmdlist
);
2421 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
2423 /* Return a vector of char pointers which point to the different
2424 possible completions in LIST of TEXT.
2426 WORD points in the same buffer as TEXT, and completions should be
2427 returned relative to this position. For example, suppose TEXT is
2428 "foo" and we want to complete to "foobar". If WORD is "oo", return
2429 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
2432 complete_on_cmdlist (struct cmd_list_element
*list
,
2433 completion_tracker
&tracker
,
2434 const char *text
, const char *word
,
2435 int ignore_help_classes
)
2437 struct cmd_list_element
*ptr
;
2438 int textlen
= strlen (text
);
2440 int saw_deprecated_match
= 0;
2442 /* We do one or two passes. In the first pass, we skip deprecated
2443 commands. If we see no matching commands in the first pass, and
2444 if we did happen to see a matching deprecated command, we do
2445 another loop to collect those. */
2446 for (pass
= 0; pass
< 2; ++pass
)
2448 bool got_matches
= false;
2450 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
2451 if (!strncmp (ptr
->name
, text
, textlen
)
2452 && !ptr
->abbrev_flag
2453 && (!ignore_help_classes
|| !ptr
->is_command_class_help ()
2454 || ptr
->is_prefix ()))
2458 if (ptr
->cmd_deprecated
)
2460 saw_deprecated_match
= 1;
2465 tracker
.add_completion
2466 (make_completion_match_str (ptr
->name
, text
, word
));
2473 /* If we saw no matching deprecated commands in the first pass,
2475 if (!saw_deprecated_match
)
2480 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
2482 /* Add the different possible completions in ENUMLIST of TEXT.
2484 WORD points in the same buffer as TEXT, and completions should be
2485 returned relative to this position. For example, suppose TEXT is "foo"
2486 and we want to complete to "foobar". If WORD is "oo", return
2487 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
2490 complete_on_enum (completion_tracker
&tracker
,
2491 const char *const *enumlist
,
2492 const char *text
, const char *word
)
2494 int textlen
= strlen (text
);
2498 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
2499 if (strncmp (name
, text
, textlen
) == 0)
2500 tracker
.add_completion (make_completion_match_str (name
, text
, word
));
2503 /* Call the command function. */
2505 cmd_func (struct cmd_list_element
*cmd
, const char *args
, int from_tty
)
2507 if (!cmd
->is_command_class_help ())
2509 gdb::optional
<scoped_restore_tmpl
<bool>> restore_suppress
;
2511 if (cmd
->suppress_notification
!= NULL
)
2512 restore_suppress
.emplace (cmd
->suppress_notification
, true);
2514 cmd
->func (args
, from_tty
, cmd
);
2517 error (_("Invalid command"));
2521 cli_user_command_p (struct cmd_list_element
*cmd
)
2523 return cmd
->theclass
== class_user
&& cmd
->func
== do_simple_func
;