GDB (xrefs)
Loading...
Searching...
No Matches
py-type.c
Go to the documentation of this file.
1/* Python interface to types.
2
3 Copyright (C) 2008-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "value.h"
22#include "python-internal.h"
23#include "charset.h"
24#include "gdbtypes.h"
25#include "cp-support.h"
26#include "demangle.h"
27#include "objfiles.h"
28#include "language.h"
29#include "typeprint.h"
30#include "ada-lang.h"
31
33{
34 PyObject_HEAD
35 struct type *type;
36
37 /* If a Type object is associated with an objfile, it is kept on a
38 doubly-linked list, rooted in the objfile. This lets us copy the
39 underlying struct type when the objfile is deleted. */
42};
43
44extern PyTypeObject type_object_type
46
47/* A Field object. */
49{
50 PyObject_HEAD
51
52 /* Dictionary holding our attributes. */
53 PyObject *dict;
54};
55
56extern PyTypeObject field_object_type
58
59/* A type iterator object. */
61 PyObject_HEAD
62 /* The current field index. */
63 int field;
64 /* What to return. */
66 /* Pointer back to the original source type object. */
68};
69
70extern PyTypeObject type_iterator_object_type
71 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("typy_iterator_object");
72
73/* This is used to initialize various gdb.TYPE_ constants. */
75{
76 /* The code. */
77 int code;
78 /* The name. */
79 const char *name;
80};
81
82/* Forward declarations. */
83static PyObject *typy_make_iter (PyObject *self, enum gdbpy_iter_kind kind);
84
85static struct pyty_code pyty_codes[] =
86{
87 /* This is kept for backward compatibility. */
88 { -1, "TYPE_CODE_BITSTRING" },
89
90#define OP(X) { X, #X },
91#include "type-codes.def"
92#undef OP
93};
94
95
96
97static void
98field_dealloc (PyObject *obj)
99{
100 field_object *f = (field_object *) obj;
101
102 Py_XDECREF (f->dict);
103 Py_TYPE (obj)->tp_free (obj);
104}
105
106static PyObject *
108{
109 gdbpy_ref<field_object> result (PyObject_New (field_object,
111
112 if (result != NULL)
113 {
114 result->dict = PyDict_New ();
115 if (!result->dict)
116 return NULL;
117 }
118 return (PyObject *) result.release ();
119}
120
121
122
123/* Return true if OBJ is of type gdb.Field, false otherwise. */
124
125int
126gdbpy_is_field (PyObject *obj)
127{
128 return PyObject_TypeCheck (obj, &field_object_type);
129}
130
131/* Return the code for this type. */
132static PyObject *
133typy_get_code (PyObject *self, void *closure)
134{
135 struct type *type = ((type_object *) self)->type;
136
137 return gdb_py_object_from_longest (type->code ()).release ();
138}
139
140/* Helper function for typy_fields which converts a single field to a
141 gdb.Field object. Returns NULL on error. */
142
143static gdbpy_ref<>
145{
146 gdbpy_ref<> result (field_new ());
147
148 if (result == NULL)
149 return NULL;
150
152 if (arg == NULL)
153 return NULL;
154 if (PyObject_SetAttrString (result.get (), "parent_type", arg.get ()) < 0)
155 return NULL;
156
157 if (!field_is_static (&type->field (field)))
158 {
159 const char *attrstring;
160
161 if (type->code () == TYPE_CODE_ENUM)
162 {
164 attrstring = "enumval";
165 }
166 else
167 {
169 arg = gdbpy_ref<>::new_reference (Py_None);
170 else
172 attrstring = "bitpos";
173 }
174
175 if (arg == NULL)
176 return NULL;
177
178 if (PyObject_SetAttrString (result.get (), attrstring, arg.get ()) < 0)
179 return NULL;
180 }
181
182 arg.reset (NULL);
183 if (type->field (field).name ())
184 {
185 const char *field_name = type->field (field).name ();
186
187 if (field_name[0] != '\0')
188 {
189 arg.reset (PyUnicode_FromString (type->field (field).name ()));
190 if (arg == NULL)
191 return NULL;
192 }
193 }
194 if (arg == NULL)
195 arg = gdbpy_ref<>::new_reference (Py_None);
196
197 if (PyObject_SetAttrString (result.get (), "name", arg.get ()) < 0)
198 return NULL;
199
200 arg.reset (PyBool_FromLong (TYPE_FIELD_ARTIFICIAL (type, field)));
201 if (PyObject_SetAttrString (result.get (), "artificial", arg.get ()) < 0)
202 return NULL;
203
204 if (type->code () == TYPE_CODE_STRUCT)
205 arg.reset (PyBool_FromLong (field < TYPE_N_BASECLASSES (type)));
206 else
207 arg = gdbpy_ref<>::new_reference (Py_False);
208 if (PyObject_SetAttrString (result.get (), "is_base_class", arg.get ()) < 0)
209 return NULL;
210
212 if (arg == NULL)
213 return NULL;
214 if (PyObject_SetAttrString (result.get (), "bitsize", arg.get ()) < 0)
215 return NULL;
216
217 /* A field can have a NULL type in some situations. */
218 if (type->field (field).type () == NULL)
219 arg = gdbpy_ref<>::new_reference (Py_None);
220 else
221 arg.reset (type_to_type_object (type->field (field).type ()));
222 if (arg == NULL)
223 return NULL;
224 if (PyObject_SetAttrString (result.get (), "type", arg.get ()) < 0)
225 return NULL;
226
227 return result;
228}
229
230/* Helper function to return the name of a field, as a gdb.Field object.
231 If the field doesn't have a name, None is returned. */
232
233static gdbpy_ref<>
234field_name (struct type *type, int field)
235{
236 gdbpy_ref<> result;
237
238 if (type->field (field).name ())
239 result.reset (PyUnicode_FromString (type->field (field).name ()));
240 else
241 result = gdbpy_ref<>::new_reference (Py_None);
242
243 return result;
244}
245
246/* Helper function for Type standard mapping methods. Returns a
247 Python object for field i of the type. "kind" specifies what to
248 return: the name of the field, a gdb.Field object corresponding to
249 the field, or a tuple consisting of field name and gdb.Field
250 object. */
251
252static gdbpy_ref<>
253make_fielditem (struct type *type, int i, enum gdbpy_iter_kind kind)
254{
255 switch (kind)
256 {
257 case iter_items:
258 {
259 gdbpy_ref<> key (field_name (type, i));
260 if (key == NULL)
261 return NULL;
263 if (value == NULL)
264 return NULL;
265 gdbpy_ref<> item (PyTuple_New (2));
266 if (item == NULL)
267 return NULL;
268 PyTuple_SET_ITEM (item.get (), 0, key.release ());
269 PyTuple_SET_ITEM (item.get (), 1, value.release ());
270 return item;
271 }
272 case iter_keys:
273 return field_name (type, i);
274 case iter_values:
275 return convert_field (type, i);
276 }
277 gdb_assert_not_reached ("invalid gdbpy_iter_kind");
278}
279
280/* Return a sequence of all field names, fields, or (name, field) pairs.
281 Each field is a gdb.Field object. */
282
283static PyObject *
284typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind)
285{
286 PyObject *py_type = self;
287 struct type *type = ((type_object *) py_type)->type;
288 struct type *checked_type = type;
289
290 try
291 {
292 checked_type = check_typedef (checked_type);
293 }
294 catch (const gdb_exception &except)
295 {
297 }
298
299 gdbpy_ref<> type_holder;
300 if (checked_type != type)
301 {
302 type_holder.reset (type_to_type_object (checked_type));
303 if (type_holder == nullptr)
304 return nullptr;
305 py_type = type_holder.get ();
306 }
307 gdbpy_ref<> iter (typy_make_iter (py_type, kind));
308 if (iter == nullptr)
309 return nullptr;
310
311 return PySequence_List (iter.get ());
312}
313
314/* Return a sequence of all fields. Each field is a gdb.Field object. */
315
316static PyObject *
317typy_values (PyObject *self, PyObject *args)
318{
319 return typy_fields_items (self, iter_values);
320}
321
322/* Return a sequence of all fields. Each field is a gdb.Field object.
323 This method is similar to typy_values, except where the supplied
324 gdb.Type is an array, in which case it returns a list of one entry
325 which is a gdb.Field object for a range (the array bounds). */
326
327static PyObject *
328typy_fields (PyObject *self, PyObject *args)
329{
330 struct type *type = ((type_object *) self)->type;
331
332 if (type->code () != TYPE_CODE_ARRAY)
333 return typy_fields_items (self, iter_values);
334
335 /* Array type. Handle this as a special case because the common
336 machinery wants struct or union or enum types. Build a list of
337 one entry which is the range for the array. */
339 if (r == NULL)
340 return NULL;
341
342 return Py_BuildValue ("[O]", r.get ());
343}
344
345/* Return a sequence of all field names. Each field is a gdb.Field object. */
346
347static PyObject *
348typy_field_names (PyObject *self, PyObject *args)
349{
350 return typy_fields_items (self, iter_keys);
351}
352
353/* Return a sequence of all (name, fields) pairs. Each field is a
354 gdb.Field object. */
355
356static PyObject *
357typy_items (PyObject *self, PyObject *args)
358{
359 return typy_fields_items (self, iter_items);
360}
361
362/* Return the type's name, or None. */
363
364static PyObject *
365typy_get_name (PyObject *self, void *closure)
366{
367 struct type *type = ((type_object *) self)->type;
368
369 if (type->name () == NULL)
370 Py_RETURN_NONE;
371 /* Ada type names are encoded, but it is better for users to see the
372 decoded form. */
373 if (ADA_TYPE_P (type))
374 {
375 std::string name = ada_decode (type->name (), false);
376 if (!name.empty ())
377 return PyUnicode_FromString (name.c_str ());
378 }
379 return PyUnicode_FromString (type->name ());
380}
381
382/* Return the type's tag, or None. */
383static PyObject *
384typy_get_tag (PyObject *self, void *closure)
385{
386 struct type *type = ((type_object *) self)->type;
387 const char *tagname = nullptr;
388
389 if (type->code () == TYPE_CODE_STRUCT
390 || type->code () == TYPE_CODE_UNION
391 || type->code () == TYPE_CODE_ENUM)
392 tagname = type->name ();
393
394 if (tagname == nullptr)
395 Py_RETURN_NONE;
396 return PyUnicode_FromString (tagname);
397}
398
399/* Return the type's objfile, or None. */
400static PyObject *
401typy_get_objfile (PyObject *self, void *closure)
402{
403 struct type *type = ((type_object *) self)->type;
404 struct objfile *objfile = type->objfile_owner ();
405
406 if (objfile == nullptr)
407 Py_RETURN_NONE;
408 return objfile_to_objfile_object (objfile).release ();
409}
410
411/* Return true if this is a scalar type, otherwise, returns false. */
412
413static PyObject *
414typy_is_scalar (PyObject *self, void *closure)
415{
416 struct type *type = ((type_object *) self)->type;
417
418 if (is_scalar_type (type))
419 Py_RETURN_TRUE;
420 else
421 Py_RETURN_FALSE;
422}
423
424/* Return true if this type is signed. Raises a ValueError if this type
425 is not a scalar type. */
426
427static PyObject *
428typy_is_signed (PyObject *self, void *closure)
429{
430 struct type *type = ((type_object *) self)->type;
431
432 if (!is_scalar_type (type))
433 {
434 PyErr_SetString (PyExc_ValueError,
435 _("Type must be a scalar type"));
436 return nullptr;
437 }
438
439 if (type->is_unsigned ())
440 Py_RETURN_FALSE;
441 else
442 Py_RETURN_TRUE;
443}
444
445/* Return the type, stripped of typedefs. */
446static PyObject *
447typy_strip_typedefs (PyObject *self, PyObject *args)
448{
449 struct type *type = ((type_object *) self)->type;
450
451 try
452 {
454 }
455 catch (const gdb_exception &except)
456 {
458 }
459
460 return type_to_type_object (type);
461}
462
463/* Strip typedefs and pointers/reference from a type. Then check that
464 it is a struct, union, or enum type. If not, raise TypeError. */
465
466static struct type *
468{
469
470 for (;;)
471 {
472 try
473 {
475 }
476 catch (const gdb_exception &except)
477 {
479 }
480
482 break;
483 type = type->target_type ();
484 }
485
486 /* If this is not a struct, union, or enum type, raise TypeError
487 exception. */
488 if (type->code () != TYPE_CODE_STRUCT
489 && type->code () != TYPE_CODE_UNION
490 && type->code () != TYPE_CODE_ENUM
491 && type->code () != TYPE_CODE_METHOD
492 && type->code () != TYPE_CODE_FUNC)
493 {
494 PyErr_SetString (PyExc_TypeError,
495 "Type is not a structure, union, enum, or function type.");
496 return NULL;
497 }
498
499 return type;
500}
501
502/* Helper for typy_array and typy_vector. */
503
504static PyObject *
505typy_array_1 (PyObject *self, PyObject *args, int is_vector)
506{
507 long n1, n2;
508 PyObject *n2_obj = NULL;
509 struct type *array = NULL;
510 struct type *type = ((type_object *) self)->type;
511
512 if (! PyArg_ParseTuple (args, "l|O", &n1, &n2_obj))
513 return NULL;
514
515 if (n2_obj)
516 {
517 if (!PyLong_Check (n2_obj))
518 {
519 PyErr_SetString (PyExc_RuntimeError,
520 _("Array bound must be an integer"));
521 return NULL;
522 }
523
524 if (! gdb_py_int_as_long (n2_obj, &n2))
525 return NULL;
526 }
527 else
528 {
529 n2 = n1;
530 n1 = 0;
531 }
532
533 if (n2 < n1 - 1) /* Note: An empty array has n2 == n1 - 1. */
534 {
535 PyErr_SetString (PyExc_ValueError,
536 _("Array length must not be negative"));
537 return NULL;
538 }
539
540 try
541 {
542 array = lookup_array_range_type (type, n1, n2);
543 if (is_vector)
544 make_vector_type (array);
545 }
546 catch (const gdb_exception &except)
547 {
549 }
550
551 return type_to_type_object (array);
552}
553
554/* Return an array type. */
555
556static PyObject *
557typy_array (PyObject *self, PyObject *args)
558{
559 return typy_array_1 (self, args, 0);
560}
561
562/* Return a vector type. */
563
564static PyObject *
565typy_vector (PyObject *self, PyObject *args)
566{
567 return typy_array_1 (self, args, 1);
568}
569
570/* Return a Type object which represents a pointer to SELF. */
571static PyObject *
572typy_pointer (PyObject *self, PyObject *args)
573{
574 struct type *type = ((type_object *) self)->type;
575
576 try
577 {
579 }
580 catch (const gdb_exception &except)
581 {
583 }
584
585 return type_to_type_object (type);
586}
587
588/* Return the range of a type represented by SELF. The return type is
589 a tuple. The first element of the tuple contains the low bound,
590 while the second element of the tuple contains the high bound. */
591static PyObject *
592typy_range (PyObject *self, PyObject *args)
593{
594 struct type *type = ((type_object *) self)->type;
595 /* Initialize these to appease GCC warnings. */
596 LONGEST low = 0, high = 0;
597
598 if (type->code () != TYPE_CODE_ARRAY
599 && type->code () != TYPE_CODE_STRING
600 && type->code () != TYPE_CODE_RANGE)
601 {
602 PyErr_SetString (PyExc_RuntimeError,
603 _("This type does not have a range."));
604 return NULL;
605 }
606
607 switch (type->code ())
608 {
609 case TYPE_CODE_ARRAY:
610 case TYPE_CODE_STRING:
611 case TYPE_CODE_RANGE:
612 if (type->bounds ()->low.kind () == PROP_CONST)
613 low = type->bounds ()->low.const_val ();
614 else
615 low = 0;
616
617 if (type->bounds ()->high.kind () == PROP_CONST)
618 high = type->bounds ()->high.const_val ();
619 else
620 high = 0;
621 break;
622 }
623
624 gdbpy_ref<> low_bound = gdb_py_object_from_longest (low);
625 if (low_bound == NULL)
626 return NULL;
627
628 gdbpy_ref<> high_bound = gdb_py_object_from_longest (high);
629 if (high_bound == NULL)
630 return NULL;
631
632 gdbpy_ref<> result (PyTuple_New (2));
633 if (result == NULL)
634 return NULL;
635
636 if (PyTuple_SetItem (result.get (), 0, low_bound.release ()) != 0
637 || PyTuple_SetItem (result.get (), 1, high_bound.release ()) != 0)
638 return NULL;
639 return result.release ();
640}
641
642/* Return a Type object which represents a reference to SELF. */
643static PyObject *
644typy_reference (PyObject *self, PyObject *args)
645{
646 struct type *type = ((type_object *) self)->type;
647
648 try
649 {
651 }
652 catch (const gdb_exception &except)
653 {
655 }
656
657 return type_to_type_object (type);
658}
659
660/* Return a Type object which represents the target type of SELF. */
661static PyObject *
662typy_target (PyObject *self, PyObject *args)
663{
664 struct type *type = ((type_object *) self)->type;
665
666 if (!type->target_type ())
667 {
668 PyErr_SetString (PyExc_RuntimeError,
669 _("Type does not have a target."));
670 return NULL;
671 }
672
674}
675
676/* Return a const-qualified type variant. */
677static PyObject *
678typy_const (PyObject *self, PyObject *args)
679{
680 struct type *type = ((type_object *) self)->type;
681
682 try
683 {
684 type = make_cv_type (1, 0, type, NULL);
685 }
686 catch (const gdb_exception &except)
687 {
689 }
690
691 return type_to_type_object (type);
692}
693
694/* Return a volatile-qualified type variant. */
695static PyObject *
696typy_volatile (PyObject *self, PyObject *args)
697{
698 struct type *type = ((type_object *) self)->type;
699
700 try
701 {
702 type = make_cv_type (0, 1, type, NULL);
703 }
704 catch (const gdb_exception &except)
705 {
707 }
708
709 return type_to_type_object (type);
710}
711
712/* Return an unqualified type variant. */
713static PyObject *
714typy_unqualified (PyObject *self, PyObject *args)
715{
716 struct type *type = ((type_object *) self)->type;
717
718 try
719 {
720 type = make_cv_type (0, 0, type, NULL);
721 }
722 catch (const gdb_exception &except)
723 {
725 }
726
727 return type_to_type_object (type);
728}
729
730/* Return the size of the type represented by SELF, in bytes. */
731static PyObject *
732typy_get_sizeof (PyObject *self, void *closure)
733{
734 struct type *type = ((type_object *) self)->type;
735
736 bool size_varies = false;
737 try
738 {
740
741 size_varies = TYPE_HAS_DYNAMIC_LENGTH (type);
742 }
743 catch (const gdb_exception &except)
744 {
745 }
746
747 /* Ignore exceptions. */
748
749 if (size_varies)
750 Py_RETURN_NONE;
751 return gdb_py_object_from_longest (type->length ()).release ();
752}
753
754/* Return the alignment of the type represented by SELF, in bytes. */
755static PyObject *
756typy_get_alignof (PyObject *self, void *closure)
757{
758 struct type *type = ((type_object *) self)->type;
759
760 ULONGEST align = 0;
761 try
762 {
763 align = type_align (type);
764 }
765 catch (const gdb_exception &except)
766 {
767 align = 0;
768 }
769
770 /* Ignore exceptions. */
771
772 return gdb_py_object_from_ulongest (align).release ();
773}
774
775/* Return whether or not the type is dynamic. */
776static PyObject *
777typy_get_dynamic (PyObject *self, void *closure)
778{
779 struct type *type = ((type_object *) self)->type;
780
781 bool result = false;
782 try
783 {
784 result = is_dynamic_type (type);
785 }
786 catch (const gdb_exception &except)
787 {
788 /* Ignore exceptions. */
789 }
790
791 if (result)
792 Py_RETURN_TRUE;
793 Py_RETURN_FALSE;
794}
795
796static struct type *
797typy_lookup_typename (const char *type_name, const struct block *block)
798{
799 struct type *type = NULL;
800
801 try
802 {
803 if (startswith (type_name, "struct "))
804 type = lookup_struct (type_name + 7, NULL);
805 else if (startswith (type_name, "union "))
806 type = lookup_union (type_name + 6, NULL);
807 else if (startswith (type_name, "enum "))
808 type = lookup_enum (type_name + 5, NULL);
809 else
811 type_name, block, 0);
812 }
813 catch (const gdb_exception &except)
814 {
816 }
817
818 return type;
819}
820
821static struct type *
822typy_lookup_type (struct demangle_component *demangled,
823 const struct block *block)
824{
825 struct type *type, *rtype = NULL;
826 enum demangle_component_type demangled_type;
827
828 /* Save the type: typy_lookup_type() may (indirectly) overwrite
829 memory pointed by demangled. */
830 demangled_type = demangled->type;
831
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)
837 {
838 type = typy_lookup_type (demangled->u.s_binary.left, block);
839 if (! type)
840 return NULL;
841
842 try
843 {
844 /* If the demangled_type matches with one of the types
845 below, run the corresponding function and save the type
846 to return later. We cannot just return here as we are in
847 an exception handler. */
848 switch (demangled_type)
849 {
850 case DEMANGLE_COMPONENT_REFERENCE:
852 break;
853 case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
855 break;
856 case DEMANGLE_COMPONENT_POINTER:
857 rtype = lookup_pointer_type (type);
858 break;
859 case DEMANGLE_COMPONENT_CONST:
860 rtype = make_cv_type (1, 0, type, NULL);
861 break;
862 case DEMANGLE_COMPONENT_VOLATILE:
863 rtype = make_cv_type (0, 1, type, NULL);
864 break;
865 }
866 }
867 catch (const gdb_exception &except)
868 {
870 }
871 }
872
873 /* If we have a type from the switch statement above, just return
874 that. */
875 if (rtype)
876 return rtype;
877
878 /* We don't have a type, so lookup the type. */
879 gdb::unique_xmalloc_ptr<char> type_name = cp_comp_to_string (demangled, 10);
880 return typy_lookup_typename (type_name.get (), block);
881}
882
883/* This is a helper function for typy_template_argument that is used
884 when the type does not have template symbols attached. It works by
885 parsing the type name. This happens with compilers, like older
886 versions of GCC, that do not emit DW_TAG_template_*. */
887
888static PyObject *
890 int argno)
891{
892 int i;
893 struct demangle_component *demangled;
894 std::unique_ptr<demangle_parse_info> info;
895 std::string err;
896 struct type *argtype;
897
898 if (type->name () == NULL)
899 {
900 PyErr_SetString (PyExc_RuntimeError, _("Null type name."));
901 return NULL;
902 }
903
904 try
905 {
906 /* Note -- this is not thread-safe. */
907 info = cp_demangled_name_to_comp (type->name (), &err);
908 }
909 catch (const gdb_exception &except)
910 {
912 }
913
914 if (! info)
915 {
916 PyErr_SetString (PyExc_RuntimeError, err.c_str ());
917 return NULL;
918 }
919 demangled = info->tree;
920
921 /* Strip off component names. */
922 while (demangled->type == DEMANGLE_COMPONENT_QUAL_NAME
923 || demangled->type == DEMANGLE_COMPONENT_LOCAL_NAME)
924 demangled = demangled->u.s_binary.right;
925
926 if (demangled->type != DEMANGLE_COMPONENT_TEMPLATE)
927 {
928 PyErr_SetString (PyExc_RuntimeError, _("Type is not a template."));
929 return NULL;
930 }
931
932 /* Skip from the template to the arguments. */
933 demangled = demangled->u.s_binary.right;
934
935 for (i = 0; demangled && i < argno; ++i)
936 demangled = demangled->u.s_binary.right;
937
938 if (! demangled)
939 {
940 PyErr_Format (PyExc_RuntimeError, _("No argument %d in template."),
941 argno);
942 return NULL;
943 }
944
945 argtype = typy_lookup_type (demangled->u.s_binary.left, block);
946 if (! argtype)
947 return NULL;
948
949 return type_to_type_object (argtype);
950}
951
952static PyObject *
953typy_template_argument (PyObject *self, PyObject *args)
954{
955 int argno;
956 struct type *type = ((type_object *) self)->type;
957 const struct block *block = NULL;
958 PyObject *block_obj = NULL;
959 struct symbol *sym;
960 struct value *val = NULL;
961
962 if (! PyArg_ParseTuple (args, "i|O", &argno, &block_obj))
963 return NULL;
964
965 if (argno < 0)
966 {
967 PyErr_SetString (PyExc_RuntimeError,
968 _("Template argument number must be non-negative"));
969 return NULL;
970 }
971
972 if (block_obj)
973 {
974 block = block_object_to_block (block_obj);
975 if (! block)
976 {
977 PyErr_SetString (PyExc_RuntimeError,
978 _("Second argument must be block."));
979 return NULL;
980 }
981 }
982
983 try
984 {
988 }
989 catch (const gdb_exception &except)
990 {
992 }
993
994 /* We might not have DW_TAG_template_*, so try to parse the type's
995 name. This is inefficient if we do not have a template type --
996 but that is going to wind up as an error anyhow. */
999
1000 if (argno >= TYPE_N_TEMPLATE_ARGUMENTS (type))
1001 {
1002 PyErr_Format (PyExc_RuntimeError, _("No argument %d in template."),
1003 argno);
1004 return NULL;
1005 }
1006
1007 sym = TYPE_TEMPLATE_ARGUMENT (type, argno);
1008 if (sym->aclass () == LOC_TYPEDEF)
1009 return type_to_type_object (sym->type ());
1010 else if (sym->aclass () == LOC_OPTIMIZED_OUT)
1011 {
1012 PyErr_Format (PyExc_RuntimeError,
1013 _("Template argument is optimized out"));
1014 return NULL;
1015 }
1016
1017 try
1018 {
1019 val = value_of_variable (sym, block);
1020 }
1021 catch (const gdb_exception &except)
1022 {
1023 GDB_PY_HANDLE_EXCEPTION (except);
1024 }
1025
1026 return value_to_value_object (val);
1027}
1028
1029static PyObject *
1030typy_str (PyObject *self)
1031{
1032 string_file thetype;
1033
1034 try
1035 {
1037 &thetype, -1, 0,
1039 }
1040 catch (const gdb_exception &except)
1041 {
1042 GDB_PY_HANDLE_EXCEPTION (except);
1043 }
1044
1045 return PyUnicode_Decode (thetype.c_str (), thetype.size (),
1046 host_charset (), NULL);
1047}
1048
1049/* Implement the richcompare method. */
1050
1051static PyObject *
1052typy_richcompare (PyObject *self, PyObject *other, int op)
1053{
1054 bool result = false;
1055 struct type *type1 = type_object_to_type (self);
1056 struct type *type2 = type_object_to_type (other);
1057
1058 /* We can only compare ourselves to another Type object, and only
1059 for equality or inequality. */
1060 if (type2 == NULL || (op != Py_EQ && op != Py_NE))
1061 {
1062 Py_INCREF (Py_NotImplemented);
1063 return Py_NotImplemented;
1064 }
1065
1066 if (type1 == type2)
1067 result = true;
1068 else
1069 {
1070 try
1071 {
1072 result = types_deeply_equal (type1, type2);
1073 }
1074 catch (const gdb_exception &except)
1075 {
1076 /* If there is a GDB exception, a comparison is not capable
1077 (or trusted), so exit. */
1078 GDB_PY_HANDLE_EXCEPTION (except);
1079 }
1080 }
1081
1082 if (op == (result ? Py_EQ : Py_NE))
1083 Py_RETURN_TRUE;
1084 Py_RETURN_FALSE;
1085}
1086
1087
1088
1089/* Deleter that saves types when an objfile is being destroyed. */
1091{
1093 {
1095 return;
1096
1097 /* This prevents another thread from freeing the objects we're
1098 operating on. */
1099 gdbpy_enter enter_py;
1100
1101 htab_up copied_types = create_copied_types_hash ();
1102
1103 while (obj)
1104 {
1105 type_object *next = obj->next;
1106
1107 htab_empty (copied_types.get ());
1108
1109 obj->type = copy_type_recursive (obj->type, copied_types.get ());
1110
1111 obj->next = NULL;
1112 obj->prev = NULL;
1113
1114 obj = next;
1115 }
1116 }
1117};
1118
1121
1122static void
1124{
1125 obj->type = type;
1126 obj->prev = NULL;
1127 if (type != nullptr && type->objfile_owner () != nullptr)
1128 {
1129 struct objfile *objfile = type->objfile_owner ();
1130
1132 if (obj->next)
1133 obj->next->prev = obj;
1135 }
1136 else
1137 obj->next = NULL;
1138}
1139
1140static void
1141typy_dealloc (PyObject *obj)
1142{
1143 type_object *type = (type_object *) obj;
1144
1145 if (type->prev)
1146 type->prev->next = type->next;
1147 else if (type->type != nullptr && type->type->objfile_owner () != nullptr)
1148 {
1149 /* Must reset head of list. */
1150 struct objfile *objfile = type->type->objfile_owner ();
1151
1152 if (objfile)
1154 }
1155 if (type->next)
1156 type->next->prev = type->prev;
1157
1158 Py_TYPE (type)->tp_free (type);
1159}
1160
1161/* Return number of fields ("length" of the field dictionary). */
1162
1163static Py_ssize_t
1164typy_length (PyObject *self)
1165{
1166 struct type *type = ((type_object *) self)->type;
1167
1169 if (type == NULL)
1170 return -1;
1171
1172 return type->num_fields ();
1173}
1174
1175/* Implements boolean evaluation of gdb.Type. Handle this like other
1176 Python objects that don't have a meaningful truth value -- all
1177 values are true. */
1178
1179static int
1180typy_nonzero (PyObject *self)
1181{
1182 return 1;
1183}
1184
1185/* Return optimized out value of this type. */
1186
1187static PyObject *
1188typy_optimized_out (PyObject *self, PyObject *args)
1189{
1190 struct type *type = ((type_object *) self)->type;
1191
1193}
1194
1195/* Return a gdb.Field object for the field named by the argument. */
1196
1197static PyObject *
1198typy_getitem (PyObject *self, PyObject *key)
1199{
1200 struct type *type = ((type_object *) self)->type;
1201 int i;
1202
1203 gdb::unique_xmalloc_ptr<char> field = python_string_to_host_string (key);
1204 if (field == NULL)
1205 return NULL;
1206
1207 /* We want just fields of this type, not of base types, so instead of
1208 using lookup_struct_elt_type, portions of that function are
1209 copied here. */
1210
1212 if (type == NULL)
1213 return NULL;
1214
1215 for (i = 0; i < type->num_fields (); i++)
1216 {
1217 const char *t_field_name = type->field (i).name ();
1218
1219 if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
1220 return convert_field (type, i).release ();
1221 }
1222 PyErr_SetObject (PyExc_KeyError, key);
1223 return NULL;
1224}
1225
1226/* Implement the "get" method on the type object. This is the
1227 same as getitem if the key is present, but returns the supplied
1228 default value or None if the key is not found. */
1229
1230static PyObject *
1231typy_get (PyObject *self, PyObject *args)
1232{
1233 PyObject *key, *defval = Py_None, *result;
1234
1235 if (!PyArg_UnpackTuple (args, "get", 1, 2, &key, &defval))
1236 return NULL;
1237
1238 result = typy_getitem (self, key);
1239 if (result != NULL)
1240 return result;
1241
1242 /* typy_getitem returned error status. If the exception is
1243 KeyError, clear the exception status and return the defval
1244 instead. Otherwise return the exception unchanged. */
1245 if (!PyErr_ExceptionMatches (PyExc_KeyError))
1246 return NULL;
1247
1248 PyErr_Clear ();
1249 Py_INCREF (defval);
1250 return defval;
1251}
1252
1253/* Implement the "has_key" method on the type object. */
1254
1255static PyObject *
1256typy_has_key (PyObject *self, PyObject *args)
1257{
1258 struct type *type = ((type_object *) self)->type;
1259 const char *field;
1260 int i;
1261
1262 if (!PyArg_ParseTuple (args, "s", &field))
1263 return NULL;
1264
1265 /* We want just fields of this type, not of base types, so instead of
1266 using lookup_struct_elt_type, portions of that function are
1267 copied here. */
1268
1270 if (type == NULL)
1271 return NULL;
1272
1273 for (i = 0; i < type->num_fields (); i++)
1274 {
1275 const char *t_field_name = type->field (i).name ();
1276
1277 if (t_field_name && (strcmp_iw (t_field_name, field) == 0))
1278 Py_RETURN_TRUE;
1279 }
1280 Py_RETURN_FALSE;
1281}
1282
1283/* Make an iterator object to iterate over keys, values, or items. */
1284
1285static PyObject *
1286typy_make_iter (PyObject *self, enum gdbpy_iter_kind kind)
1287{
1288 typy_iterator_object *typy_iter_obj;
1289
1290 /* Check that "self" is a structure or union type. */
1291 if (typy_get_composite (((type_object *) self)->type) == NULL)
1292 return NULL;
1293
1294 typy_iter_obj = PyObject_New (typy_iterator_object,
1296 if (typy_iter_obj == NULL)
1297 return NULL;
1298
1299 typy_iter_obj->field = 0;
1300 typy_iter_obj->kind = kind;
1301 Py_INCREF (self);
1302 typy_iter_obj->source = (type_object *) self;
1303
1304 return (PyObject *) typy_iter_obj;
1305}
1306
1307/* iteritems() method. */
1308
1309static PyObject *
1310typy_iteritems (PyObject *self, PyObject *args)
1311{
1312 return typy_make_iter (self, iter_items);
1313}
1314
1315/* iterkeys() method. */
1316
1317static PyObject *
1318typy_iterkeys (PyObject *self, PyObject *args)
1319{
1320 return typy_make_iter (self, iter_keys);
1321}
1322
1323/* Iterating over the class, same as iterkeys except for the function
1324 signature. */
1325
1326static PyObject *
1327typy_iter (PyObject *self)
1328{
1329 return typy_make_iter (self, iter_keys);
1330}
1331
1332/* itervalues() method. */
1333
1334static PyObject *
1335typy_itervalues (PyObject *self, PyObject *args)
1336{
1337 return typy_make_iter (self, iter_values);
1338}
1339
1340/* Return a reference to the type iterator. */
1341
1342static PyObject *
1343typy_iterator_iter (PyObject *self)
1344{
1345 Py_INCREF (self);
1346 return self;
1347}
1348
1349/* Return the next field in the iteration through the list of fields
1350 of the type. */
1351
1352static PyObject *
1354{
1355 typy_iterator_object *iter_obj = (typy_iterator_object *) self;
1356 struct type *type = iter_obj->source->type;
1357
1358 if (iter_obj->field < type->num_fields ())
1359 {
1360 gdbpy_ref<> result = make_fielditem (type, iter_obj->field,
1361 iter_obj->kind);
1362 if (result != NULL)
1363 iter_obj->field++;
1364 return result.release ();
1365 }
1366
1367 return NULL;
1368}
1369
1370static void
1372{
1373 typy_iterator_object *iter_obj = (typy_iterator_object *) obj;
1374
1375 Py_DECREF (iter_obj->source);
1376 Py_TYPE (obj)->tp_free (obj);
1377}
1378
1379/* Create a new Type referring to TYPE. */
1380PyObject *
1382{
1383 type_object *type_obj;
1384
1385 try
1386 {
1387 /* Try not to let stub types leak out to Python. */
1388 if (type->is_stub ())
1390 }
1391 catch (...)
1392 {
1393 /* Just ignore failures in check_typedef. */
1394 }
1395
1396 type_obj = PyObject_New (type_object, &type_object_type);
1397 if (type_obj)
1398 set_type (type_obj, type);
1399
1400 return (PyObject *) type_obj;
1401}
1402
1403struct type *
1404type_object_to_type (PyObject *obj)
1405{
1406 if (! PyObject_TypeCheck (obj, &type_object_type))
1407 return NULL;
1408 return ((type_object *) obj)->type;
1409}
1410
1411
1412
1413/* Implementation of gdb.lookup_type. */
1414PyObject *
1415gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
1416{
1417 static const char *keywords[] = { "name", "block", NULL };
1418 const char *type_name = NULL;
1419 struct type *type = NULL;
1420 PyObject *block_obj = NULL;
1421 const struct block *block = NULL;
1422
1423 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
1424 &type_name, &block_obj))
1425 return NULL;
1426
1427 if (block_obj)
1428 {
1429 block = block_object_to_block (block_obj);
1430 if (! block)
1431 {
1432 PyErr_SetString (PyExc_RuntimeError,
1433 _("'block' argument must be a Block."));
1434 return NULL;
1435 }
1436 }
1437
1438 type = typy_lookup_typename (type_name, block);
1439 if (! type)
1440 return NULL;
1441
1442 return type_to_type_object (type);
1443}
1444
1445int
1447{
1448 if (PyType_Ready (&type_object_type) < 0)
1449 return -1;
1450 if (PyType_Ready (&field_object_type) < 0)
1451 return -1;
1452 if (PyType_Ready (&type_iterator_object_type) < 0)
1453 return -1;
1454
1455 for (const auto &item : pyty_codes)
1456 {
1457 if (PyModule_AddIntConstant (gdb_module, item.name, item.code) < 0)
1458 return -1;
1459 }
1460
1462 (PyObject *) &type_object_type) < 0)
1463 return -1;
1464
1465 if (gdb_pymodule_addobject (gdb_module, "TypeIterator",
1466 (PyObject *) &type_iterator_object_type) < 0)
1467 return -1;
1468
1469 return gdb_pymodule_addobject (gdb_module, "Field",
1470 (PyObject *) &field_object_type);
1471}
1472
1473
1474
1476{
1477 { "alignof", typy_get_alignof, NULL,
1478 "The alignment of this type, in bytes.", NULL },
1479 { "code", typy_get_code, NULL,
1480 "The code for this type.", NULL },
1481 { "dynamic", typy_get_dynamic, NULL,
1482 "Whether this type is dynamic.", NULL },
1483 { "name", typy_get_name, NULL,
1484 "The name for this type, or None.", NULL },
1485 { "sizeof", typy_get_sizeof, NULL,
1486 "The size of this type, in bytes.", NULL },
1487 { "tag", typy_get_tag, NULL,
1488 "The tag name for this type, or None.", NULL },
1489 { "objfile", typy_get_objfile, NULL,
1490 "The objfile this type was defined in, or None.", NULL },
1491 { "is_scalar", typy_is_scalar, nullptr,
1492 "Is this a scalar type?", nullptr },
1493 { "is_signed", typy_is_signed, nullptr,
1494 "Is this an signed type?", nullptr },
1495 { NULL }
1496};
1497
1498static PyMethodDef type_object_methods[] =
1499{
1500 { "array", typy_array, METH_VARARGS,
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." },
1505 { "vector", typy_vector, METH_VARARGS,
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." },
1513 { "__contains__", typy_has_key, METH_VARARGS,
1514 "T.__contains__(k) -> True if T has a field named k, else False" },
1515 { "const", typy_const, METH_NOARGS,
1516 "const () -> Type\n\
1517Return a const variant of this type." },
1518 { "optimized_out", typy_optimized_out, METH_NOARGS,
1519 "optimized_out() -> Value\n\
1520Return optimized out value of this type." },
1521 { "fields", typy_fields, METH_NOARGS,
1522 "fields () -> list\n\
1523Return a list holding all the fields of this type.\n\
1524Each field is a gdb.Field object." },
1525 { "get", typy_get, METH_VARARGS,
1526 "T.get(k[,default]) -> returns field named k in T, if it exists;\n\
1527otherwise returns default, if supplied, or None if not." },
1528 { "has_key", typy_has_key, METH_VARARGS,
1529 "T.has_key(k) -> True if T has a field named k, else False" },
1530 { "items", typy_items, METH_NOARGS,
1531 "items () -> list\n\
1532Return a list of (name, field) pairs of this type.\n\
1533Each field is a gdb.Field object." },
1534 { "iteritems", typy_iteritems, METH_NOARGS,
1535 "iteritems () -> an iterator over the (name, field)\n\
1536pairs of this type. Each field is a gdb.Field object." },
1537 { "iterkeys", typy_iterkeys, METH_NOARGS,
1538 "iterkeys () -> an iterator over the field names of this type." },
1539 { "itervalues", typy_itervalues, METH_NOARGS,
1540 "itervalues () -> an iterator over the fields of this type.\n\
1541Each field is a gdb.Field object." },
1542 { "keys", typy_field_names, METH_NOARGS,
1543 "keys () -> list\n\
1544Return a list holding all the fields names of this type." },
1545 { "pointer", typy_pointer, METH_NOARGS,
1546 "pointer () -> Type\n\
1547Return a type of pointer to this type." },
1548 { "range", typy_range, METH_NOARGS,
1549 "range () -> tuple\n\
1550Return a tuple containing the lower and upper range for this type."},
1551 { "reference", typy_reference, METH_NOARGS,
1552 "reference () -> Type\n\
1553Return a type of reference to this type." },
1554 { "strip_typedefs", typy_strip_typedefs, METH_NOARGS,
1555 "strip_typedefs () -> Type\n\
1556Return a type formed by stripping this type of all typedefs."},
1557 { "target", typy_target, METH_NOARGS,
1558 "target () -> Type\n\
1559Return the target type of this type." },
1560 { "template_argument", typy_template_argument, METH_VARARGS,
1561 "template_argument (arg, [block]) -> Type\n\
1562Return the type of a template argument." },
1563 { "unqualified", typy_unqualified, METH_NOARGS,
1564 "unqualified () -> Type\n\
1565Return a variant of this type without const or volatile attributes." },
1566 { "values", typy_values, METH_NOARGS,
1567 "values () -> list\n\
1568Return a list holding all the fields of this type.\n\
1569Each field is a gdb.Field object." },
1570 { "volatile", typy_volatile, METH_NOARGS,
1571 "volatile () -> Type\n\
1572Return a volatile variant of this type" },
1573 { NULL }
1574};
1575
1576static PyNumberMethods type_object_as_number = {
1577 NULL, /* nb_add */
1578 NULL, /* nb_subtract */
1579 NULL, /* nb_multiply */
1580 NULL, /* nb_remainder */
1581 NULL, /* nb_divmod */
1582 NULL, /* nb_power */
1583 NULL, /* nb_negative */
1584 NULL, /* nb_positive */
1585 NULL, /* nb_absolute */
1586 typy_nonzero, /* nb_nonzero */
1587 NULL, /* nb_invert */
1588 NULL, /* nb_lshift */
1589 NULL, /* nb_rshift */
1590 NULL, /* nb_and */
1591 NULL, /* nb_xor */
1592 NULL, /* nb_or */
1593 NULL, /* nb_int */
1594 NULL, /* reserved */
1595 NULL, /* nb_float */
1596};
1597
1598static PyMappingMethods typy_mapping = {
1601 NULL /* no "set" method */
1602};
1603
1604PyTypeObject type_object_type =
1605{
1606 PyVarObject_HEAD_INIT (NULL, 0)
1607 "gdb.Type", /*tp_name*/
1608 sizeof (type_object), /*tp_basicsize*/
1609 0, /*tp_itemsize*/
1610 typy_dealloc, /*tp_dealloc*/
1611 0, /*tp_print*/
1612 0, /*tp_getattr*/
1613 0, /*tp_setattr*/
1614 0, /*tp_compare*/
1615 0, /*tp_repr*/
1616 &type_object_as_number, /*tp_as_number*/
1617 0, /*tp_as_sequence*/
1618 &typy_mapping, /*tp_as_mapping*/
1619 0, /*tp_hash */
1620 0, /*tp_call*/
1621 typy_str, /*tp_str*/
1622 0, /*tp_getattro*/
1623 0, /*tp_setattro*/
1624 0, /*tp_as_buffer*/
1625 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1626 "GDB type object", /* tp_doc */
1627 0, /* tp_traverse */
1628 0, /* tp_clear */
1629 typy_richcompare, /* tp_richcompare */
1630 0, /* tp_weaklistoffset */
1631 typy_iter, /* tp_iter */
1632 0, /* tp_iternext */
1633 type_object_methods, /* tp_methods */
1634 0, /* tp_members */
1635 type_object_getset, /* tp_getset */
1636 0, /* tp_base */
1637 0, /* tp_dict */
1638 0, /* tp_descr_get */
1639 0, /* tp_descr_set */
1640 0, /* tp_dictoffset */
1641 0, /* tp_init */
1642 0, /* tp_alloc */
1643 0, /* tp_new */
1644};
1645
1647{
1648 { "__dict__", gdb_py_generic_dict, NULL,
1649 "The __dict__ for this field.", &field_object_type },
1650 { NULL }
1651};
1652
1653PyTypeObject field_object_type =
1654{
1655 PyVarObject_HEAD_INIT (NULL, 0)
1656 "gdb.Field", /*tp_name*/
1657 sizeof (field_object), /*tp_basicsize*/
1658 0, /*tp_itemsize*/
1659 field_dealloc, /*tp_dealloc*/
1660 0, /*tp_print*/
1661 0, /*tp_getattr*/
1662 0, /*tp_setattr*/
1663 0, /*tp_compare*/
1664 0, /*tp_repr*/
1665 0, /*tp_as_number*/
1666 0, /*tp_as_sequence*/
1667 0, /*tp_as_mapping*/
1668 0, /*tp_hash */
1669 0, /*tp_call*/
1670 0, /*tp_str*/
1671 0, /*tp_getattro*/
1672 0, /*tp_setattro*/
1673 0, /*tp_as_buffer*/
1674 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1675 "GDB field object", /* tp_doc */
1676 0, /* tp_traverse */
1677 0, /* tp_clear */
1678 0, /* tp_richcompare */
1679 0, /* tp_weaklistoffset */
1680 0, /* tp_iter */
1681 0, /* tp_iternext */
1682 0, /* tp_methods */
1683 0, /* tp_members */
1684 field_object_getset, /* tp_getset */
1685 0, /* tp_base */
1686 0, /* tp_dict */
1687 0, /* tp_descr_get */
1688 0, /* tp_descr_set */
1689 offsetof (field_object, dict), /* tp_dictoffset */
1690 0, /* tp_init */
1691 0, /* tp_alloc */
1692 0, /* tp_new */
1693};
1694
1696 PyVarObject_HEAD_INIT (NULL, 0)
1697 "gdb.TypeIterator", /*tp_name*/
1698 sizeof (typy_iterator_object), /*tp_basicsize*/
1699 0, /*tp_itemsize*/
1700 typy_iterator_dealloc, /*tp_dealloc*/
1701 0, /*tp_print*/
1702 0, /*tp_getattr*/
1703 0, /*tp_setattr*/
1704 0, /*tp_compare*/
1705 0, /*tp_repr*/
1706 0, /*tp_as_number*/
1707 0, /*tp_as_sequence*/
1708 0, /*tp_as_mapping*/
1709 0, /*tp_hash */
1710 0, /*tp_call*/
1711 0, /*tp_str*/
1712 0, /*tp_getattro*/
1713 0, /*tp_setattro*/
1714 0, /*tp_as_buffer*/
1715 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1716 "GDB type iterator object", /*tp_doc */
1717 0, /*tp_traverse */
1718 0, /*tp_clear */
1719 0, /*tp_richcompare */
1720 0, /*tp_weaklistoffset */
1721 typy_iterator_iter, /*tp_iter */
1722 typy_iterator_iternext, /*tp_iternext */
1723 0 /*tp_methods */
1724};
const char *const name
Definition: aarch64-tdep.c:67
std::string ada_decode(const char *encoded, bool wrap, bool operators)
Definition: ada-lang.c:1310
if(!(yy_init))
Definition: ada-lex.c:1109
constexpr int n1
Definition: 2.cc:29
constexpr int n2
Definition: 2.cc:30
void f()
Definition: 1.cc:36
const char * host_charset(void)
Definition: charset.c:416
void set(unsigned key, void *datum)
Definition: registry.h:204
void * get(unsigned key)
Definition: registry.h:211
size_t size() const
Definition: ui-file.h:219
const char * c_str() const
Definition: ui-file.h:218
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)
Definition: gdbtypes.c:5634
struct type * lookup_pointer_type(struct type *type)
Definition: gdbtypes.c:402
struct type * lookup_enum(const char *name, const struct block *block)
Definition: gdbtypes.c:1788
struct type * lookup_lvalue_reference_type(struct type *type)
Definition: gdbtypes.c:490
struct type * lookup_typename(const struct language_defn *language, const char *name, const struct block *block, int noerr)
Definition: gdbtypes.c:1702
htab_up create_copied_types_hash()
Definition: gdbtypes.c:5596
int field_is_static(struct field *f)
Definition: gdbtypes.c:5048
int is_scalar_type(struct type *type)
Definition: gdbtypes.c:3799
int is_dynamic_type(struct type *type)
Definition: gdbtypes.c:2187
struct type * lookup_array_range_type(struct type *element_type, LONGEST low_bound, LONGEST high_bound)
Definition: gdbtypes.c:1431
struct type * make_cv_type(int cnst, int voltl, struct type *type, struct type **typeptr)
Definition: gdbtypes.c:714
struct type * lookup_rvalue_reference_type(struct type *type)
Definition: gdbtypes.c:498
unsigned type_align(struct type *type)
Definition: gdbtypes.c:3645
bool types_deeply_equal(struct type *type1, struct type *type2)
Definition: gdbtypes.c:4460
struct type * lookup_struct(const char *name, const struct block *block)
Definition: gdbtypes.c:1742
struct type * lookup_union(const char *name, const struct block *block)
Definition: gdbtypes.c:1764
struct type * check_typedef(struct type *type)
Definition: gdbtypes.c:3010
void make_vector_type(struct type *array_type)
Definition: gdbtypes.c:1517
@ PROP_CONST
Definition: gdbtypes.h:293
#define TYPE_IS_REFERENCE(t)
Definition: gdbtypes.h:156
@ FIELD_LOC_KIND_DWARF_BLOCK
Definition: gdbtypes.h:497
#define ADA_TYPE_P(type)
Definition: gdbtypes.h:2009
#define TYPE_HAS_DYNAMIC_LENGTH(t)
Definition: gdbtypes.h:168
#define TYPE_N_TEMPLATE_ARGUMENTS(thistype)
Definition: gdbtypes.h:2161
#define TYPE_FIELD_ARTIFICIAL(thistype, n)
Definition: gdbtypes.h:2122
#define TYPE_TEMPLATE_ARGUMENT(thistype, n)
Definition: gdbtypes.h:2165
#define TYPE_FIELD_BITSIZE(thistype, n)
Definition: gdbtypes.h:2123
#define TYPE_N_BASECLASSES(thistype)
Definition: gdbtypes.h:2108
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
Definition: gnu-nat.c:1790
const struct language_defn * current_language
Definition: language.c:83
const struct block * block_object_to_block(PyObject *obj)
Definition: py-block.c:342
gdbpy_ref objfile_to_objfile_object(struct objfile *objfile)
Definition: py-objfile.c:686
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
Definition: py-ref.h:43
static PyObject * typy_getitem(PyObject *self, PyObject *key)
Definition: py-type.c:1198
static PyObject * typy_pointer(PyObject *self, PyObject *args)
Definition: py-type.c:572
PyObject * type_to_type_object(struct type *type)
Definition: py-type.c:1381
static void typy_dealloc(PyObject *obj)
Definition: py-type.c:1141
static PyMappingMethods typy_mapping
Definition: py-type.c:1598
static PyObject * typy_iteritems(PyObject *self, PyObject *args)
Definition: py-type.c:1310
static PyObject * typy_get_code(PyObject *self, void *closure)
Definition: py-type.c:133
static struct pyty_code pyty_codes[]
Definition: py-type.c:85
static PyObject * typy_make_iter(PyObject *self, enum gdbpy_iter_kind kind)
Definition: py-type.c:1286
static PyObject * field_new(void)
Definition: py-type.c:107
static PyObject * typy_template_argument(PyObject *self, PyObject *args)
Definition: py-type.c:953
int gdbpy_initialize_types(void)
Definition: py-type.c:1446
static PyObject * typy_target(PyObject *self, PyObject *args)
Definition: py-type.c:662
static void typy_iterator_dealloc(PyObject *obj)
Definition: py-type.c:1371
static int typy_nonzero(PyObject *self)
Definition: py-type.c:1180
static struct type * typy_get_composite(struct type *type)
Definition: py-type.c:467
static PyObject * typy_items(PyObject *self, PyObject *args)
Definition: py-type.c:357
static PyObject * typy_optimized_out(PyObject *self, PyObject *args)
Definition: py-type.c:1188
static gdb_PyGetSetDef type_object_getset[]
Definition: py-type.c:1475
static PyObject * typy_get_tag(PyObject *self, void *closure)
Definition: py-type.c:384
PyTypeObject field_object_type
Definition: py-type.c:1653
static PyObject * typy_get_sizeof(PyObject *self, void *closure)
Definition: py-type.c:732
static PyObject * typy_vector(PyObject *self, PyObject *args)
Definition: py-type.c:565
static PyObject * typy_iterator_iter(PyObject *self)
Definition: py-type.c:1343
static PyObject * typy_reference(PyObject *self, PyObject *args)
Definition: py-type.c:644
static PyObject * typy_unqualified(PyObject *self, PyObject *args)
Definition: py-type.c:714
static PyObject * typy_get_name(PyObject *self, void *closure)
Definition: py-type.c:365
static gdbpy_ref field_name(struct type *type, int field)
Definition: py-type.c:234
static PyObject * typy_iterkeys(PyObject *self, PyObject *args)
Definition: py-type.c:1318
static PyObject * typy_volatile(PyObject *self, PyObject *args)
Definition: py-type.c:696
static Py_ssize_t typy_length(PyObject *self)
Definition: py-type.c:1164
static PyObject * typy_array_1(PyObject *self, PyObject *args, int is_vector)
Definition: py-type.c:505
static PyObject * typy_get_objfile(PyObject *self, void *closure)
Definition: py-type.c:401
static PyObject * typy_get_dynamic(PyObject *self, void *closure)
Definition: py-type.c:777
static gdbpy_ref make_fielditem(struct type *type, int i, enum gdbpy_iter_kind kind)
Definition: py-type.c:253
static PyObject * typy_iter(PyObject *self)
Definition: py-type.c:1327
static PyObject * typy_richcompare(PyObject *self, PyObject *other, int op)
Definition: py-type.c:1052
static PyObject * typy_fields(PyObject *self, PyObject *args)
Definition: py-type.c:328
static PyObject * typy_str(PyObject *self)
Definition: py-type.c:1030
static struct type * typy_lookup_type(struct demangle_component *demangled, const struct block *block)
Definition: py-type.c:822
static void set_type(type_object *obj, struct type *type)
Definition: py-type.c:1123
static PyObject * typy_is_signed(PyObject *self, void *closure)
Definition: py-type.c:428
static PyObject * typy_get(PyObject *self, PyObject *args)
Definition: py-type.c:1231
static PyObject * typy_iterator_iternext(PyObject *self)
Definition: py-type.c:1353
static PyObject * typy_legacy_template_argument(struct type *type, const struct block *block, int argno)
Definition: py-type.c:889
int gdbpy_is_field(PyObject *obj)
Definition: py-type.c:126
static PyObject * typy_is_scalar(PyObject *self, void *closure)
Definition: py-type.c:414
PyTypeObject type_object_type
Definition: py-type.c:1604
static PyObject * typy_range(PyObject *self, PyObject *args)
Definition: py-type.c:592
static PyObject * typy_const(PyObject *self, PyObject *args)
Definition: py-type.c:678
static PyObject * typy_strip_typedefs(PyObject *self, PyObject *args)
Definition: py-type.c:447
PyTypeObject type_iterator_object_type
Definition: py-type.c:1695
static struct type * typy_lookup_typename(const char *type_name, const struct block *block)
Definition: py-type.c:797
static PyObject * typy_fields_items(PyObject *self, enum gdbpy_iter_kind kind)
Definition: py-type.c:284
static void field_dealloc(PyObject *obj)
Definition: py-type.c:98
static PyObject * typy_values(PyObject *self, PyObject *args)
Definition: py-type.c:317
static PyObject * typy_itervalues(PyObject *self, PyObject *args)
Definition: py-type.c:1335
static PyObject * typy_get_alignof(PyObject *self, void *closure)
Definition: py-type.c:756
static PyMethodDef type_object_methods[]
Definition: py-type.c:1498
static const registry< objfile >::key< type_object, typy_deleter > typy_objfile_data_key
Definition: py-type.c:1120
static gdb_PyGetSetDef field_object_getset[]
Definition: py-type.c:1646
struct type * type_object_to_type(PyObject *obj)
Definition: py-type.c:1404
static gdbpy_ref convert_field(struct type *type, int field)
Definition: py-type.c:144
static PyObject * typy_array(PyObject *self, PyObject *args)
Definition: py-type.c:557
PyObject * gdbpy_lookup_type(PyObject *self, PyObject *args, PyObject *kw)
Definition: py-type.c:1415
static PyObject * typy_field_names(PyObject *self, PyObject *args)
Definition: py-type.c:348
static PyObject * typy_has_key(PyObject *self, PyObject *args)
Definition: py-type.c:1256
static PyNumberMethods type_object_as_number
Definition: py-type.c:1576
gdbpy_ref gdb_py_object_from_longest(LONGEST l)
Definition: py-utils.c:279
int gdb_py_int_as_long(PyObject *obj, long *result)
Definition: py-utils.c:301
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
Definition: py-utils.c:331
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
Definition: py-utils.c:141
PyObject * gdb_py_generic_dict(PyObject *self, void *closure)
Definition: py-utils.c:314
gdbpy_ref gdb_py_object_from_ulongest(ULONGEST l)
Definition: py-utils.c:290
PyObject * value_to_value_object(struct value *val)
Definition: py-value.c:1778
PyObject * gdb_module
Definition: python.c:84
int gdb_python_initialized
Definition: python.c:80
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
gdbpy_iter_kind
@ iter_values
@ iter_items
@ iter_keys
#define GDB_PY_HANDLE_EXCEPTION(Exception)
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
Definition: block.h:109
LONGEST const_val() const
Definition: gdbtypes.h:347
dynamic_prop_kind kind() const
Definition: gdbtypes.h:337
PyObject_HEAD PyObject * dict
Definition: py-type.c:53
LONGEST loc_bitpos() const
Definition: gdbtypes.h:586
field_loc_kind loc_kind() const
Definition: gdbtypes.h:581
LONGEST loc_enumval() const
Definition: gdbtypes.h:598
const char * name() const
Definition: gdbtypes.h:569
struct type * type() const
Definition: gdbtypes.h:559
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
const char * name
Definition: py-type.c:79
int code
Definition: py-type.c:77
struct dynamic_prop high
Definition: gdbtypes.h:696
struct dynamic_prop low
Definition: gdbtypes.h:692
address_class aclass() const
Definition: symtab.h:1235
struct type * type() const
Definition: symtab.h:1285
PyObject_HEAD struct type * type
Definition: py-type.c:35
struct type_object * prev
Definition: py-type.c:40
struct type_object * next
Definition: py-type.c:41
Definition: gdbtypes.h:922
struct type * target_type() const
Definition: gdbtypes.h:1000
type_code code() const
Definition: gdbtypes.h:927
ULONGEST length() const
Definition: gdbtypes.h:954
struct field & field(int idx) const
Definition: gdbtypes.h:983
bool is_unsigned() const
Definition: gdbtypes.h:1063
bool is_vector() const
Definition: gdbtypes.h:1149
int num_fields() const
Definition: gdbtypes.h:965
bool is_stub() const
Definition: gdbtypes.h:1091
struct objfile * objfile_owner() const
Definition: gdbtypes.h:1342
bool is_pointer_or_reference() const
Definition: gdbtypes.h:1394
range_bounds * bounds() const
Definition: gdbtypes.h:1028
const char * name() const
Definition: gdbtypes.h:939
void operator()(type_object *obj)
Definition: py-type.c:1092
PyObject_HEAD int field
Definition: py-type.c:63
enum gdbpy_iter_kind kind
Definition: py-type.c:65
type_object * source
Definition: py-type.c:67
Definition: value.c:181
@ LOC_OPTIMIZED_OUT
Definition: symtab.h:1033
@ LOC_TYPEDEF
Definition: symtab.h:989
const struct type_print_options type_print_raw_options
Definition: typeprint.c:41
int strcmp_iw(const char *string1, const char *string2)
Definition: utils.c:2981
struct value * value_of_variable(struct symbol *var, const struct block *b)
Definition: valops.c:1378
struct value * allocate_optimized_out_value(struct type *type)
Definition: value.c:1097