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