Binutils with MCST patches
Go to file
Simon Marchi b1ce65684d Fix Py_DECREF being executed without holding the GIL
When the gdbpy_ref objects get destroyed, they call Py_DECREF to
decrement the reference counter of the python object they hold a
reference to.  Any time we call into the Python API, we should be
holding the GIL.  The gdbpy_enter object does that for us in an
RAII-fashion.

However, if gdbpy_enter is declared after a gdbpy_ref object in a
function, gdbpy_enter's destructor will be called (and the GIL will be
released) before gdbpy_ref's destructor is called.  Therefore, we will
end up calling Py_DECREF without holding the GIL.

This became obvious with Python 3.6, where memory management functions
have asserts to make sure that the GIL is held.  This was exposed by
tests py-as-string.exp, py-function.exp and py-xmethods.  For example:

  (gdb) p $_as_string(enum_valid)
  Fatal Python error: Python memory allocator called without holding the GIL

  Current thread 0x00007f7f7b21c780 (most recent call first):
  [1]    18678 abort (core dumped)  ./gdb -nx testsuite/outputs/gdb.python/py-as-string/py-as-string

  #0  0x00007ffff618bc37 in raise () from /lib/x86_64-linux-gnu/libc.so.6
  #1  0x00007ffff618f028 in abort () from /lib/x86_64-linux-gnu/libc.so.6
  #2  0x00007ffff6b104d6 in Py_FatalError (msg=msg@entry=0x7ffff6ba15b8 "Python memory allocator called without holding the GIL") at Python/pylifecycle.c:1457
  #3  0x00007ffff6a37a68 in _PyMem_DebugCheckGIL () at Objects/obmalloc.c:1972
  #4  0x00007ffff6a3804e in _PyMem_DebugFree (ctx=0x7ffff6e65290 <_PyMem_Debug+48>, ptr=0x24f8830) at Objects/obmalloc.c:1994
  #5  0x00007ffff6a38e1d in PyMem_Free (ptr=<optimized out>) at Objects/obmalloc.c:442
  #6  0x00007ffff6b866c6 in _PyFaulthandler_Fini () at ./Modules/faulthandler.c:1369
  #7  0x00007ffff6b104bd in Py_FatalError (msg=msg@entry=0x7ffff6ba15b8 "Python memory allocator called without holding the GIL") at Python/pylifecycle.c:1431
  #8  0x00007ffff6a37a68 in _PyMem_DebugCheckGIL () at Objects/obmalloc.c:1972
  #9  0x00007ffff6a3804e in _PyMem_DebugFree (ctx=0x7ffff6e652c0 <_PyMem_Debug+96>, ptr=0x7ffff46b6040) at Objects/obmalloc.c:1994
  #10 0x00007ffff6a38f55 in PyObject_Free (ptr=<optimized out>) at Objects/obmalloc.c:503
  #11 0x00007ffff6a5f27e in unicode_dealloc (unicode=unicode@entry=0x7ffff46b6040) at Objects/unicodeobject.c:1794
  #12 0x00007ffff6a352a9 in _Py_Dealloc (op=0x7ffff46b6040) at Objects/object.c:1786
  #13 0x000000000063f28b in gdb_Py_DECREF (op=0x7ffff46b6040) at /home/emaisin/src/binutils-gdb/gdb/python/python-internal.h:192
  #14 0x000000000063fa33 in gdbpy_ref_policy::decref (ptr=0x7ffff46b6040) at /home/emaisin/src/binutils-gdb/gdb/python/py-ref.h:35
  #15 0x000000000063fa77 in gdb::ref_ptr<_object, gdbpy_ref_policy>::~ref_ptr (this=0x7fffffffcdf0, __in_chrg=<optimized out>) at /home/emaisin/src/binutils-gdb/gdb/common/gdb_ref_ptr.h:91
  #16 0x000000000064d8b8 in fnpy_call (gdbarch=0x2b50010, language=0x115d2c0 <c_language_defn>, cookie=0x7ffff46b7468, argc=1, argv=0x7fffffffcf48)
    at /home/emaisin/src/binutils-gdb/gdb/python/py-function.c:145

The fix is to place the gdbpy_enter first in the function.  I also
cleaned up the comments a bit and removed the unnecessary initialization
of the value variable.

gdb/ChangeLog:

	* python/py-function.c (fnpy_call): Reorder declarations to have
	the gdbpy_enter object declared first.
	* python/py-xmethods.c (gdbpy_get_xmethod_arg_types): Likewise.
