From 336bb2a1c1d24f5db07394a109f7cd6c5b58b10d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 11 Sep 2024 10:35:20 -0600 Subject: Automatically add types to Python modules PR python/32163 points out that various types provided by gdb are not added to the gdb module, so they aren't available for interactive inspection. I think this is just an oversight. This patch fixes the problem by introducing a new helper function that both readies the type and then adds it to the appropriate module. The patch also poisons PyType_Ready, the idea being to avoid this bug in the future. v2: * Fixed a bug in original patch in gdb.Architecture registration * Added regression test for the types mentioned in the bug Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32163 Reviewed-By: Alexandra Petlanova Hajkova --- gdb/testsuite/gdb.python/python.exp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gdb/testsuite/gdb.python') diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index 175a6de..e8eb9ec 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -561,3 +561,12 @@ if { [use_gdb_stub] == 0 } { } } } + +# Regression test for PR python/32163: several types were not +# previously registered with the module, so could not be inspected +# directly. +foreach type {Instruction LazyString Membuf Record RecordFunctionSegment \ + RecordGap RecordInstruction TuiWindow} { + gdb_test "python print(type(gdb.$type))" "" \ + "gdb.$type is registered" +} -- cgit v1.1