gdb python how to output integer for examine memory

Wesley nispray at gmail.com
Mon Mar 24 11:20:55 CET 2014


Hi all,
  I am trying to use gdb debug python script.
I am using gdb7.7 and python2.7.6, here is my simple test script: 
import time

def next(i):
    time.sleep(10)
    i = 1 - i

i = 1
while True:
    next(i)
When this script running, gdb attach to it, and here is snippet:

(gdb) py-bt
#5 Frame 0x201e130, for file test.py, line 6, in next (i=1)
Python Exception <type 'exceptions.IOError'> (2, '\xe6\xb2\xa1\xe6\x9c\x89\xe9\x82\xa3\xe4\xb8\xaa\xe6\x96\x87\xe4\xbb\xb6\xe6\x88\x96\xe7\x9b\xae\xe5\xbd\x95', 'test.py'): 
Error occurred in Python command: (2, '\xe6\xb2\xa1\xe6\x9c\x89\xe9\x82\xa3\xe4\xb8\xaa\xe6\x96\x87\xe4\xbb\xb6\xe6\x88\x96\xe7\x9b\xae\xe5\xbd\x95', 'test.py')
(gdb) frame 5
#5  0x00000000004d01a7 in PyEval_EvalFrameEx (f=Frame 0x201e130, for file test.py, line 6, in next (i=1), throwflag=0) at Python/ceval.c:2666
2666                x = call_function(&sp, oparg);
(gdb) py-locals
i = 1
(gdb) pyo i
No symbol "i" in current context.
(gdb) 
No symbol "i" in current context.
(gdb) p f->f_localsplus
$1 = {1}
(gdb) p f->f_localsplus[0]
$2 = 1
(gdb) p &(f->f_localsplus[0])
$3 = (PyObject **) 0x201e2b8
(gdb) x/d 0x201e2b8
0x201e2b8:      31304528
(gdb) p sizeof(f->f_localsplus[0])
$4 = 8
(gdb) x/dg 0x201e2b8
0x201e2b8:      31304528
(gdb) x/dw 0x201e2b8
0x201e2b8:      31304528
(gdb) 

So, the latter several commands, I wannted to check memory content, but , how to output integer 1?

Thanks.
Wesley



More information about the Python-list mailing list