2017-01-20 21:06:51 -05:00
bfd Automatic date update in version.in 2017-01-21 00:00:21 +00:00
binutils objdump: Better objdump section headers in wide mode 2017-01-20 09:05:41 +00:00
config picflag.m4 high bit set in comment 2017-01-05 00:02:57 +10:30
cpu Add fall through comment to source in cpu/ 2016-10-06 22:48:37 +10:30
elfcpp Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
etc update-copyright.py for binutils 2017-01-05 00:03:07 +10:30
gas Fix potential array overrun in x86 assembler. 2017-01-20 10:32:25 +00:00
gdb Fix Py_DECREF being executed without holding the GIL 2017-01-20 21:06:51 -05:00
gold Fix problem in aarch64 gold sources uncovered by Coverty - using sizeof on a pointer instead of an array. 2017-01-20 10:21:17 +00:00
gprof Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
include [DWARF] Sync GCC dwarf.def change on AArch64 2017-01-04 14:27:52 +00:00
intl Regen intl/configure 2015-08-31 12:53:36 +09:30
ld [AArch64] Optimize .gnu.hash table size for executable 2017-01-20 13:30:32 +00:00
libdecnumber Remove leading/trailing white spaces in ChangeLog 2015-07-24 04:16:47 -07:00
libiberty Sync libiberty from gcc 2017-01-05 00:03:07 +10:30
opcodes Updated Irish translation for the opcodes library. 2017-01-20 12:25:07 +00:00
readline Improve MinGW support in Readline 2016-09-17 11:50:37 +03:00
sim Fixes for addv and xtn2 instructions. 2017-01-17 16:11:09 -08:00
texinfo
zlib Sync zlib sources with GCC, upgrading to 1.2.10. 2017-01-20 10:17:42 +00:00
.cvsignore
.gitattributes Add a .gitattributes file for use with git-merge-changelog 2014-07-25 18:07:23 -04:00
.gitignore Add archives and make stamps to the .gitignore file. 2016-09-27 15:10:42 +01:00
COPYING
COPYING.LIB
COPYING.LIBGLOSS 2013-01-07 Jeff Johnston <jjohnstn@redhat.com> 2013-01-07 21:39:26 +00:00
COPYING.NEWLIB 2013-10-01 Jeff Johnston <jjohnstn@redhat.com> 2013-10-01 18:14:04 +00:00
COPYING3
COPYING3.LIB
ChangeLog Import config.sub 2016-12-31 11:47:16 +10:30
MAINTAINERS Update description of ownership of files in include/ 2014-11-04 16:14:14 -08:00
Makefile.def Sync top-level Makefile.def with GCC 2016-01-12 08:34:40 -08:00
Makefile.in Add dependencies to configure rule 2016-05-28 22:36:04 +09:30
Makefile.tpl Add dependencies to configure rule 2016-05-28 22:36:04 +09:30
README
README-maintainer-mode
compile Update from upstream Automake 2014-11-16 13:43:48 +01:00
config-ml.in Sync toplevel files with GCC 2015-07-27 07:49:05 -07:00
config.guess Sync config.sub,config.guess with upstream. 2016-11-07 13:08:55 -08:00
config.rpath
config.sub Import config.sub 2016-12-31 11:47:16 +10:30
configure sync binutils config/ with gcc 2016-12-08 21:35:11 +10:30
configure.ac Add support for Fushia OS. 2016-12-02 10:44:29 +00:00
depcomp Update from upstream Automake 2014-11-16 13:43:48 +01:00
djunpack.bat
install-sh Update from upstream Automake 2014-11-16 13:43:48 +01:00
libtool.m4 Sync top-level btool.m4 with GCC 2016-01-12 08:44:52 -08:00
ltgcc.m4
ltmain.sh PR target/59788 2014-02-06 11:01:57 +01:00
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
makefile.vms
missing Update from upstream Automake 2014-11-16 13:43:48 +01:00
mkdep
mkinstalldirs Update from upstream Automake 2014-11-16 13:43:48 +01:00
move-if-change Update `move-if-change' from gnulib 2014-11-16 17:04:02 +01:00
setup.com
src-release.sh fix gdb version parsing in src-release.sh 2016-01-17 10:01:55 +04:00
symlink-tree
ylwrap Update from upstream Automake 2014-11-16 13:43:48 +01:00

README

		   README for GNU development tools

This directory contains various GNU compilers, assemblers, linkers, 
debuggers, etc., plus their support routines, definitions, and documentation.

If you are receiving this as part of a GDB release, see the file gdb/README.
If with a binutils release, see binutils/README;  if with a libg++ release,
see libg++/README, etc.  That'll give you info about this
package -- supported targets, how to use it, how to report bugs, etc.

It is now possible to automatically configure and build a variety of
tools with one command.  To build all of the tools contained herein,
run the ``configure'' script here, e.g.:

	./configure 
	make

To install them (by default in /usr/local/bin, /usr/local/lib, etc),
then do:
	make install

(If the configure script can't determine your type of computer, give it
the name as an argument, for instance ``./configure sun4''.  You can
use the script ``config.sub'' to test whether a name is recognized; if
it is, config.sub translates it to a triplet specifying CPU, vendor,
and OS.)

If you have more than one compiler on your system, it is often best to
explicitly set CC in the environment before running configure, and to
also set CC when running make.  For example (assuming sh/bash/ksh):

	CC=gcc ./configure
	make

A similar example using csh:

	setenv CC gcc
	./configure
	make

Much of the code and documentation enclosed is copyright by
the Free Software Foundation, Inc.  See the file COPYING or
COPYING.LIB in the various directories, for a description of the
GNU General Public License terms under which you can copy the files.

REPORTING BUGS: Again, see gdb/README, binutils/README, etc., for info
on where and how to report problems.