gdb python how to output integer for examine memory

Wesley nispray at gmail.com
Tue Mar 25 09:07:13 CET 2014


在 2014年3月25日星期二UTC+8下午3时49分09秒,dieter写道:
> Wesley <nispray at gmail.com> writes:
> 
> 
> 
> >   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) 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.
> 
> 
> 
> Quite a lot of time has passed since I last had to debug Python
> 
> processes at C level -- thus, my memory may be unreliable.
> 
> 
> 
> When I remember right, then "pyo" is used to interprete
> 
> a C level variable as a Python object (and print it) -- not
> 
> a Python level variable. In your case, "i" is a Python level variable.
> 
> 
> 
> You must carefully distinguish between the C level and the Python level.
> 
> Some commands expect C level names/objects;
> 
> others may expect Python level names/objects.
> 
> 
> 
> To learn how you can obtain the value of a Python variable,
> 
> I see two approaches: look through the list of provided commands
> 
> (and their documentation) and try to figure out which might be applicable
> 
> and then may some tests; or look at the implementation of "py-locals"
> 
> and use this knowledge to define you own command (for this,
> 
> you will also need to understand the gdb language to define commands).

Hi Dieter,
  Thanks.
Actually, I can now see the varialbe names at Python level and C level.
I just want to verify x command to monitor the memory content.
So, in my origin post, I can get variable i's address, and see the value is 1,
then, I wanna have a try x command, the issue is, when use x/format i's address, the output is not 1, but other things:-(



More information about the Python-list mailing list