From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:39965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UamFw-0003vL-R4 for qemu-devel@nongnu.org; Fri, 10 May 2013 08:17:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UamFu-0007k9-Np for qemu-devel@nongnu.org; Fri, 10 May 2013 08:17:00 -0400 Received: from mail-wg0-x232.google.com ([2a00:1450:400c:c00::232]:53630) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UamFu-0007jz-IK for qemu-devel@nongnu.org; Fri, 10 May 2013 08:16:58 -0400 Received: by mail-wg0-f50.google.com with SMTP id m15so3901208wgh.17 for ; Fri, 10 May 2013 05:16:58 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 10 May 2013 14:16:39 +0200 Message-Id: <1368188203-3407-6-git-send-email-pbonzini@redhat.com> In-Reply-To: <1368188203-3407-1-git-send-email-pbonzini@redhat.com> References: <1368188203-3407-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH for-1.5 5/9] qom: trace asserting casts List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Andreas Faerber , Aurelien Jarno , mst@redhat.com This provides a way to detect the cast that leads to a (reproducible) crash even when QOM cast debugging is disabled. Signed-off-by: Paolo Bonzini --- qom/object.c | 10 +++++++++- trace-events | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/qom/object.c b/qom/object.c index bca6219..1b9c5ce 100644 --- a/qom/object.c +++ b/qom/object.c @@ -16,6 +16,7 @@ #include "qapi/string-input-visitor.h" #include "qapi/string-output-visitor.h" #include "qapi/qmp/qerror.h" +#include "trace.h" /* TODO: replace QObject with a simpler visitor to avoid a dependency * of the QOM core on QObject? */ @@ -436,6 +437,9 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename, { Object *inst; + trace_object_dynamic_cast_assert(obj ? obj->class->type->name : "(null)", + typename, file, line, func); + inst = object_dynamic_cast(obj, typename); if (!inst && obj) { @@ -500,8 +504,12 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, const char *file, int line, const char *func) { - ObjectClass *ret = object_class_dynamic_cast(class, typename); + ObjectClass *ret; + + trace_object_class_dynamic_cast_assert(class ? class->type->name : "(null)", + typename, file, line, func); + ret = object_class_dynamic_cast(class, typename); if (!ret && class) { fprintf(stderr, "%s:%d:%s: Object %p is not an instance of type %s\n", file, line, func, class, typename); diff --git a/trace-events b/trace-events index 17d75ab..4413beb 100644 --- a/trace-events +++ b/trace-events @@ -1160,3 +1160,6 @@ kvm_vm_ioctl(int type, void *arg) "type %d, arg %p" kvm_vcpu_ioctl(int cpu_index, int type, void *arg) "cpu_index %d, type %d, arg %p" kvm_run_exit(int cpu_index, uint32_t reason) "cpu_index %d, reason %d" +# qom/object.c +object_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)" +object_class_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)" -- 1.8.1.4