From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24056 invoked by alias); 27 May 2010 00:09:15 -0000 Received: (qmail 23937 invoked by uid 22791); 27 May 2010 00:09:13 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 27 May 2010 00:09:05 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 72CC22BABF2; Wed, 26 May 2010 20:09:03 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id klsl-7foMXxy; Wed, 26 May 2010 20:09:03 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 2E1572BAB97; Wed, 26 May 2010 20:09:03 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id E52F0F5888; Wed, 26 May 2010 17:08:51 -0700 (PDT) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [RFA/python:1/2] Add support for --with-pythondir. Date: Thu, 27 May 2010 00:25:00 -0000 Message-Id: <1274918921-23200-2-git-send-email-brobecker@adacore.com> In-Reply-To: <1274918921-23200-1-git-send-email-brobecker@adacore.com> References: <1274918921-23200-1-git-send-email-brobecker@adacore.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-05/txt/msg00623.txt.bz2 This is the location where the GDB python library should be installed. The default is ${datadir}/python. As with various other paths, it is relocatable if it is a subdir of the prefix. The code is mostly inspired from some work done in Archer. Based on the revision history, I think that Tom Tromey should be credited. I did rewrite the configury part by taking advantage of a patch that Doug Evans just submitted (and will hopefully commit soon). http://www.sourceware.org/ml/gdb-patches/2010-05/msg00476.html (Allow python to find its files if moved from original location) 2010-05-26 Tom Tromey Joel Brobecker * configure.ac: Add handling of --with-pythondir. * configure, config.in: Regenerate. * python/python.c (_initialize_python): Add variable "pythondir" inside module gdb. Initialize variable gdb.__path__ and execute __init__.py if found in subdirectory "gdb" of the pythondir. Tested on x86_64-linux. I tested this using various combinations of prefix, and --with-pythondir, both causing relocatable and non-relocatable paths to the pythondir... --- gdb/config.in | 7 ++++++ gdb/configure | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/configure.ac | 4 +++ gdb/python/python.c | 7 ++++++ 4 files changed, 70 insertions(+), 0 deletions(-) diff --git a/gdb/config.in b/gdb/config.in index afbd76d..b4f2f55 100644 --- a/gdb/config.in +++ b/gdb/config.in @@ -75,6 +75,13 @@ /* Define to the default OS ABI for this configuration. */ #undef GDB_OSABI_DEFAULT +/* look for global python files in this path [GDB_DATADIR/python] */ +#undef GDB_PYTHONDIR + +/* Define if the gdb-pythondir directory should be relocated when GDB is + moved. */ +#undef GDB_PYTHONDIR_RELOCATABLE + /* Define to 1 when the gnulib module memchr should be tested. */ #undef GNULIB_TEST_MEMCHR diff --git a/gdb/configure b/gdb/configure index 02b8720..487e7b6 100755 --- a/gdb/configure +++ b/gdb/configure @@ -658,6 +658,7 @@ TARGET_SYSTEM_ROOT_DEFINE TARGET_SYSTEM_ROOT CONFIG_LDFLAGS ALLOCA +GDB_PYTHONDIR PYTHON_CFLAGS LTLIBEXPAT LIBEXPAT @@ -962,6 +963,7 @@ with_gnu_ld enable_rpath with_libexpat_prefix with_python +with_gdb_pythondir with_included_regex with_sysroot with_system_gdbinit @@ -1658,6 +1660,9 @@ Optional Packages: --with-libexpat-prefix[=DIR] search for libexpat in DIR/include and DIR/lib --without-libexpat-prefix don't search for libexpat in includedir and libdir --with-python include python support (auto/yes/no/) + --with-gdb-pythondir=PATH + look for global python files in this path + [GDB_DATADIR/python] --without-included-regex don't use included regex; this is the default on systems with version 2 of the GNU C library (use @@ -10691,6 +10696,53 @@ else fi + + +# Check whether --with-gdb-pythondir was given. +if test "${with_gdb_pythondir+set}" = set; then : + withval=$with_gdb_pythondir; + GDB_PYTHONDIR=$withval +else + GDB_PYTHONDIR=${GDB_DATADIR}/python +fi + + + test "x$prefix" = xNONE && prefix="$ac_default_prefix" + test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + ac_define_dir=`eval echo $GDB_PYTHONDIR` + ac_define_dir=`eval echo $ac_define_dir` + +cat >>confdefs.h <<_ACEOF +#define GDB_PYTHONDIR "$ac_define_dir" +_ACEOF + + + + + if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then + if test "x$prefix" = xNONE; then + test_prefix=/usr/local + else + test_prefix=$prefix + fi + else + test_prefix=$exec_prefix + fi + value=0 + case ${ac_define_dir} in + "${test_prefix}"|"${test_prefix}/"*|\ + '${exec_prefix}'|'${exec_prefix}/'*) + value=1 + ;; + esac + +cat >>confdefs.h <<_ACEOF +#define GDB_PYTHONDIR_RELOCATABLE $value +_ACEOF + + + + # ------------------------- # # Checks for header files. # # ------------------------- # diff --git a/gdb/configure.ac b/gdb/configure.ac index 5b7bc38..1f423fa 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -715,6 +715,10 @@ else fi AC_SUBST(PYTHON_CFLAGS) +GDB_AC_WITH_DIR(GDB_PYTHONDIR, gdb-pythondir, + [look for global python files in this path @<:@GDB_DATADIR/python@:>@], + [${GDB_DATADIR}/python]) + # ------------------------- # # Checks for header files. # # ------------------------- # diff --git a/gdb/python/python.c b/gdb/python/python.c index 0b7b7ba..00a1ecc 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -668,6 +668,7 @@ Enables or disables printing of Python stack traces."), PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name); PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG", (char*) target_name); + PyModule_AddStringConstant (gdb_module, "pythondir", GDB_PYTHONDIR); gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL); PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc); @@ -718,6 +719,12 @@ class GdbOutputFile:\n\ \n\ sys.stderr = GdbOutputFile()\n\ sys.stdout = GdbOutputFile()\n\ +sys.path.insert(0, gdb.pythondir)\n\ +gdb.__path__ = [gdb.pythondir + '/gdb']\n\ +from os.path import exists\n\ +ipy = gdb.pythondir + '/gdb/__init__.py'\n\ +if exists (ipy):\n\ + execfile (ipy)\n\ "); /* Release the GIL while gdb runs. */ -- 1.7.1