Back to index

python3.2  3.2.2
Classes | Functions | Variables
libpython Namespace Reference

Classes

class  NullPyObjectPtr
class  StringTruncated
class  TruncatedStringIO
class  PyObjectPtr
class  PyVarObjectPtr
class  ProxyAlreadyVisited
class  InstanceProxy
class  HeapTypeObjectPtr
class  ProxyException
class  PyBaseExceptionObjectPtr
class  PyClassObjectPtr
class  BuiltInFunctionProxy
class  BuiltInMethodProxy
class  PyCFunctionObjectPtr
class  PyCodeObjectPtr
class  PyDictObjectPtr
class  PyInstanceObjectPtr
class  PyListObjectPtr
class  PyLongObjectPtr
class  PyBoolObjectPtr
class  PyNoneStructPtr
class  PyFrameObjectPtr
class  PySetObjectPtr
class  PyBytesObjectPtr
class  PyTupleObjectPtr
class  PyTypeObjectPtr
class  PyUnicodeObjectPtr
class  PyObjectPtrPrinter
class  Frame
class  PyList
class  PyUp
class  PyDown
class  PyBacktraceFull
class  PyBacktrace
class  PyPrint
class  PyLocals

Functions

def safety_limit
def safe_range
def write_unicode
def os_fsencode
def _write_instance_repr
def _PyObject_VAR_SIZE
def _unichr_is_printable
def _unichr
def int_from_int
def stringify
def pretty_printer_lookup
def register
def move_in_stack

Variables

tuple _type_char_ptr = gdb.lookup_type('char')
tuple _type_unsigned_char_ptr = gdb.lookup_type('unsigned char')
tuple _type_void_ptr = gdb.lookup_type('void')
tuple _type_size_t = gdb.lookup_type('size_t')
 SIZEOF_VOID_P = _type_void_ptr.sizeof
tuple Py_TPFLAGS_HEAPTYPE = (1L << 9)
tuple Py_TPFLAGS_LONG_SUBCLASS = (1L << 24)
tuple Py_TPFLAGS_LIST_SUBCLASS = (1L << 25)
tuple Py_TPFLAGS_TUPLE_SUBCLASS = (1L << 26)
tuple Py_TPFLAGS_BYTES_SUBCLASS = (1L << 27)
tuple Py_TPFLAGS_UNICODE_SUBCLASS = (1L << 28)
tuple Py_TPFLAGS_DICT_SUBCLASS = (1L << 29)
tuple Py_TPFLAGS_BASE_EXC_SUBCLASS = (1L << 30)
tuple Py_TPFLAGS_TYPE_SUBCLASS = (1L << 31)
int MAX_OUTPUT_LEN = 1024
string hexdigits = "0123456789abcdef"
tuple ENCODING = locale.getpreferredencoding()
 _unichr = unichr

Class Documentation

class libpython::NullPyObjectPtr

Definition at line 75 of file libpython.py.

class libpython::StringTruncated

Definition at line 116 of file libpython.py.


Function Documentation

def libpython._PyObject_VAR_SIZE (   typeobj,
  nitems 
) [private]

Definition at line 437 of file libpython.py.

00437 
00438 def _PyObject_VAR_SIZE(typeobj, nitems):
00439     return ( ( typeobj.field('tp_basicsize') +
00440                nitems * typeobj.field('tp_itemsize') +
00441                (SIZEOF_VOID_P - 1)
00442              ) & ~(SIZEOF_VOID_P - 1)
00443            ).cast(_type_size_t)

Here is the call graph for this function:

Here is the caller graph for this function:

def libpython._unichr (   x) [private]

Definition at line 1105 of file libpython.py.

01105 
01106     def _unichr(x):
01107         if x < 0x10000:
01108             return unichr(x)
01109         x -= 0x10000
01110         ch1 = 0xD800 | (x >> 10)
01111         ch2 = 0xDC00 | (x & 0x3FF)
01112         return unichr(ch1) + unichr(ch2)
01113 

