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

Mark Shroyer mshroyer at
Fri Dec 7 01:22:12 CET 2012

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 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 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 as follows:

=== 8< =================================

---	2012-12-06 15:12:18.666760664 -0500
+++	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.

More information about the Python-list mailing list