bound_registers.py: Add support for Python 3

Message ID 20161120204526.7203-1-jonah@kichwacoders.com
State New, archived
Headers

Commit Message

Jonah Graham Nov. 20, 2016, 8:45 p.m. UTC
  gdb/Changelog:

	* python/lib/gdb/printer/bound_registers.py: Add support
	for Python 3.
---
 gdb/ChangeLog                                 | 5 +++++
 gdb/python/lib/gdb/printer/bound_registers.py | 5 +++++
 2 files changed, 10 insertions(+)
  

Comments

Jonah Graham Nov. 20, 2016, 8:50 p.m. UTC | #1
Hi GDB devs,

This patch fixes
https://sourceware.org/bugzilla/show_bug.cgi?id=19637. This is my
first patch to GDB, I hope it falls within the "Small changes can be
accepted without a copyright assignment form on file." from the
CONTRIBUTING file as the new code in this file was copied from
printing.py as recommended in the bug report. In case it doesn't, and
to cover future contributions, I have started the copyright assignment
process.

Thank you,
Jonah
~~~
Jonah Graham
Kichwa Coders Ltd.
www.kichwacoders.com


On 20 November 2016 at 20:45, Jonah Graham <jonah@kichwacoders.com> wrote:
> gdb/Changelog:
>
>         * python/lib/gdb/printer/bound_registers.py: Add support
>         for Python 3.
> ---
>  gdb/ChangeLog                                 | 5 +++++
>  gdb/python/lib/gdb/printer/bound_registers.py | 5 +++++
>  2 files changed, 10 insertions(+)
>
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 3797e8b..1923888 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,8 @@
> +2016-11-20  Jonah Graham  <jonah@kichwacoders.com>
> +
> +       * python/lib/gdb/printer/bound_registers.py: Add support
> +       for Python 3.
> +
>  2016-11-19  Joel Brobecker  <brobecker@adacore.com>
>
>         * contrib/ari/gdb_ari.sh: Add detection of printf_vma and
> diff --git a/gdb/python/lib/gdb/printer/bound_registers.py b/gdb/python/lib/gdb/printer/bound_registers.py
> index 9ff94aa..e91cc19 100644
> --- a/gdb/python/lib/gdb/printer/bound_registers.py
> +++ b/gdb/python/lib/gdb/printer/bound_registers.py
> @@ -16,6 +16,11 @@
>
>  import gdb.printing
>
> +if sys.version_info[0] > 2:
> +    # Python 3 removed basestring and long
> +    basestring = str
> +    long = int
> +
>  class MpxBound128Printer:
>      """Adds size field to a mpx __gdb_builtin_type_bound128 type."""
>
> --
> 2.10.1
>
  
Luis Machado Nov. 23, 2016, 4:59 p.m. UTC | #2
On 11/20/2016 02:45 PM, Jonah Graham wrote:
> gdb/Changelog:
>
> 	* python/lib/gdb/printer/bound_registers.py: Add support
> 	for Python 3.
> ---
>  gdb/ChangeLog                                 | 5 +++++
>  gdb/python/lib/gdb/printer/bound_registers.py | 5 +++++
>  2 files changed, 10 insertions(+)
>
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 3797e8b..1923888 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,8 @@
> +2016-11-20  Jonah Graham  <jonah@kichwacoders.com>
> +
> +	* python/lib/gdb/printer/bound_registers.py: Add support
> +	for Python 3.
> +
>  2016-11-19  Joel Brobecker  <brobecker@adacore.com>
>
>  	* contrib/ari/gdb_ari.sh: Add detection of printf_vma and
> diff --git a/gdb/python/lib/gdb/printer/bound_registers.py b/gdb/python/lib/gdb/printer/bound_registers.py
> index 9ff94aa..e91cc19 100644
> --- a/gdb/python/lib/gdb/printer/bound_registers.py
> +++ b/gdb/python/lib/gdb/printer/bound_registers.py
> @@ -16,6 +16,11 @@
>
>  import gdb.printing
>
> +if sys.version_info[0] > 2:
> +    # Python 3 removed basestring and long
> +    basestring = str
> +    long = int
> +
>  class MpxBound128Printer:
>      """Adds size field to a mpx __gdb_builtin_type_bound128 type."""
>
>