def libpython._unichr_is_printable (   char) [private]

Definition at line 1094 of file libpython.py.

01094 
01095 def _unichr_is_printable(char):
01096     # Logic adapted from Python 3's Tools/unicode/makeunicodedata.py
01097     if char == u" ":
01098         return True
01099     import unicodedata
01100     return unicodedata.category(char) not in ("C", "Z")

Here is the caller graph for this function:

def libpython._write_instance_repr (   out,
  visited,
  name,
  pyop_attrdict,
  address 
) [private]
Shared code for use by old-style and new-style classes:
write a representation to file-like object "out"

Definition at line 399 of file libpython.py.

00399 
00400 def _write_instance_repr(out, visited, name, pyop_attrdict, address):
00401     '''Shared code for use by old-style and new-style classes:
00402     write a representation to file-like object "out"'''
00403     out.write('<')
00404     out.write(name)
00405 
00406     # Write dictionary of instance attributes:
00407     if isinstance(pyop_attrdict, PyDictObjectPtr):
00408         out.write('(')
00409         first = True
00410         for pyop_arg, pyop_val in pyop_attrdict.iteritems():
00411             if not first:
00412                 out.write(', ')
00413             first = False
00414             out.write(pyop_arg.proxyval(visited))
00415             out.write('=')
00416             pyop_val.write_repr(out, visited)
00417         out.write(')')
00418     out.write(' at remote 0x%x>' % address)
00419 

Here is the caller graph for this function:

def libpython.int_from_int (   gdbval)

Definition at line 1271 of file libpython.py.

01271 
01272 def int_from_int(gdbval):
01273     return int(str(gdbval))
01274 

Here is the caller graph for this function:

def libpython.move_in_stack (   move_up)
Move up or down the stack (for the py-up/py-down command)

Definition at line 1534 of file libpython.py.

01534 
01535 def move_in_stack(move_up):
01536     '''Move up or down the stack (for the py-up/py-down command)'''
01537     frame = Frame.get_selected_python_frame()
01538     while frame:
01539         if move_up:
01540             iter_frame = frame.older()
01541         else:
01542             iter_frame = frame.newer()
01543 
01544         if not iter_frame:
01545             break
01546 
01547         if iter_frame.is_evalframeex():
01548             # Result:
01549             if iter_frame.select():
01550                 iter_frame.print_summary()
01551             return
01552 
01553         frame = iter_frame
01554 
01555     if move_up:
01556         print 'Unable to find an older python frame'
01557     else:
01558         print 'Unable to find a newer python frame'

Here is the caller graph for this function:

def libpython.os_fsencode (   filename)

Definition at line 99 of file libpython.py.

00099 
00100 def os_fsencode(filename):
00101     if not isinstance(filename, unicode):
00102         return filename
00103     encoding = sys.getfilesystemencoding()
00104     if encoding == 'mbcs':
00105         # mbcs doesn't support surrogateescape
00106         return filename.encode(encoding)
00107     encoded = []
00108     for char in filename:
00109         # surrogateescape error handler
00110         if 0xDC80 <= ord(char) <= 0xDCFF:
00111             byte = chr(ord(char) - 0xDC00)
00112         else:
00113             byte = char.encode(encoding)
00114         encoded.append(byte)
00115     return ''.join(encoded)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1301 of file libpython.py.

