1 /* Handle lists of commands, their decoding and documentation, for GDB.
3 Copyright (C) 1986-2018 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
= new struct cmd_list_element (name
, theclass
,
198 struct cmd_list_element
*p
, *iter
;
200 /* Turn each alias of the old command into an alias of the new
202 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
203 &c
->hook_post
, &c
->hookee_post
);
204 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
205 iter
->cmd_pointer
= c
;
207 c
->hook_pre
->hookee_pre
= c
;
209 c
->hookee_pre
->hook_pre
= c
;
211 c
->hook_post
->hookee_post
= c
;
213 c
->hookee_post
->hook_post
= c
;
215 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
223 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
234 struct cmd_list_element
*
235 add_cmd (const char *name
, enum command_class theclass
,
236 const char *doc
, struct cmd_list_element
**list
)
238 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
240 result
->function
.const_cfunc
= NULL
;
244 struct cmd_list_element
*
245 add_cmd (const char *name
, enum command_class theclass
,
246 cmd_const_cfunc_ftype
*fun
,
247 const char *doc
, struct cmd_list_element
**list
)
249 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
250 set_cmd_cfunc (result
, fun
);
254 /* Deprecates a command CMD.
255 REPLACEMENT is the name of the command which should be used in
256 place of this command, or NULL if no such command exists.
258 This function does not check to see if command REPLACEMENT exists
259 since gdb may not have gotten around to adding REPLACEMENT when
260 this function is called.
262 Returns a pointer to the deprecated command. */
264 struct cmd_list_element
*
265 deprecate_cmd (struct cmd_list_element
*cmd
, const char *replacement
)
267 cmd
->cmd_deprecated
= 1;
268 cmd
->deprecated_warn_user
= 1;
270 if (replacement
!= NULL
)
271 cmd
->replacement
= replacement
;
273 cmd
->replacement
= NULL
;
278 struct cmd_list_element
*
279 add_alias_cmd (const char *name
, cmd_list_element
*old
,
280 enum command_class theclass
, int abbrev_flag
,
281 struct cmd_list_element
**list
)
285 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
286 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
287 &prehook
, &prehookee
,
288 &posthook
, &posthookee
);
290 /* If this happens, it means a programmer error somewhere. */
291 gdb_assert (!aliases
&& !prehook
&& !prehookee
292 && !posthook
&& ! posthookee
);
296 struct cmd_list_element
*c
= add_cmd (name
, theclass
, old
->doc
, list
);
298 /* If OLD->DOC can be freed, we should make another copy. */
299 if (old
->doc_allocated
)
301 c
->doc
= xstrdup (old
->doc
);
302 c
->doc_allocated
= 1;
304 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
306 c
->function
= old
->function
;
307 c
->prefixlist
= old
->prefixlist
;
308 c
->prefixname
= old
->prefixname
;
309 c
->allow_unknown
= old
->allow_unknown
;
310 c
->abbrev_flag
= abbrev_flag
;
311 c
->cmd_pointer
= old
;
312 c
->alias_chain
= old
->aliases
;
315 set_cmd_prefix (c
, list
);
319 struct cmd_list_element
*
320 add_alias_cmd (const char *name
, const char *oldname
,
321 enum command_class theclass
, int abbrev_flag
,
322 struct cmd_list_element
**list
)
325 struct cmd_list_element
*old
;
328 old
= lookup_cmd (&tmp
, *list
, "", 1, 1);
330 return add_alias_cmd (name
, old
, theclass
, abbrev_flag
, list
);
334 /* Like add_cmd but adds an element for a command prefix: a name that
335 should be followed by a subcommand to be looked up in another
336 command list. PREFIXLIST should be the address of the variable
337 containing that list. */
339 struct cmd_list_element
*
340 add_prefix_cmd (const char *name
, enum command_class theclass
,
341 cmd_const_cfunc_ftype
*fun
,
342 const char *doc
, struct cmd_list_element
**prefixlist
,
343 const char *prefixname
, int allow_unknown
,
344 struct cmd_list_element
**list
)
346 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
347 struct cmd_list_element
*p
;
349 c
->prefixlist
= prefixlist
;
350 c
->prefixname
= prefixname
;
351 c
->allow_unknown
= allow_unknown
;
353 if (list
== &cmdlist
)
356 set_cmd_prefix (c
, list
);
358 /* Update the field 'prefix' of each cmd_list_element in *PREFIXLIST. */
359 for (p
= *prefixlist
; p
!= NULL
; p
= p
->next
)
365 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
367 struct cmd_list_element
*
368 add_abbrev_prefix_cmd (const char *name
, enum command_class theclass
,
369 cmd_const_cfunc_ftype
*fun
, const char *doc
,
370 struct cmd_list_element
**prefixlist
,
371 const char *prefixname
,
372 int allow_unknown
, struct cmd_list_element
**list
)
374 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
376 c
->prefixlist
= prefixlist
;
377 c
->prefixname
= prefixname
;
378 c
->allow_unknown
= allow_unknown
;
383 /* This is an empty "cfunc". */
385 not_just_help_class_command (const char *args
, int from_tty
)
389 /* This is an empty "sfunc". */
392 empty_sfunc (const char *args
, int from_tty
, struct cmd_list_element
*c
)
396 /* Add element named NAME to command list LIST (the list for set/show
397 or some sublist thereof).
398 TYPE is set_cmd or show_cmd.
399 CLASS is as in add_cmd.
400 VAR_TYPE is the kind of thing we are setting.
401 VAR is address of the variable being controlled by this command.
402 DOC is the documentation string. */
404 static struct cmd_list_element
*
405 add_set_or_show_cmd (const char *name
,
407 enum command_class theclass
,
411 struct cmd_list_element
**list
)
413 struct cmd_list_element
*c
= add_cmd (name
, theclass
, doc
, list
);
415 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
417 c
->var_type
= var_type
;
419 /* This needs to be something besides NULL so that this isn't
420 treated as a help class. */
421 set_cmd_sfunc (c
, empty_sfunc
);
425 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
426 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
427 setting. VAR is address of the variable being controlled by this
428 command. SET_FUNC and SHOW_FUNC are the callback functions (if
429 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
430 strings. PRINT the format string to print the value. SET_RESULT
431 and SHOW_RESULT, if not NULL, are set to the resulting command
435 add_setshow_cmd_full (const char *name
,
436 enum command_class theclass
,
437 var_types var_type
, void *var
,
438 const char *set_doc
, const char *show_doc
,
439 const char *help_doc
,
440 cmd_const_sfunc_ftype
*set_func
,
441 show_value_ftype
*show_func
,
442 struct cmd_list_element
**set_list
,
443 struct cmd_list_element
**show_list
,
444 struct cmd_list_element
**set_result
,
445 struct cmd_list_element
**show_result
)
447 struct cmd_list_element
*set
;
448 struct cmd_list_element
*show
;
452 if (help_doc
!= NULL
)
454 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
455 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
459 full_set_doc
= xstrdup (set_doc
);
460 full_show_doc
= xstrdup (show_doc
);
462 set
= add_set_or_show_cmd (name
, set_cmd
, theclass
, var_type
, var
,
463 full_set_doc
, set_list
);
464 set
->doc_allocated
= 1;
466 if (set_func
!= NULL
)
467 set_cmd_sfunc (set
, set_func
);
469 set_cmd_prefix (set
, set_list
);
471 show
= add_set_or_show_cmd (name
, show_cmd
, theclass
, var_type
, var
,
472 full_show_doc
, show_list
);
473 show
->doc_allocated
= 1;
474 show
->show_value_func
= show_func
;
476 if (set_result
!= NULL
)
478 if (show_result
!= NULL
)
482 /* Add element named NAME to command list LIST (the list for set or
483 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
484 of strings which may follow NAME. VAR is address of the variable
485 which will contain the matching string (from ENUMLIST). */
488 add_setshow_enum_cmd (const char *name
,
489 enum command_class theclass
,
490 const char *const *enumlist
,
493 const char *show_doc
,
494 const char *help_doc
,
495 cmd_const_sfunc_ftype
*set_func
,
496 show_value_ftype
*show_func
,
497 struct cmd_list_element
**set_list
,
498 struct cmd_list_element
**show_list
)
500 struct cmd_list_element
*c
;
502 add_setshow_cmd_full (name
, theclass
, var_enum
, var
,
503 set_doc
, show_doc
, help_doc
,
510 const char * const auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
512 /* Add an auto-boolean command named NAME to both the set and show
513 command list lists. CLASS is as in add_cmd. VAR is address of the
514 variable which will contain the value. DOC is the documentation
515 string. FUNC is the corresponding callback. */
517 add_setshow_auto_boolean_cmd (const char *name
,
518 enum command_class theclass
,
519 enum auto_boolean
*var
,
520 const char *set_doc
, 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_auto_boolean
, var
,
530 set_doc
, show_doc
, help_doc
,
534 c
->enums
= auto_boolean_enums
;
537 /* Add element named NAME to both the set and show command LISTs (the
538 list for set/show or some sublist thereof). CLASS is as in
539 add_cmd. VAR is address of the variable which will contain the
540 value. SET_DOC and SHOW_DOC are the documentation strings. */
542 add_setshow_boolean_cmd (const char *name
, enum command_class theclass
, int *var
,
543 const char *set_doc
, const char *show_doc
,
544 const char *help_doc
,
545 cmd_const_sfunc_ftype
*set_func
,
546 show_value_ftype
*show_func
,
547 struct cmd_list_element
**set_list
,
548 struct cmd_list_element
**show_list
)
550 static const char *boolean_enums
[] = { "on", "off", NULL
};
551 struct cmd_list_element
*c
;
553 add_setshow_cmd_full (name
, theclass
, var_boolean
, var
,
554 set_doc
, show_doc
, help_doc
,
558 c
->enums
= boolean_enums
;
561 /* Add element named NAME to both the set and show command LISTs (the
562 list for set/show or some sublist thereof). */
564 add_setshow_filename_cmd (const char *name
, enum command_class theclass
,
566 const char *set_doc
, const char *show_doc
,
567 const char *help_doc
,
568 cmd_const_sfunc_ftype
*set_func
,
569 show_value_ftype
*show_func
,
570 struct cmd_list_element
**set_list
,
571 struct cmd_list_element
**show_list
)
573 struct cmd_list_element
*set_result
;
575 add_setshow_cmd_full (name
, theclass
, var_filename
, var
,
576 set_doc
, show_doc
, help_doc
,
580 set_cmd_completer (set_result
, filename_completer
);
583 /* Add element named NAME to both the set and show command LISTs (the
584 list for set/show or some sublist thereof). */
586 add_setshow_string_cmd (const char *name
, enum command_class theclass
,
588 const char *set_doc
, const char *show_doc
,
589 const char *help_doc
,
590 cmd_const_sfunc_ftype
*set_func
,
591 show_value_ftype
*show_func
,
592 struct cmd_list_element
**set_list
,
593 struct cmd_list_element
**show_list
)
595 add_setshow_cmd_full (name
, theclass
, var_string
, var
,
596 set_doc
, show_doc
, help_doc
,
602 /* Add element named NAME to both the set and show command LISTs (the
603 list for set/show or some sublist thereof). */
604 struct cmd_list_element
*
605 add_setshow_string_noescape_cmd (const char *name
, enum command_class theclass
,
607 const char *set_doc
, const char *show_doc
,
608 const char *help_doc
,
609 cmd_const_sfunc_ftype
*set_func
,
610 show_value_ftype
*show_func
,
611 struct cmd_list_element
**set_list
,
612 struct cmd_list_element
**show_list
)
614 struct cmd_list_element
*set_cmd
;
616 add_setshow_cmd_full (name
, theclass
, var_string_noescape
, var
,
617 set_doc
, show_doc
, help_doc
,
624 /* Add element named NAME to both the set and show command LISTs (the
625 list for set/show or some sublist thereof). */
627 add_setshow_optional_filename_cmd (const char *name
, enum command_class theclass
,
629 const char *set_doc
, const char *show_doc
,
630 const char *help_doc
,
631 cmd_const_sfunc_ftype
*set_func
,
632 show_value_ftype
*show_func
,
633 struct cmd_list_element
**set_list
,
634 struct cmd_list_element
**show_list
)
636 struct cmd_list_element
*set_result
;
638 add_setshow_cmd_full (name
, theclass
, var_optional_filename
, var
,
639 set_doc
, show_doc
, help_doc
,
644 set_cmd_completer (set_result
, filename_completer
);
648 /* Completes on literal "unlimited". Used by integer commands that
649 support a special "unlimited" value. */
652 integer_unlimited_completer (struct cmd_list_element
*ignore
,
653 completion_tracker
&tracker
,
654 const char *text
, const char *word
)
656 static const char * const keywords
[] =
662 complete_on_enum (tracker
, keywords
, text
, word
);
665 /* Add element named NAME to both the set and show command LISTs (the
666 list for set/show or some sublist thereof). CLASS is as in
667 add_cmd. VAR is address of the variable which will contain the
668 value. SET_DOC and SHOW_DOC are the documentation strings. This
669 function is only used in Python API. Please don't use it elsewhere. */
671 add_setshow_integer_cmd (const char *name
, enum command_class theclass
,
673 const char *set_doc
, const char *show_doc
,
674 const char *help_doc
,
675 cmd_const_sfunc_ftype
*set_func
,
676 show_value_ftype
*show_func
,
677 struct cmd_list_element
**set_list
,
678 struct cmd_list_element
**show_list
)
680 struct cmd_list_element
*set
;
682 add_setshow_cmd_full (name
, theclass
, var_integer
, var
,
683 set_doc
, show_doc
, help_doc
,
688 set_cmd_completer (set
, integer_unlimited_completer
);
691 /* Add element named NAME to both the set and show command LISTs (the
692 list for set/show or some sublist thereof). CLASS is as in
693 add_cmd. VAR is address of the variable which will contain the
694 value. SET_DOC and SHOW_DOC are the documentation strings. */
696 add_setshow_uinteger_cmd (const char *name
, enum command_class theclass
,
698 const char *set_doc
, const char *show_doc
,
699 const char *help_doc
,
700 cmd_const_sfunc_ftype
*set_func
,
701 show_value_ftype
*show_func
,
702 struct cmd_list_element
**set_list
,
703 struct cmd_list_element
**show_list
)
705 struct cmd_list_element
*set
;
707 add_setshow_cmd_full (name
, theclass
, var_uinteger
, var
,
708 set_doc
, show_doc
, help_doc
,
713 set_cmd_completer (set
, integer_unlimited_completer
);
716 /* Add element named NAME to both the set and show command LISTs (the
717 list for set/show or some sublist thereof). CLASS is as in
718 add_cmd. VAR is address of the variable which will contain the
719 value. SET_DOC and SHOW_DOC are the documentation strings. */
721 add_setshow_zinteger_cmd (const char *name
, enum command_class theclass
,
723 const char *set_doc
, const char *show_doc
,
724 const char *help_doc
,
725 cmd_const_sfunc_ftype
*set_func
,
726 show_value_ftype
*show_func
,
727 struct cmd_list_element
**set_list
,
728 struct cmd_list_element
**show_list
)
730 add_setshow_cmd_full (name
, theclass
, var_zinteger
, var
,
731 set_doc
, show_doc
, help_doc
,
738 add_setshow_zuinteger_unlimited_cmd (const char *name
,
739 enum command_class theclass
,
742 const char *show_doc
,
743 const char *help_doc
,
744 cmd_const_sfunc_ftype
*set_func
,
745 show_value_ftype
*show_func
,
746 struct cmd_list_element
**set_list
,
747 struct cmd_list_element
**show_list
)
749 struct cmd_list_element
*set
;
751 add_setshow_cmd_full (name
, theclass
, var_zuinteger_unlimited
, var
,
752 set_doc
, show_doc
, help_doc
,
757 set_cmd_completer (set
, integer_unlimited_completer
);
760 /* Add element named NAME to both the set and show command LISTs (the
761 list for set/show or some sublist thereof). CLASS is as in
762 add_cmd. VAR is address of the variable which will contain the
763 value. SET_DOC and SHOW_DOC are the documentation strings. */
765 add_setshow_zuinteger_cmd (const char *name
, enum command_class theclass
,
767 const char *set_doc
, const char *show_doc
,
768 const char *help_doc
,
769 cmd_const_sfunc_ftype
*set_func
,
770 show_value_ftype
*show_func
,
771 struct cmd_list_element
**set_list
,
772 struct cmd_list_element
**show_list
)
774 add_setshow_cmd_full (name
, theclass
, var_zuinteger
, var
,
775 set_doc
, show_doc
, help_doc
,
781 /* Remove the command named NAME from the command list. Return the
782 list commands which were aliased to the deleted command. If the
783 command had no aliases, return NULL. The various *HOOKs are set to
784 the pre- and post-hook commands for the deleted command. If the
785 command does not have a hook, the corresponding out parameter is
788 static struct cmd_list_element
*
789 delete_cmd (const char *name
, struct cmd_list_element
**list
,
790 struct cmd_list_element
**prehook
,
791 struct cmd_list_element
**prehookee
,
792 struct cmd_list_element
**posthook
,
793 struct cmd_list_element
**posthookee
)
795 struct cmd_list_element
*iter
;
796 struct cmd_list_element
**previous_chain_ptr
;
797 struct cmd_list_element
*aliases
= NULL
;
803 previous_chain_ptr
= list
;
805 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
807 if (strcmp (iter
->name
, name
) == 0)
810 iter
->destroyer (iter
, iter
->context
);
811 if (iter
->hookee_pre
)
812 iter
->hookee_pre
->hook_pre
= 0;
813 *prehook
= iter
->hook_pre
;
814 *prehookee
= iter
->hookee_pre
;
815 if (iter
->hookee_post
)
816 iter
->hookee_post
->hook_post
= 0;
817 *posthook
= iter
->hook_post
;
818 *posthookee
= iter
->hookee_post
;
820 /* Update the link. */
821 *previous_chain_ptr
= iter
->next
;
823 aliases
= iter
->aliases
;
825 /* If this command was an alias, remove it from the list of
827 if (iter
->cmd_pointer
)
829 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
830 struct cmd_list_element
*a
= *prevp
;
834 prevp
= &a
->alias_chain
;
837 *prevp
= iter
->alias_chain
;
842 /* We won't see another command with the same name. */
846 previous_chain_ptr
= &iter
->next
;
852 /* Shorthands to the commands above. */
854 /* Add an element to the list of info subcommands. */
856 struct cmd_list_element
*
857 add_info (const char *name
, cmd_const_cfunc_ftype
*fun
, const char *doc
)
859 return add_cmd (name
, class_info
, fun
, doc
, &infolist
);
862 /* Add an alias to the list of info subcommands. */
864 struct cmd_list_element
*
865 add_info_alias (const char *name
, const char *oldname
, int abbrev_flag
)
867 return add_alias_cmd (name
, oldname
, class_run
, abbrev_flag
, &infolist
);
870 /* Add an element to the list of commands. */
872 struct cmd_list_element
*
873 add_com (const char *name
, enum command_class theclass
,
874 cmd_const_cfunc_ftype
*fun
,
877 return add_cmd (name
, theclass
, fun
, doc
, &cmdlist
);
880 /* Add an alias or abbreviation command to the list of commands. */
882 struct cmd_list_element
*
883 add_com_alias (const char *name
, const char *oldname
, enum command_class theclass
,
886 return add_alias_cmd (name
, oldname
, theclass
, abbrev_flag
, &cmdlist
);
889 /* Add an element with a suppress notification to the list of commands. */
891 struct cmd_list_element
*
892 add_com_suppress_notification (const char *name
, enum command_class theclass
,
893 cmd_const_cfunc_ftype
*fun
, const char *doc
,
894 int *suppress_notification
)
896 struct cmd_list_element
*element
;
898 element
= add_cmd (name
, theclass
, fun
, doc
, &cmdlist
);
899 element
->suppress_notification
= suppress_notification
;
904 /* Recursively walk the commandlist structures, and print out the
905 documentation of commands that match our regex in either their
906 name, or their documentation.
909 apropos_cmd (struct ui_file
*stream
,
910 struct cmd_list_element
*commandlist
,
911 compiled_regex
®ex
, const char *prefix
)
913 struct cmd_list_element
*c
;
916 /* Walk through the commands. */
917 for (c
=commandlist
;c
;c
=c
->next
)
919 returnvalue
= -1; /* Needed to avoid double printing. */
922 size_t name_len
= strlen (c
->name
);
924 /* Try to match against the name. */
925 returnvalue
= regex
.search (c
->name
, name_len
, 0, name_len
, NULL
);
926 if (returnvalue
>= 0)
928 print_help_for_command (c
, prefix
,
929 0 /* don't recurse */, stream
);
932 if (c
->doc
!= NULL
&& returnvalue
< 0)
934 size_t doc_len
= strlen (c
->doc
);
936 /* Try to match against documentation. */
937 if (regex
.search (c
->doc
, doc_len
, 0, doc_len
, NULL
) >= 0)
939 print_help_for_command (c
, prefix
,
940 0 /* don't recurse */, stream
);
943 /* Check if this command has subcommands and is not an
944 abbreviation. We skip listing subcommands of abbreviations
945 in order to avoid duplicates in the output. */
946 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
948 /* Recursively call ourselves on the subcommand list,
949 passing the right prefix in. */
950 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
955 /* This command really has to deal with two things:
956 1) I want documentation on *this string* (usually called by
959 2) I want documentation on *this list* (usually called by giving a
960 command that requires subcommands. Also called by saying just
963 I am going to split this into two seperate comamnds, help_cmd and
967 help_cmd (const char *command
, struct ui_file
*stream
)
969 struct cmd_list_element
*c
;
973 help_list (cmdlist
, "", all_classes
, stream
);
977 if (strcmp (command
, "all") == 0)
983 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
988 /* There are three cases here.
989 If c->prefixlist is nonzero, we have a prefix command.
990 Print its documentation, then list its subcommands.
992 If c->func is non NULL, we really have a command. Print its
993 documentation and return.
995 If c->func is NULL, we have a class name. Print its
996 documentation (as if it were a command) and then set class to the
997 number of this class so that the commands in the class will be
1000 fputs_filtered (c
->doc
, stream
);
1001 fputs_filtered ("\n", stream
);
1003 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
1005 fprintf_filtered (stream
, "\n");
1007 /* If this is a prefix command, print it's subcommands. */
1009 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
1011 /* If this is a class name, print all of the commands in the class. */
1012 if (c
->func
== NULL
)
1013 help_list (cmdlist
, "", c
->theclass
, stream
);
1015 if (c
->hook_pre
|| c
->hook_post
)
1016 fprintf_filtered (stream
,
1017 "\nThis command has a hook (or hooks) defined:\n");
1020 fprintf_filtered (stream
,
1021 "\tThis command is run after : %s (pre hook)\n",
1024 fprintf_filtered (stream
,
1025 "\tThis command is run before : %s (post hook)\n",
1026 c
->hook_post
->name
);
1030 * Get a specific kind of help on a command list.
1033 * CMDTYPE is the prefix to use in the title string.
1034 * CLASS is the class with which to list the nodes of this list (see
1035 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
1036 * everything, ALL_CLASSES for just classes, and non-negative for only things
1037 * in a specific class.
1038 * and STREAM is the output stream on which to print things.
1039 * If you call this routine with a class >= 0, it recurses.
1042 help_list (struct cmd_list_element
*list
, const char *cmdtype
,
1043 enum command_class theclass
, struct ui_file
*stream
)
1046 char *cmdtype1
, *cmdtype2
;
1048 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
1050 len
= strlen (cmdtype
);
1051 cmdtype1
= (char *) alloca (len
+ 1);
1053 cmdtype2
= (char *) alloca (len
+ 4);
1058 memcpy (cmdtype1
+ 1, cmdtype
, len
- 1);
1060 memcpy (cmdtype2
, cmdtype
, len
- 1);
1061 strcpy (cmdtype2
+ len
- 1, " sub");
1064 if (theclass
== all_classes
)
1065 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
1067 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
1069 help_cmd_list (list
, theclass
, cmdtype
, (int) theclass
>= 0, stream
);
1071 if (theclass
== all_classes
)
1073 fprintf_filtered (stream
, "\n\
1074 Type \"help%s\" followed by a class name for a list of commands in ",
1077 fprintf_filtered (stream
, "that class.");
1079 fprintf_filtered (stream
, "\n\
1080 Type \"help all\" for the list of all commands.");
1083 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
1084 cmdtype1
, cmdtype2
);
1086 fputs_filtered ("for ", stream
);
1088 fputs_filtered ("full ", stream
);
1090 fputs_filtered ("documentation.\n", stream
);
1091 fputs_filtered ("Type \"apropos word\" to search "
1092 "for commands related to \"word\".\n", stream
);
1093 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
1098 help_all (struct ui_file
*stream
)
1100 struct cmd_list_element
*c
;
1101 int seen_unclassified
= 0;
1103 for (c
= cmdlist
; c
; c
= c
->next
)
1107 /* If this is a class name, print all of the commands in the
1110 if (c
->func
== NULL
)
1112 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
1113 help_cmd_list (cmdlist
, c
->theclass
, "", 1, stream
);
1117 /* While it's expected that all commands are in some class,
1118 as a safety measure, we'll print commands outside of any
1119 class at the end. */
1121 for (c
= cmdlist
; c
; c
= c
->next
)
1126 if (c
->theclass
== no_class
)
1128 if (!seen_unclassified
)
1130 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
1131 seen_unclassified
= 1;
1133 print_help_for_command (c
, "", 1, stream
);
1139 /* Print only the first line of STR on STREAM. */
1141 print_doc_line (struct ui_file
*stream
, const char *str
)
1143 static char *line_buffer
= 0;
1144 static int line_size
;
1150 line_buffer
= (char *) xmalloc (line_size
);
1153 /* Keep printing '.' or ',' not followed by a whitespace for embedded strings
1156 while (*p
&& *p
!= '\n'
1157 && ((*p
!= '.' && *p
!= ',') || (p
[1] && !isspace (p
[1]))))
1159 if (p
- str
> line_size
- 1)
1161 line_size
= p
- str
+ 1;
1162 xfree (line_buffer
);
1163 line_buffer
= (char *) xmalloc (line_size
);
1165 strncpy (line_buffer
, str
, p
- str
);
1166 line_buffer
[p
- str
] = '\0';
1167 if (islower (line_buffer
[0]))
1168 line_buffer
[0] = toupper (line_buffer
[0]);
1169 fputs_filtered (line_buffer
, stream
);
1172 /* Print one-line help for command C.
1173 If RECURSE is non-zero, also print one-line descriptions
1174 of all prefixed subcommands. */
1176 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
1177 int recurse
, struct ui_file
*stream
)
1179 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1180 print_doc_line (stream
, c
->doc
);
1181 fputs_filtered ("\n", stream
);
1184 && c
->prefixlist
!= 0
1185 && c
->abbrev_flag
== 0)
1186 /* Subcommands of a prefix command typically have 'all_commands'
1187 as class. If we pass CLASS to recursive invocation,
1188 most often we won't see anything. */
1189 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1193 * Implement a help command on command list LIST.
1194 * RECURSE should be non-zero if this should be done recursively on
1195 * all sublists of LIST.
1196 * PREFIX is the prefix to print before each command name.
1197 * STREAM is the stream upon which the output should be written.
1198 * THECLASS should be:
1199 * A non-negative class number to list only commands in that
1201 * ALL_COMMANDS to list all commands in list.
1202 * ALL_CLASSES to list all classes in list.
1204 * Note that RECURSE will be active on *all* sublists, not just the
1205 * ones selected by the criteria above (ie. the selection mechanism
1206 * is at the low level, not the high-level).
1209 help_cmd_list (struct cmd_list_element
*list
, enum command_class theclass
,
1210 const char *prefix
, int recurse
, struct ui_file
*stream
)
1212 struct cmd_list_element
*c
;
1214 for (c
= list
; c
; c
= c
->next
)
1216 if (c
->abbrev_flag
== 0
1217 && !c
->cmd_deprecated
1218 && (theclass
== all_commands
1219 || (theclass
== all_classes
&& c
->func
== NULL
)
1220 || (theclass
== c
->theclass
&& c
->func
!= NULL
)))
1222 print_help_for_command (c
, prefix
, recurse
, stream
);
1224 else if (c
->abbrev_flag
== 0
1226 && !c
->cmd_deprecated
1227 && theclass
== class_user
&& c
->prefixlist
!= NULL
)
1228 /* User-defined commands may be subcommands. */
1229 help_cmd_list (*c
->prefixlist
, theclass
, c
->prefixname
,
1235 /* Search the input clist for 'command'. Return the command if
1236 found (or NULL if not), and return the number of commands
1239 static struct cmd_list_element
*
1240 find_cmd (const char *command
, int len
, struct cmd_list_element
*clist
,
1241 int ignore_help_classes
, int *nfound
)
1243 struct cmd_list_element
*found
, *c
;
1247 for (c
= clist
; c
; c
= c
->next
)
1248 if (!strncmp (command
, c
->name
, len
)
1249 && (!ignore_help_classes
|| c
->func
))
1253 if (c
->name
[len
] == '\0')
1262 /* Return the length of command name in TEXT. */
1265 find_command_name_length (const char *text
)
1267 const char *p
= text
;
1269 /* Treating underscores as part of command words is important
1270 so that "set args_foo()" doesn't get interpreted as
1271 "set args _foo()". */
1272 /* Some characters are only used for TUI specific commands.
1273 However, they are always allowed for the sake of consistency.
1275 Note that this is larger than the character set allowed when
1276 creating user-defined commands. */
1278 /* Recognize '!' as a single character command so that, e.g., "!ls"
1279 works as expected. */
1283 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1284 /* Characters used by TUI specific commands. */
1285 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')
1291 /* Return TRUE if NAME is a valid user-defined command name.
1292 This is a stricter subset of all gdb commands,
1293 see find_command_name_length. */
1296 valid_user_defined_cmd_name_p (const char *name
)
1303 /* Alas "42" is a legitimate user-defined command.
1304 In the interests of not breaking anything we preserve that. */
1306 for (p
= name
; *p
!= '\0'; ++p
)
1319 /* This routine takes a line of TEXT and a CLIST in which to start the
1320 lookup. When it returns it will have incremented the text pointer past
1321 the section of text it matched, set *RESULT_LIST to point to the list in
1322 which the last word was matched, and will return a pointer to the cmd
1323 list element which the text matches. It will return NULL if no match at
1324 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1325 matches are possible; in this case *RESULT_LIST will be set to point to
1326 the list in which there are ambiguous choices (and *TEXT will be set to
1327 the ambiguous text string).
1329 If the located command was an abbreviation, this routine returns the base
1330 command of the abbreviation.
1332 It does no error reporting whatsoever; control will always return
1333 to the superior routine.
1335 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1336 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1337 if no prefix command was ever found. For example, in the case of "info a",
1338 "info" matches without ambiguity, but "a" could be "args" or "address", so
1339 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1340 RESULT_LIST should not be interpreted as a pointer to the beginning of a
1341 list; it simply points to a specific command. In the case of an ambiguous
1342 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1343 "info t" can be "info types" or "info target"; upon return *TEXT has been
1344 advanced past "info ").
1346 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1347 affect the operation).
1349 This routine does *not* modify the text pointed to by TEXT.
1351 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1352 are actually help classes rather than commands (i.e. the function field of
1353 the struct cmd_list_element is NULL). */
1355 struct cmd_list_element
*
1356 lookup_cmd_1 (const char **text
, struct cmd_list_element
*clist
,
1357 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1361 struct cmd_list_element
*found
, *c
;
1362 const char *line
= *text
;
1364 while (**text
== ' ' || **text
== '\t')
1367 /* Identify the name of the command. */
1368 len
= find_command_name_length (*text
);
1370 /* If nothing but whitespace, return 0. */
1374 /* *text and p now bracket the first command word to lookup (and
1375 it's length is len). We copy this into a local temporary. */
1378 command
= (char *) alloca (len
+ 1);
1379 memcpy (command
, *text
, len
);
1380 command
[len
] = '\0';
1385 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1387 /* If nothing matches, we have a simple failure. */
1393 if (result_list
!= NULL
)
1394 /* Will be modified in calling routine
1395 if we know what the prefix command is. */
1397 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1400 /* We've matched something on this list. Move text pointer forward. */
1404 if (found
->cmd_pointer
)
1406 /* We drop the alias (abbreviation) in favor of the command it
1407 is pointing to. If the alias is deprecated, though, we need to
1408 warn the user about it before we drop it. Note that while we
1409 are warning about the alias, we may also warn about the command
1410 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1413 if (found
->deprecated_warn_user
)
1414 deprecated_cmd_warning (line
);
1415 found
= found
->cmd_pointer
;
1417 /* If we found a prefix command, keep looking. */
1419 if (found
->prefixlist
)
1421 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1422 ignore_help_classes
);
1425 /* Didn't find anything; this is as far as we got. */
1426 if (result_list
!= NULL
)
1427 *result_list
= clist
;
1430 else if (c
== CMD_LIST_AMBIGUOUS
)
1432 /* We've gotten this far properly, but the next step is
1433 ambiguous. We need to set the result list to the best
1434 we've found (if an inferior hasn't already set it). */
1435 if (result_list
!= NULL
)
1437 /* This used to say *result_list = *found->prefixlist.
1438 If that was correct, need to modify the documentation
1439 at the top of this function to clarify what is
1440 supposed to be going on. */
1441 *result_list
= found
;
1452 if (result_list
!= NULL
)
1453 *result_list
= clist
;
1458 /* All this hair to move the space to the front of cmdtype */
1461 undef_cmd_error (const char *cmdtype
, const char *q
)
1463 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1466 *cmdtype
? " " : "",
1467 (int) strlen (cmdtype
) - 1,
1471 /* Look up the contents of *LINE as a command in the command list LIST.
1472 LIST is a chain of struct cmd_list_element's.
1473 If it is found, return the struct cmd_list_element for that command
1474 and update *LINE to point after the command name, at the first argument.
1475 If not found, call error if ALLOW_UNKNOWN is zero
1476 otherwise (or if error returns) return zero.
1477 Call error if specified command is ambiguous,
1478 unless ALLOW_UNKNOWN is negative.
1479 CMDTYPE precedes the word "command" in the error message.
1481 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1482 elements which are actually help classes rather than commands (i.e.
1483 the function field of the struct cmd_list_element is 0). */
1485 struct cmd_list_element
*
1486 lookup_cmd (const char **line
, struct cmd_list_element
*list
,
1487 const char *cmdtype
,
1488 int allow_unknown
, int ignore_help_classes
)
1490 struct cmd_list_element
*last_list
= 0;
1491 struct cmd_list_element
*c
;
1493 /* Note: Do not remove trailing whitespace here because this
1494 would be wrong for complete_command. Jim Kingdon */
1497 error (_("Lack of needed %scommand"), cmdtype
);
1499 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1506 int len
= find_command_name_length (*line
);
1508 q
= (char *) alloca (len
+ 1);
1509 strncpy (q
, *line
, len
);
1511 undef_cmd_error (cmdtype
, q
);
1516 else if (c
== CMD_LIST_AMBIGUOUS
)
1518 /* Ambigous. Local values should be off prefixlist or called
1520 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1522 const char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1523 struct cmd_list_element
*local_list
=
1524 (last_list
? *(last_list
->prefixlist
) : list
);
1526 if (local_allow_unknown
< 0)
1529 return last_list
; /* Found something. */
1531 return 0; /* Found nothing. */
1535 /* Report as error. */
1540 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1541 && (*line
)[amb_len
] != '\t');
1546 for (c
= local_list
; c
; c
= c
->next
)
1547 if (!strncmp (*line
, c
->name
, amb_len
))
1549 if (strlen (ambbuf
) + strlen (c
->name
) + 6
1550 < (int) sizeof ambbuf
)
1552 if (strlen (ambbuf
))
1553 strcat (ambbuf
, ", ");
1554 strcat (ambbuf
, c
->name
);
1558 strcat (ambbuf
, "..");
1562 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1564 return 0; /* lint */
1569 if (c
->type
== set_cmd
&& **line
!= '\0' && !isspace (**line
))
1570 error (_("Argument must be preceded by space."));
1572 /* We've got something. It may still not be what the caller
1573 wants (if this command *needs* a subcommand). */
1574 while (**line
== ' ' || **line
== '\t')
1577 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1578 undef_cmd_error (c
->prefixname
, *line
);
1580 /* Seems to be what he wants. Return it. */
1586 /* We are here presumably because an alias or command in TEXT is
1587 deprecated and a warning message should be generated. This
1588 function decodes TEXT and potentially generates a warning message
1591 Example for 'set endian big' which has a fictitious alias 'seb'.
1593 If alias wasn't used in TEXT, and the command is deprecated:
1594 "warning: 'set endian big' is deprecated."
1596 If alias was used, and only the alias is deprecated:
1597 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1599 If alias was used and command is deprecated (regardless of whether
1600 the alias itself is deprecated:
1602 "warning: 'set endian big' (seb) is deprecated."
1604 After the message has been sent, clear the appropriate flags in the
1605 command and/or the alias so the user is no longer bothered.
1609 deprecated_cmd_warning (const char *text
)
1611 struct cmd_list_element
*alias
= NULL
;
1612 struct cmd_list_element
*prefix_cmd
= NULL
;
1613 struct cmd_list_element
*cmd
= NULL
;
1615 if (!lookup_cmd_composition (text
, &alias
, &prefix_cmd
, &cmd
))
1616 /* Return if text doesn't evaluate to a command. */
1619 if (!((alias
? alias
->deprecated_warn_user
: 0)
1620 || cmd
->deprecated_warn_user
) )
1621 /* Return if nothing is deprecated. */
1624 printf_filtered ("Warning:");
1626 if (alias
&& !cmd
->cmd_deprecated
)
1627 printf_filtered (" '%s', an alias for the", alias
->name
);
1629 printf_filtered (" command '");
1632 printf_filtered ("%s", prefix_cmd
->prefixname
);
1634 printf_filtered ("%s", cmd
->name
);
1636 if (alias
&& cmd
->cmd_deprecated
)
1637 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1639 printf_filtered ("' is deprecated.\n");
1642 /* If it is only the alias that is deprecated, we want to indicate
1643 the new alias, otherwise we'll indicate the new command. */
1645 if (alias
&& !cmd
->cmd_deprecated
)
1647 if (alias
->replacement
)
1648 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1650 printf_filtered ("No alternative known.\n\n");
1654 if (cmd
->replacement
)
1655 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1657 printf_filtered ("No alternative known.\n\n");
1660 /* We've warned you, now we'll keep quiet. */
1662 alias
->deprecated_warn_user
= 0;
1664 cmd
->deprecated_warn_user
= 0;
1668 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1669 Return 1 on success, 0 on failure.
1671 If LINE refers to an alias, *alias will point to that alias.
1673 If LINE is a postfix command (i.e. one that is preceded by a prefix
1674 command) set *prefix_cmd.
1676 Set *cmd to point to the command LINE indicates.
1678 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1679 exist, they are NULL when we return.
1683 lookup_cmd_composition (const char *text
,
1684 struct cmd_list_element
**alias
,
1685 struct cmd_list_element
**prefix_cmd
,
1686 struct cmd_list_element
**cmd
)
1690 struct cmd_list_element
*cur_list
;
1691 struct cmd_list_element
*prev_cmd
;
1701 /* Go through as many command lists as we need to,
1702 to find the command TEXT refers to. */
1706 while (*text
== ' ' || *text
== '\t')
1709 /* Identify the name of the command. */
1710 len
= find_command_name_length (text
);
1712 /* If nothing but whitespace, return. */
1716 /* Text is the start of the first command word to lookup (and
1717 it's length is len). We copy this into a local temporary. */
1719 command
= (char *) alloca (len
+ 1);
1720 memcpy (command
, text
, len
);
1721 command
[len
] = '\0';
1726 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1728 if (*cmd
== CMD_LIST_AMBIGUOUS
)
1730 return 0; /* ambiguous */
1734 return 0; /* nothing found */
1737 if ((*cmd
)->cmd_pointer
)
1739 /* cmd was actually an alias, we note that an alias was
1740 used (by assigning *alais) and we set *cmd. */
1742 *cmd
= (*cmd
)->cmd_pointer
;
1744 *prefix_cmd
= prev_cmd
;
1746 if ((*cmd
)->prefixlist
)
1747 cur_list
= *(*cmd
)->prefixlist
;
1755 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1757 /* Return a vector of char pointers which point to the different
1758 possible completions in LIST of TEXT.
1760 WORD points in the same buffer as TEXT, and completions should be
1761 returned relative to this position. For example, suppose TEXT is
1762 "foo" and we want to complete to "foobar". If WORD is "oo", return
1763 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1766 complete_on_cmdlist (struct cmd_list_element
*list
,
1767 completion_tracker
&tracker
,
1768 const char *text
, const char *word
,
1769 int ignore_help_classes
)
1771 struct cmd_list_element
*ptr
;
1772 int textlen
= strlen (text
);
1774 int saw_deprecated_match
= 0;
1776 /* We do one or two passes. In the first pass, we skip deprecated
1777 commands. If we see no matching commands in the first pass, and
1778 if we did happen to see a matching deprecated command, we do
1779 another loop to collect those. */
1780 for (pass
= 0; pass
< 2; ++pass
)
1782 bool got_matches
= false;
1784 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1785 if (!strncmp (ptr
->name
, text
, textlen
)
1786 && !ptr
->abbrev_flag
1787 && (!ignore_help_classes
|| ptr
->func
1788 || ptr
->prefixlist
))
1792 if (ptr
->cmd_deprecated
)
1794 saw_deprecated_match
= 1;
1799 tracker
.add_completion
1800 (make_completion_match_str (ptr
->name
, text
, word
));
1807 /* If we saw no matching deprecated commands in the first pass,
1809 if (!saw_deprecated_match
)
1814 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1816 /* Add the different possible completions in ENUMLIST of TEXT.
1818 WORD points in the same buffer as TEXT, and completions should be
1819 returned relative to this position. For example, suppose TEXT is "foo"
1820 and we want to complete to "foobar". If WORD is "oo", return
1821 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1824 complete_on_enum (completion_tracker
&tracker
,
1825 const char *const *enumlist
,
1826 const char *text
, const char *word
)
1828 int textlen
= strlen (text
);
1832 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1833 if (strncmp (name
, text
, textlen
) == 0)
1834 tracker
.add_completion (make_completion_match_str (name
, text
, word
));
1838 /* Check function pointer. */
1840 cmd_func_p (struct cmd_list_element
*cmd
)
1842 return (cmd
->func
!= NULL
);
1846 /* Call the command function. */
1848 cmd_func (struct cmd_list_element
*cmd
, const char *args
, int from_tty
)
1850 if (cmd_func_p (cmd
))
1852 gdb::optional
<scoped_restore_tmpl
<int>> restore_suppress
;
1854 if (cmd
->suppress_notification
!= NULL
)
1855 restore_suppress
.emplace (cmd
->suppress_notification
, 1);
1857 (*cmd
->func
) (cmd
, args
, from_tty
);
1860 error (_("Invalid command"));
1864 cli_user_command_p (struct cmd_list_element
*cmd
)
1866 return (cmd
->theclass
== class_user
1867 && (cmd
->func
== do_const_cfunc
|| cmd
->func
== do_sfunc
));