Pythons scripting API question

Keith Seitz keiths@redhat.com
Wed May 30 21:23:00 GMT 2012


On 05/30/2012 11:10 AM, Evan Driscoll wrote:

> I'd like to get a list of the local variables in a frame, or at least
> the parameters. I'm looking through the documentation of the Python API,
> and not seeing how to do it.

Frames contain blocks, blocks contain variables. Blocks in python can be 
iterated, so:

$ ./gdb -nx -q gdb -ex "break main" -ex "run"
(gdb) python import gdb
(gdb) python for n in gdb.selected_frame().block(): print n,
argc argv args
(gdb) python print n.type
struct captured_main_args
(gdb) python print n.name
args
(gdb) python print n.is_argument
False
(gdb) python print n.value(gdb.selected_frame())
{argc = 0, argv = 0x488f80 <_start>, use_windows = -8032, interpreter_p 
= 0x0}

This will give you both parameters and locals. There are methods you can 
use to determine which is which (e.g., Symbol.is_argument).

See the relevant sections in the Gdb Users Manual (23.2.2.16, 23.2.2.18).

Keith



More information about the Gdb mailing list