You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2020-03-25.16:28:32.499>created_at=<Date2020-03-06.09:24:50.515>labels= ['interpreter-core', '3.9']
title='Debug mode: check if objects are valid'updated_at=<Date2020-03-25.16:28:32.498>user='https://github.com/vstinner'
My previous attempt to help debugging such issue failed: bpo-36389 "Add gc.enable_object_debugger(): detect corrupted Python objects in the GC". The idea was to check frequently if all objects tracked by the GC are valid. The problem is that even if the check looked trivial, checking all objects made Python way slower. Even when I tried to only check objects of the "young" GC generation (generation 0), it was still too slow.
Here I propose a different approach: attempt to only check objects when they are accessed. Recently, I started to replace explicit cast to (PyObject *) type with an indirection: a new _PyObject_CAST() macro which should be the only way to cast any object pointer to (PyObject *).
/* Cast argument to PyObject* type. */#define_PyObject_CAST(op) ((PyObject*)(op))
This macro is used in many "core" macros like Py_TYPE(op), Py_REFCNT(op), Py_SIZE(op), Py_SETREF(op, op2), Py_VISIT(op), etc.
The idea here is to inject code in _PyObject_CAST(op) when Python is built in debug mode to ensure that the object is valid. The intent is to detect corrupted objects earlier than a garbage collection, to ease debugging C extensions.
The checks should be limited to reduce the performance overhead.
This change was mostly an experimentation. But I'm not sure that it does solve any issue. The change is more intrusive than what I expected. I prefer to abandon PR 18803 and this issue.
Activity
vstinner commentedon Mar 6, 2020
One of the worst issue that I had to debug is a crash in the Python garbage collector. It is usually a crash in visit_decref(). See my notes:
https://pythondev.readthedocs.io/debug_tools.html#debug-crash-in-garbage-collection-visit-decref
My previous attempt to help debugging such issue failed: bpo-36389 "Add gc.enable_object_debugger(): detect corrupted Python objects in the GC". The idea was to check frequently if all objects tracked by the GC are valid. The problem is that even if the check looked trivial, checking all objects made Python way slower. Even when I tried to only check objects of the "young" GC generation (generation 0), it was still too slow.
Here I propose a different approach: attempt to only check objects when they are accessed. Recently, I started to replace explicit cast to (PyObject *) type with an indirection: a new _PyObject_CAST() macro which should be the only way to cast any object pointer to (PyObject *).
This macro is used in many "core" macros like Py_TYPE(op), Py_REFCNT(op), Py_SIZE(op), Py_SETREF(op, op2), Py_VISIT(op), etc.
The idea here is to inject code in _PyObject_CAST(op) when Python is built in debug mode to ensure that the object is valid. The intent is to detect corrupted objects earlier than a garbage collection, to ease debugging C extensions.
The checks should be limited to reduce the performance overhead.
Attached PR implemnts this idea.
vstinner commentedon Mar 6, 2020
See also bpo-38392: "Ensure that objects entering the GC are valid". I fixed this one with commit 1b18455.
vstinner commentedon Mar 6, 2020
New changeset 1fb5a9f by Victor Stinner in branch 'master':
bpo-39873: PyObject_Init() uses PyObject_INIT() (GH-18804)
1fb5a9f
vstinner commentedon Mar 6, 2020
New changeset 9a73705 by Victor Stinner in branch 'master':
bpo-39873: Cleanup _PyObject_CheckConsistency() (GH-18807)
9a73705
vstinner commentedon Mar 25, 2020
This change was mostly an experimentation. But I'm not sure that it does solve any issue. The change is more intrusive than what I expected. I prefer to abandon PR 18803 and this issue.