Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Private Attributes
libpython.HeapTypeObjectPtr Class Reference
Inheritance diagram for libpython.HeapTypeObjectPtr:
Inheritance graph
[legend]
Collaboration diagram for libpython.HeapTypeObjectPtr:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def get_attr_dict
def proxyval
def write_repr
def field
def pyop_field
def write_field_repr
def get_truncated_repr
def type
def is_null
def is_optimized_out
def safe_tp_name
def subclass_from_type
def from_pyobject_ptr
def get_gdb_type
def as_address

Public Attributes

 tp_name
 address
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Private Attributes

string _typename = 'PyObject'

Detailed Description

Definition at line 444 of file libpython.py.


Member Function Documentation

def libpython.PyObjectPtr.as_address (   self) [inherited]

Definition at line 379 of file libpython.py.

00379 
00380     def as_address(self):
00381         return long(self._gdbval)

Here is the caller graph for this function:

def libpython.PyObjectPtr.field (   self,
  name 
) [inherited]
Get the gdb.Value for the given field within the PyObject, coping with
some python 2 versus python 3 differences.

Various libpython types are defined using the "PyObject_HEAD" and
"PyObject_VAR_HEAD" macros.

In Python 2, this these are defined so that "ob_type" and (for a var
object) "ob_size" are fields of the type in question.

In Python 3, this is defined as an embedded PyVarObject type thus:
   PyVarObject ob_base;
so that the "ob_size" field is located insize the "ob_base" field, and
the "ob_type" is most easily accessed by casting back to a (PyObject*).

Definition at line 157 of file libpython.py.

00157 
00158     def field(self, name):
00159         '''
00160         Get the gdb.Value for the given field within the PyObject, coping with
00161         some python 2 versus python 3 differences.
00162 
00163         Various libpython types are defined using the "PyObject_HEAD" and
00164         "PyObject_VAR_HEAD" macros.
00165 
00166         In Python 2, this these are defined so that "ob_type" and (for a var
00167         object) "ob_size" are fields of the type in question.
00168 
00169         In Python 3, this is defined as an embedded PyVarObject type thus:
00170            PyVarObject ob_base;
00171         so that the "ob_size" field is located insize the "ob_base" field, and
00172         the "ob_type" is most easily accessed by casting back to a (PyObject*).
00173         '''
00174         if self.is_null():
00175             raise NullPyObjectPtr(self)
00176 
00177         if name == 'ob_type':
00178             pyo_ptr = self._gdbval.cast(PyObjectPtr.get_gdb_type())
00179             return pyo_ptr.dereference()[name]
00180 
00181         if name == 'ob_size':
00182             pyo_ptr = self._gdbval.cast(PyVarObjectPtr.get_gdb_type())
00183             return pyo_ptr.dereference()[name]
00184 
00185         # General case: look it up inside the object:
00186         return self._gdbval.dereference()[name]

Here is the call graph for this function:

Here is the caller graph for this function:

def libpython.PyObjectPtr.from_pyobject_ptr (   cls,
  gdbval 
) [inherited]
Try to locate the appropriate derived class dynamically, and cast
the pointer accordingly.

Definition at line 360 of file libpython.py.

00360 
00361     def from_pyobject_ptr(cls, gdbval):
00362         '''
00363         Try to locate the appropriate derived class dynamically, and cast
00364         the pointer accordingly.
00365         '''
00366         try:
00367             p = PyObjectPtr(gdbval)
00368             cls = cls.subclass_from_type(p.type())
00369             return cls(gdbval, cast_to=cls.get_gdb_type())
00370         except RuntimeError:
00371             # Handle any kind of error e.g. NULL ptrs by simply using the base
00372             # class
00373             pass
00374         return cls(gdbval)

