From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ODEjKD++nmUnyjcAWB0awg (envelope-from ) for ; Wed, 10 Jan 2024 10:56:47 -0500 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=dVqcGcUv; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A11AE1E0C3; Wed, 10 Jan 2024 10:56:47 -0500 (EST) 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 887821E0BB for ; Wed, 10 Jan 2024 10:56:45 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 06387386100F for ; Wed, 10 Jan 2024 15:56:45 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8DF0438582B0 for ; Wed, 10 Jan 2024 15:55:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8DF0438582B0 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 8DF0438582B0 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=1704902102; cv=none; b=W8ilMm7rBWuDTy4H0av/8not8s3uzPAiSJ0ymGR+TZImeF8T8Yi6dyPUt4ghrC9DuyoH11J7aAZkAwSogkUcSNCHleyrC9vR111Xnqd1TbvaSLDmMNYjS6Y8YPWZ7EXG5alcejEqqPxKYph4zH45EnioDXO4DlRkPCJn2poUOwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704902102; c=relaxed/simple; bh=yoVpfo3dycYaM9L7ds6RIBN48HBNBn+AWphZVfLY/lc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=N1Mo4NyCJeuSS40eC80Xp04rC4P4FEjGQ0joWNgZv0R6K3fhmWy6yxFuDRsxJsnOTe8kDUZl80b9C3eks0/G+M6FpcJ9GpLfOi4f7cjGX4OtW/Kf5mn8Phx4x/Vvig0uCLfzyBSI/wlIa9r7jnG2OmrlvPDDQiSOw89QLGFM5Jo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704902100; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=08vr4FmuHFtNm/C6njOEFGhYSQD4wqYkXTlPYw8W5ZY=; b=dVqcGcUvVgXxLFIj3TfEwIELSZ2fSgqteVp8cmR6opijqdkyErP894dvSM93mOJMBY9CAI SNQ8zWiN8Rza9YifIs/1brd9gIF4rWiWMTqbMw9OoTEe9RYJ+vQkq3GycnqxDhN3V2I6ut YKlgT3lNv3d7FXZ356QgWhG+s12/4Po= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-463-cCgAL-AFP56qj_GI2JmIeg-1; Wed, 10 Jan 2024 10:54:58 -0500 X-MC-Unique: cCgAL-AFP56qj_GI2JmIeg-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-40e4caa37f5so17507435e9.0 for ; Wed, 10 Jan 2024 07:54:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704902097; x=1705506897; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=08vr4FmuHFtNm/C6njOEFGhYSQD4wqYkXTlPYw8W5ZY=; b=mqvlYj56r3HCM4mTbWYi+qmf79+p5n+eKOGFtzyZLlbq4ui+W+ku0bifWih0oLLaM+ 8upTfKodDdhbj7DIoX7/ZXAFC5urkhSUP/xB+IW1pDhG3gaX+m4jxuJCN3uA169PFWEw Mxd9Y6OdXeqVhJeSAv9bv+pnj5g+KKjPo3ADHgK8v/77xSq/08nT08BT8yWM8wdJi1M1 lMRhwRuynfcCVCjPzfYhwmcRruFgasOMMS0g1xG1/JM3xKT1ObAJScWukgfQd3j4XziK yytWHsp1+5cd26QRAt/nJSTVfVu4r/fH8v2gRYejAm1utV2avi+BAhA+dy2px8pob8ni joCQ== X-Gm-Message-State: AOJu0Yz5i917mOXIDmrm5HL+migHa2UHKWQ3xwRvgUpiDxTGJ/fS7GIi 7KNEfs3mJuzDn2F02Eh852L52OLhifk9yeii8EyPO89VjHX5fgwDVtX8YixXLmHPIz9djD3rAOR BFvuW+F47c5WhMzuVo0m3/XMgSRitxPlajZ7jXFyXaA8H74bLG4yr26VCgSWKpH2tplXYlnhSzz dzUemznFm2dM9jHg== X-Received: by 2002:a05:600c:154e:b0:40e:4617:2290 with SMTP id f14-20020a05600c154e00b0040e46172290mr675555wmg.97.1704902097029; Wed, 10 Jan 2024 07:54:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFl22ziK6IXStyEXup8qEt6THASvtyp3USpmQlO7yMvC3nacbfHmDIR+Gu2z3IpqlZXTDK5A== X-Received: by 2002:a05:600c:154e:b0:40e:4617:2290 with SMTP id f14-20020a05600c154e00b0040e46172290mr675548wmg.97.1704902096719; Wed, 10 Jan 2024 07:54:56 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id r15-20020a05600c458f00b0040d1bd0e716sm2641853wmo.9.2024.01.10.07.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 07:54:55 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Eli Zaretskii Subject: [PATCHv2 4/8] gdb/python: remove users ability to create gdb.Progspace objects Date: Wed, 10 Jan 2024 15:54:41 +0000 Message-Id: <8990b13a57adba8f48f0aef44364bacf305c7bca.1704901918.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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 I noticed that it is possible for the user to create a new gdb.Progspace object, like this: (gdb) pi >>> p = gdb.Progspace() >>> p >>> p.is_valid() False As the new gdb.Progspace object is not associated with an actual C++ program_space object within GDB core, then the new gdb.Progspace is created invalid, and there is no way in which the new object can ever become valid. Nor do I believe there's anywhere in the Python API where it makes sense to consume an invalid gdb.Progspace created in this way, for example, the gdb.Progspace could be passed as the locus to register_type_printer, but all that would happen is that the registered printer would never be used. In this commit I propose to remove the ability to create new gdb.Progspace objects. Attempting to do so now gives an error, like this: (gdb) pi >>> gdb.Progspace() Traceback (most recent call last): File "", line 1, in TypeError: cannot create 'gdb.Progspace' instances Of course, there is a small risk here that some existing user code might break ... but if that happens I don't believe the user code can have been doing anything useful, so I see this as a small risk. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 5 +++++ gdb/python/py-progspace.c | 16 +--------------- gdb/testsuite/gdb.python/py-progspace.exp | 6 ++++++ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 11cd6c0663e..36443c38aca 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -87,6 +87,11 @@ show remote thread-options-packet ** New function gdb.interrupt(), that interrupts GDB as if the user typed control-c. + ** It is no longer possible to create new gdb.Progspace object using + 'gdb.Progspace()', this will result in a TypeError. Progspace + objects can still be obtained through calling other API + functions, for example 'gdb.current_progspace()'. + * Debugger Adapter Protocol changes ** GDB now emits the "process" event. diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 0797ef1fa6b..bfc6ff50f01 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -210,20 +210,6 @@ pspy_initialize (pspace_object *self) return 1; } -static PyObject * -pspy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) -{ - gdbpy_ref self ((pspace_object *) type->tp_alloc (type, 0)); - - if (self != NULL) - { - if (!pspy_initialize (self.get ())) - return NULL; - } - - return (PyObject *) self.release (); -} - PyObject * pspy_get_printers (PyObject *o, void *ignore) { @@ -859,5 +845,5 @@ PyTypeObject pspace_object_type = offsetof (pspace_object, dict), /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ - pspy_new, /* tp_new */ + 0, /* tp_new */ }; diff --git a/gdb/testsuite/gdb.python/py-progspace.exp b/gdb/testsuite/gdb.python/py-progspace.exp index befd6433e47..5f6a9577f82 100644 --- a/gdb/testsuite/gdb.python/py-progspace.exp +++ b/gdb/testsuite/gdb.python/py-progspace.exp @@ -53,6 +53,12 @@ gdb_py_test_silent_cmd "python progspace.random_attribute = 42" \ gdb_test "python print (progspace.random_attribute)" "42" \ "Verify set of random attribute in progspace" +# Check that we can't create new (invalid) gdb.Progspace objects. +gdb_test "python gdb.Progspace()" \ + [multi_line "TypeError: cannot create 'gdb.Progspace' instances" \ + "Error while executing Python code\\."] \ + "check for error when calling gdb.Progspace() directly" + if {![runto_main]} { return } -- 2.25.4