aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-11-15 23:04:10 -0500
committerMike Frysinger <vapier@gentoo.org>2021-11-16 01:13:39 -0500
commit8cfc9a1895d9f720e2cc38fd57b94ca5efba07b1 (patch)
treeebec67af6051c58a695f48b6f69d6bf005fd3116
parent54f7a83a62c27d6da9ee66da1022572d6ea45d84 (diff)
downloadgdb-8cfc9a1895d9f720e2cc38fd57b94ca5efba07b1.zip
gdb-8cfc9a1895d9f720e2cc38fd57b94ca5efba07b1.tar.gz
gdb-8cfc9a1895d9f720e2cc38fd57b94ca5efba07b1.tar.bz2
sim: callback: expose argv & environ
Pass the existing strings data to the callbacks so that common libgloss syscalls can be implemented (which we'll do shortly).
-rw-r--r--include/sim/callback.h6
-rw-r--r--sim/aarch64/interp.c4
-rw-r--r--sim/bfin/interp.c4
-rw-r--r--sim/bpf/sim-if.c5
-rw-r--r--sim/common/callback.c2
-rw-r--r--sim/cris/sim-if.c16
-rw-r--r--sim/example-synacor/interp.c5
-rw-r--r--sim/frv/sim-if.c9
-rw-r--r--sim/ft32/interp.c4
-rw-r--r--sim/iq2000/sim-if.c5
-rw-r--r--sim/lm32/sim-if.c9
-rw-r--r--sim/m32r/sim-if.c11
-rw-r--r--sim/pru/interp.c4
-rw-r--r--sim/riscv/interp.c5
14 files changed, 79 insertions, 10 deletions
diff --git a/include/sim/callback.h b/include/sim/callback.h
index 06aa2d4..a51c4de 100644
--- a/include/sim/callback.h
+++ b/include/sim/callback.h
@@ -178,6 +178,12 @@ struct host_callback_struct
enum bfd_endian target_endian;
+ /* Program command line options. */
+ char **argv;
+
+ /* Program environment. */
+ char **envp;
+
/* Size of an "int" on the target (for syscalls whose ABI uses "int").
This must include padding, and only padding-at-higher-address is
supported. For example, a 64-bit target with 32-bit int:s which
diff --git a/sim/aarch64/interp.c b/sim/aarch64/interp.c
index 4d7f421..3289953 100644
--- a/sim/aarch64/interp.c
+++ b/sim/aarch64/interp.c
@@ -126,6 +126,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
char * const *argv, char * const *env)
{
sim_cpu *cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
bfd_vma addr = 0;
if (abfd != NULL)
@@ -150,6 +151,9 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
if (trace_load_symbols (sd))
{
STATE_PROG_SYMS_COUNT (sd) =
diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c
index 9d0e737..88ddbd0 100644
--- a/sim/bfin/interp.c
+++ b/sim/bfin/interp.c
@@ -1151,6 +1151,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
char * const *argv, char * const *env)
{
SIM_CPU *cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
SIM_ADDR addr;
/* Set the PC. */
@@ -1176,6 +1177,9 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
switch (STATE_ENVIRONMENT (sd))
{
case USER_ENVIRONMENT:
diff --git a/sim/bpf/sim-if.c b/sim/bpf/sim-if.c
index 7503a30..6d2f672 100644
--- a/sim/bpf/sim-if.c
+++ b/sim/bpf/sim-if.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
+#include "sim/callback.h"
#include "sim-main.h"
#include "sim-options.h"
#include "libiberty.h"
@@ -193,6 +194,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
char *const *argv, char *const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
SIM_ADDR addr;
/* Determine the start address.
@@ -219,5 +221,8 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
return SIM_RC_OK;
}
diff --git a/sim/common/callback.c b/sim/common/callback.c
index 941f430..a5f0fbe 100644
--- a/sim/common/callback.c
+++ b/sim/common/callback.c
@@ -770,6 +770,8 @@ host_callback default_callback =
/* Defaults expected to be overridden at initialization, where needed. */
BFD_ENDIAN_UNKNOWN, /* target_endian */
+ NULL, /* argv */
+ NULL, /* envp */
4, /* target_sizeof_int */
HOST_CALLBACK_MAGIC,
diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c
index d29ccc5..8bfb624 100644
--- a/sim/cris/sim-if.c
+++ b/sim/cris/sim-if.c
@@ -23,14 +23,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* This must come before any other includes. */
#include "defs.h"
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+
#include "libiberty.h"
#include "bfd.h"
#include "elf-bfd.h"
+#include "sim/callback.h"
#include "sim-main.h"
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
#include "sim-options.h"
#include "sim-hw.h"
#include "dis-asm.h"
@@ -741,7 +743,9 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
/* Find out how much room is needed for the environment and argv, create
that memory and fill it. Only do this when there's a program
- specified. */
+ specified.
+
+ TODO: Move this to sim_create_inferior and use STATE_PROG_ENVP. */
if (abfd != NULL && !cris_bare_iron)
{
const char *name = bfd_get_filename (abfd);
@@ -955,6 +959,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
char * const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
SIM_ADDR addr;
if (sd != NULL)
@@ -983,6 +988,9 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
return SIM_RC_OK;
}
diff --git a/sim/example-synacor/interp.c b/sim/example-synacor/interp.c
index 93aea7b..6b69994 100644
--- a/sim/example-synacor/interp.c
+++ b/sim/example-synacor/interp.c
@@ -28,6 +28,7 @@
/* This must come before any other includes. */
#include "defs.h"
+#include "sim/callback.h"
#include "sim-main.h"
#include "sim-options.h"
@@ -155,6 +156,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
char * const *argv, char * const *env)
{
SIM_CPU *cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
sim_cia addr;
/* Set the PC. */
@@ -180,5 +182,8 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
return SIM_RC_OK;
}
diff --git a/sim/frv/sim-if.c b/sim/frv/sim-if.c
index 7b0913d..c634077 100644
--- a/sim/frv/sim-if.c
+++ b/sim/frv/sim-if.c
@@ -20,10 +20,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* This must come before any other includes. */
#include "defs.h"
+#include <stdlib.h>
+
+#include "sim/callback.h"
+
#define WANT_CPU
#define WANT_CPU_FRVBF
#include "sim-main.h"
-#include <stdlib.h>
#include "sim-options.h"
#include "libiberty.h"
#include "bfd.h"
@@ -178,6 +181,7 @@ sim_create_inferior (SIM_DESC sd, bfd *abfd, char * const *argv,
char * const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
SIM_ADDR addr;
if (abfd != NULL)
@@ -202,5 +206,8 @@ sim_create_inferior (SIM_DESC sd, bfd *abfd, char * const *argv,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
return SIM_RC_OK;
}
diff --git a/sim/ft32/interp.c b/sim/ft32/interp.c
index 2838395..3514f75 100644
--- a/sim/ft32/interp.c
+++ b/sim/ft32/interp.c
@@ -884,6 +884,7 @@ sim_create_inferior (SIM_DESC sd,
{
uint32_t addr;
sim_cpu *cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
/* Set the PC. */
if (abfd != NULL)
@@ -907,6 +908,9 @@ sim_create_inferior (SIM_DESC sd,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
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 05b348e..6c75b0e 100644
--- a/sim/iq2000/sim-if.c
+++ b/sim/iq2000/sim-if.c
@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h>
+#include "sim/callback.h"
#include "sim-options.h"
#include "libiberty.h"
#include "bfd.h"
@@ -134,6 +135,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
char * const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
SIM_ADDR addr;
if (abfd != NULL)
@@ -158,5 +160,8 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
return SIM_RC_OK;
}
diff --git a/sim/lm32/sim-if.c b/sim/lm32/sim-if.c
index e7bffbd..8bbd83d 100644
--- a/sim/lm32/sim-if.c
+++ b/sim/lm32/sim-if.c
@@ -21,12 +21,13 @@
/* This must come before any other includes. */
#include "defs.h"
+#include <stdlib.h>
+
+#include "sim/callback.h"
#include "sim-main.h"
#include "sim-options.h"
#include "libiberty.h"
#include "bfd.h"
-
-#include <stdlib.h>
/* Cover function of sim_state_free to free the cpu buffers as well. */
@@ -195,6 +196,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
char * const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
SIM_ADDR addr;
if (abfd != NULL)
@@ -219,5 +221,8 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
return SIM_RC_OK;
}
diff --git a/sim/m32r/sim-if.c b/sim/m32r/sim-if.c
index 0cb49a1..084ed5a 100644
--- a/sim/m32r/sim-if.c
+++ b/sim/m32r/sim-if.c
@@ -20,14 +20,15 @@
/* This must come before any other includes. */
#include "defs.h"
+#include <string.h>
+#include <stdlib.h>
+
+#include "sim/callback.h"
#include "sim-main.h"
#include "sim-options.h"
#include "libiberty.h"
#include "bfd.h"
-#include <string.h>
-#include <stdlib.h>
-
#include "dv-m32r_uart.h"
#define M32R_DEFAULT_MEM_SIZE 0x2000000 /* 32M */
@@ -148,6 +149,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
char * const *env)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
SIM_ADDR addr;
if (abfd != NULL)
@@ -180,6 +182,9 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
return SIM_RC_OK;
}
diff --git a/sim/pru/interp.c b/sim/pru/interp.c
index f243df9..af72a21 100644
--- a/sim/pru/interp.c
+++ b/sim/pru/interp.c
@@ -831,6 +831,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd,
char * const *argv, char * const *env)
{
SIM_CPU *cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
SIM_ADDR addr;
addr = bfd_get_start_address (prog_bfd);
@@ -854,5 +855,8 @@ sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
return SIM_RC_OK;
}
diff --git a/sim/riscv/interp.c b/sim/riscv/interp.c
index 7ecdd55..efa4b56 100644
--- a/sim/riscv/interp.c
+++ b/sim/riscv/interp.c
@@ -21,6 +21,7 @@
/* This must come before any other includes. */
#include "defs.h"
+#include "sim/callback.h"
#include "sim-main.h"
#include "sim-options.h"
@@ -134,6 +135,7 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
char * const *argv, char * const *env)
{
SIM_CPU *cpu = STATE_CPU (sd, 0);
+ host_callback *cb = STATE_CALLBACK (sd);
SIM_ADDR addr;
/* Set the PC. */
@@ -159,6 +161,9 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
STATE_PROG_ENVP (sd) = dupargv (env);
}
+ cb->argv = STATE_PROG_ARGV (sd);
+ cb->envp = STATE_PROG_ENVP (sd);
+
initialize_env (sd, (void *)argv, (void *)env);
return SIM_RC_OK;