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_cfunc (struct cmd_list_element
*c
, char *args
, int from_tty
)
106 c
->function
.cfunc (args
, from_tty
);
110 set_cmd_cfunc (struct cmd_list_element
*cmd
, cmd_cfunc_ftype
*cfunc
)
115 cmd
->func
= do_cfunc
;
116 cmd
->function
.cfunc
= cfunc
;
120 do_const_cfunc (struct cmd_list_element
*c
, char *args
, int from_tty
)
122 c
->function
.const_cfunc (args
, from_tty
);
126 set_cmd_cfunc (struct cmd_list_element
*cmd
, cmd_const_cfunc_ftype
*cfunc
)
131 cmd
->func
= do_const_cfunc
;
132 cmd
->function
.const_cfunc
= cfunc
;
136 do_sfunc (struct cmd_list_element
*c
, char *args
, int from_tty
)
138 c
->function
.sfunc (args
, from_tty
, c
);
142 set_cmd_sfunc (struct cmd_list_element
*cmd
, cmd_sfunc_ftype
*sfunc
)
147 cmd
->func
= do_sfunc
;
148 cmd
->function
.sfunc
= sfunc
;
152 cmd_cfunc_eq (struct cmd_list_element
*cmd
, cmd_cfunc_ftype
*cfunc
)
154 return cmd
->func
== do_cfunc
&& cmd
->function
.cfunc
== cfunc
;
158 cmd_cfunc_eq (struct cmd_list_element
*cmd
, cmd_const_cfunc_ftype
*cfunc
)
160 return cmd
->func
== do_const_cfunc
&& cmd
->function
.const_cfunc
== cfunc
;
164 set_cmd_context (struct cmd_list_element
*cmd
, void *context
)
166 cmd
->context
= context
;
170 get_cmd_context (struct cmd_list_element
*cmd
)
176 cmd_type (struct cmd_list_element
*cmd
)
182 set_cmd_completer (struct cmd_list_element
*cmd
, completer_ftype
*completer
)
184 cmd
->completer
= completer
; /* Ok. */
187 /* See definition in commands.h. */
190 set_cmd_completer_handle_brkchars (struct cmd_list_element
*cmd
,
191 completer_handle_brkchars_ftype
*func
)
193 cmd
->completer_handle_brkchars
= func
;
196 /* Add element named NAME.
197 Space for NAME and DOC must be allocated by the caller.
198 CLASS is the top level category into which commands are broken down
200 FUN should be the function to execute the command;
201 it will get a character string as argument, with leading
202 and trailing blanks already eliminated.
204 DOC is a documentation string for the command.
205 Its first line should be a complete sentence.
206 It should start with ? for a command that is an abbreviation
207 or with * for a command that most users don't need to know about.
209 Add this command to command list *LIST.
211 Returns a pointer to the added command (not necessarily the head
214 static struct cmd_list_element
*
215 do_add_cmd (const char *name
, enum command_class theclass
,
216 const char *doc
, struct cmd_list_element
**list
)
218 struct cmd_list_element
*c
= XNEW (struct cmd_list_element
);
219 struct cmd_list_element
*p
, *iter
;
221 /* Turn each alias of the old command into an alias of the new
223 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
224 &c
->hook_post
, &c
->hookee_post
);
225 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
226 iter
->cmd_pointer
= c
;
228 c
->hook_pre
->hookee_pre
= c
;
230 c
->hookee_pre
->hook_pre
= c
;
232 c
->hook_post
->hookee_post
= c
;
234 c
->hookee_post
->hook_post
= c
;
236 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
244 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
253 c
->theclass
= theclass
;
254 set_cmd_context (c
, NULL
);
256 c
->cmd_deprecated
= 0;
257 c
->deprecated_warn_user
= 0;
258 c
->malloced_replacement
= 0;
259 c
->doc_allocated
= 0;
260 c
->replacement
= NULL
;
261 c
->pre_show_hook
= NULL
;
263 c
->prefixlist
= NULL
;
264 c
->prefixname
= NULL
;
265 c
->allow_unknown
= 0;
268 set_cmd_completer (c
, symbol_completer
);
269 c
->completer_handle_brkchars
= NULL
;
271 c
->type
= not_set_cmd
;
273 c
->var_type
= var_boolean
;
275 c
->user_commands
= NULL
;
276 c
->cmd_pointer
= NULL
;
277 c
->alias_chain
= NULL
;
278 c
->suppress_notification
= NULL
;
283 struct cmd_list_element
*
284 add_cmd (const char *name
, enum command_class theclass
, cmd_cfunc_ftype
*fun
,
285 const char *doc
, struct cmd_list_element
**list
)
287 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
288 set_cmd_cfunc (result
, fun
);
292 struct cmd_list_element
*
293 add_cmd (const char *name
, enum command_class theclass
,
294 const char *doc
, struct cmd_list_element
**list
)
296 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
298 result
->function
.cfunc
= NULL
; /* Ok. */
302 struct cmd_list_element
*
303 add_cmd (const char *name
, enum command_class theclass
,
304 cmd_const_cfunc_ftype
*fun
,
305 const char *doc
, struct cmd_list_element
**list
)
307 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
308 set_cmd_cfunc (result
, fun
);
312 /* Deprecates a command CMD.
313 REPLACEMENT is the name of the command which should be used in
314 place of this command, or NULL if no such command exists.
316 This function does not check to see if command REPLACEMENT exists
317 since gdb may not have gotten around to adding REPLACEMENT when
318 this function is called.
320 Returns a pointer to the deprecated command. */
322 struct cmd_list_element
*
323 deprecate_cmd (struct cmd_list_element
*cmd
, const char *replacement
)
325 cmd
->cmd_deprecated
= 1;
326 cmd
->deprecated_warn_user
= 1;
328 if (replacement
!= NULL
)
329 cmd
->replacement
= replacement
;
331 cmd
->replacement
= NULL
;
336 struct cmd_list_element
*
337 add_alias_cmd (const char *name
, cmd_list_element
*old
,
338 enum command_class theclass
, int abbrev_flag
,
339 struct cmd_list_element
**list
)
343 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
344 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
345 &prehook
, &prehookee
,
346 &posthook
, &posthookee
);
348 /* If this happens, it means a programmer error somewhere. */
349 gdb_assert (!aliases
&& !prehook
&& !prehookee
350 && !posthook
&& ! posthookee
);
354 struct cmd_list_element
*c
= add_cmd (name
, theclass
, old
->doc
, list
);
356 /* If OLD->DOC can be freed, we should make another copy. */
357 if (old
->doc_allocated
)
359 c
->doc
= xstrdup (old
->doc
);
360 c
->doc_allocated
= 1;
362 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
364 c
->function
= old
->function
;
365 c
->prefixlist
= old
->prefixlist
;
366 c
->prefixname
= old
->prefixname
;
367 c
->allow_unknown
= old
->allow_unknown
;
368 c
->abbrev_flag
= abbrev_flag
;
369 c
->cmd_pointer
= old
;
370 c
->alias_chain
= old
->aliases
;
373 set_cmd_prefix (c
, list
);
377 struct cmd_list_element
*
378 add_alias_cmd (const char *name
, const char *oldname
,
379 enum command_class theclass
, int abbrev_flag
,
380 struct cmd_list_element
**list
)
383 struct cmd_list_element
*old
;
386 old
= lookup_cmd (&tmp
, *list
, "", 1, 1);
388 return add_alias_cmd (name
, old
, theclass
, abbrev_flag
, list
);
392 /* Like add_cmd but adds an element for a command prefix: a name that
393 should be followed by a subcommand to be looked up in another
394 command list. PREFIXLIST should be the address of the variable
395 containing that list. */
397 struct cmd_list_element
*
398 add_prefix_cmd (const char *name
, enum command_class theclass
,
399 cmd_const_cfunc_ftype
*fun
,
400 const char *doc
, struct cmd_list_element
**prefixlist
,
401 const char *prefixname
, int allow_unknown
,
402 struct cmd_list_element
**list
)
404 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
405 struct cmd_list_element
*p
;
407 c
->prefixlist
= prefixlist
;
408 c
->prefixname
= prefixname
;
409 c
->allow_unknown
= allow_unknown
;
411 if (list
== &cmdlist
)
414 set_cmd_prefix (c
, list
);
416 /* Update the field 'prefix' of each cmd_list_element in *PREFIXLIST. */
417 for (p
= *prefixlist
; p
!= NULL
; p
= p
->next
)
423 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
425 struct cmd_list_element
*
426 add_abbrev_prefix_cmd (const char *name
, enum command_class theclass
,
427 cmd_const_cfunc_ftype
*fun
, const char *doc
,
428 struct cmd_list_element
**prefixlist
,
429 const char *prefixname
,
430 int allow_unknown
, struct cmd_list_element
**list
)
432 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
434 c
->prefixlist
= prefixlist
;
435 c
->prefixname
= prefixname
;
436 c
->allow_unknown
= allow_unknown
;
441 /* This is an empty "cfunc". */
443 not_just_help_class_command (const char *args
, int from_tty
)
447 /* This is an empty "sfunc". */
448 static void empty_sfunc (char *, int, struct cmd_list_element
*);
451 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
455 /* Add element named NAME to command list LIST (the list for set/show
456 or some sublist thereof).
457 TYPE is set_cmd or show_cmd.
458 CLASS is as in add_cmd.
459 VAR_TYPE is the kind of thing we are setting.
460 VAR is address of the variable being controlled by this command.
461 DOC is the documentation string. */
463 static struct cmd_list_element
*
464 add_set_or_show_cmd (const char *name
,
466 enum command_class theclass
,
470 struct cmd_list_element
**list
)
472 struct cmd_list_element
*c
= add_cmd (name
, theclass
, doc
, list
);
474 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
476 c
->var_type
= var_type
;
478 /* This needs to be something besides NULL so that this isn't
479 treated as a help class. */
480 set_cmd_sfunc (c
, empty_sfunc
);
484 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
485 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
486 setting. VAR is address of the variable being controlled by this
487 command. SET_FUNC and SHOW_FUNC are the callback functions (if
488 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
489 strings. PRINT the format string to print the value. SET_RESULT
490 and SHOW_RESULT, if not NULL, are set to the resulting command
494 add_setshow_cmd_full (const char *name
,
495 enum command_class theclass
,
496 var_types var_type
, void *var
,
497 const char *set_doc
, const char *show_doc
,
498 const char *help_doc
,
499 cmd_sfunc_ftype
*set_func
,
500 show_value_ftype
*show_func
,
501 struct cmd_list_element
**set_list
,
502 struct cmd_list_element
**show_list
,
503 struct cmd_list_element
**set_result
,
504 struct cmd_list_element
**show_result
)
506 struct cmd_list_element
*set
;
507 struct cmd_list_element
*show
;
511 if (help_doc
!= NULL
)
513 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
514 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
518 full_set_doc
= xstrdup (set_doc
);
519 full_show_doc
= xstrdup (show_doc
);
521 set
= add_set_or_show_cmd (name
, set_cmd
, theclass
, var_type
, var
,
522 full_set_doc
, set_list
);
523 set
->doc_allocated
= 1;
525 if (set_func
!= NULL
)
526 set_cmd_sfunc (set
, set_func
);
528 set_cmd_prefix (set
, set_list
);
530 show
= add_set_or_show_cmd (name
, show_cmd
, theclass
, var_type
, var
,
531 full_show_doc
, show_list
);
532 show
->doc_allocated
= 1;
533 show
->show_value_func
= show_func
;
535 if (set_result
!= NULL
)
537 if (show_result
!= NULL
)
541 /* Add element named NAME to command list LIST (the list for set or
542 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
543 of strings which may follow NAME. VAR is address of the variable
544 which will contain the matching string (from ENUMLIST). */
547 add_setshow_enum_cmd (const char *name
,
548 enum command_class theclass
,
549 const char *const *enumlist
,
552 const char *show_doc
,
553 const char *help_doc
,
554 cmd_sfunc_ftype
*set_func
,
555 show_value_ftype
*show_func
,
556 struct cmd_list_element
**set_list
,
557 struct cmd_list_element
**show_list
)
559 struct cmd_list_element
*c
;
561 add_setshow_cmd_full (name
, theclass
, var_enum
, var
,
562 set_doc
, show_doc
, help_doc
,
569 const char * const auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
571 /* Add an auto-boolean command named NAME to both the set and show
572 command list lists. CLASS is as in add_cmd. VAR is address of the
573 variable which will contain the value. DOC is the documentation
574 string. FUNC is the corresponding callback. */
576 add_setshow_auto_boolean_cmd (const char *name
,
577 enum command_class theclass
,
578 enum auto_boolean
*var
,
579 const char *set_doc
, const char *show_doc
,
580 const char *help_doc
,
581 cmd_sfunc_ftype
*set_func
,
582 show_value_ftype
*show_func
,
583 struct cmd_list_element
**set_list
,
584 struct cmd_list_element
**show_list
)
586 struct cmd_list_element
*c
;
588 add_setshow_cmd_full (name
, theclass
, var_auto_boolean
, var
,
589 set_doc
, show_doc
, help_doc
,
593 c
->enums
= auto_boolean_enums
;
596 /* Add element named NAME to both the set and show command LISTs (the
597 list for set/show or some sublist thereof). CLASS is as in
598 add_cmd. VAR is address of the variable which will contain the
599 value. SET_DOC and SHOW_DOC are the documentation strings. */
601 add_setshow_boolean_cmd (const char *name
, enum command_class theclass
, int *var
,
602 const char *set_doc
, const char *show_doc
,
603 const char *help_doc
,
604 cmd_sfunc_ftype
*set_func
,
605 show_value_ftype
*show_func
,
606 struct cmd_list_element
**set_list
,
607 struct cmd_list_element
**show_list
)
609 static const char *boolean_enums
[] = { "on", "off", NULL
};
610 struct cmd_list_element
*c
;
612 add_setshow_cmd_full (name
, theclass
, var_boolean
, var
,
613 set_doc
, show_doc
, help_doc
,
617 c
->enums
= boolean_enums
;
620 /* Add element named NAME to both the set and show command LISTs (the
621 list for set/show or some sublist thereof). */
623 add_setshow_filename_cmd (const char *name
, enum command_class theclass
,
625 const char *set_doc
, const char *show_doc
,
626 const char *help_doc
,
627 cmd_sfunc_ftype
*set_func
,
628 show_value_ftype
*show_func
,
629 struct cmd_list_element
**set_list
,
630 struct cmd_list_element
**show_list
)
632 struct cmd_list_element
*set_result
;
634 add_setshow_cmd_full (name
, theclass
, var_filename
, var
,
635 set_doc
, show_doc
, help_doc
,
639 set_cmd_completer (set_result
, filename_completer
);
642 /* Add element named NAME to both the set and show command LISTs (the
643 list for set/show or some sublist thereof). */
645 add_setshow_string_cmd (const char *name
, enum command_class theclass
,
647 const char *set_doc
, const char *show_doc
,
648 const char *help_doc
,
649 cmd_sfunc_ftype
*set_func
,
650 show_value_ftype
*show_func
,
651 struct cmd_list_element
**set_list
,
652 struct cmd_list_element
**show_list
)
654 add_setshow_cmd_full (name
, theclass
, var_string
, var
,
655 set_doc
, show_doc
, help_doc
,
661 /* Add element named NAME to both the set and show command LISTs (the
662 list for set/show or some sublist thereof). */
663 struct cmd_list_element
*
664 add_setshow_string_noescape_cmd (const char *name
, enum command_class theclass
,
666 const char *set_doc
, const char *show_doc
,
667 const char *help_doc
,
668 cmd_sfunc_ftype
*set_func
,
669 show_value_ftype
*show_func
,
670 struct cmd_list_element
**set_list
,
671 struct cmd_list_element
**show_list
)
673 struct cmd_list_element
*set_cmd
;
675 add_setshow_cmd_full (name
, theclass
, var_string_noescape
, var
,
676 set_doc
, show_doc
, help_doc
,
683 /* Add element named NAME to both the set and show command LISTs (the
684 list for set/show or some sublist thereof). */
686 add_setshow_optional_filename_cmd (const char *name
, enum command_class theclass
,
688 const char *set_doc
, const char *show_doc
,
689 const char *help_doc
,
690 cmd_sfunc_ftype
*set_func
,
691 show_value_ftype
*show_func
,
692 struct cmd_list_element
**set_list
,
693 struct cmd_list_element
**show_list
)
695 struct cmd_list_element
*set_result
;
697 add_setshow_cmd_full (name
, theclass
, var_optional_filename
, var
,
698 set_doc
, show_doc
, help_doc
,
703 set_cmd_completer (set_result
, filename_completer
);
707 /* Completes on literal "unlimited". Used by integer commands that
708 support a special "unlimited" value. */
711 integer_unlimited_completer (struct cmd_list_element
*ignore
,
712 completion_tracker
&tracker
,
713 const char *text
, const char *word
)
715 static const char * const keywords
[] =
721 complete_on_enum (tracker
, keywords
, text
, word
);
724 /* Add element named NAME to both the set and show command LISTs (the
725 list for set/show or some sublist thereof). CLASS is as in
726 add_cmd. VAR is address of the variable which will contain the
727 value. SET_DOC and SHOW_DOC are the documentation strings. This
728 function is only used in Python API. Please don't use it elsewhere. */
730 add_setshow_integer_cmd (const char *name
, enum command_class theclass
,
732 const char *set_doc
, const char *show_doc
,
733 const char *help_doc
,
734 cmd_sfunc_ftype
*set_func
,
735 show_value_ftype
*show_func
,
736 struct cmd_list_element
**set_list
,
737 struct cmd_list_element
**show_list
)
739 struct cmd_list_element
*set
;
741 add_setshow_cmd_full (name
, theclass
, var_integer
, var
,
742 set_doc
, show_doc
, help_doc
,
747 set_cmd_completer (set
, integer_unlimited_completer
);
750 /* Add element named NAME to both the set and show command LISTs (the
751 list for set/show or some sublist thereof). CLASS is as in
752 add_cmd. VAR is address of the variable which will contain the
753 value. SET_DOC and SHOW_DOC are the documentation strings. */
755 add_setshow_uinteger_cmd (const char *name
, enum command_class theclass
,
757 const char *set_doc
, const char *show_doc
,
758 const char *help_doc
,
759 cmd_sfunc_ftype
*set_func
,
760 show_value_ftype
*show_func
,
761 struct cmd_list_element
**set_list
,
762 struct cmd_list_element
**show_list
)
764 struct cmd_list_element
*set
;
766 add_setshow_cmd_full (name
, theclass
, var_uinteger
, var
,
767 set_doc
, show_doc
, help_doc
,
772 set_cmd_completer (set
, integer_unlimited_completer
);
775 /* Add element named NAME to both the set and show command LISTs (the
776 list for set/show or some sublist thereof). CLASS is as in
777 add_cmd. VAR is address of the variable which will contain the
778 value. SET_DOC and SHOW_DOC are the documentation strings. */
780 add_setshow_zinteger_cmd (const char *name
, enum command_class theclass
,
782 const char *set_doc
, const char *show_doc
,
783 const char *help_doc
,
784 cmd_sfunc_ftype
*set_func
,
785 show_value_ftype
*show_func
,
786 struct cmd_list_element
**set_list
,
787 struct cmd_list_element
**show_list
)
789 add_setshow_cmd_full (name
, theclass
, var_zinteger
, var
,
790 set_doc
, show_doc
, help_doc
,
797 add_setshow_zuinteger_unlimited_cmd (const char *name
,
798 enum command_class theclass
,
801 const char *show_doc
,
802 const char *help_doc
,
803 cmd_sfunc_ftype
*set_func
,
804 show_value_ftype
*show_func
,
805 struct cmd_list_element
**set_list
,
806 struct cmd_list_element
**show_list
)
808 struct cmd_list_element
*set
;
810 add_setshow_cmd_full (name
, theclass
, var_zuinteger_unlimited
, var
,
811 set_doc
, show_doc
, help_doc
,
816 set_cmd_completer (set
, integer_unlimited_completer
);
819 /* Add element named NAME to both the set and show command LISTs (the
820 list for set/show or some sublist thereof). CLASS is as in
821 add_cmd. VAR is address of the variable which will contain the
822 value. SET_DOC and SHOW_DOC are the documentation strings. */
824 add_setshow_zuinteger_cmd (const char *name
, enum command_class theclass
,
826 const char *set_doc
, const char *show_doc
,
827 const char *help_doc
,
828 cmd_sfunc_ftype
*set_func
,
829 show_value_ftype
*show_func
,
830 struct cmd_list_element
**set_list
,
831 struct cmd_list_element
**show_list
)
833 add_setshow_cmd_full (name
, theclass
, var_zuinteger
, var
,
834 set_doc
, show_doc
, help_doc
,
840 /* Remove the command named NAME from the command list. Return the
841 list commands which were aliased to the deleted command. If the
842 command had no aliases, return NULL. The various *HOOKs are set to
843 the pre- and post-hook commands for the deleted command. If the
844 command does not have a hook, the corresponding out parameter is
847 static struct cmd_list_element
*
848 delete_cmd (const char *name
, struct cmd_list_element
**list
,
849 struct cmd_list_element
**prehook
,
850 struct cmd_list_element
**prehookee
,
851 struct cmd_list_element
**posthook
,
852 struct cmd_list_element
**posthookee
)
854 struct cmd_list_element
*iter
;
855 struct cmd_list_element
**previous_chain_ptr
;
856 struct cmd_list_element
*aliases
= NULL
;
862 previous_chain_ptr
= list
;
864 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
866 if (strcmp (iter
->name
, name
) == 0)
869 iter
->destroyer (iter
, iter
->context
);
870 if (iter
->hookee_pre
)
871 iter
->hookee_pre
->hook_pre
= 0;
872 *prehook
= iter
->hook_pre
;
873 *prehookee
= iter
->hookee_pre
;
874 if (iter
->hookee_post
)
875 iter
->hookee_post
->hook_post
= 0;
876 if (iter
->doc
&& iter
->doc_allocated
)
877 xfree ((char *) iter
->doc
);
878 *posthook
= iter
->hook_post
;
879 *posthookee
= iter
->hookee_post
;
881 /* Update the link. */
882 *previous_chain_ptr
= iter
->next
;
884 aliases
= iter
->aliases
;
886 /* If this command was an alias, remove it from the list of
888 if (iter
->cmd_pointer
)
890 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
891 struct cmd_list_element
*a
= *prevp
;
895 prevp
= &a
->alias_chain
;
898 *prevp
= iter
->alias_chain
;
903 /* We won't see another command with the same name. */
907 previous_chain_ptr
= &iter
->next
;
913 /* Shorthands to the commands above. */
915 /* Add an element to the list of info subcommands. */
917 struct cmd_list_element
*
918 add_info (const char *name
, cmd_const_cfunc_ftype
*fun
, const char *doc
)
920 return add_cmd (name
, class_info
, fun
, doc
, &infolist
);
923 /* Add an alias to the list of info subcommands. */
925 struct cmd_list_element
*
926 add_info_alias (const char *name
, const char *oldname
, int abbrev_flag
)
928 return add_alias_cmd (name
, oldname
, class_run
, abbrev_flag
, &infolist
);
931 /* Add an element to the list of commands. */
933 struct cmd_list_element
*
934 add_com (const char *name
, enum command_class theclass
,
935 cmd_const_cfunc_ftype
*fun
,
938 return add_cmd (name
, theclass
, fun
, doc
, &cmdlist
);
941 /* Add an alias or abbreviation command to the list of commands. */
943 struct cmd_list_element
*
944 add_com_alias (const char *name
, const char *oldname
, enum command_class theclass
,
947 return add_alias_cmd (name
, oldname
, theclass
, abbrev_flag
, &cmdlist
);
950 /* Add an element with a suppress notification to the list of commands. */
952 struct cmd_list_element
*
953 add_com_suppress_notification (const char *name
, enum command_class theclass
,
954 cmd_const_cfunc_ftype
*fun
, const char *doc
,
955 int *suppress_notification
)
957 struct cmd_list_element
*element
;
959 element
= add_cmd (name
, theclass
, fun
, doc
, &cmdlist
);
960 element
->suppress_notification
= suppress_notification
;
965 /* Recursively walk the commandlist structures, and print out the
966 documentation of commands that match our regex in either their
967 name, or their documentation.
970 apropos_cmd (struct ui_file
*stream
,
971 struct cmd_list_element
*commandlist
,
972 compiled_regex
®ex
, const char *prefix
)
974 struct cmd_list_element
*c
;
977 /* Walk through the commands. */
978 for (c
=commandlist
;c
;c
=c
->next
)
980 returnvalue
= -1; /* Needed to avoid double printing. */
983 size_t name_len
= strlen (c
->name
);
985 /* Try to match against the name. */
986 returnvalue
= regex
.search (c
->name
, name_len
, 0, name_len
, NULL
);
987 if (returnvalue
>= 0)
989 print_help_for_command (c
, prefix
,
990 0 /* don't recurse */, stream
);
993 if (c
->doc
!= NULL
&& returnvalue
< 0)
995 size_t doc_len
= strlen (c
->doc
);
997 /* Try to match against documentation. */
998 if (regex
.search (c
->doc
, doc_len
, 0, doc_len
, NULL
) >= 0)
1000 print_help_for_command (c
, prefix
,
1001 0 /* don't recurse */, stream
);
1004 /* Check if this command has subcommands and is not an
1005 abbreviation. We skip listing subcommands of abbreviations
1006 in order to avoid duplicates in the output. */
1007 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
1009 /* Recursively call ourselves on the subcommand list,
1010 passing the right prefix in. */
1011 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
1016 /* This command really has to deal with two things:
1017 1) I want documentation on *this string* (usually called by
1018 "help commandname").
1020 2) I want documentation on *this list* (usually called by giving a
1021 command that requires subcommands. Also called by saying just
1024 I am going to split this into two seperate comamnds, help_cmd and
1028 help_cmd (const char *command
, struct ui_file
*stream
)
1030 struct cmd_list_element
*c
;
1034 help_list (cmdlist
, "", all_classes
, stream
);
1038 if (strcmp (command
, "all") == 0)
1044 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
1049 /* There are three cases here.
1050 If c->prefixlist is nonzero, we have a prefix command.
1051 Print its documentation, then list its subcommands.
1053 If c->func is non NULL, we really have a command. Print its
1054 documentation and return.
1056 If c->func is NULL, we have a class name. Print its
1057 documentation (as if it were a command) and then set class to the
1058 number of this class so that the commands in the class will be
1061 fputs_filtered (c
->doc
, stream
);
1062 fputs_filtered ("\n", stream
);
1064 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
1066 fprintf_filtered (stream
, "\n");
1068 /* If this is a prefix command, print it's subcommands. */
1070 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
1072 /* If this is a class name, print all of the commands in the class. */
1073 if (c
->func
== NULL
)
1074 help_list (cmdlist
, "", c
->theclass
, stream
);
1076 if (c
->hook_pre
|| c
->hook_post
)
1077 fprintf_filtered (stream
,
1078 "\nThis command has a hook (or hooks) defined:\n");
1081 fprintf_filtered (stream
,
1082 "\tThis command is run after : %s (pre hook)\n",
1085 fprintf_filtered (stream
,
1086 "\tThis command is run before : %s (post hook)\n",
1087 c
->hook_post
->name
);
1091 * Get a specific kind of help on a command list.
1094 * CMDTYPE is the prefix to use in the title string.
1095 * CLASS is the class with which to list the nodes of this list (see
1096 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
1097 * everything, ALL_CLASSES for just classes, and non-negative for only things
1098 * in a specific class.
1099 * and STREAM is the output stream on which to print things.
1100 * If you call this routine with a class >= 0, it recurses.
1103 help_list (struct cmd_list_element
*list
, const char *cmdtype
,
1104 enum command_class theclass
, struct ui_file
*stream
)
1107 char *cmdtype1
, *cmdtype2
;
1109 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
1111 len
= strlen (cmdtype
);
1112 cmdtype1
= (char *) alloca (len
+ 1);
1114 cmdtype2
= (char *) alloca (len
+ 4);
1119 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
1121 strncpy (cmdtype2
, cmdtype
, len
- 1);
1122 strcpy (cmdtype2
+ len
- 1, " sub");
1125 if (theclass
== all_classes
)
1126 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
1128 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
1130 help_cmd_list (list
, theclass
, cmdtype
, (int) theclass
>= 0, stream
);
1132 if (theclass
== all_classes
)
1134 fprintf_filtered (stream
, "\n\
1135 Type \"help%s\" followed by a class name for a list of commands in ",
1138 fprintf_filtered (stream
, "that class.");
1140 fprintf_filtered (stream
, "\n\
1141 Type \"help all\" for the list of all commands.");
1144 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
1145 cmdtype1
, cmdtype2
);
1147 fputs_filtered ("for ", stream
);
1149 fputs_filtered ("full ", stream
);
1151 fputs_filtered ("documentation.\n", stream
);
1152 fputs_filtered ("Type \"apropos word\" to search "
1153 "for commands related to \"word\".\n", stream
);
1154 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
1159 help_all (struct ui_file
*stream
)
1161 struct cmd_list_element
*c
;
1162 int seen_unclassified
= 0;
1164 for (c
= cmdlist
; c
; c
= c
->next
)
1168 /* If this is a class name, print all of the commands in the
1171 if (c
->func
== NULL
)
1173 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
1174 help_cmd_list (cmdlist
, c
->theclass
, "", 1, stream
);
1178 /* While it's expected that all commands are in some class,
1179 as a safety measure, we'll print commands outside of any
1180 class at the end. */
1182 for (c
= cmdlist
; c
; c
= c
->next
)
1187 if (c
->theclass
== no_class
)
1189 if (!seen_unclassified
)
1191 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
1192 seen_unclassified
= 1;
1194 print_help_for_command (c
, "", 1, stream
);
1200 /* Print only the first line of STR on STREAM. */
1202 print_doc_line (struct ui_file
*stream
, const char *str
)
1204 static char *line_buffer
= 0;
1205 static int line_size
;
1211 line_buffer
= (char *) xmalloc (line_size
);
1214 /* Keep printing '.' or ',' not followed by a whitespace for embedded strings
1217 while (*p
&& *p
!= '\n'
1218 && ((*p
!= '.' && *p
!= ',') || (p
[1] && !isspace (p
[1]))))
1220 if (p
- str
> line_size
- 1)
1222 line_size
= p
- str
+ 1;
1223 xfree (line_buffer
);
1224 line_buffer
= (char *) xmalloc (line_size
);
1226 strncpy (line_buffer
, str
, p
- str
);
1227 line_buffer
[p
- str
] = '\0';
1228 if (islower (line_buffer
[0]))
1229 line_buffer
[0] = toupper (line_buffer
[0]);
1230 fputs_filtered (line_buffer
, stream
);
1233 /* Print one-line help for command C.
1234 If RECURSE is non-zero, also print one-line descriptions
1235 of all prefixed subcommands. */
1237 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
1238 int recurse
, struct ui_file
*stream
)
1240 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1241 print_doc_line (stream
, c
->doc
);
1242 fputs_filtered ("\n", stream
);
1245 && c
->prefixlist
!= 0
1246 && c
->abbrev_flag
== 0)
1247 /* Subcommands of a prefix command typically have 'all_commands'
1248 as class. If we pass CLASS to recursive invocation,
1249 most often we won't see anything. */
1250 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1254 * Implement a help command on command list LIST.
1255 * RECURSE should be non-zero if this should be done recursively on
1256 * all sublists of LIST.
1257 * PREFIX is the prefix to print before each command name.
1258 * STREAM is the stream upon which the output should be written.
1259 * THECLASS should be:
1260 * A non-negative class number to list only commands in that
1262 * ALL_COMMANDS to list all commands in list.
1263 * ALL_CLASSES to list all classes in list.
1265 * Note that RECURSE will be active on *all* sublists, not just the
1266 * ones selected by the criteria above (ie. the selection mechanism
1267 * is at the low level, not the high-level).
1270 help_cmd_list (struct cmd_list_element
*list
, enum command_class theclass
,
1271 const char *prefix
, int recurse
, struct ui_file
*stream
)
1273 struct cmd_list_element
*c
;
1275 for (c
= list
; c
; c
= c
->next
)
1277 if (c
->abbrev_flag
== 0
1278 && !c
->cmd_deprecated
1279 && (theclass
== all_commands
1280 || (theclass
== all_classes
&& c
->func
== NULL
)
1281 || (theclass
== c
->theclass
&& c
->func
!= NULL
)))
1283 print_help_for_command (c
, prefix
, recurse
, stream
);
1285 else if (c
->abbrev_flag
== 0
1287 && !c
->cmd_deprecated
1288 && theclass
== class_user
&& c
->prefixlist
!= NULL
)
1289 /* User-defined commands may be subcommands. */
1290 help_cmd_list (*c
->prefixlist
, theclass
, c
->prefixname
,
1296 /* Search the input clist for 'command'. Return the command if
1297 found (or NULL if not), and return the number of commands
1300 static struct cmd_list_element
*
1301 find_cmd (const char *command
, int len
, struct cmd_list_element
*clist
,
1302 int ignore_help_classes
, int *nfound
)
1304 struct cmd_list_element
*found
, *c
;
1308 for (c
= clist
; c
; c
= c
->next
)
1309 if (!strncmp (command
, c
->name
, len
)
1310 && (!ignore_help_classes
|| c
->func
))
1314 if (c
->name
[len
] == '\0')
1323 /* Return the length of command name in TEXT. */
1326 find_command_name_length (const char *text
)
1328 const char *p
= text
;
1330 /* Treating underscores as part of command words is important
1331 so that "set args_foo()" doesn't get interpreted as
1332 "set args _foo()". */
1333 /* Some characters are only used for TUI specific commands.
1334 However, they are always allowed for the sake of consistency.
1336 Note that this is larger than the character set allowed when
1337 creating user-defined commands. */
1339 /* Recognize '!' as a single character command so that, e.g., "!ls"
1340 works as expected. */
1344 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1345 /* Characters used by TUI specific commands. */
1346 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')
1352 /* Return TRUE if NAME is a valid user-defined command name.
1353 This is a stricter subset of all gdb commands,
1354 see find_command_name_length. */
1357 valid_user_defined_cmd_name_p (const char *name
)
1364 /* Alas "42" is a legitimate user-defined command.
1365 In the interests of not breaking anything we preserve that. */
1367 for (p
= name
; *p
!= '\0'; ++p
)
1380 /* This routine takes a line of TEXT and a CLIST in which to start the
1381 lookup. When it returns it will have incremented the text pointer past
1382 the section of text it matched, set *RESULT_LIST to point to the list in
1383 which the last word was matched, and will return a pointer to the cmd
1384 list element which the text matches. It will return NULL if no match at
1385 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1386 matches are possible; in this case *RESULT_LIST will be set to point to
1387 the list in which there are ambiguous choices (and *TEXT will be set to
1388 the ambiguous text string).
1390 If the located command was an abbreviation, this routine returns the base
1391 command of the abbreviation.
1393 It does no error reporting whatsoever; control will always return
1394 to the superior routine.
1396 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1397 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1398 if no prefix command was ever found. For example, in the case of "info a",
1399 "info" matches without ambiguity, but "a" could be "args" or "address", so
1400 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1401 RESULT_LIST should not be interpreted as a pointer to the beginning of a
1402 list; it simply points to a specific command. In the case of an ambiguous
1403 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1404 "info t" can be "info types" or "info target"; upon return *TEXT has been
1405 advanced past "info ").
1407 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1408 affect the operation).
1410 This routine does *not* modify the text pointed to by TEXT.
1412 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1413 are actually help classes rather than commands (i.e. the function field of
1414 the struct cmd_list_element is NULL). */
1416 struct cmd_list_element
*
1417 lookup_cmd_1 (const char **text
, struct cmd_list_element
*clist
,
1418 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1421 int len
, tmp
, nfound
;
1422 struct cmd_list_element
*found
, *c
;
1423 const char *line
= *text
;
1425 while (**text
== ' ' || **text
== '\t')
1428 /* Identify the name of the command. */
1429 len
= find_command_name_length (*text
);
1431 /* If nothing but whitespace, return 0. */
1435 /* *text and p now bracket the first command word to lookup (and
1436 it's length is len). We copy this into a local temporary. */
1439 command
= (char *) alloca (len
+ 1);
1440 memcpy (command
, *text
, len
);
1441 command
[len
] = '\0';
1446 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1448 /* If nothing matches, we have a simple failure. */
1454 if (result_list
!= NULL
)
1455 /* Will be modified in calling routine
1456 if we know what the prefix command is. */
1458 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1461 /* We've matched something on this list. Move text pointer forward. */
1465 if (found
->cmd_pointer
)
1467 /* We drop the alias (abbreviation) in favor of the command it
1468 is pointing to. If the alias is deprecated, though, we need to
1469 warn the user about it before we drop it. Note that while we
1470 are warning about the alias, we may also warn about the command
1471 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1474 if (found
->deprecated_warn_user
)
1475 deprecated_cmd_warning (line
);
1476 found
= found
->cmd_pointer
;
1478 /* If we found a prefix command, keep looking. */
1480 if (found
->prefixlist
)
1482 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1483 ignore_help_classes
);
1486 /* Didn't find anything; this is as far as we got. */
1487 if (result_list
!= NULL
)
1488 *result_list
= clist
;
1491 else if (c
== CMD_LIST_AMBIGUOUS
)
1493 /* We've gotten this far properly, but the next step is
1494 ambiguous. We need to set the result list to the best
1495 we've found (if an inferior hasn't already set it). */
1496 if (result_list
!= NULL
)
1498 /* This used to say *result_list = *found->prefixlist.
1499 If that was correct, need to modify the documentation
1500 at the top of this function to clarify what is
1501 supposed to be going on. */
1502 *result_list
= found
;
1513 if (result_list
!= NULL
)
1514 *result_list
= clist
;
1519 /* All this hair to move the space to the front of cmdtype */
1522 undef_cmd_error (const char *cmdtype
, const char *q
)
1524 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1527 *cmdtype
? " " : "",
1528 (int) strlen (cmdtype
) - 1,
1532 /* Look up the contents of *LINE as a command in the command list LIST.
1533 LIST is a chain of struct cmd_list_element's.
1534 If it is found, return the struct cmd_list_element for that command
1535 and update *LINE to point after the command name, at the first argument.
1536 If not found, call error if ALLOW_UNKNOWN is zero
1537 otherwise (or if error returns) return zero.
1538 Call error if specified command is ambiguous,
1539 unless ALLOW_UNKNOWN is negative.
1540 CMDTYPE precedes the word "command" in the error message.
1542 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1543 elements which are actually help classes rather than commands (i.e.
1544 the function field of the struct cmd_list_element is 0). */
1546 struct cmd_list_element
*
1547 lookup_cmd (const char **line
, struct cmd_list_element
*list
,
1548 const char *cmdtype
,
1549 int allow_unknown
, int ignore_help_classes
)
1551 struct cmd_list_element
*last_list
= 0;
1552 struct cmd_list_element
*c
;
1554 /* Note: Do not remove trailing whitespace here because this
1555 would be wrong for complete_command. Jim Kingdon */
1558 error (_("Lack of needed %scommand"), cmdtype
);
1560 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1567 int len
= find_command_name_length (*line
);
1569 q
= (char *) alloca (len
+ 1);
1570 strncpy (q
, *line
, len
);
1572 undef_cmd_error (cmdtype
, q
);
1577 else if (c
== CMD_LIST_AMBIGUOUS
)
1579 /* Ambigous. Local values should be off prefixlist or called
1581 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1583 const char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1584 struct cmd_list_element
*local_list
=
1585 (last_list
? *(last_list
->prefixlist
) : list
);
1587 if (local_allow_unknown
< 0)
1590 return last_list
; /* Found something. */
1592 return 0; /* Found nothing. */
1596 /* Report as error. */
1601 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1602 && (*line
)[amb_len
] != '\t');
1607 for (c
= local_list
; c
; c
= c
->next
)
1608 if (!strncmp (*line
, c
->name
, amb_len
))
1610 if (strlen (ambbuf
) + strlen (c
->name
) + 6
1611 < (int) sizeof ambbuf
)
1613 if (strlen (ambbuf
))
1614 strcat (ambbuf
, ", ");
1615 strcat (ambbuf
, c
->name
);
1619 strcat (ambbuf
, "..");
1623 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1625 return 0; /* lint */
1630 if (c
->type
== set_cmd
&& **line
!= '\0' && !isspace (**line
))
1631 error (_("Argument must be preceded by space."));
1633 /* We've got something. It may still not be what the caller
1634 wants (if this command *needs* a subcommand). */
1635 while (**line
== ' ' || **line
== '\t')
1638 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1639 undef_cmd_error (c
->prefixname
, *line
);
1641 /* Seems to be what he wants. Return it. */
1647 /* We are here presumably because an alias or command in TEXT is
1648 deprecated and a warning message should be generated. This
1649 function decodes TEXT and potentially generates a warning message
1652 Example for 'set endian big' which has a fictitious alias 'seb'.
1654 If alias wasn't used in TEXT, and the command is deprecated:
1655 "warning: 'set endian big' is deprecated."
1657 If alias was used, and only the alias is deprecated:
1658 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1660 If alias was used and command is deprecated (regardless of whether
1661 the alias itself is deprecated:
1663 "warning: 'set endian big' (seb) is deprecated."
1665 After the message has been sent, clear the appropriate flags in the
1666 command and/or the alias so the user is no longer bothered.
1670 deprecated_cmd_warning (const char *text
)
1672 struct cmd_list_element
*alias
= NULL
;
1673 struct cmd_list_element
*prefix_cmd
= NULL
;
1674 struct cmd_list_element
*cmd
= NULL
;
1676 if (!lookup_cmd_composition (text
, &alias
, &prefix_cmd
, &cmd
))
1677 /* Return if text doesn't evaluate to a command. */
1680 if (!((alias
? alias
->deprecated_warn_user
: 0)
1681 || cmd
->deprecated_warn_user
) )
1682 /* Return if nothing is deprecated. */
1685 printf_filtered ("Warning:");
1687 if (alias
&& !cmd
->cmd_deprecated
)
1688 printf_filtered (" '%s', an alias for the", alias
->name
);
1690 printf_filtered (" command '");
1693 printf_filtered ("%s", prefix_cmd
->prefixname
);
1695 printf_filtered ("%s", cmd
->name
);
1697 if (alias
&& cmd
->cmd_deprecated
)
1698 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1700 printf_filtered ("' is deprecated.\n");
1703 /* If it is only the alias that is deprecated, we want to indicate
1704 the new alias, otherwise we'll indicate the new command. */
1706 if (alias
&& !cmd
->cmd_deprecated
)
1708 if (alias
->replacement
)
1709 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1711 printf_filtered ("No alternative known.\n\n");
1715 if (cmd
->replacement
)
1716 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1718 printf_filtered ("No alternative known.\n\n");
1721 /* We've warned you, now we'll keep quiet. */
1723 alias
->deprecated_warn_user
= 0;
1725 cmd
->deprecated_warn_user
= 0;
1729 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1730 Return 1 on success, 0 on failure.
1732 If LINE refers to an alias, *alias will point to that alias.
1734 If LINE is a postfix command (i.e. one that is preceded by a prefix
1735 command) set *prefix_cmd.
1737 Set *cmd to point to the command LINE indicates.
1739 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1740 exist, they are NULL when we return.
1744 lookup_cmd_composition (const char *text
,
1745 struct cmd_list_element
**alias
,
1746 struct cmd_list_element
**prefix_cmd
,
1747 struct cmd_list_element
**cmd
)
1750 int len
, tmp
, nfound
;
1751 struct cmd_list_element
*cur_list
;
1752 struct cmd_list_element
*prev_cmd
;
1762 /* Go through as many command lists as we need to,
1763 to find the command TEXT refers to. */
1767 while (*text
== ' ' || *text
== '\t')
1770 /* Identify the name of the command. */
1771 len
= find_command_name_length (text
);
1773 /* If nothing but whitespace, return. */
1777 /* Text is the start of the first command word to lookup (and
1778 it's length is len). We copy this into a local temporary. */
1780 command
= (char *) alloca (len
+ 1);
1781 memcpy (command
, text
, len
);
1782 command
[len
] = '\0';
1787 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1789 if (*cmd
== CMD_LIST_AMBIGUOUS
)
1791 return 0; /* ambiguous */
1795 return 0; /* nothing found */
1798 if ((*cmd
)->cmd_pointer
)
1800 /* cmd was actually an alias, we note that an alias was
1801 used (by assigning *alais) and we set *cmd. */
1803 *cmd
= (*cmd
)->cmd_pointer
;
1805 *prefix_cmd
= prev_cmd
;
1807 if ((*cmd
)->prefixlist
)
1808 cur_list
= *(*cmd
)->prefixlist
;
1816 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1818 /* Return a vector of char pointers which point to the different
1819 possible completions in LIST of TEXT.
1821 WORD points in the same buffer as TEXT, and completions should be
1822 returned relative to this position. For example, suppose TEXT is
1823 "foo" and we want to complete to "foobar". If WORD is "oo", return
1824 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1827 complete_on_cmdlist (struct cmd_list_element
*list
,
1828 completion_tracker
&tracker
,
1829 const char *text
, const char *word
,
1830 int ignore_help_classes
)
1832 struct cmd_list_element
*ptr
;
1833 int textlen
= strlen (text
);
1835 int saw_deprecated_match
= 0;
1837 /* We do one or two passes. In the first pass, we skip deprecated
1838 commands. If we see no matching commands in the first pass, and
1839 if we did happen to see a matching deprecated command, we do
1840 another loop to collect those. */
1841 for (pass
= 0; pass
< 2; ++pass
)
1843 bool got_matches
= false;
1845 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1846 if (!strncmp (ptr
->name
, text
, textlen
)
1847 && !ptr
->abbrev_flag
1848 && (!ignore_help_classes
|| ptr
->func
1849 || ptr
->prefixlist
))
1855 if (ptr
->cmd_deprecated
)
1857 saw_deprecated_match
= 1;
1862 match
= (char *) xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1864 strcpy (match
, ptr
->name
);
1865 else if (word
> text
)
1867 /* Return some portion of ptr->name. */
1868 strcpy (match
, ptr
->name
+ (word
- text
));
1872 /* Return some of text plus ptr->name. */
1873 strncpy (match
, word
, text
- word
);
1874 match
[text
- word
] = '\0';
1875 strcat (match
, ptr
->name
);
1877 tracker
.add_completion (gdb::unique_xmalloc_ptr
<char> (match
));
1884 /* If we saw no matching deprecated commands in the first pass,
1886 if (!saw_deprecated_match
)
1891 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1893 /* Add the different possible completions in ENUMLIST of TEXT.
1895 WORD points in the same buffer as TEXT, and completions should be
1896 returned relative to this position. For example, suppose TEXT is "foo"
1897 and we want to complete to "foobar". If WORD is "oo", return
1898 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1901 complete_on_enum (completion_tracker
&tracker
,
1902 const char *const *enumlist
,
1903 const char *text
, const char *word
)
1905 int textlen
= strlen (text
);
1909 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1910 if (strncmp (name
, text
, textlen
) == 0)
1914 match
= (char *) xmalloc (strlen (word
) + strlen (name
) + 1);
1916 strcpy (match
, name
);
1917 else if (word
> text
)
1919 /* Return some portion of name. */
1920 strcpy (match
, name
+ (word
- text
));
1924 /* Return some of text plus name. */
1925 strncpy (match
, word
, text
- word
);
1926 match
[text
- word
] = '\0';
1927 strcat (match
, name
);
1929 tracker
.add_completion (gdb::unique_xmalloc_ptr
<char> (match
));
1934 /* Check function pointer. */
1936 cmd_func_p (struct cmd_list_element
*cmd
)
1938 return (cmd
->func
!= NULL
);
1942 /* Call the command function. */
1944 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1946 if (cmd_func_p (cmd
))
1948 gdb::optional
<scoped_restore_tmpl
<int>> restore_suppress
;
1950 if (cmd
->suppress_notification
!= NULL
)
1951 restore_suppress
.emplace (cmd
->suppress_notification
, 1);
1953 (*cmd
->func
) (cmd
, args
, from_tty
);
1956 error (_("Invalid command"));
1960 cli_user_command_p (struct cmd_list_element
*cmd
)
1962 return (cmd
->theclass
== class_user
1963 && (cmd
->func
== do_cfunc
|| cmd
->func
== do_sfunc
1964 || cmd
->func
== do_const_cfunc
));