From: Andrew Cagney Date: Wed, 27 Aug 1997 00:35:34 +0000 (+0000) Subject: Save a copy of argv, not just a pointer. X-Git-Tag: gdb-4_18~4938 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d07dddd2b24abd93f92412a6764129f29c1acc0e;p=platform%2Fupstream%2Fbinutils.git Save a copy of argv, not just a pointer. --- diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 7fc83af..b4dd678 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,11 @@ +Wed Aug 27 09:51:42 1997 Andrew Cagney + + * 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 * configure: Regenerated to track ../common/aclocal.m4 changes. diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c index 7a8dbe7..8ed5f63 100644 --- a/sim/common/sim-options.c +++ b/sim/common/sim-options.c @@ -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"); diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c index fbb61d4..e0432f8 100644 --- a/sim/common/sim-utils.c +++ b/sim/common/sim-utils.c @@ -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 #endif + #ifdef HAVE_TIME_H #include #endif + #ifdef HAVE_SYS_TIME_H #include /* needed by sys/resource.h */ #endif + #ifdef HAVE_SYS_RESOURCE_H #include #endif + +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#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);