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 /* Add an element with a suppress notification to the LIST of commands. */
256 struct cmd_list_element
*
257 add_cmd_suppress_notification (const char *name
, enum command_class theclass
,
258 cmd_const_cfunc_ftype
*fun
, const char *doc
,
259 struct cmd_list_element
**list
,
260 int *suppress_notification
)
262 struct cmd_list_element
*element
;
264 element
= add_cmd (name
, theclass
, fun
, doc
, list
);
265 element
->suppress_notification
= suppress_notification
;
271 /* Deprecates a command CMD.
272 REPLACEMENT is the name of the command which should be used in
273 place of this command, or NULL if no such command exists.
275 This function does not check to see if command REPLACEMENT exists
276 since gdb may not have gotten around to adding REPLACEMENT when
277 this function is called.
279 Returns a pointer to the deprecated command. */
281 struct cmd_list_element
*
282 deprecate_cmd (struct cmd_list_element
*cmd
, const char *replacement
)
284 cmd
->cmd_deprecated
= 1;
285 cmd
->deprecated_warn_user
= 1;
287 if (replacement
!= NULL
)
288 cmd
->replacement
= replacement
;
290 cmd
->replacement
= NULL
;
295 struct cmd_list_element
*
296 add_alias_cmd (const char *name
, cmd_list_element
*old
,
297 enum command_class theclass
, int abbrev_flag
,
298 struct cmd_list_element
**list
)
302 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
303 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
304 &prehook
, &prehookee
,
305 &posthook
, &posthookee
);
307 /* If this happens, it means a programmer error somewhere. */
308 gdb_assert (!aliases
&& !prehook
&& !prehookee
309 && !posthook
&& ! posthookee
);
313 struct cmd_list_element
*c
= add_cmd (name
, theclass
, old
->doc
, list
);
315 /* If OLD->DOC can be freed, we should make another copy. */
316 if (old
->doc_allocated
)
318 c
->doc
= xstrdup (old
->doc
);
319 c
->doc_allocated
= 1;
321 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
323 c
->function
= old
->function
;
324 c
->prefixlist
= old
->prefixlist
;
325 c
->prefixname
= old
->prefixname
;
326 c
->allow_unknown
= old
->allow_unknown
;
327 c
->abbrev_flag
= abbrev_flag
;
328 c
->cmd_pointer
= old
;
329 c
->alias_chain
= old
->aliases
;
332 set_cmd_prefix (c
, list
);
336 struct cmd_list_element
*
337 add_alias_cmd (const char *name
, const char *oldname
,
338 enum command_class theclass
, int abbrev_flag
,
339 struct cmd_list_element
**list
)
342 struct cmd_list_element
*old
;
345 old
= lookup_cmd (&tmp
, *list
, "", 1, 1);
347 return add_alias_cmd (name
, old
, theclass
, abbrev_flag
, list
);
351 /* Like add_cmd but adds an element for a command prefix: a name that
352 should be followed by a subcommand to be looked up in another
353 command list. PREFIXLIST should be the address of the variable
354 containing that list. */
356 struct cmd_list_element
*
357 add_prefix_cmd (const char *name
, enum command_class theclass
,
358 cmd_const_cfunc_ftype
*fun
,
359 const char *doc
, struct cmd_list_element
**prefixlist
,
360 const char *prefixname
, int allow_unknown
,
361 struct cmd_list_element
**list
)
363 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
364 struct cmd_list_element
*p
;
366 c
->prefixlist
= prefixlist
;
367 c
->prefixname
= prefixname
;
368 c
->allow_unknown
= allow_unknown
;
370 if (list
== &cmdlist
)
373 set_cmd_prefix (c
, list
);
375 /* Update the field 'prefix' of each cmd_list_element in *PREFIXLIST. */
376 for (p
= *prefixlist
; p
!= NULL
; p
= p
->next
)
382 /* Like ADD_PREFIX_CMD but sets the suppress_notification pointer on the
383 new command list element. */
385 struct cmd_list_element
*
386 add_prefix_cmd_suppress_notification
387 (const char *name
, enum command_class theclass
,
388 cmd_const_cfunc_ftype
*fun
,
389 const char *doc
, struct cmd_list_element
**prefixlist
,
390 const char *prefixname
, int allow_unknown
,
391 struct cmd_list_element
**list
,
392 int *suppress_notification
)
394 struct cmd_list_element
*element
395 = add_prefix_cmd (name
, theclass
, fun
, doc
, prefixlist
,
396 prefixname
, allow_unknown
, list
);
397 element
->suppress_notification
= suppress_notification
;
401 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
403 struct cmd_list_element
*
404 add_abbrev_prefix_cmd (const char *name
, enum command_class theclass
,
405 cmd_const_cfunc_ftype
*fun
, const char *doc
,
406 struct cmd_list_element
**prefixlist
,
407 const char *prefixname
,
408 int allow_unknown
, struct cmd_list_element
**list
)
410 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
412 c
->prefixlist
= prefixlist
;
413 c
->prefixname
= prefixname
;
414 c
->allow_unknown
= allow_unknown
;
419 /* This is an empty "cfunc". */
421 not_just_help_class_command (const char *args
, int from_tty
)
425 /* This is an empty "sfunc". */
428 empty_sfunc (const char *args
, int from_tty
, struct cmd_list_element
*c
)
432 /* Add element named NAME to command list LIST (the list for set/show
433 or some sublist thereof).
434 TYPE is set_cmd or show_cmd.
435 CLASS is as in add_cmd.
436 VAR_TYPE is the kind of thing we are setting.
437 VAR is address of the variable being controlled by this command.
438 DOC is the documentation string. */
440 static struct cmd_list_element
*
441 add_set_or_show_cmd (const char *name
,
443 enum command_class theclass
,
447 struct cmd_list_element
**list
)
449 struct cmd_list_element
*c
= add_cmd (name
, theclass
, doc
, list
);
451 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
453 c
->var_type
= var_type
;
455 /* This needs to be something besides NULL so that this isn't
456 treated as a help class. */
457 set_cmd_sfunc (c
, empty_sfunc
);
461 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
462 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
463 setting. VAR is address of the variable being controlled by this
464 command. SET_FUNC and SHOW_FUNC are the callback functions (if
465 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
466 strings. PRINT the format string to print the value. SET_RESULT
467 and SHOW_RESULT, if not NULL, are set to the resulting command
471 add_setshow_cmd_full (const char *name
,
472 enum command_class theclass
,
473 var_types var_type
, void *var
,
474 const char *set_doc
, const char *show_doc
,
475 const char *help_doc
,
476 cmd_const_sfunc_ftype
*set_func
,
477 show_value_ftype
*show_func
,
478 struct cmd_list_element
**set_list
,
479 struct cmd_list_element
**show_list
,
480 struct cmd_list_element
**set_result
,
481 struct cmd_list_element
**show_result
)
483 struct cmd_list_element
*set
;
484 struct cmd_list_element
*show
;
488 if (help_doc
!= NULL
)
490 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
491 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
495 full_set_doc
= xstrdup (set_doc
);
496 full_show_doc
= xstrdup (show_doc
);
498 set
= add_set_or_show_cmd (name
, set_cmd
, theclass
, var_type
, var
,
499 full_set_doc
, set_list
);
500 set
->doc_allocated
= 1;
502 if (set_func
!= NULL
)
503 set_cmd_sfunc (set
, set_func
);
505 set_cmd_prefix (set
, set_list
);
507 show
= add_set_or_show_cmd (name
, show_cmd
, theclass
, var_type
, var
,
508 full_show_doc
, show_list
);
509 show
->doc_allocated
= 1;
510 show
->show_value_func
= show_func
;
512 if (set_result
!= NULL
)
514 if (show_result
!= NULL
)
518 /* Add element named NAME to command list LIST (the list for set or
519 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
520 of strings which may follow NAME. VAR is address of the variable
521 which will contain the matching string (from ENUMLIST). */
524 add_setshow_enum_cmd (const char *name
,
525 enum command_class theclass
,
526 const char *const *enumlist
,
529 const char *show_doc
,
530 const char *help_doc
,
531 cmd_const_sfunc_ftype
*set_func
,
532 show_value_ftype
*show_func
,
533 struct cmd_list_element
**set_list
,
534 struct cmd_list_element
**show_list
)
536 struct cmd_list_element
*c
;
538 add_setshow_cmd_full (name
, theclass
, var_enum
, var
,
539 set_doc
, show_doc
, help_doc
,
546 const char * const auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
548 /* Add an auto-boolean command named NAME to both the set and show
549 command list lists. CLASS is as in add_cmd. VAR is address of the
550 variable which will contain the value. DOC is the documentation
551 string. FUNC is the corresponding callback. */
553 add_setshow_auto_boolean_cmd (const char *name
,
554 enum command_class theclass
,
555 enum auto_boolean
*var
,
556 const char *set_doc
, const char *show_doc
,
557 const char *help_doc
,
558 cmd_const_sfunc_ftype
*set_func
,
559 show_value_ftype
*show_func
,
560 struct cmd_list_element
**set_list
,
561 struct cmd_list_element
**show_list
)
563 struct cmd_list_element
*c
;
565 add_setshow_cmd_full (name
, theclass
, var_auto_boolean
, var
,
566 set_doc
, show_doc
, help_doc
,
570 c
->enums
= auto_boolean_enums
;
573 /* Add element named NAME to both the set and show command LISTs (the
574 list for set/show or some sublist thereof). CLASS is as in
575 add_cmd. VAR is address of the variable which will contain the
576 value. SET_DOC and SHOW_DOC are the documentation strings. */
578 add_setshow_boolean_cmd (const char *name
, enum command_class theclass
, int *var
,
579 const char *set_doc
, const char *show_doc
,
580 const char *help_doc
,
581 cmd_const_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 static const char *boolean_enums
[] = { "on", "off", NULL
};
587 struct cmd_list_element
*c
;
589 add_setshow_cmd_full (name
, theclass
, var_boolean
, var
,
590 set_doc
, show_doc
, help_doc
,
594 c
->enums
= boolean_enums
;
597 /* Add element named NAME to both the set and show command LISTs (the
598 list for set/show or some sublist thereof). */
600 add_setshow_filename_cmd (const char *name
, enum command_class theclass
,
602 const char *set_doc
, const char *show_doc
,
603 const char *help_doc
,
604 cmd_const_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 struct cmd_list_element
*set_result
;
611 add_setshow_cmd_full (name
, theclass
, var_filename
, var
,
612 set_doc
, show_doc
, help_doc
,
616 set_cmd_completer (set_result
, filename_completer
);
619 /* Add element named NAME to both the set and show command LISTs (the
620 list for set/show or some sublist thereof). */
622 add_setshow_string_cmd (const char *name
, enum command_class theclass
,
624 const char *set_doc
, const char *show_doc
,
625 const char *help_doc
,
626 cmd_const_sfunc_ftype
*set_func
,
627 show_value_ftype
*show_func
,
628 struct cmd_list_element
**set_list
,
629 struct cmd_list_element
**show_list
)
631 add_setshow_cmd_full (name
, theclass
, var_string
, var
,
632 set_doc
, show_doc
, help_doc
,
638 /* Add element named NAME to both the set and show command LISTs (the
639 list for set/show or some sublist thereof). */
640 struct cmd_list_element
*
641 add_setshow_string_noescape_cmd (const char *name
, enum command_class theclass
,
643 const char *set_doc
, const char *show_doc
,
644 const char *help_doc
,
645 cmd_const_sfunc_ftype
*set_func
,
646 show_value_ftype
*show_func
,
647 struct cmd_list_element
**set_list
,
648 struct cmd_list_element
**show_list
)
650 struct cmd_list_element
*set_cmd
;
652 add_setshow_cmd_full (name
, theclass
, var_string_noescape
, var
,
653 set_doc
, show_doc
, help_doc
,
660 /* Add element named NAME to both the set and show command LISTs (the
661 list for set/show or some sublist thereof). */
663 add_setshow_optional_filename_cmd (const char *name
, enum command_class theclass
,
665 const char *set_doc
, const char *show_doc
,
666 const char *help_doc
,
667 cmd_const_sfunc_ftype
*set_func
,
668 show_value_ftype
*show_func
,
669 struct cmd_list_element
**set_list
,
670 struct cmd_list_element
**show_list
)
672 struct cmd_list_element
*set_result
;
674 add_setshow_cmd_full (name
, theclass
, var_optional_filename
, var
,
675 set_doc
, show_doc
, help_doc
,
680 set_cmd_completer (set_result
, filename_completer
);
684 /* Completes on literal "unlimited". Used by integer commands that
685 support a special "unlimited" value. */
688 integer_unlimited_completer (struct cmd_list_element
*ignore
,
689 completion_tracker
&tracker
,
690 const char *text
, const char *word
)
692 static const char * const keywords
[] =
698 complete_on_enum (tracker
, keywords
, text
, word
);
701 /* Add element named NAME to both the set and show command LISTs (the
702 list for set/show or some sublist thereof). CLASS is as in
703 add_cmd. VAR is address of the variable which will contain the
704 value. SET_DOC and SHOW_DOC are the documentation strings. This
705 function is only used in Python API. Please don't use it elsewhere. */
707 add_setshow_integer_cmd (const char *name
, enum command_class theclass
,
709 const char *set_doc
, const char *show_doc
,
710 const char *help_doc
,
711 cmd_const_sfunc_ftype
*set_func
,
712 show_value_ftype
*show_func
,
713 struct cmd_list_element
**set_list
,
714 struct cmd_list_element
**show_list
)
716 struct cmd_list_element
*set
;
718 add_setshow_cmd_full (name
, theclass
, var_integer
, var
,
719 set_doc
, show_doc
, help_doc
,
724 set_cmd_completer (set
, integer_unlimited_completer
);
727 /* Add element named NAME to both the set and show command LISTs (the
728 list for set/show or some sublist thereof). CLASS is as in
729 add_cmd. VAR is address of the variable which will contain the
730 value. SET_DOC and SHOW_DOC are the documentation strings. */
732 add_setshow_uinteger_cmd (const char *name
, enum command_class theclass
,
734 const char *set_doc
, const char *show_doc
,
735 const char *help_doc
,
736 cmd_const_sfunc_ftype
*set_func
,
737 show_value_ftype
*show_func
,
738 struct cmd_list_element
**set_list
,
739 struct cmd_list_element
**show_list
)
741 struct cmd_list_element
*set
;
743 add_setshow_cmd_full (name
, theclass
, var_uinteger
, var
,
744 set_doc
, show_doc
, help_doc
,
749 set_cmd_completer (set
, integer_unlimited_completer
);
752 /* Add element named NAME to both the set and show command LISTs (the
753 list for set/show or some sublist thereof). CLASS is as in
754 add_cmd. VAR is address of the variable which will contain the
755 value. SET_DOC and SHOW_DOC are the documentation strings. */
757 add_setshow_zinteger_cmd (const char *name
, enum command_class theclass
,
759 const char *set_doc
, const char *show_doc
,
760 const char *help_doc
,
761 cmd_const_sfunc_ftype
*set_func
,
762 show_value_ftype
*show_func
,
763 struct cmd_list_element
**set_list
,
764 struct cmd_list_element
**show_list
)
766 add_setshow_cmd_full (name
, theclass
, var_zinteger
, var
,
767 set_doc
, show_doc
, help_doc
,
774 add_setshow_zuinteger_unlimited_cmd (const char *name
,
775 enum command_class theclass
,
778 const char *show_doc
,
779 const char *help_doc
,
780 cmd_const_sfunc_ftype
*set_func
,
781 show_value_ftype
*show_func
,
782 struct cmd_list_element
**set_list
,
783 struct cmd_list_element
**show_list
)
785 struct cmd_list_element
*set
;
787 add_setshow_cmd_full (name
, theclass
, var_zuinteger_unlimited
, var
,
788 set_doc
, show_doc
, help_doc
,
793 set_cmd_completer (set
, integer_unlimited_completer
);
796 /* Add element named NAME to both the set and show command LISTs (the
797 list for set/show or some sublist thereof). CLASS is as in
798 add_cmd. VAR is address of the variable which will contain the
799 value. SET_DOC and SHOW_DOC are the documentation strings. */
801 add_setshow_zuinteger_cmd (const char *name
, enum command_class theclass
,
803 const char *set_doc
, const char *show_doc
,
804 const char *help_doc
,
805 cmd_const_sfunc_ftype
*set_func
,
806 show_value_ftype
*show_func
,
807 struct cmd_list_element
**set_list
,
808 struct cmd_list_element
**show_list
)
810 add_setshow_cmd_full (name
, theclass
, var_zuinteger
, var
,
811 set_doc
, show_doc
, help_doc
,
817 /* Remove the command named NAME from the command list. Return the
818 list commands which were aliased to the deleted command. If the
819 command had no aliases, return NULL. The various *HOOKs are set to
820 the pre- and post-hook commands for the deleted command. If the
821 command does not have a hook, the corresponding out parameter is
824 static struct cmd_list_element
*
825 delete_cmd (const char *name
, struct cmd_list_element
**list
,
826 struct cmd_list_element
**prehook
,
827 struct cmd_list_element
**prehookee
,
828 struct cmd_list_element
**posthook
,
829 struct cmd_list_element
**posthookee
)
831 struct cmd_list_element
*iter
;
832 struct cmd_list_element
**previous_chain_ptr
;
833 struct cmd_list_element
*aliases
= NULL
;
839 previous_chain_ptr
= list
;
841 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
843 if (strcmp (iter
->name
, name
) == 0)
846 iter
->destroyer (iter
, iter
->context
);
847 if (iter
->hookee_pre
)
848 iter
->hookee_pre
->hook_pre
= 0;
849 *prehook
= iter
->hook_pre
;
850 *prehookee
= iter
->hookee_pre
;
851 if (iter
->hookee_post
)
852 iter
->hookee_post
->hook_post
= 0;
853 *posthook
= iter
->hook_post
;
854 *posthookee
= iter
->hookee_post
;
856 /* Update the link. */
857 *previous_chain_ptr
= iter
->next
;
859 aliases
= iter
->aliases
;
861 /* If this command was an alias, remove it from the list of
863 if (iter
->cmd_pointer
)
865 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
866 struct cmd_list_element
*a
= *prevp
;
870 prevp
= &a
->alias_chain
;
873 *prevp
= iter
->alias_chain
;
878 /* We won't see another command with the same name. */
882 previous_chain_ptr
= &iter
->next
;
888 /* Shorthands to the commands above. */
890 /* Add an element to the list of info subcommands. */
892 struct cmd_list_element
*
893 add_info (const char *name
, cmd_const_cfunc_ftype
*fun
, const char *doc
)
895 return add_cmd (name
, class_info
, fun
, doc
, &infolist
);
898 /* Add an alias to the list of info subcommands. */
900 struct cmd_list_element
*
901 add_info_alias (const char *name
, const char *oldname
, int abbrev_flag
)
903 return add_alias_cmd (name
, oldname
, class_run
, abbrev_flag
, &infolist
);
906 /* Add an element to the list of commands. */
908 struct cmd_list_element
*
909 add_com (const char *name
, enum command_class theclass
,
910 cmd_const_cfunc_ftype
*fun
,
913 return add_cmd (name
, theclass
, fun
, doc
, &cmdlist
);
916 /* Add an alias or abbreviation command to the list of commands. */
918 struct cmd_list_element
*
919 add_com_alias (const char *name
, const char *oldname
, enum command_class theclass
,
922 return add_alias_cmd (name
, oldname
, theclass
, abbrev_flag
, &cmdlist
);
925 /* Add an element with a suppress notification to the list of commands. */
927 struct cmd_list_element
*
928 add_com_suppress_notification (const char *name
, enum command_class theclass
,
929 cmd_const_cfunc_ftype
*fun
, const char *doc
,
930 int *suppress_notification
)
932 return add_cmd_suppress_notification (name
, theclass
, fun
, doc
,
933 &cmdlist
, suppress_notification
);
936 /* Recursively walk the commandlist structures, and print out the
937 documentation of commands that match our regex in either their
938 name, or their documentation.
941 apropos_cmd (struct ui_file
*stream
,
942 struct cmd_list_element
*commandlist
,
943 compiled_regex
®ex
, const char *prefix
)
945 struct cmd_list_element
*c
;
948 /* Walk through the commands. */
949 for (c
=commandlist
;c
;c
=c
->next
)
951 returnvalue
= -1; /* Needed to avoid double printing. */
954 size_t name_len
= strlen (c
->name
);
956 /* Try to match against the name. */
957 returnvalue
= regex
.search (c
->name
, name_len
, 0, name_len
, NULL
);
958 if (returnvalue
>= 0)
960 print_help_for_command (c
, prefix
,
961 0 /* don't recurse */, stream
);
964 if (c
->doc
!= NULL
&& returnvalue
< 0)
966 size_t doc_len
= strlen (c
->doc
);
968 /* Try to match against documentation. */
969 if (regex
.search (c
->doc
, doc_len
, 0, doc_len
, NULL
) >= 0)
971 print_help_for_command (c
, prefix
,
972 0 /* don't recurse */, stream
);
975 /* Check if this command has subcommands and is not an
976 abbreviation. We skip listing subcommands of abbreviations
977 in order to avoid duplicates in the output. */
978 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
980 /* Recursively call ourselves on the subcommand list,
981 passing the right prefix in. */
982 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
987 /* This command really has to deal with two things:
988 1) I want documentation on *this string* (usually called by
991 2) I want documentation on *this list* (usually called by giving a
992 command that requires subcommands. Also called by saying just
995 I am going to split this into two seperate comamnds, help_cmd and
999 help_cmd (const char *command
, struct ui_file
*stream
)
1001 struct cmd_list_element
*c
;
1005 help_list (cmdlist
, "", all_classes
, stream
);
1009 if (strcmp (command
, "all") == 0)
1015 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
1020 /* There are three cases here.
1021 If c->prefixlist is nonzero, we have a prefix command.
1022 Print its documentation, then list its subcommands.
1024 If c->func is non NULL, we really have a command. Print its
1025 documentation and return.
1027 If c->func is NULL, we have a class name. Print its
1028 documentation (as if it were a command) and then set class to the
1029 number of this class so that the commands in the class will be
1032 fputs_filtered (c
->doc
, stream
);
1033 fputs_filtered ("\n", stream
);
1035 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
1037 fprintf_filtered (stream
, "\n");
1039 /* If this is a prefix command, print it's subcommands. */
1041 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
1043 /* If this is a class name, print all of the commands in the class. */
1044 if (c
->func
== NULL
)
1045 help_list (cmdlist
, "", c
->theclass
, stream
);
1047 if (c
->hook_pre
|| c
->hook_post
)
1048 fprintf_filtered (stream
,
1049 "\nThis command has a hook (or hooks) defined:\n");
1052 fprintf_filtered (stream
,
1053 "\tThis command is run after : %s (pre hook)\n",
1056 fprintf_filtered (stream
,
1057 "\tThis command is run before : %s (post hook)\n",
1058 c
->hook_post
->name
);
1062 * Get a specific kind of help on a command list.
1065 * CMDTYPE is the prefix to use in the title string.
1066 * CLASS is the class with which to list the nodes of this list (see
1067 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
1068 * everything, ALL_CLASSES for just classes, and non-negative for only things
1069 * in a specific class.
1070 * and STREAM is the output stream on which to print things.
1071 * If you call this routine with a class >= 0, it recurses.
1074 help_list (struct cmd_list_element
*list
, const char *cmdtype
,
1075 enum command_class theclass
, struct ui_file
*stream
)
1078 char *cmdtype1
, *cmdtype2
;
1080 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
1082 len
= strlen (cmdtype
);
1083 cmdtype1
= (char *) alloca (len
+ 1);
1085 cmdtype2
= (char *) alloca (len
+ 4);
1090 memcpy (cmdtype1
+ 1, cmdtype
, len
- 1);
1092 memcpy (cmdtype2
, cmdtype
, len
- 1);
1093 strcpy (cmdtype2
+ len
- 1, " sub");
1096 if (theclass
== all_classes
)
1097 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
1099 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
1101 help_cmd_list (list
, theclass
, cmdtype
, (int) theclass
>= 0, stream
);
1103 if (theclass
== all_classes
)
1105 fprintf_filtered (stream
, "\n\
1106 Type \"help%s\" followed by a class name for a list of commands in ",
1109 fprintf_filtered (stream
, "that class.");
1111 fprintf_filtered (stream
, "\n\
1112 Type \"help all\" for the list of all commands.");
1115 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
1116 cmdtype1
, cmdtype2
);
1118 fputs_filtered ("for ", stream
);
1120 fputs_filtered ("full ", stream
);
1122 fputs_filtered ("documentation.\n", stream
);
1123 fputs_filtered ("Type \"apropos word\" to search "
1124 "for commands related to \"word\".\n", stream
);
1125 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
1130 help_all (struct ui_file
*stream
)
1132 struct cmd_list_element
*c
;
1133 int seen_unclassified
= 0;
1135 for (c
= cmdlist
; c
; c
= c
->next
)
1139 /* If this is a class name, print all of the commands in the
1142 if (c
->func
== NULL
)
1144 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
1145 help_cmd_list (cmdlist
, c
->theclass
, "", 1, stream
);
1149 /* While it's expected that all commands are in some class,
1150 as a safety measure, we'll print commands outside of any
1151 class at the end. */
1153 for (c
= cmdlist
; c
; c
= c
->next
)
1158 if (c
->theclass
== no_class
)
1160 if (!seen_unclassified
)
1162 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
1163 seen_unclassified
= 1;
1165 print_help_for_command (c
, "", 1, stream
);
1171 /* Print only the first line of STR on STREAM. */
1173 print_doc_line (struct ui_file
*stream
, const char *str
)
1175 static char *line_buffer
= 0;
1176 static int line_size
;
1182 line_buffer
= (char *) xmalloc (line_size
);
1185 /* Keep printing '.' or ',' not followed by a whitespace for embedded strings
1188 while (*p
&& *p
!= '\n'
1189 && ((*p
!= '.' && *p
!= ',') || (p
[1] && !isspace (p
[1]))))
1191 if (p
- str
> line_size
- 1)
1193 line_size
= p
- str
+ 1;
1194 xfree (line_buffer
);
1195 line_buffer
= (char *) xmalloc (line_size
);
1197 strncpy (line_buffer
, str
, p
- str
);
1198 line_buffer
[p
- str
] = '\0';
1199 if (islower (line_buffer
[0]))
1200 line_buffer
[0] = toupper (line_buffer
[0]);
1201 fputs_filtered (line_buffer
, stream
);
1204 /* Print one-line help for command C.
1205 If RECURSE is non-zero, also print one-line descriptions
1206 of all prefixed subcommands. */
1208 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
1209 int recurse
, struct ui_file
*stream
)
1211 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1212 print_doc_line (stream
, c
->doc
);
1213 fputs_filtered ("\n", stream
);
1216 && c
->prefixlist
!= 0
1217 && c
->abbrev_flag
== 0)
1218 /* Subcommands of a prefix command typically have 'all_commands'
1219 as class. If we pass CLASS to recursive invocation,
1220 most often we won't see anything. */
1221 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1225 * Implement a help command on command list LIST.
1226 * RECURSE should be non-zero if this should be done recursively on
1227 * all sublists of LIST.
1228 * PREFIX is the prefix to print before each command name.
1229 * STREAM is the stream upon which the output should be written.
1230 * THECLASS should be:
1231 * A non-negative class number to list only commands in that
1233 * ALL_COMMANDS to list all commands in list.
1234 * ALL_CLASSES to list all classes in list.
1236 * Note that RECURSE will be active on *all* sublists, not just the
1237 * ones selected by the criteria above (ie. the selection mechanism
1238 * is at the low level, not the high-level).
1241 help_cmd_list (struct cmd_list_element
*list
, enum command_class theclass
,
1242 const char *prefix
, int recurse
, struct ui_file
*stream
)
1244 struct cmd_list_element
*c
;
1246 for (c
= list
; c
; c
= c
->next
)
1248 if (c
->abbrev_flag
== 0
1249 && !c
->cmd_deprecated
1250 && (theclass
== all_commands
1251 || (theclass
== all_classes
&& c
->func
== NULL
)
1252 || (theclass
== c
->theclass
&& c
->func
!= NULL
)))
1254 print_help_for_command (c
, prefix
, recurse
, stream
);
1256 else if (c
->abbrev_flag
== 0
1258 && !c
->cmd_deprecated
1259 && theclass
== class_user
&& c
->prefixlist
!= NULL
)
1260 /* User-defined commands may be subcommands. */
1261 help_cmd_list (*c
->prefixlist
, theclass
, c
->prefixname
,
1267 /* Search the input clist for 'command'. Return the command if
1268 found (or NULL if not), and return the number of commands
1271 static struct cmd_list_element
*
1272 find_cmd (const char *command
, int len
, struct cmd_list_element
*clist
,
1273 int ignore_help_classes
, int *nfound
)
1275 struct cmd_list_element
*found
, *c
;
1279 for (c
= clist
; c
; c
= c
->next
)
1280 if (!strncmp (command
, c
->name
, len
)
1281 && (!ignore_help_classes
|| c
->func
))
1285 if (c
->name
[len
] == '\0')
1294 /* Return the length of command name in TEXT. */
1297 find_command_name_length (const char *text
)
1299 const char *p
= text
;
1301 /* Treating underscores as part of command words is important
1302 so that "set args_foo()" doesn't get interpreted as
1303 "set args _foo()". */
1304 /* Some characters are only used for TUI specific commands.
1305 However, they are always allowed for the sake of consistency.
1307 Note that this is larger than the character set allowed when
1308 creating user-defined commands. */
1310 /* Recognize '!' as a single character command so that, e.g., "!ls"
1311 works as expected. */
1315 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1316 /* Characters used by TUI specific commands. */
1317 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')
1323 /* Return TRUE if NAME is a valid user-defined command name.
1324 This is a stricter subset of all gdb commands,
1325 see find_command_name_length. */
1328 valid_user_defined_cmd_name_p (const char *name
)
1335 /* Alas "42" is a legitimate user-defined command.
1336 In the interests of not breaking anything we preserve that. */
1338 for (p
= name
; *p
!= '\0'; ++p
)
1351 /* This routine takes a line of TEXT and a CLIST in which to start the
1352 lookup. When it returns it will have incremented the text pointer past
1353 the section of text it matched, set *RESULT_LIST to point to the list in
1354 which the last word was matched, and will return a pointer to the cmd
1355 list element which the text matches. It will return NULL if no match at
1356 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1357 matches are possible; in this case *RESULT_LIST will be set to point to
1358 the list in which there are ambiguous choices (and *TEXT will be set to
1359 the ambiguous text string).
1361 If the located command was an abbreviation, this routine returns the base
1362 command of the abbreviation.
1364 It does no error reporting whatsoever; control will always return
1365 to the superior routine.
1367 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1368 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1369 if no prefix command was ever found. For example, in the case of "info a",
1370 "info" matches without ambiguity, but "a" could be "args" or "address", so
1371 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1372 RESULT_LIST should not be interpreted as a pointer to the beginning of a
1373 list; it simply points to a specific command. In the case of an ambiguous
1374 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1375 "info t" can be "info types" or "info target"; upon return *TEXT has been
1376 advanced past "info ").
1378 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1379 affect the operation).
1381 This routine does *not* modify the text pointed to by TEXT.
1383 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1384 are actually help classes rather than commands (i.e. the function field of
1385 the struct cmd_list_element is NULL). */
1387 struct cmd_list_element
*
1388 lookup_cmd_1 (const char **text
, struct cmd_list_element
*clist
,
1389 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1393 struct cmd_list_element
*found
, *c
;
1394 const char *line
= *text
;
1396 while (**text
== ' ' || **text
== '\t')
1399 /* Identify the name of the command. */
1400 len
= find_command_name_length (*text
);
1402 /* If nothing but whitespace, return 0. */
1406 /* *text and p now bracket the first command word to lookup (and
1407 it's length is len). We copy this into a local temporary. */
1410 command
= (char *) alloca (len
+ 1);
1411 memcpy (command
, *text
, len
);
1412 command
[len
] = '\0';
1417 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1419 /* If nothing matches, we have a simple failure. */
1425 if (result_list
!= NULL
)
1426 /* Will be modified in calling routine
1427 if we know what the prefix command is. */
1429 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1432 /* We've matched something on this list. Move text pointer forward. */
1436 if (found
->cmd_pointer
)
1438 /* We drop the alias (abbreviation) in favor of the command it
1439 is pointing to. If the alias is deprecated, though, we need to
1440 warn the user about it before we drop it. Note that while we
1441 are warning about the alias, we may also warn about the command
1442 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1445 if (found
->deprecated_warn_user
)
1446 deprecated_cmd_warning (line
);
1447 found
= found
->cmd_pointer
;
1449 /* If we found a prefix command, keep looking. */
1451 if (found
->prefixlist
)
1453 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1454 ignore_help_classes
);
1457 /* Didn't find anything; this is as far as we got. */
1458 if (result_list
!= NULL
)
1459 *result_list
= clist
;
1462 else if (c
== CMD_LIST_AMBIGUOUS
)
1464 /* We've gotten this far properly, but the next step is
1465 ambiguous. We need to set the result list to the best
1466 we've found (if an inferior hasn't already set it). */
1467 if (result_list
!= NULL
)
1469 /* This used to say *result_list = *found->prefixlist.
1470 If that was correct, need to modify the documentation
1471 at the top of this function to clarify what is
1472 supposed to be going on. */
1473 *result_list
= found
;
1484 if (result_list
!= NULL
)
1485 *result_list
= clist
;
1490 /* All this hair to move the space to the front of cmdtype */
1493 undef_cmd_error (const char *cmdtype
, const char *q
)
1495 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1498 *cmdtype
? " " : "",
1499 (int) strlen (cmdtype
) - 1,
1503 /* Look up the contents of *LINE as a command in the command list LIST.
1504 LIST is a chain of struct cmd_list_element's.
1505 If it is found, return the struct cmd_list_element for that command
1506 and update *LINE to point after the command name, at the first argument.
1507 If not found, call error if ALLOW_UNKNOWN is zero
1508 otherwise (or if error returns) return zero.
1509 Call error if specified command is ambiguous,
1510 unless ALLOW_UNKNOWN is negative.
1511 CMDTYPE precedes the word "command" in the error message.
1513 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1514 elements which are actually help classes rather than commands (i.e.
1515 the function field of the struct cmd_list_element is 0). */
1517 struct cmd_list_element
*
1518 lookup_cmd (const char **line
, struct cmd_list_element
*list
,
1519 const char *cmdtype
,
1520 int allow_unknown
, int ignore_help_classes
)
1522 struct cmd_list_element
*last_list
= 0;
1523 struct cmd_list_element
*c
;
1525 /* Note: Do not remove trailing whitespace here because this
1526 would be wrong for complete_command. Jim Kingdon */
1529 error (_("Lack of needed %scommand"), cmdtype
);
1531 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1538 int len
= find_command_name_length (*line
);
1540 q
= (char *) alloca (len
+ 1);
1541 strncpy (q
, *line
, len
);
1543 undef_cmd_error (cmdtype
, q
);
1548 else if (c
== CMD_LIST_AMBIGUOUS
)
1550 /* Ambigous. Local values should be off prefixlist or called
1552 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1554 const char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1555 struct cmd_list_element
*local_list
=
1556 (last_list
? *(last_list
->prefixlist
) : list
);
1558 if (local_allow_unknown
< 0)
1561 return last_list
; /* Found something. */
1563 return 0; /* Found nothing. */
1567 /* Report as error. */
1572 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1573 && (*line
)[amb_len
] != '\t');
1578 for (c
= local_list
; c
; c
= c
->next
)
1579 if (!strncmp (*line
, c
->name
, amb_len
))
1581 if (strlen (ambbuf
) + strlen (c
->name
) + 6
1582 < (int) sizeof ambbuf
)
1584 if (strlen (ambbuf
))
1585 strcat (ambbuf
, ", ");
1586 strcat (ambbuf
, c
->name
);
1590 strcat (ambbuf
, "..");
1594 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1600 if (c
->type
== set_cmd
&& **line
!= '\0' && !isspace (**line
))
1601 error (_("Argument must be preceded by space."));
1603 /* We've got something. It may still not be what the caller
1604 wants (if this command *needs* a subcommand). */
1605 while (**line
== ' ' || **line
== '\t')
1608 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1609 undef_cmd_error (c
->prefixname
, *line
);
1611 /* Seems to be what he wants. Return it. */
1617 /* We are here presumably because an alias or command in TEXT is
1618 deprecated and a warning message should be generated. This
1619 function decodes TEXT and potentially generates a warning message
1622 Example for 'set endian big' which has a fictitious alias 'seb'.
1624 If alias wasn't used in TEXT, and the command is deprecated:
1625 "warning: 'set endian big' is deprecated."
1627 If alias was used, and only the alias is deprecated:
1628 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1630 If alias was used and command is deprecated (regardless of whether
1631 the alias itself is deprecated:
1633 "warning: 'set endian big' (seb) is deprecated."
1635 After the message has been sent, clear the appropriate flags in the
1636 command and/or the alias so the user is no longer bothered.
1640 deprecated_cmd_warning (const char *text
)
1642 struct cmd_list_element
*alias
= NULL
;
1643 struct cmd_list_element
*prefix_cmd
= NULL
;
1644 struct cmd_list_element
*cmd
= NULL
;
1646 if (!lookup_cmd_composition (text
, &alias
, &prefix_cmd
, &cmd
))
1647 /* Return if text doesn't evaluate to a command. */
1650 if (!((alias
? alias
->deprecated_warn_user
: 0)
1651 || cmd
->deprecated_warn_user
) )
1652 /* Return if nothing is deprecated. */
1655 printf_filtered ("Warning:");
1657 if (alias
&& !cmd
->cmd_deprecated
)
1658 printf_filtered (" '%s', an alias for the", alias
->name
);
1660 printf_filtered (" command '");
1663 printf_filtered ("%s", prefix_cmd
->prefixname
);
1665 printf_filtered ("%s", cmd
->name
);
1667 if (alias
&& cmd
->cmd_deprecated
)
1668 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1670 printf_filtered ("' is deprecated.\n");
1673 /* If it is only the alias that is deprecated, we want to indicate
1674 the new alias, otherwise we'll indicate the new command. */
1676 if (alias
&& !cmd
->cmd_deprecated
)
1678 if (alias
->replacement
)
1679 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1681 printf_filtered ("No alternative known.\n\n");
1685 if (cmd
->replacement
)
1686 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1688 printf_filtered ("No alternative known.\n\n");
1691 /* We've warned you, now we'll keep quiet. */
1693 alias
->deprecated_warn_user
= 0;
1695 cmd
->deprecated_warn_user
= 0;
1699 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1700 Return 1 on success, 0 on failure.
1702 If LINE refers to an alias, *alias will point to that alias.
1704 If LINE is a postfix command (i.e. one that is preceded by a prefix
1705 command) set *prefix_cmd.
1707 Set *cmd to point to the command LINE indicates.
1709 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1710 exist, they are NULL when we return.
1714 lookup_cmd_composition (const char *text
,
1715 struct cmd_list_element
**alias
,
1716 struct cmd_list_element
**prefix_cmd
,
1717 struct cmd_list_element
**cmd
)
1721 struct cmd_list_element
*cur_list
;
1722 struct cmd_list_element
*prev_cmd
;
1732 /* Go through as many command lists as we need to,
1733 to find the command TEXT refers to. */
1737 while (*text
== ' ' || *text
== '\t')
1740 /* Identify the name of the command. */
1741 len
= find_command_name_length (text
);
1743 /* If nothing but whitespace, return. */
1747 /* Text is the start of the first command word to lookup (and
1748 it's length is len). We copy this into a local temporary. */
1750 command
= (char *) alloca (len
+ 1);
1751 memcpy (command
, text
, len
);
1752 command
[len
] = '\0';
1757 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1759 if (*cmd
== CMD_LIST_AMBIGUOUS
)
1761 return 0; /* ambiguous */
1765 return 0; /* nothing found */
1768 if ((*cmd
)->cmd_pointer
)
1770 /* cmd was actually an alias, we note that an alias was
1771 used (by assigning *alais) and we set *cmd. */
1773 *cmd
= (*cmd
)->cmd_pointer
;
1775 *prefix_cmd
= prev_cmd
;
1777 if ((*cmd
)->prefixlist
)
1778 cur_list
= *(*cmd
)->prefixlist
;
1786 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1788 /* Return a vector of char pointers which point to the different
1789 possible completions in LIST of TEXT.
1791 WORD points in the same buffer as TEXT, and completions should be
1792 returned relative to this position. For example, suppose TEXT is
1793 "foo" and we want to complete to "foobar". If WORD is "oo", return
1794 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1797 complete_on_cmdlist (struct cmd_list_element
*list
,
1798 completion_tracker
&tracker
,
1799 const char *text
, const char *word
,
1800 int ignore_help_classes
)
1802 struct cmd_list_element
*ptr
;
1803 int textlen
= strlen (text
);
1805 int saw_deprecated_match
= 0;
1807 /* We do one or two passes. In the first pass, we skip deprecated
1808 commands. If we see no matching commands in the first pass, and
1809 if we did happen to see a matching deprecated command, we do
1810 another loop to collect those. */
1811 for (pass
= 0; pass
< 2; ++pass
)
1813 bool got_matches
= false;
1815 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1816 if (!strncmp (ptr
->name
, text
, textlen
)
1817 && !ptr
->abbrev_flag
1818 && (!ignore_help_classes
|| ptr
->func
1819 || ptr
->prefixlist
))
1823 if (ptr
->cmd_deprecated
)
1825 saw_deprecated_match
= 1;
1830 tracker
.add_completion
1831 (make_completion_match_str (ptr
->name
, text
, word
));
1838 /* If we saw no matching deprecated commands in the first pass,
1840 if (!saw_deprecated_match
)
1845 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1847 /* Add the different possible completions in ENUMLIST of TEXT.
1849 WORD points in the same buffer as TEXT, and completions should be
1850 returned relative to this position. For example, suppose TEXT is "foo"
1851 and we want to complete to "foobar". If WORD is "oo", return
1852 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1855 complete_on_enum (completion_tracker
&tracker
,
1856 const char *const *enumlist
,
1857 const char *text
, const char *word
)
1859 int textlen
= strlen (text
);
1863 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1864 if (strncmp (name
, text
, textlen
) == 0)
1865 tracker
.add_completion (make_completion_match_str (name
, text
, word
));
1869 /* Check function pointer. */
1871 cmd_func_p (struct cmd_list_element
*cmd
)
1873 return (cmd
->func
!= NULL
);
1877 /* Call the command function. */
1879 cmd_func (struct cmd_list_element
*cmd
, const char *args
, int from_tty
)
1881 if (cmd_func_p (cmd
))
1883 gdb::optional
<scoped_restore_tmpl
<int>> restore_suppress
;
1885 if (cmd
->suppress_notification
!= NULL
)
1886 restore_suppress
.emplace (cmd
->suppress_notification
, 1);
1888 (*cmd
->func
) (cmd
, args
, from_tty
);
1891 error (_("Invalid command"));
1895 cli_user_command_p (struct cmd_list_element
*cmd
)
1897 return (cmd
->theclass
== class_user
1898 && (cmd
->func
== do_const_cfunc
|| cmd
->func
== do_sfunc
));