198944Sobrien/* Header file for GDB command decoding library. 298944Sobrien 3130803Smarcel Copyright 2000, 2003 Free Software Foundation, Inc. 4130803Smarcel 598944Sobrien This program is free software; you can redistribute it and/or modify 698944Sobrien it under the terms of the GNU General Public License as published by 798944Sobrien the Free Software Foundation; either version 2 of the License, or 898944Sobrien (at your option) any later version. 998944Sobrien 1098944Sobrien This program is distributed in the hope that it will be useful, 1198944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1298944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1398944Sobrien GNU General Public License for more details. 1498944Sobrien 1598944Sobrien You should have received a copy of the GNU General Public License 1698944Sobrien along with this program; if not, write to the Free Software 1798944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 1898944Sobrien Boston, MA 02111-1307, USA. */ 1998944Sobrien 2098944Sobrien#if !defined (CLI_DECODE_H) 2198944Sobrien#define CLI_DECODE_H 1 2298944Sobrien 23130803Smarcel#include "command.h" 2498944Sobrien 25130803Smarcelstruct re_pattern_buffer; 2698944Sobrien 27130803Smarcel#if 0 28130803Smarcel/* FIXME: cagney/2002-03-17: Once cmd_type() has been removed, ``enum 29130803Smarcel cmd_types'' can be moved from "command.h" to "cli-decode.h". */ 3098944Sobrien/* Not a set/show command. Note that some commands which begin with 3198944Sobrien "set" or "show" might be in this category, if their syntax does 3298944Sobrien not fall into one of the following categories. */ 3398944Sobrientypedef enum cmd_types 3498944Sobrien { 3598944Sobrien not_set_cmd, 3698944Sobrien set_cmd, 3798944Sobrien show_cmd 3898944Sobrien } 3998944Sobriencmd_types; 40130803Smarcel#endif 4198944Sobrien 4298944Sobrien/* This structure records one command'd definition. */ 4398944Sobrien 4498944Sobrien 4598944Sobrien/* This flag is used by the code executing commands to warn the user 4698944Sobrien the first time a deprecated command is used, see the 'flags' field in 4798944Sobrien the following struct. 4898944Sobrien*/ 4998944Sobrien#define CMD_DEPRECATED 0x1 5098944Sobrien#define DEPRECATED_WARN_USER 0x2 5198944Sobrien#define MALLOCED_REPLACEMENT 0x4 5298944Sobrien 5398944Sobrienstruct cmd_list_element 5498944Sobrien { 5598944Sobrien /* Points to next command in this list. */ 5698944Sobrien struct cmd_list_element *next; 5798944Sobrien 5898944Sobrien /* Name of this command. */ 5998944Sobrien char *name; 6098944Sobrien 6198944Sobrien /* Command class; class values are chosen by application program. */ 6298944Sobrien enum command_class class; 6398944Sobrien 6498944Sobrien /* Function definition of this command. NULL for command class 6598944Sobrien names and for help topics that are not really commands. NOTE: 6698944Sobrien cagney/2002-02-02: This function signature is evolving. For 6798944Sobrien the moment suggest sticking with either set_cmd_cfunc() or 6898944Sobrien set_cmd_sfunc(). */ 6998944Sobrien void (*func) (struct cmd_list_element *c, char *args, int from_tty); 7098944Sobrien /* The command's real callback. At present func() bounces through 7198944Sobrien to one of the below. */ 7298944Sobrien union 7398944Sobrien { 74130803Smarcel /* If type is not_set_cmd, call it like this: */ 75130803Smarcel cmd_cfunc_ftype *cfunc; 76130803Smarcel /* If type is set_cmd or show_cmd, first set the variables, 77130803Smarcel and then call this: */ 78130803Smarcel cmd_sfunc_ftype *sfunc; 7998944Sobrien } 8098944Sobrien function; 8198944Sobrien 82130803Smarcel /* Local state (context) for this command. This can be anything. */ 83130803Smarcel void *context; 84130803Smarcel 8598944Sobrien /* Documentation of this command (or help topic). 8698944Sobrien First line is brief documentation; remaining lines form, with it, 8798944Sobrien the full documentation. First line should end with a period. 8898944Sobrien Entire string should also end with a period, not a newline. */ 8998944Sobrien char *doc; 9098944Sobrien 9198944Sobrien /* flags : a bitfield 9298944Sobrien 9398944Sobrien bit 0: (LSB) CMD_DEPRECATED, when 1 indicated that this command 9498944Sobrien is deprecated. It may be removed from gdb's command set in the 9598944Sobrien future. 9698944Sobrien 9798944Sobrien bit 1: DEPRECATED_WARN_USER, the user needs to be warned that 9898944Sobrien this is a deprecated command. The user should only be warned 9998944Sobrien the first time a command is used. 10098944Sobrien 10198944Sobrien bit 2: MALLOCED_REPLACEMENT, when functions are deprecated at 10298944Sobrien compile time (this is the way it should, in general, be done) 10398944Sobrien the memory containing the replacement string is statically 10498944Sobrien allocated. In some cases it makes sense to deprecate commands 10598944Sobrien at runtime (the testsuite is one example). In this case the 10698944Sobrien memory for replacement is malloc'ed. When a command is 10798944Sobrien undeprecated or re-deprecated at runtime we don't want to risk 10898944Sobrien calling free on statically allocated memory, so we check this 10998944Sobrien flag. 11098944Sobrien */ 11198944Sobrien int flags; 11298944Sobrien 11398944Sobrien /* if this command is deprecated, this is the replacement name */ 11498944Sobrien char *replacement; 11598944Sobrien 11698944Sobrien /* If this command represents a show command, then this function 11798944Sobrien is called before the variable's value is examined. */ 11898944Sobrien void (*pre_show_hook) (struct cmd_list_element *c); 11998944Sobrien 12098944Sobrien /* Hook for another command to be executed before this command. */ 12198944Sobrien struct cmd_list_element *hook_pre; 12298944Sobrien 12398944Sobrien /* Hook for another command to be executed after this command. */ 12498944Sobrien struct cmd_list_element *hook_post; 12598944Sobrien 12698944Sobrien /* Flag that specifies if this command is already running it's hook. */ 12798944Sobrien /* Prevents the possibility of hook recursion. */ 12898944Sobrien int hook_in; 12998944Sobrien 13098944Sobrien /* Nonzero identifies a prefix command. For them, the address 13198944Sobrien of the variable containing the list of subcommands. */ 13298944Sobrien struct cmd_list_element **prefixlist; 13398944Sobrien 13498944Sobrien /* For prefix commands only: 13598944Sobrien String containing prefix commands to get here: this one 13698944Sobrien plus any others needed to get to it. Should end in a space. 13798944Sobrien It is used before the word "command" in describing the 13898944Sobrien commands reached through this prefix. */ 13998944Sobrien char *prefixname; 14098944Sobrien 14198944Sobrien /* For prefix commands only: 14298944Sobrien nonzero means do not get an error if subcommand is not 14398944Sobrien recognized; call the prefix's own function in that case. */ 14498944Sobrien char allow_unknown; 14598944Sobrien 14698944Sobrien /* Nonzero says this is an abbreviation, and should not 14798944Sobrien be mentioned in lists of commands. 14898944Sobrien This allows "br<tab>" to complete to "break", which it 14998944Sobrien otherwise wouldn't. */ 15098944Sobrien char abbrev_flag; 15198944Sobrien 15298944Sobrien /* Completion routine for this command. TEXT is the text beyond 15398944Sobrien what was matched for the command itself (leading whitespace is 15498944Sobrien skipped). It stops where we are supposed to stop completing 15598944Sobrien (rl_point) and is '\0' terminated. 15698944Sobrien 15798944Sobrien Return value is a malloc'd vector of pointers to possible completions 15898944Sobrien terminated with NULL. If there are no completions, returning a pointer 15998944Sobrien to a NULL would work but returning NULL itself is also valid. 16098944Sobrien WORD points in the same buffer as TEXT, and completions should be 16198944Sobrien returned relative to this position. For example, suppose TEXT is "foo" 16298944Sobrien and we want to complete to "foobar". If WORD is "oo", return 16398944Sobrien "oobar"; if WORD is "baz/foo", return "baz/foobar". */ 16498944Sobrien char **(*completer) (char *text, char *word); 16598944Sobrien 16698944Sobrien /* Type of "set" or "show" command (or SET_NOT_SET if not "set" 16798944Sobrien or "show"). */ 16898944Sobrien cmd_types type; 16998944Sobrien 17098944Sobrien /* Pointer to variable affected by "set" and "show". Doesn't matter 17198944Sobrien if type is not_set. */ 17298944Sobrien void *var; 17398944Sobrien 17498944Sobrien /* What kind of variable is *VAR? */ 17598944Sobrien var_types var_type; 17698944Sobrien 17798944Sobrien /* Pointer to NULL terminated list of enumerated values (like argv). */ 17898944Sobrien const char **enums; 17998944Sobrien 18098944Sobrien /* Pointer to command strings of user-defined commands */ 18198944Sobrien struct command_line *user_commands; 18298944Sobrien 18398944Sobrien /* Pointer to command that is hooked by this one, (by hook_pre) 18498944Sobrien so the hook can be removed when this one is deleted. */ 18598944Sobrien struct cmd_list_element *hookee_pre; 18698944Sobrien 18798944Sobrien /* Pointer to command that is hooked by this one, (by hook_post) 18898944Sobrien so the hook can be removed when this one is deleted. */ 18998944Sobrien struct cmd_list_element *hookee_post; 19098944Sobrien 19198944Sobrien /* Pointer to command that is aliased by this one, so the 19298944Sobrien aliased command can be located in case it has been hooked. */ 19398944Sobrien struct cmd_list_element *cmd_pointer; 19498944Sobrien }; 19598944Sobrien 19698944Sobrien/* API to the manipulation of command lists. */ 19798944Sobrien 19898944Sobrienextern struct cmd_list_element *add_cmd (char *, enum command_class, 19998944Sobrien void (*fun) (char *, int), char *, 20098944Sobrien struct cmd_list_element **); 20198944Sobrien 20298944Sobrienextern struct cmd_list_element *add_alias_cmd (char *, char *, 20398944Sobrien enum command_class, int, 20498944Sobrien struct cmd_list_element **); 20598944Sobrien 20698944Sobrienextern struct cmd_list_element *add_prefix_cmd (char *, enum command_class, 20798944Sobrien void (*fun) (char *, int), 20898944Sobrien char *, 20998944Sobrien struct cmd_list_element **, 21098944Sobrien char *, int, 21198944Sobrien struct cmd_list_element **); 21298944Sobrien 21398944Sobrienextern struct cmd_list_element *add_abbrev_prefix_cmd (char *, 21498944Sobrien enum command_class, 21598944Sobrien void (*fun) (char *, 21698944Sobrien int), 21798944Sobrien char *, 21898944Sobrien struct cmd_list_element 21998944Sobrien **, char *, int, 22098944Sobrien struct cmd_list_element 22198944Sobrien **); 22298944Sobrien 22398944Sobrien/* Set the commands corresponding callback. */ 22498944Sobrien 22598944Sobrienextern void set_cmd_cfunc (struct cmd_list_element *cmd, 22698944Sobrien void (*cfunc) (char *args, int from_tty)); 22798944Sobrien 22898944Sobrienextern void set_cmd_sfunc (struct cmd_list_element *cmd, 22998944Sobrien void (*sfunc) (char *args, int from_tty, 23098944Sobrien struct cmd_list_element * c)); 23198944Sobrien 232130803Smarcelextern void set_cmd_completer (struct cmd_list_element *cmd, 233130803Smarcel char **(*completer) (char *text, char *word)); 234130803Smarcel 23598944Sobrien/* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs 23698944Sobrien around in cmd objects to test the value of the commands sfunc(). */ 23798944Sobrienextern int cmd_cfunc_eq (struct cmd_list_element *cmd, 23898944Sobrien void (*cfunc) (char *args, int from_tty)); 23998944Sobrien 240130803Smarcel/* Access to the command's local context. */ 241130803Smarcelextern void set_cmd_context (struct cmd_list_element *cmd, void *context); 242130803Smarcelextern void *get_cmd_context (struct cmd_list_element *cmd); 243130803Smarcel 24498944Sobrienextern struct cmd_list_element *lookup_cmd (char **, 24598944Sobrien struct cmd_list_element *, char *, 24698944Sobrien int, int); 24798944Sobrien 24898944Sobrienextern struct cmd_list_element *lookup_cmd_1 (char **, 24998944Sobrien struct cmd_list_element *, 25098944Sobrien struct cmd_list_element **, 25198944Sobrien int); 25298944Sobrien 25398944Sobrienextern struct cmd_list_element * 25498944Sobrien deprecate_cmd (struct cmd_list_element *, char * ); 25598944Sobrien 25698944Sobrienextern void 25798944Sobrien deprecated_cmd_warning (char **); 25898944Sobrien 25998944Sobrienextern int 26098944Sobrien lookup_cmd_composition (char *text, 26198944Sobrien struct cmd_list_element **alias, 26298944Sobrien struct cmd_list_element **prefix_cmd, 26398944Sobrien struct cmd_list_element **cmd); 26498944Sobrien 26598944Sobrienextern struct cmd_list_element *add_com (char *, enum command_class, 26698944Sobrien void (*fun) (char *, int), char *); 26798944Sobrien 26898944Sobrienextern struct cmd_list_element *add_com_alias (char *, char *, 26998944Sobrien enum command_class, int); 27098944Sobrien 27198944Sobrienextern struct cmd_list_element *add_info (char *, void (*fun) (char *, int), 27298944Sobrien char *); 27398944Sobrien 27498944Sobrienextern struct cmd_list_element *add_info_alias (char *, char *, int); 27598944Sobrien 27698944Sobrienextern char **complete_on_cmdlist (struct cmd_list_element *, char *, char *); 27798944Sobrien 27898944Sobrienextern char **complete_on_enum (const char *enumlist[], char *, char *); 27998944Sobrien 28098944Sobrienextern void delete_cmd (char *, struct cmd_list_element **); 28198944Sobrien 28298944Sobrienextern void help_cmd_list (struct cmd_list_element *, enum command_class, 28398944Sobrien char *, int, struct ui_file *); 28498944Sobrien 28598944Sobrienextern struct cmd_list_element *add_set_cmd (char *name, enum 28698944Sobrien command_class class, 28798944Sobrien var_types var_type, void *var, 28898944Sobrien char *doc, 28998944Sobrien struct cmd_list_element **list); 29098944Sobrien 29198944Sobrienextern struct cmd_list_element *add_set_enum_cmd (char *name, 29298944Sobrien enum command_class class, 29398944Sobrien const char *enumlist[], 29498944Sobrien const char **var, 29598944Sobrien char *doc, 29698944Sobrien struct cmd_list_element **list); 29798944Sobrien 29898944Sobrienextern struct cmd_list_element *add_show_from_set (struct cmd_list_element *, 29998944Sobrien struct cmd_list_element 30098944Sobrien **); 30198944Sobrien 30298944Sobrien/* Functions that implement commands about CLI commands. */ 30398944Sobrien 30498944Sobrienextern void help_cmd (char *, struct ui_file *); 30598944Sobrien 30698944Sobrienextern void help_list (struct cmd_list_element *, char *, 30798944Sobrien enum command_class, struct ui_file *); 30898944Sobrien 30998944Sobrienextern void apropos_cmd (struct ui_file *, struct cmd_list_element *, 31098944Sobrien struct re_pattern_buffer *, char *); 31198944Sobrien 31298944Sobrien/* Used to mark commands that don't do anything. If we just leave the 31398944Sobrien function field NULL, the command is interpreted as a help topic, or 31498944Sobrien as a class of commands. */ 31598944Sobrien 31698944Sobrienextern void not_just_help_class_command (char *arg, int from_tty); 31798944Sobrien 31898944Sobrien/* Exported to cli/cli-setshow.c */ 31998944Sobrien 32098944Sobrienextern void print_doc_line (struct ui_file *, char *); 32198944Sobrien 32298944Sobrien 32398944Sobrien#endif /* !defined (CLI_DECODE_H) */ 324