This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Python API questions and use cases
On 09/15/2010 06:56 PM, Tom Tromey wrote:
>>>>>> "Joel" == Joel BorggrÃn-Franck <joel.borggren.franck@gmail.com> writes:
>
> Joel> 1) Getting the value of a global
> Joel> foo myGlobalFoo;
> Joel> in some C file, how do I access the value of myGlobalFoo from
> Joel> python?
>
> Joel> The only working solution I have at the moment is to escape to
> Joel> gdb-script with:
> Joel> gdb.parse_and_eval("myGlobalFoo")
> Joel> is this intended?
>
> This is simplest.
>
> Joel> I know I can iterate over symbols in the symbol table, but I
> Joel> haven't found a way to go from symbol to value.
>
> Hmm, we don't seem to expose a way to do that. Sorry about that.
> Could you file a bug report for this?
If you have the frame, you can use .read_var and pass the symbol as an
argument. You can read the value behind the symbol then (as we know
what frame; can you divine it otherwise, just from the symbol?)
Cheers,
Phil