Message ID | 1521160947-2270-1-git-send-email-weimin.pan@oracle.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 22260 invoked by alias); 16 Mar 2018 01:07:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 21043 invoked by uid 89); 16 Mar 2018 01:07:55 -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_PASS, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.2 spammy= X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Mar 2018 01:07:53 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2G0bEi9005126 for <gdb-patches@sourceware.org>; Fri, 16 Mar 2018 01:07:51 GMT Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2gr3dk8258-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <gdb-patches@sourceware.org>; Fri, 16 Mar 2018 01:07:51 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w2G17nwo021764 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <gdb-patches@sourceware.org>; Fri, 16 Mar 2018 01:07:50 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w2G17nw3027079 for <gdb-patches@sourceware.org>; Fri, 16 Mar 2018 01:07:49 GMT Received: from wmpan.us.oracle.com (/10.147.27.127) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 15 Mar 2018 18:07:49 -0700 From: Weimin Pan <weimin.pan@oracle.com> To: gdb-patches@sourceware.org Subject: [PATCH PR gdb/16959] gdb hangs in infinite recursion Date: Thu, 15 Mar 2018 18:42:27 -0600 Message-Id: <1521160947-2270-1-git-send-email-weimin.pan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8833 signatures=668690 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803160005 |
Commit Message
Weimin Pan
March 16, 2018, 12:42 a.m. UTC
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. 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(-)
Comments
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 <weimin.pan@oracle.com> > + > + 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 <palves@redhat.com> > > 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
On 3/17/2018 10:13 AM, Simon Marchi wrote: > 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") Hi Simon, Will see if I can add this testing to an existing test case or I need to create a new test case for it. Maybe the latter is preferred? Also I need to study/learn your "commit" command since I'm a new "git" user. Thank you very much for your comment. Weimin > >> 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 <weimin.pan@oracle.com> >> + >> + 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 <palves@redhat.com> >> >> 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 >
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 <weimin.pan@oracle.com> + + 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 <palves@redhat.com> 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,