aboutsummaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-11-15 23:00:04 -0500
committerMike Frysinger <vapier@gentoo.org>2021-11-16 00:58:41 -0500
commit54f7a83a62c27d6da9ee66da1022572d6ea45d84 (patch)
treeeb0670d282c37c15e28f3f4b3344285d7581399d /sim
parent38f9e52086c8d513bc7ef713043c03752924df89 (diff)
downloadgdb-54f7a83a62c27d6da9ee66da1022572d6ea45d84.zip
gdb-54f7a83a62c27d6da9ee66da1022572d6ea45d84.tar.gz
gdb-54f7a83a62c27d6da9ee66da1022572d6ea45d84.tar.bz2
sim: keep track of program environment strings
We've been passing the environment strings to sim_create_inferior, but most ports don't do anything with them. A few will use ad-hoc logic to stuff the stack for user-mode programs, but that's it. Let's formalize this across the board by storing the strings in the normal sim state. This will allow (in future commits) supporting more functionality in the run interface, and to unify some of the libgloss syscalls.
Diffstat (limited to 'sim')
-rw-r--r--sim/aarch64/interp.c6
-rw-r--r--sim/bfin/interp.c6
-rw-r--r--sim/bpf/sim-if.c8
-rw-r--r--sim/common/sim-base.h4
-rw-r--r--sim/common/sim-utils.c1
-rw-r--r--sim/cris/sim-if.c10
-rw-r--r--sim/example-synacor/interp.c6
-rw-r--r--sim/frv/sim-if.c8
-rw-r--r--sim/ft32/interp.c7
-rw-r--r--sim/iq2000/sim-if.c8
-rw-r--r--sim/lm32/sim-if.c8
-rw-r--r--sim/m32r/sim-if.c8
-rw-r--r--sim/pru/interp.c6
-rw-r--r--sim/riscv/interp.c6
14 files changed, 85 insertions, 7 deletions
diff --git a/sim/aarch64/interp.c b/sim/aarch64/interp.c
index 999b949..4d7f421 100644
--- a/sim/aarch64/interp.c
+++ b/sim/aarch64/interp.c
@@ -144,6 +144,12 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
if (trace_load_symbols (sd))
{
STATE_PROG_SYMS_COUNT (sd) =
diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c
index 088b559..9d0e737 100644
--- a/sim/bfin/interp.c
+++ b/sim/bfin/interp.c
@@ -1170,6 +1170,12 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
switch (STATE_ENVIRONMENT (sd))
{
case USER_ENVIRONMENT:
diff --git a/sim/bpf/sim-if.c b/sim/bpf/sim-if.c
index a8d9441..7503a30 100644
--- a/sim/bpf/sim-if.c
+++ b/sim/bpf/sim-if.c
@@ -190,7 +190,7 @@ sim_open (SIM_OPEN_KIND kind,
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
- char *const *argv, char *const *envp)
+ char *const *argv, char *const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
SIM_ADDR addr;
@@ -213,5 +213,11 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
return SIM_RC_OK;
}
diff --git a/sim/common/sim-base.h b/sim/common/sim-base.h
index c34f6f6..50def1e 100644
--- a/sim/common/sim-base.h
+++ b/sim/common/sim-base.h
@@ -165,6 +165,10 @@ struct sim_state {
char *prog_argv0;
#define STATE_PROG_ARGV0(sd) ((sd)->prog_argv0)
+ /* The program's environment. */
+ char **prog_envp;
+#define STATE_PROG_ENVP(sd) ((sd)->prog_envp)
+
/* The program's bfd. */
struct bfd *prog_bfd;
#define STATE_PROG_BFD(sd) ((sd)->prog_bfd)
diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c
index 6f147b2..ff6234b 100644
--- a/sim/common/sim-utils.c
+++ b/sim/common/sim-utils.c
@@ -99,6 +99,7 @@ sim_state_free (SIM_DESC sd)
free (STATE_PROG_FILE (sd));
free (STATE_PROG_ARGV0 (sd));
+ freeargv (STATE_PROG_ENVP (sd));
free (sd);
}
diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c
index 500941a..d29ccc5 100644
--- a/sim/cris/sim-if.c
+++ b/sim/cris/sim-if.c
@@ -951,8 +951,8 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
- char * const *argv ATTRIBUTE_UNUSED,
- char * const *envp ATTRIBUTE_UNUSED)
+ char * const *argv,
+ char * const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
SIM_ADDR addr;
@@ -977,6 +977,12 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
return SIM_RC_OK;
}
diff --git a/sim/example-synacor/interp.c b/sim/example-synacor/interp.c
index d1a82e5..93aea7b 100644
--- a/sim/example-synacor/interp.c
+++ b/sim/example-synacor/interp.c
@@ -174,5 +174,11 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
return SIM_RC_OK;
}
diff --git a/sim/frv/sim-if.c b/sim/frv/sim-if.c
index d036153..7b0913d 100644
--- a/sim/frv/sim-if.c
+++ b/sim/frv/sim-if.c
@@ -175,7 +175,7 @@ frv_sim_close (SIM_DESC sd, int quitting)
SIM_RC
sim_create_inferior (SIM_DESC sd, bfd *abfd, char * const *argv,
- char * const *envp)
+ char * const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
SIM_ADDR addr;
@@ -196,5 +196,11 @@ sim_create_inferior (SIM_DESC sd, bfd *abfd, char * const *argv,
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
return SIM_RC_OK;
}
diff --git a/sim/ft32/interp.c b/sim/ft32/interp.c
index a1cc9ab..2838395 100644
--- a/sim/ft32/interp.c
+++ b/sim/ft32/interp.c
@@ -900,6 +900,13 @@ sim_create_inferior (SIM_DESC sd,
freeargv (STATE_PROG_ARGV (sd));
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
cpu->state.regs[FT32_HARD_SP] = addr;
cpu->state.num_i = 0;
cpu->state.cycles = 0;
diff --git a/sim/iq2000/sim-if.c b/sim/iq2000/sim-if.c
index 21ed821..05b348e 100644
--- a/sim/iq2000/sim-if.c
+++ b/sim/iq2000/sim-if.c
@@ -131,7 +131,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
- char * const *envp)
+ char * const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
SIM_ADDR addr;
@@ -152,5 +152,11 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
return SIM_RC_OK;
}
diff --git a/sim/lm32/sim-if.c b/sim/lm32/sim-if.c
index ce9ab5a..e7bffbd 100644
--- a/sim/lm32/sim-if.c
+++ b/sim/lm32/sim-if.c
@@ -192,7 +192,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
- char * const *envp)
+ char * const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
SIM_ADDR addr;
@@ -213,5 +213,11 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
return SIM_RC_OK;
}
diff --git a/sim/m32r/sim-if.c b/sim/m32r/sim-if.c
index b2f7b46..0cb49a1 100644
--- a/sim/m32r/sim-if.c
+++ b/sim/m32r/sim-if.c
@@ -145,7 +145,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
- char * const *envp)
+ char * const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
SIM_ADDR addr;
@@ -174,6 +174,12 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
return SIM_RC_OK;
}
diff --git a/sim/pru/interp.c b/sim/pru/interp.c
index ca640f4..f243df9 100644
--- a/sim/pru/interp.c
+++ b/sim/pru/interp.c
@@ -848,5 +848,11 @@ sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd,
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
return SIM_RC_OK;
}
diff --git a/sim/riscv/interp.c b/sim/riscv/interp.c
index f94a842..7ecdd55 100644
--- a/sim/riscv/interp.c
+++ b/sim/riscv/interp.c
@@ -153,6 +153,12 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ARGV (sd) = dupargv (argv);
}
+ if (STATE_PROG_ENVP (sd) != env)
+ {
+ freeargv (STATE_PROG_ENVP (sd));
+ STATE_PROG_ENVP (sd) = dupargv (env);
+ }
+
initialize_env (sd, (void *)argv, (void *)env);
return SIM_RC_OK;