/* Simulator option handling.
- Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 2004, 2007, 2008, 2009, 2010, 2011
+ 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 modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation; either version 3 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. */
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "sim-main.h"
#ifdef HAVE_STRING_H
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_LOAD_LMA,
OPTION_LOAD_VMA,
+ OPTION_SYSROOT
} STANDARD_OPTIONS;
static const OPTION standard_options[] =
{
{ {"verbose", no_argument, NULL, OPTION_VERBOSE},
'v', NULL, "Verbose output",
- standard_option_handler },
+ standard_option_handler, NULL },
-#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
+ standard_option_handler, NULL },
#ifdef SIM_HAVE_ENVIRONMENT
/* This option isn't supported unless all choices are supported in keeping
#ifdef SIM_HAVE_FLATMEM
{ {"mem-size", required_argument, NULL, OPTION_MEM_SIZE},
- 'm', "MEMORY SIZE", "Specify memory size",
- standard_option_handler },
+ 'm', "<size>[in bytes, Kb (k suffix), Mb (m suffix) or Gb (g suffix)]",
+ "Specify memory size", standard_option_handler },
#endif
{ {"do-command", required_argument, NULL, OPTION_DO_COMMAND},
'\0', NULL, "", standard_option_handler, "" },
#endif
- { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
+ { {"sysroot", required_argument, NULL, OPTION_SYSROOT},
+ '\0', "SYSROOT",
+ "Root for system calls with absolute file-names and cwd at start",
+ standard_option_handler, NULL },
+
+ { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL, NULL }
};
static SIM_RC
STATE_VERBOSE_P (sd) = 1;
break;
-#ifdef SIM_HAVE_BIENDIAN
case OPTION_ENDIAN:
if (strcmp (arg, "big") == 0)
{
return SIM_RC_FAIL;
}
break;
-#endif
case OPTION_ENVIRONMENT:
if (strcmp (arg, "user") == 0)
if (WITH_ENVIRONMENT != ALL_ENVIRONMENT
&& WITH_ENVIRONMENT != STATE_ENVIRONMENT (sd))
{
- char *type;
+ const char *type;
switch (WITH_ENVIRONMENT)
{
case USER_ENVIRONMENT: type = "user"; break;
#ifdef SIM_HAVE_FLATMEM
case OPTION_MEM_SIZE:
{
- unsigned long ul = strtol (arg, NULL, 0);
+ char * endp;
+ unsigned long ul = strtol (arg, &endp, 0);
+
+ switch (* endp)
+ {
+ case 'k': case 'K': size <<= 10; break;
+ case 'm': case 'M': size <<= 20; break;
+ case 'g': case 'G': size <<= 30; break;
+ case ' ': case '\0': case '\t': break;
+ default:
+ if (ul > 0)
+ sim_io_eprintf (sd, "Ignoring strange character at end of memory size: %c\n", * endp);
+ break;
+ }
+
/* 16384: some minimal amount */
if (! isdigit (arg[0]) || ul < 16384)
{
exit (0);
/* FIXME: 'twould be nice to do something similar if gdb. */
break;
+
+ case OPTION_SYSROOT:
+ /* Don't leak memory in the odd event that there's lots of
+ --sysroot=... options. */
+ if (simulator_sysroot[0] != '\0' && arg[0] != '\0')
+ free (simulator_sysroot);
+ simulator_sysroot = xstrdup (arg);
+ break;
}
return SIM_RC_OK;
#define ARG_HASH(a) ((256 * (unsigned char) a[0] + (unsigned char) a[1]) % ARG_HASH_SIZE)
static int
-dup_arg_p (arg)
- char *arg;
+dup_arg_p (const char *arg)
{
int hash;
- static char **arg_table = NULL;
+ static const char **arg_table = NULL;
if (arg == NULL)
{
if (arg_table == NULL)
- arg_table = (char **) xmalloc (ARG_HASH_SIZE * sizeof (char *));
+ arg_table = (const char **) xmalloc (ARG_HASH_SIZE * sizeof (char *));
memset (arg_table, 0, ARG_HASH_SIZE * sizeof (char *));
return 0;
}
/* Called by sim_open to parse the arguments. */
SIM_RC
-sim_parse_args (sd, argv)
- SIM_DESC sd;
- char **argv;
+sim_parse_args (SIM_DESC sd, char **argv)
{
int c, i, argc, num_opts;
char *p, *short_options;
char *name;
*lp = opt->opt;
/* Prepend --<cpuname>- to the option. */
- asprintf (&name, "%s-%s", CPU_NAME (cpu), lp->name);
+ if (asprintf (&name, "%s-%s", CPU_NAME (cpu), lp->name) < 0)
+ {
+ sim_io_eprintf (sd, "internal error, out of memory");
+ result = SIM_RC_FAIL;
+ break;
+ }
lp->name = name;
/* Dynamically assign `val' numbers for long options. */
lp->val = i++;
}
}
- zfree (long_options);
- zfree (short_options);
- zfree (handlers);
- zfree (opt_cpu);
- zfree (orig_val);
+ free (long_options);
+ free (short_options);
+ free (handlers);
+ free (opt_cpu);
+ free (orig_val);
return result;
}
/* Print help messages for the options. */
void
-sim_print_help (sd, is_command)
- SIM_DESC sd;
- int is_command;
+sim_print_help (SIM_DESC sd, int is_command)
{
if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
sim_io_printf (sd, "Usage: %s [options] program [program args]\n",