]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim: run: support concise env var settings
authorMike Frysinger <vapier@gentoo.org>
Tue, 16 Nov 2021 08:16:09 +0000 (03:16 -0500)
committerMike Frysinger <vapier@gentoo.org>
Tue, 16 Nov 2021 08:34:28 +0000 (03:34 -0500)
Support the same syntax as other common utilities where env vars can
be specified before the program to be run without an explicit option.

This behavior can be suppressed by using the -- marker.

sim/common/nrun.c
sim/common/sim-options.c

index 320380e91d59f9612a36ba019ef2b39e0c4f261b..557a060e569120cedcd5c31690c24a2e423187be 100644 (file)
@@ -229,7 +229,8 @@ main (int argc, char **argv)
 static void
 usage (void)
 {
-  fprintf (stderr, "Usage: %s [options] [--] program [program args]\n", myname);
+  fprintf (stderr, "Usage: %s [options] [VAR=VAL|--] program [program args]\n",
+          myname);
   fprintf (stderr, "Run `%s --help' for full list of options.\n", myname);
   exit (1);
 }
index f94b814a6cb3985cbabc3a5a26e3481e1e98e722..8c9b7cfec370d43dac5b425bd43beab64150f7b4 100644 (file)
@@ -719,6 +719,22 @@ sim_parse_args (SIM_DESC sd, char * const *argv)
              free (STATE_PROG_FILE (sd));
              STATE_PROG_FILE (sd) = NULL;
 
+             /* Handle any inline variables if -- wasn't used.  */
+             if (argv[optind] != NULL && optind > 0
+                 && strcmp (argv[optind - 1], "--") != 0)
+               {
+                 while (1)
+                   {
+                     const char *arg = argv[optind];
+
+                     if (strchr (arg, '=') == NULL)
+                       break;
+
+                     env_set (sd, arg);
+                     ++optind;
+                   }
+               }
+
              new_argv = dupargv (argv + optind);
              freeargv (STATE_PROG_ARGV (sd));
              STATE_PROG_ARGV (sd) = new_argv;
@@ -914,7 +930,8 @@ void
 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",
+    sim_io_printf (sd,
+                  "Usage: %s [options] [VAR=VAL|--] program [program args]\n",
                   STATE_MY_NAME (sd));
 
   /* Initialize duplicate argument checker.  */
@@ -950,6 +967,9 @@ sim_print_help (SIM_DESC sd, int is_command)
   if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
     {
       sim_io_printf (sd, "\n");
+      sim_io_printf (sd,
+                    "VAR=VAL         Environment variables to set.  "
+                    "Ignored if -- is used.\n");
       sim_io_printf (sd, "program args    Arguments to pass to simulated program.\n");
       sim_io_printf (sd, "                Note: Very few simulators support this.\n");
     }