Problem using py-bt, py-locals, etc. during GDB debugging [solved]

Mark Shroyer mshroyer at awaredigital.com
Fri Dec 7 07:28:46 CET 2012


On Thu, Dec 06, 2012 at 07:37:22PM -0500, MRAB wrote:
> On 2012-12-07 00:22, Mark Shroyer wrote:
> >
> > [...]
> >
> >   2. Patch Python 2.7.3's python-gdb.py as follows:
> >
> > === 8< =================================
> >
> > --- python-gdb.py.orig	2012-12-06 15:12:18.666760664 -0500
> > +++ python-gdb.py	2012-12-06 19:17:19.588356874 -0500
> > @@ -1074,7 +1074,11 @@
> >
> >
> >   def int_from_int(gdbval):
> > -    return int(str(gdbval))
> > +    int_str = str(gdbval)
> > +    if int_str.startswith("0x"):
> > +        return int(int_str[2:], 16)
> > +    else:
> > +        return int(int_str)
> >
> >
> >   def stringify(val):
> >
> > === 8< =================================
> >
> > I haven't checked to see whether this also applies to the GDB extension
> > for Python 3, though.
> >
> A shorter fix would be:
> 
> def int_from_int(gdbval):
>      return int(str(gdbval), 0)
> 
> 
> Some examples:
> 
>  >>> # Decimal
>  >>> int("12", 0)
> 12
>  >>> # Hexadecimal
>  >>> int("0x12", 0)
> 18
>  >>> # Octal
>  >>> int("012", 0)
> 10
>  >>> # Octal
>  >>> int("0o12", 0)
> 10
>  >>> # Binary
>  >>> int("0b11", 0)
> 3

Nice, I didn't know about that... thanks!




More information about the Python-list mailing list