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. */
118 static const OPTION standard_options[] =
120 { {"verbose", no_argument, NULL, OPTION_VERBOSE},
121 'v', NULL, "Verbose output",
122 standard_option_handler },
124 #if defined (SIM_HAVE_BIENDIAN) /* ??? && WITH_TARGET_BYTE_ORDER == 0 */
125 { {"endian", required_argument, NULL, OPTION_ENDIAN},
126 'E', "big|little", "Set endianness",
127 standard_option_handler },
130 #ifdef SIM_HAVE_ENVIRONMENT
131 /* This option isn't supported unless all choices are supported in keeping
132 with the goal of not printing in --help output things the simulator can't
133 do [as opposed to things that just haven't been configured in]. */
134 { {"environment", required_argument, NULL, OPTION_ENVIRONMENT},
135 '\0', "user|virtual|operating", "Set running environment",
136 standard_option_handler },
139 { {"alignment", required_argument, NULL, OPTION_ALIGNMENT},
140 '\0', "strict|nonstrict|forced", "Set memory access alignment",
141 standard_option_handler },
143 { {"debug", no_argument, NULL, OPTION_DEBUG},
144 'D', NULL, "Print debugging messages",
145 standard_option_handler },
146 { {"debug-insn", no_argument, NULL, OPTION_DEBUG_INSN},
147 '\0', NULL, "Print instruction debugging messages",
148 standard_option_handler },
149 { {"debug-file", required_argument, NULL, OPTION_DEBUG_FILE},
150 '\0', "FILE NAME", "Specify debugging output file",
151 standard_option_handler },
153 #ifdef SIM_H8300 /* FIXME: Should be movable to h8300 dir. */
154 { {"h8300h", no_argument, NULL, OPTION_H8300},
155 'h', NULL, "Indicate the CPU is h8/300h or h8/300s",
156 standard_option_handler },
159 #ifdef SIM_HAVE_FLATMEM
160 { {"mem-size", required_argument, NULL, OPTION_MEM_SIZE},
161 'm', "MEMORY SIZE", "Specify memory size",
162 standard_option_handler },
165 { {"do-command", required_argument, NULL, OPTION_DO_COMMAND},
166 '\0', "COMMAND", ""/*undocumented*/,
167 standard_option_handler },
169 { {"help", no_argument, NULL, OPTION_HELP},
170 'H', NULL, "Print help information",
171 standard_option_handler },
173 { {"architecture", required_argument, NULL, OPTION_ARCHITECTURE},
174 '\0', "MACHINE", "Specify the architecture to use",
175 standard_option_handler },
176 { {"architecture-info", no_argument, NULL, OPTION_ARCHITECTURE_INFO},
177 '\0', NULL, "List supported architectures",
178 standard_option_handler },
179 { {"info-architecture", no_argument, NULL, OPTION_ARCHITECTURE_INFO},
181 standard_option_handler },
183 { {"target", required_argument, NULL, OPTION_TARGET},
184 '\0', "BFDNAME", "Specify the object-code format for the object files",
185 standard_option_handler },
187 #ifdef SIM_HANDLES_LMA
188 { {"load-lma", no_argument, NULL, OPTION_LOAD_LMA},
191 "Use VMA or LMA addresses when loading image (default LMA)",
193 "Use VMA or LMA addresses when loading image (default VMA)",
195 standard_option_handler, "load-{lma,vma}" },
196 { {"load-vma", no_argument, NULL, OPTION_LOAD_VMA},
197 '\0', NULL, "", standard_option_handler, "" },
200 { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
204 standard_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
205 char *arg, int is_command)
209 switch ((STANDARD_OPTIONS) opt)
212 STATE_VERBOSE_P (sd) = 1;
215 #ifdef SIM_HAVE_BIENDIAN
217 if (strcmp (arg, "big") == 0)
219 if (WITH_TARGET_BYTE_ORDER == LITTLE_ENDIAN)
221 sim_io_eprintf (sd, "Simulator compiled for little endian only.\n");
224 /* FIXME:wip: Need to set something in STATE_CONFIG. */
225 current_target_byte_order = BIG_ENDIAN;
227 else if (strcmp (arg, "little") == 0)
229 if (WITH_TARGET_BYTE_ORDER == BIG_ENDIAN)
231 sim_io_eprintf (sd, "Simulator compiled for big endian only.\n");
234 /* FIXME:wip: Need to set something in STATE_CONFIG. */
235 current_target_byte_order = LITTLE_ENDIAN;
239 sim_io_eprintf (sd, "Invalid endian specification `%s'\n", arg);
245 case OPTION_ENVIRONMENT:
246 if (strcmp (arg, "user") == 0)
247 STATE_ENVIRONMENT (sd) = USER_ENVIRONMENT;
248 else if (strcmp (arg, "virtual") == 0)
249 STATE_ENVIRONMENT (sd) = VIRTUAL_ENVIRONMENT;
250 else if (strcmp (arg, "operating") == 0)
251 STATE_ENVIRONMENT (sd) = OPERATING_ENVIRONMENT;
254 sim_io_eprintf (sd, "Invalid environment specification `%s'\n", arg);
257 if (WITH_ENVIRONMENT != ALL_ENVIRONMENT
258 && WITH_ENVIRONMENT != STATE_ENVIRONMENT (sd))
261 switch (WITH_ENVIRONMENT)
263 case USER_ENVIRONMENT: type = "user"; break;
264 case VIRTUAL_ENVIRONMENT: type = "virtual"; break;
265 case OPERATING_ENVIRONMENT: type = "operating"; break;
267 sim_io_eprintf (sd, "Simulator compiled for the %s environment only.\n",
273 case OPTION_ALIGNMENT:
274 if (strcmp (arg, "strict") == 0)
276 if (WITH_ALIGNMENT == 0 || WITH_ALIGNMENT == STRICT_ALIGNMENT)
278 current_alignment = STRICT_ALIGNMENT;
282 else if (strcmp (arg, "nonstrict") == 0)
284 if (WITH_ALIGNMENT == 0 || WITH_ALIGNMENT == NONSTRICT_ALIGNMENT)
286 current_alignment = NONSTRICT_ALIGNMENT;
290 else if (strcmp (arg, "forced") == 0)
292 if (WITH_ALIGNMENT == 0 || WITH_ALIGNMENT == FORCED_ALIGNMENT)
294 current_alignment = FORCED_ALIGNMENT;
300 sim_io_eprintf (sd, "Invalid alignment specification `%s'\n", arg);
303 switch (WITH_ALIGNMENT)
305 case STRICT_ALIGNMENT:
306 sim_io_eprintf (sd, "Simulator compiled for strict alignment only.\n");
308 case NONSTRICT_ALIGNMENT:
309 sim_io_eprintf (sd, "Simulator compiled for nonstrict alignment only.\n");
311 case FORCED_ALIGNMENT:
312 sim_io_eprintf (sd, "Simulator compiled for forced alignment only.\n");
319 sim_io_eprintf (sd, "Debugging not compiled in, `-D' ignored\n");
322 for (n = 0; n < MAX_NR_PROCESSORS; ++n)
323 for (i = 0; i < MAX_DEBUG_VALUES; ++i)
324 CPU_DEBUG_FLAGS (STATE_CPU (sd, n))[i] = 1;
328 case OPTION_DEBUG_INSN :
330 sim_io_eprintf (sd, "Debugging not compiled in, `--debug-insn' ignored\n");
333 for (n = 0; n < MAX_NR_PROCESSORS; ++n)
334 CPU_DEBUG_FLAGS (STATE_CPU (sd, n))[DEBUG_INSN_IDX] = 1;
338 case OPTION_DEBUG_FILE :
340 sim_io_eprintf (sd, "Debugging not compiled in, `--debug-file' ignored\n");
343 FILE *f = fopen (arg, "w");
347 sim_io_eprintf (sd, "Unable to open debug output file `%s'\n", arg);
350 for (n = 0; n < MAX_NR_PROCESSORS; ++n)
351 CPU_DEBUG_FILE (STATE_CPU (sd, n)) = f;
355 #ifdef SIM_H8300 /* FIXME: Can be moved to h8300 dir. */
361 #ifdef SIM_HAVE_FLATMEM
362 case OPTION_MEM_SIZE:
364 unsigned long ul = strtol (arg, NULL, 0);
365 /* 16384: some minimal amount */
366 if (! isdigit (arg[0]) || ul < 16384)
368 sim_io_eprintf (sd, "Invalid memory size `%s'", arg);
371 STATE_MEM_SIZE (sd) = ul;
376 case OPTION_DO_COMMAND:
377 sim_do_command (sd, arg);
380 case OPTION_ARCHITECTURE:
382 const struct bfd_arch_info *ap = bfd_scan_arch (arg);
385 sim_io_eprintf (sd, "Architecture `%s' unknown\n", arg);
388 STATE_ARCHITECTURE (sd) = ap;
392 case OPTION_ARCHITECTURE_INFO:
394 const char **list = bfd_arch_list();
398 sim_io_printf (sd, "Possible architectures:");
399 for (lp = list; *lp != NULL; lp++)
400 sim_io_printf (sd, " %s", *lp);
401 sim_io_printf (sd, "\n");
408 STATE_TARGET (sd) = xstrdup (arg);
412 case OPTION_LOAD_LMA:
414 STATE_LOAD_AT_LMA_P (sd) = 1;
418 case OPTION_LOAD_VMA:
420 STATE_LOAD_AT_LMA_P (sd) = 0;
425 sim_print_help (sd, is_command);
426 if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
428 /* FIXME: 'twould be nice to do something similar if gdb. */
435 /* Add the standard option list to the simulator. */
438 standard_install (SIM_DESC sd)
440 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
441 if (sim_add_option_table (sd, NULL, standard_options) != SIM_RC_OK)
443 #ifdef SIM_HANDLES_LMA
444 STATE_LOAD_AT_LMA_P (sd) = SIM_HANDLES_LMA;
449 /* Return non-zero if arg is a duplicate argument.
450 If ARG is NULL, initialize. */
452 #define ARG_HASH_SIZE 97
453 #define ARG_HASH(a) ((256 * (unsigned char) a[0] + (unsigned char) a[1]) % ARG_HASH_SIZE)
460 static char **arg_table = NULL;
464 if (arg_table == NULL)
465 arg_table = (char **) xmalloc (ARG_HASH_SIZE * sizeof (char *));
466 memset (arg_table, 0, ARG_HASH_SIZE * sizeof (char *));
470 hash = ARG_HASH (arg);
471 while (arg_table[hash] != NULL)
473 if (strcmp (arg, arg_table[hash]) == 0)
475 /* We assume there won't be more than ARG_HASH_SIZE arguments so we
476 don't check if the table is full. */
477 if (++hash == ARG_HASH_SIZE)
480 arg_table[hash] = arg;
484 /* Called by sim_open to parse the arguments. */
487 sim_parse_args (sd, argv)
491 int c, i, argc, num_opts;
492 char *p, *short_options;
493 /* The `val' option struct entry is dynamically assigned for options that
494 only come in the long form. ORIG_VAL is used to get the original value
497 struct option *lp, *long_options;
498 const struct option_list *ol;
500 OPTION_HANDLER **handlers;
503 /* Count the number of arguments. */
504 for (argc = 0; argv[argc] != NULL; ++argc)
507 /* Count the number of options. */
509 for (ol = STATE_OPTIONS (sd); ol != NULL; ol = ol->next)
510 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
512 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
513 for (ol = CPU_OPTIONS (STATE_CPU (sd, i)); ol != NULL; ol = ol->next)
514 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
517 /* Initialize duplicate argument checker. */
518 (void) dup_arg_p (NULL);
520 /* Build the option table for getopt. */
522 long_options = NZALLOC (struct option, num_opts + 1);
524 short_options = NZALLOC (char, num_opts * 3 + 1);
526 handlers = NZALLOC (OPTION_HANDLER *, OPTION_START + num_opts);
527 orig_val = NZALLOC (int, OPTION_START + num_opts);
528 opt_cpu = NZALLOC (sim_cpu *, OPTION_START + num_opts);
530 /* Set '+' as first char so argument permutation isn't done. This
531 is done to stop getopt_long returning options that appear after
532 the target program. Such options should be passed unchanged into
533 the program image. */
536 for (i = OPTION_START, ol = STATE_OPTIONS (sd); ol != NULL; ol = ol->next)
537 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
539 if (dup_arg_p (opt->opt.name))
541 if (opt->shortopt != 0)
543 *p++ = opt->shortopt;
544 if (opt->opt.has_arg == required_argument)
546 else if (opt->opt.has_arg == optional_argument)
547 { *p++ = ':'; *p++ = ':'; }
548 handlers[(unsigned char) opt->shortopt] = opt->handler;
549 if (opt->opt.val != 0)
550 orig_val[(unsigned char) opt->shortopt] = opt->opt.val;
552 orig_val[(unsigned char) opt->shortopt] = opt->shortopt;
554 if (opt->opt.name != NULL)
557 /* Dynamically assign `val' numbers for long options. */
559 handlers[lp->val] = opt->handler;
560 orig_val[lp->val] = opt->opt.val;
561 opt_cpu[lp->val] = NULL;
566 for (c = 0; c < MAX_NR_PROCESSORS; ++c)
568 sim_cpu *cpu = STATE_CPU (sd, c);
569 for (ol = CPU_OPTIONS (cpu); ol != NULL; ol = ol->next)
570 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
572 #if 0 /* Each option is prepended with --<cpuname>- so this greatly cuts down
573 on the need for dup_arg_p checking. Maybe in the future it'll be
574 needed so this is just commented out, and not deleted. */
575 if (dup_arg_p (opt->opt.name))
578 /* Don't allow short versions of cpu specific options for now. */
579 if (opt->shortopt != 0)
581 sim_io_eprintf (sd, "internal error, short cpu specific option");
584 if (opt->opt.name != NULL)
588 /* Prepend --<cpuname>- to the option. */
589 asprintf (&name, "%s-%s", CPU_NAME (cpu), lp->name);
591 /* Dynamically assign `val' numbers for long options. */
593 handlers[lp->val] = opt->handler;
594 orig_val[lp->val] = opt->opt.val;
595 opt_cpu[lp->val] = cpu;
601 /* Terminate the short and long option lists. */
605 /* Ensure getopt is initialized. */
612 optc = getopt_long (argc, argv, short_options, long_options, &longind);
615 if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
616 STATE_PROG_ARGV (sd) = dupargv (argv + optind);
622 if ((*handlers[optc]) (sd, opt_cpu[optc], orig_val[optc], optarg, 0/*!is_command*/) == SIM_RC_FAIL)
629 /* Utility of sim_print_help to print a list of option tables. */
632 print_help (SIM_DESC sd, sim_cpu *cpu, const struct option_list *ol, int is_command)
636 for ( ; ol != NULL; ol = ol->next)
637 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
639 const int indent = 30;
643 if (dup_arg_p (opt->opt.name))
646 if (opt->doc == NULL)
649 if (opt->doc_name != NULL && opt->doc_name [0] == '\0')
652 sim_io_printf (sd, " ");
657 /* list any short options (aliases) for the current OPT */
663 if (o->shortopt != '\0')
665 sim_io_printf (sd, "%s-%c", comma ? ", " : "", o->shortopt);
666 len += (comma ? 2 : 0) + 2;
669 if (o->opt.has_arg == optional_argument)
671 sim_io_printf (sd, "[%s]", o->arg);
672 len += 1 + strlen (o->arg) + 1;
676 sim_io_printf (sd, " %s", o->arg);
677 len += 1 + strlen (o->arg);
684 while (OPTION_VALID_P (o) && o->doc == NULL);
687 /* list any long options (aliases) for the current OPT */
692 const char *cpu_prefix = cpu ? CPU_NAME (cpu) : NULL;
693 if (o->doc_name != NULL)
699 sim_io_printf (sd, "%s%s%s%s%s",
701 is_command ? "" : "--",
702 cpu ? cpu_prefix : "",
705 len += ((comma ? 2 : 0)
706 + (is_command ? 0 : 2)
710 if (o->opt.has_arg == optional_argument)
712 sim_io_printf (sd, "[=%s]", o->arg);
713 len += 2 + strlen (o->arg) + 1;
717 sim_io_printf (sd, " %s", o->arg);
718 len += 1 + strlen (o->arg);
725 while (OPTION_VALID_P (o) && o->doc == NULL);
729 sim_io_printf (sd, "\n%*s", indent, "");
732 sim_io_printf (sd, "%*s", indent - len, "");
734 /* print the description, word wrap long lines */
736 const char *chp = opt->doc;
737 unsigned doc_width = 80 - indent;
738 while (strlen (chp) >= doc_width) /* some slack */
740 const char *end = chp + doc_width - 1;
741 while (end > chp && !isspace (*end))
744 end = chp + doc_width - 1;
745 sim_io_printf (sd, "%.*s\n%*s", end - chp, chp, indent, "");
747 while (isspace (*chp) && *chp != '\0')
750 sim_io_printf (sd, "%s\n", chp);
755 /* Print help messages for the options. */
758 sim_print_help (sd, is_command)
762 if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
763 sim_io_printf (sd, "Usage: %s [options] program [program args]\n",
766 /* Initialize duplicate argument checker. */
767 (void) dup_arg_p (NULL);
769 if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
770 sim_io_printf (sd, "Options:\n");
772 sim_io_printf (sd, "Commands:\n");
774 print_help (sd, NULL, STATE_OPTIONS (sd), is_command);
775 sim_io_printf (sd, "\n");
777 /* Print cpu-specific options. */
781 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
783 sim_cpu *cpu = STATE_CPU (sd, i);
784 if (CPU_OPTIONS (cpu) == NULL)
786 sim_io_printf (sd, "CPU %s specific options:\n", CPU_NAME (cpu));
787 print_help (sd, cpu, CPU_OPTIONS (cpu), is_command);
788 sim_io_printf (sd, "\n");
792 sim_io_printf (sd, "Note: Depending on the simulator configuration some %ss\n",
793 STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE ? "option" : "command");
794 sim_io_printf (sd, " may not be applicable\n");
796 if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
798 sim_io_printf (sd, "\n");
799 sim_io_printf (sd, "program args Arguments to pass to simulated program.\n");
800 sim_io_printf (sd, " Note: Very few simulators support this.\n");
804 /* Utility of sim_args_command to find the closest match for a command.
805 Commands that have "-" in them can be specified as separate words.
806 e.g. sim memory-region 0x800000,0x4000
807 or sim memory region 0x800000,0x4000
808 If CPU is non-null, use its option table list, otherwise use the main one.
809 *PARGI is where to start looking in ARGV. It is updated to point past
812 static const OPTION *
813 find_match (SIM_DESC sd, sim_cpu *cpu, char *argv[], int *pargi)
815 const struct option_list *ol;
817 /* most recent option match */
818 const OPTION *matching_opt = NULL;
819 int matching_argi = -1;
822 ol = CPU_OPTIONS (cpu);
824 ol = STATE_OPTIONS (sd);
826 /* Skip passed elements specified by *PARGI. */
829 for ( ; ol != NULL; ol = ol->next)
830 for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
833 const char *name = opt->opt.name;
836 while (argv [argi] != NULL
837 && strncmp (name, argv [argi], strlen (argv [argi])) == 0)
839 name = &name [strlen (argv[argi])];
842 /* leading match ...<a-b-c>-d-e-f - continue search */
843 name ++; /* skip `-' */
847 else if (name [0] == '\0')
849 /* exact match ...<a-b-c-d-e-f> - better than before? */
850 if (argi > matching_argi)
852 matching_argi = argi;
862 *pargi = matching_argi;
867 sim_args_command (SIM_DESC sd, char *cmd)
869 /* something to do? */
871 return SIM_RC_OK; /* FIXME - perhaphs help would be better */
875 /* user specified -<opt> ... form? */
876 char **argv = buildargv (cmd);
877 SIM_RC rc = sim_parse_args (sd, argv);
883 char **argv = buildargv (cmd);
884 const OPTION *matching_opt = NULL;
888 if (argv [0] == NULL)
889 return SIM_RC_OK; /* FIXME - perhaphs help would be better */
891 /* First check for a cpu selector. */
893 char *cpu_name = xstrdup (argv[0]);
894 char *hyphen = strchr (cpu_name, '-');
897 cpu = sim_cpu_lookup (sd, cpu_name);
900 /* If <cpuname>-<command>, point argv[0] at <command>. */
904 argv[0] += hyphen - cpu_name + 1;
908 matching_opt = find_match (sd, cpu, argv, &matching_argi);
909 /* If hyphen found restore argv[0]. */
911 argv[0] -= hyphen - cpu_name + 1;
916 /* If that failed, try the main table. */
917 if (matching_opt == NULL)
920 matching_opt = find_match (sd, NULL, argv, &matching_argi);
923 if (matching_opt != NULL)
925 switch (matching_opt->opt.has_arg)
928 if (argv [matching_argi + 1] == NULL)
929 matching_opt->handler (sd, cpu, matching_opt->opt.val,
930 NULL, 1/*is_command*/);
932 sim_io_eprintf (sd, "Command `%s' takes no arguments\n",
933 matching_opt->opt.name);
935 case optional_argument:
936 if (argv [matching_argi + 1] == NULL)
937 matching_opt->handler (sd, cpu, matching_opt->opt.val,
938 NULL, 1/*is_command*/);
939 else if (argv [matching_argi + 2] == NULL)
940 matching_opt->handler (sd, cpu, matching_opt->opt.val,
941 argv [matching_argi + 1], 1/*is_command*/);
943 sim_io_eprintf (sd, "Command `%s' requires no more than one argument\n",
944 matching_opt->opt.name);
946 case required_argument:
947 if (argv [matching_argi + 1] == NULL)
948 sim_io_eprintf (sd, "Command `%s' requires an argument\n",
949 matching_opt->opt.name);
950 else if (argv [matching_argi + 2] == NULL)
951 matching_opt->handler (sd, cpu, matching_opt->opt.val,
952 argv [matching_argi + 1], 1/*is_command*/);
954 sim_io_eprintf (sd, "Command `%s' requires only one argument\n",
955 matching_opt->opt.name);
964 /* didn't find anything that remotly matched */