qom: trace asserting casts
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 <pbonzini@redhat.com> Message-id: 1368188203-3407-6-git-send-email-pbonzini@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
		
							parent
							
								
									be17f18b8c
								
							
						
					
					
						commit
						fa131d94a5
					
				
							
								
								
									
										10
									
								
								qom/object.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								qom/object.c
									
									
									
									
									
								
							@ -16,6 +16,7 @@
 | 
				
			|||||||
#include "qapi/string-input-visitor.h"
 | 
					#include "qapi/string-input-visitor.h"
 | 
				
			||||||
#include "qapi/string-output-visitor.h"
 | 
					#include "qapi/string-output-visitor.h"
 | 
				
			||||||
#include "qapi/qmp/qerror.h"
 | 
					#include "qapi/qmp/qerror.h"
 | 
				
			||||||
 | 
					#include "trace.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* TODO: replace QObject with a simpler visitor to avoid a dependency
 | 
					/* TODO: replace QObject with a simpler visitor to avoid a dependency
 | 
				
			||||||
 * of the QOM core on QObject?  */
 | 
					 * of the QOM core on QObject?  */
 | 
				
			||||||
@ -436,6 +437,9 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename,
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    Object *inst;
 | 
					    Object *inst;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    trace_object_dynamic_cast_assert(obj ? obj->class->type->name : "(null)",
 | 
				
			||||||
 | 
					                                     typename, file, line, func);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    inst = object_dynamic_cast(obj, typename);
 | 
					    inst = object_dynamic_cast(obj, typename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!inst && obj) {
 | 
					    if (!inst && obj) {
 | 
				
			||||||
@ -500,8 +504,12 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
 | 
				
			|||||||
                                              const char *file, int line,
 | 
					                                              const char *file, int line,
 | 
				
			||||||
                                              const char *func)
 | 
					                                              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) {
 | 
					    if (!ret && class) {
 | 
				
			||||||
        fprintf(stderr, "%s:%d:%s: Object %p is not an instance of type %s\n",
 | 
					        fprintf(stderr, "%s:%d:%s: Object %p is not an instance of type %s\n",
 | 
				
			||||||
                file, line, func, class, typename);
 | 
					                file, line, func, class, typename);
 | 
				
			||||||
 | 
				
			|||||||
@ -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_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"
 | 
					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)"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user