From patchwork Fri Aug 10 19:49:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 176613 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 18D0E2C008B for ; Sat, 11 Aug 2012 05:49:57 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1345232998; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: From:To:Subject:CC:Date:Message-ID:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=Nsqhn9ZvKzt958clEsBs mD/PGro=; b=maklIIzTPtVnZDc8P+vsqH+tfaPXMzdlWtMqjS61mTNu9+vAkIoV 95MeLs/c1TWGo0ANXasCC65tzaLZsGi8J74sRxvt2PTQF0WS14aZGt+vqCJdmDaB ipceWD7xv8TAycqGQNGT0xE9KCb4e6tQyCfSGBHVLPslEbtTg5ONqo0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:From:To:Subject:CC:Date:Message-ID:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=qGV3UNYEybcr/PmEwyJ7vwINeijbdevrufAWO9XVJd59PrZD3xgPnXHKJLXA8B xSxyQvJWhgscslqw0qzvqfbzAzouy1HVwxIid1ZXOYk5ctOMBu9fdEvvMPIKe0LZ di7Is7WWyP5QRU5N7JHuUtnACvFnhm13xXJTHEtIA5cdQ=; Received: (qmail 362 invoked by alias); 10 Aug 2012 19:49:43 -0000 Received: (qmail 345 invoked by uid 22791); 10 Aug 2012 19:49:42 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 10 Aug 2012 19:49:28 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7AJnSPm001288 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 10 Aug 2012 15:49:28 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q7AJnQBj002470 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 10 Aug 2012 15:49:27 -0400 From: Tom Tromey To: libstdc Subject: RFC: fix std::unique_ptr pretty-printer CC: gcc-patches@gcc.gnu.org Date: Fri, 10 Aug 2012 13:49:26 -0600 Message-ID: <874noaa5o9.fsf@fleche.redhat.com> MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org A user reported on irc that the std::unique_ptr pretty-printer yields bad results. For example: (gdb) p uptr $1 = std::tuple containing = { [1] = , [2] = { > = {}, } } This omits the actual pointer and prints some useless stuff instead. This patch fixes the printer and adds a test. The new output looks like this: $11 = std::unique_ptr containing (datum *) 0x6067d0 Let me know what you think. Tom b/libstdc++-v3/ChangeLog: 2012-08-10 Tom Tromey * testsuite/libstdc++-prettyprinters/cxx11.cc (struct datum): New. (global): New global. (main): Add test for unique_ptr. * python/libstdcxx/v6/printers.py (UniquePointerPrinter.to_string): Extract the pointer and also print its type. diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 4520f32..dcb98de 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -71,7 +71,8 @@ class UniquePointerPrinter: self.val = val def to_string (self): - return self.val['_M_t'] + v = self.val['_M_t']['_M_head_impl'] + return 'std::unique_ptr containing (' + str(v.type) + ') ' + str(v) class StdListPrinter: "Print a std::list" diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc index 54b3275..7e2e240 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc @@ -48,6 +48,14 @@ use(const T &container) placeholder(*i); } +struct datum +{ + std::string s; + int i; +}; + +std::unique_ptr global; + int main() { @@ -86,6 +94,11 @@ main() uoms.insert(5); // { dg-final { note-test uoms {std::unordered_multiset with 1 elements = {[0] = 5}} } } + std::unique_ptr uptr (new datum); + uptr->s = "hi bob"; + uptr->i = 23; +// { dg-final { regexp-test uptr {std::unique_ptr containing .datum .. 0x.*} } } + placeholder(""); // Mark SPOT use(efl); use(fl); @@ -93,6 +106,8 @@ main() use(eumm); use(eus); use(eums); + use(uoms); + use(uptr->s); return 0; }