summaryrefslogtreecommitdiff
path: root/sim/common
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-11-15 02:32:06 -0500
committerMike Frysinger <vapier@gentoo.org>2021-11-15 02:53:29 -0500
commite8f20a28b1192d746475f045d77ac84411f164df (patch)
tree3ff31f3c32862561e65c1d23650b13eb0c28702a /sim/common
parent7b2ec4e46fb726a7616a07e67c4270f48c8c546e (diff)
sim: split program path out of argv vector
We use the program argv to both find the program to run (argv[0]) and to hold the arguments to the program. Most of the time this is fine, but if we want to let programs specify argv[0] independently (which is possible in standard *NIX programs), this double duty doesn't work. So let's split the path to the program to run out into a separate field by itself. This simplifies the various sim_open funcs too. By itself, this code is more of a logical cleanup than something that is super useful. But it will open up customization of argv[0] in a follow up commit. Split the changes to make it easier to review.
Diffstat (limited to 'sim/common')
-rw-r--r--sim/common/nrun.c2
-rw-r--r--sim/common/sim-base.h5
-rw-r--r--sim/common/sim-options.c5
-rw-r--r--sim/common/sim-utils.c1
4 files changed, 11 insertions, 2 deletions
diff --git a/sim/common/nrun.c b/sim/common/nrun.c
index 3fd78346f9..f1fb7d12eb 100644
--- a/sim/common/nrun.c
+++ b/sim/common/nrun.c
@@ -103,7 +103,7 @@ main (int argc, char **argv)
if (prog_argv == NULL || *prog_argv == NULL)
usage ();
- name = *prog_argv;
+ name = STATE_PROG_FILE (sd);
/* For simulators that don't open prog during sim_open() */
if (prog_bfd == NULL)
diff --git a/sim/common/sim-base.h b/sim/common/sim-base.h
index 674b2d4230..ff54f1d1e4 100644
--- a/sim/common/sim-base.h
+++ b/sim/common/sim-base.h
@@ -151,6 +151,11 @@ struct sim_state {
const char *model_name;
#define STATE_MODEL_NAME(sd) ((sd)->model_name)
+ /* In standalone simulator, this is the program to run. Not to be confused
+ with argv which are the strings passed to the program itself. */
+ char *prog_file;
+#define STATE_PROG_FILE(sd) ((sd)->prog_file)
+
/* In standalone simulator, this is the program's arguments passed
on the command line. */
char **prog_argv;
diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c
index e82ac33fe7..7e5695d8cc 100644
--- a/sim/common/sim-options.c
+++ b/sim/common/sim-options.c
@@ -604,7 +604,10 @@ sim_parse_args (SIM_DESC sd, char * const *argv)
if (optc == -1)
{
if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
- STATE_PROG_ARGV (sd) = dupargv (argv + optind);
+ {
+ STATE_PROG_FILE (sd) = xstrdup (argv[optind]);
+ STATE_PROG_ARGV (sd) = dupargv (argv + optind);
+ }
break;
}
if (optc == '?')
diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c
index 88fd20e887..0e8cd5afc2 100644
--- a/sim/common/sim-utils.c
+++ b/sim/common/sim-utils.c
@@ -97,6 +97,7 @@ sim_state_free (SIM_DESC sd)
SIM_STATE_FREE (sd);
#endif
+ free (STATE_PROG_FILE (sd));
free (sd);
}