error: Track locations on command line

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
This commit is contained in:
Markus Armbruster 2010-02-18 20:13:51 +01:00
parent ef82516d8f
commit 0f0bc3f1d5
3 changed files with 27 additions and 5 deletions

View File

@ -113,6 +113,16 @@ void loc_set_none(void)
cur_loc->kind = LOC_NONE; cur_loc->kind = LOC_NONE;
} }
/*
* 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->num = cnt;
cur_loc->ptr = argv + idx;
}
/* /*
* Change the current location to file FNAME, line LNO. * Change the current location to file FNAME, line LNO.
*/ */
@ -143,12 +153,22 @@ void error_set_progname(const char *argv0)
void error_print_loc(void) void error_print_loc(void)
{ {
const char *sep = ""; const char *sep = "";
int i;
const char *const *argp;
if (!cur_mon) { if (!cur_mon) {
fprintf(stderr, "%s:", progname); fprintf(stderr, "%s:", progname);
sep = " "; sep = " ";
} }
switch (cur_loc->kind) { switch (cur_loc->kind) {
case LOC_CMDLINE:
argp = cur_loc->ptr;
for (i = 0; i < cur_loc->num; i++) {
error_printf("%s%s", sep, argp[i]);
sep = " ";
}
error_printf(": ");
break;
case LOC_FILE: case LOC_FILE:
error_printf("%s:", (const char *)cur_loc->ptr); error_printf("%s:", (const char *)cur_loc->ptr);
if (cur_loc->num) { if (cur_loc->num) {

View File

@ -15,7 +15,7 @@
typedef struct Location { typedef struct Location {
/* all members are private to qemu-error.c */ /* all members are private to qemu-error.c */
enum { LOC_NONE, LOC_FILE } kind; enum { LOC_NONE, LOC_CMDLINE, LOC_FILE } kind;
int num; int num;
const void *ptr; const void *ptr;
struct Location *prev; struct Location *prev;
@ -27,6 +27,7 @@ Location *loc_pop(Location *loc);
Location *loc_save(Location *loc); Location *loc_save(Location *loc);
void loc_restore(Location *loc); void loc_restore(Location *loc);
void loc_set_none(void); 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 loc_set_file(const char *fname, int lno);
void error_vprintf(const char *fmt, va_list ap); void error_vprintf(const char *fmt, va_list ap);

9
vl.c
View File

@ -4796,6 +4796,7 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
char *r = argv[optind]; char *r = argv[optind];
const char *optarg; const char *optarg;
loc_set_cmdline(argv, optind, 1);
optind++; optind++;
/* Treat --foo the same as -foo. */ /* Treat --foo the same as -foo. */
if (r[1] == '-') if (r[1] == '-')
@ -4803,8 +4804,7 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
popt = qemu_options; popt = qemu_options;
for(;;) { for(;;) {
if (!popt->name) { if (!popt->name) {
fprintf(stderr, "%s: invalid option -- '%s'\n", error_report("invalid option");
argv[0], r);
exit(1); exit(1);
} }
if (!strcmp(popt->name, r + 1)) if (!strcmp(popt->name, r + 1))
@ -4813,11 +4813,11 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
} }
if (popt->flags & HAS_ARG) { if (popt->flags & HAS_ARG) {
if (optind >= argc) { if (optind >= argc) {
fprintf(stderr, "%s: option '%s' requires an argument\n", error_report("requires an argument");
argv[0], r);
exit(1); exit(1);
} }
optarg = argv[optind++]; optarg = argv[optind++];
loc_set_cmdline(argv, optind - 2, 2);
} else { } else {
optarg = NULL; optarg = NULL;
} }
@ -5662,6 +5662,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 /* If no data_dir is specified then try to find it relative to the
executable path. */ executable path. */