1 /* Handle lists of commands, their decoding and documentation, for GDB.
3 Copyright (C) 1986-2019 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 "cli/cli-style.h"
27 #include "gdbsupport/gdb_optional.h"
29 /* Prototypes for local functions. */
31 static void undef_cmd_error (const char *, const char *);
33 static struct cmd_list_element
*delete_cmd (const char *name
,
34 struct cmd_list_element
**list
,
35 struct cmd_list_element
**prehook
,
36 struct cmd_list_element
**prehookee
,
37 struct cmd_list_element
**posthook
,
38 struct cmd_list_element
**posthookee
);
40 static struct cmd_list_element
*find_cmd (const char *command
,
42 struct cmd_list_element
*clist
,
43 int ignore_help_classes
,
46 static void help_all (struct ui_file
*stream
);
48 /* Look up a command whose 'prefixlist' is KEY. Return the command if found,
49 otherwise return NULL. */
51 static struct cmd_list_element
*
52 lookup_cmd_for_prefixlist (struct cmd_list_element
**key
,
53 struct cmd_list_element
*list
)
55 struct cmd_list_element
*p
= NULL
;
57 for (p
= list
; p
!= NULL
; p
= p
->next
)
59 struct cmd_list_element
*q
;
61 if (p
->prefixlist
== NULL
)
63 else if (p
->prefixlist
== key
)
66 q
= lookup_cmd_for_prefixlist (key
, *(p
->prefixlist
));
75 set_cmd_prefix (struct cmd_list_element
*c
, struct cmd_list_element
**list
)
77 struct cmd_list_element
*p
;
79 /* Check to see if *LIST contains any element other than C. */
80 for (p
= *list
; p
!= NULL
; p
= p
->next
)
86 /* *SET_LIST only contains SET. */
87 p
= lookup_cmd_for_prefixlist (list
, setlist
);
89 c
->prefix
= p
? (p
->cmd_pointer
? p
->cmd_pointer
: p
) : p
;
92 c
->prefix
= p
->prefix
;
96 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
97 int recurse
, struct ui_file
*stream
);
100 /* Set the callback function for the specified command. For each both
101 the commands callback and func() are set. The latter set to a
102 bounce function (unless cfunc / sfunc is NULL that is). */
105 do_const_cfunc (struct cmd_list_element
*c
, const char *args
, int from_tty
)
107 c
->function
.const_cfunc (args
, from_tty
);
111 set_cmd_cfunc (struct cmd_list_element
*cmd
, cmd_const_cfunc_ftype
*cfunc
)
116 cmd
->func
= do_const_cfunc
;
117 cmd
->function
.const_cfunc
= cfunc
;
121 do_sfunc (struct cmd_list_element
*c
, const char *args
, int from_tty
)
123 c
->function
.sfunc (args
, from_tty
, c
);
127 set_cmd_sfunc (struct cmd_list_element
*cmd
, cmd_const_sfunc_ftype
*sfunc
)
132 cmd
->func
= do_sfunc
;
133 cmd
->function
.sfunc
= sfunc
;
137 cmd_cfunc_eq (struct cmd_list_element
*cmd
, cmd_const_cfunc_ftype
*cfunc
)
139 return cmd
->func
== do_const_cfunc
&& cmd
->function
.const_cfunc
== cfunc
;
143 set_cmd_context (struct cmd_list_element
*cmd
, void *context
)
145 cmd
->context
= context
;
149 get_cmd_context (struct cmd_list_element
*cmd
)
155 cmd_type (struct cmd_list_element
*cmd
)
161 set_cmd_completer (struct cmd_list_element
*cmd
, completer_ftype
*completer
)
163 cmd
->completer
= completer
; /* Ok. */
166 /* See definition in commands.h. */
169 set_cmd_completer_handle_brkchars (struct cmd_list_element
*cmd
,
170 completer_handle_brkchars_ftype
*func
)
172 cmd
->completer_handle_brkchars
= func
;
175 /* Add element named NAME.
176 Space for NAME and DOC must be allocated by the caller.
177 CLASS is the top level category into which commands are broken down
179 FUN should be the function to execute the command;
180 it will get a character string as argument, with leading
181 and trailing blanks already eliminated.
183 DOC is a documentation string for the command.
184 Its first line should be a complete sentence.
185 It should start with ? for a command that is an abbreviation
186 or with * for a command that most users don't need to know about.
188 Add this command to command list *LIST.
190 Returns a pointer to the added command (not necessarily the head
193 static struct cmd_list_element
*
194 do_add_cmd (const char *name
, enum command_class theclass
,
195 const char *doc
, struct cmd_list_element
**list
)
197 struct cmd_list_element
*c
= new struct cmd_list_element (name
, theclass
,
199 struct cmd_list_element
*p
, *iter
;
201 /* Turn each alias of the old command into an alias of the new
203 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
204 &c
->hook_post
, &c
->hookee_post
);
205 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
206 iter
->cmd_pointer
= c
;
208 c
->hook_pre
->hookee_pre
= c
;
210 c
->hookee_pre
->hook_pre
= c
;
212 c
->hook_post
->hookee_post
= c
;
214 c
->hookee_post
->hook_post
= c
;
216 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
224 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
235 struct cmd_list_element
*
236 add_cmd (const char *name
, enum command_class theclass
,
237 const char *doc
, struct cmd_list_element
**list
)
239 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
241 result
->function
.const_cfunc
= NULL
;
245 struct cmd_list_element
*
246 add_cmd (const char *name
, enum command_class theclass
,
247 cmd_const_cfunc_ftype
*fun
,
248 const char *doc
, struct cmd_list_element
**list
)
250 cmd_list_element
*result
= do_add_cmd (name
, theclass
, doc
, list
);
251 set_cmd_cfunc (result
, fun
);
255 /* Add an element with a suppress notification to the LIST of commands. */
257 struct cmd_list_element
*
258 add_cmd_suppress_notification (const char *name
, enum command_class theclass
,
259 cmd_const_cfunc_ftype
*fun
, const char *doc
,
260 struct cmd_list_element
**list
,
261 int *suppress_notification
)
263 struct cmd_list_element
*element
;
265 element
= add_cmd (name
, theclass
, fun
, doc
, list
);
266 element
->suppress_notification
= suppress_notification
;
272 /* Deprecates a command CMD.
273 REPLACEMENT is the name of the command which should be used in
274 place of this command, or NULL if no such command exists.
276 This function does not check to see if command REPLACEMENT exists
277 since gdb may not have gotten around to adding REPLACEMENT when
278 this function is called.
280 Returns a pointer to the deprecated command. */
282 struct cmd_list_element
*
283 deprecate_cmd (struct cmd_list_element
*cmd
, const char *replacement
)
285 cmd
->cmd_deprecated
= 1;
286 cmd
->deprecated_warn_user
= 1;
288 if (replacement
!= NULL
)
289 cmd
->replacement
= replacement
;
291 cmd
->replacement
= NULL
;
296 struct cmd_list_element
*
297 add_alias_cmd (const char *name
, cmd_list_element
*old
,
298 enum command_class theclass
, int abbrev_flag
,
299 struct cmd_list_element
**list
)
303 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
304 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
305 &prehook
, &prehookee
,
306 &posthook
, &posthookee
);
308 /* If this happens, it means a programmer error somewhere. */
309 gdb_assert (!aliases
&& !prehook
&& !prehookee
310 && !posthook
&& ! posthookee
);
314 struct cmd_list_element
*c
= add_cmd (name
, theclass
, old
->doc
, list
);
316 /* If OLD->DOC can be freed, we should make another copy. */
317 if (old
->doc_allocated
)
319 c
->doc
= xstrdup (old
->doc
);
320 c
->doc_allocated
= 1;
322 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
324 c
->function
= old
->function
;
325 c
->prefixlist
= old
->prefixlist
;
326 c
->prefixname
= old
->prefixname
;
327 c
->allow_unknown
= old
->allow_unknown
;
328 c
->abbrev_flag
= abbrev_flag
;
329 c
->cmd_pointer
= old
;
330 c
->alias_chain
= old
->aliases
;
333 set_cmd_prefix (c
, list
);
337 struct cmd_list_element
*
338 add_alias_cmd (const char *name
, const char *oldname
,
339 enum command_class theclass
, int abbrev_flag
,
340 struct cmd_list_element
**list
)
343 struct cmd_list_element
*old
;
346 old
= lookup_cmd (&tmp
, *list
, "", 1, 1);
348 return add_alias_cmd (name
, old
, theclass
, abbrev_flag
, list
);
352 /* Like add_cmd but adds an element for a command prefix: a name that
353 should be followed by a subcommand to be looked up in another
354 command list. PREFIXLIST should be the address of the variable
355 containing that list. */
357 struct cmd_list_element
*
358 add_prefix_cmd (const char *name
, enum command_class theclass
,
359 cmd_const_cfunc_ftype
*fun
,
360 const char *doc
, struct cmd_list_element
**prefixlist
,
361 const char *prefixname
, int allow_unknown
,
362 struct cmd_list_element
**list
)
364 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
365 struct cmd_list_element
*p
;
367 c
->prefixlist
= prefixlist
;
368 c
->prefixname
= prefixname
;
369 c
->allow_unknown
= allow_unknown
;
371 if (list
== &cmdlist
)
374 set_cmd_prefix (c
, list
);
376 /* Update the field 'prefix' of each cmd_list_element in *PREFIXLIST. */
377 for (p
= *prefixlist
; p
!= NULL
; p
= p
->next
)
383 /* Like ADD_PREFIX_CMD but sets the suppress_notification pointer on the
384 new command list element. */
386 struct cmd_list_element
*
387 add_prefix_cmd_suppress_notification
388 (const char *name
, enum command_class theclass
,
389 cmd_const_cfunc_ftype
*fun
,
390 const char *doc
, struct cmd_list_element
**prefixlist
,
391 const char *prefixname
, int allow_unknown
,
392 struct cmd_list_element
**list
,
393 int *suppress_notification
)
395 struct cmd_list_element
*element
396 = add_prefix_cmd (name
, theclass
, fun
, doc
, prefixlist
,
397 prefixname
, allow_unknown
, list
);
398 element
->suppress_notification
= suppress_notification
;
402 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
404 struct cmd_list_element
*
405 add_abbrev_prefix_cmd (const char *name
, enum command_class theclass
,
406 cmd_const_cfunc_ftype
*fun
, const char *doc
,
407 struct cmd_list_element
**prefixlist
,
408 const char *prefixname
,
409 int allow_unknown
, struct cmd_list_element
**list
)
411 struct cmd_list_element
*c
= add_cmd (name
, theclass
, fun
, doc
, list
);
413 c
->prefixlist
= prefixlist
;
414 c
->prefixname
= prefixname
;
415 c
->allow_unknown
= allow_unknown
;
420 /* This is an empty "cfunc". */
422 not_just_help_class_command (const char *args
, int from_tty
)
426 /* This is an empty "sfunc". */
429 empty_sfunc (const char *args
, int from_tty
, struct cmd_list_element
*c
)
433 /* Add element named NAME to command list LIST (the list for set/show
434 or some sublist thereof).
435 TYPE is set_cmd or show_cmd.
436 CLASS is as in add_cmd.
437 VAR_TYPE is the kind of thing we are setting.
438 VAR is address of the variable being controlled by this command.
439 DOC is the documentation string. */
441 static struct cmd_list_element
*
442 add_set_or_show_cmd (const char *name
,
444 enum command_class theclass
,
448 struct cmd_list_element
**list
)
450 struct cmd_list_element
*c
= add_cmd (name
, theclass
, doc
, list
);
452 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
454 c
->var_type
= var_type
;
456 /* This needs to be something besides NULL so that this isn't
457 treated as a help class. */
458 set_cmd_sfunc (c
, empty_sfunc
);
462 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
463 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
464 setting. VAR is address of the variable being controlled by this
465 command. SET_FUNC and SHOW_FUNC are the callback functions (if
466 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
467 strings. PRINT the format string to print the value. SET_RESULT
468 and SHOW_RESULT, if not NULL, are set to the resulting command
472 add_setshow_cmd_full (const char *name
,
473 enum command_class theclass
,
474 var_types var_type
, void *var
,
475 const char *set_doc
, const char *show_doc
,
476 const char *help_doc
,
477 cmd_const_sfunc_ftype
*set_func
,
478 show_value_ftype
*show_func
,
479 struct cmd_list_element
**set_list
,
480 struct cmd_list_element
**show_list
,
481 struct cmd_list_element
**set_result
,
482 struct cmd_list_element
**show_result
)
484 struct cmd_list_element
*set
;
485 struct cmd_list_element
*show
;
489 if (help_doc
!= NULL
)
491 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
492 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
496 full_set_doc
= xstrdup (set_doc
);
497 full_show_doc
= xstrdup (show_doc
);
499 set
= add_set_or_show_cmd (name
, set_cmd
, theclass
, var_type
, var
,
500 full_set_doc
, set_list
);
501 set
->doc_allocated
= 1;
503 if (set_func
!= NULL
)
504 set_cmd_sfunc (set
, set_func
);
506 set_cmd_prefix (set
, set_list
);
508 show
= add_set_or_show_cmd (name
, show_cmd
, theclass
, var_type
, var
,
509 full_show_doc
, show_list
);
510 show
->doc_allocated
= 1;
511 show
->show_value_func
= show_func
;
512 /* Disable the default symbol completer. Doesn't make much sense
513 for the "show" command to complete on anything. */
514 set_cmd_completer (show
, nullptr);
516 if (set_result
!= NULL
)
518 if (show_result
!= NULL
)
522 /* Add element named NAME to command list LIST (the list for set or
523 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
524 of strings which may follow NAME. VAR is address of the variable
525 which will contain the matching string (from ENUMLIST). */
528 add_setshow_enum_cmd (const char *name
,
529 enum command_class theclass
,
530 const char *const *enumlist
,
533 const char *show_doc
,
534 const char *help_doc
,
535 cmd_const_sfunc_ftype
*set_func
,
536 show_value_ftype
*show_func
,
537 struct cmd_list_element
**set_list
,
538 struct cmd_list_element
**show_list
,
541 struct cmd_list_element
*c
, *show
;
543 add_setshow_cmd_full (name
, theclass
, var_enum
, var
,
544 set_doc
, show_doc
, help_doc
,
550 set_cmd_context (c
, context
);
551 set_cmd_context (show
, context
);
554 /* See cli-decode.h. */
555 const char * const auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
557 /* Add an auto-boolean command named NAME to both the set and show
558 command list lists. CLASS is as in add_cmd. VAR is address of the
559 variable which will contain the value. DOC is the documentation
560 string. FUNC is the corresponding callback. */
562 add_setshow_auto_boolean_cmd (const char *name
,
563 enum command_class theclass
,
564 enum auto_boolean
*var
,
565 const char *set_doc
, const char *show_doc
,
566 const char *help_doc
,
567 cmd_const_sfunc_ftype
*set_func
,
568 show_value_ftype
*show_func
,
569 struct cmd_list_element
**set_list
,
570 struct cmd_list_element
**show_list
)
572 struct cmd_list_element
*c
;
574 add_setshow_cmd_full (name
, theclass
, var_auto_boolean
, var
,
575 set_doc
, show_doc
, help_doc
,
579 c
->enums
= auto_boolean_enums
;
582 /* See cli-decode.h. */
583 const char * const boolean_enums
[] = { "on", "off", NULL
};
585 /* Add element named NAME to both the set and show command LISTs (the
586 list for set/show or some sublist thereof). CLASS is as in
587 add_cmd. VAR is address of the variable which will contain the
588 value. SET_DOC and SHOW_DOC are the documentation strings.
589 Returns the new command element. */
592 add_setshow_boolean_cmd (const char *name
, enum command_class theclass
, int *var
,
593 const char *set_doc
, const char *show_doc
,
594 const char *help_doc
,
595 cmd_const_sfunc_ftype
*set_func
,
596 show_value_ftype
*show_func
,
597 struct cmd_list_element
**set_list
,
598 struct cmd_list_element
**show_list
)
600 struct cmd_list_element
*c
;
602 add_setshow_cmd_full (name
, theclass
, var_boolean
, var
,
603 set_doc
, show_doc
, help_doc
,
607 c
->enums
= boolean_enums
;
612 /* Add element named NAME to both the set and show command LISTs (the
613 list for set/show or some sublist thereof). */
615 add_setshow_filename_cmd (const char *name
, enum command_class theclass
,
617 const char *set_doc
, const char *show_doc
,
618 const char *help_doc
,
619 cmd_const_sfunc_ftype
*set_func
,
620 show_value_ftype
*show_func
,
621 struct cmd_list_element
**set_list
,
622 struct cmd_list_element
**show_list
)
624 struct cmd_list_element
*set_result
;
626 add_setshow_cmd_full (name
, theclass
, var_filename
, var
,
627 set_doc
, show_doc
, help_doc
,
631 set_cmd_completer (set_result
, filename_completer
);
634 /* Add element named NAME to both the set and show command LISTs (the
635 list for set/show or some sublist thereof). */
637 add_setshow_string_cmd (const char *name
, enum command_class theclass
,
639 const char *set_doc
, const char *show_doc
,
640 const char *help_doc
,
641 cmd_const_sfunc_ftype
*set_func
,
642 show_value_ftype
*show_func
,
643 struct cmd_list_element
**set_list
,
644 struct cmd_list_element
**show_list
)
646 cmd_list_element
*set_cmd
;
648 add_setshow_cmd_full (name
, theclass
, var_string
, var
,
649 set_doc
, show_doc
, help_doc
,
654 /* Disable the default symbol completer. */
655 set_cmd_completer (set_cmd
, nullptr);
658 /* Add element named NAME to both the set and show command LISTs (the
659 list for set/show or some sublist thereof). */
660 struct cmd_list_element
*
661 add_setshow_string_noescape_cmd (const char *name
, enum command_class theclass
,
663 const char *set_doc
, const char *show_doc
,
664 const char *help_doc
,
665 cmd_const_sfunc_ftype
*set_func
,
666 show_value_ftype
*show_func
,
667 struct cmd_list_element
**set_list
,
668 struct cmd_list_element
**show_list
)
670 struct cmd_list_element
*set_cmd
;
672 add_setshow_cmd_full (name
, theclass
, var_string_noescape
, var
,
673 set_doc
, show_doc
, help_doc
,
678 /* Disable the default symbol completer. */
679 set_cmd_completer (set_cmd
, nullptr);
684 /* Add element named NAME to both the set and show command LISTs (the
685 list for set/show or some sublist thereof). */
687 add_setshow_optional_filename_cmd (const char *name
, enum command_class theclass
,
689 const char *set_doc
, const char *show_doc
,
690 const char *help_doc
,
691 cmd_const_sfunc_ftype
*set_func
,
692 show_value_ftype
*show_func
,
693 struct cmd_list_element
**set_list
,
694 struct cmd_list_element
**show_list
)
696 struct cmd_list_element
*set_result
;
698 add_setshow_cmd_full (name
, theclass
, var_optional_filename
, var
,
699 set_doc
, show_doc
, help_doc
,
704 set_cmd_completer (set_result
, filename_completer
);
708 /* Completes on literal "unlimited". Used by integer commands that
709 support a special "unlimited" value. */
712 integer_unlimited_completer (struct cmd_list_element
*ignore
,
713 completion_tracker
&tracker
,
714 const char *text
, const char *word
)
716 static const char * const keywords
[] =
722 complete_on_enum (tracker
, keywords
, text
, word
);
725 /* Add element named NAME to both the set and show command LISTs (the
726 list for set/show or some sublist thereof). CLASS is as in
727 add_cmd. VAR is address of the variable which will contain the
728 value. SET_DOC and SHOW_DOC are the documentation strings. This
729 function is only used in Python API. Please don't use it elsewhere. */
731 add_setshow_integer_cmd (const char *name
, enum command_class theclass
,
733 const char *set_doc
, const char *show_doc
,
734 const char *help_doc
,
735 cmd_const_sfunc_ftype
*set_func
,
736 show_value_ftype
*show_func
,
737 struct cmd_list_element
**set_list
,
738 struct cmd_list_element
**show_list
)
740 struct cmd_list_element
*set
;
742 add_setshow_cmd_full (name
, theclass
, var_integer
, var
,
743 set_doc
, show_doc
, help_doc
,
748 set_cmd_completer (set
, integer_unlimited_completer
);
751 /* Add element named NAME to both the set and show command LISTs (the
752 list for set/show or some sublist thereof). CLASS is as in
753 add_cmd. VAR is address of the variable which will contain the
754 value. SET_DOC and SHOW_DOC are the documentation strings. */
756 add_setshow_uinteger_cmd (const char *name
, enum command_class theclass
,
758 const char *set_doc
, const char *show_doc
,
759 const char *help_doc
,
760 cmd_const_sfunc_ftype
*set_func
,
761 show_value_ftype
*show_func
,
762 struct cmd_list_element
**set_list
,
763 struct cmd_list_element
**show_list
)
765 struct cmd_list_element
*set
;
767 add_setshow_cmd_full (name
, theclass
, var_uinteger
, var
,
768 set_doc
, show_doc
, help_doc
,
773 set_cmd_completer (set
, integer_unlimited_completer
);
776 /* Add element named NAME to both the set and show command LISTs (the
777 list for set/show or some sublist thereof). CLASS is as in
778 add_cmd. VAR is address of the variable which will contain the
779 value. SET_DOC and SHOW_DOC are the documentation strings. */
781 add_setshow_zinteger_cmd (const char *name
, enum command_class theclass
,
783 const char *set_doc
, const char *show_doc
,
784 const char *help_doc
,
785 cmd_const_sfunc_ftype
*set_func
,
786 show_value_ftype
*show_func
,
787 struct cmd_list_element
**set_list
,
788 struct cmd_list_element
**show_list
)
790 add_setshow_cmd_full (name
, theclass
, var_zinteger
, var
,
791 set_doc
, show_doc
, help_doc
,
798 add_setshow_zuinteger_unlimited_cmd (const char *name
,
799 enum command_class theclass
,
802 const char *show_doc
,
803 const char *help_doc
,
804 cmd_const_sfunc_ftype
*set_func
,
805 show_value_ftype
*show_func
,
806 struct cmd_list_element
**set_list
,
807 struct cmd_list_element
**show_list
)
809 struct cmd_list_element
*set
;
811 add_setshow_cmd_full (name
, theclass
, var_zuinteger_unlimited
, var
,
812 set_doc
, show_doc
, help_doc
,
817 set_cmd_completer (set
, integer_unlimited_completer
);
820 /* Add element named NAME to both the set and show command LISTs (the
821 list for set/show or some sublist thereof). CLASS is as in
822 add_cmd. VAR is address of the variable which will contain the
823 value. SET_DOC and SHOW_DOC are the documentation strings. */
825 add_setshow_zuinteger_cmd (const char *name
, enum command_class theclass
,
827 const char *set_doc
, const char *show_doc
,
828 const char *help_doc
,
829 cmd_const_sfunc_ftype
*set_func
,
830 show_value_ftype
*show_func
,
831 struct cmd_list_element
**set_list
,
832 struct cmd_list_element
**show_list
)
834 add_setshow_cmd_full (name
, theclass
, var_zuinteger
, var
,
835 set_doc
, show_doc
, help_doc
,
841 /* Remove the command named NAME from the command list. Return the
842 list commands which were aliased to the deleted command. If the
843 command had no aliases, return NULL. The various *HOOKs are set to
844 the pre- and post-hook commands for the deleted command. If the
845 command does not have a hook, the corresponding out parameter is
848 static struct cmd_list_element
*
849 delete_cmd (const char *name
, struct cmd_list_element
**list
,
850 struct cmd_list_element
**prehook
,
851 struct cmd_list_element
**prehookee
,
852 struct cmd_list_element
**posthook
,
853 struct cmd_list_element
**posthookee
)
855 struct cmd_list_element
*iter
;
856 struct cmd_list_element
**previous_chain_ptr
;
857 struct cmd_list_element
*aliases
= NULL
;
863 previous_chain_ptr
= list
;
865 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
867 if (strcmp (iter
->name
, name
) == 0)
870 iter
->destroyer (iter
, iter
->context
);
871 if (iter
->hookee_pre
)
872 iter
->hookee_pre
->hook_pre
= 0;
873 *prehook
= iter
->hook_pre
;
874 *prehookee
= iter
->hookee_pre
;
875 if (iter
->hookee_post
)
876 iter
->hookee_post
->hook_post
= 0;
877 *posthook
= iter
->hook_post
;
878 *posthookee
= iter
->hookee_post
;
880 /* Update the link. */
881 *previous_chain_ptr
= iter
->next
;
883 aliases
= iter
->aliases
;
885 /* If this command was an alias, remove it from the list of
887 if (iter
->cmd_pointer
)
889 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
890 struct cmd_list_element
*a
= *prevp
;
894 prevp
= &a
->alias_chain
;
897 *prevp
= iter
->alias_chain
;
902 /* We won't see another command with the same name. */
906 previous_chain_ptr
= &iter
->next
;
912 /* Shorthands to the commands above. */
914 /* Add an element to the list of info subcommands. */
916 struct cmd_list_element
*
917 add_info (const char *name
, cmd_const_cfunc_ftype
*fun
, const char *doc
)
919 return add_cmd (name
, class_info
, fun
, doc
, &infolist
);
922 /* Add an alias to the list of info subcommands. */
924 struct cmd_list_element
*
925 add_info_alias (const char *name
, const char *oldname
, int abbrev_flag
)
927 return add_alias_cmd (name
, oldname
, class_run
, abbrev_flag
, &infolist
);
930 /* Add an element to the list of commands. */
932 struct cmd_list_element
*
933 add_com (const char *name
, enum command_class theclass
,
934 cmd_const_cfunc_ftype
*fun
,
937 return add_cmd (name
, theclass
, fun
, doc
, &cmdlist
);
940 /* Add an alias or abbreviation command to the list of commands. */
942 struct cmd_list_element
*
943 add_com_alias (const char *name
, const char *oldname
, enum command_class theclass
,
946 return add_alias_cmd (name
, oldname
, theclass
, abbrev_flag
, &cmdlist
);
949 /* Add an element with a suppress notification to the list of commands. */
951 struct cmd_list_element
*
952 add_com_suppress_notification (const char *name
, enum command_class theclass
,
953 cmd_const_cfunc_ftype
*fun
, const char *doc
,
954 int *suppress_notification
)
956 return add_cmd_suppress_notification (name
, theclass
, fun
, doc
,
957 &cmdlist
, suppress_notification
);
960 /* If VERBOSE, print the full help for command C and highlight the
961 documentation parts matching HIGHLIGHT,
962 otherwise print only one-line help for command C. */
965 print_doc_of_command (struct cmd_list_element
*c
, const char *prefix
,
966 bool verbose
, compiled_regex
&highlight
,
967 struct ui_file
*stream
)
969 /* When printing the full documentation, add a line to separate
970 this documentation from the previous command help, in the likely
971 case that apropos finds several commands. */
973 fputs_filtered ("\n", stream
);
975 fprintf_styled (stream
, title_style
.style (),
976 "%s%s", prefix
, c
->name
);
977 fputs_filtered (" -- ", stream
);
979 fputs_highlighted (c
->doc
, highlight
, stream
);
981 print_doc_line (stream
, c
->doc
, false);
982 fputs_filtered ("\n", stream
);
985 /* Recursively walk the commandlist structures, and print out the
986 documentation of commands that match our regex in either their
987 name, or their documentation.
988 If VERBOSE, prints the complete documentation and highlight the
989 documentation parts matching REGEX, otherwise prints only
993 apropos_cmd (struct ui_file
*stream
,
994 struct cmd_list_element
*commandlist
,
995 bool verbose
, compiled_regex
®ex
, const char *prefix
)
997 struct cmd_list_element
*c
;
1000 /* Walk through the commands. */
1001 for (c
=commandlist
;c
;c
=c
->next
)
1003 returnvalue
= -1; /* Needed to avoid double printing. */
1004 if (c
->name
!= NULL
)
1006 size_t name_len
= strlen (c
->name
);
1008 /* Try to match against the name. */
1009 returnvalue
= regex
.search (c
->name
, name_len
, 0, name_len
, NULL
);
1010 if (returnvalue
>= 0)
1011 print_doc_of_command (c
, prefix
, verbose
, regex
, stream
);
1013 if (c
->doc
!= NULL
&& returnvalue
< 0)
1015 size_t doc_len
= strlen (c
->doc
);
1017 /* Try to match against documentation. */
1018 if (regex
.search (c
->doc
, doc_len
, 0, doc_len
, NULL
) >= 0)
1019 print_doc_of_command (c
, prefix
, verbose
, regex
, stream
);
1021 /* Check if this command has subcommands and is not an
1022 abbreviation. We skip listing subcommands of abbreviations
1023 in order to avoid duplicates in the output. */
1024 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
1026 /* Recursively call ourselves on the subcommand list,
1027 passing the right prefix in. */
1028 apropos_cmd (stream
, *c
->prefixlist
, verbose
, regex
, c
->prefixname
);
1033 /* This command really has to deal with two things:
1034 1) I want documentation on *this string* (usually called by
1035 "help commandname").
1037 2) I want documentation on *this list* (usually called by giving a
1038 command that requires subcommands. Also called by saying just
1041 I am going to split this into two seperate comamnds, help_cmd and
1045 help_cmd (const char *command
, struct ui_file
*stream
)
1047 struct cmd_list_element
*c
;
1051 help_list (cmdlist
, "", all_classes
, stream
);
1055 if (strcmp (command
, "all") == 0)
1061 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
1066 /* There are three cases here.
1067 If c->prefixlist is nonzero, we have a prefix command.
1068 Print its documentation, then list its subcommands.
1070 If c->func is non NULL, we really have a command. Print its
1071 documentation and return.
1073 If c->func is NULL, we have a class name. Print its
1074 documentation (as if it were a command) and then set class to the
1075 number of this class so that the commands in the class will be
1078 fputs_filtered (c
->doc
, stream
);
1079 fputs_filtered ("\n", stream
);
1081 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
1083 fprintf_filtered (stream
, "\n");
1085 /* If this is a prefix command, print it's subcommands. */
1087 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
1089 /* If this is a class name, print all of the commands in the class. */
1090 if (c
->func
== NULL
)
1091 help_list (cmdlist
, "", c
->theclass
, stream
);
1093 if (c
->hook_pre
|| c
->hook_post
)
1094 fprintf_filtered (stream
,
1095 "\nThis command has a hook (or hooks) defined:\n");
1098 fprintf_filtered (stream
,
1099 "\tThis command is run after : %s (pre hook)\n",
1102 fprintf_filtered (stream
,
1103 "\tThis command is run before : %s (post hook)\n",
1104 c
->hook_post
->name
);
1108 * Get a specific kind of help on a command list.
1111 * CMDTYPE is the prefix to use in the title string.
1112 * CLASS is the class with which to list the nodes of this list (see
1113 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
1114 * everything, ALL_CLASSES for just classes, and non-negative for only things
1115 * in a specific class.
1116 * and STREAM is the output stream on which to print things.
1117 * If you call this routine with a class >= 0, it recurses.
1120 help_list (struct cmd_list_element
*list
, const char *cmdtype
,
1121 enum command_class theclass
, struct ui_file
*stream
)
1124 char *cmdtype1
, *cmdtype2
;
1126 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
1128 len
= strlen (cmdtype
);
1129 cmdtype1
= (char *) alloca (len
+ 1);
1131 cmdtype2
= (char *) alloca (len
+ 4);
1136 memcpy (cmdtype1
+ 1, cmdtype
, len
- 1);
1138 memcpy (cmdtype2
, cmdtype
, len
- 1);
1139 strcpy (cmdtype2
+ len
- 1, " sub");
1142 if (theclass
== all_classes
)
1143 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
1145 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
1147 help_cmd_list (list
, theclass
, cmdtype
, (int) theclass
>= 0, stream
);
1149 if (theclass
== all_classes
)
1151 fprintf_filtered (stream
, "\n\
1152 Type \"help%s\" followed by a class name for a list of commands in ",
1155 fprintf_filtered (stream
, "that class.");
1157 fprintf_filtered (stream
, "\n\
1158 Type \"help all\" for the list of all commands.");
1161 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
1162 cmdtype1
, cmdtype2
);
1164 fputs_filtered ("for ", stream
);
1166 fputs_filtered ("full ", stream
);
1168 fputs_filtered ("documentation.\n", stream
);
1169 fputs_filtered ("Type \"apropos word\" to search "
1170 "for commands related to \"word\".\n", stream
);
1171 fputs_filtered ("Type \"apropos -v word\" for full documentation", stream
);
1173 fputs_filtered (" of commands related to \"word\".\n", stream
);
1174 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
1179 help_all (struct ui_file
*stream
)
1181 struct cmd_list_element
*c
;
1182 int seen_unclassified
= 0;
1184 for (c
= cmdlist
; c
; c
= c
->next
)
1188 /* If this is a class name, print all of the commands in the
1191 if (c
->func
== NULL
)
1193 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
1194 help_cmd_list (cmdlist
, c
->theclass
, "", 1, stream
);
1198 /* While it's expected that all commands are in some class,
1199 as a safety measure, we'll print commands outside of any
1200 class at the end. */
1202 for (c
= cmdlist
; c
; c
= c
->next
)
1207 if (c
->theclass
== no_class
)
1209 if (!seen_unclassified
)
1211 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
1212 seen_unclassified
= 1;
1214 print_help_for_command (c
, "", 1, stream
);
1220 /* See cli-decode.h. */
1223 print_doc_line (struct ui_file
*stream
, const char *str
,
1224 bool for_value_prefix
)
1226 static char *line_buffer
= 0;
1227 static int line_size
;
1233 line_buffer
= (char *) xmalloc (line_size
);
1236 /* Searches for the first end of line or the end of STR. */
1238 while (*p
&& *p
!= '\n')
1240 if (p
- str
> line_size
- 1)
1242 line_size
= p
- str
+ 1;
1243 xfree (line_buffer
);
1244 line_buffer
= (char *) xmalloc (line_size
);
1246 strncpy (line_buffer
, str
, p
- str
);
1247 if (for_value_prefix
)
1249 if (islower (line_buffer
[0]))
1250 line_buffer
[0] = toupper (line_buffer
[0]);
1251 gdb_assert (p
> str
);
1252 if (line_buffer
[p
- str
- 1] == '.')
1253 line_buffer
[p
- str
- 1] = '\0';
1255 line_buffer
[p
- str
] = '\0';
1258 line_buffer
[p
- str
] = '\0';
1259 fputs_filtered (line_buffer
, stream
);
1262 /* Print one-line help for command C.
1263 If RECURSE is non-zero, also print one-line descriptions
1264 of all prefixed subcommands. */
1266 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
1267 int recurse
, struct ui_file
*stream
)
1269 fprintf_styled (stream
, title_style
.style (),
1270 "%s%s", prefix
, c
->name
);
1271 fputs_filtered (" -- ", stream
);
1272 print_doc_line (stream
, c
->doc
, false);
1273 fputs_filtered ("\n", stream
);
1276 && c
->prefixlist
!= 0
1277 && c
->abbrev_flag
== 0)
1278 /* Subcommands of a prefix command typically have 'all_commands'
1279 as class. If we pass CLASS to recursive invocation,
1280 most often we won't see anything. */
1281 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1285 * Implement a help command on command list LIST.
1286 * RECURSE should be non-zero if this should be done recursively on
1287 * all sublists of LIST.
1288 * PREFIX is the prefix to print before each command name.
1289 * STREAM is the stream upon which the output should be written.
1290 * THECLASS should be:
1291 * A non-negative class number to list only commands in that
1293 * ALL_COMMANDS to list all commands in list.
1294 * ALL_CLASSES to list all classes in list.
1296 * Note that RECURSE will be active on *all* sublists, not just the
1297 * ones selected by the criteria above (ie. the selection mechanism
1298 * is at the low level, not the high-level).
1301 help_cmd_list (struct cmd_list_element
*list
, enum command_class theclass
,
1302 const char *prefix
, int recurse
, struct ui_file
*stream
)
1304 struct cmd_list_element
*c
;
1306 for (c
= list
; c
; c
= c
->next
)
1308 if (c
->abbrev_flag
== 0
1309 && !c
->cmd_deprecated
1310 && (theclass
== all_commands
1311 || (theclass
== all_classes
&& c
->func
== NULL
)
1312 || (theclass
== c
->theclass
&& c
->func
!= NULL
)))
1314 print_help_for_command (c
, prefix
, recurse
, stream
);
1316 else if (c
->abbrev_flag
== 0
1318 && !c
->cmd_deprecated
1319 && theclass
== class_user
&& c
->prefixlist
!= NULL
)
1320 /* User-defined commands may be subcommands. */
1321 help_cmd_list (*c
->prefixlist
, theclass
, c
->prefixname
,
1327 /* Search the input clist for 'command'. Return the command if
1328 found (or NULL if not), and return the number of commands
1331 static struct cmd_list_element
*
1332 find_cmd (const char *command
, int len
, struct cmd_list_element
*clist
,
1333 int ignore_help_classes
, int *nfound
)
1335 struct cmd_list_element
*found
, *c
;
1339 for (c
= clist
; c
; c
= c
->next
)
1340 if (!strncmp (command
, c
->name
, len
)
1341 && (!ignore_help_classes
|| c
->func
))
1345 if (c
->name
[len
] == '\0')
1354 /* Return the length of command name in TEXT. */
1357 find_command_name_length (const char *text
)
1359 const char *p
= text
;
1361 /* Treating underscores as part of command words is important
1362 so that "set args_foo()" doesn't get interpreted as
1363 "set args _foo()". */
1364 /* Some characters are only used for TUI specific commands.
1365 However, they are always allowed for the sake of consistency.
1367 Note that this is larger than the character set allowed when
1368 creating user-defined commands. */
1370 /* Recognize the single character commands so that, e.g., "!ls"
1371 works as expected. */
1372 if (*p
== '!' || *p
== '|')
1375 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1376 /* Characters used by TUI specific commands. */
1377 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$')
1383 /* Return TRUE if NAME is a valid user-defined command name.
1384 This is a stricter subset of all gdb commands,
1385 see find_command_name_length. */
1388 valid_user_defined_cmd_name_p (const char *name
)
1395 /* Alas "42" is a legitimate user-defined command.
1396 In the interests of not breaking anything we preserve that. */
1398 for (p
= name
; *p
!= '\0'; ++p
)
1411 /* This routine takes a line of TEXT and a CLIST in which to start the
1412 lookup. When it returns it will have incremented the text pointer past
1413 the section of text it matched, set *RESULT_LIST to point to the list in
1414 which the last word was matched, and will return a pointer to the cmd
1415 list element which the text matches. It will return NULL if no match at
1416 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1417 matches are possible; in this case *RESULT_LIST will be set to point to
1418 the list in which there are ambiguous choices (and *TEXT will be set to
1419 the ambiguous text string).
1421 If the located command was an abbreviation, this routine returns the base
1422 command of the abbreviation.
1424 It does no error reporting whatsoever; control will always return
1425 to the superior routine.
1427 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1428 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1429 if no prefix command was ever found. For example, in the case of "info a",
1430 "info" matches without ambiguity, but "a" could be "args" or "address", so
1431 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1432 RESULT_LIST should not be interpreted as a pointer to the beginning of a
1433 list; it simply points to a specific command. In the case of an ambiguous
1434 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1435 "info t" can be "info types" or "info target"; upon return *TEXT has been
1436 advanced past "info ").
1438 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1439 affect the operation).
1441 This routine does *not* modify the text pointed to by TEXT.
1443 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1444 are actually help classes rather than commands (i.e. the function field of
1445 the struct cmd_list_element is NULL). */
1447 struct cmd_list_element
*
1448 lookup_cmd_1 (const char **text
, struct cmd_list_element
*clist
,
1449 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1453 struct cmd_list_element
*found
, *c
;
1454 const char *line
= *text
;
1456 while (**text
== ' ' || **text
== '\t')
1459 /* Identify the name of the command. */
1460 len
= find_command_name_length (*text
);
1462 /* If nothing but whitespace, return 0. */
1466 /* *text and p now bracket the first command word to lookup (and
1467 it's length is len). We copy this into a local temporary. */
1470 command
= (char *) alloca (len
+ 1);
1471 memcpy (command
, *text
, len
);
1472 command
[len
] = '\0';
1477 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1479 /* If nothing matches, we have a simple failure. */
1485 if (result_list
!= NULL
)
1486 /* Will be modified in calling routine
1487 if we know what the prefix command is. */
1489 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1492 /* We've matched something on this list. Move text pointer forward. */
1496 if (found
->cmd_pointer
)
1498 /* We drop the alias (abbreviation) in favor of the command it
1499 is pointing to. If the alias is deprecated, though, we need to
1500 warn the user about it before we drop it. Note that while we
1501 are warning about the alias, we may also warn about the command
1502 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1505 if (found
->deprecated_warn_user
)
1506 deprecated_cmd_warning (line
);
1507 found
= found
->cmd_pointer
;
1509 /* If we found a prefix command, keep looking. */
1511 if (found
->prefixlist
)
1513 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1514 ignore_help_classes
);
1517 /* Didn't find anything; this is as far as we got. */
1518 if (result_list
!= NULL
)
1519 *result_list
= clist
;
1522 else if (c
== CMD_LIST_AMBIGUOUS
)
1524 /* We've gotten this far properly, but the next step is
1525 ambiguous. We need to set the result list to the best
1526 we've found (if an inferior hasn't already set it). */
1527 if (result_list
!= NULL
)
1529 /* This used to say *result_list = *found->prefixlist.
1530 If that was correct, need to modify the documentation
1531 at the top of this function to clarify what is
1532 supposed to be going on. */
1533 *result_list
= found
;
1544 if (result_list
!= NULL
)
1545 *result_list
= clist
;
1550 /* All this hair to move the space to the front of cmdtype */
1553 undef_cmd_error (const char *cmdtype
, const char *q
)
1555 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1558 *cmdtype
? " " : "",
1559 (int) strlen (cmdtype
) - 1,
1563 /* Look up the contents of *LINE as a command in the command list LIST.
1564 LIST is a chain of struct cmd_list_element's.
1565 If it is found, return the struct cmd_list_element for that command
1566 and update *LINE to point after the command name, at the first argument.
1567 If not found, call error if ALLOW_UNKNOWN is zero
1568 otherwise (or if error returns) return zero.
1569 Call error if specified command is ambiguous,
1570 unless ALLOW_UNKNOWN is negative.
1571 CMDTYPE precedes the word "command" in the error message.
1573 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1574 elements which are actually help classes rather than commands (i.e.
1575 the function field of the struct cmd_list_element is 0). */
1577 struct cmd_list_element
*
1578 lookup_cmd (const char **line
, struct cmd_list_element
*list
,
1579 const char *cmdtype
,
1580 int allow_unknown
, int ignore_help_classes
)
1582 struct cmd_list_element
*last_list
= 0;
1583 struct cmd_list_element
*c
;
1585 /* Note: Do not remove trailing whitespace here because this
1586 would be wrong for complete_command. Jim Kingdon */
1589 error (_("Lack of needed %scommand"), cmdtype
);
1591 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1598 int len
= find_command_name_length (*line
);
1600 q
= (char *) alloca (len
+ 1);
1601 strncpy (q
, *line
, len
);
1603 undef_cmd_error (cmdtype
, q
);
1608 else if (c
== CMD_LIST_AMBIGUOUS
)
1610 /* Ambigous. Local values should be off prefixlist or called
1612 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1614 const char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1615 struct cmd_list_element
*local_list
=
1616 (last_list
? *(last_list
->prefixlist
) : list
);
1618 if (local_allow_unknown
< 0)
1621 return last_list
; /* Found something. */
1623 return 0; /* Found nothing. */
1627 /* Report as error. */
1632 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1633 && (*line
)[amb_len
] != '\t');
1638 for (c
= local_list
; c
; c
= c
->next
)
1639 if (!strncmp (*line
, c
->name
, amb_len
))
1641 if (strlen (ambbuf
) + strlen (c
->name
) + 6
1642 < (int) sizeof ambbuf
)
1644 if (strlen (ambbuf
))
1645 strcat (ambbuf
, ", ");
1646 strcat (ambbuf
, c
->name
);
1650 strcat (ambbuf
, "..");
1654 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1660 if (c
->type
== set_cmd
&& **line
!= '\0' && !isspace (**line
))
1661 error (_("Argument must be preceded by space."));
1663 /* We've got something. It may still not be what the caller
1664 wants (if this command *needs* a subcommand). */
1665 while (**line
== ' ' || **line
== '\t')
1668 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1669 undef_cmd_error (c
->prefixname
, *line
);
1671 /* Seems to be what he wants. Return it. */
1677 /* We are here presumably because an alias or command in TEXT is
1678 deprecated and a warning message should be generated. This
1679 function decodes TEXT and potentially generates a warning message
1682 Example for 'set endian big' which has a fictitious alias 'seb'.
1684 If alias wasn't used in TEXT, and the command is deprecated:
1685 "warning: 'set endian big' is deprecated."
1687 If alias was used, and only the alias is deprecated:
1688 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1690 If alias was used and command is deprecated (regardless of whether
1691 the alias itself is deprecated:
1693 "warning: 'set endian big' (seb) is deprecated."
1695 After the message has been sent, clear the appropriate flags in the
1696 command and/or the alias so the user is no longer bothered.
1700 deprecated_cmd_warning (const char *text
)
1702 struct cmd_list_element
*alias
= NULL
;
1703 struct cmd_list_element
*prefix_cmd
= NULL
;
1704 struct cmd_list_element
*cmd
= NULL
;
1706 if (!lookup_cmd_composition (text
, &alias
, &prefix_cmd
, &cmd
))
1707 /* Return if text doesn't evaluate to a command. */
1710 if (!((alias
? alias
->deprecated_warn_user
: 0)
1711 || cmd
->deprecated_warn_user
) )
1712 /* Return if nothing is deprecated. */
1715 printf_filtered ("Warning:");
1717 if (alias
&& !cmd
->cmd_deprecated
)
1718 printf_filtered (" '%s', an alias for the", alias
->name
);
1720 printf_filtered (" command '");
1723 printf_filtered ("%s", prefix_cmd
->prefixname
);
1725 printf_filtered ("%s", cmd
->name
);
1727 if (alias
&& cmd
->cmd_deprecated
)
1728 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1730 printf_filtered ("' is deprecated.\n");
1733 /* If it is only the alias that is deprecated, we want to indicate
1734 the new alias, otherwise we'll indicate the new command. */
1736 if (alias
&& !cmd
->cmd_deprecated
)
1738 if (alias
->replacement
)
1739 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1741 printf_filtered ("No alternative known.\n\n");
1745 if (cmd
->replacement
)
1746 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1748 printf_filtered ("No alternative known.\n\n");
1751 /* We've warned you, now we'll keep quiet. */
1753 alias
->deprecated_warn_user
= 0;
1755 cmd
->deprecated_warn_user
= 0;
1759 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1760 Return 1 on success, 0 on failure.
1762 If LINE refers to an alias, *alias will point to that alias.
1764 If LINE is a postfix command (i.e. one that is preceded by a prefix
1765 command) set *prefix_cmd.
1767 Set *cmd to point to the command LINE indicates.
1769 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1770 exist, they are NULL when we return.
1774 lookup_cmd_composition (const char *text
,
1775 struct cmd_list_element
**alias
,
1776 struct cmd_list_element
**prefix_cmd
,
1777 struct cmd_list_element
**cmd
)
1781 struct cmd_list_element
*cur_list
;
1782 struct cmd_list_element
*prev_cmd
;
1792 /* Go through as many command lists as we need to,
1793 to find the command TEXT refers to. */
1797 while (*text
== ' ' || *text
== '\t')
1800 /* Identify the name of the command. */
1801 len
= find_command_name_length (text
);
1803 /* If nothing but whitespace, return. */
1807 /* Text is the start of the first command word to lookup (and
1808 it's length is len). We copy this into a local temporary. */
1810 command
= (char *) alloca (len
+ 1);
1811 memcpy (command
, text
, len
);
1812 command
[len
] = '\0';
1817 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1819 if (*cmd
== CMD_LIST_AMBIGUOUS
)
1821 return 0; /* ambiguous */
1825 return 0; /* nothing found */
1828 if ((*cmd
)->cmd_pointer
)
1830 /* cmd was actually an alias, we note that an alias was
1831 used (by assigning *alais) and we set *cmd. */
1833 *cmd
= (*cmd
)->cmd_pointer
;
1835 *prefix_cmd
= prev_cmd
;
1837 if ((*cmd
)->prefixlist
)
1838 cur_list
= *(*cmd
)->prefixlist
;
1846 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1848 /* Return a vector of char pointers which point to the different
1849 possible completions in LIST of TEXT.
1851 WORD points in the same buffer as TEXT, and completions should be
1852 returned relative to this position. For example, suppose TEXT is
1853 "foo" and we want to complete to "foobar". If WORD is "oo", return
1854 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1857 complete_on_cmdlist (struct cmd_list_element
*list
,
1858 completion_tracker
&tracker
,
1859 const char *text
, const char *word
,
1860 int ignore_help_classes
)
1862 struct cmd_list_element
*ptr
;
1863 int textlen
= strlen (text
);
1865 int saw_deprecated_match
= 0;
1867 /* We do one or two passes. In the first pass, we skip deprecated
1868 commands. If we see no matching commands in the first pass, and
1869 if we did happen to see a matching deprecated command, we do
1870 another loop to collect those. */
1871 for (pass
= 0; pass
< 2; ++pass
)
1873 bool got_matches
= false;
1875 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1876 if (!strncmp (ptr
->name
, text
, textlen
)
1877 && !ptr
->abbrev_flag
1878 && (!ignore_help_classes
|| ptr
->func
1879 || ptr
->prefixlist
))
1883 if (ptr
->cmd_deprecated
)
1885 saw_deprecated_match
= 1;
1890 tracker
.add_completion
1891 (make_completion_match_str (ptr
->name
, text
, word
));
1898 /* If we saw no matching deprecated commands in the first pass,
1900 if (!saw_deprecated_match
)
1905 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1907 /* Add the different possible completions in ENUMLIST of TEXT.
1909 WORD points in the same buffer as TEXT, and completions should be
1910 returned relative to this position. For example, suppose TEXT is "foo"
1911 and we want to complete to "foobar". If WORD is "oo", return
1912 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1915 complete_on_enum (completion_tracker
&tracker
,
1916 const char *const *enumlist
,
1917 const char *text
, const char *word
)
1919 int textlen
= strlen (text
);
1923 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1924 if (strncmp (name
, text
, textlen
) == 0)
1925 tracker
.add_completion (make_completion_match_str (name
, text
, word
));
1929 /* Check function pointer. */
1931 cmd_func_p (struct cmd_list_element
*cmd
)
1933 return (cmd
->func
!= NULL
);
1937 /* Call the command function. */
1939 cmd_func (struct cmd_list_element
*cmd
, const char *args
, int from_tty
)
1941 if (cmd_func_p (cmd
))
1943 gdb::optional
<scoped_restore_tmpl
<int>> restore_suppress
;
1945 if (cmd
->suppress_notification
!= NULL
)
1946 restore_suppress
.emplace (cmd
->suppress_notification
, 1);
1948 (*cmd
->func
) (cmd
, args
, from_tty
);
1951 error (_("Invalid command"));
1955 cli_user_command_p (struct cmd_list_element
*cmd
)
1957 return (cmd
->theclass
== class_user
1958 && (cmd
->func
== do_const_cfunc
|| cmd
->func
== do_sfunc
));