gdb: add cmd_list_element::is_alias
[binutils-gdb.git] / gdb / cli / cli-decode.c
1 /* Handle lists of commands, their decoding and documentation, for GDB.
2
3 Copyright (C) 1986-2021 Free Software Foundation, Inc.
4
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.
9
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.
14
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/>. */
17
18 #include "defs.h"
19 #include "symtab.h"
20 #include <ctype.h>
21 #include "gdb_regex.h"
22 #include "completer.h"
23 #include "ui-out.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"
28
29 /* Prototypes for local functions. */
30
31 static void undef_cmd_error (const char *, const char *);
32
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);
39
40 static struct cmd_list_element *find_cmd (const char *command,
41 int len,
42 struct cmd_list_element *clist,
43 int ignore_help_classes,
44 int *nfound);
45
46 static void help_cmd_list (struct cmd_list_element *list,
47 enum command_class theclass,
48 bool recurse,
49 struct ui_file *stream);
50
51 static void help_all (struct ui_file *stream);
52
53 static int lookup_cmd_composition_1 (const char *text,
54 struct cmd_list_element **alias,
55 struct cmd_list_element **prefix_cmd,
56 struct cmd_list_element **cmd,
57 struct cmd_list_element *cur_list);
58
59 /* Look up a command whose 'subcommands' field is SUBCOMMANDS. Return the
60 command if found, otherwise return NULL. */
61
62 static struct cmd_list_element *
63 lookup_cmd_with_subcommands (cmd_list_element **subcommands,
64 cmd_list_element *list)
65 {
66 struct cmd_list_element *p = NULL;
67
68 for (p = list; p != NULL; p = p->next)
69 {
70 struct cmd_list_element *q;
71
72 if (p->subcommands == NULL)
73 continue;
74 else if (p->subcommands == subcommands)
75 {
76 /* If we found an alias, we must return the aliased
77 command. */
78 return p->is_alias () ? p->alias_target : p;
79 }
80
81 q = lookup_cmd_with_subcommands (subcommands, *(p->subcommands));
82 if (q != NULL)
83 return q;
84 }
85
86 return NULL;
87 }
88
89 static void
90 print_help_for_command (struct cmd_list_element *c,
91 bool recurse, struct ui_file *stream);
92
93 \f
94 /* Set the callback function for the specified command. For each both
95 the commands callback and func() are set. The latter set to a
96 bounce function (unless cfunc / sfunc is NULL that is). */
97
98 static void
99 do_const_cfunc (struct cmd_list_element *c, const char *args, int from_tty)
100 {
101 c->function.const_cfunc (args, from_tty);
102 }
103
104 static void
105 set_cmd_cfunc (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc)
106 {
107 if (cfunc == NULL)
108 cmd->func = NULL;
109 else
110 cmd->func = do_const_cfunc;
111 cmd->function.const_cfunc = cfunc;
112 }
113
114 static void
115 do_sfunc (struct cmd_list_element *c, const char *args, int from_tty)
116 {
117 c->function.sfunc (args, from_tty, c);
118 }
119
120 void
121 set_cmd_sfunc (struct cmd_list_element *cmd, cmd_const_sfunc_ftype *sfunc)
122 {
123 if (sfunc == NULL)
124 cmd->func = NULL;
125 else
126 cmd->func = do_sfunc;
127 cmd->function.sfunc = sfunc;
128 }
129
130 int
131 cmd_cfunc_eq (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc)
132 {
133 return cmd->func == do_const_cfunc && cmd->function.const_cfunc == cfunc;
134 }
135
136 void
137 set_cmd_context (struct cmd_list_element *cmd, void *context)
138 {
139 cmd->context = context;
140 }
141
142 void *
143 get_cmd_context (struct cmd_list_element *cmd)
144 {
145 return cmd->context;
146 }
147
148 void
149 set_cmd_completer (struct cmd_list_element *cmd, completer_ftype *completer)
150 {
151 cmd->completer = completer; /* Ok. */
152 }
153
154 /* See definition in commands.h. */
155
156 void
157 set_cmd_completer_handle_brkchars (struct cmd_list_element *cmd,
158 completer_handle_brkchars_ftype *func)
159 {
160 cmd->completer_handle_brkchars = func;
161 }
162
163 std::string
164 cmd_list_element::prefixname () const
165 {
166 if (this->subcommands == nullptr)
167 /* Not a prefix command. */
168 return "";
169
170 std::string prefixname;
171 if (this->prefix != nullptr)
172 prefixname = this->prefix->prefixname ();
173
174 prefixname += this->name;
175 prefixname += " ";
176
177 return prefixname;
178 }
179
180 /* Add element named NAME.
181 Space for NAME and DOC must be allocated by the caller.
182 CLASS is the top level category into which commands are broken down
183 for "help" purposes.
184 FUN should be the function to execute the command;
185 it will get a character string as argument, with leading
186 and trailing blanks already eliminated.
187
188 DOC is a documentation string for the command.
189 Its first line should be a complete sentence.
190 It should start with ? for a command that is an abbreviation
191 or with * for a command that most users don't need to know about.
192
193 Add this command to command list *LIST.
194
195 Returns a pointer to the added command (not necessarily the head
196 of *LIST). */
197
198 static struct cmd_list_element *
199 do_add_cmd (const char *name, enum command_class theclass,
200 const char *doc, struct cmd_list_element **list)
201 {
202 struct cmd_list_element *c = new struct cmd_list_element (name, theclass,
203 doc);
204 struct cmd_list_element *p, *iter;
205
206 /* Turn each alias of the old command into an alias of the new
207 command. */
208 c->aliases = delete_cmd (name, list, &c->hook_pre, &c->hookee_pre,
209 &c->hook_post, &c->hookee_post);
210 for (iter = c->aliases; iter; iter = iter->alias_chain)
211 iter->alias_target = c;
212 if (c->hook_pre)
213 c->hook_pre->hookee_pre = c;
214 if (c->hookee_pre)
215 c->hookee_pre->hook_pre = c;
216 if (c->hook_post)
217 c->hook_post->hookee_post = c;
218 if (c->hookee_post)
219 c->hookee_post->hook_post = c;
220
221 if (*list == NULL || strcmp ((*list)->name, name) >= 0)
222 {
223 c->next = *list;
224 *list = c;
225 }
226 else
227 {
228 p = *list;
229 while (p->next && strcmp (p->next->name, name) <= 0)
230 {
231 p = p->next;
232 }
233 c->next = p->next;
234 p->next = c;
235 }
236
237 /* Search the prefix cmd of C, and assigns it to C->prefix.
238 See also add_prefix_cmd and update_prefix_field_of_prefixed_commands. */
239 cmd_list_element *prefixcmd = lookup_cmd_with_subcommands (list, cmdlist);
240 c->prefix = prefixcmd;
241
242
243 return c;
244 }
245
246 struct cmd_list_element *
247 add_cmd (const char *name, enum command_class theclass,
248 const char *doc, struct cmd_list_element **list)
249 {
250 cmd_list_element *result = do_add_cmd (name, theclass, doc, list);
251 result->func = NULL;
252 result->function.const_cfunc = NULL;
253 return result;
254 }
255
256 struct cmd_list_element *
257 add_cmd (const char *name, enum command_class theclass,
258 cmd_const_cfunc_ftype *fun,
259 const char *doc, struct cmd_list_element **list)
260 {
261 cmd_list_element *result = do_add_cmd (name, theclass, doc, list);
262 set_cmd_cfunc (result, fun);
263 return result;
264 }
265
266 /* Add an element with a suppress notification to the LIST of commands. */
267
268 struct cmd_list_element *
269 add_cmd_suppress_notification (const char *name, enum command_class theclass,
270 cmd_const_cfunc_ftype *fun, const char *doc,
271 struct cmd_list_element **list,
272 int *suppress_notification)
273 {
274 struct cmd_list_element *element;
275
276 element = add_cmd (name, theclass, fun, doc, list);
277 element->suppress_notification = suppress_notification;
278
279 return element;
280 }
281
282
283 /* Deprecates a command CMD.
284 REPLACEMENT is the name of the command which should be used in
285 place of this command, or NULL if no such command exists.
286
287 This function does not check to see if command REPLACEMENT exists
288 since gdb may not have gotten around to adding REPLACEMENT when
289 this function is called.
290
291 Returns a pointer to the deprecated command. */
292
293 struct cmd_list_element *
294 deprecate_cmd (struct cmd_list_element *cmd, const char *replacement)
295 {
296 cmd->cmd_deprecated = 1;
297 cmd->deprecated_warn_user = 1;
298
299 if (replacement != NULL)
300 cmd->replacement = replacement;
301 else
302 cmd->replacement = NULL;
303
304 return cmd;
305 }
306
307 struct cmd_list_element *
308 add_alias_cmd (const char *name, cmd_list_element *target,
309 enum command_class theclass, int abbrev_flag,
310 struct cmd_list_element **list)
311 {
312 gdb_assert (target != nullptr);
313
314 struct cmd_list_element *c = add_cmd (name, theclass, target->doc, list);
315
316 /* If TARGET->DOC can be freed, we should make another copy. */
317 if (target->doc_allocated)
318 {
319 c->doc = xstrdup (target->doc);
320 c->doc_allocated = 1;
321 }
322 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
323 c->func = target->func;
324 c->function = target->function;
325 c->subcommands = target->subcommands;
326 c->allow_unknown = target->allow_unknown;
327 c->abbrev_flag = abbrev_flag;
328 c->alias_target = target;
329 c->alias_chain = target->aliases;
330 target->aliases = c;
331
332 return c;
333 }
334
335 struct cmd_list_element *
336 add_alias_cmd (const char *name, const char *target_name,
337 enum command_class theclass, int abbrev_flag,
338 struct cmd_list_element **list)
339 {
340 const char *tmp = target_name;
341 cmd_list_element *target = lookup_cmd (&tmp, *list, "", NULL, 1, 1);
342
343 return add_alias_cmd (name, target, theclass, abbrev_flag, list);
344 }
345
346
347 /* Update the prefix field of all sub-commands of the prefix command C.
348 We must do this when a prefix command is defined as the GDB init sequence
349 does not guarantee that a prefix command is created before its sub-commands.
350 For example, break-catch-sig.c initialization runs before breakpoint.c
351 initialization, but it is breakpoint.c that creates the "catch" command used
352 by the "catch signal" command created by break-catch-sig.c. */
353
354 static void
355 update_prefix_field_of_prefixed_commands (struct cmd_list_element *c)
356 {
357 for (cmd_list_element *p = *c->subcommands; p != NULL; p = p->next)
358 {
359 p->prefix = c;
360
361 /* We must recursively update the prefix field to cover
362 e.g. 'info auto-load libthread-db' where the creation
363 order was:
364 libthread-db
365 auto-load
366 info
367 In such a case, when 'auto-load' was created by do_add_cmd,
368 the 'libthread-db' prefix field could not be updated, as the
369 'auto-load' command was not yet reachable by
370 lookup_cmd_for_subcommands (list, cmdlist)
371 that searches from the top level 'cmdlist'. */
372 if (p->subcommands != nullptr)
373 update_prefix_field_of_prefixed_commands (p);
374 }
375 }
376
377
378 /* Like add_cmd but adds an element for a command prefix: a name that
379 should be followed by a subcommand to be looked up in another
380 command list. SUBCOMMANDS should be the address of the variable
381 containing that list. */
382
383 struct cmd_list_element *
384 add_prefix_cmd (const char *name, enum command_class theclass,
385 cmd_const_cfunc_ftype *fun,
386 const char *doc, struct cmd_list_element **subcommands,
387 int allow_unknown, struct cmd_list_element **list)
388 {
389 struct cmd_list_element *c = add_cmd (name, theclass, fun, doc, list);
390
391 c->subcommands = subcommands;
392 c->allow_unknown = allow_unknown;
393
394 /* Now that prefix command C is defined, we need to set the prefix field
395 of all prefixed commands that were defined before C itself was defined. */
396 update_prefix_field_of_prefixed_commands (c);
397
398 return c;
399 }
400
401 /* A helper function for add_basic_prefix_cmd. This is a command
402 function that just forwards to help_list. */
403
404 static void
405 do_prefix_cmd (const char *args, int from_tty, struct cmd_list_element *c)
406 {
407 /* Look past all aliases. */
408 while (c->is_alias ())
409 c = c->alias_target;
410
411 help_list (*c->subcommands, c->prefixname ().c_str (),
412 all_commands, gdb_stdout);
413 }
414
415 /* See command.h. */
416
417 struct cmd_list_element *
418 add_basic_prefix_cmd (const char *name, enum command_class theclass,
419 const char *doc, struct cmd_list_element **subcommands,
420 int allow_unknown, struct cmd_list_element **list)
421 {
422 struct cmd_list_element *cmd = add_prefix_cmd (name, theclass, nullptr,
423 doc, subcommands,
424 allow_unknown, list);
425 set_cmd_sfunc (cmd, do_prefix_cmd);
426 return cmd;
427 }
428
429 /* A helper function for add_show_prefix_cmd. This is a command
430 function that just forwards to cmd_show_list. */
431
432 static void
433 do_show_prefix_cmd (const char *args, int from_tty, struct cmd_list_element *c)
434 {
435 cmd_show_list (*c->subcommands, from_tty);
436 }
437
438 /* See command.h. */
439
440 struct cmd_list_element *
441 add_show_prefix_cmd (const char *name, enum command_class theclass,
442 const char *doc, struct cmd_list_element **subcommands,
443 int allow_unknown, struct cmd_list_element **list)
444 {
445 struct cmd_list_element *cmd = add_prefix_cmd (name, theclass, nullptr,
446 doc, subcommands,
447 allow_unknown, list);
448 set_cmd_sfunc (cmd, do_show_prefix_cmd);
449 return cmd;
450 }
451
452 /* Like ADD_PREFIX_CMD but sets the suppress_notification pointer on the
453 new command list element. */
454
455 struct cmd_list_element *
456 add_prefix_cmd_suppress_notification
457 (const char *name, enum command_class theclass,
458 cmd_const_cfunc_ftype *fun,
459 const char *doc, struct cmd_list_element **subcommands,
460 int allow_unknown, struct cmd_list_element **list,
461 int *suppress_notification)
462 {
463 struct cmd_list_element *element
464 = add_prefix_cmd (name, theclass, fun, doc, subcommands,
465 allow_unknown, list);
466 element->suppress_notification = suppress_notification;
467 return element;
468 }
469
470 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
471
472 struct cmd_list_element *
473 add_abbrev_prefix_cmd (const char *name, enum command_class theclass,
474 cmd_const_cfunc_ftype *fun, const char *doc,
475 struct cmd_list_element **subcommands,
476 int allow_unknown, struct cmd_list_element **list)
477 {
478 struct cmd_list_element *c = add_cmd (name, theclass, fun, doc, list);
479
480 c->subcommands = subcommands;
481 c->allow_unknown = allow_unknown;
482 c->abbrev_flag = 1;
483 return c;
484 }
485
486 /* This is an empty "cfunc". */
487 void
488 not_just_help_class_command (const char *args, int from_tty)
489 {
490 }
491
492 /* This is an empty "sfunc". */
493
494 static void
495 empty_sfunc (const char *args, int from_tty, struct cmd_list_element *c)
496 {
497 }
498
499 /* Add element named NAME to command list LIST (the list for set/show
500 or some sublist thereof).
501 TYPE is set_cmd or show_cmd.
502 CLASS is as in add_cmd.
503 VAR_TYPE is the kind of thing we are setting.
504 VAR is address of the variable being controlled by this command.
505 DOC is the documentation string. */
506
507 static struct cmd_list_element *
508 add_set_or_show_cmd (const char *name,
509 enum cmd_types type,
510 enum command_class theclass,
511 var_types var_type,
512 void *var,
513 const char *doc,
514 struct cmd_list_element **list)
515 {
516 struct cmd_list_element *c = add_cmd (name, theclass, doc, list);
517
518 gdb_assert (type == set_cmd || type == show_cmd);
519 c->type = type;
520 c->var_type = var_type;
521 c->var = var;
522 /* This needs to be something besides NULL so that this isn't
523 treated as a help class. */
524 set_cmd_sfunc (c, empty_sfunc);
525 return c;
526 }
527
528 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
529 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
530 setting. VAR is address of the variable being controlled by this
531 command. SET_FUNC and SHOW_FUNC are the callback functions (if
532 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
533 strings. PRINT the format string to print the value. SET_RESULT
534 and SHOW_RESULT, if not NULL, are set to the resulting command
535 structures. */
536
537 static void
538 add_setshow_cmd_full (const char *name,
539 enum command_class theclass,
540 var_types var_type, void *var,
541 const char *set_doc, const char *show_doc,
542 const char *help_doc,
543 cmd_const_sfunc_ftype *set_func,
544 show_value_ftype *show_func,
545 struct cmd_list_element **set_list,
546 struct cmd_list_element **show_list,
547 struct cmd_list_element **set_result,
548 struct cmd_list_element **show_result)
549 {
550 struct cmd_list_element *set;
551 struct cmd_list_element *show;
552 char *full_set_doc;
553 char *full_show_doc;
554
555 if (help_doc != NULL)
556 {
557 full_set_doc = xstrprintf ("%s\n%s", set_doc, help_doc);
558 full_show_doc = xstrprintf ("%s\n%s", show_doc, help_doc);
559 }
560 else
561 {
562 full_set_doc = xstrdup (set_doc);
563 full_show_doc = xstrdup (show_doc);
564 }
565 set = add_set_or_show_cmd (name, set_cmd, theclass, var_type, var,
566 full_set_doc, set_list);
567 set->doc_allocated = 1;
568
569 if (set_func != NULL)
570 set_cmd_sfunc (set, set_func);
571
572 show = add_set_or_show_cmd (name, show_cmd, theclass, var_type, var,
573 full_show_doc, show_list);
574 show->doc_allocated = 1;
575 show->show_value_func = show_func;
576 /* Disable the default symbol completer. Doesn't make much sense
577 for the "show" command to complete on anything. */
578 set_cmd_completer (show, nullptr);
579
580 if (set_result != NULL)
581 *set_result = set;
582 if (show_result != NULL)
583 *show_result = show;
584 }
585
586 /* Add element named NAME to command list LIST (the list for set or
587 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
588 of strings which may follow NAME. VAR is address of the variable
589 which will contain the matching string (from ENUMLIST). */
590
591 void
592 add_setshow_enum_cmd (const char *name,
593 enum command_class theclass,
594 const char *const *enumlist,
595 const char **var,
596 const char *set_doc,
597 const char *show_doc,
598 const char *help_doc,
599 cmd_const_sfunc_ftype *set_func,
600 show_value_ftype *show_func,
601 struct cmd_list_element **set_list,
602 struct cmd_list_element **show_list,
603 void *context)
604 {
605 struct cmd_list_element *c, *show;
606
607 add_setshow_cmd_full (name, theclass, var_enum, var,
608 set_doc, show_doc, help_doc,
609 set_func, show_func,
610 set_list, show_list,
611 &c, &show);
612 c->enums = enumlist;
613
614 set_cmd_context (c, context);
615 set_cmd_context (show, context);
616 }
617
618 /* See cli-decode.h. */
619 const char * const auto_boolean_enums[] = { "on", "off", "auto", NULL };
620
621 /* Add an auto-boolean command named NAME to both the set and show
622 command list lists. CLASS is as in add_cmd. VAR is address of the
623 variable which will contain the value. DOC is the documentation
624 string. FUNC is the corresponding callback. */
625 void
626 add_setshow_auto_boolean_cmd (const char *name,
627 enum command_class theclass,
628 enum auto_boolean *var,
629 const char *set_doc, const char *show_doc,
630 const char *help_doc,
631 cmd_const_sfunc_ftype *set_func,
632 show_value_ftype *show_func,
633 struct cmd_list_element **set_list,
634 struct cmd_list_element **show_list)
635 {
636 struct cmd_list_element *c;
637
638 add_setshow_cmd_full (name, theclass, var_auto_boolean, var,
639 set_doc, show_doc, help_doc,
640 set_func, show_func,
641 set_list, show_list,
642 &c, NULL);
643 c->enums = auto_boolean_enums;
644 }
645
646 /* See cli-decode.h. */
647 const char * const boolean_enums[] = { "on", "off", NULL };
648
649 /* Add element named NAME to both the set and show command LISTs (the
650 list for set/show or some sublist thereof). CLASS is as in
651 add_cmd. VAR is address of the variable which will contain the
652 value. SET_DOC and SHOW_DOC are the documentation strings.
653 Returns the new command element. */
654
655 cmd_list_element *
656 add_setshow_boolean_cmd (const char *name, enum command_class theclass, bool *var,
657 const char *set_doc, const char *show_doc,
658 const char *help_doc,
659 cmd_const_sfunc_ftype *set_func,
660 show_value_ftype *show_func,
661 struct cmd_list_element **set_list,
662 struct cmd_list_element **show_list)
663 {
664 struct cmd_list_element *c;
665
666 add_setshow_cmd_full (name, theclass, var_boolean, var,
667 set_doc, show_doc, help_doc,
668 set_func, show_func,
669 set_list, show_list,
670 &c, NULL);
671 c->enums = boolean_enums;
672
673 return c;
674 }
675
676 /* Add element named NAME to both the set and show command LISTs (the
677 list for set/show or some sublist thereof). */
678 void
679 add_setshow_filename_cmd (const char *name, enum command_class theclass,
680 char **var,
681 const char *set_doc, const char *show_doc,
682 const char *help_doc,
683 cmd_const_sfunc_ftype *set_func,
684 show_value_ftype *show_func,
685 struct cmd_list_element **set_list,
686 struct cmd_list_element **show_list)
687 {
688 struct cmd_list_element *set_result;
689
690 add_setshow_cmd_full (name, theclass, var_filename, var,
691 set_doc, show_doc, help_doc,
692 set_func, show_func,
693 set_list, show_list,
694 &set_result, NULL);
695 set_cmd_completer (set_result, filename_completer);
696 }
697
698 /* Add element named NAME to both the set and show command LISTs (the
699 list for set/show or some sublist thereof). */
700 void
701 add_setshow_string_cmd (const char *name, enum command_class theclass,
702 char **var,
703 const char *set_doc, const char *show_doc,
704 const char *help_doc,
705 cmd_const_sfunc_ftype *set_func,
706 show_value_ftype *show_func,
707 struct cmd_list_element **set_list,
708 struct cmd_list_element **show_list)
709 {
710 cmd_list_element *set_cmd;
711
712 add_setshow_cmd_full (name, theclass, var_string, var,
713 set_doc, show_doc, help_doc,
714 set_func, show_func,
715 set_list, show_list,
716 &set_cmd, NULL);
717
718 /* Disable the default symbol completer. */
719 set_cmd_completer (set_cmd, nullptr);
720 }
721
722 /* Add element named NAME to both the set and show command LISTs (the
723 list for set/show or some sublist thereof). */
724 struct cmd_list_element *
725 add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
726 char **var,
727 const char *set_doc, const char *show_doc,
728 const char *help_doc,
729 cmd_const_sfunc_ftype *set_func,
730 show_value_ftype *show_func,
731 struct cmd_list_element **set_list,
732 struct cmd_list_element **show_list)
733 {
734 struct cmd_list_element *set_cmd;
735
736 add_setshow_cmd_full (name, theclass, var_string_noescape, var,
737 set_doc, show_doc, help_doc,
738 set_func, show_func,
739 set_list, show_list,
740 &set_cmd, NULL);
741
742 /* Disable the default symbol completer. */
743 set_cmd_completer (set_cmd, nullptr);
744
745 return set_cmd;
746 }
747
748 /* Add element named NAME to both the set and show command LISTs (the
749 list for set/show or some sublist thereof). */
750 void
751 add_setshow_optional_filename_cmd (const char *name, enum command_class theclass,
752 char **var,
753 const char *set_doc, const char *show_doc,
754 const char *help_doc,
755 cmd_const_sfunc_ftype *set_func,
756 show_value_ftype *show_func,
757 struct cmd_list_element **set_list,
758 struct cmd_list_element **show_list)
759 {
760 struct cmd_list_element *set_result;
761
762 add_setshow_cmd_full (name, theclass, var_optional_filename, var,
763 set_doc, show_doc, help_doc,
764 set_func, show_func,
765 set_list, show_list,
766 &set_result, NULL);
767
768 set_cmd_completer (set_result, filename_completer);
769
770 }
771
772 /* Completes on literal "unlimited". Used by integer commands that
773 support a special "unlimited" value. */
774
775 static void
776 integer_unlimited_completer (struct cmd_list_element *ignore,
777 completion_tracker &tracker,
778 const char *text, const char *word)
779 {
780 static const char * const keywords[] =
781 {
782 "unlimited",
783 NULL,
784 };
785
786 complete_on_enum (tracker, keywords, text, word);
787 }
788
789 /* Add element named NAME to both the set and show command LISTs (the
790 list for set/show or some sublist thereof). CLASS is as in
791 add_cmd. VAR is address of the variable which will contain the
792 value. SET_DOC and SHOW_DOC are the documentation strings. This
793 function is only used in Python API. Please don't use it elsewhere. */
794 void
795 add_setshow_integer_cmd (const char *name, enum command_class theclass,
796 int *var,
797 const char *set_doc, const char *show_doc,
798 const char *help_doc,
799 cmd_const_sfunc_ftype *set_func,
800 show_value_ftype *show_func,
801 struct cmd_list_element **set_list,
802 struct cmd_list_element **show_list)
803 {
804 struct cmd_list_element *set;
805
806 add_setshow_cmd_full (name, theclass, var_integer, var,
807 set_doc, show_doc, help_doc,
808 set_func, show_func,
809 set_list, show_list,
810 &set, NULL);
811
812 set_cmd_completer (set, integer_unlimited_completer);
813 }
814
815 /* Add element named NAME to both the set and show command LISTs (the
816 list for set/show or some sublist thereof). CLASS is as in
817 add_cmd. VAR is address of the variable which will contain the
818 value. SET_DOC and SHOW_DOC are the documentation strings. */
819 void
820 add_setshow_uinteger_cmd (const char *name, enum command_class theclass,
821 unsigned int *var,
822 const char *set_doc, const char *show_doc,
823 const char *help_doc,
824 cmd_const_sfunc_ftype *set_func,
825 show_value_ftype *show_func,
826 struct cmd_list_element **set_list,
827 struct cmd_list_element **show_list)
828 {
829 struct cmd_list_element *set;
830
831 add_setshow_cmd_full (name, theclass, var_uinteger, var,
832 set_doc, show_doc, help_doc,
833 set_func, show_func,
834 set_list, show_list,
835 &set, NULL);
836
837 set_cmd_completer (set, integer_unlimited_completer);
838 }
839
840 /* Add element named NAME to both the set and show command LISTs (the
841 list for set/show or some sublist thereof). CLASS is as in
842 add_cmd. VAR is address of the variable which will contain the
843 value. SET_DOC and SHOW_DOC are the documentation strings. */
844 void
845 add_setshow_zinteger_cmd (const char *name, enum command_class theclass,
846 int *var,
847 const char *set_doc, const char *show_doc,
848 const char *help_doc,
849 cmd_const_sfunc_ftype *set_func,
850 show_value_ftype *show_func,
851 struct cmd_list_element **set_list,
852 struct cmd_list_element **show_list)
853 {
854 add_setshow_cmd_full (name, theclass, var_zinteger, var,
855 set_doc, show_doc, help_doc,
856 set_func, show_func,
857 set_list, show_list,
858 NULL, NULL);
859 }
860
861 void
862 add_setshow_zuinteger_unlimited_cmd (const char *name,
863 enum command_class theclass,
864 int *var,
865 const char *set_doc,
866 const char *show_doc,
867 const char *help_doc,
868 cmd_const_sfunc_ftype *set_func,
869 show_value_ftype *show_func,
870 struct cmd_list_element **set_list,
871 struct cmd_list_element **show_list)
872 {
873 struct cmd_list_element *set;
874
875 add_setshow_cmd_full (name, theclass, var_zuinteger_unlimited, var,
876 set_doc, show_doc, help_doc,
877 set_func, show_func,
878 set_list, show_list,
879 &set, NULL);
880
881 set_cmd_completer (set, integer_unlimited_completer);
882 }
883
884 /* Add element named NAME to both the set and show command LISTs (the
885 list for set/show or some sublist thereof). CLASS is as in
886 add_cmd. VAR is address of the variable which will contain the
887 value. SET_DOC and SHOW_DOC are the documentation strings. */
888 void
889 add_setshow_zuinteger_cmd (const char *name, enum command_class theclass,
890 unsigned int *var,
891 const char *set_doc, const char *show_doc,
892 const char *help_doc,
893 cmd_const_sfunc_ftype *set_func,
894 show_value_ftype *show_func,
895 struct cmd_list_element **set_list,
896 struct cmd_list_element **show_list)
897 {
898 add_setshow_cmd_full (name, theclass, var_zuinteger, var,
899 set_doc, show_doc, help_doc,
900 set_func, show_func,
901 set_list, show_list,
902 NULL, NULL);
903 }
904
905 /* Remove the command named NAME from the command list. Return the
906 list commands which were aliased to the deleted command. If the
907 command had no aliases, return NULL. The various *HOOKs are set to
908 the pre- and post-hook commands for the deleted command. If the
909 command does not have a hook, the corresponding out parameter is
910 set to NULL. */
911
912 static struct cmd_list_element *
913 delete_cmd (const char *name, struct cmd_list_element **list,
914 struct cmd_list_element **prehook,
915 struct cmd_list_element **prehookee,
916 struct cmd_list_element **posthook,
917 struct cmd_list_element **posthookee)
918 {
919 struct cmd_list_element *iter;
920 struct cmd_list_element **previous_chain_ptr;
921 struct cmd_list_element *aliases = NULL;
922
923 *prehook = NULL;
924 *prehookee = NULL;
925 *posthook = NULL;
926 *posthookee = NULL;
927 previous_chain_ptr = list;
928
929 for (iter = *previous_chain_ptr; iter; iter = *previous_chain_ptr)
930 {
931 if (strcmp (iter->name, name) == 0)
932 {
933 if (iter->destroyer)
934 iter->destroyer (iter, iter->context);
935 if (iter->hookee_pre)
936 iter->hookee_pre->hook_pre = 0;
937 *prehook = iter->hook_pre;
938 *prehookee = iter->hookee_pre;
939 if (iter->hookee_post)
940 iter->hookee_post->hook_post = 0;
941 *posthook = iter->hook_post;
942 *posthookee = iter->hookee_post;
943
944 /* Update the link. */
945 *previous_chain_ptr = iter->next;
946
947 aliases = iter->aliases;
948
949 /* If this command was an alias, remove it from the list of
950 aliases. */
951 if (iter->is_alias ())
952 {
953 struct cmd_list_element **prevp = &iter->alias_target->aliases;
954 struct cmd_list_element *a = *prevp;
955
956 while (a != iter)
957 {
958 prevp = &a->alias_chain;
959 a = *prevp;
960 }
961 *prevp = iter->alias_chain;
962 }
963
964 delete iter;
965
966 /* We won't see another command with the same name. */
967 break;
968 }
969 else
970 previous_chain_ptr = &iter->next;
971 }
972
973 return aliases;
974 }
975 \f
976 /* Shorthands to the commands above. */
977
978 /* Add an element to the list of info subcommands. */
979
980 struct cmd_list_element *
981 add_info (const char *name, cmd_const_cfunc_ftype *fun, const char *doc)
982 {
983 return add_cmd (name, class_info, fun, doc, &infolist);
984 }
985
986 /* Add an alias to the list of info subcommands. */
987
988 struct cmd_list_element *
989 add_info_alias (const char *name, const char *target_name, int abbrev_flag)
990 {
991 return add_alias_cmd (name, target_name, class_run, abbrev_flag, &infolist);
992 }
993
994 /* Add an element to the list of commands. */
995
996 struct cmd_list_element *
997 add_com (const char *name, enum command_class theclass,
998 cmd_const_cfunc_ftype *fun,
999 const char *doc)
1000 {
1001 return add_cmd (name, theclass, fun, doc, &cmdlist);
1002 }
1003
1004 /* Add an alias or abbreviation command to the list of commands.
1005 For aliases predefined by GDB (such as bt), THECLASS must be
1006 different of class_alias, as class_alias is used to identify
1007 user defined aliases. */
1008
1009 struct cmd_list_element *
1010 add_com_alias (const char *name, const char *target_name,
1011 command_class theclass, int abbrev_flag)
1012 {
1013 return add_alias_cmd (name, target_name, theclass, abbrev_flag, &cmdlist);
1014 }
1015
1016 /* Add an element with a suppress notification to the list of commands. */
1017
1018 struct cmd_list_element *
1019 add_com_suppress_notification (const char *name, enum command_class theclass,
1020 cmd_const_cfunc_ftype *fun, const char *doc,
1021 int *suppress_notification)
1022 {
1023 return add_cmd_suppress_notification (name, theclass, fun, doc,
1024 &cmdlist, suppress_notification);
1025 }
1026
1027 /* Print the prefix of C followed by name of C in title style. */
1028
1029 static void
1030 fput_command_name_styled (struct cmd_list_element *c, struct ui_file *stream)
1031 {
1032 std::string prefixname
1033 = c->prefix == nullptr ? "" : c->prefix->prefixname ();
1034
1035 fprintf_styled (stream, title_style.style (), "%s%s",
1036 prefixname.c_str (), c->name);
1037 }
1038
1039 /* Print the definition of alias C using title style for alias
1040 and aliased command. */
1041
1042 static void
1043 fput_alias_definition_styled (struct cmd_list_element *c,
1044 struct ui_file *stream)
1045 {
1046 gdb_assert (c->is_alias ());
1047 fputs_filtered (" alias ", stream);
1048 fput_command_name_styled (c, stream);
1049 fprintf_filtered (stream, " = ");
1050 fput_command_name_styled (c->alias_target, stream);
1051 fprintf_filtered (stream, " %s\n", c->default_args.c_str ());
1052 }
1053
1054 /* Print the definition of the aliases of CMD that have default args. */
1055
1056 static void
1057 fput_aliases_definition_styled (struct cmd_list_element *cmd,
1058 struct ui_file *stream)
1059 {
1060 if (cmd->aliases != nullptr)
1061 {
1062 for (cmd_list_element *iter = cmd->aliases;
1063 iter;
1064 iter = iter->alias_chain)
1065 {
1066 if (!iter->default_args.empty ())
1067 fput_alias_definition_styled (iter, stream);
1068 }
1069 }
1070 }
1071
1072
1073 /* If C has one or more aliases, style print the name of C and
1074 the name of its aliases, separated by commas.
1075 If ALWAYS_FPUT_C_NAME, print the name of C even if it has no aliases.
1076 If one or more names are printed, POSTFIX is printed after the last name.
1077 */
1078
1079 static void
1080 fput_command_names_styled (struct cmd_list_element *c,
1081 bool always_fput_c_name, const char *postfix,
1082 struct ui_file *stream)
1083 {
1084 if (always_fput_c_name || c->aliases != nullptr)
1085 fput_command_name_styled (c, stream);
1086 if (c->aliases != nullptr)
1087 {
1088 for (cmd_list_element *iter = c->aliases; iter; iter = iter->alias_chain)
1089 {
1090 fputs_filtered (", ", stream);
1091 wrap_here (" ");
1092 fput_command_name_styled (iter, stream);
1093 }
1094 }
1095 if (always_fput_c_name || c->aliases != nullptr)
1096 fputs_filtered (postfix, stream);
1097 }
1098
1099 /* If VERBOSE, print the full help for command C and highlight the
1100 documentation parts matching HIGHLIGHT,
1101 otherwise print only one-line help for command C. */
1102
1103 static void
1104 print_doc_of_command (struct cmd_list_element *c, const char *prefix,
1105 bool verbose, compiled_regex &highlight,
1106 struct ui_file *stream)
1107 {
1108 /* When printing the full documentation, add a line to separate
1109 this documentation from the previous command help, in the likely
1110 case that apropos finds several commands. */
1111 if (verbose)
1112 fputs_filtered ("\n", stream);
1113
1114 fput_command_names_styled (c, true,
1115 verbose ? "" : " -- ", stream);
1116 if (verbose)
1117 {
1118 fputs_filtered ("\n", stream);
1119 fput_aliases_definition_styled (c, stream);
1120 fputs_highlighted (c->doc, highlight, stream);
1121 fputs_filtered ("\n", stream);
1122 }
1123 else
1124 {
1125 print_doc_line (stream, c->doc, false);
1126 fputs_filtered ("\n", stream);
1127 fput_aliases_definition_styled (c, stream);
1128 }
1129 }
1130
1131 /* Recursively walk the commandlist structures, and print out the
1132 documentation of commands that match our regex in either their
1133 name, or their documentation.
1134 If VERBOSE, prints the complete documentation and highlight the
1135 documentation parts matching REGEX, otherwise prints only
1136 the first line.
1137 */
1138 void
1139 apropos_cmd (struct ui_file *stream,
1140 struct cmd_list_element *commandlist,
1141 bool verbose, compiled_regex &regex, const char *prefix)
1142 {
1143 struct cmd_list_element *c;
1144 int returnvalue;
1145
1146 /* Walk through the commands. */
1147 for (c=commandlist;c;c=c->next)
1148 {
1149 if (c->is_alias ())
1150 {
1151 /* Command aliases/abbreviations are skipped to ensure we print the
1152 doc of a command only once, when encountering the aliased
1153 command. */
1154 continue;
1155 }
1156
1157 returnvalue = -1; /* Needed to avoid double printing. */
1158 if (c->name != NULL)
1159 {
1160 size_t name_len = strlen (c->name);
1161
1162 /* Try to match against the name. */
1163 returnvalue = regex.search (c->name, name_len, 0, name_len, NULL);
1164 if (returnvalue >= 0)
1165 print_doc_of_command (c, prefix, verbose, regex, stream);
1166
1167 /* Try to match against the name of the aliases. */
1168 for (cmd_list_element *iter = c->aliases;
1169 returnvalue < 0 && iter;
1170 iter = iter->alias_chain)
1171 {
1172 name_len = strlen (iter->name);
1173 returnvalue = regex.search (iter->name, name_len, 0, name_len, NULL);
1174 if (returnvalue >= 0)
1175 print_doc_of_command (c, prefix, verbose, regex, stream);
1176 }
1177 }
1178 if (c->doc != NULL && returnvalue < 0)
1179 {
1180 size_t doc_len = strlen (c->doc);
1181
1182 /* Try to match against documentation. */
1183 if (regex.search (c->doc, doc_len, 0, doc_len, NULL) >= 0)
1184 print_doc_of_command (c, prefix, verbose, regex, stream);
1185 }
1186 /* Check if this command has subcommands. */
1187 if (c->subcommands != NULL)
1188 {
1189 /* Recursively call ourselves on the subcommand list,
1190 passing the right prefix in. */
1191 apropos_cmd (stream, *c->subcommands, verbose, regex,
1192 c->prefixname ().c_str ());
1193 }
1194 }
1195 }
1196
1197 /* This command really has to deal with two things:
1198 1) I want documentation on *this string* (usually called by
1199 "help commandname").
1200
1201 2) I want documentation on *this list* (usually called by giving a
1202 command that requires subcommands. Also called by saying just
1203 "help".)
1204
1205 I am going to split this into two separate commands, help_cmd and
1206 help_list. */
1207
1208 void
1209 help_cmd (const char *command, struct ui_file *stream)
1210 {
1211 struct cmd_list_element *c, *alias, *prefix_cmd, *c_cmd;
1212
1213 if (!command)
1214 {
1215 help_list (cmdlist, "", all_classes, stream);
1216 return;
1217 }
1218
1219 if (strcmp (command, "all") == 0)
1220 {
1221 help_all (stream);
1222 return;
1223 }
1224
1225 const char *orig_command = command;
1226 c = lookup_cmd (&command, cmdlist, "", NULL, 0, 0);
1227
1228 if (c == 0)
1229 return;
1230
1231 lookup_cmd_composition (orig_command, &alias, &prefix_cmd, &c_cmd);
1232
1233 /* There are three cases here.
1234 If c->subcommands is nonzero, we have a prefix command.
1235 Print its documentation, then list its subcommands.
1236
1237 If c->func is non NULL, we really have a command. Print its
1238 documentation and return.
1239
1240 If c->func is NULL, we have a class name. Print its
1241 documentation (as if it were a command) and then set class to the
1242 number of this class so that the commands in the class will be
1243 listed. */
1244
1245 /* If the user asked 'help somecommand' and there is no alias,
1246 the false indicates to not output the (single) command name. */
1247 fput_command_names_styled (c, false, "\n", stream);
1248 fput_aliases_definition_styled (c, stream);
1249 fputs_filtered (c->doc, stream);
1250 fputs_filtered ("\n", stream);
1251
1252 if (c->subcommands == 0 && c->func != NULL)
1253 return;
1254 fprintf_filtered (stream, "\n");
1255
1256 /* If this is a prefix command, print it's subcommands. */
1257 if (c->subcommands)
1258 help_list (*c->subcommands, c->prefixname ().c_str (),
1259 all_commands, stream);
1260
1261 /* If this is a class name, print all of the commands in the class. */
1262 if (c->func == NULL)
1263 help_list (cmdlist, "", c->theclass, stream);
1264
1265 if (c->hook_pre || c->hook_post)
1266 fprintf_filtered (stream,
1267 "\nThis command has a hook (or hooks) defined:\n");
1268
1269 if (c->hook_pre)
1270 fprintf_filtered (stream,
1271 "\tThis command is run after : %s (pre hook)\n",
1272 c->hook_pre->name);
1273 if (c->hook_post)
1274 fprintf_filtered (stream,
1275 "\tThis command is run before : %s (post hook)\n",
1276 c->hook_post->name);
1277 }
1278
1279 /*
1280 * Get a specific kind of help on a command list.
1281 *
1282 * LIST is the list.
1283 * CMDTYPE is the prefix to use in the title string.
1284 * CLASS is the class with which to list the nodes of this list (see
1285 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
1286 * everything, ALL_CLASSES for just classes, and non-negative for only things
1287 * in a specific class.
1288 * and STREAM is the output stream on which to print things.
1289 * If you call this routine with a class >= 0, it recurses.
1290 */
1291 void
1292 help_list (struct cmd_list_element *list, const char *cmdtype,
1293 enum command_class theclass, struct ui_file *stream)
1294 {
1295 int len;
1296 char *cmdtype1, *cmdtype2;
1297
1298 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
1299 */
1300 len = strlen (cmdtype);
1301 cmdtype1 = (char *) alloca (len + 1);
1302 cmdtype1[0] = 0;
1303 cmdtype2 = (char *) alloca (len + 4);
1304 cmdtype2[0] = 0;
1305 if (len)
1306 {
1307 cmdtype1[0] = ' ';
1308 memcpy (cmdtype1 + 1, cmdtype, len - 1);
1309 cmdtype1[len] = 0;
1310 memcpy (cmdtype2, cmdtype, len - 1);
1311 strcpy (cmdtype2 + len - 1, " sub");
1312 }
1313
1314 if (theclass == all_classes)
1315 fprintf_filtered (stream, "List of classes of %scommands:\n\n", cmdtype2);
1316 else
1317 fprintf_filtered (stream, "List of %scommands:\n\n", cmdtype2);
1318
1319 help_cmd_list (list, theclass, theclass >= 0, stream);
1320
1321 if (theclass == all_classes)
1322 {
1323 fprintf_filtered (stream, "\n\
1324 Type \"help%s\" followed by a class name for a list of commands in ",
1325 cmdtype1);
1326 wrap_here ("");
1327 fprintf_filtered (stream, "that class.");
1328
1329 fprintf_filtered (stream, "\n\
1330 Type \"help all\" for the list of all commands.");
1331 }
1332
1333 fprintf_filtered (stream, "\nType \"help%s\" followed by %scommand name ",
1334 cmdtype1, cmdtype2);
1335 wrap_here ("");
1336 fputs_filtered ("for ", stream);
1337 wrap_here ("");
1338 fputs_filtered ("full ", stream);
1339 wrap_here ("");
1340 fputs_filtered ("documentation.\n", stream);
1341 fputs_filtered ("Type \"apropos word\" to search "
1342 "for commands related to \"word\".\n", stream);
1343 fputs_filtered ("Type \"apropos -v word\" for full documentation", stream);
1344 wrap_here ("");
1345 fputs_filtered (" of commands related to \"word\".\n", stream);
1346 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
1347 stream);
1348 }
1349
1350 static void
1351 help_all (struct ui_file *stream)
1352 {
1353 struct cmd_list_element *c;
1354 int seen_unclassified = 0;
1355
1356 for (c = cmdlist; c; c = c->next)
1357 {
1358 if (c->abbrev_flag)
1359 continue;
1360 /* If this is a class name, print all of the commands in the
1361 class. */
1362
1363 if (c->func == NULL)
1364 {
1365 fprintf_filtered (stream, "\nCommand class: %s\n\n", c->name);
1366 help_cmd_list (cmdlist, c->theclass, true, stream);
1367 }
1368 }
1369
1370 /* While it's expected that all commands are in some class,
1371 as a safety measure, we'll print commands outside of any
1372 class at the end. */
1373
1374 for (c = cmdlist; c; c = c->next)
1375 {
1376 if (c->abbrev_flag)
1377 continue;
1378
1379 if (c->theclass == no_class)
1380 {
1381 if (!seen_unclassified)
1382 {
1383 fprintf_filtered (stream, "\nUnclassified commands\n\n");
1384 seen_unclassified = 1;
1385 }
1386 print_help_for_command (c, true, stream);
1387 }
1388 }
1389
1390 }
1391
1392 /* See cli-decode.h. */
1393
1394 void
1395 print_doc_line (struct ui_file *stream, const char *str,
1396 bool for_value_prefix)
1397 {
1398 static char *line_buffer = 0;
1399 static int line_size;
1400 const char *p;
1401
1402 if (!line_buffer)
1403 {
1404 line_size = 80;
1405 line_buffer = (char *) xmalloc (line_size);
1406 }
1407
1408 /* Searches for the first end of line or the end of STR. */
1409 p = str;
1410 while (*p && *p != '\n')
1411 p++;
1412 if (p - str > line_size - 1)
1413 {
1414 line_size = p - str + 1;
1415 xfree (line_buffer);
1416 line_buffer = (char *) xmalloc (line_size);
1417 }
1418 strncpy (line_buffer, str, p - str);
1419 if (for_value_prefix)
1420 {
1421 if (islower (line_buffer[0]))
1422 line_buffer[0] = toupper (line_buffer[0]);
1423 gdb_assert (p > str);
1424 if (line_buffer[p - str - 1] == '.')
1425 line_buffer[p - str - 1] = '\0';
1426 else
1427 line_buffer[p - str] = '\0';
1428 }
1429 else
1430 line_buffer[p - str] = '\0';
1431 fputs_filtered (line_buffer, stream);
1432 }
1433
1434 /* Print one-line help for command C.
1435 If RECURSE is non-zero, also print one-line descriptions
1436 of all prefixed subcommands. */
1437 static void
1438 print_help_for_command (struct cmd_list_element *c,
1439 bool recurse, struct ui_file *stream)
1440 {
1441 fput_command_names_styled (c, true, " -- ", stream);
1442 print_doc_line (stream, c->doc, false);
1443 fputs_filtered ("\n", stream);
1444 if (!c->default_args.empty ())
1445 fput_alias_definition_styled (c, stream);
1446 fput_aliases_definition_styled (c, stream);
1447
1448 if (recurse
1449 && c->subcommands != 0
1450 && c->abbrev_flag == 0)
1451 /* Subcommands of a prefix command typically have 'all_commands'
1452 as class. If we pass CLASS to recursive invocation,
1453 most often we won't see anything. */
1454 help_cmd_list (*c->subcommands, all_commands, true, stream);
1455 }
1456
1457 /*
1458 * Implement a help command on command list LIST.
1459 * RECURSE should be non-zero if this should be done recursively on
1460 * all sublists of LIST.
1461 * STREAM is the stream upon which the output should be written.
1462 * THECLASS should be:
1463 * A non-negative class number to list only commands in that
1464 * ALL_COMMANDS to list all commands in list.
1465 * ALL_CLASSES to list all classes in list.
1466 *
1467 * Note that aliases are only shown when THECLASS is class_alias.
1468 * In the other cases, the aliases will be shown together with their
1469 * aliased command.
1470 *
1471 * Note that RECURSE will be active on *all* sublists, not just the
1472 * ones selected by the criteria above (ie. the selection mechanism
1473 * is at the low level, not the high-level).
1474 */
1475
1476 static void
1477 help_cmd_list (struct cmd_list_element *list, enum command_class theclass,
1478 bool recurse, struct ui_file *stream)
1479 {
1480 struct cmd_list_element *c;
1481
1482 for (c = list; c; c = c->next)
1483 {
1484 if (c->abbrev_flag == 1 || c->cmd_deprecated)
1485 {
1486 /* Do not show abbreviations or deprecated commands. */
1487 continue;
1488 }
1489
1490 if (c->is_alias () && theclass != class_alias)
1491 {
1492 /* Do not show an alias, unless specifically showing the
1493 list of aliases: for all other classes, an alias is
1494 shown (if needed) together with its aliased command. */
1495 continue;
1496 }
1497
1498 if (theclass == all_commands
1499 || (theclass == all_classes && c->func == NULL)
1500 || (theclass == c->theclass && c->func != NULL))
1501 {
1502 /* show C when
1503 - showing all commands
1504 - showing all classes and C is a help class
1505 - showing commands of THECLASS and C is not the help class */
1506
1507 /* If we show the class_alias and C is an alias, do not recurse,
1508 as this would show the (possibly very long) not very useful
1509 list of sub-commands of the aliased command. */
1510 print_help_for_command
1511 (c,
1512 recurse && (theclass != class_alias || !c->is_alias ()),
1513 stream);
1514 continue;
1515 }
1516
1517 if (recurse
1518 && (theclass == class_user || theclass == class_alias)
1519 && c->subcommands != NULL)
1520 {
1521 /* User-defined commands or aliases may be subcommands. */
1522 help_cmd_list (*c->subcommands, theclass, recurse, stream);
1523 continue;
1524 }
1525
1526 /* Do not show C or recurse on C, e.g. because C does not belong to
1527 THECLASS or because C is a help class. */
1528 }
1529 }
1530 \f
1531
1532 /* Search the input clist for 'command'. Return the command if
1533 found (or NULL if not), and return the number of commands
1534 found in nfound. */
1535
1536 static struct cmd_list_element *
1537 find_cmd (const char *command, int len, struct cmd_list_element *clist,
1538 int ignore_help_classes, int *nfound)
1539 {
1540 struct cmd_list_element *found, *c;
1541
1542 found = NULL;
1543 *nfound = 0;
1544 for (c = clist; c; c = c->next)
1545 if (!strncmp (command, c->name, len)
1546 && (!ignore_help_classes || c->func))
1547 {
1548 found = c;
1549 (*nfound)++;
1550 if (c->name[len] == '\0')
1551 {
1552 *nfound = 1;
1553 break;
1554 }
1555 }
1556 return found;
1557 }
1558
1559 /* Return the length of command name in TEXT. */
1560
1561 int
1562 find_command_name_length (const char *text)
1563 {
1564 const char *p = text;
1565
1566 /* Treating underscores as part of command words is important
1567 so that "set args_foo()" doesn't get interpreted as
1568 "set args _foo()". */
1569 /* Some characters are only used for TUI specific commands.
1570 However, they are always allowed for the sake of consistency.
1571
1572 Note that this is larger than the character set allowed when
1573 creating user-defined commands. */
1574
1575 /* Recognize the single character commands so that, e.g., "!ls"
1576 works as expected. */
1577 if (*p == '!' || *p == '|')
1578 return 1;
1579
1580 while (valid_cmd_char_p (*p)
1581 /* Characters used by TUI specific commands. */
1582 || *p == '+' || *p == '<' || *p == '>' || *p == '$')
1583 p++;
1584
1585 return p - text;
1586 }
1587
1588 /* See command.h. */
1589
1590 bool
1591 valid_cmd_char_p (int c)
1592 {
1593 /* Alas "42" is a legitimate user-defined command.
1594 In the interests of not breaking anything we preserve that. */
1595
1596 return isalnum (c) || c == '-' || c == '_' || c == '.';
1597 }
1598
1599 /* See command.h. */
1600
1601 bool
1602 valid_user_defined_cmd_name_p (const char *name)
1603 {
1604 const char *p;
1605
1606 if (*name == '\0')
1607 return false;
1608
1609 for (p = name; *p != '\0'; ++p)
1610 {
1611 if (valid_cmd_char_p (*p))
1612 ; /* Ok. */
1613 else
1614 return false;
1615 }
1616
1617 return true;
1618 }
1619
1620 /* See command.h. */
1621
1622 struct cmd_list_element *
1623 lookup_cmd_1 (const char **text, struct cmd_list_element *clist,
1624 struct cmd_list_element **result_list, std::string *default_args,
1625 int ignore_help_classes, bool lookup_for_completion_p)
1626 {
1627 char *command;
1628 int len, nfound;
1629 struct cmd_list_element *found, *c;
1630 bool found_alias = false;
1631 const char *line = *text;
1632
1633 while (**text == ' ' || **text == '\t')
1634 (*text)++;
1635
1636 /* Identify the name of the command. */
1637 len = find_command_name_length (*text);
1638
1639 /* If nothing but whitespace, return 0. */
1640 if (len == 0)
1641 return 0;
1642
1643 /* *text and p now bracket the first command word to lookup (and
1644 it's length is len). We copy this into a local temporary. */
1645
1646
1647 command = (char *) alloca (len + 1);
1648 memcpy (command, *text, len);
1649 command[len] = '\0';
1650
1651 /* Look it up. */
1652 found = 0;
1653 nfound = 0;
1654 found = find_cmd (command, len, clist, ignore_help_classes, &nfound);
1655
1656 /* If nothing matches, we have a simple failure. */
1657 if (nfound == 0)
1658 return 0;
1659
1660 if (nfound > 1)
1661 {
1662 if (result_list != nullptr)
1663 /* Will be modified in calling routine
1664 if we know what the prefix command is. */
1665 *result_list = 0;
1666 if (default_args != nullptr)
1667 *default_args = std::string ();
1668 return CMD_LIST_AMBIGUOUS; /* Ambiguous. */
1669 }
1670
1671 /* We've matched something on this list. Move text pointer forward. */
1672
1673 *text += len;
1674
1675 if (found->is_alias ())
1676 {
1677 /* We drop the alias (abbreviation) in favor of the command it
1678 is pointing to. If the alias is deprecated, though, we need to
1679 warn the user about it before we drop it. Note that while we
1680 are warning about the alias, we may also warn about the command
1681 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1682 flags. */
1683
1684 if (found->deprecated_warn_user && !lookup_for_completion_p)
1685 deprecated_cmd_warning (line, clist);
1686
1687
1688 /* Return the default_args of the alias, not the default_args
1689 of the command it is pointing to. */
1690 if (default_args != nullptr)
1691 *default_args = found->default_args;
1692 found = found->alias_target;
1693 found_alias = true;
1694 }
1695 /* If we found a prefix command, keep looking. */
1696
1697 if (found->subcommands)
1698 {
1699 c = lookup_cmd_1 (text, *found->subcommands, result_list, default_args,
1700 ignore_help_classes, lookup_for_completion_p);
1701 if (!c)
1702 {
1703 /* Didn't find anything; this is as far as we got. */
1704 if (result_list != nullptr)
1705 *result_list = clist;
1706 if (!found_alias && default_args != nullptr)
1707 *default_args = found->default_args;
1708 return found;
1709 }
1710 else if (c == CMD_LIST_AMBIGUOUS)
1711 {
1712 /* We've gotten this far properly, but the next step is
1713 ambiguous. We need to set the result list to the best
1714 we've found (if an inferior hasn't already set it). */
1715 if (result_list != nullptr)
1716 if (!*result_list)
1717 /* This used to say *result_list = *found->subcommands.
1718 If that was correct, need to modify the documentation
1719 at the top of this function to clarify what is
1720 supposed to be going on. */
1721 *result_list = found;
1722 /* For ambiguous commands, do not return any default_args args. */
1723 if (default_args != nullptr)
1724 *default_args = std::string ();
1725 return c;
1726 }
1727 else
1728 {
1729 /* We matched! */
1730 return c;
1731 }
1732 }
1733 else
1734 {
1735 if (result_list != nullptr)
1736 *result_list = clist;
1737 if (!found_alias && default_args != nullptr)
1738 *default_args = found->default_args;
1739 return found;
1740 }
1741 }
1742
1743 /* All this hair to move the space to the front of cmdtype */
1744
1745 static void
1746 undef_cmd_error (const char *cmdtype, const char *q)
1747 {
1748 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1749 cmdtype,
1750 q,
1751 *cmdtype ? " " : "",
1752 (int) strlen (cmdtype) - 1,
1753 cmdtype);
1754 }
1755
1756 /* Look up the contents of *LINE as a command in the command list LIST.
1757 LIST is a chain of struct cmd_list_element's.
1758 If it is found, return the struct cmd_list_element for that command,
1759 update *LINE to point after the command name, at the first argument
1760 and update *DEFAULT_ARGS (if DEFAULT_ARGS is not null) to the default
1761 args to prepend to the user provided args when running the command.
1762 Note that if the found cmd_list_element is found via an alias,
1763 the default args of the alias are returned.
1764
1765 If not found, call error if ALLOW_UNKNOWN is zero
1766 otherwise (or if error returns) return zero.
1767 Call error if specified command is ambiguous,
1768 unless ALLOW_UNKNOWN is negative.
1769 CMDTYPE precedes the word "command" in the error message.
1770
1771 If IGNORE_HELP_CLASSES is nonzero, ignore any command list
1772 elements which are actually help classes rather than commands (i.e.
1773 the function field of the struct cmd_list_element is 0). */
1774
1775 struct cmd_list_element *
1776 lookup_cmd (const char **line, struct cmd_list_element *list,
1777 const char *cmdtype,
1778 std::string *default_args,
1779 int allow_unknown, int ignore_help_classes)
1780 {
1781 struct cmd_list_element *last_list = 0;
1782 struct cmd_list_element *c;
1783
1784 /* Note: Do not remove trailing whitespace here because this
1785 would be wrong for complete_command. Jim Kingdon */
1786
1787 if (!*line)
1788 error (_("Lack of needed %scommand"), cmdtype);
1789
1790 c = lookup_cmd_1 (line, list, &last_list, default_args, ignore_help_classes);
1791
1792 if (!c)
1793 {
1794 if (!allow_unknown)
1795 {
1796 char *q;
1797 int len = find_command_name_length (*line);
1798
1799 q = (char *) alloca (len + 1);
1800 strncpy (q, *line, len);
1801 q[len] = '\0';
1802 undef_cmd_error (cmdtype, q);
1803 }
1804 else
1805 return 0;
1806 }
1807 else if (c == CMD_LIST_AMBIGUOUS)
1808 {
1809 /* Ambigous. Local values should be off subcommands or called
1810 values. */
1811 int local_allow_unknown = (last_list ? last_list->allow_unknown :
1812 allow_unknown);
1813 std::string local_cmdtype
1814 = last_list ? last_list->prefixname () : cmdtype;
1815 struct cmd_list_element *local_list =
1816 (last_list ? *(last_list->subcommands) : list);
1817
1818 if (local_allow_unknown < 0)
1819 {
1820 if (last_list)
1821 return last_list; /* Found something. */
1822 else
1823 return 0; /* Found nothing. */
1824 }
1825 else
1826 {
1827 /* Report as error. */
1828 int amb_len;
1829 char ambbuf[100];
1830
1831 for (amb_len = 0;
1832 ((*line)[amb_len] && (*line)[amb_len] != ' '
1833 && (*line)[amb_len] != '\t');
1834 amb_len++)
1835 ;
1836
1837 ambbuf[0] = 0;
1838 for (c = local_list; c; c = c->next)
1839 if (!strncmp (*line, c->name, amb_len))
1840 {
1841 if (strlen (ambbuf) + strlen (c->name) + 6
1842 < (int) sizeof ambbuf)
1843 {
1844 if (strlen (ambbuf))
1845 strcat (ambbuf, ", ");
1846 strcat (ambbuf, c->name);
1847 }
1848 else
1849 {
1850 strcat (ambbuf, "..");
1851 break;
1852 }
1853 }
1854 error (_("Ambiguous %scommand \"%s\": %s."),
1855 local_cmdtype.c_str (), *line, ambbuf);
1856 }
1857 }
1858 else
1859 {
1860 if (c->type == set_cmd && **line != '\0' && !isspace (**line))
1861 error (_("Argument must be preceded by space."));
1862
1863 /* We've got something. It may still not be what the caller
1864 wants (if this command *needs* a subcommand). */
1865 while (**line == ' ' || **line == '\t')
1866 (*line)++;
1867
1868 if (c->subcommands && **line && !c->allow_unknown)
1869 undef_cmd_error (c->prefixname ().c_str (), *line);
1870
1871 /* Seems to be what he wants. Return it. */
1872 return c;
1873 }
1874 return 0;
1875 }
1876
1877 /* See command.h. */
1878
1879 struct cmd_list_element *
1880 lookup_cmd_exact (const char *name,
1881 struct cmd_list_element *list,
1882 bool ignore_help_classes)
1883 {
1884 const char *tem = name;
1885 struct cmd_list_element *cmd = lookup_cmd (&tem, list, "", NULL, -1,
1886 ignore_help_classes);
1887 if (cmd != nullptr && strcmp (name, cmd->name) != 0)
1888 cmd = nullptr;
1889 return cmd;
1890 }
1891
1892 /* We are here presumably because an alias or command in TEXT is
1893 deprecated and a warning message should be generated. This
1894 function decodes TEXT and potentially generates a warning message
1895 as outlined below.
1896
1897 Example for 'set endian big' which has a fictitious alias 'seb'.
1898
1899 If alias wasn't used in TEXT, and the command is deprecated:
1900 "warning: 'set endian big' is deprecated."
1901
1902 If alias was used, and only the alias is deprecated:
1903 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1904
1905 If alias was used and command is deprecated (regardless of whether
1906 the alias itself is deprecated:
1907
1908 "warning: 'set endian big' (seb) is deprecated."
1909
1910 After the message has been sent, clear the appropriate flags in the
1911 command and/or the alias so the user is no longer bothered.
1912
1913 */
1914 void
1915 deprecated_cmd_warning (const char *text, struct cmd_list_element *list)
1916 {
1917 struct cmd_list_element *alias = nullptr;
1918 struct cmd_list_element *cmd = nullptr;
1919
1920 /* Return if text doesn't evaluate to a command. We place this lookup
1921 within its own scope so that the PREFIX_CMD local is not visible
1922 later in this function. The value returned in PREFIX_CMD is based on
1923 the prefix found in TEXT, and is our case this prefix can be missing
1924 in some situations (when LIST is not the global CMDLIST).
1925
1926 It is better for our purposes to use the prefix commands directly from
1927 the ALIAS and CMD results. */
1928 {
1929 struct cmd_list_element *prefix_cmd = nullptr;
1930 if (!lookup_cmd_composition_1 (text, &alias, &prefix_cmd, &cmd, list))
1931 return;
1932 }
1933
1934 /* Return if nothing is deprecated. */
1935 if (!((alias != nullptr ? alias->deprecated_warn_user : 0)
1936 || cmd->deprecated_warn_user))
1937 return;
1938
1939 /* Join command prefix (if any) and the command name. */
1940 std::string tmp_cmd_str;
1941 if (cmd->prefix != nullptr)
1942 tmp_cmd_str += cmd->prefix->prefixname ();
1943 tmp_cmd_str += std::string (cmd->name);
1944
1945 /* Display the appropriate first line, this warns that the thing the user
1946 entered is deprecated. */
1947 if (alias != nullptr)
1948 {
1949 /* Join the alias prefix (if any) and the alias name. */
1950 std::string tmp_alias_str;
1951 if (alias->prefix != nullptr)
1952 tmp_alias_str += alias->prefix->prefixname ();
1953 tmp_alias_str += std::string (alias->name);
1954
1955 if (cmd->cmd_deprecated)
1956 printf_filtered (_("Warning: command '%ps' (%ps) is deprecated.\n"),
1957 styled_string (title_style.style (),
1958 tmp_cmd_str.c_str ()),
1959 styled_string (title_style.style (),
1960 tmp_alias_str.c_str ()));
1961 else
1962 printf_filtered (_("Warning: '%ps', an alias for the command '%ps', "
1963 "is deprecated.\n"),
1964 styled_string (title_style.style (),
1965 tmp_alias_str.c_str ()),
1966 styled_string (title_style.style (),
1967 tmp_cmd_str.c_str ()));
1968 }
1969 else
1970 printf_filtered (_("Warning: command '%ps' is deprecated.\n"),
1971 styled_string (title_style.style (),
1972 tmp_cmd_str.c_str ()));
1973
1974 /* Now display a second line indicating what the user should use instead.
1975 If it is only the alias that is deprecated, we want to indicate the
1976 new alias, otherwise we'll indicate the new command. */
1977 const char *replacement;
1978 if (alias != nullptr && !cmd->cmd_deprecated)
1979 replacement = alias->replacement;
1980 else
1981 replacement = cmd->replacement;
1982 if (replacement != nullptr)
1983 printf_filtered (_("Use '%ps'.\n\n"),
1984 styled_string (title_style.style (),
1985 replacement));
1986 else
1987 printf_filtered (_("No alternative known.\n\n"));
1988
1989 /* We've warned you, now we'll keep quiet. */
1990 if (alias != nullptr)
1991 alias->deprecated_warn_user = 0;
1992 cmd->deprecated_warn_user = 0;
1993 }
1994
1995 /* Look up the contents of TEXT as a command in the command list CUR_LIST.
1996 Return 1 on success, 0 on failure.
1997
1998 If TEXT refers to an alias, *ALIAS will point to that alias.
1999
2000 If TEXT is a subcommand (i.e. one that is preceded by a prefix
2001 command) set *PREFIX_CMD.
2002
2003 Set *CMD to point to the command TEXT indicates.
2004
2005 If any of *ALIAS, *PREFIX_CMD, or *CMD cannot be determined or do not
2006 exist, they are NULL when we return.
2007
2008 */
2009
2010 static int
2011 lookup_cmd_composition_1 (const char *text,
2012 struct cmd_list_element **alias,
2013 struct cmd_list_element **prefix_cmd,
2014 struct cmd_list_element **cmd,
2015 struct cmd_list_element *cur_list)
2016 {
2017 *alias = nullptr;
2018 *prefix_cmd = cur_list->prefix;
2019 *cmd = nullptr;
2020
2021 text = skip_spaces (text);
2022
2023 /* Go through as many command lists as we need to, to find the command
2024 TEXT refers to. */
2025 while (1)
2026 {
2027 /* Identify the name of the command. */
2028 int len = find_command_name_length (text);
2029
2030 /* If nothing but whitespace, return. */
2031 if (len == 0)
2032 return 0;
2033
2034 /* TEXT is the start of the first command word to lookup (and
2035 it's length is LEN). We copy this into a local temporary. */
2036 std::string command (text, len);
2037
2038 /* Look it up. */
2039 int nfound = 0;
2040 *cmd = find_cmd (command.c_str (), len, cur_list, 1, &nfound);
2041
2042 /* We only handle the case where a single command was found. */
2043 if (*cmd == CMD_LIST_AMBIGUOUS || *cmd == nullptr)
2044 return 0;
2045 else
2046 {
2047 if ((*cmd)->is_alias ())
2048 {
2049 /* If the command was actually an alias, we note that an
2050 alias was used (by assigning *ALIAS) and we set *CMD. */
2051 *alias = *cmd;
2052 *cmd = (*cmd)->alias_target;
2053 }
2054 }
2055
2056 text += len;
2057 text = skip_spaces (text);
2058
2059 if ((*cmd)->subcommands != nullptr && *text != '\0')
2060 {
2061 cur_list = *(*cmd)->subcommands;
2062 *prefix_cmd = *cmd;
2063 }
2064 else
2065 return 1;
2066 }
2067 }
2068
2069 /* Look up the contents of TEXT as a command in the command list 'cmdlist'.
2070 Return 1 on success, 0 on failure.
2071
2072 If TEXT refers to an alias, *ALIAS will point to that alias.
2073
2074 If TEXT is a subcommand (i.e. one that is preceded by a prefix
2075 command) set *PREFIX_CMD.
2076
2077 Set *CMD to point to the command TEXT indicates.
2078
2079 If any of *ALIAS, *PREFIX_CMD, or *CMD cannot be determined or do not
2080 exist, they are NULL when we return.
2081
2082 */
2083
2084 int
2085 lookup_cmd_composition (const char *text,
2086 struct cmd_list_element **alias,
2087 struct cmd_list_element **prefix_cmd,
2088 struct cmd_list_element **cmd)
2089 {
2090 return lookup_cmd_composition_1 (text, alias, prefix_cmd, cmd, cmdlist);
2091 }
2092
2093 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
2094
2095 /* Return a vector of char pointers which point to the different
2096 possible completions in LIST of TEXT.
2097
2098 WORD points in the same buffer as TEXT, and completions should be
2099 returned relative to this position. For example, suppose TEXT is
2100 "foo" and we want to complete to "foobar". If WORD is "oo", return
2101 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
2102
2103 void
2104 complete_on_cmdlist (struct cmd_list_element *list,
2105 completion_tracker &tracker,
2106 const char *text, const char *word,
2107 int ignore_help_classes)
2108 {
2109 struct cmd_list_element *ptr;
2110 int textlen = strlen (text);
2111 int pass;
2112 int saw_deprecated_match = 0;
2113
2114 /* We do one or two passes. In the first pass, we skip deprecated
2115 commands. If we see no matching commands in the first pass, and
2116 if we did happen to see a matching deprecated command, we do
2117 another loop to collect those. */
2118 for (pass = 0; pass < 2; ++pass)
2119 {
2120 bool got_matches = false;
2121
2122 for (ptr = list; ptr; ptr = ptr->next)
2123 if (!strncmp (ptr->name, text, textlen)
2124 && !ptr->abbrev_flag
2125 && (!ignore_help_classes || ptr->func
2126 || ptr->subcommands))
2127 {
2128 if (pass == 0)
2129 {
2130 if (ptr->cmd_deprecated)
2131 {
2132 saw_deprecated_match = 1;
2133 continue;
2134 }
2135 }
2136
2137 tracker.add_completion
2138 (make_completion_match_str (ptr->name, text, word));
2139 got_matches = true;
2140 }
2141
2142 if (got_matches)
2143 break;
2144
2145 /* If we saw no matching deprecated commands in the first pass,
2146 just bail out. */
2147 if (!saw_deprecated_match)
2148 break;
2149 }
2150 }
2151
2152 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
2153
2154 /* Add the different possible completions in ENUMLIST of TEXT.
2155
2156 WORD points in the same buffer as TEXT, and completions should be
2157 returned relative to this position. For example, suppose TEXT is "foo"
2158 and we want to complete to "foobar". If WORD is "oo", return
2159 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
2160
2161 void
2162 complete_on_enum (completion_tracker &tracker,
2163 const char *const *enumlist,
2164 const char *text, const char *word)
2165 {
2166 int textlen = strlen (text);
2167 int i;
2168 const char *name;
2169
2170 for (i = 0; (name = enumlist[i]) != NULL; i++)
2171 if (strncmp (name, text, textlen) == 0)
2172 tracker.add_completion (make_completion_match_str (name, text, word));
2173 }
2174
2175
2176 /* Check function pointer. */
2177 int
2178 cmd_func_p (struct cmd_list_element *cmd)
2179 {
2180 return (cmd->func != NULL);
2181 }
2182
2183
2184 /* Call the command function. */
2185 void
2186 cmd_func (struct cmd_list_element *cmd, const char *args, int from_tty)
2187 {
2188 if (cmd_func_p (cmd))
2189 {
2190 gdb::optional<scoped_restore_tmpl<int>> restore_suppress;
2191
2192 if (cmd->suppress_notification != NULL)
2193 restore_suppress.emplace (cmd->suppress_notification, 1);
2194
2195 (*cmd->func) (cmd, args, from_tty);
2196 }
2197 else
2198 error (_("Invalid command"));
2199 }
2200
2201 int
2202 cli_user_command_p (struct cmd_list_element *cmd)
2203 {
2204 return (cmd->theclass == class_user
2205 && (cmd->func == do_const_cfunc || cmd->func == do_sfunc));
2206 }