cpython: e1c6f8895fd8 (original) (raw)

Mercurial > cpython

changeset 101080:e1c6f8895fd8 3.5

python-gdb.py: get C types at runtime Issue #26799: Fix python-gdb.py: don't get once C types when the Python code is loaded, but get C types on demande. The C types can change if python-gdb.py is loaded before the Python executable. Patch written by Thomas Ilsche. [#26799]

Victor Stinner victor.stinner@gmail.com
date Wed, 20 Apr 2016 18:07:21 +0200
parents a54f6e207b22
children 6425728d8dc6 952c89a10be6
files Misc/ACKS Misc/NEWS Tools/gdb/libpython.py
diffstat 3 files changed, 39 insertions(+), 14 deletions(-)[+] [-] Misc/ACKS 1 Misc/NEWS 5 Tools/gdb/libpython.py 47

line wrap: on

line diff

--- a/Misc/ACKS +++ b/Misc/ACKS @@ -648,6 +648,7 @@ Catalin Iacob Mihai Ibanescu Ali Ikinci Aaron Iles +Thomas Ilsche Lars Immisch Bobby Impollonia Naoki Inada

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -467,6 +467,11 @@ Windows Tools/Demos ----------- +- Issue #26799: Fix python-gdb.py: don't get once C types when the Python code

--- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -56,16 +56,35 @@ if sys.version_info[0] >= 3: long = int

Look up the gdb.Type for some standard types:

-_type_char_ptr = gdb.lookup_type('char').pointer() # char* -_type_unsigned_char_ptr = gdb.lookup_type('unsigned char').pointer() # unsigned char* -_type_void_ptr = gdb.lookup_type('void').pointer() # void* -_type_unsigned_short_ptr = gdb.lookup_type('unsigned short').pointer() -_type_unsigned_int_ptr = gdb.lookup_type('unsigned int').pointer() +# Those need to be refreshed as types (pointer sizes) may change when +# gdb loads different executables + + +def _type_char_ptr():

+ + +def _type_unsigned_char_ptr():

+ + +def _type_void_ptr():

+ + +def _type_unsigned_short_ptr():

+ + +def _type_unsigned_int_ptr():

value computed later, see PyUnicodeObjectPtr.proxy()

_is_pep393 = None -SIZEOF_VOID_P = _type_void_ptr.sizeof + +def _sizeof_void_p():

Py_TPFLAGS_HEAPTYPE = (1 << 9) @@ -460,8 +479,8 @@ def _PyObject_VAR_SIZE(typeobj, nitems): return ( ( typeobj.field('tp_basicsize') + nitems * typeobj.field('tp_itemsize') +

_PyObject_VAR_SIZE._type_size_t = None @@ -485,9 +504,9 @@ class HeapTypeObjectPtr(PyObjectPtr): size = _PyObject_VAR_SIZE(typeobj, tsize) dictoffset += size assert dictoffset > 0

@@ -1004,7 +1023,7 @@ class PyBytesObjectPtr(PyObjectPtr): def str(self): field_ob_size = self.field('ob_size') field_ob_sval = self.field('ob_sval')

def proxyval(self, visited): @@ -1135,11 +1154,11 @@ class PyUnicodeObjectPtr(PyObjectPtr): field_str = self.field('data')['any'] repr_kind = int(state['kind']) if repr_kind == 1: