1 /* Simulator option handling.
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "libiberty.h"
34 #include "sim-options.h"
36 #include "sim-assert.h"
40 /* Add a set of options to the simulator.
41 TABLE is an array of OPTIONS terminated by a NULL `opt.name' entry.
42 This is intended to be called by modules in their `install' handler. */
45 sim_add_option_table (SIM_DESC sd, sim_cpu *cpu, const OPTION *table)
47 struct option_list *ol = ((struct option_list *)
48 xmalloc (sizeof (struct option_list)));
50 /* Note: The list is constructed in the reverse order we're called so
51 later calls will override earlier ones (in case that ever happens).
52 This is the intended behaviour. */
56 ol->next = CPU_OPTIONS (cpu);
58 CPU_OPTIONS (cpu) = ol;
62 ol->next = STATE_OPTIONS (sd);
64 STATE_OPTIONS (sd) = ol;
70 /* Standard option table.
71 Modules may specify additional ones.
72 The caller of sim_parse_args may also specify additional options
73 by calling sim_add_option_table first. */
75 static DECLARE_OPTION_HANDLER (standard_option_handler);
77 /* FIXME: We shouldn't print in --help output options that aren't usable.
78 Some fine tuning will be necessary. One can either move less general
79 options to another table or use a HAVE_FOO macro to ifdef out unavailable
82 /* ??? One might want to conditionally compile out the entries that
83 aren't enabled. There's a distinction, however, between options a
84 simulator can't support and options that haven't been configured in.
85 Certainly options a simulator can't support shouldn't appear in the
86 output of --help. Whether the same thing applies to options that haven't
87 been configured in or not isn't something I can get worked up over.
88 [Note that conditionally compiling them out might simply involve moving
89 the option to another table.]
90 If you decide to conditionally compile them out as well, delete this
91 comment and add a comment saying that that is the rule. */
94 OPTION_DEBUG_INSN = OPTION_START,
99 OPTION_ARCHITECTURE_INFO,
103 #if defined (SIM_HAVE_BIENDIAN)
107 #ifdef SIM_HAVE_FLATMEM
111 #ifdef SIM_H8300 /* FIXME: Should be movable to h8300 dir. */
119 static const OPTION standard_options[] =
121 { {"verbose", no_argument, NULL, OPTION_VERBOSE},
122 'v', NULL, "Verbose output",
123 standard_option_handler },
125 #if defined (SIM_HAVE_BIENDIAN) /* ??? && WITH_TARGET_BYTE_ORDER == 0 */
126 { {"endian", required_argument, NULL, OPTION_ENDIAN},
127 'E', "big|little", "Set endianness",
128 standard_option_handler },
131 #ifdef SIM_HAVE_ENVIRONMENT
132 /* This option isn't supported unless all choices are supported in keeping
133 with the goal of not printing in --help output things the simulator can't
134 do [as opposed to things that just haven't been configured in]. */
135 { {"environment", required_argument, NULL, OPTION_ENVIRONMENT},
136 '\0', "user|virtual|operating", "Set running environment",
137 standard_option_handler },
140 { {"alignment", required_argument, NULL, OPTION_ALIGNMENT},
141 '\0', "strict|nonstrict|forced", "Set memory access alignment",
142 standard_option_handler },
144 { {"debug", no_argument, NULL, OPTION_DEBUG},
145 'D', NULL, "Print debugging messages",
146 standard_option_handler },
147 { {"debug-insn", no_argument, NULL, OPTION_DEBUG_INSN},
148 '\0', NULL, "Print instruction debugging messages",
149 standard_option_handler },
150 { {"debug-file", required_argument, NULL, OPTION_DEBUG_FILE},
151 '\0', "FILE NAME", "Specify debugging output file",
152 standard_option_handler },
154 #ifdef SIM_H8300 /* FIXME: Should be movable to h8300 dir. */
155 { {"h8300h", no_argument, NULL, OPTION_H8300},
156 'h', NULL, "Indicate the CPU is h8/300h",
157 standard_option_handler },
158 { {"h8300s", no_argument, NULL, OPTION_H8300S},
159 'S', NULL, "Indicate the CPU is h8/300s",
160 standard_option_handler },
163 #ifdef SIM_HAVE_FLATMEM
164 { {"mem-size", required_argument, NULL, OPTION_MEM_SIZE},
165 'm', "MEMORY SIZE", "Specify memory size",
166 standard_option_handler },
169 { {"do-command", required_argument, NULL, OPTION_DO_COMMAND},
170 '\0', "COMMAND", ""/*undocumented*/,
171 standard_option_handler },
173 { {"help", no_argument, NULL, OPTION_HELP},
174 'H', NULL, "Print help information",
175 standard_option_handler },
177 { {"architecture", required_argument, NULL, OPTION_ARCHITECTURE},
178 '\0', "MACHINE", "Specify the architecture to use",
179 standard_option_handler },
180 { {"architecture-info", no_argument, NULL, OPTION_ARCHITECTURE_INFO},
181 '\0', NULL, "List supported architectures",
182 standard_option_handler },
183 { {"info-architecture", no_argument, NULL, OPTION_ARCHITECTURE_INFO},
185 standard_option_handler },
187 { {"target", required_argument, NULL, OPTION_TARGET},
188 '\0', "BFDNAME", "Specify the object-code format for the object files",
189 standard_option_handler },
191 #ifdef SIM_HANDLES_LMA
192 { {"load-lma", no_argument, NULL, OPTION_LOAD_LMA},
195 "Use VMA or LMA addresses when loading image (default LMA)",
197 "Use VMA or LMA addresses when loading image (default VMA)",
199 standard_option_handler, "load-{lma,vma}" },
200 { {"load-vma", no_argument, NULL, OPTION_LOAD_VMA},
201 '\0', NULL, "", standard_option_handler, "" },
204 { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
208 standard_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
209 char *arg, int is_command)
213 switch ((STANDARD_OPTIONS) opt)
216 STATE_VERBOSE_P (sd) = 1;
219 #ifdef SIM_HAVE_BIENDIAN
221 if (strcmp (arg, "big") == 0)
223 if (WITH_TARGET_BYTE_ORDER == LITTLE_ENDIAN)
225 sim_io_eprintf (sd, "Simulator compiled for little endian only.\n");
228 /* FIXME:wip: Need to set something in STATE_CONFIG. */
229 current_target_byte_order = BIG_ENDIAN;
231 else if (strcmp (arg, "little") == 0)
233 if (WITH_TARGET_BYTE_ORDER == BIG_ENDIAN)
235 sim_io_eprintf (sd, "Simulator compiled for big endian only.\n");
238 /* FIXME:wip: Need to set something in STATE_CONFIG. */
239 current_target_byte_order = LITTLE_ENDIAN;
243 sim_io_eprintf (sd, "Invalid endian specification `%s'\n", arg);
249 case OPTION_ENVIRONMENT:
250 if (strcmp (arg, "user") == 0)
251 STATE_ENVIRONMENT (sd) = USER_ENVIRONMENT;
252 else if (strcmp (arg, "virtual") == 0)
253 STATE_ENVIRONMENT (sd) = VIRTUAL_ENVIRONMENT;
254 else if (strcmp (arg, "operating") == 0)
255 STATE_ENVIRONMENT (sd) = OPERATING_ENVIRONMENT;
258 sim_io_eprintf (sd, "Invalid environment specification `%s'\n", arg);
261 if (WITH_ENVIRONMENT != ALL_ENVIRONMENT
262 && WITH_ENVIRONMENT != STATE_ENVIRONMENT (sd))
265 switch (WITH_ENVIRONMENT)
267 case USER_ENVIRONMENT: type = "user"; break;
268 case VIRTUAL_ENVIRONMENT: type = "virtual"; break;
269 case OPERATING_ENVIRONMENT: type = "operating"; break;
271 sim_io_eprintf (sd, "Simulator compiled for the %s environment only.\n",
277 case OPTION_ALIGNMENT:
278 if (strcmp (arg, "strict") == 0)
280 if (WITH_ALIGNMENT == 0 || WITH_ALIGNMENT == STRICT_ALIGNMENT)
282 current_alignment = STRICT_ALIGNMENT;
286 else if (strcmp (arg, "nonstrict") == 0)
288 if (WITH_ALIGNMENT == 0 || WITH_ALIGNMENT == NONSTRICT_ALIGNMENT)
290 current_alignment = NONSTRICT_ALIGNMENT;
294 else if (strcmp (arg, "forced") == 0)
296 if (WITH_ALIGNMENT == 0 || WITH_ALIGNMENT == FORCED_ALIGNMENT)
298 current_alignment = FORCED_ALIGNMENT;
304 sim_io_eprintf (sd, "Invalid alignment specification `%s'\n", arg);
307 switch (WITH_ALIGNMENT)
309 case STRICT_ALIGNMENT:
310 sim_io_eprintf (sd, "Simulator compiled for strict alignment only.\n");
312 case NONSTRICT_ALIGNMENT:
313 sim_io_eprintf (sd, "Simulator compiled for nonstrict alignment only.\n");
315 case FORCED_ALIGNMENT:
316 sim_io_eprintf (sd, "Simulator compiled for forced alignment only.\n");
323 sim_io_eprintf (sd, "Debugging not compiled in, `-D' ignored\n");
326 for (n = 0; n < MAX_NR_PROCESSORS; ++n)
327 for (i = 0; i < MAX_DEBUG_VALUES; ++i)
328 CPU_DEBUG_FLAGS (STATE_CPU (sd, n))[i] = 1;
332 case OPTION_DEBUG_INSN :
334 sim_io_eprintf (sd, "Debugging not compiled in, `--debug-insn' ignored\n");
337 for (n = 0; n < MAX_NR_PROCESSORS; ++n)
338 CPU_DEBUG_FLAGS (STATE_CPU (sd, n))[DEBUG_INSN_IDX] = 1;
342 case OPTION_DEBUG_FILE :
344 sim_io_eprintf (sd, "Debugging not compiled in, `--debug-file' ignored\n");
347 FILE *f = fopen (arg, "w");
351 sim_io_eprintf (sd, "Unable to open debug output file `%s'\n", arg);
354 for (n = 0; n < MAX_NR_PROCESSORS; ++n)
355 CPU_DEBUG_FILE (STATE_CPU (sd, n)) = f;
359 #ifdef SIM_H8300 /* FIXME: Can be moved to h8300 dir. */
368 #ifdef SIM_HAVE_FLATMEM
369 case OPTION_MEM_SIZE:
371 unsigned long ul = strtol (arg, NULL, 0);
372 /* 16384: some minimal amount */
373 if (! isdigit (arg[0]) || ul < 16384)
375 sim_io_eprintf (sd, "Invalid memory size `%s'", arg);
378 STATE_MEM_SIZE (sd) = ul;
383 case OPTION_DO_COMMAND:
384 sim_do_command (sd, arg);
387 case OPTION_ARCHITECTURE:
389 const struct bfd_arch_info *ap = bfd_scan_arch (arg);
392 sim_io_eprintf (sd, "Architecture `%s' unknown\n", arg);
395 STATE_ARCHITECTURE (sd) = ap;
399 case OPTION_ARCHITECTURE_INFO:
401 const char **list = bfd_arch_list();
405 sim_io_printf (sd, "Possible architectures:");
406 for (lp = list; *lp != NULL; lp++)
407 sim_io_printf (sd, " %s", *lp);
408 sim_io_printf (sd, "\n");
415 STATE_TARGET (sd) = xstrdup (arg);
419 case OPTION_LOAD_LMA:
421 STATE_LOAD_AT_LMA_P (sd) = 1;
425 case OPTION_LOAD_VMA:
427 STATE_LOAD_AT_LMA_P (sd) = 0;
432 sim_print_help (sd, is_command);
433 if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
435 /* FIXME: 'twould be nice to do something similar if gdb. */
442 /* Add the standard option list to the simulator. */
445 standard_install (SIM_DESC sd)
447 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
448 if (sim_add_option_table (sd, NULL, standard_options) != SIM_RC_OK)
450 #ifdef SIM_HANDLES_LMA
451 STATE_LOAD_AT_LMA_P (sd) = SIM_HANDLES_LMA;
456 /* Return non-zero if arg is a duplicate argument.
457 If ARG is NULL, initialize. */
459 #define ARG_HASH_SIZE 97
460 #define ARG_HASH(a) ((256 * (unsigned char) a[0] + (unsigned char) a[1]) % ARG_HASH_SIZE)
467 static char **arg_table = NULL;
471 if (arg_table == NULL)
472 arg_table = (char **) xmalloc (ARG_HASH_SIZE * sizeof (char *));
473 memset (arg_table, 0, ARG_HASH_SIZE * sizeof (char *));
477 hash = ARG_HASH (arg);
478 while (arg_table[hash] != NULL)
480 if (strcmp (arg, arg_table[hash]) == 0)
482 /* We assume there won't be more than ARG_HASH_SIZE arguments so we
483 don't check if the table is full. */
484 if (++hash == ARG_HASH_SIZE)
487 arg_table[hash] = arg;
491 /* Called by sim_open to parse the arguments. */
494 sim_parse_args (sd, argv)
498 int c, i, argc, num_opts;
499 char *p, *short_options;
500 /* The `val' option struct entry is dynamically assigned for options that
501 only come in the long form. ORIG_VAL is used to get the original value
504 struct option *lp, *long_options;
505 const struct option_list *ol;
507 OPTION_HANDLER **handlers;
509 SIM_RC result = SIM_RC_OK;
511 /* Count the number of arguments. */
512 for (argc = 0; argv[argc] != NULL; ++argc)
515 /* Count the number of options. */
517 for (ol = STATE_OPTIONS (sd); ol != NULL; ol = ol->next)
518 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
520 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
521 for (ol = CPU_OPTIONS (STATE_CPU (sd, i)); ol != NULL; ol = ol->next)
522 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
525 /* Initialize duplicate argument checker. */
526 (void) dup_arg_p (NULL);
528 /* Build the option table for getopt. */
530 long_options = NZALLOC (struct option, num_opts + 1);
532 short_options = NZALLOC (char, num_opts * 3 + 1);
534 handlers = NZALLOC (OPTION_HANDLER *, OPTION_START + num_opts);
535 orig_val = NZALLOC (int, OPTION_START + num_opts);
536 opt_cpu = NZALLOC (sim_cpu *, OPTION_START + num_opts);
538 /* Set '+' as first char so argument permutation isn't done. This
539 is done to stop getopt_long returning options that appear after
540 the target program. Such options should be passed unchanged into
541 the program image. */
544 for (i = OPTION_START, ol = STATE_OPTIONS (sd); ol != NULL; ol = ol->next)
545 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
547 if (dup_arg_p (opt->opt.name))
549 if (opt->shortopt != 0)
551 *p++ = opt->shortopt;
552 if (opt->opt.has_arg == required_argument)
554 else if (opt->opt.has_arg == optional_argument)
555 { *p++ = ':'; *p++ = ':'; }
556 handlers[(unsigned char) opt->shortopt] = opt->handler;
557 if (opt->opt.val != 0)
558 orig_val[(unsigned char) opt->shortopt] = opt->opt.val;
560 orig_val[(unsigned char) opt->shortopt] = opt->shortopt;
562 if (opt->opt.name != NULL)
565 /* Dynamically assign `val' numbers for long options. */
567 handlers[lp->val] = opt->handler;
568 orig_val[lp->val] = opt->opt.val;
569 opt_cpu[lp->val] = NULL;
574 for (c = 0; c < MAX_NR_PROCESSORS; ++c)
576 sim_cpu *cpu = STATE_CPU (sd, c);
577 for (ol = CPU_OPTIONS (cpu); ol != NULL; ol = ol->next)
578 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
580 #if 0 /* Each option is prepended with --<cpuname>- so this greatly cuts down
581 on the need for dup_arg_p checking. Maybe in the future it'll be
582 needed so this is just commented out, and not deleted. */
583 if (dup_arg_p (opt->opt.name))
586 /* Don't allow short versions of cpu specific options for now. */
587 if (opt->shortopt != 0)
589 sim_io_eprintf (sd, "internal error, short cpu specific option");
590 result = SIM_RC_FAIL;
593 if (opt->opt.name != NULL)
597 /* Prepend --<cpuname>- to the option. */
598 asprintf (&name, "%s-%s", CPU_NAME (cpu), lp->name);
600 /* Dynamically assign `val' numbers for long options. */
602 handlers[lp->val] = opt->handler;
603 orig_val[lp->val] = opt->opt.val;
604 opt_cpu[lp->val] = cpu;
610 /* Terminate the short and long option lists. */
614 /* Ensure getopt is initialized. */
621 optc = getopt_long (argc, argv, short_options, long_options, &longind);
624 if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
625 STATE_PROG_ARGV (sd) = dupargv (argv + optind);
630 result = SIM_RC_FAIL;
634 if ((*handlers[optc]) (sd, opt_cpu[optc], orig_val[optc], optarg, 0/*!is_command*/) == SIM_RC_FAIL)
636 result = SIM_RC_FAIL;
641 zfree (long_options);
642 zfree (short_options);
649 /* Utility of sim_print_help to print a list of option tables. */
652 print_help (SIM_DESC sd, sim_cpu *cpu, const struct option_list *ol, int is_command)
656 for ( ; ol != NULL; ol = ol->next)
657 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
659 const int indent = 30;
663 if (dup_arg_p (opt->opt.name))
666 if (opt->doc == NULL)
669 if (opt->doc_name != NULL && opt->doc_name [0] == '\0')
672 sim_io_printf (sd, " ");
677 /* list any short options (aliases) for the current OPT */
683 if (o->shortopt != '\0')
685 sim_io_printf (sd, "%s-%c", comma ? ", " : "", o->shortopt);
686 len += (comma ? 2 : 0) + 2;
689 if (o->opt.has_arg == optional_argument)
691 sim_io_printf (sd, "[%s]", o->arg);
692 len += 1 + strlen (o->arg) + 1;
696 sim_io_printf (sd, " %s", o->arg);
697 len += 1 + strlen (o->arg);
704 while (OPTION_VALID_P (o) && o->doc == NULL);
707 /* list any long options (aliases) for the current OPT */
712 const char *cpu_prefix = cpu ? CPU_NAME (cpu) : NULL;
713 if (o->doc_name != NULL)
719 sim_io_printf (sd, "%s%s%s%s%s",
721 is_command ? "" : "--",
722 cpu ? cpu_prefix : "",
725 len += ((comma ? 2 : 0)
726 + (is_command ? 0 : 2)
730 if (o->opt.has_arg == optional_argument)
732 sim_io_printf (sd, "[=%s]", o->arg);
733 len += 2 + strlen (o->arg) + 1;
737 sim_io_printf (sd, " %s", o->arg);
738 len += 1 + strlen (o->arg);
745 while (OPTION_VALID_P (o) && o->doc == NULL);
749 sim_io_printf (sd, "\n%*s", indent, "");
752 sim_io_printf (sd, "%*s", indent - len, "");
754 /* print the description, word wrap long lines */
756 const char *chp = opt->doc;
757 unsigned doc_width = 80 - indent;
758 while (strlen (chp) >= doc_width) /* some slack */
760 const char *end = chp + doc_width - 1;
761 while (end > chp && !isspace (*end))
764 end = chp + doc_width - 1;
765 sim_io_printf (sd, "%.*s\n%*s", end - chp, chp, indent, "");
767 while (isspace (*chp) && *chp != '\0')
770 sim_io_printf (sd, "%s\n", chp);
775 /* Print help messages for the options. */
778 sim_print_help (sd, is_command)
782 if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
783 sim_io_printf (sd, "Usage: %s [options] program [program args]\n",
786 /* Initialize duplicate argument checker. */
787 (void) dup_arg_p (NULL);
789 if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
790 sim_io_printf (sd, "Options:\n");
792 sim_io_printf (sd, "Commands:\n");
794 print_help (sd, NULL, STATE_OPTIONS (sd), is_command);
795 sim_io_printf (sd, "\n");
797 /* Print cpu-specific options. */
801 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
803 sim_cpu *cpu = STATE_CPU (sd, i);
804 if (CPU_OPTIONS (cpu) == NULL)
806 sim_io_printf (sd, "CPU %s specific options:\n", CPU_NAME (cpu));
807 print_help (sd, cpu, CPU_OPTIONS (cpu), is_command);
808 sim_io_printf (sd, "\n");
812 sim_io_printf (sd, "Note: Depending on the simulator configuration some %ss\n",
813 STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE ? "option" : "command");
814 sim_io_printf (sd, " may not be applicable\n");
816 if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
818 sim_io_printf (sd, "\n");
819 sim_io_printf (sd, "program args Arguments to pass to simulated program.\n");
820 sim_io_printf (sd, " Note: Very few simulators support this.\n");
824 /* Utility of sim_args_command to find the closest match for a command.
825 Commands that have "-" in them can be specified as separate words.
826 e.g. sim memory-region 0x800000,0x4000
827 or sim memory region 0x800000,0x4000
828 If CPU is non-null, use its option table list, otherwise use the main one.
829 *PARGI is where to start looking in ARGV. It is updated to point past
832 static const OPTION *
833 find_match (SIM_DESC sd, sim_cpu *cpu, char *argv[], int *pargi)
835 const struct option_list *ol;
837 /* most recent option match */
838 const OPTION *matching_opt = NULL;
839 int matching_argi = -1;
842 ol = CPU_OPTIONS (cpu);
844 ol = STATE_OPTIONS (sd);
846 /* Skip passed elements specified by *PARGI. */
849 for ( ; ol != NULL; ol = ol->next)
850 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
853 const char *name = opt->opt.name;
856 while (argv [argi] != NULL
857 && strncmp (name, argv [argi], strlen (argv [argi])) == 0)
859 name = &name [strlen (argv[argi])];
862 /* leading match ...<a-b-c>-d-e-f - continue search */
863 name ++; /* skip `-' */
867 else if (name [0] == '\0')
869 /* exact match ...<a-b-c-d-e-f> - better than before? */
870 if (argi > matching_argi)
872 matching_argi = argi;
882 *pargi = matching_argi;
887 sim_args_command (SIM_DESC sd, char *cmd)
889 /* something to do? */
891 return SIM_RC_OK; /* FIXME - perhaphs help would be better */
895 /* user specified -<opt> ... form? */
896 char **argv = buildargv (cmd);
897 SIM_RC rc = sim_parse_args (sd, argv);
903 char **argv = buildargv (cmd);
904 const OPTION *matching_opt = NULL;
908 if (argv [0] == NULL)
909 return SIM_RC_OK; /* FIXME - perhaphs help would be better */
911 /* First check for a cpu selector. */
913 char *cpu_name = xstrdup (argv[0]);
914 char *hyphen = strchr (cpu_name, '-');
917 cpu = sim_cpu_lookup (sd, cpu_name);
920 /* If <cpuname>-<command>, point argv[0] at <command>. */
924 argv[0] += hyphen - cpu_name + 1;
928 matching_opt = find_match (sd, cpu, argv, &matching_argi);
929 /* If hyphen found restore argv[0]. */
931 argv[0] -= hyphen - cpu_name + 1;
936 /* If that failed, try the main table. */
937 if (matching_opt == NULL)
940 matching_opt = find_match (sd, NULL, argv, &matching_argi);
943 if (matching_opt != NULL)
945 switch (matching_opt->opt.has_arg)
948 if (argv [matching_argi + 1] == NULL)
949 matching_opt->handler (sd, cpu, matching_opt->opt.val,
950 NULL, 1/*is_command*/);
952 sim_io_eprintf (sd, "Command `%s' takes no arguments\n",
953 matching_opt->opt.name);
955 case optional_argument:
956 if (argv [matching_argi + 1] == NULL)
957 matching_opt->handler (sd, cpu, matching_opt->opt.val,
958 NULL, 1/*is_command*/);
959 else if (argv [matching_argi + 2] == NULL)
960 matching_opt->handler (sd, cpu, matching_opt->opt.val,
961 argv [matching_argi + 1], 1/*is_command*/);
963 sim_io_eprintf (sd, "Command `%s' requires no more than one argument\n",
964 matching_opt->opt.name);
966 case required_argument:
967 if (argv [matching_argi + 1] == NULL)
968 sim_io_eprintf (sd, "Command `%s' requires an argument\n",
969 matching_opt->opt.name);
970 else if (argv [matching_argi + 2] == NULL)
971 matching_opt->handler (sd, cpu, matching_opt->opt.val,
972 argv [matching_argi + 1], 1/*is_command*/);
974 sim_io_eprintf (sd, "Command `%s' requires only one argument\n",
975 matching_opt->opt.name);
984 /* didn't find anything that remotly matched */