* Pythons scripting API question
@ 2012-05-30 18:10 Evan Driscoll
2012-05-30 21:23 ` Keith Seitz
0 siblings, 1 reply; 6+ messages in thread
From: Evan Driscoll @ 2012-05-30 18:10 UTC (permalink / raw)
To: gdb
Hi,
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.
In some sense, I'm trying to write a command that behaves a bit like
'info locals', but outputs in a different format. (And, of course, I'd
prefer not to parse that. There's also some other stuff I want to do as
well.)
I'm using GDB 7.4.1 with Python 2.7.1.
Evan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Pythons scripting API question
2012-05-30 18:10 Pythons scripting API question Evan Driscoll
@ 2012-05-30 21:23 ` Keith Seitz
2012-05-30 22:42 ` Evan Driscoll
2012-06-06 15:46 ` Joachim Protze
0 siblings, 2 replies; 6+ messages in thread
From: Keith Seitz @ 2012-05-30 21:23 UTC (permalink / raw)
To: Evan Driscoll; +Cc: gdb
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Pythons scripting API question
2012-05-30 21:23 ` Keith Seitz
@ 2012-05-30 22:42 ` Evan Driscoll
2012-05-30 23:12 ` Keith Seitz
2012-06-06 15:46 ` Joachim Protze
1 sibling, 1 reply; 6+ messages in thread
From: Evan Driscoll @ 2012-05-30 22:42 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb
On 05/30/2012 04:23 PM, Keith Seitz wrote:
> Frames contain blocks, blocks contain variables. Blocks in python can be
> iterated
Great, it's that information that I was missing.
However, if I do this:
> $ ./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}
then on the last step I get this instead:
(gdb) python print n.value(gdb.selected_frame())
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'gdb.Symbol' object has no attribute 'value'
Error while executing Python code.
Instead, I have to use
(gdb) python print gdb.selected_frame().read_var(n)
{argc = 6742752, argv = 0x0, use_windows = -7696, interpreter_p = 0x0}
Is this just a version difference?
Evan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Pythons scripting API question
2012-05-30 22:42 ` Evan Driscoll
@ 2012-05-30 23:12 ` Keith Seitz
0 siblings, 0 replies; 6+ messages in thread
From: Keith Seitz @ 2012-05-30 23:12 UTC (permalink / raw)
To: Evan Driscoll; +Cc: gdb
On 05/30/2012 03:42 PM, Evan Driscoll wrote:
> Instead, I have to use
>
> (gdb) python print gdb.selected_frame().read_var(n)
> {argc = 6742752, argv = 0x0, use_windows = -7696, interpreter_p = 0x0}
>
>
> Is this just a version difference?
It appears that Symbol.value was added on 2012-02-07 to address
python/12027. That bug shows the target milestone to be 7.5, so I'm
guessing that although this was fixed before the 7.4.1 release, it was
not back-ported to that release.
In other words, yes, it does appear to be a difference between your
version of gdb (7.4.1) and mine (7.4.50, aka CVS HEAD). :-)
Keith
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Pythons scripting API question
2012-05-30 21:23 ` Keith Seitz
2012-05-30 22:42 ` Evan Driscoll
@ 2012-06-06 15:46 ` Joachim Protze
2012-06-06 17:58 ` Tom Tromey
1 sibling, 1 reply; 6+ messages in thread
From: Joachim Protze @ 2012-06-06 15:46 UTC (permalink / raw)
To: gdb
[-- Attachment #1: Type: text/plain, Size: 1152 bytes --]
On 30.05.2012 23:23, Keith Seitz wrote:
> 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}
>
Thank you for this example!
I never figured out this feature of Blocks :(
> See the relevant sections in the Gdb Users Manual (23.2.2.16, 23.2.2.18).
I totally miss the hint that Blocks drop Value objects on iteration in
the documentation.
How to access the "hierarchically organized" sub-blocks? Or did I
missunderstand the concept of Blocks?
main()
{
int i;
for(...)
{
int a;
}
{
int i;
}
}
I would expect a Block for the main function with two children Blocks -
but how to get these children?
- Joachim
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5306 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Pythons scripting API question
2012-06-06 15:46 ` Joachim Protze
@ 2012-06-06 17:58 ` Tom Tromey
0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2012-06-06 17:58 UTC (permalink / raw)
To: Joachim Protze; +Cc: gdb
>>>>> "Joachim" == Joachim Protze <joachim.protze@tu-dresden.de> writes:
Joachim> Thank you for this example!
Joachim> I never figured out this feature of Blocks :(
Keith> See the relevant sections in the Gdb Users Manual (23.2.2.16, 23.2.2.18).
Joachim> I totally miss the hint that Blocks drop Value objects on iteration in
Joachim> the documentation.
It was patched to be more clear:
2012-02-22 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Blocks In Python): Clarify block iteration.
The new text says:
A @code{gdb.Block} is iterable. The iterator returns the symbols
(@pxref{Symbols In Python}) local to the block. [...]
If this is insufficient, suggest more...
Joachim> How to access the "hierarchically organized" sub-blocks?
Unfortunately we are missing API for this.
Could you file a bug report for it?
Or alternatively, try to write it? I don't think gdb has a direct way
to iterate over sub-blocks; but at the very least you can iterate over
the blockvector and look for blocks with a certain parent.
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-06-06 17:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-30 18:10 Pythons scripting API question Evan Driscoll
2012-05-30 21:23 ` Keith Seitz
2012-05-30 22:42 ` Evan Driscoll
2012-05-30 23:12 ` Keith Seitz
2012-06-06 15:46 ` Joachim Protze
2012-06-06 17:58 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).