This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA/python:1/2] Add support for --with-pythondir.
- From: Joel Brobecker <brobecker at adacore dot com>
- To: gdb-patches at sourceware dot org
- Cc: Joel Brobecker <brobecker at adacore dot com>
- Date: Wed, 26 May 2010 17:08:40 -0700
- Subject: [RFA/python:1/2] Add support for --with-pythondir.
- References: <1274918921-23200-1-git-send-email-brobecker@adacore.com>
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 <tromey@adacore.com>
Joel Brobecker <brobecker@adacore.com>
* 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/<path>)
+ --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