Save a copy of argv, not just a pointer.

This commit is contained in:
Andrew Cagney 1997-08-27 00:35:34 +00:00
parent 099ddbf117
commit d07dddd2b2
3 changed files with 54 additions and 18 deletions

View File

@ -1,3 +1,11 @@
Wed Aug 27 09:51:42 1997 Andrew Cagney <cagney@b1.cygnus.com>
* sim-utils.c (sim_copy_argv): Rewrite to match malloc strategy
used by copyargv and freeargv.
* sim-options.c (sim_parse_args): Save a copy of PROG-ARGS in
STATE_PROG_ARGV, not just a pointer.
Mon Aug 25 17:50:22 1997 Andrew Cagney <cagney@b1.cygnus.com>
* configure: Regenerated to track ../common/aclocal.m4 changes.

View File

@ -375,7 +375,7 @@ sim_parse_args (sd, argv)
if (optc == -1)
{
if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
STATE_PROG_ARGV (sd) = argv + optind;
STATE_PROG_ARGV (sd) = sim_copy_argv (argv + optind);
break;
}
if (optc == '?')
@ -405,7 +405,11 @@ sim_print_help (sd, is_command)
/* Initialize duplicate argument checker. */
(void) dup_arg_p (NULL);
sim_io_printf (sd, "Options:\n");
if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
sim_io_printf (sd, "Options:\n");
else
sim_io_printf (sd, "Commands:\n");
for (ol = STATE_OPTIONS (sd); ol != NULL; ol = ol->next)
for (opt = ol->options; opt->opt.name != NULL; ++opt)
{
@ -503,6 +507,11 @@ sim_print_help (sd, is_command)
sim_io_printf (sd, "%s\n", opt->doc);
}
sim_io_printf (sd, "\n");
sim_io_printf (sd, "Note: Depending on the simulator configuration some %ss\n",
STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE ? "option" : "command");
sim_io_printf (sd, " may not be applicable\n");
if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
{
sim_io_printf (sd, "\n");

View File

@ -20,20 +20,34 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "sim-main.h"
#include "sim-assert.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h> /* needed by sys/resource.h */
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#endif
#include "libiberty.h"
#include "bfd.h"
#include "sim-utils.h"
/* Global pointer to all state data.
Set by sim_resume. */
@ -105,29 +119,33 @@ char **
sim_copy_argv (argv)
char **argv;
{
int i,argc,len;
char **copy,*p;
int i;
int argc;
int len;
char **copy;
argc = len = 0;
if (argv)
{
for ( ; argv[argc]; ++argc)
len += strlen (argv[argc]) + 1;
}
if (argv == NULL)
return NULL;
copy = (char **) malloc ((argc + 1) * sizeof (char *) + len);
/* the vector */
for (argc = 0; argv[argc] != NULL; argc++);
copy = (char **) malloc ((argc + 1) * sizeof (char *));
if (copy == NULL)
return NULL;
p = (char *) copy + (argc + 1) * sizeof (char *);
for (i = 0; i < argc; ++i)
/* the strings */
for (argc = 0; argv[argc] != NULL; argc++)
{
copy[i] = p;
strcpy (p, argv[i]);
p += strlen (argv[i]) + 1;
int len = strlen (argv[argc]);
copy[argc] = malloc (sizeof (char *) * (len + 1));
if (copy[argc] == NULL)
{
freeargv (copy);
return NULL;
}
strcpy (copy[argc], argv[argc]);
}
copy[argc] = 0;
copy[argc] = NULL;
return copy;
}
@ -140,6 +158,7 @@ sim_analyze_program (sd, prog_bfd)
{
asection *s;
SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
STATE_PROG_BFD (sd) = prog_bfd;
STATE_START_ADDR (sd) = bfd_get_start_address (prog_bfd);