* Python API iterate through the arguments of a frame
@ 2012-02-21 15:55 Cristian Zamfir
2012-02-21 19:54 ` Tom Tromey
0 siblings, 1 reply; 7+ messages in thread
From: Cristian Zamfir @ 2012-02-21 15:55 UTC (permalink / raw)
To: gdb
Hi,
I would like to write a Python script that iterates through the arguments of a frame. I was hoping I can retrieve these arguments from a Frame object, but I did not find a way to do this, unless I know the name of the variables. Similarly, I would like to iterate through all the locals of the frame.
Is this possible with the current Python API? If not, can you please point me to where I could add additional functions to the Python API?
Thank you,
Cristi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Python API iterate through the arguments of a frame
2012-02-21 15:55 Python API iterate through the arguments of a frame Cristian Zamfir
@ 2012-02-21 19:54 ` Tom Tromey
2012-02-21 22:52 ` Cristian Zamfir
0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2012-02-21 19:54 UTC (permalink / raw)
To: Cristian Zamfir; +Cc: gdb
>>>>> "Cristian" == Cristian Zamfir <cristian.zamfir@epfl.ch> writes:
Cristian> I would like to write a Python script that iterates through the
Cristian> arguments of a frame. I was hoping I can retrieve these arguments from
Cristian> a Frame object, but I did not find a way to do this, unless I know the
Cristian> name of the variables. Similarly, I would like to iterate through all
Cristian> the locals of the frame.
Cristian> Is this possible with the current Python API? If not, can you please
Cristian> point me to where I could add additional functions to the Python API?
You can find the locals and arguments via Frame.block.
I see that gdb.Block is under-documented in this area. Sorry about
that, I will write a patch.
Here's a quick example:
(top-gdb) start
[...]
Temporary breakpoint 3, main (argc=
During symbol reading, incomplete CFI data; unspecified registers (e.g., rax) at 0x488914.
1, argv=0x7fffffffe558) at ../../archer/gdb/gdb.c:26
(top-gdb) python
>for sym in gdb.newest_frame().block():
> print sym
>end
argc
argv
args
In order to find all the locals in scope, and the arguments, you may
have to iterate upwards over blocks via Block.superblock. The block
with a non-None 'function' attribute will hold the arguments.
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Python API iterate through the arguments of a frame
2012-02-21 19:54 ` Tom Tromey
@ 2012-02-21 22:52 ` Cristian Zamfir
2012-02-22 1:52 ` Paul_Koning
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Cristian Zamfir @ 2012-02-21 22:52 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb
On Feb 21, 2012, at 7:14 PM, Tom Tromey wrote:
>>>>>> "Cristian" == Cristian Zamfir <cristian.zamfir@epfl.ch> writes:
>
> Cristian> I would like to write a Python script that iterates through the
> Cristian> arguments of a frame. I was hoping I can retrieve these arguments from
> Cristian> a Frame object, but I did not find a way to do this, unless I know the
> Cristian> name of the variables. Similarly, I would like to iterate through all
> Cristian> the locals of the frame.
>
> Cristian> Is this possible with the current Python API? If not, can you please
> Cristian> point me to where I could add additional functions to the Python API?
>
> You can find the locals and arguments via Frame.block.
Great, this worked.
>
> I see that gdb.Block is under-documented in this area. Sorry about
> that, I will write a patch.
Thank you, that would be very useful. Is there a quick way to see the names of all available API functions, just in case there are more undocumented ones, other than looking into the gdb/python/ directory and infer from the Python bindings (e.g., py-block.c)?
Somehow unrelated to this, I just noticed that I can retrieve the type of a symbol while running a program inside gdb, but not when loading a dumped core. In the latter case I get this error:
AttributeError: 'gdb.Symbol' object has no attribute 'type'.
I can however still retrieve the name and the value of the symbol when loading a core. Is it possible to also get the type?
I should mention that I also see these two warnings when loading the core:
warning: core file may not match specified executable file.
warning: Can't read pathname for load map: Input/output error.
Thanks,
Cristi
>
> Here's a quick example:
>
> (top-gdb) start
> [...]
> Temporary breakpoint 3, main (argc=
> During symbol reading, incomplete CFI data; unspecified registers (e.g., rax) at 0x488914.
> 1, argv=0x7fffffffe558) at ../../archer/gdb/gdb.c:26
> (top-gdb) python
>> for sym in gdb.newest_frame().block():
>> print sym
>> end
> argc
> argv
> args
>
>
> In order to find all the locals in scope, and the arguments, you may
> have to iterate upwards over blocks via Block.superblock. The block
> with a non-None 'function' attribute will hold the arguments.
>
> Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Python API iterate through the arguments of a frame
2012-02-21 22:52 ` Cristian Zamfir
@ 2012-02-22 1:52 ` Paul_Koning
2012-02-22 8:54 ` Joachim Protze
2012-02-22 15:07 ` Tom Tromey
2 siblings, 0 replies; 7+ messages in thread
From: Paul_Koning @ 2012-02-22 1:52 UTC (permalink / raw)
To: cristian.zamfir, tromey; +Cc: gdb
>Thank you, that would be very useful. Is there a quick way to see the names of all >available API functions, just in case there are more undocumented ones, other than looking >into the gdb/python/ directory and infer from the Python bindings (e.g., py-block.c)?
Standard Python approach: help(xyz) gives you the documentation for xyz. If xyz is a
class or module, it does that recursively. So:
(gdb) python help(gdb)
will give you all the documentation for everything inside the gdb module.
paul
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Python API iterate through the arguments of a frame
2012-02-21 22:52 ` Cristian Zamfir
2012-02-22 1:52 ` Paul_Koning
@ 2012-02-22 8:54 ` Joachim Protze
2012-02-22 15:07 ` Tom Tromey
2 siblings, 0 replies; 7+ messages in thread
From: Joachim Protze @ 2012-02-22 8:54 UTC (permalink / raw)
To: Cristian Zamfir, gdb
[-- Attachment #1: Type: text/plain, Size: 475 bytes --]
On 21.02.2012 23:52, Cristian Zamfir wrote:
> Thank you, that would be very useful. Is there a quick way to see the names of all available API functions, just in case there are more undocumented ones, other than looking into the gdb/python/ directory and infer from the Python bindings (e.g., py-block.c)?
You may find the python function dir(<class>) very handy to find
undocumented functions; this lists you all methods and attributes of the
class.
- Joachim
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5306 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Python API iterate through the arguments of a frame
2012-02-21 22:52 ` Cristian Zamfir
2012-02-22 1:52 ` Paul_Koning
2012-02-22 8:54 ` Joachim Protze
@ 2012-02-22 15:07 ` Tom Tromey
2012-02-22 15:41 ` Cristian Zamfir
2 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2012-02-22 15:07 UTC (permalink / raw)
To: Cristian Zamfir; +Cc: gdb
>>>>> "Cristian" == Cristian Zamfir <cristian.zamfir@epfl.ch> writes:
Cristian> Thank you, that would be very useful. Is there a quick way to see the
Cristian> names of all available API functions, just in case there are more
Cristian> undocumented ones, other than looking into the gdb/python/ directory
Cristian> and infer from the Python bindings (e.g., py-block.c)?
In addition to the other responses, I'd like to add that we want the
documentation to be complete and clear; so please file bugs for any
holes or problems you notice.
Cristian> I can however still retrieve the name and the value of the symbol when
Cristian> loading a core. Is it possible to also get the type?
Yes, this information is orthogonal to where the inferior memory comes
from.
Cristian> warning: core file may not match specified executable file.
Cristian> warning: Can't read pathname for load map: Input/output error.
These could be a problem, but offhand I can't say what is going on.
I'm surprised about the AttributeError. I'm not sure how that could
happen.
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Python API iterate through the arguments of a frame
2012-02-22 15:07 ` Tom Tromey
@ 2012-02-22 15:41 ` Cristian Zamfir
0 siblings, 0 replies; 7+ messages in thread
From: Cristian Zamfir @ 2012-02-22 15:41 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb
On Feb 22, 2012, at 4:06 PM, Tom Tromey wrote:
>>>>>> "Cristian" == Cristian Zamfir <cristian.zamfir@epfl.ch> writes:
>
> Cristian> Thank you, that would be very useful. Is there a quick way to see the
> Cristian> names of all available API functions, just in case there are more
> Cristian> undocumented ones, other than looking into the gdb/python/ directory
> Cristian> and infer from the Python bindings (e.g., py-block.c)?
>
> In addition to the other responses, I'd like to add that we want the
> documentation to be complete and clear; so please file bugs for any
> holes or problems you notice.
Sure, I will. Thanks everyone for the help.
>
> Cristian> I can however still retrieve the name and the value of the symbol when
> Cristian> loading a core. Is it possible to also get the type?
>
> Yes, this information is orthogonal to where the inferior memory comes
> from.
>
> Cristian> warning: core file may not match specified executable file.
> Cristian> warning: Can't read pathname for load map: Input/output error.
>
> These could be a problem, but offhand I can't say what is going on.
>
> I'm surprised about the AttributeError. I'm not sure how that could
> happen.
It turned out that when I was loading the core I used an older version of gdb (7.3), in which gdb.Symbol did not have the type attribute. Everything works with the latest version.
Thanks,
Cristi
>
> Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-02-22 15:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-21 15:55 Python API iterate through the arguments of a frame Cristian Zamfir
2012-02-21 19:54 ` Tom Tromey
2012-02-21 22:52 ` Cristian Zamfir
2012-02-22 1:52 ` Paul_Koning
2012-02-22 8:54 ` Joachim Protze
2012-02-22 15:07 ` Tom Tromey
2012-02-22 15:41 ` Cristian Zamfir
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).