/* Python interface to architecture
- Copyright (C) 2013-2020 Free Software Foundation, Inc.
+ Copyright (C) 2013-2022 Free Software Foundation, Inc.
This file is part of GDB.
return gdbpy_new_reggroup_iterator (gdbarch);
}
+/* Implementation of gdb.integer_type. */
+static PyObject *
+archpy_integer_type (PyObject *self, PyObject *args, PyObject *kw)
+{
+ static const char *keywords[] = { "size", "signed", NULL };
+ int size;
+ PyObject *is_signed_obj = nullptr;
+
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "i|O", keywords,
+ &size, &is_signed_obj))
+ return nullptr;
+
+ /* Assume signed by default. */
+ bool is_signed = (is_signed_obj == nullptr
+ || PyObject_IsTrue (is_signed_obj));
+
+ struct gdbarch *gdbarch;
+ ARCHPY_REQUIRE_VALID (self, gdbarch);
+
+ const struct builtin_type *builtins = builtin_type (gdbarch);
+ struct type *type = nullptr;
+ switch (size)
+ {
+ case 0:
+ type = builtins->builtin_int0;
+ break;
+ case 8:
+ type = is_signed ? builtins->builtin_int8 : builtins->builtin_uint8;
+ break;
+ case 16:
+ type = is_signed ? builtins->builtin_int16 : builtins->builtin_uint16;
+ break;
+ case 24:
+ type = is_signed ? builtins->builtin_int24 : builtins->builtin_uint24;
+ break;
+ case 32:
+ type = is_signed ? builtins->builtin_int32 : builtins->builtin_uint32;
+ break;
+ case 64:
+ type = is_signed ? builtins->builtin_int64 : builtins->builtin_uint64;
+ break;
+ case 128:
+ type = is_signed ? builtins->builtin_int128 : builtins->builtin_uint128;
+ break;
+
+ default:
+ PyErr_SetString (PyExc_ValueError,
+ _("no integer type of that size is available"));
+ return nullptr;
+ }
+
+ return type_to_type_object (type);
+}
+
+/* Implementation of gdb.architecture_names(). Return a list of all the
+ BFD architecture names that GDB understands. */
+
+PyObject *
+gdbpy_all_architecture_names (PyObject *self, PyObject *args)
+{
+ gdbpy_ref<> list (PyList_New (0));
+ if (list == nullptr)
+ return nullptr;
+
+ std::vector<const char *> name_list = gdbarch_printable_names ();
+ for (const char *name : name_list)
+ {
+ gdbpy_ref <> py_name (PyString_FromString (name));
+ if (py_name == nullptr)
+ return nullptr;
+ if (PyList_Append (list.get (), py_name.get ()) < 0)
+ return nullptr;
+ }
+
+ return list.release ();
+}
+
+void _initialize_py_arch ();
+void
+_initialize_py_arch ()
+{
+ arch_object_data = gdbarch_data_register_post_init (arch_object_data_init);
+}
+
/* Initializes the Architecture class in the gdb module. */
int
gdbpy_initialize_arch (void)
{
- arch_object_data = gdbarch_data_register_post_init (arch_object_data_init);
arch_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&arch_object_type) < 0)
return -1;
"disassemble (start_pc [, end_pc [, count]]) -> List.\n\
Return a list of at most COUNT disassembled instructions from START_PC to\n\
END_PC." },
+ { "integer_type", (PyCFunction) archpy_integer_type,
+ METH_VARARGS | METH_KEYWORDS,
+ "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." },
{ "registers", (PyCFunction) archpy_registers,
METH_VARARGS | METH_KEYWORDS,
"registers ([ group-name ]) -> Iterator.\n\