aboutsummaryrefslogtreecommitdiff
path: root/sim/common/sim-options.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-11-16 03:16:09 -0500
committerMike Frysinger <vapier@gentoo.org>2021-11-16 03:34:28 -0500
commit3b2934856f1370b320d8be5e1d4d82ef0c628f01 (patch)
tree79363ce155d2a34339bd3501699e6485e187108e /sim/common/sim-options.c
parent35818ade9668f04ac99a68b10855a3ae45afc4b5 (diff)
downloadgdb-3b2934856f1370b320d8be5e1d4d82ef0c628f01.zip
gdb-3b2934856f1370b320d8be5e1d4d82ef0c628f01.tar.gz
gdb-3b2934856f1370b320d8be5e1d4d82ef0c628f01.tar.bz2
sim: run: support concise env var settings
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.
Diffstat (limited to 'sim/common/sim-options.c')
-rw-r--r--sim/common/sim-options.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c
index f94b814..8c9b7cf 100644
--- a/sim/common/sim-options.c
+++ b/sim/common/sim-options.c
@@ -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");
}