From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mSdrB7KdyWjY4QYAWB0awg (envelope-from ) for ; Tue, 16 Sep 2025 13:26:10 -0400 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=p26TIeRk; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 17A2C1E0BA; Tue, 16 Sep 2025 13:26:10 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham 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 098151E04C for ; Tue, 16 Sep 2025 13:26:06 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A1ADE3857037 for ; Tue, 16 Sep 2025 17:26:05 +0000 (GMT) Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id DB0B63858D39 for ; Tue, 16 Sep 2025 17:25:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB0B63858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DB0B63858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758043548; cv=none; b=Rx0DJsTHI68RMdQ0/jQeMQutziuNHuM6O06EHfSrbswIMrHnTxaRz2WdeDA82ZnP28C0Y2IVBiANL4wbegggwRFvc3wPV4qWh13p1tKiX81YoQWGJdv8rKNlBY/Yv3tWwsMv6Z+rrbwWxGfrRWsjJ5ZaYLG5rOw62gFABDdeZBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758043548; c=relaxed/simple; bh=lsI+DpSSEpW3VK/r0gRpWFdNlgHVu6q6H316mcii+SM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CujnBd18DeD2vCz9SGRyoLCMlhLX62GDjFyoGlBfaneFxQLYKpg9u3O3rt8bgIg2uysrwnSXpWBpJk2ElJ0rc4FaqA4hrGaLKGp0hk842iIkDkMgMF+INUz10d0cIAfVp0KiilJ6/W5IcMk4o3z09QifMGcBPfLIsMrRbzmLRAM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB0B63858D39 Authentication-Results: sourceware.org; dkim=policy reason="signing key too small" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=p26TIeRk Received: from eig-obgw-6004b.ext.cloudfilter.net ([10.0.30.210]) by cmsmtp with ESMTPS id yWn3uFnT2aPqLyZR5um1V0; Tue, 16 Sep 2025 17:25:47 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yZR4u5nbNDG0OyZR4uZK91; Tue, 16 Sep 2025 17:25:46 +0000 X-Authority-Analysis: v=2.4 cv=X4VSKHTe c=1 sm=1 tr=0 ts=68c99d9a a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=yJojWOMRYYMA:10 a=ItBw4LHWJt0A:10 a=20KFwNOVAAAA:8 a=3yCiHqCR-svphOB7JjYA:9 a=VS4QxaUSPT0UtbFnIvSC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:Date:References:In-Reply-To :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=CUV5Y6KVoiNyh45jWHkW5HG7GUqbwLPUG/n2IaVNLEs=; b=p26TIeRk06bwFMgW5urCuwtArI YaQwunA32WvLSFtQCGjnY5HyFZoR2KU1arxTjVdS2mZxOo9jh0FVFcvmfzT4jvHP22tGl5x+b5+p9 Ri/tYC323bPbu8Pw0YMcD40zx; Received: from 97-122-110-68.hlrn.qwest.net ([97.122.110.68]:53758 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.1) (envelope-from ) id 1uyZR3-00000001i1g-3ZBx; Tue, 16 Sep 2025 11:25:45 -0600 From: Tom Tromey To: Andrew Burgess Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 1/3] gdb/python: introduce gdb.Corefile API In-Reply-To: <974b7081b12926872eddc6a68a3dec36fb1d06d6.1756828929.git.aburgess@redhat.com> (Andrew Burgess's message of "Tue, 2 Sep 2025 17:03:49 +0100") References: <974b7081b12926872eddc6a68a3dec36fb1d06d6.1756828929.git.aburgess@redhat.com> X-Attribution: Tom Date: Tue, 16 Sep 2025 11:25:45 -0600 Message-ID: <87ecs6l36u.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.110.68 X-Source-L: No X-Exim-ID: 1uyZR3-00000001i1g-3ZBx X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-110-68.hlrn.qwest.net (bapiya) [97.122.110.68]:53758 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfLe7n0CMUWGBZg73F3Bg/56PmR+gOw0Q8PL1zszwXfAMiHkyQgHozYg4Rg/CnG7tpIyi/6peGwWQIYlRhd3+OHrtiuL1oXsYwtXap41cM8tudA/lrOih XWTdZY4rZcLHHcRgc2Najar4RCgglUhe1KTFhFN/18KOAKV8Q0+vYZdJcHmSXCJDW0f+OR7hQ1qHU2Ycx08KdgHAdVwOeSeF2h4= 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 >>>>> "Andrew" == Andrew Burgess writes: Andrew> This commit starts adding some core file related features to the Andrew> Python API. Andrew> In this initial commit I've tried to keep the changes as small as Andrew> possible for easy review. Thanks for doing this. Andrew> +++ b/gdb/python/py-corefile.c Andrew> @@ -0,0 +1,293 @@ Andrew> +/* Python interface to core files. Andrew> + Andrew> + Copyright (C) 2010-2025 Free Software Foundation, Inc. Date seems like copy-paste error. Andrew> + if (result == nullptr) Andrew> + { Andrew> + gdbpy_ref object Andrew> + ((corefile_object *) PyObject_New (corefile_object, Andrew> + &corefile_object_type)); Andrew> + if (object == nullptr) Andrew> + return nullptr; Andrew> + Andrew> + object->dict = PyDict_New (); Andrew> + if (object->dict == nullptr) Andrew> + return nullptr; Andrew> + object->inferior = inf; I don't recall how Python objects are initialized, so I wonder if we could end up in a situation where PyDict_New fails, and then object->inferior is uninitialized. cfpy_dealloc checks corefile->inferior so I guess it could matter. So if Python doesn't memset the object to zero, I guess object->inferior should be initialized before the dict. Andrew> +/* Callback from gdb::observers::core_file_changed. The core file in Andrew> + PSPACE has been changed. */ Andrew> + Andrew> +static void Andrew> +cfpy_corefile_changed (inferior *inf) Andrew> +{ Andrew> + if (!gdb_python_initialized) Andrew> + return; Andrew> + Andrew> + gdbpy_enter enter_py; Andrew> + Andrew> + /* Get any existing corefile_object for PSPACE. */ Andrew> + corefile_object *object = cfpy_inferior_corefile_data_key.get (inf); Andrew> + Andrew> + /* If we have an object, then... */ Andrew> + if (object != nullptr) Andrew> + { Andrew> + /* Clearing the inferior pointer marks the gdb.Corefile as invalid. */ Andrew> + object->inferior = nullptr; Andrew> + Andrew> + /* We're discarding our reference to the gdb.Corefile. */ I wouldn't mind seeing this comment moved to inferior_corefile_deleter::operator(). Andrew> + Py_XDECREF ((PyObject *) object); Andrew> + cfpy_inferior_corefile_data_key.set (inf, nullptr); I think the entire body of this function could be replaced with: cfpy_inferior_corefile_data_key.clear (inf); ... and this would remove duplicate code. Andrew> +static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION Andrew> +gdbpy_initialize_corefile (void) No more (void) I don't think the checker works for us any more -- at least, IIRC it didn't work for C++ stuff very well (I guess we could ask David Malcolm) and I haven't run it in years. So maybe those annotations aren't worthwhile any more. Andrew> + corefile_getset, /* tp_getset */ Andrew> + 0, /* tp_base */ Andrew> + 0, /* tp_dict */ Andrew> + 0, /* tp_descr_get */ Andrew> + 0, /* tp_descr_set */ Andrew> + offsetof (corefile_object, dict), /* tp_dictoffset */ I think if you want __dict__ to work you have to implement it by hand, see gdb_py_generic_dict and its various users. I.e., I think the getset object needs another entry. Tom