ÿØÿà JFIF    ÿÛ „ ( %!1!%*+...983,7(-.- PKm]3{"{"valgrind-python.suppnu[# # This is a valgrind suppression file that should be used when using valgrind. # # Here's an example of running valgrind: # # cd python/dist/src # valgrind --tool=memcheck --suppressions=Misc/valgrind-python.supp \ # ./python -E ./Lib/test/regrtest.py -u gui,network # # You must edit Objects/obmalloc.c and uncomment Py_USING_MEMORY_DEBUGGER # to use the preferred suppressions with address_in_range. # # If you do not want to recompile Python, you can uncomment # suppressions for _PyObject_Free and _PyObject_Realloc. # # See Misc/README.valgrind for more information. # all tool names: Addrcheck,Memcheck,cachegrind,helgrind,massif { ADDRESS_IN_RANGE/Invalid read of size 4 Memcheck:Addr4 fun:address_in_range } { ADDRESS_IN_RANGE/Invalid read of size 4 Memcheck:Value4 fun:address_in_range } { ADDRESS_IN_RANGE/Invalid read of size 8 (x86_64 aka amd64) Memcheck:Value8 fun:address_in_range } { ADDRESS_IN_RANGE/Conditional jump or move depends on uninitialised value Memcheck:Cond fun:address_in_range } # # Leaks (including possible leaks) # Hmmm, I wonder if this masks some real leaks. I think it does. # Will need to fix that. # { Suppress leaking the GIL. Happens once per process, see comment in ceval.c. Memcheck:Leak fun:malloc fun:PyThread_allocate_lock fun:PyEval_InitThreads } { Suppress leaking the GIL after a fork. Memcheck:Leak fun:malloc fun:PyThread_allocate_lock fun:PyEval_ReInitThreads } { Suppress leaking the autoTLSkey. This looks like it shouldn't leak though. Memcheck:Leak fun:malloc fun:PyThread_create_key fun:_PyGILState_Init fun:Py_InitializeEx fun:Py_Main } { Hmmm, is this a real leak or like the GIL? Memcheck:Leak fun:malloc fun:PyThread_ReInitTLS } { Handle PyMalloc confusing valgrind (possibly leaked) Memcheck:Leak fun:realloc fun:_PyObject_GC_Resize fun:COMMENT_THIS_LINE_TO_DISABLE_LEAK_WARNING } { Handle PyMalloc confusing valgrind (possibly leaked) Memcheck:Leak fun:malloc fun:_PyObject_GC_New fun:COMMENT_THIS_LINE_TO_DISABLE_LEAK_WARNING } { Handle PyMalloc confusing valgrind (possibly leaked) Memcheck:Leak fun:malloc fun:_PyObject_GC_NewVar fun:COMMENT_THIS_LINE_TO_DISABLE_LEAK_WARNING } # # Non-python specific leaks # { Handle pthread issue (possibly leaked) Memcheck:Leak fun:calloc fun:allocate_dtv fun:_dl_allocate_tls_storage fun:_dl_allocate_tls } { Handle pthread issue (possibly leaked) Memcheck:Leak fun:memalign fun:_dl_allocate_tls_storage fun:_dl_allocate_tls } ###{ ### ADDRESS_IN_RANGE/Invalid read of size 4 ### Memcheck:Addr4 ### fun:_PyObject_Free ###} ### ###{ ### ADDRESS_IN_RANGE/Invalid read of size 4 ### Memcheck:Value4 ### fun:_PyObject_Free ###} ### ###{ ### ADDRESS_IN_RANGE/Use of uninitialised value of size 8 ### Memcheck:Addr8 ### fun:_PyObject_Free ###} ### ###{ ### ADDRESS_IN_RANGE/Use of uninitialised value of size 8 ### Memcheck:Value8 ### fun:_PyObject_Free ###} ### ###{ ### ADDRESS_IN_RANGE/Conditional jump or move depends on uninitialised value ### Memcheck:Cond ### fun:_PyObject_Free ###} ###{ ### ADDRESS_IN_RANGE/Invalid read of size 4 ### Memcheck:Addr4 ### fun:_PyObject_Realloc ###} ### ###{ ### ADDRESS_IN_RANGE/Invalid read of size 4 ### Memcheck:Value4 ### fun:_PyObject_Realloc ###} ### ###{ ### ADDRESS_IN_RANGE/Use of uninitialised value of size 8 ### Memcheck:Addr8 ### fun:_PyObject_Realloc ###} ### ###{ ### ADDRESS_IN_RANGE/Use of uninitialised value of size 8 ### Memcheck:Value8 ### fun:_PyObject_Realloc ###} ### ###{ ### ADDRESS_IN_RANGE/Conditional jump or move depends on uninitialised value ### Memcheck:Cond ### fun:_PyObject_Realloc ###} ### ### All the suppressions below are for errors that occur within libraries ### that Python uses. The problems to not appear to be related to Python's ### use of the libraries. ### { Generic ubuntu ld problems Memcheck:Addr8 obj:/lib/ld-2.4.so obj:/lib/ld-2.4.so obj:/lib/ld-2.4.so obj:/lib/ld-2.4.so } { Generic gentoo ld problems Memcheck:Cond obj:/lib/ld-2.3.4.so obj:/lib/ld-2.3.4.so obj:/lib/ld-2.3.4.so obj:/lib/ld-2.3.4.so } { DBM problems, see test_dbm Memcheck:Param write(buf) fun:write obj:/usr/lib/libdb1.so.2 obj:/usr/lib/libdb1.so.2 obj:/usr/lib/libdb1.so.2 obj:/usr/lib/libdb1.so.2 fun:dbm_close } { DBM problems, see test_dbm Memcheck:Value8 fun:memmove obj:/usr/lib/libdb1.so.2 obj:/usr/lib/libdb1.so.2 obj:/usr/lib/libdb1.so.2 obj:/usr/lib/libdb1.so.2 fun:dbm_store fun:dbm_ass_sub } { DBM problems, see test_dbm Memcheck:Cond obj:/usr/lib/libdb1.so.2 obj:/usr/lib/libdb1.so.2 obj:/usr/lib/libdb1.so.2 fun:dbm_store fun:dbm_ass_sub } { DBM problems, see test_dbm Memcheck:Cond fun:memmove obj:/usr/lib/libdb1.so.2 obj:/usr/lib/libdb1.so.2 obj:/usr/lib/libdb1.so.2 obj:/usr/lib/libdb1.so.2 fun:dbm_store fun:dbm_ass_sub } { GDBM problems, see test_gdbm Memcheck:Param write(buf) fun:write fun:gdbm_open } { Uninitialised byte(s) false alarm, see bpo-35561 Memcheck:Param epoll_ctl(event) fun:epoll_ctl fun:pyepoll_internal_ctl } { ZLIB problems, see test_gzip Memcheck:Cond obj:/lib/libz.so.1.2.3 obj:/lib/libz.so.1.2.3 fun:deflate } { Avoid problems w/readline doing a putenv and leaking on exit Memcheck:Leak fun:malloc fun:xmalloc fun:sh_set_lines_and_columns fun:_rl_get_screen_size fun:_rl_init_terminal_io obj:/lib/libreadline.so.4.3 fun:rl_initialize } # Valgrind emits "Conditional jump or move depends on uninitialised value(s)" # false alarms on GCC builtin strcmp() function. The GCC code is correct. # # Valgrind bug: https://bugs.kde.org/show_bug.cgi?id=264936 { bpo-38118: Valgrind emits false alarm on GCC builtin strcmp() Memcheck:Cond fun:PyUnicode_Decode } ### ### These occur from somewhere within the SSL, when running ### test_socket_sll. They are too general to leave on by default. ### ###{ ### somewhere in SSL stuff ### Memcheck:Cond ### fun:memset ###} ###{ ### somewhere in SSL stuff ### Memcheck:Value4 ### fun:memset ###} ### ###{ ### somewhere in SSL stuff ### Memcheck:Cond ### fun:MD5_Update ###} ### ###{ ### somewhere in SSL stuff ### Memcheck:Value4 ### fun:MD5_Update ###} # Fedora's package "openssl-1.0.1-0.1.beta2.fc17.x86_64" on x86_64 # See http://bugs.python.org/issue14171 { openssl 1.0.1 prng 1 Memcheck:Cond fun:bcmp fun:fips_get_entropy fun:FIPS_drbg_instantiate fun:RAND_init_fips fun:OPENSSL_init_library fun:SSL_library_init fun:init_hashlib } { openssl 1.0.1 prng 2 Memcheck:Cond fun:fips_get_entropy fun:FIPS_drbg_instantiate fun:RAND_init_fips fun:OPENSSL_init_library fun:SSL_library_init fun:init_hashlib } { openssl 1.0.1 prng 3 Memcheck:Value8 fun:_x86_64_AES_encrypt_compact fun:AES_encrypt } # # All of these problems come from using test_socket_ssl # { from test_socket_ssl Memcheck:Cond fun:BN_bin2bn } { from test_socket_ssl Memcheck:Cond fun:BN_num_bits_word } { from test_socket_ssl Memcheck:Value4 fun:BN_num_bits_word } { from test_socket_ssl Memcheck:Cond fun:BN_mod_exp_mont_word } { from test_socket_ssl Memcheck:Cond fun:BN_mod_exp_mont } { from test_socket_ssl Memcheck:Param write(buf) fun:write obj:/usr/lib/libcrypto.so.0.9.7 } { from test_socket_ssl Memcheck:Cond fun:RSA_verify } { from test_socket_ssl Memcheck:Value4 fun:RSA_verify } { from test_socket_ssl Memcheck:Value4 fun:DES_set_key_unchecked } { from test_socket_ssl Memcheck:Value4 fun:DES_encrypt2 } { from test_socket_ssl Memcheck:Cond obj:/usr/lib/libssl.so.0.9.7 } { from test_socket_ssl Memcheck:Value4 obj:/usr/lib/libssl.so.0.9.7 } { from test_socket_ssl Memcheck:Cond fun:BUF_MEM_grow_clean } { from test_socket_ssl Memcheck:Cond fun:memcpy fun:ssl3_read_bytes } { from test_socket_ssl Memcheck:Cond fun:SHA1_Update } { from test_socket_ssl Memcheck:Value4 fun:SHA1_Update } { test_buffer_non_debug Memcheck:Addr4 fun:PyUnicodeUCS2_FSConverter } { test_buffer_non_debug Memcheck:Addr4 fun:PyUnicode_FSConverter } { wcscmp_false_positive Memcheck:Addr8 fun:wcscmp fun:_PyOS_GetOpt fun:Py_Main fun:main } # Additional suppressions for the unified decimal tests: { test_decimal Memcheck:Addr4 fun:PyUnicodeUCS2_FSConverter } { test_decimal2 Memcheck:Addr4 fun:PyUnicode_FSConverter } PKm]蘪zccgdbinitnu[# If you use the GNU debugger gdb to debug the Python C runtime, you # might find some of the following commands useful. Copy this to your # ~/.gdbinit file and it'll get loaded into gdb automatically when you # start it up. Then, at the gdb prompt you can do things like: # # (gdb) pyo apyobjectptr # # refcounts: 1 # address : 84a7a2c # $1 = void # (gdb) # # NOTE: If you have gdb 7 or later, it supports debugging of Python directly # with embedded macros that you may find superior to what is in here. # See Tools/gdb/libpython.py and http://bugs.python.org/issue8032. define pyo # side effect of calling _PyObject_Dump is to dump the object's # info - assigning just prevents gdb from printing the # NULL return value set $_unused_void = _PyObject_Dump($arg0) end document pyo Prints a representation of the object to stderr, along with the number of reference counts it currently has and the hex address the object is allocated at. The argument must be a PyObject* end define pyg print _PyGC_Dump($arg0) end document pyg Prints a representation of the object to stderr, along with the number of reference counts it currently has and the hex address the object is allocated at. The argument must be a PyGC_Head* end define pylocals set $_i = 0 while $_i < f->f_code->co_nlocals if f->f_localsplus + $_i != 0 set $_names = f->f_code->co_varnames set $_name = PyUnicode_AsUTF8(PyTuple_GetItem($_names, $_i)) printf "%s:\n", $_name pyo f->f_localsplus[$_i] end set $_i = $_i + 1 end end document pylocals Print the local variables of the current frame. end # A rewrite of the Python interpreter's line number calculator in GDB's # command language define lineno set $__continue = 1 set $__co = f->f_code set $__lasti = f->f_lasti set $__sz = ((PyVarObject *)$__co->co_lnotab)->ob_size/2 set $__p = (unsigned char *)((PyBytesObject *)$__co->co_lnotab)->ob_sval set $__li = $__co->co_firstlineno set $__ad = 0 while ($__sz-1 >= 0 && $__continue) set $__sz = $__sz - 1 set $__ad = $__ad + *$__p set $__p = $__p + 1 if ($__ad > $__lasti) set $__continue = 0 else set $__li = $__li + *$__p set $__p = $__p + 1 end end printf "%d", $__li end define pyframev pyframe pylocals end document pyframev Print the current frame - verbose end define pyframe set $__fn = PyUnicode_AsUTF8(f->f_code->co_filename) set $__n = PyUnicode_AsUTF8(f->f_code->co_name) printf "%s (", $__fn lineno printf "): %s\n", $__n ### Uncomment these lines when using from within Emacs/XEmacs so it will ### automatically track/display the current Python source line # printf "%c%c%s:", 032, 032, $__fn # lineno # printf ":1\n" end ### Use these at your own risk. It appears that a bug in gdb causes it ### to crash in certain circumstances. #define up # up-silently 1 # printframe #end #define down # down-silently 1 # printframe #end define printframe if $pc > PyEval_EvalFrameEx && $pc < _PyEval_EvalFrameDefault pyframe else frame end end # Here's a somewhat fragile way to print the entire Python stack from gdb. # It's fragile because the tests for the value of $pc depend on the layout # of specific functions in the C source code. # Explanation of while and if tests: We want to pop up the stack until we # land in Py_Main (this is probably an incorrect assumption in an embedded # interpreter, but the test can be extended by an interested party). If # Py_Main <= $pc <= Py_GetArgcArv is true, $pc is in Py_Main(), so the while # tests succeeds as long as it's not true. In a similar fashion the if # statement tests to see if we are in PyEval_EvalFrameEx(). # Note: The name of the main interpreter function and the function which # follow it has changed over time. This version of pystack works with this # version of Python. If you try using it with older or newer versions of # the interpreter you may will have to change the functions you compare with # $pc. define pystack while $pc < Py_Main || $pc > Py_GetArgcArgv if $pc > PyEval_EvalFrameEx && $pc < _PyEval_EvalFrameDefault pyframe end up-silently 1 end select-frame 0 end document pystack Print the entire Python call stack end define pystackv while $pc < Py_Main || $pc > Py_GetArgcArgv if $pc > PyEval_EvalFrameEx && $pc < _PyEval_EvalFrameDefault pyframev end up-silently 1 end select-frame 0 end document pystackv Print the entire Python call stack - verbose mode end define pu set $uni = $arg0 set $i = 0 while (*$uni && $i++<100) if (*$uni < 0x80) print *(char*)$uni++ else print /x *(short*)$uni++ end end end document pu Generally useful macro to print a Unicode string end PKm]̈README.valgrindnu[This document describes some caveats about the use of Valgrind with Python. Valgrind is used periodically by Python developers to try to ensure there are no memory leaks or invalid memory reads/writes. If you want to enable valgrind support in Python, you will need to configure Python --with-valgrind option or an older option --without-pymalloc. UPDATE: Python 3.6 now supports PYTHONMALLOC=malloc environment variable which can be used to force the usage of the malloc() allocator of the C library. If you don't want to read about the details of using Valgrind, there are still two things you must do to suppress the warnings. First, you must use a suppressions file. One is supplied in Misc/valgrind-python.supp. Second, you must uncomment the lines in Misc/valgrind-python.supp that suppress the warnings for PyObject_Free and PyObject_Realloc. If you want to use Valgrind more effectively and catch even more memory leaks, you will need to configure python --without-pymalloc. PyMalloc allocates a few blocks in big chunks and most object allocations don't call malloc, they use chunks doled about by PyMalloc from the big blocks. This means Valgrind can't detect many allocations (and frees), except for those that are forwarded to the system malloc. Note: configuring python --without-pymalloc makes Python run much slower, especially when running under Valgrind. You may need to run the tests in batches under Valgrind to keep the memory usage down to allow the tests to complete. It seems to take about 5 times longer to run --without-pymalloc. Apr 15, 2006: test_ctypes causes Valgrind 3.1.1 to fail (crash). test_socket_ssl should be skipped when running valgrind. The reason is that it purposely uses uninitialized memory. This causes many spurious warnings, so it's easier to just skip it. Details: -------- Python uses its own small-object allocation scheme on top of malloc, called PyMalloc. Valgrind may show some unexpected results when PyMalloc is used. Starting with Python 2.3, PyMalloc is used by default. You can disable PyMalloc when configuring python by adding the --without-pymalloc option. If you disable PyMalloc, most of the information in this document and the supplied suppressions file will not be useful. As discussed above, disabling PyMalloc can catch more problems. PyMalloc uses 256KB chunks of memory, so it can't detect anything wrong within these blocks. For that reason, compiling Python --without-pymalloc usually increases the usefulness of other tools. If you use valgrind on a default build of Python, you will see many errors like: ==6399== Use of uninitialised value of size 4 ==6399== at 0x4A9BDE7E: PyObject_Free (obmalloc.c:711) ==6399== by 0x4A9B8198: dictresize (dictobject.c:477) These are expected and not a problem. Tim Peters explains the situation: PyMalloc needs to know whether an arbitrary address is one that's managed by it, or is managed by the system malloc. The current scheme allows this to be determined in constant time, regardless of how many memory areas are under pymalloc's control. The memory pymalloc manages itself is in one or more "arenas", each a large contiguous memory area obtained from malloc. The base address of each arena is saved by pymalloc in a vector. Each arena is carved into "pools", and a field at the start of each pool contains the index of that pool's arena's base address in that vector. Given an arbitrary address, pymalloc computes the pool base address corresponding to it, then looks at "the index" stored near there. If the index read up is out of bounds for the vector of arena base addresses pymalloc maintains, then pymalloc knows for certain that this address is not under pymalloc's control. Otherwise the index is in bounds, and pymalloc compares the arena base address stored at that index in the vector to the arbitrary address pymalloc is investigating pymalloc controls this arbitrary address if and only if it lies in the arena the address's pool's index claims it lies in. It doesn't matter whether the memory pymalloc reads up ("the index") is initialized. If it's not initialized, then whatever trash gets read up will lead pymalloc to conclude (correctly) that the address isn't controlled by it, either because the index is out of bounds, or the index is in bounds but the arena it represents doesn't contain the address. This determination has to be made on every call to one of pymalloc's free/realloc entry points, so its speed is critical (Python allocates and frees dynamic memory at a ferocious rate -- everything in Python, from integers to "stack frames", lives in the heap). PKm]3{"{"valgrind-python.suppnu[PKm]蘪zcc"gdbinitnu[PKm]̈Y6README.valgrindnu[PKGI