public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix build for empty with-python, but with-python-libdir
@ 2021-10-25 17:53 Alexey Lapshin
  2021-10-25 18:14 ` Simon Marchi
  0 siblings, 1 reply; 8+ messages in thread
From: Alexey Lapshin @ 2021-10-25 17:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Alexey Lapshin

---
 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:
-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix build for empty with-python, but with-python-libdir
  2021-10-25 17:53 [PATCH] Fix build for empty with-python, but with-python-libdir Alexey Lapshin
@ 2021-10-25 18:14 ` Simon Marchi
  2021-10-26  6:09   ` Alexey Lapshin
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Marchi @ 2021-10-25 18:14 UTC (permalink / raw)
  To: Alexey Lapshin, gdb-patches

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix build for empty with-python, but with-python-libdir
  2021-10-25 18:14 ` Simon Marchi
@ 2021-10-26  6:09   ` Alexey Lapshin
  2021-10-26 16:40     ` Simon Marchi
  0 siblings, 1 reply; 8+ messages in thread
From: Alexey Lapshin @ 2021-10-26  6:09 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix build for empty with-python, but with-python-libdir
  2021-10-26  6:09   ` Alexey Lapshin
@ 2021-10-26 16:40     ` Simon Marchi
  2021-10-26 18:21       ` Alexey Lapshin
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Marchi @ 2021-10-26 16:40 UTC (permalink / raw)
  To: Alexey Lapshin, gdb-patches

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix build for empty with-python, but with-python-libdir
  2021-10-26 16:40     ` Simon Marchi
@ 2021-10-26 18:21       ` Alexey Lapshin
  2021-10-27 16:15         ` Simon Marchi
  2021-10-27 21:58         ` Alexey Lapshin
  0 siblings, 2 replies; 8+ messages in thread
From: Alexey Lapshin @ 2021-10-26 18:21 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

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!


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix build for empty with-python, but with-python-libdir
  2021-10-26 18:21       ` Alexey Lapshin
@ 2021-10-27 16:15         ` Simon Marchi
  2021-10-27 21:58         ` Alexey Lapshin
  1 sibling, 0 replies; 8+ messages in thread
From: Simon Marchi @ 2021-10-27 16:15 UTC (permalink / raw)
  To: Alexey Lapshin, gdb-patches

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

Hmm, I wasn't able to reproduce with just that, WITH_PYTHON_PATH always
gets set here (I think via pythonX.Y-config).

Simon

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix build for empty with-python, but with-python-libdir
  2021-10-26 18:21       ` Alexey Lapshin
  2021-10-27 16:15         ` Simon Marchi
@ 2021-10-27 21:58         ` Alexey Lapshin
  2021-10-29 13:04           ` Alexey Lapshin
  1 sibling, 1 reply; 8+ messages in thread
From: Alexey Lapshin @ 2021-10-27 21:58 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches; +Cc: Alexey Gerenkov, Ivan Grokhotkov

On 10/27/21 7:15 PM, Simon Marchi wrote:
On 10/26/21 9:21 PM, alexey lapshin wrote:
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><mailto: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!

[External: This email originated outside Espressif]



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


Hmm, I wasn't able to reproduce with just that, WITH_PYTHON_PATH always
gets set here (I think via pythonX.Y-config).

Simon


Sorry, I did not tell you that I compiled it not in a common way.
My case is compile gdb for different targets (win, macos). And having python-config ruins the build because it provides wrong flags for compiling. To avoid this I'm using only a python's header files and dynamic library.
After gdb compiled and linked with python lib - it goes to a target machine. And after that I faced a problem with loading _gdb module.

Also I found that configure script also tries to add linking with python2.7 library even --with-python-libdir was specified.
It was unexpected for me behavior. I think it should search library in the provided directory first... What do you think?

Thanks, Alexey

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix build for empty with-python, but with-python-libdir
  2021-10-27 21:58         ` Alexey Lapshin
@ 2021-10-29 13:04           ` Alexey Lapshin
  0 siblings, 0 replies; 8+ messages in thread
From: Alexey Lapshin @ 2021-10-29 13:04 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches; +Cc: Alexey Gerenkov, Ivan Grokhotkov

On 10/28/21 12:58 AM, Alexey Lapshin wrote:
> On 10/27/21 7:15 PM, Simon Marchi wrote:
>> On 10/26/21 9:21 PM, alexey lapshin wrote:
>>> 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!
>> [External: This email originated outside Espressif]
>>
>>> To reproduce just configure with "--with-python
>>> --with-python-libdir=$PYTHON_LIB_DIR". Do not specify --with-python=...
>>> keep it without path value.
>> Hmm, I wasn't able to reproduce with just that, WITH_PYTHON_PATH always
>> gets set here (I think via pythonX.Y-config).
>>
>> Simon
>
> Sorry, I did not tell you that I compiled it not in a common way.
> My case is compile gdb for different targets (win, macos). And having 
> python-config ruins the build because it provides wrong flags for 
> compiling. To avoid this I'm using only a python's header files and 
> dynamic library.
> After gdb compiled and linked with python lib - it goes to a target 
> machine. And after that I faced a problem with loading _gdb module.
>
> Also I found that configure script also tries to add linking with 
> python2.7 library even --with-python-libdir was specified.
> It was unexpected for me behavior. I think it should search library in 
> the provided directory first... What do you think?
>
> Thanks, Alexey

Hi Simon,

This patch fixes python initialization

---
  gdb/defs.h          |  2 ++
  gdb/main.c          |  2 ++
  gdb/python/python.c | 10 ++++++----
  3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/gdb/defs.h b/gdb/defs.h
index f7e09eca9db..a7deaad2af2 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;

+#ifdef 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 ca4ccc375dc..e2057575a17 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;

+#ifdef 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 c81814c557b..61aac8241d6 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 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:
@@ -1792,12 +1792,14 @@ do_start_initialization ()
       remain alive for the duration of the program's execution, so
       it is not freed after this call.  */
    Py_SetProgramName (progname_copy);
+#else
+  Py_SetProgramName (progname.release ());
+#endif // IS_PY3K
+#endif // WITH_PYTHON_LIBDIR

+#ifdef IS_PY3K
    /* Define _gdb as a built-in module.  */
    PyImport_AppendInittab ("_gdb", init__gdb_module);
-#else
-  Py_SetProgramName (progname.release ());
-#endif
  #endif

    Py_Initialize ();
-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-10-29 13:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-25 17:53 [PATCH] Fix build for empty with-python, but with-python-libdir Alexey Lapshin
2021-10-25 18:14 ` Simon Marchi
2021-10-26  6:09   ` Alexey Lapshin
2021-10-26 16:40     ` Simon Marchi
2021-10-26 18:21       ` Alexey Lapshin
2021-10-27 16:15         ` Simon Marchi
2021-10-27 21:58         ` Alexey Lapshin
2021-10-29 13:04           ` Alexey Lapshin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).