This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] ignore PYTHONHOME environment variable.
- From: Joel Brobecker <brobecker at adacore dot com>
- To: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- Cc: Doug Evans <dje at google dot com>, gdb-patches at sourceware dot org, David Malcolm <dmalcolm at redhat dot com>, Tom Tromey <tromey at redhat dot com>, Ben Woodard <woodard at redhat dot com>
- Date: Mon, 28 May 2012 07:41:21 -0700
- Subject: Re: [RFA] ignore PYTHONHOME environment variable.
- References: <1290474202-885-1-git-send-email-brobecker@adacore.com> <20101123030037.GA19962@host0.dyn.jankratochvil.net> <AANLkTiko2FVL+ktF9JTBRedYz_wvsq_eP4rU3rLcOYmF@mail.gmail.com> <20101123163045.GA1737@host0.dyn.jankratochvil.net> <AANLkTi=W+PnwOfNkRRe5OMz0qm5vCghhduO5ve1Qk3zH@mail.gmail.com> <20101123173054.GW2634@adacore.com> <20101214071210.GQ2596@adacore.com> <20101214092645.GA20415@host0.dyn.jankratochvil.net> <20101214103305.GU2596@adacore.com> <20120518193352.GA12340@host2.jankratochvil.net>
Hi Jan,
On Fri, May 18, 2012 at 09:33:52PM +0200, Jan Kratochvil wrote:
> On Tue, 14 Dec 2010 11:33:05 +0100, Joel Brobecker wrote:
> > What we can also do is warn users when we see that PYTHONHOME is
> > defined and not GDB_PYTHON_HOME. That way, they are not surprised
> > when that happens, and they get a helpful indication of how to
> > remedy the problem.
Just curious why you revived this discussion. I had written off
our changes in this area as vendor-specific, and given up on the
idea of putting it in the FSF tree for others to use.... Is there
something you need to fix on your side?
> Therefore:
>
> if ($GDB_PYTHONHOME exists) {
> use it
> } else if ($PYTHONHOME exists) {
> warn on it
> ignore it
> pass it to spawned debuggees
> } else {
> let Python use it's defaults
> }
>
> That "ignore it" part may be difficult as despite Py_SetPythonHome
> overrides $PYTHONHOME if !defined WITH_PYTHON_PATH we do not know
> which string to use for Py_SetPythonHome to override it. So maybe to
> use unsetenv before Py_Initialize and setenv the saved string back
> afterwards.
This is how we do it at AdaCore:
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 9a80dea..cc95940 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1222,6 +1222,10 @@ message == an error message without a stack will be printed."),
This must be done before calling Py_Initialize. */
Py_SetProgramName (concat (ldirname (python_libdir), SLASH_STRING, "bin",
SLASH_STRING, "python", NULL));
+
+ /* We override any value that the PYTHONHOME might have, as we want
+ to make sure that we use the Python library that comes with GDB. */
+ Py_SetPythonHome (ldirname (python_libdir));
#endif
Py_Initialize ();
It doesn't look at GDB_PYTHONHOME because we have never encountered
a situation when we needed it. But does it answer your question about
"ignore it"? We "ignore" the PYTHON_HOME value by just forcing it
using Py_SetPythonHome.
> Also I believe it should apply to any environment starting with PYTHON* as
> besides
I less sure about that...
The purpose of the proposal to ignore PYTHONHOME is to make sure that
the user does not accidently use a Python install which is incompatible
with the version that GDB was built with. I am not sure whether we should
deal with PYTHONPATH, but it seems that letthing PYTHONVERBOSE through
would be OK or even desirable...
--
Joel