From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 104954 invoked by alias); 16 Dec 2016 13:17:49 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 104748 invoked by uid 89); 16 Dec 2016 13:17:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.0 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=de, wat, policy X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Dec 2016 13:17:34 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C50AEC050918; Fri, 16 Dec 2016 13:17:33 +0000 (UTC) Received: from localhost (ovpn-116-120.ams2.redhat.com [10.36.116.120]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uBGDHW3p007022; Fri, 16 Dec 2016 08:17:33 -0500 Date: Fri, 16 Dec 2016 13:17:00 -0000 From: Jonathan Wakely To: Jan Kratochvil Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org, Keith Seitz , Pedro Alves , gdb@sourceware.org Subject: Re: [PATCH] PR59170 make pretty printers check for singular iterators Message-ID: <20161216131732.GE895@redhat.com> References: <20161215141817.GA22699@redhat.com> <20161215211903.GA22897@host1.jankratochvil.net> <20161216010707.GF22266@redhat.com> <20161216075136.GA21305@host1.jankratochvil.net> <20161216123352.GB895@redhat.com> <20161216130645.GA27556@host1.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20161216130645.GA27556@host1.jankratochvil.net> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.1 (2016-10-04) X-SW-Source: 2016-12/txt/msg00026.txt.bz2 On 16/12/16 14:06 +0100, Jan Kratochvil wrote: >On Fri, 16 Dec 2016 13:33:52 +0100, Jonathan Wakely wrote: >> We don't do auto-deref for std::shared_ptr or std::unique_ptr, even >> though we know the object they point to definitely is live and safe to >> access, and that's because those types have pointer semantics not >> reference semantics. > >This is wrong std::shared_ptr or std::unique_ptr is not auto-dereferenced for >GDB printing. But it may be more a GDB problem, not libstdc++ pretty printers >problem. > >For example glib pretty printers already auto-dereference data structures: > 5 GList* list = NULL; > (gdb) p/r list > $1 = (GList *) 0x607a00 > (gdb) p list > $2 = 0x607a00 = {0x400810} > /usr/share/glib-2.0/gdb/glib.py > if type.code == gdb.TYPE_CODE_PTR: > type = type.target().unqualified() > t = str(type) > if t == "GList": > return GListPrinter(val, "GList") > >But that is more a GDB bug that should be solved even for generic pointers. >Currently while traversing through data structures one has to randomly add or >remove '*' from the beginning of the GDB print expression: > > 1 class E { int a[1000]; int i=42; } ee; > 2 class D { E *e=ⅇ } dd; > 3 class C { D &d=dd; } cc; > 4 class B { C *c=&cc; } bb; > 5 int main() {} > (gdb) p bb > $1 = {c = 0x601030 } > (gdb) p bb.c > $2 = (C *) 0x601030 >Oops, I need to add a dereference: > (gdb) p *bb.c > $3 = {d = @0x601028} > (gdb) p *bb.c.d > No symbol "operator*" in current context. >Oops, I need to remove a dereference: > (gdb) p bb.c.d > $4 = (D &) @0x601028: {e = 0x601060 } Wat? bb.c.d is not a valid expression. B::c is a pointer, it should be bb.c->d Is it GDB policy to make invalid expressions like that "work"? Because I'm not comfortable emulating that in the libstdc++ printers. > (gdb) p bb.c.d.e > $5 = (E *) 0x601060 >Oops, I need to add a dereference: > (gdb) p *bb.c.d.e > $6 = {a = {0 }, i = 42} > (gdb) p *bb.c.d.e.i > Cannot access memory at address 0x2a >Oops, I need to remove a dereference: > (gdb) p bb.c.d.e.i > $7 = 42 I had no idea this even worked, I'd have used bb.c->d.e->i because that's the correct expression for accessing that variable.