88 { -1,
"TYPE_CODE_BITSTRING" },
90#define OP(X) { X, #X },
91#include "type-codes.def"
102 Py_XDECREF (
f->dict);
103 Py_TYPE (obj)->tp_free (obj);
114 result->dict = PyDict_New ();
118 return (
PyObject *) result.release ();
154 if (PyObject_SetAttrString (result.get (),
"parent_type", arg.get ()) < 0)
159 const char *attrstring;
161 if (
type->
code () == TYPE_CODE_ENUM)
164 attrstring =
"enumval";
172 attrstring =
"bitpos";
178 if (PyObject_SetAttrString (result.get (), attrstring, arg.get ()) < 0)
197 if (PyObject_SetAttrString (result.get (),
"name", arg.get ()) < 0)
201 if (PyObject_SetAttrString (result.get (),
"artificial", arg.get ()) < 0)
204 if (
type->
code () == TYPE_CODE_STRUCT)
208 if (PyObject_SetAttrString (result.get (),
"is_base_class", arg.get ()) < 0)
214 if (PyObject_SetAttrString (result.get (),
"bitsize", arg.get ()) < 0)
224 if (PyObject_SetAttrString (result.get (),
"type", arg.get ()) < 0)
268 PyTuple_SET_ITEM (item.get (), 0, key.release ());
269 PyTuple_SET_ITEM (item.get (), 1,
value.release ());
277 gdb_assert_not_reached (
"invalid gdbpy_iter_kind");
294 catch (
const gdb_exception &except)
300 if (checked_type !=
type)
303 if (type_holder ==
nullptr)
305 py_type = type_holder.get ();
311 return PySequence_List (iter.get ());
332 if (
type->
code () != TYPE_CODE_ARRAY)
342 return Py_BuildValue (
"[O]", r.get ());
377 return PyUnicode_FromString (
name.c_str ());
379 return PyUnicode_FromString (
type->
name ());
387 const char *tagname =
nullptr;
389 if (
type->
code () == TYPE_CODE_STRUCT
394 if (tagname ==
nullptr)
396 return PyUnicode_FromString (tagname);
434 PyErr_SetString (PyExc_ValueError,
435 _(
"Type must be a scalar type"));
455 catch (
const gdb_exception &except)
476 catch (
const gdb_exception &except)
488 if (
type->
code () != TYPE_CODE_STRUCT
491 &&
type->
code () != TYPE_CODE_METHOD
494 PyErr_SetString (PyExc_TypeError,
495 "Type is not a structure, union, enum, or function type.");
509 struct type *array = NULL;
512 if (! PyArg_ParseTuple (args,
"l|O", &
n1, &n2_obj))
517 if (!PyLong_Check (n2_obj))
519 PyErr_SetString (PyExc_RuntimeError,
520 _(
"Array bound must be an integer"));
535 PyErr_SetString (PyExc_ValueError,
536 _(
"Array length must not be negative"));
546 catch (
const gdb_exception &except)
580 catch (
const gdb_exception &except)
596 LONGEST low = 0, high = 0;
598 if (
type->
code () != TYPE_CODE_ARRAY
599 &&
type->
code () != TYPE_CODE_STRING
600 &&
type->
code () != TYPE_CODE_RANGE)
602 PyErr_SetString (PyExc_RuntimeError,
603 _(
"This type does not have a range."));
609 case TYPE_CODE_ARRAY:
610 case TYPE_CODE_STRING:
611 case TYPE_CODE_RANGE:
625 if (low_bound == NULL)
629 if (high_bound == NULL)
636 if (PyTuple_SetItem (result.get (), 0, low_bound.release ()) != 0
637 || PyTuple_SetItem (result.get (), 1, high_bound.release ()) != 0)
639 return result.release ();
652 catch (
const gdb_exception &except)
668 PyErr_SetString (PyExc_RuntimeError,
669 _(
"Type does not have a target."));
686 catch (
const gdb_exception &except)
704 catch (
const gdb_exception &except)
722 catch (
const gdb_exception &except)
736 bool size_varies =
false;
743 catch (
const gdb_exception &except)
765 catch (
const gdb_exception &except)
786 catch (
const gdb_exception &except)
803 if (startswith (type_name,
"struct "))
805 else if (startswith (type_name,
"union "))
807 else if (startswith (type_name,
"enum "))
811 type_name,
block, 0);
813 catch (
const gdb_exception &except)
826 enum demangle_component_type demangled_type;
830 demangled_type = demangled->type;
832 if (demangled_type == DEMANGLE_COMPONENT_POINTER
833 || demangled_type == DEMANGLE_COMPONENT_REFERENCE
834 || demangled_type == DEMANGLE_COMPONENT_RVALUE_REFERENCE
835 || demangled_type == DEMANGLE_COMPONENT_CONST
836 || demangled_type == DEMANGLE_COMPONENT_VOLATILE)
848 switch (demangled_type)
850 case DEMANGLE_COMPONENT_REFERENCE:
853 case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
856 case DEMANGLE_COMPONENT_POINTER:
859 case DEMANGLE_COMPONENT_CONST:
862 case DEMANGLE_COMPONENT_VOLATILE:
867 catch (
const gdb_exception &except)
893 struct demangle_component *demangled;
894 std::unique_ptr<demangle_parse_info> info;
896 struct type *argtype;
900 PyErr_SetString (PyExc_RuntimeError, _(
"Null type name."));
909 catch (
const gdb_exception &except)
916 PyErr_SetString (PyExc_RuntimeError,
err.c_str ());
919 demangled = info->tree;
922 while (demangled->type == DEMANGLE_COMPONENT_QUAL_NAME
923 || demangled->type == DEMANGLE_COMPONENT_LOCAL_NAME)
924 demangled = demangled->u.s_binary.right;
926 if (demangled->type != DEMANGLE_COMPONENT_TEMPLATE)
928 PyErr_SetString (PyExc_RuntimeError, _(
"Type is not a template."));
933 demangled = demangled->u.s_binary.right;
935 for (i = 0; demangled && i < argno; ++i)
936 demangled = demangled->u.s_binary.right;
940 PyErr_Format (PyExc_RuntimeError, _(
"No argument %d in template."),
960 struct value *val = NULL;
962 if (! PyArg_ParseTuple (args,
"i|O", &argno, &block_obj))
967 PyErr_SetString (PyExc_RuntimeError,
968 _(
"Template argument number must be non-negative"));
977 PyErr_SetString (PyExc_RuntimeError,
978 _(
"Second argument must be block."));
989 catch (
const gdb_exception &except)
1002 PyErr_Format (PyExc_RuntimeError, _(
"No argument %d in template."),
1012 PyErr_Format (PyExc_RuntimeError,
1013 _(
"Template argument is optimized out"));
1021 catch (
const gdb_exception &except)
1040 catch (
const gdb_exception &except)
1045 return PyUnicode_Decode (thetype.
c_str (), thetype.
size (),
1054 bool result =
false;
1060 if (type2 == NULL || (op != Py_EQ && op != Py_NE))
1062 Py_INCREF (Py_NotImplemented);
1063 return Py_NotImplemented;
1074 catch (
const gdb_exception &except)
1082 if (op == (result ? Py_EQ : Py_NE))
1107 htab_empty (copied_types.get ());
1219 if (t_field_name && (
strcmp_iw (t_field_name,
field.get ()) == 0))
1222 PyErr_SetObject (PyExc_KeyError, key);
1233 PyObject *key, *defval = Py_None, *result;
1235 if (!PyArg_UnpackTuple (args,
"get", 1, 2, &key, &defval))
1245 if (!PyErr_ExceptionMatches (PyExc_KeyError))
1262 if (!PyArg_ParseTuple (args,
"s", &
field))
1296 if (typy_iter_obj == NULL)
1299 typy_iter_obj->
field = 0;
1300 typy_iter_obj->
kind = kind;
1364 return result.release ();
1375 Py_DECREF (iter_obj->
source);
1376 Py_TYPE (obj)->tp_free (obj);
1417 static const char *keywords[] = {
"name",
"block", NULL };
1418 const char *type_name = NULL;
1424 &type_name, &block_obj))
1432 PyErr_SetString (PyExc_RuntimeError,
1433 _(
"'block' argument must be a Block."));
1457 if (PyModule_AddIntConstant (
gdb_module, item.name, item.code) < 0)
1478 "The alignment of this type, in bytes.", NULL },
1480 "The code for this type.", NULL },
1482 "Whether this type is dynamic.", NULL },
1484 "The name for this type, or None.", NULL },
1486 "The size of this type, in bytes.", NULL },
1488 "The tag name for this type, or None.", NULL },
1490 "The objfile this type was defined in, or None.", NULL },
1492 "Is this a scalar type?",
nullptr },
1494 "Is this an signed type?",
nullptr },
1501 "array ([LOW_BOUND,] HIGH_BOUND) -> Type\n\
1502Return a type which represents an array of objects of this type.\n\
1503The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
1504If LOW_BOUND is omitted, a value of zero is used." },
1506 "vector ([LOW_BOUND,] HIGH_BOUND) -> Type\n\
1507Return a type which represents a vector of objects of this type.\n\
1508The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
1509If LOW_BOUND is omitted, a value of zero is used.\n\
1510Vectors differ from arrays in that if the current language has C-style\n\
1511arrays, vectors don't decay to a pointer to the first element.\n\
1512They are first class values." },
1514 "T.__contains__(k) -> True if T has a field named k, else False" },
1516 "const () -> Type\n\
1517Return a const variant of this type." },
1519 "optimized_out() -> Value\n\
1520Return optimized out value of this type." },
1522 "fields () -> list\n\
1523Return a list holding all the fields of this type.\n\
1524Each field is a gdb.Field object." },
1526 "T.get(k[,default]) -> returns field named k in T, if it exists;\n\
1527otherwise returns default, if supplied, or None if not." },
1529 "T.has_key(k) -> True if T has a field named k, else False" },
1531 "items () -> list\n\
1532Return a list of (name, field) pairs of this type.\n\
1533Each field is a gdb.Field object." },
1535 "iteritems () -> an iterator over the (name, field)\n\
1536pairs of this type. Each field is a gdb.Field object." },
1538 "iterkeys () -> an iterator over the field names of this type." },
1540 "itervalues () -> an iterator over the fields of this type.\n\
1541Each field is a gdb.Field object." },
1544Return a list holding all the fields names of this type." },
1546 "pointer () -> Type\n\
1547Return a type of pointer to this type." },
1549 "range () -> tuple\n\
1550Return a tuple containing the lower and upper range for this type."},
1552 "reference () -> Type\n\
1553Return a type of reference to this type." },
1555 "strip_typedefs () -> Type\n\
1556Return a type formed by stripping this type of all typedefs."},
1558 "target () -> Type\n\
1559Return the target type of this type." },
1561 "template_argument (arg, [block]) -> Type\n\
1562Return the type of a template argument." },
1564 "unqualified () -> Type\n\
1565Return a variant of this type without const or volatile attributes." },
1567 "values () -> list\n\
1568Return a list holding all the fields of this type.\n\
1569Each field is a gdb.Field object." },
1571 "volatile () -> Type\n\
1572Return a volatile variant of this type" },
1606 PyVarObject_HEAD_INIT (NULL, 0)
1655 PyVarObject_HEAD_INIT (NULL, 0)
1696 PyVarObject_HEAD_INIT (NULL, 0)
1716 "GDB type iterator object",
std::string ada_decode(const char *encoded, bool wrap, bool operators)
const char * host_charset(void)
void set(unsigned key, void *datum)
const char * c_str() const
struct std::unique_ptr< demangle_parse_info > cp_demangled_name_to_comp(const char *demangled_name, std::string *errmsg)
gdb::unique_xmalloc_ptr< char > cp_comp_to_string(struct demangle_component *result, int estimated_len)
struct type * copy_type_recursive(struct type *type, htab_t copied_types)
struct type * lookup_pointer_type(struct type *type)
struct type * lookup_enum(const char *name, const struct block *block)
struct type * lookup_lvalue_reference_type(struct type *type)
struct type * lookup_typename(const struct language_defn *language, const char *name, const struct block *block, int noerr)
htab_up create_copied_types_hash()
int field_is_static(struct field *f)
int is_scalar_type(struct type *type)
int is_dynamic_type(struct type *type)
struct type * lookup_array_range_type(struct type *element_type, LONGEST low_bound, LONGEST high_bound)
struct type * make_cv_type(int cnst, int voltl, struct type *type, struct type **typeptr)
struct type * lookup_rvalue_reference_type(struct type *type)
unsigned type_align(struct type *type)
bool types_deeply_equal(struct type *type1, struct type *type2)
struct type * lookup_struct(const char *name, const struct block *block)
struct type * lookup_union(const char *name, const struct block *block)
struct type * check_typedef(struct type *type)
void make_vector_type(struct type *array_type)
#define TYPE_IS_REFERENCE(t)
@ FIELD_LOC_KIND_DWARF_BLOCK
#define TYPE_HAS_DYNAMIC_LENGTH(t)
#define TYPE_N_TEMPLATE_ARGUMENTS(thistype)
#define TYPE_FIELD_ARTIFICIAL(thistype, n)
#define TYPE_TEMPLATE_ARGUMENT(thistype, n)
#define TYPE_FIELD_BITSIZE(thistype, n)
#define TYPE_N_BASECLASSES(thistype)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
const struct language_defn * current_language
const struct block * block_object_to_block(PyObject *obj)
gdbpy_ref objfile_to_objfile_object(struct objfile *objfile)
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
static PyObject * typy_getitem(PyObject *self, PyObject *key)
static PyObject * typy_pointer(PyObject *self, PyObject *args)
PyObject * type_to_type_object(struct type *type)
static void typy_dealloc(PyObject *obj)
static PyMappingMethods typy_mapping
static PyObject * typy_iteritems(PyObject *self, PyObject *args)
static PyObject * typy_get_code(PyObject *self, void *closure)
static struct pyty_code pyty_codes[]
static PyObject * typy_make_iter(PyObject *self, enum gdbpy_iter_kind kind)
static PyObject * field_new(void)
static PyObject * typy_template_argument(PyObject *self, PyObject *args)
int gdbpy_initialize_types(void)
static PyObject * typy_target(PyObject *self, PyObject *args)
static void typy_iterator_dealloc(PyObject *obj)
static int typy_nonzero(PyObject *self)
static struct type * typy_get_composite(struct type *type)
static PyObject * typy_items(PyObject *self, PyObject *args)
static PyObject * typy_optimized_out(PyObject *self, PyObject *args)
static gdb_PyGetSetDef type_object_getset[]
static PyObject * typy_get_tag(PyObject *self, void *closure)
PyTypeObject field_object_type
static PyObject * typy_get_sizeof(PyObject *self, void *closure)
static PyObject * typy_vector(PyObject *self, PyObject *args)
static PyObject * typy_iterator_iter(PyObject *self)
static PyObject * typy_reference(PyObject *self, PyObject *args)
static PyObject * typy_unqualified(PyObject *self, PyObject *args)
static PyObject * typy_get_name(PyObject *self, void *closure)
static gdbpy_ref field_name(struct type *type, int field)
static PyObject * typy_iterkeys(PyObject *self, PyObject *args)
static PyObject * typy_volatile(PyObject *self, PyObject *args)
static Py_ssize_t typy_length(PyObject *self)
static PyObject * typy_array_1(PyObject *self, PyObject *args, int is_vector)
static PyObject * typy_get_objfile(PyObject *self, void *closure)
static PyObject * typy_get_dynamic(PyObject *self, void *closure)
static gdbpy_ref make_fielditem(struct type *type, int i, enum gdbpy_iter_kind kind)
static PyObject * typy_iter(PyObject *self)
static PyObject * typy_richcompare(PyObject *self, PyObject *other, int op)
static PyObject * typy_fields(PyObject *self, PyObject *args)
static PyObject * typy_str(PyObject *self)
static struct type * typy_lookup_type(struct demangle_component *demangled, const struct block *block)
static void set_type(type_object *obj, struct type *type)
static PyObject * typy_is_signed(PyObject *self, void *closure)
static PyObject * typy_get(PyObject *self, PyObject *args)
static PyObject * typy_iterator_iternext(PyObject *self)
static PyObject * typy_legacy_template_argument(struct type *type, const struct block *block, int argno)
int gdbpy_is_field(PyObject *obj)
static PyObject * typy_is_scalar(PyObject *self, void *closure)
PyTypeObject type_object_type
static PyObject * typy_range(PyObject *self, PyObject *args)
static PyObject * typy_const(PyObject *self, PyObject *args)
static PyObject * typy_strip_typedefs(PyObject *self, PyObject *args)
PyTypeObject type_iterator_object_type
static struct type * typy_lookup_typename(const char *type_name, const struct block *block)
static PyObject * typy_fields_items(PyObject *self, enum gdbpy_iter_kind kind)
static void field_dealloc(PyObject *obj)
static PyObject * typy_values(PyObject *self, PyObject *args)
static PyObject * typy_itervalues(PyObject *self, PyObject *args)
static PyObject * typy_get_alignof(PyObject *self, void *closure)
static PyMethodDef type_object_methods[]
static const registry< objfile >::key< type_object, typy_deleter > typy_objfile_data_key
static gdb_PyGetSetDef field_object_getset[]
struct type * type_object_to_type(PyObject *obj)
static gdbpy_ref convert_field(struct type *type, int field)
static PyObject * typy_array(PyObject *self, PyObject *args)
PyObject * gdbpy_lookup_type(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * typy_field_names(PyObject *self, PyObject *args)
static PyObject * typy_has_key(PyObject *self, PyObject *args)
static PyNumberMethods type_object_as_number
gdbpy_ref gdb_py_object_from_longest(LONGEST l)
int gdb_py_int_as_long(PyObject *obj, long *result)
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
PyObject * gdb_py_generic_dict(PyObject *self, void *closure)
gdbpy_ref gdb_py_object_from_ulongest(ULONGEST l)
PyObject * value_to_value_object(struct value *val)
int gdb_python_initialized
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
#define GDB_PY_HANDLE_EXCEPTION(Exception)
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
LONGEST const_val() const
dynamic_prop_kind kind() const
PyObject_HEAD PyObject * dict
LONGEST loc_bitpos() const
field_loc_kind loc_kind() const
LONGEST loc_enumval() const
const char * name() const
struct type * type() const
virtual void print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const =0
address_class aclass() const
struct type * type() const
PyObject_HEAD struct type * type
struct type_object * prev
struct type_object * next
struct type * target_type() const
struct field & field(int idx) const
struct objfile * objfile_owner() const
bool is_pointer_or_reference() const
range_bounds * bounds() const
const char * name() const
void operator()(type_object *obj)
enum gdbpy_iter_kind kind
const struct type_print_options type_print_raw_options
int strcmp_iw(const char *string1, const char *string2)
struct value * value_of_variable(struct symbol *var, const struct block *b)
struct value * allocate_optimized_out_value(struct type *type)