← 输入框|github.com|刷新
Skip to content

Debug mode: check if objects are valid #84054

Closed

Description

@vstinner
BPO 39873
Nosy @vstinner, @methane, @serhiy-storchaka, @pablogsal
PRs
  • [WIP] bpo-39873: _PyObject_CAST() check if the object is valid #18803
  • bpo-39873: PyObject_Init() uses PyObject_INIT() #18804
  • bpo-39873: Cleanup _PyObject_CheckConsistency() #18807
  • 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 = None
    closed_at = <Date 2020-03-25.16:28:32.499>
    created_at = <Date 2020-03-06.09:24:50.515>
    labels = ['interpreter-core', '3.9']
    title = 'Debug mode: check if objects are valid'
    updated_at = <Date 2020-03-25.16:28:32.498>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2020-03-25.16:28:32.498>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-03-25.16:28:32.499>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2020-03-06.09:24:50.515>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39873
    keywords = ['patch']
    message_count = 5.0
    messages = ['363499', '363500', '363521', '363529', '364997']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'methane', 'serhiy.storchaka', 'pablogsal']
    pr_nums = ['18803', '18804', '18807']
    priority = 'normal'
    resolution = 'rejected'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue39873'
    versions = ['Python 3.9']

    Activity

    1. vstinner commented on Mar 6, 2020

      @vstinner
      MemberAuthor

      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 *).

      /* 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.

      Attached PR implemnts this idea.

    2. added
      3.9 (EOL)
      interpreter-core
      on Mar 6, 2020
    3. vstinner commented on Mar 6, 2020

      @vstinner
      MemberAuthor

      See also bpo-38392: "Ensure that objects entering the GC are valid". I fixed this one with commit 1b18455.

    4. vstinner commented on Mar 6, 2020

      @vstinner
      MemberAuthor

      New changeset 1fb5a9f by Victor Stinner in branch 'master':
      bpo-39873: PyObject_Init() uses PyObject_INIT() (GH-18804)
      1fb5a9f

    5. vstinner commented on Mar 6, 2020

      @vstinner
      MemberAuthor

      New changeset 9a73705 by Victor Stinner in branch 'master':
      bpo-39873: Cleanup _PyObject_CheckConsistency() (GH-18807)
      9a73705

    6. vstinner commented on Mar 25, 2020

      @vstinner
      MemberAuthor

      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.

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.9 (EOL)interpreter-core

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions