1b725ae77Skettenis /* Header file for GDB command decoding library. 2b725ae77Skettenis 3b725ae77Skettenis Copyright 2000, 2003 Free Software Foundation, Inc. 4b725ae77Skettenis 5b725ae77Skettenis This program is free software; you can redistribute it and/or modify 6b725ae77Skettenis it under the terms of the GNU General Public License as published by 7b725ae77Skettenis the Free Software Foundation; either version 2 of the License, or 8b725ae77Skettenis (at your option) any later version. 9b725ae77Skettenis 10b725ae77Skettenis This program is distributed in the hope that it will be useful, 11b725ae77Skettenis but WITHOUT ANY WARRANTY; without even the implied warranty of 12b725ae77Skettenis MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13b725ae77Skettenis GNU General Public License for more details. 14b725ae77Skettenis 15b725ae77Skettenis You should have received a copy of the GNU General Public License 16b725ae77Skettenis along with this program; if not, write to the Free Software 17b725ae77Skettenis Foundation, Inc., 59 Temple Place - Suite 330, 18b725ae77Skettenis Boston, MA 02111-1307, USA. */ 19b725ae77Skettenis 20b725ae77Skettenis #if !defined (CLI_DECODE_H) 21b725ae77Skettenis #define CLI_DECODE_H 1 22b725ae77Skettenis 23b725ae77Skettenis #include "command.h" 24b725ae77Skettenis 25b725ae77Skettenis struct re_pattern_buffer; 26b725ae77Skettenis 27b725ae77Skettenis #if 0 28b725ae77Skettenis /* FIXME: cagney/2002-03-17: Once cmd_type() has been removed, ``enum 29b725ae77Skettenis cmd_types'' can be moved from "command.h" to "cli-decode.h". */ 30b725ae77Skettenis /* Not a set/show command. Note that some commands which begin with 31b725ae77Skettenis "set" or "show" might be in this category, if their syntax does 32b725ae77Skettenis not fall into one of the following categories. */ 33b725ae77Skettenis typedef enum cmd_types 34b725ae77Skettenis { 35b725ae77Skettenis not_set_cmd, 36b725ae77Skettenis set_cmd, 37b725ae77Skettenis show_cmd 38b725ae77Skettenis } 39b725ae77Skettenis cmd_types; 40b725ae77Skettenis #endif 41b725ae77Skettenis 42b725ae77Skettenis /* This structure records one command'd definition. */ 43b725ae77Skettenis 44b725ae77Skettenis 45b725ae77Skettenis /* This flag is used by the code executing commands to warn the user 46b725ae77Skettenis the first time a deprecated command is used, see the 'flags' field in 47b725ae77Skettenis the following struct. 48b725ae77Skettenis */ 49b725ae77Skettenis #define CMD_DEPRECATED 0x1 50b725ae77Skettenis #define DEPRECATED_WARN_USER 0x2 51b725ae77Skettenis #define MALLOCED_REPLACEMENT 0x4 52b725ae77Skettenis 53b725ae77Skettenis struct cmd_list_element 54b725ae77Skettenis { 55b725ae77Skettenis /* Points to next command in this list. */ 56b725ae77Skettenis struct cmd_list_element *next; 57b725ae77Skettenis 58b725ae77Skettenis /* Name of this command. */ 59b725ae77Skettenis char *name; 60b725ae77Skettenis 61b725ae77Skettenis /* Command class; class values are chosen by application program. */ 62b725ae77Skettenis enum command_class class; 63b725ae77Skettenis 64b725ae77Skettenis /* Function definition of this command. NULL for command class 65b725ae77Skettenis names and for help topics that are not really commands. NOTE: 66b725ae77Skettenis cagney/2002-02-02: This function signature is evolving. For 67b725ae77Skettenis the moment suggest sticking with either set_cmd_cfunc() or 68b725ae77Skettenis set_cmd_sfunc(). */ 69b725ae77Skettenis void (*func) (struct cmd_list_element *c, char *args, int from_tty); 70b725ae77Skettenis /* The command's real callback. At present func() bounces through 71b725ae77Skettenis to one of the below. */ 72b725ae77Skettenis union 73b725ae77Skettenis { 74b725ae77Skettenis /* If type is not_set_cmd, call it like this: */ 75b725ae77Skettenis cmd_cfunc_ftype *cfunc; 76b725ae77Skettenis /* If type is set_cmd or show_cmd, first set the variables, 77b725ae77Skettenis and then call this: */ 78b725ae77Skettenis cmd_sfunc_ftype *sfunc; 79b725ae77Skettenis } 80b725ae77Skettenis function; 81b725ae77Skettenis 82b725ae77Skettenis /* Local state (context) for this command. This can be anything. */ 83b725ae77Skettenis void *context; 84b725ae77Skettenis 85b725ae77Skettenis /* Documentation of this command (or help topic). 86b725ae77Skettenis First line is brief documentation; remaining lines form, with it, 87b725ae77Skettenis the full documentation. First line should end with a period. 88b725ae77Skettenis Entire string should also end with a period, not a newline. */ 89b725ae77Skettenis char *doc; 90b725ae77Skettenis 91b725ae77Skettenis /* flags : a bitfield 92b725ae77Skettenis 93b725ae77Skettenis bit 0: (LSB) CMD_DEPRECATED, when 1 indicated that this command 94b725ae77Skettenis is deprecated. It may be removed from gdb's command set in the 95b725ae77Skettenis future. 96b725ae77Skettenis 97b725ae77Skettenis bit 1: DEPRECATED_WARN_USER, the user needs to be warned that 98b725ae77Skettenis this is a deprecated command. The user should only be warned 99b725ae77Skettenis the first time a command is used. 100b725ae77Skettenis 101b725ae77Skettenis bit 2: MALLOCED_REPLACEMENT, when functions are deprecated at 102b725ae77Skettenis compile time (this is the way it should, in general, be done) 103b725ae77Skettenis the memory containing the replacement string is statically 104b725ae77Skettenis allocated. In some cases it makes sense to deprecate commands 105b725ae77Skettenis at runtime (the testsuite is one example). In this case the 106b725ae77Skettenis memory for replacement is malloc'ed. When a command is 107b725ae77Skettenis undeprecated or re-deprecated at runtime we don't want to risk 108b725ae77Skettenis calling free on statically allocated memory, so we check this 109b725ae77Skettenis flag. 110b725ae77Skettenis */ 111b725ae77Skettenis int flags; 112b725ae77Skettenis 113b725ae77Skettenis /* if this command is deprecated, this is the replacement name */ 114b725ae77Skettenis char *replacement; 115b725ae77Skettenis 116b725ae77Skettenis /* If this command represents a show command, then this function 117b725ae77Skettenis is called before the variable's value is examined. */ 118b725ae77Skettenis void (*pre_show_hook) (struct cmd_list_element *c); 119b725ae77Skettenis 120b725ae77Skettenis /* Hook for another command to be executed before this command. */ 121b725ae77Skettenis struct cmd_list_element *hook_pre; 122b725ae77Skettenis 123b725ae77Skettenis /* Hook for another command to be executed after this command. */ 124b725ae77Skettenis struct cmd_list_element *hook_post; 125b725ae77Skettenis 126b725ae77Skettenis /* Flag that specifies if this command is already running it's hook. */ 127b725ae77Skettenis /* Prevents the possibility of hook recursion. */ 128b725ae77Skettenis int hook_in; 129b725ae77Skettenis 130b725ae77Skettenis /* Nonzero identifies a prefix command. For them, the address 131b725ae77Skettenis of the variable containing the list of subcommands. */ 132b725ae77Skettenis struct cmd_list_element **prefixlist; 133b725ae77Skettenis 134b725ae77Skettenis /* For prefix commands only: 135b725ae77Skettenis String containing prefix commands to get here: this one 136b725ae77Skettenis plus any others needed to get to it. Should end in a space. 137b725ae77Skettenis It is used before the word "command" in describing the 138b725ae77Skettenis commands reached through this prefix. */ 139b725ae77Skettenis char *prefixname; 140b725ae77Skettenis 141b725ae77Skettenis /* For prefix commands only: 142b725ae77Skettenis nonzero means do not get an error if subcommand is not 143b725ae77Skettenis recognized; call the prefix's own function in that case. */ 144b725ae77Skettenis char allow_unknown; 145b725ae77Skettenis 146b725ae77Skettenis /* Nonzero says this is an abbreviation, and should not 147b725ae77Skettenis be mentioned in lists of commands. 148b725ae77Skettenis This allows "br<tab>" to complete to "break", which it 149b725ae77Skettenis otherwise wouldn't. */ 150b725ae77Skettenis char abbrev_flag; 151b725ae77Skettenis 152b725ae77Skettenis /* Completion routine for this command. TEXT is the text beyond 153b725ae77Skettenis what was matched for the command itself (leading whitespace is 154b725ae77Skettenis skipped). It stops where we are supposed to stop completing 155b725ae77Skettenis (rl_point) and is '\0' terminated. 156b725ae77Skettenis 157b725ae77Skettenis Return value is a malloc'd vector of pointers to possible completions 158b725ae77Skettenis terminated with NULL. If there are no completions, returning a pointer 159b725ae77Skettenis to a NULL would work but returning NULL itself is also valid. 160b725ae77Skettenis WORD points in the same buffer as TEXT, and completions should be 161b725ae77Skettenis returned relative to this position. For example, suppose TEXT is "foo" 162b725ae77Skettenis and we want to complete to "foobar". If WORD is "oo", return 163b725ae77Skettenis "oobar"; if WORD is "baz/foo", return "baz/foobar". */ 164b725ae77Skettenis char **(*completer) (char *text, char *word); 165b725ae77Skettenis 166b725ae77Skettenis /* Type of "set" or "show" command (or SET_NOT_SET if not "set" 167b725ae77Skettenis or "show"). */ 168b725ae77Skettenis cmd_types type; 169b725ae77Skettenis 170b725ae77Skettenis /* Pointer to variable affected by "set" and "show". Doesn't matter 171b725ae77Skettenis if type is not_set. */ 172b725ae77Skettenis void *var; 173b725ae77Skettenis 174b725ae77Skettenis /* What kind of variable is *VAR? */ 175b725ae77Skettenis var_types var_type; 176b725ae77Skettenis 177b725ae77Skettenis /* Pointer to NULL terminated list of enumerated values (like argv). */ 178b725ae77Skettenis const char **enums; 179b725ae77Skettenis 180b725ae77Skettenis /* Pointer to command strings of user-defined commands */ 181b725ae77Skettenis struct command_line *user_commands; 182b725ae77Skettenis 183b725ae77Skettenis /* Pointer to command that is hooked by this one, (by hook_pre) 184b725ae77Skettenis so the hook can be removed when this one is deleted. */ 185b725ae77Skettenis struct cmd_list_element *hookee_pre; 186b725ae77Skettenis 187b725ae77Skettenis /* Pointer to command that is hooked by this one, (by hook_post) 188b725ae77Skettenis so the hook can be removed when this one is deleted. */ 189b725ae77Skettenis struct cmd_list_element *hookee_post; 190b725ae77Skettenis 191b725ae77Skettenis /* Pointer to command that is aliased by this one, so the 192b725ae77Skettenis aliased command can be located in case it has been hooked. */ 193b725ae77Skettenis struct cmd_list_element *cmd_pointer; 194b725ae77Skettenis }; 195b725ae77Skettenis 196b725ae77Skettenis /* API to the manipulation of command lists. */ 197b725ae77Skettenis 198b725ae77Skettenis extern struct cmd_list_element *add_cmd (char *, enum command_class, 199b725ae77Skettenis void (*fun) (char *, int), char *, 200b725ae77Skettenis struct cmd_list_element **); 201b725ae77Skettenis 202b725ae77Skettenis extern struct cmd_list_element *add_alias_cmd (char *, char *, 203b725ae77Skettenis enum command_class, int, 204b725ae77Skettenis struct cmd_list_element **); 205b725ae77Skettenis 206b725ae77Skettenis extern struct cmd_list_element *add_prefix_cmd (char *, enum command_class, 207b725ae77Skettenis void (*fun) (char *, int), 208b725ae77Skettenis char *, 209b725ae77Skettenis struct cmd_list_element **, 210b725ae77Skettenis char *, int, 211b725ae77Skettenis struct cmd_list_element **); 212b725ae77Skettenis 213b725ae77Skettenis extern struct cmd_list_element *add_abbrev_prefix_cmd (char *, 214b725ae77Skettenis enum command_class, 215b725ae77Skettenis void (*fun) (char *, 216b725ae77Skettenis int), 217b725ae77Skettenis char *, 218b725ae77Skettenis struct cmd_list_element 219b725ae77Skettenis **, char *, int, 220b725ae77Skettenis struct cmd_list_element 221b725ae77Skettenis **); 222b725ae77Skettenis 223b725ae77Skettenis /* Set the commands corresponding callback. */ 224b725ae77Skettenis 225b725ae77Skettenis extern void set_cmd_cfunc (struct cmd_list_element *cmd, 226b725ae77Skettenis void (*cfunc) (char *args, int from_tty)); 227b725ae77Skettenis 228b725ae77Skettenis extern void set_cmd_sfunc (struct cmd_list_element *cmd, 229b725ae77Skettenis void (*sfunc) (char *args, int from_tty, 230b725ae77Skettenis struct cmd_list_element * c)); 231b725ae77Skettenis 232b725ae77Skettenis extern void set_cmd_completer (struct cmd_list_element *cmd, 233b725ae77Skettenis char **(*completer) (char *text, char *word)); 234b725ae77Skettenis 235b725ae77Skettenis /* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs 236b725ae77Skettenis around in cmd objects to test the value of the commands sfunc(). */ 237b725ae77Skettenis extern int cmd_cfunc_eq (struct cmd_list_element *cmd, 238b725ae77Skettenis void (*cfunc) (char *args, int from_tty)); 239b725ae77Skettenis 240b725ae77Skettenis /* Access to the command's local context. */ 241b725ae77Skettenis extern void set_cmd_context (struct cmd_list_element *cmd, void *context); 242b725ae77Skettenis extern void *get_cmd_context (struct cmd_list_element *cmd); 243b725ae77Skettenis 244b725ae77Skettenis extern struct cmd_list_element *lookup_cmd (char **, 245b725ae77Skettenis struct cmd_list_element *, char *, 246b725ae77Skettenis int, int); 247b725ae77Skettenis 248b725ae77Skettenis extern struct cmd_list_element *lookup_cmd_1 (char **, 249b725ae77Skettenis struct cmd_list_element *, 250b725ae77Skettenis struct cmd_list_element **, 251b725ae77Skettenis int); 252b725ae77Skettenis 253b725ae77Skettenis extern struct cmd_list_element * 254b725ae77Skettenis deprecate_cmd (struct cmd_list_element *, char * ); 255b725ae77Skettenis 256b725ae77Skettenis extern void 257b725ae77Skettenis deprecated_cmd_warning (char **); 258b725ae77Skettenis 259b725ae77Skettenis extern int 260b725ae77Skettenis lookup_cmd_composition (char *text, 261b725ae77Skettenis struct cmd_list_element **alias, 262b725ae77Skettenis struct cmd_list_element **prefix_cmd, 263b725ae77Skettenis struct cmd_list_element **cmd); 264b725ae77Skettenis 265b725ae77Skettenis extern struct cmd_list_element *add_com (char *, enum command_class, 266b725ae77Skettenis void (*fun) (char *, int), char *); 267b725ae77Skettenis 268b725ae77Skettenis extern struct cmd_list_element *add_com_alias (char *, char *, 269b725ae77Skettenis enum command_class, int); 270b725ae77Skettenis 271b725ae77Skettenis extern struct cmd_list_element *add_info (char *, void (*fun) (char *, int), 272b725ae77Skettenis char *); 273b725ae77Skettenis 274b725ae77Skettenis extern struct cmd_list_element *add_info_alias (char *, char *, int); 275b725ae77Skettenis 276b725ae77Skettenis extern char **complete_on_cmdlist (struct cmd_list_element *, char *, char *); 277b725ae77Skettenis 278b725ae77Skettenis extern char **complete_on_enum (const char *enumlist[], char *, char *); 279b725ae77Skettenis 280b725ae77Skettenis extern void delete_cmd (char *, struct cmd_list_element **); 281b725ae77Skettenis 282b725ae77Skettenis extern void help_cmd_list (struct cmd_list_element *, enum command_class, 283b725ae77Skettenis char *, int, struct ui_file *); 284b725ae77Skettenis 285b725ae77Skettenis extern struct cmd_list_element *add_set_cmd (char *name, enum 286b725ae77Skettenis command_class class, 287b725ae77Skettenis var_types var_type, void *var, 288b725ae77Skettenis char *doc, 289b725ae77Skettenis struct cmd_list_element **list); 290b725ae77Skettenis 291b725ae77Skettenis extern struct cmd_list_element *add_set_enum_cmd (char *name, 292b725ae77Skettenis enum command_class class, 293b725ae77Skettenis const char *enumlist[], 294b725ae77Skettenis const char **var, 295b725ae77Skettenis char *doc, 296b725ae77Skettenis struct cmd_list_element **list); 297b725ae77Skettenis 298*11efff7fSkettenis extern struct cmd_list_element *deprecated_add_show_from_set (struct cmd_list_element *, 299*11efff7fSkettenis struct cmd_list_element **); 300b725ae77Skettenis 301b725ae77Skettenis /* Functions that implement commands about CLI commands. */ 302b725ae77Skettenis 303b725ae77Skettenis extern void help_cmd (char *, struct ui_file *); 304b725ae77Skettenis 305b725ae77Skettenis extern void help_list (struct cmd_list_element *, char *, 306b725ae77Skettenis enum command_class, struct ui_file *); 307b725ae77Skettenis 308b725ae77Skettenis extern void apropos_cmd (struct ui_file *, struct cmd_list_element *, 309b725ae77Skettenis struct re_pattern_buffer *, char *); 310b725ae77Skettenis 311b725ae77Skettenis /* Used to mark commands that don't do anything. If we just leave the 312b725ae77Skettenis function field NULL, the command is interpreted as a help topic, or 313b725ae77Skettenis as a class of commands. */ 314b725ae77Skettenis 315b725ae77Skettenis extern void not_just_help_class_command (char *arg, int from_tty); 316b725ae77Skettenis 317b725ae77Skettenis /* Exported to cli/cli-setshow.c */ 318b725ae77Skettenis 319b725ae77Skettenis extern void print_doc_line (struct ui_file *, char *); 320b725ae77Skettenis 321b725ae77Skettenis 322b725ae77Skettenis #endif /* !defined (CLI_DECODE_H) */ 323