public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Simon Farre via Gdb-patches <gdb-patches@sourceware.org>
Cc: Tom Tromey <tom@tromey.com>,  Simon Farre <simon.farre.cx@gmail.com>
Subject: Re: [PATCH v2] gdb/Python: Added ThreadExitedEvent
Date: Mon, 18 Apr 2022 07:57:09 -0600	[thread overview]
Message-ID: <87lew2xznu.fsf@tromey.com> (raw)
In-Reply-To: <CACx6OkxQx16yomL9XDi8TvbLGM_4yY5+A43kvpf2UwMYkcWB7w@mail.gmail.com> (Simon Farre via Gdb-patches's message of "Mon, 18 Apr 2022 12:30:22 +0200")

>>>>> Simon Farre via Gdb-patches <gdb-patches@sourceware.org> writes:

> So my reasoning for this was; since the thread is exiting it is dying,
> and from a Python perspective I thought it proper not to hold on to
> any resources that GDB otherwise would dispose of. I'm open to
> suggestions for whether or not this logic is sound.

gdb uses a maybe-weird approach to lifetime management.

Normally, a Python object isn't allowed to keep some underlying gdb
object alive.  So, if an inferior thread exits, the gdb data structures
will be cleaned up.  However, the InferiorThread wrapper object may live
on -- but now it is in a special invalid date.

This approach is why a bunch of types, like InferiorThread, have an
'is_valid' method.

So, it's fine to emit this event with the InferiorThread object.  If the
Python code capture it, that will be fine.  (Though of course this
probably won't normally happen anyway.)

gdb could probably be better about notifying Python about these
transitions to the invalid state.  I feel like there's some Python
protocol in this area that gdb should participate in but does not.
Like, it may be useful for using these objects as keys in a weak map.

> It's currently emitted inside `delete_thread_object` which is a
> function that is attached to the observer
> `gdb::observers::thread_exit` in py-inferior.c. So if we are to return
> a reference to the thread object, the function attached here should
> probably be removed entirely and replaced with just emitting the newly
> introduced "thread exit event" (and handle the de-allocation of the
> thread object inside the thread exit event type tp_dealloc function).

I think the current placement of the code is correct.  I'm not sure I
understand the tp_dealloc comment, but I don't think a change there is
needed.

Tom

  reply	other threads:[~2022-04-18 13:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-12  9:03 Simon Farre
2022-04-15 18:06 ` Tom Tromey
2022-04-18 10:30   ` Simon Farre
2022-04-18 13:57     ` Tom Tromey [this message]
2022-04-15 19:46 ` Eli Zaretskii
2022-04-18  9:38   ` Simon Farre
2022-04-18  9:41     ` Eli Zaretskii
2022-04-18 13:58     ` Tom Tromey
2022-04-18 16:19 ` Pedro Alves
2022-04-19 11:42   ` Simon Farre

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=87lew2xznu.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.farre.cx@gmail.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).