Switch Python 2->3 (RH BZ 1014549).

This commit is contained in:
Jan Kratochvil 2015-02-16 15:56:42 +01:00
parent 7cbf529231
commit 61676c0354
4 changed files with 304 additions and 34 deletions

View File

@ -2,7 +2,7 @@ http://sourceware.org/gdb/wiki/ProjectArcher
http://sourceware.org/gdb/wiki/ArcherBranchManagement
GIT snapshot:
commit ef5e5e4d5bfedecf54ef7f1380eaf89662b617d0
commit d1a09bf2f8e7e3f752a1bbeba135bc080bf0c865
tromey/python
@ -304,7 +304,7 @@ index 0000000..6fa48ff
+IgnoreErrorsCommand ()
diff --git a/gdb/python/lib/gdb/command/pahole.py b/gdb/python/lib/gdb/command/pahole.py
new file mode 100644
index 0000000..636f99d
index 0000000..dee04f5
--- /dev/null
+++ b/gdb/python/lib/gdb/command/pahole.py
@@ -0,0 +1,81 @@
@ -339,7 +339,7 @@ index 0000000..636f99d
+ def maybe_print_hole(self, bitpos, field_bitpos):
+ if bitpos != field_bitpos:
+ hole = field_bitpos - bitpos
+ print ' /* XXX %d bit hole, try to pack */' % hole
+ print (' /* XXX %d bit hole, try to pack */' % hole)
+
+ def pahole (self, type, level, name):
+ if name is None:
@ -347,7 +347,7 @@ index 0000000..636f99d
+ tag = type.tag
+ if tag is None:
+ tag = ''
+ print '%sstruct %s {' % (' ' * (2 * level), tag)
+ print ('%sstruct %s {' % (' ' * (2 * level), tag))
+ bitpos = 0
+ for field in type.fields ():
+ # Skip static fields.
@ -365,33 +365,33 @@ index 0000000..636f99d
+ fieldsize = 8 * ftype.sizeof
+
+ # TARGET_CHAR_BIT
+ print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)),
+ print (' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)))
+ bitpos = bitpos + fieldsize
+
+ if ftype.code == gdb.TYPE_CODE_STRUCT:
+ self.pahole (ftype, level + 1, field.name)
+ else:
+ print ' ' * (2 + 2 * level),
+ print '%s %s' % (str (ftype), field.name)
+ print (' ' * (2 + 2 * level))
+ print ('%s %s' % (str (ftype), field.name))
+
+ if level == 0:
+ self.maybe_print_hole(bitpos, 8 * type.sizeof)
+
+ print ' ' * (14 + 2 * level),
+ print '} %s' % name
+ print (' ' * (14 + 2 * level))
+ print ('} %s' % name)
+
+ def invoke (self, arg, from_tty):
+ type = gdb.lookup_type (arg)
+ type = type.strip_typedefs ()
+ if type.code != gdb.TYPE_CODE_STRUCT:
+ raise TypeError, '%s is not a struct type' % arg
+ print ' ' * 14,
+ raise (TypeError, '%s is not a struct type' % arg)
+ print (' ' * 14)
+ self.pahole (type, 0, '')
+
+Pahole()
diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
new file mode 100644
index 0000000..debb3bb
index 0000000..8742680
--- /dev/null
+++ b/gdb/python/lib/gdb/function/in_scope.py
@@ -0,0 +1,47 @@
@ -419,31 +419,31 @@ index 0000000..debb3bb
+Takes one argument for each variable name to be checked."""
+
+ def __init__ (self):
+ super (InScope, self).__init__ ("in_scope")
+ super (InScope, self).__init__ ("in_scope")
+
+ def invoke (self, *vars):
+ if len (vars) == 0:
+ raise TypeError, "in_scope takes at least one argument"
+ raise (TypeError, "in_scope takes at least one argument")
+
+ # gdb.Value isn't hashable so it can't be put in a map.
+ # Convert to string first.
+ wanted = set (map (lambda x: x.string (), vars))
+ found = set ()
+ block = gdb.selected_frame ().block ()
+ while block:
+ for sym in block:
+ if (sym.is_argument or sym.is_constant
+ or sym.is_function or sym.is_variable):
+ if sym.name in wanted:
+ found.add (sym.name)
+ # Convert to string first.
+ wanted = set (map (lambda x: x.string (), vars))
+ found = set ()
+ block = gdb.selected_frame ().block ()
+ while block:
+ for sym in block:
+ if (sym.is_argument or sym.is_constant
+ or sym.is_function or sym.is_variable):
+ if sym.name in wanted:
+ found.add (sym.name)
+
+ block = block.superblock
+ block = block.superblock
+
+ return wanted == found
+ return wanted == found
+
+InScope ()
diff --git a/gdb/python/python.c b/gdb/python/python.c
index b1d8283..8eb8afe 100644
index b1d8283..54a2d9b 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -93,6 +93,8 @@ const struct extension_language_defn extension_language_python =
@ -455,7 +455,7 @@ index b1d8283..8eb8afe 100644
#include "target.h"
#include "gdbthread.h"
#include "interps.h"
@@ -1220,6 +1222,56 @@ gdbpy_print_stack (void)
@@ -1220,6 +1222,83 @@ gdbpy_print_stack (void)
/* Return the current Progspace.
There always is one. */
@ -495,7 +495,34 @@ index b1d8283..8eb8afe 100644
+ ensure_python_env (get_current_arch (), current_language);
+
+ running_python_script = 1;
+
+#if PYTHON_ABI_VERSION < 3
+ PySys_SetArgv (argc - 1, argv + 1);
+#else
+ {
+ wchar_t **wargv = alloca (sizeof (*wargv) * (argc + 1));
+ int i;
+
+ for (i = 1; i < argc; i++)
+ {
+ size_t len = mbstowcs (NULL, argv[i], 0);
+ size_t len2;
+
+ if (len == (size_t) -1)
+ {
+ fprintf (stderr, "Invalid multibyte argument #%d \"%s\"\n",
+ i, argv[i]);
+ exit (1);
+ }
+ wargv[i] = alloca (sizeof (**wargv) * (len + 1));
+ len2 = mbstowcs (wargv[i], argv[i], len + 1);
+ assert (len2 == len);
+ }
+ wargv[argc] = NULL;
+ PySys_SetArgv (argc - 1, wargv + 1);
+ }
+#endif
+
+ input = fopen (argv[0], "r");
+ if (! input)
+ {
@ -512,7 +539,7 @@ index b1d8283..8eb8afe 100644
static PyObject *
gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2)
@@ -1913,6 +1965,8 @@ static PyMethodDef GdbMethods[] =
@@ -1913,6 +1992,8 @@ static PyMethodDef GdbMethods[] =
Evaluate command, a string, as a gdb CLI command. Optionally returns\n\
a Python String containing the output of the command if to_string is\n\
set to True." },
@ -561,7 +588,7 @@ index e47f340..a7e0a52 100644
gdb_test "python print ('result = %s' % (gdb.selected_frame ().read_register ('sp') == gdb.parse_and_eval ('\$sp')))" \
" = True" \
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
index f081ff0..31b5910 100644
index f081ff0..58cce09 100644
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
@@ -388,6 +388,15 @@ proc test_value_after_death {} {
@ -574,7 +601,7 @@ index f081ff0..31b5910 100644
+proc test_cast_regression {} {
+ gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
+ gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
+ gdb_test "python print v" "5" "print value for cast test"
+ gdb_test "python print(v)" "5" "print value for cast test"
+}
+
# Regression test for invalid subscript operations. The bug was that

View File

@ -0,0 +1,175 @@
http://sourceware.org/ml/gdb-patches/2015-02/msg00091.html
Subject: [patch] Fix Python 3 build error on 32-bit hosts
--ZPt4rx8FFjLCG7dd
Content-Type: text/plain; charset=iso-2022-jp
Content-Disposition: inline
Hi,
on Fedora Rawhide (==22) i686 using --with-python=/usr/bin/python3 one gets:
gcc -g -I. -I. -I./common -I./config -DLOCALEDIR="\"/usr/local/share/locale\"" -DHAVE_CONFIG_H -I./../include/opcode -I./../opcodes/.. -I./../readline/.. -I../bfd -I./../bfd -I./../include -I../libdecnumber -I./../libdecnumber -I./gnulib/import -Ibuild-gnulib/import -DTUI=1 -pthread -I/usr/include/guile/2.0 -I/usr/include/python3.4m -I/usr/include/python3.4m -Wall -Wdeclaration-after-statement -Wpointer-arith -Wpointer-sign -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wmissing-prototypes -Wdeclaration-after-statement -Wempty-body -Wmissing-parameter-type -Wold-style-declaration -Wold-style-definition -Wformat-nonliteral -Werror -c -o py-value.o -MT py-value.o -MMD -MP -MF .deps/py-value.Tpo -fno-strict-aliasing -DNDEBUG -fwrapv ./python/py-value.c
./python/py-value.c:1696:3: error: initialization from incompatible pointer type [-Werror]
valpy_hash, /*tp_hash*/
^
./python/py-value.c:1696:3: error: (near initialization for $B!F(Bvalue_object_type.tp_hash$B!G(B) [-Werror]
cc1: all warnings being treated as errors
Makefile:2628: recipe for target 'py-value.o' failed
This is because in Python 2 tp_hash was:
typedef long (*hashfunc)(PyObject *);
while in Python 3 tp_hash is:
typedef Py_hash_t (*hashfunc)(PyObject *);
Py_hash_t is int for 32-bit hosts and long for 64-bit hosts. While on 32-bit
hosts sizeof(long)==sizeof(int) still the hashfunc type is formally
incompatible. As this patch should have no compiled code change it is not
really necessary for gdb-7.9, it would fix there just this non-fatal
compilation warning:
./python/py-value.c:1696:3: warning: initialization from incompatible pointer type
valpy_hash, /*tp_hash*/
^
./python/py-value.c:1696:3: warning: (near initialization for $B!F(Bvalue_object_type.tp_hash$B!G(B)
A question is whether the autoconf test isn't an overkill. One could use
instead just:
#if PYTHON_ABI_VERSION >= 3
Also one could use that #if either just at the valpy_hash() definition or one
could provide Py_hash_t in gdb/defs.h or one could provide some GDB_Py_hash_t
in gdb/defs.h.
Tested compilation with:
python-devel-2.7.9-4.fc22.x86_64
python-devel-2.7.9-4.fc22.i686
python3-devel-3.4.2-4.fc22.x86_64
python3-devel-3.4.2-4.fc22.i686
Jan
--ZPt4rx8FFjLCG7dd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline; filename=1
gdb/
2015-02-04 Jan Kratochvil <jan.kratochvil@redhat.com>
* configure.ac <"${have_libpython}" != no>: Define Py_hash_t.
* python/py-value.c (valpy_fetch_lazy): Use it. Remove cast to the
return type.
* config.in: Regenerate.
* configure: Regenerate.
diff --git a/gdb/config.in b/gdb/config.in
index 806cbac..44acfac 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -617,6 +617,9 @@
/* Define if the python directory should be relocated when GDB is moved. */
#undef PYTHON_PATH_RELOCATABLE
+/* Provide Python 3 Py_hash_t for Python 2. */
+#undef Py_hash_t
+
/* Relocated directory for source files. */
#undef RELOC_SRCDIR
diff --git a/gdb/configure b/gdb/configure
index 9632f9a..65f5b2c 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -8749,6 +8749,45 @@ rm -f conftest.err conftest.$ac_ext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${python_has_threads}" >&5
$as_echo "${python_has_threads}" >&6; }
CPPFLAGS="${saved_CPPFLAGS}"
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_hash_t" >&5
+$as_echo_n "checking for Py_hash_t... " >&6; }
+if test "${gdb_cv_Py_hash_t+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ old_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PYTHON_CFLAGS"
+ old_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <Python.h>
+int
+main ()
+{
+Py_hash_t var;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ gdb_cv_Py_hash_t=yes
+else
+ gdb_cv_Py_hash_t=no
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ CPPFLAGS="$old_CPPFLAGS"
+ CFLAGS="$old_CFLAGS"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_Py_hash_t" >&5
+$as_echo "$gdb_cv_Py_hash_t" >&6; }
+ if test "x$gdb_cv_Py_hash_t" = "xno"; then
+
+$as_echo "#define Py_hash_t long" >>confdefs.h
+
+ fi
else
# Even if Python support is not compiled in, we need to have this file
# included so that the "python" command, et.al., still exists.
diff --git a/gdb/configure.ac b/gdb/configure.ac
index dfc6947..f335b7b 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1016,6 +1016,25 @@ if test "${have_libpython}" != no; then
]]), [python_has_threads=no], [python_has_threads=yes])
AC_MSG_RESULT(${python_has_threads})
CPPFLAGS="${saved_CPPFLAGS}"
+
+ AC_CACHE_CHECK([for Py_hash_t], gdb_cv_Py_hash_t,
+ old_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PYTHON_CFLAGS"
+ old_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
+ AC_TRY_COMPILE(
+ [#include <Python.h>],
+ [Py_hash_t var;],
+ gdb_cv_Py_hash_t=yes,
+ gdb_cv_Py_hash_t=no
+ )
+ CPPFLAGS="$old_CPPFLAGS"
+ CFLAGS="$old_CFLAGS"
+ )
+ if test "x$gdb_cv_Py_hash_t" = "xno"; then
+ AC_DEFINE(Py_hash_t, long,
+ [Provide Python 3 Py_hash_t for Python 2.])
+ fi
else
# Even if Python support is not compiled in, we need to have this file
# included so that the "python" command, et.al., still exists.
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 4c4d36e..5a13777 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -895,10 +895,10 @@ valpy_fetch_lazy (PyObject *self, PyObject *args)
/* Calculate and return the address of the PyObject as the value of
the builtin __hash__ call. */
-static long
+static Py_hash_t
valpy_hash (PyObject *self)
{
- return (long) (intptr_t) self;
+ return (intptr_t) self;
}
enum valpy_opcode

View File

@ -0,0 +1,56 @@
http://sourceware.org/ml/gdb-patches/2015-02/msg00361.html
Subject: PR python/17927 (Python 3 testsuite compatability)
This patch updates the Python testsuite to maintain Python 3
compatibility. I'll check it in under the obvious tomorrow (if
nobody objects otherwise.)
Cheers
Phil
2015-02-16 Phil Muldoon <pmuldoon@redhat.com>
PR python/17927
* gdb.python/py-objfile.exp: Use print ()
* gdb.python/py-type.exp: Ditto.
* gdb.python/py-framefilter.py: Update to use map in
Python 3.
--
diff --git a/gdb/testsuite/gdb.python/py-framefilter.py b/gdb/testsuite/gdb.python/py-framefilter.py
index 0de026c..8c65edc 100644
--- a/gdb/testsuite/gdb.python/py-framefilter.py
+++ b/gdb/testsuite/gdb.python/py-framefilter.py
@@ -145,7 +145,10 @@ class ErrorFilter():
gdb.frame_filters [self.name] = self
def filter(self, frame_iter):
- return itertools.imap(ErrorInName, frame_iter)
+ if hasattr(itertools, "imap"):
+ return itertools.imap(ErrorInName, frame_iter)
+ else:
+ return map(ErrorInName, frame_iter)
FrameFilter()
FrameElider()
diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp
index c4c8d9f..6c4e5f8 100644
--- a/gdb/testsuite/gdb.python/py-type.exp
+++ b/gdb/testsuite/gdb.python/py-type.exp
@@ -247,10 +247,10 @@ restart_gdb "${binfile}"
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
-gdb_test "python print gdb.lookup_type('char').array(1, 0)" \
+gdb_test "python print (gdb.lookup_type('char').array(1, 0))" \
"char \\\[0\\\]"
-gdb_test "python print gdb.lookup_type('char').array(1, -1)" \
+gdb_test "python print (gdb.lookup_type('char').array(1, -1))" \
"Array length must not be negative.*"
with_test_prefix "lang_c" {

View File

@ -26,7 +26,7 @@ Version: 7.8.90.20150214
# The release always contains a leading reserved number, start it at 1.
# `upstream' is not a part of `name' to stay fully rpm dependencies compatible for the testing.
Release: 6%{?dist}
Release: 7%{?dist}
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ and GPLv2+ with exceptions and GPL+ and LGPLv2+ and BSD and Public Domain and GFDL
Group: Development/Debuggers
@ -532,6 +532,12 @@ Patch979: gdb-6.8-bz457187-largefile-test-regression-fix.patch
# Temporarily disable dg-extract-results.py to fix gdb.sum sorting.
Patch982: gdb-no-dg-extract-results-py.patch
# Fix Python 3 build error on 32-bit hosts.
Patch984: gdb-python3-py_hash_t-32bit.patch
# Fix Python 3 testsuite regressions.
Patch985: gdb-python3-testsuite.patch
%if 0%{!?rhel:1} || 0%{?rhel} > 6
# RL_STATE_FEDORA_GDB would not be found for:
# Patch642: gdb-readline62-ask-more-rh.patch
@ -548,7 +554,8 @@ BuildRequires: xz-devel%{?_isa}
BuildRequires: rpm-devel%{?_isa}
BuildRequires: zlib-devel%{?_isa} libselinux-devel%{?_isa}
%if 0%{!?_without_python:1}
BuildRequires: python-devel%{?_isa}
%global __python %{__python3}
BuildRequires: python3-devel%{?_isa}
%if 0%{?rhel:1} && 0%{?rhel} <= 6
# Temporarily before python files get moved to libstdc++.rpm
# libstdc++%{bits_other} is not present in Koji, the .spec script generating
@ -819,6 +826,8 @@ find -name "*.info*"|xargs rm -f
%patch978 -p1
%patch979 -p1
%patch982 -p1
%patch984 -p1
%patch985 -p1
%patch848 -p1
%if 0%{!?el6:1}
@ -921,7 +930,7 @@ $(: ppc64 host build crashes on ppc variant of libexpat.so ) \
--without-libexpat-prefix \
--enable-tui \
%if 0%{!?_without_python:1}
--with-python \
--with-python=%{__python} \
%else
--without-python \
%endif
@ -1315,6 +1324,9 @@ then
fi
%changelog
* Mon Feb 16 2015 Jan Kratochvil <jan.kratochvil@redhat.com> - 7.8.90.20150214-7.fc22
- Switch Python 2->3 (RH BZ 1014549).
* Sat Feb 14 2015 Jan Kratochvil <jan.kratochvil@redhat.com> - 7.8.90.20150214-6.fc22
- Rebase to 7.9-branch snapshot 7.8.90.20150214.