From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30892 invoked by alias); 29 Oct 2011 08:13:07 -0000 Received: (qmail 30874 invoked by uid 22791); 29 Oct 2011 08:13:05 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 29 Oct 2011 08:12:45 +0000 Received: from hpaq2.eem.corp.google.com (hpaq2.eem.corp.google.com [172.25.149.2]) by smtp-out.google.com with ESMTP id p9T8CiAS009749 for ; Sat, 29 Oct 2011 01:12:45 -0700 Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.18.110.50]) by hpaq2.eem.corp.google.com with ESMTP id p9T8CgRk018739 for ; Sat, 29 Oct 2011 01:12:43 -0700 Received: by ruffy.mtv.corp.google.com (Postfix, from userid 67641) id 9FA26246191; Sat, 29 Oct 2011 01:12:42 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [RFC] [python] Fix field list of typedef regression Message-Id: <20111029081242.9FA26246191@ruffy.mtv.corp.google.com> Date: Sat, 29 Oct 2011 08:23:00 -0000 From: dje@google.com (Doug Evans) X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-10/txt/msg00795.txt.bz2 Hi. This patch fixes a regression in the current tree. The field list of a typedef went from the underlying field list to an empty list. Question: What's the right way to handle ref counting here? 2011-10-29 Doug Evans * 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. Index: python/py-type.c =================================================================== RCS file: /cvs/src/src/gdb/python/py-type.c,v retrieving revision 1.27 diff -u -p -r1.27 py-type.c --- python/py-type.c 27 Oct 2011 09:14:27 -0000 1.27 +++ python/py-type.c 29 Oct 2011 08:04:06 -0000 @@ -295,11 +295,24 @@ static PyObject * typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind) { PyObject *result = NULL, *iter = NULL; - + volatile struct gdb_exception except; + + TRY_CATCH (except, RETURN_MASK_ALL) + { + struct type *type = ((type_object *) self)->type; + struct type *checked_type = type; + + CHECK_TYPEDEF (checked_type); + if (checked_type != type) + self = type_to_type_object (checked_type); + /* FIXME: reference counting of self? */ + } + GDB_PY_HANDLE_EXCEPTION (except); + iter = typy_make_iter (self, kind); if (iter == NULL) return NULL; - + result = PySequence_List (iter); Py_DECREF (iter); return result; Index: testsuite/gdb.python/py-type.c =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-type.c,v retrieving revision 1.5 diff -u -p -r1.5 py-type.c --- testsuite/gdb.python/py-type.c 28 Sep 2011 20:06:01 -0000 1.5 +++ testsuite/gdb.python/py-type.c 29 Oct 2011 08:04:06 -0000 @@ -21,6 +21,9 @@ struct s int b; }; +typedef struct s TS; +TS ts; + #ifdef __cplusplus struct C { Index: testsuite/gdb.python/py-type.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-type.exp,v retrieving revision 1.14 diff -u -p -r1.14 py-type.exp --- testsuite/gdb.python/py-type.exp 28 Sep 2011 20:06:01 -0000 1.14 +++ testsuite/gdb.python/py-type.exp 29 Oct 2011 08:04:06 -0000 @@ -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