From 0e9672991e9346d5c2cb9cd33e30fb3e573f88b8 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 26 Dec 2015 07:05:41 -0500 Subject: [PATCH] sim: standardize sim_create_inferior handling of argv a bit more For targets that process argv in sim_create_inferior, improve the code: - provide more details in the comment - make the check for when to re-init more robust - clean out legacy sim_copy_argv code This will be cleaned up more in the future when we have a common inferior creation function, but at least help new ports get it right until then. --- sim/aarch64/ChangeLog | 4 ++++ sim/aarch64/interp.c | 9 +++++---- sim/bfin/ChangeLog | 4 ++++ sim/bfin/interp.c | 9 +++++---- sim/cris/ChangeLog | 5 +++++ sim/cris/sim-if.c | 14 +++++++++----- sim/frv/ChangeLog | 4 ++++ sim/frv/sim-if.c | 13 +++++++++---- sim/ft32/ChangeLog | 4 ++++ sim/ft32/interp.c | 6 +++++- sim/iq2000/ChangeLog | 4 ++++ sim/iq2000/sim-if.c | 13 +++++++++---- sim/lm32/ChangeLog | 4 ++++ sim/lm32/sim-if.c | 13 +++++++++---- sim/m32r/ChangeLog | 4 ++++ sim/m32r/sim-if.c | 13 +++++++++---- sim/sh64/ChangeLog | 4 ++++ sim/sh64/sim-if.c | 13 +++++++++---- 18 files changed, 106 insertions(+), 34 deletions(-) diff --git a/sim/aarch64/ChangeLog b/sim/aarch64/ChangeLog index 608a056da9e..cd0cd41189d 100644 --- a/sim/aarch64/ChangeLog +++ b/sim/aarch64/ChangeLog @@ -1,3 +1,7 @@ +2015-12-26 Mike Frysinger + + * interp.c (sim_create_inferior): Update comment and argv check. + 2015-12-14 Nick Clifton * simulator.c (system_get): New function. Provides read diff --git a/sim/aarch64/interp.c b/sim/aarch64/interp.c index 46ff994679c..d9710399581 100644 --- a/sim/aarch64/interp.c +++ b/sim/aarch64/interp.c @@ -192,10 +192,11 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env) aarch64_set_next_PC (cpu, addr); aarch64_update_PC (cpu); - /* Standalone mode (ie aarch64-elf-run) will take care of the argv - for us in sim_open() -> sim_parse_args(). But in debug mode (i.e. - 'target sim' with `aarch64-...-gdb`), we need to handle it. */ - if (STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG) + /* Standalone mode (i.e. `run`) will take care of the argv for us in + sim_open() -> sim_parse_args(). But in debug mode (i.e. 'target sim' + with `gdb`), we need to handle it because the user can change the + argv on the fly via gdb's 'run'. */ + if (STATE_PROG_ARGV (sd) != argv) { freeargv (STATE_PROG_ARGV (sd)); STATE_PROG_ARGV (sd) = dupargv (argv); diff --git a/sim/bfin/ChangeLog b/sim/bfin/ChangeLog index 744f5eb2000..6717fcc9e09 100644 --- a/sim/bfin/ChangeLog +++ b/sim/bfin/ChangeLog @@ -1,3 +1,7 @@ +2015-12-26 Mike Frysinger + + * interp.c (sim_create_inferior): Update comment and argv check. + 2015-12-25 Mike Frysinger * Makefile.in (SIM_OBJS): Delete sim-model.o. diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c index 5ba204b0e06..2da70b50b62 100644 --- a/sim/bfin/interp.c +++ b/sim/bfin/interp.c @@ -1210,10 +1210,11 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, addr = 0; sim_pc_set (cpu, addr); - /* Standalone mode (i.e. `bfin-...-run`) will take care of the argv - for us in sim_open() -> sim_parse_args(). But in debug mode (i.e. - 'target sim' with `bfin-...-gdb`), we need to handle it. */ - if (STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG) + /* Standalone mode (i.e. `run`) will take care of the argv for us in + sim_open() -> sim_parse_args(). But in debug mode (i.e. 'target sim' + with `gdb`), we need to handle it because the user can change the + argv on the fly via gdb's 'run'. */ + if (STATE_PROG_ARGV (sd) != argv) { freeargv (STATE_PROG_ARGV (sd)); STATE_PROG_ARGV (sd) = dupargv (argv); diff --git a/sim/cris/ChangeLog b/sim/cris/ChangeLog index 37687686d6c..e7f4cc61d7d 100644 --- a/sim/cris/ChangeLog +++ b/sim/cris/ChangeLog @@ -1,3 +1,8 @@ +2015-12-26 Mike Frysinger + + * sim-if.c (sim_create_inferior): Delete old comment and set up + STATE_PROG_ARGV. + 2015-12-25 Mike Frysinger * configure.ac (SIM_AC_OPTION_HARDWARE): Change default to yes and diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c index 3e046559278..97307f811b7 100644 --- a/sim/cris/sim-if.c +++ b/sim/cris/sim-if.c @@ -1064,11 +1064,15 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, addr = 0; sim_pc_set (current_cpu, addr); - /* Other simulators have #if 0:d code that says - STATE_ARGV (sd) = sim_copy_argv (argv); - STATE_ENVP (sd) = sim_copy_argv (envp); - Enabling that gives you not-found link-errors for sim_copy_argv. - FIXME: Do archaeology to find out more. */ + /* Standalone mode (i.e. `run`) will take care of the argv for us in + sim_open() -> sim_parse_args(). But in debug mode (i.e. 'target sim' + with `gdb`), we need to handle it because the user can change the + argv on the fly via gdb's 'run'. */ + if (STATE_PROG_ARGV (sd) != argv) + { + freeargv (STATE_PROG_ARGV (sd)); + STATE_PROG_ARGV (sd) = dupargv (argv); + } return SIM_RC_OK; } diff --git a/sim/frv/ChangeLog b/sim/frv/ChangeLog index 549ff72800e..936bbf23203 100644 --- a/sim/frv/ChangeLog +++ b/sim/frv/ChangeLog @@ -1,3 +1,7 @@ +2015-12-26 Mike Frysinger + + * sim-if.c (sim_create_inferior): Replace old #if 0 code with dupargv. + 2015-12-25 Mike Frysinger * devices.c: Delete file. diff --git a/sim/frv/sim-if.c b/sim/frv/sim-if.c index f908778c6c1..f530763ca58 100644 --- a/sim/frv/sim-if.c +++ b/sim/frv/sim-if.c @@ -213,10 +213,15 @@ sim_create_inferior (sd, abfd, argv, envp) addr = 0; sim_pc_set (current_cpu, addr); -#if 0 - STATE_ARGV (sd) = sim_copy_argv (argv); - STATE_ENVP (sd) = sim_copy_argv (envp); -#endif + /* Standalone mode (i.e. `run`) will take care of the argv for us in + sim_open() -> sim_parse_args(). But in debug mode (i.e. 'target sim' + with `gdb`), we need to handle it because the user can change the + argv on the fly via gdb's 'run'. */ + if (STATE_PROG_ARGV (sd) != argv) + { + freeargv (STATE_PROG_ARGV (sd)); + STATE_PROG_ARGV (sd) = dupargv (argv); + } return SIM_RC_OK; } diff --git a/sim/ft32/ChangeLog b/sim/ft32/ChangeLog index a306ffedb0e..b24646755c1 100644 --- a/sim/ft32/ChangeLog +++ b/sim/ft32/ChangeLog @@ -1,3 +1,7 @@ +2015-12-26 Mike Frysinger + + * interp.c (sim_create_inferior): Update comment and argv check. + 2015-11-15 Mike Frysinger * Makefile.in (SIM_OBJS): Delete sim-reason.o, sim-reg.o, and diff --git a/sim/ft32/interp.c b/sim/ft32/interp.c index e2762b8e156..63ce77b1707 100644 --- a/sim/ft32/interp.c +++ b/sim/ft32/interp.c @@ -877,7 +877,11 @@ sim_create_inferior (SIM_DESC sd, else addr = 0; - if (STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG) + /* Standalone mode (i.e. `run`) will take care of the argv for us in + sim_open() -> sim_parse_args(). But in debug mode (i.e. 'target sim' + with `gdb`), we need to handle it because the user can change the + argv on the fly via gdb's 'run'. */ + if (STATE_PROG_ARGV (sd) != argv) { freeargv (STATE_PROG_ARGV (sd)); STATE_PROG_ARGV (sd) = dupargv (argv); diff --git a/sim/iq2000/ChangeLog b/sim/iq2000/ChangeLog index 4ee58391d67..67529e491d4 100644 --- a/sim/iq2000/ChangeLog +++ b/sim/iq2000/ChangeLog @@ -1,3 +1,7 @@ +2015-12-26 Mike Frysinger + + * sim-if.c (sim_create_inferior): Replace old #if 0 code with dupargv. + 2015-12-25 Mike Frysinger * Makefile.in (SIM_OBJS): Delete sim-model.o. diff --git a/sim/iq2000/sim-if.c b/sim/iq2000/sim-if.c index a72f5c0cb71..fd0e3ba0578 100644 --- a/sim/iq2000/sim-if.c +++ b/sim/iq2000/sim-if.c @@ -172,10 +172,15 @@ sim_create_inferior (sd, abfd, argv, envp) addr = CPU2INSN(0); sim_pc_set (current_cpu, addr); -#if 0 - STATE_ARGV (sd) = sim_copy_argv (argv); - STATE_ENVP (sd) = sim_copy_argv (envp); -#endif + /* Standalone mode (i.e. `run`) will take care of the argv for us in + sim_open() -> sim_parse_args(). But in debug mode (i.e. 'target sim' + with `gdb`), we need to handle it because the user can change the + argv on the fly via gdb's 'run'. */ + if (STATE_PROG_ARGV (sd) != argv) + { + freeargv (STATE_PROG_ARGV (sd)); + STATE_PROG_ARGV (sd) = dupargv (argv); + } return SIM_RC_OK; } diff --git a/sim/lm32/ChangeLog b/sim/lm32/ChangeLog index b94ef40ec29..a3da5608b86 100644 --- a/sim/lm32/ChangeLog +++ b/sim/lm32/ChangeLog @@ -1,3 +1,7 @@ +2015-12-26 Mike Frysinger + + * sim-if.c (sim_create_inferior): Replace old #if 0 code with dupargv. + 2015-12-25 Mike Frysinger * Makefile.in (SIM_OBJS): Delete sim-model.o. diff --git a/sim/lm32/sim-if.c b/sim/lm32/sim-if.c index 3b0575a7a62..eb13363eec2 100644 --- a/sim/lm32/sim-if.c +++ b/sim/lm32/sim-if.c @@ -263,10 +263,15 @@ sim_create_inferior (sd, abfd, argv, envp) addr = 0; sim_pc_set (current_cpu, addr); -#if 0 - STATE_ARGV (sd) = sim_copy_argv (argv); - STATE_ENVP (sd) = sim_copy_argv (envp); -#endif + /* Standalone mode (i.e. `run`) will take care of the argv for us in + sim_open() -> sim_parse_args(). But in debug mode (i.e. 'target sim' + with `gdb`), we need to handle it because the user can change the + argv on the fly via gdb's 'run'. */ + if (STATE_PROG_ARGV (sd) != argv) + { + freeargv (STATE_PROG_ARGV (sd)); + STATE_PROG_ARGV (sd) = dupargv (argv); + } return SIM_RC_OK; } diff --git a/sim/m32r/ChangeLog b/sim/m32r/ChangeLog index 09d2c053d6f..c492bd63fd1 100644 --- a/sim/m32r/ChangeLog +++ b/sim/m32r/ChangeLog @@ -1,3 +1,7 @@ +2015-12-26 Mike Frysinger + + * sim-if.c (sim_create_inferior): Replace old #if 0 code with dupargv. + 2015-12-25 Mike Frysinger * configure.ac (SIM_AC_OPTION_HARDWARE): Add m32r_cache & m32r_uart. diff --git a/sim/m32r/sim-if.c b/sim/m32r/sim-if.c index 639976d5e0f..043c6185614 100644 --- a/sim/m32r/sim-if.c +++ b/sim/m32r/sim-if.c @@ -199,10 +199,15 @@ sim_create_inferior (sd, abfd, argv, envp) m32r_decode_gdb_ctrl_regnum(SPU_REGNUM), 0x1f00000); #endif -#if 0 - STATE_ARGV (sd) = sim_copy_argv (argv); - STATE_ENVP (sd) = sim_copy_argv (envp); -#endif + /* Standalone mode (i.e. `run`) will take care of the argv for us in + sim_open() -> sim_parse_args(). But in debug mode (i.e. 'target sim' + with `gdb`), we need to handle it because the user can change the + argv on the fly via gdb's 'run'. */ + if (STATE_PROG_ARGV (sd) != argv) + { + freeargv (STATE_PROG_ARGV (sd)); + STATE_PROG_ARGV (sd) = dupargv (argv); + } return SIM_RC_OK; } diff --git a/sim/sh64/ChangeLog b/sim/sh64/ChangeLog index 9a4d1f5094d..8a2b58b13ef 100644 --- a/sim/sh64/ChangeLog +++ b/sim/sh64/ChangeLog @@ -1,3 +1,7 @@ +2015-12-26 Mike Frysinger + + * sim-if.c (sim_create_inferior): Replace old #if 0 code with dupargv. + 2015-12-25 Mike Frysinger * Makefile.in (SIM_OBJS): Delete sim-model.o. diff --git a/sim/sh64/sim-if.c b/sim/sh64/sim-if.c index 29e0936ed20..9cd6df8c0ab 100644 --- a/sim/sh64/sim-if.c +++ b/sim/sh64/sim-if.c @@ -178,10 +178,15 @@ sim_create_inferior (sd, abfd, argv, envp) addr = 0; sim_pc_set (current_cpu, addr); -#if 0 - STATE_ARGV (sd) = sim_copy_argv (argv); - STATE_ENVP (sd) = sim_copy_argv (envp); -#endif + /* Standalone mode (i.e. `run`) will take care of the argv for us in + sim_open() -> sim_parse_args(). But in debug mode (i.e. 'target sim' + with `gdb`), we need to handle it because the user can change the + argv on the fly via gdb's 'run'. */ + if (STATE_PROG_ARGV (sd) != argv) + { + freeargv (STATE_PROG_ARGV (sd)); + STATE_PROG_ARGV (sd) = dupargv (argv); + } return SIM_RC_OK; } -- 2.39.2