Since this should apply to every python module, maybe this should be 
defined inside gdb/python/lib/gdb/__init__.py?

I'm assuming it gets included by module "gdb" and therefore "long" is 
defined to be "int" for Python versions > 3.

Then we can remove that code from gdb/python/lib/gdb/printing.py (and 
from other places setting this type of version-specific adjustment).

Does that make sense?
  
Jonah Graham Nov. 23, 2016, 10:39 p.m. UTC | #3
On 23 November 2016 at 16:59, Luis Machado <lgustavo@codesourcery.com> wrote:
> On 11/20/2016 02:45 PM, Jonah Graham wrote:
>>
>> gdb/Changelog:
>>
>>         * python/lib/gdb/printer/bound_registers.py: Add support
>>         for Python 3.
>> ---
>>  gdb/ChangeLog                                 | 5 +++++
>>  gdb/python/lib/gdb/printer/bound_registers.py | 5 +++++
>>  2 files changed, 10 insertions(+)
>>
>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>> index 3797e8b..1923888 100644
>> --- a/gdb/ChangeLog
>> +++ b/gdb/ChangeLog
>> @@ -1,3 +1,8 @@
>> +2016-11-20  Jonah Graham  <jonah@kichwacoders.com>
>> +
>> +       * python/lib/gdb/printer/bound_registers.py: Add support
>> +       for Python 3.
>> +
>>  2016-11-19  Joel Brobecker  <brobecker@adacore.com>
>>
>>         * contrib/ari/gdb_ari.sh: Add detection of printf_vma and
>> diff --git a/gdb/python/lib/gdb/printer/bound_registers.py
>> b/gdb/python/lib/gdb/printer/bound_registers.py
>> index 9ff94aa..e91cc19 100644
>> --- a/gdb/python/lib/gdb/printer/bound_registers.py
>> +++ b/gdb/python/lib/gdb/printer/bound_registers.py
>> @@ -16,6 +16,11 @@
>>
>>  import gdb.printing
>>
>> +if sys.version_info[0] > 2:
>> +    # Python 3 removed basestring and long
>> +    basestring = str
>> +    long = int
>> +
>>  class MpxBound128Printer:
>>      """Adds size field to a mpx __gdb_builtin_type_bound128 type."""
>>
>>
>
> Since this should apply to every python module, maybe this should be defined
> inside gdb/python/lib/gdb/__init__.py?
>
> I'm assuming it gets included by module "gdb" and therefore "long" is
> defined to be "int" for Python versions > 3.
>
> Then we can remove that code from gdb/python/lib/gdb/printing.py (and from
> other places setting this type of version-specific adjustment).
>
> Does that make sense?

Hi Luis,

I am not sure I understand how to do it in __init__.py as the modules
that wanted to be both Python 2 and Python 3 compatible would still
have to have special code. AFAIK an __init__.py cannot change the
value of long in other py files. So python/lib/gdb/printing.py and
python/lib/gdb/printer/bound_registers.py would still need special
case code locally, even if that special case was an import for a
definition of long.

Jonah
  
