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>
This commit is contained in:
Paolo Bonzini 2012-02-14 10:19:53 +01:00 committed by Blue Swirl
parent 0a54a0ce3e
commit 59f971d451
3 changed files with 22 additions and 13 deletions

View File

@ -1072,49 +1072,49 @@ void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
{ {
Error *errp = NULL; Error *errp = NULL;
object_property_set_bool(OBJECT(dev), value, name, &errp); 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) void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value)
{ {
Error *errp = NULL; Error *errp = NULL;
object_property_set_int(OBJECT(dev), value, name, &errp); 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) void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value)
{ {
Error *errp = NULL; Error *errp = NULL;
object_property_set_int(OBJECT(dev), value, name, &errp); 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) void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value)
{ {
Error *errp = NULL; Error *errp = NULL;
object_property_set_int(OBJECT(dev), value, name, &errp); 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) void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value)
{ {
Error *errp = NULL; Error *errp = NULL;
object_property_set_int(OBJECT(dev), value, name, &errp); 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) void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value)
{ {
Error *errp = NULL; Error *errp = NULL;
object_property_set_int(OBJECT(dev), value, name, &errp); 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) void qdev_prop_set_string(DeviceState *dev, const char *name, char *value)
{ {
Error *errp = NULL; Error *errp = NULL;
object_property_set_str(OBJECT(dev), value, name, &errp); 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) 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); assert(!value || value->label);
object_property_set_str(OBJECT(dev), object_property_set_str(OBJECT(dev),
value ? value->label : "", name, &errp); value ? value->label : "", name, &errp);
assert(!errp); assert_no_error(errp);
} }
void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value) 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); assert(!value || value->name);
object_property_set_str(OBJECT(dev), object_property_set_str(OBJECT(dev),
value ? value->name : "", name, &errp); value ? value->name : "", name, &errp);
assert(!errp); assert_no_error(errp);
} }
void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value) void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
{ {
Error *errp = NULL; Error *errp = NULL;
object_property_set_int(OBJECT(dev), value ? value->id : -1, name, &errp); 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) 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]); value[0], value[1], value[2], value[3], value[4], value[5]);
object_property_set_str(OBJECT(dev), str, name, &errp); 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) 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); prop = qdev_prop_find(dev, name);
object_property_set_str(OBJECT(dev), prop->info->enum_table[value], object_property_set_str(OBJECT(dev), prop->info->enum_table[value],
name, &errp); name, &errp);
assert(!errp); assert_no_error(errp);
} }
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) 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) { } else if (props->qtype == QTYPE_QINT) {
object_property_set_int(obj, props->defval, props->name, &errp); object_property_set_int(obj, props->defval, props->name, &errp);
} }
assert(!errp); assert_no_error(errp);
} }
} }

View File

@ -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 * qobject_to_qerror(): Convert a QObject into a QError
*/ */

View File

@ -41,6 +41,7 @@ void qerror_print(QError *qerror);
void qerror_report_internal(const char *file, int linenr, const char *func, void qerror_report_internal(const char *file, int linenr, const char *func,
const char *fmt, ...) GCC_FMT_ATTR(4, 5); const char *fmt, ...) GCC_FMT_ATTR(4, 5);
void qerror_report_err(Error *err); void qerror_report_err(Error *err);
void assert_no_error(Error *err);
QString *qerror_format(const char *fmt, QDict *error); QString *qerror_format(const char *fmt, QDict *error);
#define qerror_report(fmt, ...) \ #define qerror_report(fmt, ...) \
qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__) qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)