⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cli-decode.c

📁 gdb-6.0 linux 下的调试工具
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Handle lists of commands, their decoding and documentation, for GDB.   Copyright 1986, 1989, 1990, 1991, 1998, 2000, 2001, 2002 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"#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){  register 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;  register struct cmd_list_element *old;  register 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){  register 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){  register 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 and SHOW_DOC are the documentation strings.   SET_RESULT and SHOW_RESULT, if not NULL, are set to the resulting   command structures.  */voidadd_setshow_cmd_full (char *name,		      enum command_class class,		      var_types var_type, void *var,		      char *set_doc, char *show_doc,		      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;  set = add_set_or_show_cmd (name, set_cmd, class, var_type, var,			     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,			      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;}/* 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 and SHOW_DOC are the documentation strings.  */voidadd_setshow_cmd (char *name,		 enum command_class class,		 var_types var_type, void *var,		 char *set_doc, char *show_doc,		 cmd_sfunc_ftype *set_func, cmd_sfunc_ftype *show_func,		 struct cmd_list_element **set_list,		 struct cmd_list_element **show_list){  add_setshow_cmd_full (name, class, var_type, var, set_doc, show_doc,			set_func, show_func, set_list, show_list,			NULL, NULL);}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;}/* Add an auto-boolean command named NAME to both the set and show   command list lists.  CLASS is as in add_cmd.  VAR is address of the   variable which will contain the value.  DOC is the documentation   string.  FUNC is the corresponding callback.  */voidadd_setshow_auto_boolean_cmd (char *name,			      enum command_class class,			      enum auto_boolean *var,			      char *set_doc, char *show_doc,			      cmd_sfunc_ftype *set_func,			      cmd_sfunc_ftype *show_func,			      struct cmd_list_element **set_list,			      struct cmd_list_element **show_list){  static const char *auto_boolean_enums[] = { "on", "off", "auto", NULL };  struct cmd_list_element *c;  add_setshow_cmd_full (name, class, var_auto_boolean, var,			set_doc, show_doc, set_func, show_func,			set_list, show_list,			&c, NULL);  c->enums = auto_boolean_enums;}/* Add element named NAME to both the set and show command LISTs (the   list for set/show or some sublist thereof).  CLASS is as in   add_cmd.  VAR is address of the variable which will contain the   value.  SET_DOC and SHOW_DOR are the documentation strings.  */voidadd_setshow_boolean_cmd (char *name,			 enum command_class class,			 int *var, char *set_doc, char *show_doc,			 cmd_sfunc_ftype *set_func,			 cmd_sfunc_ftype *show_func,			 struct cmd_list_element **set_list,			 struct cmd_list_element **show_list){  static const char *boolean_enums[] = { "on", "off", NULL };  struct cmd_list_element *c;  add_setshow_cmd_full (name, class, var_boolean, var,			set_doc, show_doc,			set_func, show_func,			set_list, show_list,			&c, NULL);  c->enums = boolean_enums;}/* Add element named NAME to both the set and show command LISTs (the   list for set/show or some sublist thereof).  CLASS is as in   add_cmd.  VAR is address of the variable which will contain the   value.  SET_DOC and SHOW_DOR are the documentation strings.  */voidadd_setshow_uinteger_cmd (char *name,			  enum command_class class,			  unsigned int *var, char *set_doc, char *show_doc,			  cmd_sfunc_ftype *set_func,			  cmd_sfunc_ftype *show_func,			  struct cmd_list_element **set_list,			  struct cmd_list_element **show_list){  add_setshow_cmd_full (name, class, var_uinteger, var,			set_doc, show_doc,			set_func, show_func,			set_list, show_list,			NULL, NULL);}/* Where SETCMD has already been added, add the corresponding show   command to LIST and return a pointer to the added command (not   necessarily the head of LIST).  *//* NOTE: cagney/2002-03-17: The original version of add_show_from_set   used memcpy() to clone `set' into `show'.  This meant that in   addition to all the needed fields (var, name, et.al.) some   unnecessary fields were copied (namely the callback function).  The   function explictly copies relevant fields.  For a `set' and `show'   command to share the same callback, the caller must set both   explicitly.  */struct cmd_list_element *add_show_from_set (struct cmd_list_element *setcmd,		   struct cmd_list_element **list){  char *doc;  const static char setstring[] = "Set ";  /* Create a doc string by replacing "Set " at the start of the     `set'' command's doco with "Show ".  */  gdb_assert (strncmp (setcmd->doc, setstring, sizeof (setstring) - 1) == 0);  doc = concat ("Show ", setcmd->doc + sizeof (setstring) - 1, NULL);  /* Insert the basic command.  */  return add_set_or_show_cmd (setcmd->name, show_cmd, setcmd->class,			      setcmd->var_type, setcmd->var, doc, list);}/* Remove the command named NAME from the command list.  */voiddelete_cmd (char *name, struct cmd_list_element **list){  register struct cmd_list_element *c;  struct cmd_list_element *p;  while (*list && STREQ ((*list)->name, name))    {      if ((*list)->hookee_pre)      (*list)->hookee_pre->hook_pre = 0;   /* Hook slips out of its mouth */      if ((*list)->hookee_post)      (*list)->hookee_post->hook_post = 0; /* Hook slips out of its bottom  */      p = (*list)->next;      xfree (* list);      *list = p;    }

⌨️ 快捷键说明

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