Luis Machado Nov. 23, 2016, 11:04 p.m. UTC | #4
On 11/23/2016 04:39 PM, Jonah Graham wrote:
> On 23 November 2016 at 16:59, Luis Machado <lgustavo@codesourcery.com> wrote:
>> On 11/20/2016 02:45 PM, Jonah Graham wrote:
>>>
>>> gdb/Changelog:
>>>
>>>         * python/lib/gdb/printer/bound_registers.py: Add support
>>>         for Python 3.
>>> ---
>>>  gdb/ChangeLog                                 | 5 +++++
>>>  gdb/python/lib/gdb/printer/bound_registers.py | 5 +++++
>>>  2 files changed, 10 insertions(+)
>>>
>>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>>> index 3797e8b..1923888 100644
>>> --- a/gdb/ChangeLog
>>> +++ b/gdb/ChangeLog
>>> @@ -1,3 +1,8 @@
>>> +2016-11-20  Jonah Graham  <jonah@kichwacoders.com>
>>> +
>>> +       * python/lib/gdb/printer/bound_registers.py: Add support
>>> +       for Python 3.
>>> +
>>>  2016-11-19  Joel Brobecker  <brobecker@adacore.com>
>>>
>>>         * contrib/ari/gdb_ari.sh: Add detection of printf_vma and
>>> diff --git a/gdb/python/lib/gdb/printer/bound_registers.py
>>> b/gdb/python/lib/gdb/printer/bound_registers.py
>>> index 9ff94aa..e91cc19 100644
>>> --- a/gdb/python/lib/gdb/printer/bound_registers.py
>>> +++ b/gdb/python/lib/gdb/printer/bound_registers.py
>>> @@ -16,6 +16,11 @@
>>>
>>>  import gdb.printing
>>>
>>> +if sys.version_info[0] > 2:
>>> +    # Python 3 removed basestring and long
>>> +    basestring = str
>>> +    long = int
>>> +
>>>  class MpxBound128Printer:
>>>      """Adds size field to a mpx __gdb_builtin_type_bound128 type."""
>>>
>>>
>>
>> Since this should apply to every python module, maybe this should be defined
>> inside gdb/python/lib/gdb/__init__.py?
>>
>> I'm assuming it gets included by module "gdb" and therefore "long" is
>> defined to be "int" for Python versions > 3.
>>
>> Then we can remove that code from gdb/python/lib/gdb/printing.py (and from
>> other places setting this type of version-specific adjustment).
>>
>> Does that make sense?
>
> Hi Luis,
>
> I am not sure I understand how to do it in __init__.py as the modules
> that wanted to be both Python 2 and Python 3 compatible would still
> have to have special code. AFAIK an __init__.py cannot change the
> value of long in other py files. So python/lib/gdb/printing.py and
> python/lib/gdb/printer/bound_registers.py would still need special
> case code locally, even if that special case was an import for a
> definition of long.

That was the point i wasn't sure about (not a Python expert). I see 
conditional code executing if the version is > 3, but i wasn't sure if 
it would take effect globally when a module is included.

In that case, i suppose there is not much that can be done other than 
duplicate the code.
  
Jonah Graham Nov. 23, 2016, 11:09 p.m. UTC | #5
On 23 November 2016 at 23:04, Luis Machado <lgustavo@codesourcery.com> wrote:
> On 11/23/2016 04:39 PM, Jonah Graham wrote:
>>
>> On 23 November 2016 at 16:59, Luis Machado <lgustavo@codesourcery.com>
>> wrote:
>>>
>>> On 11/20/2016 02:45 PM, Jonah Graham wrote:
>>>>
>>>>
>>>> gdb/Changelog:
>>>>
>>>>         * python/lib/gdb/printer/bound_registers.py: Add support
>>>>         for Python 3.
>>>> ---
>>>>  gdb/ChangeLog                                 | 5 +++++
>>>>  gdb/python/lib/gdb/printer/bound_registers.py | 5 +++++
>>>>  2 files changed, 10 insertions(+)
>>>>
>>>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>>>> index 3797e8b..1923888 100644
>>>> --- a/gdb/ChangeLog
>>>> +++ b/gdb/ChangeLog
>>>> @@ -1,3 +1,8 @@
>>>> +2016-11-20  Jonah Graham  <jonah@kichwacoders.com>
>>>> +
>>>> +       * python/lib/gdb/printer/bound_registers.py: Add support
>>>> +       for Python 3.
>>>> +
>>>>  2016-11-19  Joel Brobecker  <brobecker@adacore.com>
>>>>
>>>>         * contrib/ari/gdb_ari.sh: Add detection of printf_vma and
>>>> diff --git a/gdb/python/lib/gdb/printer/bound_registers.py
>>>> b/gdb/python/lib/gdb/printer/bound_registers.py
>>>> index 9ff94aa..e91cc19 100644
>>>> --- a/gdb/python/lib/gdb/printer/bound_registers.py
>>>> +++ b/gdb/python/lib/gdb/printer/bound_registers.py
>>>> @@ -16,6 +16,11 @@
>>>>
>>>>  import gdb.printing
>>>>
>>>> +if sys.version_info[0] > 2:
>>>> +    # Python 3 removed basestring and long
>>>> +    basestring = str
>>>> +    long = int
>>>> +
>>>>  class MpxBound128Printer:
>>>>      """Adds size field to a mpx __gdb_builtin_type_bound128 type."""
>>>>
>>>>
>>>
>>> Since this should apply to every python module, maybe this should be
>>> defined
>>> inside gdb/python/lib/gdb/__init__.py?
>>>
>>> I'm assuming it gets included by module "gdb" and therefore "long" is
>>> defined to be "int" for Python versions > 3.
>>>
>>> Then we can remove that code from gdb/python/lib/gdb/printing.py (and
>>> from
>>> other places setting this type of version-specific adjustment).
>>>
>>> Does that make sense?
>>
>>
>> Hi Luis,
>>
>> I am not sure I understand how to do it in __init__.py as the modules
>> that wanted to be both Python 2 and Python 3 compatible would still
>> have to have special code. AFAIK an __init__.py cannot change the
>> value of long in other py files. So python/lib/gdb/printing.py and
>> python/lib/gdb/printer/bound_registers.py would still need special
>> case code locally, even if that special case was an import for a
>> definition of long.
>
>
> That was the point i wasn't sure about (not a Python expert). I see
> conditional code executing if the version is > 3, but i wasn't sure if it
> would take effect globally when a module is included.
>
> In that case, i suppose there is not much that can be done other than
> duplicate the code.
>

