From f6b47be484b30121c0d162eafd6c4a64dbd8d59f Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Thu, 10 Nov 2011 19:15:10 +0000 Subject: [PATCH] * python/py-type.c (typy_fields_items): Call check_typedef. testsuite/ * gdb.python/py-type.c (TS): New typedef. (ts): New global. * gdb.python/py-type.exp: Test field list of typedef. --- gdb/ChangeLog | 4 ++++ gdb/python/py-type.c | 33 ++++++++++++++++++++++------ gdb/testsuite/ChangeLog | 6 +++++ gdb/testsuite/gdb.python/py-type.c | 3 +++ gdb/testsuite/gdb.python/py-type.exp | 4 ++++ 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c1770be68e0..cc877485bfc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2011-11-10 Doug Evans + + * python/py-type.c (typy_fields_items): Call check_typedef. + 2011-11-10 Joel Brobecker * findvar.c (read_frame_register_value): Read the correct bytes diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 67696fd80a7..44a22232827 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -294,14 +294,33 @@ make_fielditem (struct type *type, int i, enum gdbpy_iter_kind kind) static PyObject * typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind) { + PyObject *py_type = self; PyObject *result = NULL, *iter = NULL; - - iter = typy_make_iter (self, kind); - if (iter == NULL) - return NULL; - - result = PySequence_List (iter); - Py_DECREF (iter); + volatile struct gdb_exception except; + struct type *type = ((type_object *) py_type)->type; + struct type *checked_type = type; + + TRY_CATCH (except, RETURN_MASK_ALL) + { + CHECK_TYPEDEF (checked_type); + } + GDB_PY_HANDLE_EXCEPTION (except); + + if (checked_type != type) + py_type = type_to_type_object (checked_type); + iter = typy_make_iter (py_type, kind); + if (checked_type != type) + { + /* Need to wrap this in braces because Py_DECREF isn't wrapped + in a do{}while(0). */ + Py_DECREF (py_type); + } + if (iter != NULL) + { + result = PySequence_List (iter); + Py_DECREF (iter); + } + return result; } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 8b0abc33325..a12be84399a 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-11-10 Doug Evans + + * gdb.python/py-type.c (TS): New typedef. + (ts): New global. + * gdb.python/py-type.exp: Test field list of typedef. + 2011-11-10 Joel Brobecker * gdb.ada/small_reg_param: New testcase. diff --git a/gdb/testsuite/gdb.python/py-type.c b/gdb/testsuite/gdb.python/py-type.c index b0dcc9dc8fd..2d49ff822fc 100644 --- a/gdb/testsuite/gdb.python/py-type.c +++ b/gdb/testsuite/gdb.python/py-type.c @@ -21,6 +21,9 @@ struct s int b; }; +typedef struct s TS; +TS ts; + #ifdef __cplusplus struct C { diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp index ec86586f0af..3578a7e2267 100644 --- a/gdb/testsuite/gdb.python/py-type.exp +++ b/gdb/testsuite/gdb.python/py-type.exp @@ -64,6 +64,10 @@ proc runto_bp {bp} { proc test_fields {lang} { global gdb_prompt + # .fields() of a typedef should still return the underlying field list + gdb_test "python print len(gdb.parse_and_eval('ts').type.fields())" "2" \ + "$lang typedef field list" + if {$lang == "c++"} { # Test usage with a class gdb_py_test_silent_cmd "print c" "print value" 1 -- 2.30.2