From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678460162; 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=AgSoaOHdK7Itr6ZxIkg7AaDqP96IsuUjJQr++YE70co=; b=OePUbFEMHr5M74BCRf2IPDbUZKQymbbKctwfx/bqGSrkkp6gjSkrKzVUMSocMxoGzjMZLF 822bBs4eZ0EME4nEIEqfJj1ek7ElReXZxYMQXvXSyOhUuCkiv2CXO7FI6rW4U8tlFf3snO Of18FrhtHlySXCQiZPHxGOoDugXx5+U= 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) From: Andrew Burgess 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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\\."] -- 2.25.4