Save a copy of argv, not just a pointer.
authorAndrew Cagney <cagney@redhat.com>
Wed, 27 Aug 1997 00:35:34 +0000 (00:35 +0000)
committerAndrew Cagney <cagney@redhat.com>
Wed, 27 Aug 1997 00:35:34 +0000 (00:35 +0000)
sim/common/ChangeLog
sim/common/sim-options.c
sim/common/sim-utils.c

index 7fc83af9f10f68793573a5ec56d73e36140d634b..b4dd6782e033fd9e70570387dfab6eedf24a1d53 100644 (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.
index 7a8dbe737d6a0e66c23c3890a4b8dd906c72adc3..8ed5f6355b39c85c9fc2043aaaa6350f998afa78 100644 (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");
index fbb61d420fab02dfb0f9eaafbc419082c781455f..e0432f88c58529ed3b9da6d09b37772c05021477 100644 (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);
 
This page took 0.029957 seconds and 4 git commands to generate.