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