diff options
author | Mike Frysinger <vapier@gentoo.org> | 2021-11-15 02:36:29 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2021-11-15 02:53:31 -0500 |
commit | 852016f92107581dbc9513196c9a74a91b5a5b6e (patch) | |
tree | 0e785165301066a263f61f38c94ee8b272239bc7 /sim/common/sim-options.c | |
parent | e8f20a28b1192d746475f045d77ac84411f164df (diff) | |
download | gdb-852016f92107581dbc9513196c9a74a91b5a5b6e.zip gdb-852016f92107581dbc9513196c9a74a91b5a5b6e.tar.gz gdb-852016f92107581dbc9513196c9a74a91b5a5b6e.tar.bz2 |
sim: run: add --argv0 option to control argv[0]
We default argv[0] to the program we run which is a standard *NIX
convention, but sometimes we want to be able to control the argv[0]
setting independently (especially for programs that inspect argv[0]
to change their behavior or output). Add an option to control it.
Diffstat (limited to 'sim/common/sim-options.c')
-rw-r--r-- | sim/common/sim-options.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c index 7e5695d..ee7d11f 100644 --- a/sim/common/sim-options.c +++ b/sim/common/sim-options.c @@ -104,7 +104,8 @@ typedef enum { OPTION_VERSION, OPTION_LOAD_LMA, OPTION_LOAD_VMA, - OPTION_SYSROOT + OPTION_SYSROOT, + OPTION_ARGV0, } STANDARD_OPTIONS; static const OPTION standard_options[] = @@ -179,6 +180,10 @@ static const OPTION standard_options[] = "Root for system calls with absolute file-names and cwd at start", standard_option_handler, NULL }, + { {"argv0", required_argument, NULL, OPTION_ARGV0}, + '\0', "ARGV0", "Set argv[0] to the specified string", + standard_option_handler, NULL }, + { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL, NULL } }; @@ -420,6 +425,11 @@ standard_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt, else simulator_sysroot = ""; break; + + case OPTION_ARGV0: + free (STATE_PROG_ARGV0 (sd)); + STATE_PROG_ARGV0 (sd) = xstrdup (arg); + break; } return SIM_RC_OK; @@ -605,8 +615,16 @@ sim_parse_args (SIM_DESC sd, char * const *argv) { if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE) { + char **new_argv = dupargv (argv + optind); + STATE_PROG_FILE (sd) = xstrdup (argv[optind]); - STATE_PROG_ARGV (sd) = dupargv (argv + optind); + if (STATE_PROG_ARGV0 (sd) != NULL) + { + free (new_argv[0]); + new_argv[0] = xstrdup (STATE_PROG_ARGV0 (sd)); + } + freeargv (STATE_PROG_ARGV (sd)); + STATE_PROG_ARGV (sd) = new_argv; } break; } @@ -787,7 +805,7 @@ void sim_print_help (SIM_DESC sd, int is_command) { if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE) - sim_io_printf (sd, "Usage: %s [options] program [program args]\n", + sim_io_printf (sd, "Usage: %s [options] [--] program [program args]\n", STATE_MY_NAME (sd)); /* Initialize duplicate argument checker. */ |