There is no way I know of, as a reference
http://python3porting.com/differences.html#long recommends doing it
(roughly) the way already done in python/lib/gdb/printing.py and
copied to python/lib/gdb/printer/bound_registers.py

Thanks for the review,
Jonah
  
Jonah Graham Nov. 26, 2016, 4:27 p.m. UTC | #6
On 23 November 2016 at 23:09, Jonah Graham <jonah@kichwacoders.com> wrote:
> On 23 November 2016 at 23:04, Luis Machado <lgustavo@codesourcery.com> wrote:
>> On 11/23/2016 04:39 PM, Jonah Graham wrote:
>>>
>>> On 23 November 2016 at 16:59, Luis Machado <lgustavo@codesourcery.com>
>>> wrote:
>>>>
>>>> On 11/20/2016 02:45 PM, Jonah Graham wrote:
>>>>>
>>>>>
>>>>> gdb/Changelog:
>>>>>
>>>>>         * python/lib/gdb/printer/bound_registers.py: Add support
>>>>>         for Python 3.
>>>>> ---
>>>>>  gdb/ChangeLog                                 | 5 +++++
>>>>>  gdb/python/lib/gdb/printer/bound_registers.py | 5 +++++
>>>>>  2 files changed, 10 insertions(+)
>>>>>
>>>>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>>>>> index 3797e8b..1923888 100644
>>>>> --- a/gdb/ChangeLog
>>>>> +++ b/gdb/ChangeLog
>>>>> @@ -1,3 +1,8 @@
>>>>> +2016-11-20  Jonah Graham  <jonah@kichwacoders.com>
>>>>> +
>>>>> +       * python/lib/gdb/printer/bound_registers.py: Add support
>>>>> +       for Python 3.
>>>>> +
>>>>>  2016-11-19  Joel Brobecker  <brobecker@adacore.com>
>>>>>
>>>>>         * contrib/ari/gdb_ari.sh: Add detection of printf_vma and
>>>>> diff --git a/gdb/python/lib/gdb/printer/bound_registers.py
>>>>> b/gdb/python/lib/gdb/printer/bound_registers.py
>>>>> index 9ff94aa..e91cc19 100644
>>>>> --- a/gdb/python/lib/gdb/printer/bound_registers.py
>>>>> +++ b/gdb/python/lib/gdb/printer/bound_registers.py
>>>>> @@ -16,6 +16,11 @@
>>>>>
>>>>>  import gdb.printing
>>>>>
>>>>> +if sys.version_info[0] > 2:
>>>>> +    # Python 3 removed basestring and long
>>>>> +    basestring = str
>>>>> +    long = int
>>>>> +
>>>>>  class MpxBound128Printer:
>>>>>      """Adds size field to a mpx __gdb_builtin_type_bound128 type."""
>>>>>
>>>>>
>>>>
>>>> Since this should apply to every python module, maybe this should be
>>>> defined
>>>> inside gdb/python/lib/gdb/__init__.py?
>>>>
>>>> I'm assuming it gets included by module "gdb" and therefore "long" is
>>>> defined to be "int" for Python versions > 3.
>>>>
>>>> Then we can remove that code from gdb/python/lib/gdb/printing.py (and
>>>> from
>>>> other places setting this type of version-specific adjustment).
>>>>
>>>> Does that make sense?
>>>
>>>
>>> Hi Luis,
>>>
>>> I am not sure I understand how to do it in __init__.py as the modules
>>> that wanted to be both Python 2 and Python 3 compatible would still
>>> have to have special code. AFAIK an __init__.py cannot change the
>>> value of long in other py files. So python/lib/gdb/printing.py and
>>> python/lib/gdb/printer/bound_registers.py would still need special
>>> case code locally, even if that special case was an import for a
>>> definition of long.
>>
>>
>> That was the point i wasn't sure about (not a Python expert). I see
>> conditional code executing if the version is > 3, but i wasn't sure if it
>> would take effect globally when a module is included.
>>
>> In that case, i suppose there is not much that can be done other than
>> duplicate the code.
>>
>
> There is no way I know of, as a reference
> http://python3porting.com/differences.html#long recommends doing it
> (roughly) the way already done in python/lib/gdb/printing.py and
> copied to python/lib/gdb/printer/bound_registers.py
>
> Thanks for the review,
> Jonah

