diff options
author | Andrew Cagney <cagney@redhat.com> | 1997-08-27 00:35:34 +0000 |
---|---|---|
committer | Andrew Cagney <cagney@redhat.com> | 1997-08-27 00:35:34 +0000 |
commit | d07dddd2b24abd93f92412a6764129f29c1acc0e (patch) | |
tree | 57ac972e0d0749cdc10b8c1503a61ab46c1cb1db /sim/common | |
parent | 099ddbf11783723ba9dd45adb9ce928c299539f0 (diff) | |
download | gdb-d07dddd2b24abd93f92412a6764129f29c1acc0e.zip gdb-d07dddd2b24abd93f92412a6764129f29c1acc0e.tar.gz gdb-d07dddd2b24abd93f92412a6764129f29c1acc0e.tar.bz2 |
Save a copy of argv, not just a pointer.
Diffstat (limited to 'sim/common')
-rw-r--r-- | sim/common/ChangeLog | 8 | ||||
-rw-r--r-- | sim/common/sim-options.c | 13 | ||||
-rw-r--r-- | sim/common/sim-utils.c | 51 |
3 files changed, 54 insertions, 18 deletions
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 <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. 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 <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); |