WinDBG/Exts/CodeAnalyzer/gdbplus/gdb-7.7/gdb/python/py-ref.c
/*
 * Implementation of gdb.ref()
 * Take at least one argument: object address
 *   2nd argument: object size
 *   3rd argument: search scope
 * Returns a list of gdb.Object_ref objects
 */
Implementation of gdb.ref()
Take at least one argument: object address
2nd argument: object size
3rd argument: search scope
Returns a list of gdb.Object_ref objects
Implementation of gdb . ref () Take at least one argument : object address 2nd argument : object size 3rd argument : search scope Returns a list of gdb . Object_ref objects
PyObject *gdbpy_ref (PyObject *self, PyObject *args)
{
	PyObject *result = NULL;
	address_t obj_addr = 0;
	size_t    obj_size = 1;
	struct CA_LIST* refs;
	int num_args = PyTuple_Size (args);
	PyObject *obj;
	enum storage_type stype = ENUM_UNKNOWN;
	if (num_args < 1 || num_args > 3)
	{
		PyErr_SetString (PyExc_TypeError, _("The function takes at least one argument and three arguments in most: object address, size and scope."));
		return NULL;
	}
	obj = PyTuple_GetItem (args, 0);
	if (PyInt_Check (obj))
		obj_addr = (address_t) PyInt_AsLong (obj);
	else
	{
		PyErr_SetString (PyExc_TypeError, _("Expect an integer of object address as the first parameter"));
		return NULL;
	}
	if (num_args >= 2)
	{
		obj = PyTuple_GetItem (args, 1);
		if (PyInt_Check (obj))
			obj_size = (address_t) PyInt_AsLong (obj);
		else
		{
			PyErr_SetString (PyExc_TypeError, _("Expect an integer of object size as the second parameter"));
			return NULL;
		}
	}
	if (num_args == 3)
	{
		obj = PyTuple_GetItem (args, 2);
		if (PyInt_Check (obj))
			stype = (enum storage_type) PyInt_AsLong (obj);
		else
		{
			PyErr_SetString (PyExc_TypeError, _("Expect an integer of search scope for the third parameter"));
			return NULL;
		}
	}
	if (!update_memory_segments_and_heaps())
	{
		PyErr_SetString (PyExc_MemoryError, _("Failed to read and initialize process's heap segments."));
		return NULL;
	}
	refs = search_object_refs (obj_addr, obj_size, 1, stype);
	if (refs)
	{
		struct object_reference* ref;
		unsigned int n = ca_list_size(refs);
		unsigned int i;
		result = PyList_New(n);
		i = 0;
		ca_list_traverse_start(refs);
		while ( (ref = (struct object_reference*) ca_list_traverse_next(refs)) )
		{
			object_ref* obj_ref = PyObject_New (object_ref, &object_ref_type);
			obj_ref->ref = *ref;
			PyList_SET_ITEM(result, i, (PyObject*)obj_ref);
			i++;
			free (ref);
		}
		ca_list_delete (refs);
	}
	else
	{
		Py_INCREF (Py_None);
		result = Py_None;
	}
	return result;
}
PyObject * gdbpy_ref ( PyObject * self , PyObject * args ) { PyObject * result = NULL ; address_t obj_addr = 0 ; size_t obj_size = 1 ; struct CA_LIST * refs ; int num_args = PyTuple_Size ( args ) ; PyObject * obj ; enum storage_type stype = ENUM_UNKNOWN ; if ( num_args < 1 || num_args > 3 ) { PyErr_SetString ( PyExc_TypeError , _ ( " " ) ) ; return NULL ; } obj = PyTuple_GetItem ( args , 0 ) ; if ( PyInt_Check ( obj ) ) obj_addr = ( address_t ) PyInt_AsLong ( obj ) ; else { PyErr_SetString ( PyExc_TypeError , _ ( " " ) ) ; return NULL ; } if ( num_args >= 2 ) { obj = PyTuple_GetItem ( args , 1 ) ; if ( PyInt_Check ( obj ) ) obj_size = ( address_t ) PyInt_AsLong ( obj ) ; else { PyErr_SetString ( PyExc_TypeError , _ ( " " ) ) ; return NULL ; } } if ( num_args == 3 ) { obj = PyTuple_GetItem ( args , 2 ) ; if ( PyInt_Check ( obj ) ) stype = ( enum storage_type ) PyInt_AsLong ( obj ) ; else { PyErr_SetString ( PyExc_TypeError , _ ( " " ) ) ; return NULL ; } } if ( ! update_memory_segments_and_heaps ( ) ) { PyErr_SetString ( PyExc_MemoryError , _ ( " " ) ) ; return NULL ; } refs = search_object_refs ( obj_addr , obj_size , 1 , stype ) ; if ( refs ) { struct object_reference * ref ; unsigned int n = ca_list_size ( refs ) ; unsigned int i ; result = PyList_New ( n ) ; i = 0 ; ca_list_traverse_start ( refs ) ; while ( ( ref = ( struct object_reference * ) ca_list_traverse_next ( refs ) ) ) { object_ref * obj_ref = PyObject_New ( object_ref , & object_ref_type ) ; obj_ref -> ref = * ref ; PyList_SET_ITEM ( result , i , ( PyObject * ) obj_ref ) ; i ++ ; free ( ref ) ; } ca_list_delete ( refs ) ; } else { Py_INCREF ( Py_None ) ; result = Py_None ; } return result ; }
Implementation of gdb.ref()
 Take at least one argument: object address
   2nd argument: object size
   3rd argument: search scope
 Returns a list of gdb.Object_ref objects
Implementation of gdb . ref () Take at least one argument : object address 2nd argument : object size 3rd argument : search scope Returns a list of gdb . Object_ref objects
// Get the input arguments // The 1st argument is object address // 2nd argument is the object size // 3rd argument is the searching scope // Make sure we have built necessary data structures to do searching // Search for the references // caller is responsible to release the returned list