Hi,

Is there more I am supposed to do to get this patch into GDB? If so,
please advise and I would be happy to.

Thanks
Jonah
  
Jonah Graham Nov. 26, 2016, 6:54 p.m. UTC | #7
On 26 November 2016 at 16:27, Jonah Graham <jonah@kichwacoders.com> wrote:
> On 23 November 2016 at 23:09, Jonah Graham <jonah@kichwacoders.com> wrote:
>> On 23 November 2016 at 23:04, Luis Machado <lgustavo@codesourcery.com> wrote:
>>> On 11/23/2016 04:39 PM, Jonah Graham wrote:
>>>>
>>>> On 23 November 2016 at 16:59, Luis Machado <lgustavo@codesourcery.com>
>>>> wrote:
>>>>>
>>>>> On 11/20/2016 02:45 PM, Jonah Graham wrote:
>>>>>>
>>>>>>
>>>>>> gdb/Changelog:
>>>>>>
>>>>>>         * python/lib/gdb/printer/bound_registers.py: Add support
>>>>>>         for Python 3.
>>>>>> ---
>>>>>>  gdb/ChangeLog                                 | 5 +++++
>>>>>>  gdb/python/lib/gdb/printer/bound_registers.py | 5 +++++
>>>>>>  2 files changed, 10 insertions(+)
>>>>>>
>>>>>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>>>>>> index 3797e8b..1923888 100644
>>>>>> --- a/gdb/ChangeLog
>>>>>> +++ b/gdb/ChangeLog
>>>>>> @@ -1,3 +1,8 @@
>>>>>> +2016-11-20  Jonah Graham  <jonah@kichwacoders.com>
>>>>>> +
>>>>>> +       * python/lib/gdb/printer/bound_registers.py: Add support
>>>>>> +       for Python 3.
>>>>>> +
>>>>>>  2016-11-19  Joel Brobecker  <brobecker@adacore.com>
>>>>>>
>>>>>>         * contrib/ari/gdb_ari.sh: Add detection of printf_vma and
>>>>>> diff --git a/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>> b/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>> index 9ff94aa..e91cc19 100644
>>>>>> --- a/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>> +++ b/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>> @@ -16,6 +16,11 @@
>>>>>>
>>>>>>  import gdb.printing
>>>>>>
>>>>>> +if sys.version_info[0] > 2:
>>>>>> +    # Python 3 removed basestring and long
>>>>>> +    basestring = str
>>>>>> +    long = int
>>>>>> +
>>>>>>  class MpxBound128Printer:
>>>>>>      """Adds size field to a mpx __gdb_builtin_type_bound128 type."""
>>>>>>
>>>>>>
>>>>>
>>>>> Since this should apply to every python module, maybe this should be
>>>>> defined
>>>>> inside gdb/python/lib/gdb/__init__.py?
>>>>>
>>>>> I'm assuming it gets included by module "gdb" and therefore "long" is
>>>>> defined to be "int" for Python versions > 3.
>>>>>
>>>>> Then we can remove that code from gdb/python/lib/gdb/printing.py (and
>>>>> from
>>>>> other places setting this type of version-specific adjustment).
>>>>>
>>>>> Does that make sense?
>>>>
>>>>
>>>> Hi Luis,
>>>>
>>>> I am not sure I understand how to do it in __init__.py as the modules
>>>> that wanted to be both Python 2 and Python 3 compatible would still
>>>> have to have special code. AFAIK an __init__.py cannot change the
>>>> value of long in other py files. So python/lib/gdb/printing.py and
>>>> python/lib/gdb/printer/bound_registers.py would still need special
>>>> case code locally, even if that special case was an import for a
>>>> definition of long.
>>>
>>>
>>> That was the point i wasn't sure about (not a Python expert). I see
>>> conditional code executing if the version is > 3, but i wasn't sure if it
>>> would take effect globally when a module is included.
>>>
>>> In that case, i suppose there is not much that can be done other than
>>> duplicate the code.
>>>
>>
>> There is no way I know of, as a reference
>> http://python3porting.com/differences.html#long recommends doing it
>> (roughly) the way already done in python/lib/gdb/printing.py and
>> copied to python/lib/gdb/printer/bound_registers.py
>>
>> Thanks for the review,
>> Jonah
>
> Hi,
>
> Is there more I am supposed to do to get this patch into GDB? If so,
> please advise and I would be happy to.
>
> Thanks
> Jonah

