New LOC_CMDLINE. Use it for tracking option with argument in lookup_opt(). We now report errors like this
qemu: -device smbus-eeprom: Did not find I2C bus for smbus-eeprom Signed-off-by: Markus Armbruster <arm...@redhat.com> --- qemu-error.c | 20 ++++++++++++++++++++ qemu-error.h | 3 ++- vl.c | 9 +++++---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/qemu-error.c b/qemu-error.c index 5debb71..a726d32 100644 --- a/qemu-error.c +++ b/qemu-error.c @@ -114,6 +114,16 @@ void loc_set_none(void) } /* + * Change the current location to argument ARGV[IDX..IDX+CNT-1]. + */ +void loc_set_cmdline(char **argv, int idx, int cnt) +{ + cur_loc->kind = LOC_CMDLINE; + cur_loc->n = cnt; + cur_loc->ptr = argv + idx; +} + +/* * Change the current location to file FNAME, line LNO. */ void loc_set_file(const char *fname, int lno) @@ -143,12 +153,22 @@ void error_set_progname(const char *argv0) void error_print_loc(void) { const char *sep = ""; + int i; + const char *const *argp; if (!cur_mon) { fprintf(stderr, "%s:", progname); sep = " "; } switch (cur_loc->kind) { + case LOC_CMDLINE: + argp = cur_loc->ptr; + for (i = 0; i < cur_loc->n; i++) { + error_printf("%s%s", sep, argp[i]); + sep = " "; + } + error_printf(": "); + break; case LOC_FILE: error_printf("%s:", (const char *)cur_loc->ptr); if (cur_loc->n) { diff --git a/qemu-error.h b/qemu-error.h index 32b54e1..75bc4bf 100644 --- a/qemu-error.h +++ b/qemu-error.h @@ -15,7 +15,7 @@ typedef struct Location { /* all members are private to qemu-error.c */ - enum { LOC_NONE, LOC_FILE } kind; + enum { LOC_NONE, LOC_CMDLINE, LOC_FILE } kind; int n; const void *ptr; struct Location *prev; @@ -27,6 +27,7 @@ Location *loc_pop(Location *loc); Location *loc_save(Location *loc); void loc_restore(Location *loc); void loc_set_none(void); +void loc_set_cmdline(char **argv, int idx, int cnt); void loc_set_file(const char *fname, int lno); void error_vprintf(const char *fmt, va_list ap); diff --git a/vl.c b/vl.c index 83e3b82..fa2898d 100644 --- a/vl.c +++ b/vl.c @@ -4756,6 +4756,7 @@ static const QEMUOption *lookup_opt(int argc, char **argv, char *r = argv[optind]; const char *optarg; + loc_set_cmdline(argv, optind, 1); optind++; /* Treat --foo the same as -foo. */ if (r[1] == '-') @@ -4763,8 +4764,7 @@ static const QEMUOption *lookup_opt(int argc, char **argv, popt = qemu_options; for(;;) { if (!popt->name) { - fprintf(stderr, "%s: invalid option -- '%s'\n", - argv[0], r); + qemu_error("invalid option"); exit(1); } if (!strcmp(popt->name, r + 1)) @@ -4773,11 +4773,11 @@ static const QEMUOption *lookup_opt(int argc, char **argv, } if (popt->flags & HAS_ARG) { if (optind >= argc) { - fprintf(stderr, "%s: option '%s' requires an argument\n", - argv[0], r); + qemu_error("requires an argument"); exit(1); } optarg = argv[optind++]; + loc_set_cmdline(argv, optind - 2, 2); } else { optarg = NULL; } @@ -5614,6 +5614,7 @@ int main(int argc, char **argv, char **envp) } } } + loc_set_none(); /* If no data_dir is specified then try to find it relative to the executable path. */ -- 1.6.6