WinDBG/Exts/CodeAnalyzer/gdbplus/gdb-7.7/gdb/python/py-ref.c
/* Called by the Python interpreter to obtain string representation
 of the object.  */
Called by the Python interpreter to obtain string representation
of the object.
Called by the Python interpreter to obtain string representation of the object .
static PyObject *
object_ref_str (PyObject *obj)
{
	object_ref* self = (object_ref*) obj;
	PyObject *args = NULL, *result = NULL;
	PyObject *format = NULL;
	struct symbol* sym;
	address_t sym_addr;
	size_t    sym_size;
	const char* sym_name;
	if (self->ref.storage_type == ENUM_REGISTER)
	{
		const char* reg_name;
		if (!self->ref.where.reg.name)
		{
			struct gdbarch *gdbarch = get_current_arch();
			reg_name = gdbarch_register_name (gdbarch, self->ref.where.reg.reg_num);
		}
		else
			reg_name = self->ref.where.reg.name;
		format = PyString_FromString("[register] thread %d %s=0x%lx");
		args = Py_BuildValue("(isl)", self->ref.where.reg.tid, reg_name, self->ref.value);
	}
	else if (self->ref.storage_type == ENUM_STACK)
	{
		sym = get_stack_sym(&self->ref, &sym_addr, &sym_size);
		if (sym)
			sym_name = SYMBOL_PRINT_NAME (sym);
		else
		{
			sym_name = "";
			sym_addr = self->ref.vaddr;
		}
		format = PyString_FromString("[stack] thread %d  frame %d %s");
		args = Py_BuildValue("(iis)", self->ref.where.stack.tid, self->ref.where.stack.frame, sym_name);
	}
	else if (self->ref.storage_type == ENUM_MODULE_TEXT || self->ref.storage_type == ENUM_MODULE_DATA)
	{
		sym = get_global_sym(&self->ref, &sym_addr, &sym_size);
		if (sym)
			sym_name = SYMBOL_PRINT_NAME (sym);
		else
		{
			sym_name = "unknown";
			sym_addr = self->ref.vaddr;
		}
		format = PyString_FromString("[.text/.data] %s %s");
		args = Py_BuildValue("(ss)", self->ref.where.module.name, sym_name);
	}
	else if (self->ref.storage_type == ENUM_HEAP)
	{
		if (self->ref.where.heap.inuse)
		{
			struct type* type = get_heap_object_type(&self->ref);
			const char* type_name;
			if (type && type_name_no_tag(type))
				type_name = type_name_no_tag(type);
			else
				type_name = "unknown";
			format = PyString_FromString("[heap block] 0x%lx--0x%lx size=%ld (type=\"%s\")");
			args = Py_BuildValue("(llls)", self->ref.where.heap.addr,
							self->ref.where.heap.addr + self->ref.where.heap.size,
							self->ref.where.heap.size, type_name);
		}
		else
		{
			format = PyString_FromString("[heap block] 0x%lx--0x%lx size=%ld free");
			args = Py_BuildValue("(lll)", self->ref.where.heap.addr,
							self->ref.where.heap.addr + self->ref.where.heap.size,
							self->ref.where.heap.size);
		}
	}
	else
	{
		format = PyString_FromString("[unknown] 0x%lx");
		args = Py_BuildValue("(l)", self->ref.vaddr);
	}
	if (self->ref.target_index >= 0 && self->ref.value && format && args)
	{
		PyObject* target_format = PyString_FromString(" 0x%lx: 0x%lx");
		int pos = PyTuple_Size(args);
		PyString_Concat(&format, target_format);
		if (_PyTuple_Resize(&args, pos+2) == 0)
		{
			PyTuple_SET_ITEM(args, pos, Py_BuildValue("l", self->ref.vaddr));
			PyTuple_SET_ITEM(args, pos+1, Py_BuildValue("l", self->ref.value));
		}
		Py_DECREF(target_format);
	}
	if (format == NULL || args == NULL)
		return NULL;
	else
		result = PyString_Format(format, args);
	Py_DECREF(format);
	Py_DECREF(args);
	return result;
}
static PyObject * object_ref_str ( PyObject * obj ) { object_ref * self = ( object_ref * ) obj ; PyObject * args = NULL , * result = NULL ; PyObject * format = NULL ; struct symbol * sym ; address_t sym_addr ; size_t sym_size ; const char * sym_name ; if ( self -> ref . storage_type == ENUM_REGISTER ) { const char * reg_name ; if ( ! self -> ref . where . reg . name ) { struct gdbarch * gdbarch = get_current_arch ( ) ; reg_name = gdbarch_register_name ( gdbarch , self -> ref . where . reg . reg_num ) ; } else reg_name = self -> ref . where . reg . name ; format = PyString_FromString ( " " ) ; args = Py_BuildValue ( " " , self -> ref . where . reg . tid , reg_name , self -> ref . value ) ; } else if ( self -> ref . storage_type == ENUM_STACK ) { sym = get_stack_sym ( & self -> ref , & sym_addr , & sym_size ) ; if ( sym ) sym_name = SYMBOL_PRINT_NAME ( sym ) ; else { sym_name = " " ; sym_addr = self -> ref . vaddr ; } format = PyString_FromString ( " " ) ; args = Py_BuildValue ( " " , self -> ref . where . stack . tid , self -> ref . where . stack . frame , sym_name ) ; } else if ( self -> ref . storage_type == ENUM_MODULE_TEXT || self -> ref . storage_type == ENUM_MODULE_DATA ) { sym = get_global_sym ( & self -> ref , & sym_addr , & sym_size ) ; if ( sym ) sym_name = SYMBOL_PRINT_NAME ( sym ) ; else { sym_name = " " ; sym_addr = self -> ref . vaddr ; } format = PyString_FromString ( " " ) ; args = Py_BuildValue ( " " , self -> ref . where . module . name , sym_name ) ; } else if ( self -> ref . storage_type == ENUM_HEAP ) { if ( self -> ref . where . heap . inuse ) { struct type * type = get_heap_object_type ( & self -> ref ) ; const char * type_name ; if ( type && type_name_no_tag ( type ) ) type_name = type_name_no_tag ( type ) ; else type_name = " " ; format = PyString_FromString ( " \" \" " ) ; args = Py_BuildValue ( " " , self -> ref . where . heap . addr , self -> ref . where . heap . addr + self -> ref . where . heap . size , self -> ref . where . heap . size , type_name ) ; } else { format = PyString_FromString ( " " ) ; args = Py_BuildValue ( " " , self -> ref . where . heap . addr , self -> ref . where . heap . addr + self -> ref . where . heap . size , self -> ref . where . heap . size ) ; } } else { format = PyString_FromString ( " " ) ; args = Py_BuildValue ( " " , self -> ref . vaddr ) ; } if ( self -> ref . target_index >= 0 && self -> ref . value && format && args ) { PyObject * target_format = PyString_FromString ( " " ) ; int pos = PyTuple_Size ( args ) ; PyString_Concat ( & format , target_format ) ; if ( _PyTuple_Resize ( & args , pos + 2 ) == 0 ) { PyTuple_SET_ITEM ( args , pos , Py_BuildValue ( " " , self -> ref . vaddr ) ) ; PyTuple_SET_ITEM ( args , pos + 1 , Py_BuildValue ( " " , self -> ref . value ) ) ; } Py_DECREF ( target_format ) ; } if ( format == NULL || args == NULL ) return NULL ; else result = PyString_Format ( format , args ) ; Py_DECREF ( format ) ; Py_DECREF ( args ) ; return result ; }
Called by the Python interpreter to obtain string representation
of the object.
Called by the Python interpreter to obtain string representation of the object .