On 2012-12-07 00:22, Mark Shroyer wrote:
On Thu, Dec 06, 2012 at 04:39:41PM -0500, Mark Shroyer wrote:
I'm having trouble with the py-bt, py-locals, etc. GDB commands (from
Python's python-gdb.py) while using GDB 7.4 to debug Python 2.7.3; I was
wondering if anyone here could offer advice.

Briefly, py-bt seems to identify the python stack frames correctly, but
shows "(unable to read python frame information)" for each, and likewise
py-locals fails with "Unable to read information on python frame".

OK, I took a closer look at this and I've identified the issue; posting
my fix here in case someone else Googles this.

The problem in my case was that the python-gdb.py extension makes some
fragile assumptions about the format of values it receives from GDB, and
I had the line "set output-radix 16" in my .gdbinit, ultimately
resulting in the extension attempting to convert the string
representation of a hexadecimal number into an integer.

So there are two easy workarounds:

  1. set output-radix 10 in GDB, or

  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

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to