error: Infrastructure to track locations for error reporting

New struct Location holds a location.  So far, the only location is
LOC_NONE, so this doesn't do anything useful yet.

Passing the current location all over the place would be too
cumbersome.  Hide it away in static cur_loc instead, and provide
accessors.  Print it in error_report().

Store it in QError, and print it in qerror_print().

Store it in QemuOpt, for use by qemu_opts_foreach().  This makes
error_report() do the right thing when it runs within
qemu_opts_foreach().

We may still have to store it in other data structures holding user
input for better error messages.  Left for another day.
This commit is contained in:
Markus Armbruster 2010-02-18 19:46:49 +01:00
parent ab5b027ee6
commit 827b08139c
6 changed files with 138 additions and 3 deletions

View file

@ -27,6 +27,7 @@
#include <string.h>
#include "qemu-common.h"
#include "qemu-error.h"
#include "qemu-option.h"
/*
@ -483,6 +484,7 @@ struct QemuOpt {
struct QemuOpts {
char *id;
QemuOptsList *list;
Location loc;
QTAILQ_HEAD(QemuOptHead, QemuOpt) head;
QTAILQ_ENTRY(QemuOpts) next;
};
@ -653,6 +655,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exist
opts->id = qemu_strdup(id);
}
opts->list = list;
loc_save(&opts->loc);
QTAILQ_INIT(&opts->head);
QTAILQ_INSERT_TAIL(&list->head, opts, next);
return opts;
@ -810,13 +813,17 @@ int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc)
int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
int abort_on_failure)
{
Location loc;
QemuOpts *opts;
int rc = 0;
loc_push_none(&loc);
QTAILQ_FOREACH(opts, &list->head, next) {
loc_restore(&opts->loc);
rc |= func(opts, opaque);
if (abort_on_failure && rc != 0)
break;
}
loc_pop(&loc);
return rc;
}