56 extern PyTypeObject field_object_type
70 extern PyTypeObject type_iterator_object_type
85 #define ENTRY(X) { X, #X }
125 Py_XDECREF (f->
dict);
136 result->
dict = PyDict_New ();
143 return (PyObject *) result;
153 return PyObject_TypeCheck (obj, &field_object_type);
162 return PyInt_FromLong (
TYPE_CODE (type));
180 if (PyObject_SetAttrString (result,
"parent_type", arg) < 0)
186 const char *attrstring;
191 attrstring =
"enumval";
196 attrstring =
"bitpos";
203 if (PyObject_SetAttrString (result, (
char *) attrstring, arg) < 0)
213 if (field_name[0] !=
'\0')
225 if (PyObject_SetAttrString (result,
"name", arg) < 0)
231 if (PyObject_SetAttrString (result,
"artificial", arg) < 0)
240 if (PyObject_SetAttrString (result,
"is_base_class", arg) < 0)
247 if (PyObject_SetAttrString (result,
"bitsize", arg) < 0)
261 if (PyObject_SetAttrString (result,
"type", arg) < 0)
301 PyObject *item = NULL, *key = NULL, *
value = NULL;
312 item = PyTuple_New (2);
315 PyTuple_SET_ITEM (item, 0, key);
316 PyTuple_SET_ITEM (item, 1, value);
342 PyObject *py_type =
self;
343 PyObject *result = NULL, *iter = NULL;
345 struct type *checked_type =
type;
357 if (checked_type != type)
360 if (checked_type != type)
368 result = PySequence_List (iter);
404 rl = Py_BuildValue (
"[O]", r);
436 return PyString_FromString (
TYPE_NAME (type));
500 PyErr_SetString (PyExc_TypeError,
501 "Type is not a structure, union, or enum type.");
514 PyObject *n2_obj = NULL;
515 struct type *array = NULL;
518 if (! PyArg_ParseTuple (args,
"l|O", &n1, &n2_obj))
523 if (!PyInt_Check (n2_obj))
525 PyErr_SetString (PyExc_RuntimeError,
526 _(
"Array bound must be an integer"));
541 PyErr_SetString (PyExc_ValueError,
542 _(
"Array length must not be negative"));
604 PyObject *low_bound = NULL, *high_bound = NULL;
612 PyErr_SetString (PyExc_RuntimeError,
613 _(
"This type does not have a range."));
630 low_bound = PyLong_FromLong (low);
634 high_bound = PyLong_FromLong (high);
638 result = PyTuple_New (2);
642 if (PyTuple_SetItem (result, 0, low_bound) != 0)
647 if (PyTuple_SetItem (result, 1, high_bound) != 0)
656 Py_XDECREF (high_bound);
657 Py_XDECREF (low_bound);
688 PyErr_SetString (PyExc_RuntimeError,
689 _(
"Type does not have a target."));
788 type_name, block, 0);
804 char *type_name = NULL;
805 enum demangle_component_type demangled_type;
809 demangled_type = demangled->type;
811 if (demangled_type == DEMANGLE_COMPONENT_POINTER
812 || demangled_type == DEMANGLE_COMPONENT_REFERENCE
813 || demangled_type == DEMANGLE_COMPONENT_CONST
814 || demangled_type == DEMANGLE_COMPONENT_VOLATILE)
826 switch (demangled_type)
828 case DEMANGLE_COMPONENT_REFERENCE:
831 case DEMANGLE_COMPONENT_POINTER:
834 case DEMANGLE_COMPONENT_CONST:
837 case DEMANGLE_COMPONENT_VOLATILE:
872 struct demangle_component *demangled;
875 struct type *argtype;
880 PyErr_SetString (PyExc_RuntimeError,
_(
"Null type name."));
897 PyErr_SetString (PyExc_RuntimeError, err);
900 demangled = info->
tree;
904 while (demangled->type == DEMANGLE_COMPONENT_QUAL_NAME
905 || demangled->type == DEMANGLE_COMPONENT_LOCAL_NAME)
906 demangled = demangled->u.s_binary.right;
908 if (demangled->type != DEMANGLE_COMPONENT_TEMPLATE)
911 PyErr_SetString (PyExc_RuntimeError,
_(
"Type is not a template."));
916 demangled = demangled->u.s_binary.right;
918 for (i = 0; demangled && i < argno; ++i)
919 demangled = demangled->u.s_binary.right;
924 PyErr_Format (PyExc_RuntimeError,
_(
"No argument %d in template."),
943 PyObject *block_obj = NULL;
945 struct value *val = NULL;
947 if (! PyArg_ParseTuple (args,
"i|O", &argno, &block_obj))
955 PyErr_SetString (PyExc_RuntimeError,
956 _(
"Second argument must be block."));
981 PyErr_Format (PyExc_RuntimeError,
_(
"No argument %d in template."),
991 PyErr_Format (PyExc_RuntimeError,
992 _(
"Template argument is optimized out"));
1012 char *thetype = NULL;
1037 result = PyUnicode_Decode (thetype, length,
host_charset (), NULL);
1054 if (type2 == NULL || (op != Py_EQ && op != Py_NE))
1056 Py_INCREF (Py_NotImplemented);
1057 return Py_NotImplemented;
1077 if (op == (result ? Py_EQ : Py_NE))
1090 htab_t copied_types;
1106 htab_empty (copied_types);
1116 htab_delete (copied_types);
1130 obj->
next = objfile_data (objfile, typy_objfile_data_key);
1133 set_objfile_data (objfile, typy_objfile_data_key, obj);
1152 set_objfile_data (objfile, typy_objfile_data_key, type->
next);
1157 Py_TYPE (type)->tp_free (type);
1219 if (t_field_name && (
strcmp_iw (t_field_name, field) == 0))
1224 PyErr_SetObject (PyExc_KeyError, key);
1235 PyObject *key, *defval = Py_None, *result;
1237 if (!PyArg_UnpackTuple (args,
"get", 1, 2, &key, &defval))
1247 if (!PyErr_ExceptionMatches (PyExc_KeyError))
1264 if (!PyArg_ParseTuple (args,
"s", &field))
1279 if (t_field_name && (
strcmp_iw (t_field_name, field) == 0))
1297 &type_iterator_object_type);
1298 if (typy_iter_obj == NULL)
1301 typy_iter_obj->
field = 0;
1302 typy_iter_obj->
kind = kind;
1306 return (PyObject *) typy_iter_obj;
1390 return (PyObject *) type_obj;
1407 static char *keywords[] = {
"name",
"block", NULL };
1408 const char *type_name = NULL;
1410 PyObject *block_obj = NULL;
1413 if (! PyArg_ParseTupleAndKeywords (args, kw,
"s|O", keywords,
1414 &type_name, &block_obj))
1422 PyErr_SetString (PyExc_RuntimeError,
1423 _(
"'block' argument must be a Block."));
1440 typy_objfile_data_key
1445 if (PyType_Ready (&field_object_type) < 0)
1447 if (PyType_Ready (&type_iterator_object_type) < 0)
1450 for (i = 0; pyty_codes[i].
name; ++i)
1454 (
char *) pyty_codes[i].
name,
1455 pyty_codes[i].
code) < 0)
1464 (PyObject *) &type_iterator_object_type) < 0)
1468 (PyObject *) &field_object_type);
1476 "The code for this type.", NULL },
1478 "The name for this type, or None.", NULL },
1480 "The size of this type, in bytes.", NULL },
1482 "The tag name for this type, or None.", NULL },
1489 "array ([LOW_BOUND,] HIGH_BOUND) -> Type\n\
1490 Return a type which represents an array of objects of this type.\n\
1491 The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
1492 If LOW_BOUND is omitted, a value of zero is used." },
1494 "vector ([LOW_BOUND,] HIGH_BOUND) -> Type\n\
1495 Return a type which represents a vector of objects of this type.\n\
1496 The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
1497 If LOW_BOUND is omitted, a value of zero is used.\n\
1498 Vectors differ from arrays in that if the current language has C-style\n\
1499 arrays, vectors don't decay to a pointer to the first element.\n\
1500 They are first class values." },
1502 "T.__contains__(k) -> True if T has a field named k, else False" },
1504 "const () -> Type\n\
1505 Return a const variant of this type." },
1507 "optimized_out() -> Value\n\
1508 Return optimized out value of this type." },
1510 "fields () -> list\n\
1511 Return a list holding all the fields of this type.\n\
1512 Each field is a gdb.Field object." },
1514 "T.get(k[,default]) -> returns field named k in T, if it exists;\n\
1515 otherwise returns default, if supplied, or None if not." },
1517 "T.has_key(k) -> True if T has a field named k, else False" },
1519 "items () -> list\n\
1520 Return a list of (name, field) pairs of this type.\n\
1521 Each field is a gdb.Field object." },
1523 "iteritems () -> an iterator over the (name, field)\n\
1524 pairs of this type. Each field is a gdb.Field object." },
1526 "iterkeys () -> an iterator over the field names of this type." },
1528 "itervalues () -> an iterator over the fields of this type.\n\
1529 Each field is a gdb.Field object." },
1532 Return a list holding all the fields names of this type." },
1534 "pointer () -> Type\n\
1535 Return a type of pointer to this type." },
1537 "range () -> tuple\n\
1538 Return a tuple containing the lower and upper range for this type."},
1540 "reference () -> Type\n\
1541 Return a type of reference to this type." },
1543 "strip_typedefs () -> Type\n\
1544 Return a type formed by stripping this type of all typedefs."},
1546 "target () -> Type\n\
1547 Return the target type of this type." },
1549 "template_argument (arg, [block]) -> Type\n\
1550 Return the type of a template argument." },
1552 "unqualified () -> Type\n\
1553 Return a variant of this type without const or volatile attributes." },
1555 "values () -> list\n\
1556 Return a list holding all the fields of this type.\n\
1557 Each field is a gdb.Field object." },
1559 "volatile () -> Type\n\
1560 Return a volatile variant of this type" },
1617 &type_object_as_number,
1626 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
1634 type_object_methods,
1647 static PyGetSetDef field_object_getset[] =
1650 "The __dict__ for this field.", &field_object_type },
1654 PyTypeObject field_object_type =
1675 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
1685 field_object_getset,
1696 PyTypeObject type_iterator_object_type = {
1716 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
1717 "GDB type iterator object",
PyTypeObject type_object_type
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
struct type * lookup_array_range_type(struct type *element_type, LONGEST low_bound, LONGEST high_bound)
PyObject * gdb_py_generic_dict(PyObject *self, void *closure)
static PyObject * typy_volatile(PyObject *self, PyObject *args)
static PyObject * typy_fields(PyObject *self, PyObject *args)
#define TYPE_FIELD_NAME(thistype, n)
#define TYPE_N_BASECLASSES(thistype)
#define TYPE_LOW_BOUND(range_type)
static PyObject * typy_str(PyObject *self)
int strcmp_iw(const char *string1, const char *string2)
struct type * type_object_to_type(PyObject *obj)
#define TYPE_NAME(thistype)
#define TYPE_FIELD_ARTIFICIAL(thistype, n)
char * ui_file_xstrdup(struct ui_file *file, long *length)
#define TYPE_HIGH_BOUND(range_type)
static PyObject * typy_const(PyObject *self, PyObject *args)
const struct type_print_options type_print_raw_options
struct pyty_type_object type_object
static PyObject * convert_field(struct type *type, int field)
#define SYMBOL_CLASS(symbol)
static PyObject * typy_unqualified(PyObject *self, PyObject *args)
struct demangle_component * tree
int gdbpy_is_field(PyObject *obj)
static Py_ssize_t typy_length(PyObject *self)
static PyObject * typy_fields_items(PyObject *self, enum gdbpy_iter_kind kind)
struct cleanup * make_cleanup_cp_demangled_name_parse_free(struct demangle_parse_info *info)
PyTypeObject type_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("type_object")
#define TYPE_FIELD(thistype, n)
PyObject * gdbpy_lookup_type(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * field_new(void)
static void typy_dealloc(PyObject *obj)
#define TYPE_FIELD_ENUMVAL(thistype, n)
#define TYPE_FIELD_TYPE(thistype, n)
struct demangle_info * info
static struct type * typy_get_composite(struct type *type)
#define GDB_PY_HANDLE_EXCEPTION(Exception)
static PyObject * typy_range(PyObject *self, PyObject *args)
#define TYPE_N_TEMPLATE_ARGUMENTS(thistype)
int types_deeply_equal(struct type *type1, struct type *type2)
static void set_type(type_object *obj, struct type *type)
struct type * lookup_typename(const struct language_defn *language, struct gdbarch *gdbarch, const char *name, const struct block *block, int noerr)
static PyObject * typy_array_1(PyObject *self, PyObject *args, int is_vector)
static PyObject * typy_make_iter(PyObject *self, enum gdbpy_iter_kind kind)
static PyObject * typy_iter(PyObject *self)
static void typy_iterator_dealloc(PyObject *obj)
struct type * check_typedef(struct type *type)
#define CATCH(EXCEPTION, MASK)
static PyObject * typy_items(PyObject *self, PyObject *args)
PyObject_HEAD PyObject * dict
static PyObject * typy_get_name(PyObject *self, void *closure)
int field_is_static(struct field *f)
struct type * lookup_struct(const char *name, const struct block *block)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t err
#define gdb_assert_not_reached(message)
static struct type * typy_lookup_typename(const char *type_name, const struct block *block)
static PyObject * typy_has_key(PyObject *self, PyObject *args)
struct type * lookup_enum(const char *name, const struct block *block)
struct type * copy_type_recursive(struct objfile *objfile, struct type *type, htab_t copied_types)
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
char * python_string_to_host_string(PyObject *obj)
struct demangle_parse_info * cp_demangled_name_to_comp(const char *demangled_name, const char **errmsg)
static int typy_nonzero(PyObject *self)
const struct block * block_object_to_block(PyObject *obj)
static void save_objfile_types(struct objfile *objfile, void *datum)
static PyObject * typy_strip_typedefs(PyObject *self, PyObject *args)
struct gdbarch * python_gdbarch
struct cleanup * ensure_python_env(struct gdbarch *gdbarch, const struct language_defn *language)
struct pyty_type_object * source
static PyObject * typy_target(PyObject *self, PyObject *args)
PyObject * value_to_value_object(struct value *val)
static int startswith(const char *string, const char *pattern)
htab_t create_copied_types_hash(struct objfile *objfile)
struct type * lookup_union(const char *name, const struct block *block)
int gdb_python_initialized
static PyObject * typy_get_code(PyObject *self, void *closure)
static PyObject * typy_richcompare(PyObject *self, PyObject *other, int op)
static PyObject * typy_reference(PyObject *self, PyObject *args)
struct ui_file * mem_fileopen(void)
#define TYPE_FIELD_BITSIZE(thistype, n)
#define TYPE_FIELD_BITPOS(thistype, n)
static PyGetSetDef type_object_getset[]
char * cp_comp_to_string(struct demangle_component *result, int estimated_len)
static PyObject * typy_array(PyObject *self, PyObject *args)
static PyObject * typy_iterator_iternext(PyObject *self)
#define gdb_py_long_from_longest
#define LA_PRINT_TYPE(type, varstring, stream, show, level, flags)
enum gdbpy_iter_kind kind
static PyMethodDef type_object_methods[]
struct type * make_cv_type(int cnst, int voltl, struct type *type, struct type **typeptr)
const struct language_defn * current_language
#define TYPE_TARGET_TYPE(thistype)
static PyObject * make_fielditem(struct type *type, int i, enum gdbpy_iter_kind kind)
int gdbpy_initialize_types(void)
struct cleanup * make_cleanup_ui_file_delete(struct ui_file *arg)
#define TYPE_CODE(thistype)
#define TYPE_INDEX_TYPE(type)
static PyObject * typy_iterator_iter(PyObject *self)
struct pyty_field_object field_object
struct value * value_of_variable(struct symbol *var, const struct block *b)
static PyObject * typy_getitem(PyObject *self, PyObject *key)
static PyObject * typy_field_names(PyObject *self, PyObject *args)
#define TYPE_NFIELDS(thistype)
static PyObject * typy_iteritems(PyObject *self, PyObject *args)
static PyObject * typy_values(PyObject *self, PyObject *args)
static const struct objfile_data * typy_objfile_data_key
#define CHECK_TYPEDEF(TYPE)
struct pyty_type_object * next
struct pyty_type_object * prev
#define TYPE_TAG_NAME(type)
static PyObject * typy_optimized_out(PyObject *self, PyObject *args)
static PyObject * typy_pointer(PyObject *self, PyObject *args)
static PyObject * field_name(struct type *type, int field)
int gdb_py_int_as_long(PyObject *obj, long *result)
#define TYPE_TEMPLATE_ARGUMENT(thistype, n)
#define SYMBOL_TYPE(symbol)
static PyObject * typy_legacy_template_argument(struct type *type, const struct block *block, int argno)
struct type * lookup_reference_type(struct type *type)
const struct language_defn * python_language
static PyObject * typy_iterkeys(PyObject *self, PyObject *args)
const char * host_charset(void)
#define TYPE_LENGTH(thistype)
static PyObject * typy_get(PyObject *self, PyObject *args)
struct value * allocate_optimized_out_value(struct type *type)
static PyObject * typy_template_argument(PyObject *self, PyObject *args)
static struct type * typy_lookup_type(struct demangle_component *demangled, const struct block *block)
static PyObject * typy_itervalues(PyObject *self, PyObject *args)
static PyObject * typy_get_tag(PyObject *self, void *closure)
static PyObject * typy_vector(PyObject *self, PyObject *args)
static PyObject * typy_get_sizeof(PyObject *self, void *closure)
void make_vector_type(struct type *array_type)
static void field_dealloc(PyObject *obj)
struct type * lookup_pointer_type(struct type *type)
void do_cleanups(struct cleanup *old_chain)
static PyMappingMethods typy_mapping
static PyNumberMethods type_object_as_number
PyObject_HEAD struct type * type
#define PyVarObject_HEAD_INIT(type, size)
PyObject * type_to_type_object(struct type *type)