From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GjhOOdcat2jxUhIAWB0awg (envelope-from ) for ; Tue, 02 Sep 2025 12:27:03 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=nOJgpVBW; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D1AEB1E087; Tue, 02 Sep 2025 12:27:03 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id DE9371E057 for ; Tue, 02 Sep 2025 12:27:02 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E44D385840B for ; Tue, 2 Sep 2025 16:27:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E44D385840B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=nOJgpVBW Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 800293858D32 for ; Tue, 2 Sep 2025 16:26:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 800293858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 800293858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756830389; cv=none; b=UnkKXIsE7pu02mYo29Z6SAgZpChkr0HYHxhFGfb0GGYx98zlYucM66iLRMhA7Fw1tEL8Ev5fdzdYwcYcLHRdWX3x3pP3CXAOh8G1CdSfFHrBFNikaSNtGz1WJ5aX/TAvc4YDOPsmeeAVFk/DinT9wvzo4UPkHh3UK9hW0NoLAoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756830389; c=relaxed/simple; bh=NrHQnpvJA32pKjONRVT7c8Oqwzn6FDpomZllCC1sVjE=; h=DKIM-Signature:Date:Message-Id:From:To:Subject; b=gs/RN0hQ2C35fuUQe0OC3zUdVYgWbWgx22cSrcn7lmcEXCJ+FpOxeRLyiLFR6n0LZDEnxhXghc4F2HJ5TUnoxWEptp7Bj9pYydpviOCrEZp4bHlXXB4rmqs8przG+KbaJZHZOxwMm3jiiys8DRm7By1kywuIR+Vp/Bd6V6O0cyE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 800293858D32 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utTq0-0006MH-O5; Tue, 02 Sep 2025 12:26:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=MKytCjBetmUuE4258uipnHVYyH6MaCNbT/Y+LzA+RLI=; b=nOJgpVBW9PJN UMzPkyI7qBPzlMDF4KnPzGCBKIDocknkwNLuB3MitjKsnpSTlT0UU/KGXxCWVI6qLy6Hhwu5spcBN Xx7zzI76yczImLLILthPTXWdaNVrh6Wvgjs6LftPnG8f1CZbUQ/WI9ArCVgN42kTxe3wZ78uLszDS m3fDLANUUMC3ylqn+SrBbSJATKc32lhjU6DhKwKKwn/U8bvcXwXSD63iigulaGzsS+tSDm1kTtCL5 sdcOJ14GcVWJOiOuPDFoJ4mYU2t122Q5XwRyoC949/9oDZAOeBlnmTrq/sn3E9cjCfalfxQV6bt3m MW4lhEkrRd9mdOCQMF0JHA==; Date: Tue, 02 Sep 2025 19:26:01 +0300 Message-Id: <86h5xklt2e.fsf@gnu.org> From: Eli Zaretskii To: Andrew Burgess Cc: gdb-patches@sourceware.org In-Reply-To: <974b7081b12926872eddc6a68a3dec36fb1d06d6.1756828929.git.aburgess@redhat.com> (message from Andrew Burgess on Tue, 2 Sep 2025 17:03:49 +0100) Subject: Re: [PATCH 1/3] gdb/python: introduce gdb.Corefile API References: <974b7081b12926872eddc6a68a3dec36fb1d06d6.1756828929.git.aburgess@redhat.com> X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org > From: Andrew Burgess > Cc: Andrew Burgess > 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) python print(core.is_valid()) > True > (gdb) core-file > No core file now. > (gdb) python print(core) > > (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