public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/python: remove Py_TPFLAGS_BASETYPE from gdb.UnwindInfo
@ 2023-03-30  9:26 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2023-03-30  9:26 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=df4447e4c43e105bd6366081a07447506506f78b

commit df4447e4c43e105bd6366081a07447506506f78b
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Fri Mar 10 10:28:21 2023 +0000

    gdb/python: remove Py_TPFLAGS_BASETYPE from gdb.UnwindInfo
    
    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.
    
    Reviewed-By: Tom Tromey <tom@tromey.com>

Diff:
---
 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\\."]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-30  9:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-30  9:26 [binutils-gdb] gdb/python: remove Py_TPFLAGS_BASETYPE from gdb.UnwindInfo Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).