17 """Utilities for working with gdb.Types."""
23 """Return the "basic" type of a type.
26 type_: The type to reduce to its basic type.
29 type_ with const/volatile is stripped away,
30 and typedefs/references converted to the underlying type.
33 while (type_.code == gdb.TYPE_CODE_REF
or
34 type_.code == gdb.TYPE_CODE_TYPEDEF):
35 if type_.code == gdb.TYPE_CODE_REF:
36 type_ = type_.target()
38 type_ = type_.strip_typedefs()
39 return type_.unqualified()
43 """Return True if a type has the specified field.
46 type_: The type to examine.
47 It must be one of gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION.
48 field: The name of the field to look up.
51 True if the field is present either in type_ or any baseclass.
54 TypeError: The type is not a struct or union.
58 if (type_.code != gdb.TYPE_CODE_STRUCT
and
59 type_.code != gdb.TYPE_CODE_UNION):
60 raise TypeError(
"not a struct or union")
61 for f
in type_.fields():
73 """Return a dictionary from a program's enum type.
76 enum_type: The enum to compute the dictionary for.
79 The dictionary of the enum.
82 TypeError: The type is not an enum.
85 if enum_type.code != gdb.TYPE_CODE_ENUM:
86 raise TypeError(
"not an enum type")
88 for field
in enum_type.fields():
90 enum_dict[field.name] = field.enumval
95 """Return an iterator that recursively traverses anonymous fields.
98 type_: The type to traverse. It should be one of
99 gdb.TYPE_CODE_STRUCT or gdb.TYPE_CODE_UNION.
102 an iterator similar to gdb.Type.iteritems(), i.e., it returns
103 pairs of key, value, but for any anonymous struct or union
104 field that field is traversed recursively, depth-first.
106 for k, v
in type_.iteritems ():
110 for i
in deep_items (v.type):
114 """The base class for type printers.
116 Instances of this type can be used to substitute type names during
119 A type printer must have at least 'name' and 'enabled' attributes,
120 and supply an 'instantiate' method.
122 The 'instantiate' method must either return None, or return an
123 object which has a 'recognize' method. This method must accept a
124 gdb.Type argument and either return None, meaning that the type
125 was not recognized, or a string naming the type.
137 for printer
in plist:
139 inst = printer.instantiate()
145 "Return a list of the enabled type recognizers for the current context."
149 for objfile
in gdb.objfiles():
159 """Apply the given list of type recognizers to the type TYPE_OBJ.
160 If any recognizer in the list recognizes TYPE_OBJ, returns the name
161 given by the recognizer. Otherwise, this returns None."""
162 for r
in recognizers:
163 result = r.recognize(type_obj)
164 if result
is not None:
169 """Register a type printer.
170 PRINTER is the type printer instance.
171 LOCUS is either an objfile, a program space, or None, indicating
172 global registration."""
176 locus.type_printers.insert(0, printer)
def get_basic_type(type_)
def register_type_printer(locus, printer)
def make_enum_dict(enum_type)
def has_field(type_, field)
def _get_some_type_recognizers(result, plist)
def apply_type_recognizers(recognizers, type_obj)
def get_type_recognizers()