aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-02-14 10:19:53 +0100
committerBlue Swirl <blauwirbel@gmail.com>2012-02-14 18:57:33 +0000
commit59f971d451fbabee3194bb565f40846398ee6e6f (patch)
treed775a7dc5f9551b1b8d0e212d11d7091732807b5
parent0a54a0ce3e7659d7804274fcb058154d52fb8d82 (diff)
qdev: print error message before aborting
qdev_prop_set_* functions are always called by machine init functions that should know what they're doing, so they abort on error. Still, an assert(!errp) does not aid debugging. Print an error before aborting. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
-rw-r--r--hw/qdev-properties.c26
-rw-r--r--qerror.c8
-rw-r--r--qerror.h1
3 files changed, 22 insertions, 13 deletions
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 6f09a3568b..7b74dd5beb 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -1072,49 +1072,49 @@ void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
{
Error *errp = NULL;
object_property_set_bool(OBJECT(dev), value, name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value)
{
Error *errp = NULL;
object_property_set_int(OBJECT(dev), value, name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value)
{
Error *errp = NULL;
object_property_set_int(OBJECT(dev), value, name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value)
{
Error *errp = NULL;
object_property_set_int(OBJECT(dev), value, name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value)
{
Error *errp = NULL;
object_property_set_int(OBJECT(dev), value, name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value)
{
Error *errp = NULL;
object_property_set_int(OBJECT(dev), value, name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
void qdev_prop_set_string(DeviceState *dev, const char *name, char *value)
{
Error *errp = NULL;
object_property_set_str(OBJECT(dev), value, name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value)
@@ -1143,7 +1143,7 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valu
assert(!value || value->label);
object_property_set_str(OBJECT(dev),
value ? value->label : "", name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value)
@@ -1152,14 +1152,14 @@ void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *v
assert(!value || value->name);
object_property_set_str(OBJECT(dev),
value ? value->name : "", name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
{
Error *errp = NULL;
object_property_set_int(OBJECT(dev), value ? value->id : -1, name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
@@ -1170,7 +1170,7 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
value[0], value[1], value[2], value[3], value[4], value[5]);
object_property_set_str(OBJECT(dev), str, name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
@@ -1181,7 +1181,7 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
prop = qdev_prop_find(dev, name);
object_property_set_str(OBJECT(dev), prop->info->enum_table[value],
name, &errp);
- assert(!errp);
+ assert_no_error(errp);
}
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
@@ -1213,7 +1213,7 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props)
} else if (props->qtype == QTYPE_QINT) {
object_property_set_int(obj, props->defval, props->name, &errp);
}
- assert(!errp);
+ assert_no_error(errp);
}
}
diff --git a/qerror.c b/qerror.c
index 8e6efafe00..f55d435d11 100644
--- a/qerror.c
+++ b/qerror.c
@@ -572,6 +572,14 @@ void qerror_report_err(Error *err)
}
}
+void assert_no_error(Error *err)
+{
+ if (err) {
+ qerror_report_err(err);
+ abort();
+ }
+}
+
/**
* qobject_to_qerror(): Convert a QObject into a QError
*/
diff --git a/qerror.h b/qerror.h
index e8718bfbab..e26c63598d 100644
--- a/qerror.h
+++ b/qerror.h
@@ -41,6 +41,7 @@ void qerror_print(QError *qerror);
void qerror_report_internal(const char *file, int linenr, const char *func,
const char *fmt, ...) GCC_FMT_ATTR(4, 5);
void qerror_report_err(Error *err);
+void assert_no_error(Error *err);
QString *qerror_format(const char *fmt, QDict *error);
#define qerror_report(fmt, ...) \
qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)