This patch is missing the import of sys. Update on the way.
  
Luis Machado Nov. 26, 2016, 9:26 p.m. UTC | #8
On 11/26/2016 10:27 AM, Jonah Graham wrote:
> On 23 November 2016 at 23:09, Jonah Graham <jonah@kichwacoders.com> wrote:
>> On 23 November 2016 at 23:04, Luis Machado <lgustavo@codesourcery.com> wrote:
>>> On 11/23/2016 04:39 PM, Jonah Graham wrote:
>>>>
>>>> On 23 November 2016 at 16:59, Luis Machado <lgustavo@codesourcery.com>
>>>> wrote:
>>>>>
>>>>> On 11/20/2016 02:45 PM, Jonah Graham wrote:
>>>>>>
>>>>>>
>>>>>> gdb/Changelog:
>>>>>>
>>>>>>         * python/lib/gdb/printer/bound_registers.py: Add support
>>>>>>         for Python 3.
>>>>>> ---
>>>>>>  gdb/ChangeLog                                 | 5 +++++
>>>>>>  gdb/python/lib/gdb/printer/bound_registers.py | 5 +++++
>>>>>>  2 files changed, 10 insertions(+)
>>>>>>
>>>>>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>>>>>> index 3797e8b..1923888 100644
>>>>>> --- a/gdb/ChangeLog
>>>>>> +++ b/gdb/ChangeLog
>>>>>> @@ -1,3 +1,8 @@
>>>>>> +2016-11-20  Jonah Graham  <jonah@kichwacoders.com>
>>>>>> +
>>>>>> +       * python/lib/gdb/printer/bound_registers.py: Add support
>>>>>> +       for Python 3.
>>>>>> +
>>>>>>  2016-11-19  Joel Brobecker  <brobecker@adacore.com>
>>>>>>
>>>>>>         * contrib/ari/gdb_ari.sh: Add detection of printf_vma and
>>>>>> diff --git a/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>> b/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>> index 9ff94aa..e91cc19 100644
>>>>>> --- a/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>> +++ b/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>> @@ -16,6 +16,11 @@
>>>>>>
>>>>>>  import gdb.printing
>>>>>>
>>>>>> +if sys.version_info[0] > 2:
>>>>>> +    # Python 3 removed basestring and long
>>>>>> +    basestring = str
>>>>>> +    long = int
>>>>>> +
>>>>>>  class MpxBound128Printer:
>>>>>>      """Adds size field to a mpx __gdb_builtin_type_bound128 type."""
>>>>>>
>>>>>>
>>>>>
>>>>> Since this should apply to every python module, maybe this should be
>>>>> defined
>>>>> inside gdb/python/lib/gdb/__init__.py?
>>>>>
>>>>> I'm assuming it gets included by module "gdb" and therefore "long" is
>>>>> defined to be "int" for Python versions > 3.
>>>>>
>>>>> Then we can remove that code from gdb/python/lib/gdb/printing.py (and
>>>>> from
>>>>> other places setting this type of version-specific adjustment).
>>>>>
>>>>> Does that make sense?
>>>>
>>>>
>>>> Hi Luis,
>>>>
>>>> I am not sure I understand how to do it in __init__.py as the modules
>>>> that wanted to be both Python 2 and Python 3 compatible would still
>>>> have to have special code. AFAIK an __init__.py cannot change the
>>>> value of long in other py files. So python/lib/gdb/printing.py and
>>>> python/lib/gdb/printer/bound_registers.py would still need special
>>>> case code locally, even if that special case was an import for a
>>>> definition of long.
>>>
>>>
>>> That was the point i wasn't sure about (not a Python expert). I see
>>> conditional code executing if the version is > 3, but i wasn't sure if it
>>> would take effect globally when a module is included.
>>>
>>> In that case, i suppose there is not much that can be done other than
>>> duplicate the code.
>>>
>>
>> There is no way I know of, as a reference
>> http://python3porting.com/differences.html#long recommends doing it
>> (roughly) the way already done in python/lib/gdb/printing.py and
>> copied to python/lib/gdb/printer/bound_registers.py
>>
>> Thanks for the review,
>> Jonah
>
> Hi,
>
> Is there more I am supposed to do to get this patch into GDB? If so,
> please advise and I would be happy to.

