From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom Tromey <tom@tromey.com>
Cc: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/3] python: Add Progspace.objfiles method
Date: Wed, 12 Sep 2018 22:58:00 -0000 [thread overview]
Message-ID: <3d6d1484e08f5a40da317520443fb58d@polymtl.ca> (raw)
In-Reply-To: <874leujrxz.fsf@tromey.com>
On 2018-09-12 18:01, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@ericsson.com> writes:
>
> Simon> Question:
>
> Simon> When we try to access a property of an Inferior object that has
> Simon> become invalid, for example, we raise an exception ("Inferior no
> longer
> Simon> exists."). When doing the same with a Progspace object, we
> return None
> Simon> (the only case for now is its filename property). For
> Simon> Progspace.objfiles(), I made it return None too, but perhaps it
> should
> Simon> throw an exception instead? Especially that None is not
> iterable, so
> Simon> trying to do:
>
> Simon> for obj in pspace.objfiles():
> Simon> ...
>
> Simon> will fail horribly if we return None... so should I introduce a
> macro
> Simon> similar to INFPY_REQUIRE_VALID?
>
> There are two approaches to modeling gdb objects in the Python layer.
>
> One is taken by objects like Value whose lifetime can be arbitrarily
> "extended". For these objects, Python simply holds a reference to the
> underlying gdb object.
>
> The other approach is for objects whose lifetime can be controlled by
> the user or other external (to Python) events. For example, a
> breakpoint can be deleted by the user, leaving behind the
> gdb.Breakpoint
> representation.
>
> For these we have generally had the Python object keep a sort of weak
> reference to the gdb object; when the gdb object is destroyed, the
> Python wrapper enters a special invalid state. These objects have an
> is_valid method; and generally all other methods and attributes throw
> an
> exception if the object is invalid -- but I think this is not a
> hard-and-fast rule and can be broken where there is an obvious decent
> non-exception result.
>
> In sum I think INFPY_REQUIRE_VALID is fine if you happen to need it at
> some spot in the inferior wrapper. I wouldn't go out of my way to
> avoid
> it.
This is already how the progspace object works (the weak reference
thing), and I see you've added a PSPY_REQUIRE_VALID in your old patch.
> Normally Python code has to know not to work with an invalid object
> (and
> anyway why would it want to); but I think in this case, I would be fine
> with objfiles() returning an empty sequence. That is what my old patch
> did, I would assume intentionally, though I don't recall.
For consistency with the rest of the API, I would lean towards an
exception. I will update the patch to do that. The existing "filename"
property returns None in that case, unfortunately.
> Finally, I have another ancient and unfinished series that adds a bunch
> of methods to Inferior. If you're working in this area I can send it;
> I'd be happy to rebase it.
Sure!
Thanks,
Simon
next prev parent reply other threads:[~2018-09-12 22:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-12 19:37 [PATCH 1/3] python: Add Inferior.progspace property Simon Marchi
2018-09-12 19:36 ` [PATCH 3/3] python: Fix erroneous doc about gdb.objfiles() Simon Marchi
2018-09-12 21:46 ` Tom Tromey
2018-09-13 2:37 ` Eli Zaretskii
2018-09-13 2:42 ` Simon Marchi
2018-09-12 19:37 ` [PATCH 2/3] python: Add Progspace.objfiles method Simon Marchi
2018-09-12 22:01 ` Tom Tromey
2018-09-12 22:58 ` Simon Marchi [this message]
2018-09-13 4:50 ` Tom Tromey
2018-09-13 2:38 ` Eli Zaretskii
2018-09-12 21:42 ` [PATCH 1/3] python: Add Inferior.progspace property Tom Tromey
2018-09-12 22:22 ` Simon Marchi
2018-09-13 4:38 ` Tom Tromey
2018-09-13 22:16 ` Tom Tromey
2018-09-12 21:43 ` Tom Tromey
2018-09-13 2:37 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3d6d1484e08f5a40da317520443fb58d@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@ericsson.com \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox