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

📄 sim-options.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Simulator option handling.   Copyright (C) 1996, 1997 Free Software Foundation, Inc.   Contributed by Cygnus Support.This file is part of GDB, the GNU debugger.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, 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 ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public License alongwith this program; if not, write to the Free Software Foundation, Inc.,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */#include "sim-main.h"#ifdef HAVE_STRING_H#include <string.h>#else#ifdef HAVE_STRINGS_H#include <strings.h>#endif#endif#ifdef HAVE_STDLIB_H#include <stdlib.h>#endif#include <ctype.h>#include "libiberty.h"#include "sim-options.h"#include "sim-io.h"#include "sim-assert.h"#include "bfd.h"/* Add a set of options to the simulator.   TABLE is an array of OPTIONS terminated by a NULL `opt.name' entry.   This is intended to be called by modules in their `install' handler.  */SIM_RCsim_add_option_table (SIM_DESC sd, sim_cpu *cpu, const OPTION *table){  struct option_list *ol = ((struct option_list *)			    xmalloc (sizeof (struct option_list)));  /* Note: The list is constructed in the reverse order we're called so     later calls will override earlier ones (in case that ever happens).     This is the intended behaviour.  */  if (cpu)    {      ol->next = CPU_OPTIONS (cpu);      ol->options = table;      CPU_OPTIONS (cpu) = ol;    }  else    {      ol->next = STATE_OPTIONS (sd);      ol->options = table;      STATE_OPTIONS (sd) = ol;    }  return SIM_RC_OK;}/* Standard option table.   Modules may specify additional ones.   The caller of sim_parse_args may also specify additional options   by calling sim_add_option_table first.  */static DECLARE_OPTION_HANDLER (standard_option_handler);/* FIXME: We shouldn't print in --help output options that aren't usable.   Some fine tuning will be necessary.  One can either move less general   options to another table or use a HAVE_FOO macro to ifdef out unavailable   options.  *//* ??? One might want to conditionally compile out the entries that   aren't enabled.  There's a distinction, however, between options a   simulator can't support and options that haven't been configured in.   Certainly options a simulator can't support shouldn't appear in the   output of --help.  Whether the same thing applies to options that haven't   been configured in or not isn't something I can get worked up over.   [Note that conditionally compiling them out might simply involve moving   the option to another table.]   If you decide to conditionally compile them out as well, delete this   comment and add a comment saying that that is the rule.  */typedef enum {  OPTION_DEBUG_INSN = OPTION_START,  OPTION_DEBUG_FILE,  OPTION_DO_COMMAND,  OPTION_ARCHITECTURE,  OPTION_TARGET,  OPTION_ARCHITECTURE_INFO,  OPTION_ENVIRONMENT,  OPTION_ALIGNMENT,  OPTION_VERBOSE,#if defined (SIM_HAVE_BIENDIAN)  OPTION_ENDIAN,#endif  OPTION_DEBUG,#ifdef SIM_HAVE_FLATMEM  OPTION_MEM_SIZE,#endif  OPTION_HELP,#ifdef SIM_H8300 /* FIXME: Should be movable to h8300 dir.  */  OPTION_H8300H,  OPTION_H8300S,  OPTION_H8300SX,#endif  OPTION_LOAD_LMA,  OPTION_LOAD_VMA,} STANDARD_OPTIONS;static const OPTION standard_options[] ={  { {"verbose", no_argument, NULL, OPTION_VERBOSE},      'v', NULL, "Verbose output",      standard_option_handler },#if defined (SIM_HAVE_BIENDIAN) /* ??? && WITH_TARGET_BYTE_ORDER == 0 */  { {"endian", required_argument, NULL, OPTION_ENDIAN},      'E', "big|little", "Set endianness",      standard_option_handler },#endif#ifdef SIM_HAVE_ENVIRONMENT  /* This option isn't supported unless all choices are supported in keeping     with the goal of not printing in --help output things the simulator can't     do [as opposed to things that just haven't been configured in].  */  { {"environment", required_argument, NULL, OPTION_ENVIRONMENT},      '\0', "user|virtual|operating", "Set running environment",      standard_option_handler },#endif  { {"alignment", required_argument, NULL, OPTION_ALIGNMENT},      '\0', "strict|nonstrict|forced", "Set memory access alignment",      standard_option_handler },  { {"debug", no_argument, NULL, OPTION_DEBUG},      'D', NULL, "Print debugging messages",      standard_option_handler },  { {"debug-insn", no_argument, NULL, OPTION_DEBUG_INSN},      '\0', NULL, "Print instruction debugging messages",      standard_option_handler },  { {"debug-file", required_argument, NULL, OPTION_DEBUG_FILE},      '\0', "FILE NAME", "Specify debugging output file",      standard_option_handler },#ifdef SIM_H8300 /* FIXME: Should be movable to h8300 dir.  */  { {"h8300h", no_argument, NULL, OPTION_H8300H},      'h', NULL, "Indicate the CPU is H8/300H",      standard_option_handler },  { {"h8300s", no_argument, NULL, OPTION_H8300S},      'S', NULL, "Indicate the CPU is H8S",      standard_option_handler },  { {"h8300sx", no_argument, NULL, OPTION_H8300SX},      'x', NULL, "Indicate the CPU is H8SX",      standard_option_handler },#endif#ifdef SIM_HAVE_FLATMEM  { {"mem-size", required_argument, NULL, OPTION_MEM_SIZE},      'm', "MEMORY SIZE", "Specify memory size",      standard_option_handler },#endif  { {"do-command", required_argument, NULL, OPTION_DO_COMMAND},      '\0', "COMMAND", ""/*undocumented*/,      standard_option_handler },  { {"help", no_argument, NULL, OPTION_HELP},      'H', NULL, "Print help information",      standard_option_handler },  { {"architecture", required_argument, NULL, OPTION_ARCHITECTURE},      '\0', "MACHINE", "Specify the architecture to use",      standard_option_handler },  { {"architecture-info", no_argument, NULL, OPTION_ARCHITECTURE_INFO},      '\0', NULL, "List supported architectures",      standard_option_handler },  { {"info-architecture", no_argument, NULL, OPTION_ARCHITECTURE_INFO},      '\0', NULL, NULL,      standard_option_handler },  { {"target", required_argument, NULL, OPTION_TARGET},      '\0', "BFDNAME", "Specify the object-code format for the object files",      standard_option_handler },#ifdef SIM_HANDLES_LMA  { {"load-lma", no_argument, NULL, OPTION_LOAD_LMA},      '\0', NULL,#if SIM_HANDLES_LMA    "Use VMA or LMA addresses when loading image (default LMA)",#else    "Use VMA or LMA addresses when loading image (default VMA)",#endif      standard_option_handler, "load-{lma,vma}" },  { {"load-vma", no_argument, NULL, OPTION_LOAD_VMA},      '\0', NULL, "", standard_option_handler,  "" },#endif  { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }};static SIM_RCstandard_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,			 char *arg, int is_command){  int i,n;  switch ((STANDARD_OPTIONS) opt)    {    case OPTION_VERBOSE:      STATE_VERBOSE_P (sd) = 1;      break;#ifdef SIM_HAVE_BIENDIAN    case OPTION_ENDIAN:      if (strcmp (arg, "big") == 0)	{	  if (WITH_TARGET_BYTE_ORDER == LITTLE_ENDIAN)	    {	      sim_io_eprintf (sd, "Simulator compiled for little endian only.\n");	      return SIM_RC_FAIL;	    }	  /* FIXME:wip: Need to set something in STATE_CONFIG.  */	  current_target_byte_order = BIG_ENDIAN;	}      else if (strcmp (arg, "little") == 0)	{	  if (WITH_TARGET_BYTE_ORDER == BIG_ENDIAN)	    {	      sim_io_eprintf (sd, "Simulator compiled for big endian only.\n");	      return SIM_RC_FAIL;	    }	  /* FIXME:wip: Need to set something in STATE_CONFIG.  */	  current_target_byte_order = LITTLE_ENDIAN;	}      else	{	  sim_io_eprintf (sd, "Invalid endian specification `%s'\n", arg);	  return SIM_RC_FAIL;	}      break;#endif    case OPTION_ENVIRONMENT:      if (strcmp (arg, "user") == 0)	STATE_ENVIRONMENT (sd) = USER_ENVIRONMENT;      else if (strcmp (arg, "virtual") == 0)	STATE_ENVIRONMENT (sd) = VIRTUAL_ENVIRONMENT;      else if (strcmp (arg, "operating") == 0)	STATE_ENVIRONMENT (sd) = OPERATING_ENVIRONMENT;      else	{	  sim_io_eprintf (sd, "Invalid environment specification `%s'\n", arg);	  return SIM_RC_FAIL;	}      if (WITH_ENVIRONMENT != ALL_ENVIRONMENT	  && WITH_ENVIRONMENT != STATE_ENVIRONMENT (sd))	{	  char *type;	  switch (WITH_ENVIRONMENT)	    {	    case USER_ENVIRONMENT: type = "user"; break;	    case VIRTUAL_ENVIRONMENT: type = "virtual"; break;	    case OPERATING_ENVIRONMENT: type = "operating"; break;	    }	  sim_io_eprintf (sd, "Simulator compiled for the %s environment only.\n",			  type);	  return SIM_RC_FAIL;	}      break;    case OPTION_ALIGNMENT:      if (strcmp (arg, "strict") == 0)	{	  if (WITH_ALIGNMENT == 0 || WITH_ALIGNMENT == STRICT_ALIGNMENT)	    {	      current_alignment = STRICT_ALIGNMENT;	      break;	    }	}      else if (strcmp (arg, "nonstrict") == 0)	{	  if (WITH_ALIGNMENT == 0 || WITH_ALIGNMENT == NONSTRICT_ALIGNMENT)	    {	      current_alignment = NONSTRICT_ALIGNMENT;	      break;	    }	}      else if (strcmp (arg, "forced") == 0)	{	  if (WITH_ALIGNMENT == 0 || WITH_ALIGNMENT == FORCED_ALIGNMENT)	    {	      current_alignment = FORCED_ALIGNMENT;	      break;	    }	}      else	{	  sim_io_eprintf (sd, "Invalid alignment specification `%s'\n", arg);	  return SIM_RC_FAIL;	}      switch (WITH_ALIGNMENT)	{	case STRICT_ALIGNMENT:	  sim_io_eprintf (sd, "Simulator compiled for strict alignment only.\n");	  break;	case NONSTRICT_ALIGNMENT:	  sim_io_eprintf (sd, "Simulator compiled for nonstrict alignment only.\n");	  break;	case FORCED_ALIGNMENT:	  sim_io_eprintf (sd, "Simulator compiled for forced alignment only.\n");	  break;	}      return SIM_RC_FAIL;    case OPTION_DEBUG:      if (! WITH_DEBUG)	sim_io_eprintf (sd, "Debugging not compiled in, `-D' ignored\n");      else	{	  for (n = 0; n < MAX_NR_PROCESSORS; ++n)	    for (i = 0; i < MAX_DEBUG_VALUES; ++i)	      CPU_DEBUG_FLAGS (STATE_CPU (sd, n))[i] = 1;	}      break;    case OPTION_DEBUG_INSN :      if (! WITH_DEBUG)	sim_io_eprintf (sd, "Debugging not compiled in, `--debug-insn' ignored\n");      else	{	  for (n = 0; n < MAX_NR_PROCESSORS; ++n)	    CPU_DEBUG_FLAGS (STATE_CPU (sd, n))[DEBUG_INSN_IDX] = 1;	}      break;    case OPTION_DEBUG_FILE :      if (! WITH_DEBUG)	sim_io_eprintf (sd, "Debugging not compiled in, `--debug-file' ignored\n");      else	{	  FILE *f = fopen (arg, "w");	  if (f == NULL)	    {	      sim_io_eprintf (sd, "Unable to open debug output file `%s'\n", arg);	      return SIM_RC_FAIL;	    }	  for (n = 0; n < MAX_NR_PROCESSORS; ++n)	    CPU_DEBUG_FILE (STATE_CPU (sd, n)) = f;	}      break;#ifdef SIM_H8300 /* FIXME: Can be moved to h8300 dir.  */    case OPTION_H8300H:      set_h8300h (bfd_mach_h8300h);      break;    case OPTION_H8300S:      set_h8300h (bfd_mach_h8300s);      break;    case OPTION_H8300SX:      set_h8300h (bfd_mach_h8300sx);      break;#endif#ifdef SIM_HAVE_FLATMEM    case OPTION_MEM_SIZE:      {	unsigned long ul = strtol (arg, NULL, 0);	/* 16384: some minimal amount */	if (! isdigit (arg[0]) || ul < 16384)	  {	    sim_io_eprintf (sd, "Invalid memory size `%s'", arg);	    return SIM_RC_FAIL;	  }	STATE_MEM_SIZE (sd) = ul;      }      break;#endif    case OPTION_DO_COMMAND:      sim_do_command (sd, arg);      break;    case OPTION_ARCHITECTURE:      {	const struct bfd_arch_info *ap = bfd_scan_arch (arg);	if (ap == NULL)	  {	    sim_io_eprintf (sd, "Architecture `%s' unknown\n", arg);	    return SIM_RC_FAIL;	  }	STATE_ARCHITECTURE (sd) = ap;	break;      }    case OPTION_ARCHITECTURE_INFO:      {	const char **list = bfd_arch_list();	const char **lp;	if (list == NULL)	  abort ();	sim_io_printf (sd, "Possible architectures:");	for (lp = list; *lp != NULL; lp++)	  sim_io_printf (sd, " %s", *lp);	sim_io_printf (sd, "\n");	free (list);	break;      }    case OPTION_TARGET:      {	STATE_TARGET (sd) = xstrdup (arg);	break;      }    case OPTION_LOAD_LMA:      {	STATE_LOAD_AT_LMA_P (sd) = 1;	break;      }    case OPTION_LOAD_VMA:      {	STATE_LOAD_AT_LMA_P (sd) = 0;	break;      }    case OPTION_HELP:      sim_print_help (sd, is_command);      if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)	exit (0);      /* FIXME: 'twould be nice to do something similar if gdb.  */      break;    }  return SIM_RC_OK;}/* Add the standard option list to the simulator.  */SIM_RCstandard_install (SIM_DESC sd){  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);  if (sim_add_option_table (sd, NULL, standard_options) != SIM_RC_OK)    return SIM_RC_FAIL;#ifdef SIM_HANDLES_LMA  STATE_LOAD_AT_LMA_P (sd) = SIM_HANDLES_LMA;#endif  return SIM_RC_OK;}/* Return non-zero if arg is a duplicate argument.   If ARG is NULL, initialize.  */#define ARG_HASH_SIZE 97#define ARG_HASH(a) ((256 * (unsigned char) a[0] + (unsigned char) a[1]) % ARG_HASH_SIZE)static intdup_arg_p (arg)     char *arg;{  int hash;  static char **arg_table = NULL;  if (arg == NULL)    {      if (arg_table == NULL)	arg_table = (char **) xmalloc (ARG_HASH_SIZE * sizeof (char *));      memset (arg_table, 0, ARG_HASH_SIZE * sizeof (char *));      return 0;    }  hash = ARG_HASH (arg);  while (arg_table[hash] != NULL)    {      if (strcmp (arg, arg_table[hash]) == 0)	return 1;      /* We assume there won't be more than ARG_HASH_SIZE arguments so we	 don't check if the table is full.  */      if (++hash == ARG_HASH_SIZE)	hash = 0;    }  arg_table[hash] = arg;  return 0;}     /* Called by sim_open to parse the arguments.  */

⌨️ 快捷键说明

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