From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 40187 invoked by alias); 24 Feb 2017 16:12:24 -0000 Mailing-List: contact libstdc++-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libstdc++-owner@gcc.gnu.org Received: (qmail 40153 invoked by uid 89); 24 Feb 2017 16:12:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_SORBS_SPAM,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=held X-HELO: mail.fer.hr Received: from mail5.fer.hr (HELO mail.fer.hr) (161.53.72.235) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 24 Feb 2017 16:12:18 +0000 Received: from POSTAR.fer.hr (2001:b68:16:250::72:237) by MAIL5.fer.hr (2001:b68:16:250::72:235) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 24 Feb 2017 17:12:14 +0100 Received: from mail-wm0-f52.google.com (74.125.82.52) by POSTAR.fer.hr (161.53.72.237) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 24 Feb 2017 17:12:13 +0100 Received: by mail-wm0-f52.google.com with SMTP id t18so9429884wmt.0 for ; Fri, 24 Feb 2017 08:12:13 -0800 (PST) X-Gm-Message-State: AMke39n1E/fi2+CuIvW/6iRtmHM5ePz4KELY0+3yHJc1WCHrtmO6iH5DwIy+6RSM2vaRZXB3GlLUtRzjP0Np4g== X-Received: by 10.28.182.6 with SMTP id g6mr3321921wmf.11.1487952733341; Fri, 24 Feb 2017 08:12:13 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.224.139 with HTTP; Fri, 24 Feb 2017 08:11:32 -0800 (PST) In-Reply-To: References: <308301db772b4f7c95404d69db52baff@MAIL.fer.hr> From: =?UTF-8?B?SnVyYWogT3LFoXVsacSH?= Date: Fri, 24 Feb 2017 16:12:00 -0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Smart pointer pretty printers To: Jonathan Wakely CC: "libstdc++@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-SW-Source: 2017-02/txt/msg00084.txt.bz2 I now realized that I worked on an older version of the printers.py file. I have produced a patch against a recent version, which had some changes to the unique pointer printer regarding a newer implementation of the unique pointer. The patch includes this for both the unique and shared pointers. Also, I have added the same for the vector iterator just for your consideration. Do you think the same could be applied for other STL container iterators? Also, let me know if you need a copyright assignment. Regards, Juraj --- libstdcxx/v6/printers.py +++ libstdcxx/v6/printers.py @@ -121,6 +121,10 @@ class SharedPointerPrinter: def __init__ (self, typename, val): self.typename = strip_versioned_namespace(typename) self.val = val + self.pointer = val['_M_ptr'] + + def children (self): + return [('get()', self.pointer)] def to_string (self): state = 'empty' @@ -131,25 +135,27 @@ class SharedPointerPrinter: if usecount == 0: state = 'expired, weak %d' % weakcount else: - state = 'count %d, weak %d' % (usecount, weakcount - 1) - return '%s (%s) %s' % (self.typename, state, self.val['_M_ptr']) + state = 'use count = %d, weak count = %d' % (usecount, weakcount - 1) + return '%s<%s> (%s)' % (self.typename, str(self.pointer.type.target()), state) class UniquePointerPrinter: "Print a unique_ptr" def __init__ (self, typename, val): self.val = val - - def to_string (self): impl_type = self.val.type.fields()[0].type.tag if is_specialization_of(impl_type, '__uniq_ptr_impl'): # New implementation - v = self.val['_M_t']['_M_t']['_M_head_impl'] + self.pointer = self.val['_M_t']['_M_t']['_M_head_impl'] elif is_specialization_of(impl_type, 'tuple'): - v = self.val['_M_t']['_M_head_impl'] + self.pointer = self.val['_M_t']['_M_head_impl'] else: raise ValueError("Unsupported implementation for unique_ptr: %s" % self.val.type.fields()[0].type.tag) - return 'std::unique_ptr<%s> containing %s' % (str(v.type.target()), - str(v)) + + def children (self): + return [('get()', self.pointer)] + + def to_string (self): + return ('std::unique_ptr<%s>' % (str(self.pointer.type.target()))) def get_value_from_aligned_membuf(buf, valtype): """Returns the value held in a __gnu_cxx::__aligned_membuf.""" @@ -350,11 +356,17 @@ class StdVectorIteratorPrinter: def __init__(self, typename, val): self.val = val + self.pointer = self.val['_M_current'] + + def children(self): + if not self.pointer: + return [] + return [('operator->()', self.pointer)] def to_string(self): - if not self.val['_M_current']: + if not self.pointer: return 'non-dereferenceable iterator for std::vector' - return str(self.val['_M_current'].dereference()) + return ('std::vector<%s>::iterator' % (str(self.pointer.type.target()))) class StdTuplePrinter: "Print a std::tuple"