public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey <tom@tromey.com>,
	Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH] gdb: add Python events for program space addition and removal
Date: Wed, 27 Sep 2023 11:51:51 +0100	[thread overview]
Message-ID: <87r0mjx514.fsf@redhat.com> (raw)
In-Reply-To: <87cyyb72pj.fsf@tromey.com>

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Andrew> Initially I just wanted a Python event for when GDB removes a program
> Andrew> space, I'm writing a Python extension that caches information for each
> Andrew> program space, and need to know when I should discard entries for a
> Andrew> particular program space.
>
> Andrew> But, it seemed easy enough to also add an event for when GDB adds a
> Andrew> new program space, so I went ahead and added both new events.
>
> This approach seems totally fine to me, but it's worth noting that you
> could attach data directly to a Progspace if the tp_hash field were
> filled in.  Some other Python classes in gdb do this.  This makes caches
> easier because the cleanup is automatic.

I'm not sure I understand how tp_hash helps here?

gdb.Progspace does have a __dict__ attribute, so things like:

  progspace.my_random_var = ....

works just fine, and I did consider this.  But I wasn't sure if this was
"good practice".  My concern was mostly that this might lead to clashes
between different extensions if good names are not chosen for
'my_random_var', or even clashes between extensions and future GDB
enhancements -- my understanding is that if we later added
'my_random_var' as a builtin attribute this would take precedence over
the user defined attribute, breaking their extension.

>
> Andrew> +No @code{NewProgspaceEvent} is emitted for the very first program
> Andrew> +space, which is assigned to the first inferior.  This first program
> Andrew> +space is created within @value{GDBN} before and Python scripts are
>
> Typo, "before any"

Fixed, thanks.

>
> Other than that it looks good.

I'll likely merge this anyway, this doesn't stop folk making use of the
__dict__ approach if they prefer -- as you point out, it does have a
significant benefit in that it automates the cleanup.

>
> Approved-By: Tom Tromey <tom@tromey.com>

Thanks,
Andrew


  reply	other threads:[~2023-09-27 10:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-21 12:44 Andrew Burgess
2023-09-21 19:20 ` Tom Tromey
2023-09-27 10:51   ` Andrew Burgess [this message]
2023-09-27 14:20     ` Tom Tromey
2023-09-27 15:17       ` Andrew Burgess
2023-09-27 15:16 ` [PATCHv2] " Andrew Burgess
2023-09-29 12:41   ` Eli Zaretskii
2023-09-29 13:24   ` [PATCHv3] " Andrew Burgess
2023-09-29 15:46     ` Eli Zaretskii
2023-10-02 16:09       ` Andrew Burgess
2023-10-02 18:34     ` Simon Marchi
2023-10-02 20:36       ` Andrew Burgess
2023-10-02 20:38         ` Simon Marchi
2023-10-02 21:17           ` Andrew Burgess
2023-10-02 20:11     ` [PUSHED] gdb/python: reformat file with black Andrew Burgess

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=87r0mjx514.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).