diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index c7fd25b..b3632ea 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -56,8 +56,11 @@ typedef struct pyty_field_object static PyTypeObject field_object_type; /* A type iterator object. */ -typedef struct { +typedef struct iterator_object +{ PyObject_HEAD + /* The iterators for support fields of anonymous field */ + struct iterator_object *child; /* The current field index. */ int field; /* What to return. */ @@ -1200,6 +1203,7 @@ typy_make_iter (PyObject *self, enum gdbpy_iter_kind kind) if (typy_iter_obj == NULL) return NULL; + typy_iter_obj->child = NULL; typy_iter_obj->field = 0; typy_iter_obj->kind = kind; Py_INCREF (self); @@ -1257,11 +1261,27 @@ static PyObject * typy_iterator_iternext (PyObject *self) { typy_iterator_object *iter_obj = (typy_iterator_object *) self; - struct type *type = iter_obj->source->type; - int i; - PyObject *result; - - if (iter_obj->field < TYPE_NFIELDS (type)) + typy_iterator_object *child_iter_obj; + struct type *type; + PyObject *result, *child_pytype; + const char *name; + + if (iter_obj->child) + { + result = typy_iterator_iternext((PyObject*)iter_obj->child); + if (result) + return result; + Py_CLEAR(iter_obj->child); + } + + type = iter_obj->source->type; + +restart: + if (iter_obj->field >= TYPE_NFIELDS (type)) + return NULL; + + name = TYPE_FIELD_NAME (type, iter_obj->field); + if (!name || name[0]) /* array element or regular named member */ { result = make_fielditem (type, iter_obj->field, iter_obj->kind); if (result != NULL) @@ -1269,7 +1289,14 @@ typy_iterator_iternext (PyObject *self) return result; } - return NULL; + type = TYPE_FIELD_TYPE(type, iter_obj->field++); + child_pytype = type_to_type_object(type); + if (!child_pytype) + return NULL; + child_iter_obj = (typy_iterator_object*)typy_make_iter(child_pytype, iter_obj->kind); + iter_obj->child = child_iter_obj; + iter_obj = child_iter_obj; + goto restart; } static void