01301 
01302 def pretty_printer_lookup(gdbval):
01303     type = gdbval.type.unqualified()
01304     if type.code == gdb.TYPE_CODE_PTR:
01305         type = type.target().unqualified()
01306         t = str(type)
01307         if t in ("PyObject", "PyFrameObject", "PyUnicodeObject"):
01308             return PyObjectPtrPrinter(gdbval)
01309 
01310 """
01311 During development, I've been manually invoking the code in this way:
01312 (gdb) python
01313 
01314 import sys
01315 sys.path.append('/home/david/coding/python-gdb')
01316 import libpython
01317 end
01318 
01319 then reloading it after each edit like this:
01320 (gdb) python reload(libpython)
01321 
01322 The following code should ensure that the prettyprinter is registered
01323 if the code is autoloaded by gdb when visiting libpython.so, provided
01324 that this python file is installed to the same path as the library (or its
01325 .debug file) plus a "-gdb.py" suffix, e.g:
01326   /usr/lib/libpython2.6.so.1.0-gdb.py
01327   /usr/lib/debug/usr/lib/libpython2.6.so.1.0.debug-gdb.py
"""
def libpython.register (   obj)

Definition at line 1328 of file libpython.py.

01328 
01329 def register (obj):
01330     if obj == None:
01331         obj = gdb
01332 
01333     # Wire up the pretty-printer
01334     obj.pretty_printers.append(pretty_printer_lookup)

def libpython.safe_range (   val)

Definition at line 86 of file libpython.py.

00086 
00087 def safe_range(val):
00088     # As per range, but don't trust the value too much: cap it to a safety
00089     # threshold in case the data was corrupted
00090     return xrange(safety_limit(val))

Here is the call graph for this function:

Here is the caller graph for this function:

def libpython.safety_limit (   val)

Definition at line 79 of file libpython.py.

00079 
00080 def safety_limit(val):
00081     # Given a integer value from the process being debugged, limit it to some
00082     # safety threshold so that arbitrary breakage within said process doesn't
00083     # break the gdb process too much (e.g. sizes of iterations, sizes of lists)
00084     return min(val, 1000)
00085 

Here is the caller graph for this function:

def libpython.stringify (   val)

Definition at line 1275 of file libpython.py.

01275 
01276 def stringify(val):
01277     # TODO: repr() puts everything on one line; pformat can be nicer, but
01278     # can lead to v.long results; this function isolates the choice
01279     if True:
01280         return repr(val)
01281     else:
01282         from pprint import pformat
01283         return pformat(val)
01284 

Here is the call graph for this function:

Here is the caller graph for this function:

def libpython.write_unicode (   file,
  text 
)

Definition at line 91 of file libpython.py.

00091 
00092 def write_unicode(file, text):
00093     # Write a byte or unicode string to file. Unicode strings are encoded to
00094     # ENCODING encoding with 'backslashreplace' error handler to avoid
00095     # UnicodeEncodeError.
00096     if isinstance(text, unicode):
00097         text = text.encode(ENCODING, 'backslashreplace')
00098     file.write(text)

Here is the caller graph for this function:


Variable Documentation

tuple libpython._type_char_ptr = gdb.lookup_type('char')

Definition at line 49 of file libpython.py.

tuple libpython._type_size_t = gdb.lookup_type('size_t')

Definition at line 52 of file libpython.py.

tuple libpython._type_unsigned_char_ptr = gdb.lookup_type('unsigned char')

Definition at line 50 of file libpython.py.

tuple libpython._type_void_ptr = gdb.lookup_type('void')

Definition at line 51 of file libpython.py.

Definition at line 1102 of file libpython.py.

Definition at line 73 of file libpython.py.

string libpython.hexdigits = "0123456789abcdef"

Definition at line 71 of file libpython.py.

Definition at line 69 of file libpython.py.

Definition at line 65 of file libpython.py.

Definition at line 62 of file libpython.py.

Definition at line 64 of file libpython.py.

tuple libpython.Py_TPFLAGS_HEAPTYPE = (1L << 9)

Definition at line 57 of file libpython.py.

Definition at line 60 of file libpython.py.

Definition at line 59 of file libpython.py.

Definition at line 61 of file libpython.py.

Definition at line 66 of file libpython.py.

Definition at line 63 of file libpython.py.

libpython.SIZEOF_VOID_P = _type_void_ptr.sizeof

Definition at line 54 of file libpython.py.