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"));
458 catch (
const gdb_exception &except)
482 catch (
const gdb_exception &except)
503 catch (
const gdb_exception &except)
524 catch (
const gdb_exception &except)
536 if (
type->
code () != TYPE_CODE_STRUCT
539 &&
type->
code () != TYPE_CODE_METHOD
542 PyErr_SetString (PyExc_TypeError,
543 "Type is not a structure, union, enum, or function type.");
557 struct type *array = NULL;
560 if (! PyArg_ParseTuple (args,
"l|O", &
n1, &n2_obj))
565 if (!PyLong_Check (n2_obj))
567 PyErr_SetString (PyExc_RuntimeError,
568 _(
"Array bound must be an integer"));
583 PyErr_SetString (PyExc_ValueError,
584 _(
"Array length must not be negative"));
594 catch (
const gdb_exception &except)
628 catch (
const gdb_exception &except)
644 LONGEST low = 0, high = 0;
646 if (
type->
code () != TYPE_CODE_ARRAY
647 &&
type->
code () != TYPE_CODE_STRING
648 &&
type->
code () != TYPE_CODE_RANGE)
650 PyErr_SetString (PyExc_RuntimeError,
651 _(
"This type does not have a range."));
657 case TYPE_CODE_ARRAY:
658 case TYPE_CODE_STRING:
659 case TYPE_CODE_RANGE:
673 if (low_bound == NULL)
677 if (high_bound == NULL)
684 if (PyTuple_SetItem (result.get (), 0, low_bound.release ()) != 0
685 || PyTuple_SetItem (result.get (), 1, high_bound.release ()) != 0)
687 return result.release ();
700 catch (
const gdb_exception &except)
716 PyErr_SetString (PyExc_RuntimeError,
717 _(
"Type does not have a target."));
734 catch (
const gdb_exception &except)
752 catch (
const gdb_exception &except)
770 catch (
const gdb_exception &except)
784 bool size_varies =
false;
791 catch (
const gdb_exception &except)
813 catch (
const gdb_exception &except)
834 catch (
const gdb_exception &except)
851 if (startswith (type_name,
"struct "))
853 else if (startswith (type_name,
"union "))
855 else if (startswith (type_name,
"enum "))
859 type_name,
block, 0);
861 catch (
const gdb_exception &except)
874 enum demangle_component_type demangled_type;
878 demangled_type = demangled->type;
880 if (demangled_type == DEMANGLE_COMPONENT_POINTER
881 || demangled_type == DEMANGLE_COMPONENT_REFERENCE
882 || demangled_type == DEMANGLE_COMPONENT_RVALUE_REFERENCE
883 || demangled_type == DEMANGLE_COMPONENT_CONST
884 || demangled_type == DEMANGLE_COMPONENT_VOLATILE)
896 switch (demangled_type)
898 case DEMANGLE_COMPONENT_REFERENCE:
901 case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
904 case DEMANGLE_COMPONENT_POINTER:
907 case DEMANGLE_COMPONENT_CONST:
910 case DEMANGLE_COMPONENT_VOLATILE:
915 catch (
const gdb_exception &except)
941 struct demangle_component *demangled;
942 std::unique_ptr<demangle_parse_info> info;
944 struct type *argtype;
948 PyErr_SetString (PyExc_RuntimeError, _(
"Null type name."));
957 catch (
const gdb_exception &except)
964 PyErr_SetString (PyExc_RuntimeError,
err.c_str ());
967 demangled = info->tree;
970 while (demangled->type == DEMANGLE_COMPONENT_QUAL_NAME
971 || demangled->type == DEMANGLE_COMPONENT_LOCAL_NAME)
972 demangled = demangled->u.s_binary.right;
974 if (demangled->type != DEMANGLE_COMPONENT_TEMPLATE)
976 PyErr_SetString (PyExc_RuntimeError, _(
"Type is not a template."));
981 demangled = demangled->u.s_binary.right;
983 for (i = 0; demangled && i < argno; ++i)
984 demangled = demangled->u.s_binary.right;
988 PyErr_Format (PyExc_RuntimeError, _(
"No argument %d in template."),
1009 if (! PyArg_ParseTuple (args,
"i|O", &argno, &block_obj))
1014 PyErr_SetString (PyExc_RuntimeError,
1015 _(
"Template argument number must be non-negative"));
1024 PyErr_SetString (PyExc_RuntimeError,
1025 _(
"Second argument must be block."));
1036 catch (
const gdb_exception &except)
1049 PyErr_Format (PyExc_RuntimeError, _(
"No argument %d in template."),
1059 PyErr_Format (PyExc_RuntimeError,
1060 _(
"Template argument is optimized out"));
1071 catch (
const gdb_exception &except)
1085 if (
type ==
nullptr)
1086 return PyUnicode_FromFormat (
"<%s (invalid)>",
1087 Py_TYPE (self)->tp_name);
1096 catch (
const gdb_exception &except)
1100 auto py_typename = PyUnicode_Decode (type_name.
c_str (), type_name.
size (),
1103 return PyUnicode_FromFormat (
"<%s code=%s name=%U>", Py_TYPE (self)->tp_name,
1118 catch (
const gdb_exception &except)
1123 return PyUnicode_Decode (thetype.
c_str (), thetype.
size (),
1132 bool result =
false;
1138 if (type2 == NULL || (op != Py_EQ && op != Py_NE))
1140 Py_INCREF (Py_NotImplemented);
1141 return Py_NotImplemented;
1152 catch (
const gdb_exception &except)
1160 if (op == (result ? Py_EQ : Py_NE))
1185 htab_empty (copied_types.get ());
1298 if (t_field_name && (
strcmp_iw (t_field_name,
field.get ()) == 0))
1301 PyErr_SetObject (PyExc_KeyError, key);
1312 PyObject *key, *defval = Py_None, *result;
1314 if (!PyArg_UnpackTuple (args,
"get", 1, 2, &key, &defval))
1324 if (!PyErr_ExceptionMatches (PyExc_KeyError))
1341 if (!PyArg_ParseTuple (args,
"s", &
field))
1375 if (typy_iter_obj == NULL)
1378 typy_iter_obj->
field = 0;
1379 typy_iter_obj->
kind = kind;
1443 return result.release ();
1454 Py_DECREF (iter_obj->
source);
1455 Py_TYPE (obj)->tp_free (obj);
1496 static const char *keywords[] = {
"name",
"block", NULL };
1497 const char *type_name = NULL;
1503 &type_name, &block_obj))
1511 PyErr_SetString (PyExc_RuntimeError,
1512 _(
"'block' argument must be a Block."));
1536 if (PyModule_AddIntConstant (
gdb_module, item.name, item.code) < 0)
1559 "The alignment of this type, in bytes.", NULL },
1561 "The code for this type.", NULL },
1563 "Whether this type is dynamic.", NULL },
1565 "The name for this type, or None.", NULL },
1567 "The size of this type, in bytes.", NULL },
1569 "The tag name for this type, or None.", NULL },
1571 "The objfile this type was defined in, or None.", NULL },
1573 "Is this a scalar type?",
nullptr },
1575 "Is this a signed type?",
nullptr },
1577 "Is this an array-like type?",
nullptr },
1579 "Is this a string-like type?",
nullptr },
1586 "array ([LOW_BOUND,] HIGH_BOUND) -> Type\n\
1587Return a type which represents an array of objects of this type.\n\
1588The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
1589If LOW_BOUND is omitted, a value of zero is used." },
1591 "vector ([LOW_BOUND,] HIGH_BOUND) -> Type\n\
1592Return a type which represents a vector of objects of this type.\n\
1593The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
1594If LOW_BOUND is omitted, a value of zero is used.\n\
1595Vectors differ from arrays in that if the current language has C-style\n\
1596arrays, vectors don't decay to a pointer to the first element.\n\
1597They are first class values." },
1599 "T.__contains__(k) -> True if T has a field named k, else False" },
1601 "const () -> Type\n\
1602Return a const variant of this type." },
1604 "optimized_out() -> Value\n\
1605Return optimized out value of this type." },
1607 "fields () -> list\n\
1608Return a list holding all the fields of this type.\n\
1609Each field is a gdb.Field object." },
1611 "T.get(k[,default]) -> returns field named k in T, if it exists;\n\
1612otherwise returns default, if supplied, or None if not." },
1614 "T.has_key(k) -> True if T has a field named k, else False" },
1616 "items () -> list\n\
1617Return a list of (name, field) pairs of this type.\n\
1618Each field is a gdb.Field object." },
1620 "iteritems () -> an iterator over the (name, field)\n\
1621pairs of this type. Each field is a gdb.Field object." },
1623 "iterkeys () -> an iterator over the field names of this type." },
1625 "itervalues () -> an iterator over the fields of this type.\n\
1626Each field is a gdb.Field object." },
1629Return a list holding all the fields names of this type." },
1631 "pointer () -> Type\n\
1632Return a type of pointer to this type." },
1634 "range () -> tuple\n\
1635Return a tuple containing the lower and upper range for this type."},
1637 "reference () -> Type\n\
1638Return a type of reference to this type." },
1640 "strip_typedefs () -> Type\n\
1641Return a type formed by stripping this type of all typedefs."},
1643 "target () -> Type\n\
1644Return the target type of this type." },
1646 "template_argument (arg, [block]) -> Type\n\
1647Return the type of a template argument." },
1649 "unqualified () -> Type\n\
1650Return a variant of this type without const or volatile attributes." },
1652 "values () -> list\n\
1653Return a list holding all the fields of this type.\n\
1654Each field is a gdb.Field object." },
1656 "volatile () -> Type\n\
1657Return a volatile variant of this type" },
1691 PyVarObject_HEAD_INIT (NULL, 0)
1740 PyVarObject_HEAD_INIT (NULL, 0)
1781 PyVarObject_HEAD_INIT (NULL, 0)
1801 "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 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_TEMPLATE_ARGUMENT(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)
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_is_array_like(PyObject *self, void *closure)
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)
static PyObject * typy_is_string_like(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_repr(PyObject *self)
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 int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_types(void)
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 CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#define GDBPY_INITIALIZE_FILE(INIT,...)
#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
PyObject_HEAD PyObject * dict
LONGEST loc_bitpos() const
bool is_artificial() const
field_loc_kind loc_kind() const
LONGEST loc_enumval() const
const char * name() const
unsigned int bitsize() 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
unsigned int num_fields() 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
static struct value * allocate_optimized_out(struct type *type)
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)