Clean up "completer_handle_brkchars" callback handling
[external/binutils.git] / gdb / command.h
1 /* Header file for command creation.
2
3    Copyright (C) 1986-2017 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 "gdb_vecs.h"
22 #include "common/scoped_restore.h"
23
24 /* This file defines the public interface for any code wanting to
25    create commands.  */
26
27 /* Command classes are top-level categories into which commands are
28    broken down for "help" purposes.
29
30    Notes on classes: class_alias is for alias commands which are not
31    abbreviations of the original command.  class-pseudo is for
32    commands which are not really commands nor help topics ("stop").  */
33
34 enum command_class
35 {
36   /* Special args to help_list */
37   class_deprecated = -3, all_classes = -2, all_commands = -1,
38   /* Classes of commands */
39   no_class = -1, class_run = 0, class_vars, class_stack, class_files,
40   class_support, class_info, class_breakpoint, class_trace,
41   class_alias, class_bookmark, class_obscure, class_maintenance,
42   class_pseudo, class_tui, class_user, class_xdb,
43   no_set_class  /* Used for "show" commands that have no corresponding
44                    "set" command.  */
45 };
46
47 /* FIXME: cagney/2002-03-17: Once cmd_type() has been removed, ``enum
48    cmd_types'' can be moved from "command.h" to "cli-decode.h".  */
49 /* Not a set/show command.  Note that some commands which begin with
50    "set" or "show" might be in this category, if their syntax does
51    not fall into one of the following categories.  */
52 typedef enum cmd_types
53   {
54     not_set_cmd,
55     set_cmd,
56     show_cmd
57   }
58 cmd_types;
59
60 /* Types of "set" or "show" command.  */
61 typedef enum var_types
62   {
63     /* "on" or "off".  *VAR is an integer which is nonzero for on,
64        zero for off.  */
65     var_boolean,
66
67     /* "on" / "true" / "enable" or "off" / "false" / "disable" or
68        "auto.  *VAR is an ``enum auto_boolean''.  NOTE: In general a
69        custom show command will need to be implemented - one that for
70        "auto" prints both the "auto" and the current auto-selected
71        value.  */
72     var_auto_boolean,
73
74     /* Unsigned Integer.  *VAR is an unsigned int.  The user can type
75        0 to mean "unlimited", which is stored in *VAR as UINT_MAX.  */
76     var_uinteger,
77
78     /* Like var_uinteger but signed.  *VAR is an int.  The user can
79        type 0 to mean "unlimited", which is stored in *VAR as
80        INT_MAX.  The only remaining use of it is the Python API.
81        Don't use it elsewhere.  */
82     var_integer,
83
84     /* String which the user enters with escapes (e.g. the user types
85        \n and it is a real newline in the stored string).
86        *VAR is a malloc'd string, or NULL if the string is empty.  */
87     var_string,
88     /* String which stores what the user types verbatim.
89        *VAR is a malloc'd string, or NULL if the string is empty.  */
90     var_string_noescape,
91     /* String which stores a filename.  (*VAR) is a malloc'd string,
92        or "" if the string was empty.  */
93     var_optional_filename,
94     /* String which stores a filename.  (*VAR) is a malloc'd
95        string.  */
96     var_filename,
97     /* ZeroableInteger.  *VAR is an int.  Like var_integer except
98        that zero really means zero.  */
99     var_zinteger,
100     /* ZeroableUnsignedInteger.  *VAR is an unsigned int.  Zero really
101        means zero.  */
102     var_zuinteger,
103     /* ZeroableUnsignedInteger with unlimited value.  *VAR is an int,
104        but its range is [0, INT_MAX].  -1 stands for unlimited and
105        other negative numbers are not allowed.  */
106     var_zuinteger_unlimited,
107     /* Enumerated type.  Can only have one of the specified values.
108        *VAR is a char pointer to the name of the element that we
109        find.  */
110     var_enum
111   }
112 var_types;
113
114 /* This structure records one command'd definition.  */
115 struct cmd_list_element;
116
117 typedef void cmd_cfunc_ftype (char *args, int from_tty);
118
119 /* This structure specifies notifications to be suppressed by a cli
120    command interpreter.  */
121
122 struct cli_suppress_notification
123 {
124   /* Inferior, thread, frame selected notification suppressed?  */
125   int user_selected_context;
126 };
127
128 extern struct cli_suppress_notification cli_suppress_notification;
129
130 /* Forward-declarations of the entry-points of cli/cli-decode.c.  */
131
132 /* API to the manipulation of command lists.  */
133
134 extern int valid_user_defined_cmd_name_p (const char *name);
135
136 extern struct cmd_list_element *add_cmd (const char *, enum command_class,
137                                          cmd_cfunc_ftype *fun,
138                                          const char *,
139                                          struct cmd_list_element **);
140
141 extern struct cmd_list_element *add_alias_cmd (const char *, const char *,
142                                                enum command_class, int,
143                                                struct cmd_list_element **);
144
145 extern struct cmd_list_element *add_alias_cmd (const char *,
146                                                cmd_list_element *,
147                                                enum command_class, int,
148                                                struct cmd_list_element **);
149
150
151 extern struct cmd_list_element *add_prefix_cmd (const char *, enum command_class,
152                                                 cmd_cfunc_ftype *fun,
153                                                 const char *,
154                                                 struct cmd_list_element **,
155                                                 const char *, int,
156                                                 struct cmd_list_element **);
157
158 extern struct cmd_list_element *add_abbrev_prefix_cmd (const char *,
159                                                        enum command_class,
160                                                        cmd_cfunc_ftype *fun,
161                                                        const char *,
162                                                        struct cmd_list_element
163                                                        **, const char *, int,
164                                                        struct cmd_list_element
165                                                        **);
166
167 /* Set the commands corresponding callback.  */
168
169 extern void set_cmd_cfunc (struct cmd_list_element *cmd,
170                            cmd_cfunc_ftype *cfunc);
171
172 typedef void cmd_sfunc_ftype (char *args, int from_tty,
173                               struct cmd_list_element *c);
174 extern void set_cmd_sfunc (struct cmd_list_element *cmd,
175                            cmd_sfunc_ftype *sfunc);
176
177 /* A completion routine.  Return a list of possible completions.
178
179    TEXT is the text beyond what was matched for the command itself
180    (leading whitespace is skipped).  It stops where we are supposed to
181    stop completing (rl_point) and is '\0' terminated.  WORD points in
182    the same buffer as TEXT, and completions should be returned
183    relative to this position.  For example, suppose TEXT is "foo" and
184    we want to complete to "foobar".  If WORD is "oo", return "oobar";
185    if WORD is "baz/foo", return "baz/foobar".  */
186 typedef VEC (char_ptr) *completer_ftype (struct cmd_list_element *,
187                                          const char *text, const char *word);
188
189 /* Same, but for set_cmd_completer_handle_brkchars.  */
190 typedef void completer_handle_brkchars_ftype (struct cmd_list_element *,
191                                               const char *text, const char *word);
192
193 extern void set_cmd_completer (struct cmd_list_element *, completer_ftype *);
194
195 /* Set the completer_handle_brkchars callback.  */
196
197 extern void set_cmd_completer_handle_brkchars (struct cmd_list_element *,
198                                                completer_handle_brkchars_ftype *);
199
200 /* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs
201    around in cmd objects to test the value of the commands sfunc().  */
202 extern int cmd_cfunc_eq (struct cmd_list_element *cmd,
203                          cmd_cfunc_ftype *cfun);
204
205 /* Each command object has a local context attached to it.  */
206 extern void set_cmd_context (struct cmd_list_element *cmd,
207                              void *context);
208 extern void *get_cmd_context (struct cmd_list_element *cmd);
209
210
211 /* Execute CMD's pre/post hook.  Throw an error if the command fails.
212    If already executing this pre/post hook, or there is no pre/post
213    hook, the call is silently ignored.  */
214 extern void execute_cmd_pre_hook (struct cmd_list_element *cmd);
215 extern void execute_cmd_post_hook (struct cmd_list_element *cmd);
216
217 /* Return the type of the command.  */
218 extern enum cmd_types cmd_type (struct cmd_list_element *cmd);
219
220 /* Flag for an ambiguous cmd_list result.  */
221 #define CMD_LIST_AMBIGUOUS ((struct cmd_list_element *) -1)
222
223 extern struct cmd_list_element *lookup_cmd (const char **,
224                                             struct cmd_list_element *,
225                                             const char *,
226                                             int, int);
227
228 extern struct cmd_list_element *lookup_cmd_1 (const char **,
229                                               struct cmd_list_element *,
230                                               struct cmd_list_element **,
231                                               int);
232
233 extern struct cmd_list_element *deprecate_cmd (struct cmd_list_element *,
234                                                const char * );
235
236 extern void deprecated_cmd_warning (const char *);
237
238 extern int lookup_cmd_composition (const char *text,
239                                    struct cmd_list_element **alias,
240                                    struct cmd_list_element **prefix_cmd,
241                                    struct cmd_list_element **cmd);
242
243 extern struct cmd_list_element *add_com (const char *, enum command_class,
244                                          cmd_cfunc_ftype *fun,
245                                          const char *);
246
247 extern struct cmd_list_element *add_com_alias (const char *, const char *,
248                                                enum command_class, int);
249
250 extern struct cmd_list_element *add_com_suppress_notification
251                        (const char *name, enum command_class theclass,
252                         cmd_cfunc_ftype *fun, const char *doc,
253                         int *supress_notification);
254
255 extern struct cmd_list_element *add_info (const char *,
256                                           cmd_cfunc_ftype *fun,
257                                           const char *);
258
259 extern struct cmd_list_element *add_info_alias (const char *, const char *,
260                                                 int);
261
262 extern VEC (char_ptr) *complete_on_cmdlist (struct cmd_list_element *,
263                                             const char *, const char *, int);
264
265 extern VEC (char_ptr) *complete_on_enum (const char *const *enumlist,
266                                          const char *, const char *);
267
268 /* Functions that implement commands about CLI commands.  */
269
270 extern void help_list (struct cmd_list_element *, const char *,
271                        enum command_class, struct ui_file *);
272
273 /* Method for show a set/show variable's VALUE on FILE.  If this
274    method isn't supplied deprecated_show_value_hack() is called (which
275    is not good).  */
276 typedef void (show_value_ftype) (struct ui_file *file,
277                                  int from_tty,
278                                  struct cmd_list_element *cmd,
279                                  const char *value);
280 /* NOTE: i18n: This function is not i18n friendly.  Callers should
281    instead print the value out directly.  */
282 extern show_value_ftype deprecated_show_value_hack;
283
284 extern void add_setshow_enum_cmd (const char *name,
285                                   enum command_class theclass,
286                                   const char *const *enumlist,
287                                   const char **var,
288                                   const char *set_doc,
289                                   const char *show_doc,
290                                   const char *help_doc,
291                                   cmd_sfunc_ftype *set_func,
292                                   show_value_ftype *show_func,
293                                   struct cmd_list_element **set_list,
294                                   struct cmd_list_element **show_list);
295
296 extern void add_setshow_auto_boolean_cmd (const char *name,
297                                           enum command_class theclass,
298                                           enum auto_boolean *var,
299                                           const char *set_doc,
300                                           const char *show_doc,
301                                           const char *help_doc,
302                                           cmd_sfunc_ftype *set_func,
303                                           show_value_ftype *show_func,
304                                           struct cmd_list_element **set_list,
305                                           struct cmd_list_element **show_list);
306
307 extern void add_setshow_boolean_cmd (const char *name,
308                                      enum command_class theclass,
309                                      int *var,
310                                      const char *set_doc, const char *show_doc,
311                                      const char *help_doc,
312                                      cmd_sfunc_ftype *set_func,
313                                      show_value_ftype *show_func,
314                                      struct cmd_list_element **set_list,
315                                      struct cmd_list_element **show_list);
316
317 extern void add_setshow_filename_cmd (const char *name,
318                                       enum command_class theclass,
319                                       char **var,
320                                       const char *set_doc,
321                                       const char *show_doc,
322                                       const char *help_doc,
323                                       cmd_sfunc_ftype *set_func,
324                                       show_value_ftype *show_func,
325                                       struct cmd_list_element **set_list,
326                                       struct cmd_list_element **show_list);
327
328 extern void add_setshow_string_cmd (const char *name,
329                                     enum command_class theclass,
330                                     char **var,
331                                     const char *set_doc,
332                                     const char *show_doc,
333                                     const char *help_doc,
334                                     cmd_sfunc_ftype *set_func,
335                                     show_value_ftype *show_func,
336                                     struct cmd_list_element **set_list,
337                                     struct cmd_list_element **show_list);
338
339 extern struct cmd_list_element *add_setshow_string_noescape_cmd
340                       (const char *name,
341                        enum command_class theclass,
342                        char **var,
343                        const char *set_doc,
344                        const char *show_doc,
345                        const char *help_doc,
346                        cmd_sfunc_ftype *set_func,
347                        show_value_ftype *show_func,
348                        struct cmd_list_element **set_list,
349                        struct cmd_list_element **show_list);
350
351 extern void add_setshow_optional_filename_cmd (const char *name,
352                                                enum command_class theclass,
353                                                char **var,
354                                                const char *set_doc,
355                                                const char *show_doc,
356                                                const char *help_doc,
357                                                cmd_sfunc_ftype *set_func,
358                                                show_value_ftype *show_func,
359                                                struct cmd_list_element **set_list,
360                                                struct cmd_list_element **show_list);
361
362 extern void add_setshow_integer_cmd (const char *name,
363                                      enum command_class theclass,
364                                      int *var,
365                                      const char *set_doc,
366                                      const char *show_doc,
367                                      const char *help_doc,
368                                      cmd_sfunc_ftype *set_func,
369                                      show_value_ftype *show_func,
370                                      struct cmd_list_element **set_list,
371                                      struct cmd_list_element **show_list);
372
373 extern void add_setshow_uinteger_cmd (const char *name,
374                                       enum command_class theclass,
375                                       unsigned int *var,
376                                       const char *set_doc,
377                                       const char *show_doc,
378                                       const char *help_doc,
379                                       cmd_sfunc_ftype *set_func,
380                                       show_value_ftype *show_func,
381                                       struct cmd_list_element **set_list,
382                                       struct cmd_list_element **show_list);
383
384 extern void add_setshow_zinteger_cmd (const char *name,
385                                       enum command_class theclass,
386                                       int *var,
387                                       const char *set_doc,
388                                       const char *show_doc,
389                                       const char *help_doc,
390                                       cmd_sfunc_ftype *set_func,
391                                       show_value_ftype *show_func,
392                                       struct cmd_list_element **set_list,
393                                       struct cmd_list_element **show_list);
394
395 extern void add_setshow_zuinteger_cmd (const char *name,
396                                        enum command_class theclass,
397                                        unsigned int *var,
398                                        const char *set_doc,
399                                        const char *show_doc,
400                                        const char *help_doc,
401                                        cmd_sfunc_ftype *set_func,
402                                        show_value_ftype *show_func,
403                                        struct cmd_list_element **set_list,
404                                        struct cmd_list_element **show_list);
405
406 extern void
407   add_setshow_zuinteger_unlimited_cmd (const char *name,
408                                        enum command_class theclass,
409                                        int *var,
410                                        const char *set_doc,
411                                        const char *show_doc,
412                                        const char *help_doc,
413                                        cmd_sfunc_ftype *set_func,
414                                        show_value_ftype *show_func,
415                                        struct cmd_list_element **set_list,
416                                        struct cmd_list_element **show_list);
417
418 /* Do a "show" command for each thing on a command list.  */
419
420 extern void cmd_show_list (struct cmd_list_element *, int, const char *);
421
422 /* Used everywhere whenever at least one parameter is required and
423    none is specified.  */
424
425 extern void error_no_arg (const char *) ATTRIBUTE_NORETURN;
426
427 extern void dont_repeat (void);
428
429 extern scoped_restore_tmpl<int> prevent_dont_repeat (void);
430
431 /* Used to mark commands that don't do anything.  If we just leave the
432    function field NULL, the command is interpreted as a help topic, or
433    as a class of commands.  */
434
435 extern void not_just_help_class_command (char *, int);
436
437 /* Check function pointer.  */
438 extern int cmd_func_p (struct cmd_list_element *cmd);
439
440 /* Call the command function.  */
441 extern void cmd_func (struct cmd_list_element *cmd,
442                       char *args, int from_tty);
443
444 #endif /* !defined (COMMAND_H) */