cli-decode.c

来自「这个是LINUX下的GDB调度工具的源码」· C语言 代码 · 共 1,605 行 · 第 1/4 页

C
1,605
字号
/* Handle lists of commands, their decoding and documentation, for GDB.   Copyright 1986, 1989, 1990, 1991, 1998, 2000, 2001, 2002, 2004 Free   Software Foundation, Inc.   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place - Suite 330,   Boston, MA 02111-1307, USA.  */#include "defs.h"#include "symtab.h"#include <ctype.h>#include "gdb_regex.h"#include "gdb_string.h"#include "ui-out.h"#include "cli/cli-cmds.h"#include "cli/cli-decode.h"#ifdef TUI#include "tui/tui.h"		/* For tui_active et.al.   */#endif#include "gdb_assert.h"/* Prototypes for local functions */static void undef_cmd_error (char *, char *);static struct cmd_list_element *find_cmd (char *command,					  int len,					  struct cmd_list_element *clist,					  int ignore_help_classes,					  int *nfound);static void help_all (struct ui_file *stream);/* Set the callback function for the specified command.  For each both   the commands callback and func() are set.  The latter set to a   bounce function (unless cfunc / sfunc is NULL that is).  */static voiddo_cfunc (struct cmd_list_element *c, char *args, int from_tty){  c->function.cfunc (args, from_tty); /* Ok.  */}voidset_cmd_cfunc (struct cmd_list_element *cmd, cmd_cfunc_ftype *cfunc){  if (cfunc == NULL)    cmd->func = NULL;  else    cmd->func = do_cfunc;  cmd->function.cfunc = cfunc; /* Ok.  */}static voiddo_sfunc (struct cmd_list_element *c, char *args, int from_tty){  c->function.sfunc (args, from_tty, c); /* Ok.  */}voidset_cmd_sfunc (struct cmd_list_element *cmd, cmd_sfunc_ftype *sfunc){  if (sfunc == NULL)    cmd->func = NULL;  else    cmd->func = do_sfunc;  cmd->function.sfunc = sfunc; /* Ok.  */}intcmd_cfunc_eq (struct cmd_list_element *cmd,	      void (*cfunc) (char *args, int from_tty)){  return cmd->func == do_cfunc && cmd->function.cfunc == cfunc;}voidset_cmd_context (struct cmd_list_element *cmd, void *context){  cmd->context = context;}void *get_cmd_context (struct cmd_list_element *cmd){  return cmd->context;}enum cmd_typescmd_type (struct cmd_list_element *cmd){  return cmd->type;}voidset_cmd_completer (struct cmd_list_element *cmd,		   char **(*completer) (char *text, char *word)){  cmd->completer = completer; /* Ok.  */}/* Add element named NAME.   CLASS is the top level category into which commands are broken down   for "help" purposes.   FUN should be the function to execute the command;   it will get a character string as argument, with leading   and trailing blanks already eliminated.   DOC is a documentation string for the command.   Its first line should be a complete sentence.   It should start with ? for a command that is an abbreviation   or with * for a command that most users don't need to know about.   Add this command to command list *LIST.     Returns a pointer to the added command (not necessarily the head    of *LIST). */struct cmd_list_element *add_cmd (char *name, enum command_class class, void (*fun) (char *, int),	 char *doc, struct cmd_list_element **list){  struct cmd_list_element *c  = (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));  struct cmd_list_element *p;  delete_cmd (name, list);  if (*list == NULL || strcmp ((*list)->name, name) >= 0)    {      c->next = *list;      *list = c;    }  else    {      p = *list;      while (p->next && strcmp (p->next->name, name) <= 0)	{	  p = p->next;	}      c->next = p->next;      p->next = c;    }  c->name = name;  c->class = class;  set_cmd_cfunc (c, fun);  set_cmd_context (c, NULL);  c->doc = doc;  c->flags = 0;  c->replacement = NULL;  c->pre_show_hook = NULL;  c->hook_pre  = NULL;  c->hook_post = NULL;  c->hook_in = 0;  c->prefixlist = NULL;  c->prefixname = NULL;  c->allow_unknown = 0;  c->abbrev_flag = 0;  set_cmd_completer (c, make_symbol_completion_list);  c->type = not_set_cmd;  c->var = NULL;  c->var_type = var_boolean;  c->enums = NULL;  c->user_commands = NULL;  c->hookee_pre = NULL;  c->hookee_post = NULL;  c->cmd_pointer = NULL;  return c;}/* Deprecates a command CMD.   REPLACEMENT is the name of the command which should be used in place   of this command, or NULL if no such command exists.   This function does not check to see if command REPLACEMENT exists   since gdb may not have gotten around to adding REPLACEMENT when this   function is called.   Returns a pointer to the deprecated command.  */struct cmd_list_element *deprecate_cmd (struct cmd_list_element *cmd, char *replacement){  cmd->flags |= (CMD_DEPRECATED | DEPRECATED_WARN_USER);  if (replacement != NULL)    cmd->replacement = replacement;  else    cmd->replacement = NULL;  return cmd;}struct cmd_list_element *add_alias_cmd (char *name, char *oldname, enum command_class class,	       int abbrev_flag, struct cmd_list_element **list){  /* Must do this since lookup_cmd tries to side-effect its first arg */  char *copied_name;  struct cmd_list_element *old;  struct cmd_list_element *c;  copied_name = (char *) alloca (strlen (oldname) + 1);  strcpy (copied_name, oldname);  old = lookup_cmd (&copied_name, *list, "", 1, 1);  if (old == 0)    {      delete_cmd (name, list);      return 0;    }  c = add_cmd (name, class, NULL, old->doc, list);  /* NOTE: Both FUNC and all the FUNCTIONs need to be copied.  */  c->func = old->func;  c->function = old->function;  c->prefixlist = old->prefixlist;  c->prefixname = old->prefixname;  c->allow_unknown = old->allow_unknown;  c->abbrev_flag = abbrev_flag;  c->cmd_pointer = old;  return c;}/* Like add_cmd but adds an element for a command prefix:   a name that should be followed by a subcommand to be looked up   in another command list.  PREFIXLIST should be the address   of the variable containing that list.  */struct cmd_list_element *add_prefix_cmd (char *name, enum command_class class, void (*fun) (char *, int),		char *doc, struct cmd_list_element **prefixlist,		char *prefixname, int allow_unknown,		struct cmd_list_element **list){  struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);  c->prefixlist = prefixlist;  c->prefixname = prefixname;  c->allow_unknown = allow_unknown;  return c;}/* Like add_prefix_cmd but sets the abbrev_flag on the new command. */struct cmd_list_element *add_abbrev_prefix_cmd (char *name, enum command_class class,		       void (*fun) (char *, int), char *doc,		       struct cmd_list_element **prefixlist, char *prefixname,		       int allow_unknown, struct cmd_list_element **list){  struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);  c->prefixlist = prefixlist;  c->prefixname = prefixname;  c->allow_unknown = allow_unknown;  c->abbrev_flag = 1;  return c;}/* This is an empty "cfunc".  */voidnot_just_help_class_command (char *args, int from_tty){}/* This is an empty "sfunc".  */static void empty_sfunc (char *, int, struct cmd_list_element *);static voidempty_sfunc (char *args, int from_tty, struct cmd_list_element *c){}/* Add element named NAME to command list LIST (the list for set/show   or some sublist thereof).   TYPE is set_cmd or show_cmd.   CLASS is as in add_cmd.   VAR_TYPE is the kind of thing we are setting.   VAR is address of the variable being controlled by this command.   DOC is the documentation string.  */static struct cmd_list_element *add_set_or_show_cmd (char *name,		     enum cmd_types type,		     enum command_class class,		     var_types var_type,		     void *var,		     char *doc,		     struct cmd_list_element **list){  struct cmd_list_element *c = add_cmd (name, class, NULL, doc, list);  gdb_assert (type == set_cmd || type == show_cmd);  c->type = type;  c->var_type = var_type;  c->var = var;  /* This needs to be something besides NULL so that this isn't     treated as a help class.  */  set_cmd_sfunc (c, empty_sfunc);  return c;}/* Add element named NAME to both the command SET_LIST and SHOW_LIST.   CLASS is as in add_cmd.  VAR_TYPE is the kind of thing we are   setting.  VAR is address of the variable being controlled by this   command.  SET_FUNC and SHOW_FUNC are the callback functions (if   non-NULL).  SET_DOC, SHOW_DOC and HELP_DOC are the documentation   strings.  PRINT the format string to print the value.  SET_RESULT   and SHOW_RESULT, if not NULL, are set to the resulting command   structures.  */static voidadd_setshow_cmd_full (char *name,		      enum command_class class,		      var_types var_type, void *var,		      const char *set_doc, const char *show_doc,		      const char *help_doc, const char *print,		      cmd_sfunc_ftype *set_func,		      cmd_sfunc_ftype *show_func,		      struct cmd_list_element **set_list,		      struct cmd_list_element **show_list,		      struct cmd_list_element **set_result,		      struct cmd_list_element **show_result){  struct cmd_list_element *set;  struct cmd_list_element *show;  char *full_set_doc;  char *full_show_doc;  if (help_doc != NULL)    {      full_set_doc = xstrprintf ("%s\n%s", set_doc, help_doc);      full_show_doc = xstrprintf ("%s\n%s", show_doc, help_doc);    }  else    {      full_set_doc = xstrdup (set_doc);      full_show_doc = xstrdup (show_doc);    }  set = add_set_or_show_cmd (name, set_cmd, class, var_type, var,			     full_set_doc, set_list);  if (set_func != NULL)    set_cmd_sfunc (set, set_func);  show = add_set_or_show_cmd (name, show_cmd, class, var_type, var,			      full_show_doc, show_list);  if (show_func != NULL)    set_cmd_sfunc (show, show_func);  if (set_result != NULL)    *set_result = set;  if (show_result != NULL)    *show_result = show;}struct cmd_list_element *add_set_cmd (char *name,	     enum command_class class,	     var_types var_type,	     void *var,	     char *doc,	     struct cmd_list_element **list){  return add_set_or_show_cmd (name, set_cmd, class, var_type, var, doc, list);}/* Add element named NAME to command list LIST (the list for set   or some sublist thereof).   CLASS is as in add_cmd.   ENUMLIST is a list of strings which may follow NAME.   VAR is address of the variable which will contain the matching string   (from ENUMLIST).   DOC is the documentation string.  */struct cmd_list_element *add_set_enum_cmd (char *name,		  enum command_class class,		  const char *enumlist[],		  const char **var,		  char *doc,		  struct cmd_list_element **list){  struct cmd_list_element *c  = add_set_cmd (name, class, var_enum, var, doc, list);  c->enums = enumlist;  return c;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?