One of the maintainers needs to OK it, which shouldn't that that long. 
Given the size of the patch, i don't there's anything else that should 
be done code-wise.
  
Jonah Graham March 8, 2017, 8:34 a.m. UTC | #9
On 26 November 2016 at 21:26, Luis Machado <lgustavo@codesourcery.com> wrote:
> On 11/26/2016 10:27 AM, Jonah Graham wrote:
>>
>> On 23 November 2016 at 23:09, Jonah Graham <jonah@kichwacoders.com> wrote:
>>>
>>> On 23 November 2016 at 23:04, Luis Machado <lgustavo@codesourcery.com>
>>> wrote:
>>>>
>>>> On 11/23/2016 04:39 PM, Jonah Graham wrote:
>>>>>
>>>>>
>>>>> On 23 November 2016 at 16:59, Luis Machado <lgustavo@codesourcery.com>
>>>>> wrote:
>>>>>>
>>>>>>
>>>>>> On 11/20/2016 02:45 PM, Jonah Graham wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> gdb/Changelog:
>>>>>>>
>>>>>>>         * python/lib/gdb/printer/bound_registers.py: Add support
>>>>>>>         for Python 3.
>>>>>>> ---
>>>>>>>  gdb/ChangeLog                                 | 5 +++++
>>>>>>>  gdb/python/lib/gdb/printer/bound_registers.py | 5 +++++
>>>>>>>  2 files changed, 10 insertions(+)
>>>>>>>
>>>>>>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>>>>>>> index 3797e8b..1923888 100644
>>>>>>> --- a/gdb/ChangeLog
>>>>>>> +++ b/gdb/ChangeLog
>>>>>>> @@ -1,3 +1,8 @@
>>>>>>> +2016-11-20  Jonah Graham  <jonah@kichwacoders.com>
>>>>>>> +
>>>>>>> +       * python/lib/gdb/printer/bound_registers.py: Add support
>>>>>>> +       for Python 3.
>>>>>>> +
>>>>>>>  2016-11-19  Joel Brobecker  <brobecker@adacore.com>
>>>>>>>
>>>>>>>         * contrib/ari/gdb_ari.sh: Add detection of printf_vma and
>>>>>>> diff --git a/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>>> b/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>>> index 9ff94aa..e91cc19 100644
>>>>>>> --- a/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>>> +++ b/gdb/python/lib/gdb/printer/bound_registers.py
>>>>>>> @@ -16,6 +16,11 @@
>>>>>>>
>>>>>>>  import gdb.printing
>>>>>>>
>>>>>>> +if sys.version_info[0] > 2:
>>>>>>> +    # Python 3 removed basestring and long
>>>>>>> +    basestring = str
>>>>>>> +    long = int
>>>>>>> +
>>>>>>>  class MpxBound128Printer:
>>>>>>>      """Adds size field to a mpx __gdb_builtin_type_bound128 type."""
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> Since this should apply to every python module, maybe this should be
>>>>>> defined
>>>>>> inside gdb/python/lib/gdb/__init__.py?
>>>>>>
>>>>>> I'm assuming it gets included by module "gdb" and therefore "long" is
>>>>>> defined to be "int" for Python versions > 3.
>>>>>>
>>>>>> Then we can remove that code from gdb/python/lib/gdb/printing.py (and
>>>>>> from
>>>>>> other places setting this type of version-specific adjustment).
>>>>>>
>>>>>> Does that make sense?
>>>>>
>>>>>
>>>>>
>>>>> Hi Luis,
>>>>>
>>>>> I am not sure I understand how to do it in __init__.py as the modules
>>>>> that wanted to be both Python 2 and Python 3 compatible would still
>>>>> have to have special code. AFAIK an __init__.py cannot change the
>>>>> value of long in other py files. So python/lib/gdb/printing.py and
>>>>> python/lib/gdb/printer/bound_registers.py would still need special
>>>>> case code locally, even if that special case was an import for a
>>>>> definition of long.
>>>>
>>>>
>>>>
>>>> That was the point i wasn't sure about (not a Python expert). I see
>>>> conditional code executing if the version is > 3, but i wasn't sure if
>>>> it
>>>> would take effect globally when a module is included.
>>>>
>>>> In that case, i suppose there is not much that can be done other than
>>>> duplicate the code.
>>>>
>>>
>>> There is no way I know of, as a reference
>>> http://python3porting.com/differences.html#long recommends doing it
>>> (roughly) the way already done in python/lib/gdb/printing.py and
>>> copied to python/lib/gdb/printer/bound_registers.py
>>>
>>> Thanks for the review,
>>> Jonah
>>
>>
>> Hi,
>>
>> Is there more I am supposed to do to get this patch into GDB? If so,
>> please advise and I would be happy to.
>
>
> One of the maintainers needs to OK it, which shouldn't that that long. Given
> the size of the patch, i don't there's anything else that should be done
> code-wise.
>

Ping on this patch. Please let me know if there is anything else I can
do to get it in.
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3797e8b..1923888 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@ 
+2016-11-20  Jonah Graham  <jonah@kichwacoders.com>
+
+	* python/lib/gdb/printer/bound_registers.py: Add support
+	for Python 3.
+
 2016-11-19  Joel Brobecker  <brobecker@adacore.com>
 
 	* contrib/ari/gdb_ari.sh: Add detection of printf_vma and
diff --git a/gdb/python/lib/gdb/printer/bound_registers.py b/gdb/python/lib/gdb/printer/bound_registers.py
index 9ff94aa..e91cc19 100644
--- a/gdb/python/lib/gdb/printer/bound_registers.py
+++ b/gdb/python/lib/gdb/printer/bound_registers.py
@@ -16,6 +16,11 @@ 
 
 import gdb.printing
 
+if sys.version_info[0] > 2:
+    # Python 3 removed basestring and long
+    basestring = str
+    long = int
+
 class MpxBound128Printer:
     """Adds size field to a mpx __gdb_builtin_type_bound128 type."""