WinDBG/Exts/CodeAnalyzer/gdbplus/gdb-7.7/gdb/python/py-ref.c
/* Implementation of gdb.shared_object()
 * Take any number of thread id as input
   Returns a list of gdb.Object_ref objects which are shared by the input threads and the other */
Implementation of gdb.shared_object()
Take any number of thread id as input
Returns a list of gdb.Object_ref objects which are shared by the input threads and the other
Implementation of gdb . shared_object () Take any number of thread id as input Returns a list of gdb . Object_ref objects which are shared by the input threads and the other
PyObject *gdbpy_shared_object (PyObject *self, PyObject *args)
{
	PyObject *result = NULL;
	struct CA_LIST* threads;
	struct CA_LIST* objects;
	int* ptid;
	int i;
	if (!update_memory_segments_and_heaps())
	{
		PyErr_SetString (PyExc_MemoryError, _("Failed to read and initialize process's heap segments."));
		return NULL;
	}
	threads = ca_list_new();
	for (i = 0; i< PyTuple_Size (args); i++)
	{
		PyObject *obj = PyTuple_GetItem (args, i);
		if (PyInt_Check (obj))
		{
			int tid = PyInt_AsLong (obj);
			unsigned int index;
			struct ca_segment* segment;
			int valid_tid = 0;
			for (index=0; index<g_segment_count; index++)
			{
				segment = &g_segments[index];
				if (segment->m_type == ENUM_STACK && segment->m_thread.tid == tid)
				{
					valid_tid = 1;
					break;
				}
			}
			if (valid_tid)
			{
				ptid = (int*) malloc(sizeof(int));
				*ptid = tid;
				ca_list_push_front(threads, ptid);
			}
			else
			{
				PyErr_SetString (PyExc_TypeError, _("Input thread id is invalid."));
				return NULL;
			}
		}
		else
		{
			PyErr_SetString (PyExc_TypeError, _("Expect an integer of thread id."));
			return NULL;
		}
	}
	objects = search_shared_objects_by_threads(threads);
	if (objects)
	{
		struct object_reference* ref;
		unsigned int n = ca_list_size(objects);
		unsigned int i;
		result = PyList_New(n);
		i = 0;
		ca_list_traverse_start(objects);
		while ( (ref = (struct object_reference*) ca_list_traverse_next(objects)) )
		{
			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 (objects);
	}
	else
	{
		Py_INCREF (Py_None);
		result = Py_None;
	}
	ca_list_traverse_start(threads);
	while ( (ptid = (int*) ca_list_traverse_next(threads)))
		free (ptid);
	ca_list_delete(threads);
	return result;
}
PyObject * gdbpy_shared_object ( PyObject * self , PyObject * args ) { PyObject * result = NULL ; struct CA_LIST * threads ; struct CA_LIST * objects ; int * ptid ; int i ; if ( ! update_memory_segments_and_heaps ( ) ) { PyErr_SetString ( PyExc_MemoryError , _ ( " " ) ) ; return NULL ; } threads = ca_list_new ( ) ; for ( i = 0 ; i < PyTuple_Size ( args ) ; i ++ ) { PyObject * obj = PyTuple_GetItem ( args , i ) ; if ( PyInt_Check ( obj ) ) { int tid = PyInt_AsLong ( obj ) ; unsigned int index ; struct ca_segment * segment ; int valid_tid = 0 ; for ( index = 0 ; index < g_segment_count ; index ++ ) { segment = & g_segments [ index ] ; if ( segment -> m_type == ENUM_STACK && segment -> m_thread . tid == tid ) { valid_tid = 1 ; break ; } } if ( valid_tid ) { ptid = ( int * ) malloc ( sizeof ( int ) ) ; * ptid = tid ; ca_list_push_front ( threads , ptid ) ; } else { PyErr_SetString ( PyExc_TypeError , _ ( " " ) ) ; return NULL ; } } else { PyErr_SetString ( PyExc_TypeError , _ ( " " ) ) ; return NULL ; } } objects = search_shared_objects_by_threads ( threads ) ; if ( objects ) { struct object_reference * ref ; unsigned int n = ca_list_size ( objects ) ; unsigned int i ; result = PyList_New ( n ) ; i = 0 ; ca_list_traverse_start ( objects ) ; while ( ( ref = ( struct object_reference * ) ca_list_traverse_next ( objects ) ) ) { 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 ( objects ) ; } else { Py_INCREF ( Py_None ) ; result = Py_None ; } ca_list_traverse_start ( threads ) ; while ( ( ptid = ( int * ) ca_list_traverse_next ( threads ) ) ) free ( ptid ) ; ca_list_delete ( threads ) ; return result ; }
Implementation of gdb.shared_object()
 Take any number of thread id as input
Returns a list of gdb.Object_ref objects which are shared by the input threads and the other
Implementation of gdb . shared_object () Take any number of thread id as input Returns a list of gdb . Object_ref objects which are shared by the input threads and the other
// Make sure we have built necessary data structures to do searching // Get the input parameters // Search for the objects // clean up