2012-01-20 Pedro Alves <palves@redhat.com>
[platform/upstream/binutils.git] / gdb / command.h
1 /* Header file for command creation.
2
3    Copyright (C) 1986, 1989-1995, 1999-2000, 2002, 2004, 2007-2012 Free
4    Software Foundation, Inc.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 #if !defined (COMMAND_H)
20 #define COMMAND_H 1
21
22 /* This file defines the public interface for any code wanting to
23    create commands.  */
24
25 /* Command classes are top-level categories into which commands are
26    broken down for "help" purposes.
27
28    Notes on classes: class_alias is for alias commands which are not
29    abbreviations of the original command.  class-pseudo is for
30    commands which are not really commands nor help topics ("stop").  */
31
32 enum command_class
33 {
34   /* Special args to help_list */
35   class_deprecated = -3, all_classes = -2, all_commands = -1,
36   /* Classes of commands */
37   no_class = -1, class_run = 0, class_vars, class_stack, class_files,
38   class_support, class_info, class_breakpoint, class_trace,
39   class_alias, class_bookmark, class_obscure, class_maintenance,
40   class_pseudo, class_tui, class_user, class_xdb,
41   no_set_class  /* Used for "show" commands that have no corresponding
42                    "set" command.  */
43 };
44
45 /* FIXME: cagney/2002-03-17: Once cmd_type() has been removed, ``enum
46    cmd_types'' can be moved from "command.h" to "cli-decode.h".  */
47 /* Not a set/show command.  Note that some commands which begin with
48    "set" or "show" might be in this category, if their syntax does
49    not fall into one of the following categories.  */
50 typedef enum cmd_types
51   {
52     not_set_cmd,
53     set_cmd,
54     show_cmd
55   }
56 cmd_types;
57
58 /* Types of "set" or "show" command.  */
59 typedef enum var_types
60   {
61     /* "on" or "off".  *VAR is an integer which is nonzero for on,
62        zero for off.  */
63     var_boolean,
64
65     /* "on" / "true" / "enable" or "off" / "false" / "disable" or
66        "auto.  *VAR is an ``enum auto_boolean''.  NOTE: In general a
67        custom show command will need to be implemented - one that for
68        "auto" prints both the "auto" and the current auto-selected
69        value.  */
70     var_auto_boolean,
71
72     /* Unsigned Integer.  *VAR is an unsigned int.  The user can type
73        0 to mean "unlimited", which is stored in *VAR as UINT_MAX.  */
74     var_uinteger,
75
76     /* Like var_uinteger but signed.  *VAR is an int.  The user can
77        type 0 to mean "unlimited", which is stored in *VAR as
78        INT_MAX.  */
79     var_integer,
80
81     /* String which the user enters with escapes (e.g. the user types
82        \n and it is a real newline in the stored string).
83        *VAR is a malloc'd string, or NULL if the string is empty.  */
84     var_string,
85     /* String which stores what the user types verbatim.
86        *VAR is a malloc'd string, or NULL if the string is empty.  */
87     var_string_noescape,
88     /* String which stores a filename.  (*VAR) is a malloc'd string,
89        or "" if the string was empty.  */
90     var_optional_filename,
91     /* String which stores a filename.  (*VAR) is a malloc'd
92        string.  */
93     var_filename,
94     /* ZeroableInteger.  *VAR is an int.  Like Unsigned Integer except
95        that zero really means zero.  */
96     var_zinteger,
97     /* ZeroableUnsignedInteger.  *VAR is an unsigned int.  Zero really
98        means zero.  */
99     var_zuinteger,
100     /* Enumerated type.  Can only have one of the specified values.
101        *VAR is a char pointer to the name of the element that we
102        find.  */
103     var_enum
104   }
105 var_types;
106
107 /* This structure records one command'd definition.  */
108 struct cmd_list_element;
109
110 /* Forward-declarations of the entry-points of cli/cli-decode.c.  */
111
112 /* API to the manipulation of command lists.  */
113
114 extern int valid_user_defined_cmd_name_p (const char *name);
115
116 extern struct cmd_list_element *add_cmd (char *, enum command_class,
117                                          void (*fun) (char *, int), char *,
118                                          struct cmd_list_element **);
119
120 extern struct cmd_list_element *add_alias_cmd (char *, char *,
121                                                enum command_class, int,
122                                                struct cmd_list_element **);
123
124 extern struct cmd_list_element *add_prefix_cmd (char *, enum command_class,
125                                                 void (*fun) (char *, int),
126                                                 char *,
127                                                 struct cmd_list_element **,
128                                                 char *, int,
129                                                 struct cmd_list_element **);
130
131 extern struct cmd_list_element *add_abbrev_prefix_cmd (char *,
132                                                        enum command_class,
133                                                        void (*fun) (char *,
134                                                                     int),
135                                                        char *,
136                                                        struct cmd_list_element
137                                                        **, char *, int,
138                                                        struct cmd_list_element
139                                                        **);
140
141 /* Set the commands corresponding callback.  */
142
143 typedef void cmd_cfunc_ftype (char *args, int from_tty);
144 extern void set_cmd_cfunc (struct cmd_list_element *cmd,
145                            cmd_cfunc_ftype *cfunc);
146
147 typedef void cmd_sfunc_ftype (char *args, int from_tty,
148                               struct cmd_list_element *c);
149 extern void set_cmd_sfunc (struct cmd_list_element *cmd,
150                            cmd_sfunc_ftype *sfunc);
151
152 extern void set_cmd_completer (struct cmd_list_element *,
153                                char **(*completer) (struct cmd_list_element *,
154                                                     char *, char *));
155
156 /* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs
157    around in cmd objects to test the value of the commands sfunc().  */
158 extern int cmd_cfunc_eq (struct cmd_list_element *cmd,
159                          void (*cfunc) (char *args, int from_tty));
160
161 /* Each command object has a local context attached to it.  */
162 extern void set_cmd_context (struct cmd_list_element *cmd,
163                              void *context);
164 extern void *get_cmd_context (struct cmd_list_element *cmd);
165
166
167 /* Execute CMD's pre/post hook.  Throw an error if the command fails.
168    If already executing this pre/post hook, or there is no pre/post
169    hook, the call is silently ignored.  */
170 extern void execute_cmd_pre_hook (struct cmd_list_element *cmd);
171 extern void execute_cmd_post_hook (struct cmd_list_element *cmd);
172
173 /* Return the type of the command.  */
174 extern enum cmd_types cmd_type (struct cmd_list_element *cmd);
175
176 /* Flag for an ambiguous cmd_list result.  */
177 #define CMD_LIST_AMBIGUOUS ((struct cmd_list_element *) -1)
178
179 extern struct cmd_list_element *lookup_cmd (char **,
180                                             struct cmd_list_element *, char *,
181                                             int, int);
182
183 extern struct cmd_list_element *lookup_cmd_1 (char **,
184                                               struct cmd_list_element *,
185                                               struct cmd_list_element **,
186                                               int);
187
188 extern struct cmd_list_element *deprecate_cmd (struct cmd_list_element *,
189                                                char * );
190
191 extern void deprecated_cmd_warning (char **);
192
193 extern int lookup_cmd_composition (char *text,
194                                    struct cmd_list_element **alias,
195                                    struct cmd_list_element **prefix_cmd,
196                                    struct cmd_list_element **cmd);
197
198 extern struct cmd_list_element *add_com (char *, enum command_class,
199                                          void (*fun) (char *, int),
200                                          char *);
201
202 extern struct cmd_list_element *add_com_alias (char *, char *,
203                                                enum command_class, int);
204
205 extern struct cmd_list_element *add_info (char *,
206                                           void (*fun) (char *, int),
207                                           char *);
208
209 extern struct cmd_list_element *add_info_alias (char *, char *, int);
210
211 extern char **complete_on_cmdlist (struct cmd_list_element *,
212                                    char *, char *);
213
214 extern char **complete_on_enum (const char *enumlist[],
215                                 char *, char *);
216
217 /* Functions that implement commands about CLI commands.  */
218
219 extern void help_list (struct cmd_list_element *, char *,
220                        enum command_class, struct ui_file *);
221
222 /* Method for show a set/show variable's VALUE on FILE.  If this
223    method isn't supplied deprecated_show_value_hack() is called (which
224    is not good).  */
225 typedef void (show_value_ftype) (struct ui_file *file,
226                                  int from_tty,
227                                  struct cmd_list_element *cmd,
228                                  const char *value);
229 /* NOTE: i18n: This function is not i18n friendly.  Callers should
230    instead print the value out directly.  */
231 extern show_value_ftype deprecated_show_value_hack;
232
233 extern void add_setshow_enum_cmd (char *name,
234                                   enum command_class class,
235                                   const char *enumlist[],
236                                   const char **var,
237                                   const char *set_doc,
238                                   const char *show_doc,
239                                   const char *help_doc,
240                                   cmd_sfunc_ftype *set_func,
241                                   show_value_ftype *show_func,
242                                   struct cmd_list_element **set_list,
243                                   struct cmd_list_element **show_list);
244
245 extern void add_setshow_auto_boolean_cmd (char *name,
246                                           enum command_class class,
247                                           enum auto_boolean *var,
248                                           const char *set_doc,
249                                           const char *show_doc,
250                                           const char *help_doc,
251                                           cmd_sfunc_ftype *set_func,
252                                           show_value_ftype *show_func,
253                                           struct cmd_list_element **set_list,
254                                           struct cmd_list_element **show_list);
255
256 extern void add_setshow_boolean_cmd (char *name,
257                                      enum command_class class,
258                                      int *var,
259                                      const char *set_doc, const char *show_doc,
260                                      const char *help_doc,
261                                      cmd_sfunc_ftype *set_func,
262                                      show_value_ftype *show_func,
263                                      struct cmd_list_element **set_list,
264                                      struct cmd_list_element **show_list);
265
266 extern void add_setshow_filename_cmd (char *name,
267                                       enum command_class class,
268                                       char **var,
269                                       const char *set_doc,
270                                       const char *show_doc,
271                                       const char *help_doc,
272                                       cmd_sfunc_ftype *set_func,
273                                       show_value_ftype *show_func,
274                                       struct cmd_list_element **set_list,
275                                       struct cmd_list_element **show_list);
276
277 extern void add_setshow_string_cmd (char *name,
278                                     enum command_class class,
279                                     char **var,
280                                     const char *set_doc,
281                                     const char *show_doc,
282                                     const char *help_doc,
283                                     cmd_sfunc_ftype *set_func,
284                                     show_value_ftype *show_func,
285                                     struct cmd_list_element **set_list,
286                                     struct cmd_list_element **show_list);
287
288 extern void add_setshow_string_noescape_cmd (char *name,
289                                              enum command_class class,
290                                              char **var,
291                                              const char *set_doc,
292                                              const char *show_doc,
293                                              const char *help_doc,
294                                              cmd_sfunc_ftype *set_func,
295                                              show_value_ftype *show_func,
296                                              struct cmd_list_element **set_list,
297                                              struct cmd_list_element **show_list);
298
299 extern void add_setshow_optional_filename_cmd (char *name,
300                                                enum command_class class,
301                                                char **var,
302                                                const char *set_doc,
303                                                const char *show_doc,
304                                                const char *help_doc,
305                                                cmd_sfunc_ftype *set_func,
306                                                show_value_ftype *show_func,
307                                                struct cmd_list_element **set_list,
308                                                struct cmd_list_element **show_list);
309
310 extern void add_setshow_integer_cmd (char *name,
311                                      enum command_class class,
312                                      int *var,
313                                      const char *set_doc,
314                                      const char *show_doc,
315                                      const char *help_doc,
316                                      cmd_sfunc_ftype *set_func,
317                                      show_value_ftype *show_func,
318                                      struct cmd_list_element **set_list,
319                                      struct cmd_list_element **show_list);
320
321 extern void add_setshow_uinteger_cmd (char *name,
322                                       enum command_class class,
323                                       unsigned int *var,
324                                       const char *set_doc,
325                                       const char *show_doc,
326                                       const char *help_doc,
327                                       cmd_sfunc_ftype *set_func,
328                                       show_value_ftype *show_func,
329                                       struct cmd_list_element **set_list,
330                                       struct cmd_list_element **show_list);
331
332 extern void add_setshow_zinteger_cmd (char *name,
333                                       enum command_class class,
334                                       int *var,
335                                       const char *set_doc,
336                                       const char *show_doc,
337                                       const char *help_doc,
338                                       cmd_sfunc_ftype *set_func,
339                                       show_value_ftype *show_func,
340                                       struct cmd_list_element **set_list,
341                                       struct cmd_list_element **show_list);
342
343 extern void add_setshow_zuinteger_cmd (char *name,
344                                        enum command_class class,
345                                        unsigned int *var,
346                                        const char *set_doc,
347                                        const char *show_doc,
348                                        const char *help_doc,
349                                        cmd_sfunc_ftype *set_func,
350                                        show_value_ftype *show_func,
351                                        struct cmd_list_element **set_list,
352                                        struct cmd_list_element **show_list);
353
354 /* Do a "show" command for each thing on a command list.  */
355
356 extern void cmd_show_list (struct cmd_list_element *, int, char *);
357
358 /* Used everywhere whenever at least one parameter is required and
359    none is specified.  */
360
361 extern void error_no_arg (char *) ATTRIBUTE_NORETURN;
362
363 extern void dont_repeat (void);
364
365 extern struct cleanup *prevent_dont_repeat (void);
366
367 /* Used to mark commands that don't do anything.  If we just leave the
368    function field NULL, the command is interpreted as a help topic, or
369    as a class of commands.  */
370
371 extern void not_just_help_class_command (char *, int);
372
373 /* Check function pointer.  */
374 extern int cmd_func_p (struct cmd_list_element *cmd);
375
376 /* Call the command function.  */
377 extern void cmd_func (struct cmd_list_element *cmd,
378                       char *args, int from_tty);
379
380 #endif /* !defined (COMMAND_H) */