sim: parse_args: display getopt error ourselves

Fix a long standing todo where we let getopt write directly to stderr
when an invalid option is passed.  Use the sim io funcs instead as they
go through the filtered callbacks that gdb wants.
This commit is contained in:
Mike Frysinger 2016-01-03 21:40:34 -05:00
parent 3726f72c65
commit 77cf2ef5dc
44 changed files with 138 additions and 64 deletions

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* wrapper.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* wrapper.c (sim_target_parse_arg_array): Replace for loop with

View File

@ -819,9 +819,7 @@ sim_open (SIM_OPEN_KIND kind,
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete.

View File

@ -1704,9 +1704,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* TODO: Delete file.

View File

@ -755,9 +755,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback,
e_sim_add_option_table (sd, bfin_mmu_options);
e_sim_add_option_table (sd, bfin_mach_options);
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,9 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* sim-options.c (sim_parse_args): Declare local save_opterr. Save
opterr state to it before calling getopt_long and restore afterwards.
Set opterr to 0. When optc is '?', call sim_io_eprintf.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* hw-device.h (device): Delete commented typedef.

View File

@ -460,7 +460,7 @@ dup_arg_p (const char *arg)
SIM_RC
sim_parse_args (SIM_DESC sd, char **argv)
{
int c, i, argc, num_opts;
int c, i, argc, num_opts, save_opterr;
char *p, *short_options;
/* The `val' option struct entry is dynamically assigned for options that
only come in the long form. ORIG_VAL is used to get the original value
@ -583,6 +583,11 @@ sim_parse_args (SIM_DESC sd, char **argv)
/* Ensure getopt is initialized. */
optind = 0;
/* Do not lot getopt throw errors for us. But don't mess with the state for
any callers higher up by saving/restoring it. */
save_opterr = opterr;
opterr = 0;
while (1)
{
int longind, optc;
@ -596,6 +601,25 @@ sim_parse_args (SIM_DESC sd, char **argv)
}
if (optc == '?')
{
/* If getopt rejects a short option, optopt is set to the bad char.
If it rejects a long option, we have to look at optind. In the
short option case, argv could be multiple short options. */
const char *badopt;
char optbuf[3];
if (optopt)
{
sprintf (optbuf, "-%c", optopt);
badopt = optbuf;
}
else
badopt = argv[optind - 1];
sim_io_eprintf (sd,
"%s: unrecognized option: %s\n"
"Use --help for a complete list of options.\n",
STATE_MY_NAME (sd), badopt);
result = SIM_RC_FAIL;
break;
}
@ -607,6 +631,8 @@ sim_parse_args (SIM_DESC sd, char **argv)
}
}
opterr = save_opterr;
free (long_options);
free (short_options);
free (handlers);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete.

View File

@ -406,9 +406,7 @@ sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *cb, struct bfd *abfd,
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* sim-main.h (cris_devices): Delete.

View File

@ -680,9 +680,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete.

View File

@ -769,9 +769,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* TODO: Delete file.

View File

@ -83,9 +83,7 @@ sim_open (kind, callback, abfd, argv)
augment the meaning of an option. */
sim_add_option_table (sd, NULL, frv_options);
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete.

View File

@ -807,9 +807,7 @@ sim_open (SIM_OPEN_KIND kind,
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* compile.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* config.in, configure: Regenerate.

View File

@ -4859,9 +4859,7 @@ sim_open (SIM_OPEN_KIND kind,
return 0;
}
/* getopt will print the error message so we just have to exit if
this fails. FIXME: Hmmm... in the case of gdb we need getopt
to call print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
/* Uninstall the modules to avoid memory leaks,

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* iq2000-sim.h: Delete file.

View File

@ -82,9 +82,7 @@ sim_open (kind, callback, abfd, argv)
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete.

View File

@ -121,9 +121,7 @@ sim_open (kind, callback, abfd, argv)
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* TODO: Delete file.

View File

@ -84,9 +84,7 @@ sim_open (kind, callback, abfd, argv)
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* sim-main.h (sim_state): Delete devices member.

View File

@ -445,9 +445,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback,
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
/* Uninstall the modules to avoid memory leaks,

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete.

View File

@ -1360,9 +1360,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete.

View File

@ -404,9 +404,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete.

View File

@ -376,9 +376,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
sim_add_option_table (sd, NULL, mips_options);
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
/* Uninstall the modules to avoid memory leaks,

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete.

View File

@ -125,9 +125,7 @@ sim_open (SIM_OPEN_KIND kind,
sim_do_command (sd, "memory region 0,0x100000");
sim_do_command (sd, "memory region 0x40000000,0x200000");
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
/* Uninstall the modules to avoid memory leaks,

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete.

View File

@ -1194,9 +1194,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (count_argc): Delete.

View File

@ -2406,9 +2406,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* sh64-sim.h (GETTWI, SETTWI): Delete unused defines.

View File

@ -79,9 +79,7 @@ sim_open (kind, callback, abfd, argv)
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);

View File

@ -1,3 +1,7 @@
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_open): Update sim_parse_args comment.
2016-01-03 Mike Frysinger <vapier@gentoo.org>
* configure.ac (SIM_AC_OPTION_HOSTENDIAN): Delete.

View File

@ -234,9 +234,7 @@ sim_open (SIM_OPEN_KIND kind,
/* similarly if in the internal RAM region */
sim_do_command (sd, "memory region 0xffe000,0x1000,1024");
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
/* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
/* Uninstall the modules to avoid memory leaks,