From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14016 invoked by alias); 19 Oct 2017 10:18:44 -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 14001 invoked by uid 89); 19 Oct 2017 10:18:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-21.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=H*c:alternative X-HELO: mail-yw0-f171.google.com Received: from mail-yw0-f171.google.com (HELO mail-yw0-f171.google.com) (209.85.161.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Oct 2017 10:18:41 +0000 Received: by mail-yw0-f171.google.com with SMTP id w2so3036108ywa.9 for ; Thu, 19 Oct 2017 03:18:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=oeceaW4fO7Qtpl+dwIb6ZIozRVxDxVeqLpV3/Zn7htE=; b=RjOlFT1989KJhvPRn+2QEe5einaY/Nl+/4DvzPPwYB6CmkW6J1LtjpJ7E9v1ZPHP/e Q+oZR5px5JhQYUB7iht5UuDekHj+CC51qediQmFj21wRo5TDcIm9NR/pRgyu4VoKBRfB NgSOrj5mjNEF3i8lLWR0fX7h/8JyeGJAbxfDnS+c5IGALX0RQRnRTYxFXdSgyHZ1NNn+ 9fBmJzo5jjzydapOhtFSxGGoSzJJUTG3rJeok4AgqJAAGWiIyO05gemOdIEsBvybBl8/ uixMkDJ5uI0LP8VDSoynXbhcJrSO3A2zfq0HVlXZ7hKW9vkapPKQCdFxOZ5ENuLUERXc OTKw== X-Gm-Message-State: AMCzsaVBahDaeYAUVxBWg3OhNbmClIZyjBTceoYvbCe1+gy5vq3FKjJO Vg7UX247o14xyH2Uo/WQBfpdosHzf7cZb5bEFyrYkX6Y X-Google-Smtp-Source: ABhQp+SXvVHt28eGLYGpTf0eMgDr2c2oQOfL0ZbzL/MNb609tUmR+wM7HHQMWxOKEsvxLml162xQvKOFUCeeswNiUPE= X-Received: by 10.129.57.134 with SMTP id g128mr642345ywa.433.1508408319327; Thu, 19 Oct 2017 03:18:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.37.209.143 with HTTP; Thu, 19 Oct 2017 03:18:38 -0700 (PDT) In-Reply-To: <1508405381-16638-1-git-send-email-osscontribute@gmail.com> References: <1508405381-16638-1-git-send-email-osscontribute@gmail.com> From: Patrick Frants Date: Thu, 19 Oct 2017 10:18:00 -0000 Message-ID: Subject: Re: [PATCH] Fix faulty use of obstack_free() to *shrink* dont_print_statmem_obstack. Instead use obstack_blank_fast() with a "negative" size. A real stack data structured would be appropriate here. Added unit test gdb/testsuite/gdb.cp/printstaticrecursion.exp. To: gdb-patches@sourceware.org Cc: Patrick Frants Content-Type: text/plain; charset="UTF-8" X-SW-Source: 2017-10/txt/msg00598.txt.bz2 I am 99% sure the use of obstack_free() on line 390 (also cp-valprint.c) is used in exactly the same way (shrinking) and is therefore also wrong. However, I don't have a unit test for that case. On Thu, Oct 19, 2017 at 11:29 AM, Patrick Frants wrote: > Recursion detection for static members was not working because when > popping addresses of the stack, the stack was unintentionally cleared, > leaving the stack empty. This was caused by a call to obstack_next_free(), > which frees the current object. > The fix uses obstack_blank_fast with a negative size to shrink the current > object with the desired amount. > A unit test (gdb.cp/printstaticrecursion.exp) was added. No new > regression has been observed in testsuite/gdb.cp/*.exp. > --- > gdb/cp-valprint.c | 11 +++----- > gdb/testsuite/gdb.cp/printstaticrecursion.cc | 21 +++++++++++++++ > gdb/testsuite/gdb.cp/printstaticrecursion.exp | 39 > +++++++++++++++++++++++++++ > 3 files changed, 63 insertions(+), 8 deletions(-) > create mode 100644 gdb/testsuite/gdb.cp/printstaticrecursion.cc > create mode 100644 gdb/testsuite/gdb.cp/printstaticrecursion.exp > > diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c > index fb9bfd9..8f9658d 100644 > --- a/gdb/cp-valprint.c > +++ b/gdb/cp-valprint.c > @@ -370,14 +370,9 @@ cp_print_value_fields (struct type *type, struct type > *real_type, > > if (obstack_final_size > statmem_obstack_initial_size) > { > - /* In effect, a pop of the printed-statics stack. */ > - > - void *free_to_ptr = > - (char *) obstack_next_free (&dont_print_statmem_obstack) - > - (obstack_final_size - statmem_obstack_initial_size); > - > - obstack_free (&dont_print_statmem_obstack, > - free_to_ptr); > + /* In effect, a pop of the printed-statics stack. */ > + size_t shrink_bytes = statmem_obstack_initial_size - > obstack_final_size; > + obstack_blank_fast(&dont_print_statmem_obstack, shrink_bytes); > } > > if (last_set_recurse != recurse) > diff --git a/gdb/testsuite/gdb.cp/printstaticrecursion.cc > b/gdb/testsuite/gdb.cp/printstaticrecursion.cc > new file mode 100644 > index 0000000..616c00d > --- /dev/null > +++ b/gdb/testsuite/gdb.cp/printstaticrecursion.cc > @@ -0,0 +1,21 @@ > +#include > + > +struct Inner > +{ > + static Inner instance; > +}; > + > + > +struct Outer > +{ > + Inner inner; > + static Outer instance; > +}; > + > +Inner Inner::instance; > +Outer Outer::instance; > + > +int main() > +{ > + return 0; /* break-here */ > +} > \ No newline at end of file > diff --git a/gdb/testsuite/gdb.cp/printstaticrecursion.exp > b/gdb/testsuite/gdb.cp/printstaticrecursion.exp > new file mode 100644 > index 0000000..1407c12 > --- /dev/null > +++ b/gdb/testsuite/gdb.cp/printstaticrecursion.exp > @@ -0,0 +1,39 @@ > +# Copyright 2008-2017 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > + > +if { [skip_cplus_tests] } { continue } > + > +standard_testfile printstaticrecursion.cc > + > +# Create and source the file that provides information about the compiler > +# used to compile the test case. > +if [get_compiler_info "c++"] { > + untested "couldn't find a valid c++ compiler" > + return -1 > +} > + > +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug > c++}]} { > + return -1 > +} > + > +if ![runto_main] then { > + perror "couldn't run to main" > + continue > +} > + > +gdb_test "print Outer::instance" "{inner = {static instance = {static > instance = }}, static > instance = {inner = {static instance = {static instance = member of an already seen type>}}, static instance = of an already seen type>}}" "Print recursive static member" > +gdb_exit > +return 0 > -- > 1.8.3.1 > >