[RFC v3 07/25] gdb/python: add void_type () method to gdb.Architecture object

Jan Vrany jan.vrany@labware.com
Wed Jan 29 12:43:29 GMT 2025


This commit adds a new method to Python architecture objects that
returns a void type for that architecture.

This will be useful later to create types for function symbols created
using Python extension code.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
---
 gdb/NEWS                             |  3 +++
 gdb/doc/python.texi                  |  4 ++++
 gdb/python/py-arch.c                 | 16 +++++++++++++++-
 gdb/testsuite/gdb.python/py-arch.exp |  4 ++++
 4 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 4262a432f1e..b93e8f73497 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -160,6 +160,9 @@ binary-upload in qSupported reply
   ** Added gdb.Type.owner property.  Contains type's owner, either a
      gdb.Objfile or a gdb.Architecture.
 
+  ** Added gdb.Architecture.void_type. Returns a gdb.Type representing "void"
+     type for that architecture.
+
 * Debugger Adapter Protocol changes
 
   ** The "scopes" request will now return a scope holding global
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ec9de90b905..af9e1f8df5e 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -7199,6 +7199,10 @@ If the indicated type cannot be found, this function will throw a
 @code{ValueError} exception.
 @end defun
 
+@defun Architecture.void_type ()
+This function returns a void type.
+@end defun
+
 @anchor{gdbpy_architecture_registers}
 @defun Architecture.registers (@r{[} reggroup @r{]})
 Return a @code{gdb.RegisterDescriptorIterator} (@pxref{Registers In
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index f7e35a4aa2b..2bf6251a7cb 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -1,6 +1,6 @@
 /* Python interface to architecture
 
-   Copyright (C) 2013-2024 Free Software Foundation, Inc.
+   Copyright (C) 2013-2025 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -318,6 +318,16 @@ archpy_integer_type (PyObject *self, PyObject *args, PyObject *kw)
   return type_to_type_object (type);
 }
 
+/* Implementation of gdb.void_type.  */
+static PyObject *
+archpy_void_type (PyObject *self, PyObject *args)
+{
+  struct gdbarch *gdbarch;
+  ARCHPY_REQUIRE_VALID (self, gdbarch);
+
+  return type_to_type_object (builtin_type (gdbarch)->builtin_void);
+}
+
 /* __repr__ implementation for gdb.Architecture.  */
 
 static PyObject *
@@ -383,6 +393,10 @@ END_PC." },
     "integer_type (size [, signed]) -> type\n\
 Return an integer Type corresponding to the given bitsize and signed-ness.\n\
 If not specified, the type defaults to signed." },
+  { "void_type", (PyCFunction) archpy_void_type,
+    METH_NOARGS,
+    "void_type () -> type\n\
+Return a void Type." },
   { "registers", (PyCFunction) archpy_registers,
     METH_VARARGS | METH_KEYWORDS,
     "registers ([ group-name ]) -> Iterator.\n\
diff --git a/gdb/testsuite/gdb.python/py-arch.exp b/gdb/testsuite/gdb.python/py-arch.exp
index ba3dd9037ed..f7c1c73e4f8 100644
--- a/gdb/testsuite/gdb.python/py-arch.exp
+++ b/gdb/testsuite/gdb.python/py-arch.exp
@@ -106,6 +106,10 @@ foreach_with_prefix test_data { {None None} \
 	"check 'signed' argument can handle non-bool type $bad_type"
 }
 
+gdb_test "python print(arch.void_type())" \
+    "void" \
+    "get void type"
+
 # Test for gdb.architecture_names().  First we're going to grab the
 # complete list of architecture names using the 'complete' command.
 set arch_names []
-- 
2.47.2



More information about the Gdb-patches mailing list