From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26745 invoked by alias); 17 Sep 2010 19:56:09 -0000 Received: (qmail 26735 invoked by uid 22791); 17 Sep 2010 19:56:08 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_RP_MATCHES_RCVD,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from smtp-out1.tiscali.nl (HELO smtp-out1.tiscali.nl) (195.241.79.176) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 17 Sep 2010 19:56:02 +0000 Received: from [212.123.169.34] (helo=[192.168.1.102]) by smtp-out1.tiscali.nl with esmtp (Exim) (envelope-from ) id 1Owh2N-0003up-RU for gdb-patches@sourceware.org; Fri, 17 Sep 2010 21:55:59 +0200 Subject: [PATCH] [RFC] python: gdb.Type: strip typedefs past pointers too From: Paul Bolle To: gdb-patches@sourceware.org Content-Type: text/plain; charset="UTF-8" Date: Sat, 18 Sep 2010 14:12:00 -0000 Message-ID: <1284753356.21566.10.camel@localhost.localdomain> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit 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: 2010-09/txt/msg00325.txt.bz2 0) gdb.Type.strip_typedefs() stops stripping types if it encounters a type that is a pointer to a typedef: (gdb) ptype wchar_t type = long int (gdb) ptype wchar_t * type = long int * (gdb) python print gdb.lookup_type("wchar_t").strip_typedefs() long int (gdb) python print gdb.lookup_type("wchar_t").pointer().strip_typedefs() wchar_t * 1) I drafted a patch (pasted below this message) that works around this limitation: (gdb) ptype wchar_t type = long int (gdb) ptype wchar_t * type = long int * (gdb) python print gdb.lookup_type("wchar_t").strip_typedefs() long int (gdb) python print gdb.lookup_type("wchar_t").pointer().strip_typedefs() long int * 2) I'm not comfortable with the code I'm using here (ie, gdb's type handling code) so I'd appreciate comments on this draft patch. Paul Bolle --- Currently gdb.Type.strip_typedefs() doesn't strip typedefs if it encounters a type that is a pointer to a typedef. In those cases it doesn't really behave as advertised (well, as I understand the advertisement). So learn strip_typedefs() to handle pointers to typedefs too. --- gdb/python/py-type.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 8232436..08602a1 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -267,8 +267,29 @@ static PyObject * typy_strip_typedefs (PyObject *self, PyObject *args) { struct type *type = ((type_object *) self)->type; + struct type *real_type; + int level = 0; - return type_to_type_object (check_typedef (type)); + real_type = check_typedef (type); + + while (TYPE_CODE (real_type) == TYPE_CODE_PTR || + TYPE_CODE (real_type) == TYPE_CODE_TYPEDEF) + { + if (TYPE_CODE (real_type) == TYPE_CODE_TYPEDEF) + { + CHECK_TYPEDEF (real_type); + } + else + { + real_type = TYPE_TARGET_TYPE (real_type); + level++; + } + } + + while (level--) + real_type = lookup_pointer_type (real_type); + + return type_to_type_object (real_type); } /* Return an array type. */ -- 1.7.2.3