gdb python how to output integer for examine memory

dieter dieter at handshake.de
Tue Mar 25 08:49:09 CET 2014


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).




More information about the Python-list mailing list