[PATCH] GDB: Prefer Python 3 over 2

Chris Johns chrisj at rtems.org
Sun Mar 20 22:22:31 UTC 2022


On 19/3/2022 8:33 pm, Sebastian Huber wrote:
> On 18/03/2022 22:56, Chris Johns wrote:
>>
>>> On 19 Mar 2022, at 2:40 am, Sebastian Huber
>>> <sebastian.huber at embedded-brains.de> wrote:
>>>
>>> On 17/03/2022 12:51, Sebastian Huber wrote:
>>>> This fixes the build of a recent GDB version:
>>>> gdb/python/py-micmd.c: In function 'int
>>>> micmdpy_uninstall_command(micmdpy_object*)':
>>>> gdb/python/py-micmd.c:430:20: error: 'PyDict_GetItemWithError' was not
>>>> declared in this scope
>>>>     PyObject *curr = PyDict_GetItemWithError (mi_cmd_dict.get (),
>>>>                      ^~~~~~~~~~~~~~~~~~~~~~~
>>
>> Has a bug report been raised with gdb?
> 
> The Python 2 EOL was January 1, 2020. This code was added by:
> 
> commit 740b42ceb7c7ae7b5343183782973576a93bc7b3
> Author: Andrew Burgess <aburgess at redhat.com>
> Date:   Tue Jun 23 14:45:38 2020 +0100
> 
>     gdb/python/mi: create MI commands using python
> 
> It is not a bug from my point of view.

The change has been reviewed again ...

commit 5ec0444e8312c17e628739ebd7b8f0e29df3c9e9
Author: Andrew Burgess <aburgess at redhat.com>
Date:   Fri Mar 18 15:55:34 2022 +0000

    gdb: supply PyDict_GetItemWithError when compiling with Python2

    Commit

      commit 740b42ceb7c7ae7b5343183782973576a93bc7b3
      Date:   Tue Jun 23 14:45:38 2020 +0100

          gdb/python/mi: create MI commands using python

    Introduced a use of PyDict_GetItemWithError, which is not available in
    Python2, and so the Python2 build was broken.

    This commit provides a work around for this:

      #define PyDict_GetItemWithError PyDict_GetItem

    The arguments passed to these calls are identical, the difference is
    that the WithError version will return with an exception raised in
    some error cases, while the PyDict_GetItem suppresses some errors, and
    just returns nullptr.

    Given that we are almost at the GDB 12 branch point, this commit is
    the easiest change to get the Python2 build working again.  After GDB
    12 branches the plan is to remove Python2 support, so this #define
    will be removed anyway.

    As far as functionality I think this #define will be fine.  In the
    "normal" no error case, then obviously, everything will be fine.  The
    only difference is what happens when an error occurs.

    The only errors I think could happen if Python runs into problems
    hashing the string, or comparing the strings for equality.  Given the
    limited strings we're working with I don't expect that this should
    occur during normal operation.  So, my expectation is that this should
    only happen if they user has gone and messed around with this hash in
    some way - in which case I think it's OK if weird things happen.

    This issue was discussed on IRC, and I think Simon might be working on
    an alternative patch to remove the _mi_commands dictionary from the
    gdb module, in which case the use of PyDict_GetItemWithError will be
    removed completely.  I'm posting this just in case people want to
    consider a minimal work around for the breakage in the short term.

>>> I was able to build the latest GDB with this patch. Otherwise all
>>> architectures failed with the above error.
>>
>> Has gdb dropped Python 2 support?
> 
> It seems so.

It seems from above is after gdb 12 has branched. We could settle on gdb 12 for
rtems6?

>>
>> What happens on a host without python3 installed? Does the error appear? Does
>> this in effect force RTEMS to drop the Python2 requirement for rtems6?
> 
> I guess if we want to use the next GDB release, then Python 3 is required.
> 

Then this changes rtems6 because it forces a major change I had not expected on
to rtems6. I suggest a separate thread be started to again consider removing
python 2 support for rtems6. It do not bother me but we have some users where is
may so it is best to ask openly.

Chris


More information about the devel mailing list