From patchwork Fri Mar 10 14:55:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 66224 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED5F538515F4 for ; Fri, 10 Mar 2023 14:58:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED5F538515F4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678460290; bh=AgSoaOHdK7Itr6ZxIkg7AaDqP96IsuUjJQr++YE70co=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Nj6qtkLo7EeJQtaplYoZnK/rmFsZ59XRCcpKH+ehYDM1Pk7AffXUig1WK+sXKjziA QLUXUPW2mIFPGirb6B4v79e0fCTx5czmuijq+dMBk+5ZNKFZXOk7ie1AjimRsNAhrw xKRsidnlIUKFSFSq3TZ3I0J7+lr0t6YN3PmpRTCw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 49E403858298 for ; Fri, 10 Mar 2023 14:56:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49E403858298 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-nUtdqXARP5-lKZi5GJ4Dhg-1; Fri, 10 Mar 2023 09:56:00 -0500 X-MC-Unique: nUtdqXARP5-lKZi5GJ4Dhg-1 Received: by mail-wm1-f72.google.com with SMTP id l31-20020a05600c1d1f00b003e8626cdd42so1917137wms.3 for ; Fri, 10 Mar 2023 06:56:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678460159; 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=AgSoaOHdK7Itr6ZxIkg7AaDqP96IsuUjJQr++YE70co=; b=2TICRRMCGC4TYHTRBJe2PW84Y56l5UGSviQRhkaevVJ+co7E/hj9Mlg4L+4h9d7Mc1 QCv16/IM8AKc0z4Ult7gOERseouZoKRR+wCAOGRHvsxys7U5Fom1S+Gc1j40sN8I62ds 4ZlT7h/y37MxFFoYhaFZj7iWZrv7t+z64zGljPafyb1M+zqFqHyIBirlA+NSB47eu8Xb f884lnNwJGkMCO7122xJT2jZWG5cTEdTHn8U8z8v5xmHgdYtp7NEWXRNpu974yr54w5K PMU3DQwpxY0XClUCabfLpFJGrye/5qT8fIcBolYt7FxWWGpgvqtId9w+IEmgc953Gj1z 7Igw== X-Gm-Message-State: AO0yUKWZdYxKJObUQxYqF2XHQi/gKpAJLJKdn93fJWxUI12Mr+3VzbU+ 5p34sh8ZmlL+ylvoHiEVd/+80i9Cn7YJnh0rf3uBDZIQ+Xy8rJKJMnIjyx7yNOSbHVXdgZuJIMF FcJ4lTOBpDzDTYUT3y8L2PG5YAJ/uiGhnl0veCpGsMiGQn+6X7K+tOSlAd3QZCW5DDOOipefmWj Qo+iJbew== X-Received: by 2002:adf:efca:0:b0:2ce:34c8:44c with SMTP id i10-20020adfefca000000b002ce34c8044cmr16718186wrp.19.1678460159579; Fri, 10 Mar 2023 06:55:59 -0800 (PST) X-Google-Smtp-Source: AK7set9my3stKZbnnN27Bk4KWScNLcb/ikJkFQDnn88u5WvsOZv/CGGvWfZ1kp2StrVe9CBSZq9gtg== X-Received: by 2002:adf:efca:0:b0:2ce:34c8:44c with SMTP id i10-20020adfefca000000b002ce34c8044cmr16718172wrp.19.1678460159157; Fri, 10 Mar 2023 06:55:59 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id n6-20020a5d6b86000000b002c54c8e70b1sm31791wrx.9.2023.03.10.06.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 06:55:58 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 07/10] gdb/python: remove Py_TPFLAGS_BASETYPE from gdb.UnwindInfo Date: Fri, 10 Mar 2023 14:55:24 +0000 Message-Id: <14071218f24a990e20eab6d0fb427594be1baf05.1678460067.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 X-Spam-Status: No, score=-11.7 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" It is not currently possible to directly create gdb.UnwindInfo instances, they need to be created by calling gdb.PendingFrame.create_unwind_info so that the newly created UnwindInfo can be linked to the pending frame. As such there's no tp_init method defined for UnwindInfo. A consequence of all this is that it doesn't really make sense to allow sub-classing of gdb.UnwindInfo. Any sub-class can't call the parents __init__ method to correctly link up the PendingFrame object (there is no parent __init__ method). And any instances that sub-classes UnwindInfo but doesn't call the parent __init__ is going to be invalid for use in GDB. This commit removes the Py_TPFLAGS_BASETYPE flag from the UnwindInfo class, which prevents the class being sub-classed. Then I've added a test to check that this is indeed prevented. Any functional user code will not have any issues with this change. --- gdb/python/py-unwind.c | 2 +- gdb/testsuite/gdb.python/py-unwind.exp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index 1e94c243163..432a26a760a 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -1097,7 +1097,7 @@ PyTypeObject unwind_info_object_type = 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ "GDB UnwindInfo object", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ diff --git a/gdb/testsuite/gdb.python/py-unwind.exp b/gdb/testsuite/gdb.python/py-unwind.exp index 7e6ac9a8623..d65b8447525 100644 --- a/gdb/testsuite/gdb.python/py-unwind.exp +++ b/gdb/testsuite/gdb.python/py-unwind.exp @@ -211,3 +211,20 @@ check_for_fixed_backtrace \ "check backtrace to validate all information" gdb_test_no_output "python check_all_frame_information_matched()" + +# Check we can't sub-class from gdb.UnwindInfo. +gdb_test_multiline "Sub-class gdb.UnwindInfo " \ + "python" "" \ + "class my_unwind_info(gdb.UnwindInfo):" "" \ + " def __init__(self):" "" \ + " pass" "" \ + "end" \ + [multi_line \ + "TypeError: type 'gdb\\.UnwindInfo' is not an acceptable base type" \ + "Error while executing Python code\\."] + +# Check we can't directly instantiate a gdb.UnwindInfo. +gdb_test "python uw = gdb.UnwindInfo()" \ + [multi_line \ + "TypeError: cannot create 'gdb\\.UnwindInfo' instances" \ + "Error while executing Python code\\."]