Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/3] gdb/python: introduce gdb.Corefile API
Date: Tue, 02 Sep 2025 19:26:01 +0300	[thread overview]
Message-ID: <86h5xklt2e.fsf@gnu.org> (raw)
In-Reply-To: <974b7081b12926872eddc6a68a3dec36fb1d06d6.1756828929.git.aburgess@redhat.com> (message from Andrew Burgess on Tue, 2 Sep 2025 17:03:49 +0100)

> From: Andrew Burgess <aburgess@redhat.com>
> Cc: Andrew Burgess <aburgess@redhat.com>
> Date: Tue,  2 Sep 2025 17:03:49 +0100
> 
> This commit starts adding some core file related features to the
> Python API.
> 
> In this initial commit I've tried to keep the changes as small as
> possible for easy review.
> 
> There's a new Python class gdb.Corefile, which represents a loaded
> core file.  This API doesn't allow the user to create their own
> gdb.Corefile objects, a core file must be loaded using the 'core-file'
> command, then a gdb.Corefile object can be obtained by querying the
> inferior in which the core file was loaded.
> 
> There's a new attribute gdb.Inferior.corefile, this is None when no
> core file is loaded, or contains a gdb.Corefile object if a core file
> has been loaded.
> 
> Currently, the gdb.Corefile object has one attribute, and one method,
> these are:
> 
>   gdb.Corefile.filename -- the file name of the loaded core file.
> 
>   gdb.Corefile.is_valid() -- indicates if a gdb.Corefile object is
>   valid or not.  See notes below.
> 
> A gdb.Corefile object is only valid while the corresponding core file
> is loaded into an inferior.  Unloading the core file, or loading a
> different one will cause a gdb.Corefile object to become invalid.  For
> example:
> 
>   (gdb) core-file /tmp/core.54313
>   ... snip ...
>   (gdb) python core=gdb.selected_inferior().corefile
>   (gdb) python print(core)
>   <gdb.Corefile inferior=1 filename='/tmp/core.54313'>
>   (gdb) python print(core.is_valid())
>   True
>   (gdb) core-file
>   No core file now.
>   (gdb) python print(core)
>   <gdb.Corefile (invalid)>
>   (gdb) python print(core.is_valid())
>   False
>   (gdb)
> 
> In order to track changes to the core file, there is a new observable
> 'core_file_changed', which accounts for the changes in corelow.c,
> observable,c, and observable.h.  Currently, this observable is not
> visible as a Python event.
> 
> I chose to access the core file via the inferior even though the core
> file BFD object is actually stored within the program_space.  As such,
> it might seem that the natural choice would be to add the attribute as
> gdb.Progspace.corefile.
> 
> For background reading on my choice, please see:
> 
>   https://inbox.sourceware.org/gdb-patches/577f2c47793acb501c2611c0e6c7ea379f774830.1668789658.git.aburgess@redhat.com
> 
> This patch was never merged, it is still on my backlog, but the
> observation in that work is that some targets are not really
> shareable.  For example, the core_target (corelow.c) stores
> information about the loaded core file within the target instance.  As
> such, each target instance represents a single loaded core file.
> 
> Except that the BFD part of the core file is stored in the
> program_space, which is a little weird.
> 
> During review, Tom made the observation, that maybe we should
> investigate moving the core file BFD into the core_target.  I'm
> inclined to agree with this as a direction of travel.
> 
> All this leaves us with two observations:
> 
>   1. Currently, loading a core file into an inferior, then using
>      'add-inferior' will try to share the core_target between
>      inferiors.  This is broken, and can trigger GDB crashes.  The
>      obvious fix, without reworking core_target, is just to prevent
>      this sharing, making core_target per-inferior.
> 
>   2. Having the core file information split between the core_target
>      instance, and the BFD stored in the program_space is a little
>      weird, and is really just historical.  Planning for a future
>      where the BFD is also stored in the core_target might be wise.
> 
> So, if we imagine that the BFD is (one day) moved into the
> core_target, and that the core_target really becomes non-shareable,
> then it is, I think, clearer that the corefile attribute should live
> on the gdb.Inferior object, not the gdb.Progspace object.
> 
> There's testing for all the functionality added in this commit.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32844
> ---
>  gdb/Makefile.in                          |   1 +
>  gdb/NEWS                                 |  10 +
>  gdb/corelow.c                            |   7 +
>  gdb/doc/python.texi                      |  49 ++++
>  gdb/observable.c                         |   1 +
>  gdb/observable.h                         |   6 +
>  gdb/python/py-corefile.c                 | 293 +++++++++++++++++++++++
>  gdb/python/py-inferior.c                 |  18 ++
>  gdb/python/python-internal.h             |   8 +
>  gdb/testsuite/gdb.python/py-corefile.c   |  25 ++
>  gdb/testsuite/gdb.python/py-corefile.exp | 169 +++++++++++++
>  11 files changed, 587 insertions(+)
>  create mode 100644 gdb/python/py-corefile.c
>  create mode 100644 gdb/testsuite/gdb.python/py-corefile.c
>  create mode 100644 gdb/testsuite/gdb.python/py-corefile.exp

