2010-12-28 19:38:12 +08:00
|
|
|
This file describes some special Python build types enabled via compile-time
|
2019-04-28 02:14:35 +08:00
|
|
|
preprocessor directives.
|
2002-07-10 02:35:34 +08:00
|
|
|
|
2010-12-28 19:38:12 +08:00
|
|
|
IMPORTANT: if you want to build a debug-enabled Python, it is recommended that
|
|
|
|
you use ``./configure --with-pydebug``, rather than the options listed here.
|
2010-12-15 23:47:34 +08:00
|
|
|
|
|
|
|
However, if you wish to define some of these options individually, it is best
|
|
|
|
to define them in the EXTRA_CFLAGS make variable;
|
2006-04-21 18:40:58 +08:00
|
|
|
``make EXTRA_CFLAGS="-DPy_REF_DEBUG"``.
|
2005-04-20 04:28:09 +08:00
|
|
|
|
2002-07-10 02:35:34 +08:00
|
|
|
|
2010-12-28 19:38:12 +08:00
|
|
|
Py_REF_DEBUG
|
|
|
|
------------
|
|
|
|
|
|
|
|
Turn on aggregate reference counting. This arranges that extern _Py_RefTotal
|
2014-03-31 05:16:09 +08:00
|
|
|
hold a count of all references, the sum of ob_refcnt across all objects.
|
|
|
|
Passing ``-X showrefcount`` on the command line causes the interactive
|
|
|
|
interpreter to print the reference count total as well the number of memory
|
|
|
|
blocks allocated after each statement:
|
2002-07-10 02:35:34 +08:00
|
|
|
|
|
|
|
>>> 23
|
|
|
|
23
|
2014-03-31 05:16:09 +08:00
|
|
|
[8288 refs, 14332 blocks]
|
2002-07-10 02:35:34 +08:00
|
|
|
>>>
|
|
|
|
|
|
|
|
Note that if this count increases when you're not storing away new objects,
|
2010-12-28 19:38:12 +08:00
|
|
|
there's probably a leak. Remember, though, that in interactive mode the special
|
|
|
|
name "_" holds a reference to the last result displayed!
|
2002-07-10 02:35:34 +08:00
|
|
|
|
2010-12-28 19:38:12 +08:00
|
|
|
Py_REF_DEBUG also checks after every decref to verify that the refcount hasn't
|
|
|
|
gone negative, and causes an immediate fatal error if it has.
|
2002-07-10 02:35:34 +08:00
|
|
|
|
2019-04-25 07:46:31 +08:00
|
|
|
Py_DEBUG implies Py_REF_DEBUG.
|
|
|
|
|
2002-07-10 02:35:34 +08:00
|
|
|
Special gimmicks:
|
|
|
|
|
|
|
|
sys.gettotalrefcount()
|
|
|
|
Return current total of all refcounts.
|
2010-12-28 19:38:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
Py_TRACE_REFS
|
|
|
|
-------------
|
|
|
|
|
2019-04-25 07:46:31 +08:00
|
|
|
Build option: ``./configure --with-trace-refs``.
|
|
|
|
|
2010-12-28 19:38:12 +08:00
|
|
|
Turn on heavy reference debugging. This is major surgery. Every PyObject grows
|
|
|
|
two more pointers, to maintain a doubly-linked list of all live heap-allocated
|
|
|
|
objects. Most built-in type objects are not in this list, as they're statically
|
2020-02-03 22:17:15 +08:00
|
|
|
allocated.
|
2003-03-23 10:51:01 +08:00
|
|
|
|
|
|
|
Note that because the fundamental PyObject layout changes, Python modules
|
2010-12-28 19:38:12 +08:00
|
|
|
compiled with Py_TRACE_REFS are incompatible with modules compiled without it.
|
2002-07-10 02:35:34 +08:00
|
|
|
|
|
|
|
Special gimmicks:
|
|
|
|
|
|
|
|
sys.getobjects(max[, type])
|
2010-12-28 19:38:12 +08:00
|
|
|
Return list of the (no more than) max most-recently allocated objects, most
|
|
|
|
recently allocated first in the list, least-recently allocated last in the
|
|
|
|
list. max=0 means no limit on list length. If an optional type object is
|
|
|
|
passed, the list is also restricted to objects of that type. The return
|
|
|
|
list itself, and some temp objects created just to call sys.getobjects(),
|
|
|
|
are excluded from the return list. Note that the list returned is just
|
|
|
|
another object, though, so may appear in the return list the next time you
|
|
|
|
call getobjects(); note that every object in the list is kept alive too,
|
|
|
|
simply by virtue of being in the list.
|
|
|
|
|
|
|
|
envvar PYTHONDUMPREFS
|
2015-11-30 11:18:29 +08:00
|
|
|
If this envvar exists, Py_FinalizeEx() arranges to print a list of all
|
2010-12-28 19:38:12 +08:00
|
|
|
still-live heap objects. This is printed twice, in different formats,
|
2015-11-30 11:18:29 +08:00
|
|
|
before and after Py_FinalizeEx has cleaned up everything it can clean up. The
|
2010-12-28 19:38:12 +08:00
|
|
|
first output block produces the repr() of each object so is more
|
|
|
|
informative; however, a lot of stuff destined to die is still alive then.
|
|
|
|
The second output block is much harder to work with (repr() can't be invoked
|
|
|
|
anymore -- the interpreter has been torn down too far), but doesn't list any
|
|
|
|
objects that will die. The tool script combinerefs.py can be run over this
|
|
|
|
to combine the info from both output blocks. The second output block, and
|
2003-04-18 08:45:59 +08:00
|
|
|
combinerefs.py, were new in Python 2.3b1.
|
2010-12-28 19:38:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
Py_DEBUG
|
|
|
|
--------
|
2002-07-10 02:35:34 +08:00
|
|
|
|
|
|
|
This is what is generally meant by "a debug build" of Python.
|
|
|
|
|
2021-04-29 16:47:47 +08:00
|
|
|
Py_DEBUG implies LLTRACE and Py_REF_DEBUG. In addition, C assert()s are enabled
|
|
|
|
(via the C way: by not defining NDEBUG), and some routines do additional sanity
|
|
|
|
checks inside "#ifdef Py_DEBUG" blocks.
|
2010-12-28 19:38:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
LLTRACE
|
|
|
|
-------
|
2002-07-30 17:49:29 +08:00
|
|
|
|
2005-01-18 23:53:59 +08:00
|
|
|
Compile in support for Low Level TRACE-ing of the main interpreter loop.
|
2002-07-30 17:49:29 +08:00
|
|
|
|
2015-03-02 09:59:22 +08:00
|
|
|
When this preprocessor symbol is defined, before PyEval_EvalFrame executes a
|
|
|
|
frame's code it checks the frame's global namespace for a variable
|
2018-08-25 10:00:25 +08:00
|
|
|
"__ltrace__". If such a variable is found, mounds of information about what
|
2015-03-02 09:59:22 +08:00
|
|
|
the interpreter is doing are sprayed to stdout, such as every opcode and opcode
|
|
|
|
argument and values pushed onto and popped off the value stack.
|
2002-07-30 17:49:29 +08:00
|
|
|
|
|
|
|
Not useful very often, but very useful when needed.
|
2019-04-25 07:46:31 +08:00
|
|
|
|
|
|
|
Py_DEBUG implies LLTRACE.
|