Re: [RFA] ignore PYTHONHOME environment variable.

Joel Brobecker
2012-05-28T14:41:53Z

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