1 /* Handle lists of commands, their decoding and documentation, for GDB.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "gdb_regex.h"
22 #include "completer.h"
24 #include "cli/cli-cmds.h"
25 #include "cli/cli-decode.h"
26 #include "common/gdb_optional.h"
28 /* Prototypes for local functions. */
30 static void undef_cmd_error (const char *, const char *);
32 static struct cmd_list_element
*delete_cmd (const char *name
,
33 struct cmd_list_element
**list
,
34 struct cmd_list_element
**prehook
,
35 struct cmd_list_element
**prehookee
,
36 struct cmd_list_element
**posthook
,
37 struct cmd_list_element
**posthookee
);
39 static struct cmd_list_element
*find_cmd (const char *command
,
41 struct cmd_list_element
*clist
,
42 int ignore_help_classes
,
45 static void help_all (struct ui_file
*stream
);
47 /* Look up a command whose 'prefixlist' is KEY. Return the command if found,
48 otherwise return NULL. */
50 static struct cmd_list_element
*
51 lookup_cmd_for_prefixlist (struct cmd_list_element
**key
,
52 struct cmd_list_element
*list
)
54 struct cmd_list_element
*p
= NULL
;
56 for (p
= list
; p
!= NULL
; p
= p
->next
)
58 struct cmd_list_element
*q
;
60 if (p
->prefixlist
== NULL
)
62 else if (p
->prefixlist
== key
)
65 q
= lookup_cmd_for_prefixlist (key
, *(p
->prefixlist
));
74 set_cmd_prefix (struct cmd_list_element
*c
, struct cmd_list_element
**list
)
76 struct cmd_list_element
*p
;
78 /* Check to see if *LIST contains any element other than C. */
79 for (p
= *list
; p
!= NULL
; p
= p
->next
)
85 /* *SET_LIST only contains SET. */
86 p
= lookup_cmd_for_prefixlist (list
, setlist
);
88 c
->prefix
= p
? (p
->cmd_pointer
? p
->cmd_pointer
: p
) : p
;
91 c
->prefix
= p
->prefix
;
95 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
96 int recurse
, struct ui_file
*stream
);
99 /* Set the callback function for the specified command. For each both
100 the commands callback and func() are set. The latter set to a
101 bounce function (unless cfunc / sfunc is NULL that is). */
104 do_const_cfunc (struct cmd_list_element
*c
, 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
, char *args
, int from_tty
)
122 c
->function
.sfunc (args
, from_tty
, c
);
126 set_cmd_sfunc (struct cmd_list_element
*cmd
, cmd_sfunc_ftype
*sfunc
)
131 cmd
->func
= do_sfunc
;
132 cmd
->function
.sfunc
= sfunc
;
136 cmd_cfunc_eq (struct cmd_list_element
*cmd
, cmd_const_cfunc_ftype
*cfunc
)
138 return cmd
->func
== do_const_cfunc
&& cmd
->function
.const_cfunc
== cfunc
;
142 set_cmd_context (struct cmd_list_element
*cmd
, void *context
)
144 cmd
->context
= context
;
148 get_cmd_context (struct cmd_list_element
*cmd
)
154 cmd_type (struct cmd_list_element
*cmd
)
160 set_cmd_completer (struct cmd_list_element
*cmd
, completer_ftype
*completer
)
162 cmd
->completer
= completer
; /* Ok. */
165 /* See definition in commands.h. */
168 set_cmd_completer_handle_brkchars (struct cmd_list_element
*cmd
,
169 completer_handle_brkchars_ftype
*func
)
171 cmd
->completer_handle_brkchars
= func
;
174 /* Add element named NAME.
175 Space for NAME and DOC must be allocated by the caller.
176 CLASS is the top level category into which commands are broken down
178 FUN should be the function to execute the command;
179 it will get a character string as argument, with leading
180 and trailing blanks already eliminated.
182 DOC is a documentation string for the command.
183 Its first line should be a complete sentence.
184 It should start with ? for a command that is an abbreviation
185 or with * for a command that most users don't need to know about.
187 Add this command to command list *LIST.
189 Returns a pointer to the added command (not necessarily the head
192 static struct cmd_list_element
*
193 do_add_cmd (const char *name
, enum command_class theclass
,
194 const char *doc
, struct cmd_list_element
**list
)
196 struct cmd_list_element
*c
= XNEW (struct cmd_list_element
);
197 struct cmd_list_element
*p
, *iter
;
199 /* Turn each alias of the old command into an alias of the new
201 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
202 &c
->hook_post
, &c
->hookee_post
);
203 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
204 iter
->cmd_pointer
= c
;
206 c
->hook_pre
->hookee_pre
= c
;
208 c
->hookee_pre
->hook_pre
= c
;
210 c
->hook_post
->hookee_post
= c
;
212 c
->hookee_post
->hook_post
= c
;
214 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
222 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
231 c
->theclass
= theclass
;
232 set_cmd_context (c
, NULL
);
234 c
->cmd_deprecated
= 0;
235 c
->deprecated_warn_user
= 0;
236 c
->malloced_replacement
= 0;
237 c
->doc_allocated
= 0;
238 c
->replacement
= NULL
;
239 c
->pre_show_hook
= NULL
;
241 c
->prefixlist
= NULL
;
242 c
->prefixname
= NULL
;
243 c
->allow_unknown
= 0;
246 set_cmd_completer (c
, symbol_completer
);
247 c
->completer_handle_brkchars
= NULL
;
249 c
->type
= not_set_cmd
;
251 c
->var_type
= var_boolean
;
253 c
->user_commands
= NULL
;
254 c
->cmd_pointer
= NULL
;
255 c
->alias_chain
= NULL
;
256 c
->suppress_notification
= NULL
;
261 struct cmd_list_element
*
262 add_cmd (const char *name
, enum command_class theclass
,
263 const char *doc
, struct cmd_list_element
**list
)
265 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
267 result
->function
.const_cfunc
= NULL
;
271 struct cmd_list_element
*
272 add_cmd (const char *name
, enum command_class theclass
,
273 cmd_const_cfunc_ftype
*fun
,
274 const char *doc
, struct cmd_list_element
**list
)
276 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
277 set_cmd_cfunc (result
, fun
);
281 /* Deprecates a command CMD.
282 REPLACEMENT is the name of the command which should be used in
283 place of this command, or NULL if no such command exists.
285 This function does not check to see if command REPLACEMENT exists
286 since gdb may not have gotten around to adding REPLACEMENT when
287 this function is called.
289 Returns a pointer to the deprecated command. */
291 struct cmd_list_element
*
292 deprecate_cmd (struct cmd_list_element
*cmd
, const char *replacement
)
294 cmd
->cmd_deprecated
= 1;
295 cmd
->deprecated_warn_user
= 1;
297 if (replacement
!= NULL
)
298 cmd
->replacement
= replacement
;
300 cmd
->replacement
= NULL
;
305 struct cmd_list_element
*
306 add_alias_cmd (const char *name
, cmd_list_element
*old
,
307 enum command_class theclass
, int abbrev_flag
,
308 struct cmd_list_element
**list
)
312 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
313 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
314 &prehook
, &prehookee
,
315 &posthook
, &posthookee
);
317 /* If this happens, it means a programmer error somewhere. */
318 gdb_assert (!aliases
&& !prehook
&& !prehookee
319 && !posthook
&& ! posthookee
);
323 struct cmd_list_element
*c
= add_cmd (name
, theclass
, old
->doc
, list
);
325 /* If OLD->DOC can be freed, we should make another copy. */
326 if (old
->doc_allocated
)
328 c
->doc
= xstrdup (old
->doc
);
329 c
->doc_allocated
= 1;
331 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
333 c
->function
= old
->function
;
334 c
->prefixlist
= old
->prefixlist
;
335 c
->prefixname
= old
->prefixname
;
336 c
->allow_unknown
= old
->allow_unknown
;
337 c
->abbrev_flag
= abbrev_flag
;
338 c
->cmd_pointer
= old
;
339 c
->alias_chain
= old
->aliases
;
342 set_cmd_prefix (c
, list
);
346 struct cmd_list_element
*
347 add_alias_cmd (const char *name
, const char *oldname
,
348 enum command_class theclass
, int abbrev_flag
,
349 struct cmd_list_element
**list
)
352 struct cmd_list_element
*old
;
355 old
= lookup_cmd (&tmp
, *list
, "", 1, 1);
357 return add_alias_cmd (name
, old
, theclass
, abbrev_flag
, list
);
361 /* Like add_cmd but adds an element for a command prefix: a name that
362 should be followed by a subcommand to be looked up in another
363 command list. PREFIXLIST should be the address of the variable
364 containing that list. */
366 struct cmd_list_element
*
367 add_prefix_cmd (const char *name
, enum command_class theclass
,
368 cmd_const_cfunc_ftype
*fun
,
369 const char *doc
, struct cmd_list_element
**prefixlist
,
370 const char *prefixname
, int allow_unknown
,
371 struct cmd_list_element
**list
)
373 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
374 struct cmd_list_element
*p
;
376 c
->prefixlist
= prefixlist
;
377 c
->prefixname
= prefixname
;
378 c
->allow_unknown
= allow_unknown
;
380 if (list
== &cmdlist
)
383 set_cmd_prefix (c
, list
);
385 /* Update the field 'prefix' of each cmd_list_element in *PREFIXLIST. */
386 for (p
= *prefixlist
; p
!= NULL
; p
= p
->next
)
392 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
394 struct cmd_list_element
*
395 add_abbrev_prefix_cmd (const char *name
, enum command_class theclass
,
396 cmd_const_cfunc_ftype
*fun
, const char *doc
,
397 struct cmd_list_element
**prefixlist
,
398 const char *prefixname
,
399 int allow_unknown
, struct cmd_list_element
**list
)
401 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
403 c
->prefixlist
= prefixlist
;
404 c
->prefixname
= prefixname
;
405 c
->allow_unknown
= allow_unknown
;
410 /* This is an empty "cfunc". */
412 not_just_help_class_command (const char *args
, int from_tty
)
416 /* This is an empty "sfunc". */
417 static void empty_sfunc (char *, int, struct cmd_list_element
*);
420 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
424 /* Add element named NAME to command list LIST (the list for set/show
425 or some sublist thereof).
426 TYPE is set_cmd or show_cmd.
427 CLASS is as in add_cmd.
428 VAR_TYPE is the kind of thing we are setting.
429 VAR is address of the variable being controlled by this command.
430 DOC is the documentation string. */
432 static struct cmd_list_element
*
433 add_set_or_show_cmd (const char *name
,
435 enum command_class theclass
,
439 struct cmd_list_element
**list
)
441 struct cmd_list_element
*c
= add_cmd (name
, theclass
, doc
, list
);
443 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
445 c
->var_type
= var_type
;
447 /* This needs to be something besides NULL so that this isn't
448 treated as a help class. */
449 set_cmd_sfunc (c
, empty_sfunc
);
453 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
454 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
455 setting. VAR is address of the variable being controlled by this
456 command. SET_FUNC and SHOW_FUNC are the callback functions (if
457 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
458 strings. PRINT the format string to print the value. SET_RESULT
459 and SHOW_RESULT, if not NULL, are set to the resulting command
463 add_setshow_cmd_full (const char *name
,
464 enum command_class theclass
,
465 var_types var_type
, void *var
,
466 const char *set_doc
, const char *show_doc
,
467 const char *help_doc
,
468 cmd_sfunc_ftype
*set_func
,
469 show_value_ftype
*show_func
,
470 struct cmd_list_element
**set_list
,
471 struct cmd_list_element
**show_list
,
472 struct cmd_list_element
**set_result
,
473 struct cmd_list_element
**show_result
)
475 struct cmd_list_element
*set
;
476 struct cmd_list_element
*show
;
480 if (help_doc
!= NULL
)
482 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
483 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
487 full_set_doc
= xstrdup (set_doc
);
488 full_show_doc
= xstrdup (show_doc
);
490 set
= add_set_or_show_cmd (name
, set_cmd
, theclass
, var_type
, var
,
491 full_set_doc
, set_list
);
492 set
->doc_allocated
= 1;
494 if (set_func
!= NULL
)
495 set_cmd_sfunc (set
, set_func
);
497 set_cmd_prefix (set
, set_list
);
499 show
= add_set_or_show_cmd (name
, show_cmd
, theclass
, var_type
, var
,
500 full_show_doc
, show_list
);
501 show
->doc_allocated
= 1;
502 show
->show_value_func
= show_func
;
504 if (set_result
!= NULL
)
506 if (show_result
!= NULL
)
510 /* Add element named NAME to command list LIST (the list for set or
511 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
512 of strings which may follow NAME. VAR is address of the variable
513 which will contain the matching string (from ENUMLIST). */
516 add_setshow_enum_cmd (const char *name
,
517 enum command_class theclass
,
518 const char *const *enumlist
,
521 const char *show_doc
,
522 const char *help_doc
,
523 cmd_sfunc_ftype
*set_func
,
524 show_value_ftype
*show_func
,
525 struct cmd_list_element
**set_list
,
526 struct cmd_list_element
**show_list
)
528 struct cmd_list_element
*c
;
530 add_setshow_cmd_full (name
, theclass
, var_enum
, var
,
531 set_doc
, show_doc
, help_doc
,
538 const char * const auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
540 /* Add an auto-boolean command named NAME to both the set and show
541 command list lists. CLASS is as in add_cmd. VAR is address of the
542 variable which will contain the value. DOC is the documentation
543 string. FUNC is the corresponding callback. */
545 add_setshow_auto_boolean_cmd (const char *name
,
546 enum command_class theclass
,
547 enum auto_boolean
*var
,
548 const char *set_doc
, const char *show_doc
,
549 const char *help_doc
,
550 cmd_sfunc_ftype
*set_func
,
551 show_value_ftype
*show_func
,
552 struct cmd_list_element
**set_list
,
553 struct cmd_list_element
**show_list
)
555 struct cmd_list_element
*c
;
557 add_setshow_cmd_full (name
, theclass
, var_auto_boolean
, var
,
558 set_doc
, show_doc
, help_doc
,
562 c
->enums
= auto_boolean_enums
;
565 /* Add element named NAME to both the set and show command LISTs (the
566 list for set/show or some sublist thereof). CLASS is as in
567 add_cmd. VAR is address of the variable which will contain the
568 value. SET_DOC and SHOW_DOC are the documentation strings. */
570 add_setshow_boolean_cmd (const char *name
, enum command_class theclass
, int *var
,
571 const char *set_doc
, const char *show_doc
,
572 const char *help_doc
,
573 cmd_sfunc_ftype
*set_func
,
574 show_value_ftype
*show_func
,
575 struct cmd_list_element
**set_list
,
576 struct cmd_list_element
**show_list
)
578 static const char *boolean_enums
[] = { "on", "off", NULL
};
579 struct cmd_list_element
*c
;
581 add_setshow_cmd_full (name
, theclass
, var_boolean
, var
,
582 set_doc
, show_doc
, help_doc
,
586 c
->enums
= boolean_enums
;
589 /* Add element named NAME to both the set and show command LISTs (the
590 list for set/show or some sublist thereof). */
592 add_setshow_filename_cmd (const char *name
, enum command_class theclass
,
594 const char *set_doc
, const char *show_doc
,
595 const char *help_doc
,
596 cmd_sfunc_ftype
*set_func
,
597 show_value_ftype
*show_func
,
598 struct cmd_list_element
**set_list
,
599 struct cmd_list_element
**show_list
)
601 struct cmd_list_element
*set_result
;
603 add_setshow_cmd_full (name
, theclass
, var_filename
, var
,
604 set_doc
, show_doc
, help_doc
,
608 set_cmd_completer (set_result
, filename_completer
);
611 /* Add element named NAME to both the set and show command LISTs (the
612 list for set/show or some sublist thereof). */
614 add_setshow_string_cmd (const char *name
, enum command_class theclass
,
616 const char *set_doc
, const char *show_doc
,
617 const char *help_doc
,
618 cmd_sfunc_ftype
*set_func
,
619 show_value_ftype
*show_func
,
620 struct cmd_list_element
**set_list
,
621 struct cmd_list_element
**show_list
)
623 add_setshow_cmd_full (name
, theclass
, var_string
, var
,
624 set_doc
, show_doc
, help_doc
,
630 /* Add element named NAME to both the set and show command LISTs (the
631 list for set/show or some sublist thereof). */
632 struct cmd_list_element
*
633 add_setshow_string_noescape_cmd (const char *name
, enum command_class theclass
,
635 const char *set_doc
, const char *show_doc
,
636 const char *help_doc
,
637 cmd_sfunc_ftype
*set_func
,
638 show_value_ftype
*show_func
,
639 struct cmd_list_element
**set_list
,
640 struct cmd_list_element
**show_list
)
642 struct cmd_list_element
*set_cmd
;
644 add_setshow_cmd_full (name
, theclass
, var_string_noescape
, var
,
645 set_doc
, show_doc
, help_doc
,
652 /* Add element named NAME to both the set and show command LISTs (the
653 list for set/show or some sublist thereof). */
655 add_setshow_optional_filename_cmd (const char *name
, enum command_class theclass
,
657 const char *set_doc
, const char *show_doc
,
658 const char *help_doc
,
659 cmd_sfunc_ftype
*set_func
,
660 show_value_ftype
*show_func
,
661 struct cmd_list_element
**set_list
,
662 struct cmd_list_element
**show_list
)
664 struct cmd_list_element
*set_result
;
666 add_setshow_cmd_full (name
, theclass
, var_optional_filename
, var
,
667 set_doc
, show_doc
, help_doc
,
672 set_cmd_completer (set_result
, filename_completer
);
676 /* Completes on literal "unlimited". Used by integer commands that
677 support a special "unlimited" value. */
680 integer_unlimited_completer (struct cmd_list_element
*ignore
,
681 completion_tracker
&tracker
,
682 const char *text
, const char *word
)
684 static const char * const keywords
[] =
690 complete_on_enum (tracker
, keywords
, text
, word
);
693 /* Add element named NAME to both the set and show command LISTs (the
694 list for set/show or some sublist thereof). CLASS is as in
695 add_cmd. VAR is address of the variable which will contain the
696 value. SET_DOC and SHOW_DOC are the documentation strings. This
697 function is only used in Python API. Please don't use it elsewhere. */
699 add_setshow_integer_cmd (const char *name
, enum command_class theclass
,
701 const char *set_doc
, const char *show_doc
,
702 const char *help_doc
,
703 cmd_sfunc_ftype
*set_func
,
704 show_value_ftype
*show_func
,
705 struct cmd_list_element
**set_list
,
706 struct cmd_list_element
**show_list
)
708 struct cmd_list_element
*set
;
710 add_setshow_cmd_full (name
, theclass
, var_integer
, var
,
711 set_doc
, show_doc
, help_doc
,
716 set_cmd_completer (set
, integer_unlimited_completer
);
719 /* Add element named NAME to both the set and show command LISTs (the
720 list for set/show or some sublist thereof). CLASS is as in
721 add_cmd. VAR is address of the variable which will contain the
722 value. SET_DOC and SHOW_DOC are the documentation strings. */
724 add_setshow_uinteger_cmd (const char *name
, enum command_class theclass
,
726 const char *set_doc
, const char *show_doc
,
727 const char *help_doc
,
728 cmd_sfunc_ftype
*set_func
,
729 show_value_ftype
*show_func
,
730 struct cmd_list_element
**set_list
,
731 struct cmd_list_element
**show_list
)
733 struct cmd_list_element
*set
;
735 add_setshow_cmd_full (name
, theclass
, var_uinteger
, var
,
736 set_doc
, show_doc
, help_doc
,
741 set_cmd_completer (set
, integer_unlimited_completer
);
744 /* Add element named NAME to both the set and show command LISTs (the
745 list for set/show or some sublist thereof). CLASS is as in
746 add_cmd. VAR is address of the variable which will contain the
747 value. SET_DOC and SHOW_DOC are the documentation strings. */
749 add_setshow_zinteger_cmd (const char *name
, enum command_class theclass
,
751 const char *set_doc
, const char *show_doc
,
752 const char *help_doc
,
753 cmd_sfunc_ftype
*set_func
,
754 show_value_ftype
*show_func
,
755 struct cmd_list_element
**set_list
,
756 struct cmd_list_element
**show_list
)
758 add_setshow_cmd_full (name
, theclass
, var_zinteger
, var
,
759 set_doc
, show_doc
, help_doc
,
766 add_setshow_zuinteger_unlimited_cmd (const char *name
,
767 enum command_class theclass
,
770 const char *show_doc
,
771 const char *help_doc
,
772 cmd_sfunc_ftype
*set_func
,
773 show_value_ftype
*show_func
,
774 struct cmd_list_element
**set_list
,
775 struct cmd_list_element
**show_list
)
777 struct cmd_list_element
*set
;
779 add_setshow_cmd_full (name
, theclass
, var_zuinteger_unlimited
, var
,
780 set_doc
, show_doc
, help_doc
,
785 set_cmd_completer (set
, integer_unlimited_completer
);
788 /* Add element named NAME to both the set and show command LISTs (the
789 list for set/show or some sublist thereof). CLASS is as in
790 add_cmd. VAR is address of the variable which will contain the
791 value. SET_DOC and SHOW_DOC are the documentation strings. */
793 add_setshow_zuinteger_cmd (const char *name
, enum command_class theclass
,
795 const char *set_doc
, const char *show_doc
,
796 const char *help_doc
,
797 cmd_sfunc_ftype
*set_func
,
798 show_value_ftype
*show_func
,
799 struct cmd_list_element
**set_list
,
800 struct cmd_list_element
**show_list
)
802 add_setshow_cmd_full (name
, theclass
, var_zuinteger
, var
,
803 set_doc
, show_doc
, help_doc
,
809 /* Remove the command named NAME from the command list. Return the
810 list commands which were aliased to the deleted command. If the
811 command had no aliases, return NULL. The various *HOOKs are set to
812 the pre- and post-hook commands for the deleted command. If the
813 command does not have a hook, the corresponding out parameter is
816 static struct cmd_list_element
*
817 delete_cmd (const char *name
, struct cmd_list_element
**list
,
818 struct cmd_list_element
**prehook
,
819 struct cmd_list_element
**prehookee
,
820 struct cmd_list_element
**posthook
,
821 struct cmd_list_element
**posthookee
)
823 struct cmd_list_element
*iter
;
824 struct cmd_list_element
**previous_chain_ptr
;
825 struct cmd_list_element
*aliases
= NULL
;
831 previous_chain_ptr
= list
;
833 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
835 if (strcmp (iter
->name
, name
) == 0)
838 iter
->destroyer (iter
, iter
->context
);
839 if (iter
->hookee_pre
)
840 iter
->hookee_pre
->hook_pre
= 0;
841 *prehook
= iter
->hook_pre
;
842 *prehookee
= iter
->hookee_pre
;
843 if (iter
->hookee_post
)
844 iter
->hookee_post
->hook_post
= 0;
845 if (iter
->doc
&& iter
->doc_allocated
)
846 xfree ((char *) iter
->doc
);
847 *posthook
= iter
->hook_post
;
848 *posthookee
= iter
->hookee_post
;
850 /* Update the link. */
851 *previous_chain_ptr
= iter
->next
;
853 aliases
= iter
->aliases
;
855 /* If this command was an alias, remove it from the list of
857 if (iter
->cmd_pointer
)
859 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
860 struct cmd_list_element
*a
= *prevp
;
864 prevp
= &a
->alias_chain
;
867 *prevp
= iter
->alias_chain
;
872 /* We won't see another command with the same name. */
876 previous_chain_ptr
= &iter
->next
;
882 /* Shorthands to the commands above. */
884 /* Add an element to the list of info subcommands. */
886 struct cmd_list_element
*
887 add_info (const char *name
, cmd_const_cfunc_ftype
*fun
, const char *doc
)
889 return add_cmd (name
, class_info
, fun
, doc
, &infolist
);
892 /* Add an alias to the list of info subcommands. */
894 struct cmd_list_element
*
895 add_info_alias (const char *name
, const char *oldname
, int abbrev_flag
)
897 return add_alias_cmd (name
, oldname
, class_run
, abbrev_flag
, &infolist
);
900 /* Add an element to the list of commands. */
902 struct cmd_list_element
*
903 add_com (const char *name
, enum command_class theclass
,
904 cmd_const_cfunc_ftype
*fun
,
907 return add_cmd (name
, theclass
, fun
, doc
, &cmdlist
);
910 /* Add an alias or abbreviation command to the list of commands. */
912 struct cmd_list_element
*
913 add_com_alias (const char *name
, const char *oldname
, enum command_class theclass
,
916 return add_alias_cmd (name
, oldname
, theclass
, abbrev_flag
, &cmdlist
);
919 /* Add an element with a suppress notification to the list of commands. */
921 struct cmd_list_element
*
922 add_com_suppress_notification (const char *name
, enum command_class theclass
,
923 cmd_const_cfunc_ftype
*fun
, const char *doc
,
924 int *suppress_notification
)
926 struct cmd_list_element
*element
;
928 element
= add_cmd (name
, theclass
, fun
, doc
, &cmdlist
);
929 element
->suppress_notification
= suppress_notification
;
934 /* Recursively walk the commandlist structures, and print out the
935 documentation of commands that match our regex in either their
936 name, or their documentation.
939 apropos_cmd (struct ui_file
*stream
,
940 struct cmd_list_element
*commandlist
,
941 compiled_regex
®ex
, const char *prefix
)
943 struct cmd_list_element
*c
;
946 /* Walk through the commands. */
947 for (c
=commandlist
;c
;c
=c
->next
)
949 returnvalue
= -1; /* Needed to avoid double printing. */
952 size_t name_len
= strlen (c
->name
);
954 /* Try to match against the name. */
955 returnvalue
= regex
.search (c
->name
, name_len
, 0, name_len
, NULL
);
956 if (returnvalue
>= 0)
958 print_help_for_command (c
, prefix
,
959 0 /* don't recurse */, stream
);
962 if (c
->doc
!= NULL
&& returnvalue
< 0)
964 size_t doc_len
= strlen (c
->doc
);
966 /* Try to match against documentation. */
967 if (regex
.search (c
->doc
, doc_len
, 0, doc_len
, NULL
) >= 0)
969 print_help_for_command (c
, prefix
,
970 0 /* don't recurse */, stream
);
973 /* Check if this command has subcommands and is not an
974 abbreviation. We skip listing subcommands of abbreviations
975 in order to avoid duplicates in the output. */
976 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
978 /* Recursively call ourselves on the subcommand list,
979 passing the right prefix in. */
980 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
985 /* This command really has to deal with two things:
986 1) I want documentation on *this string* (usually called by
989 2) I want documentation on *this list* (usually called by giving a
990 command that requires subcommands. Also called by saying just
993 I am going to split this into two seperate comamnds, help_cmd and
997 help_cmd (const char *command
, struct ui_file
*stream
)
999 struct cmd_list_element
*c
;
1003 help_list (cmdlist
, "", all_classes
, stream
);
1007 if (strcmp (command
, "all") == 0)
1013 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
1018 /* There are three cases here.
1019 If c->prefixlist is nonzero, we have a prefix command.
1020 Print its documentation, then list its subcommands.
1022 If c->func is non NULL, we really have a command. Print its
1023 documentation and return.
1025 If c->func is NULL, we have a class name. Print its
1026 documentation (as if it were a command) and then set class to the
1027 number of this class so that the commands in the class will be
1030 fputs_filtered (c
->doc
, stream
);
1031 fputs_filtered ("\n", stream
);
1033 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
1035 fprintf_filtered (stream
, "\n");
1037 /* If this is a prefix command, print it's subcommands. */
1039 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
1041 /* If this is a class name, print all of the commands in the class. */
1042 if (c
->func
== NULL
)
1043 help_list (cmdlist
, "", c
->theclass
, stream
);
1045 if (c
->hook_pre
|| c
->hook_post
)
1046 fprintf_filtered (stream
,
1047 "\nThis command has a hook (or hooks) defined:\n");
1050 fprintf_filtered (stream
,
1051 "\tThis command is run after : %s (pre hook)\n",
1054 fprintf_filtered (stream
,
1055 "\tThis command is run before : %s (post hook)\n",
1056 c
->hook_post
->name
);
1060 * Get a specific kind of help on a command list.
1063 * CMDTYPE is the prefix to use in the title string.
1064 * CLASS is the class with which to list the nodes of this list (see
1065 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
1066 * everything, ALL_CLASSES for just classes, and non-negative for only things
1067 * in a specific class.
1068 * and STREAM is the output stream on which to print things.
1069 * If you call this routine with a class >= 0, it recurses.
1072 help_list (struct cmd_list_element
*list
, const char *cmdtype
,
1073 enum command_class theclass
, struct ui_file
*stream
)
1076 char *cmdtype1
, *cmdtype2
;
1078 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
1080 len
= strlen (cmdtype
);
1081 cmdtype1
= (char *) alloca (len
+ 1);
1083 cmdtype2
= (char *) alloca (len
+ 4);
1088 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
1090 strncpy (cmdtype2
, cmdtype
, len
- 1);
1091 strcpy (cmdtype2
+ len
- 1, " sub");
1094 if (theclass
== all_classes
)
1095 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
1097 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
1099 help_cmd_list (list
, theclass
, cmdtype
, (int) theclass
>= 0, stream
);
1101 if (theclass
== all_classes
)
1103 fprintf_filtered (stream
, "\n\
1104 Type \"help%s\" followed by a class name for a list of commands in ",
1107 fprintf_filtered (stream
, "that class.");
1109 fprintf_filtered (stream
, "\n\
1110 Type \"help all\" for the list of all commands.");
1113 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
1114 cmdtype1
, cmdtype2
);
1116 fputs_filtered ("for ", stream
);
1118 fputs_filtered ("full ", stream
);
1120 fputs_filtered ("documentation.\n", stream
);
1121 fputs_filtered ("Type \"apropos word\" to search "
1122 "for commands related to \"word\".\n", stream
);
1123 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
1128 help_all (struct ui_file
*stream
)
1130 struct cmd_list_element
*c
;
1131 int seen_unclassified
= 0;
1133 for (c
= cmdlist
; c
; c
= c
->next
)
1137 /* If this is a class name, print all of the commands in the
1140 if (c
->func
== NULL
)
1142 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
1143 help_cmd_list (cmdlist
, c
->theclass
, "", 1, stream
);
1147 /* While it's expected that all commands are in some class,
1148 as a safety measure, we'll print commands outside of any
1149 class at the end. */
1151 for (c
= cmdlist
; c
; c
= c
->next
)
1156 if (c
->theclass
== no_class
)
1158 if (!seen_unclassified
)
1160 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
1161 seen_unclassified
= 1;
1163 print_help_for_command (c
, "", 1, stream
);
1169 /* Print only the first line of STR on STREAM. */
1171 print_doc_line (struct ui_file
*stream
, const char *str
)
1173 static char *line_buffer
= 0;
1174 static int line_size
;
1180 line_buffer
= (char *) xmalloc (line_size
);
1183 /* Keep printing '.' or ',' not followed by a whitespace for embedded strings
1186 while (*p
&& *p
!= '\n'
1187 && ((*p
!= '.' && *p
!= ',') || (p
[1] && !isspace (p
[1]))))
1189 if (p
- str
> line_size
- 1)
1191 line_size
= p
- str
+ 1;
1192 xfree (line_buffer
);
1193 line_buffer
= (char *) xmalloc (line_size
);
1195 strncpy (line_buffer
, str
, p
- str
);
1196 line_buffer
[p
- str
] = '\0';
1197 if (islower (line_buffer
[0]))
1198 line_buffer
[0] = toupper (line_buffer
[0]);
1199 fputs_filtered (line_buffer
, stream
);
1202 /* Print one-line help for command C.
1203 If RECURSE is non-zero, also print one-line descriptions
1204 of all prefixed subcommands. */
1206 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
1207 int recurse
, struct ui_file
*stream
)
1209 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1210 print_doc_line (stream
, c
->doc
);
1211 fputs_filtered ("\n", stream
);
1214 && c
->prefixlist
!= 0
1215 && c
->abbrev_flag
== 0)
1216 /* Subcommands of a prefix command typically have 'all_commands'
1217 as class. If we pass CLASS to recursive invocation,
1218 most often we won't see anything. */
1219 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1223 * Implement a help command on command list LIST.
1224 * RECURSE should be non-zero if this should be done recursively on
1225 * all sublists of LIST.
1226 * PREFIX is the prefix to print before each command name.
1227 * STREAM is the stream upon which the output should be written.
1228 * THECLASS should be:
1229 * A non-negative class number to list only commands in that
1231 * ALL_COMMANDS to list all commands in list.
1232 * ALL_CLASSES to list all classes in list.
1234 * Note that RECURSE will be active on *all* sublists, not just the
1235 * ones selected by the criteria above (ie. the selection mechanism
1236 * is at the low level, not the high-level).
1239 help_cmd_list (struct cmd_list_element
*list
, enum command_class theclass
,
1240 const char *prefix
, int recurse
, struct ui_file
*stream
)
1242 struct cmd_list_element
*c
;
1244 for (c
= list
; c
; c
= c
->next
)
1246 if (c
->abbrev_flag
== 0
1247 && !c
->cmd_deprecated
1248 && (theclass
== all_commands
1249 || (theclass
== all_classes
&& c
->func
== NULL
)
1250 || (theclass
== c
->theclass
&& c
->func
!= NULL
)))
1252 print_help_for_command (c
, prefix
, recurse
, stream
);
1254 else if (c
->abbrev_flag
== 0
1256 && !c
->cmd_deprecated
1257 && theclass
== class_user
&& c
->prefixlist
!= NULL
)
1258 /* User-defined commands may be subcommands. */
1259 help_cmd_list (*c
->prefixlist
, theclass
, c
->prefixname
,
1265 /* Search the input clist for 'command'. Return the command if
1266 found (or NULL if not), and return the number of commands
1269 static struct cmd_list_element
*
1270 find_cmd (const char *command
, int len
, struct cmd_list_element
*clist
,
1271 int ignore_help_classes
, int *nfound
)
1273 struct cmd_list_element
*found
, *c
;
1277 for (c
= clist
; c
; c
= c
->next
)
1278 if (!strncmp (command
, c
->name
, len
)
1279 && (!ignore_help_classes
|| c
->func
))
1283 if (c
->name
[len
] == '\0')
1292 /* Return the length of command name in TEXT. */
1295 find_command_name_length (const char *text
)
1297 const char *p
= text
;
1299 /* Treating underscores as part of command words is important
1300 so that "set args_foo()" doesn't get interpreted as
1301 "set args _foo()". */
1302 /* Some characters are only used for TUI specific commands.
1303 However, they are always allowed for the sake of consistency.
1305 Note that this is larger than the character set allowed when
1306 creating user-defined commands. */
1308 /* Recognize '!' as a single character command so that, e.g., "!ls"
1309 works as expected. */
1313 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1314 /* Characters used by TUI specific commands. */
1315 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')
1321 /* Return TRUE if NAME is a valid user-defined command name.
1322 This is a stricter subset of all gdb commands,
1323 see find_command_name_length. */
1326 valid_user_defined_cmd_name_p (const char *name
)
1333 /* Alas "42" is a legitimate user-defined command.
1334 In the interests of not breaking anything we preserve that. */
1336 for (p
= name
; *p
!= '\0'; ++p
)
1349 /* This routine takes a line of TEXT and a CLIST in which to start the
1350 lookup. When it returns it will have incremented the text pointer past
1351 the section of text it matched, set *RESULT_LIST to point to the list in
1352 which the last word was matched, and will return a pointer to the cmd
1353 list element which the text matches. It will return NULL if no match at
1354 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1355 matches are possible; in this case *RESULT_LIST will be set to point to
1356 the list in which there are ambiguous choices (and *TEXT will be set to
1357 the ambiguous text string).
1359 If the located command was an abbreviation, this routine returns the base
1360 command of the abbreviation.
1362 It does no error reporting whatsoever; control will always return
1363 to the superior routine.
1365 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1366 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1367 if no prefix command was ever found. For example, in the case of "info a",
1368 "info" matches without ambiguity, but "a" could be "args" or "address", so
1369 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1370 RESULT_LIST should not be interpreted as a pointer to the beginning of a
1371 list; it simply points to a specific command. In the case of an ambiguous
1372 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1373 "info t" can be "info types" or "info target"; upon return *TEXT has been
1374 advanced past "info ").
1376 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1377 affect the operation).
1379 This routine does *not* modify the text pointed to by TEXT.
1381 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1382 are actually help classes rather than commands (i.e. the function field of
1383 the struct cmd_list_element is NULL). */
1385 struct cmd_list_element
*
1386 lookup_cmd_1 (const char **text
, struct cmd_list_element
*clist
,
1387 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1390 int len
, tmp
, nfound
;
1391 struct cmd_list_element
*found
, *c
;
1392 const char *line
= *text
;
1394 while (**text
== ' ' || **text
== '\t')
1397 /* Identify the name of the command. */
1398 len
= find_command_name_length (*text
);
1400 /* If nothing but whitespace, return 0. */
1404 /* *text and p now bracket the first command word to lookup (and
1405 it's length is len). We copy this into a local temporary. */
1408 command
= (char *) alloca (len
+ 1);
1409 memcpy (command
, *text
, len
);
1410 command
[len
] = '\0';
1415 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1417 /* If nothing matches, we have a simple failure. */
1423 if (result_list
!= NULL
)
1424 /* Will be modified in calling routine
1425 if we know what the prefix command is. */
1427 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1430 /* We've matched something on this list. Move text pointer forward. */
1434 if (found
->cmd_pointer
)
1436 /* We drop the alias (abbreviation) in favor of the command it
1437 is pointing to. If the alias is deprecated, though, we need to
1438 warn the user about it before we drop it. Note that while we
1439 are warning about the alias, we may also warn about the command
1440 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1443 if (found
->deprecated_warn_user
)
1444 deprecated_cmd_warning (line
);
1445 found
= found
->cmd_pointer
;
1447 /* If we found a prefix command, keep looking. */
1449 if (found
->prefixlist
)
1451 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1452 ignore_help_classes
);
1455 /* Didn't find anything; this is as far as we got. */
1456 if (result_list
!= NULL
)
1457 *result_list
= clist
;
1460 else if (c
== CMD_LIST_AMBIGUOUS
)
1462 /* We've gotten this far properly, but the next step is
1463 ambiguous. We need to set the result list to the best
1464 we've found (if an inferior hasn't already set it). */
1465 if (result_list
!= NULL
)
1467 /* This used to say *result_list = *found->prefixlist.
1468 If that was correct, need to modify the documentation
1469 at the top of this function to clarify what is
1470 supposed to be going on. */
1471 *result_list
= found
;
1482 if (result_list
!= NULL
)
1483 *result_list
= clist
;
1488 /* All this hair to move the space to the front of cmdtype */
1491 undef_cmd_error (const char *cmdtype
, const char *q
)
1493 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1496 *cmdtype
? " " : "",
1497 (int) strlen (cmdtype
) - 1,
1501 /* Look up the contents of *LINE as a command in the command list LIST.
1502 LIST is a chain of struct cmd_list_element's.
1503 If it is found, return the struct cmd_list_element for that command
1504 and update *LINE to point after the command name, at the first argument.
1505 If not found, call error if ALLOW_UNKNOWN is zero
1506 otherwise (or if error returns) return zero.
1507 Call error if specified command is ambiguous,
1508 unless ALLOW_UNKNOWN is negative.
1509 CMDTYPE precedes the word "command" in the error message.
1511 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1512 elements which are actually help classes rather than commands (i.e.
1513 the function field of the struct cmd_list_element is 0). */
1515 struct cmd_list_element
*
1516 lookup_cmd (const char **line
, struct cmd_list_element
*list
,
1517 const char *cmdtype
,
1518 int allow_unknown
, int ignore_help_classes
)
1520 struct cmd_list_element
*last_list
= 0;
1521 struct cmd_list_element
*c
;
1523 /* Note: Do not remove trailing whitespace here because this
1524 would be wrong for complete_command. Jim Kingdon */
1527 error (_("Lack of needed %scommand"), cmdtype
);
1529 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1536 int len
= find_command_name_length (*line
);
1538 q
= (char *) alloca (len
+ 1);
1539 strncpy (q
, *line
, len
);
1541 undef_cmd_error (cmdtype
, q
);
1546 else if (c
== CMD_LIST_AMBIGUOUS
)
1548 /* Ambigous. Local values should be off prefixlist or called
1550 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1552 const char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1553 struct cmd_list_element
*local_list
=
1554 (last_list
? *(last_list
->prefixlist
) : list
);
1556 if (local_allow_unknown
< 0)
1559 return last_list
; /* Found something. */
1561 return 0; /* Found nothing. */
1565 /* Report as error. */
1570 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1571 && (*line
)[amb_len
] != '\t');
1576 for (c
= local_list
; c
; c
= c
->next
)
1577 if (!strncmp (*line
, c
->name
, amb_len
))
1579 if (strlen (ambbuf
) + strlen (c
->name
) + 6
1580 < (int) sizeof ambbuf
)
1582 if (strlen (ambbuf
))
1583 strcat (ambbuf
, ", ");
1584 strcat (ambbuf
, c
->name
);
1588 strcat (ambbuf
, "..");
1592 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1594 return 0; /* lint */
1599 if (c
->type
== set_cmd
&& **line
!= '\0' && !isspace (**line
))
1600 error (_("Argument must be preceded by space."));
1602 /* We've got something. It may still not be what the caller
1603 wants (if this command *needs* a subcommand). */
1604 while (**line
== ' ' || **line
== '\t')
1607 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1608 undef_cmd_error (c
->prefixname
, *line
);
1610 /* Seems to be what he wants. Return it. */
1616 /* We are here presumably because an alias or command in TEXT is
1617 deprecated and a warning message should be generated. This
1618 function decodes TEXT and potentially generates a warning message
1621 Example for 'set endian big' which has a fictitious alias 'seb'.
1623 If alias wasn't used in TEXT, and the command is deprecated:
1624 "warning: 'set endian big' is deprecated."
1626 If alias was used, and only the alias is deprecated:
1627 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1629 If alias was used and command is deprecated (regardless of whether
1630 the alias itself is deprecated:
1632 "warning: 'set endian big' (seb) is deprecated."
1634 After the message has been sent, clear the appropriate flags in the
1635 command and/or the alias so the user is no longer bothered.
1639 deprecated_cmd_warning (const char *text
)
1641 struct cmd_list_element
*alias
= NULL
;
1642 struct cmd_list_element
*prefix_cmd
= NULL
;
1643 struct cmd_list_element
*cmd
= NULL
;
1645 if (!lookup_cmd_composition (text
, &alias
, &prefix_cmd
, &cmd
))
1646 /* Return if text doesn't evaluate to a command. */
1649 if (!((alias
? alias
->deprecated_warn_user
: 0)
1650 || cmd
->deprecated_warn_user
) )
1651 /* Return if nothing is deprecated. */
1654 printf_filtered ("Warning:");
1656 if (alias
&& !cmd
->cmd_deprecated
)
1657 printf_filtered (" '%s', an alias for the", alias
->name
);
1659 printf_filtered (" command '");
1662 printf_filtered ("%s", prefix_cmd
->prefixname
);
1664 printf_filtered ("%s", cmd
->name
);
1666 if (alias
&& cmd
->cmd_deprecated
)
1667 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1669 printf_filtered ("' is deprecated.\n");
1672 /* If it is only the alias that is deprecated, we want to indicate
1673 the new alias, otherwise we'll indicate the new command. */
1675 if (alias
&& !cmd
->cmd_deprecated
)
1677 if (alias
->replacement
)
1678 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1680 printf_filtered ("No alternative known.\n\n");
1684 if (cmd
->replacement
)
1685 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1687 printf_filtered ("No alternative known.\n\n");
1690 /* We've warned you, now we'll keep quiet. */
1692 alias
->deprecated_warn_user
= 0;
1694 cmd
->deprecated_warn_user
= 0;
1698 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1699 Return 1 on success, 0 on failure.
1701 If LINE refers to an alias, *alias will point to that alias.
1703 If LINE is a postfix command (i.e. one that is preceded by a prefix
1704 command) set *prefix_cmd.
1706 Set *cmd to point to the command LINE indicates.
1708 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1709 exist, they are NULL when we return.
1713 lookup_cmd_composition (const char *text
,
1714 struct cmd_list_element
**alias
,
1715 struct cmd_list_element
**prefix_cmd
,
1716 struct cmd_list_element
**cmd
)
1719 int len
, tmp
, nfound
;
1720 struct cmd_list_element
*cur_list
;
1721 struct cmd_list_element
*prev_cmd
;
1731 /* Go through as many command lists as we need to,
1732 to find the command TEXT refers to. */
1736 while (*text
== ' ' || *text
== '\t')
1739 /* Identify the name of the command. */
1740 len
= find_command_name_length (text
);
1742 /* If nothing but whitespace, return. */
1746 /* Text is the start of the first command word to lookup (and
1747 it's length is len). We copy this into a local temporary. */
1749 command
= (char *) alloca (len
+ 1);
1750 memcpy (command
, text
, len
);
1751 command
[len
] = '\0';
1756 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1758 if (*cmd
== CMD_LIST_AMBIGUOUS
)
1760 return 0; /* ambiguous */
1764 return 0; /* nothing found */
1767 if ((*cmd
)->cmd_pointer
)
1769 /* cmd was actually an alias, we note that an alias was
1770 used (by assigning *alais) and we set *cmd. */
1772 *cmd
= (*cmd
)->cmd_pointer
;
1774 *prefix_cmd
= prev_cmd
;
1776 if ((*cmd
)->prefixlist
)
1777 cur_list
= *(*cmd
)->prefixlist
;
1785 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1787 /* Return a vector of char pointers which point to the different
1788 possible completions in LIST of TEXT.
1790 WORD points in the same buffer as TEXT, and completions should be
1791 returned relative to this position. For example, suppose TEXT is
1792 "foo" and we want to complete to "foobar". If WORD is "oo", return
1793 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1796 complete_on_cmdlist (struct cmd_list_element
*list
,
1797 completion_tracker
&tracker
,
1798 const char *text
, const char *word
,
1799 int ignore_help_classes
)
1801 struct cmd_list_element
*ptr
;
1802 int textlen
= strlen (text
);
1804 int saw_deprecated_match
= 0;
1806 /* We do one or two passes. In the first pass, we skip deprecated
1807 commands. If we see no matching commands in the first pass, and
1808 if we did happen to see a matching deprecated command, we do
1809 another loop to collect those. */
1810 for (pass
= 0; pass
< 2; ++pass
)
1812 bool got_matches
= false;
1814 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1815 if (!strncmp (ptr
->name
, text
, textlen
)
1816 && !ptr
->abbrev_flag
1817 && (!ignore_help_classes
|| ptr
->func
1818 || ptr
->prefixlist
))
1824 if (ptr
->cmd_deprecated
)
1826 saw_deprecated_match
= 1;
1831 match
= (char *) xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1833 strcpy (match
, ptr
->name
);
1834 else if (word
> text
)
1836 /* Return some portion of ptr->name. */
1837 strcpy (match
, ptr
->name
+ (word
- text
));
1841 /* Return some of text plus ptr->name. */
1842 strncpy (match
, word
, text
- word
);
1843 match
[text
- word
] = '\0';
1844 strcat (match
, ptr
->name
);
1846 tracker
.add_completion (gdb::unique_xmalloc_ptr
<char> (match
));
1853 /* If we saw no matching deprecated commands in the first pass,
1855 if (!saw_deprecated_match
)
1860 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1862 /* Add the different possible completions in ENUMLIST of TEXT.
1864 WORD points in the same buffer as TEXT, and completions should be
1865 returned relative to this position. For example, suppose TEXT is "foo"
1866 and we want to complete to "foobar". If WORD is "oo", return
1867 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1870 complete_on_enum (completion_tracker
&tracker
,
1871 const char *const *enumlist
,
1872 const char *text
, const char *word
)
1874 int textlen
= strlen (text
);
1878 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1879 if (strncmp (name
, text
, textlen
) == 0)
1883 match
= (char *) xmalloc (strlen (word
) + strlen (name
) + 1);
1885 strcpy (match
, name
);
1886 else if (word
> text
)
1888 /* Return some portion of name. */
1889 strcpy (match
, name
+ (word
- text
));
1893 /* Return some of text plus name. */
1894 strncpy (match
, word
, text
- word
);
1895 match
[text
- word
] = '\0';
1896 strcat (match
, name
);
1898 tracker
.add_completion (gdb::unique_xmalloc_ptr
<char> (match
));
1903 /* Check function pointer. */
1905 cmd_func_p (struct cmd_list_element
*cmd
)
1907 return (cmd
->func
!= NULL
);
1911 /* Call the command function. */
1913 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1915 if (cmd_func_p (cmd
))
1917 gdb::optional
<scoped_restore_tmpl
<int>> restore_suppress
;
1919 if (cmd
->suppress_notification
!= NULL
)
1920 restore_suppress
.emplace (cmd
->suppress_notification
, 1);
1922 (*cmd
->func
) (cmd
, args
, from_tty
);
1925 error (_("Invalid command"));
1929 cli_user_command_p (struct cmd_list_element
*cmd
)
1931 return (cmd
->theclass
== class_user
1932 && (cmd
->func
== do_const_cfunc
|| cmd
->func
== do_sfunc
));