1 /* Handle lists of commands, their decoding and documentation, for GDB.
3 Copyright (C) 1986-2017 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 "gdb_regex.h"
22 #include "completer.h"
24 #include "cli/cli-cmds.h"
25 #include "cli/cli-decode.h"
26 #include "common/gdb_optional.h"
28 /* Prototypes for local functions. */
30 static void undef_cmd_error (const char *, const char *);
32 static struct cmd_list_element
*delete_cmd (const char *name
,
33 struct cmd_list_element
**list
,
34 struct cmd_list_element
**prehook
,
35 struct cmd_list_element
**prehookee
,
36 struct cmd_list_element
**posthook
,
37 struct cmd_list_element
**posthookee
);
39 static struct cmd_list_element
*find_cmd (const char *command
,
41 struct cmd_list_element
*clist
,
42 int ignore_help_classes
,
45 static void help_all (struct ui_file
*stream
);
47 /* Look up a command whose 'prefixlist' is KEY. Return the command if found,
48 otherwise return NULL. */
50 static struct cmd_list_element
*
51 lookup_cmd_for_prefixlist (struct cmd_list_element
**key
,
52 struct cmd_list_element
*list
)
54 struct cmd_list_element
*p
= NULL
;
56 for (p
= list
; p
!= NULL
; p
= p
->next
)
58 struct cmd_list_element
*q
;
60 if (p
->prefixlist
== NULL
)
62 else if (p
->prefixlist
== key
)
65 q
= lookup_cmd_for_prefixlist (key
, *(p
->prefixlist
));
74 set_cmd_prefix (struct cmd_list_element
*c
, struct cmd_list_element
**list
)
76 struct cmd_list_element
*p
;
78 /* Check to see if *LIST contains any element other than C. */
79 for (p
= *list
; p
!= NULL
; p
= p
->next
)
85 /* *SET_LIST only contains SET. */
86 p
= lookup_cmd_for_prefixlist (list
, setlist
);
88 c
->prefix
= p
? (p
->cmd_pointer
? p
->cmd_pointer
: p
) : p
;
91 c
->prefix
= p
->prefix
;
95 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
96 int recurse
, struct ui_file
*stream
);
99 /* Set the callback function for the specified command. For each both
100 the commands callback and func() are set. The latter set to a
101 bounce function (unless cfunc / sfunc is NULL that is). */
104 do_const_cfunc (struct cmd_list_element
*c
, const char *args
, int from_tty
)
106 c
->function
.const_cfunc (args
, from_tty
);
110 set_cmd_cfunc (struct cmd_list_element
*cmd
, cmd_const_cfunc_ftype
*cfunc
)
115 cmd
->func
= do_const_cfunc
;
116 cmd
->function
.const_cfunc
= cfunc
;
120 do_sfunc (struct cmd_list_element
*c
, const char *args
, int from_tty
)
122 c
->function
.sfunc (args
, from_tty
, c
);
126 set_cmd_sfunc (struct cmd_list_element
*cmd
, cmd_const_sfunc_ftype
*sfunc
)
131 cmd
->func
= do_sfunc
;
132 cmd
->function
.sfunc
= sfunc
;
136 cmd_cfunc_eq (struct cmd_list_element
*cmd
, cmd_const_cfunc_ftype
*cfunc
)
138 return cmd
->func
== do_const_cfunc
&& cmd
->function
.const_cfunc
== cfunc
;
142 set_cmd_context (struct cmd_list_element
*cmd
, void *context
)
144 cmd
->context
= context
;
148 get_cmd_context (struct cmd_list_element
*cmd
)
154 cmd_type (struct cmd_list_element
*cmd
)
160 set_cmd_completer (struct cmd_list_element
*cmd
, completer_ftype
*completer
)
162 cmd
->completer
= completer
; /* Ok. */
165 /* See definition in commands.h. */
168 set_cmd_completer_handle_brkchars (struct cmd_list_element
*cmd
,
169 completer_handle_brkchars_ftype
*func
)
171 cmd
->completer_handle_brkchars
= func
;
174 /* Add element named NAME.
175 Space for NAME and DOC must be allocated by the caller.
176 CLASS is the top level category into which commands are broken down
178 FUN should be the function to execute the command;
179 it will get a character string as argument, with leading
180 and trailing blanks already eliminated.
182 DOC is a documentation string for the command.
183 Its first line should be a complete sentence.
184 It should start with ? for a command that is an abbreviation
185 or with * for a command that most users don't need to know about.
187 Add this command to command list *LIST.
189 Returns a pointer to the added command (not necessarily the head
192 static struct cmd_list_element
*
193 do_add_cmd (const char *name
, enum command_class theclass
,
194 const char *doc
, struct cmd_list_element
**list
)
196 struct cmd_list_element
*c
= XNEW (struct cmd_list_element
);
197 struct cmd_list_element
*p
, *iter
;
199 /* Turn each alias of the old command into an alias of the new
201 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
202 &c
->hook_post
, &c
->hookee_post
);
203 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
204 iter
->cmd_pointer
= c
;
206 c
->hook_pre
->hookee_pre
= c
;
208 c
->hookee_pre
->hook_pre
= c
;
210 c
->hook_post
->hookee_post
= c
;
212 c
->hookee_post
->hook_post
= c
;
214 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
222 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
231 c
->theclass
= theclass
;
232 set_cmd_context (c
, NULL
);
234 c
->cmd_deprecated
= 0;
235 c
->deprecated_warn_user
= 0;
236 c
->malloced_replacement
= 0;
237 c
->doc_allocated
= 0;
238 c
->replacement
= NULL
;
239 c
->pre_show_hook
= NULL
;
241 c
->prefixlist
= NULL
;
242 c
->prefixname
= NULL
;
243 c
->allow_unknown
= 0;
246 set_cmd_completer (c
, symbol_completer
);
247 c
->completer_handle_brkchars
= NULL
;
249 c
->type
= not_set_cmd
;
251 c
->var_type
= var_boolean
;
253 c
->user_commands
= NULL
;
254 c
->cmd_pointer
= NULL
;
255 c
->alias_chain
= NULL
;
256 c
->suppress_notification
= NULL
;
261 struct cmd_list_element
*
262 add_cmd (const char *name
, enum command_class theclass
,
263 const char *doc
, struct cmd_list_element
**list
)
265 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
267 result
->function
.const_cfunc
= NULL
;
271 struct cmd_list_element
*
272 add_cmd (const char *name
, enum command_class theclass
,
273 cmd_const_cfunc_ftype
*fun
,
274 const char *doc
, struct cmd_list_element
**list
)
276 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
277 set_cmd_cfunc (result
, fun
);
281 /* Deprecates a command CMD.
282 REPLACEMENT is the name of the command which should be used in
283 place of this command, or NULL if no such command exists.
285 This function does not check to see if command REPLACEMENT exists
286 since gdb may not have gotten around to adding REPLACEMENT when
287 this function is called.
289 Returns a pointer to the deprecated command. */
291 struct cmd_list_element
*
292 deprecate_cmd (struct cmd_list_element
*cmd
, const char *replacement
)
294 cmd
->cmd_deprecated
= 1;
295 cmd
->deprecated_warn_user
= 1;
297 if (replacement
!= NULL
)
298 cmd
->replacement
= replacement
;
300 cmd
->replacement
= NULL
;
305 struct cmd_list_element
*
306 add_alias_cmd (const char *name
, cmd_list_element
*old
,
307 enum command_class theclass
, int abbrev_flag
,
308 struct cmd_list_element
**list
)
312 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
313 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
314 &prehook
, &prehookee
,
315 &posthook
, &posthookee
);
317 /* If this happens, it means a programmer error somewhere. */
318 gdb_assert (!aliases
&& !prehook
&& !prehookee
319 && !posthook
&& ! posthookee
);
323 struct cmd_list_element
*c
= add_cmd (name
, theclass
, old
->doc
, list
);
325 /* If OLD->DOC can be freed, we should make another copy. */
326 if (old
->doc_allocated
)
328 c
->doc
= xstrdup (old
->doc
);
329 c
->doc_allocated
= 1;
331 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
333 c
->function
= old
->function
;
334 c
->prefixlist
= old
->prefixlist
;
335 c
->prefixname
= old
->prefixname
;
336 c
->allow_unknown
= old
->allow_unknown
;
337 c
->abbrev_flag
= abbrev_flag
;
338 c
->cmd_pointer
= old
;
339 c
->alias_chain
= old
->aliases
;
342 set_cmd_prefix (c
, list
);
346 struct cmd_list_element
*
347 add_alias_cmd (const char *name
, const char *oldname
,
348 enum command_class theclass
, int abbrev_flag
,
349 struct cmd_list_element
**list
)
352 struct cmd_list_element
*old
;
355 old
= lookup_cmd (&tmp
, *list
, "", 1, 1);
357 return add_alias_cmd (name
, old
, theclass
, abbrev_flag
, list
);
361 /* Like add_cmd but adds an element for a command prefix: a name that
362 should be followed by a subcommand to be looked up in another
363 command list. PREFIXLIST should be the address of the variable
364 containing that list. */
366 struct cmd_list_element
*
367 add_prefix_cmd (const char *name
, enum command_class theclass
,
368 cmd_const_cfunc_ftype
*fun
,
369 const char *doc
, struct cmd_list_element
**prefixlist
,
370 const char *prefixname
, int allow_unknown
,
371 struct cmd_list_element
**list
)
373 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
374 struct cmd_list_element
*p
;
376 c
->prefixlist
= prefixlist
;
377 c
->prefixname
= prefixname
;
378 c
->allow_unknown
= allow_unknown
;
380 if (list
== &cmdlist
)
383 set_cmd_prefix (c
, list
);
385 /* Update the field 'prefix' of each cmd_list_element in *PREFIXLIST. */
386 for (p
= *prefixlist
; p
!= NULL
; p
= p
->next
)
392 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
394 struct cmd_list_element
*
395 add_abbrev_prefix_cmd (const char *name
, enum command_class theclass
,
396 cmd_const_cfunc_ftype
*fun
, const char *doc
,
397 struct cmd_list_element
**prefixlist
,
398 const char *prefixname
,
399 int allow_unknown
, struct cmd_list_element
**list
)
401 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
403 c
->prefixlist
= prefixlist
;
404 c
->prefixname
= prefixname
;
405 c
->allow_unknown
= allow_unknown
;
410 /* This is an empty "cfunc". */
412 not_just_help_class_command (const char *args
, int from_tty
)
416 /* This is an empty "sfunc". */
419 empty_sfunc (const char *args
, int from_tty
, struct cmd_list_element
*c
)
423 /* Add element named NAME to command list LIST (the list for set/show
424 or some sublist thereof).
425 TYPE is set_cmd or show_cmd.
426 CLASS is as in add_cmd.
427 VAR_TYPE is the kind of thing we are setting.
428 VAR is address of the variable being controlled by this command.
429 DOC is the documentation string. */
431 static struct cmd_list_element
*
432 add_set_or_show_cmd (const char *name
,
434 enum command_class theclass
,
438 struct cmd_list_element
**list
)
440 struct cmd_list_element
*c
= add_cmd (name
, theclass
, doc
, list
);
442 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
444 c
->var_type
= var_type
;
446 /* This needs to be something besides NULL so that this isn't
447 treated as a help class. */
448 set_cmd_sfunc (c
, empty_sfunc
);
452 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
453 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
454 setting. VAR is address of the variable being controlled by this
455 command. SET_FUNC and SHOW_FUNC are the callback functions (if
456 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
457 strings. PRINT the format string to print the value. SET_RESULT
458 and SHOW_RESULT, if not NULL, are set to the resulting command
462 add_setshow_cmd_full (const char *name
,
463 enum command_class theclass
,
464 var_types var_type
, void *var
,
465 const char *set_doc
, const char *show_doc
,
466 const char *help_doc
,
467 cmd_const_sfunc_ftype
*set_func
,
468 show_value_ftype
*show_func
,
469 struct cmd_list_element
**set_list
,
470 struct cmd_list_element
**show_list
,
471 struct cmd_list_element
**set_result
,
472 struct cmd_list_element
**show_result
)
474 struct cmd_list_element
*set
;
475 struct cmd_list_element
*show
;
479 if (help_doc
!= NULL
)
481 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
482 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
486 full_set_doc
= xstrdup (set_doc
);
487 full_show_doc
= xstrdup (show_doc
);
489 set
= add_set_or_show_cmd (name
, set_cmd
, theclass
, var_type
, var
,
490 full_set_doc
, set_list
);
491 set
->doc_allocated
= 1;
493 if (set_func
!= NULL
)
494 set_cmd_sfunc (set
, set_func
);
496 set_cmd_prefix (set
, set_list
);
498 show
= add_set_or_show_cmd (name
, show_cmd
, theclass
, var_type
, var
,
499 full_show_doc
, show_list
);
500 show
->doc_allocated
= 1;
501 show
->show_value_func
= show_func
;
503 if (set_result
!= NULL
)
505 if (show_result
!= NULL
)
509 /* Add element named NAME to command list LIST (the list for set or
510 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
511 of strings which may follow NAME. VAR is address of the variable
512 which will contain the matching string (from ENUMLIST). */
515 add_setshow_enum_cmd (const char *name
,
516 enum command_class theclass
,
517 const char *const *enumlist
,
520 const char *show_doc
,
521 const char *help_doc
,
522 cmd_const_sfunc_ftype
*set_func
,
523 show_value_ftype
*show_func
,
524 struct cmd_list_element
**set_list
,
525 struct cmd_list_element
**show_list
)
527 struct cmd_list_element
*c
;
529 add_setshow_cmd_full (name
, theclass
, var_enum
, var
,
530 set_doc
, show_doc
, help_doc
,
537 const char * const auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
539 /* Add an auto-boolean command named NAME to both the set and show
540 command list lists. CLASS is as in add_cmd. VAR is address of the
541 variable which will contain the value. DOC is the documentation
542 string. FUNC is the corresponding callback. */
544 add_setshow_auto_boolean_cmd (const char *name
,
545 enum command_class theclass
,
546 enum auto_boolean
*var
,
547 const char *set_doc
, const char *show_doc
,
548 const char *help_doc
,
549 cmd_const_sfunc_ftype
*set_func
,
550 show_value_ftype
*show_func
,
551 struct cmd_list_element
**set_list
,
552 struct cmd_list_element
**show_list
)
554 struct cmd_list_element
*c
;
556 add_setshow_cmd_full (name
, theclass
, var_auto_boolean
, var
,
557 set_doc
, show_doc
, help_doc
,
561 c
->enums
= auto_boolean_enums
;
564 /* Add element named NAME to both the set and show command LISTs (the
565 list for set/show or some sublist thereof). CLASS is as in
566 add_cmd. VAR is address of the variable which will contain the
567 value. SET_DOC and SHOW_DOC are the documentation strings. */
569 add_setshow_boolean_cmd (const char *name
, enum command_class theclass
, int *var
,
570 const char *set_doc
, const char *show_doc
,
571 const char *help_doc
,
572 cmd_const_sfunc_ftype
*set_func
,
573 show_value_ftype
*show_func
,
574 struct cmd_list_element
**set_list
,
575 struct cmd_list_element
**show_list
)
577 static const char *boolean_enums
[] = { "on", "off", NULL
};
578 struct cmd_list_element
*c
;
580 add_setshow_cmd_full (name
, theclass
, var_boolean
, var
,
581 set_doc
, show_doc
, help_doc
,
585 c
->enums
= boolean_enums
;
588 /* Add element named NAME to both the set and show command LISTs (the
589 list for set/show or some sublist thereof). */
591 add_setshow_filename_cmd (const char *name
, enum command_class theclass
,
593 const char *set_doc
, const char *show_doc
,
594 const char *help_doc
,
595 cmd_const_sfunc_ftype
*set_func
,
596 show_value_ftype
*show_func
,
597 struct cmd_list_element
**set_list
,
598 struct cmd_list_element
**show_list
)
600 struct cmd_list_element
*set_result
;
602 add_setshow_cmd_full (name
, theclass
, var_filename
, var
,
603 set_doc
, show_doc
, help_doc
,
607 set_cmd_completer (set_result
, filename_completer
);
610 /* Add element named NAME to both the set and show command LISTs (the
611 list for set/show or some sublist thereof). */
613 add_setshow_string_cmd (const char *name
, enum command_class theclass
,
615 const char *set_doc
, const char *show_doc
,
616 const char *help_doc
,
617 cmd_const_sfunc_ftype
*set_func
,
618 show_value_ftype
*show_func
,
619 struct cmd_list_element
**set_list
,
620 struct cmd_list_element
**show_list
)
622 add_setshow_cmd_full (name
, theclass
, var_string
, var
,
623 set_doc
, show_doc
, help_doc
,
629 /* Add element named NAME to both the set and show command LISTs (the
630 list for set/show or some sublist thereof). */
631 struct cmd_list_element
*
632 add_setshow_string_noescape_cmd (const char *name
, enum command_class theclass
,
634 const char *set_doc
, const char *show_doc
,
635 const char *help_doc
,
636 cmd_const_sfunc_ftype
*set_func
,
637 show_value_ftype
*show_func
,
638 struct cmd_list_element
**set_list
,
639 struct cmd_list_element
**show_list
)
641 struct cmd_list_element
*set_cmd
;
643 add_setshow_cmd_full (name
, theclass
, var_string_noescape
, var
,
644 set_doc
, show_doc
, help_doc
,
651 /* Add element named NAME to both the set and show command LISTs (the
652 list for set/show or some sublist thereof). */
654 add_setshow_optional_filename_cmd (const char *name
, enum command_class theclass
,
656 const char *set_doc
, const char *show_doc
,
657 const char *help_doc
,
658 cmd_const_sfunc_ftype
*set_func
,
659 show_value_ftype
*show_func
,
660 struct cmd_list_element
**set_list
,
661 struct cmd_list_element
**show_list
)
663 struct cmd_list_element
*set_result
;
665 add_setshow_cmd_full (name
, theclass
, var_optional_filename
, var
,
666 set_doc
, show_doc
, help_doc
,
671 set_cmd_completer (set_result
, filename_completer
);
675 /* Completes on literal "unlimited". Used by integer commands that
676 support a special "unlimited" value. */
679 integer_unlimited_completer (struct cmd_list_element
*ignore
,
680 completion_tracker
&tracker
,
681 const char *text
, const char *word
)
683 static const char * const keywords
[] =
689 complete_on_enum (tracker
, keywords
, text
, word
);
692 /* Add element named NAME to both the set and show command LISTs (the
693 list for set/show or some sublist thereof). CLASS is as in
694 add_cmd. VAR is address of the variable which will contain the
695 value. SET_DOC and SHOW_DOC are the documentation strings. This
696 function is only used in Python API. Please don't use it elsewhere. */
698 add_setshow_integer_cmd (const char *name
, enum command_class theclass
,
700 const char *set_doc
, const char *show_doc
,
701 const char *help_doc
,
702 cmd_const_sfunc_ftype
*set_func
,
703 show_value_ftype
*show_func
,
704 struct cmd_list_element
**set_list
,
705 struct cmd_list_element
**show_list
)
707 struct cmd_list_element
*set
;
709 add_setshow_cmd_full (name
, theclass
, var_integer
, var
,
710 set_doc
, show_doc
, help_doc
,
715 set_cmd_completer (set
, integer_unlimited_completer
);
718 /* Add element named NAME to both the set and show command LISTs (the
719 list for set/show or some sublist thereof). CLASS is as in
720 add_cmd. VAR is address of the variable which will contain the
721 value. SET_DOC and SHOW_DOC are the documentation strings. */
723 add_setshow_uinteger_cmd (const char *name
, enum command_class theclass
,
725 const char *set_doc
, const char *show_doc
,
726 const char *help_doc
,
727 cmd_const_sfunc_ftype
*set_func
,
728 show_value_ftype
*show_func
,
729 struct cmd_list_element
**set_list
,
730 struct cmd_list_element
**show_list
)
732 struct cmd_list_element
*set
;
734 add_setshow_cmd_full (name
, theclass
, var_uinteger
, var
,
735 set_doc
, show_doc
, help_doc
,
740 set_cmd_completer (set
, integer_unlimited_completer
);
743 /* Add element named NAME to both the set and show command LISTs (the
744 list for set/show or some sublist thereof). CLASS is as in
745 add_cmd. VAR is address of the variable which will contain the
746 value. SET_DOC and SHOW_DOC are the documentation strings. */
748 add_setshow_zinteger_cmd (const char *name
, enum command_class theclass
,
750 const char *set_doc
, const char *show_doc
,
751 const char *help_doc
,
752 cmd_const_sfunc_ftype
*set_func
,
753 show_value_ftype
*show_func
,
754 struct cmd_list_element
**set_list
,
755 struct cmd_list_element
**show_list
)
757 add_setshow_cmd_full (name
, theclass
, var_zinteger
, var
,
758 set_doc
, show_doc
, help_doc
,
765 add_setshow_zuinteger_unlimited_cmd (const char *name
,
766 enum command_class theclass
,
769 const char *show_doc
,
770 const char *help_doc
,
771 cmd_const_sfunc_ftype
*set_func
,
772 show_value_ftype
*show_func
,
773 struct cmd_list_element
**set_list
,
774 struct cmd_list_element
**show_list
)
776 struct cmd_list_element
*set
;
778 add_setshow_cmd_full (name
, theclass
, var_zuinteger_unlimited
, var
,
779 set_doc
, show_doc
, help_doc
,
784 set_cmd_completer (set
, integer_unlimited_completer
);
787 /* Add element named NAME to both the set and show command LISTs (the
788 list for set/show or some sublist thereof). CLASS is as in
789 add_cmd. VAR is address of the variable which will contain the
790 value. SET_DOC and SHOW_DOC are the documentation strings. */
792 add_setshow_zuinteger_cmd (const char *name
, enum command_class theclass
,
794 const char *set_doc
, const char *show_doc
,
795 const char *help_doc
,
796 cmd_const_sfunc_ftype
*set_func
,
797 show_value_ftype
*show_func
,
798 struct cmd_list_element
**set_list
,
799 struct cmd_list_element
**show_list
)
801 add_setshow_cmd_full (name
, theclass
, var_zuinteger
, var
,
802 set_doc
, show_doc
, help_doc
,
808 /* Remove the command named NAME from the command list. Return the
809 list commands which were aliased to the deleted command. If the
810 command had no aliases, return NULL. The various *HOOKs are set to
811 the pre- and post-hook commands for the deleted command. If the
812 command does not have a hook, the corresponding out parameter is
815 static struct cmd_list_element
*
816 delete_cmd (const char *name
, struct cmd_list_element
**list
,
817 struct cmd_list_element
**prehook
,
818 struct cmd_list_element
**prehookee
,
819 struct cmd_list_element
**posthook
,
820 struct cmd_list_element
**posthookee
)
822 struct cmd_list_element
*iter
;
823 struct cmd_list_element
**previous_chain_ptr
;
824 struct cmd_list_element
*aliases
= NULL
;
830 previous_chain_ptr
= list
;
832 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
834 if (strcmp (iter
->name
, name
) == 0)
837 iter
->destroyer (iter
, iter
->context
);
838 if (iter
->hookee_pre
)
839 iter
->hookee_pre
->hook_pre
= 0;
840 *prehook
= iter
->hook_pre
;
841 *prehookee
= iter
->hookee_pre
;
842 if (iter
->hookee_post
)
843 iter
->hookee_post
->hook_post
= 0;
844 if (iter
->doc
&& iter
->doc_allocated
)
845 xfree ((char *) iter
->doc
);
846 *posthook
= iter
->hook_post
;
847 *posthookee
= iter
->hookee_post
;
849 /* Update the link. */
850 *previous_chain_ptr
= iter
->next
;
852 aliases
= iter
->aliases
;
854 /* If this command was an alias, remove it from the list of
856 if (iter
->cmd_pointer
)
858 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
859 struct cmd_list_element
*a
= *prevp
;
863 prevp
= &a
->alias_chain
;
866 *prevp
= iter
->alias_chain
;
871 /* We won't see another command with the same name. */
875 previous_chain_ptr
= &iter
->next
;
881 /* Shorthands to the commands above. */
883 /* Add an element to the list of info subcommands. */
885 struct cmd_list_element
*
886 add_info (const char *name
, cmd_const_cfunc_ftype
*fun
, const char *doc
)
888 return add_cmd (name
, class_info
, fun
, doc
, &infolist
);
891 /* Add an alias to the list of info subcommands. */
893 struct cmd_list_element
*
894 add_info_alias (const char *name
, const char *oldname
, int abbrev_flag
)
896 return add_alias_cmd (name
, oldname
, class_run
, abbrev_flag
, &infolist
);
899 /* Add an element to the list of commands. */
901 struct cmd_list_element
*
902 add_com (const char *name
, enum command_class theclass
,
903 cmd_const_cfunc_ftype
*fun
,
906 return add_cmd (name
, theclass
, fun
, doc
, &cmdlist
);
909 /* Add an alias or abbreviation command to the list of commands. */
911 struct cmd_list_element
*
912 add_com_alias (const char *name
, const char *oldname
, enum command_class theclass
,
915 return add_alias_cmd (name
, oldname
, theclass
, abbrev_flag
, &cmdlist
);
918 /* Add an element with a suppress notification to the list of commands. */
920 struct cmd_list_element
*
921 add_com_suppress_notification (const char *name
, enum command_class theclass
,
922 cmd_const_cfunc_ftype
*fun
, const char *doc
,
923 int *suppress_notification
)
925 struct cmd_list_element
*element
;
927 element
= add_cmd (name
, theclass
, fun
, doc
, &cmdlist
);
928 element
->suppress_notification
= suppress_notification
;
933 /* Recursively walk the commandlist structures, and print out the
934 documentation of commands that match our regex in either their
935 name, or their documentation.
938 apropos_cmd (struct ui_file
*stream
,
939 struct cmd_list_element
*commandlist
,
940 compiled_regex
®ex
, const char *prefix
)
942 struct cmd_list_element
*c
;
945 /* Walk through the commands. */
946 for (c
=commandlist
;c
;c
=c
->next
)
948 returnvalue
= -1; /* Needed to avoid double printing. */
951 size_t name_len
= strlen (c
->name
);
953 /* Try to match against the name. */
954 returnvalue
= regex
.search (c
->name
, name_len
, 0, name_len
, NULL
);
955 if (returnvalue
>= 0)
957 print_help_for_command (c
, prefix
,
958 0 /* don't recurse */, stream
);
961 if (c
->doc
!= NULL
&& returnvalue
< 0)
963 size_t doc_len
= strlen (c
->doc
);
965 /* Try to match against documentation. */
966 if (regex
.search (c
->doc
, doc_len
, 0, doc_len
, NULL
) >= 0)
968 print_help_for_command (c
, prefix
,
969 0 /* don't recurse */, stream
);
972 /* Check if this command has subcommands and is not an
973 abbreviation. We skip listing subcommands of abbreviations
974 in order to avoid duplicates in the output. */
975 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
977 /* Recursively call ourselves on the subcommand list,
978 passing the right prefix in. */
979 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
984 /* This command really has to deal with two things:
985 1) I want documentation on *this string* (usually called by
988 2) I want documentation on *this list* (usually called by giving a
989 command that requires subcommands. Also called by saying just
992 I am going to split this into two seperate comamnds, help_cmd and
996 help_cmd (const char *command
, struct ui_file
*stream
)
998 struct cmd_list_element
*c
;
1002 help_list (cmdlist
, "", all_classes
, stream
);
1006 if (strcmp (command
, "all") == 0)
1012 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
1017 /* There are three cases here.
1018 If c->prefixlist is nonzero, we have a prefix command.
1019 Print its documentation, then list its subcommands.
1021 If c->func is non NULL, we really have a command. Print its
1022 documentation and return.
1024 If c->func is NULL, we have a class name. Print its
1025 documentation (as if it were a command) and then set class to the
1026 number of this class so that the commands in the class will be
1029 fputs_filtered (c
->doc
, stream
);
1030 fputs_filtered ("\n", stream
);
1032 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
1034 fprintf_filtered (stream
, "\n");
1036 /* If this is a prefix command, print it's subcommands. */
1038 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
1040 /* If this is a class name, print all of the commands in the class. */
1041 if (c
->func
== NULL
)
1042 help_list (cmdlist
, "", c
->theclass
, stream
);
1044 if (c
->hook_pre
|| c
->hook_post
)
1045 fprintf_filtered (stream
,
1046 "\nThis command has a hook (or hooks) defined:\n");
1049 fprintf_filtered (stream
,
1050 "\tThis command is run after : %s (pre hook)\n",
1053 fprintf_filtered (stream
,
1054 "\tThis command is run before : %s (post hook)\n",
1055 c
->hook_post
->name
);
1059 * Get a specific kind of help on a command list.
1062 * CMDTYPE is the prefix to use in the title string.
1063 * CLASS is the class with which to list the nodes of this list (see
1064 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
1065 * everything, ALL_CLASSES for just classes, and non-negative for only things
1066 * in a specific class.
1067 * and STREAM is the output stream on which to print things.
1068 * If you call this routine with a class >= 0, it recurses.
1071 help_list (struct cmd_list_element
*list
, const char *cmdtype
,
1072 enum command_class theclass
, struct ui_file
*stream
)
1075 char *cmdtype1
, *cmdtype2
;
1077 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
1079 len
= strlen (cmdtype
);
1080 cmdtype1
= (char *) alloca (len
+ 1);
1082 cmdtype2
= (char *) alloca (len
+ 4);
1087 memcpy (cmdtype1
+ 1, cmdtype
, len
- 1);
1089 memcpy (cmdtype2
, cmdtype
, len
- 1);
1090 strcpy (cmdtype2
+ len
- 1, " sub");
1093 if (theclass
== all_classes
)
1094 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
1096 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
1098 help_cmd_list (list
, theclass
, cmdtype
, (int) theclass
>= 0, stream
);
1100 if (theclass
== all_classes
)
1102 fprintf_filtered (stream
, "\n\
1103 Type \"help%s\" followed by a class name for a list of commands in ",
1106 fprintf_filtered (stream
, "that class.");
1108 fprintf_filtered (stream
, "\n\
1109 Type \"help all\" for the list of all commands.");
1112 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
1113 cmdtype1
, cmdtype2
);
1115 fputs_filtered ("for ", stream
);
1117 fputs_filtered ("full ", stream
);
1119 fputs_filtered ("documentation.\n", stream
);
1120 fputs_filtered ("Type \"apropos word\" to search "
1121 "for commands related to \"word\".\n", stream
);
1122 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
1127 help_all (struct ui_file
*stream
)
1129 struct cmd_list_element
*c
;
1130 int seen_unclassified
= 0;
1132 for (c
= cmdlist
; c
; c
= c
->next
)
1136 /* If this is a class name, print all of the commands in the
1139 if (c
->func
== NULL
)
1141 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
1142 help_cmd_list (cmdlist
, c
->theclass
, "", 1, stream
);
1146 /* While it's expected that all commands are in some class,
1147 as a safety measure, we'll print commands outside of any
1148 class at the end. */
1150 for (c
= cmdlist
; c
; c
= c
->next
)
1155 if (c
->theclass
== no_class
)
1157 if (!seen_unclassified
)
1159 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
1160 seen_unclassified
= 1;
1162 print_help_for_command (c
, "", 1, stream
);
1168 /* Print only the first line of STR on STREAM. */
1170 print_doc_line (struct ui_file
*stream
, const char *str
)
1172 static char *line_buffer
= 0;
1173 static int line_size
;
1179 line_buffer
= (char *) xmalloc (line_size
);
1182 /* Keep printing '.' or ',' not followed by a whitespace for embedded strings
1185 while (*p
&& *p
!= '\n'
1186 && ((*p
!= '.' && *p
!= ',') || (p
[1] && !isspace (p
[1]))))
1188 if (p
- str
> line_size
- 1)
1190 line_size
= p
- str
+ 1;
1191 xfree (line_buffer
);
1192 line_buffer
= (char *) xmalloc (line_size
);
1194 strncpy (line_buffer
, str
, p
- str
);
1195 line_buffer
[p
- str
] = '\0';
1196 if (islower (line_buffer
[0]))
1197 line_buffer
[0] = toupper (line_buffer
[0]);
1198 fputs_filtered (line_buffer
, stream
);
1201 /* Print one-line help for command C.
1202 If RECURSE is non-zero, also print one-line descriptions
1203 of all prefixed subcommands. */
1205 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
1206 int recurse
, struct ui_file
*stream
)
1208 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1209 print_doc_line (stream
, c
->doc
);
1210 fputs_filtered ("\n", stream
);
1213 && c
->prefixlist
!= 0
1214 && c
->abbrev_flag
== 0)
1215 /* Subcommands of a prefix command typically have 'all_commands'
1216 as class. If we pass CLASS to recursive invocation,
1217 most often we won't see anything. */
1218 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1222 * Implement a help command on command list LIST.
1223 * RECURSE should be non-zero if this should be done recursively on
1224 * all sublists of LIST.
1225 * PREFIX is the prefix to print before each command name.
1226 * STREAM is the stream upon which the output should be written.
1227 * THECLASS should be:
1228 * A non-negative class number to list only commands in that
1230 * ALL_COMMANDS to list all commands in list.
1231 * ALL_CLASSES to list all classes in list.
1233 * Note that RECURSE will be active on *all* sublists, not just the
1234 * ones selected by the criteria above (ie. the selection mechanism
1235 * is at the low level, not the high-level).
1238 help_cmd_list (struct cmd_list_element
*list
, enum command_class theclass
,
1239 const char *prefix
, int recurse
, struct ui_file
*stream
)
1241 struct cmd_list_element
*c
;
1243 for (c
= list
; c
; c
= c
->next
)
1245 if (c
->abbrev_flag
== 0
1246 && !c
->cmd_deprecated
1247 && (theclass
== all_commands
1248 || (theclass
== all_classes
&& c
->func
== NULL
)
1249 || (theclass
== c
->theclass
&& c
->func
!= NULL
)))
1251 print_help_for_command (c
, prefix
, recurse
, stream
);
1253 else if (c
->abbrev_flag
== 0
1255 && !c
->cmd_deprecated
1256 && theclass
== class_user
&& c
->prefixlist
!= NULL
)
1257 /* User-defined commands may be subcommands. */
1258 help_cmd_list (*c
->prefixlist
, theclass
, c
->prefixname
,
1264 /* Search the input clist for 'command'. Return the command if
1265 found (or NULL if not), and return the number of commands
1268 static struct cmd_list_element
*
1269 find_cmd (const char *command
, int len
, struct cmd_list_element
*clist
,
1270 int ignore_help_classes
, int *nfound
)
1272 struct cmd_list_element
*found
, *c
;
1276 for (c
= clist
; c
; c
= c
->next
)
1277 if (!strncmp (command
, c
->name
, len
)
1278 && (!ignore_help_classes
|| c
->func
))
1282 if (c
->name
[len
] == '\0')
1291 /* Return the length of command name in TEXT. */
1294 find_command_name_length (const char *text
)
1296 const char *p
= text
;
1298 /* Treating underscores as part of command words is important
1299 so that "set args_foo()" doesn't get interpreted as
1300 "set args _foo()". */
1301 /* Some characters are only used for TUI specific commands.
1302 However, they are always allowed for the sake of consistency.
1304 Note that this is larger than the character set allowed when
1305 creating user-defined commands. */
1307 /* Recognize '!' as a single character command so that, e.g., "!ls"
1308 works as expected. */
1312 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1313 /* Characters used by TUI specific commands. */
1314 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')
1320 /* Return TRUE if NAME is a valid user-defined command name.
1321 This is a stricter subset of all gdb commands,
1322 see find_command_name_length. */
1325 valid_user_defined_cmd_name_p (const char *name
)
1332 /* Alas "42" is a legitimate user-defined command.
1333 In the interests of not breaking anything we preserve that. */
1335 for (p
= name
; *p
!= '\0'; ++p
)
1348 /* This routine takes a line of TEXT and a CLIST in which to start the
1349 lookup. When it returns it will have incremented the text pointer past
1350 the section of text it matched, set *RESULT_LIST to point to the list in
1351 which the last word was matched, and will return a pointer to the cmd
1352 list element which the text matches. It will return NULL if no match at
1353 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1354 matches are possible; in this case *RESULT_LIST will be set to point to
1355 the list in which there are ambiguous choices (and *TEXT will be set to
1356 the ambiguous text string).
1358 If the located command was an abbreviation, this routine returns the base
1359 command of the abbreviation.
1361 It does no error reporting whatsoever; control will always return
1362 to the superior routine.
1364 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1365 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1366 if no prefix command was ever found. For example, in the case of "info a",
1367 "info" matches without ambiguity, but "a" could be "args" or "address", so
1368 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1369 RESULT_LIST should not be interpreted as a pointer to the beginning of a
1370 list; it simply points to a specific command. In the case of an ambiguous
1371 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1372 "info t" can be "info types" or "info target"; upon return *TEXT has been
1373 advanced past "info ").
1375 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1376 affect the operation).
1378 This routine does *not* modify the text pointed to by TEXT.
1380 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1381 are actually help classes rather than commands (i.e. the function field of
1382 the struct cmd_list_element is NULL). */
1384 struct cmd_list_element
*
1385 lookup_cmd_1 (const char **text
, struct cmd_list_element
*clist
,
1386 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1390 struct cmd_list_element
*found
, *c
;
1391 const char *line
= *text
;
1393 while (**text
== ' ' || **text
== '\t')
1396 /* Identify the name of the command. */
1397 len
= find_command_name_length (*text
);
1399 /* If nothing but whitespace, return 0. */
1403 /* *text and p now bracket the first command word to lookup (and
1404 it's length is len). We copy this into a local temporary. */
1407 command
= (char *) alloca (len
+ 1);
1408 memcpy (command
, *text
, len
);
1409 command
[len
] = '\0';
1414 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1416 /* If nothing matches, we have a simple failure. */
1422 if (result_list
!= NULL
)
1423 /* Will be modified in calling routine
1424 if we know what the prefix command is. */
1426 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1429 /* We've matched something on this list. Move text pointer forward. */
1433 if (found
->cmd_pointer
)
1435 /* We drop the alias (abbreviation) in favor of the command it
1436 is pointing to. If the alias is deprecated, though, we need to
1437 warn the user about it before we drop it. Note that while we
1438 are warning about the alias, we may also warn about the command
1439 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1442 if (found
->deprecated_warn_user
)
1443 deprecated_cmd_warning (line
);
1444 found
= found
->cmd_pointer
;
1446 /* If we found a prefix command, keep looking. */
1448 if (found
->prefixlist
)
1450 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1451 ignore_help_classes
);
1454 /* Didn't find anything; this is as far as we got. */
1455 if (result_list
!= NULL
)
1456 *result_list
= clist
;
1459 else if (c
== CMD_LIST_AMBIGUOUS
)
1461 /* We've gotten this far properly, but the next step is
1462 ambiguous. We need to set the result list to the best
1463 we've found (if an inferior hasn't already set it). */
1464 if (result_list
!= NULL
)
1466 /* This used to say *result_list = *found->prefixlist.
1467 If that was correct, need to modify the documentation
1468 at the top of this function to clarify what is
1469 supposed to be going on. */
1470 *result_list
= found
;
1481 if (result_list
!= NULL
)
1482 *result_list
= clist
;
1487 /* All this hair to move the space to the front of cmdtype */
1490 undef_cmd_error (const char *cmdtype
, const char *q
)
1492 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1495 *cmdtype
? " " : "",
1496 (int) strlen (cmdtype
) - 1,
1500 /* Look up the contents of *LINE as a command in the command list LIST.
1501 LIST is a chain of struct cmd_list_element's.
1502 If it is found, return the struct cmd_list_element for that command
1503 and update *LINE to point after the command name, at the first argument.
1504 If not found, call error if ALLOW_UNKNOWN is zero
1505 otherwise (or if error returns) return zero.
1506 Call error if specified command is ambiguous,
1507 unless ALLOW_UNKNOWN is negative.
1508 CMDTYPE precedes the word "command" in the error message.
1510 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1511 elements which are actually help classes rather than commands (i.e.
1512 the function field of the struct cmd_list_element is 0). */
1514 struct cmd_list_element
*
1515 lookup_cmd (const char **line
, struct cmd_list_element
*list
,
1516 const char *cmdtype
,
1517 int allow_unknown
, int ignore_help_classes
)
1519 struct cmd_list_element
*last_list
= 0;
1520 struct cmd_list_element
*c
;
1522 /* Note: Do not remove trailing whitespace here because this
1523 would be wrong for complete_command. Jim Kingdon */
1526 error (_("Lack of needed %scommand"), cmdtype
);
1528 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1535 int len
= find_command_name_length (*line
);
1537 q
= (char *) alloca (len
+ 1);
1538 strncpy (q
, *line
, len
);
1540 undef_cmd_error (cmdtype
, q
);
1545 else if (c
== CMD_LIST_AMBIGUOUS
)
1547 /* Ambigous. Local values should be off prefixlist or called
1549 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1551 const char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1552 struct cmd_list_element
*local_list
=
1553 (last_list
? *(last_list
->prefixlist
) : list
);
1555 if (local_allow_unknown
< 0)
1558 return last_list
; /* Found something. */
1560 return 0; /* Found nothing. */
1564 /* Report as error. */
1569 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1570 && (*line
)[amb_len
] != '\t');
1575 for (c
= local_list
; c
; c
= c
->next
)
1576 if (!strncmp (*line
, c
->name
, amb_len
))
1578 if (strlen (ambbuf
) + strlen (c
->name
) + 6
1579 < (int) sizeof ambbuf
)
1581 if (strlen (ambbuf
))
1582 strcat (ambbuf
, ", ");
1583 strcat (ambbuf
, c
->name
);
1587 strcat (ambbuf
, "..");
1591 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1593 return 0; /* lint */
1598 if (c
->type
== set_cmd
&& **line
!= '\0' && !isspace (**line
))
1599 error (_("Argument must be preceded by space."));
1601 /* We've got something. It may still not be what the caller
1602 wants (if this command *needs* a subcommand). */
1603 while (**line
== ' ' || **line
== '\t')
1606 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1607 undef_cmd_error (c
->prefixname
, *line
);
1609 /* Seems to be what he wants. Return it. */
1615 /* We are here presumably because an alias or command in TEXT is
1616 deprecated and a warning message should be generated. This
1617 function decodes TEXT and potentially generates a warning message
1620 Example for 'set endian big' which has a fictitious alias 'seb'.
1622 If alias wasn't used in TEXT, and the command is deprecated:
1623 "warning: 'set endian big' is deprecated."
1625 If alias was used, and only the alias is deprecated:
1626 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1628 If alias was used and command is deprecated (regardless of whether
1629 the alias itself is deprecated:
1631 "warning: 'set endian big' (seb) is deprecated."
1633 After the message has been sent, clear the appropriate flags in the
1634 command and/or the alias so the user is no longer bothered.
1638 deprecated_cmd_warning (const char *text
)
1640 struct cmd_list_element
*alias
= NULL
;
1641 struct cmd_list_element
*prefix_cmd
= NULL
;
1642 struct cmd_list_element
*cmd
= NULL
;
1644 if (!lookup_cmd_composition (text
, &alias
, &prefix_cmd
, &cmd
))
1645 /* Return if text doesn't evaluate to a command. */
1648 if (!((alias
? alias
->deprecated_warn_user
: 0)
1649 || cmd
->deprecated_warn_user
) )
1650 /* Return if nothing is deprecated. */
1653 printf_filtered ("Warning:");
1655 if (alias
&& !cmd
->cmd_deprecated
)
1656 printf_filtered (" '%s', an alias for the", alias
->name
);
1658 printf_filtered (" command '");
1661 printf_filtered ("%s", prefix_cmd
->prefixname
);
1663 printf_filtered ("%s", cmd
->name
);
1665 if (alias
&& cmd
->cmd_deprecated
)
1666 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1668 printf_filtered ("' is deprecated.\n");
1671 /* If it is only the alias that is deprecated, we want to indicate
1672 the new alias, otherwise we'll indicate the new command. */
1674 if (alias
&& !cmd
->cmd_deprecated
)
1676 if (alias
->replacement
)
1677 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1679 printf_filtered ("No alternative known.\n\n");
1683 if (cmd
->replacement
)
1684 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1686 printf_filtered ("No alternative known.\n\n");
1689 /* We've warned you, now we'll keep quiet. */
1691 alias
->deprecated_warn_user
= 0;
1693 cmd
->deprecated_warn_user
= 0;
1697 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1698 Return 1 on success, 0 on failure.
1700 If LINE refers to an alias, *alias will point to that alias.
1702 If LINE is a postfix command (i.e. one that is preceded by a prefix
1703 command) set *prefix_cmd.
1705 Set *cmd to point to the command LINE indicates.
1707 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1708 exist, they are NULL when we return.
1712 lookup_cmd_composition (const char *text
,
1713 struct cmd_list_element
**alias
,
1714 struct cmd_list_element
**prefix_cmd
,
1715 struct cmd_list_element
**cmd
)
1719 struct cmd_list_element
*cur_list
;
1720 struct cmd_list_element
*prev_cmd
;
1730 /* Go through as many command lists as we need to,
1731 to find the command TEXT refers to. */
1735 while (*text
== ' ' || *text
== '\t')
1738 /* Identify the name of the command. */
1739 len
= find_command_name_length (text
);
1741 /* If nothing but whitespace, return. */
1745 /* Text is the start of the first command word to lookup (and
1746 it's length is len). We copy this into a local temporary. */
1748 command
= (char *) alloca (len
+ 1);
1749 memcpy (command
, text
, len
);
1750 command
[len
] = '\0';
1755 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1757 if (*cmd
== CMD_LIST_AMBIGUOUS
)
1759 return 0; /* ambiguous */
1763 return 0; /* nothing found */
1766 if ((*cmd
)->cmd_pointer
)
1768 /* cmd was actually an alias, we note that an alias was
1769 used (by assigning *alais) and we set *cmd. */
1771 *cmd
= (*cmd
)->cmd_pointer
;
1773 *prefix_cmd
= prev_cmd
;
1775 if ((*cmd
)->prefixlist
)
1776 cur_list
= *(*cmd
)->prefixlist
;
1784 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1786 /* Return a vector of char pointers which point to the different
1787 possible completions in LIST of TEXT.
1789 WORD points in the same buffer as TEXT, and completions should be
1790 returned relative to this position. For example, suppose TEXT is
1791 "foo" and we want to complete to "foobar". If WORD is "oo", return
1792 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1795 complete_on_cmdlist (struct cmd_list_element
*list
,
1796 completion_tracker
&tracker
,
1797 const char *text
, const char *word
,
1798 int ignore_help_classes
)
1800 struct cmd_list_element
*ptr
;
1801 int textlen
= strlen (text
);
1803 int saw_deprecated_match
= 0;
1805 /* We do one or two passes. In the first pass, we skip deprecated
1806 commands. If we see no matching commands in the first pass, and
1807 if we did happen to see a matching deprecated command, we do
1808 another loop to collect those. */
1809 for (pass
= 0; pass
< 2; ++pass
)
1811 bool got_matches
= false;
1813 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1814 if (!strncmp (ptr
->name
, text
, textlen
)
1815 && !ptr
->abbrev_flag
1816 && (!ignore_help_classes
|| ptr
->func
1817 || ptr
->prefixlist
))
1821 if (ptr
->cmd_deprecated
)
1823 saw_deprecated_match
= 1;
1828 tracker
.add_completion
1829 (make_completion_match_str (ptr
->name
, text
, word
));
1836 /* If we saw no matching deprecated commands in the first pass,
1838 if (!saw_deprecated_match
)
1843 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1845 /* Add the different possible completions in ENUMLIST of TEXT.
1847 WORD points in the same buffer as TEXT, and completions should be
1848 returned relative to this position. For example, suppose TEXT is "foo"
1849 and we want to complete to "foobar". If WORD is "oo", return
1850 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1853 complete_on_enum (completion_tracker
&tracker
,
1854 const char *const *enumlist
,
1855 const char *text
, const char *word
)
1857 int textlen
= strlen (text
);
1861 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1862 if (strncmp (name
, text
, textlen
) == 0)
1863 tracker
.add_completion (make_completion_match_str (name
, text
, word
));
1867 /* Check function pointer. */
1869 cmd_func_p (struct cmd_list_element
*cmd
)
1871 return (cmd
->func
!= NULL
);
1875 /* Call the command function. */
1877 cmd_func (struct cmd_list_element
*cmd
, const char *args
, int from_tty
)
1879 if (cmd_func_p (cmd
))
1881 gdb::optional
<scoped_restore_tmpl
<int>> restore_suppress
;
1883 if (cmd
->suppress_notification
!= NULL
)
1884 restore_suppress
.emplace (cmd
->suppress_notification
, 1);
1886 (*cmd
->func
) (cmd
, args
, from_tty
);
1889 error (_("Invalid command"));
1893 cli_user_command_p (struct cmd_list_element
*cmd
)
1895 return (cmd
->theclass
== class_user
1896 && (cmd
->func
== do_const_cfunc
|| cmd
->func
== do_sfunc
));