command.h 32 KB

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