Get the PyDictObject ptr representing the attribute dictionary
(or None if there's a problem)

Definition at line 447 of file libpython.py.

00447 
00448     def get_attr_dict(self):
00449         '''
00450         Get the PyDictObject ptr representing the attribute dictionary
00451         (or None if there's a problem)
00452         '''
00453         try:
00454             typeobj = self.type()
00455             dictoffset = int_from_int(typeobj.field('tp_dictoffset'))
00456             if dictoffset != 0:
00457                 if dictoffset < 0:
00458                     type_PyVarObject_ptr = gdb.lookup_type('PyVarObject').pointer()
00459                     tsize = int_from_int(self._gdbval.cast(type_PyVarObject_ptr)['ob_size'])
00460                     if tsize < 0:
00461                         tsize = -tsize
00462                     size = _PyObject_VAR_SIZE(typeobj, tsize)
00463                     dictoffset += size
00464                     assert dictoffset > 0
00465                     assert dictoffset % SIZEOF_VOID_P == 0
00466 
00467                 dictptr = self._gdbval.cast(_type_char_ptr) + dictoffset
00468                 PyObjectPtrPtr = PyObjectPtr.get_gdb_type().pointer()
00469                 dictptr = dictptr.cast(PyObjectPtrPtr)
00470                 return PyObjectPtr.from_pyobject_ptr(dictptr.dereference())
00471         except RuntimeError:
00472             # Corrupt data somewhere; fail safe
00473             pass
00474 
00475         # Not found, or some kind of error:
00476         return None

Here is the call graph for this function:

Here is the caller graph for this function:

def libpython.PyObjectPtr.get_gdb_type (   cls) [inherited]

Definition at line 376 of file libpython.py.

00376 
00377     def get_gdb_type(cls):
00378         return gdb.lookup_type(cls._typename).pointer()

def libpython.PyObjectPtr.get_truncated_repr (   self,
  maxlen 
) [inherited]
Get a repr-like string for the data, but truncate it at "maxlen" bytes
(ending the object graph traversal as soon as you do)

Definition at line 202 of file libpython.py.

00202 
00203     def get_truncated_repr(self, maxlen):
00204         '''
00205         Get a repr-like string for the data, but truncate it at "maxlen" bytes
00206         (ending the object graph traversal as soon as you do)
00207         '''
00208         out = TruncatedStringIO(maxlen)
00209         try:
00210             self.write_repr(out, set())
00211         except StringTruncated:
00212             # Truncation occurred:
00213             return out.getvalue() + '...(truncated)'
00214 
00215         # No truncation occurred:
00216         return out.getvalue()

Here is the call graph for this function:

def libpython.PyObjectPtr.is_null (   self) [inherited]

Definition at line 220 of file libpython.py.

00220 
00221     def is_null(self):
00222         return 0 == long(self._gdbval)

Here is the caller graph for this function:

def libpython.PyObjectPtr.is_optimized_out (   self) [inherited]
Is the value of the underlying PyObject* visible to the debugger?

This can vary with the precise version of the compiler used to build
Python, and the precise version of gdb.

See e.g. https://bugzilla.redhat.com/show_bug.cgi?id=556975 with
PyEval_EvalFrameEx's "f"

Definition at line 223 of file libpython.py.

00223 
00224     def is_optimized_out(self):
00225         '''
00226         Is the value of the underlying PyObject* visible to the debugger?
00227 
00228         This can vary with the precise version of the compiler used to build
00229         Python, and the precise version of gdb.
00230 
00231         See e.g. https://bugzilla.redhat.com/show_bug.cgi?id=556975 with
00232         PyEval_EvalFrameEx's "f"
00233         '''
00234         return self._gdbval.is_optimized_out

Here is the caller graph for this function:

def libpython.HeapTypeObjectPtr.proxyval (   self,
  visited 
)
Support for new-style classes.

Currently we just locate the dictionary using a transliteration to
python of _PyObject_GetDictPtr, ignoring descriptors

Reimplemented from libpython.PyObjectPtr.

Definition at line 477 of file libpython.py.

00477 
00478     def proxyval(self, visited):
00479         '''
00480         Support for new-style classes.
00481 
00482         Currently we just locate the dictionary using a transliteration to
00483         python of _PyObject_GetDictPtr, ignoring descriptors
00484         '''
00485         # Guard against infinite loops:
00486         if self.as_address() in visited:
00487             return ProxyAlreadyVisited('<...>')
00488         visited.add(self.as_address())
00489 
00490         pyop_attr_dict = self.get_attr_dict()
00491         if pyop_attr_dict:
00492             attr_dict = pyop_attr_dict.proxyval(visited)
00493         else:
00494             attr_dict = {}
00495         tp_name = self.safe_tp_name()
00496 
00497         # New-style class:
00498         return InstanceProxy(tp_name, attr_dict, long(self._gdbval))

Here is the call graph for this function:

def libpython.PyObjectPtr.pyop_field (   self,
  name 
) [inherited]
Get a PyObjectPtr for the given PyObject* field within this PyObject,
coping with some python 2 versus python 3 differences.

Definition at line 187 of file libpython.py.

00187 
00188     def pyop_field(self, name):
00189         '''
00190         Get a PyObjectPtr for the given PyObject* field within this PyObject,
00191         coping with some python 2 versus python 3 differences.
00192         '''
00193         return PyObjectPtr.from_pyobject_ptr(self.field(name))

Here is the call graph for this function:

Here is the caller graph for this function:

def libpython.PyObjectPtr.safe_tp_name (   self) [inherited]

Definition at line 235 of file libpython.py.

00235 
00236     def safe_tp_name(self):
00237         try:
00238             return self.type().field('tp_name').string()
00239         except NullPyObjectPtr:
00240             # NULL tp_name?
00241             return 'unknown'
00242         except RuntimeError:
00243             # Can't even read the object at all?
00244             return 'unknown'

Here is the call graph for this function:

Here is the caller graph for this function:

def libpython.PyObjectPtr.subclass_from_type (   cls,
  t 
) [inherited]
Given a PyTypeObjectPtr instance wrapping a gdb.Value that's a
(PyTypeObject*), determine the corresponding subclass of PyObjectPtr
to use

Ideally, we would look up the symbols for the global types, but that
isn't working yet:
  (gdb) python print gdb.lookup_symbol('PyList_Type')[0].value
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  NotImplementedError: Symbol type not yet supported in Python scripts.
  Error while executing Python code.

For now, we use tp_flags, after doing some string comparisons on the
tp_name for some special-cases that don't seem to be visible through
flags

Definition at line 295 of file libpython.py.

00295 
00296     def subclass_from_type(cls, t):
00297         '''
00298         Given a PyTypeObjectPtr instance wrapping a gdb.Value that's a
00299         (PyTypeObject*), determine the corresponding subclass of PyObjectPtr
00300         to use
00301 
00302         Ideally, we would look up the symbols for the global types, but that
00303         isn't working yet:
00304           (gdb) python print gdb.lookup_symbol('PyList_Type')[0].value
00305           Traceback (most recent call last):
00306             File "<string>", line 1, in <module>
00307           NotImplementedError: Symbol type not yet supported in Python scripts.
00308           Error while executing Python code.
00309 
00310         For now, we use tp_flags, after doing some string comparisons on the
00311         tp_name for some special-cases that don't seem to be visible through
00312         flags
00313         '''
00314         try:
00315             tp_name = t.field('tp_name').string()
00316             tp_flags = int(t.field('tp_flags'))
00317         except RuntimeError:
00318             # Handle any kind of error e.g. NULL ptrs by simply using the base
00319             # class
00320             return cls
00321 
00322         #print 'tp_flags = 0x%08x' % tp_flags
00323         #print 'tp_name = %r' % tp_name
00324 
00325         name_map = {'bool': PyBoolObjectPtr,
00326                     'classobj': PyClassObjectPtr,
00327                     'instance': PyInstanceObjectPtr,
00328                     'NoneType': PyNoneStructPtr,
00329                     'frame': PyFrameObjectPtr,
00330                     'set' : PySetObjectPtr,
00331                     'frozenset' : PySetObjectPtr,
00332                     'builtin_function_or_method' : PyCFunctionObjectPtr,
00333                     }
00334         if tp_name in name_map:
00335             return name_map[tp_name]
00336 
00337         if tp_flags & Py_TPFLAGS_HEAPTYPE:
00338             return HeapTypeObjectPtr
00339 
00340         if tp_flags & Py_TPFLAGS_LONG_SUBCLASS:
00341             return PyLongObjectPtr
00342         if tp_flags & Py_TPFLAGS_LIST_SUBCLASS:
00343             return PyListObjectPtr
00344         if tp_flags & Py_TPFLAGS_TUPLE_SUBCLASS:
00345             return PyTupleObjectPtr
00346         if tp_flags & Py_TPFLAGS_BYTES_SUBCLASS:
00347             return PyBytesObjectPtr
00348         if tp_flags & Py_TPFLAGS_UNICODE_SUBCLASS:
00349             return PyUnicodeObjectPtr
00350         if tp_flags & Py_TPFLAGS_DICT_SUBCLASS:
00351             return PyDictObjectPtr
00352         if tp_flags & Py_TPFLAGS_BASE_EXC_SUBCLASS:
00353             return PyBaseExceptionObjectPtr
00354         #if tp_flags & Py_TPFLAGS_TYPE_SUBCLASS:
00355         #    return PyTypeObjectPtr
00356 
00357         # Use the base class:
00358         return cls

def libpython.PyObjectPtr.type (   self) [inherited]

Definition at line 217 of file libpython.py.

00217 
00218     def type(self):
00219         return PyTypeObjectPtr(self.field('ob_type'))

Here is the call graph for this function:

Here is the caller graph for this function:

def libpython.PyObjectPtr.write_field_repr (   self,
  name,
  out,
  visited 
) [inherited]
Extract the PyObject* field named "name", and write its representation
to file-like object "out"

Definition at line 194 of file libpython.py.

00194 
00195     def write_field_repr(self, name, out, visited):
00196         '''
00197         Extract the PyObject* field named "name", and write its representation
00198         to file-like object "out"
00199         '''
00200         field_obj = self.pyop_field(name)
00201         field_obj.write_repr(out, visited)

Here is the call graph for this function:

Here is the caller graph for this function:

def libpython.HeapTypeObjectPtr.write_repr (   self,
  out,
  visited 
)
Write a string representation of the value scraped from the inferior
process to "out", a file-like object.

Reimplemented from libpython.PyObjectPtr.

Definition at line 499 of file libpython.py.

00499 
00500     def write_repr(self, out, visited):
00501         # Guard against infinite loops:
00502         if self.as_address() in visited:
00503             out.write('<...>')
00504             return
00505         visited.add(self.as_address())
00506 
00507         pyop_attrdict = self.get_attr_dict()
00508         _write_instance_repr(out, visited,
00509                              self.safe_tp_name(), pyop_attrdict, self.as_address())

Here is the call graph for this function:


Member Data Documentation

Reimplemented from libpython.PyObjectPtr.

Definition at line 445 of file libpython.py.

Definition at line 271 of file libpython.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 270 of file libpython.py.


The documentation for this class was generated from the following file: