]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim: callback: expose argv & environ
authorMike Frysinger <vapier@gentoo.org>
Tue, 16 Nov 2021 04:04:10 +0000 (23:04 -0500)
committerMike Frysinger <vapier@gentoo.org>
Tue, 16 Nov 2021 06:13:39 +0000 (01:13 -0500)
Pass the existing strings data to the callbacks so that common
libgloss syscalls can be implemented (which we'll do shortly).

14 files changed:
include/sim/callback.h
sim/aarch64/interp.c
sim/bfin/interp.c
sim/bpf/sim-if.c
sim/common/callback.c
sim/cris/sim-if.c
sim/example-synacor/interp.c
sim/frv/sim-if.c
sim/ft32/interp.c
sim/iq2000/sim-if.c
sim/lm32/sim-if.c
sim/m32r/sim-if.c
sim/pru/interp.c
sim/riscv/interp.c

index 06aa2d4be79079575ee497ff53634744a03f643e..a51c4de9c3aafb6cfe0ee21b4d524d09e70dcbae 100644 (file)
@@ -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
index 4d7f4217456023a53a9cd2d6a219c3ddbb18f440..328995358b0d0e2eef590ddaf4dab9e8ae91340d 100644 (file)
@@ -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) =
index 9d0e737cc33c592d00384925cc3aa9b0ac6c6268..88ddbd071b3d42c295bbbdbb5c7fdb56e79c097f 100644 (file)
@@ -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:
index 7503a302ca34e302a287aefe0461cec26cbcf567..6d2f67295a1ef90c8e6e693831684ece3de46480 100644 (file)
@@ -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;
 }
index 941f4302b6e4785e00376785f0e3046a83780b8f..a5f0fbe435589297845a8f254a4faf706ac689e5 100644 (file)
@@ -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,
index d29ccc59f351f3144d5a93352d03e54d3aa3b416..8bfb624b7866a634f4b52e737daa20e929dd73dd 100644 (file)
@@ -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;
 }
 \f
index 93aea7b0a860f1560701a104416d6a16685581a9..6b6999465e37f3594732d49022365dc9ddf5e2d2 100644 (file)
@@ -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"
 \f
@@ -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;
 }
index 7b0913dad014389f60450326f2e962a86ed6f97f..c6340770f8ee220a014873a81e001fa48abeffb9 100644 (file)
@@ -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;
 }
index 2838395dd029b3a80510445df4e8964dea100722..3514f75b6a57e0af0b4cad76d42b304ae9412040 100644 (file)
@@ -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;
index 05b348efe90ef2988609237f3f93ab0e531ab4e6..6c75b0ef5518552ca65f947940f8573784bbd9f1 100644 (file)
@@ -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;
 }
index e7bffbdf3f6ea3ffe6dbbe67ac9fc223a71ffbc7..8bbd83d6dcd2a15caa2dd8bcbd67eca198b0c672 100644 (file)
 /* 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>
 \f
 /* 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;
 }
index 0cb49a1e4e1987469340ae644aac607f41f68dbb..084ed5a0d4b22fe8e75b93b88042a49fb4ed4b91 100644 (file)
 /* 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;
 }
 
index f243df9426d393842abaa0d0ecf41056845f5fa3..af72a21d74280a7e3dc78227b41def2a571525c3 100644 (file)
@@ -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;
 }
index 7ecdd55141c1114b7265379baac2083cca84925c..efa4b5669cb3fc82dd7a9bd922cfd497f8517bef 100644 (file)
@@ -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"
 \f
@@ -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;