From 43c53e07db6bdb75bd0fa4ee0165be0bc76ab9f0 Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Thu, 8 May 1997 05:28:20 +0000 Subject: [PATCH] Add function sim_args_command() which takes a `(gdb) sim ' and parses it using rules found in the simulator command-line-options databse. --- sim/common/ChangeLog | 12 ++++ sim/common/sim-options.c | 117 +++++++++++++++++++++++++++++++++------ sim/common/sim-options.h | 14 +++-- sim/tic80/ChangeLog | 5 ++ sim/tic80/sim-calls.c | 5 +- 5 files changed, 131 insertions(+), 22 deletions(-) diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 4363d4194bc..fe09b689edd 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,15 @@ +Thu May 8 12:40:07 1997 Andrew Cagney + + * sim-options.c (sim_print_help): For optional arguments, wrap + them in []. + + * sim-trace.c (set_trace_options): New function, handle optional + argument and multiple assignment. + (trace_option_handler): Update. + + * sim-trace.c (trace_option_handler): Trace branch and not fpu + when branch tracing selected. + Wed May 7 15:19:58 1997 Andrew Cagney * sim-trace.c (trace_one_insn): Make a va-args function. diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c index 1a0ec215634..5207457ef07 100644 --- a/sim/common/sim-options.c +++ b/sim/common/sim-options.c @@ -78,6 +78,7 @@ static DECLARE_OPTION_HANDLER (standard_option_handler); #define OPTION_DEBUG_INSN (OPTION_START + 0) #define OPTION_DEBUG_FILE (OPTION_START + 1) +#define OPTION_DO_COMMAND (OPTION_START + 2) static const OPTION standard_options[] = { @@ -113,6 +114,10 @@ static const OPTION standard_options[] = standard_option_handler }, #endif + { {"do-command", required_argument, NULL, OPTION_DO_COMMAND}, + '\0', "COMMAND", "Perform a builtin command", + standard_option_handler }, + { {"help", no_argument, NULL, 'H'}, 'H', NULL, "Print help information", standard_option_handler }, @@ -127,7 +132,6 @@ standard_option_handler (sd, opt, arg) char *arg; { int i,n; - unsigned long ul; switch (opt) { @@ -209,17 +213,23 @@ standard_option_handler (sd, opt, arg) #ifdef SIM_HAVE_FLATMEM case 'm': - ul = strtol (arg, NULL, 0); - /* 16384: some minimal amount */ - if (! isdigit (arg[0]) || ul < 16384) - { - sim_io_eprintf (sd, "Invalid memory size `%s'", arg); - return SIM_RC_FAIL; - } - STATE_MEM_SIZE (sd) = ul; + { + unsigned long ul = strtol (arg, NULL, 0); + /* 16384: some minimal amount */ + if (! isdigit (arg[0]) || ul < 16384) + { + sim_io_eprintf (sd, "Invalid memory size `%s'", arg); + return SIM_RC_FAIL; + } + STATE_MEM_SIZE (sd) = ul; + } break; #endif + case OPTION_DO_COMMAND: + sim_do_command (sd, arg); + break; + case 'H': sim_print_help (sd); if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE) @@ -412,13 +422,16 @@ sim_print_help (sd) len += (comma ? 2 : 0) + 2; if (o->arg != NULL) { - if (o->opt.has_arg != optional_argument) + if (o->opt.has_arg == optional_argument) { - sim_io_printf (sd, " "); - ++len; + sim_io_printf (sd, "[%s]", o->arg); + len += 1 + strlen (o->arg) + 1; + } + else + { + sim_io_printf (sd, " %s", o->arg); + len += 1 + strlen (o->arg); } - sim_io_printf (sd, "%s", o->arg); - len += strlen (o->arg); } comma = 1; } @@ -439,8 +452,16 @@ sim_print_help (sd) + strlen (o->opt.name)); if (o->arg != NULL) { - sim_io_printf (sd, " %s", o->arg); - len += 1 + strlen (o->arg); + if (o->opt.has_arg == optional_argument) + { + sim_io_printf (sd, " [%s]", o->arg); + len += 2 + strlen (o->arg) + 1; + } + else + { + sim_io_printf (sd, " %s", o->arg); + len += 1 + strlen (o->arg); + } } comma = 1; } @@ -467,3 +488,67 @@ sim_print_help (sd) sim_io_printf (sd, " Note: Very few simulators support this.\n"); } } + + + + +SIM_RC +sim_args_command (sd, cmd) + SIM_DESC sd; + char *cmd; +{ + /* something to do? */ + if (cmd == NULL) + return SIM_RC_OK; /* FIXME - perhaphs help would be better */ + + if (cmd [0] == '-') + { + /* user specified - ... form? */ + char **argv = buildargv (cmd); + SIM_RC rc = sim_parse_args (sd, argv); + freeargv (argv); + return rc; + } + else + { + /* user specified form? */ + const struct option_list *ol; + const OPTION *opt; + char **argv = buildargv (cmd); + for (ol = STATE_OPTIONS (sd); ol != NULL; ol = ol->next) + for (opt = ol->options; opt->opt.name != NULL; ++opt) + { + if (strcmp (argv[0], opt->opt.name) == 0) + { + switch (opt->opt.has_arg) + { + case no_argument: + if (argv[1] == NULL) + opt->handler (sd, opt->opt.val, NULL); + else + sim_io_eprintf (sd, "Command `%s' takes no arguments\n", opt->opt.name); + break; + case optional_argument: + if (argv[1] == NULL) + opt->handler (sd, opt->opt.val, NULL); + else if (argv[2] == NULL) + opt->handler (sd, opt->opt.val, argv[1]); + else + sim_io_eprintf (sd, "Command `%s' requires no more than one argument\n", opt->opt.name); + break; + case required_argument: + if (argv[1] == NULL) + sim_io_eprintf (sd, "Command `%s' requires an argument\n", opt->opt.name); + else if (argv[2] == NULL) + opt->handler (sd, opt->opt.val, argv[1]); + else + sim_io_eprintf (sd, "Command `%s' requires only one argument\n", opt->opt.name); + } + return SIM_RC_OK; + } + } + } + + /* didn't find anything that matched */ + return SIM_RC_FAIL; +} diff --git a/sim/common/sim-options.h b/sim/common/sim-options.h index ea0b21a6a47..f6f4ddedb81 100644 --- a/sim/common/sim-options.h +++ b/sim/common/sim-options.h @@ -27,7 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc., Options for the standalone simulator are parsed by sim_open since sim_open handles the large majority of them and it also parses the - options when invoked by gdb [or any external program]. */ + options when invoked by gdb [or any external program]. + + Per getopt: arg#2 is the option index; arg#3 is the option's + argument, NULL if optional and missing. */ typedef SIM_RC (OPTION_HANDLER) PARAMS ((SIM_DESC, int, char *)); @@ -68,9 +71,8 @@ typedef struct option_list { TABLE is an array of OPTIONS terminated by a NULL `opt.name' entry. */ SIM_RC sim_add_option_table PARAMS ((SIM_DESC sd, const OPTION *table)); -/* Initialize common parts before argument processing. - Called by sim_open. */ -SIM_RC sim_pre_argv_init PARAMS ((SIM_DESC sd, const char *myname)); +/* Install handler for the standard options. */ +MODULE_INSTALL_FN standard_install; /* Called by sim_open to parse the arguments. */ SIM_RC sim_parse_args PARAMS ((SIM_DESC sd, char **argv)); @@ -78,4 +80,8 @@ SIM_RC sim_parse_args PARAMS ((SIM_DESC sd, char **argv)); /* Print help messages for the options. */ void sim_print_help PARAMS ((SIM_DESC sd)); +/* Try to parse the command as if it is an option, Only fail when + totally unsuccessful */ +SIM_RC sim_args_command PARAMS ((SIM_DESC sd, char *cmd)); + #endif /* SIM_OPTIONS_H */ diff --git a/sim/tic80/ChangeLog b/sim/tic80/ChangeLog index 60761cecce7..02730c34493 100644 --- a/sim/tic80/ChangeLog +++ b/sim/tic80/ChangeLog @@ -1,3 +1,8 @@ +Thu May 8 14:07:16 1997 Andrew Cagney + + * sim-calls.c (sim_do_command): Implement. + (sim_store_register): Fix typo T2H v H2T. + Wed May 7 11:48:55 1997 Andrew Cagney * cpu.h (TRACE_FPU2, TRACE_FPU3, TRACE_FPU2I): Add. diff --git a/sim/tic80/sim-calls.c b/sim/tic80/sim-calls.c index cf8e2e9be30..23b38601126 100644 --- a/sim/tic80/sim-calls.c +++ b/sim/tic80/sim-calls.c @@ -201,7 +201,7 @@ sim_store_register (SIM_DESC sd, int regnr, unsigned char *buf) else if (regnr == NPC_REGNUM) STATE_CPU (sd, 0)->cia.dp = T2H_4 (*(unsigned32*)buf); else if (regnr == A0_REGNUM && regnr <= An_REGNUM) - STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM] = H2T_8 (*(unsigned64*)buf); + STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM] = T2H_8 (*(unsigned64*)buf); else sim_io_error (sd, "sim_fetch_register - unknown register nr %d", regnr); return; @@ -258,7 +258,8 @@ sim_resume (SIM_DESC sd, int step, int siggnal) void sim_do_command (SIM_DESC sd, char *cmd) { - sim_io_error (sd, "sim_do_command - unimplemented"); + if (sim_args_command (sd, cmd) != SIM_RC_OK) + sim_io_eprintf (sd, "Unknown command `%s'\n", cmd); } -- 2.30.2