[PATCH] Fix build for empty with-python, but with-python-libdir

Alexey Lapshin alexey.lapshin@espressif.com
Tue Oct 26 18:21:08 GMT 2021


On 10/26/21 7:40 PM, Simon Marchi wrote:
> [External: This email originated outside Espressif]
>
> On 2021-10-26 02:09, Alexey Lapshin wrote:
>> On 10/25/21 9:14 PM, Simon Marchi wrote:
>>> [External: This email originated outside Espressif]
>>>
>>> On 2021-10-25 13:53, Alexey Lapshin via Gdb-patches wrote:
>>>> ---
>>>>    gdb/python/python.c | 2 +-
>>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/gdb/python/python.c b/gdb/python/python.c
>>>> index c81814c557b..9e8e0149ba9 100644
>>>> --- a/gdb/python/python.c
>>>> +++ b/gdb/python/python.c
>>>> @@ -1756,7 +1756,7 @@ gdbpy_gdb_exiting (int exit_code)
>>>>    static bool
>>>>    do_start_initialization ()
>>>>    {
>>>> -#ifdef WITH_PYTHON_PATH
>>>> +#ifdef HAVE_PYTHON
>>>>      /* Work around problem where python gets confused about where it is,
>>>>         and then can't find its libraries, etc.
>>>>         NOTE: Python assumes the following layout:
>>>>
>>> Hi,
>>>
>>> Please provide a commit message that describes the issue that you see
>>> and that you try to fix.
>>>
>>> Simon
>> Hi,
>>
>> The issue I faced when compile gdb with python. Configure options are
>> --with-python --with-python-libdir=$PYTHON_DIR/lib. The issue appears if
>> I do not specify path to python via --with-python option flag.
>>
>> The problem which I see after the gdb build:
>> python exception <type 'exceptions.ImportError'> No module named _gdb
>>
>> Because _gdb is built-in module which loads in block of code under
>> "ifdef WITH_PYTHON_PATH".
>> I changed it to more suitable "ifdef HAVE_PYTHON" and it works perfectly
>>
> Ok, I'm not too sure how to reproduce on my side.  But looking at the
> code, it sounds like we want to protect the use of python_libdir here.
> So maybe we would want to check for the WITH_PYTHON_LIBDIR macro
> instead?  And maybe even not define the python_libdir variable at all if
> WITH_PYTHON_LIBDIR isn't defined.  Would the patch below work for you?
>
>  From 8ff9005b53476ef86ca6fb0a8f5e4c0415452aa1 Mon Sep 17 00:00:00 2001
> From: Simon Marchi <simon.marchi@polymtl.ca>
> Date: Tue, 26 Oct 2021 12:30:05 -0400
> Subject: [PATCH] gdb: protect use of python_libdir using WITH_PYTHON_LIBDIR
>
> Change-Id: I5f9d4bc20f4b7ab8f8a9569c37e302feab232f16
> ---
>   gdb/defs.h          | 2 ++
>   gdb/main.c          | 2 ++
>   gdb/python/python.c | 2 +-
>   3 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/defs.h b/gdb/defs.h
> index f7e09eca9db1..48da639ebd03 100644
> --- a/gdb/defs.h
> +++ b/gdb/defs.h
> @@ -126,9 +126,11 @@ extern std::string gdb_sysroot;
>   /* * GDB datadir, used to store data files.  */
>   extern std::string gdb_datadir;
>
> +#if defined(WITH_PYTHON_LIBDIR)
>   /* * If not empty, the possibly relocated path to python's "lib" directory
>      specified with --with-python.  */
>   extern std::string python_libdir;
> +#endif
>
>   /* * Search path for separate debug files.  */
>   extern std::string debug_file_directory;
> diff --git a/gdb/main.c b/gdb/main.c
> index ca4ccc375dc7..19cb845538fd 100644
> --- a/gdb/main.c
> +++ b/gdb/main.c
> @@ -75,9 +75,11 @@ std::string gdb_datadir;
>      command line, but we don't reread system.gdbinit when that happens.  */
>   static int gdb_datadir_provided = 0;
>
> +#if defined(WITH_PYTHON_LIBDIR)
>   /* If gdb was configured with --with-python=/path,
>      the possibly relocated path to python's lib directory.  */
>   std::string python_libdir;
> +#endif
>
>   /* Target IO streams.  */
>   struct ui_file *gdb_stdtargin;
> diff --git a/gdb/python/python.c b/gdb/python/python.c
> index c81814c557be..489e0ce5f910 100644
> --- a/gdb/python/python.c
> +++ b/gdb/python/python.c
> @@ -1756,7 +1756,7 @@ gdbpy_gdb_exiting (int exit_code)
>   static bool
>   do_start_initialization ()
>   {
> -#ifdef WITH_PYTHON_PATH
> +#if defined(WITH_PYTHON_LIBDIR)
>     /* Work around problem where python gets confused about where it is,
>        and then can't find its libraries, etc.
>        NOTE: Python assumes the following layout:
> --
> 2.33.1

To reproduce just configure with "--with-python 
--with-python-libdir=$PYTHON_LIB_DIR". Do not specify --with-python=... 
keep it without path value.


I will check your patch soon, thank you!



More information about the Gdb-patches mailing list