1 /* Header file for command creation.
2 
3    Copyright (C) 1986-2024 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 #if !defined (COMMAND_H)
19 #define COMMAND_H 1
20 
21 #include "gdbsupport/gdb_vecs.h"
22 #include "gdbsupport/scoped_restore.h"
23 
24 struct completion_tracker;
25 
26 /* This file defines the public interface for any code wanting to
27    create commands.  */
28 
29 /* Command classes are top-level categories into which commands are
30    broken down for "help" purposes.
31 
32    The class_alias is used for the user-defined aliases, defined
33    using the "alias" command.
34 
35    Aliases pre-defined by GDB (e.g. the alias "bt" of the "backtrace" command)
36    are not using the class_alias.
37    Different pre-defined aliases of the same command do not necessarily
38    have the same classes.  For example, class_stack is used for the
39    "backtrace" and its "bt" alias", while "info stack" (also an alias
40    of "backtrace" uses class_info.  */
41 
42 enum command_class
43 {
44   /* Classes of commands followed by a comment giving the name
45      to use in "help <classname>".
46      Note that help accepts unambiguous abbreviated class names.  */
47 
48   /* Special classes to help_list */
49   all_classes = -2,  /* help without <classname> */
50   all_commands = -1, /* all */
51 
52   /* Classes of commands */
53   no_class = -1,
54   class_run = 0,     /* running */
55   class_vars,        /* data */
56   class_stack,       /* stack */
57   class_files,       /* files */
58   class_support,     /* support */
59   class_info,        /* status */
60   class_breakpoint,  /* breakpoints */
61   class_trace,       /* tracepoints */
62   class_alias,       /* aliases */
63   class_bookmark,
64   class_obscure,     /* obscure */
65   class_maintenance, /* internals */
66   class_tui,         /* text-user-interface */
67   class_user,        /* user-defined */
68 
69   /* Used for "show" commands that have no corresponding "set" command.  */
70   no_set_class
71 };
72 
73 /* Types of "set" or "show" command.  */
74 enum var_types
75   {
76     /* "on" or "off".  *VAR is a bool which is true for on,
77        false for off.  */
78     var_boolean,
79 
80     /* "on" / "true" / "enable" or "off" / "false" / "disable" or
81        "auto.  *VAR is an ``enum auto_boolean''.  NOTE: In general a
82        custom show command will need to be implemented - one that for
83        "auto" prints both the "auto" and the current auto-selected
84        value.  */
85     var_auto_boolean,
86 
87     /* Unsigned Integer.  *VAR is an unsigned int.  In the Guile and Python
88        APIs 0 means unlimited, which is stored in *VAR as UINT_MAX.  */
89     var_uinteger,
90 
91     /* Like var_uinteger but signed.  *VAR is an int.  In the Guile and
92        Python APIs 0 means unlimited, which is stored in *VAR as INT_MAX.  */
93     var_integer,
94 
95     /* Like var_integer but negative numbers are not allowed,
96        except for special values.  *VAR is an int.  */
97     var_pinteger,
98 
99     /* String which the user enters with escapes (e.g. the user types
100        \n and it is a real newline in the stored string).
101        *VAR is a std::string, "" if the string is empty.  */
102     var_string,
103     /* String which stores what the user types verbatim.
104        *VAR is std::string, "" if the string is empty.  */
105     var_string_noescape,
106     /* String which stores a filename.  (*VAR) is a std::string,
107        "" if the string was empty.  */
108     var_optional_filename,
109     /* String which stores a filename.  (*VAR) is a std::string.  */
110     var_filename,
111     /* Enumerated type.  Can only have one of the specified values.
112        *VAR is a char pointer to the name of the element that we
113        find.  */
114     var_enum
115   };
116 
117 /* A structure describing an extra literal accepted and shown in place
118    of a number.  */
119 struct literal_def
120 {
121   /* The literal to define, e.g. "unlimited".  */
122   const char *literal;
123 
124   /* The number to substitute internally for LITERAL or VAL;
125      the use of this number is not allowed (unless the same as VAL).  */
126   LONGEST use;
127 
128   /* An optional number accepted that stands for the literal.  */
129   std::optional<LONGEST> val;
130 };
131 
132 /* Return true if a setting of type VAR_TYPE is backed with type T.
133 
134    This function is left without definition intentionally.  This template is
135    specialized for all valid types that are used to back var_types.  Therefore
136    if one tries to instantiate this un-specialized template it means the T
137    parameter is not a type used to back a var_type and it is most likely a
138    programming error.  */
139 template<typename T>
140 bool var_type_uses (var_types var_type) = delete;
141 
142 /* Return true if a setting of type T is backed by a bool variable.  */
143 template<>
144 inline bool var_type_uses<bool> (var_types t)
145 {
146   return t == var_boolean;
147 };
148 
149 /* Return true if a setting of type T is backed by a auto_boolean variable.
150 */
151 template<>
152 inline bool var_type_uses<enum auto_boolean> (var_types t)
153 {
154   return t == var_auto_boolean;
155 }
156 
157 /* Return true if a setting of type T is backed by an unsigned int variable.
158 */
159 template<>
160 inline bool var_type_uses<unsigned int> (var_types t)
161 {
162   return t == var_uinteger;
163 }
164 
165 /* Return true if a setting of type T is backed by an int variable.  */
166 template<>
167 inline bool var_type_uses<int> (var_types t)
168 {
169   return t == var_integer || t == var_pinteger;
170 }
171 
172 /* Return true if a setting of type T is backed by a std::string variable.  */
173 template<>
174 inline bool var_type_uses<std::string> (var_types t)
175 {
176   return (t == var_string || t == var_string_noescape
177             || t == var_optional_filename || t == var_filename);
178 }
179 
180 /* Return true if a setting of type T is backed by a const char * variable.
181 */
182 template<>
183 inline bool var_type_uses<const char *> (var_types t)
184 {
185   return t == var_enum;
186 }
187 
188 template<bool is_scalar, typename T> struct setting_func_types_1;
189 
190 template<typename T>
191 struct setting_func_types_1<true, T>
192 {
193   using type = T;
194   using set = void (*) (type);
195   using get = type (*) ();
196 };
197 
198 template<typename T>
199 struct setting_func_types_1<false, T>
200 {
201   using type = const T &;
202   using set = void (*) (type);
203   using get = type (*) ();
204 };
205 
206 template<typename T>
207 struct setting_func_types
208 {
209   using type = typename setting_func_types_1<std::is_scalar<T>::value, T>::type;
210   using set = typename setting_func_types_1<std::is_scalar<T>::value, T>::set;
211   using get = typename setting_func_types_1<std::is_scalar<T>::value, T>::get;
212 };
213 
214 /* Generic/type-erased function pointer.  */
215 
216 using erased_func = void (*) ();
217 
218 /* Interface for getting and setting a setting's value.
219 
220    The underlying data can be of any VAR_TYPES type.  */
221 struct setting
222 {
223   /* Create a setting backed by a variable of type T.
224 
225      Type T must match the var type VAR_TYPE (see VAR_TYPE_USES).  */
226   template<typename T>
227   setting (var_types var_type, T *var,
228              const literal_def *extra_literals = nullptr)
229     : m_var_type (var_type), m_var (var), m_extra_literals (extra_literals)
230   {
231     gdb_assert (var != nullptr);
232     gdb_assert (var_type_uses<T> (var_type));
233   }
234 
235   /* A setting can also be constructed with a pre-validated
236      type-erased variable.  Use the following function to
237      validate & type-erase said variable/function pointers.  */
238 
239   struct erased_args
240   {
241     void *var;
242     erased_func setter;
243     erased_func getter;
244   };
245 
246   template<typename T>
247   static erased_args erase_args (var_types var_type,
248                                          T *var,
249                                          typename setting_func_types<T>::set set_setting_func,
250                                          typename setting_func_types<T>::get get_setting_func)
251   {
252     gdb_assert (var_type_uses<T> (var_type));
253   /* The getter and the setter must be both provided or both omitted.  */
254     gdb_assert
255       ((set_setting_func == nullptr) == (get_setting_func == nullptr));
256 
257   /* The caller must provide a pointer to a variable or get/set functions, but
258      not both.  */
259     gdb_assert ((set_setting_func == nullptr) != (var == nullptr));
260 
261     return {
262           var,
263           reinterpret_cast<erased_func> (set_setting_func),
264           reinterpret_cast<erased_func> (get_setting_func)
265     };
266   }
267 
268   /* Create a setting backed by pre-validated type-erased args and using
269      EXTRA_LITERALS.  ERASED_VAR's fields' real types must match the var
270      type VAR_TYPE (see VAR_TYPE_USES).  */
271   setting (var_types var_type, const literal_def *extra_literals,
272              const erased_args &args)
273     : m_var_type (var_type),
274       m_var (args.var),
275       m_extra_literals (extra_literals),
276       m_getter (args.getter),
277       m_setter (args.setter)
278   {
279   }
280 
281   /* Create a setting backed by setter and getter functions.
282 
283      Type T must match the var type VAR_TYPE (see VAR_TYPE_USES).  */
284   template<typename T>
285   setting (var_types var_type,
286              typename setting_func_types<T>::set setter,
287              typename setting_func_types<T>::get getter)
288     : m_var_type (var_type)
289   {
290     gdb_assert (var_type_uses<T> (var_type));
291 
292     /* Getters and setters are cast to and from the arbitrary `void (*) ()`
293        function pointer type.  Make sure that the two types are really of the
294        same size.  */
295     static_assert (sizeof (m_getter) == sizeof (getter));
296     static_assert (sizeof (m_setter) == sizeof (setter));
297 
298     m_getter = reinterpret_cast<erased_func> (getter);
299     m_setter = reinterpret_cast<erased_func> (setter);
300   }
301 
302   /* Access the type of the current setting.  */
303   var_types type () const
304   { return m_var_type; }
305 
306   /* Access any extra literals accepted.  */
307   const literal_def *extra_literals () const
308   { return m_extra_literals; }
309 
310   /* Return the current value.
311 
312      The template parameter T is the type of the variable used to store the
313      setting.  */
314   template<typename T>
315   typename setting_func_types<T>::type get () const
316   {
317     gdb_assert (var_type_uses<T> (m_var_type));
318 
319     if (m_var == nullptr)
320       {
321           gdb_assert (m_getter != nullptr);
322           auto getter = reinterpret_cast<typename setting_func_types<T>::get> (m_getter);
323           return getter ();
324       }
325     else
326       return *static_cast<const T *> (m_var);
327   }
328 
329   /* Sets the value of the setting to V.  Returns true if the setting was
330      effectively changed, false if the update failed and the setting is left
331      unchanged.
332 
333      If we have a user-provided setter, use it to set the setting.  Otherwise
334      copy the value V to the internally referenced buffer.
335 
336      The template parameter T indicates the type of the variable used to store
337      the setting.
338 
339      The var_type of the setting must match T.  */
340   template<typename T>
341   bool set (const T &v)
342   {
343     /* Check that the current instance is of one of the supported types for
344        this instantiation.  */
345     gdb_assert (var_type_uses<T> (m_var_type));
346 
347     const T old_value = this->get<T> ();
348 
349     if (m_var == nullptr)
350       {
351           gdb_assert (m_setter != nullptr);
352           auto setter = reinterpret_cast<typename setting_func_types<T>::set> (m_setter);
353           setter (v);
354       }
355     else
356       *static_cast<T *> (m_var) = v;
357 
358     return old_value != this->get<T> ();
359   }
360 
361 private:
362   /* The type of the variable M_VAR is pointing to, or that M_GETTER / M_SETTER
363      get or set.  */
364   var_types m_var_type;
365 
366   /* Pointer to the enclosed variable
367 
368      Either M_VAR is non-nullptr, or both M_GETTER and M_SETTER are
369      non-nullptr.  */
370   void *m_var = nullptr;
371 
372   /* Any extra literals accepted.  */
373   const literal_def *m_extra_literals = nullptr;
374 
375   /* Pointer to a user provided getter.  */
376   erased_func m_getter = nullptr;
377 
378   /* Pointer to a user provided setter.  */
379   erased_func m_setter = nullptr;
380 };
381 
382 /* This structure records one command'd definition.  */
383 struct cmd_list_element;
384 
385 /* The "simple" signature of command callbacks, which doesn't include a
386    cmd_list_element parameter.  */
387 
388 typedef void cmd_simple_func_ftype (const char *args, int from_tty);
389 
390 /* This structure specifies notifications to be suppressed by a cli
391    command interpreter.  */
392 
393 struct cli_suppress_notification
394 {
395   /* Inferior, thread, frame selected notification suppressed?  */
396   bool user_selected_context = false;
397 
398   /* Normal stop event suppressed? */
399   bool normal_stop = false;
400 };
401 
402 extern struct cli_suppress_notification cli_suppress_notification;
403 
404 /* Forward-declarations of the entry-points of cli/cli-decode.c.  */
405 
406 /* API to the manipulation of command lists.  */
407 
408 /* Return TRUE if NAME is a valid user-defined command name.
409    This is a stricter subset of all gdb commands,
410    see find_command_name_length.  */
411 
412 extern bool valid_user_defined_cmd_name_p (const char *name);
413 
414 /* Return TRUE if C is a valid command character.  */
415 
416 extern bool valid_cmd_char_p (int c);
417 
418 /* Return value type for the add_setshow_* functions.  */
419 
420 struct set_show_commands
421 {
422   cmd_list_element *set, *show;
423 };
424 
425 /* Const-correct variant of the above.  */
426 
427 extern struct cmd_list_element *add_cmd (const char *, enum command_class,
428                                                    cmd_simple_func_ftype *fun,
429                                                    const char *,
430                                                    struct cmd_list_element **);
431 
432 /* Like add_cmd, but no command function is specified.  */
433 
434 extern struct cmd_list_element *add_cmd (const char *, enum command_class,
435                                                    const char *,
436                                                    struct cmd_list_element **);
437 
438 extern struct cmd_list_element *add_cmd_suppress_notification
439                               (const char *name, enum command_class theclass,
440                                cmd_simple_func_ftype *fun, const char *doc,
441                                struct cmd_list_element **list,
442                                bool *suppress_notification);
443 
444 extern struct cmd_list_element *add_alias_cmd (const char *,
445                                                          cmd_list_element *,
446                                                          enum command_class, int,
447                                                          struct cmd_list_element **);
448 
449 
450 extern struct cmd_list_element *add_prefix_cmd (const char *, enum command_class,
451                                                             cmd_simple_func_ftype *fun,
452                                                             const char *,
453                                                             struct cmd_list_element **,
454                                                             int,
455                                                             struct cmd_list_element **);
456 
457 /* Like add_prefix_cmd, but sets the callback to a function that
458    simply calls help_list.  */
459 
460 extern struct cmd_list_element *add_basic_prefix_cmd
461   (const char *, enum command_class, const char *, struct cmd_list_element **,
462    int, struct cmd_list_element **);
463 
464 /* Like add_prefix_cmd, but useful for "show" prefixes.  This sets the
465    callback to a function that simply calls cmd_show_list.  */
466 
467 extern struct cmd_list_element *add_show_prefix_cmd
468   (const char *, enum command_class, const char *, struct cmd_list_element **,
469    int, struct cmd_list_element **);
470 
471 /* Add matching set and show commands using add_basic_prefix_cmd and
472    add_show_prefix_cmd.  */
473 
474 extern set_show_commands add_setshow_prefix_cmd
475   (const char *name, command_class theclass, const char *set_doc,
476    const char *show_doc,
477    cmd_list_element **set_subcommands_list,
478    cmd_list_element **show_subcommands_list,
479    cmd_list_element **set_list,
480    cmd_list_element **show_list);
481 
482 extern struct cmd_list_element *add_prefix_cmd_suppress_notification
483                               (const char *name, enum command_class theclass,
484                                cmd_simple_func_ftype *fun,
485                                const char *doc, struct cmd_list_element **subcommands,
486                                int allow_unknown,
487                                struct cmd_list_element **list,
488                                bool *suppress_notification);
489 
490 extern struct cmd_list_element *add_abbrev_prefix_cmd (const char *,
491                                                                    enum command_class,
492                                                                    cmd_simple_func_ftype *fun,
493                                                                    const char *,
494                                                                    struct cmd_list_element
495                                                                    **, int,
496                                                                    struct cmd_list_element
497                                                                    **);
498 
499 typedef void cmd_func_ftype (const char *args, int from_tty,
500                                    cmd_list_element *c);
501 
502 /* A completion routine.  Add possible completions to tracker.
503 
504    TEXT is the text beyond what was matched for the command itself
505    (leading whitespace is skipped).  It stops where we are supposed to
506    stop completing (rl_point) and is '\0' terminated.  WORD points in
507    the same buffer as TEXT, and completions should be returned
508    relative to this position.  For example, suppose TEXT is "foo" and
509    we want to complete to "foobar".  If WORD is "oo", return "oobar";
510    if WORD is "baz/foo", return "baz/foobar".  */
511 typedef void completer_ftype (struct cmd_list_element *,
512                                     completion_tracker &tracker,
513                                     const char *text, const char *word);
514 
515 /* Same, but for set_cmd_completer_handle_brkchars.  */
516 typedef void completer_handle_brkchars_ftype (struct cmd_list_element *,
517                                                         completion_tracker &tracker,
518                                                         const char *text, const char *word);
519 
520 extern void set_cmd_completer (struct cmd_list_element *, completer_ftype *);
521 
522 /* Set the completer_handle_brkchars callback.  */
523 
524 extern void set_cmd_completer_handle_brkchars (struct cmd_list_element *,
525                                                          completer_handle_brkchars_ftype *);
526 
527 /* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs
528    around in cmd objects to test the value of the commands sfunc().  */
529 extern int cmd_simple_func_eq (struct cmd_list_element *cmd,
530                                cmd_simple_func_ftype *cfun);
531 
532 /* Execute CMD's pre/post hook.  Throw an error if the command fails.
533    If already executing this pre/post hook, or there is no pre/post
534    hook, the call is silently ignored.  */
535 extern void execute_cmd_pre_hook (struct cmd_list_element *cmd);
536 extern void execute_cmd_post_hook (struct cmd_list_element *cmd);
537 
538 /* Flag for an ambiguous cmd_list result.  */
539 #define CMD_LIST_AMBIGUOUS ((struct cmd_list_element *) -1)
540 
541 extern struct cmd_list_element *lookup_cmd (const char **,
542                                                       struct cmd_list_element *,
543                                                       const char *,
544                                                       std::string *,
545                                                       int, int);
546 
547 /* This routine takes a line of TEXT and a CLIST in which to start the
548    lookup.  When it returns it will have incremented the text pointer past
549    the section of text it matched, set *RESULT_LIST to point to the list in
550    which the last word was matched, and will return a pointer to the cmd
551    list element which the text matches.  It will return NULL if no match at
552    all was possible.  It will return -1 (cast appropriately, ick) if ambigous
553    matches are possible; in this case *RESULT_LIST will be set to point to
554    the list in which there are ambiguous choices (and *TEXT will be set to
555    the ambiguous text string).
556 
557    if DEFAULT_ARGS is not null, *DEFAULT_ARGS is set to the found command
558    default args (possibly empty).
559 
560    If the located command was an abbreviation, this routine returns the base
561    command of the abbreviation.  Note that *DEFAULT_ARGS will contain the
562    default args defined for the alias.
563 
564    It does no error reporting whatsoever; control will always return
565    to the superior routine.
566 
567    In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
568    at the prefix_command (ie. the best match) *or* (special case) will be NULL
569    if no prefix command was ever found.  For example, in the case of "info a",
570    "info" matches without ambiguity, but "a" could be "args" or "address", so
571    *RESULT_LIST is set to the cmd_list_element for "info".  So in this case
572    RESULT_LIST should not be interpreted as a pointer to the beginning of a
573    list; it simply points to a specific command.  In the case of an ambiguous
574    return *TEXT is advanced past the last non-ambiguous prefix (e.g.
575    "info t" can be "info types" or "info target"; upon return *TEXT has been
576    advanced past "info ").
577 
578    If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
579    affect the operation).
580 
581    This routine does *not* modify the text pointed to by TEXT.
582 
583    If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
584    are actually help classes rather than commands (i.e. the function field of
585    the struct cmd_list_element is NULL).
586 
587    When LOOKUP_FOR_COMPLETION_P is true the completion is being requested
588    for the completion engine, no warnings should be printed.  */
589 
590 extern struct cmd_list_element *lookup_cmd_1
591           (const char **text, struct cmd_list_element *clist,
592            struct cmd_list_element **result_list, std::string *default_args,
593            int ignore_help_classes, bool lookup_for_completion_p = false);
594 
595 /* Look up the command called NAME in the command list LIST.
596 
597    Unlike LOOKUP_CMD, partial matches are ignored and only exact matches
598    on NAME are considered.
599 
600    LIST is a chain of struct cmd_list_element's.
601 
602    If IGNORE_HELP_CLASSES is true (the default), ignore any command list
603    elements which are actually help classes rather than commands (i.e.
604    the function field of the struct cmd_list_element is null).
605 
606    If found, return the struct cmd_list_element for that command,
607    otherwise return NULLPTR.  */
608 
609 extern struct cmd_list_element *lookup_cmd_exact
610                               (const char *name,
611                                struct cmd_list_element *list,
612                                bool ignore_help_classes = true);
613 
614 extern struct cmd_list_element *deprecate_cmd (struct cmd_list_element *,
615                                                          const char * );
616 
617 extern void deprecated_cmd_warning (const char *, struct cmd_list_element *);
618 
619 extern int lookup_cmd_composition (const char *text,
620                                            struct cmd_list_element **alias,
621                                            struct cmd_list_element **prefix_cmd,
622                                            struct cmd_list_element **cmd);
623 
624 extern struct cmd_list_element *add_com (const char *, enum command_class,
625                                                    cmd_simple_func_ftype *fun,
626                                                    const char *);
627 
628 extern cmd_list_element *add_com_alias (const char *name,
629                                                   cmd_list_element *target,
630                                                   command_class theclass,
631                                                   int abbrev_flag);
632 
633 extern struct cmd_list_element *add_com_suppress_notification
634                            (const char *name, enum command_class theclass,
635                               cmd_simple_func_ftype *fun, const char *doc,
636                               bool *suppress_notification);
637 
638 extern struct cmd_list_element *add_info (const char *,
639                                                     cmd_simple_func_ftype *fun,
640                                                     const char *);
641 
642 extern cmd_list_element *add_info_alias (const char *name,
643                                                    cmd_list_element *target,
644                                                    int abbrev_flag);
645 
646 extern void complete_on_cmdlist (struct cmd_list_element *,
647                                          completion_tracker &tracker,
648                                          const char *, const char *, int);
649 
650 extern void complete_on_enum (completion_tracker &tracker,
651                                     const char *const *enumlist,
652                                     const char *, const char *);
653 
654 /* Functions that implement commands about CLI commands.  */
655 
656 extern void help_list (struct cmd_list_element *, const char *,
657                            enum command_class, struct ui_file *);
658 
659 /* Method for show a set/show variable's VALUE on FILE.  */
660 typedef void (show_value_ftype) (struct ui_file *file,
661                                          int from_tty,
662                                          struct cmd_list_element *cmd,
663                                          const char *value);
664 
665 /* Various sets of extra literals accepted.  */
666 extern const literal_def integer_unlimited_literals[];
667 extern const literal_def uinteger_unlimited_literals[];
668 extern const literal_def pinteger_unlimited_literals[];
669 
670 extern set_show_commands add_setshow_enum_cmd
671   (const char *name, command_class theclass, const char *const *enumlist,
672    const char **var, const char *set_doc, const char *show_doc,
673    const char *help_doc, cmd_func_ftype *set_func,
674    show_value_ftype *show_func, cmd_list_element **set_list,
675    cmd_list_element **show_list);
676 
677 extern set_show_commands add_setshow_enum_cmd
678   (const char *name, command_class theclass, const char *const *enumlist,
679    const char *set_doc, const char *show_doc,
680    const char *help_doc, setting_func_types<const char *>::set set_func,
681    setting_func_types<const char *>::get get_func, show_value_ftype *show_func,
682    cmd_list_element **set_list, cmd_list_element **show_list);
683 
684 extern set_show_commands add_setshow_auto_boolean_cmd
685   (const char *name, command_class theclass, auto_boolean *var,
686    const char *set_doc, const char *show_doc, const char *help_doc,
687    cmd_func_ftype *set_func, show_value_ftype *show_func,
688    cmd_list_element **set_list, cmd_list_element **show_list);
689 
690 extern set_show_commands add_setshow_auto_boolean_cmd
691   (const char *name, command_class theclass, const char *set_doc,
692    const char *show_doc, const char *help_doc,
693    setting_func_types<enum auto_boolean>::set set_func,
694    setting_func_types<enum auto_boolean>::get get_func,
695    show_value_ftype *show_func, cmd_list_element **set_list,
696    cmd_list_element **show_list);
697 
698 extern set_show_commands add_setshow_boolean_cmd
699   (const char *name, command_class theclass, bool *var, const char *set_doc,
700    const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
701    show_value_ftype *show_func, cmd_list_element **set_list,
702    cmd_list_element **show_list);
703 
704 extern set_show_commands add_setshow_boolean_cmd
705   (const char *name, command_class theclass, const char *set_doc,
706    const char *show_doc, const char *help_doc,
707    setting_func_types<bool>::set set_func,
708    setting_func_types<bool>::get get_func, show_value_ftype *show_func,
709    cmd_list_element **set_list, cmd_list_element **show_list);
710 
711 extern set_show_commands add_setshow_filename_cmd
712   (const char *name, command_class theclass, std::string *var, const char *set_doc,
713    const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
714    show_value_ftype *show_func, cmd_list_element **set_list,
715    cmd_list_element **show_list);
716 
717 extern set_show_commands add_setshow_filename_cmd
718   (const char *name, command_class theclass, const char *set_doc,
719    const char *show_doc, const char *help_doc,
720    setting_func_types<std::string>::set set_func,
721    setting_func_types<std::string>::get get_func, show_value_ftype *show_func,
722    cmd_list_element **set_list, cmd_list_element **show_list);
723 
724 extern set_show_commands add_setshow_string_cmd
725   (const char *name, command_class theclass, std::string *var, const char *set_doc,
726    const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
727    show_value_ftype *show_func, cmd_list_element **set_list,
728    cmd_list_element **show_list);
729 
730 extern set_show_commands add_setshow_string_cmd
731   (const char *name, command_class theclass, const char *set_doc,
732    const char *show_doc, const char *help_doc,
733    setting_func_types<std::string>::set set_func,
734    setting_func_types<std::string>::get get_func,
735    show_value_ftype *show_func, cmd_list_element **set_list,
736    cmd_list_element **show_list);
737 
738 extern set_show_commands add_setshow_string_noescape_cmd
739   (const char *name, command_class theclass, std::string *var, const char *set_doc,
740    const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
741    show_value_ftype *show_func, cmd_list_element **set_list,
742    cmd_list_element **show_list);
743 
744 extern set_show_commands add_setshow_string_noescape_cmd
745   (const char *name, command_class theclass, const char *set_doc,
746    const char *show_doc, const char *help_doc,
747    setting_func_types<std::string>::set set_func,
748    setting_func_types<std::string>::get get_func, show_value_ftype *show_func,
749    cmd_list_element **set_list, cmd_list_element **show_list);
750 
751 extern set_show_commands add_setshow_optional_filename_cmd
752   (const char *name, command_class theclass, std::string *var, const char *set_doc,
753    const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
754    show_value_ftype *show_func, cmd_list_element **set_list,
755    cmd_list_element **show_list);
756 
757 extern set_show_commands add_setshow_optional_filename_cmd
758   (const char *name, command_class theclass, const char *set_doc,
759    const char *show_doc, const char *help_doc,
760    setting_func_types<std::string>::set set_func,
761    setting_func_types<std::string>::get get_func,
762    show_value_ftype *show_func, cmd_list_element **set_list,
763    cmd_list_element **show_list);
764 
765 extern set_show_commands add_setshow_integer_cmd
766   (const char *name, command_class theclass, int *var,
767    const literal_def *extra_literals, const char *set_doc,
768    const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
769    show_value_ftype *show_func, cmd_list_element **set_list,
770    cmd_list_element **show_list);
771 
772 extern set_show_commands add_setshow_integer_cmd
773   (const char *name, command_class theclass, const literal_def *extra_literals,
774    const char *set_doc, const char *show_doc, const char *help_doc,
775    setting_func_types<int>::set set_func,
776    setting_func_types<int>::get get_func, show_value_ftype *show_func,
777    cmd_list_element **set_list, cmd_list_element **show_list);
778 
779 extern set_show_commands add_setshow_integer_cmd
780   (const char *name, command_class theclass, int *var, const char *set_doc,
781    const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
782    show_value_ftype *show_func, cmd_list_element **set_list,
783    cmd_list_element **show_list);
784 
785 extern set_show_commands add_setshow_integer_cmd
786   (const char *name, command_class theclass, const char *set_doc,
787    const char *show_doc, const char *help_doc,
788    setting_func_types<int>::set set_func,
789    setting_func_types<int>::get get_func, show_value_ftype *show_func,
790    cmd_list_element **set_list, cmd_list_element **show_list);
791 
792 extern set_show_commands add_setshow_pinteger_cmd
793   (const char *name, command_class theclass, int *var,
794    const literal_def *extra_literals, const char *set_doc,
795    const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
796    show_value_ftype *show_func, cmd_list_element **set_list,
797    cmd_list_element **show_list);
798 
799 extern set_show_commands add_setshow_pinteger_cmd
800   (const char *name, command_class theclass, const literal_def *extra_literals,
801    const char *set_doc, const char *show_doc, const char *help_doc,
802    setting_func_types<int>::set set_func,
803    setting_func_types<int>::get get_func, show_value_ftype *show_func,
804    cmd_list_element **set_list, cmd_list_element **show_list);
805 
806 extern set_show_commands add_setshow_uinteger_cmd
807   (const char *name, command_class theclass, unsigned int *var,
808    const literal_def *extra_literals,
809    const char *set_doc, const char *show_doc, const char *help_doc,
810    cmd_func_ftype *set_func, show_value_ftype *show_func,
811    cmd_list_element **set_list, cmd_list_element **show_list);
812 
813 extern set_show_commands add_setshow_uinteger_cmd
814   (const char *name, command_class theclass, const literal_def *extra_literals,
815    const char *set_doc, const char *show_doc, const char *help_doc,
816    setting_func_types<unsigned int>::set set_func,
817    setting_func_types<unsigned int>::get get_func, show_value_ftype *show_func,
818    cmd_list_element **set_list, cmd_list_element **show_list);
819 
820 extern set_show_commands add_setshow_uinteger_cmd
821   (const char *name, command_class theclass, unsigned int *var,
822    const char *set_doc, const char *show_doc, const char *help_doc,
823    cmd_func_ftype *set_func, show_value_ftype *show_func,
824    cmd_list_element **set_list, cmd_list_element **show_list);
825 
826 extern set_show_commands add_setshow_uinteger_cmd
827   (const char *name, command_class theclass, const char *set_doc,
828    const char *show_doc, const char *help_doc,
829    setting_func_types<unsigned int>::set set_func,
830    setting_func_types<unsigned int>::get get_func, show_value_ftype *show_func,
831    cmd_list_element **set_list, cmd_list_element **show_list);
832 
833 extern set_show_commands add_setshow_zinteger_cmd
834   (const char *name, command_class theclass, int *var, const char *set_doc,
835    const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
836    show_value_ftype *show_func, cmd_list_element **set_list,
837    cmd_list_element **show_list);
838 
839 extern set_show_commands add_setshow_zinteger_cmd
840   (const char *name, command_class theclass, const char *set_doc,
841    const char *show_doc, const char *help_doc,
842    setting_func_types<int>::set set_func,
843    setting_func_types<int>::get get_func, show_value_ftype *show_func,
844    cmd_list_element **set_list, cmd_list_element **show_list);
845 
846 extern set_show_commands add_setshow_zuinteger_cmd
847   (const char *name, command_class theclass, unsigned int *var,
848    const char *set_doc, const char *show_doc, const char *help_doc,
849    cmd_func_ftype *set_func, show_value_ftype *show_func,
850    cmd_list_element **set_list, cmd_list_element **show_list);
851 
852 extern set_show_commands add_setshow_zuinteger_cmd
853   (const char *name, command_class theclass, const char *set_doc,
854    const char *show_doc, const char *help_doc,
855    setting_func_types<unsigned int>::set set_func,
856    setting_func_types<unsigned int>::get get_func, show_value_ftype *show_func,
857    cmd_list_element **set_list, cmd_list_element **show_list);
858 
859 extern set_show_commands add_setshow_zuinteger_unlimited_cmd
860   (const char *name, command_class theclass, int *var, const char *set_doc,
861    const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
862    show_value_ftype *show_func, cmd_list_element **set_list,
863    cmd_list_element **show_list);
864 
865 extern set_show_commands add_setshow_zuinteger_unlimited_cmd
866   (const char *name, command_class theclass, const char *set_doc,
867    const char *show_doc, const char *help_doc,
868    setting_func_types<int>::set set_func, setting_func_types<int>::get get_func,
869    show_value_ftype *show_func, cmd_list_element **set_list,
870    cmd_list_element **show_list);
871 
872 /* Do a "show" command for each thing on a command list.  */
873 
874 extern void cmd_show_list (struct cmd_list_element *, int);
875 
876 /* Used everywhere whenever at least one parameter is required and
877    none is specified.  */
878 
879 extern void error_no_arg (const char *) ATTRIBUTE_NORETURN;
880 
881 
882 /* Command line saving and repetition.
883    Each input line executed is saved to possibly be repeated either
884    when the user types an empty line, or be repeated by a command
885    that wants to repeat the previously executed command.  The below
886    functions control command repetition.  */
887 
888 /* Commands call dont_repeat if they do not want to be repeated by null
889    lines or by repeat_previous ().  */
890 
891 extern void dont_repeat ();
892 
893 /* Commands call repeat_previous if they want to repeat the previous
894    command.  Such commands that repeat the previous command must
895    indicate to not repeat themselves, to avoid recursive repeat.
896    repeat_previous marks the current command as not repeating, and
897    ensures get_saved_command_line returns the previous command, so
898    that the currently executing command can repeat it.  If there's no
899    previous command, throws an error.  Otherwise, returns the result
900    of get_saved_command_line, which now points at the command to
901    repeat.  */
902 
903 extern const char *repeat_previous ();
904 
905 /* Prevent dont_repeat from working, and return a cleanup that
906    restores the previous state.  */
907 
908 extern scoped_restore_tmpl<int> prevent_dont_repeat (void);
909 
910 /* Set the arguments that will be passed if the current command is
911    repeated.  Note that the passed-in string must be a constant.  */
912 
913 extern void set_repeat_arguments (const char *args);
914 
915 /* Returns the saved command line to repeat.
916    When a command is being executed, this is the currently executing
917    command line, unless the currently executing command has called
918    repeat_previous (): in this case, get_saved_command_line returns
919    the previously saved command line.  */
920 
921 extern char *get_saved_command_line ();
922 
923 /* Takes a copy of CMD, for possible repetition.  */
924 
925 extern void save_command_line (const char *cmd);
926 
927 /* Used to mark commands that don't do anything.  If we just leave the
928    function field NULL, the command is interpreted as a help topic, or
929    as a class of commands.  */
930 
931 extern void not_just_help_class_command (const char *, int);
932 
933 /* Call the command function.  */
934 extern void cmd_func (struct cmd_list_element *cmd,
935                           const char *args, int from_tty);
936 
937 #endif /* !defined (COMMAND_H) */
938