Thanks, the documentation parts are okay.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>

  reply	other threads:[~2025-09-02 16:27 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 16:03 [PATCH 0/3] Core file Python API Andrew Burgess
2025-09-02 16:03 ` [PATCH 1/3] gdb/python: introduce gdb.Corefile API Andrew Burgess
2025-09-02 16:26   ` Eli Zaretskii [this message]
2025-09-16 17:25   ` Tom Tromey
2025-09-23 13:50     ` Andrew Burgess
2025-09-02 16:03 ` [PATCH 2/3] gdb: make structured core file mappings processing global Andrew Burgess
2025-09-16 17:28   ` Tom Tromey
2025-09-02 16:03 ` [PATCH 3/3] gdb/python: add Corefile.mapped_files method Andrew Burgess
2025-09-16 17:54   ` Tom Tromey
2025-09-23 13:52     ` Andrew Burgess
2025-09-23 13:44 ` [PATCHv2 0/3] Core file Python API Andrew Burgess
2025-09-23 13:44   ` [PATCHv2 1/3] gdb/python: introduce gdb.Corefile API Andrew Burgess
2025-10-03 18:56     ` Tom Tromey
2025-10-06  8:54       ` Andrew Burgess
2025-10-06 15:39         ` Tom Tromey
2025-10-06 16:13           ` Andrew Burgess
2025-09-23 13:44   ` [PATCHv2 2/3] gdb: make structured core file mappings processing global Andrew Burgess
2025-10-13 13:57     ` Lancelot SIX
2025-10-13 14:37       ` Andrew Burgess
2025-10-13 15:16         ` Six, Lancelot
2025-10-14  9:12         ` Lancelot SIX
2025-09-23 13:44   ` [PATCHv2 3/3] gdb/python: add Corefile.mapped_files method Andrew Burgess
2025-10-03 19:15     ` Tom Tromey
2025-10-07  6:24       ` Tom de Vries
2025-10-07 12:21         ` Andrew Burgess
2025-10-07 13:08           ` Tom de Vries
2025-10-07 13:26             ` Andrew Burgess
2025-10-07 14:38               ` Andrew Burgess
2025-10-07 15:43                 ` Tom de Vries
2025-10-07 16:28                   ` Andrew Burgess
2025-10-08  9:29                     ` Andrew Burgess
2025-10-08 10:36                       ` Tom de Vries
2025-10-08 14:14                         ` Andrew Burgess
2025-10-08 15:43                           ` Tom de Vries
2025-10-08 16:03                             ` Andrew Burgess
2025-10-16 20:00           ` Tom Tromey
2025-10-17 10:02             ` Andrew Burgess
2025-10-17 13:32               ` 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=86h5xklt2e.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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