From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 100490 invoked by alias); 17 Mar 2018 17:13:29 -0000 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 Received: (qmail 100473 invoked by uid 89); 17 Mar 2018 17:13:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 17 Mar 2018 17:13:26 +0000 Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 800BF1E4B2; Sat, 17 Mar 2018 13:13:24 -0400 (EDT) Subject: Re: [PATCH PR gdb/16959] gdb hangs in infinite recursion To: Weimin Pan , gdb-patches@sourceware.org References: <1521160947-2270-1-git-send-email-weimin.pan@oracle.com> From: Simon Marchi Message-ID: <07d54205-8f48-2d9c-f3fe-94fdce478893@simark.ca> Date: Sat, 17 Mar 2018 17:13:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1521160947-2270-1-git-send-email-weimin.pan@oracle.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2018-03/txt/msg00335.txt.bz2 On 2018-03-15 08:42 PM, Weimin Pan wrote: > The original problem was fixed (see related PR 22242). But using a typedef > as the declared type for a static member variable, as commented in this PR, > is still causing gdb to get into infinite loop when printing the static > member's value. This problem can be reproduced as follows: > > % cat t.cc > class A { > typedef A type; > public: > bool operator==(const type& other) { return true; } > > static const type INSTANCE; > }; > > const A A::INSTANCE; > > int main() { > A a; > if (a == A::INSTANCE) { > return -1; > } > return 0; > } > % g++ -g t.cc > % gdb -ex "start" -ex "p a" a.out > > The fix is rather trivial - in cp_print_static_field(), should call > check_typedef() to get the static member's real type and use it to > check whether it's a struct or an array. Hi Weimin, Would it be possible to add a test case for this? I suppose you can quite easily enhance the test case added by commit a43f3893f6cb ("Fix broken recursion detection when printing static members") > Tested on both aarch64-linux-gnu and amd64-linux-gnu. No regressions. > --- > gdb/ChangeLog | 7 +++++++ > gdb/cp-valprint.c | 2 +- > 2 files changed, 8 insertions(+), 1 deletions(-) > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > index d0a8dfd..6fd43de 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,3 +1,10 @@ > +2018-02-07 Weimin Pan > + > + PR gdb/16959 > + * cp-valprint.c: (cp_print_static_field) Use check_typedef() to get > + static member's real type for TYPE_CODE_STRUCT and TYPE_CODE_ARRAY > + comparisons. > + > 2018-01-24 Pedro Alves > > GCC PR libstdc++/83906 > diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c > index 486653f..0370b56 100644 > --- a/gdb/cp-valprint.c > +++ b/gdb/cp-valprint.c > @@ -633,6 +633,7 @@ cp_print_static_field (struct type *type, > return; > } > > + type = check_typedef (type); > if (TYPE_CODE (type) == TYPE_CODE_STRUCT) > { > CORE_ADDR *first_dont_print; > @@ -658,7 +659,6 @@ cp_print_static_field (struct type *type, > addr = value_address (val); > obstack_grow (&dont_print_statmem_obstack, (char *) &addr, > sizeof (CORE_ADDR)); > - type = check_typedef (type); > cp_print_value_fields (type, value_enclosing_type (val), > value_embedded_offset (val), addr, > stream, recurse, val, > type is passed below to val_print. I think it would be better to continue passing the original type to that function instead of the resolved type. It could affect how things are printed (if the type name is printed somewhere, or if pretty printers are involved). Many functions use a variable "real_type" to hold the result from check_typedef, you could follow that pattern. Thanks, Simon