From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QbVFGv2l0miySQ8AWB0awg (envelope-from ) for ; Tue, 23 Sep 2025 09:51:57 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MBk78owU; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 654C61E0BA; Tue, 23 Sep 2025 09:51:57 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 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_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 9C3A21E047 for ; Tue, 23 Sep 2025 09:51:56 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3BEE83858D29 for ; Tue, 23 Sep 2025 13:51:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BEE83858D29 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MBk78owU Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 731873858C78 for ; Tue, 23 Sep 2025 13:50:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 731873858C78 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 731873858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758635442; cv=none; b=cnkkvhE9mbajNRP7GMt5zVQZbJws4WD5k+C0W+iMjbZmSFLKmW4MN8u7Om/C5n9xFxJ1D9+7P9021g/kubiFnRvAPERoTY5xZOTF2EgQFawymhSSO5JI8LUBdkJkOp4GutM/ibLhLTcIn+37WInxexJi7eAwIUPnH/Ja10810FQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758635442; c=relaxed/simple; bh=KA1WIZctNgo2agt4m767+SBxw/IvIHhCZwZ5NF6ABrQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KdHeWzpf5m195p3A0V56VvYCC4xyRfRRXzmqncFSkb9wLhfDBT1Y9KCU9oX8CQzfTKur/c3Wxb0hIoHbCbfbBeMnLMX+wq1haomH4qJyAybQzyH5bJHBvvSf9eQblnRSu1LiaiGc3BjOsnQL7yNUIuERUhr/bKpWJ6FseyGH3cI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 731873858C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758635442; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0oEya0ddJr21Z4rER6ONALeJGPZ777wmtkI+3yw2858=; b=MBk78owUx26+1PniIUNggLkxIMkACEo574dHZOvBywG/4mxwfYOlO8oUG+p5H86OUeNa8I bdxp1jj0JgQh+cs473aJrnDXMsPwGr7dAoJQM0+oFcUfg5zhEnVlBheaHu4/5ubYpaOsPl bLK1nPqzlFLH6RB9XlK7JwjOLzgtKFE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-215-N7YIKTAnNF-04Ez82HuGwg-1; Tue, 23 Sep 2025 09:50:41 -0400 X-MC-Unique: N7YIKTAnNF-04Ez82HuGwg-1 X-Mimecast-MFC-AGG-ID: N7YIKTAnNF-04Ez82HuGwg_1758635440 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3ef21d77d2eso4624415f8f.1 for ; Tue, 23 Sep 2025 06:50:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758635439; x=1759240239; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0oEya0ddJr21Z4rER6ONALeJGPZ777wmtkI+3yw2858=; b=UYik3TbMy6VdxlU+HCIyfGSZ0kXPUQCEcPoK7xLQP5Py2o6yfP5Qk9gYI79uZqjsFM KC3Jztkz3Kv6WQrM3acLc+RHvn7XKaKzW64nqH23OUN2yw56Tu4+o4Bp7yTr1r7G0Mtd fhS7PkKdjkSnThsiPPyt502JjxkIDRCmWcvk8b5Wn3DVQ4yTXIMZe2RnrMO5CnPhImO8 F7FtDgvYf0fYen5tG2p78pWRSdjt4kd+mKgOlb+/Kwg7nBR5ur0neAGHv7HQIi17ZvWT L0a7g5uNQ/nYvVjSV6kmAH8Adws6fjaJbq++uj+didW/6Ult+oAtYq0F7/bKXl3PkbqC fbQw== X-Gm-Message-State: AOJu0YznCO14Yohia5O20K52V9lbH/jYEJ3fe+i1i6yhyKtPW7aWGVts DQ90CbQnab5KXQyHlHthGKsIHwyi23f6GEWrQyAOAlnL6S9YYjMnUZP7VOO7id+Yu6eUhevTb9n I0cUObi3qmnUs2YotWDgt8TO0Gd/PsIYivHgMPvnkHEUmFKAtF5osQ8ACB9ndWnRFT9QtZ1E= X-Gm-Gg: ASbGncumYHRcNRBSYmsWGQm94nD9xgb3lVPGCBkWxhfn2cxkJiQosJKnUmVvXJaPuCU znfntWUFSF7k0UF5OZtJ6ENxlm61fRZ27zH0vtotaYWqfVyQC8+yuljanArc0HBfQDLlfv32ZC4 iHmZW/enI14b1doRcHy2r3sgJZb2HypGR0pBM7LCvGkpWU96wtJ9yigjHYQjw+PtIvLwx3EVSvu ON9R+d8+3H0dML8o3LcfMb9rN3DpKbITp3ICZAUW2JYXFBkQUru/dXUSxkZwPKZaCWZZ7CYalr+ +JmNEYYWOoDvsNNKpnVep3jzHx9K6ybJB/s= X-Received: by 2002:a05:6000:25c8:b0:3e7:4197:c99d with SMTP id ffacd0b85a97d-405c57f88a5mr2607727f8f.15.1758635439471; Tue, 23 Sep 2025 06:50:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDtQuAqIgevMSk+wpjxt4bOyV/a+b75zlQfypVXvtbW65aKxuI5l6hWF6npUf6b0pSh8zWoA== X-Received: by 2002:a05:6000:25c8:b0:3e7:4197:c99d with SMTP id ffacd0b85a97d-405c57f88a5mr2607697f8f.15.1758635438987; Tue, 23 Sep 2025 06:50:38 -0700 (PDT) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3ee07408433sm23799474f8f.20.2025.09.23.06.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Sep 2025 06:50:38 -0700 (PDT) From: Andrew Burgess To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 1/3] gdb/python: introduce gdb.Corefile API In-Reply-To: <87ecs6l36u.fsf@tromey.com> References: <974b7081b12926872eddc6a68a3dec36fb1d06d6.1756828929.git.aburgess@redhat.com> <87ecs6l36u.fsf@tromey.com> Date: Tue, 23 Sep 2025 14:50:37 +0100 Message-ID: <87v7l9ffbm.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: cvpLwhC9MhF2PKa8e60Rrc0U39l_c25yik2ApvpSB7Y_1758635440 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 Tom Tromey writes: >>>>>> "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. Fixed. > > 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. You are correct to worry. PyObject_New only initialises the Python object header, not any of the other fields, i.e. 'inferior' will indeed be uninitialised. > 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. This is fixed in V2. I claim we need to first initialise the 'inferior' field to NULL. if the PyDict_New call fails then we'll end up in cfpy_dealloc as you say, and that only expects to see invalidated (inferior == NULL) core file objects. > > 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. Done. > > Andrew> +static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION > Andrew> +gdbpy_initialize_corefile (void) > > No more (void) Fixed. > > 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. I dropped the annotation. > > 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. I hadn't even realised this was a thing. I've added this in now. The code as it was already supported doing things like: core = gdb.selected_inferior().corefile core._my_attribute = "blah blah blah" which is how I've always used this feature. But users can now: core.__dict__['_my_attribute'] = "blah blah blah" too. It doesn't hurt to be consistent with other objects that implement this feature. I posted a V2 series with these fixes included. Thanks, Andrew